mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-24 21:15:12 +00:00
replace static linking with dynamically loaded libraries
This commit is contained in:
parent
f1ba90d25b
commit
5933742f82
8 changed files with 79 additions and 52 deletions
20
Makefile
20
Makefile
|
@ -457,12 +457,12 @@ GODDARD_O_FILES := $(foreach file,$(GODDARD_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
|
||||||
RPC_LIBS :=
|
RPC_LIBS :=
|
||||||
ifeq ($(DISCORDRPC),1)
|
ifeq ($(DISCORDRPC),1)
|
||||||
ifeq ($(WINDOWS_BUILD),1)
|
ifeq ($(WINDOWS_BUILD),1)
|
||||||
RPC_LIBS := src/pc/discord/libs/libdiscord-rpc-win.a
|
RPC_LIBS := src/pc/discord/lib/libdiscord-rpc.dll
|
||||||
else ifeq ($(OSX_BUILD),1)
|
else ifeq ($(OSX_BUILD),1)
|
||||||
# needs testing
|
# needs testing
|
||||||
RPC_LIBS := src/pc/discord/libs/libdiscord-rpc-osx.a
|
RPC_LIBS := src/pc/discord/lib/libdiscord-rpc.dylib
|
||||||
else
|
else
|
||||||
RPC_LIBS := src/pc/discord/libs/libdiscord-rpc-unix.a
|
RPC_LIBS := src/pc/discord/lib/libdiscord-rpc.so
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -620,6 +620,9 @@ ifeq ($(OSX_BUILD),1)
|
||||||
LDFLAGS := -lm -framework OpenGL `$(SDLCONFIG) --libs` -no-pie -lpthread `pkg-config --libs libusb-1.0 glfw3 glew`
|
LDFLAGS := -lm -framework OpenGL `$(SDLCONFIG) --libs` -no-pie -lpthread `pkg-config --libs libusb-1.0 glfw3 glew`
|
||||||
else
|
else
|
||||||
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm -lGL `$(SDLCONFIG) --libs` -no-pie -lpthread
|
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm -lGL `$(SDLCONFIG) --libs` -no-pie -lpthread
|
||||||
|
ifeq ($(DISCORDRPC),1)
|
||||||
|
LDFLAGS += -ldl -Wl,-rpath .
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif # End of LDFLAGS
|
endif # End of LDFLAGS
|
||||||
|
|
||||||
|
@ -655,8 +658,6 @@ ZEROTERM = $(PYTHON) $(TOOLS_DIR)/zeroterm.py
|
||||||
|
|
||||||
all: $(EXE)
|
all: $(EXE)
|
||||||
|
|
||||||
ifeq ($(EXTERNAL_DATA),1)
|
|
||||||
|
|
||||||
# thank you apple very cool
|
# thank you apple very cool
|
||||||
ifeq ($(HOST_OS),Darwin)
|
ifeq ($(HOST_OS),Darwin)
|
||||||
CP := gcp
|
CP := gcp
|
||||||
|
@ -664,6 +665,8 @@ else
|
||||||
CP := cp
|
CP := cp
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(EXTERNAL_DATA),1)
|
||||||
|
|
||||||
# depend on resources as well
|
# depend on resources as well
|
||||||
all: res
|
all: res
|
||||||
|
|
||||||
|
@ -697,6 +700,9 @@ test: $(ROM)
|
||||||
load: $(ROM)
|
load: $(ROM)
|
||||||
$(LOADER) $(LOADER_FLAGS) $<
|
$(LOADER) $(LOADER_FLAGS) $<
|
||||||
|
|
||||||
|
$(BUILD_DIR)/$(RPC_LIBS):
|
||||||
|
@$(CP) -f $(RPC_LIBS) $(BUILD_DIR)
|
||||||
|
|
||||||
libultra: $(BUILD_DIR)/libultra.a
|
libultra: $(BUILD_DIR)/libultra.a
|
||||||
|
|
||||||
asm/boot.s: $(BUILD_DIR)/lib/bin/ipl3_font.bin
|
asm/boot.s: $(BUILD_DIR)/lib/bin/ipl3_font.bin
|
||||||
|
@ -956,8 +962,8 @@ $(BUILD_DIR)/%.o: %.s
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(EXE): $(O_FILES) $(MIO0_FILES:.mio0=.o) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(RPC_LIBS)
|
$(EXE): $(O_FILES) $(MIO0_FILES:.mio0=.o) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(BUILD_DIR)/$(RPC_LIBS)
|
||||||
$(LD) -L $(BUILD_DIR) -o $@ $(O_FILES) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(RPC_LIBS) $(LDFLAGS)
|
$(LD) -L $(BUILD_DIR) -o $@ $(O_FILES) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(LDFLAGS)
|
||||||
|
|
||||||
.PHONY: all clean distclean default diff test load libultra res
|
.PHONY: all clean distclean default diff test load libultra res
|
||||||
.PRECIOUS: $(BUILD_DIR)/bin/%.elf $(SOUND_BIN_DIR)/%.ctl $(SOUND_BIN_DIR)/%.tbl $(SOUND_SAMPLE_TABLES) $(SOUND_BIN_DIR)/%.s $(BUILD_DIR)/%
|
.PRECIOUS: $(BUILD_DIR)/bin/%.elf $(SOUND_BIN_DIR)/%.ctl $(SOUND_BIN_DIR)/%.tbl $(SOUND_SAMPLE_TABLES) $(SOUND_BIN_DIR)/%.s $(BUILD_DIR)/%
|
||||||
|
|
|
@ -23,6 +23,10 @@
|
||||||
|
|
||||||
#include "gfx_dimensions.h"
|
#include "gfx_dimensions.h"
|
||||||
|
|
||||||
|
#ifdef DISCORDRPC
|
||||||
|
#include "pc/discord/discordrpc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
struct SpawnInfo gPlayerSpawnInfos[1];
|
struct SpawnInfo gPlayerSpawnInfos[1];
|
||||||
struct GraphNode *D_8033A160[0x100];
|
struct GraphNode *D_8033A160[0x100];
|
||||||
struct Area gAreaData[8];
|
struct Area gAreaData[8];
|
||||||
|
|
|
@ -7,12 +7,42 @@
|
||||||
#include "pc/configfile.h"
|
#include "pc/configfile.h"
|
||||||
#include "discordrpc.h"
|
#include "discordrpc.h"
|
||||||
|
|
||||||
|
#define DISCORDLIBFILE "libdiscord-rpc"
|
||||||
|
|
||||||
|
// Thanks Microsoft for being non posix compliant
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#define DISCORDLIBEXT ".dll"
|
||||||
|
#define itoa(int, str) itoa(int, str, "10")
|
||||||
|
#define dlopen(lib, flag) LoadLibrary(TEXT(lib))
|
||||||
|
#define dlerror() ""
|
||||||
|
#define dlsym(handle, func) GetProcAddress(handle, func)
|
||||||
|
#define dlclose(handle) FreeLibrary(handle)
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#define DISCORDLIBEXT ".dylib"
|
||||||
|
#elif defined(__linux__) || defined(__FreeBSD__) // lets make the bold assumption for FreeBSD
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#define DISCORDLIBEXT ".so"
|
||||||
|
#else
|
||||||
|
#error Unknown System
|
||||||
|
#endif
|
||||||
|
#define DISCORDLIB DISCORDLIBFILE DISCORDLIBEXT
|
||||||
|
|
||||||
#define DISCORD_APP_ID "709083908708237342"
|
#define DISCORD_APP_ID "709083908708237342"
|
||||||
#define DISCORD_UPDATE_RATE 5
|
#define DISCORD_UPDATE_RATE 5
|
||||||
|
|
||||||
time_t lastUpdatedTime;
|
time_t lastUpdatedTime;
|
||||||
|
|
||||||
DiscordRichPresence discordRichPresence;
|
DiscordRichPresence discordRichPresence;
|
||||||
|
bool initd = false;
|
||||||
|
|
||||||
|
void* handle;
|
||||||
|
|
||||||
|
void (*Discord_Initialize)(const char*, DiscordEventHandlers*, int, const char*);
|
||||||
|
void (*Discord_Shutdown)(void);
|
||||||
|
void (*Discord_ClearPresence)(void);
|
||||||
|
void (*Discord_UpdatePresence)(DiscordEventHandlers*);
|
||||||
|
|
||||||
extern s16 gCurrCourseNum;
|
extern s16 gCurrCourseNum;
|
||||||
extern s16 gCurrActNum;
|
extern s16 gCurrActNum;
|
||||||
|
@ -91,7 +121,7 @@ void convertstring(const u8 *str, char* output)
|
||||||
switch (output[strPos]) // decide if the next character should be capitalized
|
switch (output[strPos]) // decide if the next character should be capitalized
|
||||||
{
|
{
|
||||||
case ' ':
|
case ' ':
|
||||||
if (str[strPos] != 158) printf(stdout, "Unknown Character (%i)\n", str[strPos]); // inform that an unknown char was found
|
if (str[strPos] != 158) fprintf(stdout, "Unknown Character (%i)\n", str[strPos]); // inform that an unknown char was found
|
||||||
case '-':
|
case '-':
|
||||||
capitalizeChar = true;
|
capitalizeChar = true;
|
||||||
break;
|
break;
|
||||||
|
@ -106,6 +136,7 @@ void convertstring(const u8 *str, char* output)
|
||||||
output[strPos] = '\0';
|
output[strPos] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
void reverse(char s[])
|
void reverse(char s[])
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
@ -132,6 +163,7 @@ void itoa(int n, char s[])
|
||||||
s[i] = '\0';
|
s[i] = '\0';
|
||||||
reverse(s);
|
reverse(s);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void OnReady( const DiscordUser* user )
|
void OnReady( const DiscordUser* user )
|
||||||
{
|
{
|
||||||
|
@ -144,7 +176,9 @@ void InitializeDiscord()
|
||||||
memset(&handlers, 0, sizeof(handlers));
|
memset(&handlers, 0, sizeof(handlers));
|
||||||
handlers.ready = OnReady;
|
handlers.ready = OnReady;
|
||||||
|
|
||||||
Discord_Initialize( DISCORD_APP_ID, &handlers, false, "" );
|
(*Discord_Initialize)(DISCORD_APP_ID, &handlers, false, "");
|
||||||
|
|
||||||
|
initd = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDetails()
|
void SetDetails()
|
||||||
|
@ -247,7 +281,7 @@ void SetLogo()
|
||||||
|
|
||||||
void discordUpdateRichPresence()
|
void discordUpdateRichPresence()
|
||||||
{
|
{
|
||||||
if (!configDiscordRPC) return;
|
if (!configDiscordRPC || !initd) return;
|
||||||
if (time(NULL) < lastUpdatedTime + DISCORD_UPDATE_RATE) return;
|
if (time(NULL) < lastUpdatedTime + DISCORD_UPDATE_RATE) return;
|
||||||
|
|
||||||
lastUpdatedTime = time(NULL);
|
lastUpdatedTime = time(NULL);
|
||||||
|
@ -260,13 +294,31 @@ void discordUpdateRichPresence()
|
||||||
|
|
||||||
void discordShutdown()
|
void discordShutdown()
|
||||||
{
|
{
|
||||||
Discord_Shutdown();
|
if (handle)
|
||||||
|
{
|
||||||
|
(*Discord_ClearPresence)();
|
||||||
|
(*Discord_Shutdown)();
|
||||||
|
|
||||||
|
dlclose(handle);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void discordInit()
|
void discordInit()
|
||||||
{
|
{
|
||||||
if (configDiscordRPC)
|
if (configDiscordRPC)
|
||||||
{
|
{
|
||||||
|
handle = dlopen(DISCORDLIB, RTLD_LAZY);
|
||||||
|
if (!handle) {
|
||||||
|
fprintf(stderr, "Unable to load Discord\n%s\n", dlerror());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Discord_Initialize = dlsym(handle, "Discord_Initialize");
|
||||||
|
Discord_Shutdown = dlsym(handle, "Discord_Shutdown");
|
||||||
|
Discord_ClearPresence = dlsym(handle, "Discord_ClearPresence");
|
||||||
|
Discord_UpdatePresence = dlsym(handle, "Discord_UpdatePresence");
|
||||||
|
|
||||||
InitializeDiscord();
|
InitializeDiscord();
|
||||||
|
|
||||||
discordRichPresence.details = stage;
|
discordRichPresence.details = stage;
|
||||||
|
@ -284,6 +336,6 @@ void discordReset()
|
||||||
SetState();
|
SetState();
|
||||||
SetDetails();
|
SetDetails();
|
||||||
SetLogo();
|
SetLogo();
|
||||||
Discord_UpdatePresence( &discordRichPresence );
|
(*Discord_UpdatePresence)(&discordRichPresence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,24 +3,6 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
|
|
||||||
#if defined(DISCORD_DYNAMIC_LIB)
|
|
||||||
# if defined(_WIN32)
|
|
||||||
# if defined(DISCORD_BUILDING_SDK)
|
|
||||||
# define DISCORD_EXPORT __declspec(dllexport)
|
|
||||||
# else
|
|
||||||
# define DISCORD_EXPORT __declspec(dllimport)
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# define DISCORD_EXPORT __attribute__((visibility("default")))
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# define DISCORD_EXPORT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
typedef struct DiscordRichPresence {
|
typedef struct DiscordRichPresence {
|
||||||
const char* state; /* max 128 bytes */
|
const char* state; /* max 128 bytes */
|
||||||
const char* details; /* max 128 bytes */
|
const char* details; /* max 128 bytes */
|
||||||
|
@ -59,27 +41,6 @@ typedef struct DiscordEventHandlers {
|
||||||
#define DISCORD_REPLY_YES 1
|
#define DISCORD_REPLY_YES 1
|
||||||
#define DISCORD_REPLY_IGNORE 2
|
#define DISCORD_REPLY_IGNORE 2
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
|
||||||
DiscordEventHandlers* handlers,
|
|
||||||
int autoRegister,
|
|
||||||
const char* optionalSteamId);
|
|
||||||
DISCORD_EXPORT void Discord_Shutdown(void);
|
|
||||||
|
|
||||||
/* checks for incoming messages, dispatches callbacks */
|
|
||||||
DISCORD_EXPORT void Discord_RunCallbacks(void);
|
|
||||||
|
|
||||||
/* If you disable the lib starting its own io thread, you'll need to call this from your own */
|
|
||||||
#ifdef DISCORD_DISABLE_IO_THREAD
|
|
||||||
DISCORD_EXPORT void Discord_UpdateConnection(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence);
|
|
||||||
DISCORD_EXPORT void Discord_ClearPresence(void);
|
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);
|
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers);
|
|
||||||
|
|
||||||
void discordUpdateRichPresence();
|
void discordUpdateRichPresence();
|
||||||
void discordShutdown();
|
void discordShutdown();
|
||||||
void discordInit();
|
void discordInit();
|
||||||
|
|
BIN
src/pc/discord/lib/libdiscord-rpc.dll
Normal file
BIN
src/pc/discord/lib/libdiscord-rpc.dll
Normal file
Binary file not shown.
BIN
src/pc/discord/lib/libdiscord-rpc.dylib
Executable file
BIN
src/pc/discord/lib/libdiscord-rpc.dylib
Executable file
Binary file not shown.
BIN
src/pc/discord/lib/libdiscord-rpc.so
Normal file
BIN
src/pc/discord/lib/libdiscord-rpc.so
Normal file
Binary file not shown.
|
@ -32,6 +32,10 @@
|
||||||
|
|
||||||
#include "src/pc/controller/controller_keyboard.h"
|
#include "src/pc/controller/controller_keyboard.h"
|
||||||
|
|
||||||
|
#ifdef DISCORDRPC
|
||||||
|
#include "pc/discord/discordrpc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: figure out if this shit even works
|
// TODO: figure out if this shit even works
|
||||||
#ifdef VERSION_EU
|
#ifdef VERSION_EU
|
||||||
# define FRAMERATE 25
|
# define FRAMERATE 25
|
||||||
|
|
Loading…
Reference in a new issue