aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2018-03-16 21:31:10 +0100
committerAhmad Fatoum <ahmad@a3f.at>2018-03-16 21:37:22 +0100
commit2c219fb81458b855c9383cd38885993192d856cd (patch)
tree66c87e91fc6395500acde4a995e9a9d3293ce272 /src
parent61e0e4b4f37cc66135445bc87af7c92399fa69ee (diff)
downloadraylib-2c219fb81458b855c9383cd38885993192d856cd.tar.gz
raylib-2c219fb81458b855c9383cd38885993192d856cd.zip
Allow use of main instead of android_main
Inspired by #504. Instead of requiring the user to do PLATFORM_ANDROID #ifdefery, have the android_main entry point exported by raylib and call the user-defined main. This way many games could (in theory) run unmodified on Android and elsewhere. This is untested!
Diffstat (limited to 'src')
-rw-r--r--src/core.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/core.c b/src/core.c
index 0532c3c4..f3ee4809 100644
--- a/src/core.c
+++ b/src/core.c
@@ -499,17 +499,33 @@ void InitWindow(int width, int height, void *data)
#endif
#if defined(PLATFORM_ANDROID)
+/* To allow easier porting to android, we allow the user to define a main function
+ * which we call from android_main, that we define ourselves
+ */
+extern int main(int argc, char *argv[]);
+void android_main(struct android_app *_app) {
+ char arg0[] = "raylib"; /* argv[] are mutable */
+ app = _app;
+ /* TODO should we maybe report != 0 return codes somewhere? */
+ (void)main(1, (char*[]){ arg0, NULL });
+}
+/* TODO add this to header, if apps really need it) */
+struct android_app *GetAndroidApp(void)
+{
+ return app;
+}
+
// Initialize window and OpenGL context (and Android activity)
// NOTE: data parameter could be used to pass any kind of required data to the initialization
void InitWindow(int width, int height, void *data)
{
+ (void)data; // ignored
TraceLog(LOG_INFO, "Initializing raylib (v1.9.6-dev)");
screenWidth = width;
screenHeight = height;
// Input data is android app pointer
- app = (struct android_app *)data;
internalDataPath = app->activity->internalDataPath;
// Set desired windows flags before initializing anything