Port ngage to header-only SDL_main + SDL_RunApp()

For some reason, ngage doesn't seem to be handled in any of the
build systems, so I couldn't add SDL_ngage_runapp.cpp to any buildscript
This commit is contained in:
Daniel Gibson 2022-12-12 18:30:05 +01:00 committed by Sam Lantinga
parent 7bfc41db3c
commit 544f2c7982
4 changed files with 109 additions and 79 deletions

View File

@ -110,6 +110,14 @@
*/
#define SDL_MAIN_AVAILABLE
#elif defined(__NGAGE__)
/*
TODO: not sure if it should be SDL_MAIN_NEEDED, in SDL2 ngage had a
main implementation, but wasn't mentioned in SDL_main.h
*/
#define SDL_MAIN_AVAILABLE
#endif
#endif /* SDL_MAIN_HANDLED */
@ -272,7 +280,7 @@ extern DECLSPEC void SDLCALL SDL_GDKSuspendComplete(void);
#if !defined(SDL_MAIN_HANDLED) && !defined(SDL_MAIN_NOIMPL)
/* include header-only SDL_main implementations */
#if defined(__WIN32__) || defined(__GDK__) || defined(__IOS__) || defined(__TVOS__) \
|| defined(__3DS__) /* TODO: other platforms */
|| defined(__3DS__) || defined(__NGAGE__) /* TODO: other platforms */
#include <SDL3/SDL_main_impl.h>
#elif defined(__WINRT__) /* TODO: other C++ platforms */

View File

@ -156,7 +156,22 @@ int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
}
/* end of WinRT impl */
#elif defined(__IOS__) || defined(__TVOS__) || defined(__3DS__)
#elif defined(__NGAGE__)
/* same typedef as in ngage SDKs e32def.h */
typedef signed int TInt;
/* TODO: if it turns out that this only works when built as C++,
move __NGAGE__ into the C++ section in SDL_main.h */
TInt E32Main()
{
return SDL_RunApp(0, NULL, SDL_main, NULL);
}
/* end of __NGAGE__ impl */
/* TODO: remaining platforms */
#else /* platforms that use a standard main() and just call SDL_RunApp(), like iOS and 3DS */
#include <SDL3/begin_code.h>
@ -175,9 +190,7 @@ int main(int argc, char *argv[])
#include <SDL3/close_code.h>
/* end of __IOS__, __3DS__, __TVOS__ impls */
/* TODO: remaining platforms */
/* end of impls for standard-conforming platforms */
#endif /* __WIN32__ etc */

View File

@ -0,0 +1,80 @@
/*
based on SDL_ngage_main.c, originally for SDL 1.2 by Hannu Viitala
*/
#include "SDL_internal.h"
#ifdef __NGAGE__
#include <e32std.h>
#include <e32def.h>
#include <e32svr.h>
#include <e32base.h>
#include <estlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <w32std.h>
#include <apgtask.h>
DECLSPEC int
SDL_RunApp(int argc_, char* argv_[], SDL_main_func mainFunction, void * reserved)
{
(void)argc_; (void)argv_; (void)reserved;
/* Get the clean-up stack */
CTrapCleanup *cleanup = CTrapCleanup::New();
/* Arrange for multi-threaded operation */
SpawnPosixServerThread();
/* Get args and environment */
int argc = 0;
char **argv = 0;
char **envp = 0;
__crt0(argc, argv, envp);
/* Start the application! */
/* Create stdlib */
_REENT;
/* Set process and thread priority and name */
RThread currentThread;
RProcess thisProcess;
TParse exeName;
exeName.Set(thisProcess.FileName(), NULL, NULL);
currentThread.Rename(exeName.Name());
currentThread.SetProcessPriority(EPriorityLow);
currentThread.SetPriority(EPriorityMuchLess);
/* Increase heap size */
RHeap *newHeap = NULL;
RHeap *oldHeap = NULL;
TInt heapSize = 7500000;
int ret;
newHeap = User::ChunkHeap(NULL, heapSize, heapSize, KMinHeapGrowBy);
if (newHeap == NULL) {
ret = 3;
goto cleanup;
} else {
oldHeap = User::SwitchHeap(newHeap);
/* Call stdlib main */
SDL_SetMainReady();
ret = mainFunction(argc, argv);
}
cleanup:
_cleanup();
CloseSTDLIB();
delete cleanup;
return ret;
}
#endif // __NGAGE__
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -1,79 +1,8 @@
/*
SDL_ngage_main.c, originally for SDL 1.2 by Hannu Viitala
empty, moved to SDL_main_impl.h and src/core/ngage/SDL_ngage_runapp.cpp
TODO: delete this file
*/
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h> /* until this SDL_main impl is converted to header-only.. */
#include <e32std.h>
#include <e32def.h>
#include <e32svr.h>
#include <e32base.h>
#include <estlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <w32std.h>
#include <apgtask.h>
#ifdef main
#undef main
#endif
extern "C" int main(int argc, char *argv[]);
TInt E32Main()
{
/* Get the clean-up stack */
CTrapCleanup *cleanup = CTrapCleanup::New();
/* Arrange for multi-threaded operation */
SpawnPosixServerThread();
/* Get args and environment */
int argc = 0;
char **argv = 0;
char **envp = 0;
__crt0(argc, argv, envp);
/* Start the application! */
/* Create stdlib */
_REENT;
/* Set process and thread priority and name */
RThread currentThread;
RProcess thisProcess;
TParse exeName;
exeName.Set(thisProcess.FileName(), NULL, NULL);
currentThread.Rename(exeName.Name());
currentThread.SetProcessPriority(EPriorityLow);
currentThread.SetPriority(EPriorityMuchLess);
/* Increase heap size */
RHeap *newHeap = NULL;
RHeap *oldHeap = NULL;
TInt heapSize = 7500000;
int ret;
newHeap = User::ChunkHeap(NULL, heapSize, heapSize, KMinHeapGrowBy);
if (newHeap == NULL) {
ret = 3;
goto cleanup;
} else {
oldHeap = User::SwitchHeap(newHeap);
/* Call stdlib main */
SDL_SetMainReady();
ret = SDL_main(argc, argv);
}
cleanup:
_cleanup();
CloseSTDLIB();
delete cleanup;
return ret;
}
/* vi: set ts=4 sw=4 expandtab: */