Simplify window closing

This commit is contained in:
UnknownShadow200 2024-06-29 11:53:29 +10:00
parent 89e47e7a2a
commit 2f4eeb6aec
8 changed files with 23 additions and 27 deletions

View File

@ -30,7 +30,7 @@ extern int Game_NumLocalPlayers;
#if defined CC_BUILD_N64 #if defined CC_BUILD_N64
#define DEFAULT_VIEWDIST 20 #define DEFAULT_VIEWDIST 20
#elif defined CC_BUILD_NDS || defined CC_BUILD_PS1 #elif defined CC_BUILD_NDS || defined CC_BUILD_PS1 || defined CC_BUILD_SATURN
#define DEFAULT_VIEWDIST 192 #define DEFAULT_VIEWDIST 192
#else #else
#define DEFAULT_VIEWDIST 512 #define DEFAULT_VIEWDIST 512

View File

@ -1353,7 +1353,6 @@ static void OnInputDown(void* obj, int key, cc_bool was) {
#endif #endif
if (InputHandler_IsShutdown(key)) { if (InputHandler_IsShutdown(key)) {
/* TODO: Do we need a separate exit function in Game class? */
Window_RequestClose(); return; Window_RequestClose(); return;
} else if (InputBind_Claims(BIND_SCREENSHOT, key) && !was) { } else if (InputBind_Claims(BIND_SCREENSHOT, key) && !was) {
Game_ScreenshotRequested = true; return; Game_ScreenshotRequested = true; return;

View File

@ -498,8 +498,13 @@ static struct PauseScreen {
struct TextWidget title; struct TextWidget title;
} PauseScreen; } PauseScreen;
static void PauseScreenBase_Quit(void* a, void* b) { Window_RequestClose(); } static void PauseScreenBase_Quit(void* a, void* b) {
static void PauseScreenBase_Game(void* a, void* b) { Gui_Remove((struct Screen*)&PauseScreen); } Window_RequestClose();
}
static void PauseScreenBase_Game(void* a, void* b) {
Gui_Remove((struct Screen*)&PauseScreen);
}
static void PauseScreenBase_ContextRecreated(struct PauseScreen* s, struct FontDesc* titleFont) { static void PauseScreenBase_ContextRecreated(struct PauseScreen* s, struct FontDesc* titleFont) {
Screen_UpdateVb(s); Screen_UpdateVb(s);

View File

@ -2111,7 +2111,10 @@ static void DisconnectScreen_OnReconnect(void* s, void* w) {
Gui_ShowDefault(); Gui_ShowDefault();
Server.BeginConnect(); Server.BeginConnect();
} }
static void DisconnectScreen_OnQuit(void* s, void* w) { Window_RequestClose(); }
static void DisconnectScreen_OnQuit(void* s, void* w) {
Window_RequestClose();
}
static void DisconnectScreen_Init(void* screen) { static void DisconnectScreen_Init(void* screen) {
struct DisconnectScreen* s = (struct DisconnectScreen*)screen; struct DisconnectScreen* s = (struct DisconnectScreen*)screen;

View File

@ -465,8 +465,7 @@ void Window_SetSize(int width, int height) {
} }
void Window_RequestClose(void) { void Window_RequestClose(void) {
BMessage* msg = new BMessage(B_QUIT_REQUESTED); Event_RaiseVoid(&WindowEvents.Closing);
app_handle->PostMessage(msg);
} }
static const cc_uint8 key_map[] = { static const cc_uint8 key_map[] = {
@ -538,7 +537,7 @@ void Window_ProcessEvents(float delta) {
break; break;
case CC_WIN_QUIT: case CC_WIN_QUIT:
Window_Main.Exists = false; Window_Main.Exists = false;
Event_RaiseVoid(&WindowEvents.Closing); Window_RequestClose();
break; break;
case CC_RAW_MOUSE: case CC_RAW_MOUSE:
if (Input.RawMode) Event_RaiseRawMove(&PointerEvents.RawMoved, event.v1.i32, event.v2.i32); if (Input.RawMode) Event_RaiseRawMove(&PointerEvents.RawMoved, event.v1.i32, event.v2.i32);

View File

@ -282,16 +282,12 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
break; break;
case WM_CLOSE: case WM_CLOSE:
Event_RaiseVoid(&WindowEvents.Closing);
if (Window_Main.Exists) DestroyWindow(win_handle);
Window_Main.Exists = false; Window_Main.Exists = false;
break; Window_RequestClose();
return 0;
case WM_DESTROY: case WM_DESTROY:
Window_Main.Exists = false;
UnregisterClassW(CC_WIN_CLASSNAME, win_instance); UnregisterClassW(CC_WIN_CLASSNAME, win_instance);
if (win_DC) ReleaseDC(win_handle, win_DC);
break; break;
} }
return is_ansiWindow ? DefWindowProcA(handle, message, wParam, lParam) return is_ansiWindow ? DefWindowProcA(handle, message, wParam, lParam)
@ -404,7 +400,10 @@ static void DoCreateWindow(int width, int height) {
void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } void Window_Create2D(int width, int height) { DoCreateWindow(width, height); }
void Window_Create3D(int width, int height) { DoCreateWindow(width, height); } void Window_Create3D(int width, int height) { DoCreateWindow(width, height); }
void Window_Destroy(void) { } void Window_Destroy(void) {
if (win_DC) ReleaseDC(win_handle, win_DC);
DestroyWindow(win_handle);
}
void Window_SetTitle(const cc_string* title) { void Window_SetTitle(const cc_string* title) {
cc_winstring str; cc_winstring str;
@ -544,7 +543,7 @@ void Window_SetSize(int width, int height) {
} }
void Window_RequestClose(void) { void Window_RequestClose(void) {
PostMessageA(win_handle, WM_CLOSE, 0, 0); Event_RaiseVoid(&WindowEvents.Closing);
} }
void Window_ProcessEvents(float delta) { void Window_ProcessEvents(float delta) {

View File

@ -513,15 +513,7 @@ void Window_SetSize(int width, int height) {
} }
void Window_RequestClose(void) { void Window_RequestClose(void) {
XEvent ev = { 0 }; Event_RaiseVoid(&WindowEvents.Closing);
ev.type = ClientMessage;
ev.xclient.format = 32;
ev.xclient.display = win_display;
ev.xclient.window = win_handle;
ev.xclient.data.l[0] = wm_destroy;
XSendEvent(win_display, win_handle, false, 0, &ev);
XFlush(win_display);
} }
static int MapNativeMouse(int button) { static int MapNativeMouse(int button) {

View File

@ -437,8 +437,7 @@ void Window_Show(void) {
} }
void Window_RequestClose(void) { void Window_RequestClose(void) {
Window_Main.Exists = false; Event_RaiseVoid(&WindowEvents.Closing);
Event_RaiseVoid(&WindowEvents.Closing);
} }
void Window_ProcessEvents(float delta) { void Window_ProcessEvents(float delta) {