Add SDL3 and replace Windows semaphores (#4)

* Add SDL3 and replace Windows semaphores

* Try this

* Change for now
This commit is contained in:
Christian Semmler 2024-05-30 14:41:20 -04:00 committed by Anonymous Maarten
parent 94081312c3
commit 6f1aebbb02
6 changed files with 51 additions and 18 deletions

View File

@ -19,6 +19,13 @@ jobs:
# - { name: 'msys2 clang32', shell: 'msys2 {0}', msystem: clang32, msys-env: mingw-w64-clang-i686, clang-tidy: true, werror: true, no-dx5-libs: true } # - { name: 'msys2 clang32', shell: 'msys2 {0}', msystem: clang32, msys-env: mingw-w64-clang-i686, clang-tidy: true, werror: true, no-dx5-libs: true }
steps: steps:
# Figure out how to build for 32-bit arch
# - name: Set up SDL
# id: sdl
# uses: libsdl-org/setup-sdl@main
# with:
# version: sdl3-head
- name: Set up MSYS2 - name: Set up MSYS2
if: ${{ !!matrix.toolchain.msystem }} if: ${{ !!matrix.toolchain.msystem }}
uses: msys2/setup-msys2@v2 uses: msys2/setup-msys2@v2
@ -49,6 +56,7 @@ jobs:
submodules: true submodules: true
- name: Build - name: Build
# Add -DDOWNLOAD_DEPENDENCIES=OFF once setup-sdl works
run: | run: |
cmake -S . -B build -GNinja \ cmake -S . -B build -GNinja \
-DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_BUILD_TYPE=Debug \

View File

@ -5,6 +5,27 @@ cmake_policy(SET CMP0091 NEW)
project(isle CXX C) project(isle CXX C)
# By configuring CMake with -DDOWNLOAD_DEPENDENCIES=ON/OFF,
# users can choose between downloading dependencies or using system libraries
option(DOWNLOAD_DEPENDENCIES "Download dependencies" TRUE)
if(DOWNLOAD_DEPENDENCIES)
# FetchContent downloads and configures dependencies
include(FetchContent)
FetchContent_Declare(
SDL3
GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git"
GIT_TAG "main"
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(SDL3)
else()
# find_package looks for already-installed system packages.
# Configure with `-DCMAKE_PREFIX_PATH="/path/to/package1;/path/to/package2"`
# to add search paths.
find_package(SDL3 CONFIG REQUIRED)
endif()
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
include(CMakeDependentOption) include(CMakeDependentOption)
include(CMakePushCheckState) include(CMakePushCheckState)
@ -277,7 +298,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) target_link_libraries(omni PRIVATE dsound winmm libsmacker SDL3::SDL3)
add_library(lego1 SHARED add_library(lego1 SHARED
LEGO1/define.cpp LEGO1/define.cpp

View File

@ -3,7 +3,7 @@
#include "mxtypes.h" #include "mxtypes.h"
#include <windows.h> #include <SDL3/SDL_mutex.h>
// VTABLE: LEGO1 0x100dccf0 // VTABLE: LEGO1 0x100dccf0
// SIZE 0x08 // SIZE 0x08
@ -12,15 +12,15 @@ public:
MxSemaphore(); MxSemaphore();
// FUNCTION: LEGO1 0x100c87e0 // FUNCTION: LEGO1 0x100c87e0
~MxSemaphore() { CloseHandle(m_hSemaphore); } ~MxSemaphore() { SDL_DestroySemaphore(m_semaphore); }
virtual MxResult Init(MxU32 p_initialCount, MxU32 p_maxCount); virtual MxResult Init(MxU32 p_initialCount, MxU32 p_maxCount);
void Wait(MxU32 p_timeoutMS); void Wait();
void Release(MxU32 p_releaseCount); void Release();
private: private:
HANDLE m_hSemaphore; // 0x04 SDL_Semaphore* m_semaphore; // 0x04
}; };
#endif // MX_SEMAPHORE_H #endif // MX_SEMAPHORE_H

View File

@ -70,7 +70,7 @@ MxDiskStreamProvider::~MxDiskStreamProvider()
if (m_remainingWork) { if (m_remainingWork) {
m_remainingWork = FALSE; m_remainingWork = FALSE;
m_busySemaphore.Release(1); m_busySemaphore.Release();
m_thread.Terminate(); m_thread.Terminate();
} }
@ -164,7 +164,7 @@ void MxDiskStreamProvider::VTable0x20(MxDSAction* p_action)
MxResult MxDiskStreamProvider::WaitForWorkToComplete() MxResult MxDiskStreamProvider::WaitForWorkToComplete()
{ {
while (m_remainingWork) { while (m_remainingWork) {
m_busySemaphore.Wait(INFINITE); m_busySemaphore.Wait();
if (m_unk0x35) { if (m_unk0x35) {
PerformWork(); PerformWork();
} }
@ -205,7 +205,7 @@ MxResult MxDiskStreamProvider::FUN_100d1780(MxDSStreamingAction* p_action)
} }
m_unk0x35 = TRUE; m_unk0x35 = TRUE;
m_busySemaphore.Release(1); m_busySemaphore.Release();
return SUCCESS; return SUCCESS;
} }
@ -222,7 +222,7 @@ void MxDiskStreamProvider::PerformWork()
if (streamingAction && !FUN_100d1af0(streamingAction)) { if (streamingAction && !FUN_100d1af0(streamingAction)) {
m_thread.Sleep(500); m_thread.Sleep(500);
m_busySemaphore.Release(1); m_busySemaphore.Release();
return; return;
} }
} }

View File

@ -8,27 +8,30 @@ DECOMP_SIZE_ASSERT(MxSemaphore, 0x08)
// FUNCTION: LEGO1 0x100c87d0 // FUNCTION: LEGO1 0x100c87d0
MxSemaphore::MxSemaphore() MxSemaphore::MxSemaphore()
{ {
m_hSemaphore = NULL; m_semaphore = NULL;
} }
// FUNCTION: LEGO1 0x100c8800 // FUNCTION: LEGO1 0x100c8800
MxResult MxSemaphore::Init(MxU32 p_initialCount, MxU32 p_maxCount) MxResult MxSemaphore::Init(MxU32 p_initialCount, MxU32 p_maxCount)
{ {
// [library:synchronization] No support for max count, but shouldn't be necessary
MxResult result = FAILURE; MxResult result = FAILURE;
if ((m_hSemaphore = CreateSemaphoreA(NULL, p_initialCount, p_maxCount, NULL))) { if ((m_semaphore = SDL_CreateSemaphore(p_initialCount))) {
result = SUCCESS; result = SUCCESS;
} }
return result; return result;
} }
// FUNCTION: LEGO1 0x100c8830 // FUNCTION: LEGO1 0x100c8830
void MxSemaphore::Wait(MxU32 p_timeoutMS) void MxSemaphore::Wait()
{ {
WaitForSingleObject(m_hSemaphore, p_timeoutMS); // [library:synchronization] Removed timeout since only INFINITE is ever requested
SDL_WaitSemaphore(m_semaphore);
} }
// FUNCTION: LEGO1 0x100c8850 // FUNCTION: LEGO1 0x100c8850
void MxSemaphore::Release(MxU32 p_releaseCount) void MxSemaphore::Release()
{ {
ReleaseSemaphore(m_hSemaphore, p_releaseCount, NULL); // [library:synchronization] Removed release count since only 1 is ever requested
SDL_PostSemaphore(m_semaphore);
} }

View File

@ -5,6 +5,7 @@
#include "mxtimer.h" #include "mxtimer.h"
#include <process.h> #include <process.h>
#include <windows.h>
DECOMP_SIZE_ASSERT(MxThread, 0x1c) DECOMP_SIZE_ASSERT(MxThread, 0x1c)
DECOMP_SIZE_ASSERT(MxTickleThread, 0x20) DECOMP_SIZE_ASSERT(MxTickleThread, 0x20)
@ -81,7 +82,7 @@ void MxThread::Sleep(MxS32 p_milliseconds)
void MxThread::Terminate() void MxThread::Terminate()
{ {
m_running = FALSE; m_running = FALSE;
m_semaphore.Wait(INFINITE); m_semaphore.Wait();
} }
// FUNCTION: LEGO1 0x100bf680 // FUNCTION: LEGO1 0x100bf680
@ -93,6 +94,6 @@ unsigned MxThread::ThreadProc(void* p_thread)
// FUNCTION: LEGO1 0x100bf690 // FUNCTION: LEGO1 0x100bf690
MxResult MxThread::Run() MxResult MxThread::Run()
{ {
m_semaphore.Release(1); m_semaphore.Release();
return SUCCESS; return SUCCESS;
} }