sys_leaderboards.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __SYS_LEADERBOARDS_H__
  21. #define __SYS_LEADERBOARDS_H__
  22. /*
  23. ================================================================================================
  24. Stats (for achievements, matchmaking, etc.)
  25. ================================================================================================
  26. */
  27. /*
  28. ================================================
  29. systemStats_t
  30. This is to give the framework the ability to deal with stat indexes that are
  31. completely up to each game. The system needs to deal with some stat indexes for things like
  32. the level for matchmaking, etc.
  33. ================================================
  34. */
  35. /*
  36. ================================================================================================
  37. Leaderboards
  38. ================================================================================================
  39. */
  40. const int MAX_LEADERBOARDS = 256;
  41. const int MAX_LEADERBOARD_COLUMNS = 16;
  42. enum aggregationMethod_t {
  43. AGGREGATE_MIN, // Write the new value if it is less than the existing value.
  44. AGGREGATE_MAX, // Write the new value if it is greater than the existing value.
  45. AGGREGATE_SUM, // Add the new value to the existing value and write the result.
  46. AGGREGATE_LAST, // Write the new value.
  47. };
  48. enum rankOrder_t {
  49. RANK_GREATEST_FIRST, // Rank the in descending order, greatest score is best score
  50. RANK_LEAST_FIRST, // Rank the in ascending order, lowest score is best score
  51. };
  52. enum statsColumnDisplayType_t {
  53. STATS_COLUMN_DISPLAY_NUMBER,
  54. STATS_COLUMN_DISPLAY_TIME_MILLISECONDS,
  55. STATS_COLUMN_DISPLAY_CASH,
  56. STATS_COLUMN_NEVER_DISPLAY,
  57. };
  58. struct columnDef_t {
  59. const char * locDisplayName;
  60. int bits;
  61. aggregationMethod_t aggregationMethod;
  62. statsColumnDisplayType_t displayType;
  63. };
  64. extern struct leaderboardDefinition_t * registeredLeaderboards[MAX_LEADERBOARDS];
  65. extern int numRegisteredLeaderboards;
  66. struct leaderboardDefinition_t {
  67. leaderboardDefinition_t() :
  68. id ( -1 ),
  69. numColumns( 0 ),
  70. columnDefs( NULL ),
  71. rankOrder( RANK_GREATEST_FIRST ),
  72. supportsAttachments( false ),
  73. checkAgainstCurrent( false ) {
  74. }
  75. leaderboardDefinition_t( int id_, int numColumns_, const columnDef_t * columnDefs_, rankOrder_t rankOrder_, bool supportsAttachments_, bool checkAgainstCurrent_ ) :
  76. id ( id_ ),
  77. numColumns( numColumns_ ),
  78. columnDefs( columnDefs_ ),
  79. rankOrder( rankOrder_ ),
  80. supportsAttachments( supportsAttachments_ ),
  81. checkAgainstCurrent( checkAgainstCurrent_ ) {
  82. assert( numRegisteredLeaderboards < MAX_LEADERBOARDS );
  83. registeredLeaderboards[numRegisteredLeaderboards++] = this;
  84. }
  85. int32 id;
  86. int32 numColumns;
  87. const columnDef_t * columnDefs;
  88. rankOrder_t rankOrder;
  89. bool supportsAttachments;
  90. bool checkAgainstCurrent; // Compare column 0 with the currently stored leaderboard, and only submit the new leaderboard if the new column 0 is better
  91. };
  92. struct column_t {
  93. column_t( int64 value_ ) : value( value_ ) {}
  94. column_t() {}
  95. int64 value;
  96. };
  97. /*
  98. ================================================================================================
  99. Contains the Achievement and LeaderBoard free function declarations.
  100. ================================================================================================
  101. */
  102. typedef int32 leaderboardHandle_t;
  103. /*
  104. ================================================
  105. idLeaderBoardEntry
  106. ================================================
  107. */
  108. class idLeaderBoardEntry {
  109. public:
  110. static const int MAX_LEADERBOARD_COLUMNS = 16;
  111. idStr username; // aka gamertag
  112. int64 score;
  113. int64 columns[ MAX_LEADERBOARD_COLUMNS ];
  114. };
  115. const leaderboardDefinition_t * Sys_FindLeaderboardDef( int id );
  116. //------------------------
  117. // leaderboardError_t
  118. //------------------------
  119. enum leaderboardError_t {
  120. LEADERBOARD_ERROR_NONE,
  121. LEADERBOARD_ERROR_FAILED, // General error occurred
  122. LEADERBOARD_ERROR_NOT_ONLINE, // Not online to request leaderboards
  123. LEADERBOARD_ERROR_BUSY, // Unable to download leaderboards right now (download already in progress)
  124. LEADERBOARD_ERROR_INVALID_USER, // Unable to request leaderboards as the given user
  125. LEADERBOARD_ERROR_INVALID_REQUEST, // The leaderboard request was invalid
  126. LEADERBOARD_ERROR_DOWNLOAD, // An error occurred while downloading the leaderboard
  127. LEADERBOARD_ERROR_MAX
  128. };
  129. /*
  130. ================================================
  131. idLeaderboardCallback
  132. ================================================
  133. */
  134. class idLeaderboardCallback : public idCallback {
  135. public:
  136. struct row_t {
  137. bool hasAttachment;
  138. int64 attachmentID;
  139. idStr name;
  140. int64 rank;
  141. idArray<int64,MAX_LEADERBOARD_COLUMNS> columns;
  142. long user_id;
  143. // CSteamID user_id;
  144. };
  145. idLeaderboardCallback() : def( NULL ), startIndex( -1 ), localIndex( -1 ), numRowsInLeaderboard( -1 ), errorCode( LEADERBOARD_ERROR_NONE ) { }
  146. virtual idLeaderboardCallback * Clone() const = 0;
  147. // Used by the platform handlers to set data
  148. void ResetRows() { rows.Clear(); }
  149. void AddRow( const row_t & row ) { rows.Append( row ); }
  150. void SetNumRowsInLeaderboard( int32 i ) { numRowsInLeaderboard = i; }
  151. void SetDef( const leaderboardDefinition_t * def_ ) { def = def_; }
  152. void SetStartIndex( int startIndex_ ) { startIndex = startIndex_; }
  153. void SetLocalIndex( int localIndex_ ) { localIndex = localIndex_; }
  154. void SetErrorCode( leaderboardError_t errorCode ) { this->errorCode = errorCode; }
  155. // Used in user callback for information retrieval
  156. const leaderboardDefinition_t * GetDef() const { return def; }
  157. int GetStartIndex() const { return startIndex; }
  158. const idList< row_t > & GetRows() const { return rows; }
  159. int GetNumRowsInLeaderboard() const { return numRowsInLeaderboard; }
  160. int GetLocalIndex() const { return localIndex; }
  161. leaderboardError_t GetErrorCode() const { return this->errorCode; }
  162. protected:
  163. const leaderboardDefinition_t * def; // leaderboard def
  164. int startIndex; // where the first row starts in the online leaderboard
  165. int localIndex; // if player is in the rows, this is the offset of him within the returned rows
  166. idList< row_t > rows; // leaderboard entries for the request
  167. int numRowsInLeaderboard; // total number of rows in the online leaderboard
  168. leaderboardError_t errorCode; // error, if any, that occurred during last operation
  169. };
  170. #endif // !__SYS_LEADERBOARDS_H__