mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-11 18:41:14 +00:00
Replace Windows CriticalSection with SDL Mutex (#7)
* Replace Windows CriticalSection with SDL Mutex * Update README.md
This commit is contained in:
parent
6f2481e8d6
commit
641ae70ab9
@ -299,7 +299,7 @@ add_library(omni STATIC
|
|||||||
register_lego1_target(omni)
|
register_lego1_target(omni)
|
||||||
set_property(TARGET omni PROPERTY ARCHIVE_OUTPUT_NAME "omni$<$<CONFIG:Debug>:d>")
|
set_property(TARGET omni PROPERTY ARCHIVE_OUTPUT_NAME "omni$<$<CONFIG:Debug>:d>")
|
||||||
target_include_directories(omni PRIVATE "${CMAKE_SOURCE_DIR}/LEGO1/omni/include" "${CMAKE_SOURCE_DIR}/LEGO1" "${CMAKE_SOURCE_DIR}/util")
|
target_include_directories(omni PRIVATE "${CMAKE_SOURCE_DIR}/LEGO1/omni/include" "${CMAKE_SOURCE_DIR}/LEGO1" "${CMAKE_SOURCE_DIR}/util")
|
||||||
target_link_libraries(omni PRIVATE dsound winmm libsmacker SDL3::SDL3)
|
target_link_libraries(omni PRIVATE dsound winmm libsmacker)
|
||||||
|
|
||||||
add_library(lego1 SHARED
|
add_library(lego1 SHARED
|
||||||
LEGO1/define.cpp
|
LEGO1/define.cpp
|
||||||
@ -462,7 +462,7 @@ target_include_directories(lego1 PUBLIC "${CMAKE_SOURCE_DIR}/LEGO1/lego/legoomni
|
|||||||
target_link_libraries(lego1 PRIVATE tglrl viewmanager realtime mxdirectx roi geom anim Vec::Vec dinput dxguid misc 3dmanager omni)
|
target_link_libraries(lego1 PRIVATE tglrl viewmanager realtime mxdirectx roi geom anim Vec::Vec dinput dxguid misc 3dmanager omni)
|
||||||
|
|
||||||
foreach(tgt IN LISTS lego1_targets)
|
foreach(tgt IN LISTS lego1_targets)
|
||||||
target_link_libraries(${tgt} PRIVATE $<$<BOOL:${ISLE_USE_DX5}>:DirectX5::DirectX5>)
|
target_link_libraries(${tgt} PRIVATE $<$<BOOL:${ISLE_USE_DX5}>:DirectX5::DirectX5> SDL3::SDL3)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Make sure filenames are ALL CAPS
|
# Make sure filenames are ALL CAPS
|
||||||
@ -479,7 +479,7 @@ if (ISLE_BUILD_APP)
|
|||||||
target_compile_definitions(isle PRIVATE ISLE_APP)
|
target_compile_definitions(isle PRIVATE ISLE_APP)
|
||||||
|
|
||||||
# Use internal DirectX 5 if required
|
# Use internal DirectX 5 if required
|
||||||
target_link_libraries(isle PRIVATE $<$<BOOL:${ISLE_USE_DX5}>:DirectX5::DirectX5>)
|
target_link_libraries(isle PRIVATE $<$<BOOL:${ISLE_USE_DX5}>:DirectX5::DirectX5> SDL3::SDL3)
|
||||||
|
|
||||||
# Link DSOUND, WINMM, and LEGO1
|
# Link DSOUND, WINMM, and LEGO1
|
||||||
target_link_libraries(isle PRIVATE dsound winmm lego1)
|
target_link_libraries(isle PRIVATE dsound winmm lego1)
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#ifndef MXCRITICALSECTION_H
|
#ifndef MXCRITICALSECTION_H
|
||||||
#define MXCRITICALSECTION_H
|
#define MXCRITICALSECTION_H
|
||||||
|
|
||||||
#include <windows.h>
|
#include <SDL3/SDL_mutex.h>
|
||||||
|
|
||||||
// SIZE 0x1c
|
// SIZE 0x1c
|
||||||
class MxCriticalSection {
|
class MxCriticalSection {
|
||||||
@ -15,8 +15,11 @@ class MxCriticalSection {
|
|||||||
void Leave();
|
void Leave();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CRITICAL_SECTION m_criticalSection; // 0x00
|
// [library:synchronization]
|
||||||
HANDLE m_mutex; // 0x18
|
// SDL uses the most efficient mutex implementation available on the target platform.
|
||||||
|
// Originally this class allowed working with either a Win32 CriticalSection or Mutex,
|
||||||
|
// but only CriticalSection was ever used and we don't need both anyway.
|
||||||
|
SDL_Mutex* m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MXCRITICALSECTION_H
|
#endif // MXCRITICALSECTION_H
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
#include "mxcriticalsection.h"
|
#include "mxcriticalsection.h"
|
||||||
#include "mxstring.h"
|
#include "mxstring.h"
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
class MxAtomSet;
|
class MxAtomSet;
|
||||||
class MxDSAction;
|
class MxDSAction;
|
||||||
class MxEntity;
|
class MxEntity;
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class MxSemaphore {
|
|||||||
void Release();
|
void Release();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Semaphore* m_semaphore; // 0x04
|
SDL_Semaphore* m_semaphore;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MXSEMAPHORE_H
|
#endif // MXSEMAPHORE_H
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
#include "mxcriticalsection.h"
|
#include "mxcriticalsection.h"
|
||||||
|
|
||||||
#include "decomp.h"
|
#include "decomp.h"
|
||||||
|
#include "platform.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
DECOMP_SIZE_ASSERT(MxCriticalSection, 0x1c)
|
DECOMP_SIZE_ASSERT(MxCriticalSection, 0x1c)
|
||||||
|
|
||||||
@ -12,61 +11,27 @@ BOOL g_useMutex = FALSE;
|
|||||||
// FUNCTION: LEGO1 0x100b6d20
|
// FUNCTION: LEGO1 0x100b6d20
|
||||||
MxCriticalSection::MxCriticalSection()
|
MxCriticalSection::MxCriticalSection()
|
||||||
{
|
{
|
||||||
HANDLE mutex;
|
m_mutex = SDL_CreateMutex();
|
||||||
|
|
||||||
if (g_useMutex) {
|
|
||||||
mutex = CreateMutexA(NULL, FALSE, NULL);
|
|
||||||
m_mutex = mutex;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
InitializeCriticalSection(&m_criticalSection);
|
|
||||||
m_mutex = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100b6d60
|
// FUNCTION: LEGO1 0x100b6d60
|
||||||
MxCriticalSection::~MxCriticalSection()
|
MxCriticalSection::~MxCriticalSection()
|
||||||
{
|
{
|
||||||
if (m_mutex != NULL) {
|
if (m_mutex != NULL) {
|
||||||
CloseHandle(m_mutex);
|
SDL_DestroyMutex(m_mutex);
|
||||||
}
|
|
||||||
else {
|
|
||||||
DeleteCriticalSection(&m_criticalSection);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100b6d80
|
// FUNCTION: LEGO1 0x100b6d80
|
||||||
void MxCriticalSection::Enter()
|
void MxCriticalSection::Enter()
|
||||||
{
|
{
|
||||||
DWORD result;
|
SDL_LockMutex(m_mutex);
|
||||||
FILE* file;
|
|
||||||
|
|
||||||
if (m_mutex != NULL) {
|
|
||||||
result = WaitForSingleObject(m_mutex, 5000);
|
|
||||||
if (result == WAIT_FAILED) {
|
|
||||||
file = fopen("C:\\DEADLOCK.TXT", "a");
|
|
||||||
if (file != NULL) {
|
|
||||||
fprintf(file, "mutex timeout occurred!\n");
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
EnterCriticalSection(&m_criticalSection);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100b6de0
|
// FUNCTION: LEGO1 0x100b6de0
|
||||||
void MxCriticalSection::Leave()
|
void MxCriticalSection::Leave()
|
||||||
{
|
{
|
||||||
if (m_mutex != NULL) {
|
SDL_UnlockMutex(m_mutex);
|
||||||
ReleaseMutex(m_mutex);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LeaveCriticalSection(&m_criticalSection);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100b6e00
|
// FUNCTION: LEGO1 0x100b6e00
|
||||||
|
|||||||
16
README.md
16
README.md
@ -22,14 +22,14 @@ To achieve our goal of platform independence, we need to replace any Windows-onl
|
|||||||
|
|
||||||
| Library | Substitution | Implementation status | |
|
| Library | Substitution | Implementation status | |
|
||||||
| - | - | - | - |
|
| - | - | - | - |
|
||||||
| [Smacker](https://github.com/isledecomp/isle/tree/master/3rdparty/smacker) | [libsmacker](https://github.com/foxtacles/libsmacker) | ✅ | [Open issues](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable%20%22%2F%2F%20%5Blibrary%3Alibsmacker%5D%22&type=code) |
|
| [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 | ❌ | [Open issues](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Afilesystem%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/) | ❌ | [Open issues](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/) | ❌ | [Open issues](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%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/) | ❌ | [Open issues](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aaudio%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/) | ❌ | [Open issues](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A2d%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) |
|
||||||
| Direct3D (3D video) | [SDL3](https://www.libsdl.org/), OpenGL ES (**TBD**) | ❌ | [Open issues](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A3d%5D%22&type=code) |
|
| Direct3D (3D video) | [SDL3](https://www.libsdl.org/), OpenGL ES (**TBD**) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A3d%5D%22&type=code) |
|
||||||
| Direct3D Retained Mode | Custom re-implementation (**TBD**) | ❌ | [Open issues](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aretained%5D%22&type=code) |
|
| Direct3D Retained Mode | Custom re-implementation (**TBD**) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aretained%5D%22&type=code) |
|
||||||
| [SmartHeap](https://github.com/isledecomp/isle/tree/master/3rdparty/smartheap) | Default memory allocator | - | - |
|
| [SmartHeap](https://github.com/isledecomp/isle/tree/master/3rdparty/smartheap) | Default memory allocator | - | - |
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|||||||
20
util/platform.h
Normal file
20
util/platform.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef TYPES_H
|
||||||
|
#define TYPES_H
|
||||||
|
|
||||||
|
// Defining substitutions for definitions usually found in Windows headers
|
||||||
|
|
||||||
|
#define BOOL int32_t
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FALSE
|
||||||
|
#define FALSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#define NULL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // TYPES_H
|
||||||
Loading…
Reference in New Issue
Block a user