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(gameclient): hold director splits and skip powers that hurt nobody

Olcay Seygan96c1249e014e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 72908f215..7e775a558 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -748,7 +748,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- Watching, the bars over the buildings are everyone's too - what each factory is turning out, and how long the superweapons have left. An observer used to see none of it.
- Watching, the camera can drive itself. Two drop-downs in the camera panel on the right, above the board, say who has it and which player you follow, and you can follow nobody. The Director goes to the fight with the most on the line over the last five seconds, where a dead Overlord counts for more than six riflemen being shot at and anything happening to a superweapon counts three times over. It stays with that fight twelve seconds, leaves after six only for one four times the size, and after half a minute on the same fight a third bigger is enough. So a 4v4 is watched like a broadcast rather than hunted for, and it does not hop between spots every few seconds. Any general's power used on the map outranks every fight. A nuke is shown in its silo as it leaves, then the camera waits at the target for it to come down and stays through the blast. The particle cannon's beam is followed along its whole sweep, and a Scud Storm or a carpet bomb is watched until the last explosion has died down. Then it goes back to the fighting. The camera glides between places and slows into each one, and only cuts when the next one is across most of the map. When nobody is shooting it no longer parks on empty ground: it goes round what is worth seeing, an army on the march, a superweapon, a base going up, the rest of a base, the dearest first and fourteen seconds each, and does not come back to one of the last three while there is anything else to show. With a player picked it keeps to his fights and his own armies and buildings. Player camera shows his screen: a human player's camera comes over the network five times a second, smoothed in between, and a computer player, who has no camera, gets the Director narrowed to his own fights. Scroll with the keys or a drag, turn the view or click the radar and the camera is yours again, still following the same player. The edge of the screen does not scroll while it drives: the panel on the right stands on that edge, and reaching for it used to hand the camera back to you, so the Director stopped following the fighting the first time you went to change a setting. In a replay with the recorded camera switched on in the options, the player you follow still drives the camera the way his button in the old list did.
- Watching, the Director climbs over a wide battle until the whole of it is on the screen, and comes back down to your own height when it moves on or you take the camera. The mouse wheel still zooms while it drives, and it keeps what you chose. It stops short of the map's border too, where a fight on the edge used to come with a black corner of nothing beside it. A nuke or a Scud Storm is shown leaving its silo even when the Director has only just arrived at another fight; before, the launch was over by the time it was allowed to move. Rewinding a replay leaves your camera settings as they were, where a rewind used to hand you back a free camera with nobody followed. And following one player while a superweapon wiped out everything he had at the spot could close the game. It no longer does.
-- Watching can be filmed. Start the game with `-directorrecord` and the Director has the camera from the first second, with nothing over the picture but the radar, and the whole match goes into one video; the game closes itself when the match is decided or the replay runs out. Beside `-replay` it turns an old match into footage, and beside four computer players it films a match nobody played. 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 before either begins, and a skirmish the first run saw come to nothing is not cut to. 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. 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 and ends once the second fight has burnt down to a quarter of the first, so the picture does not flicker between one and two. Only the video shows the other pictures; the window keeps the Director's own fight under the lines. Two bases going up are not a fight, and the split ends the moment the camera's own fight and the second one turn out to be the same. The pictures go straight into ffmpeg as they are drawn, so an hour of 1080p does not need tens of gigabytes of disk first; put ffmpeg beside the game or on your PATH, because without it nothing is recorded and the game says so and closes. 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. 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. 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. 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. 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. 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 9288bb80e..fdc8fc05a 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
@@ -83,13 +83,16 @@ struct DirectorEvent
UnsignedInt until;
Real weight;
Bool superweapon;
+ Bool landed; ///< it hurt somebody where it was aimed: a superweapon from the start, any other once a hit is seen there
};
/// -directorrecord's scouting pass plays the match headless first and writes down what is worth
/// filming, so the filming pass can be there before it starts. A fight runs from the scan it was
/// first hot on, start, to the last, starting at place and last seen at target; peak is its hottest
/// scan and sides the mask of every player who dealt or took a hit in it. A special power is a
-/// moment of one frame fired from place at target, peak its weight against other powers
+/// moment of one frame fired from place at target, peak its weight against other powers; a power
+/// that is not a superweapon has 0 until a hit is seen where it was aimed, so a spy satellite or a
+/// radar scan stays at 0
struct DirectorMoment
{
UnsignedInt start;
@@ -115,27 +118,38 @@ struct DirectorFightHit
/// joins the fight still going nearest it, or starts a new one on this frame; a fight with no crowd
/// near it for a few seconds is over and is not joined again
void ObserverCamera_trackFights( std::vector< DirectorMoment > &fights, const std::vector< DirectorFightHit > &hits, UnsignedInt frame );
-/// whether a moment is worth the camera's time: every special power, and a fight that got hot enough
-/// and lasted. The rest fizzled
+/// whether a moment is worth the camera's time: a superweapon, any other special power that hurt
+/// somebody where it was aimed, and a fight that got hot enough and lasted. The rest fizzled
Bool ObserverCamera_worthFilming( const DirectorMoment &moment );
+/// the scouting pass's special powers on frame, each scan up to EVENT_FRAMES after its launch: one a
+/// hit of hits lands within the gather radius of the target of has landed
+void ObserverCamera_markLandings( std::vector< DirectorMoment > &moments, const std::vector< DirectorFightHit > &hits, UnsignedInt frame );
+/// whether the special power fired on frame at at is one the scouting pass saw land; FALSE for one
+/// it did not see, so a match it did not scout waits for the hits
+Bool ObserverCamera_powerLands( const std::vector< DirectorMoment > &timeline, UnsignedInt frame, const Coord2D &at );
+/// whether the timeline has a fight worth filming near place, going on at frame or beginning within
+/// the pre-roll, that lasts to until, leaving out any that is also near besides, the place another
+/// pane already shows (NULL for none)
+Bool ObserverCamera_fightLasts( const std::vector< DirectorMoment > &timeline, const Coord2D &place, UnsignedInt frame, UnsignedInt until,
+ const Coord2D *besides );
/// the scouting pass's fights as its run ends on frame end: one still going was cut short by the end
/// of the match, not by itself, and is counted as lasting, so a last battle that got hot is filmed
/// rather than skipped as a fizzle
void ObserverCamera_closeTimeline( std::vector< DirectorMoment > &moments, UnsignedInt end );
/// the moment the director goes to wait at on frame: of the fights worth filming and the superweapons
/// that begin within the pre-roll after frame, a superweapon first and then the hottest, leaving out
-/// any too near taken for a split to tell apart, the place another pane already shows (NULL for
-/// none). -1 for none
-Int ObserverCamera_prerollMoment( const std::vector< DirectorMoment > &timeline, UnsignedInt frame, const Coord2D *taken );
+/// any within apart of taken, the place another pane already shows (NULL for none). -1 for none
+Int ObserverCamera_prerollMoment( const std::vector< DirectorMoment > &timeline, UnsignedInt frame, const Coord2D *taken, Real apart );
/// whether the fight going on at place on frame is one the scouting pass saw fizzle, which the
/// director does not cut to. FALSE where the pass saw nothing, so a match it did not scout is
/// filmed as before
Bool ObserverCamera_fizzles( const std::vector< DirectorMoment > &timeline, const Coord2D &place, UnsignedInt frame );
-/// a fight worth filming beginning within the pre-roll after frame, or with keeping, the split up
-/// already, one going on at frame, far enough from first to want a pane of its own: the hottest such,
-/// -1 for none. A fight already going is not split for anew: where it began is only a guess at
-/// where it is now, and a fight that had wandered off left pane 1 on empty ground
-Int ObserverCamera_plannedSecond( const std::vector< DirectorMoment > &timeline, const Coord2D &first, UnsignedInt frame, Bool keeping );
+/// a fight worth filming beginning within SPLIT_LEAD_FRAMES after frame, or with keeping, the split up
+/// already, one going on at frame, more than apart from first: the hottest such, -1 for none. A
+/// fight already going is not split for anew: where it began is only a guess at where it is now, and
+/// a fight that had wandered off left pane 1 on empty ground
+Int ObserverCamera_plannedSecond( const std::vector< DirectorMoment > &timeline, const Coord2D &first, UnsignedInt frame, Real apart,
+ Bool keeping );
/// a moment as one line of the timeline file, and back; FALSE for a line that is not one
AsciiString ObserverCamera_formatMoment( const DirectorMoment &moment );
Bool ObserverCamera_parseMoment( const char *line, DirectorMoment *moment );
@@ -185,14 +199,16 @@ 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 );
-/// -directorrecord's second fight: the hottest place among the hits far enough from first that 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, Coord2D *place, Real *heat );
+/// -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 );
/// whether the recording's picture is split, given whether it is now, how far apart the two places
-/// are and how long ago it last went on or off: on, after a rest, for a second fight that is big on
-/// its own and next to a first one; off once it has been held a while and the second fight has burnt
-/// down, and at once when the second fight is over or the two places come together
-Bool ObserverCamera_holdSplit( Bool split, Real firstHeat, Real secondHeat, Real apart, UnsignedInt framesSince );
+/// are against the needed distance, and how long ago it last went on or off: on, after a rest, for a
+/// second fight more than needed away that is big on its own and next to a first one; held through
+/// SPLIT_LEAST_FRAMES whatever the second fight does, then while it keeps a quarter of the first; off
+/// at once, however new, when the two places come within two thirds of needed and the two panes
+/// 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,
@@ -226,6 +242,11 @@ Real ObserverCamera_extentAround( const std::vector< DirectorHeat > &things, con
/// reach measured at two zooms: the ground a picture covers grows in a straight line with the zoom,
/// which is how far the eye stands back
Real ObserverCamera_zoomForReach( Real zoomA, Real reachA, Real zoomB, Real reachB, Real reach, Real nearest, Real farthest );
+/// the ground a pane spans across its middle row once its circle reaches reach: screenGround is what
+/// the whole picture spans at the director's zoom and circleGround what the circle reaches there.
+/// The pane zooms out from the director's zoom, never past PANE_FIT_FARTHEST times it, and the ground
+/// grows with the zoom
+Real ObserverCamera_paneGround( Real screenGround, Real circleGround, Real reach );
/// the corners of what pane shows of a width by height picture, the rays meeting at origin: its wedge
/// cut by the screen's edges, at most eight points; the number of them
Int ObserverCamera_panePolygon( const Real *rays, Int count, Int pane, const Coord2D &origin, Int width, Int height,
@@ -345,6 +366,9 @@ private:
void pickIntroBases( void );
Region2D mapRegion( void ) const;
void updateSplit( void );
+ void measureScreenGround( void );
+ Real paneGround( const Coord2D &subject ) const;
+ Real splitApart( const Coord2D &second ) const;
void updateIntroPlaces( void );
void advancePanes( UnsignedInt frame );
void fitPanes( UnsignedInt frame );
@@ -408,7 +432,10 @@ private:
std::vector< PlayerMaskType > m_fightSides; ///< and the two players each of them was between
std::vector< IRegion2D > m_broadcast; ///< the rectangles the broadcast drew over pane 0 this frame
Real m_broadcastTop; ///< the rows the score bar took
+ Real m_screenGround; ///< the ground the whole picture spans across its middle row, last measured with no panes up
+ Real m_circleGround; ///< and the least a split's pane circle reaches on the ground with it
Bool m_split; ///< -directorrecord wants two fights side by side
+ Real m_splitApart; ///< how far apart the split's two fights had to be when it last went on or off
UnsignedInt m_splitChanged; ///< the logic frame the split last went on or off
Coord2D m_secondPlace; ///< the second fight, shown in the second pane
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
index 6d13f005a..8fd6e94af 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
@@ -108,12 +108,19 @@ static const Real PLAYER_TOP_SPEED = 4000.0f;
static const UnsignedInt LONGEST_STEP_MILLISECONDS = 100;
static const Real MILLISECONDS_PER_SECOND = 1000.0f;
/// -directorrecord: a second fight closer than this to the first shares its ground, and the split
-/// would show one fight twice
+/// would show one fight twice; the least, raised to the ground a pane's whole picture spans
static const Real SPLIT_APART = 3.0f * DIRECTOR_GATHER_RADIUS;
+/// a split opens only for two fights further apart than either pane's picture is wide, so no ground
+/// shows in both, and closes once they come within this share of that. A pane zooms out until its
+/// fight fills its circle, one and a half to two and a half times the director's zoom: at 660 apart,
+/// and at one and a half times the director's own picture, about 700, the two panes of a 1v1 showed
+/// one bridge from neighbouring views
+static const Real SPLIT_SAME_GROUND_SHARE = 2.0f / 3.0f;
/// the picture splits for a second fight at least this hot, and at least this share of the first
static const Real SPLIT_ENTER_HEAT = 2.0f;
static const Real SPLIT_ENTER_SHARE = 0.5f;
-/// a split stays this long at least, and after that while the second fight keeps this share
+/// a split is held this long once its panes are all in, and after that while the second fight keeps
+/// this share
static const UnsignedInt SPLIT_HOLD_FRAMES = 6 * LOGICFRAMES_PER_SECOND;
static const Real SPLIT_STAY_SHARE = 0.25f;
/// once the picture is whole again it stays whole this long, so it does not flicker between the two
@@ -122,6 +129,12 @@ static const UnsignedInt SPLIT_REST_FRAMES = 4 * LOGICFRAMES_PER_SECOND;
static const UnsignedInt PANE_RADAR_FRAMES = 12;
/// the panes take this long to slide in along the rays, and out again
static const UnsignedInt PANE_SLIDE_FRAMES = 15;
+/// so a split, once on, stays on this long whatever its fights do, unless its panes come to show
+/// the same ground: a split that went off before its panes were in flashed a pane in and out
+static const UnsignedInt SPLIT_LEAST_FRAMES = PANE_RADAR_FRAMES + PANE_SLIDE_FRAMES + SPLIT_HOLD_FRAMES;
+/// a split the timeline plans opens this long before its fight: at four seconds pane 1 sat on an
+/// empty bridge
+static const UnsignedInt SPLIT_LEAD_FRAMES = 3 * LOGICFRAMES_PER_SECOND;
/// the match opens on every player's base, one pane each, for this long
static const UnsignedInt PANE_INTRO_FRAMES = 7 * LOGICFRAMES_PER_SECOND;
/// the gold of a line between panes is a pixel for every this many rows of the picture
@@ -414,28 +427,28 @@ ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocati
}
//-------------------------------------------------------------------------------------------------
-Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const Coord2D &first, Coord2D *place, Real *heat )
+Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const Coord2D &first, Real needed, Coord2D *place, Real *heat )
{
std::vector< DirectorHeat > apart;
for( size_t index = 0; index < hits.size(); index++ )
{
const Real dx = hits[ index ].position.x - first.x;
const Real dy = hits[ index ].position.y - first.y;
- if( dx * dx + dy * dy > SPLIT_APART * SPLIT_APART )
+ if( dx * dx + dy * dy > needed * needed )
apart.push_back( hits[ index ] );
}
return ObserverCamera_hottestPlace( apart, place, heat );
}
//-------------------------------------------------------------------------------------------------
-Bool ObserverCamera_holdSplit( Bool split, Real firstHeat, Real secondHeat, Real apart, UnsignedInt framesSince )
+Bool ObserverCamera_holdSplit( Bool split, Real firstHeat, Real secondHeat, Real apart, Real needed, UnsignedInt framesSince )
{
- // two halves of one fight, or a half with no fight left in it, is no split at all
- if( secondHeat <= 0.0f || apart <= SPLIT_APART )
+ // two halves showing one fight's ground is no split at all, however new
+ if( apart <= needed * SPLIT_SAME_GROUND_SHARE )
return FALSE;
if( split )
- return framesSince < SPLIT_HOLD_FRAMES || secondHeat >= firstHeat * SPLIT_STAY_SHARE;
- return framesSince >= SPLIT_REST_FRAMES && firstHeat > 0.0f && secondHeat >= SPLIT_ENTER_HEAT
+ return framesSince < SPLIT_LEAST_FRAMES || ( secondHeat > 0.0f && secondHeat >= firstHeat * SPLIT_STAY_SHARE );
+ return apart > needed && framesSince >= SPLIT_REST_FRAMES && firstHeat > 0.0f && secondHeat >= SPLIT_ENTER_HEAT
&& secondHeat >= firstHeat * SPLIT_ENTER_SHARE;
}
@@ -610,6 +623,12 @@ Real ObserverCamera_zoomForReach( Real zoomA, Real reachA, Real zoomB, Real reac
return min( max( zoom, nearest ), farthest );
}
+//-------------------------------------------------------------------------------------------------
+Real ObserverCamera_paneGround( Real screenGround, Real circleGround, Real reach )
+{
+ return screenGround * min( max( reach / circleGround, 1.0f ), PANE_FIT_FARTHEST );
+}
+
//-------------------------------------------------------------------------------------------------
/** The wedge from origin between the pane's two rays, cut by the screen: where the rays meet if that
* is on the screen, the screen's corners inside the wedge, and where each ray leaves the screen.
@@ -760,7 +779,38 @@ void ObserverCamera_trackFights( std::vector< DirectorMoment > &fights, const st
//-------------------------------------------------------------------------------------------------
Bool ObserverCamera_worthFilming( const DirectorMoment &moment )
{
- return moment.power || ( moment.peak >= FIGHT_WORTH_HEAT && moment.last - moment.start >= FIGHT_WORTH_FRAMES );
+ if( moment.power )
+ return moment.superweapon || moment.peak > 0.0f;
+ return moment.peak >= FIGHT_WORTH_HEAT && moment.last - moment.start >= FIGHT_WORTH_FRAMES;
+}
+
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera_markLandings( std::vector< DirectorMoment > &moments, const std::vector< DirectorFightHit > &hits, UnsignedInt frame )
+{
+ for( size_t index = 0; index < moments.size(); index++ )
+ {
+ DirectorMoment &power = moments[ index ];
+ if( !power.power || power.superweapon || power.peak > 0.0f || frame > power.start + EVENT_FRAMES )
+ continue;
+ for( size_t hit = 0; hit < hits.size() && power.peak <= 0.0f; hit++ )
+ if( within( hits[ hit ].position, power.target, DIRECTOR_GATHER_RADIUS ) )
+ power.peak = EVENT_WEIGHT;
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The timeline is written with no decimals, so the scouting pass's target is the one fired on frame
+ * within a unit of at. */
+//-------------------------------------------------------------------------------------------------
+Bool ObserverCamera_powerLands( const std::vector< DirectorMoment > &timeline, UnsignedInt frame, const Coord2D &at )
+{
+ for( size_t index = 0; index < timeline.size(); index++ )
+ {
+ const DirectorMoment &power = timeline[ index ];
+ if( power.power && power.start == frame && within( power.target, at, 1.0f ) )
+ return ObserverCamera_worthFilming( power );
+ }
+ return FALSE;
}
//-------------------------------------------------------------------------------------------------
@@ -776,7 +826,7 @@ void ObserverCamera_closeTimeline( std::vector< DirectorMoment > &moments, Unsig
}
//-------------------------------------------------------------------------------------------------
-Int ObserverCamera_prerollMoment( const std::vector< DirectorMoment > &timeline, UnsignedInt frame, const Coord2D *taken )
+Int ObserverCamera_prerollMoment( const std::vector< DirectorMoment > &timeline, UnsignedInt frame, const Coord2D *taken, Real apart )
{
Int best = -1;
for( size_t index = 0; index < timeline.size(); index++ )
@@ -786,7 +836,7 @@ Int ObserverCamera_prerollMoment( const std::vector< DirectorMoment > &timeline,
continue;
if( moment.power ? !moment.superweapon : !ObserverCamera_worthFilming( moment ) )
continue;
- if( taken != NULL && within( moment.place, *taken, SPLIT_APART ) )
+ if( taken != NULL && within( moment.place, *taken, apart ) )
continue;
if( best >= 0 )
{
@@ -823,17 +873,39 @@ Bool ObserverCamera_fizzles( const std::vector< DirectorMoment > &timeline, cons
}
//-------------------------------------------------------------------------------------------------
-Int ObserverCamera_plannedSecond( const std::vector< DirectorMoment > &timeline, const Coord2D &first, UnsignedInt frame, Bool keeping )
+static Bool scoutedNear( const DirectorMoment &fight, const Coord2D &place )
+{
+ return within( fight.place, place, SCOUT_SAME_FIGHT ) || within( fight.target, place, SCOUT_SAME_FIGHT );
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool ObserverCamera_fightLasts( const std::vector< DirectorMoment > &timeline, const Coord2D &place, UnsignedInt frame, UnsignedInt until,
+ const Coord2D *besides )
+{
+ for( size_t index = 0; index < timeline.size(); index++ )
+ {
+ const DirectorMoment &fight = timeline[ index ];
+ if( fight.power || !ObserverCamera_worthFilming( fight ) || frame + DIRECTOR_PREROLL_FRAMES < fight.start || fight.last < until )
+ continue;
+ if( scoutedNear( fight, place ) && ( besides == NULL || !scoutedNear( fight, *besides ) ) )
+ return TRUE;
+ }
+ return FALSE;
+}
+
+//-------------------------------------------------------------------------------------------------
+Int ObserverCamera_plannedSecond( const std::vector< DirectorMoment > &timeline, const Coord2D &first, UnsignedInt frame, Real apart,
+ Bool keeping )
{
Int best = -1;
for( size_t index = 0; index < timeline.size(); index++ )
{
const DirectorMoment &fight = timeline[ index ];
- if( fight.power || !ObserverCamera_worthFilming( fight ) || frame + DIRECTOR_PREROLL_FRAMES < fight.start || frame > fight.last )
+ if( fight.power || !ObserverCamera_worthFilming( fight ) || frame + SPLIT_LEAD_FRAMES < fight.start || frame > fight.last )
continue;
if( !keeping && frame >= fight.start )
continue;
- if( within( fight.place, first, SPLIT_APART ) )
+ if( within( fight.place, first, apart ) )
continue;
if( best < 0 || fight.peak > timeline[ best ].peak )
best = (Int)index;
@@ -935,6 +1007,9 @@ void ObserverCamera::reset( void )
m_fightSides.clear();
m_broadcast.clear();
m_broadcastTop = 0.0f;
+ m_screenGround = 0.0f;
+ m_circleGround = 0.0f;
+ m_splitApart = SPLIT_APART;
m_split = FALSE;
m_splitChanged = 0;
m_secondPlace.x = m_secondPlace.y = 0.0f;
@@ -1000,6 +1075,10 @@ void ObserverCamera::noteSpecialPower( const Player *owner, const Coord3D *from,
event.until = frame + ( superweapon ? EVENT_SUPERWEAPON_FRAMES : EVENT_FRAMES );
event.weight = superweapon ? EVENT_SUPERWEAPON_WEIGHT : EVENT_WEIGHT;
event.superweapon = superweapon;
+ // a power that only looks, a spy satellite or a radar scan, hurts nobody and is not filmed: the
+ // director cut to empty ground for every one an Air Force general fired. The scouting pass knows
+ // which ones land; without it a power waits for its first hit
+ event.landed = superweapon || ObserverCamera_powerLands( m_timeline, frame, event.target );
m_events.push_back( event );
if( !TheGlobalData->m_directorScoutFile.isEmpty() )
@@ -1009,7 +1088,7 @@ void ObserverCamera::noteSpecialPower( const Player *owner, const Coord3D *from,
moment.last = frame;
moment.place = event.source;
moment.target = event.target;
- moment.peak = event.weight;
+ moment.peak = superweapon ? event.weight : 0.0f;
moment.sides = owner->getPlayerMask();
moment.power = TRUE;
moment.superweapon = superweapon;
@@ -1297,14 +1376,12 @@ Coord2D ObserverCamera::mapShift( Int pane, const Coord2D &origin, const Coord2D
}
//-------------------------------------------------------------------------------------------------
-/** How far a circle of radius pixels round centre reaches on the ground at zoom, subject put on
- * centre: the nearest of eight points round it, picked on the subject's height. */
+/** How far a circle of radius pixels round centre reaches on the ground from subject, the point under
+ * centre, through the view as it is aimed: the nearest of eight points round it, picked on ground. */
//-------------------------------------------------------------------------------------------------
-Real ObserverCamera::groundReach( const Coord2D &subject, const Coord2D &centre, Real radius, Real zoom )
+static Real reachRound( const Coord2D &subject, const Coord2D &centre, Real radius, Real ground )
{
enum { REACH_POINTS = 8 };
- placeOnPixel( subject, centre, zoom );
- const Real ground = TheTerrainLogic->getGroundHeight( subject.x, subject.y );
Real nearest = 0.0f;
for( Int point = 0; point < REACH_POINTS; point++ )
{
@@ -1322,6 +1399,16 @@ Real ObserverCamera::groundReach( const Coord2D &subject, const Coord2D &centre,
return nearest;
}
+//-------------------------------------------------------------------------------------------------
+/** How far a circle of radius pixels round centre reaches on the ground at zoom, subject put on
+ * centre. */
+//-------------------------------------------------------------------------------------------------
+Real ObserverCamera::groundReach( const Coord2D &subject, const Coord2D &centre, Real radius, Real zoom )
+{
+ placeOnPixel( subject, centre, zoom );
+ return reachRound( subject, centre, radius, TheTerrainLogic->getGroundHeight( subject.x, subject.y ) );
+}
+
//-------------------------------------------------------------------------------------------------
/** The highest zoom from nearest up to wanted at which the pane, all in and its subject on its
* circle's centre, shows no ground past the map at any corner; nearest when none does. More ground
@@ -1381,6 +1468,64 @@ Coord2D ObserverCamera::placePane( Int pane, const Coord2D &subject, const Coord
return look;
}
+//-------------------------------------------------------------------------------------------------
+/** The ground the whole picture spans across its middle row, and the least a split's pane circle
+ * reaches round its centre, at the height of the ground the view looks at, through the camera the
+ * last draw built. Taken while there are no panes, when the view is the director's own at the zoom
+ * the panes would start from. */
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::measureScreenGround( void )
+{
+ Coord3D look;
+ TheTacticalView->getPosition( &look );
+ const Real ground = TheTerrainLogic->getGroundHeight( look.x, look.y );
+ const Int width = TheDisplay->getWidth();
+ const Int height = TheDisplay->getHeight();
+ ICoord2D left, right;
+ left.x = 0;
+ right.x = width - 1;
+ left.y = right.y = height / 2;
+ Coord3D leftGround, rightGround;
+ TheTacticalView->screenToWorldAtZ( &left, &leftGround, ground );
+ TheTacticalView->screenToWorldAtZ( &right, &rightGround, ground );
+ const Real dx = rightGround.x - leftGround.x;
+ const Real dy = rightGround.y - leftGround.y;
+ m_screenGround = sqrtf( dx * dx + dy * dy );
+
+ Real rays[ OBSERVER_MOST_PANES ];
+ const Int count = ObserverCamera_paneLayout( 2, rays );
+ Coord2D centres[ OBSERVER_MOST_PANES ];
+ Real radii[ OBSERVER_MOST_PANES ];
+ ObserverCamera_paneCircles( rays, count, width, height, m_radarHalf, m_broadcastTop, centres, radii );
+ for( Int pane = 0; pane < count; pane++ )
+ {
+ ICoord2D at;
+ at.x = REAL_TO_INT( centres[ pane ].x );
+ at.y = REAL_TO_INT( centres[ pane ].y );
+ Coord3D under;
+ TheTacticalView->screenToWorldAtZ( &at, &under, ground );
+ const Coord2D subject = { under.x, under.y };
+ const Real reach = reachRound( subject, centres[ pane ], radii[ pane ], ground );
+ m_circleGround = pane == 0 ? reach : min( m_circleGround, reach );
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The ground a split's pane would span across its middle row with the fight round subject fitted
+ * into its circle, the way fitPanes fits it. */
+//-------------------------------------------------------------------------------------------------
+Real ObserverCamera::paneGround( const Coord2D &subject ) const
+{
+ const Real extent = ObserverCamera_extentAround( m_fights, subject, DIRECTOR_GATHER_RADIUS, PANE_FIT_LEAST_EXTENT );
+ return ObserverCamera_paneGround( m_screenGround, m_circleGround, extent * ( 1.0f + PANE_FIT_MARGIN ) );
+}
+
+//-------------------------------------------------------------------------------------------------
+Real ObserverCamera::splitApart( const Coord2D &second ) const
+{
+ return max( SPLIT_APART, max( paneGround( m_place ), paneGround( second ) ) );
+}
+
//-------------------------------------------------------------------------------------------------
/** -directorrecord: whether the picture is split, and the second fight it shows. Asked again only
* when the hits were counted again. Only real fighting counts, on both sides of the line: a base
@@ -1390,27 +1535,40 @@ Coord2D ObserverCamera::placePane( Int pane, const Coord2D &subject, const Coord
void ObserverCamera::updateSplit( void )
{
const UnsignedInt frame = TheGameLogic->getFrame();
+ if( m_paneCount < 2 )
+ measureScreenGround();
Coord2D middle;
Real firstHeat = ObserverCamera_heatAround( m_fights, m_place, &middle );
if( m_placeKind == PLACE_EVENT )
firstHeat = max( firstHeat, SPLIT_ENTER_HEAT );
+ // a second fight is looked for beyond what pane 0's own picture would span; a split up keeps the
+ // distance it opened at, so a fight that grows and zooms its pane out does not end it
+ const Real searched = m_split ? m_splitApart : splitApart( m_place );
Coord2D second = { 0.0f, 0.0f };
Real secondHeat = 0.0f;
- ObserverCamera_secondPlace( m_fights, m_place, &second, &secondHeat );
+ ObserverCamera_secondPlace( m_fights, m_place, searched, &second, &secondHeat );
if( secondHeat > 0.0f && ObserverCamera_fizzles( m_timeline, second, frame ) )
secondHeat = 0.0f;
+ // with a timeline a split is decided before it opens: pane 0 needs a fight the scouting pass saw
+ // last through the least hold, or a special power, or it is about to leave for something else and
+ // the split goes off before its panes are in
+ const Bool timelineKnown = !m_timeline.empty();
+ const UnsignedInt heldTo = frame + SPLIT_LEAST_FRAMES;
+ const Bool firstLasts = !timelineKnown || m_placeKind == PLACE_EVENT || ObserverCamera_fightLasts( m_timeline, m_place, frame, heldTo, NULL );
// the scouting pass knows the pairs: a second fight worth filming about to begin far enough away
// splits the picture before its first shot, pane 1 waiting where it begins, and keeps it split
// while it lasts. Once it is going it is wherever the hits are, and in a lull pane 1 stays put;
// sent back to where it began, pane 1 sat on empty ground while the fight went on elsewhere. The
// director that moved onto pane 1's fight has been handed it, and the split ends there: kept on
// by the timeline, pane 1 went over to the fight pane 0 had just left
- const Bool handedOver = m_split && within( m_place, m_secondPlace, SPLIT_APART );
- const Int planned = m_placeKind != PLACE_SIGHT ? ObserverCamera_plannedSecond( m_timeline, m_place, frame, m_split ) : -1;
+ const Real sameGround = searched * SPLIT_SAME_GROUND_SHARE;
+ const Bool handedOver = m_split && within( m_place, m_secondPlace, sameGround );
+ const Bool mayPlan = m_placeKind != PLACE_SIGHT && ( m_split || firstLasts );
+ const Int planned = mayPlan ? ObserverCamera_plannedSecond( m_timeline, m_place, frame, searched, m_split ) : -1;
const Bool plannedSplit = planned >= 0;
- if( plannedSplit && frame < m_timeline[ planned ].start && ( secondHeat <= 0.0f || !within( second, m_timeline[ planned ].place, SPLIT_APART ) ) )
+ if( plannedSplit && frame < m_timeline[ planned ].start && ( secondHeat <= 0.0f || !within( second, m_timeline[ planned ].place, sameGround ) ) )
second = m_timeline[ planned ].place;
- else if( plannedSplit && secondHeat <= 0.0f )
+ else if( m_split && secondHeat <= 0.0f )
second = m_secondPlace;
// the second fight is followed once it has moved a little, the way the director follows its own
@@ -1423,14 +1581,26 @@ void ObserverCamera::updateSplit( void )
const Real ay = shown.y - m_place.y;
const Real apart = sqrtf( ax * ax + ay * ay );
+ // with the second fight known, both panes' pictures say how far apart is far enough
+ const Real needed = m_split ? m_splitApart : splitApart( shown );
const UnsignedInt since = frame >= m_splitChanged ? frame - m_splitChanged : 0;
- const Bool split = !handedOver && ( plannedSplit || ObserverCamera_holdSplit( m_split, firstHeat, secondHeat, apart, since ) );
+ // a planned split rests after the last one like any other: opened 45 frames after one went off,
+ // the radar slid back into its corner and straight out again
+ const Bool plannedOpens = plannedSplit && ( m_split || since >= SPLIT_REST_FRAMES );
+ Bool split = plannedOpens || ObserverCamera_holdSplit( m_split, firstHeat, secondHeat, apart, needed, since );
+ // a live split opens, with a timeline, only on two different fights the scouting pass saw last: a
+ // crowd beside pane 0's that the pass saw as part of it was pane 0's fight spreading, and the split
+ // went off again two seconds later, once the director had followed it there
+ if( split && !m_split && !plannedSplit && timelineKnown )
+ split = firstLasts && ObserverCamera_fightLasts( m_timeline, shown, frame, heldTo, &m_place );
+ split = split && !handedOver && apart > needed * SPLIT_SAME_GROUND_SHARE;
if( split != m_split )
{
- DEBUG_LOG(( "OBSCAM frame %u split %s, first heat %.1f, second (%.0f,%.0f) heat %.1f, %.0f apart%s\n", frame,
- split ? "on" : "off", firstHeat, shown.x, shown.y, secondHeat, apart, plannedSplit ? ", planned" : "" ));
+ DEBUG_LOG(( "OBSCAM frame %u split %s, first heat %.1f, second (%.0f,%.0f) heat %.1f, %.0f apart of %.0f needed, screen %.0f%s\n",
+ frame, split ? "on" : "off", firstHeat, shown.x, shown.y, secondHeat, apart, needed, m_screenGround, plannedSplit ? ", planned" : "" ));
m_split = split;
m_splitChanged = frame;
+ m_splitApart = needed;
}
if( m_split )
m_secondPlace = shown;
@@ -1917,6 +2087,7 @@ void ObserverCamera::scout( void )
obj->isKindOf( KINDOF_FS_SUPERWEAPON ) );
hits.push_back( hit );
}
+ ObserverCamera_markLandings( m_scouted, hits, frame );
ObserverCamera_trackFights( m_scouted, hits, frame );
}
@@ -2108,6 +2279,9 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
// hits at the target keep it going: the missiles arriving, the bombs, the fires after
if( frame >= event.since + EVENT_LAUNCH_FRAMES && ObserverCamera_heatAround( hits, event.target, &middle ) > 0.0f )
event.until = max( event.until, frame + EVENT_AFTERMATH_FRAMES );
+ event.landed = event.landed || ObserverCamera_heatAround( fights, event.target, &middle ) > 0.0f;
+ if( !event.landed )
+ continue;
if( best == NULL || event.weight >= best->weight )
best = &event;
}
@@ -2148,7 +2322,7 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
m_placeSince = frame;
}
// the fight pane 1 holds stays pane 1's: pane 0 going there swapped the two panes' subjects
- const Int upcoming = timeline ? ObserverCamera_prerollMoment( m_timeline, frame, m_split ? &m_secondPlace : NULL ) : -1;
+ const Int upcoming = timeline ? ObserverCamera_prerollMoment( m_timeline, frame, m_split ? &m_secondPlace : NULL, m_splitApart ) : -1;
if( upcoming >= 0 && upcoming != m_placeMoment )
{
const DirectorMoment &moment = m_timeline[ upcoming ];
@@ -2174,7 +2348,7 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
const Real heatHere = ObserverCamera_heatAround( hits, m_place, &followed );
// a split's pane 0 keeps its own fight while it goes on rather than take pane 1's; once it is
// over the director moves there and the split ends, pane 1's fight handed to pane 0
- const Bool heldByPaneOne = m_split && within( hottest, m_secondPlace, SPLIT_APART );
+ const Bool heldByPaneOne = m_split && within( hottest, m_secondPlace, m_splitApart );
if( heatHere > 0.0f && ( sameFight( hottest, followed ) || heldByPaneOne || !ObserverCamera_shouldMove( heatHere, hottestHeat, held ) ) )
{
const Real dx = followed.x - m_place.x;
diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.inc
index 28be7aea8..8c81ecfa6 100644
--- a/GeneralsMD/Code/Tests/test_observer_camera.inc
+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc
@@ -302,14 +302,17 @@ TEST(the_recording_splits_for_a_second_fight_far_from_the_first_and_never_for_th
Coord2D second;
Real heat = 0.0f;
- CHECK( !ObserverCamera_secondPlace( hits, first, &second, &heat ) );
+ const Real needed = 660.0f;
+ CHECK( !ObserverCamera_secondPlace( hits, first, needed, &second, &heat ) );
for( Int each = 0; each < 3; each++ )
hits.push_back( directorHit( 3000.0f, 3000.0f + each * 20.0f ) );
- CHECK( ObserverCamera_secondPlace( hits, first, &second, &heat ) );
+ CHECK( ObserverCamera_secondPlace( hits, first, needed, &second, &heat ) );
CHECK_NEAR( heat, 3.0f, 0.001f );
CHECK_NEAR( second.x, 3000.0f, 0.001f );
CHECK_NEAR( second.y, 3020.0f, 0.001f );
+ // a picture that spans more ground wants the second fight further off
+ CHECK( !ObserverCamera_secondPlace( hits, first, 3000.0f, &second, &heat ) );
}
TEST(the_recording_splits_for_a_big_second_fight_holds_it_and_rests_after)
@@ -318,40 +321,68 @@ TEST(the_recording_splits_for_a_big_second_fight_holds_it_and_rests_after)
const UnsignedInt justJoined = 2 * LOGICFRAMES_PER_SECOND;
const UnsignedInt longHeld = 8 * LOGICFRAMES_PER_SECOND;
const Real farApart = 2000.0f;
+ const Real needed = 660.0f;
// on for a second fight hot on its own and at least half the first
- CHECK( ObserverCamera_holdSplit( FALSE, 6.0f, 3.0f, farApart, rested ) );
- CHECK( !ObserverCamera_holdSplit( FALSE, 8.0f, 3.0f, farApart, rested ) );
- CHECK( !ObserverCamera_holdSplit( FALSE, 1.0f, 1.5f, farApart, rested ) );
+ CHECK( ObserverCamera_holdSplit( FALSE, 6.0f, 3.0f, farApart, needed, rested ) );
+ CHECK( !ObserverCamera_holdSplit( FALSE, 8.0f, 3.0f, farApart, needed, rested ) );
+ CHECK( !ObserverCamera_holdSplit( FALSE, 1.0f, 1.5f, farApart, needed, rested ) );
// not straight back on after it went off
- CHECK( !ObserverCamera_holdSplit( FALSE, 6.0f, 3.0f, farApart, 2 * LOGICFRAMES_PER_SECOND ) );
+ CHECK( !ObserverCamera_holdSplit( FALSE, 6.0f, 3.0f, farApart, needed, 2 * LOGICFRAMES_PER_SECOND ) );
// held a few seconds while the second fight goes on at all, then only while it keeps a quarter
- CHECK( ObserverCamera_holdSplit( TRUE, 6.0f, 0.5f, farApart, justJoined ) );
- CHECK( ObserverCamera_holdSplit( TRUE, 8.0f, 2.0f, farApart, longHeld ) );
- CHECK( !ObserverCamera_holdSplit( TRUE, 8.0f, 1.9f, farApart, longHeld ) );
+ CHECK( ObserverCamera_holdSplit( TRUE, 6.0f, 0.5f, farApart, needed, justJoined ) );
+ CHECK( ObserverCamera_holdSplit( TRUE, 8.0f, 2.0f, farApart, needed, longHeld ) );
+ CHECK( !ObserverCamera_holdSplit( TRUE, 8.0f, 1.9f, farApart, needed, longHeld ) );
}
TEST(the_recording_split_ends_at_once_when_the_two_halves_show_one_fight)
{
const UnsignedInt justJoined = 2 * LOGICFRAMES_PER_SECOND;
+ const Real needed = 660.0f;
// the director moved onto the second fight: both halves would show the same ground
- CHECK( !ObserverCamera_holdSplit( TRUE, 12.0f, 8.0f, 60.0f, justJoined ) );
- CHECK( !ObserverCamera_holdSplit( FALSE, 6.0f, 6.0f, 600.0f, 5 * LOGICFRAMES_PER_SECOND ) );
- // the second fight is over, however new the split
- CHECK( !ObserverCamera_holdSplit( TRUE, 6.0f, 0.0f, 2000.0f, justJoined ) );
+ CHECK( !ObserverCamera_holdSplit( TRUE, 12.0f, 8.0f, 60.0f, needed, justJoined ) );
+ CHECK( !ObserverCamera_holdSplit( FALSE, 6.0f, 6.0f, 600.0f, needed, 5 * LOGICFRAMES_PER_SECOND ) );
+}
+
+TEST(a_split_once_on_stays_until_its_panes_are_in_and_held_six_seconds)
+{
+ const Real needed = 660.0f;
+ // in through the radar's slide and the panes' and held six seconds, whatever the second fight does:
+ // one that went off on the next scan slid a pane in and straight back out
+ const UnsignedInt least = 12 + 15 + 6 * LOGICFRAMES_PER_SECOND;
+ CHECK( ObserverCamera_holdSplit( TRUE, 6.0f, 0.0f, 2000.0f, needed, 15 ) );
+ CHECK( ObserverCamera_holdSplit( TRUE, 6.0f, 0.0f, 2000.0f, needed, least - 1 ) );
+ CHECK( !ObserverCamera_holdSplit( TRUE, 6.0f, 0.0f, 2000.0f, needed, least ) );
+}
+
+TEST(a_split_wants_its_fights_further_apart_the_more_ground_a_pane_shows)
+{
+ const UnsignedInt rested = 5 * LOGICFRAMES_PER_SECOND;
+ const UnsignedInt longHeld = 8 * LOGICFRAMES_PER_SECOND;
+ // panes 1650 across: a split opens past 1650, and a held one stays past 1100
+ const Real needed = 1650.0f;
+ CHECK( !ObserverCamera_holdSplit( FALSE, 6.0f, 6.0f, 1600.0f, needed, rested ) );
+ CHECK( ObserverCamera_holdSplit( FALSE, 6.0f, 6.0f, 1700.0f, needed, rested ) );
+ CHECK( ObserverCamera_holdSplit( TRUE, 6.0f, 6.0f, 1200.0f, needed, longHeld ) );
+ CHECK( !ObserverCamera_holdSplit( TRUE, 6.0f, 6.0f, 1050.0f, needed, 15 ) );
+ // a picture 460 across whose pane circle reaches 100: a fight fitted into 172 zooms the pane out
+ // 1.72 times, a smaller one leaves it at the director's zoom, a huge one stops at three times
+ CHECK_NEAR( ObserverCamera_paneGround( 460.0f, 100.0f, 172.0f ), 791.2f, 0.01f );
+ CHECK_NEAR( ObserverCamera_paneGround( 460.0f, 100.0f, 60.0f ), 460.0f, 0.01f );
+ CHECK_NEAR( ObserverCamera_paneGround( 460.0f, 100.0f, 1000.0f ), 1380.0f, 0.01f );
}
TEST(the_recording_splits_only_beside_a_real_fight)
{
// bases going up are no fight: the split's hits are only one side's on another, so the director
// looking at a sight has no heat of its own and a second fight does not split the picture
- CHECK( !ObserverCamera_holdSplit( FALSE, 0.0f, 10.0f, 2000.0f, 5 * LOGICFRAMES_PER_SECOND ) );
+ CHECK( !ObserverCamera_holdSplit( FALSE, 0.0f, 10.0f, 2000.0f, 660.0f, 5 * LOGICFRAMES_PER_SECOND ) );
// and with no fight anywhere there is no second place to show
std::vector< DirectorHeat > none;
Coord2D first;
first.x = first.y = 1000.0f;
Coord2D second;
Real heat = 0.0f;
- CHECK( !ObserverCamera_secondPlace( none, first, &second, &heat ) );
+ CHECK( !ObserverCamera_secondPlace( none, first, 660.0f, &second, &heat ) );
}
TEST(every_pane_layout_cuts_on_45_degree_rays)
@@ -627,6 +658,38 @@ TEST(the_scout_counts_a_fight_worth_filming_only_when_it_got_hot_and_lasted)
CHECK( ObserverCamera_worthFilming( scoutedPower( 100, 0.0f, 0.0f, FALSE ) ) );
}
+TEST(a_special_power_is_worth_filming_only_once_it_hurts_somebody_where_it_was_aimed)
+{
+ // a spy satellite and a carpet bomb fired the same frame; only the bomb's target is hit
+ std::vector< DirectorMoment > moments;
+ moments.push_back( scoutedPower( 1800, 500.0f, 500.0f, FALSE ) );
+ moments.push_back( scoutedPower( 1800, 500.0f, 3000.0f, FALSE ) );
+ moments.push_back( scoutedPower( 1800, 500.0f, 5000.0f, TRUE ) );
+ moments[ 0 ].peak = moments[ 1 ].peak = 0.0f;
+ // the superweapon is filmed from its launch, hit or not
+ CHECK( ObserverCamera_worthFilming( moments[ 2 ] ) );
+ CHECK( !ObserverCamera_worthFilming( moments[ 1 ] ) );
+ std::vector< DirectorFightHit > hits;
+ hits.push_back( fightHit( 2100.0f, 3000.0f, 3 ) );
+ ObserverCamera_markLandings( moments, hits, 1950 );
+ CHECK( !ObserverCamera_worthFilming( moments[ 0 ] ) );
+ CHECK( ObserverCamera_worthFilming( moments[ 1 ] ) );
+ // a hit long after the launch is somebody else's
+ hits.push_back( fightHit( 2000.0f, 500.0f, 3 ) );
+ ObserverCamera_markLandings( moments, hits, 1800 + 13 * LOGICFRAMES_PER_SECOND );
+ CHECK( !ObserverCamera_worthFilming( moments[ 0 ] ) );
+
+ // the filming pass finds the power by its frame and its target, written without decimals
+ Coord2D at;
+ at.x = 2000.4f;
+ at.y = 3000.3f;
+ CHECK( ObserverCamera_powerLands( moments, 1800, at ) );
+ at.y = 500.0f;
+ CHECK( !ObserverCamera_powerLands( moments, 1800, at ) );
+ at.y = 3000.0f;
+ CHECK( !ObserverCamera_powerLands( moments, 1801, at ) );
+}
+
TEST(a_hot_fight_the_end_of_the_scouting_run_cut_short_is_still_worth_filming)
{
std::vector< DirectorMoment > timeline;
@@ -654,14 +717,14 @@ TEST(the_director_goes_to_wait_for_a_fight_four_seconds_before_it_starts_superwe
timeline.push_back( scoutedPower( 1020, 6000.0f, 1000.0f, FALSE ) );
timeline.push_back( scoutedPower( 1100, 6000.0f, 3000.0f, TRUE ) );
const UnsignedInt preroll = 4 * LOGICFRAMES_PER_SECOND;
- CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1000 - preroll - 1, NULL ), -1 );
- CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1000 - preroll, NULL ), 0 );
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1000 - preroll - 1, NULL, 660.0f ), -1 );
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1000 - preroll, NULL, 660.0f ), 0 );
// two coming up: the hotter
- CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1050 - preroll, NULL ), 1 );
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1050 - preroll, NULL, 660.0f ), 1 );
// a superweapon over any fight
- CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1100 - preroll, NULL ), 4 );
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1100 - preroll, NULL, 660.0f ), 4 );
// one that has started is no longer waited for
- CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1100, NULL ), -1 );
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1100, NULL, 660.0f ), -1 );
}
TEST(the_director_does_not_wait_for_the_fight_the_other_pane_already_shows)
@@ -674,9 +737,9 @@ TEST(the_director_does_not_wait_for_the_fight_the_other_pane_already_shows)
Coord2D taken;
taken.x = 3100.0f;
taken.y = 3000.0f;
- CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1050 - preroll, &taken ), 0 );
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1050 - preroll, &taken, 660.0f ), 0 );
// and with nothing else coming up, none
- CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1001, &taken ), -1 );
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1001, &taken, 660.0f ), -1 );
}
TEST(the_director_skips_only_a_fight_the_scout_saw_fizzle)
@@ -709,11 +772,40 @@ TEST(the_recording_splits_before_a_known_second_fight_far_from_the_first)
timeline.push_back( scoutedFight( 900, 1500, 6000.0f, 6000.0f, 2.0f ) );
Coord2D first;
first.x = first.y = 1000.0f;
- const UnsignedInt preroll = 4 * LOGICFRAMES_PER_SECOND;
- CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1000 - preroll - 1, FALSE ), -1 );
- CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1000 - preroll, FALSE ), 0 );
- CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1500, TRUE ), 0 );
- CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1501, TRUE ), -1 );
+ // three seconds ahead: at four pane 1 sat on an empty bridge
+ const UnsignedInt lead = 3 * LOGICFRAMES_PER_SECOND;
+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1000 - lead - 1, 660.0f, FALSE ), -1 );
+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1000 - lead, 660.0f, FALSE ), 0 );
+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1500, 660.0f, TRUE ), 0 );
+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1501, 660.0f, TRUE ), -1 );
+ // the fight 4243 away is too near once the picture is so wide a split wants 4300
+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1000 - lead, 4300.0f, FALSE ), -1 );
+}
+
+TEST(a_split_is_planned_only_beside_a_fight_that_outlasts_its_least_hold)
+{
+ std::vector< DirectorMoment > timeline;
+ timeline.push_back( scoutedFight( 1000, 1300, 1000.0f, 1000.0f, 8.0f ) );
+ timeline[ 0 ].target.x = 1400.0f;
+ timeline.push_back( scoutedFight( 1000, 1300, 3000.0f, 3000.0f, 2.0f ) );
+ Coord2D place;
+ place.x = 1050.0f;
+ place.y = 1000.0f;
+ CHECK( ObserverCamera_fightLasts( timeline, place, 1100, 1300, NULL ) );
+ CHECK( !ObserverCamera_fightLasts( timeline, place, 1100, 1301, NULL ) );
+ // near where it ended up as well as where it began
+ place.x = 1600.0f;
+ CHECK( ObserverCamera_fightLasts( timeline, place, 1100, 1300, NULL ) );
+ // but not for a second pane while the first shows where it began: that is the first pane's fight
+ Coord2D first;
+ first.x = first.y = 1000.0f;
+ CHECK( !ObserverCamera_fightLasts( timeline, place, 1100, 1300, &first ) );
+ first.x = first.y = 3000.0f;
+ CHECK( ObserverCamera_fightLasts( timeline, place, 1100, 1300, &first ) );
+ // one about to begin counts; a fizzle never does
+ CHECK( ObserverCamera_fightLasts( timeline, place, 1000 - 4 * LOGICFRAMES_PER_SECOND, 1300, NULL ) );
+ place.x = place.y = 3000.0f;
+ CHECK( !ObserverCamera_fightLasts( timeline, place, 1100, 1200, NULL ) );
}
TEST(the_recording_splits_ahead_for_a_fight_still_to_begin_and_not_anew_for_one_under_way)
@@ -724,10 +816,10 @@ TEST(the_recording_splits_ahead_for_a_fight_still_to_begin_and_not_anew_for_one_
first.x = 2346.0f;
first.y = 1668.0f;
// a split already up keeps the fight while it lasts
- CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 6451, TRUE ), 0 );
+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 6451, 660.0f, TRUE ), 0 );
// none up: where it began twenty seconds ago is no place to send a pane
- CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 6451, FALSE ), -1 );
- CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 5864, FALSE ), 0 );
+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 6451, 660.0f, FALSE ), -1 );
+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 5864, 660.0f, FALSE ), 0 );
}
TEST(a_timeline_line_reads_back_as_the_moment_it_was_written_from)