Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(w3ddevice): hold zoom to cursor in the view, put it back in the menu

Olcay Seygan154784d91cc8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1e1155611..a7c726437 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -537,7 +537,7 @@ found and fixed — EA's own, not port damage.**
- The tab you are on is lit in the same green as the group headings. The original drew it in dark grey on the black panel, which read as a button you could not press rather than the page you were looking at.
- Accept sits in the bottom right corner with Cancel beside it, and Defaults stands alone on the far left, out of reach of a slip off Accept. The window is as tall as its busiest page and centred on the screen, instead of reaching from the top of the screen to the bottom with half of every page empty.
- Eight settings that used to need a text editor have a control now: window mode on display, antialiasing, the two glow settings, texture filtering and anisotropic samples on graphics, and who wears a health bar and which colours the players wear on gameplay.
-- Twelve more are decided for you instead of asked about. Grid placement, nudging a blocked building, 45 degree building rotation, the placement range ring, workers going back to supply, detailed build tooltips, the HUD overlay and archived replays are simply on - every one of them is the version of the game people were choosing anyway, and a page of eight checkboxes nobody unticks is a page of eight decisions nobody wanted to make. Middle-mouse panning, zoom to cursor, edge scrolling in a window and 45 degree camera steps left the screen too; those four are still yours by name in `Options.ini` if the defaults are wrong for your setup.
+- Twelve more are decided for you instead of asked about. Grid placement, nudging a blocked building, 45 degree building rotation, the placement range ring, workers going back to supply, detailed build tooltips, the HUD overlay and archived replays are simply on - every one of them is the version of the game people were choosing anyway, and a page of eight checkboxes nobody unticks is a page of eight decisions nobody wanted to make. Middle-mouse panning left the screen too, and edge scrolling in a window and 45 degree camera steps are still yours by name in `Options.ini` if the defaults are wrong for your setup.
- A page no longer says its own name twice. Every tab used to open onto a heading repeating the word already written on the button you just pressed, with a rule under it dividing nothing from nothing.
- An open dropdown covers what is under it instead of the other way round. The list of resolutions grew downwards behind the labels below it, so half the entries were readable and half were words on top of words.
- Every button, slider and checkbox is the artwork the game already had, down to the fonts and the hover colours.- Writing a line into `Options.ini` by hand still works, and the screen shows you what is in there when it opens. Window mode takes effect the moment you accept it; antialiasing applies the next time the display device resets.
@@ -587,6 +587,7 @@ found and fixed — EA's own, not port damage.**
- The command bar's artwork moves with the command bar. Minimising it slid the buttons off the bottom of the screen and left the metal they sit on painted over the battlefield; the same painting stood still through the slide the bar makes when a match opens. It travels with the bar and goes with it.
- Play it the way it shipped. Options > Controls has a Mouse and Keyboard box with two answers. Modern is this game as it is now. Legacy is the 2003 game: left click selects and orders, right click deselects, a right drag scrolls the map, a middle drag turns the camera, and the command bar answers the game's own letter for each button, painted in the button's corner the way the grid keys are. Holding Ctrl makes a click force fire, at the ground or at your own units. Those letters are the English game's even when the words are Turkish: the translation marks every label's first letter, which would have put K on three GLA structures and S on five. The promotion screen's number keys and the general's power keys are this game's additions, so under Legacy their labels are gone and the number keys pick your groups again. Every key comes from the game's own key map, so the grid keys, the two-key structures, Alt+Z signals, Ctrl+Z barracks, Tab, box select filters, formation lines, zoom to cursor and clickable health bars all stand down. It changes the moment you press Accept, even in the middle of a match, and it only changes your own screen.
- The lines from your selection to where it is headed can be switched off. Options > Gameplay has an Order Lines box, on by default. Off, a selected unit shows no line to its goal and none through its queue, but the marker on every point it is headed for stays, so an attack move or a string of waypoints is still there to see. The line you draw while dragging a formation still shows, because that one is the order being given. It changes the moment you press Accept.
+- Zoom to cursor is a box on Options > Controls again, on by default, for anyone who would rather the wheel zoomed on the middle of the screen. It also stopped fighting you. The camera corrected itself a frame after each step of the zoom, so the ground slid off the cursor and was pulled back the whole way in, and the last pull landed after the zoom had finished, as a small jump towards the cursor. And a wheel spun over a spot with no ground under it, out past the edge of the map, threw the camera to the corner of the map. The ground under the cursor stays under it on every frame now, and a spot with no ground zooms on the middle of the screen.
- Click through the command bar wherever its metal is not. The bar is three shaped plates with sloped tops and cut corners, but it caught clicks over the whole rectangle each plate sits in, so a unit standing in the sky above the radar's slope, or in the notch beside the command grid, could not be clicked or ordered to. Between 3 and 22 percent of each plate's rectangle is empty, depending on the side and the panel. Those parts belong to the battlefield now, and the buttons and metal still take every click they did.
- Drag the camera across the radar. Press on the radar and keep the button down, and the camera follows the cursor over the map until you let go; before, it jumped once per click, so crossing the map meant clicking your way over it. The button that moves the camera with a click is the one that drags it, left under Modern and right under Legacy, and with nothing selected either one does. Run the left button off the side of the radar and the camera waits at the edge of the map. It keeps following while the arrow keys are scrolling too, which used to leave the drag dead until the key came up. A selection box dragged onto the radar from the battlefield leaves the camera where it is.
- Widescreen resolutions are back in the options menu, and the list works during a match. It was greyed out the moment a game started, because changing it rebuilt the menus and then pushed the main menu over whatever you were playing. It rebuilds the menus for later and leaves you on the battlefield with the command bar back up.
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 5fa98e19b..a0facc695 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -623,7 +623,7 @@ GUI:ZoomToCursor
END
TOOLTIP:ZoomToCursor
-"The wheel zooms towards whatever the cursor is over instead of the middle of the screen."
+"The wheel zooms towards whatever the cursor is over instead of the middle of the screen. Modern controls only."
END
GUI:EdgeScrollWindowed
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index bf664a89f..487a5d887 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15194,7 +15194,7 @@ GUI:ZoomToCursor
END
TOOLTIP:ZoomToCursor
-"Tekerlek, ekranın ortası yerine imlecin üzerinde durduğu yere doğru yakınlaştırır."
+"Tekerlek, ekranın ortası yerine imlecin üzerinde durduğu yere doğru yakınlaştırır. Yalnızca Modern kontrollerde."
END
GUI:EdgeScrollWindowed
diff --git a/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd b/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd
index bd3b165df..7a2ec17ff 100644
--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd
+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd
@@ -5831,6 +5831,53 @@ WINDOW
IMAGE: NoImage, COLOR: 255 255 255 255, BORDERCOLOR: 255 255 255 255;
END
CHILD
+ WINDOW
+ WINDOWTYPE = CHECKBOX;
+ SCREENRECT = UPPERLEFT: 40 238, BOTTOMRIGHT: 264 262, CREATIONRESOLUTION: 800 600;
+ NAME = "OptionsMenu.wnd:CheckZoomToCursor";
+ STATUS = ENABLED+IMAGE+BORDER;
+ STYLE = CHECKBOX+MOUSETRACK;
+ SYSTEMCALLBACK = "[None]";
+ INPUTCALLBACK = "[None]";
+ TOOLTIPCALLBACK = "[None]";
+ DRAWCALLBACK = "[None]";
+ FONT = NAME: "Arial", SIZE: 14, BOLD: 0;
+ HEADERTEMPLATE = "MinorTitle";
+ TOOLTIPTEXT = "TOOLTIP:ZoomToCursor";
+ TOOLTIPDELAY = -1;
+ TEXT = "GUI:ZoomToCursor";
+ TEXTCOLOR = ENABLED: 255 255 255 255, ENABLEDBORDER: 0 0 0 255,
+ DISABLED: 192 192 192 255, DISABLEDBORDER: 64 64 64 255,
+ HILITE: 186 255 12 255, HILITEBORDER: 0 0 0 255;
+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,
+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,
+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ END
+ CHILD
WINDOW
WINDOWTYPE = STATICTEXT;
SCREENRECT = UPPERLEFT: 282 150, BOTTOMRIGHT: 506 174, CREATIONRESOLUTION: 800 600;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h
index ba9e67399..f2e286cfc 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h
@@ -47,24 +47,7 @@ public:
void resetModes(); //Used when disabling input, so when we reenable it we aren't stuck in a mode.
private:
- //
- // ZoomToCursor: the wheel only moves the camera's *desired* height, and W3DView::update eases
- // the real zoom towards it over the frames that follow, so the world point under the cursor is
- // held in place by re-measuring it every frame for as long as that easing lasts.
- //
enum
- {
- ZOOM_ANCHOR_MAX_TICKS = 240, ///< hard budget, so a stalled camera cannot pin the view forever
- ZOOM_ANCHOR_GRACE_TICKS = 4 ///< ticks before a still zoom is allowed to end the pin
- };
- void updateZoomToCursor( void ); ///< keep the anchored world point under its pixel
- Bool m_zoomAnchorValid; ///< a wheel zoom is being followed
- ICoord2D m_zoomAnchorPixel; ///< the pixel the wheel was spun over
- Coord3D m_zoomAnchorWorld; ///< the terrain point that has to stay under it
- Real m_zoomAnchorZoom; ///< last zoom seen, to tell whether the camera is still easing
- Int m_zoomAnchorTicks; ///< ticks left in the budget
-
- enum
{
MAX_VIEW_LOCS = 8
};
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
index 6b4ae4854..5fcfe0c3e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
@@ -185,6 +185,7 @@ public:
virtual void setHeightAboveGround(Real z) { m_heightAboveGround = z; }
virtual void zoomIn( Real steps = 1.0f ); ///< Zoom in, closer to the ground, limit to min
virtual void zoomOut( Real steps = 1.0f ); ///< Zoom out, farther away from the ground, limit to max
+ virtual void anchorZoomAt( const ICoord2D *pixel ) { } ///< ZoomToCursor: hold the ground under this pixel there while the zoom settles
virtual void setZoomToDefault( void ) { } ///< Set zoom to default value
virtual void setZoomToMax( void ) { } ///< Set zoom as far out as the player may zoom by hand
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
index 54c3fdd00..a79b82b15 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -170,7 +170,7 @@ const OptionDef TheOptionCatalog[] =
{
// iniKey, widgetName, labelKey, kind, apply, lo, hi, get, set
- // The four camera and mouse habits below have no control in OptionsMenu.wnd any more. They are
+ // The camera and mouse habits below have no control in OptionsMenu.wnd any more. They are
// not gone: an empty widgetName only makes the menu passes skip the row, so Options.ini still
// loads, clamps and saves each one and a player who wants the old behaviour can put the key
// back by hand. The defaults in GlobalData are what everybody else gets.
@@ -196,7 +196,10 @@ const OptionDef TheOptionCatalog[] =
// MiddleMousePans used to sit here. The middle button is the only camera drag there is now, so
// there is nothing left to choose: it pans, and Ctrl turns the same drag into a rotate.
- { "ZoomToCursor", "", "",
+
+ // Back on Options > Controls: players split on whether the wheel should chase the cursor, and
+ // Legacy zooms on the middle of the screen whatever this says.
+ { "ZoomToCursor", OPT_WND( "CheckZoomToCursor" ), "GUI:ZoomToCursor",
OPTION_BOOL, APPLY_LIVE, 0, 1,
get_m_zoomToCursor, set_m_zoomToCursor },
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
index cd93d89ea..6936ec022 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
@@ -114,14 +114,8 @@ LookAtTranslator::LookAtTranslator() :
m_timestamp(0),
m_lastPlaneID(INVALID_DRAWABLE_ID),
m_lastMouseMoveFrame(0),
- m_scrollType(SCROLL_NONE),
- m_zoomAnchorValid(FALSE),
- m_zoomAnchorZoom(0.0f),
- m_zoomAnchorTicks(0)
+ m_scrollType(SCROLL_NONE)
{
- m_zoomAnchorPixel.x = m_zoomAnchorPixel.y = 0;
- m_zoomAnchorWorld.zero();
-
//Added By Sadullah Nader
//Initializations misssing and needed
m_anchor.x = m_anchor.y = 0;
@@ -165,65 +159,6 @@ void LookAtTranslator::setCurrentPos( const ICoord2D& pos )
m_currentPos = pos;
}
-//-----------------------------------------------------------------------------
-/**
- * Keep the terrain point the wheel was spun over sitting under that same pixel while the camera
- * eases towards the zoom it was asked for. Re-measuring rather than projecting means the pin is
- * right at any pitch or field of view, and it converges: each frame's leftover error is the next
- * frame's correction. The pin ends when the zoom stops moving, when something else takes the
- * camera, or when its tick budget runs out.
- */
-void LookAtTranslator::updateZoomToCursor( void )
-{
- if (!m_zoomAnchorValid)
- return;
-
- // anything that moves the camera on purpose wins over the pin
- if (m_isScrolling || !TheInGameUI->getInputEnabled())
- {
- m_zoomAnchorValid = FALSE;
- return;
- }
-
- const Real zoom = TheTacticalView->getZoom();
- const Bool stillEasing = fabs( zoom - m_zoomAnchorZoom ) > 0.00001f;
- m_zoomAnchorZoom = zoom;
-
- Coord3D world;
- world.zero();
- TheTacticalView->screenToTerrain( &m_zoomAnchorPixel, &world );
-
- //
- // Move the camera by the world-space residual itself. scrollBy() is not the way to do it:
- // its delta is a *screen* delta that it pushes through Device_To_World_Space with a fixed
- // 250 unit resolution and then scales by frame time, so a world offset handed to it comes
- // out as some other distance entirely and the anchor never lands. lookAt is the exact move:
- // given a z on the ground it is a plain setPosition plus setCameraTransform, so the camera is
- // still clamped to the map the same way scrolling is.
- //
- const Real shiftX = m_zoomAnchorWorld.x - world.x;
- const Real shiftY = m_zoomAnchorWorld.y - world.y;
- if (shiftX != 0.0f || shiftY != 0.0f)
- {
- Coord3D pos;
- TheTacticalView->getPosition( &pos );
- pos.x += shiftX;
- pos.y += shiftY;
- pos.z = 0.0f;
- TheTacticalView->lookAt( &pos );
- }
-
- //
- // The first few ticks are a grace period: the wheel is handled in the message stream, which
- // runs before the view updates, so a zoom that has not started moving yet is not a zoom that
- // has finished.
- //
- const Bool grace = (m_zoomAnchorTicks > ZOOM_ANCHOR_MAX_TICKS - ZOOM_ANCHOR_GRACE_TICKS);
- if (--m_zoomAnchorTicks <= 0 || (!stillEasing && !grace))
- m_zoomAnchorValid = FALSE;
-
-} // end updateZoomToCursor
-
//-----------------------------------------------------------------------------
/**
* The LookAt Translator is responsible for camera movements. It is directly responsible for
@@ -486,25 +421,11 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
TheInGameUI->rotatePendingPlacement( rotateSteps ))
return DESTROY_MESSAGE;
- //
- // ZoomToCursor: remember the world point under the cursor and keep it there while the
- // camera moves. Measuring it again right after the zoom call - which is what this used
- // to do - always measured a camera that had not moved yet: zoomIn()/zoomOut() only
- // change the *desired* height above ground, and W3DView::update eases the actual zoom
- // towards it over the frames that follow. The shift therefore came out zero every time
- // and the feature did nothing at all. The anchor is now followed frame by frame in
- // updateZoomToCursor() for as long as that easing lasts, which also keeps it correct
- // whatever the pitch and the field of view are.
- //
+ // ZoomToCursor: the view holds the ground under the cursor while the zoom eases in. It does
+ // it inside its own update, between the zoom moving and the frame being drawn; held from
+ // here, the correction always landed a frame late.
if (TheGlobalData->m_zoomToCursor && !TheGlobalData->isLegacyInput() && TheInGameUI->getInputEnabled())
- {
- m_zoomAnchorPixel = msg->getArgument( 0 )->pixel;
- m_zoomAnchorWorld.zero();
- TheTacticalView->screenToTerrain( &m_zoomAnchorPixel, &m_zoomAnchorWorld );
- m_zoomAnchorZoom = TheTacticalView->getZoom();
- m_zoomAnchorTicks = ZOOM_ANCHOR_MAX_TICKS;
- m_zoomAnchorValid = TRUE;
- }
+ TheTacticalView->anchorZoomAt( &msg->getArgument( 0 )->pixel );
if (spin > 0.0f)
TheTacticalView->zoomIn( spin );
@@ -532,9 +453,6 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
{
Coord2D offset = {0, 0};
- // hold whatever the wheel was spun over under the cursor while the zoom eases
- updateZoomToCursor();
-
// If we've been forced to stop scrolling (script action?) then stop
if (m_isScrolling && !TheInGameUI->isScrolling())
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
index fcfec2e88..f621f4164 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
@@ -202,6 +202,7 @@ public:
virtual void setZoomToDefault( void ); ///< Set zoom to default value
virtual void setZoomToMax( void ); ///< Set zoom as far out as the player may zoom by hand
void setZoomToHeight( Real heightAboveGround ); ///< Frame the camera at this height above the terrain
+ virtual void anchorZoomAt( const ICoord2D *pixel );
virtual void setFieldOfView( Real angle ); ///< Set the horizontal field of view angle
@@ -286,6 +287,11 @@ private:
Bool m_cameraConstraintValid; ///< if f, recalc cam constraints
Bool m_recalcCamera; ///< if t, rebuild the camera transform in the next render update
+ Bool m_zoomAnchorValid; ///< a wheel zoom is holding the ground under the cursor
+ ICoord2D m_zoomAnchorPixel; ///< the pixel the wheel was spun over
+ Coord3D m_zoomAnchorWorld; ///< the ground that has to stay under it
+ void holdZoomAnchor( Bool zoomMoved ); ///< move the camera so the anchored ground is back under its pixel
+
Bool isDoingScriptedCamera( void ) const; ///< True while any scripted camera movement owns the view
void stopDoingScriptedCamera( void ); ///< Hand the view back to the user, whatever the script was doing
void setCameraTransform( void ); ///< set the transform matrix of m_3DCamera, based on m_pos & m_angle
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index 77dd66433..e9c0dcad4 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -194,6 +194,7 @@ W3DView::W3DView()
m_shakerAngles.Z =0.0f;
m_recalcCamera = false;
+ m_zoomAnchorValid = false;
} // end W3DView
@@ -1487,6 +1488,7 @@ void W3DView::update(void)
*/
m_terrainHeightUnderCamera = getHeightAroundPos(m_pos.x, m_pos.y);
m_currentHeightAboveGround = m_cameraOffset.z * m_zoom - m_terrainHeightUnderCamera;
+ const Real zoomBeforeSettle = m_zoom;
//
// The settle below is an exponential approach tuned for one 30Hz step. Gating it on
// stepTime made the zoom crawl in visible 30Hz jumps on a faster display; run it every
@@ -1538,6 +1540,8 @@ void W3DView::update(void)
}
}
}
+ if (m_zoomAnchorValid)
+ holdZoomAnchor( m_zoom != zoomBeforeSettle && !didScriptedMovement );
if (TheScriptEngine->isTimeFast()) {
return; // don't draw - makes it faster :) jba.
}
@@ -2241,6 +2245,7 @@ void W3DView::setHeightAboveGround(Real z)
void W3DView::setZoom(Real z)
{
View::setZoom(z);
+ m_zoomAnchorValid = false; // a saved view or a script set this zoom, not the wheel
stopDoingScriptedCamera();
m_cameraConstraintValid = false; // recalc it.
@@ -2684,11 +2689,58 @@ void W3DView::lookAt( const Coord3D *o )
pos.z = 0;
setPosition(&pos);
stopDoingScriptedCamera();
+ // a jump across the map mid-zoom goes where it was sent, not back to the ground the wheel was on
+ m_zoomAnchorValid = false;
m_recalcCamera = true;
}
+//-------------------------------------------------------------------------------------------------
+/** ZoomToCursor. The wheel only moves the height the camera settles towards, and update() eases the
+ * real zoom there over the frames that follow, so the ground the wheel was spun over is held under
+ * its pixel by holdZoomAnchor for as long as that easing lasts. A pixel over no ground has nothing
+ * to hold: screenToTerrain hands back the map corner for it, and holding that ran the camera off to
+ * the edge of the map. */
+//-------------------------------------------------------------------------------------------------
+void W3DView::anchorZoomAt( const ICoord2D *pixel )
+{
+ m_zoomAnchorPixel = *pixel;
+ m_zoomAnchorValid = screenToTerrain( pixel, &m_zoomAnchorWorld );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Runs inside update(), after the zoom has eased and before the frame's camera is built. The pin
+ * used to run in the message stream, after the frame was already drawn, so every frame showed the
+ * ground sliding off the cursor and the next one pulled it back; the last correction landed after
+ * the zoom had stopped and read as a snap towards the cursor. */
+//-------------------------------------------------------------------------------------------------
+void W3DView::holdZoomAnchor( Bool zoomMoved )
+{
+ if (!zoomMoved || TheInGameUI->isScrolling())
+ {
+ m_zoomAnchorValid = false;
+ return;
+ }
+
+ // a locked view builds no camera this frame, so a measurement would read the last frame's again
+ if (m_viewLockedUntilFrame > TheGameClient->getFrame())
+ return;
+
+ setCameraTransform();
+ Coord3D world;
+ if (!screenToTerrain( &m_zoomAnchorPixel, &world ))
+ {
+ m_zoomAnchorValid = false;
+ return;
+ }
+
+ Coord3D pos = *getPosition();
+ pos.x += m_zoomAnchorWorld.x - world.x;
+ pos.y += m_zoomAnchorWorld.y - world.y;
+ setPosition( &pos );
+}
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void W3DView::initHeightForMap( void )
diff --git a/GeneralsMD/Code/Tests/test_camera_behavior.inc b/GeneralsMD/Code/Tests/test_camera_behavior.inc
index d89bdf1e6..aae6ef027 100644
--- a/GeneralsMD/Code/Tests/test_camera_behavior.inc
+++ b/GeneralsMD/Code/Tests/test_camera_behavior.inc
@@ -56,7 +56,10 @@ public:
Coord3D terrainPoint = {0, 0, 0};
Int terrainPicks = 0;
Int lookAtCalls = 0;
+ Int zoomAnchors = 0;
+ ICoord2D zoomAnchor = {0, 0};
void lookAt(const Coord3D *pos) { ++lookAtCalls; setPosition(pos); }
+ void anchorZoomAt(const ICoord2D *pixel) { zoomAnchor = *pixel; ++zoomAnchors; }
void forceCameraConstraintRecalc() { ++constraintRecalcs; }
void scrollBy(Coord2D *delta) { last = *delta; ++samples; }
Drawable *pickDrawable(const ICoord2D*, Bool, PickType) { return NULL; }
@@ -184,3 +187,42 @@ TEST(camera_margin_preferences_load_and_rebuild_constraints)
CHECK_EQ(f.global->m_cameraBoundaryMargin, 300);
CHECK_EQ(f.view.constraintRecalcs, 1);
}
+
+TEST(camera_wheel_anchors_zoom_to_cursor_only_under_modern_with_the_box_ticked)
+{
+ // Pull request 5 asked for zoom to cursor to go; it stayed as a menu box instead.
+ const OptionDef *def = findOptionDef("ZoomToCursor");
+ CHECK(def != NULL);
+ if (def == NULL)
+ return;
+ CHECK(def->widgetName != NULL && def->widgetName[0] != '\0');
+ CHECK_EQ(def->apply, APPLY_LIVE);
+
+ CHECK(bootOnce());
+ CameraInputFixture f;
+ const ICoord2D cursor = {320, 240};
+ const Real zoomInOneNotch = 1.0f;
+ const auto spinWheel = [&f, &cursor, zoomInOneNotch]()
+ {
+ GameMessage *message = newInstance(GameMessage)(GameMessage::MSG_RAW_MOUSE_WHEEL);
+ message->appendPixelArgument(cursor);
+ message->appendRealArgument(zoomInOneNotch);
+ f.camera.translateGameMessage(message);
+ message->deleteInstance();
+ };
+
+ CHECK(f.global->m_zoomToCursor);
+ spinWheel();
+ CHECK_EQ(f.view.zoomAnchors, 1);
+ CHECK_EQ(f.view.zoomAnchor.x, cursor.x);
+ CHECK_EQ(f.view.zoomAnchor.y, cursor.y);
+
+ f.global->m_zoomToCursor = FALSE;
+ spinWheel();
+ CHECK_EQ(f.view.zoomAnchors, 1);
+
+ f.global->m_zoomToCursor = TRUE;
+ f.global->m_inputScheme = INPUT_SCHEME_LEGACY;
+ spinWheel();
+ CHECK_EQ(f.view.zoomAnchors, 1);
+}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index ba3facb5e..665b78b2e 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -10009,11 +10009,11 @@ TEST(gameplay_conveniences_are_forced_on_and_left_the_catalog)
CHECK( bars != NULL );
CHECK( bars->widgetName != NULL && bars->widgetName[ 0 ] != '\0' );
- /* The four camera and mouse habits went the other way: no control, but the row stays, so an
- Options.ini that names one still wins over the default. */
+ /* The camera and mouse habits went the other way: no control, but the row stays, so an
+ Options.ini that names one still wins over the default. ZoomToCursor came back to the menu. */
static const char *const hidden[] =
{
- "FormationDrag", "ZoomToCursor", "EdgeScrollInWindowedMode", "SnapCameraRotateTo45", NULL
+ "FormationDrag", "EdgeScrollInWindowedMode", "SnapCameraRotateTo45", NULL
};
for( Int i = 0; hidden[ i ] != NULL; ++i )
{