27#include "res/resource.h"
69#define WNDCLASS_NAME "Lego Island MainNoM App"
72#define WINDOW_TITLE "LEGO\xAE"
86 m_flipSurfaces =
FALSE;
87 m_backBuffersInVram =
TRUE;
94 m_useJoystick =
FALSE;
96 m_wideViewAngle =
TRUE;
99 m_gameStarted =
FALSE;
101 m_windowActive =
TRUE;
114 m_windowHandle =
NULL;
115 m_cursorArrow =
NULL;
118 m_cursorCurrent =
NULL;
170 while (
Lego() && !
Lego()->DoesEntityExist(ds)) {
182 GetProfileStringA(
"LEGO Island",
"MediaPath",
"", mediaPath,
sizeof(mediaPath));
235int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nShowCmd)
244 for (
int i = 0; i < 20; i++) {
256 "\"LEGO\xAE Island\" is not detecting a DirectSound compatible sound card. Please quit all other "
257 "applications and try again.",
271 "\"LEGO\xAE Island\" failed to start. Please quit all other applications and try again.",
272 "LEGO\xAE Island Error",
290 LoadAcceleratorsA(hInstance,
"AppAccel");
295 while (!PeekMessageA(&msg,
NULL, 0, 0, PM_NOREMOVE)) {
306 if (!PeekMessageA(&msg,
NULL, 0, 0, PM_REMOVE)) {
312 !PeekMessageA(&nextMsg,
NULL, 0, 0, PM_NOREMOVE) || nextMsg.message != WM_MOUSEMOVE) {
313 TranslateMessage(&msg);
314 DispatchMessageA(&msg);
338 DestroyWindow(window);
348 if (SetForegroundWindow(
hWnd)) {
349 ShowWindow(
hWnd, SW_RESTORE);
370LRESULT WINAPI
WndProc(HWND
hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
373 unsigned char keyCode = 0;
376 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
381 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
383 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
398 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
406 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
407 case WM_GETMINMAXINFO:
413 case WM_ENTERMENULOOP:
414 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
416 if (wParam == SC_SCREENSAVE) {
431 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
432 case WM_EXITMENULOOP:
433 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
436 GetWindowRect(
hWnd, (LPRECT) lParam);
439 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
444 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
445 case WM_DISPLAYCHANGE:
448 int targetDepth = wParam;
449 int targetWidth = LOWORD(lParam);
450 int targetHeight = HIWORD(lParam);
477 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
481 if (lParam & (KF_REPEAT << 16)) {
482 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
516 return DefWindowProcA(
hWnd, uMsg, wParam, lParam);
524 int x = LOWORD(lParam);
525 int y = HIWORD(lParam);
543 ZeroMemory(&wndclass,
sizeof(WNDCLASSA));
561 srand(timeGetTime() / 1000);
562 SystemParametersInfoA(SPI_SETMOUSETRAILS, 0,
NULL, 0);
564 ZeroMemory(&wndclass,
sizeof(WNDCLASSA));
566 wndclass.cbClsExtra = 0;
567 wndclass.style = CS_HREDRAW | CS_VREDRAW;
568 wndclass.lpfnWndProc =
WndProc;
569 wndclass.cbWndExtra = 0;
570 wndclass.hIcon = LoadIconA(hInstance, MAKEINTRESOURCEA(
APP_ICON));
571 wndclass.hCursor = m_cursorArrow = m_cursorCurrent = LoadCursorA(hInstance, MAKEINTRESOURCEA(
ISLE_ARROW));
572 m_cursorBusy = LoadCursorA(hInstance, MAKEINTRESOURCEA(
ISLE_BUSY));
573 m_cursorNo = LoadCursorA(hInstance, MAKEINTRESOURCEA(
ISLE_NO));
574 wndclass.hInstance = hInstance;
575 wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
578 if (!RegisterClassA(&wndclass)) {
583 AdjustWindowRectEx(&
g_windowRect, WS_CAPTION | WS_SYSMENU, 0, WS_EX_APPWINDOW);
585 m_windowHandle = CreateWindowExA(
589 WS_CAPTION | WS_SYSMENU,
601 AdjustWindowRectEx(&
g_windowRect, WS_CAPTION | WS_SYSMENU, 0, WS_EX_APPWINDOW);
603 m_windowHandle = CreateWindowExA(
607 WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
619 if (!m_windowHandle) {
634 ShowWindow(m_windowHandle, SW_SHOWNORMAL);
635 UpdateWindow(m_windowHandle);
645 switch (m_islandQuality) {
656 int uVar1 = (m_islandTexture == 0);
679 ShowWindow(m_windowHandle, SW_SHOWNORMAL);
680 UpdateWindow(m_windowHandle);
692 DWORD size = outSize;
693 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Mindscape\\LEGO Island", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
694 if (RegQueryValueExA(hKey, name,
NULL, &valueType, (LPBYTE) outValue, &size) == ERROR_SUCCESS) {
695 if (RegCloseKey(hKey) == ERROR_SUCCESS) {
711 if (strcmp(
"YES", buffer) == 0) {
716 if (strcmp(
"NO", buffer) == 0) {
744 if (!
ReadReg(
"diskpath", buffer,
sizeof(buffer))) {
748 m_hdPath =
new char[strlen(buffer) + 1];
749 strcpy(m_hdPath, buffer);
752 if (!
ReadReg(
"cdpath", buffer,
sizeof(buffer))) {
756 m_cdPath =
new char[strlen(buffer) + 1];
757 strcpy(m_cdPath, buffer);
766 ReadRegInt(
"JoystickIndex", &m_joystickIndex);
769 int backBuffersInVRAM;
770 if (
ReadRegBool(
"Back Buffers in Video RAM", &backBuffersInVRAM)) {
771 m_backBuffersInVram = !backBuffersInVRAM;
775 if (
ReadRegInt(
"Display Bit Depth", &bitDepth)) {
779 else if (bitDepth == 16) {
784 if (!
ReadReg(
"Island Quality", buffer,
sizeof(buffer))) {
787 m_islandQuality = atoi(buffer);
789 if (!
ReadReg(
"Island Texture", buffer,
sizeof(buffer))) {
792 m_islandTexture = atoi(buffer);
794 if (
ReadReg(
"3D Device ID", buffer,
sizeof(buffer))) {
795 m_deviceId =
new char[strlen(buffer) + 1];
796 strcpy(m_deviceId, buffer);
799 if (
ReadReg(
"savepath", buffer,
sizeof(buffer))) {
800 m_savePath =
new char[strlen(buffer) + 1];
801 strcpy(m_savePath, buffer);
809 static MxLong g_lastFrameTime = 0;
812 static int g_startupDelay = 200;
814 if (!m_windowActive) {
830 if (currentTime < g_lastFrameTime) {
831 g_lastFrameTime = -m_frameDelta;
834 if (m_frameDelta + g_lastFrameTime < currentTime) {
835 if (!
Lego()->IsPaused()) {
838 g_lastFrameTime = currentTime;
840 if (g_startupDelay == 0) {
845 if (g_startupDelay != 0) {
877 m_gameStarted =
TRUE;
880 else if (sleepIfNotNextFrame != 0) {
890 m_cursorCurrent = m_cursorArrow;
893 m_cursorCurrent = m_cursorBusy;
896 m_cursorCurrent = m_cursorNo;
899 m_cursorCurrent =
NULL;
911 SetCursor(m_cursorCurrent);
#define ISLE_NO
[AI] Resource ID for the custom "no" cursor, typically indicates an invalid action or forbidden area.
#define APP_ICON
[AI] Resource ID for the main application icon (e.g., window/taskbar icon for LEGO Island).
#define ISLE_ARROW
[AI] Resource ID definitions for cursor icons and application icon.
#define ISLE_BUSY
[AI] Resource ID for the custom "busy" cursor, used to indicate processes such as loading or waiting.
[AI] Main application class for LEGO Island.
void Tick(BOOL sleepIfNotNextFrame)
[AI] Executes a single frame tick/update for the game, managing timing, engine state,...
MxResult SetupWindow(HINSTANCE hInstance, LPSTR lpCmdLine)
[AI] Creates the application window, registers the window class, loads icons/cursors,...
HCURSOR GetCursorCurrent()
[AI] Gets the HCURSOR currently active for the application.
void SetupCursor(WPARAM wParam)
[AI] Sets the current mouse cursor based on application or game state.
void LoadConfig()
[AI] Loads all configuration from the registry (disk path, CD path, sound, joystick,...
BOOL GetDrawCursor()
[AI] Returns TRUE if the application is drawing the custom cursor.
void SetWindowActive(BOOL p_windowActive)
[AI] Sets application window active status (focus/active state).
BOOL ReadRegBool(LPCSTR name, BOOL *out)
[AI] Reads a boolean (YES/NO string) value from registry.
BOOL SetupLegoOmni()
[AI] Initializes the core LEGO Island engine with the current settings and media path.
void SetupVideoFlags(BOOL fullScreen, BOOL flipSurfaces, BOOL backBuffers, BOOL using8bit, BOOL using16bit, BOOL param_6, BOOL param_7, BOOL wideViewAngle, char *deviceId)
[AI] Configures video mode and 3D device flags for rendering (fullscreen, backbuffers,...
HCURSOR GetCursorNo()
[AI] Gets the HCURSOR representing the "not allowed" cursor.
~IsleApp()
[AI] Destructor.
BOOL GetFullScreen()
[AI] Returns TRUE if the game is in fullscreen mode.
void Close()
[AI] Gracefully closes down the LEGO Island game, including engine teardown and saving player progres...
IsleApp()
[AI] Constructor.
HCURSOR GetCursorBusy()
[AI] Gets the HCURSOR representing the "busy" cursor.
HWND GetWindowHandle()
[AI] Returns the handle to the main application window.
BOOL ReadReg(LPCSTR name, LPSTR outValue, DWORD outSize)
[AI] Reads a string value from the LEGO Island registry key under HKLM.
BOOL ReadRegInt(LPCSTR name, int *out)
[AI] Reads an integer value from registry.
Lego3DView * GetLego3DView()
[AI] Returns the encapsulated Lego3DView instance.
ViewManager * GetViewManager()
[AI] Returns the ViewManager responsible for managing scene objects and transformations.
static void configureLegoAnimationManager(MxS32 p_legoAnimationManagerConfig)
[AI] Updates the configuration values (global) for animation manager's allowed number of extras,...
static void configureLegoBuildingManager(MxS32 p_buildingManagerConfig)
[AI] Configure static settings for the LegoBuildingManager globally.
void SerializeScoreHistory(MxS16 p_flags)
Serializes the score history table to score file.
void SetSavePath(char *p_savePath)
Sets the path for current save slot directory; creates a copy of input string.
void SerializePlayersInfo(MxS16 p_flags)
Serializes all player info (usernames, player count) to the appropriate storage.
MxResult Save(MxULong p_slot)
Saves persistent game state (world variables, actor, etc.) to a file slot.
static void configureLegoModelPresenter(MxS32 p_modelPresenterConfig)
[AI] Configures the LegoModelPresenter's handling of textures/model data.
void Resume() override
[AI] Resumes engine/game state and sets default cursor.
static LegoOmni * GetInstance()
[AI] Returns the current LegoOmni singleton pointer, cast from MxOmni.
void RemoveWorld(const MxAtomId &p_atom, MxLong p_objectId)
[AI] Removes worlds by Atom and/or id, deleting matching entries from the world list and freeing reso...
LegoInputManager * GetInputManager()
[AI] Returns the input manager.
static void CreateInstance()
[AI] Allocates and sets up a new LegoOmni singleton instance, replacing the previous one if any.
void CreateBackgroundAudio()
[AI] Initializes background audio manager and starts music using global script.
void Pause() override
[AI] Pauses the engine/game state and sets busy cursor.
MxResult Create(MxOmniCreateParam &p_param) override
[AI] Creates and initializes all subsystems for the game, wiring up all managers and attaching Lego-s...
void DeleteObject(MxDSAction &p_dsAction) override
[AI] Deletes an entity or world referenced by the given DSAction (by object and Atom),...
static void configureLegoPartPresenter(MxS32 p_partPresenterConfig1, MxS32 p_partPresenterConfig2)
[AI] Configure global settings for texture loading order and maximum number of LODs.
static void configureLegoROI(int p_roi)
[AI] [Static] Configures the global ROI loading limit, controlling max LODs at load time.
@ c_read
Open for read operations. [AI].
int EnableRMDevice()
[AI] Enables the Direct3D Retained Mode (RM) rendering device, and re-creates the device/viewport if ...
void EnableFullScreenMovie(MxBool p_enable)
[AI] Convenience method to enable or disable fullscreen movie playback with default scaling.
int DisableRMDevice()
[AI] Disables the Direct3D Retained Mode (RM) rendering device and saves/restores 3D state as needed.
Lego3DManager * Get3DManager()
[AI] Returns the Lego3DManager for this manager, which owns all 3D scene representations and view con...
void MoveCursor(MxS32 p_cursorX, MxS32 p_cursorY)
[AI] Updates the position of the custom software cursor overlay, and ensures it renders on the next f...
static void configureLegoWorldPresenter(MxS32 p_legoWorldPresenterQuality)
[AI] Configure the global 'quality' level for presenting the LEGO world.
void Enable(MxBool p_enable)
[AI] Enables or disables the background audio manager.
[AI] Represents an action deserialized from SI chunks, holding key animation or script parameters suc...
const MxAtomId & GetAtomId()
[AI] Returns a const-reference to the object's atom identifier.
virtual void SetAtomId(MxAtomId p_atomId)
[AI] Sets the atom id for this object instance, used for indexing or lookup.
void SetUnknown24(MxS16 p_unk0x24)
[AI] Sets the unknown field at 0x24 (possibly version/state).
void SetObjectId(MxU32 p_objectId)
[AI] Sets the object id (for serialization or lookup).
MxU32 GetObjectId()
[AI] Returns the object id numeric value.
static int GetPrimaryBitDepth()
Returns the bit depth (color depth) of the primary display device.
[AI] Stores creation flags for initializing core LEGO Island engine subsystems.
[AI] Encapsulates parameters required to initialize the core Omni engine.
static const char * GetCD()
[AI] Retrieves the configured CD-ROM media path string used for resource location.
static void SetCD(const char *p_cd)
[AI] Sets the global CD media path used for source file lookup.
static void DestroyInstance()
[AI] Destroys the singleton MxOmni instance and performs memory cleanup.
static const char * GetHD()
[AI] Retrieves the configured hard disk media path string used for resource location.
static void SetSound3D(MxBool p_use3dSound)
[AI] Enables or disables use of 3D sound processing.
static void SetHD(const char *p_hd)
[AI] Sets the global hard disk media path used for resource lookup.
[AI] Rectangle using 32-bit signed integer coordinates.
[AI] Controller for streaming and managing multimedia resources and actions during gameplay.
MxAtomId & GetAtom()
[AI] Retrieves the atom ID (unique logical identifier) for this stream controller.
MxStreamController * Open(const char *p_name, MxU16 p_openMode)
Open a stream, returning a controller for further access [AI].
@ e_diskStream
Load streaming resource from disk [AI].
virtual void SetClientTickleInterval(MxCore *p_client, MxTime p_interval)
[AI] Changes the tickle interval of an already registered client.
MxResult Tickle() override
[AI] Iterates over registered clients and invokes their Tickle() methods as needed.
MxLong GetRealTime()
Retrieves the elapsed real time (in ms) since timer construction or last reset.
void SetWaitIndicator(MxVideoPresenter *p_waitIndicator)
[AI] Sets or resets the visual wait indicator presented during blocking transitions.
void SetVariable(const char *p_key, const char *p_value)
Sets a variable by key and value, replacing or updating if it exists.
[AI] Manages video parameter flags, providing an abstraction for various video settings such as fulls...
void SetF1bit7(MxBool p_e)
[AI] Set an additional flag (purpose unknown; originally used by the engine for extension).
void SetF2bit1(MxBool p_e)
[AI] Set secondary flag 1 (often used for internal video logic).
void SetWideViewAngle(MxBool p_e)
[AI] Enable or disable a wider field of view for 3D rendering.
void SetBackBuffers(MxBool p_e)
[AI] Toggle the use of a back buffer (double-buffered rendering).
void SetF2bit0(MxBool p_e)
[AI] Set secondary flag 0 (often used for internal video logic).
void Set16Bit(MxBool p_e)
[AI] Specify whether 16-bit color depth should be used for rendering.
void SetFlipSurfaces(MxBool p_e)
[AI] Toggle the use of flip (page flipping) for surfaces.
void SetFullScreen(MxBool p_e)
[AI] Enable or disable fullscreen mode.
[AI] Video parameter configuration for display and rendering, encapsulates resolution,...
void SetDeviceName(char *p_deviceId)
[AI] Set the device name/id for this video parameter (e.g., a specific display adapter),...
MxVideoParamFlags & Flags()
[AI] Access the video parameter flags (windowed/fullscreen, rendering mode, etc).
void RemoveAll(ViewROI *p_roi)
[AI] Recursively removes all ViewROI objects.
typedef DWORD(FAR PASCAL *LPCLIPPERCALLBACK)(LPDIRECTDRAWCLIPPER lpDDClipper
#define DECOMP_SIZE_ASSERT(T, S)
HRESULT WINAPI DirectSoundCreate(LPGUID, LPDIRECTSOUND *, LPUNKNOWN)
struct IDirectSound * LPDIRECTSOUND
unsigned char g_mousemoved
unsigned char g_mousedown
BOOL g_waitingForTargetDepth
BOOL FindExistingInstance()
LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
#define NULL
[AI] Null pointer value (C/C++ semantics).
#define FAILURE
[AI] Used to indicate a failed operation in result codes.
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
#define WM_ISLE_SETCURSOR
[AI] Custom Windows message for setting the cursor in LEGO Island. Used with PostMessage....
@ e_cursorUnused3
[AI] Reserved slot. Not used. [AI]
@ e_cursorUnused5
[AI] Reserved slot. Not used. [AI]
@ e_cursorUnused7
[AI] Reserved slot. Not used. [AI]
@ e_cursorBusy
[AI] Busy or loading cursor (e.g., hourglass). [AI]
@ e_cursorNone
[AI] No cursor (invisible or hidden). [AI]
@ e_cursorUnused10
[AI] Reserved slot. Not used. [AI]
@ e_cursorUnused8
[AI] Reserved slot. Not used. [AI]
@ e_cursorArrow
[AI] Standard arrow cursor. [AI]
@ e_cursorUnused9
[AI] Reserved slot. Not used. [AI]
@ e_cursorUnused4
[AI] Reserved slot. Not used. [AI]
@ e_cursorUnused6
[AI] Reserved slot. Not used. [AI]
@ e_cursorNo
[AI] 'Not allowed' cursor. [AI]
LegoGameState * GameState()
[AI] Accessor for the game's central game state controller. [AI]
LegoVideoManager * VideoManager()
[AI] Accessor for the game's LegoVideoManager subsystem. Used for managing 3D/video hardware....
MxTransitionManager * TransitionManager()
[AI] Accessor for the MxTransitionManager, handling level transitions, fades, and world changes....
MxBackgroundAudioManager * BackgroundAudioManager()
[AI] Accessor for the background audio manager. Used for background music and ambient sounds....
LegoOmni * Lego()
[AI] Retrieves the global LegoOmni singleton instance, providing access to core subsystems.
LegoInputManager * InputManager()
[AI] Accessor for the input manager, which handles keyboard, mouse, and controller input....
MxTimer * Timer()
[AI] Returns the global simulation timer.
MxResult Start(MxDSAction *p_dsAction)
[AI] Schedules and initiates execution of a script action.
MxVariableTable * VariableTable()
[AI] Returns the variable table used for script variables and global key/value state.
MxStreamer * Streamer()
[AI] Returns the global streamer used for all chunked media streaming (SI file, audio,...
MxTickleManager * TickleManager()
[AI] Provides access to the global tickle manager.
NotificationId
Several of those should be defined in LegoOmni.
@ c_notificationTimer
[AI] Timer-related event [AI]
@ c_notificationButtonUp
[AI] Mouse/gamepad button release [AI]
@ c_notificationButtonDown
[AI] Mouse/gamepad button press [AI]
@ c_notificationMouseMove
[AI] Mouse movement event [AI]
@ c_notificationKeyPress
[AI] Keyboard key press detected [AI]