mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
refactor game/launcher loop to simplify mobile
This commit is contained in:
parent
056a849b9b
commit
f595a5bca8
@ -166,7 +166,6 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */
|
|||||||
#define CC_BUILD_EGL
|
#define CC_BUILD_EGL
|
||||||
#define CC_BUILD_TOUCH
|
#define CC_BUILD_TOUCH
|
||||||
#define CC_BUILD_OPENSLES
|
#define CC_BUILD_OPENSLES
|
||||||
#define CC_NOMAIN
|
|
||||||
#elif defined __linux__
|
#elif defined __linux__
|
||||||
#define CC_BUILD_LINUX
|
#define CC_BUILD_LINUX
|
||||||
#define CC_BUILD_POSIX
|
#define CC_BUILD_POSIX
|
||||||
@ -189,7 +188,6 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */
|
|||||||
#define CC_BUILD_GLMODERN
|
#define CC_BUILD_GLMODERN
|
||||||
#define CC_BUILD_IOS
|
#define CC_BUILD_IOS
|
||||||
#define CC_BUILD_TOUCH
|
#define CC_BUILD_TOUCH
|
||||||
#define CC_NOMAIN
|
|
||||||
#elif defined __x86_64__ || defined __arm64__
|
#elif defined __x86_64__ || defined __arm64__
|
||||||
#define CC_BUILD_COCOA
|
#define CC_BUILD_COCOA
|
||||||
#define CC_BUILD_MACOS
|
#define CC_BUILD_MACOS
|
||||||
|
@ -663,12 +663,6 @@ static void Game_RunLoop(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Game_Run(int width, int height, const cc_string* title) {
|
void Game_Run(int width, int height, const cc_string* title) {
|
||||||
#ifdef CC_BUILD_ANDROID
|
|
||||||
/* Reset components */
|
|
||||||
Platform_LogConst("undoing components");
|
|
||||||
Drawer2D_Component.Free();
|
|
||||||
//Http_Component.Free();
|
|
||||||
#endif
|
|
||||||
Window_Create(width, height);
|
Window_Create(width, height);
|
||||||
Window_SetTitle(title);
|
Window_SetTitle(title);
|
||||||
Window_Show();
|
Window_Show();
|
||||||
|
@ -794,6 +794,7 @@ static void WorkerLoop(void) {
|
|||||||
static void Http_Init(void) {
|
static void Http_Init(void) {
|
||||||
httpOnly = Options_GetBool(OPT_HTTP_ONLY, false);
|
httpOnly = Options_GetBool(OPT_HTTP_ONLY, false);
|
||||||
ScheduledTask_Add(30, Http_CleanCacheTask);
|
ScheduledTask_Add(30, Http_CleanCacheTask);
|
||||||
|
/* Http component gets initialised multiple times on Android */
|
||||||
if (workerThread) return;
|
if (workerThread) return;
|
||||||
|
|
||||||
HttpBackend_Init();
|
HttpBackend_Init();
|
||||||
|
@ -329,16 +329,13 @@ void Launcher_Run(void) {
|
|||||||
Launcher_Free();
|
Launcher_Free();
|
||||||
|
|
||||||
#ifdef CC_BUILD_MOBILE
|
#ifdef CC_BUILD_MOBILE
|
||||||
extern int Program_Run(int argc, char** argv);
|
/* infinite loop on mobile */
|
||||||
extern cc_bool Window_RemakeSurface(void);
|
Launcher_ShouldExit = false;
|
||||||
|
/* Reset components */
|
||||||
if (Launcher_ShouldExit) {
|
Platform_LogConst("undoing components");
|
||||||
Launcher_ShouldExit = false;
|
Drawer2D_Component.Free();
|
||||||
Http_Component.Free();
|
Http_Component.Free();
|
||||||
Program_Run(0, NULL);
|
#else
|
||||||
Launcher_Run();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (Launcher_ShouldUpdate) {
|
if (Launcher_ShouldUpdate) {
|
||||||
const char* action;
|
const char* action;
|
||||||
cc_result res = Updater_Start(&action);
|
cc_result res = Updater_Start(&action);
|
||||||
@ -346,6 +343,7 @@ void Launcher_Run(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (WindowInfo.Exists) Window_Close();
|
if (WindowInfo.Exists) Window_Close();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1227,8 +1227,13 @@ cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
#if defined CC_BUILD_ANDROID
|
#if defined CC_BUILD_ANDROID
|
||||||
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
|
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
|
||||||
if (!gameArgs.length) return 0;
|
int count = 0;
|
||||||
return String_UNSAFE_Split(&gameArgs, ' ', args, GAME_MAX_CMDARGS);
|
if (gameArgs.length) {
|
||||||
|
count = String_UNSAFE_Split(&gameArgs, ' ', args, GAME_MAX_CMDARGS);
|
||||||
|
/* clear arguments so after game is closed, launcher is started */
|
||||||
|
gameArgs.length = 0;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
|
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
|
||||||
|
@ -52,12 +52,21 @@ CC_NOINLINE static void WarnMissingArgs(int argsCount, const cc_string* args) {
|
|||||||
Logger_DialogWarn(&tmp);
|
Logger_DialogWarn(&tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CC_BUILD_MOBILE
|
static void SetupProgram(int argc, char** argv) {
|
||||||
/* Needs to be externally visible as this is called by Launcher_Run */
|
static char ipBuffer[STRING_SIZE];
|
||||||
int Program_Run(int argc, char** argv) {
|
cc_result res;
|
||||||
#else
|
Logger_Hook();
|
||||||
static int Program_Run(int argc, char** argv) {
|
Platform_Init();
|
||||||
#endif
|
Window_Init();
|
||||||
|
|
||||||
|
res = Platform_SetDefaultCurrentDirectory(argc, argv);
|
||||||
|
if (res) Logger_SysWarn(res, "setting current directory");
|
||||||
|
Platform_LogConst("Starting " GAME_APP_NAME " ..");
|
||||||
|
String_InitArray(Server.Address, ipBuffer);
|
||||||
|
Options_Load();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int RunProgram(int argc, char** argv) {
|
||||||
cc_string args[GAME_MAX_CMDARGS];
|
cc_string args[GAME_MAX_CMDARGS];
|
||||||
cc_uint16 port;
|
cc_uint16 port;
|
||||||
|
|
||||||
@ -102,48 +111,23 @@ static int Program_Run(int argc, char** argv) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOTE: main_real is used for when compiling with MingW without linking to startup files. */
|
|
||||||
/* Normally, the final code produced for "main" is our "main" combined with crt's main */
|
|
||||||
/* (mingw-w64-crt/crt/gccmain.c) - alas this immediately crashes the game on startup. */
|
|
||||||
/* Using main_real instead and setting main_real as the entrypoint fixes the crash. */
|
|
||||||
#ifdef CC_NOMAIN
|
|
||||||
int main_real(int argc, char** argv) {
|
|
||||||
#else
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
#endif
|
|
||||||
static char ipBuffer[STRING_SIZE];
|
|
||||||
cc_result res;
|
|
||||||
Logger_Hook();
|
|
||||||
Platform_Init();
|
|
||||||
Window_Init();
|
|
||||||
|
|
||||||
res = Platform_SetDefaultCurrentDirectory(argc, argv);
|
|
||||||
if (res) Logger_SysWarn(res, "setting current directory");
|
|
||||||
Platform_LogConst("Starting " GAME_APP_NAME " ..");
|
|
||||||
String_InitArray(Server.Address, ipBuffer);
|
|
||||||
Options_Load();
|
|
||||||
|
|
||||||
res = Program_Run(argc, argv);
|
|
||||||
Process_Exit(res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined CC_BUILD_IOS
|
#if defined CC_BUILD_IOS
|
||||||
/* ClassiCube is sort of and sort of not the executable */
|
/* ClassiCube is sort of and sort of not the executable */
|
||||||
/* on iOS - UIKit is responsible for kickstarting the game. */
|
/* on iOS - UIKit is responsible for kickstarting the game. */
|
||||||
/* (this is handled interop_ios.m as the code is Objective C) */
|
/* (this is handled interop_ios.m as the code is Objective C) */
|
||||||
|
int main_real(int argc, char** argv) {
|
||||||
|
SetupProgram(argc, argv);
|
||||||
|
for (;;) { RunProgram(argc, argv); }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#elif defined CC_BUILD_ANDROID
|
#elif defined CC_BUILD_ANDROID
|
||||||
/* ClassiCube is just a native library on android, */
|
/* ClassiCube is just a native library on android, */
|
||||||
/* unlike other platforms where it is the executable. */
|
/* unlike other platforms where it is the executable. */
|
||||||
/* (activity java class is responsible for kickstarting the game) */
|
/* (activity java class is responsible for kickstarting the game) */
|
||||||
static void android_main(void) {
|
static void android_main(void) {
|
||||||
Platform_LogConst("Main loop started!");
|
Platform_LogConst("Main loop started!");
|
||||||
/* Android client is always built with CC_NOMAIN, because a user who */
|
SetupProgram(0, NULL);
|
||||||
/* compiled a custom version of the client ran into an issue where */
|
for (;;) { RunProgram(0, NULL); }
|
||||||
/* the game would wrongly call main in /system/bin/app_process64 */
|
|
||||||
/* instead of the main located just above here. (see issue #864) */
|
|
||||||
/* So use main_real instead to avoid the issue altogether */
|
|
||||||
main_real(0, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called eventually by the activity java class to actually start the game */
|
/* Called eventually by the activity java class to actually start the game */
|
||||||
@ -175,4 +159,21 @@ CC_API jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
|||||||
JavaRegisterNatives(env, methods);
|
JavaRegisterNatives(env, methods);
|
||||||
return JNI_VERSION_1_4;
|
return JNI_VERSION_1_4;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
/* NOTE: main_real is used for when compiling with MingW without linking to startup files. */
|
||||||
|
/* Normally, the final code produced for "main" is our "main" combined with crt's main */
|
||||||
|
/* (mingw-w64-crt/crt/gccmain.c) - alas this immediately crashes the game on startup. */
|
||||||
|
/* Using main_real instead and setting main_real as the entrypoint fixes the crash. */
|
||||||
|
#ifdef CC_NOMAIN
|
||||||
|
int main_real(int argc, char** argv) {
|
||||||
|
#else
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
#endif
|
||||||
|
cc_result res;
|
||||||
|
SetupProgram(argc, argv);
|
||||||
|
|
||||||
|
res = RunProgram(argc, argv);
|
||||||
|
Process_Exit(res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user