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): split observer camera and followed player, fix fog shadows
Olcay Seyganb3187e12f598
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 501fa295b..0dbe1f085 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -484,8 +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, 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. Stealth goes by his eyes too: a Jarmen Kell he has not found is gone from the screen and the radar, and his own stealthed units show the way they show him. 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.+- Watching, the camera can drive itself. Two drop-downs at the top of the board on the right say who has it and which player you follow, and you can follow nobody. 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; with a player picked it keeps to the fights he is in. Player camera shows 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, still following the same player. 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. Stealth goes by his eyes too: a Jarmen Kell he has not found is gone from the screen and the radar, and his own stealthed units show the way they show him. It stays on whoever drives the camera, until you switch it off or follow nobody. Switch to another player and his fog comes in whole, shadows included: a building he has never seen casts nothing on his grey ground. 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.@@ -902,7 +902,9 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- A building stands on the ground instead of sitting on top of it. There is a soft patch under everystructure's footprint, the darkening a corner traps in daylight, and the shadow it casts starts atits own wall rather than a step away from it. The frame's corners and creases get the same- treatment through the finishing passes.+ treatment through the finishing passes. The patch goes with the building's shadow in the fog: an+ enemy base you have never scouted used to leave its dark footprints on grey ground, a map of+ where every building stood.- Infantry shadows are built from the pose: arms, head, weapon, moving with him.- `UseShadowVolumesForSkins = No` puts the old flat blobs back.- Scuds, rockets and falling bombs cast a shadow running along the ground.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex e0a797556..808cbf666 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -1193,6 +1193,21 @@ GUI:HudCameraFree"Free"END+// the camera shows what the followed player's own screen shows+GUI:HudCameraPlayer+"Player camera"+END++// the spectator's second drop-down, "Player: Nova", the player the camera and the fog follow+GUI:HudFollow+"Player"+END++// in that drop-down, following nobody+GUI:HudFollowNobody+"None"+END+// draw the followed player's fog of war, so the spectator sees only what he seesGUI:HudFog"Fog of war"diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.strindex 46212fccd..46fcda4e0 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -15713,6 +15713,18 @@ GUI:HudCameraFree"Serbest"END+GUI:HudCameraPlayer+"Oyuncu kamerası"+END++GUI:HudFollow+"Oyuncu"+END++GUI:HudFollowNobody+"Hiçbiri"+END+GUI:HudFog"Savaş sisi"ENDdiff --git a/GeneralsMD/Code/Data/Window/Html/Spectator.html b/GeneralsMD/Code/Data/Window/Html/Spectator.htmlindex 9016d0a46..1a422cf4e 100644--- a/GeneralsMD/Code/Data/Window/Html/Spectator.html+++ b/GeneralsMD/Code/Data/Window/Html/Spectator.html@@ -50,14 +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 followed+ {{camera}} names who drives the camera (GameClient/ObserverCamera.h), and {{camerafree}}+ {{cameradirector}} {{cameraplayer}} are "on" while it is that one. A data-click of+ camera:free, camera:director or camera:player hands it over and folds up flip:camera+ data-each="follows", every player the camera can follow, grouped by team: {{image}} {{color}}+ {{name}}, {{click}} "follow:N" and {{on}} "on" while he is the one followed. follow:none+ follows nobody and {{follownobody}} is "on" then; each folds up flip:follow. {{follow}}+ {{followcolor}} are the followed player's name and colour, or the nobody label and no colour+ {{fog}} "on" while the fog is drawn for the followed player, flipped with data-click="fog"The 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@@ -271,13 +271,24 @@<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 class="choice {{cameradirector}}" data-click="camera:director"><span class="box"></span>{{text:GUI:HudCameraDirector}}</div>+ <div class="choice {{cameraplayer}}" data-click="camera:player"><span class="box"></span>{{text:GUI:HudCameraPlayer}}</div>+ </div>+ </div>++ <div class="head plate">+ <div class="combo well" data-click="flip:follow">{{text:GUI:HudFollow}}: <span style="color: {{followcolor}}">{{follow}}</span><span class="tab">▼</span></div>+ </div>++ <div class="{{flip:follow}}">+ <div class="choices well">+ <div class="choice {{follownobody}}" data-click="follow:none"><span class="box"></span>{{text:GUI:HudFollowNobody}}</div>+ <div class="choice {{on}}" data-each="follows" data-click="{{click}}"><span class="box"></span><span style="color: {{color}}">{{name}}</span></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="row {{fog}}" data-click="fog"><span class="box"></span>{{text:GUI:HudFog}}</div><div class="head plate"><div class="combo well" data-click="flip:stat">{{stat}}<span class="tab">▼</span></div>diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.hindex 41d506ba1..3dda551c8 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h@@ -19,18 +19,20 @@// 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 mode and the followed player are picked apart, from two lists. 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; with a player picked it+// counts only the fights that player is in. 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), an+// AI, which has no camera, gets the narrowed director, and with nobody picked it does nothing.+// Scrolling, turning the camera or clicking the radar hands it back to the watcher, who keeps the+// player he picked.//-// 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, stealthed units he has not detected included; following nobody it changes nothing. Nothing here is logic: the camera and the fog-// are this machine's picture only.+// The followed player is picked from his own 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, stealthed units he has not detected included; following nobody it changes nothing.+// Nothing here is logic: the camera and the fog are this machine's picture only.///////////////////////////////////////////////////////////////////////////////////////////////////#pragma once@@ -83,9 +85,9 @@ public: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 anybodyvoid setMode( ObserverCameraMode mode );- /// show this player's screen, and his fog while fog is on+ /// the player whose screen the player mode shows, whose fights the director keeps to and whose+ /// fog is drawn while fog is on; NO_PLAYER for nobodyvoid followPlayer( Int playerIndex );/// the player being followed, still while the watcher has the camera in his own hands, or/// NO_PLAYER@@ -103,6 +105,7 @@ private:void updateShroudViewer( void );void holdHeight( Bool hold );Bool takenByHand( const ViewLocation ¤t ) const;+ Bool isShowingPlayerView( void ) const;Bool chooseTarget( const ViewLocation ¤t, ViewLocation *target );Bool directorPlace( const Player *narrowTo, Coord2D *place );diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GhostObject.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GhostObject.hindex fc287176a..bf09ef806 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GhostObject.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GhostObject.h@@ -54,6 +54,8 @@ public:virtual void snapShot(int playerIndex)=0;virtual void updateParentObject(Object *object, PartitionData *mod)=0;virtual void freeSnapShot(int playerIndex)=0;+ /// whether this player's fog shows the snapshot in place of the object+ virtual Bool hasSnapShot(int playerIndex) const=0;inline PartitionData *friend_getPartitionData(void) const {return m_partitionData;}inline GeometryType getGeometryType(void) const {return m_parentGeometryType;}inline Bool getGeometrySmall(void) const {return m_parentGeometryIsSmall;}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cppindex 998b6f7ac..8dc12c077 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp@@ -736,7 +736,7 @@ static void handleCommand( const AsciiString &command )/* 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. */+ follow: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 );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex 4c0f5a6f9..e53826332 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -1039,7 +1039,10 @@ void Drawable::allocateShadows(void)//-------------------------------------------------------------------------------------------------void Drawable::setFullyObscuredByShroud(Bool fullyObscured){- if (m_drawableFullyObscuredByShroud != fullyObscured)+ // passed on every frame while obscured, not only on the change: whether a building's shadow stays+ // in the fog can change under a flag that does not, when its ground goes from fogged to shrouded+ // or its snapshot is taken or freed+ if (m_drawableFullyObscuredByShroud != fullyObscured || fullyObscured){for (DrawModule** dm = getDrawModules(); *dm; ++dm){diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 25ffe74a1..7014012f2 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -1792,12 +1792,17 @@ 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+// data-click="camera:free", "camera:director" or "camera:player" picks who drives the camera+// (ObserverCamera.h) and folds up flip:camera; "follow:N" or "follow:none" picks the player it+// follows and folds up flip:follow; "fog" turns the followed player's fog on and offstatic 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_PLAYER = "player";static const std::string CAMERA_GROUP = "camera";+static const std::string FOLLOW_ACTION = "follow:";+static const std::string FOLLOW_NOBODY = "none";+static const std::string FOLLOW_GROUP = "follow";static const std::string FOG_ACTION = "fog";static const std::string TEXT_LOOKUP = "text:";static const std::string STAT_GROUP = "stat";@@ -2214,10 +2219,9 @@ 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. */+ * following is marked every frame, not at the lists' rebuilds. *///--------------------------------------------------------------------------------------------------static void fillSpectatorCameras( std::vector< SpectatorStats > players, std::vector< HtmlValues > &entries )+static void fillSpectatorFollows( 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; } );@@ -2226,37 +2230,40 @@ static void fillSpectatorCameras( std::vector< SpectatorStats > players, std::vefor( 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() );+ entry[ "click" ] = FOLLOW_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. */+/** What the camera's and the followed player's drop-downs and the fog switch show this frame. *///--------------------------------------------------------------------------------------------------static void fillSpectatorCameraValues( std::vector< HtmlValues > &cameras, HtmlValues &values )+static void fillSpectatorCameraValues( std::vector< HtmlValues > &follows, 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 std::string followedClick = FOLLOW_ACTION + std::to_string( followed );+ for( size_t index = 0; index < follows.size(); index++ )+ follows[ index ][ "on" ] = follows[ index ][ "click" ] == followedClick ? "on" : "";- const char *label = mode == OBSERVER_CAMERA_DIRECTOR ? "GUI:HudCameraDirector" : "GUI:HudCameraFree";+ const char *label = mode == OBSERVER_CAMERA_DIRECTOR ? "GUI:HudCameraDirector"+ : mode == OBSERVER_CAMERA_PLAYER ? "GUI:HudCameraPlayer" : "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[ "cameraplayer" ] = mode == OBSERVER_CAMERA_PLAYER ? "on" : "";+ values[ "camerafree" ] = mode == OBSERVER_CAMERA_FREE ? "on" : "";values[ "fog" ] = TheObserverCamera.isFogOn() ? "on" : "";- values[ "fogname" ] = "";- values[ "fogcolor" ] = "";+ values[ "follownobody" ] = followed == ObserverCamera::NO_PLAYER ? "on" : "";if( followed == ObserverCamera::NO_PLAYER )+ {+ values[ "follow" ] = WideCharStringToMultiByte( TheGameText->fetch( "GUI:HudFollowNobody" ).str() );+ values[ "followcolor" ] = "";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" );+ values[ "follow" ] = head.at( "name" );+ values[ "followcolor" ] = head.at( "color" );}//-------------------------------------------------------------------------------------------------@@ -2544,7 +2551,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" ] );+ fillSpectatorFollows( players, m_spectatorLists[ "follows" ] );fillSpectatorSuperweapons( players, m_spectatorSuperweapons, m_spectatorLists[ "superweapons" ] );fillSpectatorSkills( players, m_spectatorLists[ "skills" ] );@@ -2585,7 +2592,7 @@ void InGameUI::drawSpectatorPage( void )}HtmlValues values = m_spectatorTotals;- fillSpectatorCameraValues( m_spectatorLists[ "cameras" ], values );+ fillSpectatorCameraValues( m_spectatorLists[ "follows" ], 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;@@ -2657,10 +2664,8 @@ void InGameUI::runSpectatorAction( const std::string &action )// what picking him in the old player list didif( TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay ){- if( watched != NULL )- TheObserverCamera.followPlayer( watched->getPlayerIndex() );- else- TheObserverCamera.setMode( OBSERVER_CAMERA_FREE );+ TheObserverCamera.followPlayer( watched != NULL ? watched->getPlayerIndex() : ObserverCamera::NO_PLAYER );+ TheObserverCamera.setMode( watched != NULL ? OBSERVER_CAMERA_PLAYER : OBSERVER_CAMERA_FREE );}}else if( action.compare( 0, CAMERA_ACTION.size(), CAMERA_ACTION ) == 0 )@@ -2669,16 +2674,22 @@ void InGameUI::runSpectatorAction( const std::string &action )m_spectatorFlipped.erase( CAMERA_GROUP );if( choice == CAMERA_DIRECTOR )TheObserverCamera.setMode( OBSERVER_CAMERA_DIRECTOR );+ else if( choice == CAMERA_PLAYER )+ TheObserverCamera.setMode( OBSERVER_CAMERA_PLAYER );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() );- }+ DEBUG_LOG(( "Spectator page: data-click=\"%s\" names no camera\n", action.c_str() ));+ }+ else if( action.compare( 0, FOLLOW_ACTION.size(), FOLLOW_ACTION ) == 0 )+ {+ // following a player is watching him too: his seat lit, his side on the bar+ const std::string choice = action.substr( FOLLOW_ACTION.size() );+ Player *player = choice == FOLLOW_NOBODY ? NULL : ThePlayerList->getNthPlayer( atoi( choice.c_str() ) );+ m_spectatorFlipped.erase( FOLLOW_GROUP );+ deselectAllDrawables();+ TheControlBar->watchPlayer( player );+ TheObserverCamera.followPlayer( player != NULL ? player->getPlayerIndex() : ObserverCamera::NO_PLAYER );}else if( action == FOG_ACTION )TheObserverCamera.setFog( !TheObserverCamera.isFogOn() );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cppindex f9be20c77..03bdabb56 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp@@ -188,7 +188,6 @@ void ObserverCamera::notePlayerView( Int playerIndex, const ViewLocation &view )void ObserverCamera::setMode( ObserverCameraMode mode ){m_mode = mode;- m_followed = NO_PLAYER;m_driving = FALSE;m_placeValid = FALSE;}@@ -196,7 +195,6 @@ void ObserverCamera::setMode( ObserverCameraMode mode )//-------------------------------------------------------------------------------------------------void ObserverCamera::followPlayer( Int playerIndex ){- m_mode = OBSERVER_CAMERA_PLAYER;m_followed = playerIndex;m_driving = FALSE;m_placeValid = FALSE;@@ -212,12 +210,11 @@ Int ObserverCamera::getShroudPlayerIndex( void ) const/** 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.+ * starts keeping everybody's the first time he asks for somebody else's; what the new viewer saw+ * before that has no snapshot and is not drawn in his fog, shadow included.*- * 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. */+ * The frame each drawable was last seen clear belongs to the old viewer and is cleared, or a unit+ * he saw stays drawn two seconds into the new viewer's fog. *///-------------------------------------------------------------------------------------------------void ObserverCamera::updateShroudViewer( void ){@@ -230,10 +227,7 @@ void ObserverCamera::updateShroudViewer( void )TheGhostObjectManager->setLocalPlayerIndex( getShroudPlayerIndex() );ThePartitionManager->refreshShroudForLocalPlayer();for( Drawable *draw = TheGameClient->firstDrawable(); draw != NULL; draw = draw->getNextDrawable() )- {- draw->setFullyObscuredByShroud( FALSE );draw->setShroudClearFrame( 0 );- }}//-------------------------------------------------------------------------------------------------@@ -335,27 +329,31 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )return m_placeValid;}+//-------------------------------------------------------------------------------------------------+Bool ObserverCamera::isShowingPlayerView( void ) const+{+ return m_mode == OBSERVER_CAMERA_PLAYER && m_followed != NO_PLAYER && m_playerViews[ m_followed ].isValid();+}++//-------------------------------------------------------------------------------------------------+/** The director with a player picked keeps to his fights; a player's camera with nobody picked has+ * nothing to show and leaves the camera where it is. *///-------------------------------------------------------------------------------------------------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;- }+ if( m_mode == OBSERVER_CAMERA_PLAYER && m_followed == NO_PLAYER )+ return FALSE;- const ViewLocation &view = m_playerViews[ m_followed ];- if( view.isValid() )+ if( isShowingPlayerView() ){- *target = view;+ *target = m_playerViews[ m_followed ];return TRUE;}- if( !directorPlace( ThePlayerList->getNthPlayer( m_followed ), &place ) )+ const Player *narrowTo = m_followed == NO_PLAYER ? NULL : ThePlayerList->getNthPlayer( m_followed );+ const Coord3D &at = current.getPosition();+ Coord2D place;+ if( !directorPlace( narrowTo, &place ) )return FALSE;target->init( place.x, place.y, at.z, current.getAngle(), current.getPitch(), current.getZoom() );return TRUE;@@ -396,7 +394,7 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )return;}- holdHeight( m_mode == OBSERVER_CAMERA_PLAYER && m_playerViews[ m_followed ].isValid() );+ holdHeight( isShowingPlayerView() );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 );diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.hindex aede91852..f559817ee 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h@@ -357,6 +357,7 @@ public:virtual void releaseShadows(void); ///< frees all shadow resources used by this module - used by Options screen.virtual void allocateShadows(void); ///< create shadow resources if not already present. Used by Options screen.void allocateContactShadow(void); ///< the soft patch under a structure, which is what stands it on the ground+ Bool isShadowHiddenByShroud(void) const; ///< obscured, and not something that keeps its shadow in fogBool registerModelShadow(void); ///< hand this model's shape to the tree buffer to cast; TRUE if it took itvoid unregisterModelShadow(void); ///< take it back when the model changes or the drawable goesdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameLogic/W3DGhostObject.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameLogic/W3DGhostObject.hindex 3d18e7d69..eacbbfd77 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameLogic/W3DGhostObject.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameLogic/W3DGhostObject.h@@ -51,6 +51,7 @@ public:virtual void snapShot(int playerIndex);virtual void updateParentObject(Object *object, PartitionData *mod);virtual void freeSnapShot(int playerIndex);+ virtual Bool hasSnapShot(int playerIndex) const { return m_parentSnapshots[playerIndex] != NULL; }protected:virtual void crc( Xfer *xfer);virtual void xfer( Xfer *xfer );diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cppindex 31e19c232..9d2485d54 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp@@ -51,6 +51,8 @@#include "GameClient/PlayerColorScheme.h"#include "GameClient/Shadow.h"#include "GameLogic/GameLogic.h" // for real-time frame+#include "GameLogic/GhostObject.h"+#include "GameLogic/PartitionManager.h"#include "Common/Player.h"#include "Common/PlayerList.h"#include "GameLogic/Object.h"@@ -2032,7 +2034,7 @@ void W3DModelDraw::allocateShadows(void)}if (m_shadow)- { m_shadow->enableShadowInvisible(m_fullyObscuredByShroud);+ { m_shadow->enableShadowInvisible(isShadowHiddenByShroud());if (m_renderObject->Is_Hidden() || !m_shadowEnabled)m_shadow->enableShadowRender(FALSE);}@@ -2085,7 +2087,7 @@ void W3DModelDraw::allocateContactShadow(void)if (m_contactShadow){m_contactShadow->setOpacity( CONTACT_SHADOW_OPACITY );- m_contactShadow->enableShadowInvisible( m_fullyObscuredByShroud );+ m_contactShadow->enableShadowInvisible( isShadowHiddenByShroud() );if (m_renderObject->Is_Hidden() || !m_shadowEnabled)m_contactShadow->enableShadowRender( FALSE );}@@ -2161,8 +2163,10 @@ void W3DModelDraw::getRenderCostRecursive(RenderCost & rc,RenderObjClass * robj)Anything that moves does not, and this is not a detail: a shadow crawling across fogged groundis the position of a unit you are not allowed to see.- Never-seen ground is not fog and gets nothing - the check below asks for the real shroud status- rather than trusting the obscured flag, which cannot tell the two apart. */+ What decides it is whether the snapshot is standing there for whoever's fog is drawn, not the+ shroud status. Never-seen ground has no snapshot, and neither has a building an observer's+ newly picked player saw before his fog was being remembered: there the building is not drawn,+ and a kept shadow was a building-shaped hole in the light on empty ground. */static Bool keepsShadowInFog(const Drawable *draw){if (draw == NULL)@@ -2175,22 +2179,36 @@ static Bool keepsShadowInFog(const Drawable *draw)if (!obj->isKindOf(KINDOF_IMMOBILE) || obj->isKindOf(KINDOF_PROJECTILE))return FALSE;- //fogged keeps it, shrouded does not- const Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;- return obj->getShroudedStatus(localPlayerIndex) < OBJECTSHROUD_SHROUDED;+ const PartitionData *partition = obj->friend_getPartitionData();+ if (partition == NULL || partition->getGhostObject() == NULL)+ return FALSE;++ const Int viewerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;+ return partition->getGhostObject()->hasSnapShot(viewerIndex);+}++//-------------------------------------------------------------------------------------------------+Bool W3DModelDraw::isShadowHiddenByShroud(void) const+{+ return m_fullyObscuredByShroud && !keepsShadowInFog(getDrawable());}//-------------------------------------------------------------------------------------------------void W3DModelDraw::setFullyObscuredByShroud(Bool fullyObscured){- if (m_fullyObscuredByShroud != fullyObscured)- {- m_fullyObscuredByShroud = fullyObscured;+ const Bool changed = m_fullyObscuredByShroud != fullyObscured;+ m_fullyObscuredByShroud = fullyObscured;- const Bool hideShadow = m_fullyObscuredByShroud && !keepsShadowInFog(getDrawable());+ const Bool hideShadow = isShadowHiddenByShroud();+ if (m_shadow)+ m_shadow->enableShadowInvisible(hideShadow);+ //the patch under a building used to keep the value it was made with, so a building the+ //fog's owner has never seen still darkened the ground where it stands+ if (m_contactShadow)+ m_contactShadow->enableShadowInvisible(hideShadow);- if (m_shadow)- m_shadow->enableShadowInvisible(hideShadow);+ if (changed)+ {//the terrain decal is a marker, not a shadow: it goes with the thing it marksif (m_terrainDecal)m_terrainDecal->enableShadowInvisible(m_fullyObscuredByShroud);@@ -3337,7 +3355,7 @@ void W3DModelDraw::setModelState(const ModelConditionInfo* newState)}if (m_shadow)- { m_shadow->enableShadowInvisible(m_fullyObscuredByShroud);+ { m_shadow->enableShadowInvisible(isShadowHiddenByShroud());m_shadow->enableShadowRender(m_shadowEnabled);}}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cppindex ba2482cfd..09fe88275 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp@@ -317,14 +317,10 @@ W3DGhostObject::W3DGhostObject()// ------------------------------------------------------------------------------------------------W3DGhostObject::~W3DGhostObject(){-#ifdef DEBUG_FOG_MEMORYfor (Int i=0; i<MAX_PLAYER_COUNT; i++){DEBUG_ASSERTCRASH(m_parentSnapshots[i] == NULL, ("Delete of non-empty GhostObject"));}-#else- DEBUG_ASSERTCRASH(m_parentSnapshots[TheGhostObjectManager->getLocalPlayerIndex()] == NULL, ("Delete of non-empty GhostObject"));-#endif}// ------------------------------------------------------------------------------------------------@@ -334,10 +330,10 @@ Should only be called when object enters the fogged state.*/// ------------------------------------------------------------------------------------------------void W3DGhostObject::snapShot(int playerIndex){-#ifndef DEBUG_FOG_MEMORY- if (playerIndex != TheGhostObjectManager->getLocalPlayerIndex())- return; //we only snapshot things for the initial local player because local player can't change in non-debug game.-#endif+ //every player's memory is kept only where the fog can be handed to somebody else, an observer's+ //machine; without it a building the new viewer saw lost its snapshot and left its shadow behind+ if (playerIndex != TheGhostObjectManager->getLocalPlayerIndex() && !TheGhostObjectManager->trackAllPlayers())+ return;Drawable *draw=m_parentObject->getDrawable();if (draw->isDrawableEffectivelyHidden())@@ -448,6 +444,11 @@ void W3DGhostObject::restoreParentObject(void)//Notify drawable that it's okay to render its render objects again.draw->setFullyObscuredByShroud(false);+ // a headless run keeps every player's snapshots for an observer too, and has no scene to put+ // the object back into - see W3DRenderObjectSnapshot::addToScene+ if (W3DDisplay::m_3DScene == NULL)+ return;+//walk through all W3D render objects used by this objectfor (DrawModule ** dm = draw->getDrawModules(); *dm; ++dm){@@ -476,31 +477,8 @@ void W3DGhostObject::restoreParentObject(void)// ------------------------------------------------------------------------------------------------void W3DGhostObject::freeAllSnapShots(void){- Int playerIndex;--#ifdef DEBUG_FOG_MEMORY- for (playerIndex=0; playerIndex<MAX_PLAYER_COUNT; playerIndex++)-#else- playerIndex = TheGhostObjectManager->getLocalPlayerIndex();-#endif- if (m_parentSnapshots[playerIndex])- { //if we have a snapshot for this object, remove it from- //scene.- removeFromScene(playerIndex);-- //Restore actual objects assuming they are still alive.- if (m_parentObject)- restoreParentObject();-- W3DRenderObjectSnapshot *snap=m_parentSnapshots[playerIndex];- W3DRenderObjectSnapshot *nextSnap;- while (snap)- { nextSnap = snap->m_next;- delete snap;- snap = nextSnap;- }- m_parentSnapshots[playerIndex]=NULL;- }+ for (Int playerIndex=0; playerIndex<MAX_PLAYER_COUNT; playerIndex++)+ freeSnapShot(playerIndex);}// ------------------------------------------------------------------------------------------------@@ -508,11 +486,6 @@ void W3DGhostObject::freeAllSnapShots(void)// ------------------------------------------------------------------------------------------------void W3DGhostObject::freeSnapShot(int playerIndex){-#ifndef DEBUG_FOG_MEMORY- if (playerIndex != TheGhostObjectManager->getLocalPlayerIndex())- return; //we only snapshot things for the local player-#endif-if (m_parentSnapshots[playerIndex]){ //if we have a snapshot for this object, remove it from//scene and put back the original object if it still exists.@@ -1059,15 +1032,13 @@ void W3DGhostObjectManager::updateOrphanedObjects(int *playerIndexList, int numNif (!mod->m_parentObject){numStoredSnapshots=0;-#ifdef DEBUG_FOG_MEMORY- for (int i=0; i<numNonLocalPlayers; i++, playerIndexList++)+ for (int i=0; i<numNonLocalPlayers; i++){- if (mod->m_parentSnapshots[*playerIndexList])- mod->getShroudStatus(*playerIndexList);- if (mod->m_parentSnapshots[*playerIndexList])+ if (mod->m_parentSnapshots[playerIndexList[i]])+ mod->getShroudStatus(playerIndexList[i]);+ if (mod->m_parentSnapshots[playerIndexList[i]])numStoredSnapshots++;}-#endifmod->getShroudStatus(m_localPlayer);if (mod->m_parentSnapshots[m_localPlayer])numStoredSnapshots++;