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): let the camera follow the ground again, and stop it latching

Olcay Seygan00a6a19e9ae7
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
index 7417928ae..9b522fd83 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
@@ -126,6 +126,7 @@ public:
virtual void setOrigin( Int x, Int y) { m_originX=x; m_originY=y;} ///< Sets location of top-left view corner on display
virtual void getOrigin( Int *x, Int *y) { *x=m_originX; *y=m_originY;} ///< Return location of top-left view corner on display
+ virtual void lockViewForOneFrame(); ///< Refuse camera transforms for the rest of this client frame.
virtual void forceRedraw() = 0;
virtual void lookAt( const Coord3D *o ); ///< Center the view on the given coordinate
@@ -179,14 +180,13 @@ public:
virtual const Coord3D& get3DCameraPosition() const = 0; ///< Returns the actual camera position
virtual Real getZoom() { return m_zoom; }
- virtual void setZoom(Real z) { }
+ virtual void setZoom(Real z) { m_zoom = z; }
virtual Real getHeightAboveGround() { return m_heightAboveGround; }
virtual void setHeightAboveGround(Real z) { m_heightAboveGround = z; }
virtual void zoomIn( Real steps = 1.0f ); ///< Zoom in, closer to the ground, limit to min
virtual void zoomOut( Real steps = 1.0f ); ///< Zoom out, farther away from the ground, limit to max
virtual void setZoomToDefault( void ) { } ///< Set zoom to default value
virtual void setZoomToMax( void ) { } ///< Set zoom as far out as the player may zoom by hand
- virtual Real getMaxZoom( void ) { return m_maxZoom; } ///< return max zoom value
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
// for debugging
@@ -256,6 +256,8 @@ protected:
UnsignedInt m_id; ///< Rhe ID of this view
static UnsignedInt m_idNext; ///< Used for allocating view ID's for all views
+ UnsignedInt m_viewLockedUntilFrame; ///< Client frame the camera is free to move again
+
Coord3D m_pos; ///< Position of this view, in world coordinates
Int m_width, m_height; ///< Dimensions of the view
Int m_originX, m_originY; ///< Location of top/left view corner
@@ -263,8 +265,6 @@ protected:
Real m_angle; ///< Angle at which view has been rotated about the Z axis
Real m_pitchAngle; ///< Rotation of view direction around horizontal (X) axis
- Real m_maxZoom; ///< Largest zoom value (minimum actual zoom)
- Real m_minZoom; ///< Smallest zoom value (maximum actual zoom)
Real m_maxHeightAboveGround;
Real m_minHeightAboveGround;
Real m_zoom; ///< Current zoom value
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index b8e841004..238df2d49 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -845,7 +845,9 @@ void InGameUI::setSuperweaponDisplayEnabledByScript(Bool enable)
// ------------------------------------------------------------------------------------------------
Bool InGameUI::getSuperweaponDisplayEnabledByScript(void) const
{
- return m_superweaponHiddenByScript;
+ // The getter asks whether the display is enabled, so it is the negation of the hidden flag.
+ // Nothing calls it yet, which is why the inversion went unnoticed.
+ return !m_superweaponHiddenByScript;
}
// ------------------------------------------------------------------------------------------------
@@ -2438,7 +2440,17 @@ void InGameUI::reset( void )
m_shiftAttackQueueUnits.clear();
m_shiftAttackQueueRunning = FALSE;
m_clientQuiet = false;
-
+
+ // TheSuperHackers @bugfix A key or button still held when the game ended left its camera
+ // interaction latched on, and the shell then scrolled or spun on its own.
+ setScrolling(false);
+ setSelecting(false);
+ setCameraRotateLeft(false);
+ setCameraRotateRight(false);
+ setCameraZoomIn(false);
+ setCameraZoomOut(false);
+ setCameraTrackingDrawable(false);
+
m_windowLayouts.clear();
m_tooltipsDisabledUntil = 0;
@@ -8176,8 +8188,10 @@ void InGameUI::updateAndDrawWorldAnimations( void )
UnsignedInt width = wad->m_anim->getCurrentFrameWidth();
UnsignedInt height = wad->m_anim->getCurrentFrameHeight();
- // scale the width and height given the camera zoom level
- Real zoomScale = TheTacticalView->getMaxZoom() / TheTacticalView->getZoom();
+ // scale the width and height given the camera zoom level. The 1.3 was the old maximum
+ // zoom value, which is gone; this number is the size the artwork was drawn against.
+ const Real WORLD_ANIM_ZOOM_REFERENCE = 1.3f;
+ Real zoomScale = WORLD_ANIM_ZOOM_REFERENCE / TheTacticalView->getZoom();
width *= zoomScale;
height *= zoomScale;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp
index 99e9ec4bf..8bb298b40 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp
@@ -32,6 +32,7 @@
#include "Common/Xfer.h"
#include "GameClient/View.h"
#include "GameClient/Drawable.h"
+#include "GameClient/GameClient.h"
UnsignedInt View::m_idNext = 1;
@@ -79,9 +80,8 @@ View::View( void )
m_heightAboveGround = 0.0f;
m_lockDist = 0.0f;
m_maxHeightAboveGround = 0.0f;
- m_maxZoom = 0.0f;
m_minHeightAboveGround = 0.0f;
- m_minZoom = 0.0f;
+ m_viewLockedUntilFrame = 0;
m_next = NULL;
m_okToAdjustHeight = TRUE;
m_originX = 0;
@@ -129,9 +129,7 @@ void View::init( void )
m_cameraLockDrawable = NULL;
m_zoomLimited = TRUE;
- m_maxZoom = 1.3f;
- m_minZoom = 0.2f;
- m_zoom = m_maxZoom;
+ m_zoom = 1.0f;
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight;
m_minHeightAboveGround = TheGlobalData->m_minCameraHeight;
m_okToAdjustHeight = FALSE;
@@ -144,6 +142,13 @@ void View::reset( void )
{
// Only fixing the reported bug. Who knows what side effects resetting the rest could have.
m_zoomLimited = TRUE;
+
+ m_viewLockedUntilFrame = 0;
+}
+
+void View::lockViewForOneFrame()
+{
+ m_viewLockedUntilFrame = TheGameClient->getFrame() + 1;
}
/**
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index 1177dc6b6..c67d30d07 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -2174,6 +2174,10 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
loc.init(pos.x, pos.y, pos.z, angle, pitch, zoom);
TheTacticalView->setLocation( &loc );
+ // TheSuperHackers @fix Hold the restored location for this frame, or the user's
+ // own scroll and zoom input lands on top of it and the camera never arrives.
+ TheTacticalView->lockViewForOneFrame();
+
if (!TheLookAtTranslator->hasMouseMovedRecently())
{
TheMouse->setCursor( (Mouse::MouseCursor)(msg->getArgument( 4 )->integer) );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index ddc12e0c8..ba185dfd9 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -611,6 +611,9 @@ void W3DView::getPickRay(const ICoord2D *screen, Vector3 *rayStart, Vector3 *ray
//-------------------------------------------------------------------------------------------------
void W3DView::setCameraTransform( void )
{
+ if (m_viewLockedUntilFrame > TheGameClient->getFrame())
+ return;
+
m_cameraHasMovedSinceRequest = true;
Matrix3D cameraTransform( 1 );
@@ -1472,7 +1475,9 @@ void W3DView::update(void)
{
Real desiredHeight = (m_terrainHeightUnderCamera + m_heightAboveGround);
Real desiredZoom = desiredHeight / m_cameraOffset.z;
- if (didScriptedMovement || (TheGameLogic->isInReplayGame() && TheGlobalData->m_useCameraInReplay))
+ // TheSuperHackers @bugfix Watching a replay pinned the height to whatever the camera happened
+ // to be at, so the camera stopped following the terrain under it for the whole playback.
+ if (didScriptedMovement)
{
// if we are in a scripted camera movement, take its height above ground as our desired height.
m_heightAboveGround = m_currentHeightAboveGround;
@@ -2219,15 +2224,12 @@ void W3DView::setHeightAboveGround(Real z)
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
+// TheSuperHackers @bugfix setZoom is no longer clamped by a min and max zoom; the camera height is
+// clamped in setHeightAboveGround instead. A zoom clamp fought camera playback in a replay, where a
+// rise in the terrain under the camera could not raise the camera with it.
void W3DView::setZoom(Real z)
{
- m_zoom = z;
-
- if (m_zoom < m_minZoom)
- m_zoom = m_minZoom;
-
- if (m_zoom > m_maxZoom)
- m_zoom = m_maxZoom;
+ View::setZoom(z);
m_doingMoveCameraOnWaypointPath = false;
m_CameraArrivedAtWaypointOnPathFlag = false;
diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp
index 8d188f548..8c7e1b5de 100644
--- a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp
+++ b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp
@@ -242,7 +242,6 @@ public:
virtual void zoomIn( void ) { } ///< Zoom in, closer to the ground, limit to min
virtual void zoomOut( void ) { } ///< Zoom out, farther away from the ground, limit to max
virtual void setZoomToDefault( void ) { } ///< Set zoom to default value
- virtual Real getMaxZoom( void ) { return 0.0f; }
virtual void setOkToAdjustHeight( Bool val ) { } ///< Set this to adjust camera height
virtual Real getTerrainHeightUnderCamera() { return 0.0f; }