mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 09:06:55 -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
|
#endif
|
||||||
|
|
||||||
|
void Game_Run(int width, int height, const cc_string* title) {
|
||||||
#ifdef CC_BUILD_ANDROID
|
#ifdef CC_BUILD_ANDROID
|
||||||
extern cc_bool Window_RemakeSurface(void);
|
|
||||||
static cc_bool SwitchToGame() {
|
|
||||||
/* Reset components */
|
/* Reset components */
|
||||||
Platform_LogConst("undoing components");
|
Platform_LogConst("undoing components");
|
||||||
Drawer2D_Component.Free();
|
Drawer2D_Component.Free();
|
||||||
//Http_Component.Free();
|
//Http_Component.Free();
|
||||||
return Window_RemakeSurface();
|
|
||||||
}
|
|
||||||
#endif
|
#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_Create(width, height);
|
||||||
Window_SetTitle(title);
|
Window_SetTitle(title);
|
||||||
Window_Show();
|
Window_Show();
|
||||||
|
@ -280,7 +280,6 @@ void Launcher_Run(void) {
|
|||||||
static const cc_string title = String_FromConst(GAME_APP_TITLE);
|
static const cc_string title = String_FromConst(GAME_APP_TITLE);
|
||||||
Window_Create(640, 400);
|
Window_Create(640, 400);
|
||||||
#ifdef CC_BUILD_MOBILE
|
#ifdef CC_BUILD_MOBILE
|
||||||
Window_EnterFullscreen();
|
|
||||||
Window_LockLandscapeOrientation(Options_GetBool(OPT_LANDSCAPE_MODE, false));
|
Window_LockLandscapeOrientation(Options_GetBool(OPT_LANDSCAPE_MODE, false));
|
||||||
#endif
|
#endif
|
||||||
Window_SetTitle(&title);
|
Window_SetTitle(&title);
|
||||||
@ -336,10 +335,7 @@ void Launcher_Run(void) {
|
|||||||
if (Launcher_ShouldExit) {
|
if (Launcher_ShouldExit) {
|
||||||
Launcher_ShouldExit = false;
|
Launcher_ShouldExit = false;
|
||||||
Http_Component.Free();
|
Http_Component.Free();
|
||||||
|
|
||||||
Program_Run(0, NULL);
|
Program_Run(0, NULL);
|
||||||
Window_ExitFullscreen(); /* TODO remove */
|
|
||||||
Window_RemakeSurface();
|
|
||||||
Launcher_Run();
|
Launcher_Run();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <android/native_window_jni.h>
|
#include <android/native_window_jni.h>
|
||||||
#include <android/keycodes.h>
|
#include <android/keycodes.h>
|
||||||
static ANativeWindow* win_handle;
|
static ANativeWindow* win_handle;
|
||||||
|
static cc_bool winCreated;
|
||||||
|
|
||||||
static void RefreshWindowBounds(void) {
|
static void RefreshWindowBounds(void) {
|
||||||
WindowInfo.Width = ANativeWindow_getWidth(win_handle);
|
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) {
|
static void JNICALL java_processSurfaceCreated(JNIEnv* env, jobject o, jobject surface) {
|
||||||
Platform_LogConst("WIN - CREATED");
|
Platform_LogConst("WIN - CREATED");
|
||||||
win_handle = ANativeWindow_fromSurface(env, surface);
|
win_handle = ANativeWindow_fromSurface(env, surface);
|
||||||
|
winCreated = true;
|
||||||
WindowInfo.Handle = win_handle;
|
WindowInfo.Handle = win_handle;
|
||||||
RefreshWindowBounds();
|
RefreshWindowBounds();
|
||||||
/* TODO: Restore context */
|
/* TODO: Restore context */
|
||||||
@ -193,7 +195,7 @@ static void JNICALL java_onLowMemory(JNIEnv* env, jobject o) {
|
|||||||
/* TODO: Low memory */
|
/* TODO: Low memory */
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JNINativeMethod methods[19] = {
|
static const JNINativeMethod methods[] = {
|
||||||
{ "processKeyDown", "(I)V", java_processKeyDown },
|
{ "processKeyDown", "(I)V", java_processKeyDown },
|
||||||
{ "processKeyUp", "(I)V", java_processKeyUp },
|
{ "processKeyUp", "(I)V", java_processKeyUp },
|
||||||
{ "processKeyChar", "(I)V", java_processKeyChar },
|
{ "processKeyChar", "(I)V", java_processKeyChar },
|
||||||
@ -233,14 +235,7 @@ void Window_Init(void) {
|
|||||||
DisplayInfo.ScaleY = JavaCallFloat(env, "getDpiY", "()F", NULL);
|
DisplayInfo.ScaleY = JavaCallFloat(env, "getDpiY", "()F", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window_Create(int width, int height) {
|
static void Window_RemakeSurface(void) {
|
||||||
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) {
|
|
||||||
JNIEnv* env;
|
JNIEnv* env;
|
||||||
JavaGetCurrentEnv(env);
|
JavaGetCurrentEnv(env);
|
||||||
winCreated = false;
|
winCreated = false;
|
||||||
@ -248,18 +243,23 @@ cc_bool Window_RemakeSurface(void) {
|
|||||||
/* Force window to be destroyed and re-created */
|
/* Force window to be destroyed and re-created */
|
||||||
/* (see comments in setupForGame for why this has to be done) */
|
/* (see comments in setupForGame for why this has to be done) */
|
||||||
JavaCallVoid(env, "setupForGame", "()V", NULL);
|
JavaCallVoid(env, "setupForGame", "()V", NULL);
|
||||||
Event_Register_(&WindowEvents.Created, NULL, OnWindowCreated);
|
|
||||||
Platform_LogConst("Entering wait for window exist loop..");
|
Platform_LogConst("Entering wait for window exist loop..");
|
||||||
|
|
||||||
/* Loop until window gets created by main UI thread */
|
/* Loop until window gets created by main UI thread */
|
||||||
while (WindowInfo.Exists && !winCreated) {
|
while (!winCreated) {
|
||||||
Window_ProcessEvents();
|
Window_ProcessEvents();
|
||||||
Thread_Sleep(10);
|
Thread_Sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
Platform_LogConst("OK window created..");
|
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) {
|
void Window_SetTitle(const cc_string* title) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user