1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

WIP: experiment a reinit (buggy)

This commit is contained in:
Mathieu Schroeter 2018-06-28 00:03:37 +02:00
parent 190147015d
commit 979dacd151
5 changed files with 92 additions and 43 deletions

View File

@ -86,6 +86,9 @@ struct url_data {
}; };
#endif /* USE_CURL */ #endif /* USE_CURL */
static int Create ();
static void Release ();
template <typename Out> template <typename Out>
static void static void
split (const std::string & s, char delim, Out result) split (const std::string & s, char delim, Out result)
@ -394,6 +397,18 @@ HandleEvent (const SDL_Event & event)
{ {
switch (event.user.code) 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: case EV_UPDATE:
if (!g_pEvent->IsMovie ()) // pas de film en cours ? if (!g_pEvent->IsMovie ()) // pas de film en cours ?
{ {
@ -696,40 +711,11 @@ parseArgs (int argc, char * argv[], bool & exit)
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
// Main initialization function.
static int static int
DoInit (int argc, char * argv[], bool & exit) Create ()
{ {
int rc = parseArgs (argc, argv, exit);
if (exit)
return rc;
Point totalDim, iconDim; Point totalDim, iconDim;
Rect rcRect; 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. // Create a window.
g_window = SDL_CreateWindow ( g_window = SDL_CreateWindow (
@ -1015,13 +1001,64 @@ DoInit (int argc, char * argv[], bool & exit)
g_pPixmap->LoadCursors (); g_pPixmap->LoadCursors ();
g_pPixmap->ChangeSprite (SPRITE_WAIT); g_pPixmap->ChangeSprite (SPRITE_WAIT);
g_updateThread = new std::thread (CheckForUpdates);
if (zoom != g_zoom) if (zoom != g_zoom)
g_pEvent->SetWindowSize (g_zoom); g_pEvent->SetWindowSize (g_zoom);
g_pEvent->SetFullScreen (g_bFullScreen); g_pEvent->SetFullScreen (g_bFullScreen);
g_pEvent->ChangePhase (EV_PHASE_INTRO1); 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; return EXIT_SUCCESS;
} }
@ -1061,13 +1098,7 @@ main (int argc, char * argv[])
} }
SDL_RemoveTimer (updateTimer); SDL_RemoveTimer (updateTimer);
FinishObjects (); Release ();
if (g_renderer)
SDL_DestroyRenderer (g_renderer);
if (g_window)
SDL_DestroyWindow (g_window);
SDL_Quit (); SDL_Quit ();

View File

@ -399,6 +399,7 @@ enum ShiftDirection {
#define EV_UPDATE (EV_OFFSET+1) #define EV_UPDATE (EV_OFFSET+1)
#define EV_WARPMOUSE (EV_OFFSET+2) #define EV_WARPMOUSE (EV_OFFSET+2)
#define EV_CHECKUPDATE (EV_OFFSET+3) #define EV_CHECKUPDATE (EV_OFFSET+3)
#define EV_REINIT (EV_OFFSET+4)
#define EV_DECOR1 (EV_OFFSET+20) #define EV_DECOR1 (EV_OFFSET+20)
#define EV_DECOR2 (EV_OFFSET+21) #define EV_DECOR2 (EV_OFFSET+21)

View File

@ -31,8 +31,14 @@ Display::readDisplaySize ()
if (res < 0) if (res < 0)
return; return;
this->width = displayMode.w; this->setDisplaySize (displayMode.w, displayMode.h);
this->height = displayMode.h; }
void
Display::setDisplaySize (Sint32 width, Sint32 height)
{
this->width = width;
this->height = height;
if (this->width < this->getLogicWidth ()) if (this->width < this->getLogicWidth ())
this->width = this->getLogicWidth (); this->width = this->getLogicWidth ();

View File

@ -16,6 +16,7 @@ public:
static Display & getDisplay (); static Display & getDisplay ();
void readDisplaySize (); void readDisplaySize ();
void setDisplaySize (Sint32 width, Sint32 height);
Sint32 getWidth (); Sint32 getWidth ();
Sint32 getHeight (); Sint32 getHeight ();
Sint32 getLogicWidth (); Sint32 getLogicWidth ();

View File

@ -1752,8 +1752,16 @@ CEvent::SetFullScreen (bool bFullScreen, double prevScale)
/* It seems that the fullscreen switching works better when the window /* It seems that the fullscreen switching works better when the window
* is at the top left corner of the current display. * is at the top left corner of the current display.
*/ */
SDL_SetWindowPosition ( //SDL_SetWindowPosition (
g_window, displayBounds[displayIndex].x, displayBounds[displayIndex].y); // 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 ( SDL_SetWindowFullscreen (
@ -1761,7 +1769,9 @@ CEvent::SetFullScreen (bool bFullScreen, double prevScale)
: SDL_WINDOW_FULLSCREEN) : SDL_WINDOW_FULLSCREEN)
: 0); : 0);
SDL_SetWindowBordered (g_window, bFullScreen ? SDL_FALSE : SDL_TRUE); SDL_SetWindowBordered (g_window, bFullScreen ? SDL_FALSE : SDL_TRUE);
#ifndef DEBUG
SDL_SetWindowGrab (g_window, bFullScreen ? SDL_TRUE : SDL_FALSE); SDL_SetWindowGrab (g_window, bFullScreen ? SDL_TRUE : SDL_FALSE);
#endif /* !DEBUG */
m_pPixmap->LoadCursors (); m_pPixmap->LoadCursors ();