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
fix(gameclient): menu framing, the zoom anchor, and tree shadows
Olcay Seygan8220ac63ea0e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 743c41581..58a3339d8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -170,14 +170,17 @@ windowed mode, and scrolling speed that no longer depends on your frame rate.**Zoom toward the cursor works now.** It was in the options and it did nothing at all. The cameradoes not jump to a new zoom, it glides there over the next fraction of a second - and the game wasmeasuring how far the ground had slid under your pointer straight away, before the camera had moved-a millimetre, so it always measured nothing and moved nothing. The spot under your pointer is now+a millimetre, so it always measured nothing and moved nothing. Then it did measure the slide, and+handed it to the part of the camera that scrolls in screen inches rather than ground yards, so the+camera went somewhere else instead. The spot under your pointer is nowheld there for the whole glide. Roll the wheel over the far corner of your base and you end up atthat corner, not in the middle of the screen.**A skirmish opens zoomed all the way out.** The game used to drop you at the map author's owncamera height, which is tighter than the wheel will go, so the first thing anyone did on everysingle map was roll the wheel back to see their base and the ground around it. It now opens at the-widest view the wheel can reach. Middle-click still snaps back to the author's framing, and+widest view the wheel can reach — the main menu behind the buttons is left alone, at the framing it+was built for. Middle-click still snaps back to the author's framing, and`StartAtMaxZoom = No` in `GameData.ini` puts the old opening back.**Hold Ctrl and roll the wheel to turn a building before you put it down** — a clean 45 degrees a@@ -234,13 +237,13 @@ sparks are too small and too short-lived to earn it, and fire and glows are stilshade. It is one soft patch per plume rather than a shadow for every puff, so a battlefield full ofsmoke costs no more than a battlefield with one fire.-Then the trees. Every one of them dropped the same round grey blob, the same size in every-direction, no matter where the sun was or how tall the tree was — and if you had shadows set to-the good kind rather than the cheap kind, the trees dropped nothing at all, so a forest sat on-clean ground next to buildings with long shadows behind them. A tree's shadow now leans away from-the sun and stretches by the tree's own height, the way everything else on the map does, and it-is drawn whichever shadow setting you are on. At noon it is a pool under the trunk; late in the-day the whole treeline lies across the ground in front of you.+Then the trees. If you had shadows set to the good kind rather than the cheap kind, the trees+dropped nothing at all, so a forest sat on clean ground next to buildings with long shadows behind+them. Trees are drawn in one batch to keep a forest cheap, which is why they have never had a+shadow with a shape - what they get is one soft pool under the trunk, and it is now drawn whichever+shadow setting you are on. Leaning that pool away from the sun was tried and put back: a round+smudge sitting a tree's width to one side does not read as that tree's shadow, it reads as a stain+on the ground.And the scenery nobody gave a shadow to at all: fences, walls of tyres, rubbish piles, lowshrubs, the props that dress a map. They stood on the terrain with nothing under them, which is@@ -321,7 +324,9 @@ question. The aircraft attack-move fix came from a log line, not an argument.**Things that did not work were reverted, and written down.** A wider field of view for widescreenlooked past the edge of the maps and went back. Four separate pathfinding experiments were tried ingame, made things worse, and were reverted. A three-panel command bar that fixed the widescreen-stretch was tried and reverted too — the game's own bar is the one people want to see. All of it is+stretch was tried and reverted too — the game's own bar is the one people want to see. Tree shadows+that leaned away from the sun went the same way, on the evidence of before-and-after screenshots.+All of it isrecorded so nobody re-tries it in two years.**Bugs deliberately left alone are pinned by a test** that documents the current behaviour, so@@ -336,6 +341,13 @@ has stood in front of a skirmish full of soldiers to judge how they look, or meain frames. If they turn out to be ugly or expensive, `UseShadowVolumesForSkins = No` turns them offand this entry gets rewritten.+**Zoom toward the cursor has been fixed twice and eyeballed once.** The first fix measured a camera+that had not moved; the second found the camera being pushed in the wrong units. The second one is+argued from the code rather than watched: the mouse wheel cannot be faked from outside the game —+injected wheel events never reach its input, which is how it was established that they never+arrived rather than that they arrived and did nothing. If it still misses the mark, say so and it+gets a third look.+---## Not there yetdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cppindex ac41aeb6a..ab0cb8b69 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp@@ -189,11 +189,25 @@ void LookAtTranslator::updateZoomToCursor( void )world.zero();TheTacticalView->screenToTerrain( &m_zoomAnchorPixel, &world );- Coord2D shift;- shift.x = m_zoomAnchorWorld.x - world.x;- shift.y = m_zoomAnchorWorld.y - world.y;- if (shift.x != 0.0f || shift.y != 0.0f)- TheTacticalView->scrollBy( &shift );+ //+ // 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, whichdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex e65628bf8..da1efd3c8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -2029,8 +2029,9 @@ void GameLogic::startNewGame( Bool loadingSaveGame )TheTacticalView->setAngleAndPitchToDefault();//StartAtMaxZoom: open the map as far out as the wheel itself may go rather than at the map's- //own default height, which is the tighter of the two.- if( TheGlobalData->m_startAtMaxZoom )+ //own default height, which is the tighter of the two. Not the shell map behind the menus:+ //that one is framed as a set piece and its own default framing is the point of it.+ if( TheGlobalData->m_startAtMaxZoom && !isInShellGame() )TheTacticalView->setZoomToMax();elseTheTacticalView->setZoomToDefault();@@ -2080,8 +2081,9 @@ void GameLogic::startNewGame( Bool loadingSaveGame )TheTacticalView->initHeightForMap();TheTacticalView->setAngleAndPitchToDefault();//StartAtMaxZoom: open the map as far out as the wheel itself may go rather than at the map's- //own default height, which is the tighter of the two.- if( TheGlobalData->m_startAtMaxZoom )+ //own default height, which is the tighter of the two. Not the shell map behind the menus:+ //that one is framed as a set piece and its own default framing is the point of it.+ if( TheGlobalData->m_startAtMaxZoom && !isInShellGame() )TheTacticalView->setZoomToMax();elseTheTacticalView->setZoomToDefault();diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.hindex c47d356c4..0cecc724d 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h@@ -137,7 +137,6 @@ typedef struct {Bool m_halfTile; ///< Tiles are 64x64 pixels, half tile supports a 32x32 bit texture. Have to adjust the uv values.Vector3 m_offset;Real m_shadowSize; ///< Shadow radius.- Real m_shadowHeight; ///< Model height, so the blob can be stretched away from the sun.Bool m_doShadow; ///< Draw shadow.} TTreeType;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cppindex aba40e7fa..787a1a775 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp@@ -58,7 +58,6 @@ enum#include <stdio.h>#include <string.h>-#include <math.h>#include <assetmgr.h>#include <texture.h>#include "Common/MapReaderWriterInfo.h"@@ -1394,7 +1393,6 @@ Int W3DTreeBuffer::addTreeType(const W3DTreeDrawModuleData *data)m_treeTypes[m_numTreeTypes].m_data = data;m_treeTypes[m_numTreeTypes].m_offset = offset;m_treeTypes[m_numTreeTypes].m_shadowSize = (box.Extent.X + box.Extent.Y); // Average extent * 2. jba.- m_treeTypes[m_numTreeTypes].m_shadowHeight = box.Center.Z + box.Extent.Z; // top of the model above its base.m_treeTypes[m_numTreeTypes].m_doShadow = data->m_doShadow;m_numTreeTypes++;return m_numTreeTypes-1;@@ -1611,16 +1609,12 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pDInt curTree;// Draw tree shadows.- // Trees are batched vertices with no render object of their own, so a volume shadow is not- // available to them - the shared blob is all there is. Lean and stretch it along the sun so it- // at least points where every other shadow in the scene points, and draw it whenever either- // shadow option is on: with volumes only, trees used to be the one thing standing on nothing.+ // Trees are batched vertices with no render object of their own, so the one shared blob decal+ // is all they can have. The loop used to be gated on m_useShadowDecals alone, so with volume+ // shadows picked trees were the one thing in the scene standing on nothing; draw it under+ // either option.if (m_shadow && TheW3DProjectedShadowManager &&(TheGlobalData->m_useShadowDecals || TheGlobalData->m_useShadowVolumes)) {- Vector3 sun(0.0f, 0.0f, 1.0f);- if (TheW3DShadowManager) {- sun = TheW3DShadowManager->getLightPosWorld(0);- }for (curTree=0; curTree<m_numTrees; curTree++) {Int type = m_trees[curTree].treeType;if (type<0) { // deleted.@@ -1634,24 +1628,8 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pDm_trees[curTree].m_toppleState == TOPPLE_DOWN) {continue;}- const Real size = m_treeTypes[type].m_shadowSize;- Real dirX = 1.0f, dirY = 0.0f, reach = 0.0f;- const Real dx = m_trees[curTree].location.X - sun.X;- const Real dy = m_trees[curTree].location.Y - sun.Y;- const Real dz = sun.Z - m_trees[curTree].location.Z;- const Real len = (Real)sqrt(dx*dx + dy*dy);- if (len > 0.001f && dz > 1.0f) {- dirX = dx/len;- dirY = dy/len;- reach = m_treeTypes[type].m_shadowHeight * len / dz;- if (reach > 2.0f*size) {- reach = 2.0f*size; // a low sun would otherwise smear one tree across half the map.- }- }- m_shadow->setAngle((Real)atan2(dirY, dirX));- m_shadow->setSize(size + reach, -size*factor);- m_shadow->setPosition(m_trees[curTree].location.X + dirX*reach*0.5f,- m_trees[curTree].location.Y + dirY*reach*0.5f, m_trees[curTree].location.Z);+ m_shadow->setSize(m_treeTypes[type].m_shadowSize, -m_treeTypes[type].m_shadowSize*factor);+ m_shadow->setPosition(m_trees[curTree].location.X, m_trees[curTree].location.Y, m_trees[curTree].location.Z);TheW3DProjectedShadowManager->queueDecal(m_shadow);}TheW3DProjectedShadowManager->flushDecals(m_shadow->getTexture(0), SHADOW_DECAL);