diff options
| author | Ahmad Fatoum <[email protected]> | 2018-03-16 21:31:10 +0100 |
|---|---|---|
| committer | Ahmad Fatoum <[email protected]> | 2018-03-16 21:37:22 +0100 |
| commit | 2c219fb81458b855c9383cd38885993192d856cd (patch) | |
| tree | 66c87e91fc6395500acde4a995e9a9d3293ce272 /templates | |
| parent | 61e0e4b4f37cc66135445bc87af7c92399fa69ee (diff) | |
| download | raylib-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 'templates')
| -rw-r--r-- | templates/advance_game/advance_game.c | 19 | ||||
| -rw-r--r-- | templates/simple_game/simple_game.c | 17 | ||||
| -rw-r--r-- | templates/standard_game/standard_game.c | 19 |
3 files changed, 8 insertions, 47 deletions
diff --git a/templates/advance_game/advance_game.c b/templates/advance_game/advance_game.c index 5499b2d8..768b2f94 100644 --- a/templates/advance_game/advance_game.c +++ b/templates/advance_game/advance_game.c @@ -15,10 +15,6 @@ #include "raylib.h" #include "screens/screens.h" // NOTE: Defines global variable: currentScreen -#if defined(PLATFORM_ANDROID) - #include "android_native_app_glue.h" -#endif - #if defined(PLATFORM_WEB) #include <emscripten/emscripten.h> #endif @@ -53,19 +49,11 @@ static void UpdateDrawFrame(void); // Update and Draw one frame //---------------------------------------------------------------------------------- // Main entry point //---------------------------------------------------------------------------------- -#if defined(PLATFORM_ANDROID) -void android_main(struct android_app *app) -#else int main(void) -#endif { - // Initialization + // Initialization (Note windowTitle is unused on Android) //--------------------------------------------------------- -#if defined(PLATFORM_ANDROID) - InitWindow(screenWidth, screenHeight, app); -#else InitWindow(screenWidth, screenHeight, "raylib template - advance game"); -#endif // Global data loading (assets that must be available in all screens, i.e. fonts) InitAudioDevice(); @@ -116,9 +104,8 @@ int main(void) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- -#if !defined(PLATFORM_ANDROID) + return 0; -#endif } //---------------------------------------------------------------------------------- @@ -299,4 +286,4 @@ static void UpdateDrawFrame(void) EndDrawing(); //---------------------------------------------------------------------------------- -}
\ No newline at end of file +} diff --git a/templates/simple_game/simple_game.c b/templates/simple_game/simple_game.c index 50859221..028b1da8 100644 --- a/templates/simple_game/simple_game.c +++ b/templates/simple_game/simple_game.c @@ -14,10 +14,6 @@ #include "raylib.h" -#if defined(PLATFORM_ANDROID) - #include "android_native_app_glue.h" -#endif - //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- @@ -26,22 +22,14 @@ typedef enum GameScreen { LOGO = 0, TITLE, GAMEPLAY, ENDING } GameScreen; //---------------------------------------------------------------------------------- // Main entry point //---------------------------------------------------------------------------------- -#if defined(PLATFORM_ANDROID) -void android_main(struct android_app *app) -#else int main(void) -#endif { - // Initialization + // Initialization (Note windowTitle is unused on Android) //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; -#if defined(PLATFORM_ANDROID) - InitWindow(screenWidth, screenHeight, app); -#else InitWindow(screenWidth, screenHeight, "raylib template - simple game"); -#endif GameScreen currentScreen = LOGO; @@ -158,7 +146,6 @@ int main(void) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- -#if !defined(PLATFORM_ANDROID) + return 0; -#endif } diff --git a/templates/standard_game/standard_game.c b/templates/standard_game/standard_game.c index cf059451..8871484e 100644 --- a/templates/standard_game/standard_game.c +++ b/templates/standard_game/standard_game.c @@ -15,29 +15,17 @@ #include "raylib.h" #include "screens/screens.h" // NOTE: Defines global variable: currentScreen -#if defined(PLATFORM_ANDROID) - #include "android_native_app_glue.h" -#endif - //---------------------------------------------------------------------------------- // Main entry point //---------------------------------------------------------------------------------- -#if defined(PLATFORM_ANDROID) -void android_main(struct android_app *app) -#else int main(void) -#endif { - // Initialization + // Initialization (Note windowTitle is unused on Android) //--------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; -#if defined(PLATFORM_ANDROID) - InitWindow(screenWidth, screenHeight, app); -#else InitWindow(screenWidth, screenHeight, "raylib template - standard game"); -#endif // TODO: Load global data here (assets that must be available in all screens, i.e. fonts) @@ -150,7 +138,6 @@ int main(void) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- -#if !defined(PLATFORM_ANDROID) + return 0; -#endif -}
\ No newline at end of file +} |
