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(gameengine): end a menu transition past its last frame

Olcay Seygan5c3f62fb7483
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8e766d12e..23cc4d2c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1425,6 +1425,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Opening Skirmish crashed on a game that loads its menus from a mod or from the original files, as the Shockwave mod does. Those menus have no game speed box, and the game set one up anyway. The same was true of the tree sway box and the detail presets on the Options screen. A missing box is now left out, and a skirmish without one plays at normal speed.
- The opening movies froze on their first frame with that picture on. A movie writes a new image every frame into a texture the copy had already taken.
- Opening Single Player could take the game down a quarter of a second in, as the buttons flashed in. The menu's animation list names a Custom Mission button that only the 1.04 patch's main menu has, and on an install whose menu lacks it, every step of the flash skipped the missing button except one, which tried to draw it. That step skips it now too.
+- On those same installs Single Player then froze the menu instead. The buttons lit up under the pointer and none of them did anything until Alt+F4. The menu waits for its animation to end before it takes a click, and the missing button's flash never got to say it had ended. The animation now ends on its last frame whatever its buttons say, and the dropdown takes clicks a second after it opens, as it does on a full install.
- A skirmish against the computer could crash when a fresh unit joined one of its teams. The newcomer copies what a teammate is doing, and when that teammate was following a road the map had drawn for it, the newcomer got the order without the road and the game fell over looking for its first stop. It now gets the road as well, and a unit handed that order with no road at all gives it up instead.
- Two blocks of 2003 assembly destroyed registers and took down the main menu.
- A model file with no skeleton in it is refused as it loads. It used to load, and the game went down the first time anything asked it for a bone.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowTransitions.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowTransitions.h
index 3112a8e75..367ec463d 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowTransitions.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowTransitions.h
@@ -645,6 +645,7 @@ public:
Bool isFireOnce( void ) { return m_fireOnce; }
Bool m_fireOnce;
private:
+ Int getTotalFrames( void ); ///< the frame the last window ends on
typedef std::list<TransitionWindow *> TransitionWindowList;
TransitionWindowList m_transitionWindowList;
Int m_directionMultiplier;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowTransitions.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowTransitions.cpp
index c49270aa3..0361ce597 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowTransitions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowTransitions.cpp
@@ -236,6 +236,7 @@ Int TransitionWindow::getTotalFrames( void )
TransitionGroup::TransitionGroup( void )
{
m_currentFrame = 0;
+ m_directionMultiplier = 1;
m_fireOnce = FALSE;
m_lastStepMs = 0;
m_stepAccumMs = 0.0f;
@@ -293,6 +294,14 @@ void TransitionGroup::update( void )
Bool TransitionGroup::isFinished( void )
{
+ // Past its last frame (or, reversed, before its first) no window takes another update, so
+ // nothing left in the group can still change. A window that has not called itself finished by
+ // then never will: a button the layout lacks (ButtonCustomMission, only in the 1.04 patch's
+ // MainMenu.wnd) stops a flash short of its end. Waiting on it held the group open for good, and
+ // the main menu refuses every click while a group runs.
+ if (m_directionMultiplier > 0 ? m_currentFrame > getTotalFrames() : m_currentFrame < 0)
+ return TRUE;
+
TransitionWindowList::iterator it = m_transitionWindowList.begin();
while (it != m_transitionWindowList.end())
{
@@ -305,11 +314,9 @@ Bool TransitionGroup::isFinished( void )
return TRUE;
}
-void TransitionGroup::reverse( void )
+Int TransitionGroup::getTotalFrames( void )
{
- Int totalFrames =0;
- m_directionMultiplier = -1;
-
+ Int totalFrames = 0;
TransitionWindowList::iterator it = m_transitionWindowList.begin();
while (it != m_transitionWindowList.end())
{
@@ -319,7 +326,15 @@ void TransitionGroup::reverse( void )
totalFrames = winFrames;
it++;
}
- it = m_transitionWindowList.begin();
+ return totalFrames;
+}
+
+void TransitionGroup::reverse( void )
+{
+ Int totalFrames = getTotalFrames();
+ m_directionMultiplier = -1;
+
+ TransitionWindowList::iterator it = m_transitionWindowList.begin();
while (it != m_transitionWindowList.end())
{
TransitionWindow *tWin = *it;
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index fcf433bb7..035166559 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -16146,6 +16146,7 @@ public:
};
Int drawState( void ) const { return m_drawState; }
+ void start( void ) { m_isFinished = FALSE; m_isForward = TRUE; } // init() without the gradient lookup
};
TEST(button_flash_draws_nothing_for_a_button_the_layout_lacks)
@@ -16158,6 +16159,29 @@ TEST(button_flash_draws_nothing_for_a_button_the_layout_lacks)
}
}
+/* The same flash never reaches its own end, so the group holding it has to call itself finished
+ * once it is past the last frame. It waited on the flash for good instead, and the main menu
+ * refuses every click while a group runs: issue 86, Single Player and then nothing. The group
+ * steps on the wall clock, 30 a second, so this takes about 0.6 seconds of real time. */
+#include "Lib/Clock.h"
+
+TEST(transition_group_finishes_past_a_flash_for_a_button_the_layout_lacks)
+{
+ ButtonFlashWithoutWindow *flash = NEW ButtonFlashWithoutWindow;
+ flash->start();
+ TransitionWindow *window = NEW TransitionWindow;
+ window->m_transition = flash;
+ TransitionGroup group;
+ group.addWindow( window ); // the group deletes it, and it deletes the flash
+
+ UnsignedInt start = Clock_Milliseconds();
+ while( !group.isFinished() && Clock_Milliseconds() - start < 3000 )
+ group.update();
+
+ CHECK( group.isFinished() );
+ CHECK( !flash->isFinished() );
+}
+
// Camera scroll timing must advance during stationary frames as well as moving frames.
#include "GameClient/CameraScrollClock.h"