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(gameclient): pan pace follows the zoom, classic keeps the map margin

Olcay Seygan82a1ce28a3e9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 20505e597..28d2c6c87 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1089,7 +1089,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Display, graphics, effects, audio, controls, interface and network, behind seven buttons across the top. The original screen was one panel with everything on it at once, and it was already full the day it shipped: the language filter, the keyboard button and four camera checkboxes are all still in there, parked off the right edge where nobody can reach them, because there was nowhere left to put them.
- Every setting sits with the ones that do the same kind of job. Display is the screen and its brightness. Graphics is what the picture costs and how sharp it is, with the glow and the lighting in a group of their own instead of mixed in with the anti-aliasing. Effects is what stands in the world: all seven shadow boxes together, cloud shadows included, then the scenery, then smoke. Controls splits the camera, the orders, building placement and the mouse into four groups, and Interface holds the command bar size, the income readout, the health bars, the colours, the order lines and the language. In Classic the screen leaves out the twelve boxes Classic ignores anyway, from zoom to cursor and grid placement to the HUD size and the health bar choice, and closes the gaps they leave, so a box on that screen always does something.
- Classic Graphics, on the Graphics page, puts the game back the way it looked in 2003 in one click: its own textures and ground in place of the upscaled ones, the old hard shadows, the round dark patch under every tree where Reforged lays the tree's own outline on the ground, and no glow or sharpening over the picture. Leave it off and you have Reforged. The rest of the options stay yours either way, and the box takes effect the next time the game starts.
-- Interface, in the launcher, picks between Classic and Reforged. Classic is the command bar, mouse and hotkeys of Zero Hour 1.04 that your hands still remember; Reforged is the console in the middle, right-click orders and the key grid this version built. Every player starts on Classic, and a game started without the launcher is Classic too. The choice is yours alone: two players on different styles still play the same match and the same replay. It takes effect the next time the game starts. Classic's screen is EA's again: the one-piece command bar in each side's own painting, the radar with its flashing under-attack lamp, the beacon button, six lines of messages in the top left that fade as they did, superweapon countdowns written out by name, the old chat line and quit menu, lettering at the old sizes, and Tab opening diplomacy. On a 16:9 or 21:9 screen every menu outside a match sits in a 4:3 frame in the middle at its drawn shape, backdrop and border included, with black down both sides the way a 4:3 game looks on a wide monitor; in a match the options and save screens keep that 4:3 frame over the battlefield. The command bar runs edge to edge up to 16:9, as it always did. Past that, on 21:9 or 32:9, the match's own furniture keeps the 16:9 layout in the middle of the screen: the bar, your general's powers beside it, the build tooltip over it, the promotion screen, the superweapon countdowns, the messages, the chat line, the quit menu and diplomacy sit where a 16:9 screen has them, and the battlefield runs on past both ends, 320 pixels either side at 2560x1080. On 16:10 and anything wider the bar is one painted for 16:9, so it is not pulled out of shape the way EA's 4:3 one was: the radar and your selection sit at its two ends, the build grid has a longer field, the money box is in the middle and the power bar is nearly twice as long. A 4:3 or 5:4 screen keeps EA's bar as it was. The wide bar is the work of moddb_dev, from the "C&C Generals HD User Interface" mod on ModDB, itself built on pWn3d_1337's Operation Firestorm interface, and it is here with its author's permission. The mouse and keys are 1.04's as well. The left button selects and gives the order, so an enemy under it is an attack and a bunker under your infantry is a way in; the right button drops your selection or takes back a half-given order, and a right drag scrolls the map. Ctrl held is force fire. Alt held lays waypoints, and the white path joining them is drawn again. A guard order holds the range it always held, Shift and a number adds that group to what you have selected, and a build button is one unit a click. The keys are your language's own key map from the game's files, with nothing of Reforged's grid laid over it, and a build button's key is the letter 1.04 gave it, taken from the English name in every language, so a Turkish or German player presses the same key an English one does. The letter sits in the button's corner on the dark badge Reforged puts its grid keys on, in the middle of a square plate the same size for every letter, larger than Reforged's and in gold while the button can be pressed; the tooltip's name is plain white with no letter picked out. A structure is selected on its own, as it always was. The radar shows no money piles or tech buildings, and the clock plate, the frame counter and the experience bar under the portrait stay off the screen. So does the peace time plate, though a host's truce still holds. The money readout is the money alone, with no income figure beside it. Health bars and garrison squares look and behave as they do in Reforged, and the Health Bars and empty garrison squares settings are back on Classic's options page. The build buttons are the pictures alone, without the seconds, price and power figures. Those seconds were measured against the wall clock, so on a match running just under full speed a 120 second build read 125. An upgrade bought for a group of buildings goes to the one whose buttons you see. In a network game a Classic player's camera is not sent to observers, as it never was in 1.04. The camera zooms on the middle of the screen ten units a notch, as near and as far as Reforged's camera goes, turns without snapping, and scrolls from the last three pixels of a full screen and not at all in a window, whatever the options say. A move order puts 1.04's animated ring on the ground where it lands, and no marker or line stays behind it. None of it reaches the battle itself: Classic sends the game only the orders 1.04 sent, so a Classic player and a Reforged one share a match, and a replay plays back the same in either.
+- Interface, in the launcher, picks between Classic and Reforged. Classic is the command bar, mouse and hotkeys of Zero Hour 1.04 that your hands still remember; Reforged is the console in the middle, right-click orders and the key grid this version built. Every player starts on Classic, and a game started without the launcher is Classic too. The choice is yours alone: two players on different styles still play the same match and the same replay. It takes effect the next time the game starts. Classic's screen is EA's again: the one-piece command bar in each side's own painting, the radar with its flashing under-attack lamp, the beacon button, six lines of messages in the top left that fade as they did, superweapon countdowns written out by name, the old chat line and quit menu, lettering at the old sizes, and Tab opening diplomacy. On a 16:9 or 21:9 screen every menu outside a match sits in a 4:3 frame in the middle at its drawn shape, backdrop and border included, with black down both sides the way a 4:3 game looks on a wide monitor; in a match the options and save screens keep that 4:3 frame over the battlefield. The command bar runs edge to edge up to 16:9, as it always did. Past that, on 21:9 or 32:9, the match's own furniture keeps the 16:9 layout in the middle of the screen: the bar, your general's powers beside it, the build tooltip over it, the promotion screen, the superweapon countdowns, the messages, the chat line, the quit menu and diplomacy sit where a 16:9 screen has them, and the battlefield runs on past both ends, 320 pixels either side at 2560x1080. On 16:10 and anything wider the bar is one painted for 16:9, so it is not pulled out of shape the way EA's 4:3 one was: the radar and your selection sit at its two ends, the build grid has a longer field, the money box is in the middle and the power bar is nearly twice as long. A 4:3 or 5:4 screen keeps EA's bar as it was. The wide bar is the work of moddb_dev, from the "C&C Generals HD User Interface" mod on ModDB, itself built on pWn3d_1337's Operation Firestorm interface, and it is here with its author's permission. The mouse and keys are 1.04's as well. The left button selects and gives the order, so an enemy under it is an attack and a bunker under your infantry is a way in; the right button drops your selection or takes back a half-given order, and a right drag scrolls the map. Ctrl held is force fire. Alt held lays waypoints, and the white path joining them is drawn again. A guard order holds the range it always held, Shift and a number adds that group to what you have selected, and a build button is one unit a click. The keys are your language's own key map from the game's files, with nothing of Reforged's grid laid over it, and a build button's key is the letter 1.04 gave it, taken from the English name in every language, so a Turkish or German player presses the same key an English one does. The letter sits in the button's corner on the dark badge Reforged puts its grid keys on, in the middle of a square plate the same size for every letter, larger than Reforged's and in gold while the button can be pressed; the tooltip's name is plain white with no letter picked out. A structure is selected on its own, as it always was. The radar shows no money piles or tech buildings, and the clock plate, the frame counter and the experience bar under the portrait stay off the screen. So does the peace time plate, though a host's truce still holds. The money readout is the money alone, with no income figure beside it. Health bars and garrison squares look and behave as they do in Reforged, and the Health Bars and empty garrison squares settings are back on Classic's options page. The build buttons are the pictures alone, without the seconds, price and power figures. Those seconds were measured against the wall clock, so on a match running just under full speed a 120 second build read 125. An upgrade bought for a group of buildings goes to the one whose buttons you see. In a network game a Classic player's camera is not sent to observers, as it never was in 1.04. The camera zooms on the middle of the screen ten units a notch, as near and as far as Reforged's camera goes, turns without snapping, and scrolls from the last three pixels of a full screen and not at all in a window, whatever the options say. It runs past the edge of the map as far as Reforged's camera does, 200 units unless `CameraBoundaryMargin` says otherwise, so a base in a corner comes to the middle of the screen in either interface. A move order puts 1.04's animated ring on the ground where it lands, and no marker or line stays behind it. None of it reaches the battle itself: Classic sends the game only the orders 1.04 sent, so a Classic player and a Reforged one share a match, and a replay plays back the same in either.
- Classic shows what a factory is building again. Select one with anything queued and its queue takes the portrait's place, the unit in production wearing its build clock, and a click on any entry cancels it; the portrait comes back when the queue runs dry. Until now a Classic factory could queue a hundred units with nothing on screen to count them by. The queue stops at nine, the number of slots that show it, and the build buttons grey out at nine as they did in 1.04. Your general's powers climb the right edge of the screen from the top of the bar, one over the other, as they did in 1.04, and the empty strip above them no longer swallows clicks on the battlefield. They carry how many are ready, with no key letter and no recharge seconds, and the promotion screen carries no number keys either, since Classic's number keys pick teams. Every button on that screen takes its click again: the right half used to sit under the powers bar's empty frame and the bottom row under the command bar's top edge, and a click there went nowhere.
- Supply piles stop shouting their cash over the whole map. A small pile shows its amount only while your cursor is on it or close by, in a smaller font; a big supply dock keeps its label all the time. Classic has the same labels now, with the radar still leaving the piles off.
- The Esc menu and the general's promotion screen close the way they open, in both interfaces. Both used to vanish in a single frame, and Classic's Esc menu had lost its opening flash as well. Classic plays 1.04's flash and fade, forwards to open and backwards to close; Reforged fades its pages out over a little more than a tenth of a second, as fast as they fade in.
@@ -1163,6 +1163,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- 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.
- The lines from your selection to where it is headed can be switched off. Options > Interface 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.
+- Scrolling keeps up with the zoom. The camera moved the same distance over the ground at every height, so right down on the ground the map flew past and from the farthest zoom it crawled, ten times slower across the screen, and turning the scroll speed up hardly showed. The pace now follows the zoom: where a map opens it is exactly what it was, zoomed out it covers ground as fast as the picture shows it, and the scroll speed slider sets that pace at every height. Arrow keys, the screen's edges and a right drag all go by it, in Classic and Reforged alike.
- Orders land where you clicked when the camera is right down on the ground. Zoomed all the way in, a right click sent the units to the corner of the map instead of to the spot under the pointer, and the marker and the line went there with them. The game works out what you clicked on by firing a line from the camera at the ground, and that line was thrown away whenever the camera itself had dropped below the height of the tallest hill on the map - so it went wrong on hilly maps first and stayed fine on flat ones, which is why it looked random.
- 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 left button that moves the camera with a click is the one that drags it, and with nothing selected the right one does too. 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.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
index 1c1ff8455..1db166671 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
@@ -152,7 +152,7 @@ void LookAtTranslator::setScrolling(Int x)
TheTacticalView->setMouseLock( TRUE );
m_scrollType = x;
// A manual pan restores map constraints widened by scripted camera paths.
- if (TheGlobalData->m_useCameraConstraints && TheGlobalData->m_cameraBoundaryMargin > 0 && !TheGlobalData->isClassicUI())
+ if ((TheGlobalData->m_useCameraConstraints || TheGlobalData->isClassicUI()) && TheGlobalData->m_cameraBoundaryMargin > 0)
TheTacticalView->forceCameraConstraintRecalc();
if(TheStatsCollector)
TheStatsCollector->startScrollTime();
@@ -623,6 +623,15 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
else //not scrolling so reset amount
TheInGameUI->setScrollAmount(offset);
+ // The view turns this into the same number of world units at any height, so a pan crossed
+ // the screen ten times faster right down on the ground than from the farthest zoom, and
+ // zoomed out no setting of the scroll speed made it feel like it moved. Scaled by the
+ // height against MaxCameraHeight, where maps open, it crosses the screen at one pace at
+ // every zoom: the pace it always had at that height.
+ const Real zoomScale = TheTacticalView->getHeightAboveGround() / TheGlobalData->m_maxCameraHeight;
+ offset.x *= zoomScale;
+ offset.y *= zoomScale;
+
// Advance the pan clock even while stationary, so restarting does not include idle time.
TheTacticalView->scrollBy( &offset );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index 89f45964c..e67c64f40 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -575,7 +575,7 @@ void W3DView::calcCameraConstraints()
{
Region3D mapRegion;
TheTerrainLogic->getExtent( &mapRegion );
- if (TheGlobalData->m_cameraBoundaryMargin > 0 && !TheGlobalData->isClassicUI())
+ if (TheGlobalData->m_cameraBoundaryMargin > 0)
{
// A fixed margin follows the map rather than shrinking with zoom or camera angle.
m_cameraConstraint = cameraBoundaryFromMap(mapRegion, (Real)TheGlobalData->m_cameraBoundaryMargin);
diff --git a/GeneralsMD/Code/Tests/test_camera_behavior.inc b/GeneralsMD/Code/Tests/test_camera_behavior.inc
index a96bfec45..2f2bdb79d 100644
--- a/GeneralsMD/Code/Tests/test_camera_behavior.inc
+++ b/GeneralsMD/Code/Tests/test_camera_behavior.inc
@@ -188,6 +188,18 @@ TEST(camera_margin_preferences_load_and_rebuild_constraints)
CHECK(f.global->m_useCameraConstraints);
CHECK_EQ(f.global->m_cameraBoundaryMargin, 300);
CHECK_EQ(f.view.constraintRecalcs, 1);
+
+ // Classic keeps the constraint on whatever the box says, and runs past the edge as far: a pan
+ // puts the margin back the way it does in Reforged
+ f.global->m_interfaceStyle = INTERFACE_STYLE_CLASSIC;
+ f.global->m_useCameraConstraints = FALSE;
+ GameMessage *key = newInstance(GameMessage)(GameMessage::MSG_RAW_KEY_DOWN);
+ key->appendIntegerArgument(KEY_RIGHT);
+ key->appendIntegerArgument(KEY_STATE_DOWN);
+ f.camera.translateGameMessage(key);
+ key->deleteInstance();
+ CHECK(f.ui->scrolling);
+ CHECK_EQ(f.view.constraintRecalcs, 2);
}
TEST(camera_wheel_anchors_zoom_to_cursor_only_with_the_box_ticked)
@@ -312,6 +324,42 @@ TEST(arrow_keys_scroll_the_camera_and_w_a_s_d_stay_grid_keys)
CHECK(!f.ui->scrolling);
}
+TEST(scroll_speed_follows_the_zoom_in_both_interfaces)
+{
+ CHECK(bootOnce());
+ CameraInputFixture f;
+ const auto stepAt = [&f](Real height)
+ {
+ f.view.setHeightAboveGround(height);
+ GameMessage *message = newInstance(GameMessage)(GameMessage::MSG_FRAME_TICK);
+ f.camera.translateGameMessage(message);
+ message->deleteInstance();
+ return f.view.last.x;
+ };
+ GameMessage *key = newInstance(GameMessage)(GameMessage::MSG_RAW_KEY_DOWN);
+ key->appendIntegerArgument(KEY_RIGHT);
+ key->appendIntegerArgument(KEY_STATE_DOWN);
+ f.camera.translateGameMessage(key);
+ key->deleteInstance();
+ CHECK(f.ui->scrolling);
+
+ const Real maxHeight = f.global->m_maxCameraHeight;
+ for (Int style = 0; style < 2; ++style)
+ {
+ f.global->m_interfaceStyle = style ? INTERFACE_STYLE_CLASSIC : INTERFACE_STYLE_REFORGED;
+ f.global->m_keyboardScrollFactor = 0.5f;
+ // where a map opens, the step the arrow keys always took: SCROLL_AMT 100 times the speed
+ const Real opening = stepAt(maxHeight);
+ CHECK_NEAR(opening, f.global->m_horizontalScrollSpeedFactor * 100.0f * 0.5f, 0.001f);
+ // from the farthest zoom it is 2.9 times that, so the ground crosses the screen as fast
+ CHECK_NEAR(stepAt(maxHeight * 2.9f), 2.9f * opening, 0.001f);
+ // and the scroll speed still sets the pace at every height
+ f.global->m_keyboardScrollFactor = 1.0f;
+ CHECK_NEAR(stepAt(maxHeight * 2.9f), 2.0f * 2.9f * opening, 0.001f);
+ CHECK_NEAR(stepAt(maxHeight * 0.3f), 2.0f * 0.3f * opening, 0.001f);
+ }
+}
+
TEST(right_drag_pans_past_the_drag_tolerance_and_middle_drag_turns)
{
CHECK(bootOnce());