Subversion Repositories eduke32

Compare Revisions

Ignore whitespace Rev 8095 → Rev 8096

/source/voidwrap/include/voidwrap.h
24,22 → 24,20
 
// #define VWDEBUG
 
// Callback types
typedef void (*VW_CALLBACK_NOPARAM)(void);
typedef void (*VW_CALLBACK_INT32)(int32_t);
typedef void (*VW_CALLBACK_CHARPTR)(char const *);
 
// Callback setup function types
typedef void (*VW_SETCALLBACK_NOPARAM)(VW_CALLBACK_NOPARAM);
typedef void (*VW_SETCALLBACK_INT32)(VW_CALLBACK_INT32);
typedef void (*VW_SETCALLBACK_CHARPTR)(VW_CALLBACK_CHARPTR);
 
// Function types
typedef void (*VW_VOID)(void);
typedef void (*VW_VOID_INT32)(int32_t);
typedef void (*VW_VOID_CONSTCHARPTR)(char const *);
typedef void (*VW_VOID_CONSTCHARPTR_INT32)(char const *, int32_t);
typedef bool (*VW_BOOL)(void);
#ifdef VWSCREENSHOT
typedef bool (*VW_BOOL_SCREENSHOT)(char * filepath, int32_t width, int32_t height);
#endif
typedef void (*VW_VOID)(void);
typedef int32_t (*VW_INT32)(void);
 
// Callback setup function types
typedef void (*VW_SETCALLBACK_VOID)(VW_VOID);
typedef void (*VW_SETCALLBACK_VOID_INT32)(VW_VOID_INT32);
typedef void (*VW_SETCALLBACK_VOID_CONSTCHARPTR)(VW_VOID_CONSTCHARPTR);
 
#endif
/source/voidwrap/include/voidwrap_steam.h
13,15 → 13,18
VOIDWRAP_API void Voidwrap_Steam_Shutdown(void);
VOIDWRAP_API void Voidwrap_Steam_RunCallbacks(void);
 
VOIDWRAP_API void Voidwrap_Steam_UnlockAchievement(char const * id);
VOIDWRAP_API void Voidwrap_Steam_SetStat(char const * id, int32_t value);
 
#ifdef VWDEBUG
VOIDWRAP_API void Voidwrap_Steam_SetCallback_PrintDebug(VW_CALLBACK_CHARPTR function);
VOIDWRAP_API void Voidwrap_Steam_SetCallback_PrintDebug(VW_VOID_CONSTCHARPTR function);
#endif
 
#ifdef VWSCREENSHOT
VOIDWRAP_API bool Voidwrap_Steam_SendScreenshot(char * filepath, int32_t width, int32_t height);
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotRequested(VW_CALLBACK_NOPARAM function);
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotRequested(VW_VOID function);
#if 0
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotReady(VW_CALLBACK_INT32 function);
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotReady(VW_VOID_INT32 function);
#endif
#endif
 
39,15 → 42,18
static VW_VOID Voidwrap_Steam_Shutdown;
static VW_VOID Voidwrap_Steam_RunCallbacks;
 
static VW_VOID_CONSTCHARPTR Voidwrap_Steam_UnlockAchievement;
static VW_VOID_CONSTCHARPTR_INT32 Voidwrap_Steam_SetStat;
 
#ifdef VWDEBUG
static VW_SETCALLBACK_CHARPTR Voidwrap_Steam_SetCallback_PrintDebug;
static VW_SETCALLBACK_VOID_CONSTCHARPTR Voidwrap_Steam_SetCallback_PrintDebug;
#endif
 
#ifdef VWSCREENSHOT
static VW_BOOL_SCREENSHOT Voidwrap_Steam_SendScreenshot;
static VW_SETCALLBACK_NOPARAM Voidwrap_Steam_SetCallback_ScreenshotRequested;
static VW_SETCALLBACK_VOID Voidwrap_Steam_SetCallback_ScreenshotRequested;
#if 0
static VW_SETCALLBACK_INT32 Voidwrap_Steam_SetCallback_ScreenshotReady;
static VW_SETCALLBACK_VOID_INT32 Voidwrap_Steam_SetCallback_ScreenshotReady;
#endif
#endif
 
/source/voidwrap/src/voidwrap_steam.cpp
10,7 → 10,7
static uint64_t AppID;
 
 
static VW_CALLBACK_CHARPTR Callback_PrintDebug;
static VW_VOID_CONSTCHARPTR Callback_PrintDebug;
 
static void PrintDebug(const char * fmt, ...)
{
40,7 → 40,7
}
 
#ifdef VWDEBUG
VOIDWRAP_API void Voidwrap_Steam_SetCallback_PrintDebug(VW_CALLBACK_CHARPTR function)
VOIDWRAP_API void Voidwrap_Steam_SetCallback_PrintDebug(VW_VOID_CONSTCHARPTR function)
{
Callback_PrintDebug = function;
}
47,6 → 47,127
#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
{
56,16 → 177,16
};
 
static SteamScreenshotHandler * ScreenHandler;
static VW_CALLBACK_NOPARAM Callback_ScreenshotRequested;
// static VW_CALLBACK_INT32 Callback_ScreenshotReady;
static VW_VOID Callback_ScreenshotRequested;
// static VW_VOID_INT32 Callback_ScreenshotReady;
 
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotRequested(VW_CALLBACK_NOPARAM function)
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotRequested(VW_VOID function)
{
Callback_ScreenshotRequested = function;
}
 
#if 0
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotReady(VW_CALLBACK_INT32 function)
VOIDWRAP_API void Voidwrap_Steam_SetCallback_ScreenshotReady(VW_VOID_INT32 function)
{
Callback_ScreenshotReady = function;
}
136,6 → 257,8
if (SteamUtils()->IsOverlayEnabled()) { PrintDebug("Overlay is enabled."); }
#endif
 
StatsAndAchievementsHandler = new SteamStatsAndAchievementsHandler{};
 
#ifdef VWSCREENSHOT
SteamScreenshots()->HookScreenshots(true);
if (SteamScreenshots()->IsScreenshotsHooked()) { PrintDebug("Screenshots hooked."); }
159,5 → 282,7
 
VOIDWRAP_API void Voidwrap_Steam_RunCallbacks()
{
StatsAndAchievementsHandler->Process();
 
SteamAPI_RunCallbacks();
}