Skip to content

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.

fix(gameengine): equal-area director panes on wide screens

Olcay Seyganb4a737aec846
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0e411b574..2794273bb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -750,7 +750,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- 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 eight seconds, leaves after four for one two and a half times the size, and after twenty seconds on the same fight, or as soon as the fight has burnt down to half of what it was, 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 nine 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.
- The Director stands further back. It used to frame the unit the shots came from and miss the tanks fighting just beside it; now it watches every place from 200 paces over your own height, so the whole fight and what is around it are on the screen. Its climbs and descents take a couple of seconds and ease in and out, and gliding over hills no longer pumps the picture in and out over every ridge. A superweapon or a general's power is one shot now: when the screen split to show the silo and the target, the camera used to drop low when the split closed and then spend ten seconds climbing back up, and it comes out of the split at the height it was heading for.
-- 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. It plays the match twice. The first time there is no picture and the game runs as fast as the machine goes, 8,000 frames of a four-player match in 17 seconds, writing down where each fight starts and when each superweapon fires; the second time it films, and the camera is already at a fight four seconds before the first shot instead of arriving halfway through it. When two fights are about to start far apart the screen splits three seconds before the second begins, and only when the first run saw the Director's own fight go on for the whole time the split will be up, so the second picture never sweeps in and straight back out. A skirmish the first run saw come to nothing is not cut to, and neither is a special power that hurts nobody: an Air Force general's spy satellite every minute used to pull the camera to empty ground, where a carpet bomb or an artillery strike still gets it from the launch. Each half keeps its own fight. The main camera used to leave for the second half's fight as it began, and the two halves glided past each other over empty ground and swapped places; now it takes that fight over only once its own is finished, and the second half closes as it does. The two runs compare the whole state of the game every 30 seconds, and if they ever disagree the rest is filmed the old way, finding fights as they happen. A skirmish without `-seed` is handed one, the same for both runs. 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, which stays on the first player's base until something happens instead of gliding across empty ground to another one. 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. In its corner the radar sits flush against the bottom and left of the picture with a thin gold edge on its top and right only, where it used to stand in a heavy frame a few pixels in from the corner. Under each line and round the radar lies a soft band of the Reforged blue. The pictures slide into place first, and only then does the gold draw out from where the lines meet, over most of a second, with the band fading in behind it and the radar's frame tracing its gold round the map once the radar has arrived; going out, the gold pulls back in before the pictures leave. The opening plays it the same way from the first player's full view. While the screen stays cut a bright white-gold light runs out along every line every five seconds, the opening included. At first all of this ran inside the half second the pictures take to slide, and on film the lines were already whole by the third 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 three times as high. A fight that spreads is let out smoothly; one that shrinks does not make the picture pump in and out. The single view rises and settles over a second and a half when it reaches a fight, where it used to glide in for seconds and then step back up in a third of one, and the hand-over between the cut screen and the single view is one camera: the opening's last picture used to jump sideways about fifty paces the moment it became the Director's. When the Director moves onto the second half's fight, that half is the one that stays: it widens to fill the screen and carries straight on as the single view, where the other half used to fill the screen and the camera then cut across the map. The opening frames each player's base the same way. A split holds at least six seconds after its second picture is all the way in and ends once the second fight has burnt down to a quarter of the first, and the picture then stays whole four seconds even for a fight the first run saw coming, so it does not flicker between one and two. Inside a split no picture ever jumps. A split ends the usual way after eighteen seconds, or the moment either half's fight is over or moves on to somewhere else, and only then does the camera go where the next fight is; in an eight-player film one split stayed up for three minutes while the main half was thrown across the map to six new fights, once by 2,900 paces as it was still sweeping in. The two fights have to be further apart than either half's picture is wide once it has risen to fit its fight, so no piece of ground shows in both: at a fixed 660 the two halves of a 1v1 showed the same bridge from neighbouring angles. A crowd beside the Director's fight that the first run saw as part of it does not split the screen either; that was the Director's own fight spreading, and the second half swept in for two seconds before the camera followed it there. 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. The film carries a score bar across the top in the Reforged colours, the match clock in a tab over it and every side in one row, "Team A vs Team B vs" a player alone: a card a player, his colour along its top, his name in that colour, his general (a computer player goes by his general with his difficulty under it, where every one of them used to read "Hard AI"), then on one line his cash and what his army cost, the army's figure labelled so the two never get mixed up; the bar is a fifth shorter than its first cut, 99 rows of a 720p picture for a 1v1 where it took 126. A team's cards sit together under its name and its army's total. Under the whole row is one bar the armies pull on, each player's share in his colour and a gold mark at the middle when two sides play, so whoever is past it is ahead. From five players on the cards stand in two rows, a team never broken across them, and each card keeps to one line, the name and the army's value, so the type stays at its full size: eight players in one row had shrunk it to letters six pixels tall that nobody could read in motion. Eight alone take 103 rows of a 720p picture, a 4v4 with its two team names 139. A dark colour like purple is lightened where it is text, so it reads on the bar's ground, and the gold player's colour gets a dark edge two pixels wide even at 720p so it does not melt into the gold lines. A skirmish can be staged in any shape now, 4v1 or three players alone beside a pair: `-team 4 0` puts slot 4 on team 0. The opening seats teammates next to each other and names their team on their plates, and a split names a team as "Team A" where a player alone keeps his own name. Each picture of the opening names its player on a plate hanging just over his command centre, and the plate stays on the building as the camera rises and the pictures sweep away. The name sits over his general and team in smaller type, and the plate stays wholly inside its picture: in an eight-player opening the lines used to cut it down to "ank General Team A", and in a 4v1 the top one hid under the score bar. Each half of a split names the players in its fight, in a plate inside its own slice clear of the lines and the radar, and while the halves sweep in it rides above its fight, where it used to slide down over it. It is sized from the screen's height and reads the same at 720p and 1080p, and the pictures under it are framed below it, so no base or fight sits behind the bar. 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. It plays the match twice. The first time there is no picture and the game runs as fast as the machine goes, 8,000 frames of a four-player match in 17 seconds, writing down where each fight starts and when each superweapon fires; the second time it films, and the camera is already at a fight four seconds before the first shot instead of arriving halfway through it. When two fights are about to start far apart the screen splits three seconds before the second begins, and only when the first run saw the Director's own fight go on for the whole time the split will be up, so the second picture never sweeps in and straight back out. A skirmish the first run saw come to nothing is not cut to, and neither is a special power that hurts nobody: an Air Force general's spy satellite every minute used to pull the camera to empty ground, where a carpet bomb or an artillery strike still gets it from the launch. Each half keeps its own fight. The main camera used to leave for the second half's fight as it began, and the two halves glided past each other over empty ground and swapped places; now it takes that fight over only once its own is finished, and the second half closes as it does. The two runs compare the whole state of the game every 30 seconds, and if they ever disagree the rest is filmed the old way, finding fights as they happen. A skirmish without `-seed` is handed one, the same for both runs. The film opens on every player at once: the screen cut into one picture per player along lines that meet round the radar, two players on a diagonal and four on an X, each picture on that player's base. Every picture gets the same share of the screen, whatever its shape: the lines used to stand at a fixed 45 degrees, and on a 16:9 screen three players got a sliver of 14% at the top and two big halves below, and at 21:9 the sliver was 10%. Now each has a third. Seven seconds in they sweep away to the Director's single view, which stays on the first player's base until something happens instead of gliding across empty ground to another one. 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 the screen's 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. In its corner the radar sits flush against the bottom and left of the picture with a thin gold edge on its top and right only, where it used to stand in a heavy frame a few pixels in from the corner. Under each line and round the radar lies a soft band of the Reforged blue. The pictures slide into place first, and only then does the gold draw out from where the lines meet, over most of a second, with the band fading in behind it and the radar's frame tracing its gold round the map once the radar has arrived; going out, the gold pulls back in before the pictures leave. The opening plays it the same way from the first player's full view. While the screen stays cut a bright white-gold light runs out along every line every five seconds, the opening included. At first all of this ran inside the half second the pictures take to slide, and on film the lines were already whole by the third 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 three times as high. A fight that spreads is let out smoothly; one that shrinks does not make the picture pump in and out. The single view rises and settles over a second and a half when it reaches a fight, where it used to glide in for seconds and then step back up in a third of one, and the hand-over between the cut screen and the single view is one camera: the opening's last picture used to jump sideways about fifty paces the moment it became the Director's. When the Director moves onto the second half's fight, that half is the one that stays: it widens to fill the screen and carries straight on as the single view, where the other half used to fill the screen and the camera then cut across the map. The opening frames each player's base the same way. A split holds at least six seconds after its second picture is all the way in and ends once the second fight has burnt down to a quarter of the first, and the picture then stays whole four seconds even for a fight the first run saw coming, so it does not flicker between one and two. Inside a split no picture ever jumps. A split ends the usual way after eighteen seconds, or the moment either half's fight is over or moves on to somewhere else, and only then does the camera go where the next fight is; in an eight-player film one split stayed up for three minutes while the main half was thrown across the map to six new fights, once by 2,900 paces as it was still sweeping in. The two fights have to be further apart than either half's picture is wide once it has risen to fit its fight, so no piece of ground shows in both: at a fixed 660 the two halves of a 1v1 showed the same bridge from neighbouring angles. A crowd beside the Director's fight that the first run saw as part of it does not split the screen either; that was the Director's own fight spreading, and the second half swept in for two seconds before the camera followed it there. 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. The film carries a score bar across the top in the Reforged colours, the match clock in a tab over it and every side in one row, "Team A vs Team B vs" a player alone: a card a player, his colour along its top, his name in that colour, his general (a computer player goes by his general with his difficulty under it, where every one of them used to read "Hard AI"), then on one line his cash and what his army cost, the army's figure labelled so the two never get mixed up; the bar is a fifth shorter than its first cut, 99 rows of a 720p picture for a 1v1 where it took 126. A team's cards sit together under its name and its army's total. Under the whole row is one bar the armies pull on, each player's share in his colour and a gold mark at the middle when two sides play, so whoever is past it is ahead. From five players on the cards stand in two rows, a team never broken across them, and each card keeps to one line, the name and the army's value, so the type stays at its full size: eight players in one row had shrunk it to letters six pixels tall that nobody could read in motion. Eight alone take 103 rows of a 720p picture, a 4v4 with its two team names 139. A dark colour like purple is lightened where it is text, so it reads on the bar's ground, and the gold player's colour gets a dark edge two pixels wide even at 720p so it does not melt into the gold lines. A skirmish can be staged in any shape now, 4v1 or three players alone beside a pair: `-team 4 0` puts slot 4 on team 0. The opening seats teammates next to each other and names their team on their plates, and a split names a team as "Team A" where a player alone keeps his own name. Each picture of the opening names its player on a plate hanging just over his command centre, and the plate stays on the building as the camera rises and the pictures sweep away. The name sits over his general and team in smaller type, and the plate stays wholly inside its picture: in an eight-player opening the lines used to cut it down to "ank General Team A", and in a 4v1 the top one hid under the score bar. Each half of a split names the players in its fight, in a plate inside its own slice clear of the lines and the radar, and while the halves sweep in it rides above its fight, where it used to slide down over it. It is sized from the screen's height and reads the same at 720p and 1080p, and the pictures under it are framed below it, so no base or fight sits behind the bar. 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.
- The film shows who fired what. When a player uses a general's power, a small flag drops out from under his card in the score bar carrying the power's icon, hangs there four seconds and pulls back up; a superweapon's flag is edged in gold. A power gets its flag only once it hits somebody, the same rule the camera follows, so an Air Force general's spy satellite never hangs one, and a player who fires two in quick succession has them wait their turn under his card. A player knocked out no longer blinks out of the bar. His card flashes red with a line drawn through his name, and a second later it closes while the cards beside it slide into the room it leaves, where the whole row used to jump on the frame he lost. At the same moment a banner opens across the lower part of the picture with his name and general under a red Defeated. The match no longer cuts off on the frame the last card falls, either: the film runs three and a half seconds past the decision, so the last defeat plays out and the winner's banner comes up in gold beneath it.
- 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.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
index a1550b341..c889f7390 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
@@ -255,13 +255,16 @@ Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const
/// would show the same ground
Bool ObserverCamera_holdSplit( Bool split, Real firstHeat, Real secondHeat, Real apart, Real needed, UnsignedInt framesSince );
-/// -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
+/// -directorrecord's panes. The picture is cut by rays from one point, 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 rays for count panes on a width by height picture, ascending from 0 to 360, so that every
+/// pane's wedge of it is as big as every other's; 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, Int width, Int height );
+/// the angle from the middle of a width by height picture at which a ray sweeping counterclockwise
+/// from 0 has covered share of it, 0 to 1
+Real ObserverCamera_angleForShare( Real share, Int width, Int height );
/// 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
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
index 688914122..7dce20011 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
@@ -542,26 +542,67 @@ Bool ObserverCamera_holdSplit( Bool split, Real firstHeat, Real secondHeat, Real
}
//-------------------------------------------------------------------------------------------------
-/** 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. */
+/** How much of a picture half w wide and half h high round its middle a ray sweeping counterclockwise
+ * from 0 has covered by angle degrees. In each quarter the swept part is a triangle against the near
+ * side until the ray reaches the corner, and the whole quarter less a triangle against the far side
+ * after; the quarters that start upright are the same with the sides swapped. */
+//-------------------------------------------------------------------------------------------------
+static Real sweptArea( Real angle, Real halfWidth, Real halfHeight )
+{
+ const Int quarter = min( (Int)( angle / 90.0f ), 3 );
+ const Real within = ( angle - quarter * 90.0f ) * PI / 180.0f;
+ const Real along = quarter % 2 == 0 ? halfWidth : halfHeight;
+ const Real across = quarter % 2 == 0 ? halfHeight : halfWidth;
+ Real part;
+ if( within <= atan2f( across, along ) )
+ part = 0.5f * along * along * tanf( within );
+ else
+ part = along * across - 0.5f * across * across * tanf( PI * 0.5f - within );
+ return quarter * halfWidth * halfHeight + part;
+}
+
+//-------------------------------------------------------------------------------------------------
+Real ObserverCamera_angleForShare( Real share, Int width, Int height )
+{
+ const Real halfWidth = width * 0.5f;
+ const Real halfHeight = height * 0.5f;
+ const Real wanted = share * 4.0f * halfWidth * halfHeight;
+ Real low = 0.0f;
+ Real high = 360.0f;
+ for( Int step = 0; step < 40; step++ )
+ {
+ const Real tried = ( low + high ) * 0.5f;
+ if( sweptArea( tried, halfWidth, halfHeight ) < wanted )
+ low = tried;
+ else
+ high = tried;
+ }
+ return ( low + high ) * 0.5f;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Each layout is where its rays would stand on a round picture, where angle and area are one; on the
+ * real picture each ray goes where it covers the same share of it. Two panes are the diagonal
+ * corner to corner, its upper left half the radar's; four are both diagonals. Three is a Y, the top
+ * wedge and two below; the odd counts keep a ray straight down, the even ones a pair of opposite
+ * rays. At a fixed 45 degrees a 16:9 Y gave its top pane 14% of the picture and each of the others
+ * 43%; every pane now has its share, a third of it for three. */
//-------------------------------------------------------------------------------------------------
-Int ObserverCamera_paneLayout( Int count, Real *rays )
+Int ObserverCamera_paneLayout( Int count, Real *rays, Int width, Int height )
{
static const Real two[] = { 45, 225 };
- static const Real three[] = { 45, 135, 270 };
+ static const Real three[] = { 30, 150, 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 five[] = { 54, 126, 198, 270, 342 };
+ static const Real six[] = { 30, 90, 150, 210, 270, 330 };
+ static const Real seven[] = { 12.857f, 64.286f, 115.714f, 167.143f, 218.571f, 270, 321.429f };
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 ];
+ rays[ ray ] = ObserverCamera_angleForShare( layouts[ count - 2 ][ ray ] / 360.0f, width, height );
return count;
}
@@ -1963,7 +2004,7 @@ void ObserverCamera::measureScreenGround( void )
m_screenGround = sqrtf( dx * dx + dy * dy );
Real rays[ OBSERVER_MOST_PANES ];
- const Int count = ObserverCamera_paneLayout( 2, rays );
+ const Int count = ObserverCamera_paneLayout( 2, rays, width, height );
Coord2D centres[ OBSERVER_MOST_PANES ];
Real radii[ OBSERVER_MOST_PANES ];
ObserverCamera_paneCircles( rays, count, width, height, m_radarHalf, m_broadcastTop, centres, radii );
@@ -2141,7 +2182,7 @@ void ObserverCamera::advancePanes( UnsignedInt frame )
found[ pane ] = m_panePlayers[ order[ pane ] ];
for( Int pane = 0; pane < players; pane++ )
m_panePlayers[ pane ] = found[ pane ];
- m_paneCount = ObserverCamera_paneLayout( players, m_paneRays );
+ m_paneCount = ObserverCamera_paneLayout( players, m_paneRays, TheDisplay->getWidth(), TheDisplay->getHeight() );
// the opening starts on the first view whole and opens into its panes like a split
if( m_paneCount >= 2 )
{
@@ -2151,7 +2192,7 @@ void ObserverCamera::advancePanes( UnsignedInt frame )
}
else if( m_split )
{
- m_paneCount = ObserverCamera_paneLayout( 2, m_paneRays );
+ m_paneCount = ObserverCamera_paneLayout( 2, m_paneRays, TheDisplay->getWidth(), TheDisplay->getHeight() );
next = PANES_RADAR_OUT;
}
if( next != PANES_NONE )
diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.inc
index 188c5155e..f666bd2df 100644
--- a/GeneralsMD/Code/Tests/test_observer_camera.inc
+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc
@@ -422,36 +422,83 @@ TEST(the_recording_splits_only_beside_a_real_fight)
CHECK( !ObserverCamera_secondPlace( none, first, 660.0f, &second, &heat ) );
}
-TEST(every_pane_layout_cuts_on_45_degree_rays)
+static Real paneArea( const Real *rays, Int count, Int pane, Int width, Int height )
{
- CHECK_EQ( ObserverCamera_paneLayout( 1, NULL ), 0 );
- for( Int count = 2; count <= OBSERVER_MOST_PANES; count++ )
+ const Coord2D middle = { width * 0.5f, height * 0.5f };
+ Coord2D vertices[ 8 ];
+ const Int found = ObserverCamera_panePolygon( rays, count, pane, middle, width, height, vertices );
+ // the polygon's corners come unordered: sort them round the middle of the wedge before the shoelace
+ Coord2D centroid = { 0.0f, 0.0f };
+ for( Int vertex = 0; vertex < found; vertex++ )
+ {
+ centroid.x += vertices[ vertex ].x / found;
+ centroid.y += vertices[ vertex ].y / found;
+ }
+ std::vector< std::pair< Real, Coord2D > > round;
+ for( Int vertex = 0; vertex < found; vertex++ )
+ round.push_back( std::make_pair( atan2f( vertices[ vertex ].y - centroid.y, vertices[ vertex ].x - centroid.x ), vertices[ vertex ] ) );
+ std::sort( round.begin(), round.end(), []( const std::pair< Real, Coord2D > &a, const std::pair< Real, Coord2D > &b ) { return a.first < b.first; } );
+ Real twice = 0.0f;
+ for( size_t vertex = 0; vertex < round.size(); vertex++ )
+ {
+ const Coord2D &a = round[ vertex ].second;
+ const Coord2D &b = round[ ( vertex + 1 ) % round.size() ].second;
+ twice += a.x * b.y - b.x * a.y;
+ }
+ return fabsf( twice ) * 0.5f;
+}
+
+TEST(every_pane_layout_gives_each_pane_an_equal_share_of_a_wide_picture)
+{
+ CHECK_EQ( ObserverCamera_paneLayout( 1, NULL, 1280, 720 ), 0 );
+ const Int sizes[ 2 ][ 2 ] = { { 1280, 720 }, { 2560, 1080 } };
+ for( Int size = 0; size < 2; size++ )
{
- Real rays[ OBSERVER_MOST_PANES ];
- CHECK_EQ( ObserverCamera_paneLayout( count, rays ), count );
- for( Int ray = 0; ray < count; ray++ )
+ const Int width = sizes[ size ][ 0 ];
+ const Int height = sizes[ size ][ 1 ];
+ for( Int count = 2; count <= OBSERVER_MOST_PANES; count++ )
{
- CHECK_EQ( (Int)rays[ ray ] % 45, 0 );
- CHECK( ray == 0 || rays[ ray ] > rays[ ray - 1 ] );
+ Real rays[ OBSERVER_MOST_PANES ];
+ CHECK_EQ( ObserverCamera_paneLayout( count, rays, width, height ), count );
+ const Real share = (Real)width * height / count;
+ for( Int ray = 0; ray < count; ray++ )
+ {
+ CHECK( ray == 0 || rays[ ray ] > rays[ ray - 1 ] );
+ // no wedge wider than half the turn, which the polygon and the exit rely on
+ const Real next = ray + 1 < count ? rays[ ray + 1 ] : rays[ 0 ] + 360.0f;
+ CHECK( next - rays[ ray ] <= 180.01f );
+ const Real area = paneArea( rays, count, ray, width, height );
+ CHECK( area > share * 0.95f && area < share * 1.05f );
+ }
}
}
- // more players than panes share the eight
+ // the old fixed 45 degrees gave a 16:9 Y's top pane 14% of the picture; now its rays leave the
+ // sides 120 rows down, and the bottom ray stays straight down
Real rays[ OBSERVER_MOST_PANES ];
- CHECK_EQ( ObserverCamera_paneLayout( 12, rays ), (Int)OBSERVER_MOST_PANES );
+ ObserverCamera_paneLayout( 3, rays, 1280, 720 );
+ CHECK_NEAR( rays[ 0 ], 20.56f, 0.05f );
+ CHECK_NEAR( rays[ 1 ], 159.44f, 0.05f );
+ CHECK_NEAR( rays[ 2 ], 270.0f, 0.05f );
+ // two and four panes run corner to corner
+ ObserverCamera_paneLayout( 4, rays, 2560, 1080 );
+ CHECK_NEAR( rays[ 0 ], atan2f( 540.0f, 1280.0f ) * 180.0f / PI, 0.05f );
+ // more players than panes share the eight
+ CHECK_EQ( ObserverCamera_paneLayout( 12, rays, 1280, 720 ), (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 );
+ ObserverCamera_paneLayout( 2, rays, 1280, 720 );
+ // the diagonal corner to corner of 1280x720 drops 56 rows in 100 columns: pane 0 above it on
+ // the left, pane 1 below it
+ CHECK_EQ( ObserverCamera_paneOf( 740.0f, 300.0f, 640.0f, 360.0f, rays, 2 ), 0 );
+ CHECK_EQ( ObserverCamera_paneOf( 740.0f, 308.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 );
+ ObserverCamera_paneLayout( 4, rays, 1280, 720 );
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 );
@@ -461,9 +508,10 @@ TEST(a_pixel_lies_in_the_wedge_counter_clockwise_of_its_ray)
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 );
+ ObserverCamera_paneLayout( 2, rays, 1280, 720 );
+ // the diagonal has to clear the bottom right corner, 639.5 by 359.5 from the middle, square to the
+ // diagonal's own slope of 360 over 640: 2 * 639.5 * 359.5 / sqrt( 640^2 + 360^2 )
+ CHECK_NEAR( ObserverCamera_paneExit( rays, 2, 1280, 720 ), 626.6f, 2.0f );
const Coord2D away = ObserverCamera_paneExitDirection( rays );
CHECK( away.x > 0.0f && away.y > 0.0f );
}
@@ -475,30 +523,29 @@ TEST(a_pane_circle_is_the_largest_its_wedge_holds)
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 );
+ // two panes: the upper left half is the triangle on the top and left edges and the diagonal, its
+ // circle the incircle, area over half the perimeter: 460800 / 1734.3; pane 1's is its mirror
+ ObserverCamera_paneLayout( 2, rays, 1280, 720 );
ObserverCamera_paneCircles( rays, 2, 1280, 720, noRadar, 0.0f, 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[ 0 ], 265.7f, 8.0f );
+ CHECK_NEAR( centres[ 0 ].x, 265.7f, 15.0f );
+ CHECK_NEAR( centres[ 0 ].y, 265.7f, 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 );
+ // both diagonals: the top wedge is the triangle on the whole top edge to the middle, its incircle
+ // 230400 / 1374.3; the left one stands on the left edge, 230400 / 1094.3
+ ObserverCamera_paneLayout( 4, rays, 1280, 720 );
ObserverCamera_paneCircles( rays, 4, 1280, 720, noRadar, 0.0f, centres, radii );
- CHECK_NEAR( radii[ 0 ], 149.1f, 8.0f );
+ CHECK_NEAR( radii[ 0 ], 167.6f, 8.0f );
CHECK_NEAR( centres[ 0 ].x, 640.0f, 15.0f );
- CHECK_NEAR( radii[ 1 ], 265.1f, 8.0f );
+ CHECK_NEAR( radii[ 1 ], 210.5f, 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_paneLayout( 3, rays, 1280, 720 );
ObserverCamera_paneCircles( rays, 3, 1280, 720, noRadar, 0.0f, centres, radii );
for( Int pane = 0; pane < 3; pane++ )
{
@@ -509,16 +556,16 @@ TEST(a_pane_circle_is_the_largest_its_wedge_holds)
}
// the framed radar in the middle takes room from the two pane circle, which reached its corner
- ObserverCamera_paneLayout( 2, rays );
+ ObserverCamera_paneLayout( 2, rays, 1280, 720 );
const Coord2D radar = { 150.0f, 100.0f };
ObserverCamera_paneCircles( rays, 2, 1280, 720, radar, 0.0f, centres, radii );
- CHECK( radii[ 0 ] < 285.0f );
+ CHECK( radii[ 0 ] < 255.0f );
CHECK( radii[ 0 ] > 150.0f );
// the score bar's rows at the top are no pane's: the upper circle stays below them
ObserverCamera_paneCircles( rays, 2, 1280, 720, noRadar, 90.0f, centres, radii );
CHECK( centres[ 0 ].y - radii[ 0 ] >= 90.0f - 6.0f );
- CHECK( radii[ 0 ] < 285.0f );
+ CHECK( radii[ 0 ] < 258.0f );
}
TEST(a_pane_label_hangs_as_high_in_its_circle_as_the_circle_holds_it)
@@ -590,21 +637,21 @@ TEST(a_pane_whose_top_leaves_the_map_is_moved_in_by_the_top_alone)
TEST(a_pane_shows_its_wedge_cut_by_the_screen)
{
Real rays[ OBSERVER_MOST_PANES ];
- ObserverCamera_paneLayout( 2, rays );
+ ObserverCamera_paneLayout( 3, rays, 1280, 720 );
const Coord2D middle = { 640.0f, 360.0f };
Coord2D vertices[ 8 ];
- // the upper left half: the meeting point, the two left corners and where the diagonal leaves the
- // top and the bottom
- CHECK_EQ( ObserverCamera_panePolygon( rays, 2, 0, middle, 1280, 720, vertices ), 5 );
- Bool top = FALSE;
- Bool bottom = FALSE;
+ // a Y's top pane: the meeting point, the two top corners and where its rays leave the two sides,
+ // 240 rows above the middle
+ CHECK_EQ( ObserverCamera_panePolygon( rays, 3, 0, middle, 1280, 720, vertices ), 5 );
+ Bool right = FALSE;
+ Bool left = FALSE;
for( Int vertex = 0; vertex < 5; vertex++ )
{
- top = top || ( fabs( vertices[ vertex ].x - 1000.0f ) < 0.5f && fabs( vertices[ vertex ].y ) < 0.5f );
- bottom = bottom || ( fabs( vertices[ vertex ].x - 280.0f ) < 0.5f && fabs( vertices[ vertex ].y - 720.0f ) < 0.5f );
+ right = right || ( fabs( vertices[ vertex ].x - 1280.0f ) < 0.5f && fabs( vertices[ vertex ].y - 120.0f ) < 1.0f );
+ left = left || ( fabs( vertices[ vertex ].x ) < 0.5f && fabs( vertices[ vertex ].y - 120.0f ) < 1.0f );
}
- CHECK( top );
- CHECK( bottom );
+ CHECK( right );
+ CHECK( left );
// with no panes it is the whole screen
CHECK_EQ( ObserverCamera_panePolygon( rays, 1, 0, middle, 1280, 720, vertices ), 4 );
}