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
feat(gameengine): add -cinema, a shot list that flies the camera with the hud off
Olcay Seygan46eb93120cc4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9ab7deb6e..9473f55da 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1165,6 +1165,7 @@ found and fixed — EA's own, not port damage.**- 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".- A picture cannot show a unit turning the wrong way, so an unattended match can now film itself: name the first and the last game frame and every frame between them is drawn once and saved, then stitched into an mp4 at the game's own 30 frames a second. A replay films the same way, which puts any match ever recorded on video without anybody sitting through it.+- And a match can be shot like a film. Give it a shot list, a text file of lines like "at 16 seconds, fly through these three points over 8 seconds" or "at 4 seconds, ride with the nearest Crusader", and the interface, the cursor and the health bars leave the screen while the camera cuts, glides along a curve, orbits, tilts, closes in and chases a unit on its own, with widescreen bars if you ask for them. The camera keeps time by the game's own clock, so the same list over the same match frames the same picture on every run, and with filming switched on the footage comes out at the speed it was written for, however slowly the disk took each frame.- A unit's cost is argued with the same army twice. An unattended match can now take its army from a text file - spawn eight of that unit there on frame thirty, send them across the map on frame six hundred, stop them on frame nine hundred - and be told which faction each seat plays and to leave every seat without a computer player behind it. Before that, whatever was on the field came out of the seed: measuring what angry mobs cost meant waiting for a match that happened to build some, and two runs that drew different sides were never comparable in the first place.- And the other half of that: a running game will now take orders down a socket. Started with the switch for it, the game listens on this machine only and answers anything that can speak to a web page - start a match on this map with these players, put five of that unit there, send them across the map, take a picture, tell me the frame number and what everybody owns. The commands are the same lines the text file above takes. A twenty-line Python script can now set up a match, produce an army and read the result back, which is how the mob numbers in this list were produced.- Reverted and recorded: wide FOV, the whole group movement rework, tree shadows out of a stencildiff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex 7a0ca7161..36ccc49e5 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -668,7 +668,12 @@ add_custom_command(TARGET generals POST_BUILD# for one, and a scenario run cannot be replayed anyway.COMMAND ${CMAKE_COMMAND} -E copy_directory${CMAKE_CURRENT_SOURCE_DIR}/Data/Scenarios- ${CMAKE_CURRENT_SOURCE_DIR}/../Run/Scenarios)+ ${CMAKE_CURRENT_SOURCE_DIR}/../Run/Scenarios+ # -cinema reads these shot lists. Client-side only, never checksummed, and a tool for making+ # footage rather than anything a player needs, so they stay out of package.bat too.+ COMMAND ${CMAKE_COMMAND} -E copy_directory+ ${CMAKE_CURRENT_SOURCE_DIR}/Data/Cinema+ ${CMAKE_CURRENT_SOURCE_DIR}/../Run/Cinema)# ===========================================================================# Tests. Run with: ctest --test-dir build -C Release --output-on-failurediff --git a/GeneralsMD/Code/Data/Cinema/demo.txt b/GeneralsMD/Code/Data/Cinema/demo.txtnew file mode 100644index 000000000..1fa387dcb--- /dev/null+++ b/GeneralsMD/Code/Data/Cinema/demo.txt@@ -0,0 +1,38 @@+# A tour of the verbs, written for the parade scenario:+#+# generals.exe -win -xres 1280 -yres 720 -quickstart -noshellmap -observer -multiInstance+# -randommap 1 2 small -autoskirmish 2 -takeover -seed 1 -peacetime 10+# -scenario parade -cinema demo+#+# Add -video 0 1200 demo to get Videos\demo.mp4 instead of watching it (ffmpeg on the PATH).+# Coordinates are for that map: the column forms up round (700,550) and (1000,250), the order goes+# out at 3 seconds and sends it to (1000,1150).+#+# <seconds> <verb> ...+# cut <x> <y> [zoom] [angle] [pitch] be there now+# move <x> <y> <s> slide to a point+# route <s> <x> <y> <x> <y> ... slide through points on a curve+# zoom <factor> <s> 1 is the distance the list started at, below 1 is closer+# angle <deg> <s> / orbit <deg> <s> turn to a heading / turn by this much+# pitch <deg> <s> tilt, -36 to 36; 0 is the game's own+# follow <template> [s] chase the nearest one of those+# unfollow | hud on|off | letterbox on|off | shot | end++0 cut 850 420 1.1 0 0+0 letterbox on+# come down over the column and swing round it while it sets off+1 zoom 0.6 5+1 pitch -20 5+1 orbit 60 8+# ride with one tank+4 follow AmericaTankCrusader 12+5 zoom 0.4 4+# pull back and fly ahead of them to where they are going, then circle it as they arrive+16 route 8 900 950 1000 1150+16 zoom 1.0 6+16 pitch 0 6+22 orbit -150 12+28 shot+30 zoom 0.55 6+37 shot+38 enddiff --git a/GeneralsMD/Code/Data/Cinema/nohud.txt b/GeneralsMD/Code/Data/Cinema/nohud.txtnew file mode 100644index 000000000..cedd184fe--- /dev/null+++ b/GeneralsMD/Code/Data/Cinema/nohud.txt@@ -0,0 +1,5 @@+# The interface off and nothing else: no shots, so the camera stays the player's.+#+# generals.exe -cinema nohud ...+#+# Scroll, zoom and turn the camera by hand for a clean picture; F12 still takes a screenshot.diff --git a/GeneralsMD/Code/Data/Scenarios/parade.txt b/GeneralsMD/Code/Data/Scenarios/parade.txtnew file mode 100644index 000000000..e9a99cb70--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/parade.txt@@ -0,0 +1,13 @@+# Something to film: a column that marches most of the way across a small generated map, for+# Cinema\demo.txt. Not a measurement; massmove is the one that counts arrivals.+#+# generals.exe -win -xres 1280 -yres 720 -quickstart -noshellmap -observer -multiInstance+# -randommap 1 2 small -autoskirmish 2 -takeover -seed 1 -peacetime 10+# -scenario parade -cinema demo+#+# On that map the tanks form up round (700,550), the infantry round (1000,250), and the order sends+# them all to (1000,1150).++30 spawn 0 AmericaTankCrusader 40 start0:0:300 40+30 spawn 0 AmericaInfantryRanger 40 start0:300:0 20+90 playermove 0 * 1000 1150diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex ba63f2b8e..db4a9baf5 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -438,6 +438,7 @@ public:Bool m_noRenderDevice; ///< -nodevice: run without a Direct3D device at all, for a machine whose session is lockedInt m_controlPort; ///< -control [port]: listen for WebSocket commands on 127.0.0.1 (0 = off)AsciiString m_scenarioFile; ///< -scenario <name>: play Run/Scenarios/<name>.txt instead of leaving the match to a person or an AI (empty = off)+ AsciiString m_cinemaScript; ///< -cinema <name>: interface off, camera flown by Run/Cinema/<name>.txt (empty = off)Bool m_autoSkirmishTakeover; ///< -takeover: give every -autoskirmish slot a driverless human seat, so nothing thinks unless a scenario says soAsciiString m_autoSkirmishSide[ MAX_PLAYER_COUNT ]; ///< -side <slot> <faction>: name that slot's faction instead of drawing it from the seedAsciiString m_netGameHosts; ///< -netgame <ip>[,<ip>...]: the slot list of a LAN game started from the command line (empty = off)diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.h b/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.hnew file mode 100644index 000000000..e0d2ca252--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.h@@ -0,0 +1,81 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++// FILE: CinemaDirector.h /////////////////////////////////////////////////////////////////////////+// -cinema <name>: the interface off and the camera flown from a shot list in Run/Cinema/<name>.txt.+///////////////////////////////////////////////////////////////////////////////////////////////////++#pragma once++#ifndef __CINEMADIRECTOR_H_+#define __CINEMADIRECTOR_H_++#include "Lib/BaseType.h"+#include "Common/AsciiString.h"++enum CinemaVerb+{+ CINEMA_VERB_CUT, ///< cut <x> <y> [zoom] [angle] [pitch]: be there now+ CINEMA_VERB_MOVE, ///< move <x> <y> <seconds>: slide the point looked at+ CINEMA_VERB_ROUTE, ///< route <seconds> <x> <y> <x> <y> ...: slide through every point, curving+ CINEMA_VERB_ZOOM, ///< zoom <factor> <seconds>: distance from the ground, 1 is where the shot list began+ CINEMA_VERB_ANGLE, ///< angle <degrees> <seconds>: turn to a heading+ CINEMA_VERB_ORBIT, ///< orbit <degrees> <seconds>: turn by this much+ CINEMA_VERB_PITCH, ///< pitch <degrees> <seconds>: tilt, -36 to 36, 0 is the game's own+ CINEMA_VERB_FOLLOW, ///< follow <template> [seconds]: keep the nearest one in the middle of the frame+ CINEMA_VERB_UNFOLLOW, ///< unfollow: stop following, stay where the camera is+ CINEMA_VERB_HUD, ///< hud on|off+ CINEMA_VERB_LETTERBOX, ///< letterbox on|off+ CINEMA_VERB_SHOT, ///< shot: one screenshot+ CINEMA_VERB_END, ///< end: quit the game++ CINEMA_VERB_COUNT+};++enum { CINEMA_MAX_ROUTE_POINTS = 16 };++struct CinemaShot+{+ Real at; ///< seconds into the match+ CinemaVerb verb;+ Real seconds; ///< how long the move takes; 0 is a cut+ Real value[ 3 ]; ///< x y, or the one number the verb takes, or zoom angle pitch after cut's x y+ Int values; ///< how many of value[] the line gave+ Real routeX[ CINEMA_MAX_ROUTE_POINTS ];+ Real routeY[ CINEMA_MAX_ROUTE_POINTS ];+ Int routePoints;+ AsciiString name; ///< follow's template+ Bool on; ///< hud and letterbox+};++/// parse one line of a shot list; FALSE with a reason for a line that is neither a shot nor blank+Bool CinemaDirector_parseLine( const char *line, CinemaShot *shot, Bool *isShot, AsciiString *reason );++/// smoothstep: 0 at 0, 1 at 1, level at both ends, which is what makes a move ease in and out+Real CinemaDirector_ease( Real t );++/// a point on a Catmull-Rom curve through points[], t from 0 at the first point to 1 at the last+void CinemaDirector_routePoint( const Real *xs, const Real *ys, Int count, Real t, Real *x, Real *y );++/// once a render pass, after the logic tick+void CinemaDirector_update( void );++/// the interface is off: nothing but the world is drawn+Bool CinemaDirector_hidesHud( void );++#endif // __CINEMADIRECTOR_H_diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.hindex 547a6fb8a..502acf8f4 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h@@ -192,6 +192,7 @@ public:virtual void enableLetterBox(Bool enable) = 0; ///< forces letter-boxed display on/offvirtual Bool isLetterBoxFading( void ) { return FALSE; } ///< returns true while letterbox fades in/outvirtual Bool isLetterBoxed( void ) { return FALSE; } //WST 10/2/2002. Added query interface+ void setLetterBoxAspect( Real widthOverHeight ) { m_letterBoxAspect = widthOverHeight; } ///< the picture the bars leave; 16:9 is the game's, and draws nothing on a 16:9 screenvirtual const wchar_t *getRendererName( void ) const = 0; ///< the graphics API the picture is presented through, for the HUD cornervirtual void setCinematicText( AsciiString string ) { m_cinematicText = string; }@@ -225,6 +226,7 @@ protected:void *m_debugDisplayUserData; ///< Data for debug display update handlerReal m_letterBoxFadeLevel; ///<tracks the current alpha level for fading letter-boxed mode in/out.Bool m_letterBoxEnabled; ///<current state of letterbox+ Real m_letterBoxAspect; ///< width over height of the picture between the barsUnsignedInt m_letterBoxFadeStartTime; ///< time of letterbox fade startInt m_movieHoldTime; ///< time that we hold on the last frame of the movieInt m_copyrightHoldTime; ///< time that the copyright must be on the screendiff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex d4c94fbd6..66efe5960 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -1771,6 +1771,19 @@ Int parseScenario(char *args[], int num)return 1;}+/* -cinema <name>: take the interface off and fly the camera from Run/Cinema/<name>.txt, for+ footage. A name with no such file still takes the interface off and leaves the camera to the+ player. CinemaDirector.cpp has the shot list's grammar. */+Int parseCinema(char *args[], int num)+{+ if (TheWritableGlobalData && num > 1 && args[1])+ {+ TheWritableGlobalData->m_cinemaScript = args[1];+ return 2;+ }+ return 1;+}+/* -side <slot> <faction> nails one -autoskirmish slot to a faction instead of letting the seedpick it.@@ -2252,6 +2265,7 @@ static CommandLineParam params[] ={ "-control", parseControlPort },{ "-nodevice", parseNoDevice },{ "-scenario", parseScenario },+ { "-cinema", parseCinema },{ "-side", parseSide },{ "-takeover", parseTakeover },{ "-replay", parseReplay },diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex 63a78a1d3..6c1922f80 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -91,6 +91,7 @@#include "GameLogic/ScriptEngine.h"#include "GameLogic/SidesList.h"+#include "GameClient/CinemaDirector.h"#include "GameClient/Display.h"#include "GameClient/FXList.h"#include "GameClient/GameClient.h"@@ -2256,6 +2257,7 @@ void GameEngine::update( void )updateShellScreenShot();updateFixedCamera();updateAutoCamera();+ CinemaDirector_update();updateUIDrill();updateResDrill();updateInputWatch();diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 4efb2241d..366c120a6 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -715,6 +715,7 @@ GlobalData::GlobalData()m_noRenderDevice = FALSE; // -headless still takes a 100x100 device unless -nodevice says not tom_controlPort = 0; // nothing listens; -control opens the socketm_scenarioFile.clear(); // nothing is scripted; -scenario is a measuring tool and ruins the match it runs in+ m_cinemaScript.clear(); // the interface is on and the camera belongs to the playerm_autoSkirmishTakeover = FALSE; // the AI plays the opponents unless -takeover empties their seatsfor( Int slot = 0; slot < MAX_PLAYER_COUNT; slot++ )m_autoSkirmishSide[ slot ].clear(); // every faction still comes out of the seed unless -side names onediff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cppnew file mode 100644index 000000000..dff44c40e--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp@@ -0,0 +1,759 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++// FILE: CinemaDirector.cpp ///////////////////////////////////////////////////////////////////////+//+// -cinema <name>: take the interface off the screen and fly the camera from a shot list.+//+// The script engine can already move a camera, but only from inside a map, and every one of its+// moves runs on the wall clock: under -video the passes are paced by the capture, not by 33ms, and+// a pan timed in milliseconds comes out at whatever speed the disk allowed. Here the clock is the+// logic frame (plus how far the render pass is between two of them, when nothing is recording), so+// the same shot list over the same -seed frames the same picture on every run and every machine.+//+// A shot list is Run/Cinema/<name>.txt, one line a shot: <seconds> <verb> <arguments>.+// Every shot starts at its own time and runs for its own length; shots on different channels+// (where the camera looks, how far away it is, which way it faces, how far it tilts) overlap freely,+// which is how a pan that climbs and turns at once is written: three lines with one time.+//+///////////////////////////////////////////////////////////////////////////////////////////////////++#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine++#include "Common/file.h"+#include "Common/FileSystem.h"+#include "Common/GameEngine.h"+#include "Common/GlobalData.h"+#include "Common/Recorder.h"+#include "Common/ThingTemplate.h"+#include "GameClient/CinemaDirector.h"+#include "Common/NameKeyGenerator.h"+#include "GameClient/Display.h"+#include "GameClient/GameWindow.h"+#include "GameClient/GameWindowManager.h"+#include "GameClient/GUICallbacks.h"+#include "GameClient/InGameUI.h"+#include "GameClient/Mouse.h"+#include "GameClient/View.h"+#include "GameLogic/GameLogic.h"+#include "GameLogic/Object.h"+#include "GameLogic/TerrainLogic.h"++#include <algorithm>+#include <vector>++static const char *CINEMA_DIRECTORY = "Cinema\\";+static const char *CINEMA_EXTENSION = ".txt";+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_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++// ------------------------------------------------------------------------------------------------+// the shot list+// ------------------------------------------------------------------------------------------------++static Bool isCinemaSpace( char c )+{+ return c == ' ' || c == '\t' || c == '\r' || c == '\n';+}++static Int tokenizeCinemaLine( const char *line, AsciiString *tokens, Int maxTokens )+{+ Int found = 0;+ const char *at = line;+ while (*at != 0)+ {+ while (*at != 0 && isCinemaSpace( *at ))+ ++at;+ if (*at == 0 || *at == CINEMA_COMMENT_CHAR)+ break;+ const char *start = at;+ while (*at != 0 && !isCinemaSpace( *at ) && *at != CINEMA_COMMENT_CHAR)+ ++at;+ if (found < maxTokens)+ {+ char word[ 128 ];+ const Int length = (Int)(at - start);+ const Int copied = (length < (Int)sizeof( word ) - 1) ? length : (Int)sizeof( word ) - 1;+ memcpy( word, start, copied );+ word[ copied ] = 0;+ tokens[ found ].set( word );+ }+ ++found;+ }+ return found;+}++/** strtod takes "12abc" as 12; a typo in a shot list should say so rather than fire at the wrong time. */+static Bool parseCinemaNumber( const AsciiString &token, Real *value )+{+ const char *text = token.str();+ char *end = NULL;+ const double parsed = strtod( text, &end );+ if (end == text || *end != 0)+ return FALSE;+ *value = (Real)parsed;+ return TRUE;+}++static Bool parseCinemaSwitch( const AsciiString &token, Bool *on )+{+ if (token == "on")+ {+ *on = TRUE;+ return TRUE;+ }+ if (token == "off")+ {+ *on = FALSE;+ return TRUE;+ }+ return FALSE;+}++static Bool refuseCinemaLine( AsciiString *reason, const char *why )+{+ reason->set( why );+ return FALSE;+}++/** Read `count` numbers from tokens[first...] into out[]. */+static Bool parseCinemaNumbers( const AsciiString *tokens, Int first, Int count, Real *out )+{+ for (Int i = 0; i < count; ++i)+ {+ if (!parseCinemaNumber( tokens[ first + i ], &out[ i ] ))+ return FALSE;+ }+ return TRUE;+}++Bool CinemaDirector_parseLine( const char *line, CinemaShot *shot, Bool *isShot, AsciiString *reason )+{+ AsciiString tokens[ CINEMA_MAX_TOKENS ];+ const Int count = tokenizeCinemaLine( line, tokens, CINEMA_MAX_TOKENS );+ *isShot = FALSE;+ if (count == 0)+ return TRUE;+ if (count > CINEMA_MAX_TOKENS)+ return refuseCinemaLine( reason, "too many words on the line" );+ if (count < 2)+ return refuseCinemaLine( reason, "a shot is <seconds> <verb> ..." );+ if (!parseCinemaNumber( tokens[ 0 ], &shot->at ) || shot->at < 0.0f)+ return refuseCinemaLine( reason, "the first word is not a time in seconds" );++ shot->seconds = 0.0f;+ shot->values = 0;+ shot->routePoints = 0;+ shot->name.clear();+ shot->on = FALSE;++ const AsciiString &verb = tokens[ 1 ];+ const Int args = count - 2;+ if (verb == "cut")+ {+ shot->verb = CINEMA_VERB_CUT;+ // x y, then as many of zoom, angle, pitch as the line cares to give+ if (args < 2 || args > 5)+ return refuseCinemaLine( reason, "cut <x> <y> [zoom] [angle] [pitch]" );+ Real numbers[ 5 ];+ if (!parseCinemaNumbers( tokens, 2, args, numbers ))+ return refuseCinemaLine( reason, "cut takes numbers" );+ shot->routeX[ 0 ] = numbers[ 0 ];+ shot->routeY[ 0 ] = numbers[ 1 ];+ shot->values = args - 2;+ for (Int i = 0; i < shot->values; ++i)+ shot->value[ i ] = numbers[ 2 + i ];+ }+ else if (verb == "move")+ {+ shot->verb = CINEMA_VERB_MOVE;+ Real numbers[ 3 ];+ if (args != 3 || !parseCinemaNumbers( tokens, 2, 3, numbers ))+ return refuseCinemaLine( reason, "move <x> <y> <seconds>" );+ shot->routeX[ 0 ] = numbers[ 0 ];+ shot->routeY[ 0 ] = numbers[ 1 ];+ shot->routePoints = 1;+ shot->seconds = numbers[ 2 ];+ }+ else if (verb == "route")+ {+ shot->verb = CINEMA_VERB_ROUTE;+ if (args < 3 || (args - 1) % 2 != 0 || (args - 1) / 2 > CINEMA_MAX_ROUTE_POINTS - 1)+ return refuseCinemaLine( reason, "route <seconds> <x> <y> [<x> <y> ...], at most 15 points" );+ if (!parseCinemaNumber( tokens[ 2 ], &shot->seconds ))+ return refuseCinemaLine( reason, "route takes numbers" );+ shot->routePoints = (args - 1) / 2;+ for (Int i = 0; i < shot->routePoints; ++i)+ {+ if (!parseCinemaNumber( tokens[ 3 + 2 * i ], &shot->routeX[ i ] )+ || !parseCinemaNumber( tokens[ 4 + 2 * i ], &shot->routeY[ i ] ))+ return refuseCinemaLine( reason, "route takes numbers" );+ }+ }+ else if (verb == "zoom" || verb == "angle" || verb == "orbit" || verb == "pitch")+ {+ if (verb == "zoom")+ shot->verb = CINEMA_VERB_ZOOM;+ else if (verb == "angle")+ shot->verb = CINEMA_VERB_ANGLE;+ else if (verb == "orbit")+ shot->verb = CINEMA_VERB_ORBIT;+ else+ shot->verb = CINEMA_VERB_PITCH;+ Real numbers[ 2 ];+ if (args != 2 || !parseCinemaNumbers( tokens, 2, 2, numbers ))+ return refuseCinemaLine( reason, "zoom, angle, orbit and pitch take <amount> <seconds>" );+ shot->value[ 0 ] = numbers[ 0 ];+ shot->values = 1;+ shot->seconds = numbers[ 1 ];+ if (shot->verb == CINEMA_VERB_ZOOM && shot->value[ 0 ] <= 0.0f)+ return refuseCinemaLine( reason, "zoom is a factor above 0" );+ if (shot->verb == CINEMA_VERB_PITCH && fabs( shot->value[ 0 ] ) > CINEMA_PITCH_LIMIT_DEGREES)+ return refuseCinemaLine( reason, "pitch is -36 to 36 degrees" );+ }+ else if (verb == "follow")+ {+ shot->verb = CINEMA_VERB_FOLLOW;+ if (args < 1 || args > 2)+ return refuseCinemaLine( reason, "follow <template> [seconds]" );+ shot->name = tokens[ 2 ];+ if (args == 2 && !parseCinemaNumber( tokens[ 3 ], &shot->seconds ))+ return refuseCinemaLine( reason, "follow's length is a number of seconds" );+ }+ else if (verb == "unfollow" || verb == "shot" || verb == "end")+ {+ if (args != 0)+ return refuseCinemaLine( reason, "unfollow, shot and end take nothing" );+ if (verb == "unfollow")+ shot->verb = CINEMA_VERB_UNFOLLOW;+ else if (verb == "shot")+ shot->verb = CINEMA_VERB_SHOT;+ else+ shot->verb = CINEMA_VERB_END;+ }+ else if (verb == "hud" || verb == "letterbox")+ {+ shot->verb = (verb == "hud") ? CINEMA_VERB_HUD : CINEMA_VERB_LETTERBOX;+ if (args != 1 || !parseCinemaSwitch( tokens[ 2 ], &shot->on ))+ return refuseCinemaLine( reason, "hud and letterbox take on or off" );+ }+ else+ {+ return refuseCinemaLine( reason, "unknown verb" );+ }++ if (shot->seconds < 0.0f)+ return refuseCinemaLine( reason, "a length cannot be negative" );+ *isShot = TRUE;+ return TRUE;+}++Real CinemaDirector_ease( Real t )+{+ if (t <= 0.0f)+ return 0.0f;+ if (t >= 1.0f)+ return 1.0f;+ return t * t * (3.0f - 2.0f * t);+}++/** Catmull-Rom through every point, with the ends doubled so the curve starts and stops on them. The+ parameter is split evenly between the spans rather than by their length, which is fine for a route+ of roughly even legs and is written down here so a lopsided one is not a surprise. */+void CinemaDirector_routePoint( const Real *xs, const Real *ys, Int count, Real t, Real *x, Real *y )+{+ if (count == 1 || t <= 0.0f)+ {+ *x = xs[ 0 ];+ *y = ys[ 0 ];+ return;+ }+ if (t >= 1.0f)+ {+ *x = xs[ count - 1 ];+ *y = ys[ count - 1 ];+ return;+ }+ const Real spans = (Real)(count - 1);+ Int span = (Int)(t * spans);+ if (span > count - 2)+ span = count - 2;+ const Real u = t * spans - (Real)span;+ const Int i0 = (span > 0) ? span - 1 : 0;+ const Int i1 = span;+ const Int i2 = span + 1;+ const Int i3 = (span + 2 < count) ? span + 2 : count - 1;+ const Real u2 = u * u;+ const Real u3 = u2 * u;+ *x = 0.5f * ((2.0f * xs[ i1 ]) + (-xs[ i0 ] + xs[ i2 ]) * u+ + (2.0f * xs[ i0 ] - 5.0f * xs[ i1 ] + 4.0f * xs[ i2 ] - xs[ i3 ]) * u2+ + (-xs[ i0 ] + 3.0f * xs[ i1 ] - 3.0f * xs[ i2 ] + xs[ i3 ]) * u3);+ *y = 0.5f * ((2.0f * ys[ i1 ]) + (-ys[ i0 ] + ys[ i2 ]) * u+ + (2.0f * ys[ i0 ] - 5.0f * ys[ i1 ] + 4.0f * ys[ i2 ] - ys[ i3 ]) * u2+ + (-ys[ i0 ] + 3.0f * ys[ i1 ] - 3.0f * ys[ i2 ] + ys[ i3 ]) * u3);+}++// ------------------------------------------------------------------------------------------------+// the camera+// ------------------------------------------------------------------------------------------------++/** One number moving from one value to another over a stretch of the shot list's clock. */+struct CinemaTween+{+ Real from;+ Real to;+ Real start;+ Real length;++ Real at( Real now ) const+ {+ if (length <= 0.0f)+ return to;+ return from + (to - from) * CinemaDirector_ease( (now - start) / length );+ }++ void go( Real now, Real target, Real seconds )+ {+ from = at( now );+ to = target;+ start = now;+ length = seconds;+ }++ void cut( Real value )+ {+ from = value;+ to = value;+ length = 0.0f;+ }+};++enum CinemaPlaceMode+{+ CINEMA_PLACE_STILL,+ CINEMA_PLACE_ROUTE,+ CINEMA_PLACE_FOLLOW+};++static Bool theCinemaLoaded = FALSE;+static std::vector<CinemaShot> theCinemaShots;+static size_t theCinemaNext = 0;+static Bool theCinemaHudHidden = FALSE;+static Bool theCinemaLetterbox = FALSE;+static Bool theCinemaFlying = FALSE; ///< a camera verb has run; until then the player has the camera+static Real theCinemaBaseZoom = 1.0f;+static Real theCinemaStillX = 0.0f;+static Real theCinemaStillY = 0.0f;+static CinemaPlaceMode theCinemaPlaceMode = CINEMA_PLACE_STILL;+static Real theCinemaRouteX[ CINEMA_MAX_ROUTE_POINTS ];+static Real theCinemaRouteY[ CINEMA_MAX_ROUTE_POINTS ];+static Int theCinemaRoutePoints = 0;+static Real theCinemaRouteStart = 0.0f;+static Real theCinemaRouteLength = 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;+static CinemaTween theCinemaZoom;+static CinemaTween theCinemaAngle;+static CinemaTween theCinemaPitch;+static UnsignedInt theCinemaSeenFrame = 0;+static DWORD theCinemaSeenFrameAt = 0;++static Bool cinemaShotIsEarlier( const CinemaShot &left, const CinemaShot &right )+{+ return left.at < right.at;+}++static void loadCinema( void )+{+ theCinemaLoaded = TRUE;++ AsciiString path;+ path.set( CINEMA_DIRECTORY );+ path.concat( TheGlobalData->m_cinemaScript );+ path.concat( CINEMA_EXTENSION );++ // bytes, not text, for the reason loadScenario gives+ File *file = TheFileSystem->openFile( path.str(), File::READ );+ if (file == NULL)+ {+ DEBUG_LOG(("CINEMA: cannot open '%s'; the interface is off and the camera is yours\n", path.str()));+ return;+ }+ const Int fileSize = file->size();+ char *contents = file->readEntireAndClose();+ if (contents == NULL)+ {+ DEBUG_LOG(("CINEMA: '%s' read as nothing\n", path.str()));+ return;+ }++ Int lineNumber = 0;+ Int refused = 0;+ Int at = 0;+ while (at < fileSize)+ {+ Int end = at;+ while (end < fileSize && contents[ end ] != '\n')+ ++end;+ char line[ 512 ];+ const Int length = end - at;+ const Int copied = (length < (Int)sizeof( line ) - 1) ? length : (Int)sizeof( line ) - 1;+ memcpy( line, contents + at, copied );+ line[ copied ] = 0;+ ++lineNumber;++ CinemaShot shot;+ Bool isShot = FALSE;+ AsciiString reason;+ if (!CinemaDirector_parseLine( line, &shot, &isShot, &reason ))+ {+ DEBUG_LOG(("CINEMA: %s line %d: %s\n", path.str(), lineNumber, reason.str()));+ ++refused;+ }+ else if (isShot)+ {+ theCinemaShots.push_back( shot );+ }+ at = end + 1;+ }+ delete [] contents;++ std::stable_sort( theCinemaShots.begin(), theCinemaShots.end(), cinemaShotIsEarlier );+ DEBUG_LOG(("CINEMA: loaded '%s', %d shots, %d lines refused\n", path.str(), (Int)theCinemaShots.size(), refused));+}++/** The shot list's clock in seconds. Between logic frames it runs on from the last one by the wall+ clock, capped at one frame, so a camera does not move in 30Hz steps on a faster display; while a+ -video range is being recorded it is the logic frame alone, because that is what each picture is. */+static Real cinemaNow( void )+{+ const UnsignedInt frame = TheGameLogic->getFrame();+ const DWORD wall = timeGetTime();+ if (frame != theCinemaSeenFrame)+ {+ theCinemaSeenFrame = frame;+ theCinemaSeenFrameAt = wall;+ }+ Real fraction = 0.0f;+ const Bool recording = TheGlobalData->m_videoEndFrame > 0;+ if (!recording && !TheGameLogic->isGamePaused())+ {+ fraction = (Real)(wall - theCinemaSeenFrameAt) / CINEMA_FRAME_MS;+ if (fraction > 1.0f)+ fraction = 1.0f;+ }+ return ((Real)frame + fraction) / (Real)LOGICFRAMES_PER_SECOND;+}++static void cinemaPlace( Real now, Real *x, Real *y )+{+ if (theCinemaPlaceMode == CINEMA_PLACE_ROUTE)+ {+ const Real t = (theCinemaRouteLength > 0.0f) ? CinemaDirector_ease( (now - theCinemaRouteStart) / theCinemaRouteLength ) : 1.0f;+ CinemaDirector_routePoint( theCinemaRouteX, theCinemaRouteY, theCinemaRoutePoints, t, x, y );+ return;+ }+ *x = theCinemaStillX;+ *y = theCinemaStillY;+}++/** Freeze wherever the camera is looking right now; the next move starts from there. */+static void cinemaSettle( Real now )+{+ cinemaPlace( now, &theCinemaStillX, &theCinemaStillY );+ theCinemaPlaceMode = CINEMA_PLACE_STILL;+}++static void cinemaTakeTheCamera( void )+{+ if (theCinemaFlying)+ return;+ theCinemaFlying = TRUE;++ Coord3D pos;+ TheTacticalView->getPosition( &pos );+ theCinemaStillX = pos.x;+ theCinemaStillY = pos.y;+ theCinemaBaseZoom = TheTacticalView->getZoom();+ theCinemaZoom.cut( 1.0f );+ theCinemaAngle.cut( TheTacticalView->getAngle() * 180.0f / PI );+ theCinemaPitch.cut( TheTacticalView->getPitch() * 180.0f / PI );++ // the view eases its own zoom towards the ground under it and chases a locked unit; both would+ // fight a camera that is being told exactly where to be every frame+ TheTacticalView->setOkToAdjustHeight( FALSE );+ TheTacticalView->setCameraLock( INVALID_ID );+}++static Object *findNearestOfTemplate( const AsciiString &name, Real x, Real y )+{+ Object *best = NULL;+ Real bestDistance = 0.0f;+ for (Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject())+ {+ if (obj->isEffectivelyDead() || obj->getTemplate()->getName() != name)+ continue;+ const Real dx = obj->getPosition()->x - x;+ const Real dy = obj->getPosition()->y - y;+ const Real distance = dx * dx + dy * dy;+ if (best == NULL || distance < bestDistance)+ {+ best = obj;+ bestDistance = distance;+ }+ }+ return best;+}++static void cinemaEndTheMatch( void )+{+ // the same teardown an unattended run finishes with, and for the same reasons (updateHeadlessRun)+ if (TheRecorder->getMode() == RECORDERMODETYPE_RECORD)+ TheRecorder->stopRecording();+ TheGameLogic->clearGameData( FALSE );+ TheGameEngine->setQuitting( TRUE );+}++static GameWindow *cinemaControlBarWindow( void )+{+ static const NameKeyType id = TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:ControlBarParent" ) );+ return TheWindowManager->winGetWindowFromId( NULL, id );+}++static void cinemaSetHud( Bool hidden )+{+ if (hidden == theCinemaHudHidden)+ return;+ theCinemaHudHidden = hidden;+ if (hidden)+ {+ HideControlBar( TRUE );+ TheInGameUI->deselectAllDrawables();+ }+ else+ {+ ShowControlBar( TRUE );+ TheMouse->setVisibility( TRUE );+ }+}++/** The match puts the control bar up and the letterbox down on its own when loading finishes, which is+ after the first frame this runs on, so what the shot list asked for is re-asserted every pass. */+static void cinemaHoldTheFrame( void )+{+ if (theCinemaHudHidden)+ {+ GameWindow *bar = cinemaControlBarWindow();+ if (bar != NULL && !bar->winIsHidden())+ HideControlBar( TRUE );+ // the cursor comes back whenever the game decides it should, so it is put away every pass+ TheMouse->setVisibility( FALSE );+ if (TheInGameUI->getSelectCount() > 0)+ TheInGameUI->deselectAllDrawables();+ }+ if (theCinemaLetterbox != TheDisplay->isLetterBoxed() && !TheDisplay->isLetterBoxFading())+ {+ TheDisplay->setLetterBoxAspect( CINEMA_LETTERBOX_ASPECT );+ TheDisplay->enableLetterBox( theCinemaLetterbox );+ }+}++static void runShot( const CinemaShot &shot )+{+ const Real now = shot.at;+ DEBUG_LOG(("CINEMA: %.2fs verb %d over %.2fs\n", now, (Int)shot.verb, shot.seconds));++ switch (shot.verb)+ {+ case CINEMA_VERB_CUT:+ cinemaTakeTheCamera();+ theCinemaPlaceMode = CINEMA_PLACE_STILL;+ theCinemaFollowID = INVALID_ID;+ theCinemaStillX = shot.routeX[ 0 ];+ theCinemaStillY = shot.routeY[ 0 ];+ if (shot.values > 0)+ theCinemaZoom.cut( shot.value[ 0 ] );+ if (shot.values > 1)+ theCinemaAngle.cut( shot.value[ 1 ] );+ if (shot.values > 2)+ theCinemaPitch.cut( shot.value[ 2 ] );+ break;++ case CINEMA_VERB_MOVE:+ case CINEMA_VERB_ROUTE:+ {+ cinemaTakeTheCamera();+ cinemaSettle( now );+ theCinemaFollowID = INVALID_ID;+ theCinemaRouteX[ 0 ] = theCinemaStillX;+ theCinemaRouteY[ 0 ] = theCinemaStillY;+ theCinemaRoutePoints = 1;+ const Int points = (shot.verb == CINEMA_VERB_MOVE) ? 1 : shot.routePoints;+ for (Int i = 0; i < points; ++i)+ {+ theCinemaRouteX[ theCinemaRoutePoints ] = shot.routeX[ i ];+ theCinemaRouteY[ theCinemaRoutePoints ] = shot.routeY[ i ];+ ++theCinemaRoutePoints;+ }+ theCinemaRouteStart = now;+ theCinemaRouteLength = shot.seconds;+ theCinemaPlaceMode = CINEMA_PLACE_ROUTE;+ break;+ }++ case CINEMA_VERB_ZOOM:+ cinemaTakeTheCamera();+ theCinemaZoom.go( now, shot.value[ 0 ], shot.seconds );+ break;++ case CINEMA_VERB_ANGLE:+ cinemaTakeTheCamera();+ theCinemaAngle.go( now, shot.value[ 0 ], shot.seconds );+ break;++ case CINEMA_VERB_ORBIT:+ cinemaTakeTheCamera();+ theCinemaAngle.go( now, theCinemaAngle.to + shot.value[ 0 ], shot.seconds );+ break;++ case CINEMA_VERB_PITCH:+ cinemaTakeTheCamera();+ theCinemaPitch.go( now, shot.value[ 0 ], shot.seconds );+ break;++ case CINEMA_VERB_FOLLOW:+ {+ cinemaTakeTheCamera();+ cinemaSettle( now );+ Object *obj = findNearestOfTemplate( shot.name, theCinemaStillX, theCinemaStillY );+ if (obj == NULL)+ {+ DEBUG_LOG(("CINEMA: follow: no '%s' on the map\n", shot.name.str()));+ break;+ }+ theCinemaFollowID = obj->getID();+ theCinemaFollowUntil = (shot.seconds > 0.0f) ? now + shot.seconds : 0.0f;+ theCinemaPlaceMode = CINEMA_PLACE_FOLLOW;+ break;+ }++ case CINEMA_VERB_UNFOLLOW:+ theCinemaFollowID = INVALID_ID;+ theCinemaPlaceMode = CINEMA_PLACE_STILL;+ break;++ case CINEMA_VERB_HUD:+ cinemaSetHud( !shot.on );+ break;++ case CINEMA_VERB_LETTERBOX:+ theCinemaLetterbox = shot.on;+ break;++ case CINEMA_VERB_SHOT:+ {+ Coord3D pos;+ TheTacticalView->getPosition( &pos );+ DEBUG_LOG(("CINEMA: shot at %.2fs, looking at (%.0f,%.0f), zoom %.2f, angle %.1f, pitch %.1f\n", now,+ pos.x, pos.y, TheTacticalView->getZoom(), TheTacticalView->getAngle() * 180.0f / PI,+ TheTacticalView->getPitch() * 180.0f / PI));+ TheDisplay->takeScreenShot();+ break;+ }++ case CINEMA_VERB_END:+ cinemaEndTheMatch();+ break;++ default:+ DEBUG_CRASH(("CINEMA: verb %d has no handler", (Int)shot.verb));+ break;+ }+}++/** 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 )+{+ const Real elapsed = now - theCinemaLastNow;+ if (theCinemaFollowUntil > 0.0f && now >= theCinemaFollowUntil)+ {+ theCinemaFollowID = INVALID_ID;+ theCinemaPlaceMode = CINEMA_PLACE_STILL;+ return;+ }+ Object *obj = TheGameLogic->findObjectByID( theCinemaFollowID );+ if (obj == NULL || obj->isEffectivelyDead())+ {+ theCinemaFollowID = INVALID_ID;+ theCinemaPlaceMode = CINEMA_PLACE_STILL;+ return;+ }+ 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;+}++void CinemaDirector_update( void )+{+ if (TheGlobalData->m_cinemaScript.isEmpty() || TheTacticalView == NULL || TheTerrainLogic == NULL)+ return;+ if (!TheGameLogic->isInGame() || TheGameLogic->isInShellGame())+ return;++ if (!theCinemaLoaded)+ {+ loadCinema();+ cinemaSetHud( TRUE );+ }++ const Real now = cinemaNow();+ while (theCinemaNext < theCinemaShots.size() && theCinemaShots[ theCinemaNext ].at <= now)+ {+ runShot( theCinemaShots[ theCinemaNext ] );+ ++theCinemaNext;+ if (TheGameEngine->getQuitting())+ return;+ }++ cinemaHoldTheFrame();++ if (theCinemaFlying)+ {+ if (theCinemaPlaceMode == CINEMA_PLACE_FOLLOW)+ cinemaChase( now );+ Coord3D look;+ cinemaPlace( now, &look.x, &look.y );+ look.z = TheTerrainLogic->getGroundHeight( look.x, look.y );+ TheTacticalView->lookAt( &look );+ TheTacticalView->setZoom( theCinemaBaseZoom * theCinemaZoom.at( now ) );+ TheTacticalView->setAngle( theCinemaAngle.at( now ) * PI / 180.0f );+ TheTacticalView->setPitch( theCinemaPitch.at( now ) * PI / 180.0f );+ }+ theCinemaLastNow = now;+}++Bool CinemaDirector_hidesHud( void )+{+ return theCinemaHudHidden;+}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Display.cppindex 1bfb3d5b3..4ec122a7b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp@@ -55,6 +55,7 @@ Display::Display()m_debugDisplay = NULL;m_letterBoxFadeLevel = 0;m_letterBoxEnabled = FALSE;+ m_letterBoxAspect = 16.0f / 9.0f;m_cinematicText = AsciiString::TheEmptyString;m_cinematicFont = NULL;m_cinematicTextFrames = 0;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex df4212544..97eab75b5 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -2576,8 +2576,8 @@ void W3DDisplay::renderLetterBox(UnsignedInt currentTime)Int height = (Int)(getHeight() * 0.12f * m_letterBoxFadeLevel);TheTacticalView->setOrigin(0, height);#else- drawFillRect( 0, 0, m_width, (m_height-(9.0f/16.0f * m_width))*0.5f, lbcolor );- drawFillRect( 0, m_height-(m_height-(9.0f/16.0f * m_width))*0.5f, m_width, m_height, lbcolor );+ drawFillRect( 0, 0, m_width, (m_height-(m_width / m_letterBoxAspect))*0.5f, lbcolor );+ drawFillRect( 0, m_height-(m_height-(m_width / m_letterBoxAspect))*0.5f, m_width, m_height, lbcolor );#endif}else@@ -2594,8 +2594,8 @@ void W3DDisplay::renderLetterBox(UnsignedInt currentTime)Int height = (Int)(getHeight() * 0.12f * m_letterBoxFadeLevel);TheTacticalView->setOrigin(0, height);#else- drawFillRect( 0, 0, m_width, (m_height-(9.0f/16.0f * m_width))*0.5f, lbcolor );- //drawFillRect( 0, m_height-(m_height-(9.0f/16.0f * m_width))*0.5f, m_width, m_height, lbcolor );+ drawFillRect( 0, 0, m_width, (m_height-(m_width / m_letterBoxAspect))*0.5f, lbcolor );+ drawFillRect( 0, m_height-(m_height-(m_width / m_letterBoxAspect))*0.5f, m_width, m_height, lbcolor );#endif}elsediff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex ada84a51c..f91e61c7a 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -39,6 +39,7 @@#include "GameLogic/TerrainLogic.h"#include "GameLogic/GameLogic.h"#include "GameLogic/Object.h"+#include "GameClient/CinemaDirector.h"#include "GameClient/DisplayStringManager.h"#include "GameClient/Drawable.h"#include "GameClient/GadgetListBox.h"@@ -396,6 +397,14 @@ void W3DInGameUI::reset( void )//-------------------------------------------------------------------------------------------------void W3DInGameUI::draw( void ){+ // -cinema: none of the interface, only the windows - the control bar is already hidden, and+ // what is left on the window list is the menu somebody opened on purpose+ if( CinemaDirector_hidesHud() )+ {+ TheWindowManager->winRepaint();+ return;+ }+preDraw();// draw selection region if drag selectingdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex d95a61266..cd5d911f7 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -50,6 +50,7 @@#include "GameClient/Color.h"#include "GameClient/CameraBoundary.h"+#include "GameClient/CinemaDirector.h"#include "GameClient/CommandXlat.h"#include "GameClient/Drawable.h"#include "GameClient/GameClient.h"@@ -1086,6 +1087,10 @@ static void drawablePostDraw( Drawable *draw, void *userData )if (draw->isDrawableEffectivelyHidden() || FXPitch < 0.0f)return;+ // -cinema: no health bars, ranks or captions over the units+ if (CinemaDirector_hidesHud())+ return;+Object* obj = draw->getObject();Int localPlayerIndex = ThePlayerList ? ThePlayerList->getLocalPlayer()->getPlayerIndex() : 0;#if defined(_DEBUG) || defined(_INTERNAL)diff --git a/GeneralsMD/Code/Tests/test_cinema.inc b/GeneralsMD/Code/Tests/test_cinema.incnew file mode 100644index 000000000..6f5540e68--- /dev/null+++ b/GeneralsMD/Code/Tests/test_cinema.inc@@ -0,0 +1,96 @@+// -cinema's shot list. A shot that is half-read still flies a camera, just not the one written down,+// and footage is judged by eye, so every refused line has to say why and every accepted one has to+// carry exactly the numbers on it.++#include "GameClient/CinemaDirector.h"++TEST(cinema_parses_a_move_and_a_cut)+{+ CinemaShot shot;+ Bool isShot = FALSE;+ AsciiString reason;++ CHECK( CinemaDirector_parseLine( "2.5 move 1200 900 4", &shot, &isShot, &reason ) );+ CHECK( isShot );+ CHECK_EQ( (Int)shot.verb, (Int)CINEMA_VERB_MOVE );+ CHECK_NEAR( shot.at, 2.5f, 0.001f );+ CHECK_NEAR( shot.routeX[ 0 ], 1200.0f, 0.001f );+ CHECK_NEAR( shot.routeY[ 0 ], 900.0f, 0.001f );+ CHECK_NEAR( shot.seconds, 4.0f, 0.001f );++ // a cut takes x y and then as much of zoom, angle and pitch as it cares to give+ CHECK( CinemaDirector_parseLine( "0 cut 500 600 0.8 45", &shot, &isShot, &reason ) );+ CHECK_EQ( (Int)shot.verb, (Int)CINEMA_VERB_CUT );+ CHECK_EQ( shot.values, 2 );+ CHECK_NEAR( shot.value[ 0 ], 0.8f, 0.001f );+ CHECK_NEAR( shot.value[ 1 ], 45.0f, 0.001f );+ CHECK_NEAR( shot.seconds, 0.0f, 0.001f );+}++TEST(cinema_parses_a_route_follow_and_switches)+{+ CinemaShot shot;+ Bool isShot = FALSE;+ AsciiString reason;++ CHECK( CinemaDirector_parseLine( "10 route 6 100 100 200 150 300 100 # along the river", &shot, &isShot, &reason ) );+ CHECK_EQ( (Int)shot.verb, (Int)CINEMA_VERB_ROUTE );+ CHECK_EQ( shot.routePoints, 3 );+ CHECK_NEAR( shot.routeX[ 2 ], 300.0f, 0.001f );+ CHECK_NEAR( shot.seconds, 6.0f, 0.001f );++ CHECK( CinemaDirector_parseLine( "12 follow AmericaTankCrusader 5", &shot, &isShot, &reason ) );+ CHECK_EQ( (Int)shot.verb, (Int)CINEMA_VERB_FOLLOW );+ CHECK_STR( shot.name.str(), "AmericaTankCrusader" );+ CHECK_NEAR( shot.seconds, 5.0f, 0.001f );++ CHECK( CinemaDirector_parseLine( "0 hud on", &shot, &isShot, &reason ) );+ CHECK_EQ( (Int)shot.verb, (Int)CINEMA_VERB_HUD );+ CHECK( shot.on );++ CHECK( CinemaDirector_parseLine( " # only a comment", &shot, &isShot, &reason ) );+ CHECK( !isShot );+}++TEST(cinema_refuses_what_it_cannot_read)+{+ CinemaShot shot;+ Bool isShot = FALSE;+ AsciiString reason;++ // strtod would read "3s" as 3; a typo has to be refused, not fired at the wrong time+ CHECK( !CinemaDirector_parseLine( "3s move 1 2 3", &shot, &isShot, &reason ) );+ CHECK( !reason.isEmpty() );+ CHECK( !CinemaDirector_parseLine( "3 move 1 2", &shot, &isShot, &reason ) );+ CHECK( !CinemaDirector_parseLine( "3 zoom 0 2", &shot, &isShot, &reason ) );+ CHECK( !CinemaDirector_parseLine( "3 pitch 50 2", &shot, &isShot, &reason ) );+ CHECK( !CinemaDirector_parseLine( "3 route 5 100", &shot, &isShot, &reason ) );+ CHECK( !CinemaDirector_parseLine( "3 hud maybe", &shot, &isShot, &reason ) );+ CHECK( !CinemaDirector_parseLine( "3 dolly 1 2", &shot, &isShot, &reason ) );+ CHECK( !CinemaDirector_parseLine( "-1 shot", &shot, &isShot, &reason ) );+}++TEST(cinema_eases_and_curves_through_its_points)+{+ CHECK_NEAR( CinemaDirector_ease( -1.0f ), 0.0f, 0.0001f );+ CHECK_NEAR( CinemaDirector_ease( 0.5f ), 0.5f, 0.0001f );+ CHECK_NEAR( CinemaDirector_ease( 2.0f ), 1.0f, 0.0001f );+ // level at the ends: the first tenth covers far less than a tenth of the way+ CHECK( CinemaDirector_ease( 0.1f ) < 0.05f );++ const Real xs[] = { 0.0f, 100.0f, 200.0f };+ const Real ys[] = { 0.0f, 100.0f, 0.0f };+ Real x = 0.0f;+ Real y = 0.0f;+ CinemaDirector_routePoint( xs, ys, 3, 0.0f, &x, &y );+ CHECK_NEAR( x, 0.0f, 0.001f );+ CinemaDirector_routePoint( xs, ys, 3, 0.5f, &x, &y );+ CHECK_NEAR( x, 100.0f, 0.001f );+ CHECK_NEAR( y, 100.0f, 0.001f );+ CinemaDirector_routePoint( xs, ys, 3, 1.0f, &x, &y );+ CHECK_NEAR( x, 200.0f, 0.001f );+ CHECK_NEAR( y, 0.0f, 0.001f );+ // between the points it bends through them rather than cutting the corner+ CinemaDirector_routePoint( xs, ys, 3, 0.25f, &x, &y );+ CHECK( y > 50.0f );+}diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 52d3064c5..2b8187eb5 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -13041,3 +13041,4 @@ TEST(camera_preferences_default_to_a_finite_map_margin)#include "test_minimap_input.inc"#include "test_selection_priority.inc"#include "test_supply_center_save.inc"+#include "test_cinema.inc"