SteamAPIのLeaderboardsでスコア以外の追加情報をアップロードする
UploadLeaderboardScoreのpScoreDetailsの使い方についてです。
pScoreDetailsはnScore以外の追加情報を設定できます。
例えば、スコアをアップロードした日付や、ゲーム内でのパラメータ(ランクやレベル)といった情報です。
関連ソースコードは以下です。
struct ScoreDetails {
int val1 = 60;
int val2 = 120;
int peakRank = 999;
int suvirvalDay = 200;
long long Score = 123456789123456;
};
bool CSteamLeaderboards::UploadScore(int score)
{
if (!m_CurrentLeaderboard)
return false;
const int32* pScoreDetails = (int32*) new ScoreDetails();
SteamAPICall_t hSteamAPICall =
SteamUserStats()->UploadLeaderboardScore(m_CurrentLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, score, pScoreDetails, 6);
m_callResultUploadScore.Set(hSteamAPICall, this, &CSteamLeaderboards::OnUploadScore);
return true;
}
void CSteamLeaderboards::OnUploadScore(LeaderboardScoreUploaded_t* pCallback, bool bIOFailure)
{
if (!pCallback->m_bSuccess || bIOFailure)
{
int aaa = 0;
aaa++;
}
}
bool CSteamLeaderboards::DownloadScores()
{
if (!m_CurrentLeaderboard)
return false;
// 現在のユーザー周辺の指定されたランキングデータを読み込む
SteamAPICall_t hSteamAPICall = SteamUserStats()->DownloadLeaderboardEntries(
m_CurrentLeaderboard, k_ELeaderboardDataRequestGlobalAroundUser, -4, 5);
m_callResultDownloadScore.Set(hSteamAPICall, this, &CSteamLeaderboards::OnDownloadScore);
return true;
}
void CSteamLeaderboards::OnDownloadScore(LeaderboardScoresDownloaded_t* pCallback, bool bIOFailure)
{
if (!bIOFailure)
{
m_nLeaderboardEntries = std::min(pCallback->m_cEntryCount, 10);
int32* pScoreDetails = (int32*) new ScoreDetails();
for (int index = 0; index < m_nLeaderboardEntries; index++)
{
SteamUserStats()->GetDownloadedLeaderboardEntry(
pCallback->m_hSteamLeaderboardEntries, index, &m_leaderboardEntries[index], pScoreDetails, 6);
}
ScoreDetails* ppp = (ScoreDetails*)pScoreDetails;
int aaa = 0;
aaa++;
}
}
UploadLeaderboardScoreの第4引数にconst int32*にキャストしたScoreDetailsを入力しています。
UploadLeaderboardScoreの第5引数はScoreDetails構造体のintの数です。
今回の例だと、intが4つ、longlongが1つなので、int6個分なので6としています。
あとは、OnDownloadScoreで同様に取得します。
受け取るための構造体(int32*)のメモリを確保して、GetDownloadedLeaderboardEntryの第3引数に入力しています。
あとは、int32をScoreDetailsにキャストしているだけです。
これでアップロードした時のScoreDetailsの情報を取得できます!