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(gameclient): scout a director record match headless before filming it

Olcay Seygan9d634053e20e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ef3a9667..9e5f5caf5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -748,7 +748,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- Watching, the bars over the buildings are everyone's too - what each factory is turning out, and how long the superweapons have left. An observer used to see none of it.
- Watching, the camera can drive itself. Two drop-downs in the camera panel on the right, above the board, say who has it and which player you follow, and you can follow nobody. The Director goes to the fight with the most on the line over the last five seconds, where a dead Overlord counts for more than six riflemen being shot at and anything happening to a superweapon counts three times over. It stays with that fight twelve seconds, leaves after six only for one four times the size, and after half a minute on the same fight a third bigger is enough. So a 4v4 is watched like a broadcast rather than hunted for, and it does not hop between spots every few seconds. Any general's power used on the map outranks every fight. A nuke is shown in its silo as it leaves, then the camera waits at the target for it to come down and stays through the blast. The particle cannon's beam is followed along its whole sweep, and a Scud Storm or a carpet bomb is watched until the last explosion has died down. Then it goes back to the fighting. The camera glides between places and slows into each one, and only cuts when the next one is across most of the map. When nobody is shooting it no longer parks on empty ground: it goes round what is worth seeing, an army on the march, a superweapon, a base going up, the rest of a base, the dearest first and fourteen seconds each, and does not come back to one of the last three while there is anything else to show. With a player picked it keeps to his fights and his own armies and buildings. Player camera shows his screen: a human player's camera comes over the network five times a second, smoothed in between, and a computer player, who has no camera, gets the Director narrowed to his own fights. Scroll with the keys or a drag, turn the view or click the radar and the camera is yours again, still following the same player. The edge of the screen does not scroll while it drives: the panel on the right stands on that edge, and reaching for it used to hand the camera back to you, so the Director stopped following the fighting the first time you went to change a setting. In a replay with the recorded camera switched on in the options, the player you follow still drives the camera the way his button in the old list did.
- Watching, the Director climbs over a wide battle until the whole of it is on the screen, and comes back down to your own height when it moves on or you take the camera. The mouse wheel still zooms while it drives, and it keeps what you chose. It stops short of the map's border too, where a fight on the edge used to come with a black corner of nothing beside it. A nuke or a Scud Storm is shown leaving its silo even when the Director has only just arrived at another fight; before, the launch was over by the time it was allowed to move. Rewinding a replay leaves your camera settings as they were, where a rewind used to hand you back a free camera with nobody followed. And following one player while a superweapon wiped out everything he had at the spot could close the game. It no longer does.
-- Watching can be filmed. Start the game with `-directorrecord` and the Director has the camera from the first second, with nothing over the picture but the radar, and the whole match goes into one video; the game closes itself when the match is decided or the replay runs out. Beside `-replay` it turns an old match into footage, and beside four computer players it films a match nobody played. The film opens on every player at once: the screen cut into one picture per player along lines at 45 degrees that meet round the radar, two players on a diagonal and four on an X, each picture on that player's base. Seven seconds in they sweep away to the Director's single view. When two real fights far apart are both worth watching, the radar slides out of its corner, then the second fight sweeps in from the corner along a 45 degree diagonal, carrying the radar in a frame of the same line to the middle, one fight on each side with its own camera gliding to it. Going back is the same film run backwards: the second fight sweeps out with the radar, and the radar slides back into its corner. The lines are the Reforged gold on a dark edge, so they read on snow and at night, and they run straight into the radar's frame. While the screen is cut, each picture frames its own fight: the camera puts it in the biggest round space its slice has clear of the lines and the radar, and rises until the whole fight fits there with room to spare, never lower than the Director flies and never more than twice as high. A fight that spreads is let out smoothly; one that shrinks does not make the picture pump in and out. The opening frames each player's base the same way. A split holds at least six seconds and ends once the second fight has burnt down to a quarter of the first, so the picture does not flicker between one and two. Only the video shows the other pictures; the window keeps the Director's own fight under the lines. Two bases going up are not a fight, and the split ends the moment the camera's own fight and the second one turn out to be the same. The pictures go straight into ffmpeg as they are drawn, so an hour of 1080p does not need tens of gigabytes of disk first; put ffmpeg beside the game or on your PATH, because without it nothing is recorded and the game says so and closes. Any recorded clip also plays its animations at their real speed now. The animation clock used to move by however long each picture took to save, and a slow disk made every explosion in the footage run fast.
+- Watching 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. 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. 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. 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/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index f8f9b1ae3..cceda7eb2 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -478,6 +478,8 @@ public:
Int m_videoEndFrame; ///< -video: the last logic frame recorded (0 = no video)
AsciiString m_videoName; ///< -video: the recording is Videos\<name>.mp4 next to the save games
Bool m_directorRecord; ///< -directorrecord [name]: the director films the whole match, split for two fights, and the run quits at its end
+ AsciiString m_directorScoutFile; ///< -directorscout <file>: -directorrecord's first pass, headless, writes the match's fights and special powers here
+ AsciiString m_directorTimelineFile; ///< -directortimeline <file>: what the first pass wrote, which the filming pass reads to arrive before each fight
Int m_wavStartFrame; ///< -wav <from> <to> [name]: the first logic frame of the sound recording
Int m_wavEndFrame; ///< -wav: the last logic frame recorded (0 = no sound recording)
AsciiString m_wavName; ///< -wav: the recording is Videos\<name>.wav next to the save games
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
index 04423b4ce..31d5d35ca 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
@@ -49,6 +49,7 @@
#ifndef _OBSERVER_CAMERA_H_
#define _OBSERVER_CAMERA_H_
+#include "Common/AsciiString.h"
#include "Common/GameCommon.h"
#include "GameClient/View.h"
@@ -84,6 +85,53 @@ struct DirectorEvent
Bool superweapon;
};
+/// -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
+struct DirectorMoment
+{
+ UnsignedInt start;
+ UnsignedInt last;
+ Coord2D place;
+ Coord2D target;
+ Real peak;
+ UnsignedInt sides;
+ Bool power;
+ Bool superweapon;
+};
+
+/// one hit a player dealt another he is at war with, for the scouting pass: where, what it counts
+/// for, and the two players' masks together
+struct DirectorFightHit
+{
+ Coord2D position;
+ Real weight;
+ UnsignedInt sides;
+};
+
+/// the scouting pass's fights carried over one scan of the hits. Each crowd of hits, hottest first,
+/// 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
+Bool ObserverCamera_worthFilming( const DirectorMoment &moment );
+/// 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. -1 for none
+Int ObserverCamera_prerollMoment( const std::vector< DirectorMoment > &timeline, UnsignedInt frame );
+/// 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 going on at frame, or beginning within the pre-roll, far enough from first
+/// to want a pane of its own: the hottest such, where it begins; FALSE for none
+Bool ObserverCamera_plannedSecond( const std::vector< DirectorMoment > &timeline, const Coord2D &first, UnsignedInt frame, Coord2D *second );
+/// 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 );
+
/// how fast the camera is going on each of its six axes, carried from one frame's step to the next
struct ObserverCameraVelocity
{
@@ -241,6 +289,12 @@ public:
void beginPanePass( Int pane );
void endPanePass( void );
+ /// -directorrecord's scouting pass, once a pass of a headless run: count the fights on every scan
+ /// and a checkpoint of the logic's CRC now and then
+ void scout( void );
+ /// and at its end, the timeline written to the -directorscout file
+ void finishScout( void );
+
enum { NO_PLAYER = -1 };
private:
@@ -270,8 +324,27 @@ private:
Bool directorPlace( const Player *narrowTo, Coord2D *place );
DirectorEvent *findEvent( UnsignedInt id );
void dropOldEvents( UnsignedInt frame );
+ void loadTimeline( void );
+ void checkTimeline( UnsignedInt frame );
+
+ /// a sight, a fight going on, a special power, or a fight the timeline says is about to begin
+ enum PlaceKind { PLACE_SIGHT, PLACE_FIGHT, PLACE_EVENT, PLACE_UPCOMING };
+
+ /// a logic frame and the logic's CRC on it, which the two passes compare to know they played one match
+ struct CrcCheckpoint
+ {
+ UnsignedInt frame;
+ UnsignedInt crc;
+ };
- enum PlaceKind { PLACE_SIGHT, PLACE_FIGHT, PLACE_EVENT };
+ std::vector< DirectorMoment > m_scouted; ///< the scouting pass's fights and special powers so far
+ std::vector< CrcCheckpoint > m_scoutCrcs; ///< and its checkpoints
+ UnsignedInt m_scoutScanned; ///< the logic frame it last counted the hits on
+ std::vector< DirectorMoment > m_timeline; ///< what the scouting pass saw, for the filming pass
+ std::vector< CrcCheckpoint > m_timelineCrcs;
+ Bool m_timelineLoaded;
+ Int m_placeMoment; ///< the timeline's moment the director waits at, while the place is one
+ Coord2D m_skippedFight; ///< the last fizzling fight the director passed over, so it is logged once
ObserverCameraMode m_mode;
Int m_followed;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index 8e18d1637..f1f726d38 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -1567,6 +1567,25 @@ Int parseDirectorRecord(char *args[], int num)
return consumed;
}
+/* -directorscout <file> and -directortimeline <file>: the two passes of -directorrecord. WinMain
+ starts the same match again headless with -directorscout before it films anything, and that run
+ writes down where and when every fight starts and every special power is used; the filming run
+ is handed the file with -directortimeline and arrives at each fight before it starts. Neither is
+ a switch for a person: WinMain names the file and passes both. */
+Int parseDirectorScout(char *args[], int num)
+{
+ if (TheWritableGlobalData && num > 1)
+ TheWritableGlobalData->m_directorScoutFile = args[1];
+ return 2;
+}
+
+Int parseDirectorTimeline(char *args[], int num)
+{
+ if (TheWritableGlobalData && num > 1)
+ TheWritableGlobalData->m_directorTimelineFile = args[1];
+ return 2;
+}
+
/* -wav <from> <to> [name]: record what the game sounds like over logic frames <from> to <to>.
*
* A movie made by -video has no sound in it: the picture comes from a frame dump and the frames are
@@ -2582,6 +2601,8 @@ static CommandLineParam params[] =
{ "-showHudOverlay", parseShowHudOverlay },
{ "-video", parseVideo },
{ "-directorrecord", parseDirectorRecord },
+ { "-directorscout", parseDirectorScout },
+ { "-directortimeline", parseDirectorTimeline },
{ "-wav", parseWav },
{ "-turbo", parseTurbo },
{ "-msaa", parseMSAA },
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 8a66d775d..eebf513f7 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -123,6 +123,7 @@
#include "GameClient/GUICallbacks.h"
#include "GameClient/ControlBar.h" // -uidrill works the command bar the way a player does
#include "GameClient/InGameUI.h" // -resdrill selects a building before it changes the mode
+#include "GameClient/ObserverCamera.h" // -directorscout counts the fights of a headless run
#include "GameLogic/Object.h"
#include "GameNetwork/GameInfo.h"
@@ -2317,7 +2318,8 @@ static void updateHeadlessRun( void )
than a decision, goes back to the shell, and the run ends there; the display's teardown
finishes the movie. */
static Bool directorRecordSawMatch = FALSE;
- if (TheGlobalData->m_directorRecord && !TheGameEngine->getQuitting())
+ const Bool scouting = !TheGlobalData->m_directorScoutFile.isEmpty();
+ if ((TheGlobalData->m_directorRecord || scouting) && !TheGameEngine->getQuitting())
{
const Bool inMatch = TheGameLogic->isInGame() && !TheGameLogic->isInShellGame();
if (inMatch)
@@ -2327,6 +2329,8 @@ static void updateHeadlessRun( void )
else if (directorRecordSawMatch)
{
DEBUG_LOG(("-directorrecord: the match is over, quitting\n"));
+ if (scouting)
+ TheObserverCamera.finishScout();
TheGameEngine->setQuitting( TRUE );
return;
}
@@ -2354,6 +2358,10 @@ static void updateHeadlessRun( void )
const UnsignedInt frame = TheGameLogic->getFrame();
+ // -directorrecord's scouting pass: a headless run of the same match counting its fights
+ if (scouting)
+ TheObserverCamera.scout();
+
/* -screenshot <n>: hand the renderer a shot request as the run passes frame n. W3DDisplay only
sets a pending flag here and writes the file out of the back buffer on its next draw, so this
does something only in a run that is drawing - -autoskirmish without -headless. It is the
@@ -2501,6 +2509,9 @@ static void updateHeadlessRun( void )
slot, team));
}
+ if (scouting)
+ TheObserverCamera.finishScout();
+
/* Tear the match down the way the benchmark timer does, so the replay of the run is closed and
written rather than left half-flushed by the process going away. */
if (TheRecorder->getMode() == RECORDERMODETYPE_RECORD)
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 9f1c66eda..d344f1205 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -733,6 +733,8 @@ GlobalData::GlobalData()
m_videoEndFrame = 0; // record nothing unless -video asks for a range
m_videoName.clear();
m_directorRecord = FALSE;
+ m_directorScoutFile.clear();
+ m_directorTimelineFile.clear();
m_wavStartFrame = 0;
m_wavEndFrame = 0; // record no sound unless -wav asks for a range
m_wavName.clear();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
index d5b04cc82..ea0d87be8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
@@ -139,6 +139,20 @@ static const Real PANE_FIT_LEAST_EXTENT = 150.0f;
static const Real PANE_INTRO_REACH = 500.0f;
/// how much of the way to a new fit a pane's zoom goes each logic frame, about a second and a half
static const Real PANE_FIT_FOLLOW = 0.06f;
+/// the scouting pass: a crowd of hits this near a fight still going is more of that fight
+static const Real SCOUT_SAME_FIGHT = 2.0f * DIRECTOR_GATHER_RADIUS;
+/// a fight with no crowd near it for this long is over; its hits stay hot DIRECTOR_HEAT_FRAMES on top
+static const UnsignedInt SCOUT_FIGHT_GAP = 3 * LOGICFRAMES_PER_SECOND;
+/// a fight is worth filming once one scan of it was this hot and it ran this long, hot tail and all;
+/// a jeep shot up on its way past is neither
+static const Real FIGHT_WORTH_HEAT = 4.0f;
+static const UnsignedInt FIGHT_WORTH_FRAMES = 8 * LOGICFRAMES_PER_SECOND;
+/// the director goes to wait at a fight this long before it begins: the glide takes about a second
+/// and a half of it
+static const UnsignedInt DIRECTOR_PREROLL_FRAMES = 4 * LOGICFRAMES_PER_SECOND;
+/// both passes take the logic's CRC this often, and a filming pass whose CRC differs from the
+/// scouting pass's is not playing the match the timeline describes
+static const UnsignedInt SCOUT_CRC_FRAMES = 30 * LOGICFRAMES_PER_SECOND;
//-------------------------------------------------------------------------------------------------
static Bool sameFight( const Coord2D &a, const Coord2D &b )
@@ -645,6 +659,185 @@ Int ObserverCamera_panePolygon( const Real *rays, Int count, Int pane, const Coo
return found;
}
+//-------------------------------------------------------------------------------------------------
+static Real distanceSquared( const Coord2D &a, const Coord2D &b )
+{
+ const Real dx = a.x - b.x;
+ const Real dy = a.y - b.y;
+ return dx * dx + dy * dy;
+}
+
+static Bool within( const Coord2D &a, const Coord2D &b, Real distance )
+{
+ return distanceSquared( a, b ) <= distance * distance;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A crowd's hits are taken out of the scan before the next hottest place is looked for, so each
+ * pass of the loop is another crowd. The crowd's own first hit lies within the gather radius of
+ * the crowd's middle, which is a weighted middle of hits all within that radius of it, so every
+ * pass takes at least one hit out. */
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera_trackFights( std::vector< DirectorMoment > &fights, const std::vector< DirectorFightHit > &hits, UnsignedInt frame )
+{
+ std::vector< DirectorHeat > left;
+ std::vector< UnsignedInt > leftSides;
+ for( size_t index = 0; index < hits.size(); index++ )
+ {
+ DirectorHeat heat;
+ heat.position = hits[ index ].position;
+ heat.weight = hits[ index ].weight;
+ left.push_back( heat );
+ leftSides.push_back( hits[ index ].sides );
+ }
+
+ Coord2D crowd;
+ Real heat = 0.0f;
+ while( ObserverCamera_hottestPlace( left, &crowd, &heat ) )
+ {
+ UnsignedInt sides = 0;
+ size_t kept = 0;
+ for( size_t index = 0; index < left.size(); index++ )
+ {
+ if( sameFight( left[ index ].position, crowd ) )
+ {
+ sides |= leftSides[ index ];
+ continue;
+ }
+ left[ kept ] = left[ index ];
+ leftSides[ kept ] = leftSides[ index ];
+ kept++;
+ }
+ left.resize( kept );
+ leftSides.resize( kept );
+
+ DirectorMoment *joined = NULL;
+ for( size_t index = 0; index < fights.size(); index++ )
+ {
+ DirectorMoment &fight = fights[ index ];
+ if( fight.power || frame > fight.last + SCOUT_FIGHT_GAP || !within( fight.target, crowd, SCOUT_SAME_FIGHT ) )
+ continue;
+ if( joined == NULL || distanceSquared( fight.target, crowd ) < distanceSquared( joined->target, crowd ) )
+ joined = &fight;
+ }
+ if( joined == NULL )
+ {
+ DirectorMoment fight;
+ fight.start = frame;
+ fight.last = frame;
+ fight.place = crowd;
+ fight.target = crowd;
+ fight.peak = heat;
+ fight.sides = sides;
+ fight.power = FALSE;
+ fight.superweapon = FALSE;
+ fights.push_back( fight );
+ continue;
+ }
+ joined->last = frame;
+ joined->target = crowd;
+ joined->peak = max( joined->peak, heat );
+ joined->sides |= sides;
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool ObserverCamera_worthFilming( const DirectorMoment &moment )
+{
+ return moment.power || ( moment.peak >= FIGHT_WORTH_HEAT && moment.last - moment.start >= FIGHT_WORTH_FRAMES );
+}
+
+//-------------------------------------------------------------------------------------------------
+Int ObserverCamera_prerollMoment( const std::vector< DirectorMoment > &timeline, UnsignedInt frame )
+{
+ Int best = -1;
+ for( size_t index = 0; index < timeline.size(); index++ )
+ {
+ const DirectorMoment &moment = timeline[ index ];
+ if( moment.start <= frame || moment.start > frame + DIRECTOR_PREROLL_FRAMES )
+ continue;
+ if( moment.power ? !moment.superweapon : !ObserverCamera_worthFilming( moment ) )
+ continue;
+ if( best >= 0 )
+ {
+ const DirectorMoment &held = timeline[ best ];
+ const Bool better = moment.superweapon != held.superweapon ? moment.superweapon : moment.peak > held.peak;
+ if( !better )
+ continue;
+ }
+ best = (Int)index;
+ }
+ return best;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A fight is looked for from a scan before the scouting pass first saw it to the end of its gap,
+ * the two passes' scans need not fall on the same frames; near where it began or where it was last
+ * seen, since a fight moves. */
+//-------------------------------------------------------------------------------------------------
+Bool ObserverCamera_fizzles( const std::vector< DirectorMoment > &timeline, const Coord2D &place, UnsignedInt frame )
+{
+ Bool seen = FALSE;
+ for( size_t index = 0; index < timeline.size(); index++ )
+ {
+ const DirectorMoment &fight = timeline[ index ];
+ if( fight.power || frame + DIRECTOR_SCAN_FRAMES < fight.start || frame > fight.last + SCOUT_FIGHT_GAP )
+ continue;
+ if( !within( fight.place, place, SCOUT_SAME_FIGHT ) && !within( fight.target, place, SCOUT_SAME_FIGHT ) )
+ continue;
+ if( ObserverCamera_worthFilming( fight ) )
+ return FALSE;
+ seen = TRUE;
+ }
+ return seen;
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool ObserverCamera_plannedSecond( const std::vector< DirectorMoment > &timeline, const Coord2D &first, UnsignedInt frame, Coord2D *second )
+{
+ 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 )
+ continue;
+ if( within( fight.place, first, SPLIT_APART ) )
+ continue;
+ if( best < 0 || fight.peak > timeline[ best ].peak )
+ best = (Int)index;
+ }
+ if( best < 0 )
+ return FALSE;
+ *second = timeline[ best ].place;
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------------------------------
+AsciiString ObserverCamera_formatMoment( const DirectorMoment &moment )
+{
+ AsciiString line;
+ line.format( "%s %u %u %.0f %.0f %.0f %.0f %.2f %u %d", moment.power ? "power" : "fight", moment.start, moment.last,
+ moment.place.x, moment.place.y, moment.target.x, moment.target.y, moment.peak, moment.sides, moment.superweapon ? 1 : 0 );
+ return line;
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool ObserverCamera_parseMoment( const char *line, DirectorMoment *moment )
+{
+ char kind[ 8 ];
+ Int superweapon = 0;
+ const Int read = sscanf( line, "%7s %u %u %f %f %f %f %f %u %d", kind, &moment->start, &moment->last, &moment->place.x,
+ &moment->place.y, &moment->target.x, &moment->target.y, &moment->peak, &moment->sides, &superweapon );
+ if( read != 10 )
+ return FALSE;
+ const Bool power = strcmp( kind, "power" ) == 0;
+ if( !power && strcmp( kind, "fight" ) != 0 )
+ return FALSE;
+ moment->power = power;
+ moment->superweapon = superweapon != 0;
+ return TRUE;
+}
+
//-------------------------------------------------------------------------------------------------
Real ObserverCamera_easeFrames( UnsignedInt frame, UnsignedInt start, UnsignedInt length )
{
@@ -673,6 +866,9 @@ Int ObserverCamera_paneSeamBand( Int height )
//-------------------------------------------------------------------------------------------------
ObserverCamera::ObserverCamera()
{
+ // the timeline is the whole process's, read once and kept across the resets a match start makes
+ m_scoutScanned = 0;
+ m_timelineLoaded = FALSE;
reset();
}
@@ -701,6 +897,8 @@ void ObserverCamera::reset( void )
m_placeKind = PLACE_SIGHT;
m_placeHeight = 0.0f;
m_placeEvent = 0;
+ m_placeMoment = -1;
+ m_skippedFight.x = m_skippedFight.y = 0.0f;
m_seen.clear();
m_events.clear();
m_nextEventId = 1;
@@ -770,6 +968,20 @@ void ObserverCamera::noteSpecialPower( const Player *owner, const Coord3D *from,
event.weight = superweapon ? EVENT_SUPERWEAPON_WEIGHT : EVENT_WEIGHT;
event.superweapon = superweapon;
m_events.push_back( event );
+
+ if( !TheGlobalData->m_directorScoutFile.isEmpty() )
+ {
+ DirectorMoment moment;
+ moment.start = frame;
+ moment.last = frame;
+ moment.place = event.source;
+ moment.target = event.target;
+ moment.peak = event.weight;
+ moment.sides = owner->getPlayerMask();
+ moment.power = TRUE;
+ moment.superweapon = superweapon;
+ m_scouted.push_back( moment );
+ }
}
//-------------------------------------------------------------------------------------------------
@@ -1152,6 +1364,14 @@ void ObserverCamera::updateSplit( void )
Coord2D second = { 0.0f, 0.0f };
Real secondHeat = 0.0f;
ObserverCamera_secondPlace( m_fights, m_place, &second, &secondHeat );
+ if( secondHeat > 0.0f && ObserverCamera_fizzles( m_timeline, second, frame ) )
+ secondHeat = 0.0f;
+ // the scouting pass knows the pairs: a second fight worth filming going on or about to begin far
+ // enough away splits the picture before its first shot, and keeps it split while it lasts
+ Coord2D planned;
+ const Bool plannedSplit = m_placeKind != PLACE_SIGHT && ObserverCamera_plannedSecond( m_timeline, m_place, frame, &planned );
+ if( plannedSplit && ( secondHeat <= 0.0f || !within( second, planned, SPLIT_APART ) ) )
+ second = planned;
// the second fight is followed once it has moved a little, the way the director follows its own
Coord2D shown = m_secondPlace;
@@ -1164,11 +1384,11 @@ void ObserverCamera::updateSplit( void )
const Real apart = sqrtf( ax * ax + ay * ay );
const UnsignedInt since = frame >= m_splitChanged ? frame - m_splitChanged : 0;
- const Bool split = ObserverCamera_holdSplit( m_split, firstHeat, secondHeat, apart, since );
+ const Bool split = plannedSplit || ObserverCamera_holdSplit( m_split, firstHeat, secondHeat, apart, since );
if( split != m_split )
{
- DEBUG_LOG(( "OBSCAM frame %u split %s, first heat %.1f, second (%.0f,%.0f) heat %.1f, %.0f apart\n", frame,
- split ? "on" : "off", firstHeat, shown.x, shown.y, secondHeat, apart ));
+ 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" : "" ));
m_split = split;
m_splitChanged = frame;
}
@@ -1533,6 +1753,151 @@ Bool ObserverCamera::takenByHand( const ViewLocation &current ) const
return dx * dx + dy * dy > HAND_JUMP_DISTANCE * HAND_JUMP_DISTANCE;
}
+//-------------------------------------------------------------------------------------------------
+/** The players a recent hit was between, when one dealt it to another he is at war with; none for a
+ * tree a dozer cleared, or a building's own wear, which is no fight. */
+//-------------------------------------------------------------------------------------------------
+static PlayerMaskType fightSides( const Object *obj, const BodyModuleInterface *body )
+{
+ const PlayerMaskType sourceMask = body->getLastDamageInfo()->in.m_sourcePlayerMask;
+ const Player *victim = obj->getControllingPlayer();
+ if( sourceMask == 0 || victim == NULL || ( sourceMask & victim->getPlayerMask() ) != 0 )
+ return 0;
+ const Player *source = ThePlayerList->getPlayerFromMask( sourceMask );
+ if( source == NULL || victim->getRelationship( source->getDefaultTeam() ) != ENEMIES )
+ return 0;
+ return sourceMask | victim->getPlayerMask();
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The scouting pass counts the hits the way the director does on the same scan frames, so a fight
+ * starts on the scan the filming pass would first have seen it. */
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::scout( void )
+{
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ if( frame == m_scoutScanned )
+ return;
+ m_scoutScanned = frame;
+ if( frame % SCOUT_CRC_FRAMES == 0 )
+ {
+ const CrcCheckpoint checkpoint = { frame, TheGameLogic->getCRC( CRC_RECALC ) };
+ m_scoutCrcs.push_back( checkpoint );
+ }
+ if( frame % DIRECTOR_SCAN_FRAMES != 0 )
+ return;
+
+ std::vector< DirectorFightHit > hits;
+ for( Object *obj = TheGameLogic->getFirstObject(); obj != NULL; obj = obj->getNextObject() )
+ {
+ // a thing with no body module takes no damage, so it has no hits to count
+ const BodyModuleInterface *body = obj->getBodyModule();
+ if( body == NULL )
+ continue;
+ const UnsignedInt hitAt = body->getLastDamageTimestamp();
+ if( hitAt == 0 || frame >= hitAt + DIRECTOR_HEAT_FRAMES )
+ continue;
+ DirectorFightHit hit;
+ hit.sides = fightSides( obj, body );
+ if( hit.sides == 0 )
+ continue;
+ hit.position.x = obj->getPosition()->x;
+ hit.position.y = obj->getPosition()->y;
+ hit.weight = ObserverCamera_hitWeight( obj->getTemplate()->friend_getBuildCost(), obj->isEffectivelyDead(),
+ obj->isKindOf( KINDOF_FS_SUPERWEAPON ) );
+ hits.push_back( hit );
+ }
+ ObserverCamera_trackFights( m_scouted, hits, frame );
+}
+
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::finishScout( void )
+{
+ const char *path = TheGlobalData->m_directorScoutFile.str();
+ FILE *file = fopen( path, "w" );
+ if( file == NULL )
+ {
+ DEBUG_LOG(( "-directorscout: cannot write '%s', the filming pass films live\n", path ));
+ return;
+ }
+ Int worth = 0;
+ for( size_t index = 0; index < m_scouted.size(); index++ )
+ {
+ const AsciiString line = ObserverCamera_formatMoment( m_scouted[ index ] );
+ fprintf( file, "%s\n", line.str() );
+ if( !ObserverCamera_worthFilming( m_scouted[ index ] ) )
+ continue;
+ worth++;
+ DEBUG_LOG(( "OBSCAM scouted %s\n", line.str() ));
+ }
+ for( size_t index = 0; index < m_scoutCrcs.size(); index++ )
+ fprintf( file, "crc %u %u\n", m_scoutCrcs[ index ].frame, m_scoutCrcs[ index ].crc );
+ fclose( file );
+ DEBUG_LOG(( "-directorscout: %d moments, %d worth filming, %d CRC checkpoints, to frame %u, written to '%s'\n",
+ (Int)m_scouted.size(), worth, (Int)m_scoutCrcs.size(), TheGameLogic->getFrame(), path ));
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The file is the scouting pass's, made for this run alone, and gone once it is read. */
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::loadTimeline( void )
+{
+ m_timelineLoaded = TRUE;
+ const char *path = TheGlobalData->m_directorTimelineFile.str();
+ if( TheGlobalData->m_directorTimelineFile.isEmpty() )
+ return;
+ FILE *file = fopen( path, "r" );
+ if( file == NULL )
+ {
+ DEBUG_LOG(( "-directortimeline: no '%s', the director films live\n", path ));
+ return;
+ }
+ char line[ 256 ];
+ Int worth = 0;
+ while( fgets( line, sizeof( line ), file ) != NULL )
+ {
+ CrcCheckpoint checkpoint;
+ DirectorMoment moment;
+ if( sscanf( line, "crc %u %u", &checkpoint.frame, &checkpoint.crc ) == 2 )
+ m_timelineCrcs.push_back( checkpoint );
+ else if( ObserverCamera_parseMoment( line, &moment ) )
+ {
+ m_timeline.push_back( moment );
+ if( ObserverCamera_worthFilming( moment ) )
+ worth++;
+ }
+ }
+ fclose( file );
+ remove( path );
+ DEBUG_LOG(( "-directortimeline: %d moments, %d worth filming, %d CRC checkpoints\n", (Int)m_timeline.size(), worth,
+ (Int)m_timelineCrcs.size() ));
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Same seed and same switches play the same match, and the checkpoints are how that is known rather
+ * than hoped: the first that differs throws the timeline away and the rest is filmed live. */
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera::checkTimeline( UnsignedInt frame )
+{
+ while( !m_timelineCrcs.empty() && m_timelineCrcs.front().frame <= frame )
+ {
+ const CrcCheckpoint checkpoint = m_timelineCrcs.front();
+ m_timelineCrcs.erase( m_timelineCrcs.begin() );
+ if( checkpoint.frame < frame )
+ continue;
+ const UnsignedInt crc = TheGameLogic->getCRC( CRC_RECALC );
+ DEBUG_LOG(( "OBSCAM frame %u timeline CRC: scouted 0x%08X filmed 0x%08X\n", frame, checkpoint.crc, crc ));
+ if( crc == checkpoint.crc )
+ continue;
+ DEBUG_LOG(( "OBSCAM frame %u the match went another way than the scouting pass's, the director films live\n", frame ));
+ m_timeline.clear();
+ m_timelineCrcs.clear();
+ m_placeMoment = -1;
+ if( m_placeKind == PLACE_UPCOMING )
+ m_placeValid = FALSE;
+ }
+}
+
//-------------------------------------------------------------------------------------------------
/** Where the director looks: the fight with the most at stake, held for a while, followed as it
* moves, and left for a clearly bigger one. With no fight anywhere it goes round what is worth
@@ -1591,14 +1956,8 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
heat.weight = ObserverCamera_hitWeight( cost, obj->isEffectivelyDead(), superweapon );
hits.push_back( heat );
- // -directorrecord's split counts a hit only when one player dealt it to another he is at war
- // with: a tree a dozer cleared, or a building's own wear, is no fight
- const PlayerMaskType sourceMask = body->getLastDamageInfo()->in.m_sourcePlayerMask;
- const Player *victim = obj->getControllingPlayer();
- if( sourceMask == 0 || victim == NULL || ( sourceMask & victim->getPlayerMask() ) != 0 )
- continue;
- const Player *source = ThePlayerList->getPlayerFromMask( sourceMask );
- if( source != NULL && victim->getRelationship( source->getDefaultTeam() ) == ENEMIES )
+ // -directorrecord's split counts only fights
+ if( fightSides( obj, body ) != 0 )
fights.push_back( heat );
}
m_fights = fights;
@@ -1606,6 +1965,15 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
Coord2D hottest;
Real hottestHeat = 0.0f;
ObserverCamera_hottestPlace( hits, &hottest, &hottestHeat );
+ // a fight the scouting pass saw come to nothing is not worth the trip
+ const Bool timeline = narrowTo == NULL && !m_timeline.empty();
+ if( timeline && hottestHeat > 0.0f && ObserverCamera_fizzles( m_timeline, hottest, frame ) )
+ {
+ if( !sameFight( hottest, m_skippedFight ) )
+ DEBUG_LOG(( "OBSCAM frame %u skips a fight at (%.0f,%.0f) heat %.1f the scout saw fizzle\n", frame, hottest.x, hottest.y, hottestHeat ));
+ m_skippedFight = hottest;
+ hottestHeat = 0.0f;
+ }
const UnsignedInt held = frame >= m_placeSince ? frame - m_placeSince : 0;
Coord2D followed = m_place;
@@ -1649,6 +2017,40 @@ Bool ObserverCamera::directorPlace( const Player *narrowTo, Coord2D *place )
return TRUE;
}
+ // a fight the scouting pass saw begin is waited for where it begins, so the picture has it from
+ // the first shot; it becomes an ordinary fight when it starts. It is gone to from nothing, from a
+ // fight that has settled when it is clearly bigger, and from anything for a superweapon's silo
+ if( m_placeValid && m_placeKind == PLACE_UPCOMING )
+ {
+ if( frame < m_timeline[ m_placeMoment ].start )
+ {
+ *place = m_place;
+ return TRUE;
+ }
+ m_placeKind = PLACE_FIGHT;
+ m_placeSince = frame;
+ }
+ const Int upcoming = timeline ? ObserverCamera_prerollMoment( m_timeline, frame ) : -1;
+ if( upcoming >= 0 && upcoming != m_placeMoment )
+ {
+ const DirectorMoment &moment = m_timeline[ upcoming ];
+ Coord2D middle;
+ const Real heatHere = m_placeValid && m_placeKind == PLACE_FIGHT ? ObserverCamera_heatAround( hits, m_place, &middle ) : 0.0f;
+ if( moment.superweapon || heatHere <= 0.0f || ( held >= DIRECTOR_SETTLE_FRAMES && moment.peak > heatHere * DIRECTOR_SWITCH_MARGIN ) )
+ {
+ DEBUG_LOG(( "OBSCAM frame %u pre-roll to %s at frame %u (%.0f,%.0f) peak %.1f\n", frame,
+ moment.superweapon ? "superweapon" : "fight", moment.start, moment.place.x, moment.place.y, moment.peak ));
+ m_place = moment.place;
+ m_placeKind = PLACE_UPCOMING;
+ m_placeHeight = 0.0f;
+ m_placeMoment = upcoming;
+ m_placeSince = frame;
+ m_placeValid = TRUE;
+ *place = m_place;
+ return TRUE;
+ }
+ }
+
if( m_placeValid && m_placeKind == PLACE_FIGHT )
{
const Real heatHere = ObserverCamera_heatAround( hits, m_place, &followed );
@@ -1787,6 +2189,9 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )
if( TheGlobalData->m_directorRecord )
{
const UnsignedInt frame = TheGameLogic->getFrame();
+ if( !m_timelineLoaded )
+ loadTimeline();
+ checkTimeline( frame );
const Bool introStarting = !m_introDone;
advancePanes( frame );
if( m_intro && introStarting )
diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp
index 17ba6d08d..6be292052 100644
--- a/GeneralsMD/Code/Main/WinMain.cpp
+++ b/GeneralsMD/Code/Main/WinMain.cpp
@@ -1067,6 +1067,118 @@ static LONG WINAPI dumpUnhandledException( EXCEPTION_POINTERS *e_info )
return EXCEPTION_EXECUTE_HANDLER;
}
+/** One argument on the end of a command line, in quotes when it holds a space. */
+static void appendArgument( char *line, size_t size, const char *argument )
+{
+ const Bool spaced = strchr( argument, ' ' ) != NULL;
+ strlcat( line, spaced ? " \"" : " ", size );
+ strlcat( line, argument, size );
+ if (spaced)
+ strlcat( line, "\"", size );
+}
+
+/** -directorrecord films a match the director has already seen. Before this process makes its
+ window it plays the same match in a copy of itself, -headless and as fast as the machine goes,
+ with -directorscout naming a file for what the copy saw: where each fight begins, when each
+ superweapon fires, and the logic's CRC every 30 seconds. Then this process plays the match for the
+ camera with -directortimeline naming that file. The same switches and the same seed play the same
+ match, so a skirmish with no -seed is given one here, the same to both. The copy is in a job that
+ dies with this process, so a script that stops this one by its id stops both. */
+static void runDirectorScout( int &argc, char **argv, int capacity )
+{
+ Bool recording = FALSE;
+ Bool seeded = FALSE;
+ for (int index = 1; index < argc; ++index)
+ {
+ if (strcasecmp( argv[index], "-directorrecord" ) == 0)
+ recording = TRUE;
+ if (strcasecmp( argv[index], "-seed" ) == 0 || strcasecmp( argv[index], "-replay" ) == 0)
+ seeded = TRUE;
+ if (strcasecmp( argv[index], "-headless" ) == 0 || strcasecmp( argv[index], "-directortimeline" ) == 0)
+ return;
+ }
+ if (!recording)
+ return;
+ const int addedArguments = 4;
+ if (argc + addedArguments > capacity)
+ {
+ DEBUG_LOG(("-directorrecord: no room on the command line for the scouting pass, the director films live\n"));
+ return;
+ }
+
+ static char seedSwitch[] = "-seed";
+ static char seedText[ 16 ];
+ if (!seeded)
+ {
+ const DWORD seedRange = 1000000; // well inside the Int -seed is read into
+ snprintf( seedText, sizeof( seedText ), "%lu", GetTickCount() % seedRange );
+ argv[argc++] = seedSwitch;
+ argv[argc++] = seedText;
+ }
+
+ char exePath[ _MAX_PATH ];
+ GetModuleFileNameA( NULL, exePath, sizeof( exePath ) );
+ char logPrefix[ 32 ] = "";
+ findEarlyCommandLineValue( L"-logPrefix", logPrefix, sizeof( logPrefix ) );
+ char scoutPrefix[ 32 ];
+ snprintf( scoutPrefix, sizeof( scoutPrefix ), "scout_%s", logPrefix );
+ char tempDirectory[ _MAX_PATH ];
+ GetTempPathA( sizeof( tempDirectory ), tempDirectory );
+ static char timelinePath[ _MAX_PATH ];
+ snprintf( timelinePath, sizeof( timelinePath ), "%szhr_directorscout_%lu.txt", tempDirectory, GetCurrentProcessId() );
+
+ static char commandLine[ 32768 ];
+ snprintf( commandLine, sizeof( commandLine ), "\"%s\"", exePath );
+ for (int index = 1; index < argc; ++index)
+ {
+ // the copy films nothing, and its log is its own
+ if (strcasecmp( argv[index], "-directorrecord" ) == 0 || strcasecmp( argv[index], "-logPrefix" ) == 0)
+ {
+ if (index + 1 < argc && argv[index + 1][0] != '-')
+ ++index;
+ continue;
+ }
+ appendArgument( commandLine, sizeof( commandLine ), argv[index] );
+ }
+ // -headless, -multiInstance and -logPrefix are read word by word off the raw line, so never quoted
+ strlcat( commandLine, " -observer -headless -multiInstance -logPrefix ", sizeof( commandLine ) );
+ strlcat( commandLine, scoutPrefix, sizeof( commandLine ) );
+ strlcat( commandLine, " -directorscout", sizeof( commandLine ) );
+ appendArgument( commandLine, sizeof( commandLine ), timelinePath );
+
+ STARTUPINFOA startup;
+ memset( &startup, 0, sizeof( startup ) );
+ startup.cb = sizeof( startup );
+ PROCESS_INFORMATION process;
+ const DWORD started = GetTickCount();
+ if (!CreateProcessA( exePath, commandLine, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &process ))
+ {
+ DEBUG_LOG(("-directorrecord: the scouting pass did not start, error %lu, the director films live\n", GetLastError()));
+ return;
+ }
+ HANDLE job = CreateJobObjectA( NULL, NULL );
+ JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits;
+ memset( &limits, 0, sizeof( limits ) );
+ limits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+ SetInformationJobObject( job, JobObjectExtendedLimitInformation, &limits, sizeof( limits ) );
+ if (!AssignProcessToJobObject( job, process.hProcess ))
+ DEBUG_LOG(("-directorrecord: the scouting pass is not in a job, error %lu: it outlives this process if this one is stopped\n", GetLastError()));
+ ResumeThread( process.hThread );
+ DEBUG_LOG(("-directorrecord: scouting pass %lu started: %s\n", process.dwProcessId, commandLine));
+ WaitForSingleObject( process.hProcess, INFINITE );
+ DWORD exitCode = 0;
+ GetExitCodeProcess( process.hProcess, &exitCode );
+ CloseHandle( process.hThread );
+ CloseHandle( process.hProcess );
+ CloseHandle( job );
+ DEBUG_LOG(("-directorrecord: scouting pass took %lu ms, exit code %lu, its log is %sDebugLogFile.txt\n",
+ GetTickCount() - started, exitCode, scoutPrefix));
+
+ static char timelineSwitch[] = "-directortimeline";
+ argv[argc++] = timelineSwitch;
+ argv[argc++] = timelinePath;
+}
+
// WinMain ====================================================================
/** Application entry point */
//=============================================================================
@@ -1223,6 +1335,8 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
return 0;
}
+ runDirectorScout( argc, argv, MAXIMUM_ARGUMENTS );
+
#ifdef _DEBUG
// Turn on Memory heap tracking
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.inc
index 089962fee..cdfbc1362 100644
--- a/GeneralsMD/Code/Tests/test_observer_camera.inc
+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc
@@ -528,6 +528,162 @@ TEST(pane_lines_grow_with_the_picture_and_the_join_keeps_all_of_them)
CHECK( ObserverCamera_paneSeamBand( 720 ) >= 8 );
}
+static DirectorFightHit fightHit( Real x, Real y, UnsignedInt sides )
+{
+ DirectorFightHit hit;
+ hit.position.x = x;
+ hit.position.y = y;
+ hit.weight = 1.0f;
+ hit.sides = sides;
+ return hit;
+}
+
+static DirectorMoment scoutedFight( UnsignedInt start, UnsignedInt last, Real x, Real y, Real peak )
+{
+ DirectorMoment fight;
+ fight.start = start;
+ fight.last = last;
+ fight.place.x = fight.target.x = x;
+ fight.place.y = fight.target.y = y;
+ fight.peak = peak;
+ fight.sides = 3;
+ fight.power = FALSE;
+ fight.superweapon = FALSE;
+ return fight;
+}
+
+static DirectorMoment scoutedPower( UnsignedInt frame, Real x, Real y, Bool superweapon )
+{
+ DirectorMoment power = scoutedFight( frame, frame, x, y, superweapon ? 5.0f : 1.0f );
+ power.target.x = x + 1500.0f;
+ power.power = TRUE;
+ power.superweapon = superweapon;
+ return power;
+}
+
+TEST(the_scout_follows_a_fight_from_its_first_scan_to_its_last_and_keeps_two_apart)
+{
+ std::vector< DirectorMoment > fights;
+ std::vector< DirectorFightHit > hits;
+ for( Int each = 0; each < 3; each++ )
+ hits.push_back( fightHit( 1000.0f + each * 10.0f, 1000.0f, 1 | 2 ) );
+ hits.push_back( fightHit( 4000.0f, 4000.0f, 4 | 8 ) );
+ hits.push_back( fightHit( 4010.0f, 4000.0f, 4 | 8 ) );
+ ObserverCamera_trackFights( fights, hits, 15 );
+ CHECK_EQ( (Int)fights.size(), 2 );
+ CHECK_EQ( fights[ 0 ].start, 15u );
+ CHECK_NEAR( fights[ 0 ].peak, 3.0f, 0.001f );
+ CHECK_EQ( fights[ 0 ].sides, 3u );
+ CHECK_EQ( fights[ 1 ].sides, 12u );
+
+ // the first fight moves 200 on and a third player joins it: the same fight, seen later
+ hits.clear();
+ for( Int each = 0; each < 4; each++ )
+ hits.push_back( fightHit( 1200.0f + each * 10.0f, 1000.0f, 1 | 4 ) );
+ ObserverCamera_trackFights( fights, hits, 30 );
+ CHECK_EQ( (Int)fights.size(), 2 );
+ CHECK_EQ( fights[ 0 ].start, 15u );
+ CHECK_EQ( fights[ 0 ].last, 30u );
+ CHECK_NEAR( fights[ 0 ].place.x, 1010.0f, 0.001f );
+ CHECK_NEAR( fights[ 0 ].target.x, 1215.0f, 0.001f );
+ CHECK_NEAR( fights[ 0 ].peak, 4.0f, 0.001f );
+ CHECK_EQ( fights[ 0 ].sides, 7u );
+ CHECK_EQ( fights[ 1 ].last, 15u );
+
+ // quiet for longer than the gap, the place starts a new fight
+ ObserverCamera_trackFights( fights, hits, 30 + 4 * LOGICFRAMES_PER_SECOND );
+ CHECK_EQ( (Int)fights.size(), 3 );
+ CHECK_EQ( fights[ 2 ].start, 30u + 4 * LOGICFRAMES_PER_SECOND );
+}
+
+TEST(the_scout_counts_a_fight_worth_filming_only_when_it_got_hot_and_lasted)
+{
+ CHECK( ObserverCamera_worthFilming( scoutedFight( 100, 100 + 8 * LOGICFRAMES_PER_SECOND, 0.0f, 0.0f, 4.0f ) ) );
+ CHECK( !ObserverCamera_worthFilming( scoutedFight( 100, 100 + 8 * LOGICFRAMES_PER_SECOND, 0.0f, 0.0f, 3.9f ) ) );
+ CHECK( !ObserverCamera_worthFilming( scoutedFight( 100, 100 + 3 * LOGICFRAMES_PER_SECOND, 0.0f, 0.0f, 20.0f ) ) );
+ CHECK( ObserverCamera_worthFilming( scoutedPower( 100, 0.0f, 0.0f, FALSE ) ) );
+}
+
+TEST(the_director_goes_to_wait_for_a_fight_four_seconds_before_it_starts_superweapons_first)
+{
+ std::vector< DirectorMoment > timeline;
+ timeline.push_back( scoutedFight( 1000, 1600, 1000.0f, 1000.0f, 6.0f ) );
+ timeline.push_back( scoutedFight( 1050, 1600, 3000.0f, 3000.0f, 9.0f ) );
+ timeline.push_back( scoutedFight( 1010, 1030, 5000.0f, 5000.0f, 2.0f ) );
+ 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 ), -1 );
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1000 - preroll ), 0 );
+ // two coming up: the hotter
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1050 - preroll ), 1 );
+ // a superweapon over any fight
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1100 - preroll ), 4 );
+ // one that has started is no longer waited for
+ CHECK_EQ( ObserverCamera_prerollMoment( timeline, 1100 ), -1 );
+}
+
+TEST(the_director_skips_only_a_fight_the_scout_saw_fizzle)
+{
+ std::vector< DirectorMoment > timeline;
+ timeline.push_back( scoutedFight( 500, 560, 2000.0f, 2000.0f, 2.0f ) );
+ timeline.push_back( scoutedFight( 500, 900, 5000.0f, 5000.0f, 8.0f ) );
+ Coord2D place;
+ place.x = 2050.0f;
+ place.y = 2000.0f;
+ CHECK( ObserverCamera_fizzles( timeline, place, 520 ) );
+ // over and past its gap, whatever is there now the scout did not see
+ CHECK( !ObserverCamera_fizzles( timeline, place, 560 + 4 * LOGICFRAMES_PER_SECOND ) );
+ place.x = place.y = 5000.0f;
+ CHECK( !ObserverCamera_fizzles( timeline, place, 600 ) );
+ place.x = place.y = 8000.0f;
+ CHECK( !ObserverCamera_fizzles( timeline, place, 520 ) );
+ // a fight worth filming in the same place beats the fizzle beside it
+ timeline.push_back( scoutedFight( 500, 900, 2100.0f, 2000.0f, 8.0f ) );
+ place.x = 2050.0f;
+ place.y = 2000.0f;
+ CHECK( !ObserverCamera_fizzles( timeline, place, 520 ) );
+}
+
+TEST(the_recording_splits_before_a_known_second_fight_far_from_the_first)
+{
+ std::vector< DirectorMoment > timeline;
+ timeline.push_back( scoutedFight( 1000, 1500, 4000.0f, 4000.0f, 8.0f ) );
+ timeline.push_back( scoutedFight( 900, 1500, 1200.0f, 1000.0f, 20.0f ) );
+ timeline.push_back( scoutedFight( 900, 1500, 6000.0f, 6000.0f, 2.0f ) );
+ Coord2D first;
+ first.x = first.y = 1000.0f;
+ Coord2D second;
+ const UnsignedInt preroll = 4 * LOGICFRAMES_PER_SECOND;
+ CHECK( !ObserverCamera_plannedSecond( timeline, first, 1000 - preroll - 1, &second ) );
+ CHECK( ObserverCamera_plannedSecond( timeline, first, 1000 - preroll, &second ) );
+ CHECK_NEAR( second.x, 4000.0f, 0.001f );
+ CHECK( ObserverCamera_plannedSecond( timeline, first, 1500, &second ) );
+ CHECK( !ObserverCamera_plannedSecond( timeline, first, 1501, &second ) );
+}
+
+TEST(a_timeline_line_reads_back_as_the_moment_it_was_written_from)
+{
+ DirectorMoment fight = scoutedFight( 450, 1230, 1234.0f, 567.0f, 7.25f );
+ fight.target.x = 1400.0f;
+ fight.sides = 0x30;
+ DirectorMoment read;
+ CHECK( ObserverCamera_parseMoment( ObserverCamera_formatMoment( fight ).str(), &read ) );
+ CHECK_EQ( read.start, 450u );
+ CHECK_EQ( read.last, 1230u );
+ CHECK_NEAR( read.place.x, 1234.0f, 0.001f );
+ CHECK_NEAR( read.place.y, 567.0f, 0.001f );
+ CHECK_NEAR( read.target.x, 1400.0f, 0.001f );
+ CHECK_NEAR( read.peak, 7.25f, 0.001f );
+ CHECK_EQ( read.sides, 0x30u );
+ CHECK( !read.power );
+ CHECK( ObserverCamera_parseMoment( ObserverCamera_formatMoment( scoutedPower( 90, 10.0f, 20.0f, TRUE ) ).str(), &read ) );
+ CHECK( read.power );
+ CHECK( read.superweapon );
+ CHECK( !ObserverCamera_parseMoment( "crc 900 305419896", &read ) );
+ CHECK( !ObserverCamera_parseMoment( "", &read ) );
+}
+
TEST(pane_animations_ease_over_logic_frames)
{
CHECK_NEAR( ObserverCamera_easeFrames( 100, 100, 15 ), 0.0f, 0.0001f );