Skip to content

Commit ce654d2

Browse files
committed
refactor(view): Simplify some View code
1 parent 6418de5 commit ce654d2

File tree

3 files changed

+25
-35
lines changed
  • GeneralsMD/Code

3 files changed

+25
-35
lines changed

GeneralsMD/Code/GameEngine/Include/GameClient/View.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ class View : public Snapshot
186186
virtual Real getZoom() { return m_zoom; }
187187
virtual void setZoom(Real z) { }
188188
virtual Real getHeightAboveGround() { return m_heightAboveGround; }
189-
virtual void setHeightAboveGround(Real z) { m_heightAboveGround = z; }
189+
virtual void setHeightAboveGround(Real z);
190190
virtual void zoom( Real height ); ///< Zoom in/out, closer to the ground, limit to min, or farther away from the ground, limit to max
191-
virtual void setZoomToDefault( void ) { } ///< Set zoom to default value
191+
virtual void setZoomToDefault( void ) { m_zoom = 1.0f; } ///< Set zoom to default value
192192
virtual Real getMaxZoom( void ) { return m_maxZoom; } ///< return max zoom value
193193
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
194194

@@ -269,8 +269,8 @@ class View : public Snapshot
269269

270270
Real m_maxZoom; ///< Largest zoom value (minimum actual zoom)
271271
Real m_minZoom; ///< Smallest zoom value (maximum actual zoom)
272-
Real m_maxHeightAboveGround;
273-
Real m_minHeightAboveGround;
272+
Real m_maxHeightAboveGround; ///< Highest camera above ground value
273+
Real m_minHeightAboveGround; ///< Lowest camera above ground value
274274
Real m_zoom; ///< Current zoom value
275275
Real m_heightAboveGround; ///< User's desired height above ground
276276
Bool m_zoomLimited; ///< Camera restricted in zoom height
@@ -280,7 +280,7 @@ class View : public Snapshot
280280
Real m_terrainHeightUnderCamera; ///< Cached value for debugging
281281

282282
ObjectID m_cameraLock; ///< if nonzero, id of object that the camera should follow
283-
Drawable *m_cameraLockDrawable; ///< if nonzero, drawble of object that camera should follow.
283+
Drawable *m_cameraLockDrawable; ///< if nonzero, drawable of object that camera should follow.
284284
CameraLockType m_lockType; ///< are we following or just tethering?
285285
Real m_lockDist; ///< how far can we be when tethered?
286286

@@ -290,7 +290,7 @@ class View : public Snapshot
290290
Bool m_okToAdjustHeight; ///< Should we attempt to adjust camera height?
291291
Bool m_snapImmediate; ///< Should we immediately snap to the object we're following?
292292

293-
Coord2D m_guardBandBias; ///< Exttra beefy margins so huge thins can stay "on-screen"
293+
Coord2D m_guardBandBias; ///< Extra beefy margins so huge thins can stay "on-screen"
294294

295295
};
296296

GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,8 @@ void View::setAngle( Real angle )
166166
*/
167167
void View::setPitch( Real angle )
168168
{
169-
m_pitchAngle = angle;
170-
171-
Real limit = PI/5.0f;
172-
173-
if (m_pitchAngle < -limit)
174-
m_pitchAngle = -limit;
175-
else if (m_pitchAngle > limit)
176-
m_pitchAngle = limit;
169+
constexpr Real limit = PI/5.0f;
170+
m_pitchAngle = clamp(-limit, angle, limit);
177171
}
178172

179173
/**
@@ -185,6 +179,19 @@ void View::setAngleAndPitchToDefault( void )
185179
m_pitchAngle = m_defaultPitchAngle;
186180
}
187181

182+
void View::setHeightAboveGround(Real z)
183+
{
184+
// if our zoom is limited, we will stay within a predefined distance from the terrain
185+
if( m_zoomLimited )
186+
{
187+
m_heightAboveGround = clamp(m_minHeightAboveGround, z, m_maxHeightAboveGround);
188+
}
189+
else
190+
{
191+
m_heightAboveGround = z;
192+
}
193+
}
194+
188195
/**
189196
* write the view's current location in to the view location object
190197
*/

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,8 @@ void W3DView::buildCameraTransform( Matrix3D *transform )
445445
// WST 10.22.2002. Update the Listener positions used by audio system
446446
//--------------------------------------------------------------------
447447
Vector3 position = transform->Get_Translation();
448-
m_pos.x = position.X;
449-
m_pos.y = position.Y;
450-
m_pos.z = position.Z;
451-
452-
453-
//DEBUG_LOG(("mpos x%f, y%f, z%f", m_pos.x, m_pos.y, m_pos.z ));
454-
448+
Coord3D coord(position.X, position.Y, position.Z);
449+
View::setPosition(&coord);
455450
break;
456451
}
457452
}
@@ -1919,7 +1914,7 @@ void W3DView::setAngleAndPitchToDefault( void )
19191914
// call our base class, we are adding functionality
19201915
View::setAngleAndPitchToDefault();
19211916

1922-
this->m_FXPitch = 1.0;
1917+
m_FXPitch = 1.0;
19231918

19241919
// set the camera
19251920
setCameraTransform();
@@ -1941,19 +1936,7 @@ void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight)
19411936
//-------------------------------------------------------------------------------------------------
19421937
void W3DView::setHeightAboveGround(Real z)
19431938
{
1944-
m_heightAboveGround = z;
1945-
1946-
// if our zoom is limited, we will stay within a predefined distance from the terrain
1947-
if( m_zoomLimited )
1948-
{
1949-
1950-
if (m_heightAboveGround < m_minHeightAboveGround)
1951-
m_heightAboveGround = m_minHeightAboveGround;
1952-
1953-
if (m_heightAboveGround > m_maxHeightAboveGround)
1954-
m_heightAboveGround = m_maxHeightAboveGround;
1955-
1956-
}
1939+
View::setHeightAboveGround(z);
19571940

19581941
m_doingMoveCameraOnWaypointPath = false;
19591942
m_CameraArrivedAtWaypointOnPathFlag = false;

0 commit comments

Comments
 (0)