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(w3ddevice): one place that hands the camera back from a script

Olcay Seygan0a2f929e4765
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
index 9b0d26295..48853db0e 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
@@ -283,6 +283,8 @@ private:
Region2D m_cameraConstraint; ///< m_pos should be constrained to be within this area
Bool m_cameraConstraintValid; ///< if f, recalc cam constraints
+ Bool isDoingScriptedCamera( void ) const; ///< True while any scripted camera movement owns the view
+ void stopDoingScriptedCamera( void ); ///< Hand the view back to the user, whatever the script was doing
void setCameraTransform( void ); ///< set the transform matrix of m_3DCamera, based on m_pos & m_angle
void buildCameraTransform( Matrix3D *transform ) ; ///< calculate (but do not set) the transform matrix of m_3DCamera, based on m_pos & m_angle
void calcCameraConstraints() ; ///< recalc m_cameraConstraint
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index ba185dfd9..85b74da16 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -608,6 +608,27 @@ void W3DView::getPickRay(const ICoord2D *screen, Vector3 *rayStart, Vector3 *ray
//-------------------------------------------------------------------------------------------------
/** set the transform matrix of m_3DCamera, based on m_pos & m_angle */
+//-------------------------------------------------------------------------------------------------
+Bool W3DView::isDoingScriptedCamera( void ) const
+{
+ return m_doingRotateCamera || m_doingMoveCameraOnWaypointPath || m_doingPitchCamera
+ || m_doingZoomCamera || m_doingScriptedCameraLock;
+}
+
+//-------------------------------------------------------------------------------------------------
+// Every user camera action takes the view away from whatever the script was doing with it. This
+// used to be five assignments copied into each setter, and the copies had drifted: lookAt left a
+// scripted pitch and zoom running, and setPitch left the waypoint-arrival flag set.
+void W3DView::stopDoingScriptedCamera( void )
+{
+ m_doingMoveCameraOnWaypointPath = false;
+ m_CameraArrivedAtWaypointOnPathFlag = false;
+ m_doingRotateCamera = false;
+ m_doingPitchCamera = false;
+ m_doingZoomCamera = false;
+ m_doingScriptedCameraLock = false;
+}
+
//-------------------------------------------------------------------------------------------------
void W3DView::setCameraTransform( void )
{
@@ -1411,7 +1432,7 @@ void W3DView::update(void)
recalcCamera = true;
}
} else {
- if (m_doingRotateCamera || m_doingMoveCameraOnWaypointPath || m_doingPitchCamera || m_doingZoomCamera || m_doingScriptedCameraLock) {
+ if (isDoingScriptedCamera()) {
didScriptedMovement = true; // don't mess up the scripted movement
}
}
@@ -2135,13 +2156,7 @@ void W3DView::setAngle( Real angle )
View::setAngle( angle );
- m_doingMoveCameraOnWaypointPath = false;
- m_CameraArrivedAtWaypointOnPathFlag = false;
-
- m_doingRotateCamera = false;
- m_doingPitchCamera = false;
- m_doingZoomCamera = false;
- m_doingScriptedCameraLock = false;
+ stopDoingScriptedCamera();
// set the camera
setCameraTransform();
}
@@ -2159,11 +2174,7 @@ void W3DView::setPitch( Real angle )
m_cameraConstraintValid = false;
- m_doingMoveCameraOnWaypointPath = false;
- m_doingRotateCamera = false;
- m_doingPitchCamera = false;
- m_doingZoomCamera = false;
- m_doingScriptedCameraLock = false;
+ stopDoingScriptedCamera();
// set the camera
setCameraTransform();
}
@@ -2212,12 +2223,7 @@ void W3DView::setHeightAboveGround(Real z)
} // end if
- m_doingMoveCameraOnWaypointPath = false;
- m_CameraArrivedAtWaypointOnPathFlag = false;
- m_doingRotateCamera = false;
- m_doingPitchCamera = false;
- m_doingZoomCamera = false;
- m_doingScriptedCameraLock = false;
+ stopDoingScriptedCamera();
m_cameraConstraintValid = false; // recalc it.
setCameraTransform();
}
@@ -2231,12 +2237,7 @@ void W3DView::setZoom(Real z)
{
View::setZoom(z);
- m_doingMoveCameraOnWaypointPath = false;
- m_CameraArrivedAtWaypointOnPathFlag = false;
- m_doingRotateCamera = false;
- m_doingPitchCamera = false;
- m_doingZoomCamera = false;
- m_doingScriptedCameraLock = false;
+ stopDoingScriptedCamera();
m_cameraConstraintValid = false; // recalc it.
setCameraTransform();
}
@@ -2257,12 +2258,7 @@ void W3DView::setZoomToHeight( Real heightAboveGround )
m_zoom = desiredZoom;
m_heightAboveGround = heightAboveGround;
- m_doingMoveCameraOnWaypointPath = false;
- m_CameraArrivedAtWaypointOnPathFlag = false;
- m_doingRotateCamera = false;
- m_doingPitchCamera = false;
- m_doingZoomCamera = false;
- m_doingScriptedCameraLock = false;
+ stopDoingScriptedCamera();
m_cameraConstraintValid = false; // recalc it.
setCameraTransform();
}
@@ -2664,11 +2660,8 @@ void W3DView::lookAt( const Coord3D *o )
} // end if
}
pos.z = 0;
- setPosition(&pos);
- m_doingRotateCamera = false;
- m_doingMoveCameraOnWaypointPath = false;
- m_CameraArrivedAtWaypointOnPathFlag = false;
- m_doingScriptedCameraLock = false;
+ setPosition(&pos);
+ stopDoingScriptedCamera();
setCameraTransform();