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): fit each director pane's subject into its wedge
Olcay Seygan236895d84ad9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex df997863e..6ef3a9667 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. 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. The lines are the Reforged gold on a dark edge, so they read on snow and at night, and they run straight into the radar's frame. While the screen is cut, every camera rises to keep its fight whole in a narrower slice: 30 percent higher for two pictures, half again for four or more, easing up and back down with the sweep. 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 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. The lines are the Reforged gold on a dark edge, so they read on snow and at night, and they run straight into the radar's frame. While the screen is cut, each picture frames its own fight: the camera puts it in the biggest round space its slice has clear of the lines and the radar, and rises until the whole fight fits there with room to spare, never lower than the Director flies and never more than twice as high. A fight that spreads is let out smoothly; one that shrinks does not make the picture pump in and out. The opening frames each player's base the same way. 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 f5cd21b2a..34b675b14 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h@@ -152,13 +152,21 @@ Int ObserverCamera_paneOf( Real x, Real y, Real originX, Real originY, const ReaReal 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 awayCoord2D 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 );+/// the largest circle that fits in each pane with the rays meeting in the middle of the picture, kept+/// off the screen's edges, the rays and the radar's frame, a rectangle radarHalf wide and high each+/// way from the middle. Its centre is where the pane's subject is put and its radius, in pixels,+/// what the subject is fitted into; centres and radii have count entries+void ObserverCamera_paneCircles( const Real *rays, Int count, Int width, Int height, const Coord2D &radarHalf,+ Coord2D *centres, Real *radii );+/// how far from around the farthest of the things within reach of it lie, on the ground, and never less+/// than least+Real ObserverCamera_extentAround( const std::vector< DirectorHeat > &things, const Coord2D &around, Real reach, Real least );+/// the zoom that fits a subject extent across on the ground into a circle radius pixels across, with a+/// margin, for a view whose ground per pixel is groundPerPixelAtOne at zoom 1; never under nearest or+/// over farthest+Real ObserverCamera_fitZoom( Real extent, Real radius, Real groundPerPixelAtOne, Real nearest, Real farthest );/// how far an animation of length frames that started on start is on frame, eased in and out, 0 to 1Real ObserverCamera_easeFrames( UnsignedInt frame, UnsignedInt start, UnsignedInt length );-/// how much higher every camera stands while count panes are progress of the way in, 1 with none-Real ObserverCamera_paneZoom( Int count, Real progress );/// the dark edge each side of the gold of a line between panes and of the radar's frame, in pixelsenum { OBSERVER_PANE_LINE_EDGE = 2 };/// the gold of a line between panes, in pixels, for a picture height pixels high: 6 at 720, 9 at 1080@@ -237,10 +245,12 @@ private:void driveHeight( Real extra );Bool takenByHand( const ViewLocation ¤t ) const;Coord2D keepInMap( const Coord2D &place, const ViewLocation ¤t ) const;- Coord2D screenToGround( const ViewLocation ¤t, const Coord2D &pixels ) const;+ Coord2D screenToGround( const ViewLocation ¤t, const Coord2D &pixels, Real zoom ) const;void updateSplit( void );void updateIntroPlaces( void );void advancePanes( UnsignedInt frame );+ void fitPanes( UnsignedInt frame );+ Real paneZoom( Int pane ) const;void stepPaneCameras( const ViewLocation &step, Real elapsedSeconds );Bool isShowingPlayerView( void ) const;Bool chooseTarget( const ViewLocation ¤t, ViewLocation *target );@@ -294,6 +304,13 @@ private:Real m_paneProgress; ///< 0 for no panes on the screen, 1 for all of them, easedReal m_paneExit; ///< how far off the meeting point goes, in pixelsReal m_paneBaseZoom; ///< the view's zoom when the panes started, which they rise from+ Coord2D m_paneCentres[ OBSERVER_MOST_PANES ]; ///< where each pane's subject is put, the rays meeting in the middle+ Real m_paneRadii[ OBSERVER_MOST_PANES ]; ///< how much of its pane each subject is fitted into, in pixels+ Real m_paneExtent[ OBSERVER_MOST_PANES ]; ///< how far each pane's subject spreads on the ground+ Real m_paneFit[ OBSERVER_MOST_PANES ]; ///< each pane's zoom with the panes all in, eased on logic frames+ Bool m_paneFitValid; ///< m_paneFit holds a fit of these panes+ UnsignedInt m_paneFitFrame; ///< the logic frame m_paneFit last moved on+ Coord2D m_radarHalf; ///< half the framed radar's size, taken from its last drawCoord2D m_paneOrigin; ///< where the rays meet now, in pixelsReal m_cornerRadarSlide;IRegion2D m_radarFrame;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cppindex 05ccaf749..ef4984085 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp@@ -124,15 +124,21 @@ static const UnsignedInt PANE_RADAR_FRAMES = 12;static const UnsignedInt PANE_SLIDE_FRAMES = 15;/// the match opens on every player's base, one pane each, for this longstatic const UnsignedInt PANE_INTRO_FRAMES = 7 * LOGICFRAMES_PER_SECOND;-/// how much higher the cameras stand with the panes all in, by how many panes there are-static const Real PANE_ZOOM_TWO = 1.3f;-static const Real PANE_ZOOM_THREE = 1.4f;-static const Real PANE_ZOOM_FOUR_OR_MORE = 1.5f;/// the gold of a line between panes is a pixel for every this many rows of the picturestatic const Real PANE_LINE_ROWS_A_PIXEL = 120.0f;-/// 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;+/// a pane's circle is looked for on a grid this fine, a centre every 10 pixels at 1280x720+static const Int PANE_CIRCLE_COLUMNS = 128;+static const Int PANE_CIRCLE_ROWS = 72;+/// a subject fitted into its pane's circle leaves this much of the radius round it+static const Real PANE_FIT_MARGIN = 0.15f;+/// a pane never comes closer than the director's own zoom, and never goes further out than this times it+static const Real PANE_FIT_FARTHEST = 2.0f;+/// a fight is never fitted as smaller than this across, so two tanks are not filled into a pane+static const Real PANE_FIT_LEAST_EXTENT = 150.0f;+/// the opening fits what a player has within this of the middle of it, his base and the army beside it+static const Real PANE_INTRO_REACH = 500.0f;+/// how much of the way to a new fit a pane's zoom goes each logic frame, about a second and a half+static const Real PANE_FIT_FOLLOW = 0.06f;//-------------------------------------------------------------------------------------------------static Bool sameFight( const Coord2D &a, const Coord2D &b )@@ -494,31 +500,82 @@ Real ObserverCamera_paneExit( const Real *rays, Int count, Int width, Int height}//--------------------------------------------------------------------------------------------------void ObserverCamera_paneMiddles( const Real *rays, Int count, Int width, Int height, Coord2D *middles )+/** How far a point is from a ray out of the middle: across to the ray's line, or back to where the+ * ray starts when the point is behind it. */+//-------------------------------------------------------------------------------------------------+static Real distanceToRay( Real x, Real y, Real middleX, Real middleY, Real degrees ){- Int samples[ OBSERVER_MOST_PANES ];+ const Real angle = degrees * PI / 180.0f;+ const Real alongX = cosf( angle );+ const Real alongY = -sinf( angle );+ const Real fromX = x - middleX;+ const Real fromY = y - middleY;+ if( fromX * alongX + fromY * alongY <= 0.0f )+ return sqrtf( fromX * fromX + fromY * fromY );+ return fabs( fromX * alongY - fromY * alongX );+}++//-------------------------------------------------------------------------------------------------+/** Every pane is a wedge of 180 degrees or less, so the nearest of its edges is one of its two rays,+ * the screen's four sides or the radar's frame; the grid point furthest from all of them is the+ * circle's centre. */+//-------------------------------------------------------------------------------------------------+void ObserverCamera_paneCircles( const Real *rays, Int count, Int width, Int height, const Coord2D &radarHalf,+ Coord2D *centres, Real *radii )+{+ const Real middleX = width * 0.5f;+ const Real middleY = height * 0.5f;for( Int pane = 0; pane < count; pane++ ){- samples[ pane ] = 0;- middles[ pane ].x = middles[ pane ].y = 0.0f;+ radii[ pane ] = 0.0f;+ centres[ pane ].x = middleX;+ centres[ pane ].y = middleY;}- for( Int row = 0; row < PANE_MIDDLE_ROWS; row++ )+ for( Int row = 0; row < PANE_CIRCLE_ROWS; row++ ){- for( Int column = 0; column < PANE_MIDDLE_COLUMNS; column++ )+ for( Int column = 0; column < PANE_CIRCLE_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 ]++;+ const Real x = ( column + 0.5f ) * width / PANE_CIRCLE_COLUMNS;+ const Real y = ( row + 0.5f ) * height / PANE_CIRCLE_ROWS;+ const Int pane = ObserverCamera_paneOf( x, y, middleX, middleY, rays, count );+ Real clear = min( min( x, width - x ), min( y, height - y ) );+ clear = min( clear, distanceToRay( x, y, middleX, middleY, rays[ pane ] ) );+ clear = min( clear, distanceToRay( x, y, middleX, middleY, rays[ ( pane + 1 ) % count ] ) );+ const Real outX = max( fabs( x - middleX ) - radarHalf.x, 0.0f );+ const Real outY = max( fabs( y - middleY ) - radarHalf.y, 0.0f );+ clear = min( clear, sqrtf( outX * outX + outY * outY ) );+ if( clear > radii[ pane ] )+ {+ radii[ pane ] = clear;+ centres[ pane ].x = x;+ centres[ pane ].y = y;+ }}}- for( Int pane = 0; pane < count; pane++ )+}++//-------------------------------------------------------------------------------------------------+Real ObserverCamera_extentAround( const std::vector< DirectorHeat > &things, const Coord2D &around, Real reach, Real least )+{+ Real farthest = least;+ for( size_t index = 0; index < things.size(); index++ ){- middles[ pane ].x /= samples[ pane ];- middles[ pane ].y /= samples[ pane ];+ const Real dx = things[ index ].position.x - around.x;+ const Real dy = things[ index ].position.y - around.y;+ const Real distance = sqrtf( dx * dx + dy * dy );+ if( distance <= reach )+ farthest = max( farthest, distance );}+ return farthest;+}++//-------------------------------------------------------------------------------------------------+/** The ground a pixel covers grows with the zoom, the camera standing that much further back. */+//-------------------------------------------------------------------------------------------------+Real ObserverCamera_fitZoom( Real extent, Real radius, Real groundPerPixelAtOne, Real nearest, Real farthest )+{+ const Real zoom = extent * ( 1.0f + PANE_FIT_MARGIN ) / ( radius * groundPerPixelAtOne );+ return min( max( zoom, nearest ), farthest );}//-------------------------------------------------------------------------------------------------@@ -530,18 +587,6 @@ Real ObserverCamera_easeFrames( UnsignedInt frame, UnsignedInt start, UnsignedInreturn t * t * ( 3.0f - 2.0f * t );}-//--------------------------------------------------------------------------------------------------/** A wedge is a slice of the screen, so its subject wants more ground round it than the whole- * screen gave; more panes are narrower slices and stand higher still. */-//--------------------------------------------------------------------------------------------------Real ObserverCamera_paneZoom( Int count, Real progress )-{- if( count < 2 )- return 1.0f;- const Real highest = count == 2 ? PANE_ZOOM_TWO : count == 3 ? PANE_ZOOM_THREE : PANE_ZOOM_FOUR_OR_MORE;- return 1.0f + ( highest - 1.0f ) * progress;-}-//-------------------------------------------------------------------------------------------------Int ObserverCamera_paneLineWidth( Int height ){@@ -606,6 +651,9 @@ void ObserverCamera::reset( void )m_paneProgress = 0.0f;m_paneExit = 0.0f;m_paneBaseZoom = 1.0f;+ m_paneFitValid = FALSE;+ m_paneFitFrame = 0;+ m_radarHalf.x = m_radarHalf.y = 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;@@ -614,6 +662,10 @@ void ObserverCamera::reset( void )m_paneRays[ pane ] = 0.0f;m_panePlayers[ pane ] = NULL;m_paneSubject[ pane ].x = m_paneSubject[ pane ].y = 0.0f;+ m_paneCentres[ pane ].x = m_paneCentres[ pane ].y = 0.0f;+ m_paneRadii[ pane ] = 0.0f;+ m_paneExtent[ pane ] = PANE_FIT_LEAST_EXTENT;+ m_paneFit[ pane ] = 1.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;@@ -825,10 +877,12 @@ Coord2D ObserverCamera::keepInMap( const Coord2D &place, const ViewLocation &cur//-------------------------------------------------------------------------------------------------/** 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. */+ * back by it puts what was in the middle of the screen at that many pixels from it. Measured on the+ * view as it stands and taken to zoom, the ground a pixel covers growing with the zoom. *///--------------------------------------------------------------------------------------------------Coord2D ObserverCamera::screenToGround( const ViewLocation ¤t, const Coord2D &pixels ) const+Coord2D ObserverCamera::screenToGround( const ViewLocation ¤t, const Coord2D &pixels, Real zoom ) const{+ const Real scale = zoom / TheTacticalView->getZoom();const Coord3D &at = current.getPosition();Coord3D world[ 4 ];TheTacticalView->getScreenCornerWorldPointsAtZ( &world[ 0 ], &world[ 1 ], &world[ 2 ], &world[ 3 ],@@ -838,8 +892,8 @@ Coord2D ObserverCamera::screenToGround( const ViewLocation ¤t, const Coordconst 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();+ const Real right = pixels.x / TheDisplay->getWidth() * scale;+ const Real down = pixels.y / TheDisplay->getHeight() * scale;Coord2D ground;ground.x = acrossX * right + downX * down;ground.y = acrossY * right + downY * down;@@ -926,8 +980,12 @@ void ObserverCamera::advancePanes( UnsignedInt frame ){m_paneExit = ObserverCamera_paneExit( m_paneRays, m_paneCount, TheDisplay->getWidth(), TheDisplay->getHeight() );m_paneBaseZoom = TheTacticalView->getZoom();+ m_paneFitValid = FALSE;for( Int pane = 0; pane < OBSERVER_MOST_PANES; pane++ )+ {m_paneGlide[ pane ] = ViewLocation();+ m_paneExtent[ pane ] = PANE_FIT_LEAST_EXTENT;+ }}break;case PANES_RADAR_OUT:@@ -1030,15 +1088,72 @@ void ObserverCamera::updateIntroPlaces( void ){Real heat = 0.0f;ObserverCamera_hottestPlace( sights[ pane ], &m_paneSubject[ pane ], &heat );+ m_paneExtent[ pane ] = ObserverCamera_extentAround( sights[ pane ], m_paneSubject[ pane ], PANE_INTRO_REACH, PANE_FIT_LEAST_EXTENT );}}+//-------------------------------------------------------------------------------------------------+/** Each pane's zoom with the panes all in: its subject's spread, fitted into the largest circle its+ * wedge holds clear of the rays, the screen's edges and the radar's frame. Never closer than the+ * director was when the panes came, never more than PANE_FIT_FARTHEST times further out. It moves+ * towards a new fit a share a logic frame, and while the panes are held only outwards, so a fight+ * that grows is let out and one that shrinks does not pump the zoom. */+//-------------------------------------------------------------------------------------------------+void ObserverCamera::fitPanes( UnsignedInt frame )+{+ const IRegion2D &radar = m_radarFrame;+ if( radar.hi.x > radar.lo.x )+ {+ m_radarHalf.x = ( radar.hi.x - radar.lo.x ) * 0.5f;+ m_radarHalf.y = ( radar.hi.y - radar.lo.y ) * 0.5f;+ }+ ObserverCamera_paneCircles( m_paneRays, m_paneCount, TheDisplay->getWidth(), TheDisplay->getHeight(), m_radarHalf,+ m_paneCentres, m_paneRadii );++ if( !m_intro )+ {+ m_paneExtent[ 0 ] = ObserverCamera_extentAround( m_fights, m_panesLeftPlace, DIRECTOR_GATHER_RADIUS, PANE_FIT_LEAST_EXTENT );+ m_paneExtent[ 1 ] = ObserverCamera_extentAround( m_fights, m_secondPlace, DIRECTOR_GATHER_RADIUS, PANE_FIT_LEAST_EXTENT );+ }++ // the ground a pixel covers at zoom 1, from the screen's width on the ground now+ Coord3D world[ 4 ];+ Coord3D at;+ TheTacticalView->getPosition( &at );+ TheTacticalView->getScreenCornerWorldPointsAtZ( &world[ 0 ], &world[ 1 ], &world[ 2 ], &world[ 3 ],+ TheTerrainLogic->getGroundHeight( at.x, at.y ) );+ 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 groundPerPixelAtOne = sqrtf( acrossX * acrossX + acrossY * acrossY ) / TheDisplay->getWidth() / TheTacticalView->getZoom();++ const Bool moves = frame != m_paneFitFrame;+ m_paneFitFrame = frame;+ for( Int pane = 0; pane < m_paneCount; pane++ )+ {+ const Real wanted = ObserverCamera_fitZoom( m_paneExtent[ pane ], m_paneRadii[ pane ], groundPerPixelAtOne,+ m_paneBaseZoom, m_paneBaseZoom * PANE_FIT_FARTHEST );+ if( !m_paneFitValid )+ m_paneFit[ pane ] = wanted;+ else if( moves && ( m_panePhase != PANES_HELD || wanted > m_paneFit[ pane ] ) )+ m_paneFit[ pane ] += ( wanted - m_paneFit[ pane ] ) * PANE_FIT_FOLLOW;+ }+ m_paneFitValid = TRUE;+}++//-------------------------------------------------------------------------------------------------+/** A pane's zoom now: the director's own with no panes, its fit with them all in. */+//-------------------------------------------------------------------------------------------------+Real ObserverCamera::paneZoom( Int pane ) const+{+ return m_paneBaseZoom + ( m_paneFit[ pane ] - m_paneBaseZoom ) * m_paneProgress;+}+//-------------------------------------------------------------------------------------------------/** 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. While the rays' meeting- * point slides, the camera sits back by that much more, so the pane's picture slides with it and- * is the world on the whole screen, with no edge of a moved picture to show. Angle, pitch and zoom- * are the main camera's. */+ * subject by the centre of the pane's circle, at the pane's own zoom, so the subject fills the+ * circle. While the rays' meeting point slides, the camera sits back by that much more, so the+ * pane's picture slides with it and is the world on the whole screen, with no edge of a moved+ * picture to show. Angle and pitch are the main camera's. *///-------------------------------------------------------------------------------------------------void ObserverCamera::stepPaneCameras( const ViewLocation &step, Real elapsedSeconds ){@@ -1047,11 +1162,10 @@ void ObserverCamera::stepPaneCameras( const ViewLocation &step, Real elapsedSecoif( !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++ ){+ const Real zoom = paneZoom( 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() )@@ -1068,14 +1182,14 @@ void ObserverCamera::stepPaneCameras( const ViewLocation &step, Real elapsedSeco}Coord2D fromMiddle;- fromMiddle.x = middles[ pane ].x + m_paneOrigin.x - TheDisplay->getWidth();- fromMiddle.y = middles[ pane ].y + m_paneOrigin.y - TheDisplay->getHeight();- const Coord2D offset = screenToGround( step, fromMiddle );+ fromMiddle.x = m_paneCentres[ pane ].x + m_paneOrigin.x - TheDisplay->getWidth();+ fromMiddle.y = m_paneCentres[ pane ].y + m_paneOrigin.y - TheDisplay->getHeight();+ const Coord2D offset = screenToGround( step, fromMiddle, zoom );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() );+ m_paneView[ pane ].init( camera.x, camera.y, at.z, step.getAngle(), step.getPitch(), zoom );}}@@ -1401,15 +1515,14 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )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+ // the glide is of the subject; the camera sits back from it so the subject is in pane 0's circle,+ // moving there as the panes come in and back to the middle of the screen as they goCoord2D fromMiddle = { 0.0f, 0.0f };- if( m_paneCount >= 2 && !isShowingPlayerView() )+ if( panesZoom ){- 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;+ fitPanes( TheGameLogic->getFrame() );+ fromMiddle.x = ( m_paneCentres[ 0 ].x - TheDisplay->getWidth() * 0.5f ) * m_paneProgress;+ fromMiddle.y = ( m_paneCentres[ 0 ].y - TheDisplay->getHeight() * 0.5f ) * m_paneProgress;}const Coord3D &camera = current.getPosition();ViewLocation subject;@@ -1437,10 +1550,9 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )if( panesZoom ){const Coord3D &stepAt = step.getPosition();- step.init( stepAt.x, stepAt.y, stepAt.z, step.getAngle(), step.getPitch(),- m_paneBaseZoom * ObserverCamera_paneZoom( m_paneCount, m_paneProgress ) );+ step.init( stepAt.x, stepAt.y, stepAt.z, step.getAngle(), step.getPitch(), paneZoom( 0 ) );}- const Coord2D offset = screenToGround( step, fromMiddle );+ const Coord2D offset = screenToGround( step, fromMiddle, step.getZoom() );Coord2D sitBack;sitBack.x = step.getPosition().x - offset.x;sitBack.y = step.getPosition().y - offset.y;diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.incindex c1cb7b979..2aca7ccab 100644--- a/GeneralsMD/Code/Tests/test_observer_camera.inc+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc@@ -400,26 +400,80 @@ TEST(pane_zero_fills_the_screen_once_the_meeting_point_is_out_far_enough)CHECK( away.x > 0.0f && away.y > 0.0f );}-TEST(the_two_pane_middles_mirror_through_the_screen_middle)+TEST(a_pane_circle_is_the_largest_its_wedge_holds){Real rays[ OBSERVER_MOST_PANES ];+ Coord2D centres[ OBSERVER_MOST_PANES ];+ Real radii[ OBSERVER_MOST_PANES ];+ const Coord2D noRadar = { 0.0f, 0.0f };++ // two panes: the circle touching the top, the left and the diagonal x + y = 1000 has a radius of+ // 1000 / (2 + root 2), and pane 1's is its mirror through the middle+ ObserverCamera_paneLayout( 2, rays );+ ObserverCamera_paneCircles( rays, 2, 1280, 720, noRadar, centres, radii );+ CHECK_NEAR( radii[ 0 ], 292.9f, 8.0f );+ CHECK_NEAR( centres[ 0 ].x, 292.9f, 15.0f );+ CHECK_NEAR( centres[ 0 ].y, 292.9f, 15.0f );+ CHECK_NEAR( radii[ 1 ], radii[ 0 ], 8.0f );+ CHECK_NEAR( centres[ 0 ].x + centres[ 1 ].x, 1280.0f, 20.0f );++ // an X: the top wedge is a right triangle on a 720 wide side, its circle 149 in radius; the left+ // one runs past the top and bottom corners, and its circle touching the left edge and both rays has+ // 640 / (1 + root 2)+ ObserverCamera_paneLayout( 4, rays );+ ObserverCamera_paneCircles( rays, 4, 1280, 720, noRadar, centres, radii );+ CHECK_NEAR( radii[ 0 ], 149.1f, 8.0f );+ CHECK_NEAR( centres[ 0 ].x, 640.0f, 15.0f );+ CHECK_NEAR( radii[ 1 ], 265.1f, 8.0f );+ CHECK_NEAR( centres[ 1 ].y, 360.0f, 15.0f );+ CHECK_NEAR( radii[ 2 ], radii[ 0 ], 8.0f );+ CHECK_NEAR( radii[ 3 ], radii[ 1 ], 8.0f );++ // a Y: three circles, every one inside the screen+ ObserverCamera_paneLayout( 3, rays );+ ObserverCamera_paneCircles( rays, 3, 1280, 720, noRadar, centres, radii );+ for( Int pane = 0; pane < 3; pane++ )+ {+ CHECK( radii[ pane ] > 100.0f );+ CHECK( centres[ pane ].x - radii[ pane ] >= 0.0f && centres[ pane ].x + radii[ pane ] <= 1280.0f );+ CHECK( centres[ pane ].y - radii[ pane ] >= 0.0f && centres[ pane ].y + radii[ pane ] <= 720.0f );+ CHECK_EQ( ObserverCamera_paneOf( centres[ pane ].x, centres[ pane ].y, 640.0f, 360.0f, rays, 3 ), pane );+ }++ // the framed radar in the middle takes room from the two pane circle, which reached its cornerObserverCamera_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 );+ const Coord2D radar = { 150.0f, 100.0f };+ ObserverCamera_paneCircles( rays, 2, 1280, 720, radar, centres, radii );+ CHECK( radii[ 0 ] < 285.0f );+ CHECK( radii[ 0 ] > 150.0f );+}++TEST(a_subject_spreads_as_far_as_its_farthest_thing_within_reach)+{+ std::vector< DirectorHeat > things;+ const Coord2D around = { 1000.0f, 1000.0f };+ CHECK_NEAR( ObserverCamera_extentAround( things, around, 500.0f, 150.0f ), 150.0f, 0.01f );+ const Real distances[] = { 100.0f, 300.0f, 600.0f };+ for( Int index = 0; index < 3; index++ )+ {+ DirectorHeat thing;+ thing.position.x = around.x + distances[ index ];+ thing.position.y = around.y;+ thing.weight = 1.0f;+ things.push_back( thing );+ }+ CHECK_NEAR( ObserverCamera_extentAround( things, around, 500.0f, 150.0f ), 300.0f, 0.01f );}-TEST(pane_cameras_stand_higher_the_more_panes_there_are)+TEST(a_pane_zooms_out_to_fit_its_subject_and_no_further_than_the_cap){- CHECK_NEAR( ObserverCamera_paneZoom( 1, 1.0f ), 1.0f, 0.0001f );- CHECK_NEAR( ObserverCamera_paneZoom( 2, 0.0f ), 1.0f, 0.0001f );- CHECK_NEAR( ObserverCamera_paneZoom( 2, 1.0f ), 1.3f, 0.0001f );- CHECK_NEAR( ObserverCamera_paneZoom( 2, 0.5f ), 1.15f, 0.0001f );- CHECK_NEAR( ObserverCamera_paneZoom( 3, 1.0f ), 1.4f, 0.0001f );- CHECK_NEAR( ObserverCamera_paneZoom( 4, 1.0f ), 1.5f, 0.0001f );- CHECK_NEAR( ObserverCamera_paneZoom( 8, 1.0f ), 1.5f, 0.0001f );+ // 200 pixels at 2 a pixel is 400 on the ground; 300 with its 15 percent margin fits closer than+ // the director's own, which is as close as a pane comes+ CHECK_NEAR( ObserverCamera_fitZoom( 300.0f, 200.0f, 2.0f, 1.0f, 2.0f ), 1.0f, 0.0001f );+ CHECK_NEAR( ObserverCamera_fitZoom( 600.0f, 200.0f, 2.0f, 1.0f, 2.0f ), 1.725f, 0.001f );+ CHECK_NEAR( ObserverCamera_fitZoom( 2000.0f, 200.0f, 2.0f, 1.0f, 2.0f ), 2.0f, 0.0001f );+ // a smaller circle wants more ground in each pixel+ CHECK( ObserverCamera_fitZoom( 600.0f, 150.0f, 2.0f, 1.0f, 3.0f ) > ObserverCamera_fitZoom( 600.0f, 200.0f, 2.0f, 1.0f, 3.0f ) );}TEST(pane_lines_grow_with_the_picture_and_the_join_keeps_all_of_them)