mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 00:56:40 -04:00
simplify android window creation (untested)
This commit is contained in:
parent
deb887ff8e
commit
056a849b9b
14
src/Game.c
14
src/Game.c
@ -662,25 +662,13 @@ static void Game_RunLoop(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
void Game_Run(int width, int height, const cc_string* title) {
|
||||
#ifdef CC_BUILD_ANDROID
|
||||
extern cc_bool Window_RemakeSurface(void);
|
||||
static cc_bool SwitchToGame() {
|
||||
/* Reset components */
|
||||
Platform_LogConst("undoing components");
|
||||
Drawer2D_Component.Free();
|
||||
//Http_Component.Free();
|
||||
return Window_RemakeSurface();
|
||||
}
|
||||
#endif
|
||||
|
||||
void Game_Run(int width, int height, const cc_string* title) {
|
||||
#ifdef CC_BUILD_ANDROID
|
||||
/* Android won't let us change pixel surface to EGL surface */
|
||||
/* So unfortunately have to completely recreate the surface */
|
||||
if (!SwitchToGame()) return;
|
||||
Window_EnterFullscreen();
|
||||
#endif
|
||||
|
||||
Window_Create(width, height);
|
||||
Window_SetTitle(title);
|
||||
Window_Show();
|
||||
|
@ -280,7 +280,6 @@ void Launcher_Run(void) {
|
||||
static const cc_string title = String_FromConst(GAME_APP_TITLE);
|
||||
Window_Create(640, 400);
|
||||
#ifdef CC_BUILD_MOBILE
|
||||
Window_EnterFullscreen();
|
||||
Window_LockLandscapeOrientation(Options_GetBool(OPT_LANDSCAPE_MODE, false));
|
||||
#endif
|
||||
Window_SetTitle(&title);
|
||||
@ -336,10 +335,7 @@ void Launcher_Run(void) {
|
||||
if (Launcher_ShouldExit) {
|
||||
Launcher_ShouldExit = false;
|
||||
Http_Component.Free();
|
||||
|
||||
Program_Run(0, NULL);
|
||||
Window_ExitFullscreen(); /* TODO remove */
|
||||
Window_RemakeSurface();
|
||||
Launcher_Run();
|
||||
}
|
||||
#endif
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <android/native_window_jni.h>
|
||||
#include <android/keycodes.h>
|
||||
static ANativeWindow* win_handle;
|
||||
static cc_bool winCreated;
|
||||
|
||||
static void RefreshWindowBounds(void) {
|
||||
WindowInfo.Width = ANativeWindow_getWidth(win_handle);
|
||||
@ -121,6 +122,7 @@ static void JNICALL java_processPointerMove(JNIEnv* env, jobject o, jint id, jin
|
||||
static void JNICALL java_processSurfaceCreated(JNIEnv* env, jobject o, jobject surface) {
|
||||
Platform_LogConst("WIN - CREATED");
|
||||
win_handle = ANativeWindow_fromSurface(env, surface);
|
||||
winCreated = true;
|
||||
WindowInfo.Handle = win_handle;
|
||||
RefreshWindowBounds();
|
||||
/* TODO: Restore context */
|
||||
@ -193,7 +195,7 @@ static void JNICALL java_onLowMemory(JNIEnv* env, jobject o) {
|
||||
/* TODO: Low memory */
|
||||
}
|
||||
|
||||
static const JNINativeMethod methods[19] = {
|
||||
static const JNINativeMethod methods[] = {
|
||||
{ "processKeyDown", "(I)V", java_processKeyDown },
|
||||
{ "processKeyUp", "(I)V", java_processKeyUp },
|
||||
{ "processKeyChar", "(I)V", java_processKeyChar },
|
||||
@ -233,14 +235,7 @@ void Window_Init(void) {
|
||||
DisplayInfo.ScaleY = JavaCallFloat(env, "getDpiY", "()F", NULL);
|
||||
}
|
||||
|
||||
void Window_Create(int width, int height) {
|
||||
WindowInfo.Exists = true;
|
||||
/* actual window creation is done when processSurfaceCreated is received */
|
||||
}
|
||||
|
||||
static cc_bool winCreated;
|
||||
static void OnWindowCreated(void* obj) { winCreated = true; }
|
||||
cc_bool Window_RemakeSurface(void) {
|
||||
static void Window_RemakeSurface(void) {
|
||||
JNIEnv* env;
|
||||
JavaGetCurrentEnv(env);
|
||||
winCreated = false;
|
||||
@ -248,18 +243,23 @@ cc_bool Window_RemakeSurface(void) {
|
||||
/* Force window to be destroyed and re-created */
|
||||
/* (see comments in setupForGame for why this has to be done) */
|
||||
JavaCallVoid(env, "setupForGame", "()V", NULL);
|
||||
Event_Register_(&WindowEvents.Created, NULL, OnWindowCreated);
|
||||
Platform_LogConst("Entering wait for window exist loop..");
|
||||
|
||||
/* Loop until window gets created by main UI thread */
|
||||
while (WindowInfo.Exists && !winCreated) {
|
||||
while (!winCreated) {
|
||||
Window_ProcessEvents();
|
||||
Thread_Sleep(10);
|
||||
}
|
||||
|
||||
Platform_LogConst("OK window created..");
|
||||
Event_Unregister_(&WindowEvents.Created, NULL, OnWindowCreated);
|
||||
return winCreated;
|
||||
}
|
||||
|
||||
void Window_Create(int width, int height) {
|
||||
WindowInfo.Exists = true;
|
||||
/* actual window creation is done when processSurfaceCreated is received */
|
||||
Window_RemakeSurface();
|
||||
/* always start as fullscreen */
|
||||
Window_EnterFullscrene();
|
||||
}
|
||||
|
||||
void Window_SetTitle(const cc_string* title) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user