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(gameengine): put a followed unit in the middle of the cinema frame

Olcay Seyganfb05b0821e8a
diff --git a/GeneralsMD/Code/Data/Cinema/tr_ai.txt b/GeneralsMD/Code/Data/Cinema/tr_ai.txt
deleted file mode 100644
index 635c360da..000000000
--- a/GeneralsMD/Code/Data/Cinema/tr_ai.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-# Trailer: four brutal computer players four minutes into a match, seen from the field.
-#
-# generals.exe -borderless -msaa 0 -quickstart -noshellmap -observer -multiInstance
-# -particlecap 2500 -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 4 -teams 2
-# -aidiff brutal -seed 7 -side 0 FactionChina -side 1 FactionAmerica -side 2 FactionGLA
-# -side 3 FactionChina -cinema tr_ai -video 16200 16740 tr_ai -maxframes 16760
-#
-# Nothing here is staged: the camera rides whatever the computer players have put on the map.
-
-0 letterbox on
-539 pitch -24 2
-540 follow ChinaTankBattleMaster 12
-540 zoom 0.55 6
-548 orbit 50 10
-554 unfollow
-554 zoom 1.4 4
-558 end
diff --git a/GeneralsMD/Code/Data/Cinema/tr_arrival.txt b/GeneralsMD/Code/Data/Cinema/tr_arrival.txt
new file mode 100644
index 000000000..27714338c
--- /dev/null
+++ b/GeneralsMD/Code/Data/Cinema/tr_arrival.txt
@@ -0,0 +1,13 @@
+# Trailer: two hundred mixed units filling the point they were sent to, seen from above the point.
+# They cross the whole of Twilight Flame to get there, so the filming starts at 45 seconds.
+#
+# generals.exe -borderless -msaa 0 -quickstart -noshellmap -multiInstance
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover -seed 7 -peacetime 20
+# -scenario trailer_arrival -cinema tr_arrival -video 810 1350 tr_arrival -maxframes 1370
+#
+# 1733,4405 is slot 1's start on that map, which is where the crowd is sent.
+
+27 cut 1135 3900 0.6 0 -30
+28 zoom 0.42 16
+28 orbit 25 16
+45 end
diff --git a/GeneralsMD/Code/Data/Cinema/tr_battle.txt b/GeneralsMD/Code/Data/Cinema/tr_battle.txt
deleted file mode 100644
index ec913cb33..000000000
--- a/GeneralsMD/Code/Data/Cinema/tr_battle.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-# Trailer: two mixed armies walking into each other, ridden from inside the column.
-#
-# generals.exe -borderless -msaa 0 -quickstart -noshellmap -observer -multiInstance
-# -particlecap 2500 -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
-# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -scenario crowdbattle
-# -cinema tr_battle -video 300 780 tr_battle -maxframes 800
-#
-# No coordinates: the camera takes whichever Battlemaster is nearest what it is already looking at.
-
-0 letterbox on
-9 pitch -22 3
-10 follow ChinaTankBattleMaster 12
-10 zoom 0.5 6
-16 orbit 45 9
-22 unfollow
-22 zoom 1.3 4
-22 pitch -8 4
-26 end
diff --git a/GeneralsMD/Code/Data/Cinema/tr_clash.txt b/GeneralsMD/Code/Data/Cinema/tr_clash.txt
new file mode 100644
index 000000000..600adc661
--- /dev/null
+++ b/GeneralsMD/Code/Data/Cinema/tr_clash.txt
@@ -0,0 +1,17 @@
+# Trailer: the middle of a combined-arms fight, ridden from beside a tank and then pulled up over it.
+# No letterbox: the interface goes, the picture stays the full frame.
+#
+# generals.exe -borderless -msaa 0 -quickstart -noshellmap -observer -multiInstance
+# -particlecap 2500 -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -scenario trailer_clash
+# -cinema tr_clash -video 780 1320 tr_clash -maxframes 1340
+
+25 pitch -6 2
+26 follow ChinaTankBattleMaster 10
+26 zoom 0.45 5
+31 orbit 40 10
+36 unfollow
+36 zoom 0.9 5
+36 pitch -18 5
+41 follow AmericaTankCrusader 6
+44 end
diff --git a/GeneralsMD/Code/Data/Cinema/tr_corridor.txt b/GeneralsMD/Code/Data/Cinema/tr_corridor.txt
new file mode 100644
index 000000000..f963fae4f
--- /dev/null
+++ b/GeneralsMD/Code/Data/Cinema/tr_corridor.txt
@@ -0,0 +1,15 @@
+# Trailer: the column narrowing where the map narrows and opening out again on the other side. The
+# camera rides one tank through it, so the lanes go past the frame rather than the frame past them.
+#
+# generals.exe -borderless -msaa 0 -quickstart -noshellmap -multiInstance
+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover -seed 3 -peacetime 20
+# -scenario trailer_corridor -cinema tr_corridor -video 900 1440 tr_corridor -maxframes 1460
+
+29 pitch -10 2
+29 zoom 0.3 3
+30 follow AmericaTankCrusader 18
+38 orbit 35 10
+48 unfollow
+48 zoom 0.75 4
+48 pitch -24 4
+52 end
diff --git a/GeneralsMD/Code/Data/Cinema/tr_crowd.txt b/GeneralsMD/Code/Data/Cinema/tr_crowd.txt
deleted file mode 100644
index 838ed3e91..000000000
--- a/GeneralsMD/Code/Data/Cinema/tr_crowd.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-# Trailer: two hundred units sent to one point, arriving as a crowd instead of a queue.
-#
-# generals.exe -borderless -msaa 0 -quickstart -noshellmap -multiInstance -randommap 1 2 small
-# -autoskirmish 2 -takeover -seed 1 -peacetime 20 -scenario massmove
-# -cinema tr_crowd -video 400 900 tr_crowd -maxframes 920
-#
-# massmove spawns at start0 and sends everything to 700,600 on frame 90.
-
-0 letterbox on
-13 cut 700 600 1.5 0 -30
-14 zoom 1.0 14
-14 orbit 20 16
-30 end
diff --git a/GeneralsMD/Code/Data/Cinema/tr_map.txt b/GeneralsMD/Code/Data/Cinema/tr_map.txt
deleted file mode 100644
index 4bb5dd2dd..000000000
--- a/GeneralsMD/Code/Data/Cinema/tr_map.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-# Trailer: a pass across a map the game generated from a seed, with a column crossing it.
-#
-# generals.exe -borderless -msaa 0 -quickstart -noshellmap -observer -multiInstance
-# -randommap 1 2 small -autoskirmish 2 -takeover -seed 1 -peacetime 20 -scenario parade
-# -cinema tr_map -video 200 620 tr_map -maxframes 640
-#
-# Same map as Cinema\demo.txt: the column forms up round 700,550 and is sent to 1000,1150.
-
-0 letterbox on
-7 cut 700 550 1.6 0 -8
-8 route 13 850 750 1000 1150
-8 pitch -26 13
-8 zoom 1.1 13
-21 end
diff --git a/GeneralsMD/Code/Data/Cinema/tr_oasis.txt b/GeneralsMD/Code/Data/Cinema/tr_oasis.txt
index 324d3000f..de74ab1fd 100644
--- a/GeneralsMD/Code/Data/Cinema/tr_oasis.txt
+++ b/GeneralsMD/Code/Data/Cinema/tr_oasis.txt
@@ -4,7 +4,6 @@
# -autoskirmish 2 -aidiff easy -seed 5 -map "Maps\Golden Oasis\Golden Oasis.map"
# -cinema tr_oasis -video 300 690 tr_oasis -maxframes 710
-0 letterbox on
10 cut 3040 1450 0.75 0 -14
11 route 12 3040 1330 3040 1210 2980 1130
11 zoom 0.5 12
diff --git a/GeneralsMD/Code/Data/Cinema/tr_open.txt b/GeneralsMD/Code/Data/Cinema/tr_open.txt
index d47f81139..734a5db5e 100644
--- a/GeneralsMD/Code/Data/Cinema/tr_open.txt
+++ b/GeneralsMD/Code/Data/Cinema/tr_open.txt
@@ -1,15 +1,13 @@
-# Trailer, cold open: thirty inferno cannons shelling a parked column.
+# Trailer, cold open: the guns firing at the moment the two armies meet, from among them.
#
-# generals.exe -borderless -msaa 0 -quickstart -noshellmap -multiInstance -particlecap 2500
-# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover
-# -side 0 FactionChina -side 1 FactionAmerica -seed 1 -scenario fireball
-# -cinema tr_open -video 60 450 tr_open -maxframes 470
-#
-# The scenario puts the guns at 760,700 and the targets at 760,1000, and opens fire at 2 seconds.
+# generals.exe -borderless -msaa 0 -quickstart -noshellmap -observer -multiInstance
+# -particlecap 2500 -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -scenario trailer_clash
+# -cinema tr_open -video 690 1050 tr_open -maxframes 1070
-0 letterbox on
-2 cut 760 1000 0.45 0 -22
-2 orbit 30 12
-2 zoom 0.7 12
-9 move 760 940 5
-14 end
+22 pitch -8 2
+22 zoom 0.32 3
+23 follow ChinaVehicleInfernoCannon 7
+30 follow AmericaTankCrusader 5
+30 orbit 25 5
+35 end
diff --git a/GeneralsMD/Code/Data/Cinema/tr_palms.txt b/GeneralsMD/Code/Data/Cinema/tr_palms.txt
index ef6c0543d..c596e14b3 100644
--- a/GeneralsMD/Code/Data/Cinema/tr_palms.txt
+++ b/GeneralsMD/Code/Data/Cinema/tr_palms.txt
@@ -6,7 +6,6 @@
#
# 2643,3580 is the palm stand; 3040,900 is the oasis water and its stone bridge.
-0 letterbox on
10 cut 2643 3580 0.9 0 -18
11 zoom 0.55 12
11 orbit 35 12
diff --git a/GeneralsMD/Code/Data/Cinema/tr_watch.txt b/GeneralsMD/Code/Data/Cinema/tr_watch.txt
index b547ded42..779289697 100644
--- a/GeneralsMD/Code/Data/Cinema/tr_watch.txt
+++ b/GeneralsMD/Code/Data/Cinema/tr_watch.txt
@@ -9,5 +9,4 @@
# No camera verb runs, so the camera stays the one -autocamera moves: every six seconds it jumps to
# wherever the fighting is. The jumps are the cuts.
-0 letterbox on
558 end
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp
index dff44c40e..b514a1c20 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp
@@ -63,6 +63,8 @@ static const char CINEMA_COMMENT_CHAR = '#';
enum { CINEMA_MAX_TOKENS = 3 + 2 * CINEMA_MAX_ROUTE_POINTS };
static const Real CINEMA_PITCH_LIMIT_DEGREES = 36.0f; ///< View::setPitch clamps to PI/5 either way
static const Real CINEMA_FOLLOW_RATE = 4.0f; ///< how fast a follow catches up, per second
+static const Real CINEMA_CENTRE_GAIN = 0.5f; ///< share of the framing error taken out each frame
+static const Real CINEMA_CENTRE_LIMIT = 900.0f; ///< a correction larger than this is a bad projection
static const Real CINEMA_FRAME_MS = 1000.0f / (Real)LOGICFRAMES_PER_SECOND;
static const Real CINEMA_LETTERBOX_ASPECT = 2.39f; ///< the game's own bars crop to 16:9, which on a 16:9 screen is no bars at all
@@ -369,6 +371,8 @@ static Real theCinemaRouteY[ CINEMA_MAX_ROUTE_POINTS ];
static Int theCinemaRoutePoints = 0;
static Real theCinemaRouteStart = 0.0f;
static Real theCinemaRouteLength = 0.0f;
+static Real theCinemaCentreX = 0.0f; ///< what the framing loop is adding to the look point
+static Real theCinemaCentreY = 0.0f;
static ObjectID theCinemaFollowID = INVALID_ID;
static Real theCinemaFollowUntil = 0.0f; ///< 0 is for as long as the next shot allows
static Real theCinemaLastNow = 0.0f;
@@ -654,6 +658,8 @@ static void runShot( const CinemaShot &shot )
theCinemaFollowID = obj->getID();
theCinemaFollowUntil = (shot.seconds > 0.0f) ? now + shot.seconds : 0.0f;
theCinemaPlaceMode = CINEMA_PLACE_FOLLOW;
+ theCinemaCentreX = 0.0f;
+ theCinemaCentreY = 0.0f;
break;
}
@@ -691,6 +697,30 @@ static void runShot( const CinemaShot &shot )
}
}
+/** The camera looks at a point on the ground and the tilt swings the picture around it, so a unit
+ standing on that point rides above the middle of the frame, further the steeper the tilt. Rather
+ than work the offset out from the projection, the loop measures it: where the frame's middle
+ lands in the world at the unit's own height is the point the camera should be looking at, and
+ the difference between that and the unit is taken out of the look point a little at a time.
+ It settles in a few frames and stays settled while the tilt or the zoom is still moving. */
+static void cinemaCentreOn( const Coord3D *subject )
+{
+ ICoord2D middle;
+ middle.x = TheTacticalView->getWidth() / 2;
+ middle.y = TheTacticalView->getHeight() / 2;
+
+ Coord3D atMiddle;
+ TheTacticalView->screenToWorldAtZ( &middle, &atMiddle, subject->z );
+
+ const Real missX = subject->x - atMiddle.x;
+ const Real missY = subject->y - atMiddle.y;
+ if (fabs( missX ) > CINEMA_CENTRE_LIMIT || fabs( missY ) > CINEMA_CENTRE_LIMIT)
+ return;
+
+ theCinemaCentreX += missX * CINEMA_CENTRE_GAIN;
+ theCinemaCentreY += missY * CINEMA_CENTRE_GAIN;
+}
+
/** A followed unit is chased, not pinned: the camera closes a fixed share of the gap every second,
so a unit that jinks does not shake the picture and one that dies leaves the camera where it was. */
static void cinemaChase( Real now )
@@ -712,6 +742,7 @@ static void cinemaChase( Real now )
const Real share = (elapsed > 0.0f) ? 1.0f - (Real)exp( -CINEMA_FOLLOW_RATE * elapsed ) : 0.0f;
theCinemaStillX += (obj->getPosition()->x - theCinemaStillX) * share;
theCinemaStillY += (obj->getPosition()->y - theCinemaStillY) * share;
+ cinemaCentreOn( obj->getPosition() );
}
void CinemaDirector_update( void )
@@ -744,6 +775,11 @@ void CinemaDirector_update( void )
cinemaChase( now );
Coord3D look;
cinemaPlace( now, &look.x, &look.y );
+ if (theCinemaPlaceMode == CINEMA_PLACE_FOLLOW)
+ {
+ look.x += theCinemaCentreX;
+ look.y += theCinemaCentreY;
+ }
look.z = TheTerrainLogic->getGroundHeight( look.x, look.y );
TheTacticalView->lookAt( &look );
TheTacticalView->setZoom( theCinemaBaseZoom * theCinemaZoom.at( now ) );