diff --git a/LEGO1/omni/include/mxthread.h b/LEGO1/omni/include/mxthread.h index 5f04a26c..64d47884 100644 --- a/LEGO1/omni/include/mxthread.h +++ b/LEGO1/omni/include/mxthread.h @@ -5,6 +5,8 @@ #include "mxsemaphore.h" #include "mxtypes.h" +#include + class MxCore; // VTABLE: LEGO1 0x100dc860 @@ -33,10 +35,9 @@ public: private: static unsigned ThreadProc(void* p_thread); - MxULong m_hThread; // 0x04 - MxU32 m_threadId; // 0x08 - MxBool m_running; // 0x0c - MxSemaphore m_semaphore; // 0x10 + SDL_Thread* m_thread; + MxBool m_running; + MxSemaphore m_semaphore; protected: MxCore* m_target; // 0x18 diff --git a/LEGO1/omni/src/system/mxsemaphore.cpp b/LEGO1/omni/src/system/mxsemaphore.cpp index 96398150..edeb0f60 100644 --- a/LEGO1/omni/src/system/mxsemaphore.cpp +++ b/LEGO1/omni/src/system/mxsemaphore.cpp @@ -16,9 +16,11 @@ MxResult MxSemaphore::Init(MxU32 p_initialCount, MxU32 p_maxCount) { // [library:synchronization] No support for max count, but shouldn't be necessary MxResult result = FAILURE; + if ((m_semaphore = SDL_CreateSemaphore(p_initialCount))) { result = SUCCESS; } + return result; } diff --git a/LEGO1/omni/src/system/mxthread.cpp b/LEGO1/omni/src/system/mxthread.cpp index 455ce8f3..c84cace6 100644 --- a/LEGO1/omni/src/system/mxthread.cpp +++ b/LEGO1/omni/src/system/mxthread.cpp @@ -2,39 +2,45 @@ #include "decomp.h" -#include -#include +#include DECOMP_SIZE_ASSERT(MxThread, 0x1c) // FUNCTION: LEGO1 0x100bf510 MxThread::MxThread() { - m_hThread = NULL; + m_thread = NULL; m_running = TRUE; - m_threadId = 0; } // FUNCTION: LEGO1 0x100bf5a0 MxThread::~MxThread() { - if (m_hThread) { - CloseHandle((HANDLE) m_hThread); + if (m_thread) { + SDL_WaitThread(m_thread, NULL); } } -typedef unsigned(__stdcall* ThreadFunc)(void*); - // FUNCTION: LEGO1 0x100bf610 MxResult MxThread::Start(MxS32 p_stack, MxS32 p_flag) { MxResult result = FAILURE; if (m_semaphore.Init(0, 1) == SUCCESS) { - if ((m_hThread = - _beginthreadex(NULL, p_stack << 2, (ThreadFunc) &MxThread::ThreadProc, this, p_flag, &m_threadId))) { + const SDL_PropertiesID props = SDL_CreateProperties(); + SDL_SetProperty( + props, + SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER, + (SDL_FunctionPointer) &MxThread::ThreadProc + ); + SDL_SetProperty(props, SDL_PROP_THREAD_CREATE_USERDATA_POINTER, this); + SDL_SetNumberProperty(props, SDL_PROP_THREAD_CREATE_STACKSIZE_NUMBER, p_stack << 2); + + if ((m_thread = SDL_CreateThreadWithProperties(props))) { result = SUCCESS; } + + SDL_DestroyProperties(props); } return result; @@ -43,7 +49,7 @@ MxResult MxThread::Start(MxS32 p_stack, MxS32 p_flag) // FUNCTION: LEGO1 0x100bf660 void MxThread::Sleep(MxS32 p_milliseconds) { - ::Sleep(p_milliseconds); + SDL_Delay(p_milliseconds); } // FUNCTION: LEGO1 0x100bf670 diff --git a/README.md b/README.md index 694f7ac4..b2dd8c38 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ To achieve our goal of platform independence, we need to replace any Windows-onl | - | - | - | - | | [Smacker](https://github.com/isledecomp/isle/tree/master/3rdparty/smacker) | [libsmacker](https://github.com/foxtacles/libsmacker) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable%20%22%2F%2F%20%5Blibrary%3Alibsmacker%5D%22&type=code) | | Filesystem | C standard library | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Afilesystem%5D%22&type=code) | -| Threads, Mutexes (Synchronization) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Asynchronization%5D%22&type=code) | +| Threads, Mutexes (Synchronization) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Asynchronization%5D%22&type=code) | | Keyboard, Mouse, Joystick, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) | | WinMM, DirectSound (Audio) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aaudio%5D%22&type=code) | | DirectDraw (2D video) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A2d%5D%22&type=code) |