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!
This commit is contained in:
Ahmad Fatoum
2018-03-16 21:31:10 +01:00
parent 61e0e4b4f3
commit 2c219fb814
21 changed files with 77 additions and 315 deletions

View File

@ -15,10 +15,6 @@
#include "raylib.h"
#include "screens/screens.h" // NOTE: Defines currentScreen
#if defined(PLATFORM_ANDROID)
#include "android_native_app_glue.h"
#endif
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif
@ -47,12 +43,7 @@ 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
{
int main(void) {
// Initialization
//---------------------------------------------------------
const int screenWidth = 1280;
@ -62,11 +53,8 @@ int main(void)
//ShowLogo();
//SetConfigFlags(FLAG_FULLSCREEN_MODE);
#if defined(PLATFORM_ANDROID)
InitWindow(screenWidth, screenHeight, app);
#else
// Note that windowTitle is ignored on Android
InitWindow(screenWidth, screenHeight, windowTitle);
#endif
// Load global data here (assets that must be available in all screens, i.e. fonts)
font = LoadSpriteFont("resources/graphics/mainfont.png");
@ -145,9 +133,8 @@ int main(void)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
#if !defined(PLATFORM_ANDROID)
return 0;
#endif
}
void TransitionToScreen(int screen)
@ -282,4 +269,4 @@ void UpdateDrawFrame(void)
EndDrawing();
//----------------------------------------------------------------------------------
}
}