Wii/Gamecube: Support being able to go in-game from the launcher

Also fix being unable to start singleplayer/multiplayer. Also work more on BeOS support
This commit is contained in:
UnknownShadow200 2023-07-01 22:14:27 +10:00
parent 2caa47452e
commit bfc5fd4be8
6 changed files with 145 additions and 75 deletions

View File

@ -53,7 +53,7 @@ LDFLAGS=-rdynamic -framework Carbon -framework AGL -framework OpenGL -framework
endif
ifeq ($(PLAT),mac_x64)
OBJECTS+=interop_cocoa.o
OBJECTS+=src/interop_cocoa.o
CFLAGS=-g -m64 -pipe -fno-math-errno
LIBS=
LDFLAGS=-rdynamic -framework Cocoa -framework OpenGL -framework IOKit -lobjc
@ -84,14 +84,14 @@ LIBS=-lexecinfo -lGL -lX11 -lXi -lm -lpthread
endif
ifeq ($(PLAT),haiku)
OBJECTS+=Window_Haiku.o
OBJECTS+=src/interop_BeOS.o
CFLAGS=-g -pipe -fno-math-errno
LDFLAGS=-g
LIBS=-lm -lexecinfo -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker
endif
ifeq ($(PLAT),beos)
OBJECTS+=Window_Haiku.o
OBJECTS+=src/interop_BeOS.o
CFLAGS=-g -pipe
LDFLAGS=-g
LIBS=-lm -lexecinfo -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker
@ -166,7 +166,7 @@ $(C_OBJECTS): %.o : %.c
src/interop_cocoa.o: src/interop_cocoa.m
$(CC) $(CFLAGS) -c $< -o $@
src/Window_Haiku.o: src/Window_Haiku.cpp
src/interop_BeOS.o: src/interop_BeOS.cpp
$(CC) $(CFLAGS) -c $< -o $@
# PSP requires fixups

View File

@ -220,7 +220,7 @@ typedef cc_uint8 cc_bool;
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#elif defined __BEOS__
#define CC_BUILD_HAIKU
#define CC_BUILD_BEOS
#define CC_BUILD_POSIX
#define CC_BUILD_GL
#define CC_BUILD_CURL

View File

@ -524,8 +524,48 @@ static void InitSockets(void) {
/*########################################################################################################################*
*-----------------------------------------------------Process/Module------------------------------------------------------*
*#########################################################################################################################*/
static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE];
static int gameNumArgs;
static cc_bool gameHasArgs;
cc_result Process_StartGame2(const cc_string* args, int numArgs) {
return ERR_NOT_SUPPORTED;
for (int i = 0; i < numArgs; i++)
{
String_CopyToRawArray(gameArgs[i], &args[i]);
}
Platform_LogConst("START GAME");
gameHasArgs = true;
gameNumArgs = numArgs;
return 0;
}
static int GetGameArgs(cc_string* args) {
int count = gameNumArgs;
for (int i = 0; i < count; i++)
{
args[i] = String_FromRawArray(gameArgs[i]);
}
// clear arguments so after game is closed, launcher is started
gameNumArgs = 0;
return count;
}
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
if (gameHasArgs) return GetGameArgs(args);
// GC/WII *sometimes* doesn't use argv[0] for program name and so argc will be 0
if (!argc) return 0;
int count = min(argc, GAME_MAX_CMDARGS);
for (int i = 0; i < count; i++)
{
args[i] = String_FromReadonly(argv[i]);
}
return count;
}
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
return 0;
}
void Process_Exit(cc_result code) { exit(code); }
@ -617,24 +657,4 @@ cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) {
cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
return ERR_NOT_SUPPORTED;
}
/*########################################################################################################################*
*-----------------------------------------------------Configuration-------------------------------------------------------*
*#########################################################################################################################*/
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
// GC/WII *sometimes* doesn't use argv[0] for program name and so argc will be 0
if (!argc) return 0;
int count = min(argc, GAME_MAX_CMDARGS);
for (int i = 0; i < count; i++) {
args[i] = String_FromReadonly(argv[i]);
}
return count;
}
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
return 0;
}
#endif

View File

@ -83,13 +83,6 @@ void Mem_Free(void* mem) {
/*########################################################################################################################*
*------------------------------------------------------Logging/Time-------------------------------------------------------*
*#########################################################################################################################*/
/* TODO: check this is actually accurate */
static cc_uint64 sw_freqMul = 1, sw_freqDiv = 1;
cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
if (end < beg) return 0;
return ((end - beg) * sw_freqMul) / sw_freqDiv;
}
#if defined CC_BUILD_ANDROID
/* implemented in Platform_Android.c */
#elif defined CC_BUILD_IOS
@ -122,14 +115,44 @@ void DateTime_CurrentLocal(struct DateTime* t) {
t->second = loc_time.tm_sec;
}
/*########################################################################################################################*
*--------------------------------------------------------Stopwatch--------------------------------------------------------*
*#########################################################################################################################*/
#define NS_PER_SEC 1000000000ULL
#if defined CC_BUILD_HAIKU || defined CC_BUILD_BEOS
/* Implemented in interop_BeOS.cpp */
#elif defined CC_BUILD_DARWIN
static cc_uint64 sw_freqMul, sw_freqDiv;
static void Stopwatch_Init(void) {
mach_timebase_info_data_t tb = { 0 };
mach_timebase_info(&tb);
sw_freqMul = tb.numer;
/* tb.denom may be large, so multiplying by 1000 overflows 32 bits */
/* (one powerpc system had tb.denom of 33329426) */
sw_freqDiv = (cc_uint64)tb.denom * 1000;
}
cc_uint64 Stopwatch_Measure(void) { return mach_absolute_time(); }
cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
if (end < beg) return 0;
return ((end - beg) * sw_freqMul) / sw_freqDiv;
}
#elif defined CC_BUILD_SOLARIS
/* https://docs.oracle.com/cd/E86824_01/html/E54766/gethrtime-3c.html */
/* The gethrtime() function returns the current high-resolution real time. Time is expressed as nanoseconds since some arbitrary time in the past */
cc_uint64 Stopwatch_Measure(void) { return gethrtime(); }
cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
if (end < beg) return 0;
return (end - beg) / 1000;
}
#else
/* clock_gettime is optional, see http://pubs.opengroup.org/onlinepubs/009696899/functions/clock_getres.html */
/* "... These functions are part of the Timers option and need not be available on all implementations..." */
#if defined CC_BUILD_DARWIN
cc_uint64 Stopwatch_Measure(void) { return mach_absolute_time(); }
#elif defined CC_BUILD_SOLARIS
cc_uint64 Stopwatch_Measure(void) { return gethrtime(); }
#else
cc_uint64 Stopwatch_Measure(void) {
struct timespec t;
#ifdef CC_BUILD_IRIX
@ -140,6 +163,11 @@ cc_uint64 Stopwatch_Measure(void) {
#endif
return (cc_uint64)t.tv_sec * NS_PER_SEC + t.tv_nsec;
}
cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
if (end < beg) return 0;
return (end - beg) / 1000;
}
#endif
@ -580,8 +608,9 @@ void Socket_Close(cc_socket s) {
close(s);
}
#if defined CC_BUILD_DARWIN
#if defined CC_BUILD_DARWIN || defined CC_BUILD_BEOS
/* poll is broken on old OSX apparently https://daniel.haxx.se/docs/poll-vs-select.html */
/* BeOS lacks support for poll */
static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
fd_set set;
struct timeval time = { 0 };
@ -695,16 +724,8 @@ cc_result Process_StartOpen(const cc_string* args) {
CFRelease(urlCF);
return 0;
}
#elif defined CC_BUILD_HAIKU
cc_result Process_StartOpen(const cc_string* args) {
char str[NATIVE_STR_LEN];
char* cmd[3];
String_EncodeUtf8(str, args);
cmd[0] = "open"; cmd[1] = str; cmd[2] = NULL;
Process_RawStart("open", cmd);
return 0;
}
#elif defined CC_BUILD_HAIKU || defined CC_BUILD_BEOS
/* Implemented in interop_BeOS.cpp */
#else
cc_result Process_StartOpen(const cc_string* args) {
char str[NATIVE_STR_LEN];
@ -995,9 +1016,6 @@ static void Platform_InitPosix(void) {
signal(SIGCHLD, SIG_IGN);
/* So writing to closed socket doesn't raise SIGPIPE */
signal(SIGPIPE, SIG_IGN);
/* Assume stopwatch is in nanoseconds */
/* Some platforms (e.g. macOS) override this */
sw_freqDiv = 1000;
}
void Platform_Free(void) { }
@ -1029,15 +1047,6 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
#endif
#if defined CC_BUILD_DARWIN
static void Platform_InitStopwatch(void) {
mach_timebase_info_data_t tb = { 0 };
mach_timebase_info(&tb);
sw_freqMul = tb.numer;
/* tb.denom may be large, so multiplying by 1000 overflows 32 bits */
/* (one powerpc system had tb.denom of 33329426) */
sw_freqDiv = (cc_uint64)tb.denom * 1000;
}
#if defined CC_BUILD_MACOS
static void Platform_InitSpecific(void) {
@ -1052,21 +1061,25 @@ static void Platform_InitSpecific(void) {
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
#else
static void Platform_InitSpecific(void) {
Platform_SingleProcess = true;
/* Always foreground process on iOS */
static void Platform_InitSpecific(void) { }
}
#endif
void Platform_Init(void) {
Stopwatch_Init();
Platform_InitPosix();
Platform_InitSpecific();
}
#else
void Platform_Init(void) {
#ifdef CC_BUILD_MOBILE
Platform_SingleProcess = true;
#endif
Platform_InitPosix();
Platform_InitStopwatch();
Platform_InitSpecific();
}
#else
void Platform_Init(void) { Platform_InitPosix(); }
#endif

View File

@ -138,7 +138,7 @@ void android_main(void) {
SetupProgram(0, NULL);
for (;;) { RunProgram(0, NULL); }
}
#elif defined CC_BUILD_3DS || defined CC_BUILD_PSP
#elif defined CC_BUILD_3DS || defined CC_BUILD_PSP || defined CC_BUILD_GCWII
int main(int argc, char** argv) {
SetupProgram(argc, argc);
for (;;) { RunProgram(argc, argv); }

View File

@ -1,5 +1,5 @@
#include "Core.h"
#if defined CC_BUILD_HAIKU && !defined CC_BUILD_SDL
#if defined CC_BUILD_HAIKU || defined CC_BUILD_BEOS
extern "C" {
#include "_WindowBase.h"
#include "Graphics.h"
@ -10,6 +10,9 @@ extern "C" {
#include "Utils.h"
}
// Other
#include <errno.h>
#include <Url.h>
// AppKit
#include <Application.h>
#include <Clipboard.h>
@ -25,6 +28,35 @@ extern "C" {
#include <FilePanel.h>
#include <Path.h>
/*########################################################################################################################*
*--------------------------------------------------------Platform---------------------------------------------------------*
*#########################################################################################################################*/
cc_uint64 Stopwatch_Measure(void) {
return system_time();
}
cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
if (end < beg) return 0;
return end - beg;
}
cc_result Process_StartOpen(const cc_string* args) {
static const cc_string https_protocol = String_FromConst("https://");
char str[NATIVE_STR_LEN];
String_EncodeUtf8(str, args);
cc_bool https = String_CaselessStarts(args, &https_protocol);
const char* mime = https ? "application/x-vnd.Be.URL.https" : "application/x-vnd.Be.URL.http";
const char* argv[] = { str, NULL };
return be_roster->Launch(mime, 1, argv);
}
/*########################################################################################################################*
*---------------------------------------------------------Window----------------------------------------------------------*
*#########################################################################################################################*/
#if !defined CC_BUILD_SDL
static BApplication* app_handle;
static BWindow* win_handle;
static BView* view_handle;
@ -635,7 +667,11 @@ void GLContext_Free(void) {
}
void* GLContext_GetAddress(const char* function) {
#if defined CC_BUILD_BEOS
return NULL;
#else
return view_3D->GetGLProcAddress(function);
#endif
}
cc_bool GLContext_SwapBuffers(void) {
@ -647,5 +683,6 @@ void GLContext_SetFpsLimit(cc_bool vsync, float minFrameMs) {
win_vsync = vsync;
}
void GLContext_GetApiInfo(cc_string* info) { }
#endif
#endif // CC_BUILD_GL && !CC_BUILD_EGL
#endif // !CC_BUILD_SDL
#endif