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(gameclient): freecam photo mode in the console
Olcay Seygan67e84b5c20b7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6c834f924..c8bf01760 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1052,6 +1052,14 @@ A third pass went through the generals' powers, promotions and unit abilities.- One press is one letter. Holding a key repeats it, and the game timed that wait in frames: a third of a second at the 30 frames a second it was written for, 70 milliseconds on a 144 Hz screen, which is shorter than an ordinary keypress. It waits 0.4 seconds now whatever the frame rate, in the console, the chat box and every text field.- On a UK keyboard, AltGr+4 types the euro sign. It used to type the wrong character.+## A photo mode, from the console++- Type `freecam` and the camera comes off its rails. W and S fly it forward and back along wherever you are looking, A and D slide it sideways, R lifts it and F drops it, and the mouse turns it with no button held. Shift flies four times as fast. It tilts to straight up and straight down, and there is no ceiling, no floor and no edge of the map to stop at: put it on the ground behind a tank and look up at a Comanche, or climb until the whole map fits on the screen. Escape or `freecam` again puts you back where you left off.+- The interface goes while it flies, so the picture is only the battlefield: no command bar, no cursor, no health bars. F12 still takes the screenshot. Every key belongs to the camera in the meantime, so W does not select a unit and F does not build anything.+- The whole map is drawn out to its edges from wherever the camera is. The usual view draws the ground and the shadows the camera can see from above; aimed at the horizon, the old limits cut the world off a short way out and left the far half of a map dark and shadowless. In the freecam the shadows cover the whole map, with a shadow map four times as wide so the far ones are as sharp as the near ones.+- The match carries on underneath, and the fog of war stays as it is: the camera sees what you could already see. It changes nothing in the battle, so it works in replays and in multiplayer too.+- `freecam 1200 900 600 45 -30` flies straight to a spot: the position, then the heading and the tilt in degrees. Leaving the freecam prints where it was in that same form, so a good angle can be found again.+## A scoreboard on Tab- Hold Tab and a scoreboard opens in the top left corner of the screen, beside the menu key; let go and it is gone. All eight seats of a full game fit in the top half of a 720 line screen. It is built from your command bar's steel, grey, red or sand for your side, with the match clock in its corner. Each side sits under a band edged green for yours and red for the enemy, and the band says how many of that side are still in the game, 4/4 down to 0/4. Watching, there is a band for every team. With a group selected, Tab still steps through the units in it as before, so the scoreboard wants one unit or none selected.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.h b/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.hindex e0d2ca252..30b4690c3 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.h@@ -75,7 +75,7 @@ void CinemaDirector_routePoint( const Real *xs, const Real *ys, Int count, Real/// once a render pass, after the logic tickvoid CinemaDirector_update( void );-/// the interface is off: nothing but the world is drawn+/// the interface is off, under -cinema or the console's freecam: nothing but the world is drawnBool CinemaDirector_hidesHud( void );#endif // __CINEMADIRECTOR_H_diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GameConsole.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GameConsole.hindex 04660c4da..37ee89205 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GameConsole.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GameConsole.h@@ -98,6 +98,9 @@ private:extern GameConsole *TheGameConsole;+/// -freecam x y z heading tilt: the console's "freecam" with that pose, run once the match is up+void GameConsole_setStartupFreeCamera( const char *pose );+/*** Sits ahead of the window system on the message stream so the console gets the key above Tab* before anything bound in CommandMap.ini does, and swallows every key while it is open.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.hindex 23ff53a39..36cc538d5 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.h@@ -276,6 +276,9 @@ public:virtual void draw( void ); ///< draw the mousevirtual void setPosition( Int x, Int y ); ///< set the mouse position+ /// move the real pointer to this pixel of the game's window; FALSE where the platform cannot, or+ /// the window is not the one in front+ virtual Bool warpCursor( Int x, Int y ) { return FALSE; }virtual void setCursor( MouseCursor cursor ) = 0; ///< set mouse cursorvirtual void capture( void ) = 0; ///< capture the mousediff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h b/GeneralsMD/Code/GameEngine/Include/GameClient/View.hindex 5eaaa0606..8dbc5a33c 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h@@ -242,6 +242,27 @@ public:virtual void forceCameraConstraintRecalc(void) {}virtual void setGuardBandBias( const Coord2D *gb ) = 0;+ /** The console's freecam, a photo mode: the camera flies on its own from an eye point with a+ * heading and a tilt, free of the look point, the zoom, the pitch range and the map's edges, and+ * draws the whole map. The look point (getPosition) stays where it was, so nothing that reads+ * it sees the flight. Client only. */+ enum FreeCameraKeys+ {+ FREECAM_FORWARD = 0x01,+ FREECAM_BACK = 0x02,+ FREECAM_LEFT = 0x04,+ FREECAM_RIGHT = 0x08,+ FREECAM_UP = 0x10,+ FREECAM_DOWN = 0x20,+ };+ virtual void setFreeCamera( Bool on ) { }+ virtual Bool isFreeCamera( void ) const { return FALSE; }+ /// eye in world units, heading and tilt in radians (heading 0 looks along +x, tilt 0 is level)+ virtual void setFreeCameraPose( const Coord3D *eye, Real heading, Real tilt ) { }+ virtual void getFreeCameraPose( Coord3D *eye, Real *heading, Real *tilt ) const { }+ /// which of the FreeCameraKeys are held+ virtual void setFreeCameraKeys( UnsignedInt keys ) { }+protected:friend class Display;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex e458a591b..68c40c6e0 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -37,6 +37,7 @@#include "GameClient/TerrainVisual.h" // for TERRAIN_LOD_MIN definition#include "GameClient/GameText.h"#include "GameClient/ChromaKeyboard.h"+#include "GameClient/GameConsole.h" // for -freecam#include "GameNetwork/GameInfo.h" // for the SlotState -autoskirmish hands the AI slots#include "GameNetwork/NetworkUtil.h" // for ResolveIP, which -lanip parses its address with#include "Common/FileSystem.h"@@ -1969,6 +1970,22 @@ Int parseCinema(char *args[], int num)return 1;}+/* -freecam <x> <y> <z> <heading> <tilt> puts the match into the console's freecam at that pose once+ it is up, the way typing 'freecam x y z heading tilt' would. A screenshot script cannot fly the+ camera with the mouse, so this is how a photo-mode picture is taken unattended. Angles are in+ degrees, heading 0 along +x, tilt 0 level and negative looking down. */+Int parseFreeCamera(char *args[], int num)+{+ if (num > 5)+ {+ AsciiString pose;+ pose.format("%s %s %s %s %s", args[1], args[2], args[3], args[4], args[5]);+ GameConsole_setStartupFreeCamera(pose.str());+ return 6;+ }+ return 1;+}+/* -side <slot> <faction> nails one -autoskirmish slot to a faction instead of letting the seedpick it.@@ -2557,6 +2574,7 @@ static CommandLineParam params[] ={ "-nodevice", parseNoDevice },{ "-scenario", parseScenario },{ "-cinema", parseCinema },+ { "-freecam", parseFreeCamera },{ "-side", parseSide },{ "-takeover", parseTakeover },{ "-replay", parseReplay },diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cppindex 5601f52d0..a5415b373 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp@@ -819,5 +819,6 @@ void CinemaDirector_update( void )Bool CinemaDirector_hidesHud( void ){- return theCinemaHudHidden;+ // the console's freecam is a photo mode, and the interface is the first thing out of a photo+ return theCinemaHudHidden || (TheTacticalView != NULL && TheTacticalView->isFreeCamera());}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cppindex be5e5384f..65f18801e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp@@ -51,6 +51,7 @@#include "GameClient/KeyDefs.h"#include "GameClient/Keyboard.h"#include "GameClient/Mouse.h"+#include "GameClient/View.h"GameConsole *TheGameConsole = NULL;@@ -231,6 +232,75 @@ static AsciiString runSetOption( AsciiString arguments )return describeOption( *def );}+//-------------------------------------------------------------------------------------------------+/** The freecam, a photo mode: the tactical view flies free and draws the whole map, the interface+ * goes, and the keys and the mouse belong to the camera until it lands. Nothing of it reaches the+ * logic, so it is offered in every match, network games and replays included. */+//-------------------------------------------------------------------------------------------------+static const char *const FREECAM_HELP =+ "freecam on: W/S forward and back, A/D left and right, R up, F down, mouse turns, Shift faster; Esc or 'freecam' lands";+static const UnsignedInt FREECAM_STARTUP_FRAME = 2; ///< -freecam waits for the map's own opening view to land++static AsciiString theStartupFreeCamera; ///< -freecam's console line, run once the match is up++void GameConsole_setStartupFreeCamera( const char *pose )+{+ theStartupFreeCamera.format( "freecam %s", pose );+}++static AsciiString describeFreeCameraPose( void )+{+ Coord3D eye;+ Real heading, tilt;+ TheTacticalView->getFreeCameraPose( &eye, &heading, &tilt );+ AsciiString result;+ result.format( "%.0f %.0f %.0f %.1f %.1f", eye.x, eye.y, eye.z, heading * 180.0f / PI, tilt * 180.0f / PI );+ return result;+}++static AsciiString runFreeCamera( AsciiString arguments )+{+ AsciiString result;+ if( TheTacticalView == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )+ {+ result = "freecam: in a match or a replay only";+ return result;+ }++ Real pose[ 5 ];+ const Int given = arguments.isEmpty() ? 0+ : sscanf( arguments.str(), "%f %f %f %f %f", &pose[ 0 ], &pose[ 1 ], &pose[ 2 ], &pose[ 3 ], &pose[ 4 ] );+ if( !arguments.isEmpty() && given != 5 )+ {+ result = "freecam: takes nothing, or x y z heading tilt with the angles in degrees";+ return result;+ }++ if( given == 5 )+ {+ TheTacticalView->setFreeCamera( TRUE );+ Coord3D eye;+ eye.set( pose[ 0 ], pose[ 1 ], pose[ 2 ] );+ TheTacticalView->setFreeCameraPose( &eye, pose[ 3 ] * PI / 180.0f, pose[ 4 ] * PI / 180.0f );+ }+ else if( TheTacticalView->isFreeCamera() )+ {+ // where it landed, in the form 'freecam x y z heading tilt' takes back+ result.format( "freecam off, was at %s", describeFreeCameraPose().str() );+ TheTacticalView->setFreeCamera( FALSE );+ return result;+ }+ else+ {+ TheTacticalView->setFreeCamera( TRUE );+ }++ if( TheGameConsole )+ TheGameConsole->closeCheatPanel(); // it would be in every picture+ result = FREECAM_HELP;+ return result;+}+//-------------------------------------------------------------------------------------------------GameConsole::GameConsole(): m_isOpen( FALSE ),@@ -404,6 +474,10 @@ void GameConsole::runCommand( AsciiString commandLine )printLine( AsciiString( "get [key] a setting by its Options.ini key; no key lists them all" ) );printLine( AsciiString( "set <key> <v> change a setting and save it, e.g. 'set ShowNetBox no' hides the" ) );printLine( AsciiString( " top right info box, 'set ShowSuperweaponStrip no' the superweapon timers" ) );+ printLine( AsciiString( "freecam photo mode: fly the camera anywhere, the whole map drawn, no interface." ) );+ printLine( AsciiString( " W/S forward and back, A/D left and right, R up, F down, mouse turns," ) );+ printLine( AsciiString( " Shift faster; Esc or 'freecam' again lands. 'freecam x y z heading tilt'" ) );+ printLine( AsciiString( " flies to a pose, angles in degrees" ) );if( areCheatsAvailable() ){printLine( AsciiString( "cheats single-player cheats" ) );@@ -458,6 +532,15 @@ void GameConsole::runCommand( AsciiString commandLine )return;}+ if( command == "freecam" )+ {+ printLine( runFreeCamera( arguments ) );+ // out of the way of the picture, and of the keys the camera now takes+ if( TheTacticalView && TheTacticalView->isFreeCamera() )+ close();+ return;+ }+if( command == "get" ){if( arguments.isEmpty() )@@ -487,6 +570,15 @@ void GameConsole::runCommand( AsciiString commandLine )//-------------------------------------------------------------------------------------------------void GameConsole::render( void ){+ if( !theStartupFreeCamera.isEmpty() && TheGameLogic->isInGame() && !TheGameLogic->isInShellGame()+ && TheGameLogic->getFrame() >= FREECAM_STARTUP_FRAME )+ {+ const AsciiString line = theStartupFreeCamera;+ theStartupFreeCamera.clear();+ runCommand( line );+ DEBUG_LOG(( "-freecam: %s\n", line.str() ));+ }+renderCheatPanel(); // under the console, which covers it when it dropsif( !m_isOpen )@@ -688,12 +780,59 @@ Bool GameConsole::handleCheatPanelMouse( const ICoord2D &mouse, Bool act )return TRUE;}+//-------------------------------------------------------------------------------------------------+/** While the freecam flies every key is the camera's, so nothing reaches a hotkey or an order:+ * W/A/S/D/R/F are held for the flight, Esc lands on its release (the press is eaten too, so the+ * quit menu never sees either half), and F12 still takes a picture. */+//-------------------------------------------------------------------------------------------------+static UnsignedInt theFreeCameraKeys = 0;++static GameMessageDisposition translateFreeCameraKey( UnsignedByte key, UnsignedShort keyState )+{+ const Bool down = BitTest( keyState, KEY_STATE_DOWN );+ UnsignedInt bit = 0;+ switch( key )+ {+ case KEY_W: bit = View::FREECAM_FORWARD; break;+ case KEY_S: bit = View::FREECAM_BACK; break;+ case KEY_A: bit = View::FREECAM_LEFT; break;+ case KEY_D: bit = View::FREECAM_RIGHT; break;+ case KEY_R: bit = View::FREECAM_UP; break;+ case KEY_F: bit = View::FREECAM_DOWN; break;++ case KEY_ESC:+ if( !down )+ {+ TheGameConsole->printLine( runFreeCamera( AsciiString::TheEmptyString ) );+ theFreeCameraKeys = 0;+ }+ return DESTROY_MESSAGE;++ case KEY_F12:+ return KEEP_MESSAGE;+ }++ if( bit != 0 )+ {+ if( down )+ theFreeCameraKeys |= bit;+ else+ theFreeCameraKeys &= ~bit;+ TheTacticalView->setFreeCameraKeys( theFreeCameraKeys );+ }+ return DESTROY_MESSAGE;+}+//-------------------------------------------------------------------------------------------------GameMessageDisposition GameConsoleTranslator::translateGameMessage( const GameMessage *msg ){if( TheGameConsole == NULL )return KEEP_MESSAGE;+ const Bool freeCamera = TheTacticalView && TheTacticalView->isFreeCamera();+ if( !freeCamera )+ theFreeCameraKeys = 0;+switch( msg->getType() ){case GameMessage::MSG_RAW_KEY_DOWN:@@ -712,10 +851,19 @@ GameMessageDisposition GameConsoleTranslator::translateGameMessage( const GameMeif( TheGameConsole->isOpen() ){+ // a flight key let go while the console had it would otherwise stay held+ if( freeCamera && theFreeCameraKeys != 0 )+ {+ theFreeCameraKeys = 0;+ TheTacticalView->setFreeCameraKeys( 0 );+ }TheGameConsole->handleKey( key, keyState );return DESTROY_MESSAGE;}+ if( freeCamera )+ return translateFreeCameraKey( key, keyState );+// Esc shuts the cheat panel rather than opening the quit menu: the press is eaten, and the// release shuts it so that release is not left to open the menu eitherif( key == KEY_ESC && TheGameConsole->isCheatPanelOpen() )@@ -730,9 +878,14 @@ GameMessageDisposition GameConsoleTranslator::translateGameMessage( const GameMe// the wheel carries no position, and the cursor's moves are everybody'scase GameMessage::MSG_RAW_MOUSE_POSITION:case GameMessage::MSG_RAW_MOUSE_WHEEL:- return KEEP_MESSAGE;+ return freeCamera ? DESTROY_MESSAGE : KEEP_MESSAGE;}+ // the freecam's mouse only turns the view (W3DView reads the pointer itself): no click selects,+ // orders or scrolls anything while it flies+ if( freeCamera && msg->getType() > GameMessage::MSG_RAW_MOUSE_BEGIN && msg->getType() < GameMessage::MSG_RAW_MOUSE_END )+ return DESTROY_MESSAGE;+// A press on the cheat panel is the panel's, and so is everything that button does until it is// let go, wherever the pointer has gone by then: nothing after this sees a press it never saw// start. A press that started off the panel is left alone to its release, so a drag box pulleddiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.hindex 074083ffb..e5768c51b 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h@@ -223,6 +223,7 @@ public:Bool isCliffCell(Real x, Real y); ///<return height and normal at given pointReal getMinHeight(void) const {return m_minHeight;} ///<return minimum height of entire terrainReal getMaxHeight(void) const {return m_maxHeight;} ///<return maximum height of entire terrain+ void getDrawnExtent(Region3D *extent); ///<everything the terrain draws, the border ring past the playable map included, lowest to highest groundReal getMaxCellHeight(Real x, Real y) const; ///< returns maximum height of the 4 cell corners.WorldHeightMap *getMap(void) {return m_map;} ///< returns object holding the heightmap samples - need this for fast access.Bool isClearLineOfSight(const Coord3D& pos, const Coord3D& posOther) const;diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.hindex 4ca87064a..ccd350476 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h@@ -238,9 +238,26 @@ public:virtual void setGuardBandBias( const Coord2D *gb ) { m_guardBandBias.x = gb->x; m_guardBandBias.y = gb->y; }+ virtual void setFreeCamera( Bool on );+ virtual Bool isFreeCamera( void ) const { return m_freeCamera; }+ virtual void setFreeCameraPose( const Coord3D *eye, Real heading, Real tilt );+ virtual void getFreeCameraPose( Coord3D *eye, Real *heading, Real *tilt ) const;+ virtual void setFreeCameraKeys( UnsignedInt keys ) { m_freeCameraKeys = keys; }+private:+ Bool m_freeCamera; ///< the console's freecam has the view+ Vector3 m_freeCameraEye;+ Real m_freeCameraHeading; ///< radians, 0 looks along +x+ Real m_freeCameraTilt; ///< radians, 0 is level, up positive+ UnsignedInt m_freeCameraKeys; ///< View::FreeCameraKeys held+ UnsignedInt m_freeCameraLastStep; ///< Clock_Milliseconds of the last flight step+ ICoord2D m_freeCameraMouse; ///< where the pointer was left after the last step+ Bool m_freeCameraMouseValid;+ void stepFreeCamera( void ); ///< fly and turn by what the keys and the mouse did since the last step+ void setFreeCameraTransform( void ); ///< the freecam's view, clip planes out to the far corner of the map+CameraClass *m_3DCamera; ///< camera representation for 3D sceneCameraClass *m_2DCamera; ///< camera for UI overlayed on top of 3D sceneenum FilterModes m_viewFilterMode;diff --git a/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/GameClient/Win32Mouse.h b/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/GameClient/Win32Mouse.hindex 26a467226..e48c030ba 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/GameClient/Win32Mouse.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/GameClient/Win32Mouse.h@@ -79,6 +79,7 @@ public:virtual void releaseCapture( void ); ///< release mouse capturevirtual void setVisibility(Bool visible);+ virtual Bool warpCursor( Int x, Int y );virtual Bool isCursorInWindow( void ) const { return m_cursorInWindow; }diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cppindex 3933184f4..0c08de680 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp@@ -1085,6 +1085,16 @@ void BaseHeightMapRenderObjClass::Get_Obj_Space_Bounding_Box(AABoxClass & box) ca volume enclosing things that can float above terrain.*///-------------------------------------------------------------------------------------------------+/** TerrainLogic::getExtent is the playable map from 0,0; the terrain draws every cell of the+ heightmap, the border ring around it too, and that is what the freecam can see. */+void BaseHeightMapRenderObjClass::getDrawnExtent(Region3D *extent)+{+ const Int border = m_map->getBorderSizeInline();+ extent->lo.set( -border * MAP_XY_FACTOR, -border * MAP_XY_FACTOR, m_minHeight );+ extent->hi.set( (m_map->getXExtent() - 1 - border) * MAP_XY_FACTOR,+ (m_map->getYExtent() - 1 - border) * MAP_XY_FACTOR, m_maxHeight );+}+Bool BaseHeightMapRenderObjClass::getMaximumVisibleBox(const FrustumClass &frustum, AABoxClass *box, Bool ignoreMaxHeight){//create a plane from the lowest point on the terraindiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cppindex 2b1184e74..0ce235fda 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp@@ -121,6 +121,15 @@ const Real cosAngleToCare = cos ((0.2 * PI) / 180.0); //1.5 degree difference#define SHADOW_MAP_SUN_DISTANCE 2000.0f#define SHADOW_MAP_NEAR_CLIP 10.0f#define SHADOW_MAP_FAR_CLIP 4000.0f+// The console's freecam can look across the whole map at once, so its box is the whole map rather+// than the ground around a look point, and the map is four times as wide to keep the texels about+// the size they are at the usual zoom: a 6000 unit map is a box about 8500 across, a unit a texel.+// 8192 square at 32 bits is 256 MB of video memory while the freecam flies; a device that refuses+// it gets the usual 2048 over the same box, coarser. Aircraft fly up to this far above the highest+// ground and still have to be inside the box's depth.+#define SHADOW_MAP_WHOLE_MAP_TEXELS 8192+#define SHADOW_MAP_WHOLE_MAP_HEADROOM 600.0f+#define SHADOW_MAP_WHOLE_MAP_DEPTH_MARGIN 200.0f// How far a surface has to be behind what the map holds before it counts as shadowed, how dark a// fully blocked pixel goes, and how far the filter reaches in texels. The first is the one that// decides between a surface shadowing itself in stripes and a shadow lifting off its own caster.@@ -3890,7 +3899,7 @@ struct SmokeCasterparticles nearest the camera's focus win, so a new fire on screen is never starved by old smokeat the edge. Every system with a particle in the map is marked, and those lose their blob;with the option off, or the map refused, none is. */-static void fillSmokeMap( const Matrix3D &sunTransform, const Vector3 &focus, Real halfWidth )+static void fillSmokeMap( const Matrix3D &sunTransform, const Vector3 &focus, Real halfWidth, Real farClip ){static std::vector<SmokeCaster> found; // kept: a burning base is thousands of particles every framestatic std::vector<Real> packed;@@ -3931,7 +3940,7 @@ static void fillSmokeMap( const Matrix3D &sunTransform, const Vector3 &focus, ReMatrix3D::Inverse_Transform_Vector( sunTransform, Vector3( pos->x, pos->y, pos->z ), &inSun );const Real reach = halfWidth + radius;if (inSun.X < -reach || inSun.X > reach || inSun.Y < -reach || inSun.Y > reach- || -inSun.Z < SHADOW_MAP_NEAR_CLIP - radius || -inSun.Z > SHADOW_MAP_FAR_CLIP + radius)+ || -inSun.Z < SHADOW_MAP_NEAR_CLIP - radius || -inSun.Z > farClip + radius)continue;SmokeCaster caster;@@ -4137,6 +4146,40 @@ static Real shadowMapHalfWidth( const CameraClass &sceneCamera, const Matrix3D &return held;}+/** The freecam's box: the whole map. Its middle at the lowest ground, and its eight corners at the+ lowest ground and at the highest plus aircraft headroom, taken into the sun's frame, give the half+ width and how far the box reaches toward the sun and away from it. The sun's seat is set back+ past the nearest corner and the far plane past the furthest, so nothing on the map falls out of+ the box's depth however low the sun is. */+static void wholeMapSunBox( const Vector3 &toSun, Vector3 *focus, Real *halfWidth, Real *sunDistance, Real *farClip )+{+ Region3D extent;+ TheTerrainRenderObject->getDrawnExtent( &extent ); // the border ring is drawn, so it takes shadows too+ const Real lowest = extent.lo.z;+ const Real highest = extent.hi.z + SHADOW_MAP_WHOLE_MAP_HEADROOM;+ focus->Set( (extent.lo.x + extent.hi.x) * 0.5f, (extent.lo.y + extent.hi.y) * 0.5f, lowest );++ Matrix3D sunAtFocus;+ sunAtFocus.Look_At( *focus + toSun, *focus, 0.0f );+ Real across = 0.0f;+ Real towardSun = 0.0f;+ Real awayFromSun = 0.0f;+ for (Int corner = 0; corner < 8; ++corner)+ {+ const Vector3 at( (corner & 1) ? extent.hi.x : extent.lo.x, (corner & 2) ? extent.hi.y : extent.lo.y,+ (corner & 4) ? highest : lowest );+ Vector3 inSun;+ Matrix3D::Inverse_Transform_Vector( sunAtFocus, at, &inSun );+ across = WWMath::Max( across, WWMath::Max( WWMath::Fabs( inSun.X ), WWMath::Fabs( inSun.Y ) ) );+ const Real along = Vector3::Dot_Product( at - *focus, toSun );+ towardSun = WWMath::Max( towardSun, along );+ awayFromSun = WWMath::Max( awayFromSun, -along );+ }+ *halfWidth = WWMath::Ceil( across / SHADOW_MAP_HALF_WIDTH_STEP ) * SHADOW_MAP_HALF_WIDTH_STEP;+ *sunDistance = towardSun + SHADOW_MAP_WHOLE_MAP_DEPTH_MARGIN + SHADOW_MAP_NEAR_CLIP;+ *farClip = *sunDistance + awayFromSun + SHADOW_MAP_WHOLE_MAP_DEPTH_MARGIN;+}+/** The sun's depth pass. The casters are the ones that cast a volume today, drawn again from thesun into a depth buffer nothing samples yet, so this phase can be proved on its own: with itoff the frame is what it was, and with it on the map has the world in it and the frame is@@ -4147,8 +4190,30 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera ){theShadowMapHoldsTheFrame = FALSE;- if (!TheGlobalData->m_shadowMap || m_shadowList == NULL || TheTacticalView == NULL- || !Direct3D11_Begin_Shadow_Map( SHADOW_MAP_TEXELS ))+ /* The freecam asks for a map four times as wide and makes do with the usual one if refused. A+ refusal is remembered until the freecam lands: asking again every frame released the usual+ map, failed the large one and made the usual one again, a texture rebuild a frame. */+ const Bool wholeMap = TheTacticalView != NULL && TheTacticalView->isFreeCamera();+ static Bool wholeMapRefused = FALSE;+ if (!wholeMap)+ wholeMapRefused = FALSE;+ UnsignedInt texels = SHADOW_MAP_TEXELS;+ Bool begun = FALSE;+ if (TheGlobalData->m_shadowMap && m_shadowList != NULL && TheTacticalView != NULL)+ {+ if (wholeMap && !wholeMapRefused && Direct3D11_Begin_Shadow_Map( SHADOW_MAP_WHOLE_MAP_TEXELS ))+ {+ texels = SHADOW_MAP_WHOLE_MAP_TEXELS;+ begun = TRUE;+ }+ else+ {+ if (wholeMap)+ wholeMapRefused = TRUE;+ begun = Direct3D11_Begin_Shadow_Map( SHADOW_MAP_TEXELS );+ }+ }+ if (!begun){//no Direct3D 11 device, or it refused the surface: the volumes keep the frame, no smoke is//read out of a map the last frame filled, and every cloud keeps its blob@@ -4168,44 +4233,53 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )tShadowStart = Clock_Ticks();#endif- Coord3D look;- TheTacticalView->getPosition( &look );- const Vector3 focus( look.x, look.y, TheTerrainLogic->getGroundHeight( look.x, look.y ) );-Vector3 toSun = TheW3DShadowManager->getLightPosWorld( 0 );toSun.Normalize();+ Vector3 focus;+ Real halfWidth;+ Real sunDistance = SHADOW_MAP_SUN_DISTANCE;+ Real farClip = SHADOW_MAP_FAR_CLIP;Matrix3D transform;- transform.Look_At( focus + toSun * SHADOW_MAP_SUN_DISTANCE, focus, 0.0f );-const Real lowestReceiver = TheTerrainRenderObject->getMinHeight();- const Real halfWidth = shadowMapHalfWidth( sceneCamera, transform, lowestReceiver,- TheTerrainRenderObject->getMaxHeight() );+ if (wholeMap)+ {+ wholeMapSunBox( toSun, &focus, &halfWidth, &sunDistance, &farClip );+ transform.Look_At( focus + toSun * sunDistance, focus, 0.0f );+ }+ else+ {+ Coord3D look;+ TheTacticalView->getPosition( &look );+ focus.Set( look.x, look.y, TheTerrainLogic->getGroundHeight( look.x, look.y ) );+ transform.Look_At( focus + toSun * sunDistance, focus, 0.0f );+ halfWidth = shadowMapHalfWidth( sceneCamera, transform, lowestReceiver,+ TheTerrainRenderObject->getMaxHeight() );+ }CameraClass sun;sun.Set_Projection_Type( CameraClass::ORTHO );sun.Set_View_Plane( Vector2( -halfWidth, -halfWidth ), Vector2( halfWidth, halfWidth ) );- sun.Set_Clip_Planes( SHADOW_MAP_NEAR_CLIP, SHADOW_MAP_FAR_CLIP );+ sun.Set_Clip_Planes( SHADOW_MAP_NEAR_CLIP, farClip );/* The box has to sit on whole texels of its own map, or every scroll of the camera slides thegrid under the world by a fraction of a texel and every shadow edge crawls and sparkles. Thelook point is taken into the sun's own frame, rounded to the texel it lands in, and taken backout: the box then moves in texel steps and a shadow that did not move does not shimmer. */- const Real texelWidth = (2.0f * halfWidth) / (Real)SHADOW_MAP_TEXELS;+ const Real texelWidth = (2.0f * halfWidth) / (Real)texels;Vector3 focusInSun;Matrix3D::Inverse_Transform_Vector( transform, focus, &focusInSun );focusInSun.X = WWMath::Floor( focusInSun.X / texelWidth + 0.5f ) * texelWidth;focusInSun.Y = WWMath::Floor( focusInSun.Y / texelWidth + 0.5f ) * texelWidth;Vector3 snapped;Matrix3D::Transform_Vector( transform, focusInSun, &snapped );- transform.Look_At( snapped + toSun * SHADOW_MAP_SUN_DISTANCE, snapped, 0.0f );+ transform.Look_At( snapped + toSun * sunDistance, snapped, 0.0f );sun.Set_Transform( transform );Matrix4x4 projection;sun.Get_D3D_Projection_Matrix( &projection );- DX8Wrapper::Set_Projection_Transform_With_Z_Bias( projection, SHADOW_MAP_NEAR_CLIP,- SHADOW_MAP_FAR_CLIP );+ DX8Wrapper::Set_Projection_Transform_With_Z_Bias( projection, SHADOW_MAP_NEAR_CLIP, farClip );Matrix3D view;transform.Get_Orthogonal_Inverse( view );DX8Wrapper::Set_Transform( D3DTS_VIEW, view );@@ -4233,8 +4307,9 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )/* The filter's limits were chosen in texels of the 900 box. Held at the same width on the groundas the box opens, a tank's edge stays as hard and a helicopter's shadow as pale from full height- as it does at the usual one; counted in texels they would both spread with the zoom. */- const Real texelsPerBoxTexel = SHADOW_MAP_HALF_WIDTH / halfWidth;+ as it does at the usual one; counted in texels they would both spread with the zoom. The+ freecam's larger map is the same rule: it is the width of a texel on the ground that counts. */+ const Real texelsPerBoxTexel = (2.0f * SHADOW_MAP_HALF_WIDTH / (Real)SHADOW_MAP_TEXELS) / texelWidth;const Real widest = texelsPerBoxTexel * ((TheGlobalData->m_shadowMapWidest > 0.0f)? TheGlobalData->m_shadowMapWidest : SHADOW_MAP_WIDEST_TEXELS);const Real narrowest = texelsPerBoxTexel * SHADOW_MAP_NARROWEST_TEXELS;@@ -4326,7 +4401,9 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )Direct3D11_End_Shadow_Map();// The smoke goes into a map of its own through the sun the casters were just drawn with.- fillSmokeMap( transform, focus, halfWidth );+ // past the map's limit the smoke nearest the camera wins: the freecam's box is centred on the+ // map's middle, which is not where it is looking from+ fillSmokeMap( transform, wholeMap ? sceneCamera.Get_Position() : focus, halfWidth, farClip );// The frame's own camera, put back: the view, the projection and the viewport all went with the// sun. Without this everything drawn after the pass is drawn from the sun's seat, which is the@@ -4353,7 +4430,13 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )many world units across, and a unit of depth is the whole of the near to far range, becausean orthographic projection puts depth on a straight line. */const Real worldPerTexel = texelWidth;- const Real unitsPerUnitOfDepth = SHADOW_MAP_FAR_CLIP - SHADOW_MAP_NEAR_CLIP;+ const Real unitsPerUnitOfDepth = farClip - SHADOW_MAP_NEAR_CLIP;+ /* The bias is a share of that range, picked for the usual 3990 units. The freecam's deeper box+ would stretch it to tens of units and lift every shadow off its caster, so it is held at the+ same distance in the world: six units. */+ const Real depthBias = wholeMap+ ? SHADOW_MAP_DEPTH_BIAS * (SHADOW_MAP_FAR_CLIP - SHADOW_MAP_NEAR_CLIP) / unitsPerUnitOfDepth+ : SHADOW_MAP_DEPTH_BIAS;// -shadowtune overrules any of the four that it was given; a zero leaves the build's own.const Real penumbra = (TheGlobalData->m_shadowMapPenumbra > 0.0f)@@ -4363,7 +4446,7 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )const Real strength = (TheGlobalData->m_shadowMapStrength > 0.0f)? TheGlobalData->m_shadowMapStrength : SHADOW_MAP_STRENGTH;- Direct3D11_Set_Shadow_Parameters( SHADOW_MAP_DEPTH_BIAS, strength, widest,+ Direct3D11_Set_Shadow_Parameters( depthBias, strength, widest,narrowest, penumbra / worldPerTexel, unitsPerUnitOfDepth, skyFill );/* Said last, and only on the way out: everything above can bail, and the volumes have to knowdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex e67c64f40..5f6c519b6 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -60,7 +60,10 @@#include "GameClient/CommandXlat.h"#include "GameClient/Drawable.h"#include "GameClient/GameClient.h"+#include "GameClient/GameConsole.h"#include "GameClient/GameWindowManager.h"+#include "GameClient/Keyboard.h"+#include "GameClient/Mouse.h"#include "GameClient/Image.h"#include "GameClient/InGameUI.h"#include "GameClient/Line2D.h"@@ -209,6 +212,15 @@ W3DView::W3DView()m_zoomAnchorTerrainHeight = 0.0f;m_scrollWheelHeight = 0.0f;+ m_freeCamera = FALSE;+ m_freeCameraEye.Set( 0.0f, 0.0f, 0.0f );+ m_freeCameraHeading = 0.0f;+ m_freeCameraTilt = 0.0f;+ m_freeCameraKeys = 0;+ m_freeCameraLastStep = 0;+ m_freeCameraMouse.x = m_freeCameraMouse.y = 0;+ m_freeCameraMouseValid = FALSE;+} // end W3DView//-------------------------------------------------------------------------------------------------@@ -858,6 +870,12 @@ Bool W3DView::wantsIsometric( void ) constvoid W3DView::setCameraTransform( void ){m_cameraHasMovedSinceRequest = true;+ if (m_freeCamera)+ {+ // every setter that dirties the player's camera ends here, and none of them owns the view now+ setFreeCameraTransform();+ return;+ }Matrix3D cameraTransform( 1 );Real nearZ, farZ;@@ -963,6 +981,170 @@ void W3DView::setCameraTransform( void )TheRadar->notifyViewChanged();}+//-------------------------------------------------------------------------------------------------+// The freecam. A map cell is ten units, so a 300 cell map is 3000 across and the plain speed+// crosses it in seven and a half seconds; Shift is four times that.+static const Real FREECAM_SPEED = 400.0f; ///< world units a second+static const Real FREECAM_FAST = 4.0f;+static const Real FREECAM_TURN_PER_PIXEL = 0.0025f; ///< radians of heading or tilt per pixel of mouse+// Look_At has no up straight up or straight down; half a degree short of either is the only limit+static const Real FREECAM_STEEPEST = DEG_TO_RADF( 89.5f );+// past the far corner of the map, for whatever stands on the edge or flies beyond it+static const Real FREECAM_FAR_MARGIN = 1000.0f;++static Real freeCameraTilt( Real tilt )+{+ return WWMath::Clamp( tilt, -FREECAM_STEEPEST, FREECAM_STEEPEST );+}++static Vector3 freeCameraForward( Real heading, Real tilt )+{+ const Real level = cos( tilt );+ return Vector3( level * cos( heading ), level * sin( heading ), sin( tilt ) );+}++//-------------------------------------------------------------------------------------------------+void W3DView::setFreeCamera( Bool on )+{+ if (on == m_freeCamera)+ return;++ if (on)+ {+ // take off from where the player's camera is, looking where it looks (a W3D camera looks down -Z)+ const Matrix3D &transform = m_3DCamera->Get_Transform();+ const Vector3 forward = -transform.Get_Z_Vector();+ m_freeCameraEye = transform.Get_Translation();+ m_freeCameraHeading = atan2( forward.Y, forward.X );+ m_freeCameraTilt = freeCameraTilt( asin( WWMath::Clamp( forward.Z, -1.0f, 1.0f ) ) );+ }+ else if (TheMouse)+ {+ TheMouse->setVisibility( TRUE );+ }++ m_freeCamera = on;+ m_freeCameraKeys = 0;+ m_freeCameraMouseValid = FALSE;+ m_freeCameraLastStep = Clock_Milliseconds();+ // leaving, the player's camera is rebuilt from its look point, which never moved+ setCameraTransform();+}++//-------------------------------------------------------------------------------------------------+void W3DView::setFreeCameraPose( const Coord3D *eye, Real heading, Real tilt )+{+ m_freeCameraEye.Set( eye->x, eye->y, eye->z );+ m_freeCameraHeading = heading;+ m_freeCameraTilt = freeCameraTilt( tilt );+ if (m_freeCamera)+ setFreeCameraTransform();+}++//-------------------------------------------------------------------------------------------------+void W3DView::getFreeCameraPose( Coord3D *eye, Real *heading, Real *tilt ) const+{+ eye->set( m_freeCameraEye.X, m_freeCameraEye.Y, m_freeCameraEye.Z );+ *heading = m_freeCameraHeading;+ *tilt = m_freeCameraTilt;+}++//-------------------------------------------------------------------------------------------------+/** One render frame of flight. The mouse turns the view with no button held: the pointer is put+ * back in the middle of the view after every step, so it never stops at a screen edge, and it is+ * hidden. Only Win32Mouse can move the pointer so far, so on SDL the mouse does not turn the+ * freecam yet (ponytail: SdlMouse::warpCursor through SDL_WarpMouseInWindow would add it).+ * While the console is open the pointer and the keys are the console's. */+//-------------------------------------------------------------------------------------------------+void W3DView::stepFreeCamera( void )+{+ const UnsignedInt now = Clock_Milliseconds();+ Real seconds = (Real)(now - m_freeCameraLastStep) * 0.001f;+ m_freeCameraLastStep = now;+ if (seconds > 0.1f)+ seconds = 0.1f; // a hitch is not a reason to jump across the map++ const Bool consoleOpen = TheGameConsole && TheGameConsole->isOpen();+ if (TheMouse && !consoleOpen)+ {+ const ICoord2D pos = TheMouse->getMouseStatus()->pos;+ if (m_freeCameraMouseValid)+ {+ m_freeCameraHeading -= (Real)(pos.x - m_freeCameraMouse.x) * FREECAM_TURN_PER_PIXEL;+ m_freeCameraTilt = freeCameraTilt( m_freeCameraTilt - (Real)(pos.y - m_freeCameraMouse.y) * FREECAM_TURN_PER_PIXEL );+ m_freeCameraHeading = WWMath::Wrap( m_freeCameraHeading, (Real)-PI, (Real)PI );+ }+ ICoord2D middle;+ middle.x = m_originX + m_width / 2;+ middle.y = m_originY + m_height / 2;+ // a step that could not put the pointer back turns nothing next time either: the pointer is+ // another window's while ours is not in front, and whatever it did there is not a turn+ m_freeCameraMouse = middle;+ m_freeCameraMouseValid = TheMouse->warpCursor( middle.x, middle.y );+ if (TheMouse->getVisibility())+ TheMouse->setVisibility( FALSE );+ }+ else+ {+ m_freeCameraMouseValid = FALSE;+ if (TheMouse && !TheMouse->getVisibility())+ TheMouse->setVisibility( TRUE );+ }++ const Vector3 forward = freeCameraForward( m_freeCameraHeading, m_freeCameraTilt );+ const Vector3 right( sin( m_freeCameraHeading ), -cos( m_freeCameraHeading ), 0.0f );+ const Vector3 up( 0.0f, 0.0f, 1.0f );+ Vector3 move( 0.0f, 0.0f, 0.0f );+ const UnsignedInt keys = consoleOpen ? 0 : m_freeCameraKeys;+ if (keys & FREECAM_FORWARD) move += forward;+ if (keys & FREECAM_BACK) move -= forward;+ if (keys & FREECAM_RIGHT) move += right;+ if (keys & FREECAM_LEFT) move -= right;+ if (keys & FREECAM_UP) move += up;+ if (keys & FREECAM_DOWN) move -= up;+ const Real speed = FREECAM_SPEED * ((TheKeyboard && TheKeyboard->isShift()) ? FREECAM_FAST : 1.0f);+ m_freeCameraEye += move * (speed * seconds);+}++//-------------------------------------------------------------------------------------------------+/** The freecam's camera. The far plane reaches the furthest corner of the map from wherever the+ * eye is, so the whole map draws to its edges: every terrain, tree, water, particle and shadow+ * cull in the renderer is a test against this frustum, and the terrain itself is the whole map+ * on every map. The perspective lens is the player's, never the isometric one. */+//-------------------------------------------------------------------------------------------------+void W3DView::setFreeCameraTransform( void )+{+ Matrix3D transform( 1 );+ transform.Look_At( m_freeCameraEye, m_freeCameraEye + freeCameraForward( m_freeCameraHeading, m_freeCameraTilt ), 0.0f );++ Real farthest = 0.0f;+ if (TheTerrainRenderObject)+ {+ Region3D extent;+ TheTerrainRenderObject->getDrawnExtent( &extent );+ for (Int corner = 0; corner < 8; ++corner)+ {+ const Vector3 at( (corner & 1) ? extent.hi.x : extent.lo.x, (corner & 2) ? extent.hi.y : extent.lo.y,+ (corner & 4) ? extent.hi.z : extent.lo.z );+ farthest = WWMath::Max( farthest, (at - m_freeCameraEye).Length() );+ }+ }+ m_3DCamera->Set_Clip_Planes( MAP_XY_FACTOR, farthest + FREECAM_FAR_MARGIN );+ m_3DCamera->Set_View_Plane( perspectiveHorizontalFov( getWidth() ), -1 );+ m_isometricApplied = false;+ m_3DCamera->Set_Transform( transform );++ if (TheTerrainRenderObject)+ {+ RefRenderObjListIterator *it = W3DDisplay::m_3DScene->createLightsIterator();+ TheTerrainRenderObject->updateCenter( m_3DCamera, it );+ if (it)+ W3DDisplay::m_3DScene->destroyLightsIterator( it );+ }+ if (TheRadar)+ TheRadar->notifyViewChanged();+}+//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------void W3DView::init( void )@@ -1015,6 +1197,15 @@ void W3DView::reset( void ){View::reset();+ // a match that ends in the freecam leaves it there; the next one starts on the player's camera+ if (m_freeCamera)+ {+ m_freeCamera = FALSE;+ m_freeCameraKeys = 0;+ if (TheMouse)+ TheMouse->setVisibility( TRUE );+ }+// Just in case...setTimeMultiplier(1); // Set time rate back to 1.@@ -1495,6 +1686,29 @@ void W3DView::update(void)}}+ /* The freecam owns the view outright: no lock, no script, no shake, no height settle. The look+ point is left where it was, and every drawable on the map is updated, not just the ones under+ the player's frame, because the freecam can see the whole map at once. */+ if (m_freeCamera)+ {+ stepFreeCamera();+ setFreeCameraTransform();+ m_recalcCamera = false;+ if (TheScriptEngine->isTimeFast() || TheTerrainRenderObject == NULL)+ return;+ Region3D wholeMap;+ TheTerrainRenderObject->getDrawnExtent( &wholeMap );+ wholeMap.lo.x -= DRAWABLE_OVERSCAN;+ wholeMap.lo.y -= DRAWABLE_OVERSCAN;+ wholeMap.hi.x += DRAWABLE_OVERSCAN;+ wholeMap.hi.y += DRAWABLE_OVERSCAN;+ wholeMap.lo.z -= 999999.0f;+ wholeMap.hi.z += 999999.0f;+ if (WW3D::Get_Frame_Time())+ TheGameClient->iterateDrawablesInRegion( &wholeMap, drawDrawable, this );+ return;+ }+static Real followFactor = -1;ObjectID cameraLock = getCameraLock();if (cameraLock == INVALID_ID)diff --git a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cpp b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cppindex 00978e4cf..07dd62ac9 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cpp@@ -437,6 +437,19 @@ void Win32Mouse::setVisibility(Bool visible)Win32Mouse::setCursor(getMouseCursor());}+/** The freecam's mouse look puts the pointer back in the middle of the window every frame. Never+ while another window is in front: the pointer is that window's then. */+Bool Win32Mouse::warpCursor( Int x, Int y )+{+ if( ::GetForegroundWindow() != ApplicationHWnd )+ return FALSE;+ POINT screen = { x, y };+ if( !::ClientToScreen( ApplicationHWnd, &screen ) || !::SetCursorPos( screen.x, screen.y ) )+ return FALSE;+ setPosition( x, y );+ return TRUE;+}+/**Preload all the cursors we may need during the game. This must be done before the D3D deviceis created to avoid cursor corruption on buggy ATI Radeon cards. */void Win32Mouse::initCursorResources(void)diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cppindex def24a3d7..ad06a8939 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp@@ -484,13 +484,26 @@ void DX11BackendClass::Shutdown()/** The sun's depth buffer. One surface with two views of it, because a depth buffer that is alsosampled cannot be made as a depth format: the surface is typeless and each view says how its- bits are to be read. Made at the first size asked for and kept at that size. */+ bits are to be read. Made at the size asked for and kept while that is what is asked for; the+ console's freecam asks for a larger one over the whole map, and the surface is made again at+ whichever size the frame wants. The views are dropped with it; a draw that still has the old+ texture view bound holds its own reference until the unbind below. */bool DX11BackendClass::Begin_Shadow_Map(unsigned size){if (Device == NULL || size == 0 || ShadowMapBound) {return false;}+ if (ShadowMapSurface != NULL && ShadowMapSize != size) {+ ShadowMapTexture->Release();+ ShadowMapTexture = NULL;+ ShadowMapDepth->Release();+ ShadowMapDepth = NULL;+ ShadowMapSurface->Release();+ ShadowMapSurface = NULL;+ ShadowMapSize = 0;+ }+if (ShadowMapSurface == NULL) {D3D11_TEXTURE2D_DESC description;memset(&description, 0, sizeof(description));