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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameclient): observer camera with a director, player cameras and fog
Olcay Seygan320c71e918c4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 41ac53485..8a77c3661 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -484,7 +484,8 @@ found and fixed — EA's own, not port damage.**- Every row and every countdown stands in real metal, cut from the same tray the general's powers sit in down in the corner - the side your command bar is showing. Watching a match there is no bar of your own, so the superweapon countdowns used to fall back to a flat black box for the whole match; now they wear the metal of the player you are watching, and follow it when you switch seats.- Watching, the command bar is down to the radar. The list of players it held is the row of seats across the top of the screen now: click a seat and you are looking at that player, his money and his side's steel, the way his button in the list did, and the seat is lit gold. Click it again for everybody. A seat click drops whatever you had selected, so the promotions on screen are that player's and not the owner of the tank you last clicked, and the seat stays yours when you click empty ground. The portrait panel in the right corner comes up when you select something and goes when you click empty ground, so an empty match leaves the bottom of the screen to the battle.- Watching, the bars over the buildings are everyone's too - what each factory is turning out, and how long the superweapons have left. An observer used to see none of it.-- Watching, you see the fog the player you are watching sees. The game only ever remembered one player's fog, so switching seats handed you the first player's idea of the map.+- Watching, the camera can drive itself. The drop-down at the top of the board on the right says who has it. The Director goes wherever the most things were hit in the last five seconds, stays with that fight at least six seconds, and cuts away only for one clearly bigger, so a 4v4 is watched like a broadcast rather than hunted for. Pick a player instead and you see his screen: a human player's camera comes over the network five times a second, smoothed in between, and a computer player, who has no camera, gets the Director narrowed to his own fights. Scroll, turn the view or click the radar and the camera is yours again. In a replay with the recorded camera switched on in the options, a seat click still follows that player the way it always did.+- Watching, tick Fog of war under the camera and you see what the player you follow sees and nothing more: black where he has never been, grey where he has been, none of the enemy he cannot see, and an enemy base as he last saw it. One gap: a stealthed enemy he has not detected still shows, because stealth is still judged from your seat. It stays on when you take the camera back, until you switch it off or hand the camera to the Director. An observer used to have no fog at all: the whole map, all match, with no way to see the game the way one of its players was seeing it.- An ally, and anyone watching, now sees a stealthed unit's muzzle flash, its promotion and the cash it earns - if they can see the unit at all. Those three asked 'is it mine' instead of 'can I see it', so allies and observers got nothing.- Watching, the match opens on the middle of the map. An observer has no start position, so the game looked for the camera waypoint of "player zero", did not find it, and fell back to the corner of the map: every match watched from the stands began pointed at empty ground in the south west.- Watching, you can click a stealth building. The rule that stops you selecting an enemy you cannot see never asked who was asking, so an observer, and a player already knocked out, could see a stealthed structure on the map and not pick it up to read it. A spectator commands nothing and sees everything already, so there is nothing there to give away.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex 4d41e15ba..e0a797556 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -1178,6 +1178,26 @@ GUI:HudArmies"Armies"END+// the spectator's camera drop-down, "Camera: Director"+GUI:HudCamera+"Camera"+END++// the camera goes to the biggest fight on the map by itself+GUI:HudCameraDirector+"Director"+END++// the camera is the spectator's own again+GUI:HudCameraFree+"Free"+END++// draw the followed player's fog of war, so the spectator sees only what he sees+GUI:HudFog+"Fog of war"+END+// under a superweapon's name in the spectator's feed, the moment it can fireGUI:HudSuperweaponReady"ready to fire"diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.strindex 5fff03b1e..46212fccd 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -15701,6 +15701,22 @@ GUI:HudArmies"Ordular"END+GUI:HudCamera+"Kamera"+END++GUI:HudCameraDirector+"Yönetmen"+END++GUI:HudCameraFree+"Serbest"+END++GUI:HudFog+"Savaş sisi"+END+GUI:HudSuperweaponReady"ateşe hazır"ENDdiff --git a/GeneralsMD/Code/Data/Window/Html/Spectator.html b/GeneralsMD/Code/Data/Window/Html/Spectator.htmlindex 0b1752908..9016d0a46 100644--- a/GeneralsMD/Code/Data/Window/Html/Spectator.html+++ b/GeneralsMD/Code/Data/Window/Html/Spectator.html@@ -8,7 +8,8 @@#top every player across the top of the screen, grouped by team, the match clock between two teams#hud-top the left panel: the strips drop-down, the superweapon countdowns and the promotions bought#feed a superweapon coming ready, on the left for a few seconds, the way Dota's kill feed runs- #board the right panel: every player ranked by a picked stat, the lead graph, the armies+ #board the right panel: the camera and the fog, every player ranked by a picked stat, the lead+ graph, the armiesLaid out by litehtml and drawn by the game (GameClient/HtmlOverlay.h). A CSS pixel is a pixel ofan 800x600 screen and font-size is the game font's point size there; the page is scaled with the@@ -49,6 +50,14 @@data-each="skills", then his promotions, "skill" with {{image}}data-each="toasts", the superweapons that came ready in the last eight seconds, oldest first:{{portrait}} {{color}} {{name}} of the owner, {{image}} the weapon's cameo and {{what}} its name+ data-each="cameras", every player the camera can follow, grouped by team: {{image}} {{color}}+ {{name}}, {{click}} "camera:N" and {{on}} "on" while the camera is following him. A+ data-click of camera:director or camera:free hands the camera to the director or back to the+ watcher, camera:N follows player N's own screen (GameClient/ObserverCamera.h), and each folds+ up flip:camera. {{camera}} is what drives it now, the director, free or the player's name;+ {{cameradirector}} and {{camerafree}} are "on" while it is that one+ {{fog}} "on" while the fog is drawn for the followed player, flipped with data-click="fog";+ {{fogname}} {{fogcolor}} are that player's, empty while nobody is followedThe stats: networth, cash, income, army, kills, rank, power. A data-click of option:Key flipsthat option and saves it; flip:name flips the name for the rest of the match; pick:group:choice@@ -256,6 +265,20 @@</div><div id="board" class="well">+ <div class="head plate">+ <div class="combo well" data-click="flip:camera">{{text:GUI:HudCamera}}: {{camera}}<span class="tab">▼</span></div>+ </div>++ <div class="{{flip:camera}}">+ <div class="choices well">+ <div class="choice {{cameradirector}}" data-click="camera:director"><span class="box"></span>{{text:GUI:HudCameraDirector}}</div>+ <div class="choice {{on}}" data-each="cameras" data-click="{{click}}"><span class="box"></span><span style="color: {{color}}">{{name}}</span></div>+ <div class="choice {{camerafree}}" data-click="camera:free"><span class="box"></span>{{text:GUI:HudCameraFree}}</div>+ </div>+ </div>++ <div class="row {{fog}}" data-click="fog"><span class="box"></span>{{text:GUI:HudFog}} <span style="color: {{fogcolor}}">{{fogname}}</span></div>+<div class="head plate"><div class="combo well" data-click="flip:stat">{{stat}}<span class="tab">▼</span></div></div>diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 1e00f47ef..0950cb703 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -1067,6 +1067,10 @@ public:/** The patch of an ally's own colour lying under their cursor. On the ground so that it reads* as light falling on the map rather than as a disc floating over it. */virtual void drawAllyCursorLights( void ) { }++ /// what a data-click on the spectator's page does, by its text: a click on the page, or the+ /// control socket's "spectator" verb, which a script uses instead of finding the pixel+ void runSpectatorAction( const std::string &action );protected:void clearWorldAnimations( void ); ///< delete all world animationsdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.hindex 09cebed30..a982c8d2d 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h@@ -42,6 +42,8 @@ public:/// where the middle-button scroll was started from, or NULL if no such scroll is runningconst ICoord2D* getScrollAnchor( void );Bool hasMouseMovedRecently( void );+ /// scrolling, turning or tilting the camera by hand, with the mouse or the keys, right now+ Bool isMovingCamera( void ) const { return m_isScrolling || m_isRotating || m_isPitching; }void setCurrentPos( const ICoord2D& pos );void resetModes(); //Used when disabling input, so when we reenable it we aren't stuck in a mode.@@ -76,7 +78,10 @@ private:Bool m_scrollMovesCursor; // the scroll in progress swapped the cursor for the scroll arrows and puts it back when it stopsvoid setScrolling( Int );void stopScrolling( void );+ Bool networkCameraDue( const ViewLocation &view );UnsignedInt m_lastMouseMoveFrame;+ UnsignedInt m_cameraSentFrame; ///< the logic frame this player's camera last went to the other machines+ ViewLocation m_cameraSent; ///< and where it was then};extern LookAtTranslator *TheLookAtTranslator;diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.hnew file mode 100644index 000000000..fa26368d8--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h@@ -0,0 +1,129 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++// ObserverCamera.h ///////////////////////////////////////////////////////////////////////////////+// Who drives a watcher's camera, and whose fog his screen is drawn in.+//+// Free is the camera in the watcher's own hands. Director goes wherever the most things have+// been hit in the last few seconds and stays there a while before it looks for a hotter fight.+// Player shows what the followed player's own screen shows: a player's camera comes over the+// network a few times a second (MSG_SET_REPLAY_CAMERA), and an AI, which has no camera, gets the+// director narrowed to the fights his own units are in. Scrolling, turning the camera or clicking+// the radar hands it back to the watcher, who keeps following that player's fog.+//+// The followed player is picked from the camera's list, not the seats: clicking a unit makes its+// owner the watched player, and the camera jumping to an enemy's screen on a click would be no use.+// Fog on draws the followed player's fog, what he has seen and what he has not, and hides what he+// cannot see; following nobody it changes nothing. Nothing here is logic: the camera and the fog+// are this machine's picture only.+///////////////////////////////////////////////////////////////////////////////////////////////////++#pragma once++#ifndef _OBSERVER_CAMERA_H_+#define _OBSERVER_CAMERA_H_++#include "Common/GameCommon.h"+#include "GameClient/View.h"++#include <vector>++enum ObserverCameraMode+{+ OBSERVER_CAMERA_FREE,+ OBSERVER_CAMERA_DIRECTOR,+ OBSERVER_CAMERA_PLAYER+};++/// one thing hit lately, where it stands and how much it counts for+struct DirectorHeat+{+ Coord2D position;+ Real weight;+};++/// the place the hits crowd most: each hit's weight summed over those within DIRECTOR_GATHER_RADIUS+/// of it, and the best one's neighbours averaged by weight. FALSE when nothing was hit+Bool ObserverCamera_hottestPlace( const std::vector< DirectorHeat > &hits, Coord2D *place, Real *heat );+/// the weight of the hits within DIRECTOR_GATHER_RADIUS of a place, and their weighted middle+Real ObserverCamera_heatAround( const std::vector< DirectorHeat > &hits, const Coord2D &around, Coord2D *middle );+/// whether a director holding a place with heatHere for framesHere should cut to one with heatThere+Bool ObserverCamera_shouldMove( Real heatHere, Real heatThere, UnsignedInt framesHere );+/// a step of the camera towards where it is going, easing with timeConstant, or the jump there when+/// the two are further apart than a pan should cross+ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocation &to, Real elapsedSeconds, Real timeConstant );++class Player;++class ObserverCamera+{+public:+ ObserverCamera();++ void reset( void );+ /// once a frame on a watcher's machine: move the camera and swap the fog when it has to+ void update( UnsignedInt nowMilliseconds );++ /// a player's camera as it came over the network or out of a replay+ void notePlayerView( Int playerIndex, const ViewLocation &view );++ ObserverCameraMode getMode( void ) const { return m_mode; }+ /// the director, or the camera back in the watcher's hands; either stops following anybody+ void setMode( ObserverCameraMode mode );+ /// show this player's screen, and his fog while fog is on+ void followPlayer( Int playerIndex );+ /// the player being followed, still while the watcher has the camera in his own hands, or+ /// NO_PLAYER+ Int getFollowedPlayerIndex( void ) const { return m_followed; }+ Bool isFogOn( void ) const { return m_fog; }+ void setFog( Bool fog ) { m_fog = fog; }++ /// the player whose fog the screen is drawn in: the local player, or whoever a watcher with fog+ /// on is following+ Int getShroudPlayerIndex( void ) const;++ enum { NO_PLAYER = -1 };++private:+ void updateShroudViewer( void );+ void holdHeight( Bool hold );+ Bool takenByHand( const ViewLocation ¤t ) const;+ Bool chooseTarget( const ViewLocation ¤t, ViewLocation *target );+ Bool directorPlace( const Player *narrowTo, Coord2D *place );++ ObserverCameraMode m_mode;+ Int m_followed;+ Bool m_fog;+ Int m_shroudViewer;+ Bool m_driving; ///< the camera was put where it is by this, last frame+ Bool m_holdingHeight; ///< the view's own height easing is off while a player's zoom is shown+ Coord3D m_drivenTo;+ UnsignedInt m_lastUpdate;++ ViewLocation m_playerViews[ MAX_PLAYER_COUNT ];++ Bool m_placeValid;+ Coord2D m_place; ///< where the director is looking+ UnsignedInt m_placeSince; ///< the logic frame it went there+ UnsignedInt m_placeScanned; ///< the logic frame the hits were last counted+ const Player *m_placeFor; ///< whose fights the place was picked from, NULL for everybody's+};++extern ObserverCamera TheObserverCamera;++#endifdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h b/GeneralsMD/Code/GameEngine/Include/GameClient/View.hindex 5fcfe0c3e..af3a65644 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h@@ -126,7 +126,6 @@ public:virtual void setOrigin( Int x, Int y) { m_originX=x; m_originY=y;} ///< Sets location of top-left view corner on displayvirtual 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@@ -260,8 +259,6 @@ protected:UnsignedInt m_id; ///< Rhe ID of this viewstatic 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 coordinatesInt m_width, m_height; ///< Dimensions of the viewInt m_originX, m_originY; ///< Location of top/left view cornerdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameSounds.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameSounds.cppindex 5ee9d289c..920b042d7 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameSounds.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameSounds.cpp@@ -54,6 +54,7 @@#include "Common/PlayerList.h"#include "GameLogic/PartitionManager.h"+#include "GameClient/ObserverCamera.h"///////////////////////////////////////////////////////////////////////////////////////////////////#ifdef _INTERNAL@@ -232,7 +233,7 @@ Bool SoundManager::canPlayNow( AudioEventRTS *event )return false;}- Int localPlayerNdx = ThePlayerList->getLocalPlayer()->getPlayerIndex();+ Int localPlayerNdx = TheObserverCamera.getShroudPlayerIndex();if( (event->getAudioEventInfo()->m_type & ST_SHROUDED) &&ThePartitionManager->getShroudStatusForPlayer(localPlayerNdx, pos) != CELLSHROUD_CLEAR ){diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cppindex c09169ca5..998b6f7ac 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp@@ -35,6 +35,7 @@#include "Common/Player.h"#include "Common/PlayerList.h"#include "GameClient/Display.h"+#include "GameClient/InGameUI.h"#include "GameClient/KeyDefs.h"#include "GameClient/MetaEvent.h"#include "GameLogic/GameLogic.h"@@ -733,6 +734,16 @@ static void handleCommand( const AsciiString &command )return;}+ /* spectator <action>+ What a data-click on the spectator's page does, without finding its pixel: camera:director,+ camera:3, fog, flip:camera and the rest of the actions Window/Html/Spectator.html names. */+ if (strncmp( command.str(), "spectator ", 10 ) == 0)+ {+ TheInGameUI->runSpectatorAction( command.str() + 10 );+ replyOk( "\"done\":true" );+ return;+ }+/* skirmish <players> <seed> <map>The map is whatever is left on the line, spaces and all, because every shipped map has aspace in its name and quoting rules would be one more thing to get wrong at the far end. */diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex 253a53c9c..4c0f5a6f9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -83,6 +83,7 @@#include "GameClient/GlobalLanguage.h"#include "GameClient/InGameUI.h"#include "GameClient/Image.h"+#include "GameClient/ObserverCamera.h"#include "GameClient/ParticleSys.h"#include "GameClient/PlayerColorScheme.h"#include "GameClient/LanguageFilter.h"@@ -4004,7 +4005,7 @@ void Drawable::drawSupplyCash( const IRegion2D *healthBarRegion )}// shrouded ground keeps its secrets: what was there when you last looked is not news- if( obj->getShroudedStatus( ThePlayerList->getLocalPlayer()->getPlayerIndex() ) != OBJECTSHROUD_CLEAR )+ if( obj->getShroudedStatus( TheObserverCamera.getShroudPlayerIndex() ) != OBJECTSHROUD_CLEAR )return;if( m_supplyCashDisplayString == NULL )diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cppindex 56fefd635..1f4f4ca04 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cpp@@ -47,6 +47,7 @@#include "GameClient/Display.h"#include "GameClient/GameClient.h"#include "GameClient/Drawable.h"+#include "GameClient/ObserverCamera.h"#include "GameClient/ParticleSys.h"#include "GameLogic/PartitionManager.h"@@ -806,7 +807,7 @@ void FXList::clear()//-------------------------------------------------------------------------------------------------void FXList::doFXPos(const Coord3D *primary, const Matrix3D* primaryMtx, const Real primarySpeed, const Coord3D *secondary, const Real overrideRadius ) const{- if (ThePartitionManager->getShroudStatusForPlayer(ThePlayerList->getLocalPlayer()->getPlayerIndex(), primary) != CELLSHROUD_CLEAR)+ if (ThePartitionManager->getShroudStatusForPlayer(TheObserverCamera.getShroudPlayerIndex(), primary) != CELLSHROUD_CLEAR)return;for (FXNuggetList::const_iterator it = m_nuggets.begin(); it != m_nuggets.end(); ++it)@@ -818,7 +819,7 @@ void FXList::doFXPos(const Coord3D *primary, const Matrix3D* primaryMtx, const R//-------------------------------------------------------------------------------------------------void FXList::doFXObj(const Object* primary, const Object* secondary) const{- if (primary && primary->getShroudedStatus(ThePlayerList->getLocalPlayer()->getPlayerIndex()) > OBJECTSHROUD_PARTIAL_CLEAR)+ if (primary && primary->getShroudedStatus(TheObserverCamera.getShroudPlayerIndex()) > OBJECTSHROUD_PARTIAL_CLEAR)return; //the primary object is fogged or shrouded so don't bother with the effect.for (FXNuggetList::const_iterator it = m_nuggets.begin(); it != m_nuggets.end(); ++it)diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cppindex 85e3adfec..cd6fd1a0d 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp@@ -70,6 +70,7 @@#include "GameClient/LookAtXlat.h"#include "GameClient/MetaEvent.h"#include "GameClient/Mouse.h"+#include "GameClient/ObserverCamera.h"#include "GameClient/ParticleSys.h"#include "GameClient/PlaceEventTranslator.h"#include "GameClient/RayEffect.h"@@ -745,7 +746,8 @@ void GameClient::update( void )freezeTime = freezeTime || TheScriptEngine->isTimeFrozenDebug();freezeTime = freezeTime || TheScriptEngine->isTimeFrozenScript();freezeTime = freezeTime || TheGameLogic->isGamePaused();- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ // the player whose fog is drawn: this machine's, or the one a watcher looks through with fog on+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;// hack to let client spin fast in network games but still do effects at the same pace. -MDCstatic UnsignedInt lastFrame = ~0;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 5abc51348..25ffe74a1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -79,6 +79,7 @@#include "GameClient/PlayerColorScheme.h"#include "GameClient/VideoPlayer.h"#include "GameClient/Mouse.h"+#include "GameClient/ObserverCamera.h"#include "GameClient/Keyboard.h"#include "GameClient/GadgetStaticText.h"#include "GameClient/View.h"@@ -1791,6 +1792,13 @@ static const std::string OPTION_ACTION = "option:";static const std::string FLIP_ACTION = "flip:";static const std::string PICK_ACTION = "pick:";static const std::string WATCH_ACTION = "watch:";+// data-click="camera:director", "camera:free" or "camera:N" drives the camera (ObserverCamera.h) and+// folds up flip:camera; data-click="fog" turns the followed player's fog on and off+static const std::string CAMERA_ACTION = "camera:";+static const std::string CAMERA_DIRECTOR = "director";+static const std::string CAMERA_FREE = "free";+static const std::string CAMERA_GROUP = "camera";+static const std::string FOG_ACTION = "fog";static const std::string TEXT_LOOKUP = "text:";static const std::string STAT_GROUP = "stat";@@ -2204,6 +2212,53 @@ static void fillSpectatorTop( std::vector< SpectatorStats > players, std::vector}}+//-------------------------------------------------------------------------------------------------+/** The players the camera can follow, grouped by team the way the seats are. Which one it is+ * following is marked every frame, since scrolling by hand lets go of him between two of the+ * lists' rebuilds. */+//-------------------------------------------------------------------------------------------------+static void fillSpectatorCameras( std::vector< SpectatorStats > players, std::vector< HtmlValues > &entries )+{+ std::stable_sort( players.begin(), players.end(),+ []( const SpectatorStats &a, const SpectatorStats &b ) { return a.team < b.team; } );++ entries.clear();+ for( size_t index = 0; index < players.size(); index++ )+ {+ HtmlValues entry = spectatorHead( players[ index ].player );+ entry[ "click" ] = CAMERA_ACTION + std::to_string( players[ index ].player->getPlayerIndex() );+ entries.push_back( entry );+ }+}++//-------------------------------------------------------------------------------------------------+/** What the camera's drop-down and the fog switch show this frame. */+//-------------------------------------------------------------------------------------------------+static void fillSpectatorCameraValues( std::vector< HtmlValues > &cameras, HtmlValues &values )+{+ const Int followed = TheObserverCamera.getFollowedPlayerIndex();+ const ObserverCameraMode mode = TheObserverCamera.getMode();+ const std::string followedClick = CAMERA_ACTION + std::to_string( followed );+ for( size_t index = 0; index < cameras.size(); index++ )+ cameras[ index ][ "on" ] = mode == OBSERVER_CAMERA_PLAYER && cameras[ index ][ "click" ] == followedClick ? "on" : "";++ const char *label = mode == OBSERVER_CAMERA_DIRECTOR ? "GUI:HudCameraDirector" : "GUI:HudCameraFree";+ values[ "camera" ] = WideCharStringToMultiByte( TheGameText->fetch( label ).str() );+ values[ "cameradirector" ] = mode == OBSERVER_CAMERA_DIRECTOR ? "on" : "";+ values[ "camerafree" ] = mode == OBSERVER_CAMERA_FREE && followed == ObserverCamera::NO_PLAYER ? "on" : "";+ values[ "fog" ] = TheObserverCamera.isFogOn() ? "on" : "";+ values[ "fogname" ] = "";+ values[ "fogcolor" ] = "";+ if( followed == ObserverCamera::NO_PLAYER )+ return;++ const HtmlValues head = spectatorHead( ThePlayerList->getNthPlayer( followed ) );+ if( mode == OBSERVER_CAMERA_PLAYER )+ values[ "camera" ] = head.at( "name" );+ values[ "fogname" ] = head.at( "name" );+ values[ "fogcolor" ] = head.at( "color" );+}+//-------------------------------------------------------------------------------------------------/** Every player still in the match for the pages a player sees: grouped by team, allies both ways* sharing one, the local player's own team first. Only the player and the team are filled in;@@ -2489,6 +2544,7 @@ void InGameUI::drawSpectatorPage( void )fillSpectatorPlayers( players, stat, teams, m_spectatorLists[ "players" ] );fillSpectatorArmies( players, m_spectatorLists[ "army" ] );fillSpectatorTop( players, m_spectatorLists[ "top" ] );+ fillSpectatorCameras( players, m_spectatorLists[ "cameras" ] );fillSpectatorSuperweapons( players, m_spectatorSuperweapons, m_spectatorLists[ "superweapons" ] );fillSpectatorSkills( players, m_spectatorLists[ "skills" ] );@@ -2529,6 +2585,7 @@ void InGameUI::drawSpectatorPage( void )}HtmlValues values = m_spectatorTotals;+ fillSpectatorCameraValues( m_spectatorLists[ "cameras" ], values );for( std::map< std::string, std::string >::const_iterator pick = m_spectatorPicked.begin(); pick != m_spectatorPicked.end(); ++pick ){values[ PICK_ACTION + pick->first ] = pick->second;@@ -2558,7 +2615,13 @@ Bool InGameUI::handleSpectatorPageClick( const ICoord2D *mouse, Bool act )if( !act )return TRUE;- const std::string action = m_spectatorOverlay->click( *mouse );+ runSpectatorAction( m_spectatorOverlay->click( *mouse ) );+ return TRUE;+}++//-------------------------------------------------------------------------------------------------+void InGameUI::runSpectatorAction( const std::string &action )+{if( action.compare( 0, FLIP_ACTION.size(), FLIP_ACTION ) == 0 ){const std::string name = action.substr( FLIP_ACTION.size() );@@ -2572,7 +2635,7 @@ Bool InGameUI::handleSpectatorPageClick( const ICoord2D *mouse, Bool act )if( colon == std::string::npos ){DEBUG_LOG(( "Spectator page: data-click=\"%s\" is not pick:group:choice\n", action.c_str() ));- return TRUE;+ return;}const std::string group = pick.substr( 0, colon );@@ -2589,14 +2652,43 @@ Bool InGameUI::handleSpectatorPageClick( const ICoord2D *mouse, Bool act )Player *watched = player == TheControlBar->getObserverLookAtPlayer() ? NULL : player;deselectAllDrawables();TheControlBar->watchPlayer( watched );++ // a replay with the recorded camera switched on in the options follows whoever is watched,+ // what picking him in the old player list did+ if( TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay )+ {+ if( watched != NULL )+ TheObserverCamera.followPlayer( watched->getPlayerIndex() );+ else+ TheObserverCamera.setMode( OBSERVER_CAMERA_FREE );+ }}+ else if( action.compare( 0, CAMERA_ACTION.size(), CAMERA_ACTION ) == 0 )+ {+ const std::string choice = action.substr( CAMERA_ACTION.size() );+ m_spectatorFlipped.erase( CAMERA_GROUP );+ if( choice == CAMERA_DIRECTOR )+ TheObserverCamera.setMode( OBSERVER_CAMERA_DIRECTOR );+ else if( choice == CAMERA_FREE )+ TheObserverCamera.setMode( OBSERVER_CAMERA_FREE );+ else+ {+ // following a player is watching him too: his seat lit, his side on the bar+ Player *player = ThePlayerList->getNthPlayer( atoi( choice.c_str() ) );+ deselectAllDrawables();+ TheControlBar->watchPlayer( player );+ TheObserverCamera.followPlayer( player->getPlayerIndex() );+ }+ }+ else if( action == FOG_ACTION )+ TheObserverCamera.setFog( !TheObserverCamera.isFogOn() );else if( action.compare( 0, OPTION_ACTION.size(), OPTION_ACTION ) == 0 ){const OptionDef *option = findOptionDef( action.substr( OPTION_ACTION.size() ).c_str() );if( option == NULL || option->kind != OPTION_BOOL ){DEBUG_LOG(( "Spectator page: data-click=\"%s\" names no on/off option\n", action.c_str() ));- return TRUE;+ return;}const Bool now = !option->get();@@ -2606,7 +2698,6 @@ Bool InGameUI::handleSpectatorPageClick( const ICoord2D *mouse, Bool act )pref[ AsciiString( option->iniKey ) ] = AsciiString( now ? "yes" : "no" );pref.write();}- return TRUE;}//-------------------------------------------------------------------------------------------------@@ -3945,6 +4036,11 @@ void InGameUI::update( void )// alt-tab does not fling the camera across the map on the first frame. See FINDINGS.md 7.4.//const UnsignedInt cameraNowMs = timeGetTime();++ // a watcher's camera is driven for him while it is not in his own hands (ObserverCamera.h)+ if( TheGameLogic->isInGame() && localPlayerWatching() )+ TheObserverCamera.update( cameraNowMs );+Real cameraSteps = 1.0f;if( m_cameraKeyLastMs != 0 )cameraSteps = (Real)(cameraNowMs - m_cameraKeyLastMs) * (LOGICFRAMES_PER_SECOND / 1000.0f);@@ -4043,6 +4139,7 @@ void InGameUI::reset( void )m_quitMenuPageLoaded = FALSE;m_signalsWereShown = FALSE;m_spectatorPageLoaded = FALSE;+ TheObserverCamera.reset();m_spectatorFlipped.clear();m_spectatorPicked.clear();m_spectatorLists.clear();@@ -5274,12 +5371,12 @@ Bool InGameUI::issueAttackCircle( void )}//--------------------------------------------------------------------------------------------------/** Whether the shroud is over this object as far as the player at this machine is concerned. */+/** Whether the shroud is over this object as far as the player at this machine is concerned, or the+ * player a watcher with fog on is looking through. *///-------------------------------------------------------------------------------------------------Bool InGameUI::isHiddenByShroud( const Object *obj ) const{- const Int localIndex = ThePlayerList->getLocalPlayer()->getPlayerIndex();- return obj->getShroudedStatus( localIndex ) > OBJECTSHROUD_PARTIAL_CLEAR;+ return obj->getShroudedStatus( TheObserverCamera.getShroudPlayerIndex() ) > OBJECTSHROUD_PARTIAL_CLEAR;}//-------------------------------------------------------------------------------------------------@@ -5944,7 +6041,7 @@ void InGameUI::createMouseoverHint( const GameMessage *msg )elsetooltip = str;- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;Int x, y;ThePartitionManager->worldToCell(obj->getPosition()->x, obj->getPosition()->y, &x, &y);@@ -12498,8 +12595,8 @@ void InGameUI::drawFloatingText( void ){ftd = *it;ICoord2D pos;- // get the local player's index- Int playerNdx = ThePlayerList->getLocalPlayer()->getPlayerIndex();+ // whose fog the screen is drawn in+ Int playerNdx = TheObserverCamera.getShroudPlayerIndex();// which PartitionManager cells are we looking at?Int pCX, pCY;@@ -12783,7 +12880,7 @@ void InGameUI::updateAndDrawWorldAnimations( void )// don't bother going forward with the draw process if this location is shrouded for// the local player//- Int playerIndex = ThePlayerList->getLocalPlayer()->getPlayerIndex();+ Int playerIndex = TheObserverCamera.getShroudPlayerIndex();if( ThePartitionManager->getShroudStatusForPlayer( playerIndex, &wad->m_worldPos ) != CELLSHROUD_CLEAR ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cppindex a6b765116..d4c71fb5e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp@@ -134,6 +134,7 @@ LookAtTranslator::LookAtTranslator() :m_timestamp(0),m_lastPlaneID(INVALID_DRAWABLE_ID),m_lastMouseMoveFrame(0),+ m_cameraSentFrame(0),m_scrollType(SCROLL_NONE),m_scrollMovesCursor(true){@@ -180,6 +181,30 @@ void LookAtTranslator::setCurrentPos( const ICoord2D& pos )m_currentPos = pos;}+/// how often at most a player's camera goes out to the other machines: five times a second, about+/// fifty bytes each, and the observer smooths the steps between+static const UnsignedInt CAMERA_NETWORK_FRAMES = LOGICFRAMES_PER_SECOND / 5;++//-----------------------------------------------------------------------------+/** Is this playing player's camera due to go out over the network? Only in a match between+ * machines, only from somebody still playing, and only when it moved since the last one went. */+Bool LookAtTranslator::networkCameraDue( const ViewLocation &view )+{+ if( !TheGameLogic->isInMultiplayerGame() || !ThePlayerList->getLocalPlayer()->isPlayerActive() )+ return FALSE;++ const UnsignedInt frame = TheGameLogic->getFrame();+ if( frame >= m_cameraSentFrame && frame < m_cameraSentFrame + CAMERA_NETWORK_FRAMES )+ return FALSE;+ if( view.m_pos.x == m_cameraSent.m_pos.x && view.m_pos.y == m_cameraSent.m_pos.y+ && view.m_angle == m_cameraSent.m_angle && view.m_pitch == m_cameraSent.m_pitch && view.m_zoom == m_cameraSent.m_zoom )+ return FALSE;++ m_cameraSentFrame = frame;+ m_cameraSent = view;+ return TRUE;+}+//-----------------------------------------------------------------------------/*** The LookAt Translator is responsible for camera movements. It is directly responsible for@@ -597,12 +622,14 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage// Advance the pan clock even while stationary, so restarting does not include idle time.TheTacticalView->scrollBy( &offset );- //if (TheGlobalData->m_saveCameraInReplay /*&& TheRecorder->getMode() != RECORDERMODETYPE_PLAYBACK *//**/&& (TheGameLogic->isInSinglePlayerGame() || TheGameLogic->isInSkirmishGame())/**/)- //if (TheGlobalData->m_saveCameraInReplay && (TheGameLogic->isInMultiplayerGame() || TheGameLogic->isInSinglePlayerGame() || TheGameLogic->isInSkirmishGame()))- if (TheGlobalData->m_saveCameraInReplay && (TheGameLogic->isInSinglePlayerGame() || TheGameLogic->isInSkirmishGame()))+ // A playing player's camera goes to the other machines too, so an observer can watch his+ // screen: every CAMERA_NETWORK_FRAMES logic frames at most and only when it moved, where+ // a game on one machine records it every frame as EA did.+ ViewLocation currentView;+ TheTacticalView->getLocation(¤tView);+ const Bool recordCamera = TheGlobalData->m_saveCameraInReplay && (TheGameLogic->isInSinglePlayerGame() || TheGameLogic->isInSkirmishGame());+ if (recordCamera || networkCameraDue(currentView)){- ViewLocation currentView;- TheTacticalView->getLocation(¤tView);GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_SET_REPLAY_CAMERA );msg->appendLocationArgument( currentView.m_pos );msg->appendRealArgument( currentView.m_angle );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cppnew file mode 100644index 000000000..f9be20c77--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp@@ -0,0 +1,405 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++// ObserverCamera.cpp /////////////////////////////////////////////////////////////////////////////+// The watcher's camera driven for him, and the watched player's fog. ObserverCamera.h says which+// is which.+///////////////////////////////////////////////////////////////////////////////////////////////////++#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine++#include "Common/Player.h"+#include "Common/PlayerList.h"+#include "GameClient/Drawable.h"+#include "GameClient/GameClient.h"+#include "GameClient/LookAtXlat.h"+#include "GameClient/ObserverCamera.h"+#include "GameLogic/Damage.h"+#include "GameLogic/GameLogic.h"+#include "GameLogic/GhostObject.h"+#include "GameLogic/Module/BodyModule.h"+#include "GameLogic/Object.h"+#include "GameLogic/PartitionManager.h"++#include <math.h>++ObserverCamera TheObserverCamera;++/// how far round a hit the others count as the same fight: about half a screen at the default zoom+static const Real DIRECTOR_GATHER_RADIUS = 220.0f;+/// how long a hit keeps a place hot+static const UnsignedInt DIRECTOR_HEAT_FRAMES = 5 * LOGICFRAMES_PER_SECOND;+/// how often the hits are counted again+static const UnsignedInt DIRECTOR_SCAN_FRAMES = LOGICFRAMES_PER_SECOND / 2;+/// how long the director stays with a fight that is still going before it looks for a better one+static const UnsignedInt DIRECTOR_HOLD_FRAMES = 6 * LOGICFRAMES_PER_SECOND;+/// how much hotter somewhere else has to be to be worth leaving a fight that is still going+static const Real DIRECTOR_SWITCH_MARGIN = 1.5f;+/// further apart than this the camera cuts rather than pans: a pan across the map shows nothing+static const Real CUT_DISTANCE = 700.0f;+/// the camera found further than this from where it was put was moved by something else, the radar+/// most likely; the edge of the map pulls it back by less+static const Real HAND_JUMP_DISTANCE = 400.0f;+/// how quickly the camera closes on where it is going, in seconds to cover about two thirds of it+static const Real DIRECTOR_PAN_SECONDS = 0.35f;+/// a player's camera comes a few times a second, and this smooths the steps between+static const Real PLAYER_PAN_SECONDS = 0.12f;+/// a frame longer than this is a hitch, and is not allowed to throw the camera across the map+static const UnsignedInt LONGEST_STEP_MILLISECONDS = 100;+static const Real MILLISECONDS_PER_SECOND = 1000.0f;++//-------------------------------------------------------------------------------------------------+Real ObserverCamera_heatAround( const std::vector< DirectorHeat > &hits, const Coord2D &around, Coord2D *middle )+{+ Real heat = 0.0f;+ Coord2D sum = { 0.0f, 0.0f };+ for( size_t index = 0; index < hits.size(); index++ )+ {+ const DirectorHeat &hit = hits[ index ];+ const Real dx = hit.position.x - around.x;+ const Real dy = hit.position.y - around.y;+ if( dx * dx + dy * dy > DIRECTOR_GATHER_RADIUS * DIRECTOR_GATHER_RADIUS )+ continue;++ heat += hit.weight;+ sum.x += hit.position.x * hit.weight;+ sum.y += hit.position.y * hit.weight;+ }++ *middle = around;+ if( heat > 0.0f )+ {+ middle->x = sum.x / heat;+ middle->y = sum.y / heat;+ }+ return heat;+}++//-------------------------------------------------------------------------------------------------+Bool ObserverCamera_hottestPlace( const std::vector< DirectorHeat > &hits, Coord2D *place, Real *heat )+{+ // ponytail: every hit against every other, fine for the few hundred a big fight makes in five+ // seconds; a grid of cells if a match ever gets to thousands+ *heat = 0.0f;+ for( size_t index = 0; index < hits.size(); index++ )+ {+ Coord2D middle;+ const Real around = ObserverCamera_heatAround( hits, hits[ index ].position, &middle );+ if( around > *heat )+ {+ *heat = around;+ *place = middle;+ }+ }+ return *heat > 0.0f;+}++//-------------------------------------------------------------------------------------------------+Bool ObserverCamera_shouldMove( Real heatHere, Real heatThere, UnsignedInt framesHere )+{+ if( heatHere <= 0.0f )+ return heatThere > 0.0f;+ return framesHere >= DIRECTOR_HOLD_FRAMES && heatThere > heatHere * DIRECTOR_SWITCH_MARGIN;+}++//-------------------------------------------------------------------------------------------------+/** An angle's shortest way round to another, so a camera facing just west of north turns a few+ * degrees to just east of it rather than all the way back round. */+//-------------------------------------------------------------------------------------------------+static Real turnTowards( Real from, Real to, Real share )+{+ Real turn = to - from;+ while( turn > PI )+ turn -= 2.0f * PI;+ while( turn < -PI )+ turn += 2.0f * PI;+ return from + turn * share;+}++//-------------------------------------------------------------------------------------------------+ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocation &to, Real elapsedSeconds, Real timeConstant )+{+ const Coord3D &start = from.getPosition();+ const Coord3D &end = to.getPosition();+ const Real dx = end.x - start.x;+ const Real dy = end.y - start.y;+ if( dx * dx + dy * dy > CUT_DISTANCE * CUT_DISTANCE )+ return to;++ const Real share = 1.0f - expf( -elapsedSeconds / timeConstant );+ ViewLocation step;+ step.init( start.x + dx * share, start.y + dy * share, start.z + ( end.z - start.z ) * share,+ turnTowards( from.getAngle(), to.getAngle(), share ),+ from.getPitch() + ( to.getPitch() - from.getPitch() ) * share,+ from.getZoom() + ( to.getZoom() - from.getZoom() ) * share );+ return step;+}++//-------------------------------------------------------------------------------------------------+ObserverCamera::ObserverCamera()+{+ reset();+}++//-------------------------------------------------------------------------------------------------+void ObserverCamera::reset( void )+{+ m_mode = OBSERVER_CAMERA_FREE;+ m_followed = NO_PLAYER;+ m_fog = FALSE;+ m_shroudViewer = NO_PLAYER;+ m_driving = FALSE;+ m_holdingHeight = FALSE;+ m_drivenTo.zero();+ m_lastUpdate = 0;+ for( Int index = 0; index < MAX_PLAYER_COUNT; index++ )+ m_playerViews[ index ] = ViewLocation();+ m_placeValid = FALSE;+ m_place.x = m_place.y = 0.0f;+ m_placeSince = 0;+ m_placeScanned = 0;+ m_placeFor = NULL;+}++//-------------------------------------------------------------------------------------------------+void ObserverCamera::notePlayerView( Int playerIndex, const ViewLocation &view )+{+ if( !m_playerViews[ playerIndex ].isValid() )+ DEBUG_LOG(( "OBSCAM frame %u first camera from player %d\n", TheGameLogic->getFrame(), playerIndex ));+ m_playerViews[ playerIndex ] = view;+}++//-------------------------------------------------------------------------------------------------+void ObserverCamera::setMode( ObserverCameraMode mode )+{+ m_mode = mode;+ m_followed = NO_PLAYER;+ m_driving = FALSE;+ m_placeValid = FALSE;+}++//-------------------------------------------------------------------------------------------------+void ObserverCamera::followPlayer( Int playerIndex )+{+ m_mode = OBSERVER_CAMERA_PLAYER;+ m_followed = playerIndex;+ m_driving = FALSE;+ m_placeValid = FALSE;+}++//-------------------------------------------------------------------------------------------------+Int ObserverCamera::getShroudPlayerIndex( void ) const+{+ return m_shroudViewer != NO_PLAYER ? m_shroudViewer : ThePlayerList->getLocalPlayer()->getPlayerIndex();+}++//-------------------------------------------------------------------------------------------------+/** The fog is the followed player's while it is on. Swapping it is what the debug key that makes+ * you another player does to the fog: his ghosts of what he last saw in, and the ground redrawn+ * in his shroud. A knocked-out player's machine kept only his own fog memory until now, so it+ * starts keeping everybody's the first time he asks for somebody else's.+ *+ * Two things each drawable remembers belong to the old viewer and are cleared: whether it is+ * obscured, which a building's shadow is only decided again on a change of, and the frame it was+ * last seen clear, which keeps a unit drawn two seconds after it goes into fog. The drawable+ * walk in GameClient::update sets the first again for the new viewer before the next frame. */+//-------------------------------------------------------------------------------------------------+void ObserverCamera::updateShroudViewer( void )+{+ const Int viewer = m_fog ? m_followed : NO_PLAYER;+ if( viewer == m_shroudViewer )+ return;++ m_shroudViewer = viewer;+ TheGhostObjectManager->setTrackAllPlayers( TRUE );+ TheGhostObjectManager->setLocalPlayerIndex( getShroudPlayerIndex() );+ ThePartitionManager->refreshShroudForLocalPlayer();+ for( Drawable *draw = TheGameClient->firstDrawable(); draw != NULL; draw = draw->getNextDrawable() )+ {+ draw->setFullyObscuredByShroud( FALSE );+ draw->setShroudClearFrame( 0 );+ }+}++//-------------------------------------------------------------------------------------------------+/** While a player's camera is shown, his zoom is: the view otherwise eases its height back towards+ * the watcher's own every frame and the two meet two thirds of the way. Only ever let go when+ * this took it, so the cinema's hold on the height is not undone. */+//-------------------------------------------------------------------------------------------------+void ObserverCamera::holdHeight( Bool hold )+{+ if( hold == m_holdingHeight )+ return;++ m_holdingHeight = hold;+ TheTacticalView->setOkToAdjustHeight( !hold );+}++//-------------------------------------------------------------------------------------------------+Bool ObserverCamera::takenByHand( const ViewLocation ¤t ) const+{+ if( TheLookAtTranslator->isMovingCamera() )+ return TRUE;++ const Real dx = current.getPosition().x - m_drivenTo.x;+ const Real dy = current.getPosition().y - m_drivenTo.y;+ return dx * dx + dy * dy > HAND_JUMP_DISTANCE * HAND_JUMP_DISTANCE;+}++//-------------------------------------------------------------------------------------------------+/** Where the director looks: the hottest fight, held for a while, followed as it moves, and left+ * for a clearly hotter one. Narrowed to one player it counts only the hits on his things and the+ * hits his things made, and with none of those it goes home to his command centre. */+//-------------------------------------------------------------------------------------------------+Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )+{+ const UnsignedInt frame = TheGameLogic->getFrame();+ if( narrowTo != m_placeFor )+ {+ m_placeFor = narrowTo;+ m_placeValid = FALSE;+ }+ if( m_placeValid && frame >= m_placeScanned && frame < m_placeScanned + DIRECTOR_SCAN_FRAMES )+ {+ *place = m_place;+ return TRUE;+ }+ m_placeScanned = frame;++ std::vector< DirectorHeat > hits;+ const Object *home = NULL;+ for( Object *obj = TheGameLogic->getFirstObject(); obj != NULL; obj = obj->getNextObject() )+ {+ if( narrowTo != NULL && home == NULL && obj->getControllingPlayer() == narrowTo+ && obj->isKindOf( KINDOF_COMMANDCENTER ) )+ home = obj;++ const BodyModuleInterface *body = obj->getBodyModule();+ const UnsignedInt hitAt = body->getLastDamageTimestamp();+ if( hitAt == 0 || frame >= hitAt + DIRECTOR_HEAT_FRAMES )+ continue;+ if( narrowTo != NULL && obj->getControllingPlayer() != narrowTo+ && ( body->getLastDamageInfo()->in.m_sourcePlayerMask & narrowTo->getPlayerMask() ) == 0 )+ continue;++ DirectorHeat hit;+ hit.position.x = obj->getPosition()->x;+ hit.position.y = obj->getPosition()->y;+ hit.weight = 1.0f;+ hits.push_back( hit );+ }++ Coord2D hottest;+ Real hottestHeat = 0.0f;+ ObserverCamera_hottestPlace( hits, &hottest, &hottestHeat );++ Coord2D followed = m_place;+ const Real heatHere = m_placeValid ? ObserverCamera_heatAround( hits, m_place, &followed ) : 0.0f;+ if( !m_placeValid || ObserverCamera_shouldMove( heatHere, hottestHeat, frame - m_placeSince ) )+ {+ if( hottestHeat > 0.0f )+ {+ DEBUG_LOG(( "OBSCAM frame %u director to (%.0f,%.0f) heat %.0f, was %.0f here\n",+ frame, hottest.x, hottest.y, hottestHeat, heatHere ));+ m_place = hottest;+ m_placeSince = frame;+ m_placeValid = TRUE;+ }+ else if( home != NULL )+ {+ m_place.x = home->getPosition()->x;+ m_place.y = home->getPosition()->y;+ m_placeSince = frame;+ m_placeValid = TRUE;+ }+ }+ else+ m_place = followed;++ *place = m_place;+ return m_placeValid;+}++//-------------------------------------------------------------------------------------------------+Bool ObserverCamera::chooseTarget( const ViewLocation ¤t, ViewLocation *target )+{+ const Coord3D &at = current.getPosition();+ Coord2D place;+ if( m_mode == OBSERVER_CAMERA_DIRECTOR )+ {+ if( !directorPlace( NULL, &place ) )+ return FALSE;+ target->init( place.x, place.y, at.z, current.getAngle(), current.getPitch(), current.getZoom() );+ return TRUE;+ }++ const ViewLocation &view = m_playerViews[ m_followed ];+ if( view.isValid() )+ {+ *target = view;+ return TRUE;+ }++ if( !directorPlace( ThePlayerList->getNthPlayer( m_followed ), &place ) )+ return FALSE;+ target->init( place.x, place.y, at.z, current.getAngle(), current.getPitch(), current.getZoom() );+ return TRUE;+}++//-------------------------------------------------------------------------------------------------+void ObserverCamera::update( UnsignedInt nowMilliseconds )+{+ const UnsignedInt elapsed = m_lastUpdate == 0 ? 0 : min( nowMilliseconds - m_lastUpdate, LONGEST_STEP_MILLISECONDS );+ m_lastUpdate = nowMilliseconds;++ updateShroudViewer();++ if( m_mode == OBSERVER_CAMERA_FREE )+ {+ m_driving = FALSE;+ holdHeight( FALSE );+ return;+ }++ ViewLocation current;+ TheTacticalView->getLocation( ¤t );+ // the followed player stays followed, for his fog, with the camera back in the watcher's hands+ if( m_driving && takenByHand( current ) )+ {+ DEBUG_LOG(( "OBSCAM frame %u the watcher took the camera\n", TheGameLogic->getFrame() ));+ m_mode = OBSERVER_CAMERA_FREE;+ m_driving = FALSE;+ holdHeight( FALSE );+ return;+ }++ ViewLocation target;+ if( !chooseTarget( current, &target ) )+ {+ m_driving = FALSE;+ holdHeight( FALSE );+ return;+ }++ holdHeight( m_mode == OBSERVER_CAMERA_PLAYER && m_playerViews[ m_followed ].isValid() );+ const Real timeConstant = m_mode == OBSERVER_CAMERA_PLAYER ? PLAYER_PAN_SECONDS : DIRECTOR_PAN_SECONDS;+ const ViewLocation step = ObserverCamera_approach( current, target, elapsed / MILLISECONDS_PER_SECOND, timeConstant );+ TheTacticalView->setLocation( &step );+ m_drivenTo = step.getPosition();+ m_driving = TRUE;+}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/View.cppindex 8bb298b40..593772eba 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp@@ -81,7 +81,6 @@ View::View( void )m_lockDist = 0.0f;m_maxHeightAboveGround = 0.0f;m_minHeightAboveGround = 0.0f;- m_viewLockedUntilFrame = 0;m_next = NULL;m_okToAdjustHeight = TRUE;m_originX = 0;@@ -142,13 +141,6 @@ 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/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cppindex 409c7b4a0..3e1cbc1fe 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp@@ -81,6 +81,7 @@#include "GameClient/Line2D.h"#include "GameClient/ControlBar.h"+#include "GameClient/ObserverCamera.h"#include <float.h>@@ -1333,7 +1334,7 @@ void PartitionCell::addLooker(Int playerIndex)invalidateShroudedStatusForAllCois( playerIndex );updateSeenStructures( playerIndex, oldShroud, newShroud );- if( playerIndex == ThePlayerList->getLocalPlayer()->getPlayerIndex() )+ if( playerIndex == TheObserverCamera.getShroudPlayerIndex() ){// and if this is the local player, do the Client update.TheDisplay->setShroudLevel(m_cellX, m_cellY, newShroud);@@ -1370,7 +1371,7 @@ void PartitionCell::removeLooker(Int playerIndex)invalidateShroudedStatusForAllCois( playerIndex );updateSeenStructures( playerIndex, oldShroud, newShroud );- if( playerIndex == ThePlayerList->getLocalPlayer()->getPlayerIndex() )+ if( playerIndex == TheObserverCamera.getShroudPlayerIndex() ){// and if this is the local player, do the Client update.TheDisplay->setShroudLevel(m_cellX, m_cellY, newShroud);@@ -1399,7 +1400,7 @@ void PartitionCell::addShrouder( Int playerIndex )updateSeenStructures( playerIndex, oldShroud, newShroud );// and update the client if we are on the local player- if( playerIndex == ThePlayerList->getLocalPlayer()->getPlayerIndex() )+ if( playerIndex == TheObserverCamera.getShroudPlayerIndex() ){TheDisplay->setShroudLevel(m_cellX, m_cellY, newShroud);TheRadar->setShroudLevel(m_cellX, m_cellY, newShroud);@@ -3145,11 +3146,12 @@ void PartitionManager::shroudMapForPlayer( Int playerIndex )//-----------------------------------------------------------------------------void PartitionManager::refreshShroudForLocalPlayer(){- // This is a drawing refresh only, and so is allowed to use the Local Player.+ // This is a drawing refresh only, and so is allowed to use the Local Player, or the player a+ // watcher is looking through.TheDisplay->clearShroud();TheRadar->clearShroud();- Int playerIndex = ThePlayerList->getLocalPlayer()->getPlayerIndex();+ Int playerIndex = TheObserverCamera.getShroudPlayerIndex();for (int i = 0; i < m_totalCellCount; ++i){Int x = m_cells[i].getCellX();diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex 4826fbb44..8c274eac3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -131,6 +131,7 @@ static void considerBuilderProc( Object *obj, void *userData )#include "GameClient/InGameUI.h"#include "GameClient/KeyDefs.h"#include "GameClient/Mouse.h"+#include "GameClient/ObserverCamera.h"#include "GameClient/ParticleSys.h"#include "GameClient/PlayerColorScheme.h"#include "GameClient/Shell.h"@@ -2343,35 +2344,25 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )// --------------------------------------------------------------------------------------------case GameMessage::MSG_SET_REPLAY_CAMERA:{- if (TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay && TheControlBar->getObserverLookAtPlayer() == thisPlayer)+ // Where this player's camera is, out of a replay or over the network from a match going on.+ // Only a watcher's camera is ever moved by it, and that is the observer camera's to do on+ // its own frame when it is following this player; the logic only passes it on.+ ViewLocation loc;+ const Coord3D &pos = msg->getArgument( 0 )->location;+ loc.init( pos.x, pos.y, pos.z, msg->getArgument( 1 )->real, msg->getArgument( 2 )->real, msg->getArgument( 3 )->real );+ TheObserverCamera.notePlayerView( thisPlayer->getPlayerIndex(), loc );++ // a replay shows the recorded player's pointer too, while the watcher is not using his own+ if (TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheObserverCamera.getMode() == OBSERVER_CAMERA_PLAYER+ && TheObserverCamera.getFollowedPlayerIndex() == thisPlayer->getPlayerIndex() && !TheLookAtTranslator->hasMouseMovedRecently()){- if (TheTacticalView->isCameraMovementFinished())- {- ViewLocation loc;- Coord3D pos;- Real pitch, angle, zoom;- pos = msg->getArgument( 0 )->location;- angle = msg->getArgument( 1 )->real;- pitch = msg->getArgument( 2 )->real;- zoom = msg->getArgument( 3 )->real;- 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) );- ICoord2D mousePos = msg->getArgument( 5 )->pixel;- TheMouse->setPosition( mousePos.x, mousePos.y );- TheLookAtTranslator->setCurrentPos( mousePos );- }- }+ TheMouse->setCursor( (Mouse::MouseCursor)(msg->getArgument( 4 )->integer) );+ ICoord2D mousePos = msg->getArgument( 5 )->pixel;+ TheMouse->setPosition( mousePos.x, mousePos.y );+ TheLookAtTranslator->setCurrentPos( mousePos );}break;- } // end beacon text+ }//---------------------------------------------------------------------------------------------case GameMessage::MSG_CREATE_TEAM0:diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cppindex 58ed4052e..2c938844a 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp@@ -42,6 +42,7 @@#include "GameClient/Color.h"#include "GameClient/Display.h"#include "GameClient/GameClient.h"+#include "GameClient/ObserverCamera.h"#include "GameClient/GameWindow.h"#include "GameClient/Image.h"#include "GameClient/Line2D.h"@@ -355,8 +356,7 @@ void W3DRadar::drawLandmarkIcon( Int pixelX, Int pixelY, Int width, Int height,//-------------------------------------------------------------------------------------------------void W3DRadar::collectLandmarks( const RadarObject *listHead ){- const Player *localPlayer = ThePlayerList->getLocalPlayer();- const Int localPlayerIndex = localPlayer ? localPlayer->getPlayerIndex() : 0;+ const Int localPlayerIndex = TheObserverCamera.getShroudPlayerIndex();for( const RadarObject *rObj = listHead; rObj; rObj = rObj->friend_getNext() ){@@ -781,10 +781,7 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text// loop through all objects and drawICoord2D radarPoint;- Player *player = ThePlayerList->getLocalPlayer();- Int playerIndex=0;- if (player)- playerIndex=player->getPlayerIndex();+ const Int playerIndex = TheObserverCamera.getShroudPlayerIndex();if( calcHero ){diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cppindex 025ab3aa9..31e19c232 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp@@ -47,6 +47,7 @@#include "Common/QuickTrig.h"#include "GameClient/Drawable.h"#include "GameClient/FXList.h"+#include "GameClient/ObserverCamera.h"#include "GameClient/PlayerColorScheme.h"#include "GameClient/Shadow.h"#include "GameLogic/GameLogic.h" // for real-time frame@@ -2175,7 +2176,7 @@ static Bool keepsShadowInFog(const Drawable *draw)return FALSE;//fogged keeps it, shrouded does not- const Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ const Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;return obj->getShroudedStatus(localPlayerIndex) < OBJECTSHROUD_SHROUDED;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DPropBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DPropBuffer.cppindex 7de62652d..a6610b95f 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DPropBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DPropBuffer.cpp@@ -54,6 +54,7 @@#include "Common/PerfTimer.h"#include "Common/Player.h"#include "Common/PlayerList.h"+#include "GameClient/ObserverCamera.h"#include "WW3D2/Camera.h"#include "WW3D2/RInfo.h"#include "WW3D2/Light.h"@@ -369,7 +370,7 @@ void W3DPropBuffer::drawProps(RenderInfoClass &rinfo)m_props[i].ss = OBJECTSHROUD_CLEAR;}if (m_props[i].ss == OBJECTSHROUD_INVALID) {- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;m_props[i].ss = ThePartitionManager->getPropShroudStatusForPlayer(localPlayerIndex, &m_props[i].location);}if (m_props[i].ss >= OBJECTSHROUD_SHROUDED) {diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cppindex 8c66c3451..61d43b383 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp@@ -43,6 +43,7 @@#include "GameLogic/Object.h"#include "GameLogic/GameLogic.h"#include "GameClient/Drawable.h"+#include "GameClient/ObserverCamera.h"#include "GameClient/ParticleSys.h"#include "GameClient/Color.h"#include "GameClient/PlayerColorScheme.h"@@ -569,7 +570,7 @@ void RTS3DScene::renderSpecificDrawables(RenderInfoClass &rinfo, Int numDrawable#ifdef DIRTY_CONDITION_FLAGSStDrawableDirtyStuffLocker lockDirtyStuff;#endif- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;RefRenderObjListIterator it(&UpdateList);// loop through all render objects in the list:for (it.First(&RenderList); !it.Is_Done();)@@ -1163,7 +1164,7 @@ void RTS3DScene::Customized_Render( RenderInfoClass &rinfo )Get_Extra_Pass_Polygon_Mode() == EXTRA_PASS_DISABLE)TheW3DVolumetricShadowManager->renderShadowMap(rinfo.Camera);- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;#define USE_LIGHT_ENV 1@@ -1427,7 +1428,7 @@ void RTS3DScene::flushOccludedObjectsIntoStencil(RenderInfoClass & rinfo)//Assume no player colors are visible and all stencil bits are free for use by shadows.TheW3DShadowManager->setStencilShadowMask(0);- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;if (m_numPotentialOccludees && m_numPotentialOccluders){@@ -1619,7 +1620,7 @@ void RTS3DScene::flushOccludedObjects(RenderInfoClass & rinfo)if (m_occludedObjectsCount){- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;if (DX8Wrapper::Has_Stencil()) //just in case we have shadows, disable them over occluded pixels.{@@ -1689,7 +1690,7 @@ void RTS3DScene::flushTranslucentObjects(RenderInfoClass & rinfo)if (m_translucentObjectsCount){- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;for (Int i=0; i<m_translucentObjectsCount; i++){diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cppindex dde05b1c0..9e6a0c51e 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp@@ -73,6 +73,7 @@ enum#include "GameClient/ClientRandomValue.h"#include "GameClient/GameClient.h" // logic-frame gate for the sway phase#include "GameClient/FXList.h"+#include "GameClient/ObserverCamera.h"#include "W3DDevice/GameClient/TerrainTex.h"#include "W3DDevice/GameClient/HeightMap.h"#include "W3DDevice/GameClient/W3DDynamicLight.h"@@ -2503,7 +2504,7 @@ void W3DTreeBuffer::updateTopplingTree(TTree *tree)return;const W3DTreeDrawModuleData* d = m_treeTypes[tree->treeType].m_data;- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;Coord3D pos;pos.set(tree->location.X, tree->location.Y, tree->location.Z);ObjectShroudStatus ss = ThePartitionManager->getPropShroudStatusForPlayer(localPlayerIndex, &pos);diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex a40a65c0f..ab357bd31 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -51,6 +51,7 @@#include "GameClient/Color.h"#include "GameClient/CameraBoundary.h"#include "GameClient/CinemaDirector.h"+#include "GameClient/ObserverCamera.h"#include "GameClient/CommandXlat.h"#include "GameClient/Drawable.h"#include "GameClient/GameClient.h"@@ -648,9 +649,6 @@ void W3DView::stopDoingScriptedCamera( void )//-------------------------------------------------------------------------------------------------void W3DView::setCameraTransform( void ){- if (m_viewLockedUntilFrame > TheGameClient->getFrame())- return;-m_cameraHasMovedSinceRequest = true;Matrix3D cameraTransform( 1 );@@ -1093,7 +1091,7 @@ static void drawablePostDraw( Drawable *draw, void *userData )return;Object* obj = draw->getObject();- Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;+ Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;#if defined(_DEBUG) || defined(_INTERNAL)ObjectShroudStatus ss = (!obj || !TheGlobalData->m_shroudOn) ? OBJECTSHROUD_CLEAR : obj->getShroudedStatus(localPlayerIndex);#else@@ -2756,10 +2754,6 @@ void W3DView::holdZoomAnchor( Bool zoomMoved )return;}- // a locked view builds no camera this frame, so a measurement would read the last frame's again- if (m_viewLockedUntilFrame > TheGameClient->getFrame())- return;-setCameraTransform();Coord3D world;if (!screenToTerrain( &m_zoomAnchorPixel, &world ))diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 36c2b70c9..0471d2664 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -13755,6 +13755,7 @@ TEST(the_spectator_page_names_only_on_off_options)}#include "test_camera_behavior.inc"+#include "test_observer_camera.inc"#include "test_production_input.inc"#include "test_minimap_input.inc"#include "test_selection_priority.inc"diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.incnew file mode 100644index 000000000..90f051151--- /dev/null+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc@@ -0,0 +1,64 @@+// The observer camera's director and its pan, included into test_gameengine.cpp.++#include "GameClient/ObserverCamera.h"++static DirectorHeat directorHit( Real x, Real y )+{+ DirectorHeat hit;+ hit.position.x = x;+ hit.position.y = y;+ hit.weight = 1.0f;+ return hit;+}++TEST(the_director_goes_to_the_crowded_fight_not_the_lone_hit)+{+ std::vector< DirectorHeat > hits;+ for( Int each = 0; each < 5; each++ )+ hits.push_back( directorHit( 1000.0f + each * 20.0f, 1000.0f ) );+ hits.push_back( directorHit( 3000.0f, 3000.0f ) );+ hits.push_back( directorHit( 3010.0f, 3000.0f ) );++ Coord2D place;+ Real heat = 0.0f;+ CHECK( ObserverCamera_hottestPlace( hits, &place, &heat ) );+ CHECK_NEAR( heat, 5.0f, 0.001f );+ CHECK_NEAR( place.x, 1040.0f, 0.001f );+ CHECK_NEAR( place.y, 1000.0f, 0.001f );++ std::vector< DirectorHeat > none;+ CHECK( !ObserverCamera_hottestPlace( none, &place, &heat ) );+}++TEST(the_director_holds_a_live_fight_and_leaves_a_dead_one)+{+ const UnsignedInt longHeld = 10 * LOGICFRAMES_PER_SECOND;+ const UnsignedInt justArrived = LOGICFRAMES_PER_SECOND;+ CHECK( ObserverCamera_shouldMove( 0.0f, 1.0f, justArrived ) );+ CHECK( !ObserverCamera_shouldMove( 0.0f, 0.0f, longHeld ) );+ CHECK( !ObserverCamera_shouldMove( 4.0f, 20.0f, justArrived ) );+ CHECK( !ObserverCamera_shouldMove( 4.0f, 5.0f, longHeld ) );+ CHECK( ObserverCamera_shouldMove( 4.0f, 7.0f, longHeld ) );+}++TEST(the_observer_camera_pans_a_short_way_and_cuts_a_long_one)+{+ ViewLocation from;+ from.init( 1000.0f, 1000.0f, 0.0f, 3.0f, 0.5f, 1.0f );+ // not "near" and "far": windef.h defines both away to nothing+ ViewLocation beside;+ beside.init( 1100.0f, 1000.0f, 0.0f, -3.0f, 0.5f, 1.0f );+ ViewLocation across;+ across.init( 3000.0f, 1000.0f, 0.0f, 3.0f, 0.5f, 1.0f );++ const ViewLocation still = ObserverCamera_approach( from, beside, 0.0f, 0.2f );+ CHECK_NEAR( still.getPosition().x, 1000.0f, 0.001f );++ const ViewLocation step = ObserverCamera_approach( from, beside, 0.1f, 0.2f );+ CHECK( step.getPosition().x > 1000.0f && step.getPosition().x < 1100.0f );+ // 3 to -3 is the short way through the back, not six radians round the front+ CHECK( fabs( step.getAngle() ) > 3.0f );++ const ViewLocation cut = ObserverCamera_approach( from, across, 0.01f, 0.2f );+ CHECK_NEAR( cut.getPosition().x, 3000.0f, 0.001f );+}