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): tread, wheel and chassis motion at any frame rate
Olcay Seygan2f70fbf28cf0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6df852b17..0eb13011e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -68,6 +68,7 @@ found and fixed — EA's own, not port damage.**- Raise the particle limit as far as you like and every puff gets drawn. Past about sixteen thousand smoke and fire sprites on screen the game quietly stopped drawing the rest: a test with 68,000 of them showed barely a fifth. A test with 101,000 now draws all of them at 8.3ms a frame, and in 1,200 frames not one fell below 60 a second. The first version that drew them all took 22.4ms; the rest came from sorting and copying them far less and from sharing the work across every core of the processor.- Big fights no longer drag the picture down into the twenties. Every moving tank and soldier, and every puff of smoke, goes to the graphics card through one shared scratch area, and it was so small that a big fight on Bombardment Beach filled it about fifty times a frame. Each refill made the processor wait for the card, 8 to 12ms of every frame, while the card sat two thirds idle. The area is made full size once now and refills about seven times a frame, in 0.02ms. The same 16,000-frame battle, fast-forwarded, finishes in 226 seconds where it took between 263 and 325, and the seconds that fell under 50 frames a second went from 125 or more to 4.- Every animation runs on a clock instead of counting frames.+- Tanks and trucks move the same at any frame rate. Their treads scrolled a fixed step every picture, so at 120 frames a second they ran four times too fast, and a tank turning on the spot rolled both treads forward as if it were driving. Each tread now covers exactly the ground under it. In a tight turn the two run against each other, and backing up runs them backwards. Wheels spin with the distance driven the same way. The hull's springs used to settle four times too fast as well, and every start or stop threw the chassis to its full tilt in a single picture. Now a tank squats as it pulls away and dips its nose when it brakes, easing in over a tenth of a second and settling within half a second. In a corner it leans out, a Crusader up to two and a half degrees. The Humvee, which never moved on its springs at all, rocks too. A run drawing one picture per game tick and one drawing fourteen put every tank in the same pose, to the last digit, for as long as neither skipped a tick.- A scroll that starts after the camera has stood still no longer lurches. The first frame of the move was timed from the last time the camera moved, so after a few seconds of looking at one spot it was worth three frames of scrolling at once. The clock runs while the camera is still now, and the first frame moves one frame's worth.- Briefing and cutscene subtitles hold long enough to read again.- The radar's under-attack pulse throbs instead of strobing, and no longer ends early.diff --git a/GeneralsMD/Code/Data/Scenarios/vehiclelean.txt b/GeneralsMD/Code/Data/Scenarios/vehiclelean.txtnew file mode 100644index 000000000..cf078eeb3--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/vehiclelean.txt@@ -0,0 +1,32 @@+# A Crusader and a Humvee on open ground, for the chassis lean, the tread scroll and the wheel spin.+# The Crusader pulls away east and stops, pivots to face south and drives, then turns back west on a+# long diagonal. The Humvee drives east, swings north-west through a turn and comes back east.+#+# generals.exe -win -turbo -quickstart -noshellmap -observer -multiInstance+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionChina -seed 7 -maxframes 700+# -scenario vehiclelean -logPrefix vehiclelean_+#+# -turbo draws one picture a logic frame. The same line without -turbo and with -noFPSLimit drew+# 9421 pictures over 663 logic frames, about 14 each. Measured 2026-10-03 with temporary log lines+# of the chassis lean, pitch and lift, the tread offsets and the wheel angles, one per unit per logic+# frame: the two runs wrote the same 945 lines, digit for digit, up to frame 182, where the paced run+# stalled 1.2 seconds and drew nothing for several logic frames. From there the catch-up steps on+# an averaged change of speed, and the pitch differs by 0.00004 rad at the 95th percentile and+# 0.0027 at most. -drawdelay 45 (20 pictures a second, half the logic frames undrawn) stays within+# 0.0034 rad at the 95th percentile, and the lean itself within 0.0004.+#+# With the locomotor's acceleration ramped over about 36 frames, the Crusader squats 1.5 degrees+# pulling away (frames 63 to 110, 305 to 345, 500 to 525), dives 1.2 braking (frames 260 to 300 and+# 430 to 490) and rolls 2.1 to 2.5 degrees through the turns after frame 500. On the turn after+# frame 300 its two treads run against each other. The Humvee backs off at frame 63, pitches 1.7+# degrees either way and rolls 1.4 through the turns at 340 to 370 and 585 to 625.++30 spawn 0 AmericaTankCrusader 1 1000 3500+30 spawn 0 AmericaVehicleHumvee 1 1000 3750+60 move 0 AmericaTankCrusader 1200 3500+60 move 0 AmericaVehicleHumvee 1350 3750+300 move 0 AmericaTankCrusader 1200 3350+300 move 0 AmericaVehicleHumvee 1050 3950+480 move 0 AmericaTankCrusader 950 3500+480 move 0 AmericaVehicleHumvee 1350 3750diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.hindex b177df315..04ccd9878 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h@@ -180,6 +180,15 @@ public:Real m_leanPitch[2]; ///< a helicopter's pitch target, smoothed through two stages once a logic frameReal m_leanRoll[2]; ///< the same for rollUnsignedInt m_leanFrame; ///< the logic frame the lean targets were last stepped on+ Real m_groundLeanStages[2][3]; ///< a ground vehicle's pitch and roll lean, smoothed through three stages once a logic frame+ UnsignedInt m_groundFrame; ///< the logic frame those were last stepped on+ Real m_prevForwardSpeed; ///< a ground vehicle's forward speed on that frame+ Real m_prevAngle; ///< and its heading+ Real m_groundLeanPitch; ///< a ground vehicle's lean from starting, braking and turning, on top of terrain and recoil+ Real m_groundLeanRoll;+ Real m_groundPitch; ///< a ground vehicle's chassis pitch, roll and lift from that frame, drawn until the next one+ Real m_groundRoll;+ Real m_groundZ;TWheelInfo m_wheelInfo; ///< Wheel offset & angle info for a wheeled type locomotor.DrawableLocoInfo();@@ -662,6 +671,7 @@ protected:Bool calcPhysicsXform(PhysicsXformInfo& info);void calcPhysicsXformThrust(const Locomotor *locomotor, PhysicsXformInfo& info);void calcPhysicsXformHoverOrWings(const Locomotor *locomotor, PhysicsXformInfo& info);+ void calcPhysicsXformGround(const Locomotor *locomotor, PhysicsXformInfo& info);void calcPhysicsXformTreads(const Locomotor *locomotor, PhysicsXformInfo& info);void calcPhysicsXformWheels(const Locomotor *locomotor, PhysicsXformInfo& info);void calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXformInfo& info );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex d53907b7b..43cfdef15 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -226,6 +226,16 @@ DrawableLocoInfo::DrawableLocoInfo()m_leanPitch[0] = m_leanPitch[1] = 0.0f;m_leanRoll[0] = m_leanRoll[1] = 0.0f;m_leanFrame = 0;+ for (Int i = 0; i < 3; ++i)+ m_groundLeanStages[0][i] = m_groundLeanStages[1][i] = 0.0f;+ m_groundFrame = 0;+ m_prevForwardSpeed = 0.0f;+ m_prevAngle = 0.0f;+ m_groundLeanPitch = 0.0f;+ m_groundLeanRoll = 0.0f;+ m_groundPitch = 0.0f;+ m_groundRoll = 0.0f;+ m_groundZ = 0.0f;}// ------------------------------------------------------------------------------------------------@@ -1572,15 +1582,9 @@ Bool Drawable::calcPhysicsXform(PhysicsXformInfo& info)switch (locomotor->getAppearance()){case LOCO_WHEELS_FOUR:- calcPhysicsXformWheels(locomotor, info);- hasPhysicsXform = true;- break;case LOCO_MOTORCYCLE:- calcPhysicsXformMotorcycle( locomotor, info );- hasPhysicsXform = TRUE;- break;case LOCO_TREADS:- calcPhysicsXformTreads(locomotor, info);+ calcPhysicsXformGround(locomotor, info);hasPhysicsXform = true;break;case LOCO_HOVER:@@ -1860,6 +1864,105 @@ void Drawable::calcPhysicsXformHoverOrWings( const Locomotor *locomotor, Physicsinfo.m_totalZ = 0.0f;}+//-------------------------------------------------------------------------------------------------+/** Treads, wheels and motorcycles. EA stepped their springs once a drawn frame, which was once a+ * logic frame at the 30 pictures a second the game was tuned at; at 120 the chassis bounced and+ * settled four times as fast. They are stepped once a logic frame here, catching up when a slow+ * picture let more than one go by, and the pictures in between show the last result: the unit's+ * position does not move between logic frames either.+ *+ * The lean from speeding up, braking and turning is worked out here as well. EA kicked the recoil+ * spring with the physics acceleration, and with Acceleration = 1000 in most locomotors that is one+ * frame long, so every start and stop pinned the chassis to its limit in a single picture. The+ * spring is left to the weapon recoil, which is what it is tuned for. The lean+ * follows the change of forward speed over a logic frame as a share of top speed, and in a turn+ * speed times turn rate as a share of the most the locomotor can do, eased through three stages:+ * a standing start to top speed inside one frame peaks four frames later at most of the limit and+ * has gone by about half a second, and a slower pull away leans less for longer. */+//-------------------------------------------------------------------------------------------------+void Drawable::calcPhysicsXformGround( const Locomotor *locomotor, PhysicsXformInfo& info )+{+ if (m_locoInfo == NULL)+ m_locoInfo = newInstance(DrawableLocoInfo);++ const UnsignedInt MAX_CATCH_UP_FRAMES = 4; // more than this unseen and there is nothing to measure against+ const Real LEAN_EASE_FRAMES = 3.0f; // each of the three smoothing stages, in logic frames+ const Real START_GAIN = 11.0f; // a one frame start from rest to top speed peaks at tanh(1.2) of the limit+ const Real DEFAULT_LEAN_LIMIT = 0.07f; // 4 degrees, for a locomotor that reacts but names no limit, like the Humvee's++ UnsignedInt now = TheGameLogic->getFrame();+ UnsignedInt steps = now - m_locoInfo->m_groundFrame;+ if (steps != 0)+ {+ const Object *obj = getObject();+ BodyDamageType bdt = obj->getBodyModule()->getDamageState();+ Real speed = obj->getPhysics()->getForwardSpeed2D();+ Real angle = getOrientation();+ if (steps > MAX_CATCH_UP_FRAMES)+ {+ // long unseen, or just loaded: let the springs settle without a lurch from the gap+ m_locoInfo->m_prevForwardSpeed = speed;+ m_locoInfo->m_prevAngle = angle;+ steps = MAX_CATCH_UP_FRAMES;+ }+ Real forwardAccel = (speed - m_locoInfo->m_prevForwardSpeed) / steps;+ Real lateralAccel = speed * stdAngleDiff(angle, m_locoInfo->m_prevAngle) / steps;+ m_locoInfo->m_prevForwardSpeed = speed;+ m_locoInfo->m_prevAngle = angle;+ m_locoInfo->m_groundFrame = now;++ /* A locomotor with neither factor set never leaned under EA either (the train, a taxiing jet).+ One with a factor but no limit, the Humvee's, was clamped flat; it gets a small one. The+ change of speed is not asked whether the locomotor caused it, as EA's kick was: the last+ frame of a stop is not a motive one, and a shove from a blast is a lurch as well. */+ Real pitchIn = 0.0f;+ Real rollIn = 0.0f;+ if (locomotor->getForwardAccelCoef() != 0.0f || locomotor->getLateralAccelCoef() != 0.0f)+ {+ Real maxSpeed = locomotor->getMaxSpeedForCondition(bdt);+ Real maxLateral = maxSpeed * locomotor->getMaxTurnRate(bdt);+ pitchIn = maxSpeed > 0.0f ? -START_GAIN * forwardAccel / maxSpeed : 0.0f;+ rollIn = maxLateral > 0.0f ? -lateralAccel / maxLateral : 0.0f;+ }+ Real accelLimit = locomotor->getAccelPitchLimit();+ Real decelLimit = locomotor->getDecelPitchLimit();+ if (accelLimit == 0.0f)+ accelLimit = DEFAULT_LEAN_LIMIT;+ if (decelLimit == 0.0f)+ decelLimit = DEFAULT_LEAN_LIMIT;++ PhysicsXformInfo step;+ for (UnsignedInt i = 0; i < steps; ++i)+ {+ Real *p = m_locoInfo->m_groundLeanStages[0];+ Real *r = m_locoInfo->m_groundLeanStages[1];+ p[0] += (pitchIn - p[0]) / LEAN_EASE_FRAMES;+ p[1] += (p[0] - p[1]) / LEAN_EASE_FRAMES;+ p[2] += (p[1] - p[2]) / LEAN_EASE_FRAMES;+ r[0] += (rollIn - r[0]) / LEAN_EASE_FRAMES;+ r[1] += (r[0] - r[1]) / LEAN_EASE_FRAMES;+ r[2] += (r[1] - r[2]) / LEAN_EASE_FRAMES;+ // negative is the squat of a start and the lean out of a left turn, as EA had it+ m_locoInfo->m_groundLeanPitch = (p[2] < 0.0f ? accelLimit : decelLimit) * tanh(p[2]);+ m_locoInfo->m_groundLeanRoll = (r[2] < 0.0f ? accelLimit : decelLimit) * tanh(r[2]);++ step = PhysicsXformInfo();+ switch (locomotor->getAppearance())+ {+ case LOCO_WHEELS_FOUR: calcPhysicsXformWheels(locomotor, step); break;+ case LOCO_MOTORCYCLE: calcPhysicsXformMotorcycle(locomotor, step); break;+ case LOCO_TREADS: calcPhysicsXformTreads(locomotor, step); break;+ }+ }+ m_locoInfo->m_groundPitch = step.m_totalPitch;+ m_locoInfo->m_groundRoll = step.m_totalRoll;+ m_locoInfo->m_groundZ = step.m_totalZ;+ }+ info.m_totalPitch = m_locoInfo->m_groundPitch;+ info.m_totalRoll = m_locoInfo->m_groundRoll;+ info.m_totalZ = m_locoInfo->m_groundZ;+}+//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------void Drawable::calcPhysicsXformTreads( const Locomotor *locomotor, PhysicsXformInfo& info )@@ -1878,9 +1981,7 @@ void Drawable::calcPhysicsXformTreads( const Locomotor *locomotor, PhysicsXformIconst Real ROLL_STIFFNESS = locomotor->getRollStiffness();const Real PITCH_DAMPING = locomotor->getPitchDamping();const Real ROLL_DAMPING = locomotor->getRollDamping();- const Real FORWARD_ACCEL_COEFF = locomotor->getForwardAccelCoef();- const Real LATERAL_ACCEL_COEFF = locomotor->getLateralAccelCoef();- const Real UNIFORM_AXIAL_DAMPING = locomotor->getUniformAxialDamping();+ const Real UNIFORM_AXIAL_DAMPING = locomotor->getUniformAxialDamping();// get object from logicObject *obj = getObject();@@ -1899,7 +2000,6 @@ void Drawable::calcPhysicsXformTreads( const Locomotor *locomotor, PhysicsXformI// get our position and direction vectorconst Coord3D *pos = getPosition();const Coord3D *dir = getUnitDirectionVector2D();- const Coord3D *accel = physics->getAcceleration();const Coord3D *vel = physics->getVelocity();// compute perpendicular (2d)@@ -2036,19 +2136,9 @@ void Drawable::calcPhysicsXformTreads( const Locomotor *locomotor, PhysicsXformIm_locoInfo->m_accelerationRollRate += ((-ROLL_STIFFNESS * m_locoInfo->m_accelerationRoll) + (-ROLL_DAMPING * m_locoInfo->m_accelerationRollRate)); // spring/damperm_locoInfo->m_accelerationRoll += m_locoInfo->m_accelerationRollRate;- // compute total pitch and roll of tank- info.m_totalPitch = m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch;- info.m_totalRoll = m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll;-- if (physics->isMotive())- {- // cause the chassis to pitch & roll in reaction to acceleration/deceleration- Real forwardAccel = dir->x * accel->x + dir->y * accel->y;- m_locoInfo->m_accelerationPitchRate += -(FORWARD_ACCEL_COEFF * forwardAccel);-- Real lateralAccel = -dir->y * accel->x + dir->x * accel->y;- m_locoInfo->m_accelerationRollRate += -(LATERAL_ACCEL_COEFF * lateralAccel);- }+ // compute total pitch and roll of tank: terrain, weapon recoil, and the lean calcPhysicsXformGround worked out+ info.m_totalPitch = m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch + m_locoInfo->m_groundLeanPitch;+ info.m_totalRoll = m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll + m_locoInfo->m_groundLeanRoll;#ifdef RECOIL_FROM_BEING_DAMAGED// recoil from being hit@@ -2132,9 +2222,7 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformIconst Real ROLL_STIFFNESS = locomotor->getRollStiffness();const Real PITCH_DAMPING = locomotor->getPitchDamping();const Real ROLL_DAMPING = locomotor->getRollDamping();- const Real FORWARD_ACCEL_COEFF = locomotor->getForwardAccelCoef();- const Real LATERAL_ACCEL_COEFF = locomotor->getLateralAccelCoef();- const Real UNIFORM_AXIAL_DAMPING = locomotor->getUniformAxialDamping();+ const Real UNIFORM_AXIAL_DAMPING = locomotor->getUniformAxialDamping();const Real MAX_SUSPENSION_EXTENSION = locomotor->getMaxWheelExtension(); //-2.3f;// const Real MAX_SUSPENSION_COMPRESSION = locomotor->getMaxWheelCompression(); //1.4f;@@ -2159,7 +2247,6 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformI// get our position and direction vectorconst Coord3D *pos = getPosition();const Coord3D *dir = getUnitDirectionVector2D();- const Coord3D *accel = physics->getAcceleration();// compute perpendicular (2d)Coord3D perp;@@ -2179,18 +2266,18 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformIBool airborne = obj->isSignificantlyAboveTerrain();- if (airborne)+ if (airborne){- if (DO_WHEELS)- {+ if (DO_WHEELS)+ {// Wheels extend when airborne.m_locoInfo->m_wheelInfo.m_framesAirborne = 0;m_locoInfo->m_wheelInfo.m_framesAirborneCounter++;- if (pos->z - hheight > -MAX_SUSPENSION_EXTENSION)+ if (pos->z - hheight > -MAX_SUSPENSION_EXTENSION){m_locoInfo->m_wheelInfo.m_rearLeftHeightOffset += (MAX_SUSPENSION_EXTENSION - m_locoInfo->m_wheelInfo.m_rearLeftHeightOffset)/2.0f;m_locoInfo->m_wheelInfo.m_rearRightHeightOffset += (MAX_SUSPENSION_EXTENSION - m_locoInfo->m_wheelInfo.m_rearRightHeightOffset)/2.0f;- }+ }else{m_locoInfo->m_wheelInfo.m_rearLeftHeightOffset += (0 - m_locoInfo->m_wheelInfo.m_rearLeftHeightOffset)/2.0f;@@ -2255,7 +2342,7 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformIm_locoInfo->m_pitch += m_locoInfo->m_pitchRate * UNIFORM_AXIAL_DAMPING;m_locoInfo->m_roll += m_locoInfo->m_rollRate * UNIFORM_AXIAL_DAMPING;- // process chassis acceleration dynamics - damp back towards zero+ // process chassis recoil dynamics - damp back towards zerom_locoInfo->m_accelerationPitchRate += ((-PITCH_STIFFNESS * (m_locoInfo->m_accelerationPitch)) + (-PITCH_DAMPING * m_locoInfo->m_accelerationPitchRate)); // spring/damperm_locoInfo->m_accelerationPitch += m_locoInfo->m_accelerationPitchRate;@@ -2263,21 +2350,11 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformIm_locoInfo->m_accelerationRollRate += ((-ROLL_STIFFNESS * m_locoInfo->m_accelerationRoll) + (-ROLL_DAMPING * m_locoInfo->m_accelerationRollRate)); // spring/damperm_locoInfo->m_accelerationRoll += m_locoInfo->m_accelerationRollRate;- // compute total pitch and roll of tank- info.m_totalPitch = m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch;- info.m_totalRoll = m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll;-- if (physics->isMotive())- {- // cause the chassis to pitch & roll in reaction to acceleration/deceleration- Real forwardAccel = dir->x * accel->x + dir->y * accel->y;- m_locoInfo->m_accelerationPitchRate += -(FORWARD_ACCEL_COEFF * forwardAccel);+ // compute total pitch and roll: terrain, weapon recoil, and the lean calcPhysicsXformGround worked out+ info.m_totalPitch = m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch + m_locoInfo->m_groundLeanPitch;+ info.m_totalRoll = m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll + m_locoInfo->m_groundLeanRoll;- Real lateralAccel = -dir->y * accel->x + dir->x * accel->y;- m_locoInfo->m_accelerationRollRate += -(LATERAL_ACCEL_COEFF * lateralAccel);- }-- // limit acceleration pitch and roll+ // limit recoil pitch and rollif (m_locoInfo->m_accelerationPitch > DECEL_PITCH_LIMIT)m_locoInfo->m_accelerationPitch = DECEL_PITCH_LIMIT;@@ -2296,8 +2373,8 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformIReal width = obj->getGeometryInfo().getMinorRadius();Real pitchHeight = length*Sin(info.m_totalPitch-groundPitch);Real rollHeight = width*Sin(info.m_totalRoll-groundRoll);- if (DO_WHEELS)- {+ if (DO_WHEELS)+ {// calculate each wheel positionm_locoInfo->m_wheelInfo.m_framesAirborne = m_locoInfo->m_wheelInfo.m_framesAirborneCounter;m_locoInfo->m_wheelInfo.m_framesAirborneCounter = 0;@@ -2317,11 +2394,11 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformI/////@todo Steven/John ... please review this and make sure it makes sense (CBD)- // we're going to add the angle to the current wheel rotation ... but we're going to+ // we're going to add the angle to the current wheel rotation ... but we're going to// divide that number to add small angles. This allows for "smoother" wheel turning// transitions ... and when the AI has things move in a straight line, since it's// constantly telling the object to go left, go straight, go right, go straight,- // etc, this smaller angle we'll be adding covers the constant wheel shifting+ // etc, this smaller angle we'll be adding covers the constant wheel shifting// left and right when moving in a relatively straight line//#define WHEEL_SMOOTHNESS 10.0f // higher numbers add smaller angles, make it more "smooth"@@ -2427,9 +2504,7 @@ void Drawable::calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXfconst Real ROLL_STIFFNESS = locomotor->getRollStiffness();const Real PITCH_DAMPING = locomotor->getPitchDamping();const Real ROLL_DAMPING = locomotor->getRollDamping();- const Real FORWARD_ACCEL_COEFF = locomotor->getForwardAccelCoef();- const Real LATERAL_ACCEL_COEFF = locomotor->getLateralAccelCoef();- const Real UNIFORM_AXIAL_DAMPING = locomotor->getUniformAxialDamping();+ const Real UNIFORM_AXIAL_DAMPING = locomotor->getUniformAxialDamping();const Real MAX_SUSPENSION_EXTENSION = locomotor->getMaxWheelExtension(); //-2.3f;// const Real MAX_SUSPENSION_COMPRESSION = locomotor->getMaxWheelCompression(); //1.4f;@@ -2454,7 +2529,6 @@ void Drawable::calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXf// get our position and direction vectorconst Coord3D *pos = getPosition();const Coord3D *dir = getUnitDirectionVector2D();- const Coord3D *accel = physics->getAcceleration();// compute perpendicular (2d)Coord3D perp;@@ -2495,7 +2569,7 @@ void Drawable::calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXf// Calculate suspension info.Real length = obj->getGeometryInfo().getMajorRadius();//Real width = obj->getGeometryInfo().getMinorRadius();- Real pitchHeight = length*Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch);+ Real pitchHeight = length*Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch + m_locoInfo->m_groundLeanPitch - groundPitch);//Real rollHeight = width*Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll);info.m_totalZ = fabs(pitchHeight)/4;// + fabs(rollHeight)/4;//return; // maintain the same orientation while we fly through the air.@@ -2561,8 +2635,8 @@ void Drawable::calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXfm_locoInfo->m_accelerationRollRate += ((-ROLL_STIFFNESS * m_locoInfo->m_accelerationRoll) + (-ROLL_DAMPING * m_locoInfo->m_accelerationRollRate)); // spring/damperm_locoInfo->m_accelerationRoll += m_locoInfo->m_accelerationRollRate;- // compute total pitch and roll of tank- info.m_totalPitch = m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch;+ // compute total pitch and roll: terrain, weapon recoil, and the lean calcPhysicsXformGround worked out+ info.m_totalPitch = m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch + m_locoInfo->m_groundLeanPitch;// THis logic had recently been added to Drawable::applyPhysicsXform(), which was naughty, since it clamped the roll in every drawable in the game@@ -2570,20 +2644,6 @@ void Drawable::calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXfReal unclampedRoll = m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll;info.m_totalRoll = (unclampedRoll > 0.5f && unclampedRoll < -0.5f ? unclampedRoll : 0.0f);- if( airborne )- {- }-- if (physics->isMotive())- {- // cause the chassis to pitch & roll in reaction to acceleration/deceleration- Real forwardAccel = dir->x * accel->x + dir->y * accel->y;- m_locoInfo->m_accelerationPitchRate += -(FORWARD_ACCEL_COEFF * forwardAccel);-- Real lateralAccel = -dir->y * accel->x + dir->x * accel->y;- m_locoInfo->m_accelerationRollRate += -(LATERAL_ACCEL_COEFF * lateralAccel);- }-// limit acceleration pitch and rollif (m_locoInfo->m_accelerationPitch > DECEL_PITCH_LIMIT)diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.hindex a3932872c..6819222fa 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h@@ -462,6 +462,8 @@ protected:Real getCurAnimDistanceCovered() const;Bool setCurAnimDurationInMsec(Real duration);+ UnsignedInt stepGroundMotion(Real& forward, Real& turn); ///< distance driven along the heading and angle turned since the last call; returns the logic frames between+inline Bool getFullyObscuredByShroud() const { return m_fullyObscuredByShroud; }@@ -511,6 +513,9 @@ private:Int m_whichAnimInCurState; ///< the index of the currently playing anim in cur state (if any)WeaponRecoilInfoVec m_weaponRecoilInfoVec[WEAPONSLOT_COUNT];Bool m_needRecalcBoneParticleSystems;+ Coord3D m_groundMotionPos; ///< where stepGroundMotion last saw the unit+ Real m_groundMotionAngle;+ UnsignedInt m_groundMotionFrame; ///< and on which logic frame, 0 before the first callBool m_fullyObscuredByShroud;Bool m_shadowEnabled; ///< cached state of shadow. Used to determine if shadows should be enabled via options screen.Bool m_hasModelShadow; ///< this drawable's shape is being cast by the tree buffer, so it wants no decal of its owndiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankDraw.hindex 3354bc42f..78ea40425 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankDraw.h@@ -48,9 +48,9 @@ public:AsciiString m_treadDebrisNameLeft;AsciiString m_treadDebrisNameRight;- Real m_treadAnimationRate; ///<amount of tread texture to scroll per sec. 1.0 == full width.- Real m_treadPivotSpeedFraction; ///<fraction of locomotor speed below which we allow pivoting.- Real m_treadDriveSpeedFraction; ///<fraction of locomotor speed below which treads stop animating.+ Real m_treadAnimationRate; ///<amount of tread texture to scroll per sec at top speed. 1.0 == full width.+ Real m_treadPivotSpeedFraction; ///<no longer read: the treads follow the ground. Kept so the INI key parses.+ Real m_treadDriveSpeedFraction; ///<no longer read either.W3DTankDrawModuleData();~W3DTankDrawModuleData();@@ -96,7 +96,6 @@ protected:TreadObjectInfo m_treads[MAX_TREADS_PER_TANK];Int m_treadCount;- Coord3D m_lastDirection; ///< orientation of tank last time it was drawn.void createEmitters( void ); ///< Create particle effects.void tossEmitters( void ); ///< Create particle effects.@@ -104,7 +103,6 @@ protected:void startMoveDebris( void ); ///< start creating debris from the tank treadsvoid stopMoveDebris( void ); ///< stop creating debris from the tank treadsvoid updateTreadObjects(void); ///< update pointers to sub-objects like treads.- void updateTreadPositions(Real uvDelta); ///< update uv coordinates on each tread};#endif // _W3D_TANK_DRAW_H_diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankTruckDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankTruckDraw.hindex 06db5b823..bebf4ca4e 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankTruckDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankTruckDraw.h@@ -67,9 +67,9 @@ public:AsciiString m_treadDebrisNameLeft;AsciiString m_treadDebrisNameRight;- Real m_treadAnimationRate; ///<amount of tread texture to scroll per sec. 1.0 == full width.- Real m_treadPivotSpeedFraction; ///<fraction of locomotor speed below which we allow pivoting.- Real m_treadDriveSpeedFraction; ///<fraction of locomotor speed below which treads stop animating.+ Real m_treadAnimationRate; ///<amount of tread texture to scroll per sec at top speed. 1.0 == full width.+ Real m_treadPivotSpeedFraction; ///<no longer read: the treads follow the ground. Kept so the INI key parses.+ Real m_treadDriveSpeedFraction; ///<no longer read either.W3DTankTruckDrawModuleData();~W3DTankTruckDrawModuleData();@@ -151,7 +151,6 @@ protected:void startMoveDebris( void ); ///< start creating debris from the tank treadsvoid stopMoveDebris( void ); ///< stop creating debris from the tank treadsvoid updateTreadObjects(void); ///< update pointers to sub-objects like treads.- void updateTreadPositions(Real uvDelta); ///< update uv coordinates on each tread};#endif // _W3D_TANKTRUCK_DRAW_H_diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cppindex 308b1134b..12d5b950e 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp@@ -1762,6 +1762,9 @@ W3DModelDraw::W3DModelDraw(Thing *thing, const ModuleData* moduleData) : DrawMod}m_needRecalcBoneParticleSystems = false;m_fullyObscuredByShroud = false;+ m_groundMotionPos.zero();+ m_groundMotionAngle = 0.0f;+ m_groundMotionFrame = 0;// only validate the current time-of-day and weather conditions by default.getW3DModelDrawModuleData()->validateStuffForTimeAndWeather(getDrawable(),@@ -2534,6 +2537,34 @@ Bool W3DModelDraw::setCurAnimDurationInMsec(Real desiredDurationInMsec)return false;}+//-------------------------------------------------------------------------------------------------+/** How far the unit has driven along its own heading, and how far it has turned, since the last+ * call, read off the position and heading the logic left. A wheel or a tread turned by these+ * amounts keeps pace with the ground however many pictures a logic frame gets, and runs backwards+ * when the unit backs up. Returns how many logic frames went by, 0 between two of them. */+//-------------------------------------------------------------------------------------------------+UnsignedInt W3DModelDraw::stepGroundMotion(Real& forward, Real& turn)+{+ const Coord3D *pos = getDrawable()->getPosition();+ Real angle = getDrawable()->getOrientation();+ UnsignedInt now = TheGameLogic->getFrame();+ if (m_groundMotionFrame == 0)+ {+ m_groundMotionPos = *pos;+ m_groundMotionAngle = angle;+ m_groundMotionFrame = now;+ }++ forward = (pos->x - m_groundMotionPos.x) * Cos(angle) + (pos->y - m_groundMotionPos.y) * Sin(angle);+ turn = stdAngleDiff(angle, m_groundMotionAngle);+ UnsignedInt frames = now - m_groundMotionFrame;++ m_groundMotionPos = *pos;+ m_groundMotionAngle = angle;+ m_groundMotionFrame = now;+ return frames;+}+//-------------------------------------------------------------------------------------------------Real W3DModelDraw::getCurAnimDistanceCovered() const{diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cppindex cede275a5..986576356 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp@@ -41,6 +41,7 @@#include "GameLogic/Module/PhysicsUpdate.h"#include "GameLogic/Module/BodyModule.h"#include "GameLogic/ScriptEngine.h"+#include "GameLogic/Locomotor.h"#include "GameLogic/Module/AIUpdate.h"#include "GameClient/Drawable.h"#include "GameClient/ParticleSys.h"@@ -100,10 +101,6 @@ W3DTankDraw::W3DTankDraw( Thing *thing, const ModuleData* moduleData )m_treads[i].m_robj = NULL;m_treadCount=0;- //Assume all things face along x axis when created.- m_lastDirection.x=1.0f;- m_lastDirection.y=0.0f;- m_lastDirection.z=0.0f;createEmitters();}@@ -219,27 +216,6 @@ void W3DTankDraw::setFullyObscuredByShroud(Bool fullyObscured)W3DModelDraw::setFullyObscuredByShroud(fullyObscured);}-/**Update uv coordinates on each tread object to simulate movement*/-void W3DTankDraw::updateTreadPositions(Real uvDelta)-{- Real offset_u;- TreadObjectInfo *pTread=m_treads;-- for (Int i=0; i<m_treadCount; i++)- {- if (pTread->m_type == TREAD_LEFT) //this tread needs to scroll forwards- offset_u = pTread->m_materialSettings.customUVOffset.X + uvDelta;- else- if (pTread->m_type == TREAD_RIGHT) //this tread needs to scroll backwards- offset_u = pTread->m_materialSettings.customUVOffset.X - uvDelta;-- // ensure coordinates of offset are in [0, 1] range:- offset_u = offset_u - WWMath::Floor(offset_u);- pTread->m_materialSettings.customUVOffset.Set(offset_u,0);- pTread++;- }-}-/**Grab pointers to the sub-meshes for each tread*/void W3DTankDraw::updateTreadObjects(void){@@ -359,47 +335,32 @@ void W3DTankDraw::doDrawModule(const Matrix3D* transformMtx)m_treadDebrisLeft->setBurstCountMultiplier( velMult.z );m_treadDebrisRight->setBurstCountMultiplier( velMult.z );- //Update movement of treads- if (m_treadCount)+ /* EA scrolled the treads by TreadAnimationRate every drawn frame once the tank passed a share of+ its top speed, which at 120 pictures a second ran them four times too fast, never backwards, and+ both at once in a turn. Each tread now runs over exactly the ground it covered: the distance+ driven, less or plus the turn times half the track width, at TreadAnimationRate per top speed's+ worth of distance. A pivot runs them against each other, a reverse runs them backwards. */+ Real forward, turn;+ stepGroundMotion(forward, turn);+ // undamaged top speed: a damaged tank is slower, and its treads still have to match the ground+ const Locomotor *loco = obj->getAIUpdateInterface()->getCurLocomotor();+ Real maxSpeed = loco ? loco->getMaxSpeedForCondition(BODY_PRISTINE) : 0.0f;+ if (m_treadCount && maxSpeed > 0.0f){- PhysicsTurningType turn=physics->getTurning();- Real offset_u;- Real treadScrollSpeed=getW3DTankDrawModuleData()->m_treadAnimationRate;+ Real uvPerDistance = getW3DTankDrawModuleData()->m_treadAnimationRate / maxSpeed;+ Real sideways = turn * obj->getGeometryInfo().getMinorRadius();TreadObjectInfo *pTread=m_treads;- Real maxSpeed=obj->getAIUpdateInterface()->getCurLocomotorSpeed();-- //For optimization sake, we only do complex tread scrolling when tank- //is mostly stationary and turning- if (turn != TURN_NONE && physics->getVelocityMagnitude()/maxSpeed < getW3DTankDrawModuleData()->m_treadPivotSpeedFraction)+ for (Int i=0; i<m_treadCount; i++, pTread++){- //Check if we have turned enough since last draw to require animation- Coord3D dir;- obj->getUnitDirectionVector2D(dir);- Real angleToGoal = dir.x * m_lastDirection.x + dir.y * m_lastDirection.y;-- if (fabs(1.0f-angleToGoal) > 0.00001f) //check if difference in angle cosines is greater than some cutoff.- {- if (turn == TURN_NEGATIVE) //turning right- updateTreadPositions(-treadScrollSpeed);- else //turning left- updateTreadPositions(treadScrollSpeed);- }- m_lastDirection=dir; //update for next frame- }- else- if (physics->isMotive() && physics->getVelocityMagnitude()/maxSpeed >= getW3DTankDrawModuleData()->m_treadDriveSpeedFraction)- { //do simple scrolling based only on speed when tank is moving straight at high speed.- //we stop scrolling when tank slows down to reduce the appearance of sliding- //tread scrolling speed was not directly tied into tank velocity because it looked odd- //under certain situations when tank moved sideways.- for (Int i=0; i<m_treadCount; i++)- {- offset_u = pTread->m_materialSettings.customUVOffset.X - treadScrollSpeed;- // ensure coordinates of offset are in [0, 1] range:- offset_u = offset_u - WWMath::Floor(offset_u);- pTread->m_materialSettings.customUVOffset.Set(offset_u,0);- pTread++;- }+ Real distance = forward;+ if (pTread->m_type == TREAD_LEFT)+ distance -= sideways;+ else if (pTread->m_type == TREAD_RIGHT)+ distance += sideways;+ Real offset_u = pTread->m_materialSettings.customUVOffset.X - uvPerDistance * distance;+ // ensure coordinates of offset are in [0, 1] range:+ offset_u = offset_u - WWMath::Floor(offset_u);+ pTread->m_materialSettings.customUVOffset.Set(offset_u,0);}}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cppindex d5b9c2214..69b425a8e 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp@@ -42,6 +42,7 @@#include "GameLogic/Module/PhysicsUpdate.h"#include "GameLogic/Module/BodyModule.h"#include "GameLogic/ScriptEngine.h"+#include "GameLogic/Locomotor.h"#include "GameLogic/Module/AIUpdate.h"#include "GameClient/Drawable.h"#include "GameClient/ParticleSys.h"@@ -400,30 +401,6 @@ void W3DTankTruckDraw::setHidden(Bool h)}}-/**Update uv coordinates on each tread object to simulate movement*/-void W3DTankTruckDraw::updateTreadPositions(Real uvDelta)-{- Real offset_u;- TreadObjectInfo *pTread=m_treads;-- for (Int i=0; i<m_treadCount; i++)- {- if (pTread->m_type == TREAD_MIDDLE) //this tread needs to scroll backwards- offset_u = pTread->m_materialSettings.customUVOffset.X + uvDelta;- else- if (pTread->m_type == TREAD_LEFT) //this tread needs to scroll forwards- offset_u = pTread->m_materialSettings.customUVOffset.X + uvDelta;- else- if (pTread->m_type == TREAD_RIGHT) //this tread needs to scroll backwards- offset_u = pTread->m_materialSettings.customUVOffset.X - uvDelta;-- // ensure coordinates of offset are in [0, 1] range:- offset_u = offset_u - WWMath::Floor(offset_u);- pTread->m_materialSettings.customUVOffset.Set(offset_u,0);- pTread++;- }-}-/**Grab pointers to the sub-meshes for each tread*/void W3DTankTruckDraw::updateTreadObjects(void){@@ -537,20 +514,22 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx)const Coord3D *vel = physics->getVelocity();Real speed = physics->getVelocityMagnitude();+ // wheels and treads turn by the ground covered since the last picture, not by speed every picture+ Real forward, turn;+ UnsignedInt frames = stepGroundMotion(forward, turn);const TWheelInfo *wheelInfo = getDrawable()->getWheelInfo(); // note, can return null!- if (wheelInfo && (m_frontLeftTireBone || m_rearLeftTireBone))+ if (wheelInfo && (m_frontLeftTireBone || m_rearLeftTireBone)){- static Real rotation = 0;const Real rotationFactor = getW3DTankTruckDrawModuleData()->m_rotationSpeedMultiplier;- m_frontWheelRotation += rotationFactor*speed;- if (m_isPowersliding)+ m_frontWheelRotation += rotationFactor*forward;+ if (m_isPowersliding){- m_rearWheelRotation += rotationFactor*(speed+getW3DTankTruckDrawModuleData()->m_powerslideRotationAddition);- }- else+ m_rearWheelRotation += rotationFactor*(forward + frames*getW3DTankTruckDrawModuleData()->m_powerslideRotationAddition);+ }+ else{- m_rearWheelRotation += rotationFactor*speed;+ m_rearWheelRotation += rotationFactor*forward;}Matrix3D wheelXfrm(1);if (m_frontLeftTireBone)@@ -707,38 +686,20 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx)m_treadDebrisLeft->setBurstCountMultiplier( velMult.z );m_treadDebrisRight->setBurstCountMultiplier( velMult.z );#endif- //Update movement of treads- if (m_treadCount)+ //Update movement of treads: these vehicles steer with their wheels, so every tread runs over the+ //distance driven, at TreadAnimationRate per top speed's worth of it, and backwards in reverse.+ const Locomotor *loco = obj->getAIUpdateInterface()->getCurLocomotor();+ Real maxSpeed = loco ? loco->getMaxSpeedForCondition(BODY_PRISTINE) : 0.0f;+ if (m_treadCount && maxSpeed > 0.0f){- Real offset_u;- Real treadScrollSpeed=getW3DTankTruckDrawModuleData()->m_treadAnimationRate;+ Real uvDelta = getW3DTankTruckDrawModuleData()->m_treadAnimationRate * forward / maxSpeed;TreadObjectInfo *pTread=m_treads;- Real maxSpeed=obj->getAIUpdateInterface()->getCurLocomotorSpeed();-/* Commented out because these vehicles are presumed not to turn via treads.- PhysicsTurningType turn=physics->getTurning();- //For optimization sake, we only do complex tread scrolling when tank- //is mostly stationary and turning- if ((turn=physics->getTurning()) != TURN_NONE && physics->getSpeed()/maxSpeed < getW3DTankTruckDrawModuleData()->m_treadPivotSpeedFraction)+ for (Int i=0; i<m_treadCount; i++, pTread++){- if (turn == TURN_NEGATIVE) //turning right- updateTreadPositions(-treadScrollSpeed);- else //turning left- updateTreadPositions(treadScrollSpeed);- }- else*/- if (physics->isMotive() && physics->getVelocityMagnitude()/maxSpeed >= getW3DTankTruckDrawModuleData()->m_treadDriveSpeedFraction)- { //do simple scrolling based only on speed when tank is moving straight at high speed.- //we stop scrolling when tank slows down to reduce the appearance of sliding- //tread scrolling speed was not directly tied into tank velocity because it looked odd- //under certain situations when tank moved sideways.- for (Int i=0; i<m_treadCount; i++)- {- offset_u = pTread->m_materialSettings.customUVOffset.X - treadScrollSpeed;- // ensure coordinates of offset are in [0, 1] range:- offset_u = offset_u - WWMath::Floor(offset_u);- pTread->m_materialSettings.customUVOffset.Set(offset_u,0);- pTread++;- }+ Real offset_u = pTread->m_materialSettings.customUVOffset.X - uvDelta;+ // ensure coordinates of offset are in [0, 1] range:+ offset_u = offset_u - WWMath::Floor(offset_u);+ pTread->m_materialSettings.customUVOffset.Set(offset_u,0);}}}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTruckDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTruckDraw.cppindex 75e4e4f67..61a385f6c 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTruckDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTruckDraw.cpp@@ -423,6 +423,12 @@ void W3DTruckDraw::doDrawModule(const Matrix3D* transformMtx)const Coord3D *vel = physics->getVelocity();Real speed = physics->getVelocityMagnitude();+ // wheels turn by the ground covered since the last picture, and the cab and trailer swing once a+ // logic frame: both used to step every picture, four times as fast at 120 a second+ Real forward, turn;+ UnsignedInt frames = stepGroundMotion(forward, turn);+ Real swing = 1.0f - pow(1.0f - moduleData->m_rotationDampingFactor, (Real)frames);+const TWheelInfo *wheelInfo = getDrawable()->getWheelInfo(); // note, can return null!AIUpdateInterface *ai = obj->getAI();if (m_cabBone && wheelInfo) {@@ -448,7 +454,7 @@ void W3DTruckDraw::doDrawModule(const Matrix3D* transformMtx)}Real deltaAngle = desiredAngle - m_curCabRotation;- deltaAngle *= moduleData->m_rotationDampingFactor;+ deltaAngle *= swing;m_curCabRotation += deltaAngle;cabXfrm.Rotate_Z(m_curCabRotation);getRenderObject()->Capture_Bone( m_cabBone );@@ -456,7 +462,7 @@ void W3DTruckDraw::doDrawModule(const Matrix3D* transformMtx)if (m_trailerBone && wheelInfo) {desiredAngle = -wheelInfo->m_wheelAngle*moduleData->m_trailerRotationFactor;Real deltaAngle = desiredAngle - m_curTrailerRotation;- deltaAngle *= moduleData->m_rotationDampingFactor;+ deltaAngle *= swing;m_curTrailerRotation += deltaAngle;cabXfrm.Make_Identity();cabXfrm.Rotate_Z(m_curTrailerRotation);@@ -467,25 +473,18 @@ void W3DTruckDraw::doDrawModule(const Matrix3D* transformMtx)if (m_frontLeftTireBone || m_rearLeftTireBone){- Real powerslideRotationAddition = moduleData->m_powerslideRotationAddition;- if (ai) {- Locomotor *loco = ai->getCurLocomotor();- if (loco) {- if (loco->isMovingBackwards()) {- speed = -speed; // rotate wheels backwards. jba.- powerslideRotationAddition = -powerslideRotationAddition;- }- }- }+ Real powerslideRotationAddition = frames * moduleData->m_powerslideRotationAddition;+ if (forward < 0.0f)+ powerslideRotationAddition = -powerslideRotationAddition; // rotate wheels backwards. jba.const Real rotationFactor = moduleData->m_rotationSpeedMultiplier;- m_frontWheelRotation += rotationFactor*speed;- if (m_isPowersliding)+ m_frontWheelRotation += rotationFactor*forward;+ if (m_isPowersliding){- m_rearWheelRotation += rotationFactor*(speed + powerslideRotationAddition);- }- else+ m_rearWheelRotation += rotationFactor*(forward + powerslideRotationAddition);+ }+ else{- m_rearWheelRotation += rotationFactor*speed;+ m_rearWheelRotation += rotationFactor*forward;}// For now, just use the same values for mid wheels -- may want to do independent calcs later...