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

Convert timer stuff to SDL timer

This commit is contained in:
Mathieu Schroeter 2017-01-30 21:51:32 +01:00
parent 36b44d9578
commit 795875e6a4

103
blupi.cpp
View File

@ -380,18 +380,6 @@ LRESULT CALLBACK WindowProc2 (HWND hWnd, UINT message,
switch( message ) switch( message )
{ {
case WM_TIMER:
case WM_UPDATE:
if ( !g_pEvent->IsMovie() ) // pas de film en cours ?
{
if ( g_bActive )
{
UpdateFrame();
}
g_pPixmap->Display();
}
break;
case WM_CREATE: case WM_CREATE:
hInstance = ((LPCREATESTRUCT)lParam)->hInstance; hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
return 0; return 0;
@ -464,40 +452,66 @@ LRESULT CALLBACK WindowProc2 (HWND hWnd, UINT message,
break; break;
} }
if (event && event->type == SDL_WINDOWEVENT) if (event)
{ {
switch (event->window.event) switch (event->type)
{ {
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT:
if (g_bFullScreen) {
switch (event->window.event)
{ {
RestoreGame (); case SDL_WINDOWEVENT_FOCUS_GAINED:
g_lastPhase = 999; if (g_bFullScreen)
} {
if (!g_bFullScreen && g_bTermInit) RestoreGame ();
{ g_lastPhase = 999;
totalDim.x = 64; }
totalDim.y = 66; if (!g_bFullScreen && g_bTermInit)
iconDim.x = 64; {
iconDim.y = 66 / 2; totalDim.x = 64;
g_pPixmap->Cache (CHHILI, "image\\hili.blp", totalDim, iconDim, true); totalDim.y = 66;
g_pPixmap->SetTransparent (CHHILI, RGB (0, 0, 255)); // bleu iconDim.x = 64;
iconDim.y = 66 / 2;
g_pPixmap->Cache (CHHILI, "image\\hili.blp", totalDim, iconDim, true);
g_pPixmap->SetTransparent (CHHILI, RGB (0, 0, 255)); // bleu
g_pPixmap->SavePalette (); g_pPixmap->SavePalette ();
g_pPixmap->InitSysPalette (); g_pPixmap->InitSysPalette ();
} }
SDL_SetWindowTitle (g_window, "Blupi"); SDL_SetWindowTitle (g_window, "Blupi");
if (g_pSound != NULL) g_pSound->RestartMusic (); if (g_pSound != NULL) g_pSound->RestartMusic ();
return 0; return 0;
case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_FOCUS_LOST:
if (g_bFullScreen) if (g_bFullScreen)
{ {
FlushGame (); FlushGame ();
}
SDL_SetWindowTitle (g_window, "Blupi -- stop");
if (g_pSound != NULL) g_pSound->SuspendMusic ();
return 0;
} }
SDL_SetWindowTitle (g_window, "Blupi -- stop"); break;
if (g_pSound != NULL) g_pSound->SuspendMusic (); }
return 0;
case SDL_USEREVENT:
{
switch (event->user.code)
{
case WM_TIMER:
case WM_UPDATE:
if (!g_pEvent->IsMovie ()) // pas de film en cours ?
{
if (g_bActive)
{
UpdateFrame ();
}
g_pPixmap->Display ();
}
break;
}
break;
}
} }
} }
@ -555,7 +569,7 @@ static bool DoInit(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow)
RegisterClass(&wc); RegisterClass(&wc);
SDL_SetMainReady (); SDL_SetMainReady ();
auto res = SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO); auto res = SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER);
if (res < 0) if (res < 0)
return false; return false;
@ -825,7 +839,12 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
return false; return false;
} }
SetTimer(g_hWnd, 1, g_timerInterval, NULL); SDL_TimerID my_timer_id = SDL_AddTimer (g_timerInterval, [] (Uint32 interval, void *param) -> Uint32
{
CEvent::PushUserEvent (WM_UPDATE);
return interval;
}, nullptr);
while (SDL_TRUE) while (SDL_TRUE)
{ {