2020-07-19 21:05:41 +02:00
|
|
|
#include <stdint.h>
|
2020-01-13 17:15:17 +01:00
|
|
|
|
2020-08-03 05:35:00 +02:00
|
|
|
#include "MakeAndPlay.h"
|
2021-05-20 23:12:51 +02:00
|
|
|
#include "Unused.h"
|
2020-06-01 18:23:07 +02:00
|
|
|
|
2020-08-03 05:35:00 +02:00
|
|
|
#ifdef MAKEANDPLAY
|
2021-09-07 03:56:39 +02:00
|
|
|
#ifdef STEAM_NETWORK
|
|
|
|
#undef STEAM_NETWORK
|
|
|
|
#endif
|
|
|
|
#ifdef GOG_NETWORK
|
|
|
|
#undef GOG_NETWORK
|
|
|
|
#endif
|
2020-08-03 05:35:00 +02:00
|
|
|
#endif
|
|
|
|
|
2020-06-01 18:23:07 +02: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 17:15:17 +01:00
|
|
|
#define DECLARE_BACKEND(name) \
|
2021-09-07 03:56:39 +02:00
|
|
|
int32_t name##_init(void); \
|
|
|
|
void name##_shutdown(void); \
|
|
|
|
void name##_update(void); \
|
2021-09-20 06:49:54 +02:00
|
|
|
void name##_unlockAchievement(const char *name);
|
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
|
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
int32_t IsInit;
|
|
|
|
int32_t (*Init)(void);
|
|
|
|
void (*Shutdown)(void);
|
|
|
|
void (*Update)(void);
|
|
|
|
void (*UnlockAchievement)(const char*);
|
2020-01-13 17:15:17 +01:00
|
|
|
} 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
|
|
|
|
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 23:23:59 +01:00
|
|
|
int NETWORK_init(void)
|
2020-01-13 17:15:17 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
int32_t i, any = 0;
|
|
|
|
#define ASSIGN_BACKEND(name, index) \
|
|
|
|
backends[index].Init = name##_init; \
|
|
|
|
backends[index].Shutdown = name##_shutdown; \
|
|
|
|
backends[index].Update = name##_update; \
|
2021-09-20 06:49:54 +02:00
|
|
|
backends[index].UnlockAchievement = name##_unlockAchievement;
|
2021-09-07 03:56:39 +02:00
|
|
|
#ifdef STEAM_NETWORK
|
|
|
|
ASSIGN_BACKEND(STEAM, 0)
|
|
|
|
#endif
|
|
|
|
#ifdef GOG_NETWORK
|
|
|
|
ASSIGN_BACKEND(GOG, STEAM_NUM)
|
|
|
|
#endif
|
|
|
|
#undef ASSIGN_BACKEND
|
|
|
|
#if NUM_BACKENDS > 0
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
{
|
|
|
|
backends[i].IsInit = backends[i].Init();
|
|
|
|
any |= backends[i].IsInit;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
UNUSED(i);
|
|
|
|
#endif
|
|
|
|
return any;
|
2020-01-13 17:15:17 +01: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 23:23:59 +01:00
|
|
|
void NETWORK_shutdown(void)
|
2020-01-13 17:15:17 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
#if NUM_BACKENDS > 0
|
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].Shutdown();
|
|
|
|
}
|
|
|
|
#endif
|
2020-01-13 17:15:17 +01: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 23:23:59 +01:00
|
|
|
void NETWORK_update(void)
|
2020-01-13 17:15:17 +01:00
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
#if NUM_BACKENDS > 0
|
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].Update();
|
|
|
|
}
|
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NETWORK_unlockAchievement(const char *name)
|
|
|
|
{
|
2021-09-07 03:56:39 +02:00
|
|
|
#if NUM_BACKENDS > 0
|
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
|
|
|
if (backends[i].IsInit)
|
|
|
|
{
|
|
|
|
backends[i].UnlockAchievement(name);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
UNUSED(name);
|
|
|
|
#endif
|
2020-01-13 17:15:17 +01:00
|
|
|
}
|