mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01:00
Add support for multiple Network backends, stub in GOGNetwork
This commit is contained in:
parent
8be05ca40f
commit
9758290cf3
5 changed files with 151 additions and 19 deletions
|
@ -91,7 +91,9 @@ SET(VVV_SRC
|
||||||
src/UtilityClass.cpp
|
src/UtilityClass.cpp
|
||||||
src/WarpClass.cpp
|
src/WarpClass.cpp
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
src/Network.c
|
||||||
src/SteamNetwork.c
|
src/SteamNetwork.c
|
||||||
|
src/GOGNetwork.c
|
||||||
)
|
)
|
||||||
SET(XML_SRC
|
SET(XML_SRC
|
||||||
../third_party/tinyxml/tinystr.cpp
|
../third_party/tinyxml/tinystr.cpp
|
||||||
|
|
29
desktop_version/src/GOGNetwork.c
Normal file
29
desktop_version/src/GOGNetwork.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* Totally unimplemented right now! */
|
||||||
|
|
||||||
|
int32_t GOG_init()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GOG_shutdown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GOG_update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GOG_unlockAchievement(const char *name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t GOG_getAchievementProgress(const char *name)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GOG_setAchievementProgress(const char *name, int32_t stat)
|
||||||
|
{
|
||||||
|
}
|
105
desktop_version/src/Network.c
Normal file
105
desktop_version/src/Network.c
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
#include "Network.h"
|
||||||
|
|
||||||
|
#define NUM_BACKENDS 2
|
||||||
|
#define DECLARE_BACKEND(name) \
|
||||||
|
extern int name##_init(); \
|
||||||
|
extern void name##_shutdown(); \
|
||||||
|
extern void name##_update(); \
|
||||||
|
extern void name##_unlockAchievement(); \
|
||||||
|
extern void name##_getAchievementProgress(const char *name); \
|
||||||
|
extern void name##_setAchievementProgress(const char *name, int32_t stat);
|
||||||
|
DECLARE_BACKEND(STEAM)
|
||||||
|
DECLARE_BACKEND(GOG)
|
||||||
|
#undef DECLARE_BACKEND
|
||||||
|
|
||||||
|
typedef intptr_t (*SteamInternal_CreateInterfaceFunc)(const char*);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
static NetworkBackend backends[NUM_BACKENDS];
|
||||||
|
|
||||||
|
int NETWORK_init()
|
||||||
|
{
|
||||||
|
int32_t i, any = 0;
|
||||||
|
#define ASSIGN_BACKEND(name, index) \
|
||||||
|
backends[index].Init = name##_init; \
|
||||||
|
backends[index].Init = name##_init; \
|
||||||
|
backends[index].Init = name##_init; \
|
||||||
|
backends[index].Init = name##_init; \
|
||||||
|
backends[index].Init = name##_init; \
|
||||||
|
backends[index].Init = name##_init;
|
||||||
|
ASSIGN_BACKEND(STEAM, 0)
|
||||||
|
ASSIGN_BACKEND(GOG, 1)
|
||||||
|
#undef ASSIGN_BACKEND
|
||||||
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
||||||
|
{
|
||||||
|
backends[i].IsInit = backends[i].Init();
|
||||||
|
any |= backends[i].IsInit;
|
||||||
|
}
|
||||||
|
return any;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NETWORK_shutdown()
|
||||||
|
{
|
||||||
|
int32_t i;
|
||||||
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
||||||
|
if (backends[i].IsInit)
|
||||||
|
{
|
||||||
|
backends[i].Shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NETWORK_update()
|
||||||
|
{
|
||||||
|
int32_t i;
|
||||||
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
||||||
|
if (backends[i].IsInit)
|
||||||
|
{
|
||||||
|
backends[i].Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NETWORK_unlockAchievement(const char *name)
|
||||||
|
{
|
||||||
|
int32_t i;
|
||||||
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
||||||
|
if (backends[i].IsInit)
|
||||||
|
{
|
||||||
|
backends[i].UnlockAchievement(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t NETWORK_getAchievementProgress(const char *name)
|
||||||
|
{
|
||||||
|
/* The highest stat gets priority, will eventually pass to the others */
|
||||||
|
int32_t i, stat, max = 0;
|
||||||
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
||||||
|
if (backends[i].IsInit)
|
||||||
|
{
|
||||||
|
stat = backends[i].GetAchievementProgress(name);
|
||||||
|
if (stat > max)
|
||||||
|
{
|
||||||
|
max = stat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NETWORK_setAchievementProgress(const char *name, int32_t stat)
|
||||||
|
{
|
||||||
|
int32_t i;
|
||||||
|
for (i = 0; i < NUM_BACKENDS; i += 1)
|
||||||
|
if (backends[i].IsInit)
|
||||||
|
{
|
||||||
|
backends[i].SetAchievementProgress(name, stat);
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int NETWORK_init();
|
int32_t NETWORK_init();
|
||||||
|
|
||||||
void NETWORK_shutdown();
|
void NETWORK_shutdown();
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ int32_t NETWORK_getAchievementProgress(const char *name);
|
||||||
|
|
||||||
void NETWORK_setAchievementProgress(const char *name, int32_t stat);
|
void NETWORK_setAchievementProgress(const char *name, int32_t stat);
|
||||||
|
|
||||||
/* TODO: Steam Workshop? */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#include "Network.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
@ -12,13 +10,13 @@
|
||||||
/* Shared object file name */
|
/* Shared object file name */
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define NETWORK_LIBRARY "steam_api.dll"
|
#define STEAM_LIBRARY "steam_api.dll"
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
#define NETWORK_LIBRARY "libsteam_api.dylib"
|
#define STEAM_LIBRARY "libsteam_api.dylib"
|
||||||
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
|
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||||
#define NETWORK_LIBRARY "libsteam_api.so"
|
#define STEAM_LIBRARY "libsteam_api.so"
|
||||||
#else
|
#else
|
||||||
#error NETWORK_LIBRARY: Unrecognized platform!
|
#error STEAM_LIBRARY: Unrecognized platform!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Function Pointer Types */
|
/* Function Pointer Types */
|
||||||
|
@ -95,18 +93,18 @@ static void ClearPointers()
|
||||||
|
|
||||||
/* NETWORK API Implementation */
|
/* NETWORK API Implementation */
|
||||||
|
|
||||||
int NETWORK_init()
|
int32_t STEAM_init()
|
||||||
{
|
{
|
||||||
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||||
return 1;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
intptr_t steamClient;
|
intptr_t steamClient;
|
||||||
int32_t steamUser, steamPipe;
|
int32_t steamUser, steamPipe;
|
||||||
|
|
||||||
libHandle = SDL_LoadObject(NETWORK_LIBRARY);
|
libHandle = SDL_LoadObject(STEAM_LIBRARY);
|
||||||
if (!libHandle)
|
if (!libHandle)
|
||||||
{
|
{
|
||||||
printf("%s not found!\n", NETWORK_LIBRARY);
|
printf("%s not found!\n", STEAM_LIBRARY);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +112,7 @@ int NETWORK_init()
|
||||||
name = (name##Func) SDL_LoadFunction(libHandle, #name); \
|
name = (name##Func) SDL_LoadFunction(libHandle, #name); \
|
||||||
if (!name) \
|
if (!name) \
|
||||||
{ \
|
{ \
|
||||||
printf("%s symbol %s not found!\n", NETWORK_LIBRARY, #name); \
|
printf("%s symbol %s not found!\n", STEAM_LIBRARY, #name); \
|
||||||
ClearPointers(); \
|
ClearPointers(); \
|
||||||
return 0; \
|
return 0; \
|
||||||
}
|
}
|
||||||
|
@ -165,7 +163,7 @@ int NETWORK_init()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NETWORK_shutdown()
|
void STEAM_shutdown()
|
||||||
{
|
{
|
||||||
if (libHandle)
|
if (libHandle)
|
||||||
{
|
{
|
||||||
|
@ -174,7 +172,7 @@ void NETWORK_shutdown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NETWORK_update()
|
void STEAM_update()
|
||||||
{
|
{
|
||||||
if (libHandle)
|
if (libHandle)
|
||||||
{
|
{
|
||||||
|
@ -182,7 +180,7 @@ void NETWORK_update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NETWORK_unlockAchievement(const char *name)
|
void STEAM_unlockAchievement(const char *name)
|
||||||
{
|
{
|
||||||
if (libHandle)
|
if (libHandle)
|
||||||
{
|
{
|
||||||
|
@ -194,7 +192,7 @@ void NETWORK_unlockAchievement(const char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t NETWORK_getAchievementProgress(const char *name)
|
int32_t STEAM_getAchievementProgress(const char *name)
|
||||||
{
|
{
|
||||||
int32_t result = -1;
|
int32_t result = -1;
|
||||||
if (libHandle)
|
if (libHandle)
|
||||||
|
@ -208,7 +206,7 @@ int32_t NETWORK_getAchievementProgress(const char *name)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NETWORK_setAchievementProgress(const char *name, int32_t stat)
|
void STEAM_setAchievementProgress(const char *name, int32_t stat)
|
||||||
{
|
{
|
||||||
if (libHandle)
|
if (libHandle)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue