Add SDL callbacks to isleapp

This commit is contained in:
Christian Semmler 2024-05-31 10:13:10 -04:00
parent 9c83acb3b1
commit 4717531f91

View File

@ -27,6 +27,8 @@
#include "roi/legoroi.h"
#include "viewmanager/viewmanager.h"
#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL_main.h>
#include <dsound.h>
DECOMP_SIZE_ASSERT(IsleApp, 0x8c)
@ -236,12 +238,11 @@ void IsleApp::SetupVideoFlags(
}
}
// FUNCTION: ISLE 0x401610
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
int SDL_AppInit(void** appstate, int argc, char** argv)
{
// Look for another instance, if we find one, bring it to the foreground instead
if (!FindExistingInstance()) {
return 0;
return 1;
}
// Attempt to create DirectSound instance
@ -263,40 +264,36 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
"Lego Island Error",
MB_OK
);
return 0;
return -1;
}
// Create global app instance
g_isle = new IsleApp();
// Create window
if (g_isle->SetupWindow(hInstance, lpCmdLine) != SUCCESS) {
if (g_isle->SetupWindow(GetModuleHandle(NULL), NULL) != SUCCESS) {
MessageBoxA(
NULL,
"\"LEGO\xAE Island\" failed to start. Please quit all other applications and try again.",
"LEGO\xAE Island Error",
MB_OK
);
return 0;
return -1;
}
// Get reference to window
HWND window;
if (g_isle->GetWindowHandle()) {
window = g_isle->GetWindowHandle();
*appstate = g_isle->GetWindowHandle();
return 0;
}
// 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;
while (!g_closed) {
if (g_closed) {
return 1;
}
while (!PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (g_isle) {
g_isle->Tick(1);
@ -327,7 +324,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
if (g_closed) {
break;
return 1;
}
if (g_mousedown && g_mousemoved && g_isle) {
@ -338,11 +335,19 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_mousemoved = FALSE;
}
}
return 0;
}
DestroyWindow(window);
int SDL_AppEvent(void* appstate, const SDL_Event* event)
{
// Process events here once we use SDL window
return 0;
}
return msg.wParam;
void SDL_AppQuit(void* appstate)
{
DestroyWindow((HWND) appstate);
}
// FUNCTION: ISLE 0x401ca0