From 49430fe3f81d1a2571b88549d892296469915fc6 Mon Sep 17 00:00:00 2001 From: Milenko <39630670+MrMilenko@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:48:22 -0500 Subject: [PATCH 1/8] Named the binary's app class CAppShell The app class at 0x0017e7a0 never had a name in the binary, so I picked CAppShell and used it in the docs and comments. Its frame loop is AppShell_Run and the alloc and sound buffer helpers follow the same prefix. --- docs/decomp/AppShell.md | 4 ++-- docs/decomp/AudioSystem.md | 2 +- docs/decomp/README.md | 22 +++++++++++----------- docs/decomp/XIP.md | 4 ++-- theseus/render/xip_archive.cpp | 2 +- theseus/shared/audio_system.cpp | 2 +- theseus/xbox/disc_management.cpp | 2 +- theseus/xbox/main.cpp | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/decomp/AppShell.md b/docs/decomp/AppShell.md index c3afe11..9b5430f 100644 --- a/docs/decomp/AppShell.md +++ b/docs/decomp/AppShell.md @@ -13,9 +13,9 @@ Start up and the frame loop of the 5960 retail binary. The app object lives at ` | 0x0002d0e0 | Draw | Below | | 0x0002d7e0 | InitApp | Below | | 0x0002d930 | CleanupApp | XOnline cleanup, matrix stack, scene, class, `Class_Exit`, XIP sections, `Text_Exit`, DirectSound, app dir | -| 0x0002da00 | XApp | `InitApp`, then forever: clock, keyboard poll, camera, lerpers, scene advance, deferred deletes, `Draw` | +| 0x0002da00 | AppShell_Run | `InitApp`, then forever: clock, keyboard poll, camera, lerpers, scene advance, deferred deletes, `Draw` | | 0x0002dbc0 | GetStartupClassFile | `y:\default.xap`, current dir `y:/default.xap` | -| 0x0002dc80 | main | Crash handler unless the hardware is a debug kit, then `XApp` | +| 0x0002dc80 | main | Crash handler unless the hardware is a debug kit, then `AppShell_Run` | | 0x0002dcc0 | XboxFormatMemoryUnit | Device object into a 32 byte name, `XapiFormatFATVolume`, close | | 0x0002dd20 | Xbox_Init | Below | | 0x00062750 | DSound_Init | Below | diff --git a/docs/decomp/AudioSystem.md b/docs/decomp/AudioSystem.md index 44278ae..2d82aa0 100644 --- a/docs/decomp/AudioSystem.md +++ b/docs/decomp/AudioSystem.md @@ -165,7 +165,7 @@ The threshold balances DSound buffer allocation cost (static is cheaper but hold | Address | Function | Notes | |---------|----------|-------| | 0x00062750 | DSound_Init | Skipped in DVD boot mode (boot type 4). Reads `XGetAudioFlags`, `DirectSoundCreate(0, &ds, 0)`, then `SetMixBinHeadroom(bin, 0)` for all 31 mix bins and starts the DoWork thread (0x62680) | -| 0x000626b0 | XAppCreateSoundBuffer | Runs DSound_Init on first use, `CreateSoundBuffer` with a 0x18 byte desc, `SetHeadroom(1200)` | +| 0x000626b0 | AppShell_CreateSoundBuffer | Runs DSound_Init on first use, `CreateSoundBuffer` with a 0x18 byte desc, `SetHeadroom(1200)` | | 0x00062960 | CAudioBuf dtor | Stop, Release | | 0x000629a0 / 0x000629d0 | Lock / Unlock | Whole buffer from 0 | | 0x00062a30 | CAudioBuf::Stop | Stop, then spins on GetStatus until it reports stopped | diff --git a/docs/decomp/README.md b/docs/decomp/README.md index 2af93ec..128df54 100644 --- a/docs/decomp/README.md +++ b/docs/decomp/README.md @@ -33,7 +33,7 @@ When in doubt about an entry, run the address through Ghidra and compare. The po | 0x000147c8 | `_classCMemoryMonitor` | `CMemoryMonitor::class` (memory_monitor.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the storage-device watcher node. | | 0x00014b38 | `_classCLayout` | `CLayout::class` (scene_groups.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the radial layout container (used by the dashboard's main menu wheel). | | 0x00014b3c | `_classCBillboard` | `CBillboard::class` (scene_groups.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the camera-facing quad node. | -| 0x0001a06c | `_classCXAppNode` | `CXAppNode::class` (main.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the application root node type. | +| 0x0001a06c | `_classCAppShellNode` | `CAppShellNode::class` (main.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the application root node type. | | 0x0001a098 | `_classCTimeDepNode` | `CTimeDepNode::class` (animation_nodes.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for time-dependent node base. | | 0x0001a0f0 | `_classCArrayObject` | `CArrayObject::class` (array.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the script-visible Array type. | | 0x0001a1b0 | `_classCDateObject` | `CDateObject::class` (date_node.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the script-visible Date type. | @@ -58,18 +58,18 @@ When in doubt about an entry, run the address through Ghidra and compare. The po | 0x0001f300 | `_classCMaxMaterial` | `CMaxMaterial::class` (materials.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the 3ds Max material translator node. | | 0x0001f33c | `_classCLayer` | `CLayer::class` (scene_groups.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the 2D-overlay layer node. | | 0x0001f368 | `_classCKeyboard` | `CKeyboard::class` (keyboard_node.cpp) | [Scene Graph](Node.md) | Static `CNodeClass` registration for the on-screen keyboard node. | -| 0x0002c570 | `CXApp::CXApp` | globals init in `main.cpp` | [App Shell](#app-shell) | Constructor for the original `CXApp` singleton. Theseus replaced this with module-scope globals and free functions; the binary class is preserved for reference. | +| 0x0002c570 | `CAppShell::CAppShell` | globals init in `main.cpp` | [App Shell](#app-shell) | Constructor for the original `CAppShell` singleton. Theseus replaced this with module-scope globals and free functions; the binary class is preserved for reference. | | 0x0002cc10 | `Xbox_Init` | `Xbox_Init` (main.cpp) | [App Shell](#app-shell) | Early-boot init: `XOnlineStartup`, drive-letter symlinks, `XSetFileCacheSize`, `XInitDevices`, region detection, network bring-up. Runs before scene graph creation. | -| 0x0002d0e0 | `CXApp::Draw` | main loop in `main.cpp` | [App Shell](#app-shell) | Per-frame render entry. Calls scene graph traversal then `Present`. | -| 0x0002d7e0 | `CXApp::InitApp` | `TheseusInit` in `main.cpp` | [App Shell](#app-shell) | Direct3D device creation, scene graph bootstrap, initial XIP load. | -| 0x0002d930 | `CXApp::CleanupApp` | `TheseusShutdown` in `main.cpp` | [App Shell](#app-shell) | Tear-down: scene graph destruction, D3D device release. | -| 0x0002da00 | `XApp` | (vtable / class registration) | [App Shell](#app-shell) | CXApp class-table thunk emitted by the compiler. Theseus's CTheseus equivalent was eliminated; the binary still has it. | -| 0x0002dbc0 | `CXApp::GetStartupClassFile` | startup logic in `main.cpp` | [App Shell](#app-shell) | Resolves the boot XAP file from config. The dashboard's first scene is loaded by string lookup against this path. | +| 0x0002d0e0 | `CAppShell::Draw` | main loop in `main.cpp` | [App Shell](#app-shell) | Per-frame render entry. Calls scene graph traversal then `Present`. | +| 0x0002d7e0 | `CAppShell::InitApp` | `TheseusInit` in `main.cpp` | [App Shell](#app-shell) | Direct3D device creation, scene graph bootstrap, initial XIP load. | +| 0x0002d930 | `CAppShell::CleanupApp` | `TheseusShutdown` in `main.cpp` | [App Shell](#app-shell) | Tear-down: scene graph destruction, D3D device release. | +| 0x0002da00 | `AppShell_Run` | frame loop in `main.cpp` | [App Shell](#app-shell) | Runs `InitApp`, then the frame loop forever: clock, input, camera, lerpers, scene advance, `Draw`. | +| 0x0002dbc0 | `CAppShell::GetStartupClassFile` | startup logic in `main.cpp` | [App Shell](#app-shell) | Resolves the boot XAP file from config. The dashboard's first scene is loaded by string lookup against this path. | | 0x0002dc50 | `CRecovery::StartRecovery` | `CReboot::Reboot` in `reboot_node.cpp` | [App Shell](#app-shell) | Original entry to factory recovery via `DashRecovery()`. Theseus replaced with `CReboot::Reboot()` returning to firmware; recovery as a concept does not apply on modded hardware. | -| 0x0002dc80 | `main` | `main` (main.cpp) | [App Shell](#app-shell) | C entry point. Calls `Xbox_Init`, constructs the global `CXApp` (`theApp`), enters the per-frame `Draw` loop. | -| 0x0002def0 | `XAppCreateFile` | `TheseusCreateFile` in `main.cpp` | [App Shell](#app-shell) | Wrapper around `CreateFileA` with dashboard-specific share/disposition defaults. | +| 0x0002dc80 | `main` | `main` (main.cpp) | [App Shell](#app-shell) | C entry point. Calls `Xbox_Init`, constructs the global `CAppShell` (`theApp`), enters the per-frame `Draw` loop. | +| 0x0002def0 | `AppShell_CreateFile` | `TheseusCreateFile` in `main.cpp` | [App Shell](#app-shell) | Wrapper around `CreateFileA` with dashboard-specific share/disposition defaults. | | 0x0002ea20 | `CNodeClass::FindByName` | `CNodeClass::FindByName` in `node_system.cpp` | [Scene Graph](Node.md) | Walks the static class registration list (built from `_classCXxxx_CXxxx__2VCNodeClass__A` entries in .data) looking for a UTF-16 class name match. The XAP compiler uses this when binding `DEF` declarations. | -| 0x0002ee60 | `CXAppNode::Advance` | tick loop in `main.cpp` | [Scene Graph](Node.md) | Per-frame tick on the application root node. Drives the time-dependent node graph. | +| 0x0002ee60 | `CAppShellNode::Advance` | tick loop in `main.cpp` | [Scene Graph](Node.md) | Per-frame tick on the application root node. Drives the time-dependent node graph. | | 0x00030440 | `CArrayElementReference_CArrayElementReference` | `CArrayElementReference::CArrayElementReference` (array.cpp) | [Script VM](VM.md) | Holds the array and index an `array[i]` expression names. | | 0x000304c0 | `CArrayElementReference_dtor` | `CArrayElementReference::~CArrayElementReference` (array.cpp) | [Script VM](VM.md) | Releases the array. | | 0x00030520 | `CArrayElementReference_Assign` | `CArrayElementReference::Assign` (array.cpp) | [Script VM](VM.md) | Stores into the slot, growing the array when the index is past the end. | @@ -420,7 +420,7 @@ When in doubt about an entry, run the address through Ghidra and compare. The po | 0x0006a530 | `CLiveAccounts_GetResult` | `CLiveAccounts::GetResult` (live_accounts.cpp) | [Live Accounts](#live-accounts) | Returns the numeric result code from the most recent Live operation (logon, friends fetch, etc.). | | 0x0006a590 | `CLiveAccounts_ClearMOTDCache` | `CLiveAccounts::ClearMOTDCache` (live_accounts.cpp) | [Live Accounts](#live-accounts) | Invalidates the cached "message of the day" so the next Live update re-fetches it. | | 0x0006e6cb | `CFilePump::GetData` | `CFilePump::GetData` (audio_system.cpp) | [Audio](AudioSystem.md) | Reads the next chunk of compressed data from the file pump's source file. Called by the decoder when its input is empty. | -| 0x0007967f | `CXAppNode::GetTextureSurface` | `CXAppNode::GetTextureSurface` (main.cpp) | [Render](#render) | Returns the underlying D3D `IDirect3DSurface8` for a node's bound texture. Used by render-to-texture nodes. | +| 0x0007967f | `CAppShellNode::GetTextureSurface` | `CAppShellNode::GetTextureSurface` (main.cpp) | [Render](#render) | Returns the underlying D3D `IDirect3DSurface8` for a node's bound texture. Used by render-to-texture nodes. | | 0x000cfe09 | `CLayout::GetRadius` | `CLayout::GetRadius` (scene_groups.cpp) | [Scene Groups](SceneGroups.md) | Returns the layout's circular radius. Inlined in many .text use sites; this is the FND-bound wrapper. | | 0x0011bec2 | `CXo_XOnlineLogon` | `CXo::XOnlineLogon` (xbox_live.cpp) | [Live Accounts](#live-accounts) | Theseus-side facade over `XOnlineLogon`. Marshals the dashboard's account record into the kernel call's parameter shape. | diff --git a/docs/decomp/XIP.md b/docs/decomp/XIP.md index 861ecce..8d3b0a8 100644 --- a/docs/decomp/XIP.md +++ b/docs/decomp/XIP.md @@ -63,7 +63,7 @@ Entry types, from the `CreateObjects` switch: | 4 | a 0x14 byte CMeshRef: archive, `offset >> 24` as the buffer, `offset & 0xffffff` as the first index, `size` as the primitive count | | 5 | an index buffer, in the slot of the vertex buffer count at that moment | | 6 | a vertex buffer: a 4 byte vertex count and a 4 byte FVF lead the vertices | -| anything else | `size` raw bytes from `XAppAllocMemory` | +| anything else | `size` raw bytes from `AppShell_AllocMemory` | Entries are read back to back with no seeking, so the data has to be in table order. The directory is sorted, because `Find` binary searches it. @@ -163,7 +163,7 @@ the GPU if the buffer is still in use. The stride is `(size - 8) / count`, with count. `ReloadMeshBuffers` seeks to each buffer entry in table order and reads it again, numbering index buffers and vertex buffers separately. -Under memory pressure `XAppAllocMemory` and the block allocator call `CleanupTextureCache` first, +Under memory pressure `AppShell_AllocMemory` and the block allocator call `CleanupTextureCache` first, then `CleanupMeshCache`, which frees the buffers of the unlocked, loaded archive with the oldest cache time that still has some. The next `CMeshRef::Render` of that archive sees a NULL vertex buffer and calls `Reload`; `CInline_Render` (`0x0004e5d0`) checks the same thing inline diff --git a/theseus/render/xip_archive.cpp b/theseus/render/xip_archive.cpp index 67b4665..3c71c28 100644 --- a/theseus/render/xip_archive.cpp +++ b/theseus/render/xip_archive.cpp @@ -749,7 +749,7 @@ static LPDIRECT3DTEXTURE8 ReadTexture(CFileBuffer& file, int cbEntry) // r->first = offset & 0xffffff; r->count = size; objects[i] = r; break; // case 5: ReadIndexBuffer(i, vbCount); ibCount++; break; // case 6: ReadVertexBuffer(i, vbCount); vbCount++; break; -// default: objects[i] = XAppAllocMemory(size); read size bytes; break; +// default: objects[i] = AppShell_AllocMemory(size); read size bytes; break; // } // locked = 0; // Entries sit in file order, so this reads straight through. An index buffer diff --git a/theseus/shared/audio_system.cpp b/theseus/shared/audio_system.cpp index 358f88c..8de19ba 100755 --- a/theseus/shared/audio_system.cpp +++ b/theseus/shared/audio_system.cpp @@ -4,7 +4,7 @@ // soundtrack MP3s (Theseus's, 5960 streams WMA). On top sit the AudioClip // and PeriodicAudioGroup nodes. Rebuilt from the 5960 retail XBE // (0x61890..0x63320); see docs/decomp/AudioSystem.md. Theseus creates -// buffers through DSoundManager instead of 5960's XAppCreateSoundBuffer. +// buffers through DSoundManager instead of 5960's AppShell_CreateSoundBuffer. #include "std.h" #include "theseus.h" diff --git a/theseus/xbox/disc_management.cpp b/theseus/xbox/disc_management.cpp index 6b96dbb..b997e8d 100755 --- a/theseus/xbox/disc_management.cpp +++ b/theseus/xbox/disc_management.cpp @@ -36,7 +36,7 @@ static const TCHAR *rgszDiscType[] = int g_nDiscType; -// Theseus: 5960 does this inline in CXApp::InitApp (0x0002d7e0). +// Theseus: 5960 does this inline in CAppShell::InitApp (0x0002d7e0). void DiscDrive_Init() { g_cdrom.Open(1); diff --git a/theseus/xbox/main.cpp b/theseus/xbox/main.cpp index a3ddf84..9b70f65 100644 --- a/theseus/xbox/main.cpp +++ b/theseus/xbox/main.cpp @@ -1166,7 +1166,7 @@ void CleanupApp() } // Advance() -// Reconstructed from the frame loop in 5960 XApp @ 0x0002da00: the clock is +// Reconstructed from the frame loop in 5960 AppShell_Run @ 0x0002da00: the clock is // GetTickCount in seconds, the step is the change since last frame (never // zero: 5960 uses one millisecond's worth), then the camera, every lerper // and the scene advance. Theseus also feeds its background loader; 5960 From a73b74e1c3dc66b58741ee0a353fbb2574f8936e Mon Sep 17 00:00:00 2001 From: Milenko <39630670+MrMilenko@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:50:54 -0500 Subject: [PATCH 2/8] Gave the input code its own names Renamed the bound pad pointers, the button combo state and the remote timers in the Xbox and desktop input code. Nothing script visible changed, and the compiled code is byte for byte the same. --- theseus/desktop/joystick.cpp | 118 ++++++++++++++-------------- theseus/desktop/joystick.h | 4 +- theseus/xbox/input.cpp | 144 +++++++++++++++++------------------ theseus/xbox/input.h | 4 +- 4 files changed, 135 insertions(+), 135 deletions(-) diff --git a/theseus/desktop/joystick.cpp b/theseus/desktop/joystick.cpp index fe5922f..3ad42ef 100755 --- a/theseus/desktop/joystick.cpp +++ b/theseus/desktop/joystick.cpp @@ -14,9 +14,9 @@ #define REPEAT_DELAY 0.3f #define REPEAT_INTERVAL 0.12f -#define KS_BEGIN 0x0001 -#define KS_VERIFIED 0x0002 -#define KS_END 0x0004 +#define COMBO_STARTED 0x0001 +#define COMBO_MATCHED 0x0002 +#define COMBO_FINISHED 0x0004 float g_xaxis, g_yaxis; @@ -41,7 +41,7 @@ class CJoystick : public CNode CJoystick(); ~CJoystick(); - bool m_bNeedsInit; + bool m_bFirstPoll; bool m_isBound; float m_frequency; @@ -68,8 +68,8 @@ class CJoystick : public CNode float m_back; char *m_secretKey; - size_t m_secretKeyLength; - size_t m_secretKeyCurrentIndex; + size_t m_comboLen; + size_t m_comboPos; bool m_enableSecretKey; bool m_eatSecretKey; @@ -93,14 +93,14 @@ class CJoystick : public CNode static SDL_GameController* c_controller; - static CJoystick *c_pPreviousBoundJoystick; - static CJoystick *c_pBoundJoystick; + static CJoystick *c_pLastActivePad; + static CJoystick *c_pActivePad; JoySnapshot m_prevState; XTIME m_nextRepeatTime; float m_repeatInterval; - XTIME m_timeNextUpdate; + XTIME m_nextPollTime; uint32_t m_prevMediaKeys; // bitmask for edge detection @@ -127,8 +127,8 @@ SDL_GameController* CJoystick::c_controller = NULL; // so ImGui's key state isn't fed. SDL_GameController* Joy_GetController() { return CJoystick::c_controller; } -CJoystick *CJoystick::c_pBoundJoystick = NULL; -CJoystick *CJoystick::c_pPreviousBoundJoystick = NULL; +CJoystick *CJoystick::c_pActivePad = NULL; +CJoystick *CJoystick::c_pLastActivePad = NULL; IMPLEMENT_NODE("Joystick", CJoystick, CNode) @@ -176,7 +176,7 @@ END_NODE_FUN() // Theseus starts hat at -1 and adds the desktop poll state. CJoystick::CJoystick() { - m_bNeedsInit = true; + m_bFirstPoll = true; m_isBound = false; m_frequency = 20.0f; m_hat = -1.0f; @@ -188,8 +188,8 @@ CJoystick::CJoystick() m_leftThumb = m_rightThumb = 0.0f; m_start = m_back = 0.0f; m_secretKey = NULL; - m_secretKeyLength = 0; - m_secretKeyCurrentIndex = 0; + m_comboLen = 0; + m_comboPos = 0; m_enableSecretKey = false; m_eatSecretKey = false; m_enableRemote = true; @@ -197,11 +197,11 @@ CJoystick::CJoystick() m_LastActivePort = 0; m_nextRepeatTime = 0.0f; m_repeatInterval = 0.0f; - m_timeNextUpdate = 0.0f; + m_nextPollTime = 0.0f; m_prevMediaKeys = 0; memset(&m_prevState, 0, sizeof(m_prevState)); - if (c_pBoundJoystick == NULL) + if (c_pActivePad == NULL) Bind(); } @@ -211,10 +211,10 @@ CJoystick::CJoystick() // it, and frees the secret key. CJoystick::~CJoystick() { - if (c_pPreviousBoundJoystick == this) - c_pPreviousBoundJoystick = NULL; - if (c_pBoundJoystick == this) - c_pBoundJoystick = c_pPreviousBoundJoystick; + if (c_pLastActivePad == this) + c_pLastActivePad = NULL; + if (c_pActivePad == this) + c_pActivePad = c_pLastActivePad; delete[] m_secretKey; } @@ -223,7 +223,7 @@ CJoystick::~CJoystick() // count, and only remote events honor enableRemote. void CJoystick::CallFunction(const char *szFunc, bool bRemote /* = false */) { - if (c_pBoundJoystick != this) + if (c_pActivePad != this) return; if (bRemote && !m_enableRemote) return; @@ -237,8 +237,8 @@ void BindJoystick(CNode *pJoystickNode) { if (pJoystickNode == NULL) { - CJoystick::c_pBoundJoystick = NULL; - CJoystick::c_pPreviousBoundJoystick = NULL; + CJoystick::c_pActivePad = NULL; + CJoystick::c_pLastActivePad = NULL; return; } if (pJoystickNode->IsKindOf(NODE_CLASS(CJoystick))) @@ -268,9 +268,9 @@ void CJoystick::OnBDown() // it rereads the device so held buttons don't fire. void CJoystick::Bind() { - c_pPreviousBoundJoystick = c_pBoundJoystick; - c_pBoundJoystick = this; - if (m_bNeedsInit) + c_pLastActivePad = c_pActivePad; + c_pActivePad = this; + if (m_bFirstPoll) return; CheckDevice(); PollSDL(c_controller, &m_prevState); @@ -293,11 +293,11 @@ bool CJoystick::OnSetProperty(const PRD *pprd, const void *pvValue) { Bind(); } - else if (c_pBoundJoystick == this) + else if (c_pActivePad == this) { - c_pBoundJoystick = NULL; - if (c_pPreviousBoundJoystick != NULL) - c_pPreviousBoundJoystick->Bind(); + c_pActivePad = NULL; + if (c_pLastActivePad != NULL) + c_pLastActivePad->Bind(); } return true; } @@ -306,16 +306,16 @@ bool CJoystick::OnSetProperty(const PRD *pprd, const void *pvValue) { delete[] m_secretKey; m_secretKey = NULL; - m_secretKeyLength = 0; - if (m_secretKeyCurrentIndex != 0) - ProcessSecretKeySequence(KS_END); - m_secretKeyCurrentIndex = 0; + m_comboLen = 0; + if (m_comboPos != 0) + ProcessSecretKeySequence(COMBO_FINISHED); + m_comboPos = 0; const char *key = *(char *const *)pvValue; if (key != NULL) { - m_secretKeyLength = strlen(key); - m_secretKey = new char[m_secretKeyLength + 1]; + m_comboLen = strlen(key); + m_secretKey = new char[m_comboLen + 1]; strcpy(m_secretKey, key); m_enableSecretKey = true; } @@ -325,9 +325,9 @@ bool CJoystick::OnSetProperty(const PRD *pprd, const void *pvValue) if (field == MEMBER_OFFSET(m_enableSecretKey)) { m_enableSecretKey = *(const bool *)pvValue; - if (!m_enableSecretKey && m_secretKeyCurrentIndex != 0 && m_secretKeyCurrentIndex < m_secretKeyLength) - ProcessSecretKeySequence(KS_END); - m_secretKeyCurrentIndex = 0; + if (!m_enableSecretKey && m_comboPos != 0 && m_comboPos < m_comboLen) + ProcessSecretKeySequence(COMBO_FINISHED); + m_comboPos = 0; return true; } @@ -832,19 +832,19 @@ void CJoystick::MoveEvent(char key, const char *name) void CJoystick::Advance(float nSeconds) { CNode::Advance(nSeconds); - if (!g_bInputEnable || this != c_pBoundJoystick) + if (!g_bInputEnable || this != c_pActivePad) return; CheckDevice(); - if (m_bNeedsInit) + if (m_bFirstPoll) { PollSDL(c_controller, &m_prevState); - m_timeNextUpdate = TheseusGetNow(); - m_bNeedsInit = false; + m_nextPollTime = TheseusGetNow(); + m_bFirstPoll = false; } - if (TheseusGetNow() < m_timeNextUpdate) + if (TheseusGetNow() < m_nextPollTime) return; - m_timeNextUpdate = TheseusGetNow() + 1.0f / m_frequency; + m_nextPollTime = TheseusGetNow() + 1.0f / m_frequency; ProcessMediaKeys(); @@ -912,26 +912,26 @@ void CJoystick::Advance(float nSeconds) // CJoystick::CheckSecretKeySequence(key) // Reconstructed from 5960 retail XBE @ 0x00041790. With no key set (or -// checking off) returns 0. A wrong press restarts the sequence (KS_END if -// one was under way); a right one at the start adds KS_BEGIN, and the last -// one adds KS_END | KS_VERIFIED and restarts. +// checking off) returns 0. A wrong press restarts the sequence (COMBO_FINISHED if +// one was under way); a right one at the start adds COMBO_STARTED, and the last +// one adds COMBO_FINISHED | COMBO_MATCHED and restarts. int CJoystick::CheckSecretKeySequence(char key) { - if (!m_enableSecretKey || m_secretKeyLength == 0 || m_secretKey == NULL) + if (!m_enableSecretKey || m_comboLen == 0 || m_secretKey == NULL) return 0; - if (key != m_secretKey[m_secretKeyCurrentIndex]) + if (key != m_secretKey[m_comboPos]) { - int flags = m_secretKeyCurrentIndex != 0 ? KS_END : 0; - m_secretKeyCurrentIndex = 0; + int flags = m_comboPos != 0 ? COMBO_FINISHED : 0; + m_comboPos = 0; return flags; } - int flags = m_secretKeyCurrentIndex == 0 ? KS_BEGIN : 0; - if (++m_secretKeyCurrentIndex == m_secretKeyLength) + int flags = m_comboPos == 0 ? COMBO_STARTED : 0; + if (++m_comboPos == m_comboLen) { - flags |= KS_END | KS_VERIFIED; - m_secretKeyCurrentIndex = 0; + flags |= COMBO_FINISHED | COMBO_MATCHED; + m_comboPos = 0; } return flags; } @@ -941,10 +941,10 @@ int CJoystick::CheckSecretKeySequence(char key) // OnKeyVerificationExit, OnKeyVerified, in that order, for the flags set. void CJoystick::ProcessSecretKeySequence(int flags) { - if (flags & KS_BEGIN) + if (flags & COMBO_STARTED) CallFunction("OnKeyVerificationEnter"); - if (flags & KS_END) + if (flags & COMBO_FINISHED) CallFunction("OnKeyVerificationExit"); - if (flags & KS_VERIFIED) + if (flags & COMBO_MATCHED) CallFunction("OnKeyVerified"); } diff --git a/theseus/desktop/joystick.h b/theseus/desktop/joystick.h index de96eef..82955db 100755 --- a/theseus/desktop/joystick.h +++ b/theseus/desktop/joystick.h @@ -8,8 +8,8 @@ class CJoystick : public CNode { public: - static CJoystick* c_pBoundJoystick; - static CJoystick* c_pPreviousBoundJoystick; + static CJoystick* c_pActivePad; + static CJoystick* c_pLastActivePad; static SDL_GameController* c_controller; void Bind(); // this binds to itself diff --git a/theseus/xbox/input.cpp b/theseus/xbox/input.cpp index 5aca596..89ed9b8 100755 --- a/theseus/xbox/input.cpp +++ b/theseus/xbox/input.cpp @@ -12,9 +12,9 @@ #define REPEAT_DELAY 0.3f #define REPEAT_INTERVAL 0.12f -#define KS_BEGIN 0x0001 -#define KS_VERIFIED 0x0002 -#define KS_END 0x0004 +#define COMBO_STARTED 0x0001 +#define COMBO_MATCHED 0x0002 +#define COMBO_FINISHED 0x0004 // An analog button counts as down past this. #define ANALOG_DOWN 0x20 @@ -59,8 +59,8 @@ class CJoystick : public CNode float m_back; TCHAR *m_secretKey; - size_t m_secretKeyLength; - size_t m_secretKeyCurrentIndex; + size_t m_comboLen; + size_t m_comboPos; bool m_enableSecretKey; bool m_eatSecretKey; @@ -84,17 +84,17 @@ class CJoystick : public CNode static HANDLE c_hDevices[4]; static PXPP_DEVICE_TYPE c_devtype[4]; - static CJoystick *c_pPreviousBoundJoystick; - static CJoystick *c_pBoundJoystick; + static CJoystick *c_pLastActivePad; + static CJoystick *c_pActivePad; XINPUT_STATE_INTERNAL m_joystate[4]; XTIME m_nextRepeatTime[4]; float m_repeatInterval[4]; - float m_remoteIdleTime; - DWORD m_remoteRepeatCount; + float m_remoteQuietTime; + DWORD m_remoteRepeats; - XTIME m_timeNextUpdate; - XTIME m_timeRemoteRemoved; + XTIME m_nextPollTime; + XTIME m_remoteGoneTime; bool m_removeRemoteCalled; void OnMoveUp(); void OnMoveDown(); @@ -121,8 +121,8 @@ class CJoystick : public CNode HANDLE CJoystick::c_hDevices[4]; PXPP_DEVICE_TYPE CJoystick::c_devtype[4]; -CJoystick *CJoystick::c_pBoundJoystick = NULL; -CJoystick *CJoystick::c_pPreviousBoundJoystick = NULL; +CJoystick *CJoystick::c_pActivePad = NULL; +CJoystick *CJoystick::c_pLastActivePad = NULL; IMPLEMENT_NODE("Joystick", CJoystick, CNode) @@ -183,17 +183,17 @@ CJoystick::CJoystick() m_start = m_back = 0.0f; m_secretKey = NULL; - m_secretKeyLength = 0; - m_secretKeyCurrentIndex = 0; + m_comboLen = 0; + m_comboPos = 0; m_enableSecretKey = false; m_eatSecretKey = false; m_enableRemote = true; m_enableGamepad = true; m_LastActivePort = 0; - m_remoteIdleTime = 0.0f; - m_remoteRepeatCount = 0; - m_timeRemoteRemoved = 0.0f; + m_remoteQuietTime = 0.0f; + m_remoteRepeats = 0; + m_remoteGoneTime = 0.0f; m_removeRemoteCalled = false; for (int port = 0; port < 4; port++) { @@ -201,7 +201,7 @@ CJoystick::CJoystick() m_repeatInterval[port] = 0.0f; } - if (c_pBoundJoystick == NULL) + if (c_pActivePad == NULL) Bind(); } @@ -210,10 +210,10 @@ CJoystick::CJoystick() // previous binding, hands the binding back if it held it, frees the key. CJoystick::~CJoystick() { - if (c_pPreviousBoundJoystick == this) - c_pPreviousBoundJoystick = NULL; - if (c_pBoundJoystick == this) - c_pBoundJoystick = c_pPreviousBoundJoystick; + if (c_pLastActivePad == this) + c_pLastActivePad = NULL; + if (c_pActivePad == this) + c_pActivePad = c_pLastActivePad; delete[] m_secretKey; } @@ -221,7 +221,7 @@ CJoystick::~CJoystick() // (remote or gamepad) is enabled. 5960 tests the same at every call site. void CJoystick::CallFunction(const TCHAR *szFunc, bool bRemote /* = false */) { - if (c_pBoundJoystick != this) + if (c_pActivePad != this) return; if (bRemote ? !m_enableRemote : !m_enableGamepad) return; @@ -235,8 +235,8 @@ void BindJoystick(CNode *pJoystickNode) { if (pJoystickNode == NULL) { - CJoystick::c_pBoundJoystick = NULL; - CJoystick::c_pPreviousBoundJoystick = NULL; + CJoystick::c_pActivePad = NULL; + CJoystick::c_pLastActivePad = NULL; return; } if (pJoystickNode->IsKindOf(NODE_CLASS(CJoystick))) @@ -276,8 +276,8 @@ void CJoystick::ReadAllDevices() // it looks for devices and rereads them. void CJoystick::Bind() { - c_pPreviousBoundJoystick = c_pBoundJoystick; - c_pBoundJoystick = this; + c_pLastActivePad = c_pActivePad; + c_pActivePad = this; if (m_needsInit) return; CheckDevice(); @@ -302,11 +302,11 @@ bool CJoystick::OnSetProperty(const PRD *pprd, const void *pvValue) { Bind(); } - else if (c_pBoundJoystick == this) + else if (c_pActivePad == this) { - c_pBoundJoystick = NULL; - if (c_pPreviousBoundJoystick != NULL) - c_pPreviousBoundJoystick->Bind(); + c_pActivePad = NULL; + if (c_pLastActivePad != NULL) + c_pLastActivePad->Bind(); } return true; } @@ -315,16 +315,16 @@ bool CJoystick::OnSetProperty(const PRD *pprd, const void *pvValue) { delete[] m_secretKey; m_secretKey = NULL; - m_secretKeyLength = 0; - if (m_secretKeyCurrentIndex != 0) - ProcessSecretKeySequence(KS_END); - m_secretKeyCurrentIndex = 0; + m_comboLen = 0; + if (m_comboPos != 0) + ProcessSecretKeySequence(COMBO_FINISHED); + m_comboPos = 0; const TCHAR *szKey = *(TCHAR *const *)pvValue; if (szKey != NULL) { - m_secretKeyLength = _tcslen(szKey); - m_secretKey = new TCHAR[m_secretKeyLength + 1]; + m_comboLen = _tcslen(szKey); + m_secretKey = new TCHAR[m_comboLen + 1]; _tcscpy(m_secretKey, szKey); m_enableSecretKey = true; } @@ -334,9 +334,9 @@ bool CJoystick::OnSetProperty(const PRD *pprd, const void *pvValue) if (field == offsetof(m_enableSecretKey)) { m_enableSecretKey = *(const bool *)pvValue; - if (!m_enableSecretKey && m_secretKeyCurrentIndex != 0 && m_secretKeyCurrentIndex < m_secretKeyLength) - ProcessSecretKeySequence(KS_END); - m_secretKeyCurrentIndex = 0; + if (!m_enableSecretKey && m_comboPos != 0 && m_comboPos < m_comboLen) + ProcessSecretKeySequence(COMBO_FINISHED); + m_comboPos = 0; return true; } @@ -380,10 +380,10 @@ void CJoystick::OpenPorts(PXPP_DEVICE_TYPE type) c_devtype[port] = type; XInputGetState(c_hDevices[port], (XINPUT_STATE *)&m_joystate[port]); - m_timeNextUpdate = TheseusGetNow(); + m_nextPollTime = TheseusGetNow(); if (bRemote) { - m_timeRemoteRemoved = 0.0f; + m_remoteGoneTime = 0.0f; if (m_removeRemoteCalled) CallFunction(_T("OnInsertRemote"), true); } @@ -395,7 +395,7 @@ void CJoystick::OpenPorts(PXPP_DEVICE_TYPE type) c_hDevices[port] = NULL; if (bRemote) { - m_timeRemoteRemoved = TheseusGetNow() + 2.0f; + m_remoteGoneTime = TheseusGetNow() + 2.0f; m_removeRemoteCalled = false; } } @@ -527,7 +527,7 @@ void CJoystick::RemoteGone(int port) XInputClose(c_hDevices[port]); c_hDevices[port] = NULL; c_devtype[port] = NULL; - m_timeRemoteRemoved = TheseusGetNow() + 2.0f; + m_remoteGoneTime = TheseusGetNow() + 2.0f; m_removeRemoteCalled = false; } @@ -547,22 +547,22 @@ bool CJoystick::PollRemote(int port, float nSeconds) if (state.dwPacketNumber == m_joystate[port].dwPacketNumber) { - m_remoteIdleTime += nSeconds; - if (m_remoteIdleTime > 0.150) - m_remoteRepeatCount = 0; + m_remoteQuietTime += nSeconds; + if (m_remoteQuietTime > 0.150) + m_remoteRepeats = 0; return true; } ResetScreenSaver(); - m_remoteIdleTime = 0.0f; + m_remoteQuietTime = 0.0f; if (state.IrRemote.wKeyCode != m_joystate[port].IrRemote.wKeyCode || state.IrRemote.wTimeDelta > 120) - m_remoteRepeatCount = 1; + m_remoteRepeats = 1; else - m_remoteRepeatCount++; + m_remoteRepeats++; m_joystate[port] = state; - bool bFire = m_remoteRepeatCount == 1 || (m_remoteRepeatCount > 7 && (m_remoteRepeatCount % 2) != 0); + bool bFire = m_remoteRepeats == 1 || (m_remoteRepeats > 7 && (m_remoteRepeats % 2) != 0); if (!bFire) return true; @@ -753,10 +753,10 @@ void CJoystick::Advance(float nSeconds) { CNode::Advance(nSeconds); - if (!g_bInputEnable || this != c_pBoundJoystick) + if (!g_bInputEnable || this != c_pActivePad) return; - if (!m_removeRemoteCalled && m_timeRemoteRemoved != 0.0f && TheseusGetNow() > m_timeRemoteRemoved) + if (!m_removeRemoteCalled && m_remoteGoneTime != 0.0f && TheseusGetNow() > m_remoteGoneTime) { CallFunction(_T("OnRemoveRemote"), true); m_removeRemoteCalled = true; @@ -768,13 +768,13 @@ void CJoystick::Advance(float nSeconds) if (m_needsInit) { ReadAllDevices(); - m_timeNextUpdate = TheseusGetNow(); + m_nextPollTime = TheseusGetNow(); m_needsInit = false; } - if (TheseusGetNow() < m_timeNextUpdate) + if (TheseusGetNow() < m_nextPollTime) return; - m_timeNextUpdate = TheseusGetNow() + 1.0f / m_frequency; + m_nextPollTime = TheseusGetNow() + 1.0f / m_frequency; g_xaxis = g_yaxis = 0.0f; @@ -796,27 +796,27 @@ void CJoystick::Advance(float nSeconds) // CJoystick::CheckSecretKeySequence(letter) // Reconstructed from 5960 retail XBE @ 0x00041790. With a key set and -// enabled: the wrong letter ends a sequence in progress (KS_END) and starts -// over; the right one begins it (KS_BEGIN on the first letter) and the last -// one completes it (KS_VERIFIED | KS_END). +// enabled: the wrong letter ends a sequence in progress (COMBO_FINISHED) and starts +// over; the right one begins it (COMBO_STARTED on the first letter) and the last +// one completes it (COMBO_MATCHED | COMBO_FINISHED). int CJoystick::CheckSecretKeySequence(TCHAR key) { - if (!m_enableSecretKey || m_secretKeyLength == 0 || m_secretKey == NULL) + if (!m_enableSecretKey || m_comboLen == 0 || m_secretKey == NULL) return 0; - if (key != m_secretKey[m_secretKeyCurrentIndex]) + if (key != m_secretKey[m_comboPos]) { - int flags = m_secretKeyCurrentIndex != 0 ? KS_END : 0; - m_secretKeyCurrentIndex = 0; + int flags = m_comboPos != 0 ? COMBO_FINISHED : 0; + m_comboPos = 0; return flags; } - int flags = m_secretKeyCurrentIndex == 0 ? KS_BEGIN : 0; - m_secretKeyCurrentIndex++; - if (m_secretKeyCurrentIndex == m_secretKeyLength) + int flags = m_comboPos == 0 ? COMBO_STARTED : 0; + m_comboPos++; + if (m_comboPos == m_comboLen) { - m_secretKeyCurrentIndex = 0; - flags |= KS_VERIFIED | KS_END; + m_comboPos = 0; + flags |= COMBO_MATCHED | COMBO_FINISHED; } return flags; } @@ -826,10 +826,10 @@ int CJoystick::CheckSecretKeySequence(TCHAR key) // OnKeyVerificationExit, OnKeyVerified, in that order, for the flags set. void CJoystick::ProcessSecretKeySequence(int flags) { - if (flags & KS_BEGIN) + if (flags & COMBO_STARTED) CallFunction(_T("OnKeyVerificationEnter")); - if (flags & KS_END) + if (flags & COMBO_FINISHED) CallFunction(_T("OnKeyVerificationExit")); - if (flags & KS_VERIFIED) + if (flags & COMBO_MATCHED) CallFunction(_T("OnKeyVerified")); } diff --git a/theseus/xbox/input.h b/theseus/xbox/input.h index 2261bda..ef5e892 100755 --- a/theseus/xbox/input.h +++ b/theseus/xbox/input.h @@ -8,8 +8,8 @@ class CJoystick : public CNode { public: - static CJoystick* c_pBoundJoystick; - static CJoystick* c_pPreviousBoundJoystick; + static CJoystick* c_pActivePad; + static CJoystick* c_pLastActivePad; void Bind(); From 07e38d58f9eaefe3e6b356f584c50c1f8fca494b Mon Sep 17 00:00:00 2001 From: Milenko <39630670+MrMilenko@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:51:52 -0500 Subject: [PATCH 3/8] Renamed the memory unit slots and disc drive state The device slot defines are SLOT_P1A through SLOT_P4B plus SLOT_HDD now, and the memory monitor, disc type and CD-ROM service members got names of their own. Compiled code is unchanged. --- docs/decomp/AppShell.md | 2 +- docs/decomp/Disc.md | 12 +-- theseus/shared/file_ops.cpp | 6 +- theseus/shared/ntiosvc.cpp | 50 +++++----- theseus/shared/ntiosvc.h | 14 +-- theseus/shared/savegame_grid.cpp | 8 +- theseus/shared/theseus.h | 4 +- theseus/shared/title_collection.cpp | 2 +- theseus/shared/title_collection.h | 18 ++-- theseus/xbox/config.cpp | 2 +- theseus/xbox/disc_management.cpp | 52 +++++----- theseus/xbox/dsound_manager.cpp | 8 +- theseus/xbox/main.cpp | 12 +-- theseus/xbox/memory_monitor.cpp | 144 ++++++++++++++-------------- 14 files changed, 167 insertions(+), 167 deletions(-) diff --git a/docs/decomp/AppShell.md b/docs/decomp/AppShell.md index 9b5430f..453a481 100644 --- a/docs/decomp/AppShell.md +++ b/docs/decomp/AppShell.md @@ -44,7 +44,7 @@ load y:\default.xap, create it, D3DXCreateMatrixStack, call its initialize DirectSound is not touched here. `DSound_Init` runs the first time a sound buffer is asked for: ``` -if (g_BootType == DISC_VIDEO) return false; +if (g_BootType == DISC_DVD) return false; speaker override = (XGetAudioFlags() low word == mono); DirectSoundCreate(0, &g_pDirectSound, 0); SetMixBinHeadroom(bin, 0) for all 31 mix bins; diff --git a/docs/decomp/Disc.md b/docs/decomp/Disc.md index edb9d5a..9fad7aa 100644 --- a/docs/decomp/Disc.md +++ b/docs/decomp/Disc.md @@ -21,11 +21,11 @@ at `0x0017aee4`; the node's type names are the table at `0x0017453c` (`none`, `u ``` if (g_bHasLaunchData && reason == XLD_LAUNCH_DASHBOARD_DVDPLAYER && DoesFileExist("CDROM0:\video_ts\video_ts.ifo")) - g_BootType = DISC_VIDEO; -if ((g_bHasLaunchData && reason != 0x0C) || g_BootType == DISC_VIDEO || g_BootType == DISC_BAD) - { m_nDiscType = g_BootType; HalReadSMCTrayState(&m_trayState, 0); } + g_BootType = DISC_DVD; +if ((g_bHasLaunchData && reason != 0x0C) || g_BootType == DISC_DVD || g_BootType == DISC_BAD) + { m_discKind = g_BootType; HalReadSMCTrayState(&m_trayState, 0); } else - { m_nDiscType = DISC_NONE; m_trayState = 0x40; } // the first poll reports the disc + { m_discKind = DISC_NONE; m_trayState = 0x40; } // the first poll reports the disc ``` Reason `0x0C` is a return from the online dashboard. @@ -39,8 +39,8 @@ lastPoll = now; if (HalReadSMCTrayState(&tray, 0) < 0 || tray == m_trayState) return; m_trayState = tray; ResetScreenSaver(); g_BootType = GetDiscType(); -if (g_BootType == m_nDiscType) return; -m_nDiscType = g_BootType; replace discType string; +if (g_BootType == m_discKind) return; +m_discKind = g_BootType; replace discType string; if (m_locked) m_bDeferNotification = true; else fire OnDiscInserted (type != none) or OnDiscRemoved; ``` diff --git a/theseus/shared/file_ops.cpp b/theseus/shared/file_ops.cpp index 97b87da..03a92ce 100755 --- a/theseus/shared/file_ops.cpp +++ b/theseus/shared/file_ops.cpp @@ -603,7 +603,7 @@ void CCopyDestination::Render() bool current = m_units[i] == m_curDevUnit; (current ? m_panelMUHilite : m_panelMU)->Render(); (current ? m_panelTextHilite : m_panelText)->Render(); - (m_selDevUnit == Dev0 ? m_console : m_memoryUnit)->Render(); + (m_selDevUnit == SLOT_HDD ? m_console : m_memoryUnit)->Render(); TheseusPopWorld(); } @@ -629,11 +629,11 @@ void CCopyDestination::Advance(float nSeconds) m_unitCount = 0; for (int i = 0; i < 9; i++) { - int unit = (i == 0) ? Dev0 : i - 1; + int unit = (i == 0) ? SLOT_HDD : i - 1; if (unit == m_sourceDevUnit) continue; - if (unit != Dev0 && !g_titles[unit].IsValid()) + if (unit != SLOT_HDD && !g_titles[unit].IsValid()) { if (unit == m_curDevUnit) curRemoved = true; diff --git a/theseus/shared/ntiosvc.cpp b/theseus/shared/ntiosvc.cpp index 4b8444d..e93d2b3 100755 --- a/theseus/shared/ntiosvc.cpp +++ b/theseus/shared/ntiosvc.cpp @@ -1,13 +1,13 @@ // ntiosvc.cpp: the CD-ROM service behind audio CDs. Open, the table of // contents, raw reads and the track lengths are rebuilt from the 5960 -// retail XBE (0x64da0..0x650c0, g_cdrom at 0x188780); see +// retail XBE (0x64da0..0x650c0, g_discIoctl at 0x188780); see // docs/decomp/NtIoSvc.md. The disc id and name strings are Theseus's. #include "std.h" #include "theseus.h" #include "ntiosvc.h" -CNtIoctlCdromService g_cdrom; +CNtIoctlCdromService g_discIoctl; // A TOC address is four bytes: unused, minute, second, frame. static DWORD AddressToFrames(const UCHAR* addr) @@ -28,10 +28,10 @@ static void SplitFrames(DWORD dwFrames, int* pnMinutes, int* pnSeconds, int* pnF // CNtIoctlCdromService::CNtIoctlCdromService() // Reconstructed from 5960 retail XBE @ 0x00064da0: -// m_hDevice = -1; m_toc.LastTrack = 0; +// m_hDrive = -1; m_trackTable.LastTrack = 0; CNtIoctlCdromService::CNtIoctlCdromService() { - m_hDevice = INVALID_HANDLE_VALUE; + m_hDrive = INVALID_HANDLE_VALUE; } CNtIoctlCdromService::~CNtIoctlCdromService() @@ -41,17 +41,17 @@ CNtIoctlCdromService::~CNtIoctlCdromService() // CNtIoctlCdromService::Close() // Reconstructed from 5960 retail XBE @ 0x00064db0: -// if (m_hDevice != -1) { CloseHandle(m_hDevice); m_hDevice = -1; } -// m_toc.LastTrack = 0; +// if (m_hDrive != -1) { CloseHandle(m_hDrive); m_hDrive = -1; } +// m_trackTable.LastTrack = 0; // Theseus also frees its name strings, which clears the track count too. void CNtIoctlCdromService::Close() { - if (m_hDevice != INVALID_HANDLE_VALUE) + if (m_hDrive != INVALID_HANDLE_VALUE) { - CloseHandle(m_hDevice); - m_hDevice = INVALID_HANDLE_VALUE; + CloseHandle(m_hDrive); + m_hDrive = INVALID_HANDLE_VALUE; } - m_toc.Delete(); + m_trackTable.Delete(); } // CNtIoctlCdromService::Open(drive) @@ -63,8 +63,8 @@ void CNtIoctlCdromService::Close() // The drive number goes unused; there is only one drive. HRESULT CNtIoctlCdromService::Open(DWORD dwDriveNumber) { - m_hDevice = TheseusCreateFile(_T("CDROM0:"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (m_hDevice == INVALID_HANDLE_VALUE) + m_hDrive = TheseusCreateFile(_T("CDROM0:"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (m_hDrive == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError()); if (!GetTableOfContents()) @@ -93,7 +93,7 @@ bool CNtIoctlCdromService::GetTableOfContents() for (;;) { UCHAR* addr = toc.TrackData[i].Address; - m_toc.TrackAddr[i] = AddressToFrames(addr); + m_trackTable.TrackAddr[i] = AddressToFrames(addr); if (toc.TrackData[i].TrackNumber == 0xAA) break; @@ -108,7 +108,7 @@ bool CNtIoctlCdromService::GetTableOfContents() addr[1] -= 1; else addr[2] -= 60; - m_toc.TrackAddr[i] = AddressToFrames(addr); + m_trackTable.TrackAddr[i] = AddressToFrames(addr); break; } @@ -117,13 +117,13 @@ bool CNtIoctlCdromService::GetTableOfContents() i += 1; } - m_toc.LastTrack = i; + m_trackTable.LastTrack = i; // Theseus: the disc id. - if (m_toc.LastTrack > 0) - m_toc.UpdateDiscID(); + if (m_trackTable.LastTrack > 0) + m_trackTable.UpdateDiscID(); - return m_toc.LastTrack > 0; + return m_trackTable.LastTrack > 0; } // CNtIoctlCdromService::Read(start, count, buffer, retries) @@ -155,7 +155,7 @@ HRESULT CNtIoctlCdromService::Read(DWORD dwReadStart, DWORD dwReadLength, LPVOID HRESULT CNtIoctlCdromService::DeviceIoControl(DWORD dwControlCode, LPVOID pvInBuffer, DWORD dwInBufferSize, LPVOID pvOutBuffer, DWORD dwOutBufferSize, LPDWORD pdwBytesReturned) { DWORD dwIgnored; - if (::DeviceIoControl(m_hDevice, dwControlCode, pvInBuffer, dwInBufferSize, pvOutBuffer, dwOutBufferSize, + if (::DeviceIoControl(m_hDrive, dwControlCode, pvInBuffer, dwInBufferSize, pvOutBuffer, dwOutBufferSize, pdwBytesReturned != NULL ? pdwBytesReturned : &dwIgnored, NULL)) return S_OK; return HRESULT_FROM_WIN32(GetLastError()); @@ -170,32 +170,32 @@ bool CNtIoctlCdromService::GetTotalLength(int* pnMinutes, int* pnSeconds, int* p { if (!IsOpen()) return false; - SplitFrames(m_toc.TrackAddr[m_toc.LastTrack] - m_toc.TrackAddr[0], pnMinutes, pnSeconds, pnFrames); + SplitFrames(m_trackTable.TrackAddr[m_trackTable.LastTrack] - m_trackTable.TrackAddr[0], pnMinutes, pnSeconds, pnFrames); return true; } bool CNtIoctlCdromService::GetTrackLength(int nTrack, int* pnMinutes, int* pnSeconds, int* pnFrames) { - if (!IsOpen() || nTrack < 0 || nTrack >= m_toc.LastTrack) + if (!IsOpen() || nTrack < 0 || nTrack >= m_trackTable.LastTrack) return false; - SplitFrames(m_toc.TrackAddr[nTrack + 1] - m_toc.TrackAddr[nTrack], pnMinutes, pnSeconds, pnFrames); + SplitFrames(m_trackTable.TrackAddr[nTrack + 1] - m_trackTable.TrackAddr[nTrack], pnMinutes, pnSeconds, pnFrames); return true; } // Theseus: name lookups. Nothing fills these in yet, so they stay NULL. const TCHAR* CNtIoctlCdromService::GetTitle() { - return IsOpen() ? m_toc.szTitle : NULL; + return IsOpen() ? m_trackTable.szTitle : NULL; } const TCHAR* CNtIoctlCdromService::GetArtist() { - return IsOpen() ? m_toc.szArtist : NULL; + return IsOpen() ? m_trackTable.szArtist : NULL; } const TCHAR* CNtIoctlCdromService::GetTrackName(int nTrack) { - return IsOpen() ? m_toc.rgszTrack[nTrack] : NULL; + return IsOpen() ? m_trackTable.rgszTrack[nTrack] : NULL; } // Theseus: the strings around the 5960 track list. diff --git a/theseus/shared/ntiosvc.h b/theseus/shared/ntiosvc.h index 9373652..fac88ea 100755 --- a/theseus/shared/ntiosvc.h +++ b/theseus/shared/ntiosvc.h @@ -40,7 +40,7 @@ typedef XCDROM_TOC* PXCDROM_TOC; class CNtIoctlCdromService { private: - HANDLE m_hDevice; + HANDLE m_hDrive; public: CNtIoctlCdromService(); @@ -50,8 +50,8 @@ class CNtIoctlCdromService void Close(); HRESULT Read(DWORD dwReadStart, DWORD dwReadLength, LPVOID pvBuffer, DWORD dwRetries = 0); - bool IsOpen() const { return m_hDevice != INVALID_HANDLE_VALUE; } - int GetTrackCount() const { return IsOpen() ? m_toc.LastTrack : 0; } + bool IsOpen() const { return m_hDrive != INVALID_HANDLE_VALUE; } + int GetTrackCount() const { return IsOpen() ? m_trackTable.LastTrack : 0; } bool GetTotalLength(int* pnMinutes, int* pnSeconds, int* pnFrames); bool GetTrackLength(int nTrack, int* pnMinutes, int* pnSeconds, int* pnFrames); @@ -60,13 +60,13 @@ class CNtIoctlCdromService const TCHAR* GetArtist(); const TCHAR* GetTrackName(int nTrack); - DWORD GetTrackFrame(int nTrack) const { return IsOpen() ? m_toc.TrackAddr[nTrack] : 0; } - int GetTrackFromFrame(DWORD dwFrame) const { return m_toc.GetTrackFromFrame(dwFrame); } + DWORD GetTrackFrame(int nTrack) const { return IsOpen() ? m_trackTable.TrackAddr[nTrack] : 0; } + int GetTrackFromFrame(DWORD dwFrame) const { return m_trackTable.GetTrackFromFrame(dwFrame); } protected: - XCDROM_TOC m_toc; + XCDROM_TOC m_trackTable; bool GetTableOfContents(); HRESULT DeviceIoControl(DWORD dwControlCode, LPVOID pvInBuffer = NULL, DWORD dwInBufferSize = 0, LPVOID pvOutBuffer = NULL, DWORD dwOutBufferSize = 0, LPDWORD pdwBytesReturned = NULL); }; -extern CNtIoctlCdromService g_cdrom; +extern CNtIoctlCdromService g_discIoctl; diff --git a/theseus/shared/savegame_grid.cpp b/theseus/shared/savegame_grid.cpp index a73e756..0973805 100644 --- a/theseus/shared/savegame_grid.cpp +++ b/theseus/shared/savegame_grid.cpp @@ -239,11 +239,11 @@ class CSavedGameGrid : public CNode bool GetDLCImagePath(int nTitle, int dlcIndex, TCHAR *out); // Device-unit classification. Dev units 0..7 are physical storage - // (Dev0 = HDD, 1..7 = MU slots). Dev unit 8 is the synthetic + // (SLOT_HDD = HDD, 1..7 = MU slots). Dev unit 8 is the synthetic // "memory unit selector" view shown when the user is choosing which // MU to copy to/from. - inline bool IsHDD() const { return m_curDevUnit == Dev0; } - inline bool IsMUSlot() const { return m_curDevUnit > Dev0 && m_curDevUnit < 8; } + inline bool IsHDD() const { return m_curDevUnit == SLOT_HDD; } + inline bool IsMUSlot() const { return m_curDevUnit > SLOT_HDD && m_curDevUnit < 8; } inline bool IsMUSelector() const { return m_curDevUnit == 8; } inline bool IsValidDevUnit() const { return m_curDevUnit >= 0 && m_curDevUnit <= 8; } @@ -2053,7 +2053,7 @@ static int ScanDLContentCount(const char *titleID) int CSavedGameGrid::GetDLContentCount(int nTitle) { - if (nTitle < 0 || m_curDevUnit != Dev0) + if (nTitle < 0 || m_curDevUnit != SLOT_HDD) return 0; if (m_dlcCountCacheSize == 0) diff --git a/theseus/shared/theseus.h b/theseus/shared/theseus.h index 2dc61df..6be57fc 100755 --- a/theseus/shared/theseus.h +++ b/theseus/shared/theseus.h @@ -863,13 +863,13 @@ const WCHAR TheseusTempWmaFileW[] = L"MUSIC:\\tempwma.wma"; -extern int g_nDiscType; +extern int g_discKind; #define DISC_NONE 0 #define DISC_BAD 1 #define DISC_TITLE 2 #define DISC_AUDIO 3 -#define DISC_VIDEO 4 +#define DISC_DVD 4 diff --git a/theseus/shared/title_collection.cpp b/theseus/shared/title_collection.cpp index b325914..3eea923 100755 --- a/theseus/shared/title_collection.cpp +++ b/theseus/shared/title_collection.cpp @@ -22,7 +22,7 @@ CTitleArray g_titles [9]; // from the memory monitor as they're mounted. void TitleArray_Init() { - g_titles[Dev0].SetRoot('c', false); + g_titles[SLOT_HDD].SetRoot('c', false); } // CTitleArray::CTitleArray diff --git a/theseus/shared/title_collection.h b/theseus/shared/title_collection.h index 895e71c..4ff8214 100755 --- a/theseus/shared/title_collection.h +++ b/theseus/shared/title_collection.h @@ -6,15 +6,15 @@ #pragma once // Device slots, as the memory screens and g_titles index them. -#define Dev1Unit1 0 -#define Dev1Unit2 1 -#define Dev2Unit1 2 -#define Dev2Unit2 3 -#define Dev3Unit1 4 -#define Dev3Unit2 5 -#define Dev4Unit1 6 -#define Dev4Unit2 7 -#define Dev0 8 +#define SLOT_P1A 0 +#define SLOT_P1B 1 +#define SLOT_P2A 2 +#define SLOT_P2B 3 +#define SLOT_P3A 4 +#define SLOT_P3B 5 +#define SLOT_P4A 6 +#define SLOT_P4B 7 +#define SLOT_HDD 8 // The dashboard counts space in 16 KB blocks on every device. #define BLOCK_SIZE 16384 diff --git a/theseus/xbox/config.cpp b/theseus/xbox/config.cpp index 9724a09..b3feb7c 100755 --- a/theseus/xbox/config.cpp +++ b/theseus/xbox/config.cpp @@ -286,7 +286,7 @@ void CConfig::Set480Support(int bEnable) { WriteSettingBit(XC_VIDEO_FLAGS, AV_FLAGS_HDTV_480p, bEnable != 0); - if (g_nDiscType != DISC_VIDEO || XGetAVPack() != XC_AV_PACK_HDTV || + if (g_discKind != DISC_DVD || XGetAVPack() != XC_AV_PACK_HDTV || !(XboxHardwareInfo->Flags & XBOX_480P_MACROVISION_ENABLED)) return; diff --git a/theseus/xbox/disc_management.cpp b/theseus/xbox/disc_management.cpp index b997e8d..5d7c826 100755 --- a/theseus/xbox/disc_management.cpp +++ b/theseus/xbox/disc_management.cpp @@ -34,13 +34,13 @@ static const TCHAR *rgszDiscType[] = _T("Video"), }; -int g_nDiscType; +int g_discKind; // Theseus: 5960 does this inline in CAppShell::InitApp (0x0002d7e0). void DiscDrive_Init() { - g_cdrom.Open(1); - g_nDiscType = GetDiscType(); + g_discIoctl.Open(1); + g_discKind = GetDiscType(); } class CDiscDrive : public CNode @@ -66,7 +66,7 @@ class CDiscDrive : public CNode CStrObject *getTitle(); CStrObject *getTrackName(int nTrack); - int m_nDiscType; + int m_discKind; bool m_locked; DECLARE_NODE_PROPS() @@ -111,17 +111,17 @@ NODE_FUN_SI(getTrackName) END_NODE_FUN() #undef _FND_CLASS -// Copies the name for m_nDiscType into the discType property. +// Copies the name for m_discKind into the discType property. void CDiscDrive::SetDiscTypeString() { - const TCHAR *szName = rgszDiscType[m_nDiscType]; + const TCHAR *szName = rgszDiscType[m_discKind]; m_discType = new TCHAR[_tcslen(szName) + 1]; _tcscpy(m_discType, szName); } void CDiscDrive::NotifyDiscChange() { - CallFunction(this, m_nDiscType != DISC_NONE ? _T("OnDiscInserted") : _T("OnDiscRemoved")); + CallFunction(this, m_discKind != DISC_NONE ? _T("OnDiscInserted") : _T("OnDiscRemoved")); } // CDiscDrive::CDiscDrive() @@ -139,14 +139,14 @@ CDiscDrive::CDiscDrive() c_drives.AddNode(this); AddRef(); - if (TheseusHasLaunchData() || g_nDiscType == DISC_VIDEO || g_nDiscType == DISC_BAD) + if (TheseusHasLaunchData() || g_discKind == DISC_DVD || g_discKind == DISC_BAD) { - m_nDiscType = g_nDiscType; + m_discKind = g_discKind; HalReadSMCTrayState(&m_trayState, NULL); } else { - m_nDiscType = DISC_NONE; + m_discKind = DISC_NONE; m_trayState = SMC_TRAY_STATE_NO_MEDIA; } @@ -191,11 +191,11 @@ void CDiscDrive::Advance(float nSeconds) ResetScreenSaver(); - g_nDiscType = GetDiscType(); - if (g_nDiscType == m_nDiscType) + g_discKind = GetDiscType(); + if (g_discKind == m_discKind) return; - m_nDiscType = g_nDiscType; + m_discKind = g_discKind; delete[] m_discType; SetDiscTypeString(); @@ -207,10 +207,10 @@ void CDiscDrive::Advance(float nSeconds) // CDiscDrive::getTrackCount() [script fn 'getTrackCount', FND 0x0017fd48, sig 2] // Reconstructed from 5960 retail XBE @ 0x0003a030: -// return g_BootType == DISC_AUDIO ? g_cdrom.GetTrackCount() : 0; +// return g_BootType == DISC_AUDIO ? g_discIoctl.GetTrackCount() : 0; int CDiscDrive::getTrackCount() { - return g_nDiscType == DISC_AUDIO ? g_cdrom.GetTrackCount() : 0; + return g_discKind == DISC_AUDIO ? g_discIoctl.GetTrackCount() : 0; } // "mm:ss", or "" when there's nothing to time. @@ -231,14 +231,14 @@ static CStrObject *FormatMinutesSeconds(bool bHave, int nMinutes, int nSeconds) CStrObject *CDiscDrive::FormatTotalTime() { int nMinutes, nSeconds; - bool bHave = g_cdrom.GetTotalLength(&nMinutes, &nSeconds, NULL); + bool bHave = g_discIoctl.GetTotalLength(&nMinutes, &nSeconds, NULL); return FormatMinutesSeconds(bHave, nMinutes, nSeconds); } CStrObject *CDiscDrive::FormatTrackTime(int nTrack) { int nMinutes, nSeconds; - bool bHave = g_cdrom.GetTrackLength(nTrack, &nMinutes, &nSeconds, NULL); + bool bHave = g_discIoctl.GetTrackLength(nTrack, &nMinutes, &nSeconds, NULL); return FormatMinutesSeconds(bHave, nMinutes, nSeconds); } @@ -250,17 +250,17 @@ static CStrObject *StrOrEmpty(const TCHAR *sz) CStrObject *CDiscDrive::getArtist() { - return StrOrEmpty(g_cdrom.GetArtist()); + return StrOrEmpty(g_discIoctl.GetArtist()); } CStrObject *CDiscDrive::getTitle() { - return StrOrEmpty(g_cdrom.GetTitle()); + return StrOrEmpty(g_discIoctl.GetTitle()); } CStrObject *CDiscDrive::getTrackName(int nTrack) { - return StrOrEmpty(g_cdrom.GetTrackName(nTrack)); + return StrOrEmpty(g_discIoctl.GetTrackName(nTrack)); } // CDiscDrive::LaunchDisc() [script fn 'LaunchDisc', FND 0x0017fd90, sig 1] @@ -285,7 +285,7 @@ void CDiscDrive::LaunchDisc() delete pTitleId; } - XLaunchNewImage(g_nDiscType == DISC_TITLE ? "d:\\default.xbe" : NULL, NULL); + XLaunchNewImage(g_discKind == DISC_TITLE ? "d:\\default.xbe" : NULL, NULL); } // Theseus: the tray, through the SMC's tray register. @@ -312,7 +312,7 @@ struct DISCTYPECHECK static const DISCTYPECHECK rgddc[] = { {_T("CDROM0:\\default.xbe"), _T("Title"), DISC_TITLE}, - {_T("CDROM0:\\video_ts\\video_ts.ifo"), _T("Video"), DISC_VIDEO}, + {_T("CDROM0:\\video_ts\\video_ts.ifo"), _T("Video"), DISC_DVD}, {_T("CDROM0:\\track01.cda"), _T("Audio"), DISC_AUDIO}, }; @@ -328,8 +328,8 @@ static const DISCTYPECHECK rgddc[] = // means the disc went away. See docs/decomp/Disc.md for the instruction walk. int GetDiscType() { - if (g_cdrom.IsOpen()) - g_cdrom.Close(); + if (g_discIoctl.IsOpen()) + g_discIoctl.Close(); OBJECT_STRING cdrom; RtlInitObjectString(&cdrom, "\\??\\CdRom0:"); @@ -352,8 +352,8 @@ int GetDiscType() return bBad ? DISC_BAD : DISC_NONE; } - g_cdrom.Open(1); - if (g_cdrom.IsOpen()) + g_discIoctl.Open(1); + if (g_discIoctl.IsOpen()) return DISC_AUDIO; bool bMayRetry = true; diff --git a/theseus/xbox/dsound_manager.cpp b/theseus/xbox/dsound_manager.cpp index 354cdf9..423159b 100755 --- a/theseus/xbox/dsound_manager.cpp +++ b/theseus/xbox/dsound_manager.cpp @@ -11,8 +11,8 @@ extern "C" extern DWORD g_dwDirectSoundOverrideSpeakerConfig; -#define DISC_VIDEO 4 -extern int g_nDiscType; +#define DISC_DVD 4 +extern int g_discKind; DSoundManager* DSoundManager::pinstance = NULL; @@ -52,7 +52,7 @@ static DWORD WINAPI DirectSoundWorker(LPVOID pvParameter) // DSoundManager::Initialize() // Reconstructed from 5960 retail XBE @ 0x00062750: -// if (g_BootType == DISC_VIDEO) return false; +// if (g_BootType == DISC_DVD) return false; // g_dwDirectSoundOverrideSpeakerConfig = (XGetAudioFlags() basic == MONO); // if (DirectSoundCreate(0, &g_pDirectSound, 0) < 0) return false; // for (bin = 0; bin < 31; bin++) SetMixBinHeadroom(bin, 0); @@ -64,7 +64,7 @@ HRESULT DSoundManager::Initialize() if (m_directSound != NULL) return S_FALSE; - if (g_nDiscType == DISC_VIDEO) + if (g_discKind == DISC_DVD) return E_FAIL; // Mono stays mono; everything else mixes as stereo and lets the diff --git a/theseus/xbox/main.cpp b/theseus/xbox/main.cpp index 9b70f65..29afadf 100644 --- a/theseus/xbox/main.cpp +++ b/theseus/xbox/main.cpp @@ -286,7 +286,7 @@ static void Theseus_Init() g_dwMainThreadId = GetCurrentThreadId(); } -extern CNtIoctlCdromService g_cdrom; +extern CNtIoctlCdromService g_discIoctl; extern int GetDiscType(); HRESULT InitAudio() @@ -295,8 +295,8 @@ HRESULT InitAudio() do { // retreive the status of DVD/CD Rom - g_cdrom.Open(1); - g_nDiscType = GetDiscType(); + g_discIoctl.Open(1); + g_discKind = GetDiscType(); // initialize DSound if (!DSoundManager::Instance()) @@ -491,16 +491,16 @@ bool InitD3D() case XC_AV_PACK_SVIDEO: case XC_AV_PACK_RFU: case XC_AV_PACK_SCART: - g_pp.BackBufferWidth = (g_nDiscType == DISC_VIDEO) ? 720 : 640; + g_pp.BackBufferWidth = (g_discKind == DISC_DVD) ? 720 : 640; g_pp.BackBufferHeight = isPAL ? 576 : 480; break; case XC_AV_PACK_HDTV: - g_pp.BackBufferWidth = (g_nDiscType == DISC_VIDEO) ? 720 : 640; + g_pp.BackBufferWidth = (g_discKind == DISC_DVD) ? 720 : 640; g_pp.BackBufferHeight = 480; // Check for DVD 480p override - if ((XBOX_480P_MACROVISION_ENABLED & XboxHardwareInfo->Flags) && g_nDiscType == DISC_VIDEO) + if ((XBOX_480P_MACROVISION_ENABLED & XboxHardwareInfo->Flags) && g_discKind == DISC_DVD) { DWORD dvdFlags = 0, dvdType = 0; if (XQueryValue(XC_VIDEO_FLAGS, &dvdType, &dvdFlags, sizeof(dvdFlags), NULL) == ERROR_SUCCESS) diff --git a/theseus/xbox/memory_monitor.cpp b/theseus/xbox/memory_monitor.cpp index 48c1176..8681d97 100755 --- a/theseus/xbox/memory_monitor.cpp +++ b/theseus/xbox/memory_monitor.cpp @@ -23,14 +23,14 @@ enum { PATH_UP, PATH_DOWN, PATH_LEFT, PATH_RIGHT }; static const BYTE s_paths[8][4][3] = { // up down left right - { { PATH_END }, { Dev2Unit1, Dev2Unit2, PATH_END }, { PATH_END }, { Dev1Unit2, Dev0, PATH_END } }, - { { PATH_END }, { Dev2Unit2, Dev2Unit1, PATH_END }, { Dev1Unit1, PATH_END }, { Dev0, PATH_END } }, - { { Dev1Unit1, Dev1Unit2, PATH_END }, { PATH_END }, { PATH_END }, { Dev2Unit2, Dev0, PATH_END } }, - { { Dev1Unit2, Dev1Unit1, PATH_END }, { PATH_END }, { Dev2Unit1, PATH_END }, { Dev0, PATH_END } }, - { { Dev4Unit1, Dev4Unit2, PATH_END }, { PATH_END }, { Dev0, PATH_END }, { Dev3Unit2, PATH_END } }, - { { Dev4Unit2, Dev4Unit1, PATH_END }, { PATH_END }, { Dev3Unit1, Dev0, PATH_END }, { PATH_END } }, - { { PATH_END }, { Dev3Unit1, Dev3Unit2, PATH_END }, { Dev0, PATH_END }, { Dev4Unit2, PATH_END } }, - { { PATH_END }, { Dev3Unit2, Dev3Unit1, PATH_END }, { Dev4Unit1, Dev0, PATH_END }, { PATH_END } }, + { { PATH_END }, { SLOT_P2A, SLOT_P2B, PATH_END }, { PATH_END }, { SLOT_P1B, SLOT_HDD, PATH_END } }, + { { PATH_END }, { SLOT_P2B, SLOT_P2A, PATH_END }, { SLOT_P1A, PATH_END }, { SLOT_HDD, PATH_END } }, + { { SLOT_P1A, SLOT_P1B, PATH_END }, { PATH_END }, { PATH_END }, { SLOT_P2B, SLOT_HDD, PATH_END } }, + { { SLOT_P1B, SLOT_P1A, PATH_END }, { PATH_END }, { SLOT_P2A, PATH_END }, { SLOT_HDD, PATH_END } }, + { { SLOT_P4A, SLOT_P4B, PATH_END }, { PATH_END }, { SLOT_HDD, PATH_END }, { SLOT_P3B, PATH_END } }, + { { SLOT_P4B, SLOT_P4A, PATH_END }, { PATH_END }, { SLOT_P3A, SLOT_HDD, PATH_END }, { PATH_END } }, + { { PATH_END }, { SLOT_P3A, SLOT_P3B, PATH_END }, { SLOT_HDD, PATH_END }, { SLOT_P4B, PATH_END } }, + { { PATH_END }, { SLOT_P3B, SLOT_P3A, PATH_END }, { SLOT_P4A, SLOT_HDD, PATH_END }, { PATH_END } }, }; class CMemoryMonitor : public CNode @@ -82,9 +82,9 @@ class CMemoryMonitor : public CNode int m_nPrefCol; int m_nPrefUnit; - DWORD m_dwPendingDevUnits; - bool m_rgbValidDevUnit[8]; - char m_rgchMount[8]; + DWORD m_muArrivals; + bool m_slotMounted[8]; + char m_driveLetter[8]; DECLARE_NODE_PROPS(); DECLARE_NODE_FUNCTIONS(); @@ -98,7 +98,7 @@ class CMemoryMonitor : public CNode int FreeSlotsOf(int devUnit); }; -CMemoryMonitor *g_pMemoryMonitor; +CMemoryMonitor *g_pStorageWatch; IMPLEMENT_NODE("MemoryMonitor", CMemoryMonitor, CNode) @@ -144,9 +144,9 @@ static DWORD DeviceBit(int devUnit) { return (SlotOf(devUnit) ? 0x10000u : 1u) < // starts out pending. CMemoryMonitor::CMemoryMonitor() { - g_pMemoryMonitor = this; + g_pStorageWatch = this; - m_curDevUnit = Dev0; + m_curDevUnit = SLOT_HDD; m_invalidDevUnit = -1; m_blockInsertion = false; m_enumerationOn = false; @@ -157,10 +157,10 @@ CMemoryMonitor::CMemoryMonitor() m_nPrefCol = 0; m_nPrefUnit = 0; - memset(m_rgbValidDevUnit, 0, sizeof(m_rgbValidDevUnit)); - memset(m_rgchMount, 0, sizeof(m_rgchMount)); + memset(m_slotMounted, 0, sizeof(m_slotMounted)); + memset(m_driveLetter, 0, sizeof(m_driveLetter)); - m_dwPendingDevUnits = XGetDevices(XDEVICE_TYPE_MEMORY_UNIT); + m_muArrivals = XGetDevices(XDEVICE_TYPE_MEMORY_UNIT); UpdateValidDeviceFlags(); } @@ -174,16 +174,16 @@ bool XboxFormatMemoryUnit(UINT nDevicePort, UINT nMemoryUnit); // drive if it was selected. A bad unit that leaves stops being the bad one. void CMemoryMonitor::HandleRemoval(int devUnit) { - if (m_rgbValidDevUnit[devUnit]) + if (m_slotMounted[devUnit]) { XUnmountMU(PortOf(devUnit), SlotOf(devUnit)); - m_rgchMount[devUnit] = 0; + m_driveLetter[devUnit] = 0; g_titles[devUnit].SetRoot(0, false); - m_rgbValidDevUnit[devUnit] = false; + m_slotMounted[devUnit] = false; if (m_curDevUnit == devUnit) { - m_curDevUnit = Dev0; + m_curDevUnit = SLOT_HDD; CallFunction(this, _T("OnCurDevUnitChange")); } } @@ -202,21 +202,21 @@ void CMemoryMonitor::HandleRemoval(int devUnit) // hears OnInvalidMU(devUnit, mounted now). void CMemoryMonitor::MountPending(int devUnit) { - m_dwPendingDevUnits &= ~DeviceBit(devUnit); + m_muArrivals &= ~DeviceBit(devUnit); DWORD dwError = ERROR_SUCCESS; for (int attempt = 0; attempt < 3; attempt++) { - dwError = XMountMURoot(PortOf(devUnit), SlotOf(devUnit), &m_rgchMount[devUnit]); + dwError = XMountMURoot(PortOf(devUnit), SlotOf(devUnit), &m_driveLetter[devUnit]); if (dwError == ERROR_SUCCESS) break; } if (dwError == ERROR_SUCCESS) { - XCleanMUFromRoot(m_rgchMount[devUnit], 0); - m_rgbValidDevUnit[devUnit] = true; - g_titles[devUnit].SetRoot(m_rgchMount[devUnit], false); + XCleanMUFromRoot(m_driveLetter[devUnit], 0); + m_slotMounted[devUnit] = true; + g_titles[devUnit].SetRoot(m_driveLetter[devUnit], false); CallFunction(this, _T("OnDeviceChange")); return; } @@ -227,7 +227,7 @@ void CMemoryMonitor::MountPending(int devUnit) CObject *rgArgs[2]; rgArgs[0] = new CNumObject((float)devUnit); - rgArgs[1] = new CNumObject(m_rgbValidDevUnit[devUnit] ? 1.0f : 0.0f); + rgArgs[1] = new CNumObject(m_slotMounted[devUnit] ? 1.0f : 0.0f); CallFunction(this, _T("OnInvalidMU"), 2, rgArgs); } @@ -243,12 +243,12 @@ void CMemoryMonitor::UpdateValidDeviceFlags() return; DWORD dwInserted, dwRemoved; - if (!XGetDeviceChanges(XDEVICE_TYPE_MEMORY_UNIT, &dwInserted, &dwRemoved) && m_dwPendingDevUnits == 0) + if (!XGetDeviceChanges(XDEVICE_TYPE_MEMORY_UNIT, &dwInserted, &dwRemoved) && m_muArrivals == 0) return; ResetScreenSaver(); - m_dwPendingDevUnits = (m_dwPendingDevUnits & ~dwRemoved) | dwInserted; + m_muArrivals = (m_muArrivals & ~dwRemoved) | dwInserted; for (int devUnit = 0; devUnit < 8; devUnit++) { @@ -257,7 +257,7 @@ void CMemoryMonitor::UpdateValidDeviceFlags() if (dwRemoved & dwBit) HandleRemoval(devUnit); - if (!m_blockInsertion && (m_dwPendingDevUnits & dwBit)) + if (!m_blockInsertion && (m_muArrivals & dwBit)) MountPending(devUnit); } } @@ -268,12 +268,12 @@ void CMemoryMonitor::UpdateValidDeviceFlags() // that port's top or bottom slot holds a mounted unit; 0 for a bad port. int CMemoryMonitor::HaveDeviceTop(int nDevice) { - return (nDevice >= 0 && nDevice < 4) ? m_rgbValidDevUnit[nDevice * 2] : 0; + return (nDevice >= 0 && nDevice < 4) ? m_slotMounted[nDevice * 2] : 0; } int CMemoryMonitor::HaveDeviceBottom(int nDevice) { - return (nDevice >= 0 && nDevice < 4) ? m_rgbValidDevUnit[nDevice * 2 + 1] : 0; + return (nDevice >= 0 && nDevice < 4) ? m_slotMounted[nDevice * 2 + 1] : 0; } // CMemoryMonitor::GetTotalAndFreeBlocks(devUnit, &total, &free) @@ -281,16 +281,16 @@ int CMemoryMonitor::HaveDeviceBottom(int nDevice) // a unit its mount letter (unmounted fails). Both sizes are rounded up to // 16 KB blocks and one block comes off the total for the root directory. // If the drive can't be asked, a unit is marked gone and both read 0. -// Theseus range checks devUnit first; the hard drive (Dev0) is in range. +// Theseus range checks devUnit first; the hard drive (SLOT_HDD) is in range. bool CMemoryMonitor::GetTotalAndFreeBlocks(int devUnit, int *pnTotalBlocks, int *pnFreeBlocks) { - if (devUnit < Dev1Unit1 || devUnit > Dev0) + if (devUnit < SLOT_P1A || devUnit > SLOT_HDD) return false; char szRoot[4] = { 'C', ':', '\\', 0 }; - if (devUnit != Dev0) + if (devUnit != SLOT_HDD) { - szRoot[0] = m_rgchMount[devUnit]; + szRoot[0] = m_driveLetter[devUnit]; if (szRoot[0] == 0) return false; } @@ -298,8 +298,8 @@ bool CMemoryMonitor::GetTotalAndFreeBlocks(int devUnit, int *pnTotalBlocks, int ULARGE_INTEGER qwAvail, qwTotal, qwFree; if (!GetDiskFreeSpaceEx(szRoot, &qwAvail, &qwTotal, &qwFree)) { - if (devUnit != Dev0) - m_rgbValidDevUnit[devUnit] = false; + if (devUnit != SLOT_HDD) + m_slotMounted[devUnit] = false; if (pnTotalBlocks != NULL) *pnTotalBlocks = 0; if (pnFreeBlocks != NULL) @@ -324,9 +324,9 @@ void CMemoryMonitor::Advance(float nSeconds) UpdateValidDeviceFlags(); - if (m_curDevUnit != Dev0 && !m_rgbValidDevUnit[m_curDevUnit]) + if (m_curDevUnit != SLOT_HDD && !m_slotMounted[m_curDevUnit]) { - m_curDevUnit = Dev0; + m_curDevUnit = SLOT_HDD; CallFunction(this, _T("OnCurDevUnitChange")); } @@ -345,7 +345,7 @@ void CMemoryMonitor::FollowPath(int direction) { for (const BYTE *pNext = s_paths[m_curDevUnit][direction]; *pNext != PATH_END; pNext++) { - if (*pNext == Dev0 || m_rgbValidDevUnit[*pNext]) + if (*pNext == SLOT_HDD || m_slotMounted[*pNext]) { m_curDevUnit = *pNext; return; @@ -366,11 +366,11 @@ void CMemoryMonitor::SelectionChanged() // and 4 are the right side), and fire OnCurDevUnitChange. void CMemoryMonitor::selectUp() { - if (m_curDevUnit == Dev0) + if (m_curDevUnit == SLOT_HDD) return; FollowPath(PATH_UP); m_nPrefRow = 0; - if (m_curDevUnit != Dev0) + if (m_curDevUnit != SLOT_HDD) { m_nPrefUnit = SlotOf(m_curDevUnit); m_nPrefCol = PortOf(m_curDevUnit) > 1; @@ -380,11 +380,11 @@ void CMemoryMonitor::selectUp() void CMemoryMonitor::selectDown() { - if (m_curDevUnit == Dev0) + if (m_curDevUnit == SLOT_HDD) return; FollowPath(PATH_DOWN); m_nPrefRow = 1; - if (m_curDevUnit != Dev0) + if (m_curDevUnit != SLOT_HDD) { m_nPrefUnit = SlotOf(m_curDevUnit); m_nPrefCol = PortOf(m_curDevUnit) > 1; @@ -401,17 +401,17 @@ void CMemoryMonitor::selectDown() // and 3 are the bottom row) and fire OnCurDevUnitChange. void CMemoryMonitor::selectLeft() { - if (m_curDevUnit == Dev0) + if (m_curDevUnit == SLOT_HDD) { - int nearPort = m_nPrefRow == 0 ? Dev1Unit1 : Dev2Unit1; - int farPort = m_nPrefRow == 0 ? Dev2Unit1 : Dev1Unit1; + int nearPort = m_nPrefRow == 0 ? SLOT_P1A : SLOT_P2A; + int farPort = m_nPrefRow == 0 ? SLOT_P2A : SLOT_P1A; const int tries[4] = { nearPort + 1, nearPort, farPort + 1, farPort }; int i = 0; - while (i < 4 && !m_rgbValidDevUnit[tries[i]]) + while (i < 4 && !m_slotMounted[tries[i]]) i++; if (i == 4) { - m_curDevUnit = Dev0; + m_curDevUnit = SLOT_HDD; return; } m_curDevUnit = tries[i]; @@ -422,7 +422,7 @@ void CMemoryMonitor::selectLeft() } m_nPrefCol = 0; - if (m_curDevUnit != Dev0) + if (m_curDevUnit != SLOT_HDD) { m_nPrefUnit = SlotOf(m_curDevUnit); m_nPrefRow = PortOf(m_curDevUnit) == 1 || PortOf(m_curDevUnit) == 2; @@ -432,17 +432,17 @@ void CMemoryMonitor::selectLeft() void CMemoryMonitor::selectRight() { - if (m_curDevUnit == Dev0) + if (m_curDevUnit == SLOT_HDD) { - int nearPort = m_nPrefRow == 0 ? Dev4Unit1 : Dev3Unit1; - int farPort = m_nPrefRow == 0 ? Dev3Unit1 : Dev4Unit1; + int nearPort = m_nPrefRow == 0 ? SLOT_P4A : SLOT_P3A; + int farPort = m_nPrefRow == 0 ? SLOT_P3A : SLOT_P4A; const int tries[4] = { nearPort, nearPort + 1, farPort, farPort + 1 }; int i = 0; - while (i < 4 && !m_rgbValidDevUnit[tries[i]]) + while (i < 4 && !m_slotMounted[tries[i]]) i++; if (i == 4) { - m_curDevUnit = Dev0; + m_curDevUnit = SLOT_HDD; return; } m_curDevUnit = tries[i]; @@ -453,7 +453,7 @@ void CMemoryMonitor::selectRight() } m_nPrefCol = 1; - if (m_curDevUnit != Dev0) + if (m_curDevUnit != SLOT_HDD) { m_nPrefUnit = SlotOf(m_curDevUnit); m_nPrefRow = PortOf(m_curDevUnit) == 1 || PortOf(m_curDevUnit) == 2; @@ -471,7 +471,7 @@ int CMemoryMonitor::selectDevUnit(int DriveLetter) int letter = toupper(DriveLetter); int devUnit; if (letter == 'T' || letter == 'U') - devUnit = Dev0; + devUnit = SLOT_HDD; else if (letter >= 'H' && letter <= 'O') devUnit = letter - 'H'; else @@ -482,7 +482,7 @@ int CMemoryMonitor::selectDevUnit(int DriveLetter) UpdateValidDeviceFlags(); m_enumerationOn = bWasOn; - if (devUnit != Dev0 && !m_rgbValidDevUnit[devUnit]) + if (devUnit != SLOT_HDD && !m_slotMounted[devUnit]) return false; m_curDevUnit = devUnit; @@ -492,7 +492,7 @@ int CMemoryMonitor::selectDevUnit(int DriveLetter) // Name lookup for the save grid; an unmounted unit gives "". void FormatDeviceName(int devUnit, TCHAR *szBuf) { - if (!g_pMemoryMonitor->FormatDeviceName2(devUnit, szBuf)) + if (!g_pStorageWatch->FormatDeviceName2(devUnit, szBuf)) szBuf[0] = 0; } @@ -512,11 +512,11 @@ bool CMemoryMonitor::FormatDeviceName2(int devUnit, TCHAR *szBuf) { if (devUnit == -1) devUnit = m_curDevUnit; - if (devUnit < Dev1Unit1 || devUnit > Dev4Unit2 || m_rgchMount[devUnit] == 0) + if (devUnit < SLOT_P1A || devUnit > SLOT_P4B || m_driveLetter[devUnit] == 0) return false; TCHAR szName[MAX_MUNAME]; - if (XMUNameFromDriveLetter(m_rgchMount[devUnit], szName, MAX_MUNAME) != ERROR_SUCCESS) + if (XMUNameFromDriveLetter(m_driveLetter[devUnit], szName, MAX_MUNAME) != ERROR_SUCCESS) return false; _tcscpy(szBuf, szName); return true; @@ -604,11 +604,11 @@ float CMemoryMonitor::GetFreeTotalRatio(int devUnit) // when the name fits in MAX_MUNAME with its terminator. void CMemoryMonitor::SetMUName(int devUnit, const TCHAR *szName) { - if (devUnit < Dev1Unit1 || devUnit > Dev4Unit2 || m_rgchMount[devUnit] == 0) + if (devUnit < SLOT_P1A || devUnit > SLOT_P4B || m_driveLetter[devUnit] == 0) return; if (_tcslen(szName) + 1 > MAX_MUNAME) return; - XMUWriteNameToDriveLetter(m_rgchMount[devUnit], szName); + XMUWriteNameToDriveLetter(m_driveLetter[devUnit], szName); } // CMemoryMonitor::FormatMemoryUnit(devUnit) [script fn 'FormatMemoryUnit', FND 0x00187bc0, sig 14] @@ -616,25 +616,25 @@ void CMemoryMonitor::SetMUName(int devUnit, const TCHAR *szName) // titles), format, mount again. On a good mount the titles are rescanned // at once, so the save grid doesn't see the unit as dirty a frame later. // Theseus refuses anything that isn't a memory unit: scripts reach this, -// and Dev0 sits one past the end of the mount arrays. +// and SLOT_HDD sits one past the end of the mount arrays. void CMemoryMonitor::FormatMemoryUnit(int devUnit) { - if (devUnit < Dev1Unit1 || devUnit > Dev4Unit2) + if (devUnit < SLOT_P1A || devUnit > SLOT_P4B) return; - if (m_rgchMount[devUnit] != 0) + if (m_driveLetter[devUnit] != 0) { XUnmountMU(PortOf(devUnit), SlotOf(devUnit)); - m_rgchMount[devUnit] = 0; + m_driveLetter[devUnit] = 0; g_titles[devUnit].SetRoot(0, false); } - m_rgbValidDevUnit[devUnit] = false; + m_slotMounted[devUnit] = false; XboxFormatMemoryUnit(PortOf(devUnit), SlotOf(devUnit)); - if (XMountMURoot(PortOf(devUnit), SlotOf(devUnit), &m_rgchMount[devUnit]) == ERROR_SUCCESS) + if (XMountMURoot(PortOf(devUnit), SlotOf(devUnit), &m_driveLetter[devUnit]) == ERROR_SUCCESS) { - m_rgbValidDevUnit[devUnit] = true; - g_titles[devUnit].SetRoot(m_rgchMount[devUnit], true); + m_slotMounted[devUnit] = true; + g_titles[devUnit].SetRoot(m_driveLetter[devUnit], true); } } From 7fa11713c2f1cdcf45ddec5869ea2c2e69731f63 Mon Sep 17 00:00:00 2001 From: Milenko <39630670+MrMilenko@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:52:55 -0500 Subject: [PATCH 4/8] Renamed the script engine's internals Runner, compiler, array and class record members and globals got names of their own. Only CHECK message text changes in the compiled code; the PRD and FND table names stay as they are. --- docs/decomp/Node.md | 20 +-- docs/decomp/VM.md | 10 +- theseus/desktop/dashapp.cpp | 4 +- theseus/desktop/inspector.cpp | 20 +-- theseus/desktop/xap_editor.cpp | 6 +- theseus/engine/array.cpp | 124 ++++++++--------- theseus/engine/runner.h | 34 ++--- theseus/engine/settings_nodes.cpp | 2 +- theseus/engine/xap_compile.cpp | 140 ++++++++++---------- theseus/engine/xap_compile.h | 34 ++--- theseus/render/node.h | 36 ++--- theseus/render/node_system.cpp | 164 +++++++++++------------ theseus/render/scene_groups.cpp | 32 ++--- theseus/shared/date_node.cpp | 10 +- theseus/shared/string_util.cpp | 14 +- theseus/shared/util.cpp | 20 +-- theseus/shared/xap_vm.cpp | 212 +++++++++++++++--------------- theseus/xbox/main.cpp | 4 +- 18 files changed, 443 insertions(+), 443 deletions(-) diff --git a/docs/decomp/Node.md b/docs/decomp/Node.md index b6ff414..9176949 100644 --- a/docs/decomp/Node.md +++ b/docs/decomp/Node.md @@ -45,7 +45,7 @@ The macro patterns were deduced from the init function structure in the binary. 3. Stores the CreateNode factory function pointer 4. Links to the base class's CNodeClass 5. Links to the PRD table -6. Inserts itself into a global linked list (c_pFirstClass) +6. Inserts itself into a global linked list (c_pClassChain) This was confirmed by Ghidra cross-references resolving each registered class to its CNodeClass instance, one per node type, all linked into the same global list. @@ -78,7 +78,7 @@ Example: `sig_si` = returns CStrObject*, takes one int parameter. ### Key Addresses -- `CNodeClass::c_pFirstClass` at `0x0001a068`: head of registered class list +- `CNodeClass::c_pClassChain` at `0x0001a068`: head of registered class list - `_classCObject` at `0x0001a06c`: CObject's class descriptor - `_classCTheseusNode`: base node class descriptor - Individual class descriptors for all 64+ node types @@ -97,7 +97,7 @@ Additional virtuals: OnLoad, Advance, Render, GetBBox, GetRadius, GetPalette, Re ### Object Type IDs -The `m_obj` field encodes runtime type. Values recovered from switch statements throughout the VM (CRunner::Step, CObject::Dot, Dereference, etc.): +The `m_kind` field encodes runtime type. Values recovered from switch statements throughout the VM (CRunner::Step, CObject::Dot, Dereference, etc.): ``` 0 = objUndefined 8 = objFunctionRef @@ -113,7 +113,7 @@ The `m_obj` field encodes runtime type. Values recovered from switch statements ### Typed Array Classes -CIntArray, CNumArray, CVec2Array, CVec3Array, CVec4Array all follow the same pattern: `m_nAlloc`, `m_nSize`, `m_value` pointer. Used by PRD entries with types pt_intarray through pt_vec4array. Confirmed by SetProperty handling for each type. +CIntArray, CNumArray, CVec2Array, CVec3Array, CVec4Array all follow the same pattern: `m_reserved`, `m_nSize`, `m_value` pointer. Used by PRD entries with types pt_intarray through pt_vec4array. Confirmed by SetProperty handling for each type. ### CNodeArray @@ -136,18 +136,18 @@ The base classes sit in three runs of code, each in source-file order. ### Object layouts ``` -CObject 0x14 bytes +0x00 vtable +0x04 m_nRefCount +0x08 m_obj - +0x0c m_parent +0x10 m_members (CNameSpace*) +CObject 0x14 bytes +0x00 vtable +0x04 m_nRefCount +0x08 m_kind + +0x0c m_parent +0x10 m_pScope (CNameSpace*) CNode 0x1c bytes +0x14 m_behavior (CRunner*) +0x18 m_visible CTimeDepNode 0x30 bytes +0x1c m_loop +0x20 m_startTime +0x24 m_stopTime - +0x28 m_isActive +0x2c m_lastStartTime + +0x28 m_isActive +0x2c m_prevStartTime CNodeClass +0x14 m_className +0x18 m_nObjectSize - +0x1c m_pfnCreateNode +0x20 m_baseClass + +0x1c m_pfnNew +0x20 m_baseClass +0x24 m_rgprd +0x28 m_nextClass CClass +0x2c m_url +0x30 m_file +0x58 m_instanceFunctions +0x64 m_constructor +0x68 m_nVarCount -CInstance 0x54 bytes CGroup up to +0x44, +0x44 m_class +0x48 m_vars -CNodeArray 0x0c bytes +0x00 m_length +0x04 m_nAlloc +0x08 m_rgpNode +CInstance 0x54 bytes CGroup up to +0x44, +0x44 m_classDef +0x48 m_vars +CNodeArray 0x0c bytes +0x00 m_length +0x04 m_reserved +0x08 m_nodes ``` Vtables: CObject `0x00021b00`, CNodeClass `0x00021958`, CNode `0x000219f8`, CTimeDepNode `0x00021990`, CInstance `0x000226a0`, CClass `0x000226fc`. Slots referenced by the code below: `+0x04` GetPropMap, `+0x08` OnSetProperty, `+0x0c` AddRef, `+0x10` Release, `+0x14` GetFunctionMap, `+0x18` GetNodeClass, `+0x1c` ToNum, `+0x20` ToStr, `+0x24` Deref, `+0x34` GetMember, `+0x38` OnLoad, `+0x5c` CTimeDepNode::OnIsActiveChanged. diff --git a/docs/decomp/VM.md b/docs/decomp/VM.md index cb34904..1009066 100644 --- a/docs/decomp/VM.md +++ b/docs/decomp/VM.md @@ -89,17 +89,17 @@ Special globals resolved by name string comparison: `Math`, `camera`. Compiled functions are allocated with trailing bytecode: ``` -[CFunction header][m_rgop bytecode bytes...] +[CFunction header][m_bytecode bytecode bytes...] ``` -Created via placement new: `new(m_nop) CFunction` allocates `sizeof(CFunction) + m_nop` extra bytes. +Created via placement new: `new(m_opPos) CFunction` allocates `sizeof(CFunction) + m_opPos` extra bytes. ### Key Globals -- `g_pRunner`: current active VM instance +- `g_pActiveRunner`: current active VM instance - `g_pThis`: current `this` object for property resolution -- `g_classes`: CNameSpace for scripted class definitions -- `g_rgParam` / `g_nParam`: constructor parameter passing +- `g_classTable`: CNameSpace for scripted class definitions +- `g_scriptArgs` / `g_nParam`: constructor parameter passing ### Comment / Whitespace Handling diff --git a/theseus/desktop/dashapp.cpp b/theseus/desktop/dashapp.cpp index 091fc01..270006d 100755 --- a/theseus/desktop/dashapp.cpp +++ b/theseus/desktop/dashapp.cpp @@ -750,8 +750,8 @@ bool InitApp() if (!g_pClass->Load(szStartup)) { // A parse error has already said what went wrong. - extern bool g_bParseError; - if (!g_bParseError) + extern bool g_bXapSyntaxError; + if (!g_bXapSyntaxError) Alert("%s\n\nCannot open file.", szStartup); return false; } diff --git a/theseus/desktop/inspector.cpp b/theseus/desktop/inspector.cpp index 04921d1..63045ef 100644 --- a/theseus/desktop/inspector.cpp +++ b/theseus/desktop/inspector.cpp @@ -56,10 +56,10 @@ void SetVisibilityRecursive(CNode* pNode, bool visible, int depth) { // Find the DEF name for a node by searching an instance's class members static const TCHAR* FindNodeDefNameInInstance(CNode* pNode, CInstance* pInst) { - if (!pNode || !pInst || !pInst->m_class || !pInst->m_class->m_members) + if (!pNode || !pInst || !pInst->m_classDef || !pInst->m_classDef->m_pScope) return NULL; - for (CDefine* d = pInst->m_class->m_members->m_firstDefine; d; d = d->m_next) { - if (d->m_node && d->m_node->m_obj == objMember) { + for (CDefine* d = pInst->m_classDef->m_pScope->m_firstDefine; d; d = d->m_next) { + if (d->m_node && d->m_node->m_kind == objMember) { CMember* mem = (CMember*)d->m_node; int idx = mem->m_memberIndex; if (idx >= 0 && idx < pInst->m_vars.GetLength()) { @@ -505,13 +505,13 @@ void RenderInspectorPanel(IDirect3DDevice8* dev) { // Instance: show script variables CInstance* inst = dynamic_cast(sel); - if (inst && inst->m_class && inst->m_class->m_members) { + if (inst && inst->m_classDef && inst->m_classDef->m_pScope) { int varCount = inst->m_vars.GetLength(); if (varCount > 0) { ImGui::Spacing(); if (ImGui::CollapsingHeader("Script Variables", ImGuiTreeNodeFlags_DefaultOpen)) { - for (CDefine* d = inst->m_class->m_members->m_firstDefine; d; d = d->m_next) { - if (!d->m_node || d->m_node->m_obj != objMember) continue; + for (CDefine* d = inst->m_classDef->m_pScope->m_firstDefine; d; d = d->m_next) { + if (!d->m_node || d->m_node->m_kind != objMember) continue; CMember* mem = (CMember*)d->m_node; int idx = mem->m_memberIndex; if (idx < 0 || idx >= varCount) continue; @@ -521,10 +521,10 @@ void RenderInspectorPanel(IDirect3DDevice8* dev) { continue; } // Show value based on object type - if (varNode->m_obj == objNumber) { + if (varNode->m_kind == objNumber) { CNumObject* num = (CNumObject*)varNode; ImGui::Text(" %s: %.4g", d->m_name, num->m_value); - } else if (varNode->m_obj == objString) { + } else if (varNode->m_kind == objString) { CStrObject* str = (CStrObject*)varNode; const TCHAR* sv = str->GetSz(); // Truncate long strings in display @@ -535,12 +535,12 @@ void RenderInspectorPanel(IDirect3DDevice8* dev) { } else { ImGui::Text(" %s: \"%s\"", d->m_name, sv ? sv : ""); } - } else if (varNode->m_obj == objNode) { + } else if (varNode->m_kind == objNode) { CNodeClass* vnc = varNode->GetNodeClass(); ImGui::TextColored(ImVec4(0.6f, 0.8f, 0.6f, 1.0f), " %s: [%s]", d->m_name, (vnc && vnc->m_className) ? vnc->m_className : "node"); } else { - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), " %s: (type %d)", d->m_name, varNode->m_obj); + ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), " %s: (type %d)", d->m_name, varNode->m_kind); } } } diff --git a/theseus/desktop/xap_editor.cpp b/theseus/desktop/xap_editor.cpp index 4b9ba64..ef3bb1d 100644 --- a/theseus/desktop/xap_editor.cpp +++ b/theseus/desktop/xap_editor.cpp @@ -220,8 +220,8 @@ void ReloadSceneFromEditor() { delete g_pClass; g_pClass = new CClass; - extern bool g_bParseError; - g_bParseError = false; + extern bool g_bXapSyntaxError; + g_bXapSyntaxError = false; char* parseBuf = (char*)malloc(text.size() + 1); memcpy(parseBuf, text.c_str(), text.size() + 1); @@ -237,7 +237,7 @@ void ReloadSceneFromEditor() { bool ok = g_pClass->ParseFile(url, (const TCHAR*)parseBuf); free(parseBuf); - if (!ok || g_bParseError) { + if (!ok || g_bXapSyntaxError) { snprintf(g_xapEditorStatus, sizeof(g_xapEditorStatus), "Parse error! Check console."); g_xapEditorStatusTime = (float)SDL_GetTicks() / 1000.0f; g_pObject = (CInstance*)g_pClass->CreateNode(); diff --git a/theseus/engine/array.cpp b/theseus/engine/array.cpp index fac903f..d274127 100755 --- a/theseus/engine/array.cpp +++ b/theseus/engine/array.cpp @@ -7,7 +7,7 @@ #include "node.h" #include "runner.h" -extern CObject **g_rgParam; +extern CObject **g_scriptArgs; extern int g_nParam; extern CObject *Dereference(CObject *pObject); @@ -34,9 +34,9 @@ class CArrayObject : public CObject void Grow(int nNewLength); void Allocate(int nLength); - int m_nLength; - int m_nAlloc; - CObject **m_object; + int m_used; + int m_reserved; + CObject **m_items; DECLARE_NODE_FUNCTIONS() @@ -55,8 +55,8 @@ class CArrayElementReference : public CObject void Assign(CObject *pObject); CObject *Deref(); - CArrayObject *m_pArray; - int m_nIndex; + CArrayObject *m_pOwner; + int m_elem; }; // Takes a reference for the copy it stores. @@ -73,15 +73,15 @@ static inline CObject *Share(CObject *obj) // reference) and the index. CArrayElementReference::CArrayElementReference(CArrayObject *pArray, int nIndex) { - m_pArray = pArray; - m_pArray->AddRef(); - m_nIndex = nIndex; + m_pOwner = pArray; + m_pOwner->AddRef(); + m_elem = nIndex; } // Reconstructed from 5960 retail XBE @ 0x000304c0. CArrayElementReference::~CArrayElementReference() { - m_pArray->Release(); + m_pOwner->Release(); } // CArrayElementReference::Assign(value) @@ -90,15 +90,15 @@ CArrayElementReference::~CArrayElementReference() void CArrayElementReference::Assign(CObject *pObject) { // 5960 writes a[-1] in front of the array; refuse it instead. - if (!CHECK(m_nIndex >= 0)) + if (!CHECK(m_elem >= 0)) { - g_pRunner->Error(_T("Array reference out of bounds")); + g_pActiveRunner->Error(_T("Array reference out of bounds")); return; } - if (m_nIndex >= m_pArray->m_nLength) - m_pArray->Grow(m_nIndex + 1); + if (m_elem >= m_pOwner->m_used) + m_pOwner->Grow(m_elem + 1); - CObject *&slot = m_pArray->m_object[m_nIndex]; + CObject *&slot = m_pOwner->m_items[m_elem]; if (slot != NULL) slot->Release(); slot = Share(pObject); @@ -110,12 +110,12 @@ void CArrayElementReference::Assign(CObject *pObject) // a reference), and the reference object lets go of itself. CObject *CArrayElementReference::Deref() { - if (m_nIndex < 0 || m_nIndex >= m_pArray->m_nLength) + if (m_elem < 0 || m_elem >= m_pOwner->m_used) { - g_pRunner->Error(_T("Array reference out of bounds")); + g_pActiveRunner->Error(_T("Array reference out of bounds")); return NULL; } - CObject *value = Share(m_pArray->m_object[m_nIndex]); + CObject *value = Share(m_pOwner->m_items[m_elem]); Release(); return value; } @@ -136,13 +136,13 @@ END_NODE_FUN() // Sets up n empty slots (none at all for 0). void CArrayObject::Allocate(int nLength) { - m_nLength = nLength; - m_nAlloc = nLength; - m_object = NULL; + m_used = nLength; + m_reserved = nLength; + m_items = NULL; if (nLength != 0) { - m_object = new CObject *[nLength]; - memset(m_object, 0, nLength * sizeof(CObject *)); + m_items = new CObject *[nLength]; + memset(m_items, 0, nLength * sizeof(CObject *)); } } @@ -152,13 +152,13 @@ void CArrayObject::Allocate(int nLength) // elements, each with a reference; none makes an empty array. CArrayObject::CArrayObject() { - m_obj = objArray; + m_kind = objArray; int length = 0; if (g_nParam == 1) { - g_rgParam[0] = Dereference(g_rgParam[0]); - CNumObject *count = g_rgParam[0]->ToNum(); + g_scriptArgs[0] = Dereference(g_scriptArgs[0]); + CNumObject *count = g_scriptArgs[0]->ToNum(); length = (int)count->m_value; count->Release(); } @@ -171,7 +171,7 @@ CArrayObject::CArrayObject() if (g_nParam > 1) { for (int i = 0; i < g_nParam; i++) - m_object[i] = Share(g_rgParam[i]); + m_items[i] = Share(g_scriptArgs[i]); } } @@ -184,12 +184,12 @@ CArrayObject::CArrayObject(int nLength) // Reconstructed from 5960 retail XBE @ 0x00030800: releases every element. CArrayObject::~CArrayObject() { - for (int i = 0; i < m_nLength; i++) + for (int i = 0; i < m_used; i++) { - if (m_object[i] != NULL) - m_object[i]->Release(); + if (m_items[i] != NULL) + m_items[i]->Release(); } - delete[] m_object; + delete[] m_items; } // CArrayObject::Grow(length) @@ -199,21 +199,21 @@ CArrayObject::~CArrayObject() // don't copy every time. void CArrayObject::Grow(int nNewLength) { - if (nNewLength <= m_nLength) + if (nNewLength <= m_used) return; - if (nNewLength > m_nAlloc) + if (nNewLength > m_reserved) { int room = nNewLength + nNewLength / 2 + 16; CObject **grown = new CObject *[room]; - if (m_nLength > 0) - memcpy(grown, m_object, m_nLength * sizeof(CObject *)); - delete[] m_object; - m_object = grown; - m_nAlloc = room; + if (m_used > 0) + memcpy(grown, m_items, m_used * sizeof(CObject *)); + delete[] m_items; + m_items = grown; + m_reserved = room; } - memset(m_object + m_nLength, 0, (nNewLength - m_nLength) * sizeof(CObject *)); - m_nLength = nNewLength; + memset(m_items + m_used, 0, (nNewLength - m_used) * sizeof(CObject *)); + m_used = nNewLength; } // Reconstructed from 5960 retail XBE @ 0x00030960: join(","). @@ -228,10 +228,10 @@ CStrObject *CArrayObject::ToStr() // CObject::Dot. CObject *CArrayObject::Dot(CObject *pObject) { - if (pObject->m_obj == objNumber) + if (pObject->m_kind == objNumber) return new CArrayElementReference(this, (int)((CNumObject *)pObject)->m_value); - if (pObject->m_obj == objVariable && _tcscmp(((CVarObject *)pObject)->m_text, _T("length")) == 0) - return new CNumObject((float)m_nLength); + if (pObject->m_kind == objVariable && _tcscmp(((CVarObject *)pObject)->m_text, _T("length")) == 0) + return new CNumObject((float)m_used); return CObject::Dot(pObject); } @@ -248,15 +248,15 @@ static void CopyInto(CObject **dst, CObject *const *src, int count) // one's elements then other's; "object is not an array" for anything else. CObject *CArrayObject::concat(CObject *pObject) { - if (pObject->m_obj != objArray) + if (pObject->m_kind != objArray) { - g_pRunner->Error(_T("object is not an array")); + g_pActiveRunner->Error(_T("object is not an array")); return NULL; } CArrayObject *other = (CArrayObject *)pObject; - CArrayObject *result = new CArrayObject(m_nLength + other->m_nLength); - CopyInto(result->m_object, m_object, m_nLength); - CopyInto(result->m_object + m_nLength, other->m_object, other->m_nLength); + CArrayObject *result = new CArrayObject(m_used + other->m_used); + CopyInto(result->m_items, m_items, m_used); + CopyInto(result->m_items + m_used, other->m_items, other->m_used); return result; } @@ -266,16 +266,16 @@ CObject *CArrayObject::concat(CObject *pObject) CStrObject *CArrayObject::join(const TCHAR *szSeperator) { CStrObject *text = new CStrObject; - for (int i = 0; i < m_nLength; i++) + for (int i = 0; i < m_used; i++) { if (i > 0) text->Append(szSeperator); - if (m_object[i] == NULL) + if (m_items[i] == NULL) { text->Append(_T("[null]")); continue; } - CStrObject *part = m_object[i]->ToStr(); + CStrObject *part = m_items[i]->ToStr(); text->Append(part->GetSz()); part->Release(); } @@ -286,9 +286,9 @@ CStrObject *CArrayObject::join(const TCHAR *szSeperator) // Reconstructed from 5960 retail XBE @ 0x00030c40: a new array, back to front. CObject *CArrayObject::reverse() { - CArrayObject *result = new CArrayObject(m_nLength); - for (int i = 0; i < m_nLength; i++) - result->m_object[m_nLength - 1 - i] = Share(m_object[i]); + CArrayObject *result = new CArrayObject(m_used); + for (int i = 0; i < m_used; i++) + result->m_items[m_used - 1 - i] = Share(m_items[i]); return result; } @@ -301,26 +301,26 @@ CObject *CArrayObject::slice(CObject **rgparam, int nParam /*int nStart, int nEn { if (nParam != 1 && nParam != 2) { - g_pRunner->Error(_T("invalid number of parameters")); + g_pActiveRunner->Error(_T("invalid number of parameters")); return NULL; } int start = (int)rgparam[0]->Deref()->ToNum()->m_value; int end = nParam == 2 ? (int)rgparam[1]->Deref()->ToNum()->m_value : -1; if (end < 0) - end += m_nLength + 1; + end += m_used + 1; // 5960 reads past the array for a negative start or an end past the last // element; keep both inside it. if (start < 0) start = 0; - if (end > m_nLength) - end = m_nLength; + if (end > m_used) + end = m_used; int count = end - start; if (count < 0) count = 0; CArrayObject *result = new CArrayObject(count); - CopyInto(result->m_object, m_object + start, count); + CopyInto(result->m_items, m_items + start, count); return result; } @@ -347,8 +347,8 @@ static int __cdecl CompareElements(const void *left, const void *right) // Reconstructed from 5960 retail XBE @ 0x00030e70: a sorted copy (qsort). CObject *CArrayObject::sort() { - CArrayObject *result = new CArrayObject(m_nLength); - CopyInto(result->m_object, m_object, m_nLength); - qsort(result->m_object, result->m_nLength, sizeof(CObject *), CompareElements); + CArrayObject *result = new CArrayObject(m_used); + CopyInto(result->m_items, m_items, m_used); + qsort(result->m_items, result->m_used, sizeof(CObject *), CompareElements); return result; } diff --git a/theseus/engine/runner.h b/theseus/engine/runner.h index 24a6fa5..6112c7a 100755 --- a/theseus/engine/runner.h +++ b/theseus/engine/runner.h @@ -4,9 +4,9 @@ // binary write-up. // // Layouts checked against the 5960 retail XBE: -// CRunner: m_wakeup 0x00 (double), m_nop 0x08, m_ops 0x0c, m_sp 0x10, +// CRunner: m_wakeup 0x00 (double), m_opPos 0x08, m_code 0x0c, m_sp 0x10, // m_stack 0x14, m_spFrame 0x1a4, m_spBase 0x1a8, m_self 0x1ac, -// m_thisRef 0x1b0, m_bError 0x1b4, m_nLine 0x1b8, m_nextContext 0x1bc. +// m_thisRef 0x1b0, m_bFailed 0x1b4, m_nLine 0x1b8, m_nextContext 0x1bc. // 5960's stack holds 100 objects; Theseus gives it 256. // RUNCONTEXT 0x1c: next, ops, nop, spFrame, self, thisRef, sp (PushContext 0x37690). // CNumObject 0x18: m_value 0x14. @@ -233,8 +233,8 @@ class CNodeArrayObject : public CObject struct RUNCONTEXT { RUNCONTEXT* m_nextContext; - BYTE* m_ops; - UINT m_nop; + BYTE* m_code; + UINT m_opPos; UINT m_spFrame; CObject* m_self; CObject* m_thisRef; @@ -250,7 +250,7 @@ class CRunner bool SetFunc(const TCHAR* funcName); void SetFunc(CFunction* func); void ResetFunc(); - bool HasFunc() const { return m_ops != NULL; } + bool HasFunc() const { return m_code != NULL; } void Push(float value); void Push(int value); @@ -289,24 +289,24 @@ class CRunner inline int FetchInt() { int n; - memcpy(&n, m_ops + m_nop, sizeof (n)); - m_nop += sizeof (n); + memcpy(&n, m_code + m_opPos, sizeof (n)); + m_opPos += sizeof (n); return n; } inline UINT FetchUInt() { UINT n; - memcpy(&n, m_ops + m_nop, sizeof (n)); - m_nop += sizeof (n); + memcpy(&n, m_code + m_opPos, sizeof (n)); + m_opPos += sizeof (n); return n; } inline float FetchFloat() { float n; - memcpy(&n, m_ops + m_nop, sizeof (n)); - m_nop += sizeof (n); + memcpy(&n, m_code + m_opPos, sizeof (n)); + m_opPos += sizeof (n); return n; } @@ -314,26 +314,26 @@ class CRunner inline const TCHAR* FetchString(int& cch) { cch = FetchInt(); - const TCHAR* pch = (const TCHAR*)(m_ops + m_nop); - m_nop += cch * sizeof (TCHAR); + const TCHAR* pch = (const TCHAR*)(m_code + m_opPos); + m_opPos += cch * sizeof (TCHAR); return pch; } XTIME m_wakeup; // sleep deadline, 0 when awake - UINT m_nop; // offset into m_ops - BYTE* m_ops; // bytecode being run + UINT m_opPos; // offset into m_code + BYTE* m_code; // bytecode being run UINT m_sp; // next free stack slot CObject* m_stack [256]; UINT m_spFrame; // first local of the current call UINT m_spBase; CObject* m_self; // owner of the running function CObject* m_thisRef; // what "this" means in script - bool m_bError; + bool m_bFailed; int m_nLine; RUNCONTEXT* m_nextContext; }; -extern CRunner* g_pRunner; +extern CRunner* g_pActiveRunner; extern CObject* g_pThis; extern bool ExecuteScript(CObject* obj, const TCHAR* funcName); diff --git a/theseus/engine/settings_nodes.cpp b/theseus/engine/settings_nodes.cpp index 0a240d3..ff4c5b1 100755 --- a/theseus/engine/settings_nodes.cpp +++ b/theseus/engine/settings_nodes.cpp @@ -95,7 +95,7 @@ CSettings::~CSettings() CObject* CSettings::Dot(CObject* member) { CObject* own = CNode::Dot(member); - if (own != NULL || member->m_obj != objVariable) + if (own != NULL || member->m_kind != objVariable) return own; const TCHAR* name = ((CVarObject*)member)->m_text; diff --git a/theseus/engine/xap_compile.cpp b/theseus/engine/xap_compile.cpp index 5c1944c..ffab9be 100755 --- a/theseus/engine/xap_compile.cpp +++ b/theseus/engine/xap_compile.cpp @@ -17,12 +17,12 @@ // globals: file name @0x17ae90, line @0x17ae94, error flag @0x17ac80 and the // #file name buffer @0x17ac88. int g_nLine; -const TCHAR* g_szFileName; +const TCHAR* g_szCompileFile; static TCHAR g_szFileNameBuf[MAX_PATH]; -bool g_bParseError; +bool g_bXapSyntaxError; // The class namespace, 5960's list head @0x17ae98. -CNameSpace* g_classes; +CNameSpace* g_classTable; // Every hard failure hands back an empty string so callers stop cleanly. // 5960 points at a shared L"" (0x201c4 / 0x21b98) the same way. @@ -62,15 +62,15 @@ static inline bool IsKeyword(const TCHAR* pchTok, int cchTok, const TCHAR* szKey // after. Theseus splits that into a pair so the line can start elsewhere. void StartParse(const TCHAR* pch, const TCHAR* szFileName, int nLine) { - g_bParseError = false; + g_bXapSyntaxError = false; g_nLine = nLine; - g_szFileName = szFileName; + g_szCompileFile = szFileName; } void EndParse() { g_nLine = 0; - g_szFileName = NULL; + g_szCompileFile = NULL; } @@ -78,7 +78,7 @@ void EndParse() // Reconstructed from 5960 retail XBE @ 0x00032cf0. Ghidra decompile: // vswprintf(msg, 0x200, fmt, args); msg[511] = 0; // swprintf(out, <"Syntax Error ... File: %s Line: %d ... %s">, file, line, msg); -// g_bParseError = 1; +// g_bXapSyntaxError = 1; // Retail builds the text and drops it; Theseus sends it to Trace so it shows up. void SyntaxError(const TCHAR* szMsg, ...) { @@ -89,10 +89,10 @@ void SyntaxError(const TCHAR* szMsg, ...) va_end(args); TCHAR szReport[1024]; - _stprintf(szReport, _T("Syntax Error\n\nFile: %s\nLine: %d\n\n%s"), g_szFileName, g_nLine, szDetail); + _stprintf(szReport, _T("Syntax Error\n\nFile: %s\nLine: %d\n\n%s"), g_szCompileFile, g_nLine, szDetail); Trace(_T("\007%s\n"), szReport); - g_bParseError = true; + g_bXapSyntaxError = true; } @@ -143,7 +143,7 @@ const TCHAR* SkipWhite(const TCHAR* pch, COMMENT_TYPE ct) for (; *pch != '\0' && *pch != '\r' && *pch != '\n' && *pch != '"'; pch++) *pchName++ = *pch; *pchName = '\0'; - g_szFileName = g_szFileNameBuf; + g_szCompileFile = g_szFileNameBuf; } } @@ -640,21 +640,21 @@ const TCHAR* ParseVecArray(const TCHAR* pch, BYTE*& pbItems, int& cbArray, int n // The destructor @0x000346f0 frees the op buffer. CCompiler::CCompiler() { - m_ops = NULL; - m_nop = 0; + m_code = NULL; + m_opPos = 0; m_opsSize = 0; - m_bError = false; + m_bFailed = false; } CCompiler::~CCompiler() { - delete[] m_ops; + delete[] m_code; } // CCompiler::GrowTo // Reconstructed from 5960 retail XBE @ 0x00034590. Ghidra decompile: -// cb = (n + 0xfff) & ~0xfff; p = new BYTE[cb]; memcpy(p, m_ops, m_nop); -// delete m_ops; m_opsSize = cb; m_ops = p; +// cb = (n + 0xfff) & ~0xfff; p = new BYTE[cb]; memcpy(p, m_code, m_opPos); +// delete m_code; m_opsSize = cb; m_code = p; // The buffer grows in whole 4 KB pages. void CCompiler::GrowTo(int nNewSize) { @@ -662,16 +662,16 @@ void CCompiler::GrowTo(int nNewSize) int cbNew = (nNewSize + cbPage - 1) / cbPage * cbPage; BYTE* pbNew = new BYTE[cbNew]; - CopyMemory(pbNew, m_ops, m_nop); - delete[] m_ops; + CopyMemory(pbNew, m_code, m_opPos); + delete[] m_code; - m_ops = pbNew; + m_code = pbNew; m_opsSize = cbNew; } // CCompiler::SyntaxError // Reconstructed from 5960 retail XBE @ 0x000345e0. Same report as the free -// SyntaxError, and it also marks this compiler: m_bError = 1; g_bParseError = 1. +// SyntaxError, and it also marks this compiler: m_bFailed = 1; g_bXapSyntaxError = 1. // Theseus sends the text to Trace. void CCompiler::SyntaxError(const TCHAR* szMsg, ...) { @@ -682,26 +682,26 @@ void CCompiler::SyntaxError(const TCHAR* szMsg, ...) va_end(args); TCHAR szReport[1024]; - _stprintf(szReport, _T("Syntax Error\n\nFile: %s\nLine: %d\n\n%s"), g_szFileName, g_nLine, szDetail); + _stprintf(szReport, _T("Syntax Error\n\nFile: %s\nLine: %d\n\n%s"), g_szCompileFile, g_nLine, szDetail); Trace(_T("\007%s\n"), szReport); - m_bError = true; - g_bParseError = true; + m_bFailed = true; + g_bXapSyntaxError = true; } // CCompiler::CreateFunction // Reconstructed from 5960 retail XBE @ 0x00034670. Ghidra decompile: -// f = new(m_nop) CFunction; f->m_codeSize = m_nop; memcpy(f->m_rgop, m_ops, m_nop); +// f = new(m_opPos) CFunction; f->m_codeSize = m_opPos; memcpy(f->m_bytecode, m_code, m_opPos); // One allocation holds the function header and its ops. CFunction* CCompiler::CreateFunction() { #pragma push_macro("new") #undef new - CFunction* pFn = new(m_nop) CFunction; + CFunction* pFn = new(m_opPos) CFunction; #pragma pop_macro("new") - pFn->m_codeSize = m_nop; - CopyMemory(pFn->m_rgop, m_ops, m_nop); + pFn->m_codeSize = m_opPos; + CopyMemory(pFn->m_bytecode, m_code, m_opPos); return pFn; } @@ -713,8 +713,8 @@ CFunctionCompiler::CFunctionCompiler() { m_nFrameSize = 0; m_breaks = NULL; - m_nBreakables = 0; - m_nopTopOfLoop = 0; + m_breakDepth = 0; + m_loopStartOp = 0; m_bBehavior = false; } @@ -1039,11 +1039,11 @@ const TCHAR* CFunctionCompiler::ParseExpression(const TCHAR* pch) // CFunctionCompiler::ParseIF // Reconstructed from 5960 retail XBE @ 0x00034ea0. Ghidra decompile: // '(' expr ')' or SyntaxError(L"expected '('" / L"expected ')'") and return; -// Write(opCond); fix = m_nop; WriteInteger(0); pch = ParseStatement(pch); +// Write(opCond); fix = m_opPos; WriteInteger(0); pch = ParseStatement(pch); // pch = Token(pch, &tok, &cch); -// if (cch == 4 && !wcsncmp(tok, L"else", 4)) { Write(opJump); fix2 = m_nop; WriteInteger(0); -// patch(fix) = m_nop; pch = ParseStatement(pch); patch(fix2) = m_nop; return pch; } -// patch(fix) = m_nop; return tok; +// if (cch == 4 && !wcsncmp(tok, L"else", 4)) { Write(opJump); fix2 = m_opPos; WriteInteger(0); +// patch(fix) = m_opPos; pch = ParseStatement(pch); patch(fix2) = m_opPos; return pch; } +// patch(fix) = m_opPos; return tok; // With no else the cursor goes back to the start of the peeked token. const TCHAR* CFunctionCompiler::ParseIF(const TCHAR* pch) { @@ -1096,7 +1096,7 @@ const TCHAR* CFunctionCompiler::ParseWHILE(const TCHAR* pch) { BREAK* pOuterBreaks = m_breaks; m_breaks = NULL; - m_nBreakables++; + m_breakDepth++; pch = SkipWhite(pch); if (*pch != '(') @@ -1105,8 +1105,8 @@ const TCHAR* CFunctionCompiler::ParseWHILE(const TCHAR* pch) return szGiveUp; } - int nopOuterTop = m_nopTopOfLoop; - m_nopTopOfLoop = GetAddress(); + int nopOuterTop = m_loopStartOp; + m_loopStartOp = GetAddress(); pch = SkipWhite(ParseExpression(pch + 1)); if (*pch != ')') @@ -1122,14 +1122,14 @@ const TCHAR* CFunctionCompiler::ParseWHILE(const TCHAR* pch) pch = ParseStatement(pch + 1); Write(opJump); - WriteInteger(m_nopTopOfLoop); + WriteInteger(m_loopStartOp); Fixup(nopExit, GetAddress()); FixupBreaks(); m_breaks = pOuterBreaks; - m_nBreakables--; - m_nopTopOfLoop = nopOuterTop; + m_breakDepth--; + m_loopStartOp = nopOuterTop; return pch; } @@ -1143,10 +1143,10 @@ const TCHAR* CFunctionCompiler::ParseDO(const TCHAR* pch) { BREAK* pOuterBreaks = m_breaks; m_breaks = NULL; - m_nBreakables++; + m_breakDepth++; - int nopOuterTop = m_nopTopOfLoop; - m_nopTopOfLoop = GetAddress(); + int nopOuterTop = m_loopStartOp; + m_loopStartOp = GetAddress(); pch = ParseStatement(pch + 1); @@ -1185,14 +1185,14 @@ const TCHAR* CFunctionCompiler::ParseDO(const TCHAR* pch) WriteInteger(0); Write(opJump); - WriteInteger(m_nopTopOfLoop); + WriteInteger(m_loopStartOp); Fixup(nopExit, GetAddress()); FixupBreaks(); m_breaks = pOuterBreaks; - m_nBreakables--; - m_nopTopOfLoop = nopOuterTop; + m_breakDepth--; + m_loopStartOp = nopOuterTop; return pch + 1; } @@ -1207,7 +1207,7 @@ const TCHAR* CFunctionCompiler::ParseFOR(const TCHAR* pch) { BREAK* pOuterBreaks = m_breaks; m_breaks = NULL; - m_nBreakables++; + m_breakDepth++; pch = SkipWhite(pch); if (*pch != '(') @@ -1237,8 +1237,8 @@ const TCHAR* CFunctionCompiler::ParseFOR(const TCHAR* pch) pch++; } - int nopOuterTop = m_nopTopOfLoop; - m_nopTopOfLoop = GetAddress(); + int nopOuterTop = m_loopStartOp; + m_loopStartOp = GetAddress(); pch = SkipWhite(ParseExpression(pch)); if (*pch != ';') @@ -1251,7 +1251,7 @@ const TCHAR* CFunctionCompiler::ParseFOR(const TCHAR* pch) UINT nopStep = GetAddress(); pch = ParseExpression(pchStep); Write(opDrop); - m_nop = nopStep; + m_opPos = nopStep; pch = SkipWhite(pch); if (*pch != ')') @@ -1269,27 +1269,27 @@ const TCHAR* CFunctionCompiler::ParseFOR(const TCHAR* pch) ParseExpression(pchStep); Write(opDrop); Write(opJump); - WriteInteger(m_nopTopOfLoop); + WriteInteger(m_loopStartOp); Fixup(nopExit, GetAddress()); FixupBreaks(); m_breaks = pOuterBreaks; - m_nBreakables--; - m_nopTopOfLoop = nopOuterTop; + m_breakDepth--; + m_loopStartOp = nopOuterTop; return pch; } // CFunctionCompiler::FixupBreaks // Reconstructed from 5960 retail XBE @ 0x00035510. Ghidra decompile: -// for (b = m_breaks; b; b = next) { next = b->next; *(int*)(m_ops + b->nop) = m_nop; delete b; } +// for (b = m_breaks; b; b = next) { next = b->next; *(int*)(m_code + b->nop) = m_opPos; delete b; } void CFunctionCompiler::FixupBreaks() { BREAK* pEntry = m_breaks; while (pEntry != NULL) { BREAK* pNext = pEntry->m_next; - Fixup(pEntry->m_nop, GetAddress()); + Fixup(pEntry->m_opPos, GetAddress()); delete pEntry; pEntry = pNext; } @@ -1298,8 +1298,8 @@ void CFunctionCompiler::FixupBreaks() // CFunctionCompiler::ParseBREAK // Reconstructed from 5960 retail XBE @ 0x00035540. Ghidra decompile: // pch = SkipWhite(pch); if (*pch != ';') { SyntaxError(L"Missing ';'"); return L""; } -// if (!m_nBreakables) { SyntaxError(L"unexpected 'break'"); return L""; } -// Write(opJump); b = new BREAK; b->next = m_breaks; m_breaks = b; b->nop = m_nop; +// if (!m_breakDepth) { SyntaxError(L"unexpected 'break'"); return L""; } +// Write(opJump); b = new BREAK; b->next = m_breaks; m_breaks = b; b->nop = m_opPos; // WriteInteger(0); return pch + 1; const TCHAR* CFunctionCompiler::ParseBREAK(const TCHAR* pch) { @@ -1309,7 +1309,7 @@ const TCHAR* CFunctionCompiler::ParseBREAK(const TCHAR* pch) SyntaxError(_T("Missing ';'")); return szGiveUp; } - if (m_nBreakables == 0) + if (m_breakDepth == 0) { SyntaxError(_T("unexpected 'break'")); return szGiveUp; @@ -1318,7 +1318,7 @@ const TCHAR* CFunctionCompiler::ParseBREAK(const TCHAR* pch) Write(opJump); BREAK* pEntry = new BREAK; - pEntry->m_nop = GetAddress(); + pEntry->m_opPos = GetAddress(); pEntry->m_next = m_breaks; m_breaks = pEntry; @@ -1328,7 +1328,7 @@ const TCHAR* CFunctionCompiler::ParseBREAK(const TCHAR* pch) // CFunctionCompiler::ParseCONTINUE // Reconstructed from 5960 retail XBE @ 0x00035610. Same checks as break -// (L"unexpected 'continue'"), then: Write(opJump); WriteInteger(m_nopTopOfLoop). +// (L"unexpected 'continue'"), then: Write(opJump); WriteInteger(m_loopStartOp). const TCHAR* CFunctionCompiler::ParseCONTINUE(const TCHAR* pch) { pch = SkipWhite(pch); @@ -1337,14 +1337,14 @@ const TCHAR* CFunctionCompiler::ParseCONTINUE(const TCHAR* pch) SyntaxError(_T("Missing ';'")); return szGiveUp; } - if (m_nBreakables == 0) + if (m_breakDepth == 0) { SyntaxError(_T("unexpected 'continue'")); return szGiveUp; } Write(opJump); - WriteInteger(m_nopTopOfLoop); + WriteInteger(m_loopStartOp); return pch + 1; } @@ -1389,7 +1389,7 @@ const TCHAR* CFunctionCompiler::ParseSLEEP(const TCHAR* pch) // CFunctionCompiler::ParseBlock // Reconstructed from 5960 retail XBE @ 0x00035800. Ghidra decompile: // brace = (*pch == '{'); if (brace) pch++; -// base = m_nFrameSize; Write(opFrame); fix = m_nop; WriteInteger(0); +// base = m_nFrameSize; Write(opFrame); fix = m_opPos; WriteInteger(0); // while (*pch && !(brace && *pch == '}')) pch = ParseStatement(pch); // if (brace) { if (*pch != '}') { SyntaxError(L"expected '}'"); return pch; } pch++; } // patch(fix) = m_nFrameSize - base; Write(opEndFrame); WriteInteger(m_nFrameSize - base); @@ -1635,7 +1635,7 @@ const TCHAR* CClassCompiler::ParseNode(const TCHAR* pch) pch = Token(pch, pchName, cchName, true); CMember* pVar = (CMember*)m_targetClass->GetMember(pchName, cchName); - if (pVar == NULL || pVar->m_obj != objMember) + if (pVar == NULL || pVar->m_kind != objMember) { TCHAR szName[256]; CopyNameForMessage(szName, countof(szName), pchName, cchName); @@ -1711,7 +1711,7 @@ const TCHAR* CClassCompiler::ParseNode(const TCHAR* pch) return szGiveUp; } - g_classes->Define(pchName, cchName, (CNode*)pImported); + g_classTable->Define(pchName, cchName, (CNode*)pImported); } else { @@ -2043,7 +2043,7 @@ const TCHAR* CClassCompiler::ParseFunction(const TCHAR* pch, CFunction*& pFn, bo // Reconstructed from 5960 retail XBE @ 0x00036e50. Ghidra decompile: // Token(pch, &name, &cch); pch = SkipWhite(...); if (*pch != '{') { SyntaxError; return L""; } // c = new CClass; pch = c->ParseClassBody(pch + 1); -// if (*pch != '}') { SyntaxError; return L""; } g_classes->Define(name, cch, c); return pch + 1; +// if (*pch != '}') { SyntaxError; return L""; } g_classTable->Define(name, cch, c); return pch + 1; const TCHAR* CClassCompiler::ParseClass(const TCHAR* pch) { const TCHAR* pchName; @@ -2065,21 +2065,21 @@ const TCHAR* CClassCompiler::ParseClass(const TCHAR* pch) return szGiveUp; } - g_classes->Define(pchName, cchName, (CNode*)pNewClass); + g_classTable->Define(pchName, cchName, (CNode*)pNewClass); return pch + 1; } // Class_Init / Class_Exit // Reconstructed from 5960 retail XBE @ 0x00036f00 / 0x00036f30. Ghidra decompile: -// g_classes = new CNameSpace; // one word: the list head, zeroed -// delete g_classes; // walks the list releasing each class +// g_classTable = new CNameSpace; // one word: the list head, zeroed +// delete g_classTable; // walks the list releasing each class void Class_Init() { - g_classes = new CNameSpace; + g_classTable = new CNameSpace; } void Class_Exit() { - delete g_classes; + delete g_classTable; } diff --git a/theseus/engine/xap_compile.h b/theseus/engine/xap_compile.h index f8c414f..abe59ca 100755 --- a/theseus/engine/xap_compile.h +++ b/theseus/engine/xap_compile.h @@ -3,8 +3,8 @@ // CFunctionCompiler a function body. Bodies in xap_compile.cpp, binary // write-up in docs/decomp/Compiler.md. // -// CCompiler layout matches 5960: vtbl, m_nop 0x04, m_ops 0x08, -// m_opsSize 0x0c, m_bError 0x10. +// CCompiler layout matches 5960: vtbl, m_opPos 0x04, m_code 0x08, +// m_opsSize 0x0c, m_bFailed 0x10. #pragma once @@ -60,7 +60,7 @@ struct DOPER struct BREAK { BREAK* m_next; - int m_nop; + int m_opPos; }; // Growable op buffer shared by both compilers. @@ -73,10 +73,10 @@ class CCompiler // 5960 grows when the write would reach the end, then copies (0x34440). inline void Write(const void* data, int size) { - if (m_nop + size >= m_opsSize) - GrowTo(m_nop + size); - memcpy(m_ops + m_nop, data, size); - m_nop += size; + if (m_opPos + size >= m_opsSize) + GrowTo(m_opPos + size); + memcpy(m_code + m_opPos, data, size); + m_opPos += size; } inline void Write(BYTE b) { Write(&b, 1); } @@ -90,27 +90,27 @@ class CCompiler Write(src, len * sizeof (TCHAR)); } - inline UINT GetAddress() { return m_nop; } + inline UINT GetAddress() { return m_opPos; } // Patches a jump or frame size written earlier. 5960 stores straight in. inline void Fixup(UINT at, UINT value) { - if (CHECK(at + sizeof (UINT) <= m_nop)) - memcpy(m_ops + at, &value, sizeof (value)); + if (CHECK(at + sizeof (UINT) <= m_opPos)) + memcpy(m_code + at, &value, sizeof (value)); } void GrowTo(int size); CFunction* CreateFunction(); void SyntaxError(const TCHAR* fmt, ...); - inline void SetError() { m_bError = true; } - inline bool HadError() const { return m_bError; } + inline void SetError() { m_bFailed = true; } + inline bool HadError() const { return m_bFailed; } protected: - UINT m_nop; - BYTE* m_ops; + UINT m_opPos; + BYTE* m_code; UINT m_opsSize; - bool m_bError; + bool m_bFailed; }; // Compiles one function or behavior body. @@ -143,8 +143,8 @@ class CFunctionCompiler : public CCompiler ST m_rgstLocal[100]; int m_nFrameSize; BREAK* m_breaks; - int m_nBreakables; - int m_nopTopOfLoop; + int m_breakDepth; + int m_loopStartOp; bool m_bBehavior; }; diff --git a/theseus/render/node.h b/theseus/render/node.h index b0caaca..0ac3e6e 100755 --- a/theseus/render/node.h +++ b/theseus/render/node.h @@ -5,12 +5,12 @@ // // Layouts below are checked against the 5960 retail XBE's constructors and // factories (sizes are the operator new argument, offsets are the stores): -// CObject 0x14: vtbl, m_nRefCount 0x04, m_obj 0x08, m_parent 0x0c, m_members 0x10 +// CObject 0x14: vtbl, m_nRefCount 0x04, m_kind 0x08, m_parent 0x0c, m_pScope 0x10 // CNode 0x1c: m_behavior 0x14, m_visible 0x18 // CGroup 0x44: m_children 0x1c, m_bboxCenter 0x28, m_bboxSize 0x34, flags 0x40/0x41 -// CInstance 0x54: m_class 0x44, m_vars 0x48 +// CInstance 0x54: m_classDef 0x44, m_vars 0x48 // CTimeDepNode 0x30: m_loop 0x1c, m_startTime 0x20, m_stopTime 0x24, -// m_isActive 0x28, m_lastStartTime 0x2c +// m_isActive 0x28, m_prevStartTime 0x2c // CNodeClass 0x2c: name 0x14, size 0x18, factory 0x1c, base 0x20, props 0x24, next 0x28 // CClass: m_url 0x2c, m_file 0x30, m_nVarCount 0x68 // CProperty: m_node 0x14, m_pprd 0x18 @@ -41,7 +41,7 @@ class CFunction; class CRunner; struct TAGID; -// What kind of value a CObject is (m_obj). Scripts and the VM switch on these. +// What kind of value a CObject is (m_kind). Scripts and the VM switch on these. enum { objUndefined, @@ -304,7 +304,7 @@ public: \ className(); \ ~className(); \ void SetSize(int nSize); \ - int m_nAlloc; \ + int m_reserved; \ int m_nSize; \ elemType* m_value; \ }; @@ -363,13 +363,13 @@ class CNodeArray CNode* GetNode(int iNode) { - return (iNode >= 0 && iNode < m_length) ? m_rgpNode[iNode] : NULL; + return (iNode >= 0 && iNode < m_length) ? m_nodes[iNode] : NULL; } void SetNode(int iNode, CNode* pNode) { if (iNode >= 0 && iNode < m_length) - m_rgpNode[iNode] = pNode; + m_nodes[iNode] = pNode; } void AddNode(CNode* node); @@ -381,13 +381,13 @@ class CNodeArray void Sort(int (__cdecl *compare)(const void*, const void*)) { - qsort(m_rgpNode, m_length, sizeof (CNode*), compare); + qsort(m_nodes, m_length, sizeof (CNode*), compare); } protected: int m_length; - int m_nAlloc; - CNode** m_rgpNode; + int m_reserved; + CNode** m_nodes; }; // Root of everything the VM touches: nodes, numbers, strings, classes. @@ -426,20 +426,20 @@ class CObject CFunction* FindMemberFunction(const TCHAR* name, int nameLen); int m_nRefCount; - int m_obj; + int m_kind; CObject* m_parent; - CNameSpace* m_members; + CNameSpace* m_pScope; }; // Runtime class record. Built-in node classes are static instances that -// link themselves into c_pFirstClass at startup. +// link themselves into c_pClassChain at startup. class CNodeClass : public CObject { public: CNodeClass(const TCHAR* className, int objSize, CObject* (*factory)(), CNodeClass* base, const PRD* props); ~CNodeClass(); - static CNodeClass* c_pFirstClass; + static CNodeClass* c_pClassChain; static CNodeClass* FindByName(const TCHAR* className, int classNameLen); CObject* CreateNode(); @@ -448,7 +448,7 @@ class CNodeClass : public CObject const TCHAR* m_className; int m_nObjectSize; - CObject* (*m_pfnCreateNode)(); + CObject* (*m_pfnNew)(); CNodeClass* m_baseClass; const PRD* m_rgprd; CNodeClass* m_nextClass; @@ -463,7 +463,7 @@ class CFunction : public CObject TCHAR* m_name; int m_codeSize; - BYTE m_rgop[ANYSIZE_ARRAY]; + BYTE m_bytecode[ANYSIZE_ARRAY]; #pragma push_macro("new") #undef new @@ -562,7 +562,7 @@ class CInstance : public CGroup void Render(); BYTE* Construct(); - CClass* m_class; + CClass* m_classDef; CNodeArray m_vars; }; @@ -583,7 +583,7 @@ class CTimeDepNode : public CNode float m_startTime; float m_stopTime; bool m_isActive; - float m_lastStartTime; + float m_prevStartTime; }; // "node.prop" as a script value: reads and writes go through the PRD. diff --git a/theseus/render/node_system.cpp b/theseus/render/node_system.cpp index 21d6a50..73c54ed 100755 --- a/theseus/render/node_system.cpp +++ b/theseus/render/node_system.cpp @@ -16,8 +16,8 @@ #include "activefile.h" #include "xip_archive.h" -extern bool g_bParseError; -extern CRunner* g_pRunner; +extern bool g_bXapSyntaxError; +extern CRunner* g_pActiveRunner; extern CObject* g_pThis; extern CObject* Dereference(CObject* pObject); @@ -40,15 +40,15 @@ CNodeClass CObject::classCObject(_T("Object"), sizeof(class CObject), CObject::C // CObject::CObject / CObject::CreateNode // Reconstructed from 5960 retail XBE @ 0x0002f500 (the factory inlines the // constructor): -// p = new(0x14); p->vtbl = CObject; p->m_obj = 0; p->m_nRefCount = 1; -// p->m_parent = 0; p->m_members = 0; +// p = new(0x14); p->vtbl = CObject; p->m_kind = 0; p->m_nRefCount = 1; +// p->m_parent = 0; p->m_pScope = 0; // A fresh object is untyped, owned once, parentless and has no members. CObject::CObject() { m_nRefCount = 1; - m_obj = objUndefined; + m_kind = objUndefined; m_parent = NULL; - m_members = NULL; + m_pScope = NULL; } CObject* CObject::CreateNode() @@ -59,13 +59,13 @@ CObject* CObject::CreateNode() // CObject::~CObject // Reconstructed from 5960 retail XBE @ 0x0002f450: // CLerper_RemoveObject(this); -// if (m_members) { for each define d: d->m_node->Release(); free(d); free(m_members); } +// if (m_pScope) { for each define d: d->m_node->Release(); free(d); free(m_pScope); } // Drops any running lerps on this object, then frees the member list // (CNameSpace's destructor does the per-entry release and free). CObject::~CObject() { CLerper::RemoveObject(this); - delete m_members; + delete m_pScope; } // CObject::AddRef / CObject::Release @@ -353,7 +353,7 @@ CObject* CObject::Call(int nFunction, CObject** rgparam, int nParam) const SIGSHAPE& shape = c_rgSigShape[pfnd->sig]; if (nParam != (int)strlen(shape.args)) { - g_pRunner->Error(_T("invalid number of parameters")); + g_pActiveRunner->Error(_T("invalid number of parameters")); return NULL; } @@ -460,7 +460,7 @@ CObject* CObject::Call(int nFunction, CObject** rgparam, int nParam) // CMemberFunctionObject bound to this, so the call runs with the right self. CObject* CObject::Dot(CObject* pObj) { - if (pObj->m_obj != objVariable) + if (pObj->m_kind != objVariable) return NULL; const CVarObject* pName = (const CVarObject*)pObj; @@ -480,7 +480,7 @@ CObject* CObject::Dot(CObject* pObj) CObject* pMember = GetMember(pchName, cchName); if (pMember != NULL) { - if (pMember->m_obj == objFunction) + if (pMember->m_kind == objFunction) { AddRef(); return new CMemberFunctionObject(this, (CFunction*)pMember); @@ -499,47 +499,47 @@ CObject* CObject::Dot(CObject* pObj) // CObject::AddMember / SetMember / GetMember // Reconstructed from 5960 retail XBE @ 0x00030310 / 0x00030380 / 0x000303c0: -// if (!m_members) m_members = new CNameSpace; // 4 bytes, head = 0 +// if (!m_pScope) m_pScope = new CNameSpace; // 4 bytes, head = 0 // AddMember: push a new define at the head and point it at the object // SetMember: find-or-add the define, point it at the object -// GetMember: m_members ? lookup by name : 0 +// GetMember: m_pScope ? lookup by name : 0 // AddMember always adds, so a duplicate name shadows the older entry. void CObject::AddMember(const TCHAR* pchName, int cchName, CObject* pObject) { - if (m_members == NULL) - m_members = new CNameSpace; - m_members->Add(pchName, cchName)->m_node = (CNode*)pObject; + if (m_pScope == NULL) + m_pScope = new CNameSpace; + m_pScope->Add(pchName, cchName)->m_node = (CNode*)pObject; } void CObject::SetMember(const TCHAR* pchName, int cchName, CObject* pObject) { - if (m_members == NULL) - m_members = new CNameSpace; - m_members->Get(pchName, cchName)->m_node = (CNode*)pObject; + if (m_pScope == NULL) + m_pScope = new CNameSpace; + m_pScope->Get(pchName, cchName)->m_node = (CNode*)pObject; } CObject* CObject::GetMember(const TCHAR* pchName, int cchName) { - return m_members != NULL ? m_members->Lookup(pchName, cchName) : NULL; + return m_pScope != NULL ? m_pScope->Lookup(pchName, cchName) : NULL; } // CObject::FindMemberFunction // Reconstructed from 5960 retail XBE @ 0x000303e0: // f = this->GetMember(name); -// if (f && f->m_obj == 13) return f; +// if (f && f->m_kind == 13) return f; // for (c = this->GetNodeClass(); c; c = c->m_baseClass) -// if ((f = c->GetMember(name)) != 0) return f->m_obj == 13 ? f : 0; +// if ((f = c->GetMember(name)) != 0) return f->m_kind == 13 ? f : 0; // return 0; // The object's own members win, then the first class up the chain that // knows the name decides. FindMember is that class walk. CFunction* CObject::FindMemberFunction(const TCHAR* pchName, int cchName) { CObject* pFound = GetMember(pchName, cchName); - if (pFound != NULL && pFound->m_obj == objFunction) + if (pFound != NULL && pFound->m_kind == objFunction) return (CFunction*)pFound; pFound = FindMember(GetNodeClass(), pchName, cchName); - if (pFound != NULL && pFound->m_obj == objFunction) + if (pFound != NULL && pFound->m_kind == objFunction) return (CFunction*)pFound; return NULL; @@ -557,35 +557,35 @@ void CObject::Dump() const // ========================================================================= // Head of the class list; 0x0017e730 in the binary. -CNodeClass* CNodeClass::c_pFirstClass = NULL; +CNodeClass* CNodeClass::c_pClassChain = NULL; // CNodeClass::CNodeClass // Reconstructed from 5960 retail XBE @ 0x0002e900: // CObject fields reset; m_className = name; m_nObjectSize = size; -// m_pfnCreateNode = create; m_baseClass = base; m_rgprd = prd; -// m_nextClass = c_pFirstClass; c_pFirstClass = this; +// m_pfnNew = create; m_baseClass = base; m_rgprd = prd; +// m_nextClass = c_pClassChain; c_pClassChain = this; // Every class record pushes itself on the front of one global list. CNodeClass::CNodeClass(const TCHAR* szClassName, int nObjectSize, CObject* (*pfnCreateNode)(), CNodeClass* pBaseClass, const PRD* rgprd) { m_className = szClassName; m_nObjectSize = nObjectSize; - m_pfnCreateNode = pfnCreateNode; + m_pfnNew = pfnCreateNode; m_baseClass = pBaseClass; m_rgprd = rgprd; - m_nextClass = c_pFirstClass; - c_pFirstClass = this; + m_nextClass = c_pClassChain; + c_pClassChain = this; } // CNodeClass::~CNodeClass // Reconstructed from 5960 retail XBE @ 0x0002e970: -// for (pp = &c_pFirstClass; *pp && *pp != this; pp = &(*pp)->m_nextClass) ; +// for (pp = &c_pClassChain; *pp && *pp != this; pp = &(*pp)->m_nextClass) ; // if (*pp == this) *pp = m_nextClass; // then the inlined CObject destructor CNodeClass::~CNodeClass() { - CNodeClass** ppLink = &c_pFirstClass; + CNodeClass** ppLink = &c_pClassChain; while (*ppLink != NULL && *ppLink != this) ppLink = &(*ppLink)->m_nextClass; @@ -594,22 +594,22 @@ CNodeClass::~CNodeClass() } // CNodeClass::CreateNode Inlined into CreateNewObject @ 0x00037580: -// return m_pfnCreateNode(); +// return m_pfnNew(); CObject* CNodeClass::CreateNode() { - return m_pfnCreateNode(); + return m_pfnNew(); } // CNodeClass::FindByName // Reconstructed from 5960 retail XBE @ 0x0002ea20: -// for (c = c_pFirstClass; c; c = c->m_nextClass) +// for (c = c_pClassChain; c; c = c->m_nextClass) // if (!wcsncmp(c->m_className, name, cch) && c->m_className[cch] == 0) // return c; // return 0; // Case-sensitive, full-length match against the registered names. CNodeClass* CNodeClass::FindByName(const TCHAR* pchNodeClass, int cchNodeClass) { - for (CNodeClass* pClass = c_pFirstClass; pClass != NULL; pClass = pClass->m_nextClass) + for (CNodeClass* pClass = c_pClassChain; pClass != NULL; pClass = pClass->m_nextClass) { const TCHAR* szName = pClass->m_className; if (_tcsncmp(szName, pchNodeClass, cchNodeClass) == 0 && szName[cchNodeClass] == 0) @@ -652,11 +652,11 @@ CNodeClass CNode::classCNode(_T("Node"), sizeof(class CNode), CNode::CreateNode, // CNode::CNode / CNode::CreateNode // Reconstructed from 5960 retail XBE @ 0x0002ebf0 (factory, ctor inlined): -// p = new(0x1c); CObject fields; p->m_obj = 5; p->m_behavior = 0; p->m_visible = 1; +// p = new(0x1c); CObject fields; p->m_kind = 5; p->m_behavior = 0; p->m_visible = 1; // A node starts visible with no behavior script. CNode::CNode() { - m_obj = objNode; + m_kind = objNode; m_behavior = NULL; m_visible = true; } @@ -699,7 +699,7 @@ void CNode::OnLoad() // Reconstructed from 5960 retail XBE @ 0x0002ee60: // r = m_behavior; if (!r) return; // if (r->m_wakeup != 0) { if (now < r->m_wakeup) return; r->m_wakeup = 0; } -// g_pRunner = r; g_pThis = this; +// g_pActiveRunner = r; g_pThis = this; // for (;;) { // do { if (!r->Step()) r->ResetFunc(); } while (r->m_wakeup == 0); // if (now < r->m_wakeup) break; @@ -712,7 +712,7 @@ void CNode::Advance(float nSeconds) if (m_behavior == NULL || m_behavior->IsSleeping()) return; - g_pRunner = m_behavior; + g_pActiveRunner = m_behavior; g_pThis = this; do @@ -778,8 +778,8 @@ void CNode::Dump() const CNodeArray::CNodeArray() { m_length = 0; - m_nAlloc = 0; - m_rgpNode = NULL; + m_reserved = 0; + m_nodes = NULL; } CNodeArray::~CNodeArray() @@ -789,15 +789,15 @@ CNodeArray::~CNodeArray() // CNodeArray::AddNode // Inlined at its callers (e.g. CInstance::Construct @ 0x00033f00): -// if (m_nAlloc < m_length + 1) Allocate(m_nAlloc + 16); -// m_rgpNode[m_length++] = node; +// if (m_reserved < m_length + 1) Allocate(m_reserved + 16); +// m_nodes[m_length++] = node; // Grows sixteen slots at a time. Takes over the caller's reference. void CNodeArray::AddNode(CNode* pNode) { - if (m_length + 1 > m_nAlloc) - Allocate(m_nAlloc + 16); + if (m_length + 1 > m_reserved) + Allocate(m_reserved + 16); - m_rgpNode[m_length] = pNode; + m_nodes[m_length] = pNode; m_length++; } @@ -811,27 +811,27 @@ void CNodeArray::RemoveNode(CNode* pNode) int i = 0; while (i < m_length) { - if (m_rgpNode[i] != pNode) + if (m_nodes[i] != pNode) { i++; continue; } for (int j = i; j < m_length - 1; j++) - m_rgpNode[j] = m_rgpNode[j + 1]; + m_nodes[j] = m_nodes[j + 1]; m_length--; } } // CNodeArray::ReleaseAll / RemoveAll // Reconstructed from 5960 retail XBE @ 0x0002efa0 (RemoveAll inlined): -// for (i = 0; i < m_length; i++) if (m_rgpNode[i]) m_rgpNode[i]->Release(); -// m_length = 0; m_nAlloc = 0; free(m_rgpNode); m_rgpNode = 0; +// for (i = 0; i < m_length; i++) if (m_nodes[i]) m_nodes[i]->Release(); +// m_length = 0; m_reserved = 0; free(m_nodes); m_nodes = 0; void CNodeArray::ReleaseAll() { for (int i = 0; i < m_length; i++) { - CNode* pNode = m_rgpNode[i]; + CNode* pNode = m_nodes[i]; if (pNode != NULL) pNode->Release(); } @@ -840,32 +840,32 @@ void CNodeArray::ReleaseAll() void CNodeArray::RemoveAll() { - delete[] m_rgpNode; - m_rgpNode = NULL; + delete[] m_nodes; + m_nodes = NULL; m_length = 0; - m_nAlloc = 0; + m_reserved = 0; } // CNodeArray::Allocate // Reconstructed from 5960 retail XBE @ 0x0002eff0: -// if (m_nAlloc < n) { p = new CNode*[n]; copy the old m_nAlloc slots; -// free the old block; m_rgpNode = p; m_nAlloc = n; } +// if (m_reserved < n) { p = new CNode*[n]; copy the old m_reserved slots; +// free the old block; m_nodes = p; m_reserved = n; } // Never shrinks; new slots past the old capacity are left uninitialized. void CNodeArray::Allocate(int nLength) { - if (nLength <= m_nAlloc) + if (nLength <= m_reserved) return; CNode** rgpGrown = new CNode*[nLength]; - if (m_rgpNode != NULL) + if (m_nodes != NULL) { - for (int i = 0; i < m_nAlloc; i++) - rgpGrown[i] = m_rgpNode[i]; - delete[] m_rgpNode; + for (int i = 0; i < m_reserved; i++) + rgpGrown[i] = m_nodes[i]; + delete[] m_nodes; } - m_rgpNode = rgpGrown; - m_nAlloc = nLength; + m_nodes = rgpGrown; + m_reserved = nLength; } // CNodeArray::SetLength @@ -875,7 +875,7 @@ void CNodeArray::SetLength(int nLength) { Allocate(nLength); for (int i = m_length; i < nLength; i++) - m_rgpNode[i] = NULL; + m_nodes[i] = NULL; m_length = nLength; } @@ -896,14 +896,14 @@ END_NODE_PROPS() // CTimeDepNode::CTimeDepNode // Reconstructed from 5960 retail XBE @ 0x0002f050 (factory, ctor inlined): // CNode fields; m_loop = 0; m_startTime = 0; m_stopTime = 0; -// m_isActive = 0; m_lastStartTime = 0; +// m_isActive = 0; m_prevStartTime = 0; CTimeDepNode::CTimeDepNode() { m_loop = false; m_startTime = 0.0f; m_stopTime = 0.0f; m_isActive = false; - m_lastStartTime = 0.0f; + m_prevStartTime = 0.0f; } // CTimeDepNode::Advance @@ -925,11 +925,11 @@ void CTimeDepNode::Advance(float nSeconds) if (!m_isActive) { - bool fNewStart = now >= m_startTime && m_startTime != m_lastStartTime; + bool fNewStart = now >= m_startTime && m_startTime != m_prevStartTime; bool fBeforeStop = m_stopTime == 0.0f || now < m_stopTime; if (fNewStart && fBeforeStop) { - m_lastStartTime = m_startTime; + m_prevStartTime = m_startTime; m_isActive = true; OnIsActiveChanged(); } @@ -962,7 +962,7 @@ void CTimeDepNode::OnCycleEnded() // own fields and marks itself objClass (6). CClass::CClass() : CNodeClass(_T("[class]"), 0, NULL, NULL, NULL) { - m_obj = objClass; + m_kind = objClass; m_url = NULL; m_constructor = NULL; m_nVarCount = 0; @@ -1033,7 +1033,7 @@ bool CClass::LoadAbsURL(const TCHAR* szURL) // StartParse(file, name); // file name, line 1, no error // end = ParseClassBody(text); // if (*end) SyntaxError(L"Stuff past expected end of file!"); -// EndParse(); return !g_bParseError; +// EndParse(); return !g_bXapSyntaxError; bool CClass::ParseFile(const TCHAR* szFileName, const TCHAR* szFile) { StartParse(szFile, szFileName); @@ -1043,7 +1043,7 @@ bool CClass::ParseFile(const TCHAR* szFileName, const TCHAR* szFile) SyntaxError(_T("Stuff past expected end of file!")); EndParse(); - return !g_bParseError; + return !g_bXapSyntaxError; } // CClass::ParseClassBody @@ -1069,8 +1069,8 @@ const TCHAR* CClass::ParseClassBody(const TCHAR* pch) // class constructor, then gets OnLoad like any other node. CInstance::CInstance(CClass* pClass) { - m_obj = objInstance; - m_class = pClass; + m_kind = objInstance; + m_classDef = pClass; pClass->AddRef(); m_vars.SetLength(pClass->GetVariableCount()); @@ -1084,13 +1084,13 @@ CInstance::CInstance(CClass* pClass) // m_vars.ReleaseAll() and the CGroup destructor (member and base dtors). CInstance::~CInstance() { - m_class->Release(); + m_classDef->Release(); } // CInstance::GetNodeClass: an instance reports its script class. CNodeClass* CInstance::GetNodeClass() const { - return m_class; + return m_classDef; } // CInstance::Render: draws as the group it is. @@ -1106,15 +1106,15 @@ void CInstance::Render() // else goes to the ordinary node lookup. CObject* CInstance::Dot(CObject* pObj) { - if (pObj->m_obj == objVariable && m_class->m_members != NULL) + if (pObj->m_kind == objVariable && m_classDef->m_pScope != NULL) { const CVarObject* pName = (const CVarObject*)pObj; - CObject* pEntry = m_class->m_members->Lookup(pName->m_text, pName->m_length); + CObject* pEntry = m_classDef->m_pScope->Lookup(pName->m_text, pName->m_length); if (pEntry != NULL) { - if (pEntry->m_obj == objMember) + if (pEntry->m_kind == objMember) return new CMemberVarObject(this, ((CMember*)pEntry)->m_memberIndex); - if (pEntry->m_obj == objFunction) + if (pEntry->m_kind == objFunction) return new CMemberFunctionObject(this, (CFunction*)pEntry); } } @@ -1174,7 +1174,7 @@ struct CTORREADER BYTE* CInstance::Construct() { CTORREADER code; - code.pb = m_class->m_constructor->m_rgop; + code.pb = m_classDef->m_constructor->m_bytecode; if (code.pb == NULL) return NULL; @@ -1308,7 +1308,7 @@ BYTE* CInstance::Construct() { int cch = code.Int(); const TCHAR* pchName = code.Name(cch); - CObject* pFunction = m_class->m_instanceFunctions.GetNode(code.Int()); + CObject* pFunction = m_classDef->m_instanceFunctions.GetNode(code.Int()); pFunction->AddRef(); pCurrent->SetMember(pchName, cch, pFunction); } diff --git a/theseus/render/scene_groups.cpp b/theseus/render/scene_groups.cpp index 358eb5f..0cec8b1 100755 --- a/theseus/render/scene_groups.cpp +++ b/theseus/render/scene_groups.cpp @@ -559,7 +559,7 @@ class CInline : public CGroup CXipFile* m_xipFile; XTIME m_timeOfLoad; - CClass m_class; + CClass m_classDef; DECLARE_NODE_PROPS() @@ -645,7 +645,7 @@ void CInline::Init() // CInline::FinishLoad() // Reconstructed from 5960 retail XBE @ 0x0004e560. Ghidra decompile: -// if (m_class.LoadAbsURL(absURL)) { n = m_class.CreateNode(); +// if (m_classDef.LoadAbsURL(absURL)) { n = m_classDef.CreateNode(); // CallFunction(n, "initialize"); children.AddNode(n); n->parent = this; // CallFunction(this, "onLoad"); } // firstLoad = 0; classLoaded = 1; @@ -654,9 +654,9 @@ void CInline::FinishLoad() { long long started = Frame_Now(); - if (m_class.LoadAbsURL(m_szAbsURL)) + if (m_classDef.LoadAbsURL(m_szAbsURL)) { - CNode* root = m_class.CreateNode(); + CNode* root = m_classDef.CreateNode(); CallFunction(root, _T("initialize")); m_children.AddNode(root); root->m_parent = this; @@ -2054,9 +2054,9 @@ static void CollectInlinesRecursive(CNode* pNode, CInstance* pRoot, InlineInfo* out[*count].url = inl->m_url; out[*count].defName = NULL; - if (pRoot && pRoot->m_class && pRoot->m_class->m_members) { - for (CDefine* d = pRoot->m_class->m_members->m_firstDefine; d; d = d->m_next) { - if (d->m_node && d->m_node->m_obj == objMember) { + if (pRoot && pRoot->m_classDef && pRoot->m_classDef->m_pScope) { + for (CDefine* d = pRoot->m_classDef->m_pScope->m_firstDefine; d; d = d->m_next) { + if (d->m_node && d->m_node->m_kind == objMember) { CMember* mem = (CMember*)d->m_node; int idx = mem->m_memberIndex; if (idx >= 0 && idx < pRoot->m_vars.GetLength()) { @@ -2100,30 +2100,30 @@ bool CInline::ReloadFromText(const char* xapText) { m_children.ReleaseAll(); - m_class.~CClass(); - new (&m_class) CClass; + m_classDef.~CClass(); + new (&m_classDef) CClass; char absURL[MAX_PATH]; MakeAbsoluteURL(absURL, m_url); int cch = (int)strlen(absURL) + 1; - m_class.m_url = new char[cch]; - memcpy(m_class.m_url, absURL, cch * sizeof(char)); + m_classDef.m_url = new char[cch]; + memcpy(m_classDef.m_url, absURL, cch * sizeof(char)); - extern bool g_bParseError; - g_bParseError = false; + extern bool g_bXapSyntaxError; + g_bXapSyntaxError = false; size_t len = strlen(xapText); char* parseBuf = (char*)malloc(len + 1); memcpy(parseBuf, xapText, len + 1); - bool ok = m_class.ParseFile(absURL, (const char*)parseBuf); + bool ok = m_classDef.ParseFile(absURL, (const char*)parseBuf); free(parseBuf); - if (!ok || g_bParseError) + if (!ok || g_bXapSyntaxError) return false; - CNode* pNode = m_class.CreateNode(); + CNode* pNode = m_classDef.CreateNode(); if (!pNode) return false; diff --git a/theseus/shared/date_node.cpp b/theseus/shared/date_node.cpp index 032d2e2..4946d78 100755 --- a/theseus/shared/date_node.cpp +++ b/theseus/shared/date_node.cpp @@ -13,9 +13,9 @@ #include "../xbox/xbox_private_types.h" #endif -extern CObject** g_rgParam; +extern CObject** g_scriptArgs; extern int g_nParam; -extern CRunner* g_pRunner; +extern CRunner* g_pActiveRunner; extern CObject* Dereference(CObject* pObject); IMPLEMENT_NODE("Date", CDateObject, CObject) @@ -103,7 +103,7 @@ int CDateObject::getDaysInMonth(int nMonth, int nYear) static WORD ParamWord(int index) { - CNumObject* num = g_rgParam[index]->ToNum(); + CNumObject* num = g_scriptArgs[index]->ToNum(); WORD value = (WORD)(int)num->m_value; num->Release(); return value; @@ -129,12 +129,12 @@ CDateObject::CDateObject() } if (g_nParam < 3 || g_nParam > 7) { - g_pRunner->Error(_T("Wrong number of parameters to Date constructor\n")); + g_pActiveRunner->Error(_T("Wrong number of parameters to Date constructor\n")); return; } for (int i = 0; i < g_nParam; i++) - g_rgParam[i] = Dereference(g_rgParam[i]); + g_scriptArgs[i] = Dereference(g_scriptArgs[i]); memset(&parts, 0, sizeof(parts)); parts.wYear = ParamWord(0); diff --git a/theseus/shared/string_util.cpp b/theseus/shared/string_util.cpp index 090a43b..2b66608 100755 --- a/theseus/shared/string_util.cpp +++ b/theseus/shared/string_util.cpp @@ -31,7 +31,7 @@ END_NODE_FUN() // Reconstructed from 5960 retail XBE @ 0x00032040: type 3, no buffer. CStrObject::CStrObject() { - m_obj = objString; + m_kind = objString; m_text = NULL; m_length = 0; m_capacity = 0; @@ -43,7 +43,7 @@ CStrObject::CStrObject() // copy cch characters; text[cch] = 0; CStrObject::CStrObject(const TCHAR* pch, int cch) { - m_obj = objString; + m_kind = objString; m_length = cch; m_capacity = cch + 1; m_text = new TCHAR[m_capacity]; @@ -58,7 +58,7 @@ CStrObject::CStrObject(const TCHAR* sz) { if (sz == NULL) sz = _T(""); - m_obj = objString; + m_kind = objString; m_length = (int)_tcslen(sz); m_capacity = m_length + 1; m_text = new TCHAR[m_capacity]; @@ -189,7 +189,7 @@ CObject* CStrObject::indexOf(CObject** rgparam, int nParam) { if (nParam != 1 && nParam != 2) { - g_pRunner->Error(_T("invalid number of parameters")); + g_pActiveRunner->Error(_T("invalid number of parameters")); return NULL; } @@ -231,7 +231,7 @@ CObject* CStrObject::lastIndexOf(CObject** rgparam, int nParam) { if (nParam != 1 && nParam != 2) { - g_pRunner->Error(_T("invalid number of parameters")); + g_pActiveRunner->Error(_T("invalid number of parameters")); return NULL; } @@ -250,7 +250,7 @@ CObject* CStrObject::substr(CObject** rgparam, int nParam) { if (nParam != 1 && nParam != 2) { - g_pRunner->Error(_T("invalid number of parameters")); + g_pActiveRunner->Error(_T("invalid number of parameters")); return NULL; } @@ -273,7 +273,7 @@ CObject* CStrObject::substring(CObject** rgparam, int nParam) { if (nParam != 2) { - g_pRunner->Error(_T("invalid number of parameters")); + g_pActiveRunner->Error(_T("invalid number of parameters")); return NULL; } diff --git a/theseus/shared/util.cpp b/theseus/shared/util.cpp index 043741b..ed2969c 100644 --- a/theseus/shared/util.cpp +++ b/theseus/shared/util.cpp @@ -202,22 +202,22 @@ static void GrowArray(int& alloc, int& size, T*& values, int newSize) size = newSize; } -CIntArray::CIntArray() { m_nAlloc = 0; m_nSize = 0; m_value = NULL; } +CIntArray::CIntArray() { m_reserved = 0; m_nSize = 0; m_value = NULL; } CIntArray::~CIntArray() { delete[] m_value; } -void CIntArray::SetSize(int n) { GrowArray(m_nAlloc, m_nSize, m_value, n); } +void CIntArray::SetSize(int n) { GrowArray(m_reserved, m_nSize, m_value, n); } -CNumArray::CNumArray() { m_nAlloc = 0; m_nSize = 0; m_value = NULL; } +CNumArray::CNumArray() { m_reserved = 0; m_nSize = 0; m_value = NULL; } CNumArray::~CNumArray() { delete[] m_value; } -void CNumArray::SetSize(int n) { GrowArray(m_nAlloc, m_nSize, m_value, n); } +void CNumArray::SetSize(int n) { GrowArray(m_reserved, m_nSize, m_value, n); } -CVec2Array::CVec2Array() { m_nAlloc = 0; m_nSize = 0; m_value = NULL; } +CVec2Array::CVec2Array() { m_reserved = 0; m_nSize = 0; m_value = NULL; } CVec2Array::~CVec2Array() { delete[] m_value; } -void CVec2Array::SetSize(int n) { GrowArray(m_nAlloc, m_nSize, m_value, n); } +void CVec2Array::SetSize(int n) { GrowArray(m_reserved, m_nSize, m_value, n); } -CVec3Array::CVec3Array() { m_nAlloc = 0; m_nSize = 0; m_value = NULL; } +CVec3Array::CVec3Array() { m_reserved = 0; m_nSize = 0; m_value = NULL; } CVec3Array::~CVec3Array() { delete[] m_value; } -void CVec3Array::SetSize(int n) { GrowArray(m_nAlloc, m_nSize, m_value, n); } +void CVec3Array::SetSize(int n) { GrowArray(m_reserved, m_nSize, m_value, n); } -CVec4Array::CVec4Array() { m_nAlloc = 0; m_nSize = 0; m_value = NULL; } +CVec4Array::CVec4Array() { m_reserved = 0; m_nSize = 0; m_value = NULL; } CVec4Array::~CVec4Array() { delete[] m_value; } -void CVec4Array::SetSize(int n) { GrowArray(m_nAlloc, m_nSize, m_value, n); } +void CVec4Array::SetSize(int n) { GrowArray(m_reserved, m_nSize, m_value, n); } diff --git a/theseus/shared/xap_vm.cpp b/theseus/shared/xap_vm.cpp index c755761..82c05b2 100644 --- a/theseus/shared/xap_vm.cpp +++ b/theseus/shared/xap_vm.cpp @@ -13,8 +13,8 @@ // Shared runner state. 5960 keeps the same four at 0x17ae9c..0x17aea8. CObject* g_pThis; -CRunner* g_pRunner; -CObject** g_rgParam; +CRunner* g_pActiveRunner; +CObject** g_scriptArgs; int g_nParam; extern bool g_bInputEnable; @@ -30,24 +30,24 @@ CObject* LookupMember(CObject* pThis, const TCHAR* pchName, int cchName); // CNumObject constructors [type 2, vtable 0x22c50] // Reconstructed from 5960 retail XBE @ 0x00038fa0 (float form; the empty form // only shows up inlined). Decompile: -// m_nRefCount = 1; m_obj = 2; m_value = xmm0; +// m_nRefCount = 1; m_kind = 2; m_value = xmm0; // The string form has no standalone copy in the binary; CStrObject::ToNum // @ 0x32200 does the same (float)wcstod(sz, NULL) inline. Kept for runner.h. CNumObject::CNumObject() { - m_obj = objNumber; + m_kind = objNumber; m_value = 0.0f; } CNumObject::CNumObject(float nValue) { - m_obj = objNumber; + m_kind = objNumber; m_value = nValue; } CNumObject::CNumObject(const TCHAR* szValue) { - m_obj = objNumber; + m_kind = objNumber; m_value = (float)_tcstod(szValue, NULL); } @@ -97,10 +97,10 @@ END_NODE_PROPS() // CVec3Object constructors [type 16, vtable 0x22c88] // Reconstructed from 5960 retail XBE @ 0x00039070 (empty, via the factory) // and @ 0x000390c0 (copy). Decompile: -// m_obj = 0x10; m_x = v[0]; m_y = v[1]; m_z = v[2]; (or all 0) +// m_kind = 0x10; m_x = v[0]; m_y = v[1]; m_z = v[2]; (or all 0) CVec3Object::CVec3Object() { - m_obj = objVec3; + m_kind = objVec3; m_x = 0.0f; m_y = 0.0f; m_z = 0.0f; @@ -108,7 +108,7 @@ CVec3Object::CVec3Object() CVec3Object::CVec3Object(const D3DXVECTOR3& v) { - m_obj = objVec3; + m_kind = objVec3; m_x = v.x; m_y = v.y; m_z = v.z; @@ -138,7 +138,7 @@ class CLocalVariable : public CObject ~CLocalVariable(); CObject* Deref(); void Assign(CObject* pValue); - CObject* m_pValue; + CObject* m_pHeld; }; // CLocalVariable [vtable 0x22e48] @@ -151,27 +151,27 @@ class CLocalVariable : public CObject // Deref trades the reference to the slot for one to its value. CLocalVariable::CLocalVariable() { - m_pValue = NULL; + m_pHeld = NULL; } CLocalVariable::~CLocalVariable() { - if (m_pValue != NULL) - m_pValue->Release(); + if (m_pHeld != NULL) + m_pHeld->Release(); } void CLocalVariable::Assign(CObject* pValue) { - if (m_pValue != NULL) - m_pValue->Release(); - m_pValue = pValue; + if (m_pHeld != NULL) + m_pHeld->Release(); + m_pHeld = pValue; if (pValue != NULL) pValue->AddRef(); } CObject* CLocalVariable::Deref() { - CObject* pValue = m_pValue; + CObject* pValue = m_pHeld; if (pValue != NULL) pValue->AddRef(); Release(); @@ -185,7 +185,7 @@ CObject* CLocalVariable::Deref() // dtor: free(m_text); CVarObject::CVarObject(const TCHAR* pch, int cch) { - m_obj = objVariable; + m_kind = objVariable; m_length = cch; m_capacity = cch + 1; m_text = new TCHAR[cch + 1]; @@ -218,10 +218,10 @@ CObject* CVarObject::Deref() pFound = &theCamera; else { - pFound = g_pRunner->LookupVariable(m_text, _tcslen(m_text)); + pFound = g_pActiveRunner->LookupVariable(m_text, _tcslen(m_text)); if (pFound == NULL) { - g_pRunner->Error(_T("Unknown object: %s"), m_text); + g_pActiveRunner->Error(_T("Unknown object: %s"), m_text); return NULL; } } @@ -239,11 +239,11 @@ CObject* CVarObject::Deref() // obj->Assign(value); void CVarObject::Assign(CObject* pValue) { - CObject* pTarget = g_pRunner->LookupVariable(m_text, _tcslen(m_text)); + CObject* pTarget = g_pActiveRunner->LookupVariable(m_text, _tcslen(m_text)); if (pTarget != NULL) pTarget->Assign(pValue); else - g_pRunner->Error(_T("Unknown variable: %s"), m_text); + g_pActiveRunner->Error(_T("Unknown variable: %s"), m_text); } // ========================================================================= @@ -262,7 +262,7 @@ void CVarObject::Assign(CObject* pValue) // The range checks are what CNodeArray::GetNode/SetNode already do. CMemberVarObject::CMemberVarObject(CInstance* pInstance, int iMember) { - m_obj = objMemberVar; + m_kind = objMemberVar; m_owner = pInstance; m_memberIndex = iMember; pInstance->AddRef(); @@ -297,13 +297,13 @@ void CMemberVarObject::Assign(CObject* pValue) // Reconstructed from 5960 retail XBE @ 0x000397b0 (ctor) and @ 0x00039810 // (Deref). Decompile: // ctor: m_owner = owner; m_function = fn; (no AddRef) -// Deref: CRunner r(m_owner); r.ResetFunc(); r.m_ops = m_function->m_rgop; +// Deref: CRunner r(m_owner); r.ResetFunc(); r.m_code = m_function->m_bytecode; // ret = r.Run(); this->Release(); return ret; // Reading a method without calling it runs it on a fresh runner. The owner // is a plain CObject in Theseus so non-instance nodes can hand these out. CMemberFunctionObject::CMemberFunctionObject(CObject* pOwner, CFunction* pFunction) { - m_obj = objMemberFunction; + m_kind = objMemberFunction; m_owner = pOwner; m_function = pFunction; } @@ -324,12 +324,12 @@ CObject* CMemberFunctionObject::Deref() // CFunctionObject [type 8, vtable 0x22cc0] // Reconstructed from 5960 retail XBE @ 0x00039920 (ctor), 0x39960 (dtor), // 0x399c0 (Call). Decompile: -// ctor: m_obj = 8; m_owner = NULL; +// ctor: m_kind = 8; m_owner = NULL; // dtor: if (m_owner) m_owner->Release(); // Call: return m_owner->Call(m_functionIndex, rgparam, nParam); CFunctionObject::CFunctionObject() { - m_obj = objFunctionRef; + m_kind = objFunctionRef; m_owner = NULL; } @@ -346,12 +346,12 @@ CObject* CFunctionObject::Call(CObject** rgArgs, int nArgs) // CFunction [type 13, vtable 0x22c18] // Reconstructed from 5960 retail XBE: the constructor is inlined in -// CCompiler::CreateFunction @ 0x34670 (m_obj = 0xd, m_codeSize = 0) and the +// CCompiler::CreateFunction @ 0x34670 (m_kind = 0xd, m_codeSize = 0) and the // destructor @ 0x39b00 does nothing of its own. m_name is Theseus's debug // name for the function, so Theseus frees it here. CFunction::CFunction() { - m_obj = objFunction; + m_kind = objFunction; m_codeSize = 0; m_name = NULL; } @@ -363,7 +363,7 @@ CFunction::~CFunction() // CMember [type 9, vtable 0x22dd8] // Reconstructed from 5960 retail XBE: ctor inlined in -// CClassCompiler::ParseMemberVar @ 0x36ad0 (m_obj = 9, m_memberIndex = -1), +// CClassCompiler::ParseMemberVar @ 0x36ad0 (m_kind = 9, m_memberIndex = -1), // dtor @ 0x39b30, Deref @ 0x39b40, Assign @ 0x39b90. Decompile: // Deref: v = g_pThis->m_vars[i]; if (v) v->AddRef(); Release(); return v; // Assign: old = g_pThis->m_vars[i]; if (old) old->Release(); @@ -372,14 +372,14 @@ CFunction::~CFunction() // now (LookupMember sets it). 5960 just casts g_pThis; Theseus checks first. static CInstance* MemberOwner() { - if (!CHECK(g_pThis != NULL && g_pThis->m_obj == objInstance)) + if (!CHECK(g_pThis != NULL && g_pThis->m_kind == objInstance)) return NULL; return (CInstance*)g_pThis; } CMember::CMember() { - m_obj = objMember; + m_kind = objMember; m_memberIndex = -1; } @@ -417,7 +417,7 @@ void CMember::Assign(CObject* pValue) // Error(L"Cannot assign to objects"); void CObject::Assign(CObject* pValue) { - g_pRunner->Error(_T("Cannot assign to objects")); + g_pActiveRunner->Error(_T("Cannot assign to objects")); } // ========================================================================= @@ -426,10 +426,10 @@ void CObject::Assign(CObject* pValue) // CNodeArrayObject constructor [type 7, vtable 0x22d30] // Reconstructed from 5960 retail XBE: inlined in CProperty::Deref @ 0x38b00. -// m_obj = 7; m_nodeArray = (CNodeArray*)(node + prop offset); +// m_kind = 7; m_nodeArray = (CNodeArray*)(node + prop offset); CNodeArrayObject::CNodeArrayObject(CNodeArray* pArray) { - m_obj = objNodeArray; + m_kind = objNodeArray; m_nodeArray = pArray; } @@ -469,22 +469,22 @@ CObject* CNodeArrayObject::Call(int nFunction, CObject** rgArgs, int nArgs) // CNodeArrayObject::Dot // Reconstructed from 5960 retail XBE @ 0x00039260. Decompile: -// if (key->m_obj != objVariable) { +// if (key->m_kind != objVariable) { // i = (int)key->m_value; // if (i < 0 || i >= m_nodeArray->m_length) // { Error(L"Array reference out of bounds"); return 0; } -// n = m_nodeArray->m_rgpNode[i]; n->AddRef(); return n; } +// n = m_nodeArray->m_nodes[i]; n->AddRef(); return n; } // "length"(6) / "add"(3) / "remove"(6) -> new CFunctionObject // { m_functionIndex = 0 / 1 / 2, m_owner = this }; this->AddRef(); // else return CObject::Dot(key); CObject* CNodeArrayObject::Dot(CObject* pKey) { - if (pKey->m_obj != objVariable) + if (pKey->m_kind != objVariable) { int iItem = (int)((CNumObject*)pKey)->m_value; if (iItem < 0 || iItem >= m_nodeArray->GetLength()) { - g_pRunner->Error(_T("Array reference out of bounds")); + g_pActiveRunner->Error(_T("Array reference out of bounds")); return NULL; } @@ -585,7 +585,7 @@ CObject* CProperty::Deref() break; default: - g_pRunner->Error(_T("Unknown property type")); + g_pActiveRunner->Error(_T("Unknown property type")); return NULL; } @@ -599,7 +599,7 @@ CObject* CProperty::Deref() // integer: n = value->Deref()->ToNum(); SetProperty(prd, &(int)n->m_value); // boolean: b = n->m_value != 0; SetProperty(prd, &b); // number: SetProperty(prd, &n->m_value); (then n->Release()) -// vec3: v = value->Deref(); if (v->m_obj == objVec3) SetProperty(prd, &v->m_x); +// vec3: v = value->Deref(); if (v->m_kind == objVec3) SetProperty(prd, &v->m_x); // node: p = value ? value->Deref() : NULL; SetProperty(prd, &p); // string: s = value->Deref()->ToStr(); SetProperty(prd, &s->m_text); s->Release(); // "assignement" is the binary's spelling. Theseus passes the byte count to @@ -609,7 +609,7 @@ void CProperty::Assign(CObject* pValue) const PROP_TYPE type = m_pprd->nType; if (pValue == NULL && type != pt_node) { - g_pRunner->Error(_T("Illegal null assignement")); + g_pActiveRunner->Error(_T("Illegal null assignement")); return; } @@ -636,7 +636,7 @@ void CProperty::Assign(CObject* pValue) else if (type == pt_vec3) { CObject* pVec = pValue->Deref(); - if (pVec->m_obj == objVec3) + if (pVec->m_kind == objVec3) m_node->SetProperty(m_pprd, &((CVec3Object*)pVec)->m_x, 3 * sizeof(float)); } else if (type == pt_node) @@ -690,26 +690,26 @@ CObject* Dereference(CObject* p) // LookupClass // Reconstructed from 5960 retail XBE: inlined at the top of CreateNewObject -// @ 0x37580 as g_classes->Lookup(name) (0x32ca0) plus an objClass check. +// @ 0x37580 as g_classTable->Lookup(name) (0x32ca0) plus an objClass check. CClass* LookupClass(const TCHAR* pchName, int cchName) { - extern CNameSpace* g_classes; - CObject* pFound = g_classes->Lookup(pchName, cchName); - if (pFound != NULL && pFound->m_obj == objClass) + extern CNameSpace* g_classTable; + CObject* pFound = g_classTable->Lookup(pchName, cchName); + if (pFound != NULL && pFound->m_kind == objClass) return (CClass*)pFound; return NULL; } // CreateNewObject // Reconstructed from 5960 retail XBE @ 0x00037580. Decompile: -// g_rgParam = rgparam; g_nParam = nParam; -// c = g_classes->Lookup(name); if (c && c->m_obj == objClass) return c->CreateNode(); +// g_scriptArgs = rgparam; g_nParam = nParam; +// c = g_classTable->Lookup(name); if (c && c->m_kind == objClass) return c->CreateNode(); // nc = CNodeClass::FindByName(name); if (nc && (o = nc->CreateNode())) return o; // return 0; -// The constructor args ride in g_rgParam / g_nParam for Date, Array and friends. +// The constructor args ride in g_scriptArgs / g_nParam for Date, Array and friends. CObject* CreateNewObject(const TCHAR* pchClassName, int cchClassName, CObject** rgArgs, int nArgs) { - g_rgParam = rgArgs; + g_scriptArgs = rgArgs; g_nParam = nArgs; CClass* pScripted = LookupClass(pchClassName, cchClassName); @@ -721,9 +721,9 @@ CObject* CreateNewObject(const TCHAR* pchClassName, int cchClassName, CObject** // ExecuteScript // Reconstructed from 5960 retail XBE @ 0x00036fb0. Decompile: -// CFunctionCompiler c; c.ParseBlock(sz); if (c.m_bError) return false; +// CFunctionCompiler c; c.ParseBlock(sz); if (c.m_bFailed) return false; // c.Write(opRet); f = c.CreateFunction(); -// CRunner r(obj); r.ResetFunc(); r.m_ops = f->m_rgop; r.Run(); +// CRunner r(obj); r.ResetFunc(); r.m_code = f->m_bytecode; r.Run(); // delete f; return true; bool ExecuteScript(CObject* pObject, const TCHAR* szScript) { @@ -745,7 +745,7 @@ bool ExecuteScript(CObject* pObject, const TCHAR* szScript) // CallFunction // Reconstructed from 5960 retail XBE @ 0x000371a0. Decompile: // g_pThis = obj; CRunner r(obj); r.ResetFunc(); -// if (!(r.m_ops = r.LookupFunction(name, wcslen(name), r.m_self))) return false; +// if (!(r.m_code = r.LookupFunction(name, wcslen(name), r.m_self))) return false; // for (i = 0; i < n; i++) r.m_stack[r.m_sp++] = rgParam[i]; // r.Run(); return true; // The arguments go on the stack as is; the caller's references move with them. @@ -782,7 +782,7 @@ CObject* FindMember(CNodeClass* pClass, const TCHAR* pchName, int cchName) // LookupMember // Reconstructed from 5960 retail XBE @ 0x000399e0. Decompile: // g_pThis = obj; -// if (obj->m_obj == objNode && (prd = obj->FindProp(name))) +// if (obj->m_kind == objNode && (prd = obj->FindProp(name))) // { p = new CProperty(obj, prd); p->m_nRefCount = 0; return p; } // if ((m = obj->GetMember(name))) return m; // for (c = obj->GetNodeClass(); c; c = c->m_baseClass) @@ -796,7 +796,7 @@ CObject* LookupMember(CObject* pObj, const TCHAR* pchName, int cchName) { g_pThis = pObj; - if (pObj->m_obj == objNode) + if (pObj->m_kind == objNode) { const PRD* pprd = pObj->FindProp(pchName, cchName); if (pprd != NULL) @@ -825,8 +825,8 @@ CObject* LookupMember(CObject* pObj, const TCHAR* pchName, int cchName) // Reconstructed from 5960 retail XBE: the runner is built on the stack in // CallFunction @ 0x371a0, ExecuteScript @ 0x36fb0 and // CMemberFunctionObject::Deref @ 0x39810, always the same way: -// m_sp = m_nop = 0; m_ops = NULL; m_self = m_thisRef = obj; -// m_bError = false; m_nextContext = NULL; zero the stack; +// m_sp = m_opPos = 0; m_code = NULL; m_self = m_thisRef = obj; +// m_bFailed = false; m_nextContext = NULL; zero the stack; // and torn down with ResetFunc. 5960's stack holds 100 entries; Theseus's // holds 256 (see runner.h). Theseus also starts the line at 0 so an error // before the first statement doesn't print a junk line number. @@ -836,12 +836,12 @@ CRunner::CRunner(CObject* pOwner) m_sp = 0; m_spFrame = 0; m_spBase = 0; - m_ops = NULL; - m_nop = 0; + m_code = NULL; + m_opPos = 0; m_self = pOwner; m_thisRef = pOwner; m_nextContext = NULL; - m_bError = false; + m_bFailed = false; m_nLine = 0; m_wakeup = 0.0f; } @@ -852,22 +852,22 @@ CRunner::~CRunner() } // CRunner::SetFunc [inlined at each runner site in 5960] -// By name: ResetFunc, then m_ops = LookupFunction(name) (see CallFunction). -// By function: ResetFunc, then m_ops = fn->m_rgop with nop/sp/frame at 0. +// By name: ResetFunc, then m_code = LookupFunction(name) (see CallFunction). +// By function: ResetFunc, then m_code = fn->m_bytecode with nop/sp/frame at 0. // Theseus also clears the line number and the sleep deadline here. bool CRunner::SetFunc(const TCHAR* szFunc) { ResetFunc(); BYTE* pbCode = LookupFunction(szFunc, _tcslen(szFunc), m_thisRef); - m_ops = pbCode; + m_code = pbCode; return pbCode != NULL; } void CRunner::SetFunc(CFunction* pFunction) { ResetFunc(); - m_ops = pFunction->m_rgop; - m_nop = 0; + m_code = pFunction->m_bytecode; + m_opPos = 0; m_sp = 0; m_spFrame = 0; m_nLine = 0; @@ -877,7 +877,7 @@ void CRunner::SetFunc(CFunction* pFunction) // CRunner::ResetFunc // Reconstructed from 5960 retail XBE @ 0x00037400. Decompile: // while (m_sp) { p = m_stack[--m_sp]; m_stack[m_sp] = 0; if (p) p->Release(); } -// m_bError = 0; m_nop = 0; m_wakeup = 0.0; m_sp = 0; m_spFrame = 0; +// m_bFailed = 0; m_opPos = 0; m_wakeup = 0.0; m_sp = 0; m_spFrame = 0; void CRunner::ResetFunc() { while (m_sp != 0) @@ -887,8 +887,8 @@ void CRunner::ResetFunc() pSlot->Release(); } - m_bError = false; - m_nop = 0; + m_bFailed = false; + m_opPos = 0; m_wakeup = 0.0f; m_spFrame = 0; } @@ -943,20 +943,20 @@ CObject* CRunner::Pop() // CRunner::Error // Reconstructed from 5960 retail XBE @ 0x000375e0. Decompile: -// if (m_bError) return; +// if (m_bFailed) return; // vswprintf(msg, 512, fmt, args); // if (m_nLine == 0) swprintf(out, L"###...\n###Runtime Error\n\n%s\n###...", msg); // else swprintf(out, L"###...\n###Runtime Error\n\nLine: %d\n\n%s\n###...", m_nLine, msg); -// m_bError = 1; +// m_bFailed = 1; // Only the first error of a run is reported; Run stops on the flag. Retail // builds the text and shows it nowhere. Theseus keeps the core of that text // without the # banners, sends it to the trace output with the house error // marker, and pops a message box on desktop. void CRunner::Error(const TCHAR* szFmt, ...) { - if (m_bError) + if (m_bFailed) return; - m_bError = true; + m_bFailed = true; TCHAR szWhat[512]; va_list args; @@ -980,7 +980,7 @@ void CRunner::Error(const TCHAR* szFmt, ...) // CRunner::PushContext // Reconstructed from 5960 retail XBE @ 0x00037690. Decompile: -// c = new RUNCONTEXT; c->m_ops = m_ops; c->m_nop = m_nop; +// c = new RUNCONTEXT; c->m_code = m_code; c->m_opPos = m_opPos; // c->m_spFrame = m_spFrame; c->m_self = m_self; c->m_thisRef = m_thisRef; // c->m_sp = m_sp - nParam - 1; c->m_next = m_nextContext; m_nextContext = c; // The saved sp sits under the callee and its arguments, so returning drops both. @@ -988,8 +988,8 @@ void CRunner::PushContext(UINT nArgs) { RUNCONTEXT* pSaved = new RUNCONTEXT; pSaved->m_nextContext = m_nextContext; - pSaved->m_ops = m_ops; - pSaved->m_nop = m_nop; + pSaved->m_code = m_code; + pSaved->m_opPos = m_opPos; pSaved->m_spFrame = m_spFrame; pSaved->m_self = m_self; pSaved->m_thisRef = m_thisRef; @@ -1014,7 +1014,7 @@ static void ReleaseRange(CObject** rgSlot, UINT cSlot) // CRunner::PopContext // Reconstructed from 5960 retail XBE @ 0x000376e0. Decompile: // c = m_nextContext; ret = Dereference(Pop()); -// m_ops/m_nop/m_spFrame/m_self = c->...; g_pThis = m_thisRef = c->m_thisRef; +// m_code/m_opPos/m_spFrame/m_self = c->...; g_pThis = m_thisRef = c->m_thisRef; // for (i = c->m_sp; i < m_sp; i++) if (m_stack[i]) { m_stack[i]->Release(); m_stack[i] = 0; } // m_sp = c->m_sp; m_nextContext = c->m_next; delete c; m_stack[m_sp++] = ret; void CRunner::PopContext() @@ -1022,8 +1022,8 @@ void CRunner::PopContext() RUNCONTEXT* pSaved = m_nextContext; CObject* pResult = Dereference(Pop()); - m_ops = pSaved->m_ops; - m_nop = pSaved->m_nop; + m_code = pSaved->m_code; + m_opPos = pSaved->m_opPos; m_spFrame = pSaved->m_spFrame; m_self = pSaved->m_self; m_thisRef = pSaved->m_thisRef; @@ -1041,17 +1041,17 @@ void CRunner::PopContext() // CRunner::Run // Reconstructed from 5960 retail XBE @ 0x000377b0. Decompile: // m_spBase = m_sp; -// while (!m_bError) if (!Step(&ret)) break; +// while (!m_bFailed) if (!Step(&ret)) break; // Theseus hands back whatever the outermost return left (NULL on error). CObject* CRunner::Run() { m_spBase = m_sp; CObject* pResult = NULL; - while (!m_bError && Step(&pResult)) + while (!m_bFailed && Step(&pResult)) pResult = NULL; - return m_bError ? NULL : pResult; + return m_bFailed ? NULL : pResult; } // ========================================================================= @@ -1060,17 +1060,17 @@ CObject* CRunner::Run() // CRunner::Step // Reconstructed from 5960 retail XBE @ 0x00037800 (1880 bytes, one switch on -// the opcode byte). Sets g_pRunner, fetches the opcode and runs it; returns +// the opcode byte). Sets g_pActiveRunner, fetches the opcode and runs it; returns // false to stop (outermost return, error, or an opcode it doesn't know). // Each case is described next to its code below; the full write-up with the // decompile excerpts is in docs/decomp/VM.md. Theseus adds the stack checks // on opFrame and opCall and the null check on opCall. bool CRunner::Step(CObject** ppRetObj) { - g_pRunner = this; + g_pActiveRunner = this; - const BYTE opcode = m_ops[m_nop]; - m_nop++; + const BYTE opcode = m_code[m_opPos]; + m_opPos++; switch (opcode) { @@ -1116,7 +1116,7 @@ bool CRunner::Step(CObject** ppRetObj) // uint target. case opJump: - m_nop = FetchUInt(); + m_opPos = FetchUInt(); return true; // uint target. Pop a value; true (nonzero number) falls through, false @@ -1135,7 +1135,7 @@ bool CRunner::Step(CObject** ppRetObj) UINT nopElse = FetchUInt(); if (!bTaken) - m_nop = nopElse; + m_opPos = nopElse; } return true; @@ -1145,8 +1145,8 @@ bool CRunner::Step(CObject** ppRetObj) // function lookup. case opCall: { - int nArgs = m_ops[m_nop]; - m_nop++; + int nArgs = m_code[m_opPos]; + m_opPos++; // Theseus: not enough on the stack is a stop, not a wild read. if (!CHECK(m_sp > (UINT)nArgs)) @@ -1163,7 +1163,7 @@ bool CRunner::Step(CObject** ppRetObj) return false; } - if (pCallee->m_obj == objFunctionRef) + if (pCallee->m_kind == objFunctionRef) { m_stack[spCallee] = NULL; CObject* pResult = ((CFunctionObject*)pCallee)->Call(rgArgs, nArgs); @@ -1175,15 +1175,15 @@ bool CRunner::Step(CObject** ppRetObj) return true; } - if (pCallee->m_obj == objMemberFunction) + if (pCallee->m_kind == objMemberFunction) { CMemberFunctionObject* pMethod = (CMemberFunctionObject*)pCallee; pMethod->AddRef(); PushContext(nArgs); m_spFrame = spCallee + 1; m_self = pMethod->m_owner; - m_ops = pMethod->m_function->m_rgop; - m_nop = 0; + m_code = pMethod->m_function->m_bytecode; + m_opPos = 0; return true; } @@ -1216,8 +1216,8 @@ bool CRunner::Step(CObject** ppRetObj) m_self = pOwner; g_pThis = pOwner; m_spFrame = spCallee + 1; - m_ops = pbCode; - m_nop = 0; + m_code = pbCode; + m_opPos = 0; } return true; @@ -1280,7 +1280,7 @@ bool CRunner::Step(CObject** ppRetObj) CObject* pMember = pTarget->Dot(pKey); if (pMember == NULL) { - if (pKey->m_obj == objVariable) + if (pKey->m_kind == objVariable) { Error(_T("Unknown member: %s"), ((CVarObject*)pKey)->m_text); } @@ -1357,7 +1357,7 @@ bool CRunner::Step(CObject** ppRetObj) case opNeg: { CObject* pValue = Dereference(Pop()); - if (pValue == NULL || pValue->m_obj != objNumber) + if (pValue == NULL || pValue->m_kind != objNumber) { Error(_T("expected a number")); return false; @@ -1401,7 +1401,7 @@ bool CRunner::Step(CObject** ppRetObj) Error(_T("illegal null reference")); return false; } - if (pDelay->m_obj != objNumber) + if (pDelay->m_kind != objNumber) { Error(_T("expected a number")); return false; @@ -1438,7 +1438,7 @@ bool CRunner::BinaryOperator(BYTE op) CObject* pB = Dereference(Pop()); CObject* pA = Dereference(Pop()); - if (pA == NULL || pB == NULL || (pA->m_obj == objNode && pB->m_obj == objNode)) + if (pA == NULL || pB == NULL || (pA->m_kind == objNode && pB->m_kind == objNode)) { if (op != opEQ && op != opNE) { @@ -1456,8 +1456,8 @@ bool CRunner::BinaryOperator(BYTE op) return true; } - const int typeA = pA->m_obj; - const int typeB = pB->m_obj; + const int typeA = pA->m_kind; + const int typeB = pB->m_kind; if (typeA == objString && typeB == objString && op != opAdd) { @@ -1666,10 +1666,10 @@ BOOL CRunner::ExecuteBuiltIn(const TCHAR* pchName, int cchName, int nArgs, CObje // CRunner::LookupFunction // Reconstructed from 5960 retail XBE @ 0x000389b0. Decompile: // owner = m_self; -// if ((f = m_self->FindMemberFunction(name))) return f->m_rgop; +// if ((f = m_self->FindMemberFunction(name))) return f->m_bytecode; // for (p = m_self->m_parent; p; p = p->m_parent) // if ((m = LookupMember(p, name))) { -// owner = p; return m->m_obj == objFunction ? m->m_rgop : (BYTE*)m; } +// owner = p; return m->m_kind == objFunction ? m->m_bytecode : (BYTE*)m; } // owner = NULL; return NULL; // A non-function hit comes back as a raw pointer, as in the binary. BYTE* CRunner::LookupFunction(const TCHAR* pchName, int cchName, CObject*& pOwner) @@ -1678,7 +1678,7 @@ BYTE* CRunner::LookupFunction(const TCHAR* pchName, int cchName, CObject*& pOwne CFunction* pOwn = m_self->FindMemberFunction(pchName, cchName); if (pOwn != NULL) - return pOwn->m_rgop; + return pOwn->m_bytecode; for (CObject* pUp = m_self->m_parent; pUp != NULL; pUp = pUp->m_parent) { @@ -1686,7 +1686,7 @@ BYTE* CRunner::LookupFunction(const TCHAR* pchName, int cchName, CObject*& pOwne if (pFound != NULL) { pOwner = pUp; - return (pFound->m_obj == objFunction) ? ((CFunction*)pFound)->m_rgop : (BYTE*)pFound; + return (pFound->m_kind == objFunction) ? ((CFunction*)pFound)->m_bytecode : (BYTE*)pFound; } } diff --git a/theseus/xbox/main.cpp b/theseus/xbox/main.cpp index 29afadf..1a5bce5 100644 --- a/theseus/xbox/main.cpp +++ b/theseus/xbox/main.cpp @@ -1103,10 +1103,10 @@ bool InitApp() if (!g_pClass->Load(szFileToLoad)) { - extern bool g_bParseError; + extern bool g_bXapSyntaxError; TCHAR reason[MAX_PATH + 64]; _stprintf(reason, - g_bParseError ? _T("Parse error in %s") + g_bXapSyntaxError ? _T("Parse error in %s") : _T("Cannot open %s"), szFileToLoad); TheseusPanic(reason, From 580d471b9c63bae02f21bc05b2da048e24c12dd3 Mon Sep 17 00:00:00 2001 From: Milenko <39630670+MrMilenko@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:53:54 -0500 Subject: [PATCH 5/8] Renamed scene, camera and level transition state The view and camera matrices, level and tunnel pointers, fade and lerp endpoints, bounds, clip rects and the background loader tick have names of their own now. Compiled code is unchanged. --- docs/decomp/Camera.md | 6 +- docs/decomp/HudNode.md | 6 +- theseus/desktop/dashapp.cpp | 24 +-- theseus/desktop/guide.cpp | 4 +- theseus/render/asset_loader.cpp | 4 +- theseus/render/camera.cpp | 50 ++--- theseus/render/camera.h | 10 +- theseus/render/hud_node.cpp | 44 ++--- theseus/render/materials.cpp | 4 +- theseus/render/node.h | 8 +- theseus/render/scene_groups.cpp | 326 ++++++++++++++++---------------- theseus/render/scene_groups.h | 8 +- theseus/render/shape_render.cpp | 34 ++-- theseus/render/shape_render.h | 26 +-- theseus/render/starfield.cpp | 20 +- theseus/shared/audio_system.cpp | 6 +- theseus/xbox/main.cpp | 36 ++-- 17 files changed, 308 insertions(+), 308 deletions(-) diff --git a/docs/decomp/Camera.md b/docs/decomp/Camera.md index 4e2dd11..5a8b4a1 100644 --- a/docs/decomp/Camera.md +++ b/docs/decomp/Camera.md @@ -55,9 +55,9 @@ it onto the orientation copy. The constants mean the head drifts at most one deg It stores the position at 0x84, then - D3DXMatrixAffineTransformation(&g_matPosition /*0x17f4a8*/, 1.0, NULL, &rot, &pos); - D3DXMatrixInverse(&g_matView /*0x17f468*/, NULL, &g_matPosition); - g_matView._31.._34 = 0.0 - each; // SUBSS from a zeroed register + D3DXMatrixAffineTransformation(&g_cameraWorld /*0x17f4a8*/, 1.0, NULL, &rot, &pos); + D3DXMatrixInverse(&g_viewMatrix /*0x17f468*/, NULL, &g_cameraWorld); + g_viewMatrix._31.._34 = 0.0 - each; // SUBSS from a zeroed register copies the 16 floats into the device's view transform at `pDevice + 0xc60`, and ORs `0xff0200` into the dirty mask at `0x00156080`. Negating the third row is what turns diff --git a/docs/decomp/HudNode.md b/docs/decomp/HudNode.md index 4420449..c711cc5 100644 --- a/docs/decomp/HudNode.md +++ b/docs/decomp/HudNode.md @@ -46,8 +46,8 @@ destructor (`0x00052b80`) only resets the vtable and runs Group's. D3DXMatrixOrthoLH(&ortho, 720.0, 480.0, -10000.0, 10000.0); savedProj = g_matProjection /* 0x0017f4e8 */; g_matProjection = ortho; SetTransform(PROJECTION, &g_matProjection); // 0x00144e30 -savedView = g_matView /* 0x0017f468 */; -g_matView = g_matIdentity /* 0x00176338 */; SetTransform(VIEW, ...); // inline copy to device +0xc60 +savedView = g_viewMatrix /* 0x0017f468 */; +g_viewMatrix = g_matIdentity /* 0x00176338 */; SetTransform(VIEW, ...); // inline copy to device +0xc60 lighting = rs[LIGHTING] /* 0x0017a218 */; rs[LIGHTING] = 0; worldStack->Push(); worldStack->LoadIdentity(); // stack 0x0017e7fc, slots 4, 5 SetTransform(WORLD, worldStack->GetTop()); FUN_0005ca00(); // falloff shader constants @@ -56,7 +56,7 @@ CGroup::Render(); // 0x000 worldStack->Pop(); SetTransform(WORLD, worldStack->GetTop()); FUN_0005ca00(); rs[LIGHTING] = lighting; g_matProjection = savedProj; SetTransform(PROJECTION, ...); -g_matView = savedView; SetTransform(VIEW, ...); +g_viewMatrix = savedView; SetTransform(VIEW, ...); ``` The ortho box is a fixed 720x480, so HUD children are laid out in that space no diff --git a/theseus/desktop/dashapp.cpp b/theseus/desktop/dashapp.cpp index 270006d..7e46b49 100755 --- a/theseus/desktop/dashapp.cpp +++ b/theseus/desktop/dashapp.cpp @@ -35,7 +35,7 @@ extern void DashInit(); extern void DiscDrive_Init(); -extern void BackgroundLoader_Frame(); +extern void AssetLoader_Pump(); extern void Text_Exit(); @@ -106,11 +106,11 @@ int g_nVertPerFrame = 0; int g_nTriPerFrame = 0; char* g_szAppTitle = NULL; -D3DXMATRIX g_matView; -D3DXMATRIX g_matPosition; +D3DXMATRIX g_viewMatrix; +D3DXMATRIX g_cameraWorld; D3DXMATRIX g_matProjection; -D3DRECT g_scissorRect; -D3DRECT g_scissorRectx2; +D3DRECT g_clipRect; +D3DRECT g_clipRect2x; D3DXMATRIX g_matIdentity( 1.0f, 0.0f, 0.0f, 0.0f, @@ -155,7 +155,7 @@ HRESULT InitAudio() // D3D Initialization and Render State // ============================================================================ -float g_transitionMotionBlur; +float g_levelBlurAmount; // ========================================================================= // D3D call-trace storage + dump (Sweep 2 of project_d3d_call_audit.md) @@ -402,7 +402,7 @@ void XboxInitRenderState() for (int i = 0; i < (int)countof(states); i++) TheseusSetRenderState(states[i].state, states[i].value); - g_transitionMotionBlur = 1.0f; + g_levelBlurAmount = 1.0f; } // Scissor rectangle covering back buffer iBuffer (-1 is the front buffer). @@ -467,8 +467,8 @@ bool InitD3D() return false; } - FullBufferRect(-1, &g_scissorRect); - FullBufferRect(0, &g_scissorRectx2); + FullBufferRect(-1, &g_clipRect); + FullBufferRect(0, &g_clipRect2x); XboxInitRenderState(); @@ -616,7 +616,7 @@ static void SetupLights() ambient.b += light.Ambient.b; D3DXVECTOR3 dir(0.0f, 0.0f, -1.0f); - D3DXVec3TransformNormal(&dir, &dir, &g_matPosition); + D3DXVec3TransformNormal(&dir, &dir, &g_cameraWorld); light.Direction = dir; TheseusSetLight(nLights, &light); @@ -656,7 +656,7 @@ void Draw() TheseusSetRenderState(D3DRS_FILLMODE, g_bWireframe ? D3DFILL_WIREFRAME : D3DFILL_SOLID); // A bigger factor means less blur. - const float blurAlpha = g_transitionMotionBlur; + const float blurAlpha = g_levelBlurAmount; D3DCOLOR sky = D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.3f, 1.0f); bool bBackdrop = false; @@ -819,7 +819,7 @@ void Advance() CLerper::AdvanceAll(); g_pObject->Advance(nDelta); - BackgroundLoader_Frame(); + AssetLoader_Pump(); Debug_Frame(); } diff --git a/theseus/desktop/guide.cpp b/theseus/desktop/guide.cpp index 1c2a0f5..662ef8c 100644 --- a/theseus/desktop/guide.cpp +++ b/theseus/desktop/guide.cpp @@ -41,7 +41,7 @@ #include class CLevel; -extern CLevel* g_pCurLevel; +extern CLevel* g_pActiveLevel; extern bool g_padModeEnabled, g_padModeActive; extern bool g_mediaFullscreen, g_xcloudFullscreen; extern void* g_pActiveKeyboard_void(); @@ -1305,7 +1305,7 @@ void Guide_Frame() // First run, or Startup is "Ask": once the dashboard is up, the // welcome offers the ways in. Neither waits for the scene to settle. - if (!g.startChecked && g_pCurLevel) { + if (!g.startChecked && g_pActiveLevel) { g.startChecked = true; if (!g_welcomeDone || g_startupMode == 0) { Open(true); diff --git a/theseus/render/asset_loader.cpp b/theseus/render/asset_loader.cpp index d06e7e2..0c18133 100644 --- a/theseus/render/asset_loader.cpp +++ b/theseus/render/asset_loader.cpp @@ -263,12 +263,12 @@ bool CBackgroundLoader::Fetch(const TCHAR* szURL) return GetLastError() == ERROR_IO_PENDING; } -// BackgroundLoader_Frame() +// AssetLoader_Pump() // Inlined in the 5960 frame loop (main frame loop @ 0x0002da00, after the // lerpers advance and before Draw): // for (p = first; p; p = next) { next = p->next; // if (p->overlapped.Internal != STATUS_PENDING) { p->OnComplete(); delete p; } } -void BackgroundLoader_Frame() +void AssetLoader_Pump() { CBackgroundLoader* pNext; for (CBackgroundLoader* p = CBackgroundLoader::c_pFirst; p != NULL; p = pNext) diff --git a/theseus/render/camera.cpp b/theseus/render/camera.cpp index d6bda37..ec6d327 100755 --- a/theseus/render/camera.cpp +++ b/theseus/render/camera.cpp @@ -9,8 +9,8 @@ #include "shape_render.h" #include "interpolator.h" -extern D3DXMATRIX g_matView; -extern D3DXMATRIX g_matPosition; +extern D3DXMATRIX g_viewMatrix; +extern D3DXMATRIX g_cameraWorld; extern bool g_bMovingScreen; @@ -53,7 +53,7 @@ void CCamera::Reset() { m_position = D3DXVECTOR3(0.0f, 0.0f, 20.0f); m_orientation = D3DXQUATERNION(0.0f, 0.0f, 0.0f, 1.0f); - m_nDeltaTime = 0.0f; + m_travelTime = 0.0f; } // CCamera::UpdateViewMatrix() @@ -65,9 +65,9 @@ void CCamera::Reset() // QuaternionMultiply(&rot, &wobble, &rot); // } // this->actualPos = pos; -// MatrixAffineTransformation(&g_matPosition, 1.0, NULL, &rot, &pos); -// MatrixInverse(&g_matView, NULL, &g_matPosition); -// g_matView._31.._34 = 0.0 - each; then copied into the device view. +// MatrixAffineTransformation(&g_cameraWorld, 1.0, NULL, &rot, &pos); +// MatrixInverse(&g_viewMatrix, NULL, &g_cameraWorld); +// g_viewMatrix._31.._34 = 0.0 - each; then copied into the device view. // The wobble is at most one degree each way. Flipping the third row turns // the right handed scene camera into D3D's left handed view. void CCamera::UpdateViewMatrix() @@ -89,14 +89,14 @@ void CCamera::UpdateViewMatrix() m_actualPosition = eye; - D3DXMatrixAffineTransformation(&g_matPosition, 1.0f, NULL, &facing, &eye); - D3DXMatrixInverse(&g_matView, NULL, &g_matPosition); - g_matView._31 = 0.0f - g_matView._31; - g_matView._32 = 0.0f - g_matView._32; - g_matView._33 = 0.0f - g_matView._33; - g_matView._34 = 0.0f - g_matView._34; + D3DXMatrixAffineTransformation(&g_cameraWorld, 1.0f, NULL, &facing, &eye); + D3DXMatrixInverse(&g_viewMatrix, NULL, &g_cameraWorld); + g_viewMatrix._31 = 0.0f - g_viewMatrix._31; + g_viewMatrix._32 = 0.0f - g_viewMatrix._32; + g_viewMatrix._33 = 0.0f - g_viewMatrix._33; + g_viewMatrix._34 = 0.0f - g_viewMatrix._34; - TheseusSetTransform(D3DTS_VIEW, &g_matView); + TheseusSetTransform(D3DTS_VIEW, &g_viewMatrix); } // CCamera::Set(pPosition, pOrientation, nSeconds) @@ -106,18 +106,18 @@ void CCamera::UpdateViewMatrix() // if (secs <= 0.0) { position = newPos; orientation = newRot; } void CCamera::Set(const D3DXVECTOR3* pos, const D3DXQUATERNION* rot, float dt/*=0.0f*/) { - m_newPosition = *pos; - m_newOrientation = *rot; - m_oldPosition = m_position; - m_oldOrientation = m_orientation; + m_toPos = *pos; + m_toOrient = *rot; + m_fromPos = m_position; + m_fromOrient = m_orientation; m_nStartTime = TheseusGetNow(); - m_nDeltaTime = dt; + m_travelTime = dt; if (dt > 0.0f) return; - m_position = m_newPosition; - m_orientation = m_newOrientation; + m_position = m_toPos; + m_orientation = m_toOrient; } // CCamera::Advance(nSeconds) @@ -132,17 +132,17 @@ void CCamera::Set(const D3DXVECTOR3* pos, const D3DXQUATERNION* rot, float dt/*= // It never calls CNode::Advance. void CCamera::Advance(float dt) { - if (m_nDeltaTime > 0.0f) + if (m_travelTime > 0.0f) { - float f = (float)(TheseusGetNow() - m_nStartTime) / m_nDeltaTime; + float f = (float)(TheseusGetNow() - m_nStartTime) / m_travelTime; if (f >= 1.0f) { f = 1.0f; - m_nDeltaTime = 0.0f; + m_travelTime = 0.0f; } - D3DXVec3Lerp(&m_position, &m_oldPosition, &m_newPosition, f); - D3DXQuaternionSlerp(&m_orientation, &m_oldOrientation, &m_newOrientation, f); + D3DXVec3Lerp(&m_position, &m_fromPos, &m_toPos, f); + D3DXQuaternionSlerp(&m_orientation, &m_fromOrient, &m_toOrient, f); } UpdateViewMatrix(); diff --git a/theseus/render/camera.h b/theseus/render/camera.h index 6c6c051..055fb77 100755 --- a/theseus/render/camera.h +++ b/theseus/render/camera.h @@ -24,12 +24,12 @@ class CCamera : public CNode D3DXVECTOR3 m_position; D3DXQUATERNION m_orientation; - D3DXVECTOR3 m_oldPosition; // where the move started - D3DXQUATERNION m_oldOrientation; - D3DXVECTOR3 m_newPosition; // where it ends - D3DXQUATERNION m_newOrientation; + D3DXVECTOR3 m_fromPos; // where the move started + D3DXQUATERNION m_fromOrient; + D3DXVECTOR3 m_toPos; // where it ends + D3DXQUATERNION m_toOrient; XTIME m_nStartTime; - float m_nDeltaTime; + float m_travelTime; D3DXVECTOR3 m_actualPosition; }; diff --git a/theseus/render/hud_node.cpp b/theseus/render/hud_node.cpp index 098d8a5..b8ebbee 100644 --- a/theseus/render/hud_node.cpp +++ b/theseus/render/hud_node.cpp @@ -10,7 +10,7 @@ #include "asset_loader.h" extern D3DXMATRIX g_matIdentity; -extern D3DXMATRIX g_matView; +extern D3DXMATRIX g_viewMatrix; extern D3DXMATRIX g_matProjection; @@ -50,7 +50,7 @@ CHud::~CHud() // Reconstructed from 5960 retail XBE @ 0x00052b90. Ghidra decompile: // D3DXMatrixOrthoLH(&ortho, 720.0, 480.0, -10000.0, 10000.0); // savedProj = g_matProjection; g_matProjection = ortho; SetTransform(PROJ); -// savedView = g_matView; g_matView = g_matIdentity; SetTransform(VIEW); +// savedView = g_viewMatrix; g_viewMatrix = g_matIdentity; SetTransform(VIEW); // lighting = rs[LIGHTING]; rs[LIGHTING] = 0; // worldStack->Push(); worldStack->LoadIdentity(); SetTransform(WORLD, top); // rs[EDGEANTIALIAS] = 0; rs[MULTISAMPLEANTIALIAS] = 1; @@ -68,9 +68,9 @@ void CHud::Render() g_matProjection = ortho; TheseusSetTransform(D3DTS_PROJECTION, &g_matProjection); - D3DXMATRIX savedView = g_matView; - g_matView = g_matIdentity; - TheseusSetTransform(D3DTS_VIEW, &g_matView); + D3DXMATRIX savedView = g_viewMatrix; + g_viewMatrix = g_matIdentity; + TheseusSetTransform(D3DTS_VIEW, &g_viewMatrix); DWORD lighting; TheseusGetRenderState(D3DRS_LIGHTING, &lighting); @@ -93,8 +93,8 @@ void CHud::Render() g_matProjection = savedProjection; TheseusSetTransform(D3DTS_PROJECTION, &g_matProjection); - g_matView = savedView; - TheseusSetTransform(D3DTS_VIEW, &g_matView); + g_viewMatrix = savedView; + TheseusSetTransform(D3DTS_VIEW, &g_viewMatrix); } @@ -134,10 +134,10 @@ class CPicture : public CNode float m_endTop; float m_startWidth; float m_endWidth; - float m_startHeight; + float m_baseHeight; float m_endHeight; - LPDIRECT3DVERTEXBUFFER8 m_pVB; + LPDIRECT3DVERTEXBUFFER8 m_pVerts; DECLARE_NODE_PROPS() }; @@ -185,7 +185,7 @@ CPicture::CPicture() m_color = D3DXVECTOR3(1.0f, 1.0f, 1.0f); m_alpha = 1.0f; m_startFadeTime = 0.0; - m_pVB = NULL; + m_pVerts = NULL; } // CPicture::~CPicture() @@ -194,8 +194,8 @@ CPicture::CPicture() // Buffer first, then the texture node. CPicture::~CPicture() { - if (m_pVB) - m_pVB->Release(); + if (m_pVerts) + m_pVerts->Release(); if (m_texture) m_texture->Release(); } @@ -222,11 +222,11 @@ void CPicture::Render() return; } - if (!m_pVB) + if (!m_pVerts) { - if (FAILED(TheseusGetD3DDev()->CreateVertexBuffer(4 * sizeof(PictureVertex), D3DUSAGE_WRITEONLY, kPictureFVF, D3DPOOL_MANAGED, &m_pVB))) - m_pVB = NULL; - if (!m_pVB) + if (FAILED(TheseusGetD3DDev()->CreateVertexBuffer(4 * sizeof(PictureVertex), D3DUSAGE_WRITEONLY, kPictureFVF, D3DPOOL_MANAGED, &m_pVerts))) + m_pVerts = NULL; + if (!m_pVerts) return; } @@ -323,13 +323,13 @@ void CPicture::Render() #endif BYTE* dst = NULL; - if (SUCCEEDED(m_pVB->Lock(0, sizeof(quad), &dst, 0)) && dst) + if (SUCCEEDED(m_pVerts->Lock(0, sizeof(quad), &dst, 0)) && dst) { memcpy(dst, quad, sizeof(quad)); - m_pVB->Unlock(); + m_pVerts->Unlock(); LPDIRECT3DDEVICE8 dev = TheseusGetD3DDev(); - TheseusSetStreamSource(0, m_pVB, sizeof(PictureVertex)); + TheseusSetStreamSource(0, m_pVerts, sizeof(PictureVertex)); TheseusSetVertexShader(kPictureFVF); dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); } @@ -369,7 +369,7 @@ void CPicture::Advance(float nSeconds) m_left = m_startLeft * s + m_endLeft * t; m_top = m_startTop * s + m_endTop * t; m_width = m_startWidth * s + m_endWidth * t; - m_height = m_startHeight * s + m_endHeight * t; + m_height = m_baseHeight * s + m_endHeight * t; } // CPicture::OnLoad() @@ -387,7 +387,7 @@ void CPicture::OnLoad() m_endTop = m_top; m_startWidth = m_width; m_endWidth = m_width; - m_startHeight = m_height; + m_baseHeight = m_height; m_endHeight = m_height; CNode::OnLoad(); @@ -436,7 +436,7 @@ bool CPicture::OnSetProperty(const PRD *pprd, const void *pvValue) else if (field == offsetof(m_width)) { from = &m_startWidth; to = &m_endWidth; now = m_width; } else if (field == offsetof(m_height)) - { from = &m_startHeight; to = &m_endHeight; now = m_height; } + { from = &m_baseHeight; to = &m_endHeight; now = m_height; } else return true; diff --git a/theseus/render/materials.cpp b/theseus/render/materials.cpp index a14ee77..65616f2 100755 --- a/theseus/render/materials.cpp +++ b/theseus/render/materials.cpp @@ -32,8 +32,8 @@ const TCHAR *g_szCurTitleImage; const TCHAR *g_szSelTitleImage; bool g_bActiveKey = false; extern float g_nEffectAlpha; -extern D3DRECT g_scissorRect; -extern D3DRECT g_scissorRectx2; +extern D3DRECT g_clipRect; +extern D3DRECT g_clipRect2x; XTIME g_pulseStartTime; static class CMaxMaterial *g_pLastPulseMaxMat = NULL; int g_nMatInfoCount = 0; diff --git a/theseus/render/node.h b/theseus/render/node.h index 0ac3e6e..ab3400b 100755 --- a/theseus/render/node.h +++ b/theseus/render/node.h @@ -7,7 +7,7 @@ // factories (sizes are the operator new argument, offsets are the stores): // CObject 0x14: vtbl, m_nRefCount 0x04, m_kind 0x08, m_parent 0x0c, m_pScope 0x10 // CNode 0x1c: m_behavior 0x14, m_visible 0x18 -// CGroup 0x44: m_children 0x1c, m_bboxCenter 0x28, m_bboxSize 0x34, flags 0x40/0x41 +// CGroup 0x44: m_children 0x1c, m_boundsCenter 0x28, m_boundsSize 0x34, flags 0x40/0x41 // CInstance 0x54: m_classDef 0x44, m_vars 0x48 // CTimeDepNode 0x30: m_loop 0x1c, m_startTime 0x20, m_stopTime 0x24, // m_isActive 0x28, m_prevStartTime 0x2c @@ -544,9 +544,9 @@ class CGroup : public CNode LPDIRECT3DTEXTURE8 GetTextureSurface(); CNodeArray m_children; - D3DXVECTOR3 m_bboxCenter; - D3DXVECTOR3 m_bboxSize; - bool m_bboxSpecified; + D3DXVECTOR3 m_boundsCenter; + D3DXVECTOR3 m_boundsSize; + bool m_bHasBounds; bool m_bboxDirty; }; diff --git a/theseus/render/scene_groups.cpp b/theseus/render/scene_groups.cpp index 0cec8b1..147f32f 100755 --- a/theseus/render/scene_groups.cpp +++ b/theseus/render/scene_groups.cpp @@ -14,12 +14,12 @@ #include "file_util.h" #include "scene_groups.h" -extern D3DXMATRIX g_matView; -extern D3DXMATRIX g_matPosition; +extern D3DXMATRIX g_viewMatrix; +extern D3DXMATRIX g_cameraWorld; extern D3DXMATRIX g_matProjection; extern D3DXMATRIX g_matIdentity; extern float g_nEffectAlpha; -extern float g_transitionMotionBlur; +extern float g_levelBlurAmount; extern void BindJoystick(CNode* pJoystickNode); @@ -39,9 +39,9 @@ END_NODE_PROPS() // A size of -1 on every axis means "nobody gave us a box, work it out". CGroup::CGroup() { - m_bboxCenter = D3DXVECTOR3(0.0f, 0.0f, 0.0f); - m_bboxSize = D3DXVECTOR3(-1.0f, -1.0f, -1.0f); - m_bboxSpecified = true; + m_boundsCenter = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + m_boundsSize = D3DXVECTOR3(-1.0f, -1.0f, -1.0f); + m_bHasBounds = true; m_bboxDirty = true; } @@ -67,16 +67,16 @@ CGroup::~CGroup() // the binary's behavior and we keep it. Dirty is never cleared here. void CGroup::GetBBox(BBox* pBBox) { - if (m_bboxSize.x == -1.0f && m_bboxSize.y == -1.0f && m_bboxSize.z == -1.0f) - m_bboxSpecified = false; + if (m_boundsSize.x == -1.0f && m_boundsSize.y == -1.0f && m_boundsSize.z == -1.0f) + m_bHasBounds = false; - if (m_bboxDirty && !m_bboxSpecified) + if (m_bboxDirty && !m_bHasBounds) { int count = m_children.GetLength(); if (count == 0) { - m_bboxCenter = D3DXVECTOR3(0.0f, 0.0f, 0.0f); - m_bboxSize = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + m_boundsCenter = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + m_boundsSize = D3DXVECTOR3(0.0f, 0.0f, 0.0f); } else { @@ -99,15 +99,15 @@ void CGroup::GetBBox(BBox* pBBox) if (far_.z < hi.z) hi.z = far_.z; } - m_bboxCenter.x = (hi.x + lo.x) * 0.5f; - m_bboxCenter.y = (hi.y + lo.y) * 0.5f; - m_bboxCenter.z = (hi.z + lo.z) * 0.5f; - m_bboxSize = hi - lo; + m_boundsCenter.x = (hi.x + lo.x) * 0.5f; + m_boundsCenter.y = (hi.y + lo.y) * 0.5f; + m_boundsCenter.z = (hi.z + lo.z) * 0.5f; + m_boundsSize = hi - lo; } } - pBBox->center = m_bboxCenter; - pBBox->size = m_bboxSize; + pBBox->center = m_boundsCenter; + pBBox->size = m_boundsSize; } // CGroup::GetRadius() @@ -248,8 +248,8 @@ CTransform::CTransform() : m_timeScaleStart(0.0), m_timeRotationStart(0.0), m_timeTranslationStart(0.0), - m_timeAlphaStart(0.0), - m_timeToDisappear(0.0) + m_fadeStartTime(0.0), + m_hideTime(0.0) { } @@ -259,7 +259,7 @@ CTransform::CTransform() : void CTransform::OnLoad() { CGroup::OnLoad(); - D3DXQuaternionRotationAxis(&m_rotationQuat, (D3DXVECTOR3*)&m_rotation, m_rotation.w); + D3DXQuaternionRotationAxis(&m_orientQuat, (D3DXVECTOR3*)&m_rotation, m_rotation.w); } // CTransform::OnSetProperty(pprd, pvValue) @@ -275,7 +275,7 @@ bool CTransform::OnSetProperty(const PRD* pprd, const void* pvValue) if (offset == offsetof(m_rotation)) { const float* axisAngle = (const float*)pvValue; - D3DXQuaternionRotationAxis(&m_rotationQuat, (const D3DXVECTOR3*)axisAngle, axisAngle[3]); + D3DXQuaternionRotationAxis(&m_orientQuat, (const D3DXVECTOR3*)axisAngle, axisAngle[3]); } else if (offset == offsetof(m_alpha)) { @@ -309,15 +309,15 @@ void CTransform::Advance(float nSeconds) { CGroup::Advance(nSeconds); - if (m_timeAlphaStart > 0.0) + if (m_fadeStartTime > 0.0) { - float t = FadeStep(m_timeAlphaStart, m_fade); - m_alpha = m_alphaStart + (m_alphaEnd - m_alphaStart) * t; + float t = FadeStep(m_fadeStartTime, m_fade); + m_alpha = m_fadeFrom + (m_fadeTo - m_fadeFrom) * t; } - if (m_timeToDisappear > 0.0 && m_timeToDisappear <= TheseusGetNow()) + if (m_hideTime > 0.0 && m_hideTime <= TheseusGetNow()) { - m_timeToDisappear = 0.0; + m_hideTime = 0.0; m_alpha = 0.0f; } } @@ -331,27 +331,27 @@ void CTransform::Advance(float nSeconds) // still running (sum of their clocks > 0). void CTransform::CalcMatrix() { - D3DXMatrixIdentity(&m_matrix); + D3DXMatrixIdentity(&m_xform); if (m_timeScaleStart > 0.0) { m_moving = true; float t = FadeStep(m_timeScaleStart, m_fade); - D3DXVec3Lerp(&m_scale, &m_scaleStart, &m_scaleEnd, t); + D3DXVec3Lerp(&m_scale, &m_scaleFrom, &m_scaleTo, t); } if (m_timeTranslationStart > 0.0) { m_moving = true; float t = FadeStep(m_timeTranslationStart, m_fade); - D3DXVec3Lerp(&m_translation, &m_translationStart, &m_translationEnd, t); + D3DXVec3Lerp(&m_translation, &m_moveFrom, &m_moveTo, t); } if (m_timeRotationStart > 0.0) { m_moving = true; float t = FadeStep(m_timeRotationStart, m_fade); - D3DXQuaternionSlerp(&m_rotationQuat, &m_rotationStart, &m_rotationEnd, t); + D3DXQuaternionSlerp(&m_orientQuat, &m_turnFrom, &m_turnTo, t); } D3DXMATRIX step; @@ -359,19 +359,19 @@ void CTransform::CalcMatrix() if (m_scale.x != 1.0f || m_scale.y != 1.0f || m_scale.z != 1.0f) { D3DXMatrixScaling(&step, m_scale.x, m_scale.y, m_scale.z); - D3DXMatrixMultiply(&m_matrix, &m_matrix, &step); + D3DXMatrixMultiply(&m_xform, &m_xform, &step); } - if (m_rotationQuat.w != 0.0f) + if (m_orientQuat.w != 0.0f) { - D3DXMatrixRotationQuaternion(&step, &m_rotationQuat); - D3DXMatrixMultiply(&m_matrix, &m_matrix, &step); + D3DXMatrixRotationQuaternion(&step, &m_orientQuat); + D3DXMatrixMultiply(&m_xform, &m_xform, &step); } if (m_translation.x != 0.0f || m_translation.y != 0.0f || m_translation.z != 0.0f) { D3DXMatrixTranslation(&step, m_translation.x, m_translation.y, m_translation.z); - D3DXMatrixMultiply(&m_matrix, &m_matrix, &step); + D3DXMatrixMultiply(&m_xform, &m_xform, &step); } m_dirty = (m_timeScaleStart + m_timeTranslationStart + m_timeRotationStart) > 0.0; @@ -389,8 +389,8 @@ void CTransform::SetScale(float sx, float sy, float sz) if (m_fade > 0.0f) { m_timeScaleStart = TheseusGetNow(); - m_scaleStart = m_scale; - m_scaleEnd = target; + m_scaleFrom = m_scale; + m_scaleTo = target; m_moving = true; } else @@ -419,8 +419,8 @@ void CTransform::SetTranslation(float x, float y, float z) if (m_fade > 0.0f) { m_timeTranslationStart = TheseusGetNow(); - m_translationStart = m_translation; - m_translationEnd = target; + m_moveFrom = m_translation; + m_moveTo = target; m_moving = true; } else @@ -456,14 +456,14 @@ void CTransform::SetRotation(float x, float y, float z, float a) if (m_fade > 0.0f) { m_timeRotationStart = TheseusGetNow(); - m_rotationStart = m_rotationQuat; - m_rotationEnd = q; + m_turnFrom = m_orientQuat; + m_turnTo = q; m_moving = true; } else { m_rotation = D3DXQUATERNION(x, y, z, a); - m_rotationQuat = q; + m_orientQuat = q; } m_dirty = TRUE; } @@ -476,9 +476,9 @@ void CTransform::SetAlpha(float a) { if (m_fade > 0.0f) { - m_timeAlphaStart = TheseusGetNow(); - m_alphaStart = m_alpha; - m_alphaEnd = a; + m_fadeStartTime = TheseusGetNow(); + m_fadeFrom = m_alpha; + m_fadeTo = a; } else { @@ -492,7 +492,7 @@ void CTransform::SetAlpha(float a) // The binary adds in single precision; Theseus keeps the double clock. void CTransform::DisappearAfter(float t) { - m_timeToDisappear = t + TheseusGetNow(); + m_hideTime = t + TheseusGetNow(); } // CTransform::Render() @@ -511,7 +511,7 @@ void CTransform::Render() CalcMatrix(); TheseusPushWorld(); - TheseusMultWorld(&m_matrix); + TheseusMultWorld(&m_xform); TheseusUpdateWorld(); if (m_alpha > 0.0f) @@ -543,7 +543,7 @@ class CInline : public CGroup TCHAR* m_url; bool m_preload; - bool m_bClassLoaded; + bool m_bClassReady; bool m_fadeInDelayLoad; void Render(); @@ -554,8 +554,8 @@ class CInline : public CGroup void FinishLoad(); bool m_dirty; - bool m_bLoading; - bool m_bFirstLoad; + bool m_bLoadPending; + bool m_bInitialLoad; CXipFile* m_xipFile; XTIME m_timeOfLoad; @@ -569,8 +569,8 @@ class CInline : public CGroup #endif private: - HANDLE m_hClassLoaderThread; - TCHAR m_szAbsURL[MAX_PATH]; + HANDLE m_hLoadThread; + TCHAR m_szFullUrl[MAX_PATH]; }; IMPLEMENT_NODE("Inline", CInline, CGroup) @@ -588,14 +588,14 @@ END_NODE_PROPS() CInline::CInline() : m_url(NULL), m_preload(false), - m_bClassLoaded(false), + m_bClassReady(false), m_fadeInDelayLoad(true), m_dirty(true), - m_bLoading(false), - m_bFirstLoad(false), + m_bLoadPending(false), + m_bInitialLoad(false), m_xipFile(NULL), m_timeOfLoad(0.0), - m_hClassLoaderThread(NULL) + m_hLoadThread(NULL) { } @@ -631,15 +631,15 @@ void CInline::Init() if (slash != NULL) { _tcscpy(slash, _T(".xip")); - m_bLoading = true; - m_bFirstLoad = true; + m_bLoadPending = true; + m_bInitialLoad = true; m_xipFile = LoadXIP(xipPath); if (m_xipFile != NULL) return; - m_bLoading = false; + m_bLoadPending = false; } - MakeAbsoluteURL(m_szAbsURL, m_url); + MakeAbsoluteURL(m_szFullUrl, m_url); FinishLoad(); } @@ -654,7 +654,7 @@ void CInline::FinishLoad() { long long started = Frame_Now(); - if (m_classDef.LoadAbsURL(m_szAbsURL)) + if (m_classDef.LoadAbsURL(m_szFullUrl)) { CNode* root = m_classDef.CreateNode(); CallFunction(root, _T("initialize")); @@ -663,8 +663,8 @@ void CInline::FinishLoad() CallFunction(this, _T("onLoad")); } - m_bFirstLoad = false; - m_bClassLoaded = true; + m_bInitialLoad = false; + m_bClassReady = true; Frame_NoteLoad(Frame_Ms(Frame_Now() - started)); } @@ -679,12 +679,12 @@ void CInline::FinishLoad() // directory. See docs/decomp/SceneGroups.md. void CInline::Render() { - if (m_url == NULL || m_bLoading) + if (m_url == NULL || m_bLoadPending) return; if (m_xipFile != NULL && m_xipFile->IsUnloaded()) { - m_bLoading = true; + m_bLoadPending = true; m_xipFile->Reload(); return; } @@ -692,7 +692,7 @@ void CInline::Render() if (m_dirty) Init(); - if (m_bLoading || !m_bClassLoaded) + if (m_bLoadPending || !m_bClassReady) return; float fadeIn = 1.0f; @@ -730,26 +730,26 @@ void CInline::Advance(float nSeconds) if (m_xipFile != NULL && !m_xipFile->IsReady()) { - m_bLoading = true; + m_bLoadPending = true; return; } - if (m_bLoading) + if (m_bLoadPending) { - m_bLoading = false; - if (m_bFirstLoad) + m_bLoadPending = false; + if (m_bInitialLoad) { - MakeAbsoluteURL(m_szAbsURL, m_url); - if (m_hClassLoaderThread == NULL) + MakeAbsoluteURL(m_szFullUrl, m_url); + if (m_hLoadThread == NULL) FinishLoad(); } m_timeOfLoad = TheseusGetNow(); } - if (m_hClassLoaderThread != NULL && WaitForSingleObject(m_hClassLoaderThread, 0) == WAIT_OBJECT_0) + if (m_hLoadThread != NULL && WaitForSingleObject(m_hLoadThread, 0) == WAIT_OBJECT_0) { - CloseHandle(m_hClassLoaderThread); - m_hClassLoaderThread = NULL; + CloseHandle(m_hLoadThread); + m_hLoadThread = NULL; } CGroup::Advance(nSeconds); @@ -1169,7 +1169,7 @@ class CBillboard : public CGroup void Render(); - D3DXMATRIX m_matrix; + D3DXMATRIX m_xform; void CalcMatrix(); DECLARE_NODE_PROPS() @@ -1204,7 +1204,7 @@ void CBillboard::Render() CalcMatrix(); TheseusPushWorld(); - TheseusMultWorld(&m_matrix); + TheseusMultWorld(&m_xform); TheseusUpdateWorld(); CGroup::Render(); @@ -1242,7 +1242,7 @@ void CBillboard::CalcMatrix() D3DXVec3Cross(&side, &up, &eye); D3DXVec3Normalize(&side, &side); - m_matrix = D3DXMATRIX( + m_xform = D3DXMATRIX( side.x, side.y, side.z, 0.0f, up.x, up.y, up.z, 0.0f, eye.x, eye.y, eye.z, 0.0f, @@ -1261,7 +1261,7 @@ void CBillboard::CalcMatrix() if (side.z > 0.0f) angle = -angle; - D3DXMatrixRotationAxis(&m_matrix, &axis, angle); + D3DXMatrixRotationAxis(&m_xform, &axis, angle); } @@ -1461,13 +1461,13 @@ void CLayer::Render() D3DXVECTOR3 eyeAt(viewpoint->m_position.x, viewpoint->m_position.y, -viewpoint->m_position.z); D3DXQUATERNION facing; D3DXQuaternionRotationAxis(&facing, (const D3DXVECTOR3*)&viewpoint->m_orientation, -viewpoint->m_orientation.w); - D3DXMatrixAffineTransformation(&g_matView, 1.0f, NULL, &facing, &eyeAt); - D3DXMatrixInverse(&g_matView, NULL, &g_matView); - g_matView._31 = -g_matView._31; - g_matView._32 = -g_matView._32; - g_matView._33 = -g_matView._33; - g_matView._34 = -g_matView._34; - TheseusSetTransform(D3DTS_VIEW, &g_matView); + D3DXMatrixAffineTransformation(&g_viewMatrix, 1.0f, NULL, &facing, &eyeAt); + D3DXMatrixInverse(&g_viewMatrix, NULL, &g_viewMatrix); + g_viewMatrix._31 = -g_viewMatrix._31; + g_viewMatrix._32 = -g_viewMatrix._32; + g_viewMatrix._33 = -g_viewMatrix._33; + g_viewMatrix._34 = -g_viewMatrix._34; + TheseusSetTransform(D3DTS_VIEW, &g_viewMatrix); TheseusPushWorld(); TheseusIdentityWorld(); @@ -1476,7 +1476,7 @@ void CLayer::Render() TheseusPopWorld(); g_matProjection = savedProjection; - g_matView = savedView; + g_viewMatrix = savedView; TheseusSetTransform(D3DTS_PROJECTION, &savedProjection); TheseusSetTransform(D3DTS_WORLD, &savedWorld); TheseusSetTransform(D3DTS_VIEW, &savedView); @@ -1525,11 +1525,11 @@ CBackground::CBackground() : m_skyColor(0.0f, 0.0f, 0.0f), m_isBound(false), m_fade(0.0f), - m_timeAlphaStart(0.0), - m_alphaStart(0.0f), - m_alphaEnd(0.0f), + m_fadeStartTime(0.0), + m_fadeFrom(0.0f), + m_fadeTo(0.0f), m_alpha(1.0f), - m_timeToDisappear(0.0), + m_hideTime(0.0), m_vb(NULL) { if (TheseusGetBackground() == NULL) @@ -1560,9 +1560,9 @@ void CBackground::SetAlpha(float a) { if (m_fade > 0.0f) { - m_timeAlphaStart = TheseusGetNow(); - m_alphaStart = m_alpha; - m_alphaEnd = a; + m_fadeStartTime = TheseusGetNow(); + m_fadeFrom = m_alpha; + m_fadeTo = a; } else { @@ -1576,7 +1576,7 @@ void CBackground::SetAlpha(float a) // The sum is single precision in the binary, kept that way here. void CBackground::DisappearAfter(float t) { - m_timeToDisappear = (double)(t + (float)TheseusGetNow()); + m_hideTime = (double)(t + (float)TheseusGetNow()); } // CBackground::Advance(nSeconds) @@ -1591,15 +1591,15 @@ void CBackground::Advance(float nSeconds) { CNode::Advance(nSeconds); - if (m_timeAlphaStart > 0.0) + if (m_fadeStartTime > 0.0) { - float t = FadeStep(m_timeAlphaStart, m_fade); - m_alpha = m_alphaStart + (m_alphaEnd - m_alphaStart) * t; + float t = FadeStep(m_fadeStartTime, m_fade); + m_alpha = m_fadeFrom + (m_fadeTo - m_fadeFrom) * t; } - if (m_timeToDisappear > 0.0 && m_timeToDisappear <= TheseusGetNow()) + if (m_hideTime > 0.0 && m_hideTime <= TheseusGetNow()) { - m_timeToDisappear = 0.0; + m_hideTime = 0.0; m_alpha = 0.0f; } @@ -1745,11 +1745,11 @@ bool CBackground::OnSetProperty(const PRD* pprd, const void* pvValue) // to a level cross fades from the current one over a second, through the // tunnel and camera path between them. -CLevel* g_pCurLevel; -CLevel* g_pFromLevel; -CNode* g_pCurTunnel; +CLevel* g_pActiveLevel; +CLevel* g_pLeavingLevel; +CNode* g_pActiveTunnel; XTIME g_timeToNextLevel; -bool g_bLevelTransition; +bool g_bLevelSwitching; IMPLEMENT_NODE("Level", CLevel, CGroup) @@ -1797,12 +1797,12 @@ CLevel::CLevel() : // archive name. CLevel::~CLevel() { - if (g_pCurLevel == this) - g_pCurLevel = NULL; - if (g_pFromLevel == this) - g_pFromLevel = NULL; - if (g_pCurTunnel == m_tunnel) - g_pCurTunnel = NULL; + if (g_pActiveLevel == this) + g_pActiveLevel = NULL; + if (g_pLeavingLevel == this) + g_pLeavingLevel = NULL; + if (g_pActiveTunnel == m_tunnel) + g_pActiveTunnel = NULL; if (m_tunnel != NULL) m_tunnel->Release(); @@ -1820,10 +1820,10 @@ CLevel::~CLevel() // Reconstructed from 5960 retail XBE @ 0x0005cd80. Ghidra decompile: // a = 1; // if (fade) { t = clamp((g_timeToNextLevel - now) * 1.3333334, 0, 1); -// if (this == g_pCurLevel) a = 1 - t; else if (this == g_pFromLevel) a = t; +// if (this == g_pActiveLevel) a = 1 - t; else if (this == g_pLeavingLevel) a = t; // if (a == 0) return; } // only reached for cur or from // effectAlpha *= a; if (shell) shell->Render(); -// if (this == g_pCurLevel) g_motionBlur = min(a * 1.3, 1); +// if (this == g_pActiveLevel) g_motionBlur = min(a * 1.3, 1); // CGroup::Render(); effectAlpha restored; // The 1.3333334 is 1 / 0.75: the cross fade runs over the last 0.75 s. void CLevel::Render() @@ -1838,9 +1838,9 @@ void CLevel::Render() else if (t < 0.0f) t = 0.0f; - if (this == g_pCurLevel) + if (this == g_pActiveLevel) a = 1.0f - t; - else if (this == g_pFromLevel) + else if (this == g_pLeavingLevel) a = t; if (a == 0.0f) @@ -1853,8 +1853,8 @@ void CLevel::Render() if (m_shell != NULL) m_shell->Render(); - if (this == g_pCurLevel) - g_transitionMotionBlur = a * 1.3f > 1.0f ? 1.0f : a * 1.3f; + if (this == g_pActiveLevel) + g_levelBlurAmount = a * 1.3f > 1.0f ? 1.0f : a * 1.3f; CGroup::Render(); @@ -1863,76 +1863,76 @@ void CLevel::Render() // CLevel::Activate() // Reconstructed from 5960 retail XBE @ 0x0005ce90. Ghidra decompile: -// g_bLevelTransition = 1; +// g_bLevelSwitching = 1; // if (archive && !xip) xip = LoadXIP(archive); -// if (g_pFromLevel) { from->Deactivate() inlined; g_timeToNextLevel = 0; g_pFromLevel = 0; } -// else if (!g_pCurLevel || g_timeToNextLevel == 0) goto start; -// if (g_pCurLevel) { cur->visible = 0; +// if (g_pLeavingLevel) { from->Deactivate() inlined; g_timeToNextLevel = 0; g_pLeavingLevel = 0; } +// else if (!g_pActiveLevel || g_timeToNextLevel == 0) goto start; +// if (g_pActiveLevel) { cur->visible = 0; // if (cur->xip && cur->unloadable && !cur->xip->locked) cur->xip->DeleteMeshBuffers(); } -// g_pCurLevel = 0; -// if (g_pCurTunnel) { g_pCurTunnel->visible = 0; g_pCurTunnel = 0; } +// g_pActiveLevel = 0; +// if (g_pActiveTunnel) { g_pActiveTunnel->visible = 0; g_pActiveTunnel = 0; } // start: // BindJoystick(0) inlined; g_timeToNextLevel = now + 1.0; -// g_pFromLevel = g_pCurLevel; visible = 1; g_pCurLevel = this; +// g_pLeavingLevel = g_pActiveLevel; visible = 1; g_pActiveLevel = this; // A transition still running is cut short: both its ends are hidden and the // new one fades in from nothing. void CLevel::Activate() { - g_bLevelTransition = true; + g_bLevelSwitching = true; if (m_archive != NULL && m_xipFile == NULL) m_xipFile = LoadXIP(m_archive); - bool midTransition = g_pFromLevel != NULL || (g_pCurLevel != NULL && g_timeToNextLevel != 0.0); + bool midTransition = g_pLeavingLevel != NULL || (g_pActiveLevel != NULL && g_timeToNextLevel != 0.0); if (midTransition) { - if (g_pFromLevel != NULL) + if (g_pLeavingLevel != NULL) { - g_pFromLevel->Deactivate(); - g_pFromLevel = NULL; + g_pLeavingLevel->Deactivate(); + g_pLeavingLevel = NULL; } - if (g_pCurLevel != NULL) + if (g_pActiveLevel != NULL) { - CLevel* cur = g_pCurLevel; + CLevel* cur = g_pActiveLevel; cur->m_visible = false; if (cur->m_xipFile != NULL && cur->m_unloadable && !cur->m_xipFile->m_locked) cur->m_xipFile->DeleteMeshBuffers(); - g_pCurLevel = NULL; + g_pActiveLevel = NULL; } - if (g_pCurTunnel != NULL) + if (g_pActiveTunnel != NULL) { - g_pCurTunnel->m_visible = false; - g_pCurTunnel = NULL; + g_pActiveTunnel->m_visible = false; + g_pActiveTunnel = NULL; } } BindJoystick(NULL); g_timeToNextLevel = TheseusGetNow() + 1.0; - g_pFromLevel = g_pCurLevel; + g_pLeavingLevel = g_pActiveLevel; m_visible = true; - g_pCurLevel = this; + g_pActiveLevel = this; } // CLevel::GoTo() [script fn 'GoTo', FND 0x00188478, sig 1] // Reconstructed from 5960 retail XBE @ 0x0005cf90. Ghidra decompile: -// if (this == g_pCurLevel) return; -// Activate(); g_pCurTunnel = tunnel; if (tunnel) tunnel->visible = 1; +// if (this == g_pActiveLevel) return; +// Activate(); g_pActiveTunnel = tunnel; if (tunnel) tunnel->visible = 1; // if (path is a Viewpoint) BindViewpoint(path); // else if (path is a CameraPath) { active = 1; start = now; backward = 0; } // CallFunction(this, "OnActivate"); // The CameraPath start is its Activate(false), inlined. void CLevel::GoTo() { - if (this == g_pCurLevel) + if (this == g_pActiveLevel) return; Activate(); - g_pCurTunnel = m_tunnel; - if (g_pCurTunnel != NULL) - g_pCurTunnel->m_visible = true; + g_pActiveTunnel = m_tunnel; + if (g_pActiveTunnel != NULL) + g_pActiveTunnel->m_visible = true; if (m_path != NULL) { @@ -1947,24 +1947,24 @@ void CLevel::GoTo() // CLevel::GoBackTo() [script fn 'GoBackTo', FND 0x00188490, sig 1] // Reconstructed from 5960 retail XBE @ 0x0005d040. Ghidra decompile: -// if (this == g_pCurLevel) return; -// Activate(); g_pCurTunnel = from ? from->tunnel : 0; -// if (g_pCurTunnel) g_pCurTunnel->visible = 1; +// if (this == g_pActiveLevel) return; +// Activate(); g_pActiveTunnel = from ? from->tunnel : 0; +// if (g_pActiveTunnel) g_pActiveTunnel->visible = 1; // if (from && from->path is a CameraPath) { path: active = 1; start = now; backward = 1; } // else if (path is a Viewpoint) BindViewpoint(path); // CallFunction(this, "OnActivate"); // Going back runs the level we're leaving's tunnel and path in reverse. void CLevel::GoBackTo() { - if (this == g_pCurLevel) + if (this == g_pActiveLevel) return; Activate(); - CLevel* from = g_pFromLevel; - g_pCurTunnel = from != NULL ? from->m_tunnel : NULL; - if (g_pCurTunnel != NULL) - g_pCurTunnel->m_visible = true; + CLevel* from = g_pLeavingLevel; + g_pActiveTunnel = from != NULL ? from->m_tunnel : NULL; + if (g_pActiveTunnel != NULL) + g_pActiveTunnel->m_visible = true; if (from != NULL && from->m_path != NULL && from->m_path->IsKindOf(NODE_CLASS(CCameraPath))) ((CCameraPath*)from->m_path)->Activate(true); @@ -1977,12 +1977,12 @@ void CLevel::GoBackTo() // CLevel::Advance(nSeconds) // Reconstructed from 5960 retail XBE @ 0x0005d120. Ghidra decompile: // CGroup::Advance(dt); tunnel, path, control, shell ->Advance(dt) when set; -// if (this == g_pCurLevel && g_timeToNextLevel != 0 && g_timeToNextLevel <= now) { -// g_timeToNextLevel = 0; if (g_pCurTunnel) g_pCurTunnel->visible = 0; -// if (g_pFromLevel) { g_pFromLevel->Deactivate(); g_pFromLevel = 0; } +// if (this == g_pActiveLevel && g_timeToNextLevel != 0 && g_timeToNextLevel <= now) { +// g_timeToNextLevel = 0; if (g_pActiveTunnel) g_pActiveTunnel->visible = 0; +// if (g_pLeavingLevel) { g_pLeavingLevel->Deactivate(); g_pLeavingLevel = 0; } // arrive = 1; } // if (arrive && (!xip || xip->loaded)) { arrive = 0; BindJoystick(control); -// CallFunction(this, "OnArrival"); g_bLevelTransition = 0; } +// CallFunction(this, "OnArrival"); g_bLevelSwitching = 0; } // Arrival waits for the level's XIP before handing over the controller. void CLevel::Advance(float nSeconds) { @@ -1997,15 +1997,15 @@ void CLevel::Advance(float nSeconds) if (m_shell != NULL) m_shell->Advance(nSeconds); - if (this == g_pCurLevel && g_timeToNextLevel != 0.0 && g_timeToNextLevel <= TheseusGetNow()) + if (this == g_pActiveLevel && g_timeToNextLevel != 0.0 && g_timeToNextLevel <= TheseusGetNow()) { g_timeToNextLevel = 0.0; - if (g_pCurTunnel != NULL) - g_pCurTunnel->m_visible = false; - if (g_pFromLevel != NULL) + if (g_pActiveTunnel != NULL) + g_pActiveTunnel->m_visible = false; + if (g_pLeavingLevel != NULL) { - g_pFromLevel->Deactivate(); - g_pFromLevel = NULL; + g_pLeavingLevel->Deactivate(); + g_pLeavingLevel = NULL; } m_bArrive = true; } @@ -2015,7 +2015,7 @@ void CLevel::Advance(float nSeconds) m_bArrive = false; BindJoystick(m_control); CallFunction(this, _T("OnArrival")); - g_bLevelTransition = false; + g_bLevelSwitching = false; } } @@ -2132,8 +2132,8 @@ bool CInline::ReloadFromText(const char* xapText) { pNode->m_parent = this; CallFunction(this, "onLoad"); - m_bClassLoaded = true; - m_bLoading = false; + m_bClassReady = true; + m_bLoadPending = false; m_timeOfLoad = TheseusGetNow(); return true; diff --git a/theseus/render/scene_groups.h b/theseus/render/scene_groups.h index ae73ea1..3ae4d90 100644 --- a/theseus/render/scene_groups.h +++ b/theseus/render/scene_groups.h @@ -28,11 +28,11 @@ class CBackground : public CNode D3DXVECTOR3 m_skyColor; bool m_isBound; float m_fade; // seconds SetAlpha takes to get there - XTIME m_timeAlphaStart; - float m_alphaStart; - float m_alphaEnd; + XTIME m_fadeStartTime; + float m_fadeFrom; + float m_fadeTo; float m_alpha; - XTIME m_timeToDisappear; + XTIME m_hideTime; LPDIRECT3DVERTEXBUFFER8 m_vb; }; diff --git a/theseus/render/shape_render.cpp b/theseus/render/shape_render.cpp index 6761de0..11902bb 100644 --- a/theseus/render/shape_render.cpp +++ b/theseus/render/shape_render.cpp @@ -16,8 +16,8 @@ #include "camera.h" extern class CMeshNode* g_pRenderMeshNode; -extern D3DXMATRIX g_matPosition; -extern D3DXMATRIX g_matView; +extern D3DXMATRIX g_cameraWorld; +extern D3DXMATRIX g_viewMatrix; extern D3DXMATRIX g_matProjection; @@ -366,7 +366,7 @@ class CBox : public CNode D3DXVECTOR3 m_size; - IDirect3DVertexBuffer8* m_pVB; + IDirect3DVertexBuffer8* m_pVerts; IDirect3DIndexBuffer8* m_pIB; D3DVERTEX m_vertices [24]; @@ -389,7 +389,7 @@ END_NODE_PROPS() // ~: release vb, then ib (D3D resource release inlined) CBox::CBox() : m_size(1.0f, 1.0f, 1.0f), - m_pVB(NULL), + m_pVerts(NULL), m_pIB(NULL), m_dirty(true) { @@ -397,8 +397,8 @@ CBox::CBox() : CBox::~CBox() { - if (m_pVB) - m_pVB->Release(); + if (m_pVerts) + m_pVerts->Release(); if (m_pIB) m_pIB->Release(); } @@ -423,20 +423,20 @@ void CBox::Render() BYTE* pDst; - if (m_pVB == NULL) + if (m_pVerts == NULL) { - TheseusCreateVertexBuffer(sizeof (m_vertices), D3DUSAGE_DYNAMIC, D3DFVF_VERTEX, D3DPOOL_MANAGED, &m_pVB); - if (m_pVB != NULL) + TheseusCreateVertexBuffer(sizeof (m_vertices), D3DUSAGE_DYNAMIC, D3DFVF_VERTEX, D3DPOOL_MANAGED, &m_pVerts); + if (m_pVerts != NULL) { - if (FAILED(m_pVB->Lock(0, sizeof (m_vertices), &pDst, 0))) + if (FAILED(m_pVerts->Lock(0, sizeof (m_vertices), &pDst, 0))) { - m_pVB->Release(); - m_pVB = NULL; + m_pVerts->Release(); + m_pVerts = NULL; } else { memcpy(pDst, m_vertices, sizeof (m_vertices)); - m_pVB->Unlock(); + m_pVerts->Unlock(); } } } @@ -459,10 +459,10 @@ void CBox::Render() } } - if (m_pVB == NULL || m_pIB == NULL) + if (m_pVerts == NULL || m_pIB == NULL) return; - TheseusSetStreamSource(0, m_pVB, sizeof (D3DVERTEX)); + TheseusSetStreamSource(0, m_pVerts, sizeof (D3DVERTEX)); TheseusSetIndices(m_pIB, 0); TheseusSetVertexShader(D3DFVF_VERTEX); TheseusDrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 24, 0, 12); @@ -865,7 +865,7 @@ static void SetLightDirection(DWORD reg, const D3DXMATRIX& worldView) void SetReflectShaderFrameValues() { D3DXMATRIX worldView, t; - D3DXMatrixMultiply(&worldView, TheseusGetWorld(), &g_matView); + D3DXMatrixMultiply(&worldView, TheseusGetWorld(), &g_viewMatrix); D3DXMatrixTranspose(&t, &worldView); TheseusSetVertexShaderConstant(40, &t, 4); @@ -896,7 +896,7 @@ void SetFalloffShaderFrameValues() FramePhaseScope world(FP_TREE_WORLD); D3DXMATRIX worldView, t; - D3DXMatrixMultiply(&worldView, TheseusGetWorld(), &g_matView); + D3DXMatrixMultiply(&worldView, TheseusGetWorld(), &g_viewMatrix); D3DXMatrixMultiply(&t, &worldView, &g_matProjection); D3DXMatrixTranspose(&t, &t); diff --git a/theseus/render/shape_render.h b/theseus/render/shape_render.h index c317db4..a717c32 100755 --- a/theseus/render/shape_render.h +++ b/theseus/render/shape_render.h @@ -90,7 +90,7 @@ class CMaterial : public CNode }; // Each animated field keeps a start and end value and the time its move -// began; Advance blends them and CalcMatrix rebuilds m_matrix. +// began; Advance blends them and CalcMatrix rebuilds m_xform. class CTransform : public CGroup { DECLARE_NODE(CTransform, CGroup) @@ -118,28 +118,28 @@ class CTransform : public CGroup D3DXVECTOR3 m_center; D3DXQUATERNION m_scaleOrientation; D3DXVECTOR3 m_scale; - D3DXQUATERNION m_rotationQuat; + D3DXQUATERNION m_orientQuat; D3DXVECTOR3 m_translation; D3DXVECTOR3 m_centerStart; D3DXQUATERNION m_scaleOrientationStart; - D3DXVECTOR3 m_scaleStart; - D3DXQUATERNION m_rotationStart; - D3DXVECTOR3 m_translationStart; + D3DXVECTOR3 m_scaleFrom; + D3DXQUATERNION m_turnFrom; + D3DXVECTOR3 m_moveFrom; D3DXVECTOR3 m_centerEnd; D3DXQUATERNION m_scaleOrientationEnd; - D3DXVECTOR3 m_scaleEnd; - D3DXQUATERNION m_rotationEnd; - D3DXVECTOR3 m_translationEnd; + D3DXVECTOR3 m_scaleTo; + D3DXQUATERNION m_turnTo; + D3DXVECTOR3 m_moveTo; float m_alpha; - float m_alphaStart; - float m_alphaEnd; + float m_fadeFrom; + float m_fadeTo; bool m_moving; BOOL m_dirty; - D3DXMATRIX m_matrix; + D3DXMATRIX m_xform; float m_fade; float m_timeCenterStart; @@ -147,6 +147,6 @@ class CTransform : public CGroup XTIME m_timeScaleStart; XTIME m_timeRotationStart; XTIME m_timeTranslationStart; - XTIME m_timeAlphaStart; - XTIME m_timeToDisappear; + XTIME m_fadeStartTime; + XTIME m_hideTime; }; diff --git a/theseus/render/starfield.cpp b/theseus/render/starfield.cpp index 599d876..cc3b6bd 100755 --- a/theseus/render/starfield.cpp +++ b/theseus/render/starfield.cpp @@ -27,7 +27,7 @@ class CStarField : public CNode protected: int m_nAllocStars; - D3DXVECTOR3* m_rgstar; + D3DXVECTOR3* m_starPool; void Update(); DECLARE_NODE_PROPS() @@ -48,14 +48,14 @@ CStarField::CStarField() m_stars = 20; m_speed = 1.0f; m_nAllocStars = 0; - m_rgstar = NULL; + m_starPool = NULL; } // CStarField::~CStarField() // Reconstructed from 5960 retail XBE @ 0x00060410: frees the array, then CNode. CStarField::~CStarField() { - delete [] m_rgstar; + delete [] m_starPool; } // CStarField::Update() @@ -68,19 +68,19 @@ CStarField::~CStarField() // New stars start at z = 0, so the next Advance scatters them. void CStarField::Update() { - if (m_rgstar != NULL && m_stars <= m_nAllocStars) + if (m_starPool != NULL && m_stars <= m_nAllocStars) return; D3DXVECTOR3* grown = new D3DXVECTOR3 [m_stars]; memset(grown, 0, m_stars * sizeof (D3DXVECTOR3)); - if (m_rgstar != NULL) + if (m_starPool != NULL) { - memcpy(grown, m_rgstar, m_nAllocStars * sizeof (D3DXVECTOR3)); - delete [] m_rgstar; + memcpy(grown, m_starPool, m_nAllocStars * sizeof (D3DXVECTOR3)); + delete [] m_starPool; } - m_rgstar = grown; + m_starPool = grown; m_nAllocStars = m_stars; } @@ -103,7 +103,7 @@ void CStarField::Advance(float nSeconds) for (int i = 0; i < m_stars; i++) { - D3DXVECTOR3& star = m_rgstar[i]; + D3DXVECTOR3& star = m_starPool[i]; star.z -= m_speed * nSeconds; if (star.z > 0.0f) continue; @@ -139,7 +139,7 @@ void CStarField::RenderDynamicTexture(CSurfx* pSurfx) for (int i = 0; i < m_stars; i++) { - D3DXVECTOR3& star = m_rgstar[i]; + D3DXVECTOR3& star = m_starPool[i]; if (!(star.z > 0.0f)) continue; diff --git a/theseus/shared/audio_system.cpp b/theseus/shared/audio_system.cpp index 8de19ba..7fc8a3a 100755 --- a/theseus/shared/audio_system.cpp +++ b/theseus/shared/audio_system.cpp @@ -23,7 +23,7 @@ // removeVoice of the clip that advanced last (5960 keeps it at 0x17e768). bool g_removeVoice = false; -extern bool g_bLevelTransition; +extern bool g_bLevelSwitching; static DWORD LoopFlag(bool loop) { @@ -1072,7 +1072,7 @@ void CAudioClip::Advance(float nSeconds) if (m_pause_on_moving && m_sound != NULL && m_volume != 0.0f) { - if (g_bLevelTransition) + if (g_bLevelSwitching) { if (!m_sound->IsPaused()) { @@ -1337,7 +1337,7 @@ void CPeriodicAudioGroup::Advance(float nSeconds) { CGroup::Advance(nSeconds); - if (m_pause_on_moving && g_bLevelTransition) + if (m_pause_on_moving && g_bLevelSwitching) { if (m_playing != NULL && m_playing->IsKindOf(NODE_CLASS(CAudioClip))) m_playing->Stop(); diff --git a/theseus/xbox/main.cpp b/theseus/xbox/main.cpp index 1a5bce5..55690fc 100644 --- a/theseus/xbox/main.cpp +++ b/theseus/xbox/main.cpp @@ -40,7 +40,7 @@ extern void Class_Exit(); extern void DiscDrive_Init(); -extern void BackgroundLoader_Frame(); +extern void AssetLoader_Pump(); extern void Text_Exit(); @@ -201,11 +201,11 @@ DWORD g_dwMainThreadId = 0; -D3DXMATRIX g_matView; -D3DXMATRIX g_matPosition; +D3DXMATRIX g_viewMatrix; +D3DXMATRIX g_cameraWorld; D3DXMATRIX g_matProjection; -D3DRECT g_scissorRect; -D3DRECT g_scissorRectx2; +D3DRECT g_clipRect; +D3DRECT g_clipRect2x; D3DXMATRIX g_matIdentity( 1.0f, 0.0f, 0.0f, 0.0f, @@ -314,7 +314,7 @@ HRESULT InitAudio() } DWORD theseus_rgdwRenderStateCache[256]; bool theseus_rgbRenderStateCache[256]; -float g_transitionMotionBlur; +float g_levelBlurAmount; // XboxInitRenderState() // Reconstructed from 5960 retail XBE @ 0x0002c660: sets the startup render @@ -388,7 +388,7 @@ void XboxInitRenderState() for (int i = 0; i < (int)countof(states); i++) TheseusSetRenderState(states[i].state, states[i].value); - g_transitionMotionBlur = 1.0f; + g_levelBlurAmount = 1.0f; } // InitD3D() @@ -557,19 +557,19 @@ bool InitD3D() pFrontBuffer->GetDesc(&d3dsd); pFrontBuffer->Release(); - g_scissorRect.x1 = 0; - g_scissorRect.y1 = 0; - g_scissorRect.x2 = d3dsd.Width; - g_scissorRect.y2 = d3dsd.Height; + g_clipRect.x1 = 0; + g_clipRect.y1 = 0; + g_clipRect.x2 = d3dsd.Width; + g_clipRect.y2 = d3dsd.Height; g_pD3DDev->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pFrontBuffer); pFrontBuffer->GetDesc(&d3dsd); pFrontBuffer->Release(); - g_scissorRectx2.x1 = 0; - g_scissorRectx2.y1 = 0; - g_scissorRectx2.x2 = d3dsd.Width; - g_scissorRectx2.y2 = d3dsd.Height; + g_clipRect2x.x1 = 0; + g_clipRect2x.y1 = 0; + g_clipRect2x.x2 = d3dsd.Width; + g_clipRect2x.y2 = d3dsd.Height; XboxInitRenderState(); @@ -708,7 +708,7 @@ static void SetupLights() ambient.b += light.Ambient.b; D3DXVECTOR3 dir(0.0f, 0.0f, -1.0f); - D3DXVec3TransformNormal(&dir, &dir, &g_matPosition); + D3DXVec3TransformNormal(&dir, &dir, &g_cameraWorld); light.Direction = dir; TheseusSetLight(nLights, &light); @@ -748,7 +748,7 @@ void Draw() TheseusSetRenderState(D3DRS_FILLMODE, g_bWireframe ? D3DFILL_WIREFRAME : D3DFILL_SOLID); // A bigger factor means less blur. - const float blurAlpha = g_transitionMotionBlur; + const float blurAlpha = g_levelBlurAmount; D3DCOLOR sky = D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.3f, 1.0f); bool bBackdrop = false; @@ -1183,7 +1183,7 @@ void Advance() CLerper::AdvanceAll(); g_pObject->Advance(nDelta); - BackgroundLoader_Frame(); + AssetLoader_Pump(); #ifdef _DEBUG Debug_Frame(); From d7c2ea91508d5a6ebc031f21eba4ffb08486db7e Mon Sep 17 00:00:00 2001 From: Milenko <39630670+MrMilenko@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:55:06 -0500 Subject: [PATCH 6/8] Renamed material, texture, text and locale state Material colors, palette blending, the audio visualizer buffers, the image cache, the text edit cursor and the current language and region globals got names of their own. Compiled code is unchanged. --- docs/decomp/AssetLoader.md | 2 +- docs/decomp/ShapeRender.md | 4 +- theseus/desktop/dashinit.cpp | 2 +- theseus/desktop/desktop_nodes.cpp | 78 +++++----- theseus/desktop/inspector.cpp | 4 +- theseus/engine/locale_node.cpp | 38 ++--- theseus/engine/locale_node.h | 54 +++---- theseus/render/asset_loader.cpp | 72 ++++----- theseus/render/asset_loader.h | 10 +- theseus/render/hud_node.cpp | 8 +- theseus/render/materials.cpp | 216 ++++++++++++------------- theseus/render/materials_retail.inl | 26 ++-- theseus/render/shape_render.cpp | 10 +- theseus/render/text.cpp | 130 ++++++++-------- theseus/render/tmap_system.cpp | 234 ++++++++++++++-------------- theseus/shared/keyboard_node.cpp | 32 ++-- theseus/shared/savegame_grid.cpp | 26 ++-- theseus/xbox/config.cpp | 2 +- theseus/xbox/main.cpp | 2 +- theseus/xbox/panic_screen.cpp | 2 +- 20 files changed, 476 insertions(+), 476 deletions(-) diff --git a/docs/decomp/AssetLoader.md b/docs/decomp/AssetLoader.md index 18c58df..6776f42 100644 --- a/docs/decomp/AssetLoader.md +++ b/docs/decomp/AssetLoader.md @@ -183,7 +183,7 @@ CMeshNode::load(file): // 0x0005c250 Render stamps the time, loads on first use (the inlined `Initialize`: load if the url is set, then `Init`), and returns if there's still no mesh. Otherwise it draws with -`bSetFVF = (g_pRenderMeshNode != this)`: the shape renderer sets the FVF itself for the +`bSetFVF = (g_pDrawingShape != this)`: the shape renderer sets the FVF itself for the node it's drawing. The destructor `free`s an owned mesh without running its destructor, because the base class has no virtual one. diff --git a/docs/decomp/ShapeRender.md b/docs/decomp/ShapeRender.md index 2b22467..f8df0cc 100644 --- a/docs/decomp/ShapeRender.md +++ b/docs/decomp/ShapeRender.md @@ -49,14 +49,14 @@ for (cls = geometry->GetNodeClass(); cls; cls = cls->base) // class chain wa if (mesh->core == NULL) return; } if (mesh->core == NULL || mesh->core->GetFVF() == 0) return; - g_pRenderMeshNode /* 0x0017e758 */ = mesh; + g_pDrawingShape /* 0x0017e758 */ = mesh; SetVertexShader(GetFixedFunctionShader(fvf)); // 0x0005c740 break; } if (appearance) appearance->Render(); geometry->Render(); copy 16 dwords of the device's world matrix (pDevice + 0xde0); -position = row 3 (x, y, z); g_pRenderMeshNode = NULL; +position = row 3 (x, y, z); g_pDrawingShape = NULL; ``` **GetBBox (`0x00050eb0`)** tail calls the geometry's GetBBox, or zeroes all six floats. diff --git a/theseus/desktop/dashinit.cpp b/theseus/desktop/dashinit.cpp index 34fdc6a..8f38d84 100755 --- a/theseus/desktop/dashinit.cpp +++ b/theseus/desktop/dashinit.cpp @@ -135,7 +135,7 @@ void DashInit() TheseusCreateDirectory("e:\\TDATA\\fffe0000\\music", NULL); // Set current region - g_nCurRegion = 1; // NA + g_region = 1; // NA // Initialize skin system InitSkin(); diff --git a/theseus/desktop/desktop_nodes.cpp b/theseus/desktop/desktop_nodes.cpp index 06f640a..1590122 100644 --- a/theseus/desktop/desktop_nodes.cpp +++ b/theseus/desktop/desktop_nodes.cpp @@ -482,13 +482,13 @@ class CAudioVisualizer : public CNode void RenderEffect1(CSurfx* surface); void RenderEffect2(CSurfx* surface); - short m_pcmLeft[256]; // 0x030 - short m_pcmRight[256]; // 0x230 - short m_fftLeft[128]; // 0x430 - short m_fftRight[128]; // 0x530 - bool m_bFFTValid; // 0x630 + short m_waveL[256]; // 0x030 + short m_waveR[256]; // 0x230 + short m_specL[128]; // 0x430 + short m_specR[128]; // 0x530 + bool m_bHaveSpectrum; // 0x630 short m_pcmMono[256]; // 0x632 - bool m_bMonoValid; // 0x832 + bool m_bHaveMono; // 0x832 }; IMPLEMENT_NODE("AudioVisualizer", CAudioVisualizer, CNode) @@ -517,13 +517,13 @@ CAudioVisualizer::CAudioVisualizer() m_source = NULL; m_scale = 1.0f; m_offset = 0.0f; - m_bFFTValid = false; - m_bMonoValid = false; + m_bHaveSpectrum = false; + m_bHaveMono = false; - memset(m_pcmLeft, 0, sizeof (m_pcmLeft)); - memset(m_pcmRight, 0, sizeof (m_pcmRight)); - memset(m_fftLeft, 0, sizeof (m_fftLeft)); - memset(m_fftRight, 0, sizeof (m_fftRight)); + memset(m_waveL, 0, sizeof (m_waveL)); + memset(m_waveR, 0, sizeof (m_waveR)); + memset(m_specL, 0, sizeof (m_specL)); + memset(m_specR, 0, sizeof (m_specR)); memset(m_pcmMono, 0, sizeof (m_pcmMono)); } @@ -552,12 +552,12 @@ void CAudioVisualizer::Advance(float dt) // Theseus: 5960 has no mono mix. Average of the two channels, cached per frame. short* CAudioVisualizer::GetMonoPCM() { - if (m_bMonoValid) + if (m_bHaveMono) return m_pcmMono; for (int i = 0; i < 256; i++) - m_pcmMono[i] = (short)((m_pcmLeft[i] + m_pcmRight[i]) / 2); - m_bMonoValid = true; + m_pcmMono[i] = (short)((m_waveL[i] + m_waveR[i]) / 2); + m_bHaveMono = true; return m_pcmMono; } @@ -586,14 +586,14 @@ void CAudioVisualizer::CalcSpectrum(short* pcm, short* bins) // CAudioVisualizer::UpdateSpectrum() // Reconstructed from 5960 retail XBE @ 0x00063900: -// if (!m_bFFTValid) { CalcSpectrum(left); CalcSpectrum(right); m_bFFTValid = 1; } +// if (!m_bHaveSpectrum) { CalcSpectrum(left); CalcSpectrum(right); m_bHaveSpectrum = 1; } void CAudioVisualizer::UpdateSpectrum() { - if (!m_bFFTValid) + if (!m_bHaveSpectrum) { - CalcSpectrum(m_pcmLeft, m_fftLeft); - CalcSpectrum(m_pcmRight, m_fftRight); - m_bFFTValid = true; + CalcSpectrum(m_waveL, m_specL); + CalcSpectrum(m_waveR, m_specR); + m_bHaveSpectrum = true; } } @@ -639,9 +639,9 @@ static BYTE VizLevel(float n) // dot, and the spinner skips 5960's unused rand() call. void CAudioVisualizer::RenderDynamicTexture(CSurfx* surface) { - DashAudio_GetPCMSamples(m_pcmLeft, m_pcmRight, 256); - m_bMonoValid = false; - m_bFFTValid = false; + DashAudio_GetPCMSamples(m_waveL, m_waveR, 256); + m_bHaveMono = false; + m_bHaveSpectrum = false; const int w = surface->m_nWidth; const int h = surface->m_nHeight; @@ -650,9 +650,9 @@ void CAudioVisualizer::RenderDynamicTexture(CSurfx* surface) nFrames = h; // One channel, picked by m_channel. - const short* pcm = m_pcmLeft; + const short* pcm = m_waveL; if (m_channel != NULL && (m_channel[0] == 'r' || m_channel[0] == 'R')) - pcm = m_pcmRight; + pcm = m_waveR; TCHAR style = (m_type != NULL) ? m_type[0] : 0; if (style >= 'A' && style <= 'Z') @@ -726,9 +726,9 @@ void CAudioVisualizer::RenderDynamicTexture(CSurfx* surface) // Left spectrum high to low across the first half, right low to high after. for (int i = 0; i < 128; i++) - level[i] = VizLevel(logf((float)(m_fftLeft[127 - i] + 1)) * 8.0f); + level[i] = VizLevel(logf((float)(m_specL[127 - i] + 1)) * 8.0f); for (int i = 128; i < 256; i++) - level[i] = VizLevel(logf((float)(m_fftRight[i - 128] + 1)) * 8.0f); + level[i] = VizLevel(logf((float)(m_specR[i - 128] + 1)) * 8.0f); for (int i = 0; i < 256; i++) { @@ -794,7 +794,7 @@ void CAudioVisualizer::RenderEffect1(CSurfx* surface) int bass = 0; for (int i = 0; i < 5; i++) - bass += (m_fftLeft[i] >> 4) + (m_fftRight[i] >> 4); + bass += (m_specL[i] >> 4) + (m_specR[i] >> 4); bass /= 10; if (bass > s_bass.hiNow) @@ -876,7 +876,7 @@ void CAudioVisualizer::RenderEffect2(CSurfx* surface) s_waveSin[i] = sinf((float)i / w * 3.14159265f + 3.14159265f / 2.0f); } - float yA = (float)((((m_pcmLeft[0] + m_pcmRight[0]) >> 9) * amp * h) >> 12); + float yA = (float)((((m_waveL[0] + m_waveR[0]) >> 9) * amp * h) >> 12); float yB = yA; if (s_waveStyle == 3 && yA < 0) { @@ -892,8 +892,8 @@ void CAudioVisualizer::RenderEffect2(CSurfx* surface) float yAPrev = yA; float yBPrev = yB; int iFrame = (i << 8) / w / 5; - yA = (float)(((m_pcmRight[iFrame] >> 8) * amp * h) >> 12); - yB = (float)(((m_pcmLeft[iFrame] >> 8) * amp * h) >> 12); + yA = (float)(((m_waveR[iFrame] >> 8) * amp * h) >> 12); + yB = (float)(((m_waveL[iFrame] >> 8) * amp * h) >> 12); switch (s_waveStyle) { @@ -1844,8 +1844,8 @@ static void FormatSaveTime(char* buf, int bufSize, time_t t) } else buf[0] = 0; } -extern const TCHAR *g_szSelTitleImage; -extern const char *g_szCurTitleImage; +extern const TCHAR *g_szPickedTitleArt; +extern const char *g_szTitleArt; extern float g_nEffectAlpha; // ============================================================================ @@ -2079,9 +2079,9 @@ class CSavedGameGrid : public CNode snprintf(s_szImage, sizeof (s_szImage), "E:\\UDATA\\%s\\SaveImage.xbx", title.titleID); } - g_szCurTitleImage = s_szImage; + g_szTitleArt = s_szImage; RenderNodeAt(m_SavedIconPanel, &at); - g_szCurTitleImage = NULL; + g_szTitleArt = NULL; if (!m_detachIcon && m_iconRing != NULL && nTitle == m_curTitle && item == m_curGridItem) RenderNodeAt(m_iconRing, &at); @@ -2163,7 +2163,7 @@ class CSavedGameGrid : public CNode strcpy(s_szPodImage, "xboxlogo128.xbx"); } - g_szCurTitleImage = s_szPodImage; + g_szTitleArt = s_szPodImage; D3DXMATRIX at; D3DXMatrixTranslation(&at, xPod, y, zPod); D3DXMatrixMultiply(&at, &frame, &at); @@ -2172,7 +2172,7 @@ class CSavedGameGrid : public CNode RenderNodeAt(m_podSavePanel, &at); if (bSelected && m_curGridItem == -1 && m_podHilite != NULL) RenderNodeAt(m_podRing, &at); - g_szCurTitleImage = NULL; + g_szTitleArt = NULL; } if (bVisible) @@ -2346,11 +2346,11 @@ class CSavedGameGrid : public CNode return; strncpy(s_szSelImage, s_titles[m_curTitle].imagePath, sizeof (s_szSelImage) - 1); s_szSelImage[sizeof (s_szSelImage) - 1] = 0; - g_szSelTitleImage = s_szSelImage; + g_szPickedTitleArt = s_szSelImage; } else if (m_curTitle >= s_titleCount && m_curTitle < s_titleCount + s_iconCount) { - g_szSelTitleImage = s_iconEntries[m_curTitle - s_titleCount].iconPath; + g_szPickedTitleArt = s_iconEntries[m_curTitle - s_titleCount].iconPath; } } diff --git a/theseus/desktop/inspector.cpp b/theseus/desktop/inspector.cpp index 63045ef..b71224b 100644 --- a/theseus/desktop/inspector.cpp +++ b/theseus/desktop/inspector.cpp @@ -482,9 +482,9 @@ void RenderInspectorPanel(IDirect3DDevice8* dev) { ? (uintptr_t)baseTex->m_surface->m_bgfxTex.idx : 0; if (imguiTex) { ImGui::SameLine(); - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "%dx%d", baseTex->m_nImageWidth, baseTex->m_nImageHeight); + ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "%dx%d", baseTex->m_texWidth, baseTex->m_texHeight); float thumbH = 64.0f; - float aspect = baseTex->m_nImageWidth > 0 ? (float)baseTex->m_nImageWidth / baseTex->m_nImageHeight : 1.0f; + float aspect = baseTex->m_texWidth > 0 ? (float)baseTex->m_texWidth / baseTex->m_texHeight : 1.0f; float thumbW = thumbH * aspect; if (thumbW > ImGui::GetContentRegionAvail().x) thumbW = ImGui::GetContentRegionAvail().x; diff --git a/theseus/engine/locale_node.cpp b/theseus/engine/locale_node.cpp index b967b34..5bcaf15 100755 --- a/theseus/engine/locale_node.cpp +++ b/theseus/engine/locale_node.cpp @@ -20,8 +20,8 @@ // 5960 holds 550 pairs (0x0017aee8); the Theseus files can be longer. #define MAX_XLATE 1000 -int g_nCurLanguage; // 0x0017c024 -int g_nCurRegion; // 0x0017c020 +int g_language; // 0x0017c024 +int g_region; // 0x0017c020 // 5960 names an XBE section per language (pointer table at 0x001745b0, nine // of them); Theseus ships a .dat file for the first six. @@ -354,12 +354,12 @@ CTranslator::~CTranslator() // lists through DeleteAll so their names come back in the new language. void CTranslator::SetLanguage(int nNewLanguage) { - if (nNewLanguage == g_nCurLanguage && s_xlate[0].key != NULL) + if (nNewLanguage == g_language && s_xlate[0].key != NULL) return; if (nNewLanguage < 0 || nNewLanguage >= LANGUAGE_COUNT) return; - g_nCurLanguage = nNewLanguage; + g_language = nNewLanguage; FreeXlate(); LoadXlate(s_languageFiles[nNewLanguage]); @@ -400,13 +400,13 @@ CStrObject* CTranslator::TranslateStripColon(const TCHAR* szString) // The binary lets 9 through, one past "BR"; this stops at the last code. const TCHAR* GetLanguageCode(TCHAR* sz) { - if (g_nCurLanguage < 0 || g_nCurLanguage >= LANGUAGE_CODE_COUNT) + if (g_language < 0 || g_language >= LANGUAGE_CODE_COUNT) { sz[0] = 0; return sz; } - sz[0] = s_languageCodes[g_nCurLanguage * 2]; - sz[1] = s_languageCodes[g_nCurLanguage * 2 + 1]; + sz[0] = s_languageCodes[g_language * 2]; + sz[1] = s_languageCodes[g_language * 2 + 1]; sz[2] = 0; return sz; } @@ -416,9 +416,9 @@ const TCHAR* GetLanguageCode(TCHAR* sz) // string object, or an empty one out of range. CStrObject* CTranslator::GetLanguageCode() { - if (g_nCurLanguage < 0 || g_nCurLanguage >= LANGUAGE_CODE_COUNT) + if (g_language < 0 || g_language >= LANGUAGE_CODE_COUNT) return new CStrObject; - return new CStrObject(s_languageCodes + g_nCurLanguage * 2, 2); + return new CStrObject(s_languageCodes + g_language * 2, 2); } // GetDateSeparator() @@ -429,11 +429,11 @@ CStrObject* CTranslator::GetLanguageCode() // outside North America, and Korean dashes. TCHAR GetDateSeparator() { - int region = g_nCurRegion; + int region = g_region; if (region != XC_GAME_REGION_NA && region != XC_GAME_REGION_JAPAN && region != XC_GAME_REGION_RESTOFWORLD) return '/'; - switch (g_nCurLanguage) + switch (g_language) { case LANGUAGE_GERMAN: case LANGUAGE_ITALIAN: @@ -457,7 +457,7 @@ CStrObject* CTranslator::GetDateSeparator() // FormatInteger(out, number, locale) // 5960 has no separate copy; the script call (@ 0x0003ccb0) and the block // counts (@ 0x0004ca90) print with swprintf(out, L"%d", n) in place. -void FormatInteger(TCHAR* szBuf, int nNumber, int locale/*=LOCALE_CURRENT*/) +void FormatInteger(TCHAR* szBuf, int nNumber, int locale/*=LOCALE_ACTIVE*/) { _stprintf(szBuf, _T("%d"), nNumber); } @@ -465,7 +465,7 @@ void FormatInteger(TCHAR* szBuf, int nNumber, int locale/*=LOCALE_CURRENT*/) // FormatBlocks(out, blocks, locale) // Reconstructed from the memory monitor's block text, 5960 retail XBE // @ 0x0004ca90: past 50000 it prints "50000+". -void FormatBlocks(TCHAR* szBuf, int nBlocks, int locale/*=LOCALE_CURRENT*/) +void FormatBlocks(TCHAR* szBuf, int nBlocks, int locale/*=LOCALE_ACTIVE*/) { if (nBlocks <= MAX_BLOCKS_TO_SHOW) { @@ -521,10 +521,10 @@ static void PrintDate(TCHAR* out, int size, const SYSTEMTIME* st, int locale) // the three regions get "%d:%02d %s" on a 12 hour clock (0 shows as 12, AM // below 12); everyone else "%d:%02d" on 24. Both parts plus 2 must fit in // size or it returns false without writing. -bool FormatTime(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale/*=LOCALE_CURRENT*/) +bool FormatTime(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale/*=LOCALE_ACTIVE*/) { - if (locale == LOCALE_CURRENT) - locale = LOCALE_FROM_REGION_LANGUAGE(g_nCurRegion, g_nCurLanguage); + if (locale == LOCALE_ACTIVE) + locale = LOCALE_BY_REGION(g_region, g_language); TCHAR date[32]; PrintDate(date, countof(date), pst, locale); @@ -561,10 +561,10 @@ bool FormatTime(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale/*=LOCALE // anything else: "%02d%c%02d%c%d " day, month, year // if (chLen < len + 2) return false; copy; return true; // The Text node's prefix draws this. -bool FormatDate(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale/*=LOCALE_CURRENT*/) +bool FormatDate(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale/*=LOCALE_ACTIVE*/) { - if (locale == LOCALE_CURRENT) - locale = LOCALE_FROM_REGION_LANGUAGE(g_nCurRegion, g_nCurLanguage); + if (locale == LOCALE_ACTIVE) + locale = LOCALE_BY_REGION(g_region, g_language); TCHAR date[32]; PrintDate(date, countof(date), pst, locale); diff --git a/theseus/engine/locale_node.h b/theseus/engine/locale_node.h index 68907cb..d387a64 100755 --- a/theseus/engine/locale_node.h +++ b/theseus/engine/locale_node.h @@ -4,7 +4,7 @@ #pragma once -#define LOCALE_FROM_REGION_LANGUAGE(region, language) (((region) << 16) | (language)) +#define LOCALE_BY_REGION(region, language) (((region) << 16) | (language)) #define LANGUAGE_FROM_LOCALE(locale) ((locale) & 0x0000ffff) #define REGION_FROM_LOCALE(locale) (((locale) >> 16) & 0x0000ffff) @@ -25,33 +25,33 @@ #define LANGUAGE_COUNT 6 -#define LOCALE_CURRENT -1 -#define LOCALE_NA_ENGLISH LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_NA, LANGUAGE_ENGLISH) -#define LOCALE_NA_JAPANESE LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_NA, LANGUAGE_JAPANESE) -#define LOCALE_NA_GERMAN LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_NA, LANGUAGE_GERMAN) -#define LOCALE_NA_FRENCH LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_NA, LANGUAGE_FRENCH) -#define LOCALE_NA_SPANISH LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_NA, LANGUAGE_SPANISH) -#define LOCALE_NA_ITALIAN LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_NA, LANGUAGE_ITALIAN) -#define LOCALE_JAPAN_ENGLISH LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_JAPAN, LANGUAGE_ENGLISH) -#define LOCALE_JAPAN_JAPANESE LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_JAPAN, LANGUAGE_JAPANESE) -#define LOCALE_JAPAN_GERMAN LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_JAPAN, LANGUAGE_GERMAN) -#define LOCALE_JAPAN_FRENCH LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_JAPAN, LANGUAGE_FRENCH) -#define LOCALE_JAPAN_SPANISH LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_JAPAN, LANGUAGE_SPANISH) -#define LOCALE_JAPAN_ITALIAN LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_JAPAN, LANGUAGE_ITALIAN) -#define LOCALE_RESTOFWORLD_ENGLISH LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_ENGLISH) -#define LOCALE_RESTOFWORLD_JAPANESE LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_JAPANESE) -#define LOCALE_RESTOFWORLD_GERMAN LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_GERMAN) -#define LOCALE_RESTOFWORLD_FRENCH LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_FRENCH) -#define LOCALE_RESTOFWORLD_SPANISH LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_SPANISH) -#define LOCALE_RESTOFWORLD_ITALIAN LOCALE_FROM_REGION_LANGUAGE(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_ITALIAN) - -extern void FormatInteger(TCHAR* szBuf, int nNumber, int locale = LOCALE_CURRENT); -extern void FormatBlocks(TCHAR* szBuf, int nNumber, int locale = LOCALE_CURRENT); -extern bool FormatTime(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale = LOCALE_CURRENT); -extern bool FormatDate(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale = LOCALE_CURRENT); +#define LOCALE_ACTIVE -1 +#define LOCALE_NA_ENGLISH LOCALE_BY_REGION(XC_GAME_REGION_NA, LANGUAGE_ENGLISH) +#define LOCALE_NA_JAPANESE LOCALE_BY_REGION(XC_GAME_REGION_NA, LANGUAGE_JAPANESE) +#define LOCALE_NA_GERMAN LOCALE_BY_REGION(XC_GAME_REGION_NA, LANGUAGE_GERMAN) +#define LOCALE_NA_FRENCH LOCALE_BY_REGION(XC_GAME_REGION_NA, LANGUAGE_FRENCH) +#define LOCALE_NA_SPANISH LOCALE_BY_REGION(XC_GAME_REGION_NA, LANGUAGE_SPANISH) +#define LOCALE_NA_ITALIAN LOCALE_BY_REGION(XC_GAME_REGION_NA, LANGUAGE_ITALIAN) +#define LOCALE_JAPAN_ENGLISH LOCALE_BY_REGION(XC_GAME_REGION_JAPAN, LANGUAGE_ENGLISH) +#define LOCALE_JAPAN_JAPANESE LOCALE_BY_REGION(XC_GAME_REGION_JAPAN, LANGUAGE_JAPANESE) +#define LOCALE_JAPAN_GERMAN LOCALE_BY_REGION(XC_GAME_REGION_JAPAN, LANGUAGE_GERMAN) +#define LOCALE_JAPAN_FRENCH LOCALE_BY_REGION(XC_GAME_REGION_JAPAN, LANGUAGE_FRENCH) +#define LOCALE_JAPAN_SPANISH LOCALE_BY_REGION(XC_GAME_REGION_JAPAN, LANGUAGE_SPANISH) +#define LOCALE_JAPAN_ITALIAN LOCALE_BY_REGION(XC_GAME_REGION_JAPAN, LANGUAGE_ITALIAN) +#define LOCALE_RESTOFWORLD_ENGLISH LOCALE_BY_REGION(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_ENGLISH) +#define LOCALE_RESTOFWORLD_JAPANESE LOCALE_BY_REGION(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_JAPANESE) +#define LOCALE_RESTOFWORLD_GERMAN LOCALE_BY_REGION(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_GERMAN) +#define LOCALE_RESTOFWORLD_FRENCH LOCALE_BY_REGION(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_FRENCH) +#define LOCALE_RESTOFWORLD_SPANISH LOCALE_BY_REGION(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_SPANISH) +#define LOCALE_RESTOFWORLD_ITALIAN LOCALE_BY_REGION(XC_GAME_REGION_RESTOFWORLD, LANGUAGE_ITALIAN) + +extern void FormatInteger(TCHAR* szBuf, int nNumber, int locale = LOCALE_ACTIVE); +extern void FormatBlocks(TCHAR* szBuf, int nNumber, int locale = LOCALE_ACTIVE); +extern bool FormatTime(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale = LOCALE_ACTIVE); +extern bool FormatDate(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale = LOCALE_ACTIVE); extern const TCHAR* Translate(const TCHAR* szString, TCHAR* szTranslate, int nLanguage = LANGUAGE_CURRENT); -extern int g_nCurLanguage; -extern int g_nCurRegion; +extern int g_language; +extern int g_region; const TCHAR* GetLanguageCode(TCHAR* sz); diff --git a/theseus/render/asset_loader.cpp b/theseus/render/asset_loader.cpp index 0c18133..4eaf423 100644 --- a/theseus/render/asset_loader.cpp +++ b/theseus/render/asset_loader.cpp @@ -84,8 +84,8 @@ LPDIRECT3DTEXTURE8 CTexture::GetTextureSurface() // this->surface = CreateTexture(&w, &h); return surface != NULL; bool CTexture::Create(int nWidth, int nHeight) { - m_nImageWidth = nWidth; - m_nImageHeight = nHeight; + m_texWidth = nWidth; + m_texHeight = nHeight; m_surface = ::CreateTexture(nWidth, nHeight, m_format); return m_surface != NULL; } @@ -534,7 +534,7 @@ void CImageTexture::Load(const TCHAR* szURL) m_surface = pSlot->m_texture; m_surface->AddRef(); - TheseusGetTextureSize(m_surface, m_nImageWidth, m_nImageHeight); + TheseusGetTextureSize(m_surface, m_texWidth, m_texHeight); } @@ -823,9 +823,9 @@ LPDIRECT3DTEXTURE8 MyLoadImage(const TCHAR *szURL); struct IMGCACHE { TCHAR *m_url; - LPDIRECT3DTEXTURE8 m_hImage; + LPDIRECT3DTEXTURE8 m_pTex; SIZE m_size; - XTIME m_usage; + XTIME m_lastTouch; }; static IMGCACHE imageCache[100]; @@ -840,7 +840,7 @@ IMGCACHE *FindImage(const TCHAR *szURL) { if (imageCache[i].m_url != NULL && _tcsicmp(imageCache[i].m_url, szURL) == 0) { - imageCache[i].m_usage = TheseusGetNow(); + imageCache[i].m_lastTouch = TheseusGetNow(); return &imageCache[i]; } @@ -849,7 +849,7 @@ IMGCACHE *FindImage(const TCHAR *szURL) if (imageCache[i].m_url == NULL) pFreeOne = &imageCache[i]; - else if (pOldOne == NULL || pOldOne->m_usage > imageCache[i].m_usage) + else if (pOldOne == NULL || pOldOne->m_lastTouch > imageCache[i].m_lastTouch) pOldOne = &imageCache[i]; } @@ -857,8 +857,8 @@ IMGCACHE *FindImage(const TCHAR *szURL) { delete[] pOldOne->m_url; - if (pOldOne->m_hImage != NULL) - pOldOne->m_hImage->Release(); + if (pOldOne->m_pTex != NULL) + pOldOne->m_pTex->Release(); ZeroMemory(pOldOne, sizeof(IMGCACHE)); pFreeOne = pOldOne; @@ -869,14 +869,14 @@ IMGCACHE *FindImage(const TCHAR *szURL) pFreeOne->m_url = new TCHAR[_tcslen(szURL) + 1]; _tcscpy(pFreeOne->m_url, szURL); - pFreeOne->m_usage = TheseusGetNow(); + pFreeOne->m_lastTouch = TheseusGetNow(); - pFreeOne->m_hImage = MyLoadImage(szURL); + pFreeOne->m_pTex = MyLoadImage(szURL); - if (pFreeOne->m_hImage != NULL) + if (pFreeOne->m_pTex != NULL) { D3DSURFACE_DESC sd; - VERIFYHR(pFreeOne->m_hImage->GetLevelDesc(0, &sd)); + VERIFYHR(pFreeOne->m_pTex->GetLevelDesc(0, &sd)); pFreeOne->m_size.cx = (int)sd.Width; pFreeOne->m_size.cy = (int)sd.Height; } @@ -1035,11 +1035,11 @@ void PreloadSkinTextures() CMesh::CMesh() { m_nFaceCount = 0; - m_nVertexCount = 0; + m_vertCount = 0; m_nIndexCount = 0; - m_primitiveType = (D3DPRIMITIVETYPE)0; + m_drawMode = (D3DPRIMITIVETYPE)0; m_fvf = 0; - m_nVertexStride = 0; + m_vertSize = 0; m_vertexBuffer = NULL; m_indexBuffer = NULL; } @@ -1078,25 +1078,25 @@ bool CMesh::Create(HANDLE hFile) ReadFile(hFile, &hdr, sizeof(hdr), &cbRead, NULL); if (hdr.dwPrimitiveType == 4) - m_primitiveType = D3DPT_TRIANGLELIST; + m_drawMode = D3DPT_TRIANGLELIST; else if (hdr.dwPrimitiveType == 5) - m_primitiveType = D3DPT_TRIANGLESTRIP; + m_drawMode = D3DPT_TRIANGLESTRIP; else { #ifdef _XBOX return false; #else - m_primitiveType = (D3DPRIMITIVETYPE)hdr.dwPrimitiveType; // desktop takes the file's word for it + m_drawMode = (D3DPRIMITIVETYPE)hdr.dwPrimitiveType; // desktop takes the file's word for it #endif } m_nFaceCount = hdr.dwFaceCount; m_fvf = hdr.dwFVF; - m_nVertexStride = hdr.dwVertexStride; - m_nVertexCount = hdr.dwVertexCount; + m_vertSize = hdr.dwVertexStride; + m_vertCount = hdr.dwVertexCount; m_nIndexCount = hdr.dwIndexCount; - int cbVertices = m_nVertexCount * m_nVertexStride; + int cbVertices = m_vertCount * m_vertSize; int cbIndices = m_nIndexCount * sizeof(WORD); BYTE* pb; @@ -1176,13 +1176,13 @@ void CMesh::Render(bool bSetFVF) } #endif - TheseusSetStreamSource(0, m_vertexBuffer, m_nVertexStride); + TheseusSetStreamSource(0, m_vertexBuffer, m_vertSize); TheseusSetIndices(m_indexBuffer, 0); Frame_Count(FC_DRAW_SCENE); - TheseusDrawIndexedPrimitive(m_primitiveType, 0, m_nVertexCount, 0, m_nFaceCount); + TheseusDrawIndexedPrimitive(m_drawMode, 0, m_vertCount, 0, m_nFaceCount); #ifndef _XBOX - g_nVertPerFrame += m_nVertexCount; + g_nVertPerFrame += m_vertCount; g_nTriPerFrame += m_nFaceCount; #endif } @@ -1215,9 +1215,9 @@ CMesh* LoadMesh(const TCHAR* szFilePath) CMesh* MakeSphere(float nRadius, int nSlices, int nStacks) { CMesh* pMesh = new CMesh; - pMesh->m_primitiveType = D3DPT_TRIANGLELIST; + pMesh->m_drawMode = D3DPT_TRIANGLELIST; pMesh->m_fvf = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE; - pMesh->m_nVertexStride = sizeof(D3DXVECTOR3) * 2 + sizeof(DWORD); + pMesh->m_vertSize = sizeof(D3DXVECTOR3) * 2 + sizeof(DWORD); LPD3DXMESH pSphere = NULL; LPD3DXMESH pClone = NULL; @@ -1238,7 +1238,7 @@ CMesh* MakeSphere(float nRadius, int nSlices, int nStacks) { pMesh->m_nFaceCount = pClone->GetNumFaces(); pMesh->m_nIndexCount = pMesh->m_nFaceCount * 3; - pMesh->m_nVertexCount = pClone->GetNumVertices(); + pMesh->m_vertCount = pClone->GetNumVertices(); } if (pClone != NULL) @@ -1254,20 +1254,20 @@ CMesh* MakeSphere(float nRadius, int nSlices, int nStacks) const int cbPacked = sizeof(D3DXVECTOR3) + sizeof(DWORD) * 2; LPDIRECT3DVERTEXBUFFER8 pPacked; - TheseusCreateVertexBuffer(pMesh->m_nVertexCount * cbPacked, D3DUSAGE_DYNAMIC, 0, D3DPOOL_MANAGED, &pPacked); + TheseusCreateVertexBuffer(pMesh->m_vertCount * cbPacked, D3DUSAGE_DYNAMIC, 0, D3DPOOL_MANAGED, &pPacked); BYTE* pbFrom; BYTE* pbTo; pMesh->m_vertexBuffer->Lock(0, 0, &pbFrom, 0); pPacked->Lock(0, 0, &pbTo, 0); - for (int i = 0; i < pMesh->m_nVertexCount; i++) + for (int i = 0; i < pMesh->m_vertCount; i++) { const float* pf = (const float*)pbFrom; DWORD* pdw = (DWORD*)pbTo; CopyMemory(pbTo, pf, sizeof(D3DXVECTOR3)); pdw[3] = CompressNormal((float*)(pf + 3)); pdw[4] = ((const DWORD*)pf)[6]; - pbFrom += pMesh->m_nVertexStride; + pbFrom += pMesh->m_vertSize; pbTo += cbPacked; } pPacked->Unlock(); @@ -1276,14 +1276,14 @@ CMesh* MakeSphere(float nRadius, int nSlices, int nStacks) pMesh->m_vertexBuffer->Release(); pMesh->m_vertexBuffer = pPacked; pMesh->m_fvf = D3DFVF_XYZ | D3DFVF_NORMPACKED3 | D3DFVF_DIFFUSE; - pMesh->m_nVertexStride = cbPacked; + pMesh->m_vertSize = cbPacked; return pMesh; } // ===== Mesh node ============================================================ -class CMeshNode* g_pRenderMeshNode = NULL; // 0x0017e758 +class CMeshNode* g_pDrawingShape = NULL; // 0x0017e758 CMeshNode* CMeshNode::c_pFirst; // 0x0017c8d4 // Theseus: drops every node's mesh and marks it dirty, so the next Render @@ -1378,7 +1378,7 @@ extern DWORD GetEffectShader(int nEffect, DWORD fvf); // Reconstructed from 5960 retail XBE @ 0x0005c200. Ghidra decompile: // renderTime = now; // if (dirty) { if (url && *url) load(url); Init(); if (!mesh) return; } -// if (mesh) mesh->Render(g_pRenderMeshNode != this); +// if (mesh) mesh->Render(g_pDrawingShape != this); // The shape renderer sets the FVF itself for the node it's drawing, so the // mesh only sets it when drawn some other way. The falloff branch is Theseus's. void CMeshNode::Render() @@ -1390,7 +1390,7 @@ void CMeshNode::Render() if (m_mesh == NULL) return; - if (m_falloff > 0.0f && g_pRenderMeshNode != this) + if (m_falloff > 0.0f && g_pDrawingShape != this) { // Theseus: "Mesh { url "foo.xm" falloff 1 }" in alpha era XAPs draws // the view angle fade the retail dash does with a MaxMaterial. @@ -1412,7 +1412,7 @@ void CMeshNode::Render() return; } - m_mesh->Render(g_pRenderMeshNode != this); + m_mesh->Render(g_pDrawingShape != this); } // CMeshNode::load(file) [script fn 'load', FND 0x00188418, sig 12] diff --git a/theseus/render/asset_loader.h b/theseus/render/asset_loader.h index 0590eeb..7fce9f4 100644 --- a/theseus/render/asset_loader.h +++ b/theseus/render/asset_loader.h @@ -44,11 +44,11 @@ class CMesh : public CMeshCore DWORD GetFVF() const; int m_nFaceCount; - int m_nVertexCount; + int m_vertCount; int m_nIndexCount; - D3DPRIMITIVETYPE m_primitiveType; + D3DPRIMITIVETYPE m_drawMode; DWORD m_fvf; - int m_nVertexStride; + int m_vertSize; IDirect3DVertexBuffer8* m_vertexBuffer; IDirect3DIndexBuffer8* m_indexBuffer; }; @@ -89,8 +89,8 @@ class CTexture : public CNode bool m_titleImage; D3DFORMAT m_format; LPDIRECT3DTEXTURE8 m_surface; - int m_nImageWidth; - int m_nImageHeight; + int m_texWidth; + int m_texHeight; }; // A texture loaded from a url. Every one sits on a list for reloads. diff --git a/theseus/render/hud_node.cpp b/theseus/render/hud_node.cpp index b8ebbee..c661941 100644 --- a/theseus/render/hud_node.cpp +++ b/theseus/render/hud_node.cpp @@ -250,8 +250,8 @@ void CPicture::Render() if (image) { - w = (image->m_nImageWidth / w) * w; - h = (image->m_nImageHeight / h) * h; + w = (image->m_texWidth / w) * w; + h = (image->m_texHeight / h) * h; } } @@ -262,8 +262,8 @@ void CPicture::Render() { float surfW, surfH; TheseusGetTextureSize(surface, surfW, surfH); - maxU = image->m_nImageWidth / surfW; - maxV = image->m_nImageHeight / surfH; + maxU = image->m_texWidth / surfW; + maxV = image->m_texHeight / surfH; } TheseusSetTexture(0, surface); diff --git a/theseus/render/materials.cpp b/theseus/render/materials.cpp index 65616f2..82c0e6a 100755 --- a/theseus/render/materials.cpp +++ b/theseus/render/materials.cpp @@ -16,7 +16,7 @@ #include "settingsfile.h" #include "xip_archive.h" -extern class CMeshNode *g_pRenderMeshNode; +extern class CMeshNode *g_pDrawingShape; extern void SetFalloffShaderValues(const D3DXCOLOR &sideColor, const D3DXCOLOR &frontColor); extern DWORD GetEffectShader(int nEffect, DWORD fvf); extern LPDIRECT3DTEXTURE8 CreateTexture(int &nWidth, int &nHeight, D3DFORMAT format); @@ -28,14 +28,14 @@ extern void SetReflectShaderFrameValues(); // 0x0017c8c8), the key palette switch (0x0017e74d), and the shared pulse // clock (0x0017c8c0) with the material that last restarted it (0x0017e750). BOOL g_bEdgeAntialiasOverride; -const TCHAR *g_szCurTitleImage; -const TCHAR *g_szSelTitleImage; +const TCHAR *g_szTitleArt; +const TCHAR *g_szPickedTitleArt; bool g_bActiveKey = false; extern float g_nEffectAlpha; extern D3DRECT g_clipRect; extern D3DRECT g_clipRect2x; XTIME g_pulseStartTime; -static class CMaxMaterial *g_pLastPulseMaxMat = NULL; +static class CMaxMaterial *g_pPulsingMat = NULL; int g_nMatInfoCount = 0; TCHAR g_szLastLoadedSkin[MAX_PATH] = _T(""); @@ -82,7 +82,7 @@ class CMaxMaterial : public CMaterial void Render(); - class CMatInfo *m_pMatInfo; + class CMatInfo *m_pDef; DECLARE_NODE_PROPS() }; @@ -234,7 +234,7 @@ class CSolidMatInfo : public CMatInfo bool Setup(CMaxMaterial *pMaxMat); - BYTE m_r, m_g, m_b, m_a; + BYTE m_red, m_green, m_blue, m_alpha; }; // Falloff, vtable 0x00028bf0: side 0x0c, front 0x10, shader effect 0x14, @@ -246,10 +246,10 @@ class CFalloffMatInfo : public CMatInfo bool Setup(CMaxMaterial *pMaxMat); - D3DCOLOR m_colorSide; - D3DCOLOR m_colorFront; - int m_nShaderEffect; - TCHAR m_matName[MAX_PATH]; + D3DCOLOR m_sideColor; + D3DCOLOR m_faceColor; + int m_effect; + TCHAR m_szMatLabel[MAX_PATH]; }; // FalloffTex, vtable 0x00028be8: falloff modulated by the mesh's texture. @@ -260,9 +260,9 @@ class CFalloffTexInfo : public CMatInfo bool Setup(CMaxMaterial *pMaxMat); - D3DCOLOR m_colorSide; - D3DCOLOR m_colorFront; - int m_nShaderEffect; + D3DCOLOR m_sideColor; + D3DCOLOR m_faceColor; + int m_effect; }; // Aniso, vtable 0x00028be0: falloff through the anisotropic shader. @@ -273,9 +273,9 @@ class CAnisoMatInfo : public CMatInfo bool Setup(CMaxMaterial *pMaxMat); - D3DCOLOR m_colorSide; - D3DCOLOR m_colorFront; - int m_nShaderEffect; + D3DCOLOR m_sideColor; + D3DCOLOR m_faceColor; + int m_effect; }; // Icon, vtable 0x00028bd8: the current or selected title image. @@ -342,7 +342,7 @@ class CBackingMatInfo : public CMatInfo bool Setup(CMaxMaterial *pMaxMat); - BYTE m_r, m_g, m_b, m_a; + BYTE m_red, m_green, m_blue, m_alpha; }; // ModulateTexture, vtable 0x00028bec: the mesh's texture, pulsing alpha. @@ -353,7 +353,7 @@ class CModulateTextureMatInfo : public CMatInfo bool Setup(CMaxMaterial *pMaxMat); - BYTE m_r, m_g, m_b, m_a; + BYTE m_red, m_green, m_blue, m_alpha; }; // Reflect, vtable 0x00028be4: the environment reflection shader. @@ -364,7 +364,7 @@ class CReflectMatInfo : public CMatInfo bool Setup(CMaxMaterial *pMaxMat); - int m_nShaderEffect; + int m_effect; }; // MaskTexture, vtable 0x00028bdc: one of the masks on stage 1. @@ -393,9 +393,9 @@ class CInnerWallMatInfo : public CMatInfo bool Setup(CMaxMaterial *pMaxMat); - D3DCOLOR m_colorSide; - D3DCOLOR m_colorFront; - int m_nShaderEffect; + D3DCOLOR m_sideColor; + D3DCOLOR m_faceColor; + int m_effect; }; // The material list Material_Init fills, 0x0017c6b8, count at 0x0017e754. @@ -404,7 +404,7 @@ CMatInfo *g_rgMatInfo[240]; // The vertex shader every falloff style material starts with. static void SetEffectShader(int nEffect) { - TheseusSetVertexShader(GetEffectShader(nEffect, g_pRenderMeshNode->GetFVF())); + TheseusSetVertexShader(GetEffectShader(nEffect, g_pDrawingShape->GetFVF())); } // Texture factor alpha scaled by the scene's fade (0x00175ca0). @@ -467,10 +467,10 @@ bool CMatInfo::Setup(CMaxMaterial *pMaxMat) // A flat color with the vertex alpha kept. CSolidMatInfo::CSolidMatInfo(const TCHAR *szName, BYTE r, BYTE g, BYTE b, BYTE a, DWORD dwFlags /*=0*/) : CMatInfo(szName, dwFlags) { - m_r = r; - m_g = g; - m_b = b; - m_a = a; + m_red = r; + m_green = g; + m_blue = b; + m_alpha = a; } bool CSolidMatInfo::Setup(CMaxMaterial *pMaxMat) @@ -482,7 +482,7 @@ bool CSolidMatInfo::Setup(CMaxMaterial *pMaxMat) TheseusSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); TheseusSetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE); - TheseusSetRenderState(D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB(FadedAlpha(m_a), m_r, m_g, m_b)); + TheseusSetRenderState(D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB(FadedAlpha(m_alpha), m_red, m_green, m_blue)); #ifdef _XBOX TheseusSetRenderState(D3DRS_EDGEANTIALIAS, (m_flags & MATINFO_NO_EDGE_AA) ? FALSE : TRUE); TheseusSetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE); @@ -495,7 +495,7 @@ bool CSolidMatInfo::Setup(CMaxMaterial *pMaxMat) // Material_Init builds these inline (see the Key constructor at 0x000570c0): // side, front, shader effect 1, wcscpy(matName, name). // Setup reconstructed from 5960 retail XBE @ 0x00057790. Ghidra decompile: -// if (!g_pRenderMeshNode) return 0; +// if (!g_pDrawingShape) return 0; // tss[0].ADDRESSV = WRAP; SetVertexShader(GetEffectShader(effect, fvf)); // tss[0].COLOROP = tss[0].ALPHAOP = DISABLE; // rs.EDGEANTIALIAS = 1; rs.MULTISAMPLEANTIALIAS = 0; @@ -504,30 +504,30 @@ bool CSolidMatInfo::Setup(CMaxMaterial *pMaxMat) // The shader blends side to front by how directly a face looks at the camera. CFalloffMatInfo::CFalloffMatInfo(const TCHAR *szName, D3DCOLOR colorSide, D3DCOLOR colorFront, DWORD dwFlags /*=0*/) : CMatInfo(szName, dwFlags) { - m_colorSide = colorSide; - m_colorFront = colorFront; - m_nShaderEffect = 1; - _tcscpy(m_matName, szName); + m_sideColor = colorSide; + m_faceColor = colorFront; + m_effect = 1; + _tcscpy(m_szMatLabel, szName); } bool CFalloffMatInfo::Setup(CMaxMaterial *pMaxMat) { - if (g_pRenderMeshNode == NULL) + if (g_pDrawingShape == NULL) return false; TheseusSetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - SetEffectShader(m_nShaderEffect); + SetEffectShader(m_effect); TheseusSetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); TheseusSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); UseEdgeAntialias(); - SetFalloffShaderValues(m_colorSide, m_colorFront); + SetFalloffShaderValues(m_sideColor, m_faceColor); return CMatInfo::Setup(pMaxMat); } // CFalloffTexInfo // Setup reconstructed from 5960 retail XBE @ 0x00057940. Ghidra decompile: -// if (!g_pRenderMeshNode) return 0; +// if (!g_pDrawingShape) return 0; // SetVertexShader(GetEffectShader(effect 3, fvf)); falloff constants; // tss[0]: ADDRESSV WRAP, COLOROP and ALPHAOP MODULATE (DIFFUSE, TEXTURE); // tss[1]: COLOROP, ALPHAOP DISABLE; @@ -535,18 +535,18 @@ bool CFalloffMatInfo::Setup(CMaxMaterial *pMaxMat) // Theseus also pins stage 0 to texture coordinate set 0. CFalloffTexInfo::CFalloffTexInfo(const TCHAR *szName, D3DCOLOR colorSide, D3DCOLOR colorFront, DWORD dwFlags /*=0*/) : CMatInfo(szName, dwFlags) { - m_colorSide = colorSide; - m_colorFront = colorFront; - m_nShaderEffect = 3; + m_sideColor = colorSide; + m_faceColor = colorFront; + m_effect = 3; } bool CFalloffTexInfo::Setup(CMaxMaterial *pMaxMat) { - if (g_pRenderMeshNode == NULL) + if (g_pDrawingShape == NULL) return false; - SetEffectShader(m_nShaderEffect); - SetFalloffShaderValues(m_colorSide, m_colorFront); + SetEffectShader(m_effect); + SetFalloffShaderValues(m_sideColor, m_faceColor); TheseusSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); TheseusSetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); @@ -567,21 +567,21 @@ bool CFalloffTexInfo::Setup(CMaxMaterial *pMaxMat) // the Falloff Setup with shader effect 2 and no edge AA writes. CAnisoMatInfo::CAnisoMatInfo(const TCHAR *szName, D3DCOLOR colorSide, D3DCOLOR colorFront, DWORD dwFlags /*=0*/) : CMatInfo(szName, dwFlags) { - m_colorSide = colorSide; - m_colorFront = colorFront; - m_nShaderEffect = 2; + m_sideColor = colorSide; + m_faceColor = colorFront; + m_effect = 2; } bool CAnisoMatInfo::Setup(CMaxMaterial *pMaxMat) { - if (g_pRenderMeshNode == NULL) + if (g_pDrawingShape == NULL) return false; TheseusSetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - SetEffectShader(m_nShaderEffect); + SetEffectShader(m_effect); TheseusSetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); TheseusSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - SetFalloffShaderValues(m_colorSide, m_colorFront); + SetFalloffShaderValues(m_sideColor, m_faceColor); return CMatInfo::Setup(pMaxMat); } @@ -592,18 +592,18 @@ bool CAnisoMatInfo::Setup(CMaxMaterial *pMaxMat) // and rs.CULLMODE = NONE before CMatInfo::Setup(). CInnerWallMatInfo::CInnerWallMatInfo(const TCHAR *szName, D3DCOLOR colorSide, D3DCOLOR colorFront, DWORD dwFlags /*=0*/) : CMatInfo(szName, dwFlags) { - m_colorSide = colorSide; - m_colorFront = colorFront; - m_nShaderEffect = 3; + m_sideColor = colorSide; + m_faceColor = colorFront; + m_effect = 3; } bool CInnerWallMatInfo::Setup(CMaxMaterial *pMaxMat) { - if (g_pRenderMeshNode == NULL) + if (g_pDrawingShape == NULL) return false; - SetEffectShader(m_nShaderEffect); - SetFalloffShaderValues(m_colorSide, m_colorFront); + SetEffectShader(m_effect); + SetFalloffShaderValues(m_sideColor, m_faceColor); TheseusSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); TheseusSetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); @@ -733,10 +733,10 @@ static float PulseLevel() // the scene has finished fading in. CModulateTextureMatInfo::CModulateTextureMatInfo(const TCHAR *szName, BYTE r, BYTE g, BYTE b, BYTE a, DWORD dwFlags /*=0*/) : CMatInfo(szName, dwFlags) { - m_r = r; - m_g = g; - m_b = b; - m_a = a; + m_red = r; + m_green = g; + m_blue = b; + m_alpha = a; } bool CModulateTextureMatInfo::Setup(CMaxMaterial *pMaxMat) @@ -747,14 +747,14 @@ bool CModulateTextureMatInfo::Setup(CMaxMaterial *pMaxMat) TheseusSetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); TheseusSetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); - if (pMaxMat != g_pLastPulseMaxMat && g_nEffectAlpha == 1.0f) + if (pMaxMat != g_pPulsingMat && g_nEffectAlpha == 1.0f) { - g_pLastPulseMaxMat = pMaxMat; + g_pPulsingMat = pMaxMat; g_pulseStartTime = TheseusGetNow(); } - float nAlpha = (float)m_a * (PulseLevel() * 0.25f + 0.75f) * g_nEffectAlpha; - TheseusSetRenderState(D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB((BYTE)(int)nAlpha, m_r, m_g, m_b)); + float nAlpha = (float)m_alpha * (PulseLevel() * 0.25f + 0.75f) * g_nEffectAlpha; + TheseusSetRenderState(D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB((BYTE)(int)nAlpha, m_red, m_green, m_blue)); UseEdgeAntialias(); return CMatInfo::Setup(pMaxMat); @@ -762,7 +762,7 @@ bool CModulateTextureMatInfo::Setup(CMaxMaterial *pMaxMat) // CReflectMatInfo // Setup reconstructed from 5960 retail XBE @ 0x00056d90. Ghidra decompile: -// if (!g_pRenderMeshNode) return 0; +// if (!g_pDrawingShape) return 0; // SetVertexShader(GetEffectShader(effect 4, fvf)); // falloff constants side (229, 229, 229, 0), front (229, 229, 229, 255); // SetReflectShaderFrameValues(); @@ -771,15 +771,15 @@ bool CModulateTextureMatInfo::Setup(CMaxMaterial *pMaxMat) // return CMatInfo::Setup(); CReflectMatInfo::CReflectMatInfo(const TCHAR *szName) : CMatInfo(szName, 0) { - m_nShaderEffect = 4; + m_effect = 4; } bool CReflectMatInfo::Setup(CMaxMaterial *pMaxMat) { - if (g_pRenderMeshNode == NULL) + if (g_pDrawingShape == NULL) return false; - SetEffectShader(m_nShaderEffect); + SetEffectShader(m_effect); SetFalloffShaderValues(D3DCOLOR_ARGB(0, 229, 229, 229), D3DCOLOR_ARGB(255, 229, 229, 229)); SetReflectShaderFrameValues(); @@ -804,10 +804,10 @@ bool CReflectMatInfo::Setup(CMaxMaterial *pMaxMat) // A colored panel whose shape comes from the mask's alpha. CBackingMatInfo::CBackingMatInfo(const TCHAR *szName, BYTE r, BYTE g, BYTE b, BYTE a, DWORD dwFlags /*=0*/) : CMatInfo(szName, dwFlags) { - m_r = r; - m_g = g; - m_b = b; - m_a = a; + m_red = r; + m_green = g; + m_blue = b; + m_alpha = a; } bool CBackingMatInfo::Setup(CMaxMaterial *pMaxMat) @@ -822,7 +822,7 @@ bool CBackingMatInfo::Setup(CMaxMaterial *pMaxMat) TheseusSetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); TheseusSetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); TheseusSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - TheseusSetRenderState(D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB(FadedAlpha(m_a), m_r, m_g, m_b)); + TheseusSetRenderState(D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB(FadedAlpha(m_alpha), m_red, m_green, m_blue)); return CMatInfo::Setup(pMaxMat); } @@ -844,15 +844,15 @@ CEggGlowPulseMatInfo::CEggGlowPulseMatInfo(const TCHAR *szName, CustomColor colo bool CEggGlowPulseMatInfo::Setup(CMaxMaterial *pMaxMat) { - if (pMaxMat != g_pLastPulseMaxMat) + if (pMaxMat != g_pPulsingMat) { - g_pLastPulseMaxMat = pMaxMat; + g_pPulsingMat = pMaxMat; g_pulseStartTime = 2.0; } int nFrontAlpha = (int)(PulseLevel() * 128.0f + 64.0f); - m_colorSide = D3DCOLOR_RGBA(Color1.r, Color1.g, Color1.b, Color1.a); - m_colorFront = D3DCOLOR_RGBA(Color2.r, Color2.g, Color2.b, nFrontAlpha); + m_sideColor = D3DCOLOR_RGBA(Color1.r, Color1.g, Color1.b, Color1.a); + m_faceColor = D3DCOLOR_RGBA(Color2.r, Color2.g, Color2.b, nFrontAlpha); return CFalloffMatInfo::Setup(pMaxMat); } @@ -892,7 +892,7 @@ bool CEggGlowFadeMatInfo::Setup(CMaxMaterial *pMaxMat) nLeft = 1.0f - t; } - m_colorFront = D3DCOLOR_RGBA(Color1.r, Color1.g, Color1.b, (int)(nLeft * 255.0f)); + m_faceColor = D3DCOLOR_RGBA(Color1.r, Color1.g, Color1.b, (int)(nLeft * 255.0f)); return CFalloffMatInfo::Setup(pMaxMat); } @@ -943,14 +943,14 @@ bool CKeyMatInfo::Setup(CMaxMaterial *pMaxMat) { if (g_bActiveKey) { - if (pMaxMat != g_pLastPulseMaxMat && g_nEffectAlpha > 0.0f) + if (pMaxMat != g_pPulsingMat && g_nEffectAlpha > 0.0f) { - g_pLastPulseMaxMat = pMaxMat; + g_pPulsingMat = pMaxMat; g_pulseStartTime = TheseusGetNow(); } - m_colorSide = D3DCOLOR_RGBA(Color1.r, Color1.g, Color1.b, Color1.a); - m_colorFront = D3DCOLOR_RGBA(Color1.r, Color1.g, Color1.b, Color1.a - 65); + m_sideColor = D3DCOLOR_RGBA(Color1.r, Color1.g, Color1.b, Color1.a); + m_faceColor = D3DCOLOR_RGBA(Color1.r, Color1.g, Color1.b, Color1.a - 65); if (m_bText) KeyTextStage(D3DCOLOR_ARGB(FadedAlpha(192.0f), 0, 0, 0)); @@ -959,13 +959,13 @@ bool CKeyMatInfo::Setup(CMaxMaterial *pMaxMat) { if (m_bBright) { - m_colorSide = D3DCOLOR_RGBA(Color2.r, Color2.g, Color2.b, Color2.a); - m_colorFront = D3DCOLOR_RGBA(Color3.r, Color3.g, Color3.b, Color3.a); + m_sideColor = D3DCOLOR_RGBA(Color2.r, Color2.g, Color2.b, Color2.a); + m_faceColor = D3DCOLOR_RGBA(Color3.r, Color3.g, Color3.b, Color3.a); } else { - m_colorSide = D3DCOLOR_RGBA(Color2.r, Color2.g, Color2.b, Color2.a - 33); - m_colorFront = D3DCOLOR_RGBA(Color3.r - 5, Color3.g - 33, Color3.b, Color3.a - 19); + m_sideColor = D3DCOLOR_RGBA(Color2.r, Color2.g, Color2.b, Color2.a - 33); + m_faceColor = D3DCOLOR_RGBA(Color3.r - 5, Color3.g - 33, Color3.b, Color3.a - 19); } if (m_bText) @@ -980,10 +980,10 @@ bool CKeyMatInfo::Setup(CMaxMaterial *pMaxMat) // CIconMatInfo // Setup reconstructed from 5960 retail XBE @ 0x000572d0. Ghidra decompile: // inXIP = this->inXIP; -// if (g_szCurTitleImage && !selImg) { +// if (g_szTitleArt && !selImg) { // if (name is xboxlogo64.xbx / xboxlogo128.xbx / xboxlogo64a.xbx) inXIP = 1; // tex = FindTexture(name, async, w, h, inXIP); -// } else if (g_szSelTitleImage && selImg) { +// } else if (g_szPickedTitleArt && selImg) { // if (name is xboxlogo64.xbx / xboxlogo128.xbx / // XboxLiveAccount64.tga / XboxLiveAccount128.tga) inXIP = 1; // tex = FindTexture(...); @@ -1028,9 +1028,9 @@ bool CIconMatInfo::Setup(CMaxMaterial *pMaxMat) { const TCHAR *szImage = NULL; if (!m_bSelImg) - szImage = g_szCurTitleImage; + szImage = g_szTitleArt; else - szImage = g_szSelTitleImage; + szImage = g_szPickedTitleArt; LPDIRECT3DTEXTURE8 pImage = NULL; float nAlpha = 1.0f; @@ -1135,11 +1135,11 @@ DWORD MatInfo_GetColor(CMatInfo* p, int idx) { if (!p) return 0; if (CSolidMatInfo* m = dynamic_cast(p)) - return D3DCOLOR_RGBA(m->m_r, m->m_g, m->m_b, m->m_a); + return D3DCOLOR_RGBA(m->m_red, m->m_green, m->m_blue, m->m_alpha); if (CBackingMatInfo* m = dynamic_cast(p)) - return D3DCOLOR_RGBA(m->m_r, m->m_g, m->m_b, m->m_a); + return D3DCOLOR_RGBA(m->m_red, m->m_green, m->m_blue, m->m_alpha); if (CModulateTextureMatInfo* m = dynamic_cast(p)) - return D3DCOLOR_RGBA(m->m_r, m->m_g, m->m_b, m->m_a); + return D3DCOLOR_RGBA(m->m_red, m->m_green, m->m_blue, m->m_alpha); // The egg glows rebuild their falloff colors every frame from these, so // that's where the skin's ColorA / ColorB actually live. if (CEggGlowPulseMatInfo* m = dynamic_cast(p)) { @@ -1147,11 +1147,11 @@ DWORD MatInfo_GetColor(CMatInfo* p, int idx) return D3DCOLOR_RGBA(c.r, c.g, c.b, c.a); } if (CEggGlowFadeMatInfo* m = dynamic_cast(p)) - return (idx == 0) ? m->m_colorSide : D3DCOLOR_RGBA(m->Color1.r, m->Color1.g, m->Color1.b, m->Color1.a); + return (idx == 0) ? m->m_sideColor : D3DCOLOR_RGBA(m->Color1.r, m->Color1.g, m->Color1.b, m->Color1.a); if (CInnerWallMatInfo* m = dynamic_cast(p)) - return (idx == 0) ? m->m_colorSide : m->m_colorFront; + return (idx == 0) ? m->m_sideColor : m->m_faceColor; if (CFalloffMatInfo* m = dynamic_cast(p)) - return (idx == 0) ? m->m_colorSide : m->m_colorFront; + return (idx == 0) ? m->m_sideColor : m->m_faceColor; return 0; } @@ -1163,11 +1163,11 @@ void MatInfo_SetColor(CMatInfo* p, int idx, DWORD c) BYTE g = (BYTE)((c >> 8) & 0xFF); BYTE b = (BYTE)( c & 0xFF); if (CSolidMatInfo* m = dynamic_cast(p)) - { m->m_r=r; m->m_g=g; m->m_b=b; m->m_a=a; return; } + { m->m_red=r; m->m_green=g; m->m_blue=b; m->m_alpha=a; return; } if (CBackingMatInfo* m = dynamic_cast(p)) - { m->m_r=r; m->m_g=g; m->m_b=b; m->m_a=a; return; } + { m->m_red=r; m->m_green=g; m->m_blue=b; m->m_alpha=a; return; } if (CModulateTextureMatInfo* m = dynamic_cast(p)) - { m->m_r=r; m->m_g=g; m->m_b=b; m->m_a=a; return; } + { m->m_red=r; m->m_green=g; m->m_blue=b; m->m_alpha=a; return; } CustomColor cc; cc.r = r; cc.g = g; cc.b = b; cc.a = a; if (CEggGlowPulseMatInfo* m = dynamic_cast(p)) { @@ -1175,15 +1175,15 @@ void MatInfo_SetColor(CMatInfo* p, int idx, DWORD c) return; } if (CEggGlowFadeMatInfo* m = dynamic_cast(p)) { - if (idx == 0) m->m_colorSide = c; else m->Color1 = cc; + if (idx == 0) m->m_sideColor = c; else m->Color1 = cc; return; } if (CInnerWallMatInfo* m = dynamic_cast(p)) { - if (idx == 0) m->m_colorSide = c; else m->m_colorFront = c; + if (idx == 0) m->m_sideColor = c; else m->m_faceColor = c; return; } if (CFalloffMatInfo* m = dynamic_cast(p)) { - if (idx == 0) m->m_colorSide = c; else m->m_colorFront = c; + if (idx == 0) m->m_sideColor = c; else m->m_faceColor = c; return; } } @@ -1206,7 +1206,7 @@ CMaxMaterial::CMaxMaterial() { m_name = NULL; m_param = 0.0; - m_pMatInfo = NULL; + m_pDef = NULL; } CMaxMaterial::~CMaxMaterial() @@ -1230,7 +1230,7 @@ bool CMaxMaterial::OnSetProperty(const PRD *pprd, const void *pvValue) } if (field == offsetof(m_name)) - m_pMatInfo = NULL; + m_pDef = NULL; return true; } @@ -1246,11 +1246,11 @@ bool CMaxMaterial::OnSetProperty(const PRD *pprd, const void *pvValue) // AA. The tube meshes get the override so their outlines keep edge AA. void CMaxMaterial::Render() { - if (m_pMatInfo == NULL) + if (m_pDef == NULL) { if (m_name != NULL) - m_pMatInfo = LookupMatInfo(m_name); - if (m_pMatInfo == NULL) + m_pDef = LookupMatInfo(m_name); + if (m_pDef == NULL) return; } @@ -1265,12 +1265,12 @@ void CMaxMaterial::Render() _tcscmp(m_name, _T("TubesQ")) == 0 || _tcscmp(m_name, _T("Tube")) == 0; - m_pMatInfo->Setup(this); + m_pDef->Setup(this); #ifdef THESEUS_DESKTOP // The skin editor highlights the materials drawn this frame. extern IDirect3DDevice8* g_pD3DDev; if (g_pD3DDev != NULL) - m_pMatInfo->m_lastUsedFrame = g_pD3DDev->m_frameNumber; + m_pDef->m_lastUsedFrame = g_pD3DDev->m_frameNumber; #endif } diff --git a/theseus/render/materials_retail.inl b/theseus/render/materials_retail.inl index 6fa64ef..aea4635 100644 --- a/theseus/render/materials_retail.inl +++ b/theseus/render/materials_retail.inl @@ -281,50 +281,50 @@ static void RecolourMat(CMatInfo *p, const RetailMat &m, D3DCOLOR a, D3DCOLOR b, case MK_SOLID: { CSolidMatInfo *s = static_cast(p); - s->m_r = MAT_R(a); s->m_g = MAT_G(a); s->m_b = MAT_B(a); s->m_a = MAT_A(a); + s->m_red = MAT_R(a); s->m_green = MAT_G(a); s->m_blue = MAT_B(a); s->m_alpha = MAT_A(a); } break; case MK_BACKING: { CBackingMatInfo *s = static_cast(p); - s->m_r = MAT_R(a); s->m_g = MAT_G(a); s->m_b = MAT_B(a); s->m_a = MAT_A(a); + s->m_red = MAT_R(a); s->m_green = MAT_G(a); s->m_blue = MAT_B(a); s->m_alpha = MAT_A(a); } break; case MK_MODULATE: { CModulateTextureMatInfo *s = static_cast(p); - s->m_r = MAT_R(a); s->m_g = MAT_G(a); s->m_b = MAT_B(a); s->m_a = MAT_A(a); + s->m_red = MAT_R(a); s->m_green = MAT_G(a); s->m_blue = MAT_B(a); s->m_alpha = MAT_A(a); } break; case MK_FALLOFF: - static_cast(p)->m_colorSide = a; - static_cast(p)->m_colorFront = b; + static_cast(p)->m_sideColor = a; + static_cast(p)->m_faceColor = b; break; case MK_FALLOFFTEX: - static_cast(p)->m_colorSide = a; - static_cast(p)->m_colorFront = b; + static_cast(p)->m_sideColor = a; + static_cast(p)->m_faceColor = b; break; case MK_INNERWALL: - static_cast(p)->m_colorSide = a; - static_cast(p)->m_colorFront = b; + static_cast(p)->m_sideColor = a; + static_cast(p)->m_faceColor = b; break; case MK_ANISO: - static_cast(p)->m_colorSide = a; - static_cast(p)->m_colorFront = b; + static_cast(p)->m_sideColor = a; + static_cast(p)->m_faceColor = b; break; case MK_EGGGLOW: { // mirrors the shifted constructor: a lands in front, b in the flags CEggGlowFadeMatInfo *e = static_cast(p); - e->m_colorSide = m.dwFlags; - e->m_colorFront = a; + e->m_sideColor = m.dwFlags; + e->m_faceColor = a; e->m_flags = b; e->Color1 = ToCustomColor(b); } diff --git a/theseus/render/shape_render.cpp b/theseus/render/shape_render.cpp index 11902bb..2ed9f13 100644 --- a/theseus/render/shape_render.cpp +++ b/theseus/render/shape_render.cpp @@ -15,7 +15,7 @@ #include "scene_groups.h" #include "camera.h" -extern class CMeshNode* g_pRenderMeshNode; +extern class CMeshNode* g_pDrawingShape; extern D3DXMATRIX g_cameraWorld; extern D3DXMATRIX g_viewMatrix; extern D3DXMATRIX g_matProjection; @@ -56,11 +56,11 @@ CShape::~CShape() // if (class chain of geometry reaches MeshNode) { // if (mesh->dirty) { if (url && *url) load(url); mesh->Init(); if (!mesh->core) return; } // if (!mesh->core || !mesh->core->GetFVF()) return; -// g_pRenderMeshNode = mesh; SetVertexShader(GetFixedFunctionShader(fvf)); +// g_pDrawingShape = mesh; SetVertexShader(GetFixedFunctionShader(fvf)); // } // if (appearance) appearance->Render(); // geometry->Render(); -// position = world matrix row 3 (copied from the device); g_pRenderMeshNode = NULL; +// position = world matrix row 3 (copied from the device); g_pDrawingShape = NULL; // Initialize() is the binary's inlined load/Init/core test. The profiler // phases and the per mesh triangle tally are Theseus additions. void CShape::Render() @@ -79,7 +79,7 @@ void CShape::Render() if (meshFVF == 0) return; - g_pRenderMeshNode = pMesh; + g_pDrawingShape = pMesh; TheseusSetVertexShader(GetFixedFunctionShader(meshFVF)); } @@ -100,7 +100,7 @@ void CShape::Render() D3DXMATRIX world; TheseusGetTransform(D3DTS_WORLD, &world); m_position = D3DXVECTOR3(world._41, world._42, world._43); - g_pRenderMeshNode = NULL; + g_pDrawingShape = NULL; } // CShape::GetBBox(pBBox) / GetRadius() / Advance(nSeconds) diff --git a/theseus/render/text.cpp b/theseus/render/text.cpp index fa1ad32..213440f 100644 --- a/theseus/render/text.cpp +++ b/theseus/render/text.cpp @@ -18,9 +18,9 @@ extern void TheseusCreateMeshFVF(DWORD NumFaces, DWORD NumVertices, DWORD Option // The keyboard hands its edit string and cursor to the next Text node that // renders (0x0017e748, 0x00175220, 0x00175224 in the binary). -TCHAR* g_szText = NULL; -int g_nTextChar = -1; -int g_nTextCharLast = -1; +TCHAR* g_szEditText = NULL; +int g_editCursor = -1; +int g_editCursorPrev = -1; // *heading* formatting, off until a script turns it on through the keyboard's // SetAsteriskFormattingState (0x0017e74c, a BSS byte in 5960). @@ -120,7 +120,7 @@ class CFont void CreateTextMesh(const TCHAR* pchText, int nChars, LPD3DXMESH* ppMesh, D3DXVECTOR3* pMin, D3DXVECTOR3* pMax, float nFormatWidth, bool bDoNotBreak, float scale, float indentWidth = 0.0f, float indentHeight = 0.0f); - HANDLE m_hFile; + HANDLE m_hFontFile; private: XtfGlyphSet* m_pSet; @@ -129,7 +129,7 @@ class CFont }; CFont::CFont() : - m_hFile(INVALID_HANDLE_VALUE), + m_hFontFile(INVALID_HANDLE_VALUE), m_pSet(NULL), m_pGlyphs(NULL), m_ppShapes(NULL) @@ -148,10 +148,10 @@ CFont::~CFont() // free glyphSet, glyph records, loaded flags (plus the XTF1 buffers); void CFont::Close() { - if (m_hFile != INVALID_HANDLE_VALUE) + if (m_hFontFile != INVALID_HANDLE_VALUE) { - CloseHandle(m_hFile); - m_hFile = INVALID_HANDLE_VALUE; + CloseHandle(m_hFontFile); + m_hFontFile = INVALID_HANDLE_VALUE; } if (m_ppShapes != NULL) @@ -188,22 +188,22 @@ bool CFont::Open(const TCHAR* szFile) { Close(); - m_hFile = TheseusCreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); - if (m_hFile == INVALID_HANDLE_VALUE) + m_hFontFile = TheseusCreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (m_hFontFile == INVALID_HANDLE_VALUE) return false; DWORD dwMagic = 0, cbHeader = 0, cbSet = 0; char face[XTF_FACE_LEN]; - bool ok = ReadExact(m_hFile, &dwMagic, 4) && dwMagic == XTF0_MAGIC && - ReadExact(m_hFile, &cbHeader, 4) && - ReadExact(m_hFile, face, XTF_FACE_LEN) && - ReadExact(m_hFile, &cbSet, 4) && cbSet >= 20; + bool ok = ReadExact(m_hFontFile, &dwMagic, 4) && dwMagic == XTF0_MAGIC && + ReadExact(m_hFontFile, &cbHeader, 4) && + ReadExact(m_hFontFile, face, XTF_FACE_LEN) && + ReadExact(m_hFontFile, &cbSet, 4) && cbSet >= 20; if (ok) { m_pSet = (XtfGlyphSet*)new BYTE[cbSet]; m_pSet->cbThis = cbSet; - ok = ReadExact(m_hFile, &m_pSet->flAccel, cbSet - 4) && + ok = ReadExact(m_hFontFile, &m_pSet->flAccel, cbSet - 4) && 16 + m_pSet->cRanges * sizeof (XtfRange) == cbSet; } @@ -211,7 +211,7 @@ bool CFont::Open(const TCHAR* szFile) { DWORD nGlyphs = m_pSet->cGlyphs; m_pGlyphs = new XtfGlyph[nGlyphs]; - ok = ReadExact(m_hFile, m_pGlyphs, nGlyphs * sizeof (XtfGlyph)); + ok = ReadExact(m_hFontFile, m_pGlyphs, nGlyphs * sizeof (XtfGlyph)); m_ppShapes = new CGlyphShape*[nGlyphs]; for (DWORD i = 0; i < nGlyphs; i++) @@ -240,24 +240,24 @@ bool CFont::LoadGlyph(int nGlyph) return true; DWORD offset = m_pGlyphs[nGlyph].shapeOffset; - if (offset == 0 || SetFilePointer(m_hFile, offset, NULL, FILE_BEGIN) == (DWORD)-1) + if (offset == 0 || SetFilePointer(m_hFontFile, offset, NULL, FILE_BEGIN) == (DWORD)-1) return false; CGlyphShape* pShape = new CGlyphShape; pShape->indices = NULL; pShape->points = NULL; - bool ok = ReadExact(m_hFile, &pShape->nIndices, 2); + bool ok = ReadExact(m_hFontFile, &pShape->nIndices, 2); if (ok) { pShape->indices = new WORD[pShape->nIndices]; - ok = ReadExact(m_hFile, &pShape->nPoints, 2); + ok = ReadExact(m_hFontFile, &pShape->nPoints, 2); } if (ok) { pShape->points = new XtfPoint[pShape->nPoints]; - ok = ReadExact(m_hFile, pShape->indices, pShape->nIndices * sizeof (WORD)) && - ReadExact(m_hFile, pShape->points, pShape->nPoints * sizeof (XtfPoint)); + ok = ReadExact(m_hFontFile, pShape->indices, pShape->nIndices * sizeof (WORD)) && + ReadExact(m_hFontFile, pShape->points, pShape->nPoints * sizeof (XtfPoint)); } if (!ok) @@ -590,7 +590,7 @@ void CFont::CreateTextMesh(const TCHAR* pchText, int nChars, LPD3DXMESH* ppMesh, col2Max = colWidth[1]; } - if (g_nTextChar >= 0 && g_nTextChar <= nChars) + if (g_editCursor >= 0 && g_editCursor <= nChars) { nFaces += 2; nVerts += 4; @@ -779,7 +779,7 @@ void CFont::CreateTextMesh(const TCHAR* pchText, int nChars, LPD3DXMESH* ppMesh, v.color = color; } - if (ich - 1 == g_nTextChar) + if (ich - 1 == g_editCursor) AddCursor(indices, nIndex, verts, nVertex, x, y, true); x += Advance(nGlyph); @@ -797,7 +797,7 @@ void CFont::CreateTextMesh(const TCHAR* pchText, int nChars, LPD3DXMESH* ppMesh, // The cursor past the last character hides once it would leave the // keyboard's edit box (16.556152 units, 0x0002c1b4). - if (g_nTextChar == nChars) + if (g_editCursor == nChars) AddCursor(indices, nIndex, verts, nVertex, x, y, x < 16.556152f); for (int i = 0; i < nVerts; i++) @@ -839,7 +839,7 @@ static CFontTableEntry g_fonts[MAX_FONT_COUNT] = #endif }; -static int g_nFontCount = 1; +static int g_fontsLoaded = 1; static TCHAR* CopyString(const TCHAR* sz) { @@ -890,7 +890,7 @@ static void InitFontTable() do { - if (g_nFontCount >= MAX_FONT_COUNT) + if (g_fontsLoaded >= MAX_FONT_COUNT) continue; #ifdef _UNICODE @@ -919,9 +919,9 @@ static void InitFontTable() #endif if (_tcscmp(szFace, g_fonts[0].m_szFace) != 0) { - g_fonts[g_nFontCount].m_szFace = CopyString(szFace); - g_fonts[g_nFontCount].m_szFile = CopyString(szPath); - g_nFontCount++; + g_fonts[g_fontsLoaded].m_szFace = CopyString(szFace); + g_fonts[g_fontsLoaded].m_szFile = CopyString(szPath); + g_fontsLoaded++; } } @@ -945,17 +945,17 @@ static void InitFontTable() // Theseus builds the path from its font directory instead of the app dir. CFont* GetFont(const TCHAR* szFaceName) { - if (g_nFontCount == 1) + if (g_fontsLoaded == 1) InitFontTable(); int i = 0; - while (i < g_nFontCount && _tcsicmp(szFaceName, g_fonts[i].m_szFace) != 0) + while (i < g_fontsLoaded && _tcsicmp(szFaceName, g_fonts[i].m_szFace) != 0) i++; - if (i == g_nFontCount) + if (i == g_fontsLoaded) i = 0; CFontTableEntry& entry = g_fonts[i]; - if (entry.m_font.m_hFile == INVALID_HANDLE_VALUE) + if (entry.m_font.m_hFontFile == INVALID_HANDLE_VALUE) { TCHAR szPath[MAX_PATH]; if (_tcschr(entry.m_szFile, ':') != NULL) @@ -964,7 +964,7 @@ CFont* GetFont(const TCHAR* szFaceName) _stprintf(szPath, _T("%s%s"), TheseusGetFontDir(), entry.m_szFile); if (!entry.m_font.Open(szPath) && - g_fonts[0].m_font.m_hFile == INVALID_HANDLE_VALUE && + g_fonts[0].m_font.m_hFontFile == INVALID_HANDLE_VALUE && !g_fonts[0].m_font.Open(g_fonts[0].m_szFile)) return NULL; } @@ -977,7 +977,7 @@ CFont* GetFont(const TCHAR* szFaceName) // frees its face and file strings, then each font closes. void Text_Exit() { - for (int i = 0; i < g_nFontCount; i++) + for (int i = 0; i < g_fontsLoaded; i++) { if (i > 0) { @@ -1140,10 +1140,10 @@ class CTextNode : public CNode DECLARE_NODE_PROPS() - LPD3DXMESH m_pMesh; + LPD3DXMESH m_pGlyphMesh; D3DXVECTOR3 m_bboxMin, m_bboxMax; int m_nLanguage; - XTIME m_timeToScroll; + XTIME m_scrollAt; private: typedef bool (*StampFormatter)(TCHAR* szBuf, SIZE_T chLen, SYSTEMTIME* pst, int locale); @@ -1192,9 +1192,9 @@ CTextNode::CTextNode() : m_indentWidth(0.0f), m_indentHeight(0.0f), m_scrollHorizontal(false), - m_pMesh(NULL), + m_pGlyphMesh(NULL), m_nLanguage(0), - m_timeToScroll(0.0) + m_scrollAt(0.0) { } @@ -1208,10 +1208,10 @@ CTextNode::~CTextNode() void CTextNode::DropMesh() { - if (m_pMesh != NULL) + if (m_pGlyphMesh != NULL) { - m_pMesh->Release(); - m_pMesh = NULL; + m_pGlyphMesh->Release(); + m_pGlyphMesh = NULL; } } @@ -1231,13 +1231,13 @@ void CTextNode::Advance(float nSeconds) { CNode::Advance(nSeconds); - if (m_scrollRate <= 0.0f || m_pMesh == NULL) + if (m_scrollRate <= 0.0f || m_pGlyphMesh == NULL) return; XTIME now = TheseusGetNow(); - if (m_timeToScroll == 0.0) - m_timeToScroll = now + m_scrollDelay; - if (now < m_timeToScroll) + if (m_scrollAt == 0.0) + m_scrollAt = now + m_scrollDelay; + if (now < m_scrollAt) return; float window, content; @@ -1289,7 +1289,7 @@ int CTextNode::ExpandStamp(const TCHAR* szPrefix, StampFormatter pfnFormat, bool GetLocalTime(&st); TCHAR szValue[32]; szValue[0] = 0; - pfnFormat(szValue, countof(szValue), &st, LOCALE_CURRENT); + pfnFormat(szValue, countof(szValue), &st, LOCALE_ACTIVE); if (_tcscmp(m_text + cchPrefix, szValue) != 0) { @@ -1319,16 +1319,16 @@ void CTextNode::Render() { bool bRebuild = false; - if (g_szText != NULL) + if (g_szEditText != NULL) { - if (m_text == NULL || _tcscmp(m_text, g_szText) != 0 || g_nTextChar != g_nTextCharLast) + if (m_text == NULL || _tcscmp(m_text, g_szEditText) != 0 || g_editCursor != g_editCursorPrev) { delete [] m_text; - m_text = CopyString(g_szText); - g_nTextCharLast = g_nTextChar; + m_text = CopyString(g_szEditText); + g_editCursorPrev = g_editCursor; bRebuild = true; } - g_szText = NULL; + g_szEditText = NULL; } if (m_text == NULL || m_text[0] == 0) @@ -1344,25 +1344,25 @@ void CTextNode::Render() szText = m_text + cchStamp; } - if (m_translate && m_nLanguage != g_nCurLanguage) + if (m_translate && m_nLanguage != g_language) bRebuild = true; if (bRebuild) DropMesh(); - if (m_pMesh == NULL) + if (m_pGlyphMesh == NULL) { TCHAR szTranslated[MAX_TRANSLATE_LEN]; if (m_translate) szText = Translate(szText, szTranslated); - m_nLanguage = g_nCurLanguage; + m_nLanguage = g_language; CFont* pFont = GetFont(FaceFromFont(m_font)); if (pFont == NULL || !pFont->IsOpen()) return; - pFont->CreateTextMesh(szText, -1, &m_pMesh, &m_bboxMin, &m_bboxMax, fabsf(m_width), m_width < 0.0f, 1.0f, + pFont->CreateTextMesh(szText, -1, &m_pGlyphMesh, &m_bboxMin, &m_bboxMax, fabsf(m_width), m_width < 0.0f, 1.0f, m_indentWidth, m_indentHeight); - if (m_pMesh == NULL) + if (m_pGlyphMesh == NULL) return; } @@ -1392,11 +1392,11 @@ void CTextNode::Render() { float wrap = copy == 0 ? 0.0f : contentW + SCROLL_GAP; TEXTVERTEX* verts; - if (SUCCEEDED(m_pMesh->LockVertexBuffer(0, (BYTE**)&verts))) + if (SUCCEEDED(m_pGlyphMesh->LockVertexBuffer(0, (BYTE**)&verts))) { float left = m_scroll - 1.0f; - HorizontalFade(verts, m_pMesh->GetNumVertices(), left, left + window + 2.0f, wrap); - m_pMesh->UnlockVertexBuffer(); + HorizontalFade(verts, m_pGlyphMesh->GetNumVertices(), left, left + window + 2.0f, wrap); + m_pGlyphMesh->UnlockVertexBuffer(); } if (copy == 1 && m_scroll + window < contentW) @@ -1410,10 +1410,10 @@ void CTextNode::Render() if (m_scroll == 0.0f) top += 1.0f; // no top fade until it starts moving TEXTVERTEX* verts; - if (SUCCEEDED(m_pMesh->LockVertexBuffer(0, (BYTE**)&verts))) + if (SUCCEEDED(m_pGlyphMesh->LockVertexBuffer(0, (BYTE**)&verts))) { - VerticalFade(verts, m_pMesh->GetNumVertices(), top, bottom, wrap); - m_pMesh->UnlockVertexBuffer(); + VerticalFade(verts, m_pGlyphMesh->GetNumVertices(), top, bottom, wrap); + m_pGlyphMesh->UnlockVertexBuffer(); } if (copy == 1 && m_scroll + m_height < contentH) @@ -1438,7 +1438,7 @@ void CTextNode::Render() #endif TheseusSetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); Frame_Count(FC_DRAW_SUBSET); - m_pMesh->DrawSubset(0); + m_pGlyphMesh->DrawSubset(0); TheseusSetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); #ifndef _XBOX TheseusSetVertexAlphaMul(FALSE); @@ -1459,7 +1459,7 @@ bool CTextNode::OnSetProperty(const PRD* pprd, const void* pvValue) { DropMesh(); m_scroll = 0.0f; - m_timeToScroll = 0.0; + m_scrollAt = 0.0; } return true; } diff --git a/theseus/render/tmap_system.cpp b/theseus/render/tmap_system.cpp index 4f14274..949c528 100644 --- a/theseus/render/tmap_system.cpp +++ b/theseus/render/tmap_system.cpp @@ -181,7 +181,7 @@ void CSurfx::Fade(char* inPix, long inBytesPerRow, long inX, long inY, DeltaFiel // palette used when a DynamicTexture has none of its own. // Last recipe GetHSV ran; out of range requests come back here as 0. -int g_nPalette = -1; +int g_paletteIdx = -1; static inline int Clamp255(int c) { @@ -225,12 +225,12 @@ void HSV2RGB(float H, float S, float V, DWORD& outRGB) // GetHSV(nPalette, i, t, H, S, V) // Reconstructed from 5960 retail XBE @ 0x0005f920. Maps intensity i (0..1) at // time t (seconds) to a color for one of 10 recipes; writes the recipe it used -// to g_nPalette (0x00175e70) first, and anything past 9 snaps to 0. The pow +// to g_paletteIdx (0x00175e70) first, and anything past 9 snaps to 0. The pow // exponents are the doubles at 0x0002c068..0x0002c0f8; wrap() is the // x - floor(x) helper @ 0x0005f3d0. See docs/decomp/TmapSystem.md for the table. void GetHSV(int nPalette, float i, float t, float& H, float& S, float& V) { - g_nPalette = nPalette; + g_paletteIdx = nPalette; switch (nPalette) { @@ -289,7 +289,7 @@ void GetHSV(int nPalette, float i, float t, float& H, float& S, float& V) return; default: - g_nPalette = 0; + g_paletteIdx = 0; // fall through case 0: H = powf(i, 1.9f) * 0.166f; @@ -307,15 +307,15 @@ static inline void BlendHSV(float amount, float H2, float S2, float V2, float& H V = amount * V + (1.0f - amount) * V2; } -int g_nBlendPalette; -float g_nBlendPaletteAmount; +int g_blendTarget; +float g_blendMix; // MakePalette(outPalette) // Reconstructed from 5960 retail XBE @ 0x0005fc30. The default palette: every // 10 + rnd(5) seconds (0x0002c148, 0x0002c140) it moves on to the next recipe // and crossfades from the old one. The blend amount grows by half the time // since the switch on every call (0x0002bed4), so it accumulates rather than -// tracking elapsed time. During a fade the second lookup leaves g_nPalette on +// tracking elapsed time. During a fade the second lookup leaves g_paletteIdx on // the old recipe, so from entry 1 on both lookups read it; the binary does the same. void MakePalette(DWORD outPalette [256]) { @@ -326,9 +326,9 @@ void MakePalette(DWORD outPalette [256]) if (now > nextChange) { nextChange = now + 10.0f + rnd(5.0f); - g_nBlendPalette = g_nPalette; - g_nPalette++; - g_nBlendPaletteAmount = 0.0f; + g_blendTarget = g_paletteIdx; + g_paletteIdx++; + g_blendMix = 0.0f; blendStart = now; } @@ -336,21 +336,21 @@ void MakePalette(DWORD outPalette [256]) for (int n = 0; n < 256; n++, intensity += 1.0f / 255.0f) { float H, S, V; - GetHSV(g_nPalette, intensity, (float)now, H, S, V); - if (g_nBlendPalette != -1) + GetHSV(g_paletteIdx, intensity, (float)now, H, S, V); + if (g_blendTarget != -1) { float H2, S2, V2; - GetHSV(g_nBlendPalette, intensity, (float)now, H2, S2, V2); - BlendHSV(g_nBlendPaletteAmount, H2, S2, V2, H, S, V); + GetHSV(g_blendTarget, intensity, (float)now, H2, S2, V2); + BlendHSV(g_blendMix, H2, S2, V2, H, S, V); } HSV2RGB(H, S, V, outPalette[n]); } - if (g_nBlendPalette != -1) + if (g_blendTarget != -1) { - g_nBlendPaletteAmount += (float)(now - blendStart) / 2.0f; - if (g_nBlendPaletteAmount >= 1.0f) - g_nBlendPalette = -1; + g_blendMix += (float)(now - blendStart) / 2.0f; + if (g_blendMix >= 1.0f) + g_blendTarget = -1; } } @@ -921,7 +921,7 @@ class CPalette : public CNode const DWORD* GetPalette() { return m_palette; } #ifdef _XBOX - D3DPalette* m_pPalette; + D3DPalette* m_pColors; #endif protected: @@ -929,10 +929,10 @@ class CPalette : public CNode void RenderDynamicTexture(CSurfx* pSurfx); DWORD m_palette [256]; - int m_nBlendPalette; - float m_nBlendPaletteAmount; - XTIME m_nextPaletteChangeTime; - XTIME m_startBlendTime; + int m_blendTarget; + float m_blendMix; + XTIME m_paletteSwapTime; + XTIME m_blendBegin; DECLARE_NODE_PROPS() }; @@ -955,10 +955,10 @@ CPalette::CPalette() : m_changePeriodRandomness(0.0f), m_timeToBlend(2.0f) { - m_nBlendPalette = -1; - m_nextPaletteChangeTime = 0.0f; + m_blendTarget = -1; + m_paletteSwapTime = 0.0f; #ifdef _XBOX - m_pPalette = NULL; + m_pColors = NULL; #endif } @@ -968,8 +968,8 @@ CPalette::CPalette() : CPalette::~CPalette() { #ifdef _XBOX - if (m_pPalette != NULL) - m_pPalette->Release(); + if (m_pColors != NULL) + m_pColors->Release(); #endif } @@ -986,29 +986,29 @@ void CPalette::Advance(float nSeconds) CNode::Advance(nSeconds); XTIME now = TheseusGetNow(); - if (m_changePeriod > 0.0f && now > m_nextPaletteChangeTime) + if (m_changePeriod > 0.0f && now > m_paletteSwapTime) { - m_nextPaletteChangeTime = now + m_changePeriod + rnd(m_changePeriodRandomness); - m_nBlendPalette = m_type; + m_paletteSwapTime = now + m_changePeriod + rnd(m_changePeriodRandomness); + m_blendTarget = m_type; m_type++; - m_nBlendPaletteAmount = 0.0f; - m_startBlendTime = now; + m_blendMix = 0.0f; + m_blendBegin = now; } Update(); - if (m_nBlendPalette != -1) + if (m_blendTarget != -1) { - m_nBlendPaletteAmount = (float)(now - m_startBlendTime) / m_timeToBlend; - if (m_nBlendPaletteAmount >= 1.0f) - m_nBlendPalette = -1; + m_blendMix = (float)(now - m_blendBegin) / m_timeToBlend; + if (m_blendMix >= 1.0f) + m_blendTarget = -1; } } // CPalette::Update() // Reconstructed from 5960 retail XBE @ 0x0005d8b0. Fills the 256 entries from // GetHSV (crossfading from the old recipe while a blend runs) and copies -// g_nPalette back into type after each lookup, so an out of range type wraps +// g_paletteIdx back into type after each lookup, so an out of range type wraps // to 0. Then copies the table into a D3D palette with alpha forced to 0xff, // creating it on first use (the binary inlines CreatePalette and Lock). // The palette upload is Xbox only; on desktop the texture upload in @@ -1022,29 +1022,29 @@ void CPalette::Update() { float H, S, V; GetHSV(m_type, intensity, now, H, S, V); - m_type = g_nPalette; + m_type = g_paletteIdx; - if (m_nBlendPalette != -1) + if (m_blendTarget != -1) { float H2, S2, V2; - GetHSV(m_nBlendPalette, intensity, now, H2, S2, V2); - BlendHSV(m_nBlendPaletteAmount, H2, S2, V2, H, S, V); + GetHSV(m_blendTarget, intensity, now, H2, S2, V2); + BlendHSV(m_blendMix, H2, S2, V2, H, S, V); } HSV2RGB(H, S, V, m_palette[n]); } #ifdef _XBOX - if (m_pPalette == NULL) - TheseusGetD3DDev()->CreatePalette(D3DPALETTE_256, &m_pPalette); + if (m_pColors == NULL) + TheseusGetD3DDev()->CreatePalette(D3DPALETTE_256, &m_pColors); // A failed create or lock would leave nothing to write into. D3DCOLOR* entries; - if (m_pPalette == NULL || FAILED(m_pPalette->Lock(&entries, D3DLOCK_NOOVERWRITE))) + if (m_pColors == NULL || FAILED(m_pColors->Lock(&entries, D3DLOCK_NOOVERWRITE))) return; for (int n = 0; n < 256; n++) entries[n] = 0xFF000000 | (m_palette[n] & 0x00FFFFFF); - m_pPalette->Unlock(); + m_pColors->Unlock(); #endif } @@ -1082,8 +1082,8 @@ class CDynamicTexture : public CTexture protected: void Update(); - CSurfx* m_pSurfx; - XTIME m_lastUpdateTime; + CSurfx* m_pScratchSurf; + XTIME m_prevTick; DECLARE_NODE_PROPS() }; @@ -1109,8 +1109,8 @@ CDynamicTexture::CDynamicTexture() : m_palette(NULL) { m_format = D3DFMT_P8; - m_pSurfx = NULL; - m_lastUpdateTime = 0.0f; + m_pScratchSurf = NULL; + m_prevTick = 0.0f; } // CDynamicTexture::~CDynamicTexture() @@ -1120,7 +1120,7 @@ CDynamicTexture::~CDynamicTexture() { if (m_palette != NULL) m_palette->Release(); - delete m_pSurfx; + delete m_pScratchSurf; } // CDynamicTexture::Create(nWidth, nHeight) @@ -1131,17 +1131,17 @@ CDynamicTexture::~CDynamicTexture() // Always 512x512 whatever size asks for; the effect only fills the top left corner. bool CDynamicTexture::Create(int nWidth, int nHeight) { - m_nImageWidth = 512; - m_nImageHeight = 512; - if (FAILED(D3DXCreateTexture(TheseusGetD3DDev(), m_nImageWidth, m_nImageHeight, 1, 0, m_format, D3DPOOL_MANAGED, &m_surface))) + m_texWidth = 512; + m_texHeight = 512; + if (FAILED(D3DXCreateTexture(TheseusGetD3DDev(), m_texWidth, m_texHeight, 1, 0, m_format, D3DPOOL_MANAGED, &m_surface))) return false; D3DLOCKED_RECT lr; m_surface->LockRect(0, &lr, NULL, 0); - memset(lr.pBits, 0, m_nImageWidth * m_nImageHeight); + memset(lr.pBits, 0, m_texWidth * m_texHeight); m_surface->UnlockRect(0); - TheseusGetTextureSize(m_surface, m_nImageWidth, m_nImageHeight); + TheseusGetTextureSize(m_surface, m_texWidth, m_texHeight); return true; } @@ -1166,15 +1166,15 @@ void CDynamicTexture::Advance(float nSeconds) // applies the palette while uploading in Update. LPDIRECT3DTEXTURE8 CDynamicTexture::GetTextureSurface() { - if (TheseusGetNow() > m_lastUpdateTime + 1.0f / m_fps) + if (TheseusGetNow() > m_prevTick + 1.0f / m_fps) { - m_lastUpdateTime = TheseusGetNow(); + m_prevTick = TheseusGetNow(); Update(); } #ifdef _XBOX if (m_palette != NULL && m_palette->IsKindOf(NODE_CLASS(CPalette))) - TheseusGetD3DDev()->SetPalette(0, ((CPalette*)m_palette)->m_pPalette); + TheseusGetD3DDev()->SetPalette(0, ((CPalette*)m_palette)->m_pColors); #endif return m_surface; @@ -1193,17 +1193,17 @@ void CDynamicTexture::Update() if (m_surface == NULL && m_size > 0 && !Create(m_size, m_size)) return; - if (m_pSurfx == NULL && m_size > 0) - m_pSurfx = new CSurfx(m_size, m_size); + if (m_pScratchSurf == NULL && m_size > 0) + m_pScratchSurf = new CSurfx(m_size, m_size); - if (m_surface == NULL || m_pSurfx == NULL || TheseusGetNow() < m_lastUpdateTime) + if (m_surface == NULL || m_pScratchSurf == NULL || TheseusGetNow() < m_prevTick) return; if (m_erase) - memset(m_pSurfx->m_pels, 0, m_pSurfx->m_nWidth * m_pSurfx->m_nHeight); + memset(m_pScratchSurf->m_pels, 0, m_pScratchSurf->m_nWidth * m_pScratchSurf->m_nHeight); for (int n = 0; n < m_children.GetLength(); n++) - m_children.GetNode(n)->RenderDynamicTexture(m_pSurfx); + m_children.GetNode(n)->RenderDynamicTexture(m_pScratchSurf); const DWORD* rgpe = m_palette != NULL ? m_palette->GetPalette() : NULL; DWORD rgpeDefault [256]; @@ -1216,18 +1216,18 @@ void CDynamicTexture::Update() { #ifdef _XBOX (void)rgpe; - Swizzler swz(m_nImageWidth, m_nImageHeight, 1); + Swizzler swz(m_texWidth, m_texHeight, 1); D3DLOCKED_RECT lr; if (FAILED(m_surface->LockRect(0, &lr, NULL, D3DLOCK_DISCARD))) return; BYTE* dst = (BYTE*)lr.pBits; - const BYTE* src = m_pSurfx->m_pels; + const BYTE* src = m_pScratchSurf->m_pels; for (int y = 0; y < m_size; y++, src += m_size) { for (int x = 0; x < m_size; x++, swz.IncU()) dst[swz.Get2D()] = src[x]; swz.IncV(); - swz.AddU(swz.SwizzleU(m_nImageWidth - m_size)); + swz.AddU(swz.SwizzleU(m_texWidth - m_size)); } m_surface->UnlockRect(0); #else @@ -1235,9 +1235,9 @@ void CDynamicTexture::Update() if (FAILED(m_surface->LockRect(0, &lr, NULL, D3DLOCK_DISCARD))) return; uint32_t* pBase = (uint32_t*)lr.pBits; - // Texture is m_nImageWidth wide but we only fill m_size; respect + // Texture is m_texWidth wide but we only fill m_size; respect // the row stride or the data ends up smeared diagonally. - int dstStridePx = (lr.Pitch > 0) ? (lr.Pitch / 4) : m_nImageWidth; + int dstStridePx = (lr.Pitch > 0) ? (lr.Pitch / 4) : m_texWidth; extern bool g_useMilkdropViz; extern bool g_showAlbumCover; @@ -1320,7 +1320,7 @@ void CDynamicTexture::Update() } else { - uint8_t* pbSrc = (uint8_t*)m_pSurfx->m_pels; + uint8_t* pbSrc = (uint8_t*)m_pScratchSurf->m_pels; for (int dy = 0; dy < m_size; dy++) { uint32_t* dstRow = pBase + dy * dstStridePx; for (int dx = 0; dx < m_size; dx++) { @@ -1359,9 +1359,9 @@ class CImageFader : public CNode bool OnSetProperty(const PRD* pprd, const void* pvValue); protected: - DeltaField* m_pDeltaField; - DeltaField* m_pDeltaField2; - XTIME m_nextChangeTime; + DeltaField* m_pWarpA; + DeltaField* m_pWarpB; + XTIME m_nextSwapTime; DECLARE_NODE_PROPS() }; @@ -1382,17 +1382,17 @@ CImageFader::CImageFader() : m_changePeriod(0.0f), m_changePeriodRandomness(0.0f) { - m_pDeltaField = NULL; - m_pDeltaField2 = NULL; - m_nextChangeTime = 0.0f; + m_pWarpA = NULL; + m_pWarpB = NULL; + m_nextSwapTime = 0.0f; } // CImageFader::~CImageFader() // Reconstructed from 5960 retail XBE @ 0x0005e0c0: frees both fields. CImageFader::~CImageFader() { - delete m_pDeltaField; - delete m_pDeltaField2; + delete m_pWarpA; + delete m_pWarpB; } // Inlined twice in 0x0005e120: new DeltaField, style, Assign, SetSize to the surface. @@ -1419,38 +1419,38 @@ static DeltaField* NewDeltaField(int style, CSurfx* pSurfx) // through the current one. void CImageFader::RenderDynamicTexture(CSurfx* pSurfx) { - if (m_pDeltaField == NULL) + if (m_pWarpA == NULL) { - m_pDeltaField = NewDeltaField(m_type, pSurfx); - m_nextChangeTime = TheseusGetNow() + m_changePeriod + rnd(m_changePeriodRandomness); + m_pWarpA = NewDeltaField(m_type, pSurfx); + m_nextSwapTime = TheseusGetNow() + m_changePeriod + rnd(m_changePeriodRandomness); } - else if (m_changePeriod > 0.0f && TheseusGetNow() >= m_nextChangeTime) + else if (m_changePeriod > 0.0f && TheseusGetNow() >= m_nextSwapTime) { m_type++; - m_nextChangeTime = TheseusGetNow() + m_changePeriod; - delete m_pDeltaField; - m_pDeltaField = m_pDeltaField2; - m_pDeltaField2 = NULL; + m_nextSwapTime = TheseusGetNow() + m_changePeriod; + delete m_pWarpA; + m_pWarpA = m_pWarpB; + m_pWarpB = NULL; } - if (m_pDeltaField2 == NULL) - m_pDeltaField2 = NewDeltaField(m_type + 1, pSurfx); + if (m_pWarpB == NULL) + m_pWarpB = NewDeltaField(m_type + 1, pSurfx); - if (m_pDeltaField->IsCalculating()) + if (m_pWarpA->IsCalculating()) { for (int n = 0; n < 10; n++) - m_pDeltaField->CalcSome(); - m_type = m_pDeltaField->m_nStyle; + m_pWarpA->CalcSome(); + m_type = m_pWarpA->m_nStyle; return; } - if (m_pDeltaField2->IsCalculating()) + if (m_pWarpB->IsCalculating()) { for (int n = 0; n < 5; n++) - m_pDeltaField2->CalcSome(); + m_pWarpB->CalcSome(); } - pSurfx->Fade(m_pDeltaField->GetField()); + pSurfx->Fade(m_pWarpA->GetField()); } // CImageFader::OnSetProperty(pprd, pvValue) @@ -1462,9 +1462,9 @@ bool CImageFader::OnSetProperty(const PRD* pprd, const void* pvValue) { if (PTR2INT(pprd->pbOffset) == offsetof(m_type)) { - delete m_pDeltaField; - m_pDeltaField = m_pDeltaField2; - m_pDeltaField2 = NULL; + delete m_pWarpA; + m_pWarpA = m_pWarpB; + m_pWarpB = NULL; } return true; } @@ -1501,14 +1501,14 @@ class CAudioVisualizer : public CNode void RenderEffect1(CSurfx* pSurfx); void RenderEffect2(CSurfx* pSurfx); - short m_pcmLeft [256]; - short m_pcmRight [256]; + short m_waveL [256]; + short m_waveR [256]; - short m_fftLeft [128]; - short m_fftRight [128]; - bool m_bFFTValid; + short m_specL [128]; + short m_specR [128]; + bool m_bHaveSpectrum; short m_pcmMono [256]; - bool m_bMonoValid; + bool m_bHaveMono; DECLARE_NODE_PROPS() }; @@ -1577,11 +1577,11 @@ void CAudioVisualizer::CalcSpectrum(short* pcm, short* fft) // Reconstructed from 5960 retail XBE @ 0x00063900: once per frame, left then right. void CAudioVisualizer::UpdateSpectrum() { - if (m_bFFTValid) + if (m_bHaveSpectrum) return; - CalcSpectrum(m_pcmLeft, m_fftLeft); - CalcSpectrum(m_pcmRight, m_fftRight); - m_bFFTValid = true; + CalcSpectrum(m_waveL, m_specL); + CalcSpectrum(m_waveR, m_specR); + m_bHaveSpectrum = true; } // log(level) * 8 as a byte, 0 for silence (and NaN), 255 at the top. @@ -1620,11 +1620,11 @@ void CAudioVisualizer::RenderDynamicTexture(CSurfx* pSurfx) for (int n = 0; n < 256; n++) { - m_pcmLeft[n] = n < count ? samples[n * 2] : 0; - m_pcmRight[n] = n < count ? samples[n * 2 + 1] : 0; + m_waveL[n] = n < count ? samples[n * 2] : 0; + m_waveR[n] = n < count ? samples[n * 2 + 1] : 0; } - m_bMonoValid = false; - m_bFFTValid = false; + m_bHaveMono = false; + m_bHaveSpectrum = false; if (count > pSurfx->m_nHeight) count = pSurfx->m_nHeight; @@ -1668,9 +1668,9 @@ void CAudioVisualizer::RenderDynamicTexture(CSurfx* pSurfx) UpdateSpectrum(); for (int n = 0; n < 128; n++) - bars[n] = SpectrumByte(m_fftLeft[127 - n]); + bars[n] = SpectrumByte(m_specL[127 - n]); for (int n = 128; n < 256; n++) - bars[n] = SpectrumByte(m_fftRight[n - 128]); + bars[n] = SpectrumByte(m_specR[n - 128]); for (int n = 0; n < 256; n++) { @@ -1729,7 +1729,7 @@ void CAudioVisualizer::RenderEffect1(CSurfx* pSurfx) int bass = 0; for (int n = 0; n < 5; n++) - bass += (m_fftLeft[n] >> 4) + (m_fftRight[n] >> 4); + bass += (m_specL[n] >> 4) + (m_specR[n] >> 4); bass /= 10; if (bass > s_beat.highNow) @@ -1805,7 +1805,7 @@ void CAudioVisualizer::RenderEffect2(CSurfx* pSurfx) const int midX = width >> 1; const int midY = height >> 1; - float right = (float)((((m_pcmLeft[0] + m_pcmRight[0]) >> 9) * s_waveAmplitude * height) >> 12); + float right = (float)((((m_waveL[0] + m_waveR[0]) >> 9) * s_waveAmplitude * height) >> 12); float left = right; if (s_waveMode < 0 || TheseusGetNow() >= nextMode) @@ -1848,8 +1848,8 @@ void CAudioVisualizer::RenderEffect2(CSurfx* pSurfx) { float lastRight = right, lastLeft = left; int slot = (n << 8) / width / 5; - right = (float)(((m_pcmRight[slot] >> 8) * s_waveAmplitude * height) >> 12); - left = (float)(((m_pcmLeft[slot] >> 8) * s_waveAmplitude * height) >> 12); + right = (float)(((m_waveR[slot] >> 8) * s_waveAmplitude * height) >> 12); + left = (float)(((m_waveL[slot] >> 8) * s_waveAmplitude * height) >> 12); switch (s_waveMode) { diff --git a/theseus/shared/keyboard_node.cpp b/theseus/shared/keyboard_node.cpp index 9c2a949..38ddd0d 100755 --- a/theseus/shared/keyboard_node.cpp +++ b/theseus/shared/keyboard_node.cpp @@ -14,11 +14,11 @@ // Shared with the Text node: the keyboard lends it the edit string and cursor // (0x0017e748, 0x00175220), flags the highlighted key (0x0017e74d) and owns the // *heading* switch (0x0017e74c). -extern TCHAR* g_szText; -extern int g_nTextChar; +extern TCHAR* g_szEditText; +extern int g_editCursor; extern bool g_bActiveKey; extern bool g_bAsteriskFormatting; -extern int g_nCurLanguage; +extern int g_language; #ifndef _XBOX // Desktop: the keyboard drawn last takes the physical keyboard (sdl_main.cpp). @@ -139,7 +139,7 @@ static const WORD* const s_layouts[2][3] = static inline bool JapaneseGrid() { - return g_nCurLanguage == 1; + return g_language == 1; } static inline int BottomRow() @@ -921,10 +921,10 @@ static const TCHAR* FunctionKeyLabel(WORD key) // CKeyboard::Render() // Reconstructed from 5960 retail XBE @ 0x0005b9d0. Draws the frame, then the -// text node with the edit string and cursor handed over through g_szText / -// g_nTextChar. The key nodes only draw when the nodearray has exactly 45 +// text node with the edit string and cursor handed over through g_szEditText / +// g_editCursor. The key nodes only draw when the nodearray has exactly 45 // (western) or 99 (Japanese) entries. Each grid cell that starts a new key -// gets the next node: its label goes in g_szText (the function key name, or +// gets the next node: its label goes in g_szEditText (the function key name, or // the character, uppercased on western pages when shift and caps disagree), // g_bActiveKey says whether it is highlighted, and blanks are skipped. void CKeyboard::Render() @@ -941,24 +941,24 @@ void CKeyboard::Render() { m_edit[m_editLen] = 0; #ifdef _XBOX - g_szText = m_edit; - g_nTextChar = m_cursor; + g_szEditText = m_edit; + g_editCursor = m_cursor; #else // The text node counts bytes and puts the cursor before the character - // whose last byte is g_nTextChar, so the cursor moves into bytes too. + // whose last byte is g_editCursor, so the cursor moves into bytes too. TCHAR text[EDIT_MAX * 3 + 1]; - g_szText = text; - g_nTextChar = m_cursor; + g_szEditText = text; + g_editCursor = m_cursor; if (m_cursor >= 0) { int len = KeyLen(m_edit); int bytes = EncodeUTF8(m_edit, m_cursor < len ? m_cursor + 1 : len, text); - g_nTextChar = m_cursor < len ? bytes - 1 : bytes + m_cursor - len; + g_editCursor = m_cursor < len ? bytes - 1 : bytes + m_cursor - len; } EncodeUTF8(m_edit, m_editLen, text); #endif m_text->Render(); - g_nTextChar = -1; + g_editCursor = -1; } bool japanese = JapaneseGrid(); @@ -983,7 +983,7 @@ void CKeyboard::Render() const TCHAR* name = FunctionKeyLabel(key); if (name != NULL) { - g_szText = (TCHAR*)name; + g_szEditText = (TCHAR*)name; } else { @@ -994,7 +994,7 @@ void CKeyboard::Render() #else label[EncodeUTF8((KEYCHAR)ch, label)] = 0; #endif - g_szText = label; + g_szEditText = label; } g_bActiveKey = (cell == highlighted); diff --git a/theseus/shared/savegame_grid.cpp b/theseus/shared/savegame_grid.cpp index 0973805..52b6048 100644 --- a/theseus/shared/savegame_grid.cpp +++ b/theseus/shared/savegame_grid.cpp @@ -33,8 +33,8 @@ extern void FormatDeviceName(int devUnit, TCHAR *szBuf); extern CNode *GetTextNode(const TCHAR *szText, float nWidth); extern float g_nEffectAlpha; extern XTIME g_pulseStartTime; -extern const TCHAR *g_szCurTitleImage; -extern const TCHAR *g_szSelTitleImage; +extern const TCHAR *g_szTitleArt; +extern const TCHAR *g_szPickedTitleArt; TCHAR szSelectionBuf[MAX_PATH]; CGameCopier theGameCopier; @@ -733,10 +733,10 @@ void CSavedGameGrid::RefreshDiskFreeSpace() int totalBlocks = (int)((total.QuadPart + BLOCK_SIZE - 1) / BLOCK_SIZE) - 1; int freeBlocks = (int)((free.QuadPart + BLOCK_SIZE - 1) / BLOCK_SIZE); - if (totalBlocks == m_deviceBlocks && freeBlocks == m_freeBlocks && g_nCurLanguage == m_shownLanguage) + if (totalBlocks == m_deviceBlocks && freeBlocks == m_freeBlocks && g_language == m_shownLanguage) return; - m_shownLanguage = g_nCurLanguage; + m_shownLanguage = g_language; m_deviceBlocks = totalBlocks; m_freeBlocks = freeBlocks; CallFunction(this, _T("OnTotalFreeChanged")); @@ -994,16 +994,16 @@ void CSavedGameGrid::RenderIconRow(D3DXMATRIX *pMatrix, float y, int nTitle, int else _tcscpy(image, _T("dlcitem64.xbx")); - g_szCurTitleImage = image; + g_szTitleArt = image; RenderNodeAt(m_SavedIconPanel, &at); } else { _tcscpy(image, _T("soundtracksave64.tga")); - g_szCurTitleImage = image; + g_szTitleArt = image; RenderNodeAt(m_SoundtrackIconPanel, &at); } - g_szCurTitleImage = NULL; + g_szTitleArt = NULL; if (!m_detachIcon && m_smallIconHilite != NULL && nTitle == m_curTitle && item == m_curGridItem) RenderNodeAt(m_iconRing, &at); @@ -1060,7 +1060,7 @@ void CSavedGameGrid::RenderTitlePodAt(int nTitle, float y, const D3DXMATRIX *par TCHAR image[MAX_PATH]; ResolveTitlePodImageName(nTitle, image); - g_szCurTitleImage = image; + g_szTitleArt = image; const float alphaBefore = g_nEffectAlpha; CNode *panel = (nTitle == m_soundtrackRow) ? m_podSoundtrackPanel : m_podSavePanel; @@ -1086,7 +1086,7 @@ void CSavedGameGrid::RenderTitlePodAt(int nTitle, float y, const D3DXMATRIX *par else { g_nEffectAlpha *= 1.0f - t; - g_szCurTitleImage = NULL; + g_szTitleArt = NULL; m_focusPodMatrixValid = true; ring = false; plain = true; @@ -1120,7 +1120,7 @@ void CSavedGameGrid::RenderTitlePodAt(int nTitle, float y, const D3DXMATRIX *par } g_nEffectAlpha = alphaBefore; - g_szCurTitleImage = image; + g_szTitleArt = image; if (plain) { @@ -1130,7 +1130,7 @@ void CSavedGameGrid::RenderTitlePodAt(int nTitle, float y, const D3DXMATRIX *par RenderNodeAt(m_pod, &at); RenderNodeAt(panel, &at); } - g_szCurTitleImage = NULL; + g_szTitleArt = NULL; } // CSavedGameGrid::Render @@ -1481,7 +1481,7 @@ void CSavedGameGrid::selectRight() // TitleImage.xbx (or the logo), or the soundtrack art. Theseus adds DLC. void CSavedGameGrid::setSelImage() { - g_szSelTitleImage = NULL; + g_szPickedTitleArt = NULL; if (m_curTitle == -1) { @@ -1507,7 +1507,7 @@ void CSavedGameGrid::setSelImage() _tcscpy(szSelectionBuf, _T("dlcitem128.xbx")); } - g_szSelTitleImage = szSelectionBuf; + g_szPickedTitleArt = szSelectionBuf; } // ContentMeta.xbx is a UTF-16 INI-like blob with [language] sections each diff --git a/theseus/xbox/config.cpp b/theseus/xbox/config.cpp index b3feb7c..9ed6931 100755 --- a/theseus/xbox/config.cpp +++ b/theseus/xbox/config.cpp @@ -208,7 +208,7 @@ CStrObject *CConfig::GetAVRegion() CStrObject *CConfig::GetGameRegion() { const TCHAR *szName = NULL; - switch (g_nCurRegion) + switch (g_region) { case XC_GAME_REGION_NA: szName = _T("NA"); break; case XC_GAME_REGION_JAPAN: szName = _T("JAPAN"); break; diff --git a/theseus/xbox/main.cpp b/theseus/xbox/main.cpp index 55690fc..11ed8ff 100644 --- a/theseus/xbox/main.cpp +++ b/theseus/xbox/main.cpp @@ -1036,7 +1036,7 @@ static void Xbox_Init() DeleteFileA(TheseusTempWmaFileA); BootMark(" Xbox_Init: temp file cleanup"); - g_nCurRegion = XGetGameRegion(); + g_region = XGetGameRegion(); BootMark(" Xbox_Init: XGetGameRegion"); InitSkin(); diff --git a/theseus/xbox/panic_screen.cpp b/theseus/xbox/panic_screen.cpp index fa9bcc0..c23b8e9 100644 --- a/theseus/xbox/panic_screen.cpp +++ b/theseus/xbox/panic_screen.cpp @@ -248,7 +248,7 @@ void TheseusPanic(const TCHAR* reason, const TCHAR* nextStep, LPEXCEPTION_POINTE DWORD startTick = GetTickCount(); // Force the font table to load now so the very first frame has glyphs. - // OverlayFontDraw lazy-inits but only triggers when g_nFontCount==1, and + // OverlayFontDraw lazy-inits but only triggers when g_fontsLoaded==1, and // we want any failure to be visible in the panic log via the TRACE inside. (void)OverlayFontMeasure(_T("Theseus"), 16.0f); From 77c02a9b037ba559e9672106cc87cfdff2937dda Mon Sep 17 00:00:00 2001 From: Milenko <39630670+MrMilenko@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:55:53 -0500 Subject: [PATCH 7/8] Renamed audio, screen and settings leftovers The play state defines, the audio and screen change trackers, the screen saver pointer, the settings file member and the alloc retry counter got names of their own. Compiled code is unchanged. --- theseus/desktop/desktop_nodes.cpp | 12 ++++---- theseus/desktop/memutil.cpp | 10 +++---- theseus/engine/settings_nodes.cpp | 40 ++++++++++++------------- theseus/render/tmap_system.cpp | 2 +- theseus/shared/audio.h | 12 ++++---- theseus/shared/audio_system.cpp | 50 +++++++++++++++---------------- theseus/shared/screen.cpp | 18 +++++------ theseus/shared/screen.h | 6 ++-- theseus/xbox/memutil.cpp | 12 ++++---- 9 files changed, 81 insertions(+), 81 deletions(-) diff --git a/theseus/desktop/desktop_nodes.cpp b/theseus/desktop/desktop_nodes.cpp index 1590122..c2db6b1 100644 --- a/theseus/desktop/desktop_nodes.cpp +++ b/theseus/desktop/desktop_nodes.cpp @@ -1937,7 +1937,7 @@ class CSavedGameGrid : public CNode m_deleteUserContent = false; m_enumDone = false; m_nScrollTo = 0.0f; - m_timeScroll = 0.0f; + m_slideBegan = 0.0f; } DECLARE_NODE(CSavedGameGrid, CNode) @@ -1988,7 +1988,7 @@ class CSavedGameGrid : public CNode bool m_deleteUserContent; bool m_enumDone; float m_nScrollTo; // 5960 +0xd4 - float m_timeScroll; // 5960 keeps a double at +0xd8; this one is a float + float m_slideBegan; // 5960 keeps a double at +0xd8; this one is a float // CSavedGameGrid::Advance(dt) // From 5960 @ 0x00047e50: nothing without a device or while hidden; the @@ -2015,13 +2015,13 @@ class CSavedGameGrid : public CNode CallFunction(this, _T("OnUpdatingTitlesEnd")); } - if (m_timeScroll == 0.0f) + if (m_slideBegan == 0.0f) return; - float t = (float)(TheseusGetNow() - m_timeScroll) / 0.25f; + float t = (float)(TheseusGetNow() - m_slideBegan) / 0.25f; if (t >= 1.0f) { t = 1.0f; - m_timeScroll = 0.0f; + m_slideBegan = 0.0f; } m_scroll = (1.0f - t) * m_scroll + t * m_nScrollTo; } @@ -2285,7 +2285,7 @@ class CSavedGameGrid : public CNode if (n >= 0 && n < s_titleCount) { m_nScrollTo = -RenderLoop(false); - m_timeScroll = TheseusGetNow(); + m_slideBegan = TheseusGetNow(); } CallFunction(this, "OnSelChange"); } diff --git a/theseus/desktop/memutil.cpp b/theseus/desktop/memutil.cpp index 76b1489..f187d7e 100755 --- a/theseus/desktop/memutil.cpp +++ b/theseus/desktop/memutil.cpp @@ -9,7 +9,7 @@ extern bool CleanupTextureCache(); extern bool CleanupMeshCache(); // How far the out of memory recovery has got. -int g_nNewFailedState; +int g_allocRetryStage; // NewFailed(bytes) // Follows the 5960 retail XBE's out of memory handling (inlined around its @@ -20,9 +20,9 @@ int g_nNewFailedState; int __cdecl NewFailed(size_t nBytes) { bool freed = false; - if (g_nNewFailedState == 0) + if (g_allocRetryStage == 0) freed = CleanupTextureCache(); - else if (g_nNewFailedState == 1) + else if (g_allocRetryStage == 1) freed = CleanupMeshCache(); else { @@ -31,7 +31,7 @@ int __cdecl NewFailed(size_t nBytes) } if (!freed) - g_nNewFailedState++; + g_allocRetryStage++; return 1; } @@ -52,5 +52,5 @@ void TheseusCreateMeshFVF(DWORD NumFaces, DWORD NumVertices, DWORD Options, DWOR void Memory_Init() { - g_nNewFailedState = 0; + g_allocRetryStage = 0; } diff --git a/theseus/engine/settings_nodes.cpp b/theseus/engine/settings_nodes.cpp index ff4c5b1..59de571 100755 --- a/theseus/engine/settings_nodes.cpp +++ b/theseus/engine/settings_nodes.cpp @@ -36,7 +36,7 @@ class CSettings : public CNode protected: bool OpenCurrent(); - CSettingsFile m_sfile; + CSettingsFile m_store; }; // What settings. evaluates to: reading it fetches the value, @@ -111,17 +111,17 @@ CObject* CSettings::Dot(CObject* member) // needed. bool CSettings::OpenCurrent() { - if (m_sfile.GetFileName() != NULL && _tcsicmp(m_sfile.GetFileName(), m_file) == 0) + if (m_store.GetFileName() != NULL && _tcsicmp(m_store.GetFileName(), m_file) == 0) return true; - m_sfile.Close(); - return m_sfile.Open(m_file); + m_store.Close(); + return m_store.Open(m_file); } void CSettings::Reload() { - m_sfile.Close(); + m_store.Close(); if (m_file != NULL) - m_sfile.Open(m_file); + m_store.Open(m_file); } // CSettings::SetValue(name, value) [script fn 'SetValue', FND 0x00182028, sig 13] @@ -130,7 +130,7 @@ void CSettings::Reload() void CSettings::SetValue(const TCHAR* name, const TCHAR* value) { OpenCurrent(); - m_sfile.SetValue(m_section, name, value); + m_store.SetValue(m_section, name, value); } // CSettings::GetValue(name) [script fn 'GetValue', FND 0x00182010, sig 5] @@ -142,7 +142,7 @@ CStrObject* CSettings::GetValue(const TCHAR* name) if (!OpenCurrent()) return new CStrObject(_T("")); TCHAR value[1024]; - m_sfile.GetValue(m_section, name, value, countof(value)); + m_store.GetValue(m_section, name, value, countof(value)); return new CStrObject(value); } @@ -204,7 +204,7 @@ class CScreenSaver : public CNode void SetDelay2(float secs); void SetDelay3(float secs); - static CScreenSaver* c_pTheScreenSaver; + static CScreenSaver* c_pSaver; bool m_enabled; bool m_isActive; @@ -213,7 +213,7 @@ class CScreenSaver : public CNode float m_delay; float m_delay2; float m_delay3; - XTIME m_timeOfLastEvent; + XTIME m_lastInputTime; }; IMPLEMENT_NODE("ScreenSaver", CScreenSaver, CNode) @@ -239,7 +239,7 @@ START_NODE_FUN(CScreenSaver, CNode) END_NODE_FUN() #undef _FND_CLASS -CScreenSaver* CScreenSaver::c_pTheScreenSaver = NULL; // 0x0017e738 +CScreenSaver* CScreenSaver::c_pSaver = NULL; // 0x0017e738 XTIME g_timeOfLastEvent; // 0x0017c030 // CScreenSaver::CScreenSaver() @@ -255,15 +255,15 @@ CScreenSaver::CScreenSaver() m_delay = 300.0f; m_delay2 = 0.0f; m_delay3 = 0.0f; - m_timeOfLastEvent = TheseusGetNow(); - c_pTheScreenSaver = this; + m_lastInputTime = TheseusGetNow(); + c_pSaver = this; } // Reconstructed from 5960 retail XBE @ 0x00040190. CScreenSaver::~CScreenSaver() { - if (c_pTheScreenSaver == this) - c_pTheScreenSaver = NULL; + if (c_pSaver == this) + c_pSaver = NULL; } void CScreenSaver::StartAfter(float secs) { m_delay = secs; } @@ -289,18 +289,18 @@ void CScreenSaver::Advance(float dt) CallFunction(this, _T("OnEnd")); } } - else if (!m_isActive && now >= m_timeOfLastEvent + m_delay) + else if (!m_isActive && now >= m_lastInputTime + m_delay) { m_isActive = true; CallFunction(this, _T("OnStart")); } - if (m_delay2 > 0.0f && !m_isActive2 && now >= m_timeOfLastEvent + m_delay2) + if (m_delay2 > 0.0f && !m_isActive2 && now >= m_lastInputTime + m_delay2) { m_isActive2 = true; CallFunction(this, _T("OnDelay2")); } - if (m_delay3 > 0.0f && !m_isActive3 && now >= m_timeOfLastEvent + m_delay3) + if (m_delay3 > 0.0f && !m_isActive3 && now >= m_lastInputTime + m_delay3) { m_isActive3 = true; CallFunction(this, _T("OnDelay3")); @@ -319,7 +319,7 @@ void CScreenSaver::reset() } m_isActive2 = false; m_isActive3 = false; - m_timeOfLastEvent = TheseusGetNow(); + m_lastInputTime = TheseusGetNow(); } // CScreenSaver::OnSetProperty(prd, value) @@ -345,7 +345,7 @@ bool ResetScreenSaver() { g_timeOfLastEvent = TheseusGetNow(); - CScreenSaver* saver = CScreenSaver::c_pTheScreenSaver; + CScreenSaver* saver = CScreenSaver::c_pSaver; if (saver == NULL) return false; diff --git a/theseus/render/tmap_system.cpp b/theseus/render/tmap_system.cpp index 949c528..57da791 100644 --- a/theseus/render/tmap_system.cpp +++ b/theseus/render/tmap_system.cpp @@ -1605,7 +1605,7 @@ static inline BYTE SpectrumByte(short level) void CAudioVisualizer::RenderDynamicTexture(CSurfx* pSurfx) { CAudioClip* clip = (CAudioClip*)m_source; - if (clip == NULL || clip->GetNodeClass() != NODE_CLASS(CAudioClip) || clip->m_transportMode != TRANSPORT_PLAY) + if (clip == NULL || clip->GetNodeClass() != NODE_CLASS(CAudioClip) || clip->m_transportMode != PLAYSTATE_PLAYING) return; short* samples = (short*)clip->GetSampleBuffer(); diff --git a/theseus/shared/audio.h b/theseus/shared/audio.h index 1c4a3fa..7a45d3c 100755 --- a/theseus/shared/audio.h +++ b/theseus/shared/audio.h @@ -6,9 +6,9 @@ #pragma once // transportMode values the scripts see. -#define TRANSPORT_STOP 0 -#define TRANSPORT_PLAY 1 -#define TRANSPORT_PAUSE 2 +#define PLAYSTATE_STOPPED 0 +#define PLAYSTATE_PLAYING 1 +#define PLAYSTATE_PAUSED 2 class CAudioBuf; @@ -29,7 +29,7 @@ class CAudioClip : public CTimeDepNode float m_progress; bool m_removeVoice; int m_transportMode; - int m_lastTransportMode; + int m_prevPlayState; void Play(); void Pause(); @@ -47,9 +47,9 @@ class CAudioClip : public CTimeDepNode protected: bool m_dirty; // url changed; the sound gets loaded again bool m_unpauseNeeded; // paused for a level change, resume after - float m_lastVolume; + float m_prevVolume; float m_lastPan; - float m_lastFrequency; + float m_prevFreq; float m_fade; // seconds a volume or pan change glides over float m_volume; float m_pan; diff --git a/theseus/shared/audio_system.cpp b/theseus/shared/audio_system.cpp index 7fc8a3a..0f1032e 100755 --- a/theseus/shared/audio_system.cpp +++ b/theseus/shared/audio_system.cpp @@ -784,13 +784,13 @@ CAudioClip::CAudioClip() m_pause_on_moving = false; m_progress = 0.0f; m_removeVoice = false; - m_transportMode = TRANSPORT_STOP; - m_lastTransportMode = -1; + m_transportMode = PLAYSTATE_STOPPED; + m_prevPlayState = -1; m_dirty = true; m_unpauseNeeded = false; - m_lastVolume = 1.0f; + m_prevVolume = 1.0f; m_lastPan = 0.0f; - m_lastFrequency = 0.0f; + m_prevFreq = 0.0f; m_fade = 0.0f; m_volume = 1.0f; m_pan = 0.0f; @@ -862,9 +862,9 @@ HRESULT CAudioClip::Cleanup() Stop(); delete m_sound; m_sound = NULL; - m_lastVolume = 1.0f; + m_prevVolume = 1.0f; m_lastPan = 0.0f; - m_lastFrequency = 0.0f; + m_prevFreq = 0.0f; return S_OK; } @@ -1095,17 +1095,17 @@ void CAudioClip::Advance(float nSeconds) if (m_sound == NULL) { m_isActive = false; - m_transportMode = TRANSPORT_STOP; + m_transportMode = PLAYSTATE_STOPPED; } else if (m_isActive) { - if (m_volume != m_lastVolume) + if (m_volume != m_prevVolume) { - if (m_lastVolume == 0.0f && m_transportMode == TRANSPORT_PAUSE) + if (m_prevVolume == 0.0f && m_transportMode == PLAYSTATE_PAUSED) Pause(); - m_lastVolume = m_volume; + m_prevVolume = m_volume; m_sound->SetAttenuation((1.0f - m_volume) * 100.0f); - if (m_volume == 0.0f && m_transportMode == TRANSPORT_PLAY) + if (m_volume == 0.0f && m_transportMode == PLAYSTATE_PLAYING) Pause(); } @@ -1115,9 +1115,9 @@ void CAudioClip::Advance(float nSeconds) m_sound->SetPan(m_pan); } - if (m_frequency != m_lastFrequency) + if (m_frequency != m_prevFreq) { - m_lastFrequency = m_frequency; + m_prevFreq = m_frequency; m_sound->SetFrequency(m_frequency); } @@ -1134,11 +1134,11 @@ void CAudioClip::Advance(float nSeconds) bool ended = false; if (m_sound->IsPaused()) { - m_transportMode = TRANSPORT_PAUSE; + m_transportMode = PLAYSTATE_PAUSED; } else if (m_sound->IsPlaying()) { - m_transportMode = TRANSPORT_PLAY; + m_transportMode = PLAYSTATE_PLAYING; if (m_sendProgress) { float length = m_sound->GetPlaybackLength(); @@ -1148,20 +1148,20 @@ void CAudioClip::Advance(float nSeconds) } else { - ended = m_transportMode == TRANSPORT_PLAY; + ended = m_transportMode == PLAYSTATE_PLAYING; } if (ended) { - m_transportMode = TRANSPORT_STOP; + m_transportMode = PLAYSTATE_STOPPED; m_isActive = false; CallFunction(this, _T("OnEndOfAudio")); } } - if (m_transportMode != m_lastTransportMode) + if (m_transportMode != m_prevPlayState) { - m_lastTransportMode = m_transportMode; + m_prevPlayState = m_transportMode; CallFunction(this, _T("OnTransportModeChanged")); } } @@ -1171,7 +1171,7 @@ void CAudioClip::Advance(float nSeconds) // if (transportMode is PLAY or PAUSE) Pause(); else Play(); void CAudioClip::PlayOrPause() { - if (m_transportMode == TRANSPORT_PLAY || m_transportMode == TRANSPORT_PAUSE) + if (m_transportMode == PLAYSTATE_PLAYING || m_transportMode == PLAYSTATE_PAUSED) Pause(); else Play(); @@ -1195,7 +1195,7 @@ void CAudioClip::Play() m_sound->SetFrequency(m_frequency); if (m_sound->Play(m_capturedLoop)) { - m_transportMode = TRANSPORT_PLAY; + m_transportMode = PLAYSTATE_PLAYING; m_isActive = true; } } @@ -1206,10 +1206,10 @@ void CAudioClip::Play() // loads it fresh from the start. void CAudioClip::Stop() { - if (m_transportMode == TRANSPORT_STOP) + if (m_transportMode == PLAYSTATE_STOPPED) return; - m_transportMode = TRANSPORT_STOP; + m_transportMode = PLAYSTATE_STOPPED; if (m_sound != NULL) m_sound->Stop(); delete m_sound; @@ -1226,8 +1226,8 @@ void CAudioClip::Pause() if (m_dirty) Initialize(); - bool pausing = m_transportMode != TRANSPORT_PAUSE; - m_transportMode = pausing ? TRANSPORT_PAUSE : TRANSPORT_PLAY; + bool pausing = m_transportMode != PLAYSTATE_PAUSED; + m_transportMode = pausing ? PLAYSTATE_PAUSED : PLAYSTATE_PLAYING; if (m_sound != NULL) m_sound->Pause(pausing); } diff --git a/theseus/shared/screen.cpp b/theseus/shared/screen.cpp index 991cc14..49729ab 100755 --- a/theseus/shared/screen.cpp +++ b/theseus/shared/screen.cpp @@ -53,9 +53,9 @@ CScreen::CScreen() m_letterbox = false; m_wideScreen = false; m_brightness = 1.0f; - m_lastBrightness = 1.0f; - m_bSizeDirty = false; - m_bTitleDirty = false; + m_appliedBrightness = 1.0f; + m_bResized = false; + m_bRetitled = false; if (TheseusGetScreen() == NULL) TheseusSetScreen(this); @@ -81,11 +81,11 @@ bool CScreen::OnSetProperty(const PRD* prop, const void* value) int field = PTR2INT(prop->pbOffset); if (field == offsetof(m_width) || field == offsetof(m_height)) { - m_bSizeDirty = true; + m_bResized = true; } else if (field == offsetof(m_title)) { - m_bTitleDirty = true; + m_bRetitled = true; } else if (field == offsetof(m_brightness)) { @@ -107,12 +107,12 @@ bool CScreen::OnSetProperty(const PRD* prop, const void* value) void CScreen::Advance(float dt) { CNode::Advance(dt); - m_bSizeDirty = false; - m_bTitleDirty = false; - if (m_brightness != m_lastBrightness) + m_bResized = false; + m_bRetitled = false; + if (m_brightness != m_appliedBrightness) { SetBrightness(m_brightness); - m_lastBrightness = m_brightness; + m_appliedBrightness = m_brightness; } } diff --git a/theseus/shared/screen.h b/theseus/shared/screen.h index ccc7970..6dc6bb0 100755 --- a/theseus/shared/screen.h +++ b/theseus/shared/screen.h @@ -34,11 +34,11 @@ class CScreen : public CNode bool OnSetProperty(const PRD* pprd, const void* pvValue); void Advance(float nSeconds); - bool m_bSizeDirty; - bool m_bTitleDirty; + bool m_bResized; + bool m_bRetitled; void SetBrightness(float nBrightness); - float m_lastBrightness; + float m_appliedBrightness; DECLARE_NODE_PROPS() DECLARE_NODE_FUNCTIONS() diff --git a/theseus/xbox/memutil.cpp b/theseus/xbox/memutil.cpp index c90bf8a..58a8bed 100644 --- a/theseus/xbox/memutil.cpp +++ b/theseus/xbox/memutil.cpp @@ -12,17 +12,17 @@ extern "C" void WINAPI D3D_FreeNoncontiguousMemory(void* pMemory); extern bool CleanupTextureCache(); extern bool CleanupMeshCache(); -int g_nNewFailedState; +int g_allocRetryStage; int __cdecl NewFailed(size_t nBytes) { - switch (g_nNewFailedState) + switch (g_allocRetryStage) { case 0: - if (CleanupTextureCache()) { g_nNewFailedState = 0; return 1; } + if (CleanupTextureCache()) { g_allocRetryStage = 0; return 1; } break; case 1: - if (CleanupMeshCache()) { g_nNewFailedState = 0; return 1; } + if (CleanupMeshCache()) { g_allocRetryStage = 0; return 1; } break; default: DbgPrint("xdash: out of memory (failed to allocate %d bytes)\n", nBytes); @@ -32,7 +32,7 @@ int __cdecl NewFailed(size_t nBytes) HalReturnToFirmware(HalRebootRoutine); } - g_nNewFailedState++; + g_allocRetryStage++; return 1; } @@ -86,5 +86,5 @@ void Memory_Init() { _set_new_handler(NewFailed); _set_new_mode(1); - g_nNewFailedState = 0; + g_allocRetryStage = 0; } From 87dc78a2319f5d72e0fce4f9d584f14dbf1646b2 Mon Sep 17 00:00:00 2001 From: Milenko <39630670+MrMilenko@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:58:49 -0500 Subject: [PATCH 8/8] Renamed the warp field and surface members The image fader's warp field and the 8 bit surface still used the old mName style members, so I gave them names in our own style. Compiled code is unchanged. --- theseus/render/tmap_system.cpp | 160 ++++++++++++++++----------------- theseus/render/tmap_system.h | 34 +++---- 2 files changed, 97 insertions(+), 97 deletions(-) diff --git a/theseus/render/tmap_system.cpp b/theseus/render/tmap_system.cpp index 57da791..786357f 100644 --- a/theseus/render/tmap_system.cpp +++ b/theseus/render/tmap_system.cpp @@ -44,12 +44,12 @@ CSurfx::CSurfx(int nWidth, int nHeight) m_nWidth = nWidth; m_nHeight = nHeight; m_pels = new BYTE [(nHeight + 1) * nWidth]; - mBytesPerRow = nWidth; - mLineWidth = 1; - mClipRect.left = 0; - mClipRect.top = 0; - mClipRect.right = nWidth; - mClipRect.bottom = nHeight; + m_rowBytes = nWidth; + m_rowStride = 1; + m_clip.left = 0; + m_clip.top = 0; + m_clip.right = nWidth; + m_clip.bottom = nHeight; sTempRef++; } @@ -128,7 +128,7 @@ void CSurfx::Fade(const char* inSrce, long inBytesPerSrceRow, char* inDest, long // CSurfx::Fade(inPix, inBytesPerRow, inX, inY, inGrad) // Reconstructed from 5960 retail XBE @ 0x0005f540. Warps the image in place. -// A pixel can pull from up to mNegYExtents rows above itself, so finished rows +// A pixel can pull from up to m_negYSpan rows above itself, so finished rows // wait in a ring of that many rows (the shared DAT_0017e764 buffer, grown on // demand) and only overwrite the image once nothing can read them anymore. // Steps: first ring-full of rows goes through the out-of-place pass; each later @@ -137,7 +137,7 @@ void CSurfx::Fade(const char* inSrce, long inBytesPerSrceRow, char* inDest, long // See docs/decomp/TmapSystem.md. void CSurfx::Fade(char* inPix, long inBytesPerRow, long inX, long inY, DeltaFieldData* inGrad) { - long ringRows = inGrad->mNegYExtents; + long ringRows = inGrad->m_negYSpan; if (sTempSize < ringRows * inBytesPerRow) { sTempSize = ringRows * inBytesPerRow; @@ -147,7 +147,7 @@ void CSurfx::Fade(char* inPix, long inBytesPerRow, long inX, long inY, DeltaFiel if (ringRows > inY) ringRows = inY; - const char* grad = inGrad->mField; + const char* grad = inGrad->m_cells; Fade(inPix, inBytesPerRow, sTemp, inBytesPerRow, inX, ringRows, grad); grad += 3 * inX * ringRows; @@ -356,7 +356,7 @@ void MakePalette(DWORD outPalette [256]) // ===== Line Drawing ========================================================= // Bresenham stepping with an optional round pen. Nothing in the dash ever -// raises mLineWidth above 1, but the wide pen is there and kept working. +// raises m_rowStride above 1, but the wide pen is there and kept working. // Pen insets per row for widths 2..11, from the byte tables at 0x0002a310..0x0002a364. static const char* PenShape(int width) @@ -401,8 +401,8 @@ void CSurfx::Line(int sx, int sy, int ex, int ey, unsigned char color) ex = FoldCoord(ex); ey = FoldCoord(ey); - long w = mLineWidth; - if (mLineWidth > 3) + long w = m_rowStride; + if (m_rowStride > 3) { // 64 bit squares: the folded coordinates can reach 2^30. long long dx2 = (long long)(ex - sx) * (ex - sx); @@ -412,14 +412,14 @@ void CSurfx::Line(int sx, int sy, int ex, int ey, unsigned char color) else if (dy2 > 0 && dy2 > dx2) w = (long)(128 + 55 * dx2 / dy2); if (dx2 > 0 || dy2 > 0) - w = (mLineWidth * w + 64) >> 7; + w = (m_rowStride * w + 64) >> 7; } long half = w >> 1; - long left = mClipRect.left + half; - long top = mClipRect.top + half; - long right = mClipRect.right - half; - long bottom = mClipRect.bottom - half; + long left = m_clip.left + half; + long top = m_clip.top + half; + long right = m_clip.right - half; + long bottom = m_clip.bottom - half; if (sx < left || sx >= right || sy < top || sy >= bottom) { @@ -453,21 +453,21 @@ void CSurfx::Line(int sx, int sy, int ex, int ey, unsigned char color) if (dy < 0) { dy = -dy; - rowStep = -mBytesPerRow; + rowStep = -m_rowBytes; yLeft = (sy - dy < top) ? sy - top : dy; } else { - rowStep = mBytesPerRow; + rowStep = m_rowBytes; yLeft = (sy + dy >= bottom) ? bottom - 1 - sy : dy; } - unsigned char* p = m_pels + sy * mBytesPerRow + sx; + unsigned char* p = m_pels + sy * m_rowBytes + sx; long err = 0; if (w > 1) { - long pen = mLineWidth; + long pen = m_rowStride; long penHalf = pen >> 1; const char* shape = pen < 12 ? PenShape(pen) : NULL; @@ -476,15 +476,15 @@ void CSurfx::Line(int sx, int sy, int ex, int ey, unsigned char color) long k = row - penHalf; long inset = shape ? shape[row] : penHalf - (long)sqrt((double)(penHalf * penHalf - k * k)); if (inset < pen - inset) - memset(p + k * mBytesPerRow + inset - penHalf, color, pen - 2 * inset); + memset(p + k * m_rowBytes + inset - penHalf, color, pen - 2 * inset); } if (dx > dy) { for (; xLeft >= 0 && yLeft >= 0; xLeft--) { - unsigned char* q = p - half * mBytesPerRow; - for (long i = 0; i < w; i++, q += mBytesPerRow) + unsigned char* q = p - half * m_rowBytes; + for (long i = 0; i < w; i++, q += m_rowBytes) *q = color; p += xStep; @@ -561,22 +561,22 @@ void CSurfx::Line(int sx, int sy, int ex, int ey, unsigned char color) DeltaField::DeltaField() { m_nStyle = 0; - mCurrentY = -1; - mWidth = 0; - mHeight = 0; + m_rowCursor = -1; + m_fieldW = 0; + m_fieldH = 0; } DeltaFieldData::DeltaFieldData() { - mNegYExtents = 0; - mField = NULL; + m_negYSpan = 0; + m_cells = NULL; } // DeltaFieldData::~DeltaFieldData() // Reconstructed from 5960 retail XBE @ 0x0005e110: free(field). DeltaFieldData::~DeltaFieldData() { - delete [] mField; + delete [] m_cells; } // DeltaField::GetField() @@ -586,13 +586,13 @@ DeltaFieldData::~DeltaFieldData() // is a Theseus guard; the binary never reaches here in that state. DeltaFieldData* DeltaField::GetField() { - if (mCurrentY < 0) + if (m_rowCursor < 0) return NULL; - while (mCurrentY != mHeight) + while (m_rowCursor != m_fieldH) CalcSome(); - return &mFieldData; + return &m_grid; } // DeltaField::Assign() @@ -601,10 +601,10 @@ DeltaFieldData* DeltaField::GetField() void DeltaField::Assign() { mAspect1to1 = true; - mPolar = true; - mHasRTerm = true; - mHasThetaTerm = true; - SetSize(mWidth, mHeight, true); + m_bPolarStyle = true; + m_bUsesR = true; + m_bUsesTheta = true; + SetSize(m_fieldW, m_fieldH, true); } // DeltaField::SetSize(w, h, force) @@ -617,28 +617,28 @@ void DeltaField::Assign() // The y scale is flipped so +y points up in the warp formulas. void DeltaField::SetSize(long inWidth, long inHeight, bool inForceRegen) { - if (inWidth == mWidth && inHeight == mHeight && !inForceRegen) + if (inWidth == m_fieldW && inHeight == m_fieldH && !inForceRegen) return; - mWidth = inWidth; - mHeight = inHeight; + m_fieldW = inWidth; + m_fieldH = inHeight; - delete [] mFieldData.mField; - mFieldData.mField = new char [mWidth * mHeight * 3 + 64]; + delete [] m_grid.m_cells; + m_grid.m_cells = new char [m_fieldW * m_fieldH * 3 + 64]; - mXScale = 2.0f / (float)mWidth; - mYScale = 2.0f / (float)mHeight; + m_stretchX = 2.0f / (float)m_fieldW; + m_stretchY = 2.0f / (float)m_fieldH; if (mAspect1to1) { - if (mYScale > mXScale) - mXScale = mYScale; + if (m_stretchY > m_stretchX) + m_stretchX = m_stretchY; else - mYScale = mXScale; + m_stretchY = m_stretchX; } - mYScale *= -1.0f; + m_stretchY *= -1.0f; - mCurrentY = 0; - mNegYExtents = 0; + m_rowCursor = 0; + m_negYSpan = 0; } static inline void WriteDelta(char* cell, unsigned long code) @@ -660,70 +660,70 @@ static inline void WriteDelta(char* cell, unsigned long code) // See docs/decomp/TmapSystem.md. int DeltaField::CalcSome() { - char* cell = mFieldData.mField + mCurrentY * mWidth * 3; + char* cell = m_grid.m_cells + m_rowCursor * m_fieldW * 3; - if (mCurrentY == 0 || mCurrentY == mHeight - 1) + if (m_rowCursor == 0 || m_rowCursor == m_fieldH - 1) { - for (long x = 0; x < mWidth; x++, cell += 3) + for (long x = 0; x < m_fieldW; x++, cell += 3) WriteDelta(cell, DELTA_ZERO); - mCurrentY++; + m_rowCursor++; } - if (mCurrentY > 0 && mCurrentY < mHeight - 1) + if (m_rowCursor > 0 && m_rowCursor < m_fieldH - 1) { - mY_Cord = (mHeight - mCurrentY * 2) * mYScale * 0.5f; - float toFixedX = 32.0f / mXScale; - float toFixedY = 32.0f / mYScale; + m_cy = (m_fieldH - m_rowCursor * 2) * m_stretchY * 0.5f; + float toFixedX = 32.0f / m_stretchX; + float toFixedY = 32.0f / m_stretchY; WriteDelta(cell, DELTA_ZERO); cell += 3; - for (long px = 1; px < mWidth - 1; px++, cell += 3) + for (long px = 1; px < m_fieldW - 1; px++, cell += 3) { - mX_Cord = (px * 2 - mWidth) * mXScale * 0.5f; - if (mHasRTerm) - mR_Cord = sqrtf(mX_Cord * mX_Cord + mY_Cord * mY_Cord); - if (mHasThetaTerm) - mT_Cord = atan2f(mY_Cord, mX_Cord); + m_cx = (px * 2 - m_fieldW) * m_stretchX * 0.5f; + if (m_bUsesR) + m_polarR = sqrtf(m_cx * m_cx + m_cy * m_cy); + if (m_bUsesTheta) + m_polarT = atan2f(m_cy, m_cx); float srcX, srcY; - GetXY(mR_Cord, mT_Cord, mX_Cord, mY_Cord, srcX, srcY, mPolar, px == 1 && mCurrentY == 1); - if (mPolar) + GetXY(m_polarR, m_polarT, m_cx, m_cy, srcX, srcY, m_bPolarStyle, px == 1 && m_rowCursor == 1); + if (m_bPolarStyle) { float radius = srcX; srcX = radius * cosf(srcY); srcY = radius * sinf(srcY); } - long dx = (long)(toFixedX * (srcX - mX_Cord)); - long dy = (long)(toFixedY * (mY_Cord - srcY)); + long dx = (long)(toFixedX * (srcX - m_cx)); + long dy = (long)(toFixedY * (m_cy - srcY)); long landX = px + (dx >> 5); - if (landX >= mWidth - 1) - dx = (mWidth - 1 - px) * 32; + if (landX >= m_fieldW - 1) + dx = (m_fieldW - 1 - px) * 32; else if (landX < 0) dx = -px * 32; - long landY = mCurrentY + (dy >> 5); - if (landY >= mHeight - 1) - dy = (mHeight - 1 - mCurrentY) * 32; + long landY = m_rowCursor + (dy >> 5); + if (landY >= m_fieldH - 1) + dy = (m_fieldH - 1 - m_rowCursor) * 32; else if (landY < 0) - dy = -mCurrentY * 32; + dy = -m_rowCursor * 32; - if (dy < mNegYExtents) - mNegYExtents = dy; + if (dy < m_negYSpan) + m_negYSpan = dy; WriteDelta(cell, ((dx + 0x7E0) << 12) | (dy + 0x7E0)); } WriteDelta(cell, DELTA_ZERO); - mCurrentY++; + m_rowCursor++; } - if (mCurrentY == mHeight) - mFieldData.mNegYExtents = 1 - (mNegYExtents >> 5); + if (m_rowCursor == m_fieldH) + m_grid.m_negYSpan = 1 - (m_negYSpan >> 5); - return mHeight - mCurrentY; + return m_fieldH - m_rowCursor; } // DeltaField::GetXY(r, theta, x, y, X, Y, bPolar, bInit) diff --git a/theseus/render/tmap_system.h b/theseus/render/tmap_system.h index 7b540a2..3eb3ddb 100755 --- a/theseus/render/tmap_system.h +++ b/theseus/render/tmap_system.h @@ -12,8 +12,8 @@ class DeltaFieldData DeltaFieldData(); ~DeltaFieldData(); - long mNegYExtents; - char* mField; + long m_negYSpan; + char* m_cells; }; // 8-bit palettized drawing surface for the TMAP effects. Layout follows the @@ -24,7 +24,7 @@ class CSurfx CSurfx(int w, int h); ~CSurfx(); - BYTE* Pixel(int x, int y) { return m_pels + (y * mBytesPerRow + x); } + BYTE* Pixel(int x, int y) { return m_pels + (y * m_rowBytes + x); } void Line(int x, int y, int x2, int y2, unsigned char c); @@ -41,9 +41,9 @@ class CSurfx int m_nWidth; int m_nHeight; BYTE* m_pels; - int mBytesPerRow; - int mLineWidth; - RECT mClipRect; + int m_rowBytes; + int m_rowStride; + RECT m_clip; private: // Owns its pixels, so no copies. @@ -66,10 +66,10 @@ class DeltaField // Computes the next row; returns how many are left. int CalcSome(); - // mCurrentY is -1 before sizing, counts up while building, ends at mHeight. - bool IsUninitialized() { return mCurrentY == -1; } - bool IsCalculating() { return mCurrentY >= 0 && mCurrentY != mHeight; } - bool IsCalculated() { return mCurrentY == mHeight; } + // m_rowCursor is -1 before sizing, counts up while building, ends at m_fieldH. + bool IsUninitialized() { return m_rowCursor == -1; } + bool IsCalculating() { return m_rowCursor >= 0 && m_rowCursor != m_fieldH; } + bool IsCalculated() { return m_rowCursor == m_fieldH; } // The field, finished first if it wasn't; NULL if it was never sized. DeltaFieldData* GetField(); @@ -80,14 +80,14 @@ class DeltaField int m_nStyle; protected: - long mCurrentY; - long mNegYExtents; - float mX_Cord, mY_Cord, mR_Cord, mT_Cord; - float mXScale, mYScale; - bool mPolar, mHasRTerm, mHasThetaTerm; - long mWidth, mHeight; + long m_rowCursor; + long m_negYSpan; + float m_cx, m_cy, m_polarR, m_polarT; + float m_stretchX, m_stretchY; + bool m_bPolarStyle, m_bUsesR, m_bUsesTheta; + long m_fieldW, m_fieldH; long mAspect1to1; - DeltaFieldData mFieldData; + DeltaFieldData m_grid; }; extern void MakePalette(DWORD pal[256]);