2017-01-21 17:27:46 +01:00
|
|
|
|
// blupi.cpp
|
|
|
|
|
//
|
|
|
|
|
|
2017-01-23 00:20:27 +01:00
|
|
|
|
#include "blupi.h"
|
|
|
|
|
|
2017-01-21 17:27:46 +01:00
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
|
2017-01-22 01:03:16 +01:00
|
|
|
|
#define SDL_MAIN_HANDLED
|
|
|
|
|
#include <SDL.h>
|
2017-01-21 17:27:46 +01:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "def.h"
|
|
|
|
|
#include "resource.h"
|
|
|
|
|
#include "pixmap.h"
|
|
|
|
|
#include "sound.h"
|
|
|
|
|
#include "decor.h"
|
|
|
|
|
#include "movie.h"
|
|
|
|
|
#include "button.h"
|
|
|
|
|
#include "menu.h"
|
|
|
|
|
#include "jauge.h"
|
|
|
|
|
#include "event.h"
|
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// D<>finitions globales
|
|
|
|
|
|
|
|
|
|
#define NAME "Blupi"
|
|
|
|
|
#define TITLE "Blupi"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Variables globales
|
|
|
|
|
|
2017-01-22 01:03:28 +01:00
|
|
|
|
SDL_Window *g_window;
|
2017-01-25 21:46:51 +01:00
|
|
|
|
SDL_Renderer *g_renderer;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
CEvent* g_pEvent = nullptr;
|
|
|
|
|
CPixmap* g_pPixmap = nullptr; // pixmap principal
|
|
|
|
|
CSound* g_pSound = nullptr; // sound principal
|
|
|
|
|
CMovie* g_pMovie = nullptr; // movie principal
|
|
|
|
|
CDecor* g_pDecor = nullptr;
|
2017-01-22 00:10:12 +01:00
|
|
|
|
bool g_bFullScreen = false; // false si mode de test
|
2017-01-21 17:27:46 +01:00
|
|
|
|
int g_speedRate = 1;
|
|
|
|
|
int g_timerInterval = 50; // inverval = 50ms
|
|
|
|
|
int g_mouseType = MOUSETYPEGRA;
|
2017-01-22 00:10:12 +01:00
|
|
|
|
bool g_bActive = true; // is application active ?
|
|
|
|
|
bool g_bTermInit = false; // initialisation en cours
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
UINT g_lastPhase = 999;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Lit un num<75>ro d<>cimal.
|
|
|
|
|
|
|
|
|
|
int GetNum(char *p)
|
|
|
|
|
{
|
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
|
|
while ( *p >= '0' && *p <= '9' )
|
|
|
|
|
{
|
|
|
|
|
n *= 10;
|
|
|
|
|
n += (*p++)-'0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lit le fichier de configuration.
|
|
|
|
|
|
2017-01-22 00:10:12 +01:00
|
|
|
|
bool ReadConfig(LPSTR lpCmdLine)
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-02-05 17:54:12 +01:00
|
|
|
|
FILE* file = nullptr;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
char buffer[200];
|
|
|
|
|
char* pText;
|
2017-01-22 00:26:57 +01:00
|
|
|
|
size_t nb;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
file = fopen("data\\config.def", "rb");
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( file == nullptr ) return false;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
nb = fread(buffer, sizeof(char), 200-1, file);
|
|
|
|
|
buffer[nb] = 0;
|
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
|
|
pText = strstr(buffer, "SpeedRate=");
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( pText != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
g_speedRate = GetNum(pText+10);
|
|
|
|
|
if ( g_speedRate < 1 ) g_speedRate = 1;
|
|
|
|
|
if ( g_speedRate > 2 ) g_speedRate = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pText = strstr(buffer, "Timer=");
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( pText != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
g_timerInterval = GetNum(pText+6);
|
|
|
|
|
if ( g_timerInterval < 10 ) g_timerInterval = 10;
|
|
|
|
|
if ( g_timerInterval > 1000 ) g_timerInterval = 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pText = strstr(buffer, "FullScreen=");
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( pText != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-01-22 00:10:12 +01:00
|
|
|
|
g_bFullScreen = !!GetNum(pText+11);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
if ( g_bFullScreen != 0 ) g_bFullScreen = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pText = strstr(buffer, "MouseType=");
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( pText != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
g_mouseType = GetNum(pText+10);
|
|
|
|
|
if ( g_mouseType < 1 ) g_mouseType = 1;
|
|
|
|
|
if ( g_mouseType > 9 ) g_mouseType = 9;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return true;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mise <20> jour principale.
|
|
|
|
|
|
|
|
|
|
void UpdateFrame(void)
|
|
|
|
|
{
|
|
|
|
|
RECT clip, rcRect;
|
|
|
|
|
UINT phase;
|
|
|
|
|
POINT posMouse;
|
|
|
|
|
int i, term, speed;
|
|
|
|
|
|
|
|
|
|
posMouse = g_pEvent->GetLastMousePos();
|
|
|
|
|
|
|
|
|
|
phase = g_pEvent->GetPhase();
|
|
|
|
|
|
2017-02-05 10:55:29 +01:00
|
|
|
|
if (!(phase == g_lastPhase && phase == WM_PHASE_PLAY))
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
rcRect.left = 0;
|
|
|
|
|
rcRect.top = 0;
|
|
|
|
|
rcRect.right = LXIMAGE;
|
|
|
|
|
rcRect.bottom = LYIMAGE;
|
2017-02-05 10:48:20 +01:00
|
|
|
|
g_pPixmap->DrawImage(-1, CHBACK, rcRect); // dessine le fond
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( phase == WM_PHASE_INTRO1 ||
|
|
|
|
|
phase == WM_PHASE_INTRO2 )
|
|
|
|
|
{
|
|
|
|
|
g_pEvent->IntroStep();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( phase == WM_PHASE_PLAY )
|
|
|
|
|
{
|
|
|
|
|
clip.left = POSDRAWX;
|
|
|
|
|
clip.top = POSDRAWY+g_pDecor->GetInfoHeight();
|
|
|
|
|
clip.right = POSDRAWX+DIMDRAWX;
|
|
|
|
|
clip.bottom = POSDRAWY+DIMDRAWY;
|
|
|
|
|
|
|
|
|
|
if ( g_pEvent->IsShift() ) // shift en cours ?
|
|
|
|
|
{
|
|
|
|
|
g_pEvent->DecorAutoShift(posMouse);
|
|
|
|
|
g_pDecor->Build(clip, posMouse); // construit juste le d<>cor
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( !g_pEvent->GetPause() )
|
|
|
|
|
{
|
|
|
|
|
speed = g_pEvent->GetSpeed() * g_speedRate;
|
|
|
|
|
for ( i=0 ; i<speed ; i++ )
|
|
|
|
|
{
|
|
|
|
|
g_pDecor->BlupiStep(i==0); // avance tous les blupi
|
|
|
|
|
g_pDecor->MoveStep(i==0); // avance tous les d<>cors
|
|
|
|
|
g_pEvent->DemoStep(); // avance enregistrement/reproduction
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_pEvent->DecorAutoShift(posMouse);
|
|
|
|
|
g_pDecor->Build(clip, posMouse); // construit le d<>cor
|
|
|
|
|
g_pDecor->NextPhase(1); // refait la carte de temps en temps
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( phase == WM_PHASE_BUILD )
|
|
|
|
|
{
|
|
|
|
|
clip.left = POSDRAWX;
|
|
|
|
|
clip.top = POSDRAWY;
|
|
|
|
|
clip.right = POSDRAWX+DIMDRAWX;
|
|
|
|
|
clip.bottom = POSDRAWY+DIMDRAWY;
|
|
|
|
|
g_pEvent->DecorAutoShift(posMouse);
|
|
|
|
|
g_pDecor->Build(clip, posMouse); // construit le d<>cor
|
|
|
|
|
g_pDecor->NextPhase(-1); // refait la carte chaque fois
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( phase == WM_PHASE_INIT )
|
|
|
|
|
{
|
|
|
|
|
g_pEvent->DemoStep(); // d<>marre <20>v. d<>mo automatique
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_pEvent->DrawButtons();
|
|
|
|
|
|
|
|
|
|
g_lastPhase = phase;
|
|
|
|
|
|
|
|
|
|
if ( phase == WM_PHASE_H0MOVIE ||
|
|
|
|
|
phase == WM_PHASE_H1MOVIE ||
|
|
|
|
|
phase == WM_PHASE_H2MOVIE ||
|
|
|
|
|
phase == WM_PHASE_PLAYMOVIE ||
|
|
|
|
|
phase == WM_PHASE_WINMOVIE )
|
|
|
|
|
{
|
|
|
|
|
g_pEvent->MovieToStart(); // fait d<>marrer un film si n<>cessaire
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( phase == WM_PHASE_INSERT )
|
|
|
|
|
{
|
|
|
|
|
g_pEvent->TryInsert();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( phase == WM_PHASE_PLAY )
|
|
|
|
|
{
|
|
|
|
|
term = g_pDecor->IsTerminated();
|
|
|
|
|
if ( term == 1 ) g_pEvent->ChangePhase(WM_PHASE_LOST); // perdu
|
|
|
|
|
if ( term == 2 ) g_pEvent->ChangePhase(WM_PHASE_WINMOVIE); // gagn<67>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Benchmark()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
POINT pos = { 0, 0 };
|
|
|
|
|
|
|
|
|
|
g_pPixmap->DrawIcon(-1, 2, 10, pos, 0);
|
|
|
|
|
|
|
|
|
|
pos.x = 300;
|
|
|
|
|
pos.y = 350;
|
|
|
|
|
for ( i=0 ; i<10000 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
g_pPixmap->DrawIcon(-1, 2, i%4, pos, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_pPixmap->DrawIcon(-1, 2, 10, pos, 0);
|
|
|
|
|
g_pSound->Play(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Restitue le jeu apr<70>s une activation en mode fullScreen.
|
|
|
|
|
|
2017-01-22 00:10:12 +01:00
|
|
|
|
bool RestoreGame()
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pPixmap == nullptr ) return false;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
g_pEvent->RestoreGame();
|
2017-02-05 09:46:30 +01:00
|
|
|
|
return true;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lib<69>re le jeu avant une d<>sactivation en mode fullScreen.
|
|
|
|
|
|
2017-01-22 00:10:12 +01:00
|
|
|
|
bool FlushGame()
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pPixmap == nullptr ) return false;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
return g_pPixmap->Flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Finished with all objects we use; release them.
|
|
|
|
|
|
|
|
|
|
static void FinishObjects(void)
|
|
|
|
|
{
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pMovie != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
g_pEvent->StopMovie();
|
|
|
|
|
|
|
|
|
|
delete g_pMovie;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
g_pMovie = nullptr;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pEvent != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
delete g_pEvent;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
g_pEvent = nullptr;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pDecor != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
delete g_pDecor;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
g_pDecor = nullptr;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pSound != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
g_pSound->StopMusic(); // stoppe la musique Midi
|
|
|
|
|
|
|
|
|
|
delete g_pSound;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
g_pSound = nullptr;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pPixmap != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
delete g_pPixmap;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
g_pPixmap = nullptr;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 18:57:37 +01:00
|
|
|
|
void WindowProc2 (const SDL_Event &event)
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-01-30 22:08:08 +01:00
|
|
|
|
POINT totalDim, iconDim;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pEvent != nullptr &&
|
2017-02-04 18:57:37 +01:00
|
|
|
|
g_pEvent->TreatEvent(event) )
|
|
|
|
|
return;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
2017-02-04 18:57:37 +01:00
|
|
|
|
switch (event.type)
|
2017-01-29 22:23:37 +01:00
|
|
|
|
{
|
2017-02-04 18:57:37 +01:00
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
|
{
|
|
|
|
|
switch (event.window.event)
|
2017-01-30 21:51:32 +01:00
|
|
|
|
{
|
2017-02-04 18:57:37 +01:00
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
|
|
|
|
if (g_bFullScreen)
|
2017-01-29 22:23:37 +01:00
|
|
|
|
{
|
2017-02-04 18:57:37 +01:00
|
|
|
|
RestoreGame ();
|
|
|
|
|
g_lastPhase = 999;
|
2017-01-29 22:23:37 +01:00
|
|
|
|
}
|
2017-02-04 18:57:37 +01:00
|
|
|
|
if (!g_bFullScreen && g_bTermInit)
|
|
|
|
|
{
|
|
|
|
|
totalDim.x = 64;
|
|
|
|
|
totalDim.y = 66;
|
|
|
|
|
iconDim.x = 64;
|
|
|
|
|
iconDim.y = 66 / 2;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
g_pPixmap->Cache (CHHILI, "image\\hili.blp", totalDim, iconDim);
|
2017-02-04 18:57:37 +01:00
|
|
|
|
}
|
|
|
|
|
SDL_SetWindowTitle (g_window, "Blupi");
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if (g_pSound != nullptr) g_pSound->RestartMusic ();
|
2017-02-05 18:21:32 +01:00
|
|
|
|
if (g_pMovie)
|
|
|
|
|
g_pMovie->Resume ();
|
2017-02-04 18:57:37 +01:00
|
|
|
|
return;
|
2017-01-29 22:23:37 +01:00
|
|
|
|
|
2017-02-04 18:57:37 +01:00
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
|
|
|
|
if (g_bFullScreen)
|
2017-01-30 22:01:24 +01:00
|
|
|
|
{
|
2017-02-04 18:57:37 +01:00
|
|
|
|
FlushGame ();
|
2017-01-30 22:01:24 +01:00
|
|
|
|
}
|
2017-02-04 18:57:37 +01:00
|
|
|
|
SDL_SetWindowTitle (g_window, "Blupi -- stop");
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if (g_pSound != nullptr) g_pSound->SuspendMusic ();
|
2017-02-05 18:21:32 +01:00
|
|
|
|
if (g_pMovie)
|
|
|
|
|
g_pMovie->Pause ();
|
2017-02-04 18:57:37 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
|
switch (event.key.keysym.sym)
|
|
|
|
|
{
|
|
|
|
|
case SDLK_F5:
|
|
|
|
|
g_pEvent->SetSpeed (1);
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F6:
|
|
|
|
|
g_pEvent->SetSpeed (2);
|
2017-01-30 22:01:24 +01:00
|
|
|
|
break;
|
2017-02-04 18:57:37 +01:00
|
|
|
|
case SDLK_F7:
|
|
|
|
|
g_pEvent->SetSpeed (4);
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_F8:
|
|
|
|
|
g_pEvent->SetSpeed (8);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2017-01-30 22:01:24 +01:00
|
|
|
|
|
2017-02-04 18:57:37 +01:00
|
|
|
|
case SDL_USEREVENT:
|
|
|
|
|
{
|
|
|
|
|
switch (event.user.code)
|
2017-01-30 21:51:32 +01:00
|
|
|
|
{
|
2017-02-04 18:57:37 +01:00
|
|
|
|
case WM_TIMER:
|
|
|
|
|
case WM_UPDATE:
|
|
|
|
|
if (!g_pEvent->IsMovie ()) // pas de film en cours ?
|
2017-01-29 22:23:37 +01:00
|
|
|
|
{
|
2017-02-04 18:57:37 +01:00
|
|
|
|
if (g_bActive)
|
2017-01-30 21:51:32 +01:00
|
|
|
|
{
|
2017-02-04 18:57:37 +01:00
|
|
|
|
UpdateFrame ();
|
2017-01-30 21:51:32 +01:00
|
|
|
|
}
|
2017-02-04 18:57:37 +01:00
|
|
|
|
g_pPixmap->Display ();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2017-02-04 17:59:07 +01:00
|
|
|
|
|
2017-02-04 18:57:37 +01:00
|
|
|
|
case WM_MUSIC_STOP:
|
|
|
|
|
if (g_pSound->IsStoppedOnDemand ())
|
2017-02-04 17:59:07 +01:00
|
|
|
|
break;
|
2017-02-04 18:57:37 +01:00
|
|
|
|
|
2017-02-05 17:28:47 +01:00
|
|
|
|
g_pSound->RestartMusic ();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WM_MOVIE_PLAY:
|
|
|
|
|
if (!g_pMovie->Render ())
|
2017-02-04 18:57:37 +01:00
|
|
|
|
g_pEvent->StopMovie ();
|
2017-01-30 21:51:32 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-02-04 18:57:37 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-01-29 22:23:37 +01:00
|
|
|
|
}
|
2017-01-28 23:34:02 +01:00
|
|
|
|
}
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
// Erreur dans DoInit.
|
|
|
|
|
|
2017-01-22 00:10:12 +01:00
|
|
|
|
bool InitFail(char *msg, bool bDirectX)
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
char buffer[100];
|
|
|
|
|
|
|
|
|
|
if ( bDirectX ) strcpy(buffer, "DirectX Init FAILED\n(while ");
|
|
|
|
|
else strcpy(buffer, "Error (");
|
|
|
|
|
strcat(buffer, msg);
|
|
|
|
|
strcat(buffer, ")");
|
2017-02-05 09:15:08 +01:00
|
|
|
|
|
|
|
|
|
SDL_ShowSimpleMessageBox (SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR, "Error", buffer, g_window);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
FinishObjects();
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return false;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialisation de l'application.
|
|
|
|
|
|
2017-02-09 18:34:40 +01:00
|
|
|
|
static bool DoInit(LPSTR lpCmdLine, int nCmdShow)
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
POINT totalDim, iconDim;
|
|
|
|
|
RECT rcRect;
|
2017-01-22 00:10:12 +01:00
|
|
|
|
bool bOK;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
bOK = ReadConfig(lpCmdLine); // lit le fichier config.def
|
|
|
|
|
|
2017-01-22 01:03:16 +01:00
|
|
|
|
SDL_SetMainReady ();
|
2017-01-30 21:51:32 +01:00
|
|
|
|
auto res = SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER);
|
2017-01-22 01:03:16 +01:00
|
|
|
|
if (res < 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-01-21 17:27:46 +01:00
|
|
|
|
// Create a window.
|
|
|
|
|
if ( g_bFullScreen )
|
|
|
|
|
{
|
2017-01-22 01:03:28 +01:00
|
|
|
|
g_window = SDL_CreateWindow (
|
|
|
|
|
NAME,
|
|
|
|
|
0, 0,
|
|
|
|
|
GetSystemMetrics (SM_CXSCREEN),
|
|
|
|
|
GetSystemMetrics (SM_CYSCREEN),
|
|
|
|
|
SDL_WINDOW_FULLSCREEN
|
|
|
|
|
);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-01-26 19:11:36 +01:00
|
|
|
|
g_window = SDL_CreateWindow (NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, LXIMAGE, LYIMAGE, 0);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
2017-01-25 21:46:51 +01:00
|
|
|
|
|
2017-01-22 01:03:28 +01:00
|
|
|
|
if (!g_window)
|
|
|
|
|
{
|
2017-02-04 16:24:01 +01:00
|
|
|
|
printf (SDL_GetError ());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 17:28:47 +01:00
|
|
|
|
g_renderer = SDL_CreateRenderer (g_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_PRESENTVSYNC);
|
2017-02-04 16:24:01 +01:00
|
|
|
|
if (!g_renderer)
|
|
|
|
|
{
|
|
|
|
|
printf (SDL_GetError ());
|
|
|
|
|
SDL_DestroyWindow (g_window);
|
2017-01-22 01:03:28 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 17:28:47 +01:00
|
|
|
|
SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, "linear");
|
|
|
|
|
|
2017-01-21 17:27:46 +01:00
|
|
|
|
if ( !bOK ) // config.def pas correct ?
|
|
|
|
|
{
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Game not correctly installed", false);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cr<43>e le pixmap principal.
|
|
|
|
|
g_pPixmap = new CPixmap;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pPixmap == nullptr ) return InitFail("New pixmap", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = LXIMAGE;
|
|
|
|
|
totalDim.y = LYIMAGE;
|
2017-02-05 09:15:08 +01:00
|
|
|
|
if ( !g_pPixmap->Create(totalDim, g_bFullScreen, g_mouseType) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Create pixmap", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
OutputDebug("Image: init\n");
|
|
|
|
|
totalDim.x = LXIMAGE;
|
|
|
|
|
totalDim.y = LYIMAGE;
|
|
|
|
|
iconDim.x = 0;
|
|
|
|
|
iconDim.y = 0;
|
|
|
|
|
#if _INTRO
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHBACK, "image\\intro1.blp", totalDim, iconDim) )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
#else
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHBACK, "image\\init.blp", totalDim, iconDim) )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
#endif
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return false;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
OutputDebug("Image: init\n");
|
|
|
|
|
totalDim.x = LXIMAGE;
|
|
|
|
|
totalDim.y = LYIMAGE;
|
|
|
|
|
iconDim.x = 0;
|
|
|
|
|
iconDim.y = 0;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHGROUND, "image\\init.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return false;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
rcRect.left = 0;
|
|
|
|
|
rcRect.top = 0;
|
|
|
|
|
rcRect.right = LXIMAGE;
|
|
|
|
|
rcRect.bottom = LYIMAGE;
|
2017-02-05 10:48:20 +01:00
|
|
|
|
g_pPixmap->DrawImage(-1, CHBACK, rcRect); // dessine le fond
|
2017-01-21 17:27:46 +01:00
|
|
|
|
g_pPixmap->Display();
|
|
|
|
|
|
|
|
|
|
totalDim.x = DIMCELX*2*16;
|
|
|
|
|
totalDim.y = DIMCELY*2*6;
|
|
|
|
|
iconDim.x = DIMCELX*2;
|
|
|
|
|
iconDim.y = DIMCELY*2;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHFLOOR, "image\\floor000.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache floor000.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = DIMOBJX*16;
|
|
|
|
|
totalDim.y = DIMOBJY*8;
|
|
|
|
|
iconDim.x = DIMOBJX;
|
|
|
|
|
iconDim.y = DIMOBJY;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHOBJECT, "image\\obj000.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache obj000.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHOBJECTo, "image\\obj-o000.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache obj-o000.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = DIMBLUPIX*16;
|
|
|
|
|
totalDim.y = DIMBLUPIY*23;
|
|
|
|
|
iconDim.x = DIMBLUPIX;
|
|
|
|
|
iconDim.y = DIMBLUPIY;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHBLUPI, "image\\blupi.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache blupi.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = 64;
|
|
|
|
|
totalDim.y = 66;
|
|
|
|
|
iconDim.x = 64;
|
|
|
|
|
iconDim.y = 66/2;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHHILI, "image\\hili.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache hili.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = DIMCELX*2*3;
|
|
|
|
|
totalDim.y = DIMCELY*2*5;
|
|
|
|
|
iconDim.x = DIMCELX*2;
|
|
|
|
|
iconDim.y = DIMCELY*2;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHFOG, "image\\fog.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache fog.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = DIMCELX*2*16;
|
|
|
|
|
totalDim.y = DIMCELY*2*1;
|
|
|
|
|
iconDim.x = DIMCELX*2;
|
|
|
|
|
iconDim.y = DIMCELY*2;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHMASK1, "image\\mask1.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache mask1.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = DIMBUTTONX*6;
|
|
|
|
|
totalDim.y = DIMBUTTONY*21;
|
|
|
|
|
iconDim.x = DIMBUTTONX;
|
|
|
|
|
iconDim.y = DIMBUTTONY;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHBUTTON, "image\\button00.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache button00.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = DIMJAUGEX*1;
|
|
|
|
|
totalDim.y = DIMJAUGEY*4;
|
|
|
|
|
iconDim.x = DIMJAUGEX;
|
|
|
|
|
iconDim.y = DIMJAUGEY;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHJAUGE, "image\\jauge.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache jauge.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = DIMTEXTX*16;
|
|
|
|
|
totalDim.y = DIMTEXTY*8*3;
|
|
|
|
|
iconDim.x = DIMTEXTX;
|
|
|
|
|
iconDim.y = DIMTEXTY;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHTEXT, "image\\text.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache text.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = DIMLITTLEX*16;
|
|
|
|
|
totalDim.y = DIMLITTLEY*8;
|
|
|
|
|
iconDim.x = DIMLITTLEX;
|
|
|
|
|
iconDim.y = DIMLITTLEY;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHLITTLE, "image\\little.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache little.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
totalDim.x = 426;
|
|
|
|
|
totalDim.y = 52;
|
|
|
|
|
iconDim.x = 426;
|
|
|
|
|
iconDim.y = 52;
|
2017-02-05 09:57:43 +01:00
|
|
|
|
if ( !g_pPixmap->Cache(CHBIGNUM, "image\\bignum.blp", totalDim, iconDim) )
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return InitFail("Cache bignum.blp", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
2017-01-26 18:58:14 +01:00
|
|
|
|
// Load all cursors
|
|
|
|
|
g_pPixmap->LoadCursors ();
|
2017-01-28 23:34:02 +01:00
|
|
|
|
g_pPixmap->ChangeSprite (SPRITE_WAIT); // met le sablier maison
|
2017-01-26 18:58:14 +01:00
|
|
|
|
|
2017-01-21 17:27:46 +01:00
|
|
|
|
// Cr<43>e le gestionnaire de son.
|
|
|
|
|
g_pSound = new CSound;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pSound == nullptr ) return InitFail("New sound", true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
2017-02-04 16:48:26 +01:00
|
|
|
|
g_pSound->Create();
|
2017-01-21 17:27:46 +01:00
|
|
|
|
g_pSound->CacheAll();
|
2017-01-22 00:10:12 +01:00
|
|
|
|
g_pSound->SetState(true);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
// Cr<43>e le gestionnaire de films.
|
|
|
|
|
g_pMovie = new CMovie;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pMovie == nullptr ) return InitFail("New movie", false);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
g_pMovie->Create();
|
|
|
|
|
|
|
|
|
|
// Cr<43>e le gestionnaire de d<>cors.
|
|
|
|
|
g_pDecor = new CDecor;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pDecor == nullptr ) return InitFail("New decor", false);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
2017-02-05 09:15:08 +01:00
|
|
|
|
g_pDecor->Create(g_pSound, g_pPixmap);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
g_pDecor->MapInitColors();
|
|
|
|
|
|
|
|
|
|
// Cr<43>e le gestionnaire d'<27>v<EFBFBD>nements.
|
|
|
|
|
g_pEvent = new CEvent;
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( g_pEvent == nullptr ) return InitFail("New event", false);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
2017-02-05 09:15:08 +01:00
|
|
|
|
g_pEvent->Create(g_pPixmap, g_pDecor, g_pSound, g_pMovie);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
g_pEvent->SetFullScreen(g_bFullScreen);
|
|
|
|
|
g_pEvent->SetMouseType(g_mouseType);
|
|
|
|
|
#if _INTRO
|
|
|
|
|
g_pEvent->ChangePhase(WM_PHASE_INTRO1);
|
|
|
|
|
#else
|
|
|
|
|
g_pEvent->ChangePhase(WM_PHASE_TESTCD);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-01-22 00:10:12 +01:00
|
|
|
|
g_bTermInit = true; // initialisation termin<69>e
|
|
|
|
|
return true;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Programme principal.
|
|
|
|
|
|
|
|
|
|
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|
|
|
|
LPSTR lpCmdLine, int nCmdShow)
|
|
|
|
|
{
|
2017-02-09 18:34:40 +01:00
|
|
|
|
if (!DoInit(lpCmdLine, nCmdShow))
|
2017-01-22 00:10:12 +01:00
|
|
|
|
return false;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
2017-02-02 17:57:51 +01:00
|
|
|
|
SDL_TimerID updateTimer = SDL_AddTimer (g_timerInterval, [] (Uint32 interval, void *param) -> Uint32
|
2017-01-30 21:51:32 +01:00
|
|
|
|
{
|
|
|
|
|
CEvent::PushUserEvent (WM_UPDATE);
|
|
|
|
|
return interval;
|
|
|
|
|
}, nullptr);
|
|
|
|
|
|
2017-02-05 09:24:52 +01:00
|
|
|
|
SDL_Event event;
|
|
|
|
|
while (SDL_WaitEvent (&event))
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-02-05 09:24:52 +01:00
|
|
|
|
WindowProc2 (event);
|
|
|
|
|
|
|
|
|
|
if (event.type == SDL_QUIT)
|
|
|
|
|
break;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-22 01:03:28 +01:00
|
|
|
|
if (g_window)
|
|
|
|
|
SDL_DestroyWindow (g_window);
|
|
|
|
|
|
2017-02-02 17:57:51 +01:00
|
|
|
|
SDL_RemoveTimer (updateTimer);
|
2017-02-02 18:01:56 +01:00
|
|
|
|
FinishObjects ();
|
2017-01-22 01:03:16 +01:00
|
|
|
|
SDL_Quit ();
|
2017-02-05 09:24:52 +01:00
|
|
|
|
return 0;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|