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): animated 45 degree panes and player intro for director record
Olcay Seygan2a32097ae6ac
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e8d2c67a8..99e9e84e4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -748,7 +748,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- 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. Two drop-downs in the camera panel on the right, above the board, say who has it and which player you follow, and you can follow nobody. The Director goes to the fight with the most on the line over the last five seconds, where a dead Overlord counts for more than six riflemen being shot at and anything happening to a superweapon counts three times over. It stays with that fight twelve seconds, leaves after six only for one four times the size, and after half a minute on the same fight a third bigger is enough. So a 4v4 is watched like a broadcast rather than hunted for, and it does not hop between spots every few seconds. Any general's power used on the map outranks every fight. A nuke is shown in its silo as it leaves, then the camera waits at the target for it to come down and stays through the blast. The particle cannon's beam is followed along its whole sweep, and a Scud Storm or a carpet bomb is watched until the last explosion has died down. Then it goes back to the fighting. The camera glides between places and slows into each one, and only cuts when the next one is across most of the map. When nobody is shooting it no longer parks on empty ground: it goes round what is worth seeing, an army on the march, a superweapon, a base going up, the rest of a base, the dearest first and fourteen seconds each, and does not come back to one of the last three while there is anything else to show. With a player picked it keeps to his fights and his own armies and buildings. 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 with the keys or a drag, turn the view or click the radar and the camera is yours again, still following the same player. The edge of the screen does not scroll while it drives: the panel on the right stands on that edge, and reaching for it used to hand the camera back to you, so the Director stopped following the fighting the first time you went to change a setting. In a replay with the recorded camera switched on in the options, the player you follow still drives the camera the way his button in the old list did.- Watching, the Director climbs over a wide battle until the whole of it is on the screen, and comes back down to your own height when it moves on or you take the camera. The mouse wheel still zooms while it drives, and it keeps what you chose. It stops short of the map's border too, where a fight on the edge used to come with a black corner of nothing beside it. A nuke or a Scud Storm is shown leaving its silo even when the Director has only just arrived at another fight; before, the launch was over by the time it was allowed to move. Rewinding a replay leaves your camera settings as they were, where a rewind used to hand you back a free camera with nobody followed. And following one player while a superweapon wiped out everything he had at the spot could close the game. It no longer does.-- Watching can be filmed. Start the game with `-directorrecord` and the Director has the camera from the first second, with nothing over the picture but the radar, and the whole match goes into one video; the game closes itself when the match is decided or the replay runs out. Beside `-replay` it turns an old match into footage, and beside four computer players it films a match nobody played. When two real fights far apart are both worth watching, the picture splits along a line leaning a little off upright, one fight on each side with its own camera gliding to it, and the radar moves to the middle of the line. A split holds at least six seconds and ends once the second fight has burnt down to a quarter of the first, so the picture does not flicker between one and two. Only the video shows the split; the window keeps the Director's own fight. Two bases going up are not a fight, and the split ends the moment the camera's own fight and the second one turn out to be the same. The pictures go straight into ffmpeg as they are drawn, so an hour of 1080p does not need tens of gigabytes of disk first; put ffmpeg beside the game or on your PATH, because without it nothing is recorded and the game says so and closes. Any recorded clip also plays its animations at their real speed now. The animation clock used to move by however long each picture took to save, and a slow disk made every explosion in the footage run fast.+- Watching can be filmed. Start the game with `-directorrecord` and the Director has the camera from the first second, with nothing over the picture but the radar, and the whole match goes into one video; the game closes itself when the match is decided or the replay runs out. Beside `-replay` it turns an old match into footage, and beside four computer players it films a match nobody played. The film opens on every player at once: the screen cut into one picture per player along lines at 45 degrees that meet round the radar, two players on a diagonal and four on an X, each picture on that player's base. Seven seconds in they sweep away to the Director's single view. When two real fights far apart are both worth watching, the radar slides out of its corner, then the second fight sweeps in from the corner along a 45 degree diagonal, carrying the radar in a frame of the same line to the middle, one fight on each side with its own camera gliding to it. Going back is the same film run backwards: the second fight sweeps out with the radar, and the radar slides back into its corner. A split holds at least six seconds and ends once the second fight has burnt down to a quarter of the first, so the picture does not flicker between one and two. Only the video shows the other pictures; the window keeps the Director's own fight under the lines. Two bases going up are not a fight, and the split ends the moment the camera's own fight and the second one turn out to be the same. The pictures go straight into ffmpeg as they are drawn, so an hour of 1080p does not need tens of gigabytes of disk first; put ffmpeg beside the game or on your PATH, because without it nothing is recorded and the game says so and closes. Any recorded clip also plays its animations at their real speed now. The animation clock used to move by however long each picture took to save, and a slow disk made every explosion in the footage run fast.- 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.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.hindex cd7cbd8f1..555473258 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h@@ -137,9 +137,26 @@ Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const/// its own and next to a first one; off once it has been held a while and the second fight has burnt/// down, and at once when the second fight is over or the two places come togetherBool ObserverCamera_holdSplit( Bool split, Real firstHeat, Real secondHeat, Real apart, UnsignedInt framesSince );-/// the column the split's divider crosses row y of a width by height picture at: through the middle,-/// leaning 12 degrees with its top to the right. Columns left of it are the first fight's-Int ObserverCamera_splitBoundary( Int y, Int width, Int height );++/// -directorrecord's panes. The picture is cut by rays from one point, every ray a multiple of 45+/// degrees, and pane i is the wedge from ray i counterclockwise to ray i + 1. Angles are degrees,+/// 0 to the right and 90 up the screen+enum { OBSERVER_MOST_PANES = 8 };+/// the rays for count panes, ascending from 0 to 360; the number of rays, which is count, or 0 for+/// fewer than two panes. Pane 0 is the one the radar belongs to and the one left when the panes go+Int ObserverCamera_paneLayout( Int count, Real *rays );+/// the pane pixel x, y falls in, the rays meeting at origin x, y (pixels, y down)+Int ObserverCamera_paneOf( Real x, Real y, Real originX, Real originY, const Real *rays, Int count );+/// how far the rays' meeting point has to move, away from pane 0, before pane 0 is the whole of a+/// width by height picture: the panes come in from there and go back out to it+Real ObserverCamera_paneExit( const Real *rays, Int count, Int width, Int height );+/// the direction, in pixels with y down, that meeting point moves in to take the other panes away+Coord2D ObserverCamera_paneExitDirection( const Real *rays );+/// the middle of each pane with the rays meeting in the middle of the picture, where its subject is+/// put; middles has count entries+void ObserverCamera_paneMiddles( const Real *rays, Int count, Int width, Int height, Coord2D *middles );+/// how far an animation of length frames that started on start is on frame, eased in and out, 0 to 1+Real ObserverCamera_easeFrames( UnsignedInt frame, UnsignedInt start, UnsignedInt length );class ObserverCamera{@@ -179,13 +196,31 @@ public:/// the watcher's own height back on the view, if the director had raised it over a fightvoid releaseHeight( void );- /// -directorrecord: two fights far apart are recorded side by side. The frame is drawn twice, the- /// second fight first and never presented, then the first; the recording joins the two halves+ /// -directorrecord's panes: the players' bases for the first seconds of a match, then two fights+ /// far apart side by side. Each pane past the first is drawn first, for the recording only and+ /// never presented, then the frame everybody sees; the recording joins them along the raysBool isSplit( void ) const { return m_split; }- Bool isDrawingSecond( void ) const { return m_drawingSecond; }- /// the view moved to the second fight for one draw, and put back after it- void beginSecondPass( void );- void endSecondPass( void );+ /// how many panes the next frame is drawn in, 1 when the picture is whole+ Int getDrawnPaneCount( void ) const { return m_paneProgress > 0.0f ? m_paneCount : 1; }+ const Real *getPaneRays( void ) const { return m_paneRays; }+ /// where the rays meet on the screen, in pixels, which slides in from off the screen and back out+ Coord2D getPaneOrigin( void ) const { return m_paneOrigin; }+ /// how far a pane's picture past the first is moved with the meeting point, in pixels+ Coord2D getPaneShift( void ) const;+ /// how far the radar in the bottom left corner is slid out to the left, 0 to 1+ Real getCornerRadarSlide( void ) const { return m_cornerRadarSlide; }+ /// the radar framed on the rays' meeting point, pane 0's, while there are panes; its middle comes+ /// with the meeting point and goes off the screen with it+ Bool isRadarFramed( void ) const { return m_paneCount >= 2 && m_paneProgress > 0.0f; }+ Coord2D getFramedRadarMiddle( Real radarDiagonal ) const;+ /// the framed radar's rectangle as it was drawn, frame included: the recording takes it from pane 0+ void setRadarFrame( const IRegion2D &frame ) { m_radarFrame = frame; }+ const IRegion2D &getRadarFrame( void ) const { return m_radarFrame; }+ Bool isDrawingSecond( void ) const { return m_drawingPane != 0; }+ Int getDrawingPane( void ) const { return m_drawingPane; }+ /// the view moved to a pane's camera for one draw, and put back after it+ void beginPanePass( Int pane );+ void endPanePass( void );enum { NO_PLAYER = -1 };@@ -195,8 +230,11 @@ private:void driveHeight( Real extra );Bool takenByHand( const ViewLocation ¤t ) const;Coord2D keepInMap( const Coord2D &place, const ViewLocation ¤t ) const;- Coord2D screenQuarter( const ViewLocation ¤t ) const;+ Coord2D screenToGround( const ViewLocation ¤t, const Coord2D &pixels ) const;void updateSplit( void );+ void updateIntroPlaces( void );+ void advancePanes( UnsignedInt frame );+ void stepPaneCameras( const ViewLocation &step, Real elapsedSeconds );Bool isShowingPlayerView( void ) const;Bool chooseTarget( const ViewLocation ¤t, ViewLocation *target );Bool directorPlace( const Player *narrowTo, Coord2D *place );@@ -233,14 +271,30 @@ private:UnsignedInt m_nextEventId;std::vector< DirectorHeat > m_fights; ///< the last scan's hits one player dealt another he is at war with; the split counts only these- Bool m_split; ///< -directorrecord's picture is two fights side by side- Bool m_splitCut; ///< the split just went on: the camera cuts to its place in the left half+ Bool m_split; ///< -directorrecord wants two fights side by sideUnsignedInt m_splitChanged; ///< the logic frame the split last went on or off- Coord2D m_secondPlace; ///< the second fight, shown in the right half- ViewLocation m_secondView; ///< the right half's camera, gliding on its own- ObserverCameraVelocity m_secondVelocity;- ViewLocation m_firstView; ///< the camera's own place, put back after the right half is drawn- Bool m_drawingSecond;+ Coord2D m_secondPlace; ///< the second fight, shown in the second pane++ enum PanePhase { PANES_NONE, PANES_RADAR_OUT, PANES_IN, PANES_HELD, PANES_OUT, PANES_RADAR_IN };+ PanePhase m_panePhase;+ UnsignedInt m_panePhaseStart; ///< the logic frame the phase began on+ Bool m_intro; ///< the panes are the match's opening, one a player+ Bool m_introDone;+ Int m_paneCount; ///< 0 with no panes+ Real m_paneRays[ OBSERVER_MOST_PANES ];+ Real m_paneProgress; ///< 0 for no panes on the screen, 1 for all of them, eased+ Real m_paneExit; ///< how far off the meeting point goes, in pixels+ Coord2D m_paneOrigin; ///< where the rays meet now, in pixels+ Real m_cornerRadarSlide;+ IRegion2D m_radarFrame;+ const Player *m_panePlayers[ OBSERVER_MOST_PANES ]; ///< the intro's player for each pane+ Coord2D m_paneSubject[ OBSERVER_MOST_PANES ]; ///< what each pane past the first looks at+ ViewLocation m_paneGlide[ OBSERVER_MOST_PANES ]; ///< where each pane's subject glide has got to+ ObserverCameraVelocity m_paneVelocity[ OBSERVER_MOST_PANES ];+ ViewLocation m_paneView[ OBSERVER_MOST_PANES ]; ///< each pane's camera for its draw+ Coord2D m_mainOffset; ///< how far the camera's look point sat from its subject last frame, on the ground+ ViewLocation m_firstView; ///< the camera's own place, put back after a pane is drawn+ Int m_drawingPane;};extern ObserverCamera TheObserverCamera;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cppindex d361d553d..4ff378a12 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp@@ -934,14 +934,14 @@ void GameClient::update( void )Int64 drawStart, drawEnd;drawStart = Clock_Ticks();#endif- /* -directorrecord with two fights on: the second fight is drawn first, for the recording- only and never presented, then the frame everybody sees. W3D's clock stands still for- a second draw on one client frame, so nothing animates twice. */- if( TheObserverCamera.isSplit() )+ /* -directorrecord's panes: every pane past the first is drawn first, for the recording only+ and never presented, then the frame everybody sees. W3D's clock stands still for every+ draw after the first on one client frame, so nothing animates twice. */+ for( Int pane = 1; pane < TheObserverCamera.getDrawnPaneCount(); pane++ ){- TheObserverCamera.beginSecondPass();+ TheObserverCamera.beginPanePass( pane );TheDisplay->DRAW();- TheObserverCamera.endSecondPass();+ TheObserverCamera.endPanePass();}TheDisplay->DRAW();#ifdef DEBUG_LOGGINGdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cppindex 0496650af..342165d05 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp@@ -26,6 +26,7 @@#include "Common/Player.h"#include "Common/PlayerList.h"#include "Common/ThingTemplate.h"+#include "GameClient/Display.h"#include "GameClient/Drawable.h"#include "GameClient/GameClient.h"#include "GameClient/LookAtXlat.h"@@ -117,8 +118,15 @@ static const UnsignedInt SPLIT_HOLD_FRAMES = 6 * LOGICFRAMES_PER_SECOND;static const Real SPLIT_STAY_SHARE = 0.25f;/// once the picture is whole again it stays whole this long, so it does not flicker between the twostatic const UnsignedInt SPLIT_REST_FRAMES = 4 * LOGICFRAMES_PER_SECOND;-/// how far the divider leans off the upright-static const Real SPLIT_LEAN_DEGREES = 12.0f;+/// the corner radar takes this long to slide out to the left before the panes come, and back after+static const UnsignedInt PANE_RADAR_FRAMES = 12;+/// the panes take this long to slide in along the rays, and out again+static const UnsignedInt PANE_SLIDE_FRAMES = 15;+/// the match opens on every player's base, one pane each, for this long+static const UnsignedInt PANE_INTRO_FRAMES = 7 * LOGICFRAMES_PER_SECOND;+/// a pane's middle is measured on a grid this coarse, which is plenty for where to put a subject+static const Int PANE_MIDDLE_COLUMNS = 64;+static const Int PANE_MIDDLE_ROWS = 36;//-------------------------------------------------------------------------------------------------static Bool sameFight( const Coord2D &a, const Coord2D &b )@@ -403,10 +411,117 @@ Bool ObserverCamera_holdSplit( Bool split, Real firstHeat, Real secondHeat, Real}//--------------------------------------------------------------------------------------------------Int ObserverCamera_splitBoundary( Int y, Int width, Int height )+/** Two panes are one diagonal, its upper left half the radar's; four are an X. The others add rays to+ * the X, the bottom first: three is a Y, the top wedge and two halves below; five is the X with the+ * bottom wedge halved; six halves the top wedge as well; seven adds the right half of the level+ * line, and eight is every 45 degrees. */+//-------------------------------------------------------------------------------------------------+Int ObserverCamera_paneLayout( Int count, Real *rays )+{+ static const Real two[] = { 45, 225 };+ static const Real three[] = { 45, 135, 270 };+ static const Real four[] = { 45, 135, 225, 315 };+ static const Real five[] = { 45, 135, 225, 270, 315 };+ static const Real six[] = { 45, 90, 135, 225, 270, 315 };+ static const Real seven[] = { 0, 45, 90, 135, 225, 270, 315 };+ static const Real eight[] = { 0, 45, 90, 135, 180, 225, 270, 315 };+ static const Real *layouts[] = { two, three, four, five, six, seven, eight };+ if( count < 2 )+ return 0;+ count = min( count, (Int)OBSERVER_MOST_PANES );+ for( Int ray = 0; ray < count; ray++ )+ rays[ ray ] = layouts[ count - 2 ][ ray ];+ return count;+}++//-------------------------------------------------------------------------------------------------+Int ObserverCamera_paneOf( Real x, Real y, Real originX, Real originY, const Real *rays, Int count )+{+ Real angle = atan2f( originY - y, x - originX ) * 180.0f / PI;+ if( angle < 0.0f )+ angle += 360.0f;+ // below the first ray is the far side of the last pane, which wraps round through 0+ Int pane = count - 1;+ for( Int ray = 0; ray < count; ray++ )+ {+ if( angle >= rays[ ray ] )+ pane = ray;+ }+ return pane;+}++//-------------------------------------------------------------------------------------------------+Coord2D ObserverCamera_paneExitDirection( const Real *rays )+{+ const Real away = ( ( rays[ 0 ] + rays[ 1 ] ) * 0.5f + 180.0f ) * PI / 180.0f;+ Coord2D direction;+ direction.x = cosf( away );+ direction.y = -sinf( away );+ return direction;+}++//-------------------------------------------------------------------------------------------------+/** Pane 0 is a wedge of 180 degrees or less, so it holds the whole picture once it holds the four+ * corners. */+//-------------------------------------------------------------------------------------------------+Real ObserverCamera_paneExit( const Real *rays, Int count, Int width, Int height )+{+ const Coord2D direction = ObserverCamera_paneExitDirection( rays );+ const Real cornerX[ 4 ] = { 0.5f, width - 0.5f, 0.5f, width - 0.5f };+ const Real cornerY[ 4 ] = { 0.5f, 0.5f, height - 0.5f, height - 0.5f };+ Real inside = 2.0f * ( width + height );+ Real outside = 0.0f;+ for( Int step = 0; step < 32; step++ )+ {+ const Real tried = ( inside + outside ) * 0.5f;+ const Real originX = width * 0.5f + direction.x * tried;+ const Real originY = height * 0.5f + direction.y * tried;+ Bool whole = TRUE;+ for( Int corner = 0; corner < 4 && whole; corner++ )+ whole = ObserverCamera_paneOf( cornerX[ corner ], cornerY[ corner ], originX, originY, rays, count ) == 0;+ if( whole )+ inside = tried;+ else+ outside = tried;+ }+ return inside;+}++//-------------------------------------------------------------------------------------------------+void ObserverCamera_paneMiddles( const Real *rays, Int count, Int width, Int height, Coord2D *middles )+{+ Int samples[ OBSERVER_MOST_PANES ];+ for( Int pane = 0; pane < count; pane++ )+ {+ samples[ pane ] = 0;+ middles[ pane ].x = middles[ pane ].y = 0.0f;+ }+ for( Int row = 0; row < PANE_MIDDLE_ROWS; row++ )+ {+ for( Int column = 0; column < PANE_MIDDLE_COLUMNS; column++ )+ {+ const Real x = ( column + 0.5f ) * width / PANE_MIDDLE_COLUMNS;+ const Real y = ( row + 0.5f ) * height / PANE_MIDDLE_ROWS;+ const Int pane = ObserverCamera_paneOf( x, y, width * 0.5f, height * 0.5f, rays, count );+ middles[ pane ].x += x;+ middles[ pane ].y += y;+ samples[ pane ]++;+ }+ }+ for( Int pane = 0; pane < count; pane++ )+ {+ middles[ pane ].x /= samples[ pane ];+ middles[ pane ].y /= samples[ pane ];+ }+}++//-------------------------------------------------------------------------------------------------+Real ObserverCamera_easeFrames( UnsignedInt frame, UnsignedInt start, UnsignedInt length ){- const Real lean = tanf( SPLIT_LEAN_DEGREES * PI / 180.0f );- return (Int)floorf( width * 0.5f + ( height * 0.5f - y ) * lean + 0.5f );+ if( frame <= start )+ return 0.0f;+ const Real t = min( (Real)( frame - start ) / length, 1.0f );+ return t * t * ( 3.0f - 2.0f * t );}//-------------------------------------------------------------------------------------------------@@ -445,13 +560,31 @@ void ObserverCamera::reset( void )m_nextEventId = 1;m_fights.clear();m_split = FALSE;- m_splitCut = FALSE;m_splitChanged = 0;m_secondPlace.x = m_secondPlace.y = 0.0f;- m_secondView = ViewLocation();- m_secondVelocity.x = m_secondVelocity.y = m_secondVelocity.z = m_secondVelocity.angle = m_secondVelocity.pitch = m_secondVelocity.zoom = 0.0f;+ m_panePhase = PANES_NONE;+ m_panePhaseStart = 0;+ m_intro = FALSE;+ m_introDone = FALSE;+ m_paneCount = 0;+ m_paneProgress = 0.0f;+ m_paneExit = 0.0f;+ m_paneOrigin.x = m_paneOrigin.y = 0.0f;+ m_cornerRadarSlide = 0.0f;+ m_radarFrame.lo.x = m_radarFrame.lo.y = m_radarFrame.hi.x = m_radarFrame.hi.y = 0;+ for( Int pane = 0; pane < OBSERVER_MOST_PANES; pane++ )+ {+ m_paneRays[ pane ] = 0.0f;+ m_panePlayers[ pane ] = NULL;+ m_paneSubject[ pane ].x = m_paneSubject[ pane ].y = 0.0f;+ m_paneGlide[ pane ] = ViewLocation();+ m_paneVelocity[ pane ].x = m_paneVelocity[ pane ].y = m_paneVelocity[ pane ].z = 0.0f;+ m_paneVelocity[ pane ].angle = m_paneVelocity[ pane ].pitch = m_paneVelocity[ pane ].zoom = 0.0f;+ m_paneView[ pane ] = ViewLocation();+ }+ m_mainOffset.x = m_mainOffset.y = 0.0f;m_firstView = ViewLocation();- m_drawingSecond = FALSE;+ m_drawingPane = 0;}//-------------------------------------------------------------------------------------------------@@ -654,20 +787,26 @@ Coord2D ObserverCamera::keepInMap( const Coord2D &place, const ViewLocation &cur}//--------------------------------------------------------------------------------------------------/** A quarter of the screen's width on the ground, pointing right: moving the look point by it puts- * what was in the middle of the screen in the middle of its left half. */+/** A step across the screen in pixels, from its middle, as a step on the ground: moving the look point+ * back by it puts what was in the middle of the screen at that many pixels from it. *///--------------------------------------------------------------------------------------------------Coord2D ObserverCamera::screenQuarter( const ViewLocation ¤t ) const+Coord2D ObserverCamera::screenToGround( const ViewLocation ¤t, const Coord2D &pixels ) const{const Coord3D &at = current.getPosition();Coord3D world[ 4 ];TheTacticalView->getScreenCornerWorldPointsAtZ( &world[ 0 ], &world[ 1 ], &world[ 2 ], &world[ 3 ],TheTerrainLogic->getGroundHeight( at.x, at.y ) );- // the corners come top left, top right, bottom right, bottom left; the two edges across are averaged- Coord2D quarter;- quarter.x = ( world[ 1 ].x - world[ 0 ].x + world[ 2 ].x - world[ 3 ].x ) / 8.0f;- quarter.y = ( world[ 1 ].y - world[ 0 ].y + world[ 2 ].y - world[ 3 ].y ) / 8.0f;- return quarter;+ // the corners come top left, top right, bottom right, bottom left; opposite edges are averaged+ const Real acrossX = ( world[ 1 ].x - world[ 0 ].x + world[ 2 ].x - world[ 3 ].x ) * 0.5f;+ const Real acrossY = ( world[ 1 ].y - world[ 0 ].y + world[ 2 ].y - world[ 3 ].y ) * 0.5f;+ const Real downX = ( world[ 3 ].x - world[ 0 ].x + world[ 2 ].x - world[ 1 ].x ) * 0.5f;+ const Real downY = ( world[ 3 ].y - world[ 0 ].y + world[ 2 ].y - world[ 1 ].y ) * 0.5f;+ const Real right = pixels.x / TheDisplay->getWidth();+ const Real down = pixels.y / TheDisplay->getHeight();+ Coord2D ground;+ ground.x = acrossX * right + downX * down;+ ground.y = acrossY * right + downY * down;+ return ground;}//-------------------------------------------------------------------------------------------------@@ -705,27 +844,234 @@ void ObserverCamera::updateSplit( void )split ? "on" : "off", firstHeat, shown.x, shown.y, secondHeat, apart ));m_split = split;m_splitChanged = frame;- // both halves cut to their places rather than gliding in from the middle of the screen- m_splitCut = split;- m_secondView = ViewLocation();}if( m_split )m_secondPlace = shown;}//--------------------------------------------------------------------------------------------------void ObserverCamera::beginSecondPass( void )+/** The panes' timeline, on logic frames, which is what each recorded picture is. A split: the corner+ * radar slides out, the second pane slides in along the diagonal with the framed radar on its+ * corner, and it all goes back the same way when the split ends. The match opens with a pane a+ * player, held a few seconds and then slid away to leave pane 0. */+//-------------------------------------------------------------------------------------------------+void ObserverCamera::advancePanes( UnsignedInt frame )+{+ static const char *const phaseNames[] = { "none", "radar out", "in", "held", "out", "radar in" };+ PanePhase next = m_panePhase;+ const UnsignedInt elapsed = frame >= m_panePhaseStart ? frame - m_panePhaseStart : 0;+ switch( m_panePhase )+ {+ case PANES_NONE:+ if( !m_introDone )+ {+ m_introDone = TRUE;+ Int players = 0;+ for( Int index = 0; index < ThePlayerList->getPlayerCount() && players < OBSERVER_MOST_PANES; index++ )+ {+ const Player *player = ThePlayerList->getNthPlayer( index );+ if( player->isPlayableSide() && !player->isPlayerObserver() && player->isPlayerActive() )+ m_panePlayers[ players++ ] = player;+ }+ m_paneCount = ObserverCamera_paneLayout( players, m_paneRays );+ if( m_paneCount >= 2 )+ {+ m_intro = TRUE;+ next = PANES_HELD;+ }+ }+ else if( m_split )+ {+ m_paneCount = ObserverCamera_paneLayout( 2, m_paneRays );+ next = PANES_RADAR_OUT;+ }+ if( next != PANES_NONE )+ {+ m_paneExit = ObserverCamera_paneExit( m_paneRays, m_paneCount, TheDisplay->getWidth(), TheDisplay->getHeight() );+ for( Int pane = 0; pane < OBSERVER_MOST_PANES; pane++ )+ m_paneGlide[ pane ] = ViewLocation();+ }+ break;+ case PANES_RADAR_OUT:+ if( elapsed >= PANE_RADAR_FRAMES )+ next = PANES_IN;+ break;+ case PANES_IN:+ if( elapsed >= PANE_SLIDE_FRAMES )+ next = PANES_HELD;+ break;+ case PANES_HELD:+ if( m_intro ? elapsed >= PANE_INTRO_FRAMES : !m_split )+ next = PANES_OUT;+ break;+ case PANES_OUT:+ if( elapsed >= PANE_SLIDE_FRAMES )+ next = PANES_RADAR_IN;+ break;+ case PANES_RADAR_IN:+ if( elapsed >= PANE_RADAR_FRAMES )+ {+ next = PANES_NONE;+ m_paneCount = 0;+ m_intro = FALSE;+ }+ break;+ }+ if( next != m_panePhase )+ {+ DEBUG_LOG(( "OBSCAM frame %u panes %s, %d of them%s\n", frame, phaseNames[ next ], m_paneCount, m_intro ? ", the opening" : "" ));+ m_panePhase = next;+ m_panePhaseStart = frame;+ }++ switch( m_panePhase )+ {+ case PANES_NONE:+ m_paneProgress = 0.0f;+ m_cornerRadarSlide = 0.0f;+ break;+ case PANES_RADAR_OUT:+ m_paneProgress = 0.0f;+ m_cornerRadarSlide = ObserverCamera_easeFrames( frame, m_panePhaseStart, PANE_RADAR_FRAMES );+ break;+ case PANES_IN:+ m_paneProgress = ObserverCamera_easeFrames( frame, m_panePhaseStart, PANE_SLIDE_FRAMES );+ m_cornerRadarSlide = 1.0f;+ break;+ case PANES_HELD:+ m_paneProgress = 1.0f;+ m_cornerRadarSlide = 1.0f;+ break;+ case PANES_OUT:+ m_paneProgress = 1.0f - ObserverCamera_easeFrames( frame, m_panePhaseStart, PANE_SLIDE_FRAMES );+ m_cornerRadarSlide = 1.0f;+ break;+ case PANES_RADAR_IN:+ m_paneProgress = 0.0f;+ m_cornerRadarSlide = 1.0f - ObserverCamera_easeFrames( frame, m_panePhaseStart, PANE_RADAR_FRAMES );+ break;+ }++ m_paneOrigin.x = TheDisplay->getWidth() * 0.5f;+ m_paneOrigin.y = TheDisplay->getHeight() * 0.5f;+ if( m_paneCount >= 2 )+ {+ const Coord2D away = ObserverCamera_paneExitDirection( m_paneRays );+ m_paneOrigin.x += away.x * ( 1.0f - m_paneProgress ) * m_paneExit;+ m_paneOrigin.y += away.y * ( 1.0f - m_paneProgress ) * m_paneExit;+ }+}++//-------------------------------------------------------------------------------------------------+/** The opening's panes: where each player's things crowd, his base at the start and his army once it+ * is bigger than the base. */+//-------------------------------------------------------------------------------------------------+void ObserverCamera::updateIntroPlaces( void )+{+ std::vector< DirectorHeat > sights[ OBSERVER_MOST_PANES ];+ for( Object *obj = TheGameLogic->getFirstObject(); obj != NULL; obj = obj->getNextObject() )+ {+ const Int cost = obj->getTemplate()->friend_getBuildCost();+ if( cost <= 0 || obj->isEffectivelyDead() )+ continue;+ for( Int pane = 0; pane < m_paneCount; pane++ )+ {+ if( obj->getControllingPlayer() != m_panePlayers[ pane ] )+ continue;+ DirectorHeat heat;+ heat.position.x = obj->getPosition()->x;+ heat.position.y = obj->getPosition()->y;+ heat.weight = ObserverCamera_sightWeight( cost, obj->isKindOf( KINDOF_STRUCTURE ), FALSE, FALSE ) + 1.0f;+ sights[ pane ].push_back( heat );+ }+ }+ for( Int pane = 0; pane < m_paneCount; pane++ )+ {+ Real heat = 0.0f;+ ObserverCamera_hottestPlace( sights[ pane ], &m_paneSubject[ pane ], &heat );+ }+}++//-------------------------------------------------------------------------------------------------+/** Each pane past the first glides to its subject on its own, and its camera sits back from the+ * subject by the pane's middle, so the subject is in the middle of its pane. Angle, pitch and zoom+ * are the main camera's. */+//-------------------------------------------------------------------------------------------------+void ObserverCamera::stepPaneCameras( const ViewLocation &step, Real elapsedSeconds )+{+ if( m_paneCount < 2 )+ return;+ if( !m_intro )+ m_paneSubject[ 1 ] = m_secondPlace;++ Coord2D middles[ OBSERVER_MOST_PANES ];+ ObserverCamera_paneMiddles( m_paneRays, m_paneCount, TheDisplay->getWidth(), TheDisplay->getHeight(), middles );+ const Coord3D &at = step.getPosition();+ for( Int pane = 1; pane < m_paneCount; pane++ )+ {+ ViewLocation subject;+ subject.init( m_paneSubject[ pane ].x, m_paneSubject[ pane ].y, at.z, step.getAngle(), step.getPitch(), step.getZoom() );+ if( !m_paneGlide[ pane ].isValid() )+ {+ m_paneVelocity[ pane ].x = m_paneVelocity[ pane ].y = m_paneVelocity[ pane ].z = 0.0f;+ m_paneVelocity[ pane ].angle = m_paneVelocity[ pane ].pitch = m_paneVelocity[ pane ].zoom = 0.0f;+ m_paneGlide[ pane ] = subject;+ }+ else+ {+ const ViewLocation glide = ObserverCamera_approach( m_paneGlide[ pane ], subject, elapsedSeconds,+ DIRECTOR_PAN_SECONDS, DIRECTOR_TOP_SPEED, &m_paneVelocity[ pane ] );+ m_paneGlide[ pane ].init( glide.getPosition().x, glide.getPosition().y, at.z, step.getAngle(), step.getPitch(), step.getZoom() );+ }++ Coord2D fromMiddle;+ fromMiddle.x = middles[ pane ].x - TheDisplay->getWidth() * 0.5f;+ fromMiddle.y = middles[ pane ].y - TheDisplay->getHeight() * 0.5f;+ const Coord2D offset = screenToGround( step, fromMiddle );+ Coord2D camera;+ camera.x = m_paneGlide[ pane ].getPosition().x - offset.x;+ camera.y = m_paneGlide[ pane ].getPosition().y - offset.y;+ camera = keepInMap( camera, step );+ m_paneView[ pane ].init( camera.x, camera.y, at.z, step.getAngle(), step.getPitch(), step.getZoom() );+ }+}++//-------------------------------------------------------------------------------------------------+Coord2D ObserverCamera::getPaneShift( void ) const+{+ Coord2D shift;+ shift.x = m_paneOrigin.x - TheDisplay->getWidth() * 0.5f;+ shift.y = m_paneOrigin.y - TheDisplay->getHeight() * 0.5f;+ return shift;+}++//-------------------------------------------------------------------------------------------------+/** On the meeting point when the panes are all in, and far enough out along its way off the screen,+ * the radar's own size further, that none of it shows when they have gone. */+//-------------------------------------------------------------------------------------------------+Coord2D ObserverCamera::getFramedRadarMiddle( Real radarDiagonal ) const+{+ const Coord2D away = ObserverCamera_paneExitDirection( m_paneRays );+ const Real out = ( 1.0f - m_paneProgress ) * ( m_paneExit + radarDiagonal );+ Coord2D middle;+ middle.x = TheDisplay->getWidth() * 0.5f + away.x * out;+ middle.y = TheDisplay->getHeight() * 0.5f + away.y * out;+ return middle;+}++//-------------------------------------------------------------------------------------------------+void ObserverCamera::beginPanePass( Int pane ){TheTacticalView->getLocation( &m_firstView );- TheTacticalView->setLocation( &m_secondView );- m_drawingSecond = TRUE;+ TheTacticalView->setLocation( &m_paneView[ pane ] );+ m_drawingPane = pane;}//--------------------------------------------------------------------------------------------------void ObserverCamera::endSecondPass( void )+void ObserverCamera::endPanePass( void ){TheTacticalView->setLocation( &m_firstView );- m_drawingSecond = FALSE;+ m_drawingPane = 0;}//-------------------------------------------------------------------------------------------------@@ -939,13 +1285,9 @@ Bool ObserverCamera::chooseTarget( const ViewLocation ¤t, ViewLocation *tareturn FALSE;if( TheGlobalData->m_directorRecord && m_placeScanned == TheGameLogic->getFrame() )updateSplit();- // split, the first fight goes in the middle of the left half- if( m_split )- {- const Coord2D quarter = screenQuarter( current );- place.x += quarter.x;- place.y += quarter.y;- }+ // the opening shows the first player's base in pane 0 until the panes start to go+ if( m_intro && m_panePhase == PANES_HELD )+ place = m_paneSubject[ 0 ];place = keepInMap( place, current );target->init( place.x, place.y, at.z, current.getAngle(), current.getPitch(), current.getZoom() );return TRUE;@@ -982,6 +1324,16 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )return;}+ // -directorrecord's panes run on the logic clock, on the split the last scan decided+ if( TheGlobalData->m_directorRecord )+ {+ const UnsignedInt frame = TheGameLogic->getFrame();+ const Bool introStarting = !m_introDone;+ advancePanes( frame );+ if( m_intro && ( introStarting || frame % DIRECTOR_SCAN_FRAMES == 0 ) )+ updateIntroPlaces();+ }+ViewLocation target;if( !chooseTarget( current, &target ) ){@@ -999,41 +1351,44 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )elsedriveHeight( m_placeHeight );holdHeight( isShowingPlayerView() );- // a split going on cuts the camera to its place in the left half: gliding there would carry the- // fight out of the middle of the screen and across the line for a second- if( !m_driving || m_splitCut )+ if( !m_driving )+ {m_velocity.x = m_velocity.y = m_velocity.z = m_velocity.angle = m_velocity.pitch = m_velocity.zoom = 0.0f;+ m_mainOffset.x = m_mainOffset.y = 0.0f;+ }++ // the glide is of the subject; the camera sits back from it so the subject is in the middle of+ // pane 0, moving there as the panes come in and back to the middle of the screen as they go+ Coord2D fromMiddle = { 0.0f, 0.0f };+ if( m_paneCount >= 2 && !isShowingPlayerView() )+ {+ Coord2D middles[ OBSERVER_MOST_PANES ];+ ObserverCamera_paneMiddles( m_paneRays, m_paneCount, TheDisplay->getWidth(), TheDisplay->getHeight(), middles );+ fromMiddle.x = ( middles[ 0 ].x - TheDisplay->getWidth() * 0.5f ) * m_paneProgress;+ fromMiddle.y = ( middles[ 0 ].y - TheDisplay->getHeight() * 0.5f ) * m_paneProgress;+ }+ const Coord3D &camera = current.getPosition();+ ViewLocation subject;+ subject.init( camera.x + m_mainOffset.x, camera.y + m_mainOffset.y, camera.z, current.getAngle(), current.getPitch(), current.getZoom() );const Bool player = m_mode == OBSERVER_CAMERA_PLAYER;- const ViewLocation step = m_splitCut ? target : ObserverCamera_approach( current, target, elapsed / MILLISECONDS_PER_SECOND,+ const ViewLocation step = ObserverCamera_approach( subject, target, elapsed / MILLISECONDS_PER_SECOND,player ? PLAYER_PAN_SECONDS : DIRECTOR_PAN_SECONDS, player ? PLAYER_TOP_SPEED : DIRECTOR_TOP_SPEED, &m_velocity );- m_splitCut = FALSE;- TheTacticalView->setLocation( &step );+ const Coord2D offset = screenToGround( step, fromMiddle );+ Coord2D sitBack;+ sitBack.x = step.getPosition().x - offset.x;+ sitBack.y = step.getPosition().y - offset.y;+ if( fromMiddle.x != 0.0f || fromMiddle.y != 0.0f )+ sitBack = keepInMap( sitBack, step );+ m_mainOffset.x = step.getPosition().x - sitBack.x;+ m_mainOffset.y = step.getPosition().y - sitBack.y;+ ViewLocation placed;+ placed.init( sitBack.x, sitBack.y, step.getPosition().z, step.getAngle(), step.getPitch(), step.getZoom() );+ TheTacticalView->setLocation( &placed );// the view keeps its look point inside its constraint when it draws; held there now, a cut to a// place past the constraint is not mistaken next frame for the watcher moving the cameraTheTacticalView->applyCameraConstraint();TheTacticalView->getPosition( &m_drivenTo );m_driving = TRUE;- // the right half's camera glides to the second fight on its own, the second fight in the middle- // of the right half, and takes everything but the place from the camera's own step- if( !m_split )- return;- const Coord2D quarter = screenQuarter( step );- Coord2D place;- place.x = m_secondPlace.x - quarter.x;- place.y = m_secondPlace.y - quarter.y;- place = keepInMap( place, step );- const Coord3D &at = step.getPosition();- ViewLocation secondTarget;- secondTarget.init( place.x, place.y, at.z, step.getAngle(), step.getPitch(), step.getZoom() );- if( !m_secondView.isValid() )- {- m_secondVelocity.x = m_secondVelocity.y = m_secondVelocity.z = m_secondVelocity.angle = m_secondVelocity.pitch = m_secondVelocity.zoom = 0.0f;- m_secondView = secondTarget;- return;- }- const ViewLocation glide = ObserverCamera_approach( m_secondView, secondTarget, elapsed / MILLISECONDS_PER_SECOND,- DIRECTOR_PAN_SECONDS, DIRECTOR_TOP_SPEED, &m_secondVelocity );- const Coord3D &glidedTo = glide.getPosition();- m_secondView.init( glidedTo.x, glidedTo.y, at.z, step.getAngle(), step.getPitch(), step.getZoom() );+ stepPaneCameras( step, elapsed / MILLISECONDS_PER_SECOND );}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex c6783b10d..8abe38662 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -4063,12 +4063,14 @@ static UnsignedInt s_videoLastFrame = 0;static Int s_videoFramesWritten = 0;static Int s_videoFramesMissed = 0;static char s_videoDirectory[_MAX_PATH];-/* -directorrecord's second fight, drawn first and kept here until the frame everybody sees is read and- the right of the leaning line is taken from it */-static char *s_videoHeld = NULL;-static Int s_videoHeldWidth = 0;-static Int s_videoHeldHeight = 0;-static UnsignedInt s_videoHeldFrame = 0;+/* -directorrecord's panes past the first, each drawn before pane 0 and kept here until the frame everybody+ sees is read and the pane's wedge is taken from it */+static char *s_videoHeld[OBSERVER_MOST_PANES] = { NULL };+static Int s_videoHeldWidth[OBSERVER_MOST_PANES] = { 0 };+static Int s_videoHeldHeight[OBSERVER_MOST_PANES] = { 0 };+static UnsignedInt s_videoHeldFrame[OBSERVER_MOST_PANES] = { 0 };+static UnsignedByte *s_videoPaneMap = NULL;+static Int s_videoPaneMapSize = 0;#if defined(_WIN32)/* -directorrecord writes no frames to disk: they go down a pipe into ffmpeg as they are drawn, which awhole match of 1080p bitmaps would need tens of gigabytes for. With no ffmpeg it records nothing@@ -4136,8 +4138,14 @@ static void finishVideo(void)DEBUG_LOG(("VIDEO: %d frames written to %s, %d logic frames went by without a picture\n",s_videoFramesWritten, s_videoDirectory, s_videoFramesMissed));- delete [] s_videoHeld;- s_videoHeld = NULL;+ for (Int pane = 0; pane < OBSERVER_MOST_PANES; ++pane)+ {+ delete [] s_videoHeld[pane];+ s_videoHeld[pane] = NULL;+ }+ delete [] s_videoPaneMap;+ s_videoPaneMap = NULL;+ s_videoPaneMapSize = 0;#if defined(_WIN32)// the end of the pipe is the end of the stream: ffmpeg finishes the movie and exits@@ -4290,6 +4298,58 @@ static Bool openVideoPipe(Int width, Int height)}#endif+/** -directorrecord's panes joined into pane 0's picture: each pixel is taken from the pane whose wedge+ * it lies in, moved with the rays' meeting point. Pane 0 keeps the framed radar and a band along every+ * seam, where only its draw has the line. A pane with no picture of this frame and size stays pane+ * 0's. */+static void joinVideoPanes(char *rows, Int width, Int height, UnsignedInt frame)+{+ enum { SEAM_BAND = 2 };+ const Int count = TheObserverCamera.getDrawnPaneCount();+ const Real *rays = TheObserverCamera.getPaneRays();+ const Coord2D origin = TheObserverCamera.getPaneOrigin();+ const Coord2D shift = TheObserverCamera.getPaneShift();+ const Int shiftX = REAL_TO_INT(shift.x);+ const Int shiftY = REAL_TO_INT(shift.y);+ const IRegion2D &radar = TheObserverCamera.getRadarFrame();++ if (s_videoPaneMapSize != width * height)+ {+ delete [] s_videoPaneMap;+ s_videoPaneMapSize = width * height;+ s_videoPaneMap = NEW UnsignedByte[s_videoPaneMapSize];+ }+ for (Int y = 0; y < height; ++y)+ for (Int x = 0; x < width; ++x)+ s_videoPaneMap[y * width + x] = (UnsignedByte)ObserverCamera_paneOf((Real)x + 0.5f, (Real)y + 0.5f,+ origin.x, origin.y, rays, count);++ for (Int y = 0; y < height; ++y)+ {+ for (Int x = 0; x < width; ++x)+ {+ const Int pane = s_videoPaneMap[y * width + x];+ if (pane == 0)+ continue;+ if (s_videoHeld[pane] == NULL || s_videoHeldFrame[pane] != frame+ || s_videoHeldWidth[pane] != width || s_videoHeldHeight[pane] != height)+ continue;+ if (x >= radar.lo.x && x < radar.hi.x && y >= radar.lo.y && y < radar.hi.y)+ continue;+ const Int left = max(x - SEAM_BAND, 0);+ const Int right = min(x + SEAM_BAND, width - 1);+ const Int up = max(y - SEAM_BAND, 0);+ const Int down = min(y + SEAM_BAND, height - 1);+ if (s_videoPaneMap[y * width + left] != pane || s_videoPaneMap[y * width + right] != pane+ || s_videoPaneMap[up * width + x] != pane || s_videoPaneMap[down * width + x] != pane)+ continue;+ const Int fromX = min(max(x - shiftX, 0), width - 1);+ const Int fromY = min(max(y - shiftY, 0), height - 1);+ memcpy(rows + (y * width + x) * 3, s_videoHeld[pane] + (fromY * width + fromX) * 3, 3);+ }+ }+}+/** One picture of the recording, into ffmpeg's pipe under -directorrecord, as the next numbered .bmp* otherwise. */static Bool writeVideoFrame(char *rows, Int width, Int height)@@ -4349,12 +4409,13 @@ static void captureVideoFrame(void)return;}- // -directorrecord's second fight: kept for the frame that follows it on this logic frame+ // -directorrecord's panes past the first: kept for pane 0's draw, the last on this logic frameif (TheObserverCamera.isDrawingSecond()){- delete [] s_videoHeld;- s_videoHeld = captureFrameRows(&s_videoHeldWidth, &s_videoHeldHeight);- s_videoHeldFrame = frame;+ const Int pane = TheObserverCamera.getDrawingPane();+ delete [] s_videoHeld[pane];+ s_videoHeld[pane] = captureFrameRows(&s_videoHeldWidth[pane], &s_videoHeldHeight[pane]);+ s_videoHeldFrame[pane] = frame;return;}@@ -4400,16 +4461,8 @@ static void captureVideoFrame(void)return;}- // split: right of the leaning line is the second fight's picture- if (s_videoHeld != NULL && s_videoHeldFrame == frame && s_videoHeldWidth == width && s_videoHeldHeight == height)- {- for (Int y = 0; y < height; ++y)- {- const Int from = min(max(ObserverCamera_splitBoundary(y, width, height), 0), width);- const Int at = (y * width + from) * 3;- memcpy(rows + at, s_videoHeld + at, (width - from) * 3);- }- }+ if (TheObserverCamera.getDrawnPaneCount() >= 2)+ joinVideoPanes(rows, width, height, frame);if (writeVideoFrame(rows, width, height))++s_videoFramesWritten;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex 905ba5b39..223e43023 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -423,6 +423,13 @@ void W3DInGameUI::reset( void )static void drawGroundRing( const Coord3D& center, Real radius, UnsignedInt color, Real width );+/// -directorrecord's line between panes, and round the radar framed where they meet+static void drawPaneLine( Real fromX, Real fromY, Real toX, Real toY )+{+ TheDisplay->drawLine( REAL_TO_INT( fromX ), REAL_TO_INT( fromY ), REAL_TO_INT( toX ), REAL_TO_INT( toY ),+ 3.0f, GameMakeColor( 235, 235, 235, 255 ) );+}+//-------------------------------------------------------------------------------------------------/** Draw member for the W3D implemenation of the game user interface *///-------------------------------------------------------------------------------------------------@@ -433,21 +440,32 @@ void W3DInGameUI::draw( void )// 930 and 1230), and nothing on the list belongs in a shot. The letterbox is the display's own.if( CinemaDirector_hidesHud() ){- // -directorrecord's two fights side by side: the line between the halves, drawn the same in- // both draws so the joined picture has it whole- const Bool split = TheObserverCamera.isSplit();- if( split )+ // -directorrecord's panes: the rays between them, from where they meet to past the screen's+ // edge, drawn in pane 0's draw alone. The other panes' pictures are moved with the meeting+ // point when they are joined, which would carry a line of theirs off the seam; the join takes+ // a band along every seam from pane 0, line and all+ const Bool framed = TheObserverCamera.isRadarFramed();+ IRegion2D noFrame;+ noFrame.lo.x = noFrame.lo.y = noFrame.hi.x = noFrame.hi.y = 0;+ TheObserverCamera.setRadarFrame( noFrame );+ if( framed && !TheObserverCamera.isDrawingSecond() ){- const Int width = TheDisplay->getWidth();- const Int height = TheDisplay->getHeight();- TheDisplay->drawLine( ObserverCamera_splitBoundary( 0, width, height ), 0,- ObserverCamera_splitBoundary( height, width, height ), height, 3.0f, GameMakeColor( 235, 235, 235, 255 ) );+ const Real reach = 2.0f * ( TheDisplay->getWidth() + TheDisplay->getHeight() );+ const Coord2D origin = TheObserverCamera.getPaneOrigin();+ const Real *rays = TheObserverCamera.getPaneRays();+ for( Int ray = 0; ray < TheObserverCamera.getDrawnPaneCount(); ray++ )+ {+ const Real angle = rays[ ray ] * PI / 180.0f;+ drawPaneLine( origin.x, origin.y, origin.x + cosf( angle ) * reach, origin.y - sinf( angle ) * reach );+ }}// the console's 'hidehud showmap=true': the bar is hidden, so its radar window is put in the- // corner by hand, where the radar's own pixel maths find it too, and painted. Over a split- // picture it sits in the middle, on the line, where it covers neither fight- if( CinemaDirector_showsMap() )+ // corner by hand, where the radar's own pixel maths find it too, and painted. Under+ // -directorrecord it slides out of the corner to the left before panes come and back after+ // them, and while they are up it sits in a frame of the rays' own line where they meet,+ // pane 0's alone: the other panes' draws leave it out and the recording takes it from pane 0+ if( CinemaDirector_showsMap() && !TheObserverCamera.isDrawingSecond() ){GameWindow *radarWindow = TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( "ControlBar.wnd:LeftHUD" ) );// W3DLeftHUDDraw paints one pixel inside the window, and the radar keeps the map's shape@@ -462,17 +480,45 @@ void W3DInGameUI::draw( void )corner.hi.x = corner.lo.x + ( lr.x - ul.x ) + 2 * RADAR_BEZEL;corner.hi.y = TheDisplay->getHeight() + RADAR_BEZEL;corner.lo.y = corner.hi.y - ( lr.y - ul.y ) - 2 * RADAR_BEZEL;- if( split )+ const Int mapWidth = corner.hi.x - corner.lo.x;+ const Int mapHeight = corner.hi.y - corner.lo.y;+ enum { RADAR_FRAME_GAP = 3 };+ if( framed ){- const Int mapWidth = corner.hi.x - corner.lo.x;- const Int mapHeight = corner.hi.y - corner.lo.y;- corner.lo.x = ( TheDisplay->getWidth() - mapWidth ) / 2;+ const Real diagonal = sqrtf( (Real)( mapWidth * mapWidth + mapHeight * mapHeight ) ) + 2 * RADAR_FRAME_GAP;+ const Coord2D middle = TheObserverCamera.getFramedRadarMiddle( diagonal );+ corner.lo.x = REAL_TO_INT( middle.x ) - mapWidth / 2;corner.hi.x = corner.lo.x + mapWidth;- corner.lo.y = ( TheDisplay->getHeight() - mapHeight ) / 2;+ corner.lo.y = REAL_TO_INT( middle.y ) - mapHeight / 2;corner.hi.y = corner.lo.y + mapHeight;}+ else+ {+ const Int slide = REAL_TO_INT( TheObserverCamera.getCornerRadarSlide() * ( mapWidth + RADAR_FRAME_GAP ) );+ corner.lo.x -= slide;+ corner.hi.x -= slide;+ }TheControlBar->placeWindowAt( radarWindow, corner );W3DLeftHUDDraw( radarWindow, NULL );++ if( framed )+ {+ IRegion2D frame;+ frame.lo.x = corner.lo.x - RADAR_FRAME_GAP;+ frame.lo.y = corner.lo.y - RADAR_FRAME_GAP;+ frame.hi.x = corner.hi.x + RADAR_FRAME_GAP;+ frame.hi.y = corner.hi.y + RADAR_FRAME_GAP;+ drawPaneLine( frame.lo.x, frame.lo.y, frame.hi.x, frame.lo.y );+ drawPaneLine( frame.hi.x, frame.lo.y, frame.hi.x, frame.hi.y );+ drawPaneLine( frame.hi.x, frame.hi.y, frame.lo.x, frame.hi.y );+ drawPaneLine( frame.lo.x, frame.hi.y, frame.lo.x, frame.lo.y );+ // the line is drawn on the frame's edge, so its outer half is pane 0's too+ frame.lo.x -= RADAR_FRAME_GAP;+ frame.lo.y -= RADAR_FRAME_GAP;+ frame.hi.x += RADAR_FRAME_GAP;+ frame.hi.y += RADAR_FRAME_GAP;+ TheObserverCamera.setRadarFrame( frame );+ }}return;}diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.incindex 087035a6e..c9f2b447b 100644--- a/GeneralsMD/Code/Tests/test_observer_camera.inc+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc@@ -354,10 +354,75 @@ TEST(the_recording_splits_only_beside_a_real_fight)CHECK( !ObserverCamera_secondPlace( none, first, &second, &heat ) );}-TEST(the_split_line_leans_twelve_degrees_through_the_middle)+TEST(every_pane_layout_cuts_on_45_degree_rays){- CHECK_EQ( ObserverCamera_splitBoundary( 360, 1280, 720 ), 640 );- // 360 rows from the middle at tan 12 degrees is 76.5 columns- CHECK_EQ( ObserverCamera_splitBoundary( 0, 1280, 720 ), 717 );- CHECK_EQ( ObserverCamera_splitBoundary( 720, 1280, 720 ), 563 );+ CHECK_EQ( ObserverCamera_paneLayout( 1, NULL ), 0 );+ for( Int count = 2; count <= OBSERVER_MOST_PANES; count++ )+ {+ Real rays[ OBSERVER_MOST_PANES ];+ CHECK_EQ( ObserverCamera_paneLayout( count, rays ), count );+ for( Int ray = 0; ray < count; ray++ )+ {+ CHECK_EQ( (Int)rays[ ray ] % 45, 0 );+ CHECK( ray == 0 || rays[ ray ] > rays[ ray - 1 ] );+ }+ }+ // more players than panes share the eight+ Real rays[ OBSERVER_MOST_PANES ];+ CHECK_EQ( ObserverCamera_paneLayout( 12, rays ), (Int)OBSERVER_MOST_PANES );+}++TEST(a_pixel_lies_in_the_wedge_counter_clockwise_of_its_ray)+{+ Real rays[ OBSERVER_MOST_PANES ];+ ObserverCamera_paneLayout( 2, rays );+ // the diagonal through the middle of 1280x720: pane 0 above it on the left, pane 1 below it+ CHECK_EQ( ObserverCamera_paneOf( 740.0f, 258.0f, 640.0f, 360.0f, rays, 2 ), 0 );+ CHECK_EQ( ObserverCamera_paneOf( 740.0f, 262.0f, 640.0f, 360.0f, rays, 2 ), 1 );+ CHECK_EQ( ObserverCamera_paneOf( 100.0f, 100.0f, 640.0f, 360.0f, rays, 2 ), 0 );+ CHECK_EQ( ObserverCamera_paneOf( 1200.0f, 700.0f, 640.0f, 360.0f, rays, 2 ), 1 );++ // an X: top, left, bottom, right+ ObserverCamera_paneLayout( 4, rays );+ CHECK_EQ( ObserverCamera_paneOf( 640.0f, 100.0f, 640.0f, 360.0f, rays, 4 ), 0 );+ CHECK_EQ( ObserverCamera_paneOf( 100.0f, 360.0f, 640.0f, 360.0f, rays, 4 ), 1 );+ CHECK_EQ( ObserverCamera_paneOf( 640.0f, 700.0f, 640.0f, 360.0f, rays, 4 ), 2 );+ CHECK_EQ( ObserverCamera_paneOf( 1200.0f, 360.0f, 640.0f, 360.0f, rays, 4 ), 3 );+}++TEST(pane_zero_fills_the_screen_once_the_meeting_point_is_out_far_enough)+{+ Real rays[ OBSERVER_MOST_PANES ];+ ObserverCamera_paneLayout( 2, rays );+ // the diagonal has to clear the bottom right corner: (639.5 + 359.5) * cos 45 degrees+ CHECK_NEAR( ObserverCamera_paneExit( rays, 2, 1280, 720 ), 706.4f, 2.0f );+ const Coord2D away = ObserverCamera_paneExitDirection( rays );+ CHECK( away.x > 0.0f && away.y > 0.0f );+}++TEST(the_two_pane_middles_mirror_through_the_screen_middle)+{+ Real rays[ OBSERVER_MOST_PANES ];+ ObserverCamera_paneLayout( 2, rays );+ Coord2D middles[ OBSERVER_MOST_PANES ];+ ObserverCamera_paneMiddles( rays, 2, 1280, 720, middles );+ CHECK( middles[ 0 ].x < 640.0f && middles[ 0 ].y < 360.0f );+ CHECK_NEAR( middles[ 0 ].x + middles[ 1 ].x, 1280.0f, 1.0f );+ CHECK_NEAR( middles[ 0 ].y + middles[ 1 ].y, 720.0f, 1.0f );+}++TEST(pane_animations_ease_over_logic_frames)+{+ CHECK_NEAR( ObserverCamera_easeFrames( 100, 100, 15 ), 0.0f, 0.0001f );+ CHECK_NEAR( ObserverCamera_easeFrames( 90, 100, 15 ), 0.0f, 0.0001f );+ CHECK_NEAR( ObserverCamera_easeFrames( 110, 100, 20 ), 0.5f, 0.0001f );+ CHECK_NEAR( ObserverCamera_easeFrames( 115, 100, 15 ), 1.0f, 0.0001f );+ CHECK_NEAR( ObserverCamera_easeFrames( 400, 100, 15 ), 1.0f, 0.0001f );+ Real last = 0.0f;+ for( UnsignedInt frame = 100; frame <= 115; frame++ )+ {+ const Real now = ObserverCamera_easeFrames( frame, 100, 15 );+ CHECK( now >= last );+ last = now;+ }}