Add SDL callbacks to isleapp (#9)

* Add SDL callbacks to isleapp

* Update README.md

* Update README.md
This commit is contained in:
Christian Semmler 2024-05-31 10:45:51 -04:00 committed by Anonymous Maarten
parent 21502ecf18
commit 889bd4c1cd
2 changed files with 67 additions and 60 deletions

View File

@ -27,6 +27,8 @@
#include "roi/legoroi.h" #include "roi/legoroi.h"
#include "viewmanager/viewmanager.h" #include "viewmanager/viewmanager.h"
#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL_main.h>
#include <dsound.h> #include <dsound.h>
DECOMP_SIZE_ASSERT(IsleApp, 0x8c) DECOMP_SIZE_ASSERT(IsleApp, 0x8c)
@ -236,12 +238,11 @@ void IsleApp::SetupVideoFlags(
} }
} }
// FUNCTION: ISLE 0x401610 int SDL_AppInit(void** appstate, int argc, char** argv)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{ {
// Look for another instance, if we find one, bring it to the foreground instead // Look for another instance, if we find one, bring it to the foreground instead
if (!FindExistingInstance()) { if (!FindExistingInstance()) {
return 0; return 1;
} }
// Attempt to create DirectSound instance // Attempt to create DirectSound instance
@ -263,86 +264,90 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
"Lego Island Error", "Lego Island Error",
MB_OK MB_OK
); );
return 0; return -1;
} }
// Create global app instance // Create global app instance
g_isle = new IsleApp(); g_isle = new IsleApp();
// Create window // Create window
if (g_isle->SetupWindow(hInstance, lpCmdLine) != SUCCESS) { if (g_isle->SetupWindow(GetModuleHandle(NULL), NULL) != SUCCESS) {
MessageBoxA( MessageBoxA(
NULL, NULL,
"\"LEGO\xAE Island\" failed to start. Please quit all other applications and try again.", "\"LEGO\xAE Island\" failed to start. Please quit all other applications and try again.",
"LEGO\xAE Island Error", "LEGO\xAE Island Error",
MB_OK MB_OK
); );
return 0; return -1;
} }
// Get reference to window // Get reference to window
HWND window; *appstate = g_isle->GetWindowHandle();
if (g_isle->GetWindowHandle()) { return 0;
window = g_isle->GetWindowHandle(); }
}
// Load accelerators (this call actually achieves nothing - there is no "AppAccel" resource in the original - but
// we'll keep this for authenticity) This line may actually be here because it's in DFVIEW, an example project that
// ships with MSVC420, and was such a clean example of a Win32 app, that it was later adapted into an "ExeSkeleton"
// sample for MSVC600. It's quite possible Mindscape derived this app from that example since they no longer had the
// luxury of the MFC AppWizard which we know they used for the frontend used during development (ISLEMFC.EXE,
// MAIN.EXE, et al.)
LoadAcceleratorsA(hInstance, "AppAccel");
int SDL_AppIterate(void* appstate)
{
MSG msg; MSG msg;
if (g_closed) {
return 1;
}
while (!PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (g_isle) {
g_isle->Tick(1);
}
}
if (g_isle) {
g_isle->Tick(0);
}
while (!g_closed) { while (!g_closed) {
while (!PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) {
if (g_isle) { break;
g_isle->Tick(1);
}
} }
if (g_isle) { MSG nextMsg;
if (!g_isle || !g_isle->GetWindowHandle() || msg.message != WM_MOUSEMOVE ||
!PeekMessageA(&nextMsg, NULL, 0, 0, PM_NOREMOVE) || nextMsg.message != WM_MOUSEMOVE) {
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
if (g_reqEnableRMDevice) {
g_reqEnableRMDevice = FALSE;
VideoManager()->EnableRMDevice();
g_rmDisabled = FALSE;
Lego()->StopTimer();
}
if (g_closed) {
return 1;
}
if (g_mousedown && g_mousemoved && g_isle) {
g_isle->Tick(0); g_isle->Tick(0);
} }
while (!g_closed) { if (g_mousemoved) {
if (!PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) { g_mousemoved = FALSE;
break;
}
MSG nextMsg;
if (!g_isle || !g_isle->GetWindowHandle() || msg.message != WM_MOUSEMOVE ||
!PeekMessageA(&nextMsg, NULL, 0, 0, PM_NOREMOVE) || nextMsg.message != WM_MOUSEMOVE) {
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
if (g_reqEnableRMDevice) {
g_reqEnableRMDevice = FALSE;
VideoManager()->EnableRMDevice();
g_rmDisabled = FALSE;
Lego()->StopTimer();
}
if (g_closed) {
break;
}
if (g_mousedown && g_mousemoved && g_isle) {
g_isle->Tick(0);
}
if (g_mousemoved) {
g_mousemoved = FALSE;
}
} }
} }
DestroyWindow(window); return 0;
}
return msg.wParam; int SDL_AppEvent(void* appstate, const SDL_Event* event)
{
// Process events here once we use SDL window
return 0;
}
void SDL_AppQuit(void* appstate)
{
DestroyWindow((HWND) appstate);
} }
// FUNCTION: ISLE 0x401ca0 // FUNCTION: ISLE 0x401ca0

View File

@ -20,14 +20,16 @@ Please note: this project is dedicated to achieving platform independence withou
To achieve our goal of platform independence, we need to replace any Windows-only libraries with platform-independent alternatives. This ensures that our codebase remains versatile and compatible across various systems. The following table serves as an overview of major libraries / subsystems and their chosen replacements. For any significant changes or additions, it's recommended to discuss them with the team on the Matrix chat first to ensure consistency and alignment with our project's objectives. To achieve our goal of platform independence, we need to replace any Windows-only libraries with platform-independent alternatives. This ensures that our codebase remains versatile and compatible across various systems. The following table serves as an overview of major libraries / subsystems and their chosen replacements. For any significant changes or additions, it's recommended to discuss them with the team on the Matrix chat first to ensure consistency and alignment with our project's objectives.
| Library | Substitution | Implementation status | | | Library/subsystem | Substitution | Status | |
| - | - | - | - | | - | - | - | - |
| [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) | | Window, Events | [SDL3](https://www.libsdl.org/) | WIP | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Awindow%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) | | Windows Registry (Configuration) | [libiniparser](https://github.com/ndevilla/iniparser) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aconfig%5D%22&type=code) |
| Filesystem | [SDL3](https://www.libsdl.org/) | ❌ | [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) | | 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) | | WinMM, DirectSound (Audio) | [SDL_mixer](https://github.com/libsdl-org/SDL_mixer) | ❌ | [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) | | 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) |
| [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) |
| 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 (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**) | ❌ | [Remarks](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 | - | - |