The beginning of an idea for a global leaderboard view

This commit is contained in:
Linus Probert 2018-09-03 20:21:54 +02:00
parent cb60a035dd
commit a19a13e054
6 changed files with 118 additions and 2 deletions

View File

@ -1,4 +1,6 @@
-DDEBUG
-DSTEAM_BUILD
-include ./steamworks_c_api/sdk/public/steam/steam_api.h
-I./steamworks_c_api/src/
-I./src/steam/
-I./build/config.h

3
.vimrc
View File

@ -5,4 +5,5 @@ nnoremap <F4> :ter ++close ./_build/breakhack<cr>
packadd termdebug
let g:termdebug_wide = 1
let g:syntastic_c_include_dirs = [ '_build', '/usr/include/SDL2', 'steamworks_c_wrapper/src', 'steamworks_c_wrapper/sdk/public/steam' ]
let g:syntastic_c_include_dirs = [ '_build', '/usr/include/SDL2', 'steamworks_c_wrapper/src' ]
let g:syntastic_cpp_include_dirs = [ 'steamworks_c_wrapper/sdk/public/steam' ]

View File

@ -35,6 +35,7 @@ else ()
SHARED
src/steamworks_c_wrapper
src/CallbackHandler
src/CSteamLeaderboard
)
endif()

View File

@ -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);
}
}
}

View File

@ -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;
};