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.

feat(gameengine): director score bar in one row and a camera that does not step

Olcay Seyganf6b199a24fd2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b001bbb91..47c8f0baa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -749,7 +749,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. 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. 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 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. 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: every player's name in his own colour, his general, his cash and what his army cost (a computer player goes by his general with his difficulty beside it, where every one of them used to read "Hard AI"), the match clock in the middle, and under it one bar the two sides' armies pull on, each player's share in his colour and a gold mark at the middle, so whoever is past it is ahead. Teammates sit together on it with their team's army total under them, a free for all deals its players to both sides, and with three sides or more the bar is every side's share end to end. Eight players fit at 720p: a side of more than three rows sets them smaller and drops the general column. 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 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. 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. 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. 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 his cash and what his army cost, each beside its label so the two never get mixed up. 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. The type gets smaller as players are added, and eight alone or a 4v4 fill the width of a 720p picture without running off it. 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, 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.h
index 333569b7c..0f7d68a59 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
@@ -200,6 +200,9 @@ Coord2D ObserverCamera_keepInMap( const Coord2D &place, const Coord2D *corners,
/// it jumps there and stops
ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocation &to, Real elapsedSeconds, Real smoothSeconds,
Real topSpeed, ObserverCameraVelocity *velocity );
+/// the director's height over the watcher's own, one step from from towards to on a spring that
+/// gathers and slows over about 1.6 s; a cut takes it there at once
+Real ObserverCamera_easeHeight( Real from, Real to, Real *velocity, Real elapsedSeconds, Bool cut );
/// -directorrecord's second fight: the hottest place among the hits more than needed from first, so
/// the two halves of a split screen never show the same ground. FALSE when nothing that far was hit
Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const Coord2D &first, Real needed, Coord2D *place, Real *heat );
@@ -236,10 +239,17 @@ void ObserverCamera_paneCircles( const Real *rays, Int count, Int width, Int hei
/// holds all of it, so it stays inside the pane and clear of its lines; the circle's middle row when
/// it is too wide for that
Real ObserverCamera_paneLabelTop( const Coord2D &centre, Real radius, Real width, Real height );
-/// the score bar's column, 0 left and 1 right, for each block of players, given each block's size:
-/// two blocks face each other; more go one by one to the column with fewer rows, a block of two or
-/// more counting the row of its total as well
-std::vector< Int > ObserverCamera_blockColumns( const std::vector< Int > &sizes );
+/// the score bar's one row of cards, a card a player, each block of players (a team, or one alone)
+/// side by side with versusWidth between two blocks for the "vs" and cardGap between two cards of a
+/// block: every card's left and every block's left from the row's, and the row's whole width
+Int ObserverCamera_cardRow( const std::vector< Int > &sizes, Int cardWidth, Int cardGap, Int versusWidth,
+ std::vector< Int > *cardLefts, std::vector< Int > *blockLefts );
+/// the first of steps sizes, largest first, whose row of cards is no wider than room; the last when
+/// none is
+Int ObserverCamera_cardStep( const std::vector< Int > &sizes, const Int *cardWidths, const Int *cardGaps,
+ const Int *versusWidths, Int steps, Int room );
+/// the widest card a row of these blocks can have and still fit room
+Int ObserverCamera_cardWidthIn( const std::vector< Int > &sizes, Int cardGap, Int versusWidth, Int room );
/// values cut into width pixels in proportion, the rounding handed to the largest remainders so the
/// pieces fill width exactly; all zero when the values add up to nothing
std::vector< Int > ObserverCamera_barShares( const std::vector< Int > &values, Int width );
@@ -390,6 +400,7 @@ private:
Real zoomInMap( Int pane, const Coord2D &subject, Real nearest, Real wanted );
Coord2D placePane( Int pane, const Coord2D &subject, const Coord2D &pixel, Real zoom );
void logPanes( UnsignedInt frame ) const;
+ void logHandover( const ViewLocation &step, const ViewLocation &placed );
void pickIntroBases( void );
Region2D mapRegion( void ) const;
void updateSplit( void );
@@ -437,6 +448,12 @@ private:
Bool m_heightDriven; ///< the director has the camera's height above the ground
Real m_handHeight; ///< the watcher's own height, the wheel's turns while driven added in
Real m_drivenHeight; ///< the height the director left the view at last frame
+ Real m_heightExtra; ///< the height over the watcher's own the director has eased to so far
+ Real m_heightExtraVelocity; ///< how fast that height is moving, for its spring
+ Bool m_panesHeldZoom; ///< last frame's panes set the zoom outright
+ Real m_lastZoom; ///< the view's zoom at the last update, for the zoom jump log
+ Bool m_lastCut; ///< the last update cut
+ UnsignedInt m_handoverLogUntil; ///< the frame the per-frame hand-over log stops at
Coord3D m_drivenTo; ///< where this put the camera last frame, inside the view's constraint
UnsignedInt m_lastUpdate;
ObserverCameraVelocity m_velocity;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 4c8c14483..89c68adb9 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -10540,15 +10540,11 @@ static const char *const BROADCAST_NUMBERS = "Consolas";
static const Real BROADCAST_ROWS = 720.0f;
static const Int BROADCAST_NAME_POINTS = 11;
static const Int BROADCAST_COMPACT_POINTS = 8;
-/// a column with more rows than this, totals counted, sets its rows compact
-static const Int BROADCAST_FULL_ROWS = 3;
static const Int BROADCAST_SIDE_POINTS = 9;
static const Int BROADCAST_HEAD_POINTS = 7;
static const Int BROADCAST_CLOCK_POINTS = 16;
static const Real BROADCAST_PAD = 8.0f;
static const Real BROADCAST_GAP = 10.0f;
-static const Real BROADCAST_SWATCH = 4.0f;
-static const Real BROADCAST_ROW_GAP = 3.0f;
static const Real BROADCAST_RULE = 2.0f;
static const Real BROADCAST_TUG = 6.0f;
static const Int THOUSANDS = 3;
@@ -10694,7 +10690,7 @@ DisplayString *InGameUI::broadcastText( const std::string &key, const UnicodeStr
return string;
}
-/// one player's row of the score bar
+/// one player's card of the score bar
struct BroadcastRow
{
const SpectatorStats *stats;
@@ -10705,13 +10701,22 @@ struct BroadcastRow
DisplayString *army;
};
-//-------------------------------------------------------------------------------------------------
-/** The score bar hangs from the top edge in the middle: the match clock in a box of its own, one row a
- * player either side of it, the swatch of his colour and his name on the outside, his side, then his
- * cash and the cost of everything he has standing that is not a building nearest the clock. Two
- * teams face each other across it; in a free for all the first half of the list is on the left.
- * Under the rows the armies pull on one bar: the left's from the left edge, the right's from the
- * right, each player his colour, gold at the middle so the side ahead is the one past it. While
+/// the score bar's sizes, largest first, in 720 line points and pixels: a row of cards takes the first
+/// that fits the screen's width
+static const Int BROADCAST_CARD_STEPS = 4;
+static const Int BROADCAST_CARD_NAME_POINTS[ BROADCAST_CARD_STEPS ] = { 11, 10, 9, 8 };
+static const Int BROADCAST_CARD_DETAIL_POINTS[ BROADCAST_CARD_STEPS ] = { 9, 8, 8, 7 };
+static const Real BROADCAST_CARD_PAD[ BROADCAST_CARD_STEPS ] = { 6.0f, 5.0f, 4.0f, 3.0f };
+/// the house colour along a card's top
+static const Real BROADCAST_CARD_STRIP = 3.0f;
+
+//-------------------------------------------------------------------------------------------------
+/** The score bar hangs from the top edge in the middle: the match clock in a tab of its own, and under
+ * it every side in one row, "Team A vs Team B vs a player alone", a card a player with his name in
+ * his colour, his general or difficulty, his cash and the cost of everything he has standing that is
+ * not a building. A team's cards sit together under its name and its armies' total. Under the row
+ * the armies pull on one bar, each player his colour in the cards' order, gold at the middle when
+ * two sides play so the side ahead is the one past it. While
* a split is up each pane carries a plate in the top of its circle, inside its wedge and clear of
* the lines and the radar, naming the fight's players.
* Everything is read off the players and their objects; nothing here writes the logic. */
@@ -10727,14 +10732,11 @@ void InGameUI::drawDirectorBroadcast( void )
{ return a.team != b.team ? a.team < b.team : a.player->getPlayerIndex() < b.player->getPlayerIndex(); } );
const Int pad = broadcastPixels( BROADCAST_PAD );
- const Int gap = broadcastPixels( BROADCAST_GAP );
- const Int swatch = broadcastPixels( BROADCAST_SWATCH );
- const Int rowGap = broadcastPixels( BROADCAST_ROW_GAP );
const Int rule = broadcastPixels( BROADCAST_RULE );
const Int tug = broadcastPixels( BROADCAST_TUG );
- // a block is one side: a team, or a player on his own. Two face each other; more are dealt to the
- // two columns whole, so teammates stay together, and a team of two or more has a row of its total
+ // a block is one side: a team, or a player on his own, its players' cards side by side and a "vs"
+ // between two blocks
std::vector< Int > blockFirst, blockSizes, blockArmies;
for( size_t index = 0; index < players.size(); index++ )
{
@@ -10748,206 +10750,198 @@ void InGameUI::drawDirectorBroadcast( void )
blockArmies.back() += players[ index ].army;
}
const Int blocks = (Int)blockSizes.size();
- const std::vector< Int > columns = ObserverCamera_blockColumns( blockSizes );
- // a column of more than three rows goes compact, smaller and without the side column: four rows
- // a side and a total at full size took a third of a 720 row picture
- Int columnRows[ 2 ] = { 0, 0 };
- for( Int block = 0; block < blocks; block++ )
- columnRows[ columns[ block ] ] += blockSizes[ block ] + ( blockSizes[ block ] >= 2 ? 1 : 0 );
- const Bool compact = max( columnRows[ 0 ], columnRows[ 1 ] ) > BROADCAST_FULL_ROWS;
- const std::string size = compact ? "compact" : "";
- const Int rowPoints = broadcastPoints( compact ? BROADCAST_COMPACT_POINTS : BROADCAST_NAME_POINTS );
- std::vector< BroadcastRow > rows;
- Int nameWidth = 0, sideWidth = 0, cashWidth = 0, armyWidth = 0, rowHeight = 0;
- for( size_t index = 0; index < players.size(); index++ )
+ // every card's text at a size, and the card width it needs: the widest of the name, the general or
+ // difficulty, a label and a six digit number, and a team header spread over its block's cards.
+ // Each size keeps strings of its own, since a string keeps the font it was made with
+ std::vector< BroadcastRow > rows( players.size() );
+ std::vector< DisplayString * > teamNames( blocks, NULL ), teamTotals( blocks, NULL );
+ DisplayString *cashHead = NULL;
+ DisplayString *armyHead = NULL;
+ DisplayString *versusText = NULL;
+ auto buildCards = [ & ]( Int step ) -> Int
+ {
+ const std::string size = "card" + std::to_string( step ) + ":";
+ const Int cardPad = broadcastPixels( BROADCAST_CARD_PAD[ step ] );
+ const Int namePoints = broadcastPoints( BROADCAST_CARD_NAME_POINTS[ step ] );
+ const Int detailPoints = broadcastPoints( BROADCAST_CARD_DETAIL_POINTS[ step ] );
+ const Int labelPoints = broadcastPoints( BROADCAST_HEAD_POINTS );
+ cashHead = broadcastText( size + "cashhead", TheGameText->fetch( "GUI:HudStatCash" ), BROADCAST_WORDS, labelPoints, FALSE );
+ armyHead = broadcastText( size + "armyhead", TheGameText->fetch( "GUI:HudStatArmy" ), BROADCAST_WORDS, labelPoints, FALSE );
+ versusText = broadcastText( size + "versus", UnicodeString( u"vs" ), BROADCAST_WORDS, detailPoints, FALSE );
+ DisplayString *widest = broadcastText( size + "widest", broadcastNumber( "$", BROADCAST_WIDEST ), BROADCAST_NUMBERS, detailPoints, TRUE );
+ Int width = 0, height = 0, labelWidth = 0, widestWidth = 0;
+ cashHead->getSize( &labelWidth, &height );
+ armyHead->getSize( &width, &height );
+ labelWidth = max( labelWidth, width );
+ widest->getSize( &widestWidth, &height );
+ Int content = labelWidth + cardPad + widestWidth;
+ for( size_t index = 0; index < players.size(); index++ )
+ {
+ const SpectatorStats &stats = players[ index ];
+ const std::string seat = size + std::to_string( stats.player->getPlayerIndex() );
+ BroadcastRow &row = rows[ index ];
+ row.stats = &stats;
+ row.color = clientPlayerColor( stats.player );
+ row.name = broadcastText( "name" + seat, broadcastName( stats.player ), BROADCAST_WORDS, namePoints, TRUE );
+ row.side = broadcastText( "side" + seat, broadcastSide( stats.player ), BROADCAST_WORDS, detailPoints, FALSE );
+ row.cash = broadcastText( "cash" + seat, broadcastNumber( "$", stats.cash ), BROADCAST_NUMBERS, detailPoints, TRUE );
+ row.army = broadcastText( "army" + seat, broadcastNumber( "$", stats.army ), BROADCAST_NUMBERS, detailPoints, TRUE );
+ row.name->getSize( &width, &height );
+ content = max( content, width );
+ row.side->getSize( &width, &height );
+ content = max( content, width );
+ }
+ for( Int block = 0; block < blocks; block++ )
+ {
+ if( blockSizes[ block ] < 2 )
+ continue;
+ const std::string key = size + std::to_string( block );
+ teamNames[ block ] = broadcastText( "teamname" + key, broadcastTeamName( players, players[ blockFirst[ block ] ].team ), BROADCAST_WORDS,
+ detailPoints, TRUE );
+ teamTotals[ block ] = broadcastText( "teamtotal" + key, broadcastNumber( "$", blockArmies[ block ] ), BROADCAST_NUMBERS, detailPoints, TRUE );
+ // the total measured as six digits, as the cards' numbers are, so the width holds still
+ Int nameWidth = 0;
+ teamNames[ block ]->getSize( &nameWidth, &height );
+ const Int header = nameWidth + cardPad + widestWidth;
+ const Int cards = blockSizes[ block ];
+ content = max( content, ( header - ( cards - 1 ) * cardPad + cards - 1 ) / cards - 2 * cardPad );
+ }
+ return content + 2 * cardPad;
+ };
+
+ // the largest size whose row fits the screen less the bar's padding; past the smallest the cards are
+ // cut to fit, so the bar never runs off the picture
+ Int cardWidths[ BROADCAST_CARD_STEPS ], cardGaps[ BROADCAST_CARD_STEPS ], versusWidths[ BROADCAST_CARD_STEPS ];
+ for( Int step = 0; step < BROADCAST_CARD_STEPS; step++ )
{
- const SpectatorStats &stats = players[ index ];
- const std::string seat = size + std::to_string( stats.player->getPlayerIndex() );
- BroadcastRow row;
- row.stats = &stats;
- row.color = clientPlayerColor( stats.player );
- row.name = broadcastText( "name" + seat, broadcastName( stats.player ), BROADCAST_WORDS, rowPoints, TRUE );
- row.side = broadcastText( "side" + seat, compact ? UnicodeString::TheEmptyString : broadcastSide( stats.player ), BROADCAST_WORDS,
- broadcastPoints( BROADCAST_SIDE_POINTS ), FALSE );
- row.cash = broadcastText( "cash" + seat, broadcastNumber( "$", stats.cash ), BROADCAST_NUMBERS, rowPoints, TRUE );
- row.army = broadcastText( "army" + seat, broadcastNumber( "", stats.army ), BROADCAST_NUMBERS, rowPoints, TRUE );
- Int width = 0, height = 0;
- row.name->getSize( &width, &height );
- nameWidth = max( nameWidth, width );
- rowHeight = max( rowHeight, height );
- row.side->getSize( &width, &height );
- sideWidth = max( sideWidth, width );
- row.cash->getSize( &width, &height );
- cashWidth = max( cashWidth, width );
- rowHeight = max( rowHeight, height );
- row.army->getSize( &width, &height );
- armyWidth = max( armyWidth, width );
- rows.push_back( row );
+ cardWidths[ step ] = buildCards( step );
+ cardGaps[ step ] = broadcastPixels( BROADCAST_CARD_PAD[ step ] );
+ Int versusWidth = 0, versusHeight = 0;
+ versusText->getSize( &versusWidth, &versusHeight );
+ versusWidths[ step ] = versusWidth + 4 * cardGaps[ step ];
}
-
- // each team's name and its army's total; the total is measured into the army column
- std::vector< DisplayString * > teamNames( blocks, NULL ), teamTotals( blocks, NULL );
- Int totalHeight = 0;
- for( Int block = 0; block < blocks; block++ )
+ const Int room = (Int)TheDisplay->getWidth() - 4 * pad;
+ const Int step = ObserverCamera_cardStep( blockSizes, cardWidths, cardGaps, versusWidths, BROADCAST_CARD_STEPS, room );
+ buildCards( step );
+ const Int cardPad = cardGaps[ step ];
+ const Int versusWidth = versusWidths[ step ];
+ std::vector< Int > cardLefts, blockLefts;
+ Int cardWidth = cardWidths[ step ];
+ Int rowWidth = ObserverCamera_cardRow( blockSizes, cardWidth, cardPad, versusWidth, &cardLefts, &blockLefts );
+ if( rowWidth > room )
{
- if( blockSizes[ block ] < 2 )
- continue;
- const std::string key = size + std::to_string( block );
- const Int totalPoints = broadcastPoints( compact ? BROADCAST_COMPACT_POINTS : BROADCAST_SIDE_POINTS );
- teamNames[ block ] = broadcastText( "teamname" + key, broadcastTeamName( players, players[ blockFirst[ block ] ].team ), BROADCAST_WORDS,
- totalPoints, TRUE );
- teamTotals[ block ] = broadcastText( "teamtotal" + key, broadcastNumber( "", blockArmies[ block ] ), BROADCAST_NUMBERS, totalPoints, TRUE );
- Int width = 0, height = 0;
- teamNames[ block ]->getSize( &width, &height );
- totalHeight = max( totalHeight, height );
- teamTotals[ block ]->getSize( &width, &height );
- armyWidth = max( armyWidth, width );
- totalHeight = max( totalHeight, height );
- }
-
- DisplayString *cashHead = broadcastText( "cashhead", TheGameText->fetch( "GUI:HudStatCash" ), BROADCAST_NUMBERS,
- broadcastPoints( BROADCAST_HEAD_POINTS ), FALSE );
- DisplayString *armyHead = broadcastText( "armyhead", TheGameText->fetch( "GUI:HudStatArmy" ), BROADCAST_NUMBERS,
- broadcastPoints( BROADCAST_HEAD_POINTS ), FALSE );
+ cardWidth = ObserverCamera_cardWidthIn( blockSizes, cardPad, versusWidth, room );
+ rowWidth = ObserverCamera_cardRow( blockSizes, cardWidth, cardPad, versusWidth, &cardLefts, &blockLefts );
+ }
+
UnicodeString clockText;
clockText.translate( AsciiString( spectatorClock( TheGameLogic->getFrame() ).c_str() ) );
DisplayString *clock = broadcastText( "clock", clockText, BROADCAST_NUMBERS, broadcastPoints( BROADCAST_CLOCK_POINTS ), TRUE );
- // the number columns are as wide as six digits whatever they hold, so the bar does not change its
- // width every time a player's cash crosses a thousand
- DisplayString *cashWidest = broadcastText( "cashwidest" + size, broadcastNumber( "$", BROADCAST_WIDEST ), BROADCAST_NUMBERS, rowPoints, TRUE );
- DisplayString *armyWidest = broadcastText( "armywidest" + size, broadcastNumber( "", BROADCAST_WIDEST ), BROADCAST_NUMBERS, rowPoints, TRUE );
- Int cashHeadWidth = 0, armyHeadWidth = 0, headHeight = 0, clockWidth = 0, clockHeight = 0, widestHeight = 0;
- Int cashWidestWidth = 0, armyWidestWidth = 0;
- cashHead->getSize( &cashHeadWidth, &headHeight );
- armyHead->getSize( &armyHeadWidth, &headHeight );
+ Int clockWidth = 0, clockHeight = 0;
clock->getSize( &clockWidth, &clockHeight );
- cashWidest->getSize( &cashWidestWidth, &widestHeight );
- armyWidest->getSize( &armyWidestWidth, &widestHeight );
- const Int cashColumn = max( max( cashWidth, cashWidestWidth ), cashHeadWidth );
- const Int armyColumn = max( max( armyWidth, armyWidestWidth ), armyHeadWidth );
-
- // the bar's measures, its left edge at left and its top on the screen's
- const Int half = swatch + gap / 2 + nameWidth + gap + sideWidth + gap + cashColumn + gap + armyColumn;
- const Int blockGap = gap / 2;
- Int columnHeights[ 2 ] = { 0, 0 };
+
+ // the bar's measures: the clock in a tab at the top in the middle, under it a line of team headers
+ // when there are teams, the cards, and the armies' bar under the whole row
+ Int nameHeight = 0, sideHeight = 0, numberHeight = 0, labelHeight = 0, headerHeight = 0, width = 0;
+ rows[ 0 ].name->getSize( &width, &nameHeight );
+ rows[ 0 ].side->getSize( &width, &sideHeight );
+ rows[ 0 ].cash->getSize( &width, &numberHeight );
+ cashHead->getSize( &width, &labelHeight );
+ numberHeight = max( numberHeight, labelHeight );
for( Int block = 0; block < blocks; block++ )
- {
- Int &columnHeight = columnHeights[ columns[ block ] ];
- if( columnHeight > 0 )
- columnHeight += blockGap;
- columnHeight += blockSizes[ block ] * ( rowHeight + rowGap ) + ( teamNames[ block ] != NULL ? totalHeight + rowGap : 0 );
- }
- const Int tableTop = pad + headHeight;
- const Int tableBottom = tableTop + max( columnHeights[ 0 ], columnHeights[ 1 ] );
- const Int clockBox = clockWidth + 2 * gap;
- const Int width = 2 * ( pad + half + pad ) + clockBox;
- const Int left = ( TheDisplay->getWidth() - width ) / 2;
- const Int tugTop = tableBottom + pad / 2;
+ if( teamNames[ block ] != NULL )
+ teamNames[ block ]->getSize( &width, &headerHeight );
+ if( headerHeight > 0 )
+ headerHeight += cardPad;
+ const Int clockBox = clockWidth + 2 * broadcastPixels( BROADCAST_GAP );
+ const Int clockBoxHeight = clockHeight + rule;
+ const Int barWidth = max( rowWidth, clockBox ) + 2 * pad;
+ const Int left = ( (Int)TheDisplay->getWidth() - barWidth ) / 2;
+ const Int rowLeft = left + ( barWidth - rowWidth ) / 2;
+ const Int headerTop = clockBoxHeight + pad / 2;
+ const Int cardsTop = headerTop + headerHeight;
+ const Int strip = broadcastPixels( BROADCAST_CARD_STRIP );
+ const Int cardHeight = strip + cardPad + nameHeight + sideHeight + 2 * numberHeight + cardPad;
+ const Int tugTop = cardsTop + cardHeight + pad / 2;
const Int height = tugTop + tug + pad;
- const Int clockLeft = left + pad + half + pad;
- const Int rightStart = clockLeft + clockBox + pad;
-
- TheDisplay->drawFillRect( left, 0, width, height, BROADCAST_GROUND );
- TheDisplay->drawFillRect( clockLeft, 0, clockBox, tableBottom, BROADCAST_PANEL );
- TheDisplay->drawFillRect( clockLeft, tableBottom - rule, clockBox, rule, BROADCAST_GOLD );
- clock->draw( clockLeft + gap, ( tableBottom - clockHeight ) / 2, BROADCAST_INK, BROADCAST_GROUND );
-
- // the columns on the left run outwards in, on the right inwards out; numbers end on their column's
- // right edge both sides so their digits line up
- const Int leftCashEnd = left + pad + half - gap - armyColumn;
- const Int leftArmyEnd = left + pad + half;
- const Int rightArmyEnd = rightStart + armyColumn;
- const Int rightCashEnd = rightArmyEnd + gap + cashColumn;
- cashHead->draw( leftCashEnd - cashHeadWidth, pad, BROADCAST_MUTED, BROADCAST_GROUND );
- armyHead->draw( leftArmyEnd - armyHeadWidth, pad, BROADCAST_MUTED, BROADCAST_GROUND );
- armyHead->draw( rightArmyEnd - armyHeadWidth, pad, BROADCAST_MUTED, BROADCAST_GROUND );
- cashHead->draw( rightCashEnd - cashHeadWidth, pad, BROADCAST_MUTED, BROADCAST_GROUND );
-
- // each column's blocks top down in team order, a hairline between two blocks
- Int columnTops[ 2 ] = { tableTop, tableTop };
+ const Int clockLeft = left + ( barWidth - clockBox ) / 2;
+
+ TheDisplay->drawFillRect( left, 0, barWidth, height, BROADCAST_GROUND );
+ TheDisplay->drawFillRect( clockLeft, 0, clockBox, clockBoxHeight, BROADCAST_PANEL );
+ TheDisplay->drawFillRect( clockLeft, clockBoxHeight - rule, clockBox, rule, BROADCAST_GOLD );
+ clock->draw( clockLeft + ( clockBox - clockWidth ) / 2, 0, BROADCAST_INK, BROADCAST_GROUND );
+
+ // block by block: a "vs" before every block but the first, a team's name and its armies' total over
+ // its cards, and a card a player, the house colour along its top, the name, the general or the
+ // difficulty, then cash and army each beside its label
+ Int versusTextWidth = 0, versusTextHeight = 0;
+ versusText->getSize( &versusTextWidth, &versusTextHeight );
for( Int block = 0; block < blocks; block++ )
{
- const Bool onLeft = columns[ block ] == 0;
- Int &top = columnTops[ columns[ block ] ];
- const Int columnLeft = onLeft ? left + pad : rightStart;
- if( top > tableTop )
+ const Int blockLeft = rowLeft + blockLefts[ block ];
+ const Int blockWidth = blockSizes[ block ] * cardWidth + ( blockSizes[ block ] - 1 ) * cardPad;
+ if( block > 0 )
+ versusText->draw( blockLeft - ( versusWidth + versusTextWidth ) / 2, cardsTop + ( cardHeight - versusTextHeight ) / 2,
+ BROADCAST_MUTED, BROADCAST_GROUND );
+ if( teamNames[ block ] != NULL )
{
- TheDisplay->drawFillRect( columnLeft, top + ( blockGap - rowGap ) / 2, half, 1, BROADCAST_LINE );
- top += blockGap;
+ Int totalWidth = 0, totalHeight = 0;
+ teamTotals[ block ]->getSize( &totalWidth, &totalHeight );
+ teamNames[ block ]->draw( blockLeft, headerTop, BROADCAST_GOLD, BROADCAST_GROUND );
+ teamTotals[ block ]->draw( blockLeft + blockWidth - totalWidth, headerTop, BROADCAST_INK, BROADCAST_GROUND );
}
for( Int index = blockFirst[ block ]; index < blockFirst[ block ] + blockSizes[ block ]; index++ )
{
const BroadcastRow &row = rows[ index ];
- Int nameW = 0, nameH = 0, sideW = 0, sideH = 0, cashW = 0, cashH = 0, armyW = 0, armyH = 0;
- row.name->getSize( &nameW, &nameH );
- row.side->getSize( &sideW, &sideH );
- row.cash->getSize( &cashW, &cashH );
- row.army->getSize( &armyW, &armyH );
- const Int swatchLeft = onLeft ? left + pad : rightStart + half - swatch;
- const Int nameLeft = onLeft ? swatchLeft + swatch + gap / 2 : swatchLeft - gap / 2 - nameW;
- const Int sideLeft = onLeft ? nameLeft + nameWidth + gap : swatchLeft - gap / 2 - nameWidth - gap - sideW;
- const Int cashEnd = onLeft ? leftCashEnd : rightCashEnd;
- const Int armyEnd = onLeft ? leftArmyEnd : rightArmyEnd;
- drawBroadcastSwatch( swatchLeft, top, swatch, rowHeight, row.color );
- row.name->draw( nameLeft, top + ( rowHeight - nameH ) / 2, ObserverCamera_readableColor( row.color ), BROADCAST_GROUND );
- row.side->draw( sideLeft, top + ( rowHeight - sideH ) / 2, BROADCAST_MUTED, BROADCAST_GROUND );
- row.cash->draw( cashEnd - cashW, top + ( rowHeight - cashH ) / 2, BROADCAST_INK, BROADCAST_GROUND );
- row.army->draw( armyEnd - armyW, top + ( rowHeight - armyH ) / 2, BROADCAST_INK, BROADCAST_GROUND );
- top += rowHeight + rowGap;
+ const Int cardLeft = rowLeft + cardLefts[ index ];
+ const Int textLeft = cardLeft + cardPad;
+ const Int numberEnd = cardLeft + cardWidth - cardPad;
+ TheDisplay->drawFillRect( cardLeft, cardsTop, cardWidth, cardHeight, BROADCAST_PANEL );
+ drawBroadcastSwatch( cardLeft, cardsTop, cardWidth, strip, row.color );
+ Int top = cardsTop + strip + cardPad;
+ row.name->draw( textLeft, top, ObserverCamera_readableColor( row.color ), BROADCAST_GROUND );
+ top += nameHeight;
+ row.side->draw( textLeft, top, BROADCAST_MUTED, BROADCAST_GROUND );
+ top += sideHeight;
+ Int numberWidth = 0, numberTall = 0;
+ cashHead->draw( textLeft, top + numberHeight - labelHeight, BROADCAST_MUTED, BROADCAST_GROUND );
+ row.cash->getSize( &numberWidth, &numberTall );
+ row.cash->draw( numberEnd - numberWidth, top + numberHeight - numberTall, BROADCAST_INK, BROADCAST_GROUND );
+ top += numberHeight;
+ armyHead->draw( textLeft, top + numberHeight - labelHeight, BROADCAST_MUTED, BROADCAST_GROUND );
+ row.army->getSize( &numberWidth, &numberTall );
+ row.army->draw( numberEnd - numberWidth, top + numberHeight - numberTall, BROADCAST_INK, BROADCAST_GROUND );
}
- if( teamNames[ block ] == NULL )
- continue;
- // the team's name where its players' names are, its armies' total under theirs
- Int teamW = 0, teamH = 0, totalW = 0, totalH = 0;
- teamNames[ block ]->getSize( &teamW, &teamH );
- teamTotals[ block ]->getSize( &totalW, &totalH );
- const Int nameStart = onLeft ? left + pad + swatch + gap / 2 : rightStart + half - swatch - gap / 2 - teamW;
- const Int armyEnd = onLeft ? leftArmyEnd : rightArmyEnd;
- teamNames[ block ]->draw( nameStart, top + ( totalHeight - teamH ) / 2, BROADCAST_MUTED, BROADCAST_GROUND );
- teamTotals[ block ]->draw( armyEnd - totalW, top + ( totalHeight - totalH ) / 2, BROADCAST_MUTED, BROADCAST_GROUND );
- top += totalHeight + rowGap;
- }
-
- // the army bar: every side's share from the left, the left column's first, then the right
- // column's from the right edge in, so with two sides each pulls from its own end. Two sides meet
- // at a gold mark in the middle; more are parted by the ground's colour
- std::vector< Int > barPlayers, barArmies, barBlocks;
- for( Int column = 0; column < 2; column++ )
- {
- for( Int taken = 0; taken < blocks; taken++ )
+ }
+
+ // the armies' bar under the whole row, every player's share in the cards' order, so with two sides
+ // each pulls from its own end and they meet at a gold mark in the middle; more sides are parted by
+ // the ground's colour
+ std::vector< Int > barArmies, barBlocks;
+ for( Int block = 0; block < blocks; block++ )
+ for( Int index = blockFirst[ block ]; index < blockFirst[ block ] + blockSizes[ block ]; index++ )
{
- const Int block = column == 0 ? taken : blocks - 1 - taken;
- if( columns[ block ] != column )
- continue;
- for( Int member = 0; member < blockSizes[ block ]; member++ )
- {
- const Int index = column == 0 ? blockFirst[ block ] + member : blockFirst[ block ] + blockSizes[ block ] - 1 - member;
- barPlayers.push_back( index );
- barArmies.push_back( players[ index ].army );
- barBlocks.push_back( block );
- }
+ barArmies.push_back( players[ index ].army );
+ barBlocks.push_back( block );
}
- }
- const Int tugLeft = left + pad;
- const Int tugWidth = width - 2 * pad;
- TheDisplay->drawFillRect( tugLeft, tugTop, tugWidth, tug, BROADCAST_LINE );
- const std::vector< Int > shares = ObserverCamera_barShares( barArmies, tugWidth );
- Int barAt = tugLeft;
+ TheDisplay->drawFillRect( rowLeft, tugTop, rowWidth, tug, BROADCAST_LINE );
+ const std::vector< Int > shares = ObserverCamera_barShares( barArmies, rowWidth );
+ Int barAt = rowLeft;
for( size_t piece = 0; piece < shares.size(); piece++ )
{
- drawBroadcastSwatch( barAt, tugTop, shares[ piece ], tug, rows[ barPlayers[ piece ] ].color );
+ drawBroadcastSwatch( barAt, tugTop, shares[ piece ], tug, rows[ piece ].color );
if( blocks > 2 && piece > 0 && barBlocks[ piece ] != barBlocks[ piece - 1 ] )
TheDisplay->drawFillRect( barAt, tugTop - rule, rule, tug + 2 * rule, BROADCAST_GROUND );
barAt += shares[ piece ];
}
if( blocks == 2 )
- TheDisplay->drawFillRect( tugLeft + ( tugWidth - rule ) / 2, tugTop - rule, rule, tug + 2 * rule, BROADCAST_GOLD );
+ TheDisplay->drawFillRect( rowLeft + ( rowWidth - rule ) / 2, tugTop - rule, rule, tug + 2 * rule, BROADCAST_GOLD );
IRegion2D bar;
bar.lo.x = left;
bar.lo.y = 0;
- bar.hi.x = left + width;
+ bar.hi.x = left + barWidth;
bar.hi.y = height;
TheObserverCamera.addBroadcast( bar );
TheObserverCamera.setBroadcastTop( (Real)( height + pad ) );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
index 50b92bed0..f44a68564 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
@@ -94,6 +94,13 @@ static const Real CUT_DISTANCE = 1600.0f;
static const Real HAND_JUMP_DISTANCE = 400.0f;
/// roughly how long the director's glide takes to arrive, easing in and out
static const Real DIRECTOR_PAN_SECONDS = 1.4f;
+/// how long the director's height takes to settle on a new place's: the view's own settle took a
+/// third of a second, and a camera gliding in over seconds stepped back up in that third
+static const Real DIRECTOR_HEIGHT_SECONDS = 1.6f;
+/// how long after the panes are gone the hand-over is logged a line a frame
+static const UnsignedInt HANDOVER_LOG_FRAMES = 45;
+/// a zoom moving more than this share of itself between two updates is logged as a jump
+static const Real ZOOM_JUMP_SHARE = 0.02f;
/// the director's glide never crosses the ground faster than this, about two screens a second
static const Real DIRECTOR_TOP_SPEED = 900.0f;
/// a fight this tight is watched from the watcher's own height; wider, the camera rises this much
@@ -444,6 +451,17 @@ ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocati
return step;
}
+//-------------------------------------------------------------------------------------------------
+Real ObserverCamera_easeHeight( Real from, Real to, Real *velocity, Real elapsedSeconds, Bool cut )
+{
+ if( cut )
+ {
+ *velocity = 0.0f;
+ return to;
+ }
+ return springTowards( from, to, velocity, DIRECTOR_HEIGHT_SECONDS, elapsedSeconds );
+}
+
//-------------------------------------------------------------------------------------------------
Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const Coord2D &first, Real needed, Coord2D *place, Real *heat )
{
@@ -616,28 +634,47 @@ Real ObserverCamera_paneLabelTop( const Coord2D &centre, Real radius, Real width
}
//-------------------------------------------------------------------------------------------------
-std::vector< Int > ObserverCamera_blockColumns( const std::vector< Int > &sizes )
+Int ObserverCamera_cardRow( const std::vector< Int > &sizes, Int cardWidth, Int cardGap, Int versusWidth,
+ std::vector< Int > *cardLefts, std::vector< Int > *blockLefts )
{
- std::vector< Int > columns( sizes.size(), 0 );
- if( sizes.size() == 2 )
- {
- columns[ 1 ] = 1;
- return columns;
- }
- // the biggest first, each to the shorter column, which evens the two out best
- std::vector< Int > biggestFirst;
+ cardLefts->clear();
+ blockLefts->clear();
+ Int at = 0;
for( size_t block = 0; block < sizes.size(); block++ )
- biggestFirst.push_back( (Int)block );
- std::stable_sort( biggestFirst.begin(), biggestFirst.end(), [ &sizes ]( Int a, Int b ) { return sizes[ a ] > sizes[ b ]; } );
- Int rows[ 2 ] = { 0, 0 };
- for( size_t taken = 0; taken < biggestFirst.size(); taken++ )
{
- const Int block = biggestFirst[ taken ];
- const Int column = rows[ 1 ] < rows[ 0 ] ? 1 : 0;
- rows[ column ] += sizes[ block ] + ( sizes[ block ] >= 2 ? 1 : 0 );
- columns[ block ] = column;
+ if( block > 0 )
+ at += versusWidth;
+ blockLefts->push_back( at );
+ for( Int card = 0; card < sizes[ block ]; card++ )
+ {
+ if( card > 0 )
+ at += cardGap;
+ cardLefts->push_back( at );
+ at += cardWidth;
+ }
}
- return columns;
+ return at;
+}
+
+//-------------------------------------------------------------------------------------------------
+Int ObserverCamera_cardStep( const std::vector< Int > &sizes, const Int *cardWidths, const Int *cardGaps,
+ const Int *versusWidths, Int steps, Int room )
+{
+ std::vector< Int > cardLefts, blockLefts;
+ for( Int step = 0; step < steps; step++ )
+ if( ObserverCamera_cardRow( sizes, cardWidths[ step ], cardGaps[ step ], versusWidths[ step ], &cardLefts, &blockLefts ) <= room )
+ return step;
+ return steps - 1;
+}
+
+//-------------------------------------------------------------------------------------------------
+Int ObserverCamera_cardWidthIn( const std::vector< Int > &sizes, Int cardGap, Int versusWidth, Int room )
+{
+ Int cards = 0;
+ for( size_t block = 0; block < sizes.size(); block++ )
+ cards += sizes[ block ];
+ const Int blocks = (Int)sizes.size();
+ return ( room - ( cards - blocks ) * cardGap - ( blocks - 1 ) * versusWidth ) / cards;
}
//-------------------------------------------------------------------------------------------------
@@ -1159,6 +1196,12 @@ void ObserverCamera::reset( void )
m_heightDriven = FALSE;
m_handHeight = 0.0f;
m_drivenHeight = 0.0f;
+ m_heightExtra = 0.0f;
+ m_heightExtraVelocity = 0.0f;
+ m_panesHeldZoom = FALSE;
+ m_lastZoom = 0.0f;
+ m_lastCut = FALSE;
+ m_handoverLogUntil = 0;
m_drivenTo.zero();
m_lastUpdate = 0;
m_velocity.x = m_velocity.y = m_velocity.z = m_velocity.angle = m_velocity.pitch = m_velocity.zoom = 0.0f;
@@ -2670,6 +2713,28 @@ Bool ObserverCamera::chooseTarget( const ViewLocation &current, ViewLocation *ta
return TRUE;
}
+//-------------------------------------------------------------------------------------------------
+/** While panes are up and for HANDOVER_LOG_FRAMES after, a line a frame with pane 0's look point,
+ * zoom, subject and the pixel the view, aimed as it will draw, puts the subject on: a hand-over
+ * between the panes and the single view that jumps shows as a step in those numbers. */
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::logHandover( const ViewLocation &step, const ViewLocation &placed )
+{
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ if( m_panePhase != PANES_NONE )
+ m_handoverLogUntil = frame + HANDOVER_LOG_FRAMES;
+ if( frame >= m_handoverLogUntil )
+ return;
+ TheTacticalView->aimCamera();
+ Coord3D world = step.getPosition();
+ world.z = TheTerrainLogic->getGroundHeight( world.x, world.y );
+ ICoord2D pixel;
+ pixel.x = pixel.y = -1;
+ TheTacticalView->worldToScreenTriReturn( &world, &pixel );
+ DEBUG_LOG(( "OBSCAM frame %u hand look (%.1f,%.1f) zoom %.3f subject (%.1f,%.1f) at (%d,%d)\n", frame,
+ placed.getPosition().x, placed.getPosition().y, TheTacticalView->getZoom(), world.x, world.y, pixel.x, pixel.y ));
+}
+
//-------------------------------------------------------------------------------------------------
void ObserverCamera::update( UnsignedInt nowMilliseconds )
{
@@ -2727,14 +2792,42 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )
}
// a player's screen brings its own zoom; the director's height is the watcher's own plus what
- // the fight's width asks for
+ // the fight's width asks for, eased there on a spring of its own. Handed straight to the view,
+ // whose settle closes two thirds of a gap in ten frames, every change of place's height made a
+ // camera gliding in for seconds step back up in a third of one. A cut, the place too far for a
+ // glide, takes the height at once with it, so it is one clean cut and not a cut and a step.
+ // Panes set the zoom outright; when they let go the spring starts from the height the panes left
+ // the camera at, so the view does not settle from there to an old height in one go
+ const Bool panesZoom = m_paneCount >= 2 && !isShowingPlayerView();
+ const Coord3D &from = current.getPosition();
+ const Real gapX = target.getPosition().x - from.x - ( m_driving ? m_mainOffset.x : 0.0f );
+ const Real gapY = target.getPosition().y - from.y - ( m_driving ? m_mainOffset.y : 0.0f );
+ const Bool cut = !m_introGlide && !panesZoom && gapX * gapX + gapY * gapY > CUT_DISTANCE * CUT_DISTANCE;
+ if( !m_heightDriven )
+ {
+ m_heightExtra = 0.0f;
+ m_heightExtraVelocity = 0.0f;
+ }
+ if( m_panesHeldZoom && !panesZoom && m_heightDriven )
+ {
+ m_heightExtra = TheTacticalView->getCurrentHeightAboveGround() - m_handHeight;
+ m_heightExtraVelocity = 0.0f;
+ }
+ // a step back or in that no glide made: the zoom moved more than ZOOM_JUMP_SHARE between two
+ // updates without a cut, panes aside, which set their zoom outright as they slide
+ if( TheGlobalData->m_directorRecord && m_lastZoom > 0.0f && !m_lastCut && !panesZoom && !m_panesHeldZoom
+ && fabsf( current.getZoom() - m_lastZoom ) > m_lastZoom * ZOOM_JUMP_SHARE )
+ DEBUG_LOG(( "OBSCAM frame %u zoom jump %.3f -> %.3f\n", TheGameLogic->getFrame(), m_lastZoom, current.getZoom() ));
+ m_lastZoom = current.getZoom();
+ m_lastCut = cut;
+ m_panesHeldZoom = panesZoom;
+ m_heightExtra = ObserverCamera_easeHeight( m_heightExtra, m_placeHeight, &m_heightExtraVelocity, elapsed / MILLISECONDS_PER_SECOND, cut );
if( isShowingPlayerView() )
releaseHeight();
else
- driveHeight( m_placeHeight );
+ driveHeight( m_heightExtra );
// while there are panes the zoom is set outright from how far in they are, with the view's own
// settling held off: it eases on every draw, and a frame has a draw a pane
- const Bool panesZoom = m_paneCount >= 2 && !isShowingPlayerView();
holdHeight( isShowingPlayerView() || panesZoom );
if( !m_driving )
{
@@ -2788,6 +2881,18 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )
m_aimFrom = step;
sitBack = placePane( 0, sitBack, pixel, step.getZoom() );
}
+ else if( TheGlobalData->m_directorRecord && !player )
+ {
+ // the single view puts the subject on the screen's middle pixel the way pane 0 does at the end of
+ // its exit and the start of its entry. Looking straight at the subject drew it off the middle by
+ // the view's lift over the ground, and the picture jumped sideways by that much the frame the
+ // panes let go and again the frame they came
+ Coord2D middle;
+ middle.x = TheDisplay->getWidth() * 0.5f;
+ middle.y = TheDisplay->getHeight() * 0.5f;
+ m_aimFrom = step;
+ sitBack = placeOnPixel( sitBack, middle, step.getZoom() );
+ }
// the pane cameras are placed by aiming the view, so before the view is put where it draws
stepPaneCameras( step, elapsed / MILLISECONDS_PER_SECOND );
m_mainOffset.x = step.getPosition().x - sitBack.x;
@@ -2795,6 +2900,8 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )
ViewLocation placed;
placed.init( sitBack.x, sitBack.y, step.getPosition().z, step.getAngle(), step.getPitch(), step.getZoom() );
TheTacticalView->setLocation( &placed );
+ if( cut && !isShowingPlayerView() )
+ TheTacticalView->setZoomToHeight( m_handHeight + m_heightExtra );
// 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 camera
TheTacticalView->applyCameraConstraint();
@@ -2802,5 +2909,8 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )
m_driving = TRUE;
if( TheGlobalData->m_directorRecord )
+ {
logPanes( TheGameLogic->getFrame() );
+ logHandover( step, placed );
+ }
}
diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.inc
index 87794363c..7394279d0 100644
--- a/GeneralsMD/Code/Tests/test_observer_camera.inc
+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc
@@ -857,31 +857,71 @@ TEST(pane_animations_ease_over_logic_frames)
}
}
-TEST(the_score_bar_keeps_each_team_together_and_balances_its_two_columns)
+TEST(the_directors_height_eases_to_a_new_place_and_cuts_with_a_cut)
+{
+ // a place 300 higher: no frame at 30 a second moves more than a twentieth of it, it gets there
+ // within five seconds, and never passes it
+ Real height = 0.0f;
+ Real velocity = 0.0f;
+ Real biggestStep = 0.0f;
+ for( Int frame = 0; frame < 150; frame++ )
+ {
+ const Real next = ObserverCamera_easeHeight( height, 300.0f, &velocity, 1.0f / 30.0f, FALSE );
+ biggestStep = max( biggestStep, next - height );
+ CHECK( next <= 300.0f );
+ height = next;
+ }
+ CHECK( biggestStep < 15.0f );
+ CHECK( height > 290.0f );
+ // the first frame of a change barely moves: the view's own settle took a tenth of the gap at once
+ velocity = 0.0f;
+ CHECK( ObserverCamera_easeHeight( 0.0f, 300.0f, &velocity, 1.0f / 30.0f, FALSE ) < 3.0f );
+ // a cut is there at once and starts the next glide from rest
+ velocity = 50.0f;
+ CHECK_NEAR( ObserverCamera_easeHeight( 0.0f, 300.0f, &velocity, 1.0f / 30.0f, TRUE ), 300.0f, 0.0001f );
+ CHECK_NEAR( velocity, 0.0f, 0.0001f );
+}
+
+TEST(the_score_bar_sets_every_side_in_one_row_and_fits_eight_players)
{
- // two sides face each other whatever their sizes: 4v1
+ // 4v1: four cards with three gaps, a "vs", one card
std::vector< Int > sizes;
sizes.push_back( 4 );
sizes.push_back( 1 );
- std::vector< Int > columns = ObserverCamera_blockColumns( sizes );
- CHECK_EQ( columns[ 0 ], 0 );
- CHECK_EQ( columns[ 1 ], 1 );
- // eight alone alternate, four a column
- sizes.assign( 8, 1 );
- columns = ObserverCamera_blockColumns( sizes );
- Int left = 0;
- for( size_t block = 0; block < columns.size(); block++ )
- left += columns[ block ] == 0 ? 1 : 0;
- CHECK_EQ( left, 4 );
- // four alone and a pair: the pair's two rows and its total land where there is room
+ std::vector< Int > cardLefts, blockLefts;
+ CHECK_EQ( ObserverCamera_cardRow( sizes, 100, 4, 30, &cardLefts, &blockLefts ), 5 * 100 + 3 * 4 + 30 );
+ CHECK_EQ( (Int)cardLefts.size(), 5 );
+ CHECK_EQ( cardLefts[ 3 ], 3 * 104 );
+ CHECK_EQ( blockLefts[ 1 ], 4 * 100 + 3 * 4 + 30 );
+ CHECK_EQ( cardLefts[ 4 ], blockLefts[ 1 ] );
+ // two alone, three alone and a pair: the 1v1v1v1v2 staging
sizes.assign( 4, 1 );
sizes.push_back( 2 );
- columns = ObserverCamera_blockColumns( sizes );
- Int rows[ 2 ] = { 0, 0 };
- for( size_t block = 0; block < columns.size(); block++ )
- rows[ columns[ block ] ] += sizes[ block ] + ( sizes[ block ] >= 2 ? 1 : 0 );
- CHECK_EQ( rows[ 0 ], 4 );
- CHECK_EQ( rows[ 1 ], 3 );
+ CHECK_EQ( ObserverCamera_cardRow( sizes, 100, 4, 30, &cardLefts, &blockLefts ), 6 * 100 + 4 + 4 * 30 );
+ CHECK_EQ( blockLefts[ 4 ], 4 * 130 );
+
+ // the sizes a 720 picture measured, largest first: every count from two to eight alone and 4v4
+ // fit 1280 less the bar's padding at some step, and no step is taken that is larger than needed
+ const Int cardWidths[] = { 170, 150, 132, 116 };
+ const Int cardGaps[] = { 6, 5, 4, 3 };
+ const Int versusWidths[] = { 30, 26, 22, 20 };
+ const Int room = 1280 - 2 * 8;
+ for( Int players = 2; players <= 8; players++ )
+ {
+ sizes.assign( players, 1 );
+ const Int step = ObserverCamera_cardStep( sizes, cardWidths, cardGaps, versusWidths, 4, room );
+ CHECK( ObserverCamera_cardRow( sizes, cardWidths[ step ], cardGaps[ step ], versusWidths[ step ], &cardLefts, &blockLefts ) <= room );
+ if( step > 0 )
+ CHECK( ObserverCamera_cardRow( sizes, cardWidths[ step - 1 ], cardGaps[ step - 1 ], versusWidths[ step - 1 ], &cardLefts, &blockLefts ) > room );
+ }
+ sizes.assign( 2, 4 );
+ const Int step = ObserverCamera_cardStep( sizes, cardWidths, cardGaps, versusWidths, 4, room );
+ // 4v4 has one "vs" where eight alone have seven, so it keeps a larger size: 1200 + 30 + 26
+ CHECK_EQ( step, 1 );
+ // a row too wide at every step gets the widest card that fits
+ const Int narrow = ObserverCamera_cardWidthIn( sizes, cardGaps[ 3 ], versusWidths[ 3 ], 900 );
+ CHECK( ObserverCamera_cardRow( sizes, narrow, cardGaps[ 3 ], versusWidths[ 3 ], &cardLefts, &blockLefts ) <= 900 );
+ CHECK( ObserverCamera_cardRow( sizes, narrow + 1, cardGaps[ 3 ], versusWidths[ 3 ], &cardLefts, &blockLefts ) > 900 );
// teammates are taken together in the order their teams first appear
std::vector< Int > teams;