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): keep a fight the scout's last frame cut short worth filming

Olcay Seyganf7ee9a01bb3f
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
index f62c4a692..363909c40 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h
@@ -118,6 +118,10 @@ void ObserverCamera_trackFights( std::vector< DirectorMoment > &fights, const st
/// 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 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. -1 for none
Int ObserverCamera_prerollMoment( const std::vector< DirectorMoment > &timeline, UnsignedInt frame );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
index fbfe6394f..0f8ff56f1 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp
@@ -760,6 +760,18 @@ Bool ObserverCamera_worthFilming( const DirectorMoment &moment )
return moment.power || ( moment.peak >= FIGHT_WORTH_HEAT && moment.last - moment.start >= FIGHT_WORTH_FRAMES );
}
+//-------------------------------------------------------------------------------------------------
+void ObserverCamera_closeTimeline( std::vector< DirectorMoment > &moments, UnsignedInt end )
+{
+ for( size_t index = 0; index < moments.size(); index++ )
+ {
+ DirectorMoment &fight = moments[ index ];
+ if( fight.power || fight.last + SCOUT_FIGHT_GAP < end )
+ continue;
+ fight.last = max( fight.last, fight.start + FIGHT_WORTH_FRAMES );
+ }
+}
+
//-------------------------------------------------------------------------------------------------
Int ObserverCamera_prerollMoment( const std::vector< DirectorMoment > &timeline, UnsignedInt frame )
{
@@ -1872,6 +1884,8 @@ void ObserverCamera::finishScout( void )
DEBUG_LOG(( "-directorscout: cannot write '%s', the filming pass films live\n", path ));
return;
}
+ // the last frame the pass counted on: a replay that ran out has gone back to the shell by now
+ ObserverCamera_closeTimeline( m_scouted, m_scoutScanned );
Int worth = 0;
for( size_t index = 0; index < m_scouted.size(); index++ )
{
@@ -1886,7 +1900,7 @@ void ObserverCamera::finishScout( void )
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 ));
+ (Int)m_scouted.size(), worth, (Int)m_scoutCrcs.size(), m_scoutScanned, path ));
}
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.inc
index bf71b612c..5740c89db 100644
--- a/GeneralsMD/Code/Tests/test_observer_camera.inc
+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc
@@ -627,6 +627,24 @@ 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_hot_fight_the_end_of_the_scouting_run_cut_short_is_still_worth_filming)
+{
+ std::vector< DirectorMoment > timeline;
+ timeline.push_back( scoutedFight( 5865, 6000, 1218.0f, 1689.0f, 15.2f ) );
+ timeline.push_back( scoutedFight( 5000, 5100, 3000.0f, 3000.0f, 9.0f ) );
+ timeline.push_back( scoutedFight( 5950, 5940 + 2 * LOGICFRAMES_PER_SECOND, 4000.0f, 4000.0f, 2.0f ) );
+ timeline.push_back( scoutedPower( 5990, 500.0f, 500.0f, FALSE ) );
+ CHECK( !ObserverCamera_worthFilming( timeline[ 0 ] ) );
+ ObserverCamera_closeTimeline( timeline, 6000 );
+ CHECK( ObserverCamera_worthFilming( timeline[ 0 ] ) );
+ // one that was over before the end keeps its own end
+ CHECK_EQ( timeline[ 1 ].last, 5100u );
+ CHECK( !ObserverCamera_worthFilming( timeline[ 1 ] ) );
+ // still small at the end is still a fizzle
+ CHECK( !ObserverCamera_worthFilming( timeline[ 2 ] ) );
+ CHECK_EQ( timeline[ 3 ].last, 5990u );
+}
+
TEST(the_director_goes_to_wait_for_a_fight_four_seconds_before_it_starts_superweapons_first)
{
std::vector< DirectorMoment > timeline;