From cf5277a020a04949aca5961f30412c251f3a2ae5 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 20 Nov 2026 13:33:41 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x0043F6A0 100.0% Reimplemented StatusMenus::RenderStatusMenu_Population, from gynt's drafts: a92aa379d at 59.18% and 142ef0b38 at 64.1%, the second on sourcehold's reimpl/UI-StatusMenus; 73.2% in the status line of 67318e112 on his fork's reimpl/UI-StatusMenus-development; the newest commit on the file, e30b3f08b, is on his reimpl/UI-MenuItems-development. Through our drafts 4faa41844 (82.4%, on our fork kotijekriv's reimpl/UI-StatusMenus-development) and 6a2b83509 (93.8%, in the draft PR #313). Two differences were left, in two different loops, with one cause: the year labels' loop took the label's years as label * 5. The compiler turns that into a counter of its own either way (add ebp, 5 at 0x0043F999), but with the multiplication in the source - the sum of the first year and the label's years was an lea into a third register, where the original adds in place (add ecx, ebp at 0x0043F985), and - in the next loop, the bars' loop, the three scratch registers came out rotated (the screen width in ecx where the original has eax, at 0x0043F9F0). With the years as a second counter of the for loop (years += 5) both are gone. That the next loop followed suggests the compiler hands out scratch registers in turn, so one temporary more shifts the choices behind it. Measured: quick_diff 0.9984 with 318 instructions against 317; the one line is the jmp over the padding in front of the labels' loop (0x0043F926), which our listing shows as padding. reccmp 100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not run in game. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../RenderStatusMenu_Population.cpp | 136 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Population.cpp diff --git a/src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Population.cpp b/src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Population.cpp new file mode 100644 index 0000000000..4e2a346584 --- /dev/null +++ b/src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Population.cpp @@ -0,0 +1,136 @@ +#include "../StatusMenus.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" + +#include "OpenSHC/Globals/COL_BLACK.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuHandlerState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x0043F6A0 + void StatusMenus::RenderStatusMenu_Population() + { + // top first, then the player and x (with the player first, the match is lost) + int const top = DAT_MenuHandlerState::instance.y + 447; + int const player = DAT_GameSynchronyState::instance.currentPlayerSlotID; + int const x = DAT_MenuHandlerState::instance.x; + // the graph shows the last 300 months + int months = DAT_GameState::instance.mapAndTime.populationIndex; + if (300 < DAT_GameState::instance.mapAndTime.populationIndex) { + months = 300; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderLoadedGfx, + DAT_TextureRenderCoreObject::ptr)(1, x + 14, DAT_MenuHandlerState::instance.y + 489); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + // y then x for the title, in locals (in the call, or with x first, the match is lost) + int const titleY = DAT_MenuHandlerState::instance.y + 467; + int const titleX = DAT_MenuHandlerState::instance.x + 25; + // "Population" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_REPORT_BUTTONS, 3), + titleX, titleY, OpenSHC::Text::TTA_LEFT, 0, 17, FALSE, 0); + // the frame, three pixels thick; each line is its own call (as for loops, the match is lost) + int const bottom = top + 126; + int const right = x + 493; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x + 188, bottom, right, bottom, COL_BLACK::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x + 188, top + 127, right, top + 127, COL_BLACK::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x + 188, top + 128, right, top + 128, COL_BLACK::instance.shortValue); + int const graphTop = top + 50; + // the left side, from the inside out (a for loop loses the match) + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x + 190, graphTop, x + 190, bottom, COL_BLACK::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x + 189, graphTop, x + 189, bottom, COL_BLACK::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x + 188, graphTop, x + 188, bottom, COL_BLACK::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x + 491, graphTop, x + 491, bottom, COL_BLACK::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x + 492, graphTop, x + 492, bottom, COL_BLACK::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + right, graphTop, right, bottom, COL_BLACK::instance.shortValue); + // "Years" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_REPORT_BUTTONS, 13), + x + 340, top + 142, OpenSHC::Text::TTA_CENTER, 0, 19, FALSE, 0); + // the vertical scale: 50 people per 75 pixels, doubled until the highest population fits + int highest = 0; + for (int month = 0; month < months; ++month) { + if (DAT_GameState::instance.mapAndTime.playerPopulationStatistics[player][month] > highest) { + highest = DAT_GameState::instance.mapAndTime.playerPopulationStatistics[player][month]; + } + } + int scale; + if (highest <= 50) { + scale = 1; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + 50, x + 172, top + 45, OpenSHC::Text::TTA_LEFT, 0, 19, FALSE, 0); + } else { + if (highest <= 100) { + scale = 2; + } else if (highest <= 200) { + scale = 4; + } else if (highest <= 400) { + scale = 8; + } else if (highest <= 800) { + scale = 16; + } else { + scale = 32; + } + if (scale == 32) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + 1600, x + 156, top + 45, OpenSHC::Text::TTA_LEFT, 0, 19, FALSE, 0); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + scale * 50, x + 164, top + 45, OpenSHC::Text::TTA_LEFT, 0, 19, FALSE, 0); + } + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + 0, x + 180, top + 120, OpenSHC::Text::TTA_LEFT, 0, 19, FALSE, 0); + // a year label every five years; the years count by themselves (label * 5 in the sum loses the match) + for (int label = 0, years = 0; label <= 5; ++label, years += 5) { + // the first year shown is at least 0, through max() (an if loses the match) + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + max(0, (DAT_GameState::instance.mapAndTime.populationIndex - 300) / 12) + years, + label * 1475 / 25 + 190 + x, top + 130, OpenSHC::Text::TTA_LEFT, 0, 19, FALSE, 0); + } + // one bar per month + if (months <= 300) { + for (int month = 0; month < months; ++month) { + short const population = DAT_GameState::instance.mapAndTime.playerPopulationStatistics[player][month]; + if (population > 0) { + int const height = population * 75 / (scale * 50); + if (height >= 1) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::setRenderingRect, + DAT_TextureRenderCoreObject::ptr)( + 0, 0, DAT_WindowAndDirectDraw::instance.resolutionX, bottom); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::drawGfxOnFlaggedSurface, + DAT_TextureRenderCoreObject::ptr)(0, x + 191 + month, top - height + 126); + } + } + } + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::setRenderingRectToGameResolution, + DAT_TextureRenderCoreObject::ptr)(); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..603ed57554 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -13601,7 +13601,7 @@ SHC_3BB0A8C1_0x0043F2C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0043F2F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0043F6A0 | 0.0% | Pending +SHC_3BB0A8C1_0x0043F6A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0043F930 | 0.0% | Pending