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(w3ddevice): attachments and riders follow the drawn hull heading
Olcay Seyganfd73f52223a6
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.hindex 563efae82..8509f6818 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h@@ -212,6 +212,7 @@ public:Real m_headingLagRate; ///< and how fast that changes, a logic frameReal m_headingLogic; ///< the logic heading on m_headingFrameUnsignedInt m_headingFrame; ///< the logic frame the heading spring last stepped on+ Bool m_headingSeeded; ///< m_headingLogic and m_headingFrame hold a real heading and frameTWheelInfo m_wheelInfo; ///< Wheel offset & angle info for a wheeled type locomotor.DrawableLocoInfo();@@ -785,8 +786,9 @@ protected:Real m_totalRoll; ///< Current total roll for this frame.Real m_totalYaw; ///< Current total yaw for this frameReal m_totalZ;+ Real m_headingYaw; ///< a ground vehicle's heading lag, turned before the pitch and roll- PhysicsXformInfo() : m_totalPitch(0), m_totalRoll(0), m_totalYaw(0), m_totalZ(0) { }+ PhysicsXformInfo() : m_totalPitch(0), m_totalRoll(0), m_totalYaw(0), m_totalZ(0), m_headingYaw(0) { }};Bool calcPhysicsXform(PhysicsXformInfo& info);diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex bf4eac31b..29e504b99 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -246,6 +246,7 @@ DrawableLocoInfo::DrawableLocoInfo()m_headingLagRate = 0.0f;m_headingLogic = 0.0f;m_headingFrame = 0;+ m_headingSeeded = FALSE;}// ------------------------------------------------------------------------------------------------@@ -1762,6 +1763,7 @@ void Drawable::applyPhysicsXform(Matrix3D* mtx)if (calcPhysicsXform(info)){mtx->Translate(0.0f, 0.0f, info.m_totalZ);+ mtx->Rotate_Z( info.m_headingYaw );mtx->Rotate_Y( info.m_totalPitch );mtx->Rotate_X( -info.m_totalRoll );mtx->Rotate_Z( info.m_totalYaw );@@ -1776,9 +1778,10 @@ Bool Drawable::calcPhysicsXform(PhysicsXformInfo& info)const Object* obj = getObject();const AIUpdateInterface *ai = obj ? obj->getAIUpdateInterface() : NULL;Bool hasPhysicsXform = false;- if (ai)+ Bool ground = false;+ if (ai){- const Locomotor *locomotor = ai->getCurLocomotor();+ const Locomotor *locomotor = ai->getCurLocomotor();if (locomotor){switch (locomotor->getAppearance())@@ -1788,6 +1791,7 @@ Bool Drawable::calcPhysicsXform(PhysicsXformInfo& info)case LOCO_TREADS:calcPhysicsXformGround(locomotor, info);hasPhysicsXform = true;+ ground = true;break;case LOCO_HOVER:case LOCO_WINGS:@@ -1801,6 +1805,9 @@ Bool Drawable::calcPhysicsXform(PhysicsXformInfo& info)}}}+ // off its ground locomotor the hull is drawn on its logic heading, and so is its turret+ if (!ground && m_locoInfo)+ m_locoInfo->m_headingLag = 0.0f;if (hasPhysicsXform){@@ -2226,20 +2233,23 @@ void Drawable::calcPhysicsXformGround( const Locomotor *locomotor, PhysicsXformIconst Real HEADING_MAX_LAG = PI / 4.0f; // never further behind than this: a heading a script sets is drawn there soonconst UnsignedInt HEADING_CATCH_UP_FRAMES = 8; // more logic frames than this unseen and the hull is drawn on its heading- // the spring is stepped once a logic frame, the rate the heading itself changes at+ /* The spring is stepped once a logic frame, the rate the heading itself changes at. The heading and+ the frame are read once: with -logicthread 1 the logic can move on between two reads. */const Object *owner = getObject();UnsignedInt logicFrame = TheGameLogic->getFrame();+ Real logicAngle = getOrientation();UnsignedInt gap = logicFrame - m_locoInfo->m_headingFrame;- if (gap > HEADING_CATCH_UP_FRAMES || owner->isKindOf(KINDOF_AIRCRAFT))+ if (!m_locoInfo->m_headingSeeded || gap > HEADING_CATCH_UP_FRAMES || owner->isKindOf(KINDOF_AIRCRAFT)){- // a taxiing jet or a landed helicopter eases its own turn in the logic+ // first drawn, long unseen, or a taxiing jet or landed helicopter, which eases its own turn in the logicm_locoInfo->m_headingLag = 0.0f;m_locoInfo->m_headingLagRate = 0.0f;+ m_locoInfo->m_headingSeeded = TRUE;}else if (gap != 0){const Real omega = 2.0f / HEADING_LAG_FRAMES; // a ramp's lag is 2 / omega- Real turned = stdAngleDiff(getOrientation(), m_locoInfo->m_headingLogic) / gap;+ Real turned = stdAngleDiff(logicAngle, m_locoInfo->m_headingLogic) / gap;for (UnsignedInt i = 0; i < gap; ++i){m_locoInfo->m_headingLag -= turned;@@ -2252,14 +2262,16 @@ void Drawable::calcPhysicsXformGround( const Locomotor *locomotor, PhysicsXformIm_locoInfo->m_headingLagRate = 0.0f;}}- m_locoInfo->m_headingLogic = getOrientation();+ m_locoInfo->m_headingLogic = logicAngle;m_locoInfo->m_headingFrame = logicFrame;+ // turned first, under the lean, so the lean tips along the hull as drawn (applyPhysicsXform)+ info.m_headingYaw = m_locoInfo->m_headingLag;/* Stepped on the retail clock, every second logic frame, so the springs, the locomotor'sstiffness and damping and the ease frames below keep the timing they were tuned at. Speeds areper logic frame and only ever divided by the locomotor's own top speed, which cancels; the turnrate does not, so it is taken per retail frame. */- UnsignedInt now = TheGameLogic->getFrame() / LOGICFRAMES_PER_RETAIL_FRAME;+ UnsignedInt now = logicFrame / LOGICFRAMES_PER_RETAIL_FRAME;UnsignedInt steps = now - m_locoInfo->m_groundFrame;if (steps != 0){@@ -2270,7 +2282,7 @@ void Drawable::calcPhysicsXformGround( const Locomotor *locomotor, PhysicsXformIreturn;BodyDamageType bdt = obj->getBodyModule()->getDamageState();Real speed = physics->getForwardSpeed2D();- Real angle = getOrientation() + m_locoInfo->m_headingLag; // the turn as drawn+ Real angle = logicAngle + m_locoInfo->m_headingLag; // the turn as drawnif (steps > MAX_CATCH_UP_FRAMES){// long unseen, or just loaded: let the springs settle without a lurch from the gap@@ -2333,7 +2345,6 @@ void Drawable::calcPhysicsXformGround( const Locomotor *locomotor, PhysicsXformI}info.m_totalPitch = m_locoInfo->m_groundPitch;info.m_totalRoll = m_locoInfo->m_groundRoll;- info.m_totalYaw = m_locoInfo->m_headingLag;info.m_totalZ = m_locoInfo->m_groundZ;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cppindex a7394799d..fee50320d 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp@@ -2399,6 +2399,9 @@ Bool ParticleSystem::updateEmission( Int localPlayerIndex, Bool *keepSystem )Bool transformSet = false;const Matrix3D *parentXfrm = NULL;Bool isShrouded = false;+ // the hull of a tank or car is drawn trailing its logic heading, and exhaust and damage smoke+ // hang off the hull as drawn (Drawable::getDrawnHeadingLag)+ Matrix3D drawnXfrm;if (m_attachedToDrawableID){@@ -2409,7 +2412,9 @@ Bool ParticleSystem::updateEmission( Int localPlayerIndex, Bool *keepSystem )if (attachedTo->getFullyObscuredByShroud())isShrouded = true;- parentXfrm = attachedTo->getTransformMatrix();+ drawnXfrm = *attachedTo->getTransformMatrix();+ drawnXfrm.Rotate_Z( attachedTo->getDrawnHeadingLag() );+ parentXfrm = &drawnXfrm;m_lastPos = m_pos;m_pos = *attachedTo->getPosition();@@ -2435,7 +2440,11 @@ Bool ParticleSystem::updateEmission( Int localPlayerIndex, Bool *keepSystem )const Drawable * draw = objectAttachedTo->getDrawable();m_attachedObjectDrawableForDraw = draw ? draw->getID() : INVALID_DRAWABLE_ID;if ( draw )- parentXfrm = draw->getTransformMatrix();+ {+ drawnXfrm = *draw->getTransformMatrix();+ drawnXfrm.Rotate_Z( draw->getDrawnHeadingLag() );+ parentXfrm = &drawnXfrm;+ }elseparentXfrm = objectAttachedTo->getTransformMatrix();diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DDependencyModelDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DDependencyModelDraw.hindex 62eacd720..c691756f5 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DDependencyModelDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DDependencyModelDraw.h@@ -65,6 +65,7 @@ public:virtual void doDrawModule(const Matrix3D* transformMtx);virtual void notifyDrawModuleDependencyCleared( );///< if you were waiting for something before you drew, it's ready nowvirtual void adjustTransformMtx(Matrix3D& mtx) const;+ virtual Real getHullHeadingLag() const;protected:Bool m_dependencyCleared; // The thing we depend on will clear this, and we will relatch it after we draw.diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.hindex 4ec92a7b2..4e3b387e8 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h@@ -475,6 +475,8 @@ protected:void stopClientParticleSystems();void doHideShowSubObjs(const std::vector<ModelConditionInfo::HideShowSubObjInfo>* vec);virtual void adjustTransformMtx(Matrix3D& mtx) const;+ /// how far the hull this model is drawn on trails its logic heading, which a turret aims from+ virtual Real getHullHeadingLag() const;Real getCurAnimDistanceCovered() const;Bool setCurAnimDurationInMsec(Real duration);diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDependencyModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDependencyModelDraw.cppindex 3fe280bd9..68f0872fe 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDependencyModelDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDependencyModelDraw.cpp@@ -124,6 +124,24 @@ void W3DDependencyModelDraw::notifyDrawModuleDependencyCleared( )m_dependencyCleared = TRUE;}+// ------------------------------------------------------------------------------------------------+/** Riding on a container's bone, the rider is drawn on the container's hull, so its turret trails+ * that hull's heading as well (an Overlord's or an Emperor's Gattling Cannon). */+Real W3DDependencyModelDraw::getHullHeadingLag() const+{+ Real lag = W3DModelDraw::getHullHeadingLag();+ const Object *me = getDrawable()->getObject();+ if( getW3DDependencyModelDrawModuleData()->m_attachToDrawableBoneInContainer.isNotEmpty()+ && me+ && me->getContainedBy()+ && !me->getContainedBy()->getContain()->isEnclosingContainerFor(me)+ && me->getContainedBy()->getDrawable() )+ {+ lag += me->getContainedBy()->getDrawable()->getDrawnHeadingLag();+ }+ return lag;+}+// ------------------------------------------------------------------------------------------------void W3DDependencyModelDraw::adjustTransformMtx(Matrix3D& mtx) const{@@ -152,6 +170,7 @@ void W3DDependencyModelDraw::adjustTransformMtx(Matrix3D& mtx) constelse{mtx = *theirDrawable->getTransformMatrix();//TransformMatrix();+ mtx.Rotate_Z( theirDrawable->getDrawnHeadingLag() ); // the container as drawn, as its bone would beDEBUG_LOG_DEV(("m_attachToDrawableBoneInContainer %s not found\n",getW3DDependencyModelDrawModuleData()->m_attachToDrawableBoneInContainer.str()));}}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cppindex e4e9a6cf3..dd0ca5e77 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp@@ -2334,6 +2334,12 @@ void W3DModelDraw::adjustAnimSpeedToMovementSpeed()}}+//-------------------------------------------------------------------------------------------------+Real W3DModelDraw::getHullHeadingLag() const+{+ return getDrawable()->getDrawnHeadingLag();+}+//-------------------------------------------------------------------------------------------------void W3DModelDraw::adjustTransformMtx(Matrix3D& mtx) const{@@ -2908,7 +2914,7 @@ void W3DModelDraw::handleClientTurretPositioning()const AIUpdateInterface* ai = obj->getAIUpdateInterface();// a turret aims from the logic heading, which the drawn hull of a tank or car trailsif (ai && ai->getTurretRotAndPitch((WhichTurretType)tslot, &turretAngle, &turretPitch))- turretAngle -= getDrawable()->getDrawnHeadingLag();+ turretAngle -= getHullHeadingLag();}// do turret, if any