diff --git a/action.h b/action.h index 4205fbc..476e950 100644 --- a/action.h +++ b/action.h @@ -3,6 +3,8 @@ #pragma once +#include "blupi.h" + extern bool Action(short action, short direct, short &phase, short &step, diff --git a/blupi.cpp b/blupi.cpp index 65ba810..f9a057b 100644 --- a/blupi.cpp +++ b/blupi.cpp @@ -40,7 +40,7 @@ int g_mouseType = MOUSETYPEGRA; bool g_bActive = true; // is application active ? bool g_bTermInit = false; // initialisation en cours -UINT g_lastPhase = 999; +unsigned int g_lastPhase = 999; @@ -115,7 +115,7 @@ bool ReadConfig(int argc, char *argv[]) void UpdateFrame(void) { RECT clip, rcRect; - UINT phase; + unsigned int phase; POINT posMouse; int i, term, speed; @@ -360,7 +360,6 @@ void WindowProc2 (const SDL_Event &event) { switch (event.user.code) { - case WM_TIMER: case WM_UPDATE: if (!g_pEvent->IsMovie ()) // pas de film en cours ? { @@ -423,13 +422,7 @@ static bool DoInit(int argc, char *argv[]) // Create a window. if ( g_bFullScreen ) { - g_window = SDL_CreateWindow ( - NAME, - 0, 0, - GetSystemMetrics (SM_CXSCREEN), - GetSystemMetrics (SM_CYSCREEN), - SDL_WINDOW_FULLSCREEN - ); + g_window = SDL_CreateWindow (NAME, 0, 0, LXIMAGE, LYIMAGE, SDL_WINDOW_FULLSCREEN); } else { diff --git a/blupi.h b/blupi.h index 7d0308a..93a84da 100644 --- a/blupi.h +++ b/blupi.h @@ -5,3 +5,46 @@ extern SDL_Window *g_window; extern SDL_Renderer *g_renderer; + +struct POINT +{ + long x; + long y; +}; + +struct RECT +{ + long left; + long top; + long right; + long bottom; +}; + +typedef unsigned long COLORREF; + +#if defined(_WIN64) +typedef unsigned __int64 WPARAM; +typedef __int64 LPARAM; +#else +typedef unsigned int WPARAM; +typedef long LPARAM; +#endif + +#define LOWORD(l) ((unsigned short)(((unsigned long)(l)) & 0xffff)) +#define HIWORD(l) ((unsigned short)((((unsigned long)(l)) >> 16) & 0xffff)) + +#define MAX_PATH 260 + +#define VK_END 0x23 +#define VK_LEFT 0x25 +#define VK_UP 0x26 +#define VK_RIGHT 0x27 +#define VK_DOWN 0x28 + +#define WM_KEYDOWN 0x0100 +#define WM_KEYUP 0x0101 +#define WM_MOUSEMOVE 0x0200 +#define WM_LBUTTONDOWN 0x0201 +#define WM_LBUTTONUP 0x0202 +#define WM_RBUTTONDOWN 0x0204 +#define WM_RBUTTONUP 0x0205 diff --git a/button.cpp b/button.cpp index ca2baea..345f6aa 100644 --- a/button.cpp +++ b/button.cpp @@ -45,7 +45,7 @@ bool CButton::Create(CPixmap *pPixmap, CSound *pSound, POINT pos, int type, bool bMinimizeRedraw, int *pMenu, int nbMenu, const char **pToolTips, - int region, UINT message) + int region, unsigned int message) { POINT iconDim; int i, icon; diff --git a/button.h b/button.h index ba54ce6..945a749 100644 --- a/button.h +++ b/button.h @@ -16,7 +16,7 @@ public: POINT pos, int type, bool bMinimizeRedraw, int *pMenu, int nbMenu, const char **pToolTips, - int region, UINT message); + int region, unsigned int message); void Draw(); void Redraw(); @@ -50,7 +50,7 @@ protected: int m_type; // type de bouton bool m_bEnable; // true si bouton actif bool m_bHide; // true si bouton caché - UINT m_message; // message envoyé si bouton actionné + unsigned int m_message; // message envoyé si bouton actionné POINT m_pos; // coin sup/gauche POINT m_dim; // dimensions int m_state; // 0=relâché, 1=pressé, +2=survollé diff --git a/chemin.cpp b/chemin.cpp index 2797bdc..f940a9c 100644 --- a/chemin.cpp +++ b/chemin.cpp @@ -286,7 +286,7 @@ bool CDecor::CheminCherche(int rank, int &action) return false; } - memset(m_cheminWork, 0, (BYTE)MAXCELX*(BYTE)MAXCELY); + memset(m_cheminWork, 0, (Uint8)MAXCELX*(Uint8)MAXCELY); CheminMemPos(rank); // fait un remplissage du map de travail diff --git a/decmap.cpp b/decmap.cpp index 4d2b28d..4204863 100644 --- a/decmap.cpp +++ b/decmap.cpp @@ -483,7 +483,6 @@ void CDecor::MapPutCel(POINT pos) bool CDecor::GenerateMap() { - HBITMAP hbm; POINT dim, pos, cel; int dx, rank, i; @@ -535,11 +534,6 @@ bool CDecor::GenerateMap() g_map32_bits[i][pos.x+MAPCADREX] = m_colors[MAP_CADRE]; } - - hbm = CreateBitmap(DIMMAPX, DIMMAPY, 1, 32, g_map32_bits); - - if ( hbm == nullptr ) return false; - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(g_map32_bits, DIMMAPX, DIMMAPY, 32, 4 * DIMMAPX, 0, 0, 0, 0); dim.x = DIMMAPX; @@ -550,7 +544,7 @@ bool CDecor::GenerateMap() pos.y = POSMAPY; m_pPixmap->DrawIcon(-1, CHMAP, 0, pos); - DeleteObject(hbm); + SDL_FreeSurface (surface); return true; } diff --git a/decor.h b/decor.h index 9bf7ce1..03ed178 100644 --- a/decor.h +++ b/decor.h @@ -516,7 +516,7 @@ protected: int m_infoHeight; POINT m_memoPos[4]; - BYTE m_cheminWork[MAXCELX*MAXCELY]; + Uint8 m_cheminWork[MAXCELX*MAXCELY]; int m_cheminNbPos; POINT m_cheminPos[MAXBLUPI*2]; int m_cheminRank[MAXBLUPI*2]; diff --git a/def.h b/def.h index 952302c..2bb32d1 100644 --- a/def.h +++ b/def.h @@ -3,8 +3,6 @@ #pragma once -#include - #define _INTRO false // true si images d'introduction @@ -370,7 +368,7 @@ enum MouseSprites }; -// User define message +#define WM_USER 0x0400 #define WM_UPDATE (WM_USER+1) diff --git a/event.cpp b/event.cpp index ec7818c..71648f1 100644 --- a/event.cpp +++ b/event.cpp @@ -1573,7 +1573,7 @@ int CEvent::GetButtonIndex(int button) while ( table[m_index].buttons[i].message != 0 ) { - if ( (UINT)button == table[m_index].buttons[i].message ) + if ( (unsigned int) button == table[m_index].buttons[i].message ) { return i; } @@ -1753,7 +1753,7 @@ void AddCheatCode(char *pDst, char *pSrc) j = strlen(pDst); while ( pSrc[i] != 0 ) { - pDst[j++] = tolower(pSrc[i++]); + pDst[j++] = pSrc[i++]; } pDst[j] = 0; } @@ -2689,7 +2689,7 @@ bool CEvent::MouseOnButton(POINT pos) // Retourne l'index dans table pour une phase donnée. -int CEvent::SearchPhase(UINT phase) +int CEvent::SearchPhase(unsigned int phase) { int i=0; @@ -2747,7 +2747,7 @@ bool CEvent::IsHelpHide() // Change de phase. -bool CEvent::ChangePhase(UINT phase) +bool CEvent::ChangePhase(unsigned int phase) { int index, world, time, total, music, i, max; POINT totalDim, iconDim; @@ -3151,7 +3151,7 @@ bool CEvent::ChangePhase(UINT phase) // Retourne la phase en cours. -UINT CEvent::GetPhase() +unsigned int CEvent::GetPhase() { return m_phase; } @@ -4349,7 +4349,7 @@ void CEvent::DemoRecStop() if ( m_pDemoBuffer != nullptr ) { - DeleteFile("data\\demo.blp"); + _unlink ("data\\demo.blp"); file = fopen("data\\demo.blp", "wb"); if ( file != nullptr ) { @@ -4442,12 +4442,12 @@ void CEvent::DemoPlayStop() ChangePhase(WM_PHASE_INIT); } -void CEvent::WinToSDLEvent (UINT msg, WPARAM wParam, LPARAM lParam, SDL_Event &event) +void CEvent::WinToSDLEvent (unsigned int msg, WPARAM wParam, LPARAM lParam, SDL_Event &event) { #define GET_X_LPARAM(lp) ((int) (short) LOWORD (lp)) #define GET_Y_LPARAM(lp) ((int) (short) HIWORD (lp)) - static const std::unordered_map keycodes = { + static const std::unordered_map keycodes = { { '0', { SDL_SCANCODE_0, SDLK_0, 0, 0 } }, { '1', { SDL_SCANCODE_1, SDLK_1, 0, 0 } }, { '2', { SDL_SCANCODE_2, SDLK_2, 0, 0 } }, @@ -4539,7 +4539,7 @@ void CEvent::WinToSDLEvent (UINT msg, WPARAM wParam, LPARAM lParam, SDL_Event &e void CEvent::DemoStep() { int time; - UINT message; + unsigned int message; WPARAM wParam; LPARAM lParam; @@ -4593,7 +4593,7 @@ void CEvent::DemoStep() // Mémorise un événement. -void CEvent::DemoRecEvent(UINT message, WPARAM wParam, LPARAM lParam) +void CEvent::DemoRecEvent(unsigned int message, WPARAM wParam, LPARAM lParam) { if ( m_bDemoRec && m_pDemoBuffer != nullptr && (message == WM_KEYDOWN || @@ -4609,15 +4609,15 @@ void CEvent::DemoRecEvent(UINT message, WPARAM wParam, LPARAM lParam) m_pDemoBuffer[m_demoIndex-1].time == m_demoTime && m_pDemoBuffer[m_demoIndex-1].message == message ) { - m_pDemoBuffer[m_demoIndex-1].wParam = static_cast (wParam); - m_pDemoBuffer[m_demoIndex-1].lParam = static_cast (lParam); + m_pDemoBuffer[m_demoIndex-1].wParam = static_cast (wParam); + m_pDemoBuffer[m_demoIndex-1].lParam = static_cast (lParam); } else { m_pDemoBuffer[m_demoIndex].time = m_demoTime; m_pDemoBuffer[m_demoIndex].message = message; - m_pDemoBuffer[m_demoIndex].wParam = static_cast (wParam); - m_pDemoBuffer[m_demoIndex].lParam = static_cast (lParam); + m_pDemoBuffer[m_demoIndex].wParam = static_cast (wParam); + m_pDemoBuffer[m_demoIndex].lParam = static_cast (lParam); m_demoIndex ++; if ( m_demoIndex >= MAXDEMO ) @@ -4992,7 +4992,6 @@ bool CEvent::TreatEventBase(const SDL_Event &event) case SDLK_LCTRL: case SDLK_RCTRL: m_keymod &= ~KMOD_CTRL; - OutputDebugString ("CTRL: UP"); m_bFillMouse = false; MouseSprite(GetMousePos()); return true; diff --git a/event.h b/event.h index 3713056..e2cd660 100644 --- a/event.h +++ b/event.h @@ -4,6 +4,7 @@ #include #include +#include "blupi.h" #include "jauge.h" #include "menu.h" #include "button.h" @@ -14,7 +15,7 @@ class CMovie; typedef struct { - UINT message; + unsigned int message; int type; int iconMenu[20]; int x, y; @@ -24,7 +25,7 @@ Button; typedef struct { - UINT phase; + unsigned int phase; char backName[20]; int bCDrom; Button buttons[MAXBUTTON]; @@ -47,9 +48,9 @@ DemoHeader; typedef struct { int time; - UINT message; - UINT wParam; // WPARAM - UINT lParam; // LPARAM + unsigned int message; + unsigned int wParam; // WPARAM + unsigned int lParam; // LPARAM } DemoEvent; @@ -68,9 +69,9 @@ public: int GetPhysicalWorld(); int GetImageWorld(); bool IsHelpHide(); - bool ChangePhase(UINT phase); + bool ChangePhase(unsigned int phase); void MovieToStart(); - UINT GetPhase(); + unsigned int GetPhase(); void TryInsert(); void RestoreGame(); @@ -119,7 +120,7 @@ protected: bool CreateButtons(); bool EventButtons(const SDL_Event &event, POINT pos); bool MouseOnButton(POINT pos); - int SearchPhase(UINT phase); + int SearchPhase(unsigned int phase); void DecorShift(int dx, int dy); bool PlayDown(POINT pos, const SDL_Event &event); @@ -142,8 +143,8 @@ protected: void DemoRecStop(); bool DemoPlayStart(); void DemoPlayStop(); - static void WinToSDLEvent (UINT msg, WPARAM wParam, LPARAM lParam, SDL_Event &event); - void DemoRecEvent(UINT message, WPARAM wParam, LPARAM lParam); + static void WinToSDLEvent (unsigned int msg, WPARAM wParam, LPARAM lParam, SDL_Event &event); + void DemoRecEvent(unsigned int message, WPARAM wParam, LPARAM lParam); protected: int m_speed; diff --git a/menu.h b/menu.h index d0d1c26..4fe471e 100644 --- a/menu.h +++ b/menu.h @@ -47,7 +47,7 @@ protected: int m_buttons[MAXBUTTON]; int m_errors[MAXBUTTON]; std::unordered_map m_texts; - UINT m_messages[MAXBUTTON]; + unsigned int m_messages[MAXBUTTON]; int m_selRank; }; diff --git a/misc.cpp b/misc.cpp index d28bd85..4731ae1 100644 --- a/misc.cpp +++ b/misc.cpp @@ -1,12 +1,15 @@ // misc.cpp // +#include #include #include #include +#include +#include +#include "blupi.h" #include "def.h" - // Variables globales extern bool g_bFullScreen; // false si mode de test @@ -17,9 +20,7 @@ extern int g_mouseType; void OutputDebug(char *pMessage) { -#ifdef _DEBUG - OutputDebugString(pMessage); -#endif + SDL_LogDebug (SDL_LOG_CATEGORY_APPLICATION, "%s", pMessage); } // Conversion de la position de la souris. @@ -65,18 +66,13 @@ int Random(int min, int max) void GetCurrentDir(char *pName, size_t lg) { - size_t i; - - strncpy(pName, _pgmptr, lg-1); + char *basePath = SDL_GetBasePath (); + strncpy(pName, basePath, lg-1); pName[lg-1] = 0; lg = strlen(pName); - if ( lg == 0 ) return; - - for ( i=0 ; i 0 ) { @@ -88,10 +84,13 @@ void GetCurrentDir(char *pName, size_t lg) } } - if ( lg > 6 && strcmp(pName+lg-6, "\\debug\\") == 0 ) + if ( lg > 6 && strcmp(pName+lg-6, "\\Debug\\") == 0 ) { pName[lg-5] = 0; // ignore le dossier \debug ! } + +out: + SDL_free (basePath); } // Ajoute le chemin permettant de lire un fichier @@ -99,18 +98,12 @@ void GetCurrentDir(char *pName, size_t lg) void AddUserPath(char *pFilename) { - char temp[MAX_PATH]; + char *temp; char* pText; size_t pos; char last; - SECURITY_ATTRIBUTES att; - strcpy(temp, "c:\\Planète Blupi\\"); - - att.nLength = sizeof(SECURITY_ATTRIBUTES); - att.lpSecurityDescriptor = nullptr; - att.bInheritHandle = false; - CreateDirectory(temp, &att); + temp = SDL_GetPrefPath ("Epsitec SA", "Planet Blupi"); pText = strstr(pFilename, "\\"); if ( pText != nullptr ) @@ -119,7 +112,7 @@ void AddUserPath(char *pFilename) strcat(temp, pFilename); last = temp[pos]; temp[pos] = 0; - CreateDirectory(temp, &att); + _mkdir (temp); temp[pos] = last; } else @@ -128,4 +121,5 @@ void AddUserPath(char *pFilename) } strcpy(pFilename, temp); + SDL_free (temp); } diff --git a/misc.h b/misc.h index 9506208..56f81b4 100644 --- a/misc.h +++ b/misc.h @@ -3,7 +3,7 @@ #pragma once -#include +#include "blupi.h" extern void OutputDebug(char *pMessage); diff --git a/pixmap.h b/pixmap.h index f266424..e672669 100644 --- a/pixmap.h +++ b/pixmap.h @@ -4,7 +4,7 @@ #include -///////////////////////////////////////////////////////////////////////////// +#include "blupi.h" #define MAXIMAGE 100 #define MAXCURSORS 14 diff --git a/sound.cpp b/sound.cpp index 610d5cc..630789f 100644 --- a/sound.cpp +++ b/sound.cpp @@ -266,7 +266,7 @@ bool CSound::PlayImage(int channel, POINT pos, int rank) // Uses MCI to play a MIDI file. The window procedure // is notified when playback is complete. -bool CSound::PlayMusic(LPSTR lpszMIDIFilename) +bool CSound::PlayMusic(const char *lpszMIDIFilename) { char string[MAX_PATH]; diff --git a/sound.h b/sound.h index 71afd03..75b0cd7 100644 --- a/sound.h +++ b/sound.h @@ -4,9 +4,8 @@ #pragma once #include -#include #include - +#include "blupi.h" ///////////////////////////////////////////////////////////////////////////// @@ -35,7 +34,7 @@ public: bool Play(int channel, int volume=0, Uint8 panLeft = 255, Uint8 panRight = 255); bool PlayImage(int channel, POINT pos, int rank=-1); - bool PlayMusic(LPSTR lpszMIDIFilename); + bool PlayMusic(const char *lpszMIDIFilename); bool RestartMusic(); void SuspendMusic(); void StopMusic();