-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
171 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ else () | |
SHARED | ||
src/steamworks_c_wrapper | ||
src/CallbackHandler | ||
src/CSteamLeaderboard | ||
) | ||
endif() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <iostream> | ||
#include "CSteamLeaderboard.h" | ||
|
||
CSteamLeaderboard::CSteamLeaderboard() : m_hCurrentLeaderboard(0) | ||
{ | ||
// Nothing yet | ||
} | ||
|
||
void | ||
CSteamLeaderboard::SetCurrent(SteamLeaderboard_t hCurrentLeaderboard) | ||
{ | ||
m_hCurrentLeaderboard = hCurrentLeaderboard; | ||
} | ||
|
||
void | ||
CSteamLeaderboard::FindLeaderboard(const char *pchLeaderboardName ) | ||
{ | ||
|
||
SteamAPICall_t hSteamAPICall = SteamUserStats()->FindLeaderboard(pchLeaderboardName); | ||
m_callResultFindLeaderboard.Set(hSteamAPICall, | ||
this, | ||
&CSteamLeaderboard::OnFindLeaderboard); | ||
} | ||
|
||
bool | ||
CSteamLeaderboard::UploadScore(int score, const int *details, int nDetails) | ||
{ | ||
if (!m_hCurrentLeaderboard) | ||
return false; | ||
|
||
SteamAPICall_t hSteamAPICall = SteamUserStats()->UploadLeaderboardScore(m_hCurrentLeaderboard, | ||
k_ELeaderboardUploadScoreMethodKeepBest, | ||
score, | ||
details, | ||
nDetails); | ||
m_callResultUploadScore.Set(hSteamAPICall, this, &CSteamLeaderboard::OnUploadScore); | ||
return true; | ||
} | ||
|
||
bool | ||
CSteamLeaderboard::DownloadScores() | ||
{ | ||
if (!m_hCurrentLeaderboard) return false; | ||
SteamAPICall_t hSteamAPICall = SteamUserStats()->DownloadLeaderboardEntries( m_hCurrentLeaderboard, | ||
k_ELeaderboardDataRequestGlobalAroundUser, | ||
-4, | ||
5); | ||
|
||
m_callResultDownloadScores.Set(hSteamAPICall, this, &CSteamLeaderboard::OnDownloadScores); | ||
return true; | ||
} | ||
|
||
void | ||
CSteamLeaderboard::OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure) | ||
{ | ||
if (!pCallback->m_bLeaderboardFound || bIOFailiure) { | ||
std::cerr << "Leaderboard could not be found" << std::endl; | ||
return; | ||
} | ||
m_hCurrentLeaderboard = pCallback->m_hSteamLeaderboard; | ||
} | ||
|
||
void | ||
CSteamLeaderboard::OnUploadScore(LeaderboardScoreUploaded_t *pCallback, bool bIOFailiure) | ||
{ | ||
if (!pCallback->m_bSuccess || bIOFailiure) | ||
std::cerr << "Score could not be uploaded" << std::endl; | ||
} | ||
|
||
void | ||
CSteamLeaderboard::OnDownloadScores(LeaderboardScoresDownloaded_t *pCallback, bool bIOFailiure) | ||
{ | ||
if (!bIOFailiure) { | ||
m_nLeaderboardEntries = std::min(pCallback->m_cEntryCount, 10); | ||
for (int index = 0; index < m_nLeaderboardEntries; index++) { | ||
SteamUserStats()->GetDownloadedLeaderboardEntry( pCallback->m_hSteamLeaderboardEntries, | ||
index, | ||
&m_leaderboardEntries[index], | ||
NULL, | ||
0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <steam_api.h> | ||
|
||
class CSteamLeaderboard | ||
{ | ||
private: | ||
SteamLeaderboard_t m_hCurrentLeaderboard; | ||
LeaderboardEntry_t m_leaderboardEntries[10]; | ||
int m_nLeaderboardEntries = 0; | ||
|
||
public: | ||
CSteamLeaderboard(); | ||
|
||
void SetCurrent(SteamLeaderboard_t hCurrentLeaderboard); | ||
|
||
void FindLeaderboard(const char *pchLeaderboardName ); | ||
bool UploadScore(int score, const int *details, int nDetails); | ||
bool DownloadScores(); | ||
|
||
void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure); | ||
CCallResult<CSteamLeaderboard, LeaderboardFindResult_t> m_callResultFindLeaderboard; | ||
|
||
void OnUploadScore(LeaderboardScoreUploaded_t *pCallback, bool bIOFailiure); | ||
CCallResult<CSteamLeaderboard, LeaderboardScoreUploaded_t> m_callResultUploadScore; | ||
|
||
void OnDownloadScores(LeaderboardScoresDownloaded_t *pCallback, bool bIOFailiure); | ||
CCallResult<CSteamLeaderboard, LeaderboardScoresDownloaded_t> m_callResultDownloadScores; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters