Skip to content

Commit cf96141

Browse files
authored
refactor(view): Simplify code to set location for Replay Camera (TheSuperHackers#2353)
1 parent 747d249 commit cf96141

3 files changed

Lines changed: 24 additions & 27 deletions

File tree

Core/GameEngine/Include/GameClient/View.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ class View : public Snapshot
178178
virtual Real getPitch() { return m_pitch; } ///< Return current camera pitch
179179
virtual void setAngleToDefault(); ///< Set the view angle back to default
180180
virtual void setPitchToDefault(); ///< Set the view pitch back to default
181-
virtual void getPosition(Coord3D *pos) { *pos=m_pos;} ///< Returns position camera is looking at (z will be zero)
181+
void setPosition( const Coord3D *pos ) { m_pos = *pos; }
182+
void getPosition(Coord3D *pos) { *pos = m_pos;} ///< Returns position camera is looking at (z will be zero)
182183

183184
virtual const Coord3D& get3DCameraPosition() const = 0; ///< Returns the actual camera position
184185

@@ -205,14 +206,10 @@ class View : public Snapshot
205206
virtual void getLocation ( ViewLocation *location ); ///< write the view's current location in to the view location object
206207
virtual void setLocation ( const ViewLocation *location ); ///< set the view's current location from to the view location object
207208

208-
209209
virtual void drawView() = 0; ///< Render the world visible in this view.
210210
virtual void updateView() = 0; ///<called once per frame to determine the final camera and object transforms
211211
virtual void stepView() = 0; ///< Update view for every fixed time step
212212

213-
214-
215-
216213
virtual ObjectID getCameraLock() const { return m_cameraLock; }
217214
virtual void setCameraLock(ObjectID id) { m_cameraLock = id; m_lockDist = 0.0f; m_lockType = LOCK_FOLLOW; }
218215
virtual void snapToCameraLock() { m_snapImmediate = TRUE; }
@@ -241,14 +238,12 @@ class View : public Snapshot
241238
virtual void xfer( Xfer *xfer );
242239
virtual void loadPostProcess() { }
243240

244-
void setPosition( const Coord3D *pos ) { m_pos = *pos; }
245241
const Coord3D *getPosition() const { return &m_pos; }
246242

247243
virtual View *prependViewToList( View *list ); ///< Prepend this view to the given list, return the new list
248244
virtual View *getNextView() { return m_next; } ///< Return next view in the set
249245

250-
251-
// **********************************************************************************************
246+
protected:
252247

253248
View *m_next; ///< List links used by the Display class
254249

@@ -310,7 +305,9 @@ class ViewLocation
310305
{
311306
m_valid = FALSE;
312307
m_pos.zero();
313-
m_angle = m_pitch = m_zoom = 0.0;
308+
m_angle = 0.0f;
309+
m_pitch = 0.0f;
310+
m_zoom = 0.0f;
314311
}
315312

316313
const Coord3D& getPosition() const { return m_pos; }

Generals/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,15 +1861,15 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
18611861
{
18621862
if (TheTacticalView->isCameraMovementFinished())
18631863
{
1864-
ViewLocation loc;
1865-
Coord3D pos;
1866-
Real pitch, angle, zoom;
1867-
pos = msg->getArgument( 0 )->location;
1868-
angle = msg->getArgument( 1 )->real;
1869-
pitch = msg->getArgument( 2 )->real;
1870-
zoom = msg->getArgument( 3 )->real;
1871-
loc.init(pos.x, pos.y, pos.z, angle, pitch, zoom);
1872-
TheTacticalView->setLocation( &loc );
1864+
const Coord3D pos = msg->getArgument( 0 )->location;
1865+
const Real angle = msg->getArgument( 1 )->real;
1866+
const Real pitch = msg->getArgument( 2 )->real;
1867+
const Real zoom = msg->getArgument( 3 )->real;
1868+
1869+
TheTacticalView->setPosition(&pos);
1870+
TheTacticalView->setAngle(angle);
1871+
TheTacticalView->setPitch(pitch);
1872+
TheTacticalView->setZoom(zoom);
18731873

18741874
// TheSuperHackers @fix xezon 18/09/2025 Lock the new location to avoid user input from changing the camera in this frame.
18751875
TheTacticalView->lockViewUntilFrame( getFrame() + 1 );

GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,15 +1889,15 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
18891889
{
18901890
if (TheTacticalView->isCameraMovementFinished())
18911891
{
1892-
ViewLocation loc;
1893-
Coord3D pos;
1894-
Real pitch, angle, zoom;
1895-
pos = msg->getArgument( 0 )->location;
1896-
angle = msg->getArgument( 1 )->real;
1897-
pitch = msg->getArgument( 2 )->real;
1898-
zoom = msg->getArgument( 3 )->real;
1899-
loc.init(pos.x, pos.y, pos.z, angle, pitch, zoom);
1900-
TheTacticalView->setLocation( &loc );
1892+
const Coord3D pos = msg->getArgument( 0 )->location;
1893+
const Real angle = msg->getArgument( 1 )->real;
1894+
const Real pitch = msg->getArgument( 2 )->real;
1895+
const Real zoom = msg->getArgument( 3 )->real;
1896+
1897+
TheTacticalView->setPosition(&pos);
1898+
TheTacticalView->setAngle(angle);
1899+
TheTacticalView->setPitch(pitch);
1900+
TheTacticalView->setZoom(zoom);
19011901

19021902
// TheSuperHackers @fix xezon 18/09/2025 Lock the new location to avoid user input from changing the camera in this frame.
19031903
TheTacticalView->lockViewUntilFrame( getFrame() + 1 );

0 commit comments

Comments
 (0)