GoogleGamesSocialSession.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #if defined(__ANDROID__) && defined(GP_USE_SOCIAL)
  2. #include "Base.h"
  3. #include "GoogleGamesSocialSession.h"
  4. #include <android_native_app_glue.h>
  5. #include <android/log.h>
  6. namespace gameplay
  7. {
  8. extern struct android_app* __state;
  9. GoogleGamesSocialSession* GoogleGamesSocialSession::_session = NULL;
  10. GoogleGamesSocialSession::GoogleGamesSocialSession()
  11. : SocialSession(),
  12. _listener(NULL), _properties(NULL), _pendingUserResponse(false), _pendingFriendsResponse(false),
  13. _pendingScoresResponse(false), _pendingSubmitScoreResponse(false), _pendingAchievementResponse(false),
  14. _pendingDataResponse(false),
  15. _key(NULL)
  16. {
  17. _userOp = USEROP_GET_LOCALUSER;
  18. }
  19. GoogleGamesSocialSession::~GoogleGamesSocialSession()
  20. {
  21. }
  22. SocialSessionListener* GoogleGamesSocialSession::getListener()
  23. {
  24. return _listener;
  25. }
  26. SocialSession *GoogleGamesSocialSession::authenticate(SocialSessionListener* listener, Properties* properties)
  27. {
  28. if (!_session)
  29. {
  30. _session = new GoogleGamesSocialSession();
  31. _session->_listener = listener;
  32. _session->_properties = properties;
  33. const char* gameId = properties->getString("id");
  34. const char* gameSecret = properties->getString("secret");
  35. const char* gameVersion = properties->getString("version");
  36. const char* gameCurrency = properties->getString("currency");
  37. const char* gameLanguage = properties->getString("language");
  38. #ifdef __ANDROID__
  39. android_app* state = __state;
  40. GP_ASSERT(state && state->activity && state->activity->vm);
  41. JavaVM* jvm = state->activity->vm;
  42. JNIEnv* env = NULL;
  43. jvm->GetEnv((void **)&env, JNI_VERSION_1_6);
  44. jint r = jvm->AttachCurrentThread(&env, NULL);
  45. if (r == JNI_ERR)
  46. {
  47. GP_ERROR("Failed to retrieve JVM environment to authenticate.");
  48. return 0;
  49. }
  50. GP_ASSERT(env);
  51. jclass testClassHandle = env->FindClass("org/gameplay3d/lib/TestClass");
  52. jmethodID computeMultHandle = env->GetMethodID(testClassHandle, "ComputeMult", "(FF)I");
  53. jmethodID testClassCtor = env->GetMethodID(testClassHandle, "<init>", "()V");
  54. jobject testClassInstance = env->NewObject(testClassHandle, testClassCtor);
  55. jfloat a = 4.0f;
  56. jfloat b = 0.5f;
  57. jint result = env->CallIntMethod(testClassInstance, computeMultHandle, a, b);
  58. fprintf(stderr, "the results is %d\n", result);
  59. jvm->DetachCurrentThread();
  60. #endif
  61. }
  62. return _session;
  63. }
  64. const SocialPlayer& GoogleGamesSocialSession::getUser() const
  65. {
  66. return _user;
  67. }
  68. /**
  69. * @see SocialSession::loadFriends
  70. */
  71. void GoogleGamesSocialSession::loadFriends()
  72. {
  73. }
  74. /**
  75. * @see SocialSession::loadAchievements
  76. */
  77. void GoogleGamesSocialSession::loadAchievements()
  78. {
  79. }
  80. /**
  81. * @see SocialSession::submitAchievement
  82. */
  83. void GoogleGamesSocialSession::submitAchievement(const char* achievementId, unsigned int value, bool achieved=false)
  84. {
  85. }
  86. /**
  87. * @see SocialSession::incrementAchievement
  88. */
  89. void GoogleGamesSocialSession::incrementAchievement(const char* achievementId, unsigned int increment=1)
  90. {
  91. }
  92. /**
  93. * @see SocialSession::syncAchievements
  94. */
  95. void GoogleGamesSocialSession::synchronizeAchievements()
  96. {
  97. }
  98. /**
  99. * @see SocialSession::loadScores
  100. */
  101. void GoogleGamesSocialSession::loadScores(const char* leaderboardId, SocialSession::CommunityScope community, SocialSession::TimeScope time, const SocialPlayer& player, unsigned int count)
  102. {
  103. }
  104. /**
  105. * @see SocialSession::loadScores
  106. */
  107. void GoogleGamesSocialSession::loadScores(const char* leaderboardId, SocialSession::CommunityScope community, SocialSession::TimeScope time, unsigned int start, unsigned int count)
  108. {
  109. }
  110. /**
  111. * @see SocialSession::submitScore
  112. */
  113. void GoogleGamesSocialSession::submitScore(const char* leaderboardId, float score)
  114. {
  115. }
  116. /**
  117. * @see SocialSession::submitChallenge
  118. */
  119. void GoogleGamesSocialSession::submitChallenge(const SocialPlayer *player, unsigned int wager, float score, const char* leaderboardId=0)
  120. {
  121. }
  122. /**
  123. * @see SocialSession::loadChallenges
  124. */
  125. void GoogleGamesSocialSession::loadChallenges(bool showOpenChallengesOnly=true)
  126. {
  127. }
  128. /**
  129. * @see SocialSession::acceptChallenge
  130. */
  131. void GoogleGamesSocialSession::replyToChallenge(const SocialChallenge *challenge, bool accept)
  132. {
  133. }
  134. /**
  135. * @see SocialSession::requestSavedData
  136. */
  137. void GoogleGamesSocialSession::loadSavedData(const char* key) {}
  138. /**
  139. * @see SocialSession::submitSavedData
  140. */
  141. void GoogleGamesSocialSession::submitSavedData(const char* key, std::string data) {}
  142. void GoogleGamesSocialSession::displayLeaderboard(const char* leaderboardId) {}
  143. void GoogleGamesSocialSession::displayAchievements() {}
  144. void GoogleGamesSocialSession::displayChallenges() {}
  145. void GoogleGamesSocialSession::displayChallengeSubmit(const SocialChallenge *challenge, float score) {}
  146. }
  147. #endif