Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameclient): print countdowns in real seconds, not logic frames over 30

Olcay Seygan4f882487a558
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 74e6d2ac2..2a27cf25b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -297,6 +297,10 @@ Around it, the whole production loop got tightened:
interrupting a busy one when every worker you own is busy. Same for the build list you get with
nothing selected — it stays usable when the whole crew is out working.
- **Workers go back to collecting supplies** after they finish, instead of standing there.
+- **The times on the buttons are real seconds, not "seconds at normal speed".** Speed the game up
+ and a 20 second barracks reads 10, because that is how long you are going to be waiting. Every
+ countdown the interface prints now answers the speed the same way: build and research times,
+ general's power cooldowns, the supply drop timer, the superweapon clock and the build tooltip.
- **The clock and frame-rate readout is smaller, bolder, and drawn on top of everything.** It used
to be painted before the interface, so any panel or dialog covered the one number you look at
when something is going wrong.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index e582d0e62..54d81d0aa 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -1148,5 +1148,13 @@ private:
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
extern ControlBar *TheControlBar;
+//-------------------------------------------------------------------------------------------------
+/** Logic frames as the whole seconds they will really take at the current logic rate, rounded up
+ * and never down to zero. Defined in ControlBarCommand.cpp; every countdown and build time the
+ * UI prints goes through it, so they all answer the game speed the same way. */
+//-------------------------------------------------------------------------------------------------
+extern Int ControlBar_secondsFromFrames( Real frames );
+extern Int ControlBar_secondsFromFramesAt( Real frames, Int logicFps ); ///< ...at a rate you name
+
#endif // end __CONTROLBAR_H_
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
index 466cb1aab..d3613540b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
@@ -39,6 +39,7 @@
#include "Common/SpecialPower.h"
#include "Common/Upgrade.h"
#include "Common/BuildAssistant.h"
+#include "Common/GameEngine.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Module/BattlePlanUpdate.h"
#include "GameLogic/Module/DozerAIUpdate.h"
@@ -81,18 +82,32 @@ Bool commandWindowsInitialized = FALSE;
static Color BuildClockColor = GameMakeColor(0,0,0,120);
//-------------------------------------------------------------------------------------------------
-/** Logic frames to whole seconds, rounded up and never down to zero: a button that still has work
- * left on it must not read "0s". */
+/** Logic frames to the whole seconds they will really take, rounded up and never down to zero: a
+ * button that still has work left on it must not read "0s".
+ *
+ * Real seconds, not "logic frames over thirty". The logic rate is a knob in this fork (the game
+ * speed keys move it between 5 and 200), and a build time is a promise about how long you will
+ * be waiting - so at double speed a 20s barracks has to read 10s. `LOGICFRAMES_PER_SECOND` is
+ * only the fallback for the frames before the engine has a rate at all. */
//-------------------------------------------------------------------------------------------------
-Int ControlBar_secondsFromFrames( Real frames )
+Int ControlBar_secondsFromFramesAt( Real frames, Int logicFps )
{
if( frames <= 0.0f )
return 0;
- Int seconds = (Int)( frames / LOGICFRAMES_PER_SECOND + 0.999f );
+ if( logicFps <= 0 )
+ logicFps = LOGICFRAMES_PER_SECOND;
+
+ Int seconds = (Int)( frames / logicFps + 0.999f );
return seconds < 1 ? 1 : seconds;
}
+Int ControlBar_secondsFromFrames( Real frames )
+{
+ return ControlBar_secondsFromFramesAt( frames,
+ TheGameEngine ? TheGameEngine->getFramesPerSecondLimit() : 0 );
+}
+
//-------------------------------------------------------------------------------------------------
/** Is any selected building of the local player's researching or holding 'upgrade' in its queue?
* Hands back the queue entry when the upgrade is the one being worked on right now (that is the
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarOCLTimer.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarOCLTimer.cpp
index f947ea456..793cc6899 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarOCLTimer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarOCLTimer.cpp
@@ -145,7 +145,7 @@ void ControlBar::updateContextOCLTimer( void )
OCLUpdate *update = (OCLUpdate*)obj->findUpdateModule( key_OCLUpdate );
UnsignedInt frames = update->getRemainingFrames();
- UnsignedInt seconds = frames / LOGICFRAMES_PER_SECOND;
+ UnsignedInt seconds = ControlBar_secondsFromFrames( (Real)frames );
Real percent = update->getCountdownPercent();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
index 4b10d0313..cbc723792 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
@@ -422,7 +422,7 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,
if( TheGlobalData->m_detailedBuildTooltips )
{
UnicodeString stats;
- Int buildSecs = thingTemplate->calcTimeToBuild( player ) / LOGICFRAMES_PER_SECOND;
+ Int buildSecs = ControlBar_secondsFromFrames( (Real)thingTemplate->calcTimeToBuild( player ) );
stats.format( L"\nTime %ds", buildSecs );
// no bonuses: these are the template's own numbers, before veterancy or upgrades
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 1340be6c6..b07019f78 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -3962,7 +3962,7 @@ void InGameUI::postDraw( void )
if( module->getReadyFrame() < TheGameLogic->getFrame() )
readySecs = 0;
else
- readySecs = (module->getReadyFrame() - TheGameLogic->getFrame()) / LOGICFRAMES_PER_SECOND;
+ readySecs = ControlBar_secondsFromFrames( (Real)(module->getReadyFrame() - TheGameLogic->getFrame()) );
// Yes, integer math. We can't have float imprecision display 4:01 on a disabled superweapon.
// Only if we actually changed the ready status do we want to play an Eva event.
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index a41c27c89..32db3e0aa 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -1746,6 +1746,7 @@ TEST(pathfind_zone_flatten_collapses_a_deep_chain_in_one_pass)
including ControlBar.h for them: they are free functions in the ControlBar sources, and the
header carries the class, not these. */
extern Int ControlBar_secondsFromFrames( Real frames );
+extern Int ControlBar_secondsFromFramesAt( Real frames, Int logicFps );
extern Int ControlBar_experiencePercent( Int currentExp, Int levelExp, Int nextLevelExp );
TEST(controlbar_seconds_round_up_and_never_reach_zero_early)
@@ -1767,6 +1768,28 @@ TEST(controlbar_seconds_round_up_and_never_reach_zero_early)
CHECK_EQ( ControlBar_secondsFromFrames( 1.0f ), 1 );
}
+TEST(controlbar_seconds_are_real_seconds_at_the_current_game_speed)
+{
+ /* The number on a build button is a promise about how long you will be waiting, and the logic
+ rate is a knob in this fork (the game speed keys move it between 5 and 200). The same 600
+ frames of work is 20 seconds at the nominal rate and 10 at double speed. */
+ const Real frames = 600.0f;
+ CHECK_EQ( ControlBar_secondsFromFramesAt( frames, LOGICFRAMES_PER_SECOND ), 20 );
+ CHECK_EQ( ControlBar_secondsFromFramesAt( frames, LOGICFRAMES_PER_SECOND * 2 ), 10 );
+ CHECK_EQ( ControlBar_secondsFromFramesAt( frames, LOGICFRAMES_PER_SECOND / 2 ), 40 );
+
+ /* A rate of zero is the engine before it has one, not a division to attempt: fall back to the
+ nominal rate. This is also the path the whole suite runs on - the test binary has no
+ GameEngine, so ControlBar_secondsFromFrames() above resolves the rate to 0. */
+ CHECK_EQ( ControlBar_secondsFromFramesAt( frames, 0 ), 20 );
+ CHECK_EQ( ControlBar_secondsFromFramesAt( frames, -5 ), 20 );
+
+ /* and the round-up and the never-zero floor hold at any rate */
+ CHECK_EQ( ControlBar_secondsFromFramesAt( 61.0f, 60 ), 2 );
+ CHECK_EQ( ControlBar_secondsFromFramesAt( 1.0f, 200 ), 1 );
+ CHECK_EQ( ControlBar_secondsFromFramesAt( 0.0f, 200 ), 0 );
+}
+
TEST(controlbar_experience_percent_fills_the_rank_and_clamps)
{
/* a fresh unit at the bottom of its rank */