This commit is contained in:
Christian Semmler 2024-05-31 22:47:40 -04:00
parent 0b6c220b4f
commit 1206360013
5 changed files with 111 additions and 132 deletions

View File

@ -33,7 +33,7 @@
#include <SDL3/SDL_init.h> #include <SDL3/SDL_init.h>
#include <SDL3/SDL_main.h> #include <SDL3/SDL_main.h>
#include <SDL3/SDL_messagebox.h> #include <SDL3/SDL_messagebox.h>
#include <dsound.h> #include <SDL3/SDL_timer.h>
#include <iniparser.h> #include <iniparser.h>
#include <time.h> #include <time.h>
@ -43,34 +43,31 @@ DECOMP_SIZE_ASSERT(IsleApp, 0x8c)
IsleApp* g_isle = NULL; IsleApp* g_isle = NULL;
// GLOBAL: ISLE 0x410034 // GLOBAL: ISLE 0x410034
unsigned char g_mousedown = FALSE; MxU8 g_mousedown = FALSE;
// GLOBAL: ISLE 0x410038 // GLOBAL: ISLE 0x410038
unsigned char g_mousemoved = FALSE; MxU8 g_mousemoved = FALSE;
// GLOBAL: ISLE 0x41003c // GLOBAL: ISLE 0x41003c
BOOL g_closed = FALSE; MxS32 g_closed = FALSE;
// GLOBAL: ISLE 0x410040
RECT g_windowRect = {0, 0, 640, 480};
// GLOBAL: ISLE 0x410050 // GLOBAL: ISLE 0x410050
BOOL g_rmDisabled = FALSE; MxS32 g_rmDisabled = FALSE;
// GLOBAL: ISLE 0x410054 // GLOBAL: ISLE 0x410054
BOOL g_waitingForTargetDepth = TRUE; MxS32 g_waitingForTargetDepth = TRUE;
// GLOBAL: ISLE 0x410058 // GLOBAL: ISLE 0x410058
int g_targetWidth = 640; MxS32 g_targetWidth = 640;
// GLOBAL: ISLE 0x41005c // GLOBAL: ISLE 0x41005c
int g_targetHeight = 480; MxS32 g_targetHeight = 480;
// GLOBAL: ISLE 0x410060 // GLOBAL: ISLE 0x410060
int g_targetDepth = 16; MxS32 g_targetDepth = 16;
// GLOBAL: ISLE 0x410064 // GLOBAL: ISLE 0x410064
BOOL g_reqEnableRMDevice = FALSE; MxS32 g_reqEnableRMDevice = FALSE;
// STRING: ISLE 0x4101dc // STRING: ISLE 0x4101dc
#define WINDOW_TITLE "LEGO®" #define WINDOW_TITLE "LEGO®"
@ -154,7 +151,7 @@ void IsleApp::Close()
if (Lego()) { if (Lego()) {
GameState()->Save(0); GameState()->Save(0);
if (InputManager()) { if (InputManager()) {
InputManager()->QueueEvent(c_notificationKeyPress, 0, 0, 0, 0x20); InputManager()->QueueEvent(c_notificationKeyPress, 0, 0, 0, SDLK_SPACE);
} }
VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveAll(NULL); VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveAll(NULL);
@ -181,9 +178,9 @@ void IsleApp::Close()
} }
// FUNCTION: ISLE 0x4013b0 // FUNCTION: ISLE 0x4013b0
BOOL IsleApp::SetupLegoOmni() MxS32 IsleApp::SetupLegoOmni()
{ {
BOOL result = FALSE; MxS32 result = FALSE;
char mediaPath[256]; char mediaPath[256];
GetProfileStringA("LEGO Island", "MediaPath", "", mediaPath, sizeof(mediaPath)); GetProfileStringA("LEGO Island", "MediaPath", "", mediaPath, sizeof(mediaPath));
@ -192,14 +189,15 @@ BOOL IsleApp::SetupLegoOmni()
(HWND) SDL_GetProperty(SDL_GetWindowProperties(m_windowHandle), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); (HWND) SDL_GetProperty(SDL_GetWindowProperties(m_windowHandle), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
#ifdef COMPAT_MODE #ifdef COMPAT_MODE
BOOL failure; MxS32 failure;
{ {
MxOmniCreateParam param(mediaPath, (struct HWND__*) hwnd, m_videoParam, MxOmniCreateFlags()); MxOmniCreateParam param(mediaPath, (struct HWND__*) hwnd, m_videoParam, MxOmniCreateFlags());
failure = Lego()->Create(param) == FAILURE; failure = Lego()->Create(param) == FAILURE;
} }
#else #else
BOOL failure = Lego()->Create(MxOmniCreateParam(mediaPath, (struct HWND__*) hwnd, m_videoParam, MxOmniCreateFlags()) MxS32 failure =
) == FAILURE; Lego()->Create(MxOmniCreateParam(mediaPath, (struct HWND__*) hwnd, m_videoParam, MxOmniCreateFlags())) ==
FAILURE;
#endif #endif
if (!failure) { if (!failure) {
@ -213,14 +211,14 @@ BOOL IsleApp::SetupLegoOmni()
// FUNCTION: ISLE 0x401560 // FUNCTION: ISLE 0x401560
void IsleApp::SetupVideoFlags( void IsleApp::SetupVideoFlags(
BOOL fullScreen, MxS32 fullScreen,
BOOL flipSurfaces, MxS32 flipSurfaces,
BOOL backBuffers, MxS32 backBuffers,
BOOL using8bit, MxS32 using8bit,
BOOL using16bit, MxS32 using16bit,
BOOL param_6, MxS32 param_6,
BOOL param_7, MxS32 param_7,
BOOL wideViewAngle, MxS32 wideViewAngle,
char* deviceId char* deviceId
) )
{ {
@ -284,7 +282,7 @@ int SDL_AppIterate(void* appstate)
return 1; return 1;
} }
g_isle->Tick(0); g_isle->Tick();
if (!g_closed) { if (!g_closed) {
if (g_reqEnableRMDevice) { if (g_reqEnableRMDevice) {
@ -299,7 +297,7 @@ int SDL_AppIterate(void* appstate)
} }
if (g_mousedown && g_mousemoved && g_isle) { if (g_mousedown && g_mousemoved && g_isle) {
g_isle->Tick(0); g_isle->Tick();
} }
if (g_mousemoved) { if (g_mousemoved) {
@ -316,7 +314,8 @@ int SDL_AppEvent(void* appstate, const SDL_Event* event)
return 0; return 0;
} }
// [library:window] Remaining functionality to be implemented: // [library:window]
// Remaining functionality to be implemented:
// Full screen - crashes when minimizing/maximizing // Full screen - crashes when minimizing/maximizing
// WM_TIMER - use SDL_Timer functionality instead // WM_TIMER - use SDL_Timer functionality instead
// WM_SETCURSOR - update cursor // WM_SETCURSOR - update cursor
@ -361,7 +360,7 @@ int SDL_AppEvent(void* appstate, const SDL_Event* event)
} }
if (g_isle->GetDrawCursor()) { if (g_isle->GetDrawCursor()) {
VideoManager()->MoveCursor(Min((int) event->motion.x, 639), Min((int) event->motion.y, 479)); VideoManager()->MoveCursor(Min((MxS32) event->motion.x, 639), Min((MxS32) event->motion.y, 479));
} }
break; break;
case SDL_EVENT_MOUSE_BUTTON_DOWN: case SDL_EVENT_MOUSE_BUTTON_DOWN:
@ -442,10 +441,10 @@ MxResult IsleApp::SetupWindow()
srand(time(NULL)); srand(time(NULL));
if (m_fullScreen) { if (m_fullScreen) {
m_windowHandle = SDL_CreateWindow(WINDOW_TITLE, g_windowRect.right, g_windowRect.bottom, SDL_WINDOW_FULLSCREEN); m_windowHandle = SDL_CreateWindow(WINDOW_TITLE, g_targetWidth, g_targetHeight, SDL_WINDOW_FULLSCREEN);
} }
else { else {
m_windowHandle = SDL_CreateWindow(WINDOW_TITLE, g_windowRect.right, g_windowRect.bottom, 0); m_windowHandle = SDL_CreateWindow(WINDOW_TITLE, g_targetWidth, g_targetHeight, 0);
} }
if (!m_windowHandle) { if (!m_windowHandle) {
@ -460,7 +459,7 @@ MxResult IsleApp::SetupWindow()
GameState()->SerializePlayersInfo(1); GameState()->SerializePlayersInfo(1);
GameState()->SerializeScoreHistory(1); GameState()->SerializeScoreHistory(1);
int iVar10; MxS32 iVar10;
switch (m_islandQuality) { switch (m_islandQuality) {
case 0: case 0:
iVar10 = 1; iVar10 = 1;
@ -472,7 +471,7 @@ MxResult IsleApp::SetupWindow()
iVar10 = 100; iVar10 = 100;
} }
int uVar1 = (m_islandTexture == 0); MxS32 uVar1 = (m_islandTexture == 0);
LegoModelPresenter::configureLegoModelPresenter(uVar1); LegoModelPresenter::configureLegoModelPresenter(uVar1);
LegoPartPresenter::configureLegoPartPresenter(uVar1, iVar10); LegoPartPresenter::configureLegoPartPresenter(uVar1, iVar10);
LegoWorldPresenter::configureLegoWorldPresenter(m_islandQuality); LegoWorldPresenter::configureLegoWorldPresenter(m_islandQuality);
@ -518,12 +517,12 @@ void IsleApp::LoadConfig()
m_joystickIndex = iniparser_getint(dict, "isle:JoystickIndex", m_joystickIndex); m_joystickIndex = iniparser_getint(dict, "isle:JoystickIndex", m_joystickIndex);
m_drawCursor = iniparser_getboolean(dict, "isle:Draw Cursor", m_drawCursor); m_drawCursor = iniparser_getboolean(dict, "isle:Draw Cursor", m_drawCursor);
int backBuffersInVRAM = iniparser_getboolean(dict, "isle:Back Buffers in Video RAM", -1); MxS32 backBuffersInVRAM = iniparser_getboolean(dict, "isle:Back Buffers in Video RAM", -1);
if (backBuffersInVRAM != -1) { if (backBuffersInVRAM != -1) {
m_backBuffersInVram = !backBuffersInVRAM; m_backBuffersInVram = !backBuffersInVRAM;
} }
int bitDepth = iniparser_getint(dict, "isle:Display Bit Depth", -1); MxS32 bitDepth = iniparser_getint(dict, "isle:Display Bit Depth", -1);
if (bitDepth != -1) { if (bitDepth != -1) {
if (bitDepth == 8) { if (bitDepth == 8) {
m_using8bit = TRUE; m_using8bit = TRUE;
@ -556,16 +555,16 @@ void IsleApp::LoadConfig()
} }
// FUNCTION: ISLE 0x402c20 // FUNCTION: ISLE 0x402c20
inline void IsleApp::Tick(BOOL sleepIfNotNextFrame) inline void IsleApp::Tick()
{ {
// GLOBAL: ISLE 0x4101c0 // GLOBAL: ISLE 0x4101c0
static MxLong g_lastFrameTime = 0; static MxLong g_lastFrameTime = 0;
// GLOBAL: ISLE 0x4101bc // GLOBAL: ISLE 0x4101bc
static int g_startupDelay = 200; static MxS32 g_startupDelay = 200;
if (!m_windowActive) { if (!m_windowActive) {
Sleep(0); SDL_Delay(1);
return; return;
} }
@ -584,54 +583,54 @@ inline void IsleApp::Tick(BOOL sleepIfNotNextFrame)
g_lastFrameTime = -m_frameDelta; g_lastFrameTime = -m_frameDelta;
} }
if (m_frameDelta + g_lastFrameTime < currentTime) { if (m_frameDelta + g_lastFrameTime >= currentTime) {
if (!Lego()->IsTimerRunning()) { SDL_Delay(1);
TickleManager()->Tickle(); return;
} }
g_lastFrameTime = currentTime;
if (g_startupDelay == 0) { if (!Lego()->IsTimerRunning()) {
return; TickleManager()->Tickle();
} }
g_lastFrameTime = currentTime;
g_startupDelay--; if (g_startupDelay == 0) {
if (g_startupDelay != 0) { return;
return; }
}
LegoOmni::GetInstance()->CreateBackgroundAudio(); g_startupDelay--;
BackgroundAudioManager()->Enable(this->m_useMusic); if (g_startupDelay != 0) {
return;
}
MxStreamController* stream = Streamer()->Open("\\lego\\scripts\\isle\\isle", MxStreamer::e_diskStream); LegoOmni::GetInstance()->CreateBackgroundAudio();
MxDSAction ds; BackgroundAudioManager()->Enable(m_useMusic);
MxStreamController* stream = Streamer()->Open("\\lego\\scripts\\isle\\isle", MxStreamer::e_diskStream);
MxDSAction ds;
if (!stream) {
stream = Streamer()->Open("\\lego\\scripts\\nocd", MxStreamer::e_diskStream);
if (!stream) { if (!stream) {
stream = Streamer()->Open("\\lego\\scripts\\nocd", MxStreamer::e_diskStream); return;
if (!stream) {
return;
}
ds.SetAtomId(stream->GetAtom());
ds.SetUnknown24(-1);
ds.SetObjectId(0);
VideoManager()->EnableFullScreenMovie(TRUE, TRUE);
if (Start(&ds) != SUCCESS) {
return;
}
} }
else {
ds.SetAtomId(stream->GetAtom()); ds.SetAtomId(stream->GetAtom());
ds.SetUnknown24(-1); ds.SetUnknown24(-1);
ds.SetObjectId(0); ds.SetObjectId(0);
if (Start(&ds) != SUCCESS) { VideoManager()->EnableFullScreenMovie(TRUE, TRUE);
return;
} if (Start(&ds) != SUCCESS) {
m_gameStarted = TRUE; return;
} }
} }
else if (sleepIfNotNextFrame != 0) { else {
Sleep(0); ds.SetAtomId(stream->GetAtom());
ds.SetUnknown24(-1);
ds.SetObjectId(0);
if (Start(&ds) != SUCCESS) {
return;
}
m_gameStarted = TRUE;
} }
} }

View File

@ -16,60 +16,60 @@ class IsleApp {
void Close(); void Close();
BOOL SetupLegoOmni(); MxS32 SetupLegoOmni();
void SetupVideoFlags( void SetupVideoFlags(
BOOL fullScreen, MxS32 fullScreen,
BOOL flipSurfaces, MxS32 flipSurfaces,
BOOL backBuffers, MxS32 backBuffers,
BOOL using8bit, MxS32 using8bit,
BOOL using16bit, MxS32 using16bit,
BOOL param_6, MxS32 param_6,
BOOL param_7, MxS32 param_7,
BOOL wideViewAngle, MxS32 wideViewAngle,
char* deviceId char* deviceId
); );
MxResult SetupWindow(); MxResult SetupWindow();
void LoadConfig(); void LoadConfig();
void Tick(BOOL sleepIfNotNextFrame); void Tick();
void SetupCursor(WPARAM wParam); void SetupCursor(WPARAM wParam);
static MxU8 MapMouseButtonFlagsToModifier(SDL_MouseButtonFlags p_flags); static MxU8 MapMouseButtonFlagsToModifier(SDL_MouseButtonFlags p_flags);
inline SDL_Window* GetWindowHandle() { return m_windowHandle; } inline SDL_Window* GetWindowHandle() { return m_windowHandle; }
inline MxLong GetFrameDelta() { return m_frameDelta; } inline MxLong GetFrameDelta() { return m_frameDelta; }
inline BOOL GetFullScreen() { return m_fullScreen; } inline MxS32 GetFullScreen() { return m_fullScreen; }
inline HCURSOR GetCursorCurrent() { return m_cursorCurrent; } inline HCURSOR GetCursorCurrent() { return m_cursorCurrent; }
inline HCURSOR GetCursorBusy() { return m_cursorBusy; } inline HCURSOR GetCursorBusy() { return m_cursorBusy; }
inline HCURSOR GetCursorNo() { return m_cursorNo; } inline HCURSOR GetCursorNo() { return m_cursorNo; }
inline BOOL GetDrawCursor() { return m_drawCursor; } inline MxS32 GetDrawCursor() { return m_drawCursor; }
inline void SetWindowActive(BOOL p_windowActive) { m_windowActive = p_windowActive; } inline void SetWindowActive(MxS32 p_windowActive) { m_windowActive = p_windowActive; }
private: private:
char* m_hdPath; // 0x00 char* m_hdPath; // 0x00
char* m_cdPath; // 0x04 char* m_cdPath; // 0x04
char* m_deviceId; // 0x08 char* m_deviceId; // 0x08
char* m_savePath; // 0x0c char* m_savePath; // 0x0c
BOOL m_fullScreen; // 0x10 MxS32 m_fullScreen; // 0x10
BOOL m_flipSurfaces; // 0x14 MxS32 m_flipSurfaces; // 0x14
BOOL m_backBuffersInVram; // 0x18 MxS32 m_backBuffersInVram; // 0x18
BOOL m_using8bit; // 0x1c MxS32 m_using8bit; // 0x1c
BOOL m_using16bit; // 0x20 MxS32 m_using16bit; // 0x20
int m_unk0x24; // 0x24 MxS32 m_unk0x24; // 0x24
BOOL m_use3dSound; // 0x28 MxS32 m_use3dSound; // 0x28
BOOL m_useMusic; // 0x2c MxS32 m_useMusic; // 0x2c
BOOL m_useJoystick; // 0x30 MxS32 m_useJoystick; // 0x30
int m_joystickIndex; // 0x34 MxS32 m_joystickIndex; // 0x34
BOOL m_wideViewAngle; // 0x38 MxS32 m_wideViewAngle; // 0x38
int m_islandQuality; // 0x3c MxS32 m_islandQuality; // 0x3c
int m_islandTexture; // 0x40 MxS32 m_islandTexture; // 0x40
BOOL m_gameStarted; // 0x44 MxS32 m_gameStarted; // 0x44
MxLong m_frameDelta; // 0x48 MxLong m_frameDelta; // 0x48
MxVideoParam m_videoParam; // 0x4c MxVideoParam m_videoParam; // 0x4c
BOOL m_windowActive; // 0x70 MxS32 m_windowActive; // 0x70
SDL_Window* m_windowHandle; // 0x74 SDL_Window* m_windowHandle; // 0x74
BOOL m_drawCursor; // 0x78 MxS32 m_drawCursor; // 0x78
HCURSOR m_cursorArrow; // 0x7c HCURSOR m_cursorArrow; // 0x7c
HCURSOR m_cursorBusy; // 0x80 HCURSOR m_cursorBusy; // 0x80
HCURSOR m_cursorNo; // 0x84 HCURSOR m_cursorNo; // 0x84

View File

@ -36,8 +36,8 @@ class MxThread {
static unsigned ThreadProc(void* p_thread); static unsigned ThreadProc(void* p_thread);
SDL_Thread* m_thread; SDL_Thread* m_thread;
MxBool m_running; MxBool m_running; // 0x0c
MxSemaphore m_semaphore; MxSemaphore m_semaphore; // 0x10
protected: protected:
MxCore* m_target; // 0x18 MxCore* m_target; // 0x18

View File

@ -1,12 +1,12 @@
#include "mxcriticalsection.h" #include "mxcriticalsection.h"
#include "decomp.h" #include "decomp.h"
#include "platform.h" #include "mxtypes.h"
DECOMP_SIZE_ASSERT(MxCriticalSection, 0x1c) DECOMP_SIZE_ASSERT(MxCriticalSection, 0x1c)
// GLOBAL: LEGO1 0x10101e78 // GLOBAL: LEGO1 0x10101e78
BOOL g_useMutex = FALSE; MxS32 g_useMutex = FALSE;
// FUNCTION: LEGO1 0x100b6d20 // FUNCTION: LEGO1 0x100b6d20
MxCriticalSection::MxCriticalSection() MxCriticalSection::MxCriticalSection()

View File

@ -1,20 +0,0 @@
#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