Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
09c21cd
types(ViewportRenderState): counters, window and interval fields are …
gynt Nov 9, 2026
effad8e
Reimplement 15 Rendering::ViewportRenderState functions at 100%
gynt Nov 9, 2026
c661a3c
Reimplement Rendering::ViewportRenderState::resetupViewport
gynt Nov 10, 2026
961f8a0
Merge origin/main: upstream Ghidra header changes
gynt Nov 10, 2026
9d364b1
Merge origin/main: countof, upstream Ghidra header changes
gynt Nov 10, 2026
c6bccdd
Rendering::Enums::ViewportConstants: tile pixel sizes, screen point t…
gynt Nov 10, 2026
7093583
style(ViewportRenderState): enum names, countof bounds and compound a…
gynt Nov 10, 2026
360d8f1
types(MapConstants): map orientations MC_MAP_NORTH, EAST, SOUTH and WEST
gynt Nov 11, 2026
18b0b6e
style(ViewportRenderState): mapOrientation tests use MC_MAP_NORTH, EA…
gynt Nov 11, 2026
c429729
style(ViewportRenderState): debug overlay format strings from string-…
gynt Nov 11, 2026
978d0aa
style(ViewportRenderState): drop the decompiler's security cookie local
gynt Nov 11, 2026
d024d1b
Merge origin/main: generated MapConstants and ViewportConstants
gynt Nov 11, 2026
92ef3b7
types(ViewportRenderState): name review-flagged fields, enums for mag…
gynt Nov 14, 2026
85f7280
style(ViewportRenderState): use the review's new names and enums
gynt Nov 14, 2026
ed25ef7
Merge remote-tracking branch 'origin/main' into reimpl/ViewportRender…
gynt Nov 15, 2026
4b58b9e
style(ViewportRenderState): BuildingTargetMarker from Map::Buildings:…
gynt Nov 15, 2026
b51d31d
style(ViewportRenderState): short-form boolean tests
gynt Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "../ViewportRenderState.func.hpp"

#include "OpenSHC/Rendering/Enums/ViewportConstants.hpp"

namespace OpenSHC {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004E1FA0
ViewportRenderState* ViewportRenderState::Constructor_ViewportRenderState()
{
this->viewportState.viewportX = Enums::VC_TILE_PIXEL_WIDTH;
this->viewportState.viewportY = Enums::VC_TILE_ROW_PIXEL_HEIGHT;
this->viewportState.previousMouseTile = -1;

DWORD now = timeGetTime();
this->animationFrame32PreviousTime = now;
this->animationFrame16PreviousTime = now;
this->slowAnimationPreviousTime = now;
this->animationFrame36PreviousTime = now;

this->viewportState.isZoomedOutUnk = 0;
this->DAT_MapEditorDisplayLayer = 0;
this->animationFrame32 = 0;
this->animationFrame512 = 0;
this->animationFrame36 = 0;
this->slowAnimationTicked = FALSE;
this->animationFrame16 = 0;
this->viewportState.field_0x94 = 0;

this->animationFrame36Interval = 160;
this->slowAnimationInterval = 180;
this->animationFrame16Interval = 80;
this->animationFrame32Interval = 100;
this->availableFloaterIndex = 1;

for (int i = 0; i < countof(this->landscapeAnimationRandomTileArray); ++i) {
this->landscapeAnimationRandomTileArray[i] = 0;
}
return this;
}

}
}
35 changes: 35 additions & 0 deletions src/OpenSHC/Rendering/ViewportRenderState/assignRandomTiles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "../ViewportRenderState.func.hpp"

#include "OpenSHC/OS.func.hpp"
#include "OpenSHC/Map/LogicHelpers/Logic1.hpp"
#include "OpenSHC/Map/LogicHelpers/Logic2.hpp"
#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp"
#include "OpenSHC/Map/MapConstants.hpp"
#include "OpenSHC/Rendering/Enums/ViewportConstants.hpp"

#include "OpenSHC/Globals/DAT_TileMapState.hpp"

namespace OpenSHC {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004E5B80
void ViewportRenderState::assignRandomTiles()
{
for (int i = 0; i < countof(this->landscapeAnimationRandomTileArray); ++i) {
if (this->landscapeAnimationRandomTileArray[i] == 0) {
int randomTile = (MACRO_CALL(OpenSHC::OS_Func::_rand)() << 15 | MACRO_CALL(OpenSHC::OS_Func::_rand)())
% Map::MC_MAP_TILES_COUNT;
if ((DAT_TileMapState::instance.LogicLayer[randomTile] & Map::LogicHelpers::L_SEA)
&& !(DAT_TileMapState::instance.MiscDisplayLayer[randomTile] & Map::LogicHelpers::MD_SEA_EDGES)
&& !(DAT_TileMapState::instance.Logic2Layer[randomTile] & Map::LogicHelpers::L2_PLATEAU_HIGH)) {
this->landscapeAnimationRandomTileArray[i] = randomTile;
this->landscapeSeaWhiteCapsAnimationFrames[i] = 0;
}
} else if (Enums::VC_SEA_WHITE_CAP_FRAME_COUNT <= this->landscapeSeaWhiteCapsAnimationFrames[i]) {
this->landscapeAnimationRandomTileArray[i] = 0;
}
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "../ViewportRenderState.func.hpp"

#include "OpenSHC/Globals/DAT_TileMapState.hpp"

namespace OpenSHC {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004E6340
void ViewportRenderState::clearAllFloatingLayerElements()
{
for (int floaterIndex = 1; floaterIndex < this->availableFloaterIndex; floaterIndex++) {
DAT_TileMapState::instance.FloatingLayer[this->floatersArray[floaterIndex].tile] = 0;
this->floatersArray[floaterIndex].nextFloaterID = 0;
}
this->availableFloaterIndex = 1;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "../ViewportRenderState.func.hpp"

#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"
#include "OpenSHC/Globals/DAT_TileMapState.hpp"

namespace OpenSHC {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004E63A0
void ViewportRenderState::createFloatingLayerElement(
GmID gmID, int imageID, int imageX, int imageY, int tile, int variation)
{
int newFloaterIndex = this->availableFloaterIndex;
if (tile < 0) {
return;
}
if (countof(this->floatersArray) <= this->availableFloaterIndex) {
return;
}

if (DAT_TileMapState::instance.FloatingLayer[tile] == 0) {
this->floatersArray[newFloaterIndex].nextFloaterID = 0;
} else {
uint floaterID = DAT_TileMapState::instance.FloatingLayer[tile];
if (countof(this->floatersArray) - 1 < floaterID) {
return;
}
for (; floaterID != 0; floaterID = this->floatersArray[floaterID].nextFloaterID) {
if (this->floatersArray[floaterID].imageID == imageID && this->floatersArray[floaterID].gmID == gmID) {
return;
}
}
this->floatersArray[newFloaterIndex].nextFloaterID = DAT_TileMapState::instance.FloatingLayer[tile];
}

DAT_TileMapState::instance.FloatingLayer[tile] = newFloaterIndex;
this->floatersArray[newFloaterIndex].gmID = gmID;
this->floatersArray[newFloaterIndex].imageID = imageID;
this->floatersArray[newFloaterIndex].originX
= imageX - DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[gmID].originX;
this->floatersArray[newFloaterIndex].originY
= imageY - DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[gmID].originY;
this->floatersArray[newFloaterIndex].tile = tile;
this->floatersArray[newFloaterIndex].variation = variation;
this->availableFloaterIndex++;
}

}
}
49 changes: 49 additions & 0 deletions src/OpenSHC/Rendering/ViewportRenderState/focusOnTile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "../ViewportRenderState.func.hpp"

#include "OpenSHC/Map/MapConstants.hpp"
#include "OpenSHC/Rendering/Enums/ViewportConstants.hpp"

#include "OpenSHC/Globals/DAT_TileMapState.hpp"

namespace OpenSHC {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004E5E20
void ViewportRenderState::focusOnTile(int tile)
{
int screenPointIndex = Enums::VC_SCREEN_POINT_TABLE_START;
if (DAT_TileMapState::instance.mapOrientation != Map::MC_MAP_NORTH) {
if (DAT_TileMapState::instance.mapOrientation == Map::MC_MAP_WEST) {
screenPointIndex = Enums::VC_SCREEN_POINT_TABLE_START + Enums::VC_SCREEN_POINT_TABLE_SIZE;
} else if (DAT_TileMapState::instance.mapOrientation == Map::MC_MAP_SOUTH) {
screenPointIndex = Enums::VC_SCREEN_POINT_TABLE_START + 2 * Enums::VC_SCREEN_POINT_TABLE_SIZE;
} else if (DAT_TileMapState::instance.mapOrientation == Map::MC_MAP_EAST) {
screenPointIndex = Enums::VC_SCREEN_POINT_TABLE_START + 3 * Enums::VC_SCREEN_POINT_TABLE_SIZE;
}
}

int rowLength = Enums::VC_SCREEN_POINT_LONG_ROW;
int tileX = 0;
int tileY;
bool found = false;
for (tileY = 0; tileY < Map::MC_MAP_XY_LIMIT; tileY++) {
rowLength = (rowLength != Enums::VC_SCREEN_POINT_LONG_ROW) + Enums::VC_SCREEN_POINT_SHORT_ROW;
for (tileX = 0; tileX < rowLength; ++tileX) {
if (this->screenPointToTileNumber[screenPointIndex] == tile) {
found = true;
break;
}
screenPointIndex++;
}
if (found) {
break;
}
}

this->viewportState.viewportX = (tileX - this->viewportState.mbr_0xac) * Enums::VC_TILE_PIXEL_WIDTH;
this->viewportState.viewportY = (tileY - this->viewportState.mbr_0xb0) * Enums::VC_TILE_ROW_PIXEL_HEIGHT;
MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::setViewportBasedOnMapSize, this)();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "../ViewportRenderState.func.hpp"

#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp"
#include "OpenSHC/Rendering/Enums/ViewportConstants.hpp"

#include "OpenSHC/Globals/DAT_BuildingsState.hpp"
#include "OpenSHC/Globals/DAT_CurrentlyRenderedSpriteID.hpp"
#include "OpenSHC/Globals/DAT_RenderedUnitOwner.hpp"
#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"
#include "OpenSHC/Globals/DAT_TileMapState.hpp"

namespace OpenSHC {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004E3870
void ViewportRenderState::renderBuildingAnimation(
int buildingID, int screenX, int screenY, int tile, BOOLEnum clipToBuilding)
{
if (DAT_BuildingsState::instance.buildings[buildingID].renderAnimation == 0) {
return;
}
if (DAT_BuildingsState::instance.buildings[buildingID].animationFrame == 0) {
return;
}
if (DAT_TileMapState::instance.disableElevationRendering) {
return;
}
if (DAT_BuildingsState::instance.buildings[buildingID].drawBridgeState1 != 0) {
return;
}

if (clipToBuilding) {
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::temporarySaveMapSurfaceHeightRangeUnk,
DAT_TextureRenderCoreObject::ptr)
();
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::setMapSurfaceHeightRange,
DAT_TextureRenderCoreObject::ptr)
(screenY - 39 < 0 ? 0 : screenY - 39, Enums::VC_MAP_SURFACE_HEIGHT);
}

DAT_RenderedUnitOwner::instance = DAT_BuildingsState::instance.buildings[buildingID].playerColorUnk;
DAT_CurrentlyRenderedSpriteID::instance = DAT_BuildingsState::instance.buildings[buildingID].spriteID2;
if (DAT_BuildingsState::instance.buildings[buildingID].renderBlendStrength != 0) {
MACRO_CALL_MEMBER(
OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, DAT_TextureRenderCoreObject::ptr)
((OpenSHC::IO::Graphics::GmID)DAT_CurrentlyRenderedSpriteID::instance,
DAT_BuildingsState::instance.buildings[buildingID].animationFrame,
DAT_BuildingsState::instance.buildings[buildingID].spriteOffetX + screenX,
DAT_BuildingsState::instance.buildings[buildingID].spriteOffetY + screenY,
DAT_BuildingsState::instance.buildings[buildingID].renderBlendStrength);
} else {
MACRO_CALL_MEMBER(
OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, DAT_TextureRenderCoreObject::ptr)
((OpenSHC::DE::SHCDE::eGM)DAT_CurrentlyRenderedSpriteID::instance,
DAT_BuildingsState::instance.buildings[buildingID].animationFrame,
DAT_BuildingsState::instance.buildings[buildingID].spriteOffetX + screenX,
DAT_BuildingsState::instance.buildings[buildingID].spriteOffetY + screenY);
}
if (clipToBuilding) {
MACRO_CALL_MEMBER(
OpenSHC::UI::Rendering::TextureRenderCore_Func::restoreMapSurfaceHeightRangeFromTemporaryUnk,
DAT_TextureRenderCoreObject::ptr)
();
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "../ViewportRenderState.func.hpp"

#include "OpenSHC/OS.func.hpp"
#include "OpenSHC/Text/TextManager.func.hpp"
#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp"
#include "OpenSHC/Text/TextAlignment.hpp"
#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp"
#include "OpenSHC/string-literals.hpp"

#include "OpenSHC/Globals/DAT_TextManagerObject.hpp"
#include "OpenSHC/Globals/DAT_TileMapState.hpp"
#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp"

namespace OpenSHC {
namespace Rendering {

using OpenSHC::Text::TextAlignment;
using OpenSHC::WindowsHelper::Enums::BOOLEnum;

// FUNCTION: STRONGHOLDCRUSADER 0x004E64D0
void ViewportRenderState::renderDebugDataMousePointing(int x, int y, int width, int height)
{
char text[200];

int textX = x + 2;

MACRO_CALL(OpenSHC::OS_Func::_sprintf)
(text, s_Mouse_Atom_Ref___d_005ab8a4, this->viewportState.mouseAtomRefFloorTile);
Comment thread
TheRedDaemon marked this conversation as resolved.
Resolved
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)
(text, textX, y, OpenSHC::Text::TTA_LEFT, Colors::COL_FFFFFF, 18, FALSE, 0);

MACRO_CALL(OpenSHC::OS_Func::_sprintf)
(text, s_Mouse__x_d__y_d__off_d_005ab88c, DAT_ViewportRenderState::instance.viewportState.mouseX,
DAT_ViewportRenderState::instance.viewportState.mouseY,
DAT_ViewportRenderState::instance.viewportState.mouseFlatTile);
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)
(text, textX, y + 16, OpenSHC::Text::TTA_LEFT, Colors::COL_FFFFFF, 18, FALSE, 0);

MACRO_CALL(OpenSHC::OS_Func::_sprintf)
(text, s_Tile_centre__x_d_y_d_005ab874, DAT_ViewportRenderState::instance.viewportState.tileCenterX,
DAT_ViewportRenderState::instance.viewportState.tileCenterY);
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)
(text, textX, y + 32, OpenSHC::Text::TTA_LEFT, Colors::COL_FFFFFF, 18, FALSE, 0);

MACRO_CALL(OpenSHC::OS_Func::_sprintf)
(text, s_Chimp___d_Struct___d_Fly___d_005ab854, this->viewportState.mouseRayUnitID,
this->viewportState.mouseRayBuildingID, this->viewportState.mouseRayEntityID);
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)
(text, textX, y + 64, OpenSHC::Text::TTA_LEFT, Colors::COL_FFFFFF, 18, FALSE, 0);

MACRO_CALL(OpenSHC::OS_Func::_sprintf)
(text, s_Logic_Layer___x__x_005ab840,
DAT_TileMapState::instance.LogicLayer[this->viewportState.mouseAtomRefFloorTile],
DAT_TileMapState::instance.LogicLayer[this->viewportState.mouseFlatTile]);
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)
(text, textX, y + 80, OpenSHC::Text::TTA_LEFT, Colors::COL_FFFFFF, 18, FALSE, 0);

MACRO_CALL(OpenSHC::OS_Func::_sprintf)
(text, s_Logic2_Layer___x__x_005ab828,
DAT_TileMapState::instance.Logic2Layer[this->viewportState.mouseAtomRefFloorTile],
DAT_TileMapState::instance.Logic2Layer[this->viewportState.mouseFlatTile]);
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)
(text, textX + 20, y + 80, OpenSHC::Text::TTA_LEFT, Colors::COL_FFFFFF, 18, TRUE, 0);

MACRO_CALL(OpenSHC::OS_Func::_sprintf)
(text, s_Damage_Layer___d__d_005ab810,
DAT_TileMapState::instance.DamageLayer[this->viewportState.mouseAtomRefFloorTile],
DAT_TileMapState::instance.DamageLayer[this->viewportState.mouseFlatTile]);
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)
(text, textX, y + 96, OpenSHC::Text::TTA_LEFT, Colors::COL_FFFFFF, 18, FALSE, 0);
}

}
}
Loading
Loading