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(gameengine): -camera <x> <y> to aim an unattended run's camera

Olcay Seyganf9ce84bac9b7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b12f835da..54f095168 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -824,6 +824,7 @@ found and fixed — EA's own, not port damage.**
- That found every multiplayer replay falsely accusing itself of desync since 2003.
- Every fix was proved by putting the bug back and watching the test fail.
- No debugger here: a crash symboliser, a sampling profiler, probes in live matches.
+- A graphics fix is argued with pixels: an unattended match can now be told where to point the camera and which frame to photograph, so the two builds are compared by counting the pixels between them. The river above changed 126,535 of them and the eye had been calling it "about the same".
- Reverted and recorded: wide FOV, the whole group movement rework, tree shadows.
- The six-rung difficulty ladder is back down to three. The three extra rungs were built, played and taken out again: a player picks a level once and wants to know what it means, and six names that each moved one switch was a worse answer to that than three that each describe an opponent. The machinery underneath is the same, so the levels are still tunable in the data files, and Brutal kept the top rung's numbers rather than the old Brutal ones.
- The three-piece command bar was reverted once, for having nowhere to put the painting of the bar, and is back now that the painting has been cut into three to match. Each piece is fitted by matching it against the artwork it was cut from rather than by eye: the eyeballed fit was four percent out, which nobody sees on the metal and everybody sees on the money readout.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 52c8f41e7..2b28bfe7d 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -384,6 +384,8 @@ public:
Int m_maxGameFrames; ///< -maxframes <n>: quit after n logic frames however the match is going (0 = no limit)
Int m_screenShotFrame; ///< -screenshot <n>: save one picture when the run reaches logic frame n (0 = never)
Int m_autoCameraSeconds; ///< -autocamera <n>: every n seconds, move the camera to wherever the fighting is (0 = off)
+ Bool m_cameraLookSet; ///< -camera <x> <y>: point the camera at one map position once the match starts
+ Coord2D m_cameraLook; ///< where -camera pointed it
Int m_traceMoveID; ///< -tracemove [id]: log one movement line a frame for this object (0 = off, -1 = the first unit that gets blocked)
Real m_slowFrameMS; ///< -slowframe <ms>: a logic frame over this long logs its own breakdown (default 20)
Int m_aiSliceFrames; ///< -aislice <n>: a unit's AI decides once every n logic frames, staggered by id (1 = every frame, the default)
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index 4f156a4b2..51bb60e22 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -1330,6 +1330,25 @@ Int parseMSAA(char *args[], int num)
return 1;
}
+/* -camera <x> <y>: point the camera at one map position and leave it there.
+ *
+ * -screenshot only made a picture; it could not say of what. The camera starts at the local
+ * player's own base, so anything the player does not own - a river, a bridge, a piece of terrain
+ * a shader change is about - cannot be got into the frame from a script at all, and -autocamera
+ * follows the fighting, which is somewhere else again. Map coordinates, the same ones the log
+ * prints; the ground height is looked up. */
+Int parseCameraLook(char *args[], int num)
+{
+ if (TheWritableGlobalData && num > 2 && args[1] && args[2])
+ {
+ TheWritableGlobalData->m_cameraLook.x = (Real)atof(args[1]);
+ TheWritableGlobalData->m_cameraLook.y = (Real)atof(args[2]);
+ TheWritableGlobalData->m_cameraLookSet = TRUE;
+ return 3;
+ }
+ return 1;
+}
+
Int parseAutoCamera(char *args[], int num)
{
if (TheWritableGlobalData)
@@ -1824,6 +1843,7 @@ static CommandLineParam params[] =
{ "-screenshot", parseScreenShot },
{ "-msaa", parseMSAA },
{ "-autocamera", parseAutoCamera },
+ { "-camera", parseCameraLook },
{ "-tracemove", parseTraceMove },
{ "-slowframe", parseSlowFrame },
{ "-teams", parseTeams },
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index cb08241c7..122071c56 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -1379,6 +1379,35 @@ static Int autoCameraCountBits( UnsignedInt v )
return n;
}
+/** -----------------------------------------------------------------------------------------------
+ * -camera <x> <y>: point the camera at one map position, once, when the match starts.
+ *
+ * Applied on the first in-game frame rather than at parse time: TheTacticalView does not exist yet
+ * while the command line is read, and the map's own starting view is set during load and would win.
+ */
+static void updateFixedCamera( void )
+{
+ if( !TheGlobalData->m_cameraLookSet || TheTacticalView == NULL || TheTerrainLogic == NULL )
+ return;
+ if( !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )
+ return;
+
+ Coord3D look;
+ look.x = TheGlobalData->m_cameraLook.x;
+ look.y = TheGlobalData->m_cameraLook.y;
+ look.z = TheTerrainLogic->getGroundHeight( look.x, look.y );
+ TheTacticalView->lookAt( &look );
+
+ // held every frame, not set once: the map's own starting view and the shell's reset both land
+ // after the first in-game frame and put the camera back on the player's base.
+ static Bool logged = FALSE;
+ if( !logged )
+ {
+ logged = TRUE;
+ DEBUG_LOG(("CAMERA: holding (%.0f,%.0f)\n", look.x, look.y));
+ }
+}
+
static void updateAutoCamera( void )
{
if( TheGlobalData->m_autoCameraSeconds <= 0 || TheTacticalView == NULL || TheTerrainLogic == NULL )
@@ -1801,6 +1830,7 @@ void GameEngine::update( void )
}
updateHeadlessRun();
+ updateFixedCamera();
updateAutoCamera();
#ifdef DEBUG_LOGGING
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 72aa8dfb6..f61c6e4b1 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -690,6 +690,8 @@ GlobalData::GlobalData()
m_maxGameFrames = 0; // run until the match ends
m_screenShotFrame = 0; // take no picture unless -screenshot asks for one
m_autoCameraSeconds = 0; // the camera stays where it was put
+ m_cameraLookSet = FALSE; // -camera not given: the map decides where the view starts
+ m_cameraLook.x = m_cameraLook.y = 0.0f;
m_traceMoveID = 0; // no movement trace
m_slowFrameMS = 20.0f; // a frame worth a line in the log; -slowframe lowers it for a hunt
m_aiSliceFrames = 1; // every unit thinks every frame, which is what the game has always done