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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameclient): put a director split's second pane on the other side
Olcay Seygan54badcdb1472
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.hindex f95ef0aab..073156f58 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h@@ -185,9 +185,12 @@ Bool ObserverCamera_fizzles( const std::vector< DirectorMoment > &timeline, cons/// 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+/// a fight that had wandered off left pane 1 on empty ground. With homes, on another player's ground+/// than first, as ObserverCamera_secondPlaceInt ObserverCamera_plannedSecond( const std::vector< DirectorMoment > &timeline, const Coord2D &first, UnsignedInt frame, Real apart,- Bool keeping );+ Bool keeping, const Coord2D *homes, Int homeCount );+/// whose ground place is on: the index of the nearest of count homes, each player's base at the start+Int ObserverCamera_groundOf( const Coord2D &place, const Coord2D *homes, Int count );/// a moment as one line of the timeline file, and back; FALSE for a line that is not oneAsciiString ObserverCamera_formatMoment( const DirectorMoment &moment );Bool ObserverCamera_parseMoment( const char *line, DirectorMoment *moment );@@ -245,8 +248,11 @@ ViewLocation ObserverCamera_approach( const ViewLocation &from, const ViewLocati/// gathers and slows over about 1.6 s; a cut takes it there at onceReal ObserverCamera_easeHeight( Real from, Real to, Real *velocity, Real elapsedSeconds, Bool cut );/// -directorrecord's second fight: the hottest place among the hits more than needed from first, so-/// the two halves of a split screen never show the same ground. FALSE when nothing that far was hit-Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const Coord2D &first, Real needed, Coord2D *place, Real *heat );+/// the two halves of a split screen never show the same ground. With two homes or more it is also on+/// another player's ground than first, so a split shows the other side: in a 1v1 the two fights had+/// both been in one player's half, his base beside his own army. FALSE when nothing such was hit+Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const Coord2D &first, Real needed, const Coord2D *homes,+ Int homeCount, Coord2D *place, Real *heat );/// whether the recording's picture is split, given whether it is now, how far apart the two places/// 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@@ -610,6 +616,8 @@ private:Real m_cornerRadarSlide;IRegion2D m_radarFrame;const Player *m_panePlayers[ OBSERVER_MOST_PANES ]; ///< the intro's player for each pane+ Coord2D m_homes[ OBSERVER_MOST_PANES ]; ///< each opening player's base, whose ground a split's second fight must not share with the first+ Int m_homeCount;Coord2D m_paneSubject[ OBSERVER_MOST_PANES ]; ///< what each pane past the first looks atCoord3D m_paneMark[ OBSERVER_MOST_PANES ]; ///< the top of each opening player's command centreViewLocation m_paneGlide[ OBSERVER_MOST_PANES ]; ///< where each pane's subject glide has got todiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cppindex c29be2b51..1eaa6dc1e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp@@ -516,13 +516,36 @@ Real ObserverCamera_easeHeight( Real from, Real to, Real *velocity, Real elapsed}//--------------------------------------------------------------------------------------------------Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const Coord2D &first, Real needed, Coord2D *place, Real *heat )+Int ObserverCamera_groundOf( const Coord2D &place, const Coord2D *homes, Int count ){+ Int nearest = 0;+ Real nearestSquared = 0.0f;+ for( Int home = 0; home < count; home++ )+ {+ const Real dx = homes[ home ].x - place.x;+ const Real dy = homes[ home ].y - place.y;+ const Real squared = dx * dx + dy * dy;+ if( home == 0 || squared < nearestSquared )+ {+ nearest = home;+ nearestSquared = squared;+ }+ }+ return nearest;+}++//-------------------------------------------------------------------------------------------------+Bool ObserverCamera_secondPlace( const std::vector< DirectorHeat > &hits, const Coord2D &first, Real needed, const Coord2D *homes,+ Int homeCount, Coord2D *place, Real *heat )+{+ const Int firstGround = ObserverCamera_groundOf( first, homes, homeCount );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( homeCount >= 2 && ObserverCamera_groundOf( hits[ index ].position, homes, homeCount ) == firstGround )+ continue;if( dx * dx + dy * dy > needed * needed )apart.push_back( hits[ index ] );}@@ -1281,8 +1304,9 @@ Bool ObserverCamera_fightLasts( const std::vector< DirectorMoment > &timeline, c//-------------------------------------------------------------------------------------------------Int ObserverCamera_plannedSecond( const std::vector< DirectorMoment > &timeline, const Coord2D &first, UnsignedInt frame, Real apart,- Bool keeping )+ Bool keeping, const Coord2D *homes, Int homeCount ){+ const Int firstGround = ObserverCamera_groundOf( first, homes, homeCount );Int best = -1;for( size_t index = 0; index < timeline.size(); index++ ){@@ -1293,6 +1317,8 @@ Int ObserverCamera_plannedSecond( const std::vector< DirectorMoment > &timeline,continue;if( within( fight.place, first, apart ) )continue;+ if( homeCount >= 2 && ObserverCamera_groundOf( fight.place, homes, homeCount ) == firstGround )+ continue;if( best < 0 || fight.peak > timeline[ best ].peak )best = (Int)index;}@@ -1505,6 +1531,7 @@ void ObserverCamera::reset( void )m_introDone = FALSE;m_introGlide = FALSE;m_panesLeftPlace.x = m_panesLeftPlace.y = 0.0f;+ m_homeCount = 0;m_paneCount = 0;m_paneProgress = 0.0f;m_lineProgress = 0.0f;@@ -1521,6 +1548,7 @@ void ObserverCamera::reset( void ){m_paneRays[ pane ] = 0.0f;m_panePlayers[ pane ] = NULL;+ m_homes[ pane ].x = m_homes[ pane ].y = 0.0f;m_paneSubject[ pane ].x = m_paneSubject[ pane ].y = 0.0f;m_paneMark[ pane ].x = m_paneMark[ pane ].y = m_paneMark[ pane ].z = 0.0f;m_paneCentres[ pane ].x = m_paneCentres[ pane ].y = 0.0f;@@ -2146,7 +2174,7 @@ void ObserverCamera::updateSplit( void )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, searched, &second, &secondHeat );+ ObserverCamera_secondPlace( m_fights, m_place, searched, m_homes, m_homeCount, &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@@ -2164,7 +2192,7 @@ void ObserverCamera::updateSplit( void )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 Int planned = mayPlan ? ObserverCamera_plannedSecond( m_timeline, m_place, frame, searched, m_split, m_homes, m_homeCount ) : -1;// a planned moment whose split was ended early does not open anotherconst Bool plannedSplit = planned >= 0 && planned != m_spentMoment;if( plannedSplit && frame < m_timeline[ planned ].start && ( secondHeat <= 0.0f || !within( second, m_timeline[ planned ].place, sameGround ) ) )@@ -2212,8 +2240,9 @@ void ObserverCamera::updateSplit( void )}if( split != m_split ){- 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" : "" ));+ DEBUG_LOG(( "OBSCAM frame %u split %s, first (%.0f,%.0f) heat %.1f on home %d's ground, second (%.0f,%.0f) heat %.1f on home %d's, %.0f apart of %.0f needed, screen %.0f%s\n",+ frame, split ? "on" : "off", m_place.x, m_place.y, firstHeat, ObserverCamera_groundOf( m_place, m_homes, m_homeCount ), shown.x, shown.y,+ secondHeat, ObserverCamera_groundOf( shown, m_homes, m_homeCount ), apart, needed, m_screenGround, plannedSplit ? ", planned" : "" ));m_split = split;m_splitChanged = frame;m_splitApart = needed;@@ -2485,6 +2514,10 @@ void ObserverCamera::pickIntroBases( void )m_paneMark[ pane ].y = m_paneSubject[ pane ].y;m_paneMark[ pane ].z = TheTerrainLogic->getGroundHeight( m_paneSubject[ pane ].x, m_paneSubject[ pane ].y );}+ for( Int pane = 0; pane < m_paneCount; pane++ )+ m_homes[ pane ] = m_paneSubject[ pane ];+ m_homeCount = m_paneCount;+ DEBUG_LOG(( "OBSCAM frame %u %d homes, a split's second fight on another's ground\n", TheGameLogic->getFrame(), m_homeCount ));}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.incindex 4fc47be5e..d3f45007c 100644--- a/GeneralsMD/Code/Tests/test_observer_camera.inc+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc@@ -340,16 +340,49 @@ TEST(the_recording_splits_for_a_second_fight_far_from_the_first_and_never_for_thCoord2D second;Real heat = 0.0f;const Real needed = 660.0f;- CHECK( !ObserverCamera_secondPlace( hits, first, needed, &second, &heat ) );+ CHECK( !ObserverCamera_secondPlace( hits, first, needed, NULL, 0, &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, needed, &second, &heat ) );+ CHECK( ObserverCamera_secondPlace( hits, first, needed, NULL, 0, &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 ) );+ CHECK( !ObserverCamera_secondPlace( hits, first, 3000.0f, NULL, 0, &second, &heat ) );+}++TEST(the_recording_splits_onto_the_other_players_ground)+{+ // S1-A1 on Tournament Desert: USA's base in the south, China's in the north+ Coord2D homes[ 2 ];+ homes[ 0 ].x = 1011.0f;+ homes[ 0 ].y = 2103.0f;+ homes[ 1 ].x = 1005.0f;+ homes[ 1 ].y = 584.0f;+ CHECK_EQ( ObserverCamera_groundOf( homes[ 0 ], homes, 2 ), 0 );+ CHECK_EQ( ObserverCamera_groundOf( homes[ 1 ], homes, 2 ), 1 );++ // frame 25816: the director at USA's west edge, a hotter fight further up in USA's half and a+ // smaller one in China's. Pane 1 had taken the hotter one, two USA fights side by side+ Coord2D first;+ first.x = 421.0f;+ first.y = 2225.0f;+ std::vector< DirectorHeat > hits;+ for( Int each = 0; each < 4; each++ )+ hits.push_back( directorHit( 1074.0f + each * 20.0f, 1632.0f ) );+ for( Int each = 0; each < 2; each++ )+ hits.push_back( directorHit( 1284.0f + each * 20.0f, 564.0f ) );+ Coord2D second;+ Real heat = 0.0f;+ CHECK( ObserverCamera_secondPlace( hits, first, 859.0f, NULL, 0, &second, &heat ) );+ CHECK_NEAR( second.y, 1632.0f, 0.001f );+ CHECK( ObserverCamera_secondPlace( hits, first, 859.0f, homes, 2, &second, &heat ) );+ CHECK_NEAR( second.y, 564.0f, 0.001f );+ CHECK_NEAR( heat, 2.0f, 0.001f );+ // nothing on China's ground: no split at all rather than a second USA fight+ hits.resize( 4 );+ CHECK( !ObserverCamera_secondPlace( hits, first, 859.0f, homes, 2, &second, &heat ) );}TEST(the_recording_splits_for_a_big_second_fight_holds_it_and_rests_after)@@ -419,7 +452,7 @@ TEST(the_recording_splits_only_beside_a_real_fight)first.x = first.y = 1000.0f;Coord2D second;Real heat = 0.0f;- CHECK( !ObserverCamera_secondPlace( none, first, 660.0f, &second, &heat ) );+ CHECK( !ObserverCamera_secondPlace( none, first, 660.0f, NULL, 0, &second, &heat ) );}static Real paneArea( const Real *rays, Int count, Int pane, Int width, Int height )@@ -906,12 +939,12 @@ TEST(the_recording_splits_before_a_known_second_fight_far_from_the_first)first.x = first.y = 1000.0f;// three seconds ahead: at four pane 1 sat on an empty bridgeconst 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 );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1000 - lead - 1, 660.0f, FALSE, NULL, 0 ), -1 );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1000 - lead, 660.0f, FALSE, NULL, 0 ), 0 );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1500, 660.0f, TRUE, NULL, 0 ), 0 );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1501, 660.0f, TRUE, NULL, 0 ), -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 );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 1000 - lead, 4300.0f, FALSE, NULL, 0 ), -1 );}TEST(a_split_is_planned_only_beside_a_fight_that_outlasts_its_least_hold)@@ -948,10 +981,31 @@ 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, 660.0f, TRUE ), 0 );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 6451, 660.0f, TRUE, NULL, 0 ), 0 );// none up: where it began twenty seconds ago is no place to send a pane- CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 6451, 660.0f, FALSE ), -1 );- CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 5864, 660.0f, FALSE ), 0 );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 6451, 660.0f, FALSE, NULL, 0 ), -1 );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 5864, 660.0f, FALSE, NULL, 0 ), 0 );+}++TEST(the_recording_plans_its_split_onto_the_other_players_ground)+{+ // the pair the scouting pass planned is held to the rule a live split keeps: the hotter fight in+ // the director's own player's half loses to the smaller one in the other's+ Coord2D homes[ 2 ];+ homes[ 0 ].x = 1011.0f;+ homes[ 0 ].y = 2103.0f;+ homes[ 1 ].x = 1005.0f;+ homes[ 1 ].y = 584.0f;+ Coord2D first;+ first.x = 421.0f;+ first.y = 2225.0f;+ std::vector< DirectorMoment > timeline;+ timeline.push_back( scoutedFight( 1000, 1500, 1074.0f, 1632.0f, 20.0f ) );+ timeline.push_back( scoutedFight( 1000, 1500, 1284.0f, 564.0f, 8.0f ) );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 950, 859.0f, FALSE, NULL, 0 ), 0 );+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 950, 859.0f, FALSE, homes, 2 ), 1 );+ timeline.pop_back();+ CHECK_EQ( ObserverCamera_plannedSecond( timeline, first, 950, 859.0f, FALSE, homes, 2 ), -1 );}TEST(a_timeline_line_reads_back_as_the_moment_it_was_written_from)