From 979dacd15100ff1f7c1e6d28e3595fc3b9fa5a25 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Thu, 28 Jun 2018 00:03:37 +0200 Subject: [PATCH] WIP: experiment a reinit (buggy) --- src/blupi.cxx | 109 +++++++++++++++++++++++++++++++----------------- src/def.h | 1 + src/display.cxx | 10 ++++- src/display.h | 1 + src/event.cxx | 14 ++++++- 5 files changed, 92 insertions(+), 43 deletions(-) diff --git a/src/blupi.cxx b/src/blupi.cxx index 9401758..8175146 100644 --- a/src/blupi.cxx +++ b/src/blupi.cxx @@ -86,6 +86,9 @@ struct url_data { }; #endif /* USE_CURL */ +static int Create (); +static void Release (); + template static void split (const std::string & s, char delim, Out result) @@ -394,6 +397,18 @@ HandleEvent (const SDL_Event & event) { switch (event.user.code) { + case EV_REINIT: + Release (); + + Display::getDisplay ().setDisplaySize ( + Display::getDisplay ().getLogicWidth (), + Display::getDisplay ().getLogicHeight ()); + g_zoom = 2; + g_bFullScreen = true; + g_settingsOverload |= SETTING_ZOOM | SETTING_FULLSCREEN; + Create (); + break; + case EV_UPDATE: if (!g_pEvent->IsMovie ()) // pas de film en cours ? { @@ -696,40 +711,11 @@ parseArgs (int argc, char * argv[], bool & exit) return EXIT_SUCCESS; } -// Main initialization function. - static int -DoInit (int argc, char * argv[], bool & exit) +Create () { - int rc = parseArgs (argc, argv, exit); - if (exit) - return rc; - Point totalDim, iconDim; Rect rcRect; - bool bOK; - - bOK = ReadConfig (); // lit le fichier config.json - - if (!bOK) // Something wrong with config.json file? - { - InitFail ("Game not correctly installed"); - return EXIT_FAILURE; - } - -#ifdef _WIN32 - /* Fix laggy sounds on Windows by not using winmm driver. */ - SDL_setenv ("SDL_AUDIODRIVER", "directsound", true); -#endif /* _WIN32 */ - - auto res = SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER); - if (res < 0) - { - SDL_Log ("Unable to initialize SDL: %s", SDL_GetError ()); - return EXIT_FAILURE; - } - - Display::getDisplay ().readDisplaySize (); // Create a window. g_window = SDL_CreateWindow ( @@ -1015,13 +1001,64 @@ DoInit (int argc, char * argv[], bool & exit) g_pPixmap->LoadCursors (); g_pPixmap->ChangeSprite (SPRITE_WAIT); - g_updateThread = new std::thread (CheckForUpdates); if (zoom != g_zoom) g_pEvent->SetWindowSize (g_zoom); g_pEvent->SetFullScreen (g_bFullScreen); g_pEvent->ChangePhase (EV_PHASE_INTRO1); - g_bTermInit = true; + return EXIT_SUCCESS; +} + +static void +Release () +{ + FinishObjects (); + + if (g_renderer) + SDL_DestroyRenderer (g_renderer); + + if (g_window) + SDL_DestroyWindow (g_window); +} + +// Main initialization function. + +static int +DoInit (int argc, char * argv[], bool & exit) +{ + int rc = parseArgs (argc, argv, exit); + if (exit) + return rc; + + bool bOK; + + bOK = ReadConfig (); // lit le fichier config.json + + if (!bOK) // Something wrong with config.json file? + { + InitFail ("Game not correctly installed"); + return EXIT_FAILURE; + } + +#ifdef _WIN32 + /* Fix laggy sounds on Windows by not using winmm driver. */ + SDL_setenv ("SDL_AUDIODRIVER", "directsound", true); +#endif /* _WIN32 */ + + auto res = SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER); + if (res < 0) + { + SDL_Log ("Unable to initialize SDL: %s", SDL_GetError ()); + return EXIT_FAILURE; + } + + Display::getDisplay ().readDisplaySize (); + + Create (); + + g_updateThread = new std::thread (CheckForUpdates); + g_bTermInit = true; + return EXIT_SUCCESS; } @@ -1061,13 +1098,7 @@ main (int argc, char * argv[]) } SDL_RemoveTimer (updateTimer); - FinishObjects (); - - if (g_renderer) - SDL_DestroyRenderer (g_renderer); - - if (g_window) - SDL_DestroyWindow (g_window); + Release (); SDL_Quit (); diff --git a/src/def.h b/src/def.h index a6166c2..7e7a157 100644 --- a/src/def.h +++ b/src/def.h @@ -399,6 +399,7 @@ enum ShiftDirection { #define EV_UPDATE (EV_OFFSET+1) #define EV_WARPMOUSE (EV_OFFSET+2) #define EV_CHECKUPDATE (EV_OFFSET+3) +#define EV_REINIT (EV_OFFSET+4) #define EV_DECOR1 (EV_OFFSET+20) #define EV_DECOR2 (EV_OFFSET+21) diff --git a/src/display.cxx b/src/display.cxx index af9a94c..aaf2df1 100644 --- a/src/display.cxx +++ b/src/display.cxx @@ -31,8 +31,14 @@ Display::readDisplaySize () if (res < 0) return; - this->width = displayMode.w; - this->height = displayMode.h; + this->setDisplaySize (displayMode.w, displayMode.h); +} + +void +Display::setDisplaySize (Sint32 width, Sint32 height) +{ + this->width = width; + this->height = height; if (this->width < this->getLogicWidth ()) this->width = this->getLogicWidth (); diff --git a/src/display.h b/src/display.h index 449f1d3..aea8f81 100644 --- a/src/display.h +++ b/src/display.h @@ -16,6 +16,7 @@ public: static Display & getDisplay (); void readDisplaySize (); + void setDisplaySize (Sint32 width, Sint32 height); Sint32 getWidth (); Sint32 getHeight (); Sint32 getLogicWidth (); diff --git a/src/event.cxx b/src/event.cxx index 6dd0b77..7e4a290 100644 --- a/src/event.cxx +++ b/src/event.cxx @@ -1752,8 +1752,16 @@ CEvent::SetFullScreen (bool bFullScreen, double prevScale) /* It seems that the fullscreen switching works better when the window * is at the top left corner of the current display. */ - SDL_SetWindowPosition ( - g_window, displayBounds[displayIndex].x, displayBounds[displayIndex].y); + //SDL_SetWindowPosition ( + // g_window, displayBounds[displayIndex].x, displayBounds[displayIndex].y); + + int w, h; + SDL_GetWindowSize (g_window, &w, &h); + if (w != Display::getDisplay ().getWidth ()) + { + CEvent::PushUserEvent (EV_REINIT); + return; + } } SDL_SetWindowFullscreen ( @@ -1761,7 +1769,9 @@ CEvent::SetFullScreen (bool bFullScreen, double prevScale) : SDL_WINDOW_FULLSCREEN) : 0); SDL_SetWindowBordered (g_window, bFullScreen ? SDL_FALSE : SDL_TRUE); +#ifndef DEBUG SDL_SetWindowGrab (g_window, bFullScreen ? SDL_TRUE : SDL_FALSE); +#endif /* !DEBUG */ m_pPixmap->LoadCursors ();