Subversion Repositories eduke32

Compare Revisions

Ignore whitespace Rev 8096 → Rev 8095

/source/voidwrap/src/voidwrap_steam.cpp
10,7 → 10,7
static uint64_t AppID;
 
 
static VW_VOID_CONSTCHARPTR Callback_PrintDebug;
static VW_CALLBACK_CHARPTR Callback_PrintDebug;
 
static void PrintDebug(const char * fmt, ...)
{
40,7 → 40,7
}
 
#ifdef VWDEBUG
VOIDWRAP_API void Voidwrap_Steam_SetCallback_PrintDebug(VW_VOID_CONSTCHARPTR function)
VOIDWRAP_API void Voidwrap_Steam_SetCallback_PrintDebug(VW_CALLBACK_CHARPTR function)
{
Callback_PrintDebug = function;
}
47,127 → 47,6
#endif
 
 
class SteamStatsAndAchievementsHandler
{
public:
SteamStatsAndAchievementsHandler()
: m_pSteamUserStats{SteamUserStats()}
{ }
 
void SetAchievement(char const * id);
void SetStat(char const * id, int32_t value);
 
STEAM_CALLBACK(SteamStatsAndAchievementsHandler, OnUserStatsReceived, UserStatsReceived_t);
STEAM_CALLBACK(SteamStatsAndAchievementsHandler, OnUserStatsStored, UserStatsStored_t);
 
void Process();
 
private:
ISteamUserStats * m_pSteamUserStats;
 
bool m_bRequestedStats{};
bool m_bStatsValid{};
 
bool m_bStoreStats{};
};
 
void SteamStatsAndAchievementsHandler::SetAchievement(char const * id)
{
if (nullptr == m_pSteamUserStats)
return;
 
m_pSteamUserStats->SetAchievement(id);
 
m_bStoreStats = true;
}
 
void SteamStatsAndAchievementsHandler::SetStat(char const * id, int32_t value)
{
if (nullptr == m_pSteamUserStats)
return;
 
m_pSteamUserStats->SetStat(id, value);
 
m_bStoreStats = true;
}
 
void SteamStatsAndAchievementsHandler::OnUserStatsReceived(UserStatsReceived_t * pCallback)
{
if (nullptr == m_pSteamUserStats)
return;
 
if (SteamID64 != pCallback->m_nGameID)
return;
 
if (k_EResultOK == pCallback->m_eResult)
{
m_bStatsValid = true;
}
else
{
PrintDebug("RequestStats - failed, %d\n", pCallback->m_eResult);
}
}
 
void SteamStatsAndAchievementsHandler::OnUserStatsStored(UserStatsStored_t * pCallback)
{
if (SteamID64 != pCallback->m_nGameID)
return;
 
if (k_EResultOK == pCallback->m_eResult)
{
}
else if (k_EResultInvalidParam == pCallback->m_eResult)
{
PrintDebug("StoreStats - some failed to validate\n");
}
else
{
PrintDebug("StoreStats - failed, %d\n", pCallback->m_eResult);
}
}
 
void SteamStatsAndAchievementsHandler::Process()
{
if (!m_bRequestedStats)
{
if (nullptr == m_pSteamUserStats)
{
m_bRequestedStats = true;
return;
}
 
m_bRequestedStats = m_pSteamUserStats->RequestCurrentStats();
}
 
if (!m_bStatsValid)
return;
 
if (!m_bStoreStats)
return;
 
m_bStoreStats = !m_pSteamUserStats->StoreStats();
}
 
static SteamStatsAndAchievementsHandler * StatsAndAchievementsHandler;
 
VOIDWRAP_API void Voidwrap_Steam_UnlockAchievement(char const * id)
{
if (nullptr == StatsAndAchievementsHandler)
return;
 
StatsAndAchievementsHandler->SetAchievement(id);
}
 
VOIDWRAP_API void Voidwrap_Steam_SetStat(char const * id, int32_t value)
{
if (nullptr == StatsAndAchievementsHandler)
return;
 
StatsAndAchievementsHandler->SetStat(id, value);
}
 
 
#ifdef VWSCREENSHOT
class SteamScreenshotHandler
{
177,16 → 56,16
};
 
static SteamScreenshotHandler * ScreenHandler;
static VW_VOID Callback_ScreenshotRequested;
// static VW_VOID_INT32 Callback_ScreenshotReady;
static VW_CALLBACK_NOPARAM Callback_ScreenshotRequested;
// static VW_CALLBACK_INT32 Callback_ScreenshotReady;
 
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotRequested(VW_VOID function)
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotRequested(VW_CALLBACK_NOPARAM function)
{
Callback_ScreenshotRequested = function;
}
 
#if 0
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotReady(VW_VOID_INT32 function)
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotReady(VW_CALLBACK_INT32 function)
{
Callback_ScreenshotReady = function;
}
257,8 → 136,6
if (SteamUtils()->IsOverlayEnabled()) { PrintDebug("Overlay is enabled."); }
#endif
 
StatsAndAchievementsHandler = new SteamStatsAndAchievementsHandler{};
 
#ifdef VWSCREENSHOT
SteamScreenshots()->HookScreenshots(true);
if (SteamScreenshots()->IsScreenshotsHooked()) { PrintDebug("Screenshots hooked."); }
282,7 → 159,5
 
VOIDWRAP_API void Voidwrap_Steam_RunCallbacks()
{
StatsAndAchievementsHandler->Process();
 
SteamAPI_RunCallbacks();
}