2020-07-19 12:05:41 -07:00
|
|
|
#include <stdint.h>
|
2020-01-13 11:15:17 -05:00
|
|
|
|
2020-08-02 20:35:00 -07:00
|
|
|
#include "MakeAndPlay.h"
|
2021-05-20 14:12:51 -07:00
|
|
|
#include "Unused.h"
|
2020-06-01 09:23:07 -07:00
|
|
|
|
2020-08-02 20:35:00 -07:00
|
|
|
#ifdef MAKEANDPLAY
|
|
|
|
#ifdef STEAM_NETWORK
|
|
|
|
#undef STEAM_NETWORK
|
|
|
|
#endif
|
|
|
|
#ifdef GOG_NETWORK
|
|
|
|
#undef GOG_NETWORK
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-06-01 09:23:07 -07:00
|
|
|
#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 11:15:17 -05:00
|
|
|
#define DECLARE_BACKEND(name) \
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
int32_t name##_init(void); \
|
|
|
|
void name##_shutdown(void); \
|
|
|
|
void name##_update(void); \
|
|
|
|
void name##_unlockAchievement(const char *name); \
|
2020-08-02 20:38:16 -07:00
|
|
|
int32_t name##_getAchievementProgress(const char *name); \
|
|
|
|
void name##_setAchievementProgress(const char *name, int32_t stat);
|
2020-06-01 09:23:07 -07:00
|
|
|
#ifdef STEAM_NETWORK
|
2020-01-13 11:15:17 -05:00
|
|
|
DECLARE_BACKEND(STEAM)
|
2020-06-01 09:23:07 -07:00
|
|
|
#endif
|
|
|
|
#ifdef GOG_NETWORK
|
2020-01-13 11:15:17 -05:00
|
|
|
DECLARE_BACKEND(GOG)
|
2020-06-01 09:23:07 -07:00
|
|
|
#endif
|
2020-01-13 11:15:17 -05:00
|
|
|
#undef DECLARE_BACKEND
|
|
|
|
|
|
|
|
typedef struct NetworkBackend
|
|
|
|
{
|
|
|
|
int32_t IsInit;
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
int32_t (*Init)(void);
|
|
|
|
void (*Shutdown)(void);
|
|
|
|
void (*Update)(void);
|
|
|
|
void (*UnlockAchievement)(const char*);
|
2020-01-13 11:15:17 -05:00
|
|
|
int32_t (*GetAchievementProgress)(const char*);
|
|
|
|
void (*SetAchievementProgress)(const char*, int32_t);
|
|
|
|
} NetworkBackend;
|
|
|
|
|
2020-06-01 09:23:07 -07:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 11:15:17 -05:00
|
|
|
static NetworkBackend backends[NUM_BACKENDS];
|
2020-06-01 09:23:07 -07:00
|
|
|
#endif
|
2020-01-13 11:15:17 -05:00
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
int NETWORK_init(void)
|
2020-01-13 11:15:17 -05:00
|
|
|
{
|
2020-06-01 09:23:07 -07:00
|
|
|
int32_t any = 0;
|
2020-01-13 11:15:17 -05:00
|
|
|
#define ASSIGN_BACKEND(name, index) \
|
|
|
|
backends[index].Init = name##_init; \
|
2020-01-13 11:25:54 -05: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 09:23:07 -07:00
|
|
|
#ifdef STEAM_NETWORK
|
2020-01-13 11:15:17 -05:00
|
|
|
ASSIGN_BACKEND(STEAM, 0)
|
2020-06-01 09:23:07 -07:00
|
|
|
#endif
|
|
|
|
#ifdef GOG_NETWORK
|
|
|
|
ASSIGN_BACKEND(GOG, STEAM_NUM)
|
|
|
|
#endif
|
2020-01-13 11:15:17 -05:00
|
|
|
#undef ASSIGN_BACKEND
|
2020-06-01 09:23:07 -07:00
|
|
|
#if NUM_BACKENDS > 0
|
|
|
|
int32_t i;
|
2020-01-13 11:15:17 -05:00
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
{
|
|
|
|
backends[i].IsInit = backends[i].Init();
|
|
|
|
any |= backends[i].IsInit;
|
|
|
|
}
|
2020-06-01 09:23:07 -07:00
|
|
|
#endif
|
2020-01-13 11:15:17 -05:00
|
|
|
return any;
|
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
void NETWORK_shutdown(void)
|
2020-01-13 11:15:17 -05:00
|
|
|
{
|
2020-06-01 09:23:07 -07:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 11:15:17 -05:00
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].Shutdown();
|
|
|
|
}
|
2020-06-01 09:23:07 -07:00
|
|
|
#endif
|
2020-01-13 11:15:17 -05:00
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
void NETWORK_update(void)
|
2020-01-13 11:15:17 -05:00
|
|
|
{
|
2020-06-01 09:23:07 -07:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 11:15:17 -05:00
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].Update();
|
|
|
|
}
|
2020-06-01 09:23:07 -07:00
|
|
|
#endif
|
2020-01-13 11:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void NETWORK_unlockAchievement(const char *name)
|
|
|
|
{
|
2020-06-01 09:23:07 -07:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 11:15:17 -05:00
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].UnlockAchievement(name);
|
|
|
|
}
|
2020-06-01 09:23:07 -07:00
|
|
|
#else
|
|
|
|
UNUSED(name);
|
|
|
|
#endif
|
2020-01-13 11:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t NETWORK_getAchievementProgress(const char *name)
|
|
|
|
{
|
|
|
|
/* The highest stat gets priority, will eventually pass to the others */
|
2020-06-01 09:23:07 -07:00
|
|
|
int32_t max = 0;
|
|
|
|
#if NUM_BACKENDS > 0
|
|
|
|
int32_t i, stat;
|
2020-01-13 11:15:17 -05: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 09:23:07 -07:00
|
|
|
#else
|
|
|
|
UNUSED(name);
|
|
|
|
#endif
|
2020-01-13 11:15:17 -05:00
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NETWORK_setAchievementProgress(const char *name, int32_t stat)
|
|
|
|
{
|
2020-06-01 09:23:07 -07:00
|
|
|
#if NUM_BACKENDS > 0
|
2020-01-13 11:15:17 -05:00
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].SetAchievementProgress(name, stat);
|
|
|
|
}
|
2020-06-01 09:23:07 -07:00
|
|
|
#else
|
|
|
|
UNUSED(name);
|
|
|
|
UNUSED(stat);
|
|
|
|
#endif
|
2020-01-13 11:15:17 -05:00
|
|
|
}
|