From e928fc9425fbbf7c89a2d0176a4ee00c87219435 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 25 Oct 2023 01:24:29 +0200 Subject: [PATCH] Build fixes for mingw (#245) --- CMakeLists.txt | 3 +++ LEGO1/compat.h | 3 ++- LEGO1/decomp.h | 5 +++++ LEGO1/legogamestate.cpp | 8 ++++---- LEGO1/legogamestate.h | 4 ++-- LEGO1/legoobjectfactory.cpp | 5 ++--- LEGO1/legoomni.cpp | 2 +- LEGO1/legoomni.h | 2 +- LEGO1/legoutil.h | 2 +- LEGO1/mxactionnotificationparam.h | 4 ++-- LEGO1/mxdirect3d.cpp | 2 +- LEGO1/mxdirect3d.h | 4 ++-- LEGO1/mxdirectdraw.cpp | 2 +- LEGO1/mxdsobject.h | 2 +- LEGO1/mxhashtable.h | 15 +++++++++------ LEGO1/mxlist.h | 13 +++++++++---- LEGO1/mxmusicmanager.cpp | 6 +++--- LEGO1/mxobjectfactory.cpp | 2 -- LEGO1/mxomni.h | 2 +- LEGO1/mxomnicreateparam.h | 1 + LEGO1/mxpresenter.cpp | 4 ++-- LEGO1/mxpresenter.h | 2 +- LEGO1/mxtransitionmanager.cpp | 6 ++++-- LEGO1/mxtypes.h | 5 +++++ LEGO1/pizza.h | 2 +- 25 files changed, 64 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6ce980b..624f1f07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -209,6 +209,9 @@ add_library(lego1 SHARED LEGO1/towtrackmissionstate.cpp LEGO1/viewmanager.cpp ) +if (MINGW) + target_compile_definitions(lego1 PRIVATE DIRECTINPUT_VERSION=0x0500) +endif() # Additional include directories for both targets include_directories("${CMAKE_SOURCE_DIR}/3rdparty/vec") diff --git a/LEGO1/compat.h b/LEGO1/compat.h index ba0b9d34..bdc10633 100644 --- a/LEGO1/compat.h +++ b/LEGO1/compat.h @@ -31,7 +31,8 @@ static class msVC6_4786WorkAround { public: msVC6_4786WorkAround() {} } msVC6_47 #include #include #include -using namespace std; +using std::list; +using std::set; #endif // We use `override` so newer compilers can tell us our vtables are valid, diff --git a/LEGO1/decomp.h b/LEGO1/decomp.h index cd179ae6..5e8dfff2 100644 --- a/LEGO1/decomp.h +++ b/LEGO1/decomp.h @@ -1,8 +1,13 @@ #ifndef DECOMP_H #define DECOMP_H +#if defined(_MSC_VER) #define DECOMP_STATIC_ASSERT(V) namespace { typedef int foo[(V)?1:-1]; } #define DECOMP_SIZE_ASSERT(T, S) DECOMP_STATIC_ASSERT(sizeof(T) == S) +#else +#define DECOMP_STATIC_ASSERT(V) +#define DECOMP_SIZE_ASSERT(T, S) +#endif #ifndef _countof #define _countof(arr) sizeof(arr) / sizeof(arr[0]) diff --git a/LEGO1/legogamestate.cpp b/LEGO1/legogamestate.cpp index 6891bbcd..de9d14ab 100644 --- a/LEGO1/legogamestate.cpp +++ b/LEGO1/legogamestate.cpp @@ -192,7 +192,7 @@ void LegoGameState::SetSavePath(char *p_savePath) } // OFFSET: LEGO1 0x1003bbb0 -LegoState *LegoGameState::GetState(char *p_stateName) +LegoState *LegoGameState::GetState(COMPAT_CONST char *p_stateName) { for (MxS32 i = 0; i < m_stateCount; ++i) if (m_stateArray[i]->IsA(p_stateName)) @@ -201,11 +201,11 @@ LegoState *LegoGameState::GetState(char *p_stateName) } // OFFSET: LEGO1 0x1003bc00 -LegoState *LegoGameState::CreateState(char *p_stateName) +LegoState *LegoGameState::CreateState(COMPAT_CONST char *p_stateName) { LegoState* newState = (LegoState*)ObjectFactory()->Create(p_stateName); RegisterState(newState); - + return newState; } @@ -245,4 +245,4 @@ void LegoGameState::FUN_1003a720(MxU32 p_unk) void LegoGameState::HandleAction(MxU32 p_unk) { // TODO -} \ No newline at end of file +} diff --git a/LEGO1/legogamestate.h b/LEGO1/legogamestate.h index 2ae06e77..9590bf92 100644 --- a/LEGO1/legogamestate.h +++ b/LEGO1/legogamestate.h @@ -29,8 +29,8 @@ public: __declspec(dllexport) void SerializeScoreHistory(MxS16 p); __declspec(dllexport) void SetSavePath(char *p); - LegoState *GetState(char *p_stateName); - LegoState *CreateState(char *p_stateName); + LegoState *GetState(COMPAT_CONST char *p_stateName); + LegoState *CreateState(COMPAT_CONST char *p_stateName); void GetFileSavePath(MxString *p_outPath, MxULong p_slotn); void FUN_1003a720(MxU32 p_unk); diff --git a/LEGO1/legoobjectfactory.cpp b/LEGO1/legoobjectfactory.cpp index 222569ea..dba8f636 100644 --- a/LEGO1/legoobjectfactory.cpp +++ b/LEGO1/legoobjectfactory.cpp @@ -19,11 +19,10 @@ MxCore *LegoObjectFactory::Create(const char *p_name) { MxAtomId atom(p_name, LookupMode_Exact); - if (0) { -#define X(V) } else if (this->m_id##V == atom) { return new V; +#define X(V) if (this->m_id##V == atom) { return new V; } else FOR_LEGOOBJECTFACTORY_OBJECTS(X) #undef X - } else { + { return MxObjectFactory::Create(p_name); } } diff --git a/LEGO1/legoomni.cpp b/LEGO1/legoomni.cpp index c67e415e..0859835b 100644 --- a/LEGO1/legoomni.cpp +++ b/LEGO1/legoomni.cpp @@ -303,7 +303,7 @@ void LegoOmni::Init() } // OFFSET: LEGO1 0x10058e70 STUB -MxResult LegoOmni::Create(COMPAT_CONST MxOmniCreateParam &p) +MxResult LegoOmni::Create(MxOmniCreateParam &p) { MxOmni::Create(p); diff --git a/LEGO1/legoomni.h b/LEGO1/legoomni.h index 4b5ca98f..9f6f0019 100644 --- a/LEGO1/legoomni.h +++ b/LEGO1/legoomni.h @@ -56,7 +56,7 @@ public: } virtual void Init() override; // vtable+14 - virtual MxResult Create(COMPAT_CONST MxOmniCreateParam &p) override; // vtable+18 + virtual MxResult Create(MxOmniCreateParam &p) override; // vtable+18 virtual void Destroy() override; // vtable+1c virtual MxResult Start(MxDSAction* action) override; // vtable+20 virtual MxResult DeleteObject(MxDSAction &ds) override; // vtable+24 diff --git a/LEGO1/legoutil.h b/LEGO1/legoutil.h index 50f43fc8..08f2f7b3 100644 --- a/LEGO1/legoutil.h +++ b/LEGO1/legoutil.h @@ -47,7 +47,7 @@ inline void GetDouble(char **p_source, T& p_dest) } template -inline void GetString(char **p_source, const char *&p_dest, T *p_obj, void (T::*p_setter)(const char*)) +inline void GetString(char **p_source, const char *p_dest, T *p_obj, void (T::*p_setter)(const char*)) { (p_obj->*p_setter)(*p_source); *p_source += strlen(p_dest) + 1; diff --git a/LEGO1/mxactionnotificationparam.h b/LEGO1/mxactionnotificationparam.h index ecf70ed1..402fb783 100644 --- a/LEGO1/mxactionnotificationparam.h +++ b/LEGO1/mxactionnotificationparam.h @@ -27,7 +27,7 @@ public: } // OFFSET: LEGO1 0x10051050 - inline virtual MxActionNotificationParam::~MxActionNotificationParam() override + inline virtual ~MxActionNotificationParam() override { if (!this->m_realloc) return; @@ -58,4 +58,4 @@ public: virtual MxNotificationParam *Clone() override; // vtable+0x4 }; -#endif \ No newline at end of file +#endif diff --git a/LEGO1/mxdirect3d.cpp b/LEGO1/mxdirect3d.cpp index 6d6a43e3..9d7254e0 100644 --- a/LEGO1/mxdirect3d.cpp +++ b/LEGO1/mxdirect3d.cpp @@ -182,7 +182,7 @@ BOOL FAR PASCAL EnumerateCallback(GUID FAR *, LPSTR, LPSTR, LPVOID) } // OFFSET: LEGO1 0x1009c730 STUB -char *MxDeviceEnumerate::EnumerateErrorToString(HRESULT p_error) +const char *MxDeviceEnumerate::EnumerateErrorToString(HRESULT p_error) { // TODO: This is a list of error messages, similar to the function in // MxDirectDraw, except that this one now contains the Direct3D errors. diff --git a/LEGO1/mxdirect3d.h b/LEGO1/mxdirect3d.h index 03e9f1ac..702c8569 100644 --- a/LEGO1/mxdirect3d.h +++ b/LEGO1/mxdirect3d.h @@ -27,7 +27,7 @@ public: virtual MxResult _DoEnumerate(); BOOL FUN_1009c070(); - char *EnumerateErrorToString(HRESULT p_error); + const char *EnumerateErrorToString(HRESULT p_error); undefined4 m_unk004; undefined4 m_unk008; @@ -75,4 +75,4 @@ private: BOOL FAR PASCAL EnumerateCallback(GUID FAR *, LPSTR, LPSTR, LPVOID); -#endif // MXDIRECT3D_H \ No newline at end of file +#endif // MXDIRECT3D_H diff --git a/LEGO1/mxdirectdraw.cpp b/LEGO1/mxdirectdraw.cpp index 099e9bc6..3fd813f7 100644 --- a/LEGO1/mxdirectdraw.cpp +++ b/LEGO1/mxdirectdraw.cpp @@ -9,7 +9,7 @@ DECOMP_SIZE_ASSERT(MxDirectDraw::DeviceModesInfo, 0x17c); #endif // GLOBAL OFFSET: LEGO1 0x10100C68 -extern BOOL g_is_PALETTEINDEXED8 = 0; +BOOL g_is_PALETTEINDEXED8 = 0; // OFFSET: LEGO1 0x1009DA20 void EnableResizing(HWND hwnd, BOOL flag) diff --git a/LEGO1/mxdsobject.h b/LEGO1/mxdsobject.h index cfb5d6a1..f1d12a82 100644 --- a/LEGO1/mxdsobject.h +++ b/LEGO1/mxdsobject.h @@ -41,7 +41,7 @@ public: inline void SetObjectId(MxU32 p_objectId) { this->m_objectId = p_objectId; } inline void SetUnknown24(MxS16 p_unk24) { this->m_unk24 = p_unk24; } - inline char *GetSourceName() const { return this->m_sourceName; } + inline const char *GetSourceName() const { return this->m_sourceName; } inline void SetType(MxDSType p_type) { this->m_type = p_type; } inline MxDSType GetType() const { return (MxDSType) this->m_type; } diff --git a/LEGO1/mxhashtable.h b/LEGO1/mxhashtable.h index 3d91717b..9926f230 100644 --- a/LEGO1/mxhashtable.h +++ b/LEGO1/mxhashtable.h @@ -9,6 +9,9 @@ #define HASH_TABLE_OPT_EXPAND_ADD 1 #define HASH_TABLE_OPT_EXPAND_MULTIPLY 2 +template +class MxHashTableCursor; + template class MxHashTableNode { @@ -162,13 +165,13 @@ MxHashTable::~MxHashTable() while (t) { MxHashTableNode *next = t->m_next; - m_customDestructor(t->m_obj); + this->m_customDestructor(t->m_obj); delete t; t = next; } } - m_numKeys = 0; + this->m_numKeys = 0; memset(m_slots, 0, sizeof(MxHashTableNode *) * m_numSlots); delete[] m_slots; @@ -196,7 +199,7 @@ inline void MxHashTable::Resize() // FIXME: order? m_numKeys set after `rep stosd` m_slots = new_table; memset(m_slots, 0, sizeof(MxHashTableNode *) * m_numSlots); - m_numKeys = 0; + this->m_numKeys = 0; for (int i = 0; i != old_size; i++) { MxHashTableNode *t = old_table[i]; @@ -223,13 +226,13 @@ inline void MxHashTable::_NodeInsert(MxHashTableNode *p_node) m_slots[bucket]->m_prev = p_node; m_slots[bucket] = p_node; - m_numKeys++; + this->m_numKeys++; } template inline void MxHashTable::Add(T* p_newobj) { - if (m_resizeOption && ((m_numKeys + 1) / m_numSlots) > m_autoResizeRatio) + if (m_resizeOption && ((this->m_numKeys + 1) / m_numSlots) > m_autoResizeRatio) MxHashTable::Resize(); MxU32 hash = Hash(p_newobj); @@ -238,4 +241,4 @@ inline void MxHashTable::Add(T* p_newobj) MxHashTable::_NodeInsert(node); } -#endif // MXHASHTABLE_H \ No newline at end of file +#endif // MXHASHTABLE_H diff --git a/LEGO1/mxlist.h b/LEGO1/mxlist.h index 94798b33..82248fba 100644 --- a/LEGO1/mxlist.h +++ b/LEGO1/mxlist.h @@ -4,6 +4,11 @@ #include "mxtypes.h" #include "mxcore.h" +template +class MxList; +template +class MxListCursor; + template class MxListEntry { @@ -64,7 +69,7 @@ public: void Append(T); void OtherAppend(T p_obj) { _InsertEntry(p_obj, this->m_last, NULL); }; void DeleteAll(); - MxU32 GetCount() { return m_count; } + MxU32 GetCount() { return this->m_count; } void SetDestroy(void (*p_customDestructor)(T)) { this->m_customDestructor = p_customDestructor; } friend class MxListCursor; @@ -128,12 +133,12 @@ inline void MxList::DeleteAll() break; MxListEntry *next = t->m_next; - m_customDestructor(t->GetValue()); + this->m_customDestructor(t->GetValue()); delete t; t = next; } - m_count = 0; + this->m_count = 0; m_last = NULL; m_first = NULL; } @@ -188,7 +193,7 @@ inline void MxList::_DeleteEntry(MxListEntry *match) m_last = *pPrev; delete match; - m_count--; + this->m_count--; } template diff --git a/LEGO1/mxmusicmanager.cpp b/LEGO1/mxmusicmanager.cpp index e481ec8e..8c2d1509 100644 --- a/LEGO1/mxmusicmanager.cpp +++ b/LEGO1/mxmusicmanager.cpp @@ -27,8 +27,8 @@ void MxMusicManager::DeinitializeMIDI() { m_MIDIInitialized = FALSE; midiStreamStop(m_MIDIStreamH); - midiOutUnprepareHeader(m_MIDIStreamH, m_MIDIHdrP, sizeof(MIDIHDR)); - midiOutSetVolume(m_MIDIStreamH, m_MIDIVolume); + midiOutUnprepareHeader((HMIDIOUT)m_MIDIStreamH, m_MIDIHdrP, sizeof(MIDIHDR)); + midiOutSetVolume((HMIDIOUT)m_MIDIStreamH, m_MIDIVolume); midiStreamClose(m_MIDIStreamH); delete m_MIDIHdrP; InitData(); @@ -106,7 +106,7 @@ void MxMusicManager::SetMIDIVolume() if (streamHandle) { MxS32 volume = CalculateVolume(result); - midiOutSetVolume(streamHandle, volume); + midiOutSetVolume((HMIDIOUT)streamHandle, volume); } } diff --git a/LEGO1/mxobjectfactory.cpp b/LEGO1/mxobjectfactory.cpp index bf31bf68..2f026e58 100644 --- a/LEGO1/mxobjectfactory.cpp +++ b/LEGO1/mxobjectfactory.cpp @@ -35,8 +35,6 @@ MxCore *MxObjectFactory::Create(const char *p_name) #define X(V) else if (this->m_id##V == atom) { object = new V; } FOR_MXOBJECTFACTORY_OBJECTS(X) #undef X - else {} - return object; } diff --git a/LEGO1/mxomni.h b/LEGO1/mxomni.h index 321d788b..9243e763 100644 --- a/LEGO1/mxomni.h +++ b/LEGO1/mxomni.h @@ -40,7 +40,7 @@ public: virtual MxLong Notify(MxParam &p) override; // vtable+04 virtual void Init(); // vtable+14 - virtual MxResult Create(COMPAT_CONST MxOmniCreateParam &p); // vtable+18 + virtual MxResult Create(MxOmniCreateParam &p); // vtable+18 virtual void Destroy(); // vtable+1c virtual MxResult Start(MxDSAction *p_dsAction); // vtable+20 virtual MxResult DeleteObject(MxDSAction &p_dsAction); // vtable+24 diff --git a/LEGO1/mxomnicreateparam.h b/LEGO1/mxomnicreateparam.h index ec8a3de1..810c0798 100644 --- a/LEGO1/mxomnicreateparam.h +++ b/LEGO1/mxomnicreateparam.h @@ -17,6 +17,7 @@ public: const MxString& GetMediaPath() const { return m_mediaPath; } const HWND GetWindowHandle() const { return m_windowHandle; } MxVideoParam& GetVideoParam() { return m_videoParam; } + const MxVideoParam& GetVideoParam() const { return m_videoParam; } private: MxString m_mediaPath; diff --git a/LEGO1/mxpresenter.cpp b/LEGO1/mxpresenter.cpp index c573c26f..541bef7d 100644 --- a/LEGO1/mxpresenter.cpp +++ b/LEGO1/mxpresenter.cpp @@ -164,9 +164,9 @@ void MxPresenter::Enable(MxBool p_enable) } // OFFSET: LEGO1 0x100b5310 -char *PresenterNameDispatch(const MxDSAction &p_action) +const char *PresenterNameDispatch(const MxDSAction &p_action) { - char *name = p_action.GetSourceName(); + const char *name = p_action.GetSourceName(); MxS32 format; if (!name || strlen(name) == 0) { diff --git a/LEGO1/mxpresenter.h b/LEGO1/mxpresenter.h index 09c53298..8965fc3d 100644 --- a/LEGO1/mxpresenter.h +++ b/LEGO1/mxpresenter.h @@ -87,6 +87,6 @@ protected: MxPresenter *m_unkPresenter; // 0x3c }; -char *PresenterNameDispatch(const MxDSAction &); +const char *PresenterNameDispatch(const MxDSAction &); #endif // MXPRESENTER_H diff --git a/LEGO1/mxtransitionmanager.cpp b/LEGO1/mxtransitionmanager.cpp index 9b6ff913..eba05107 100644 --- a/LEGO1/mxtransitionmanager.cpp +++ b/LEGO1/mxtransitionmanager.cpp @@ -104,7 +104,8 @@ void MxTransitionManager::Transition_Dissolve() // If we are starting the animation if (m_animationTimer == 0) { // Generate the list of columns in order... - for (MxS32 i = 0; i < 640; i++) { + MxS32 i; + for (i = 0; i < 640; i++) { m_columnOrder[i] = i; } @@ -242,7 +243,8 @@ void MxTransitionManager::Transition_Pixelation() if (m_animationTimer == 0) { // Same init/shuffle steps as the dissolve transition, except that // we are using big blocky pixels and only need 64 columns. - for (MxS32 i = 0; i < 64; i++) { + MxS32 i; + for (i = 0; i < 64; i++) { m_columnOrder[i] = i; } diff --git a/LEGO1/mxtypes.h b/LEGO1/mxtypes.h index 75f19d4a..ad2ffbc7 100644 --- a/LEGO1/mxtypes.h +++ b/LEGO1/mxtypes.h @@ -7,8 +7,13 @@ typedef unsigned short MxU16; typedef signed short MxS16; typedef unsigned int MxU32; typedef signed int MxS32; +#ifdef _MSC_VER typedef unsigned __int64 MxU64; typedef signed __int64 MxS64; +#else +typedef unsigned long long int MxU64; +typedef signed long long int MxS64; +#endif typedef float MxFloat; typedef double MxDouble; diff --git a/LEGO1/pizza.h b/LEGO1/pizza.h index d6909810..c08ff23e 100644 --- a/LEGO1/pizza.h +++ b/LEGO1/pizza.h @@ -27,7 +27,7 @@ public: } // OFFSET: LEGO1 0x10037fa0 - inline MxBool Pizza::IsA(const char *name) const override //vtable+10 + inline MxBool IsA(const char *name) const override //vtable+10 { return !strcmp(name, Pizza::ClassName()) || IsleActor::IsA(name); }