2020-07-19 21:05:41 +02:00
|
|
|
#include <stdint.h>
|
2020-01-13 17:15:17 +01:00
|
|
|
|
2020-06-01 18:23:07 +02:00
|
|
|
#define UNUSED(expr) (void)(expr)
|
|
|
|
|
|
|
|
#ifdef STEAM_NETWORK
|
|
|
|
#define STEAM_NUM 1
|
|
|
|
#else
|
|
|
|
#define STEAM_NUM 0
|
|
|
|
#endif
|
|
|
|
#ifdef GOG_NETWORK
|
|
|
|
#define GOG_NUM 1
|
|
|
|
#else
|
|
|
|
#define GOG_NUM 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NUM_BACKENDS (STEAM_NUM+GOG_NUM)
|
2020-01-13 17:15:17 +01:00
|
|
|
#define DECLARE_BACKEND(name) \
|
2020-01-13 17:27:16 +01:00
|
|
|
extern int32_t name##_init(); \
|
2020-01-13 17:15:17 +01:00
|
|
|
extern void name##_shutdown(); \
|
|
|
|
extern void name##_update(); \
|
|
|
|
extern void name##_unlockAchievement(); \
|
2020-01-13 17:25:54 +01:00
|
|
|
extern int32_t name##_getAchievementProgress(const char *name); \
|
2020-01-13 17:15:17 +01:00
|
|
|
extern void name##_setAchievementProgress(const char *name, int32_t stat);
|
2020-06-01 18:23:07 +02:00
|
|
|
#ifdef STEAM_NETWORK
|
2020-01-13 17:15:17 +01:00
|
|
|
DECLARE_BACKEND(STEAM)
|
2020-06-01 18:23:07 +02:00
|
|
|
#endif
|
|
|
|
#ifdef GOG_NETWORK
|
2020-01-13 17:15:17 +01:00
|
|
|
DECLARE_BACKEND(GOG)
|
2020-06-01 18:23:07 +02:00
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
#undef DECLARE_BACKEND
|
|
|
|
|
|
|
|
typedef struct NetworkBackend
|
|
|
|
{
|
|
|
|
int32_t IsInit;
|
|
|
|
int32_t (*Init)();
|
|
|
|
void (*Shutdown)();
|
|
|
|
void (*Update)();
|
|
|
|
void (*UnlockAchievement)();
|
|
|
|
int32_t (*GetAchievementProgress)(const char*);
|
|
|
|
void (*SetAchievementProgress)(const char*, int32_t);
|
|
|
|
} NetworkBackend;
|
|
|
|
|
2020-06-01 18:23:07 +02:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 17:15:17 +01:00
|
|
|
static NetworkBackend backends[NUM_BACKENDS];
|
2020-06-01 18:23:07 +02:00
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
|
|
|
|
int NETWORK_init()
|
|
|
|
{
|
2020-06-01 18:23:07 +02:00
|
|
|
int32_t any = 0;
|
2020-01-13 17:15:17 +01:00
|
|
|
#define ASSIGN_BACKEND(name, index) \
|
|
|
|
backends[index].Init = name##_init; \
|
2020-01-13 17:25:54 +01:00
|
|
|
backends[index].Shutdown = name##_shutdown; \
|
|
|
|
backends[index].Update = name##_update; \
|
|
|
|
backends[index].UnlockAchievement = name##_unlockAchievement; \
|
|
|
|
backends[index].GetAchievementProgress = name##_getAchievementProgress; \
|
|
|
|
backends[index].SetAchievementProgress = name##_setAchievementProgress;
|
2020-06-01 18:23:07 +02:00
|
|
|
#ifdef STEAM_NETWORK
|
2020-01-13 17:15:17 +01:00
|
|
|
ASSIGN_BACKEND(STEAM, 0)
|
2020-06-01 18:23:07 +02:00
|
|
|
#endif
|
|
|
|
#ifdef GOG_NETWORK
|
|
|
|
ASSIGN_BACKEND(GOG, STEAM_NUM)
|
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
#undef ASSIGN_BACKEND
|
2020-06-01 18:23:07 +02:00
|
|
|
#if NUM_BACKENDS > 0
|
|
|
|
int32_t i;
|
2020-01-13 17:15:17 +01:00
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
{
|
|
|
|
backends[i].IsInit = backends[i].Init();
|
|
|
|
any |= backends[i].IsInit;
|
|
|
|
}
|
2020-06-01 18:23:07 +02:00
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
return any;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NETWORK_shutdown()
|
|
|
|
{
|
2020-06-01 18:23:07 +02:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 17:15:17 +01:00
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].Shutdown();
|
|
|
|
}
|
2020-06-01 18:23:07 +02:00
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NETWORK_update()
|
|
|
|
{
|
2020-06-01 18:23:07 +02:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 17:15:17 +01:00
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].Update();
|
|
|
|
}
|
2020-06-01 18:23:07 +02:00
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NETWORK_unlockAchievement(const char *name)
|
|
|
|
{
|
2020-06-01 18:23:07 +02:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 17:15:17 +01:00
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].UnlockAchievement(name);
|
|
|
|
}
|
2020-06-01 18:23:07 +02:00
|
|
|
#else
|
|
|
|
UNUSED(name);
|
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t NETWORK_getAchievementProgress(const char *name)
|
|
|
|
{
|
|
|
|
/* The highest stat gets priority, will eventually pass to the others */
|
2020-06-01 18:23:07 +02:00
|
|
|
int32_t max = 0;
|
|
|
|
#if NUM_BACKENDS > 0
|
|
|
|
int32_t i, stat;
|
2020-01-13 17:15:17 +01:00
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
stat = backends[i].GetAchievementProgress(name);
|
|
|
|
if (stat > max)
|
|
|
|
{
|
|
|
|
max = stat;
|
|
|
|
}
|
|
|
|
}
|
2020-06-01 18:23:07 +02:00
|
|
|
#else
|
|
|
|
UNUSED(name);
|
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NETWORK_setAchievementProgress(const char *name, int32_t stat)
|
|
|
|
{
|
2020-06-01 18:23:07 +02:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 17:15:17 +01:00
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].SetAchievementProgress(name, stat);
|
|
|
|
}
|
2020-06-01 18:23:07 +02:00
|
|
|
#else
|
|
|
|
UNUSED(name);
|
|
|
|
UNUSED(stat);
|
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
}
|