[Scummvm-git-logs] scummvm master -> 21dec1ac3e0afd18b589f1e77fdb4b82620baa08
aquadran
noreply at scummvm.org
Fri Nov 27 16:37:01 UTC 2026
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
21dec1ac3e GRIM/EMI: Update turning logic to match the original engine
Commit: 21dec1ac3e0afd18b589f1e77fdb4b82620baa08
https://github.com/scummvm/scummvm/commit/21dec1ac3e0afd18b589f1e77fdb4b82620baa08
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2026-11-27T17:36:55+01:00
Commit Message:
GRIM/EMI: Update turning logic to match the original engine
The actor's body now eases after its heading the way the original
engines do: by the turn rate plus a tenth of the angle that is left.
Smooth turning starts once the original would have made a walker for
the actor, the first time it walks, turns, or follows boxes. Before
that, SetActorRot sets the rotation at once.
GRIM:
Before, we were guessing at a turn rate multiplier. It got us
correct-looking results, but it is now replaced by the smoothing from
the original engine. TurnActor only takes the key once the body is
within two steps of the heading, and the rest chore fades in and out
with walking and turning, as in the original. Nothing in Grim seems to
rely on this behavior that I could find, but turning looks smoother.
EMI:
The bartender in the SCUMM bar relies on turn snapping. Without it, he
slowly turns when entering the bar.
We had a specific hack for the Voodoo lady, but the game scripts were
really asking for the turn smoothing we were missing.
We had a specific case for the darts players in the SCUMM bar turning
to see Guybrush. With these changes, it is no longer needed.
EnableActorPuck now turns smooth turning on and off.
Bumps the savegame version to 32.
Changed paths:
engines/grim/actor.cpp
engines/grim/actor.h
engines/grim/emi/lua_v2.h
engines/grim/emi/lua_v2_actor.cpp
engines/grim/lua_v1_actor.cpp
engines/grim/savegame.cpp
diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp
index 6e8fe7e4db8..5320df417d6 100644
--- a/engines/grim/actor.cpp
+++ b/engines/grim/actor.cpp
@@ -82,12 +82,13 @@ Actor::Actor() :
_talkColor(255, 255, 255), _pos(0, 0, 0),
_lookingMode(false), _followBoxes(false), _running(false),
_pitch(0), _yaw(0), _roll(0), _walkRate(0.3f),
- _turnRateMultiplier(0.f), _talkAnim(0),
+ _talkAnim(0),
_reflectionAngle(80), _scale(1.f), _timeScale(1.f),
- _visible(true), _lipSync(nullptr), _turning(false), _singleTurning(false), _pathWalking(false),
+ _visible(true), _lipSync(nullptr), _pathWalking(false),
_walkedLast(false), _walkedCur(false),
_collisionMode(CollisionOff), _collisionScale(1.f),
_lastTurnDir(0), _currTurnDir(0),
+ _smoothTurns(false), _yawLeft(0.f),
_sayLineText(0),
_attachedActor(0), _attachedJoint(""),
_globalAlpha(1.f), _alphaMode(AlphaOff),
@@ -136,7 +137,6 @@ void Actor::saveState(SaveGame *savedState) const {
savedState->writeFloat(_roll.getDegrees());
savedState->writeFloat(_walkRate);
savedState->writeFloat(_turnRate);
- savedState->writeFloat(_turnRateMultiplier);
savedState->writeBool(_followBoxes);
savedState->writeFloat(_reflectionAngle);
savedState->writeBool(_visible);
@@ -179,13 +179,13 @@ void Actor::saveState(SaveGame *savedState) const {
c->saveState(savedState);
}
- savedState->writeBool(_turning);
- savedState->writeBool(_singleTurning);
savedState->writeFloat(_moveYaw.getDegrees());
savedState->writeFloat(_movePitch.getDegrees());
savedState->writeFloat(_moveRoll.getDegrees());
savedState->writeBool(_pathWalking);
+ savedState->writeBool(_smoothTurns);
+ savedState->writeFloat(_yawLeft);
savedState->writeVector3d(_destPos);
_restChore.saveState(savedState);
@@ -292,10 +292,9 @@ bool Actor::restoreState(SaveGame *savedState) {
_roll = savedState->readFloat();
_walkRate = savedState->readFloat();
_turnRate = savedState->readFloat();
- if (savedState->saveMinorVersion() > 6) {
- _turnRateMultiplier = savedState->readFloat();
- } else {
- _turnRateMultiplier = 1.f;
+ if (savedState->saveMinorVersion() > 6 && savedState->saveMinorVersion() < 32) {
+ // Removed turn rate multiplier
+ savedState->readFloat();
}
_followBoxes = savedState->readBool();
_reflectionAngle = savedState->readFloat();
@@ -349,9 +348,11 @@ bool Actor::restoreState(SaveGame *savedState) {
_costumeStack.push_back(c);
}
- _turning = savedState->readBool();
- if (savedState->saveMinorVersion() > 25) {
- _singleTurning = savedState->readBool();
+ if (savedState->saveMinorVersion() < 32) {
+ // Older saves have the turning flags here
+ savedState->readBool();
+ if (savedState->saveMinorVersion() > 25)
+ savedState->readBool();
}
_moveYaw = savedState->readFloat();
if (savedState->saveMinorVersion() > 6) {
@@ -363,6 +364,15 @@ bool Actor::restoreState(SaveGame *savedState) {
}
_pathWalking = savedState->readBool();
+ if (savedState->saveMinorVersion() > 31) {
+ _smoothTurns = savedState->readBool();
+ _yawLeft = savedState->readFloat();
+ } else {
+ _smoothTurns = _followBoxes || _pathWalking;
+ if (!_smoothTurns)
+ _moveYaw = _yaw;
+ _yawLeft = 0.f;
+ }
_destPos = savedState->readVector3d();
_restChore.restoreState(savedState, this);
@@ -499,18 +509,13 @@ bool Actor::restoreState(SaveGame *savedState) {
return true;
}
-void Actor::setRot(const Math::Vector3d &pos) {
- Math::Angle y, p, r;
- calculateOrientation(pos, &p, &y, &r);
- setRot(p, y, r);
-}
-
void Actor::setRot(const Math::Angle &pitchParam, const Math::Angle &yawParam, const Math::Angle &rollParam) {
_pitch = pitchParam;
_yaw = yawParam;
- _moveYaw = _yaw;
_roll = rollParam;
- _turning = false;
+ _moveYaw = _yaw;
+ _movePitch = _pitch;
+ _moveRoll = _roll;
}
void Actor::setPos(const Math::Vector3d &position) {
@@ -567,40 +572,112 @@ void Actor::calculateOrientation(const Math::Vector3d &pos, Math::Angle *pitch,
}
}
-void Actor::turnTo(const Math::Vector3d &pos, bool snap) {
+void Actor::turnTo(const Math::Vector3d &pos) {
+ Math::Angle y, p, r;
+ calculateOrientation(pos, &p, &y, &r);
+ _movePitch = p;
+ _moveRoll = r;
+ turnToYaw(y);
+}
+
+void Actor::setSmoothTurns(bool smooth) {
+ if (smooth && !_smoothTurns) {
+ _moveYaw = _yaw;
+ _movePitch = _pitch;
+ _moveRoll = _roll;
+ }
+ if (!smooth)
+ _yawLeft = 0.f;
+ _smoothTurns = smooth;
+}
+
+void Actor::setRotFromScript(const Math::Angle &pitchParam, const Math::Angle &yawParam, const Math::Angle &rollParam, bool smooth) {
+ _pathWalking = false;
+ if (_smoothTurns) {
+ if (g_grim->getGameType() == GType_GRIM) {
+ Math::Angle d = yawParam - _moveYaw;
+ d.normalize(-180);
+ _yawLeft = ABS(d.getDegrees());
+ } else {
+ _yawLeft = yawParam.getDegrees() - _yaw.getDegrees();
+ }
+ }
+ if (!_smoothTurns || !smooth) {
+ setRot(pitchParam, yawParam, rollParam);
+ return;
+ }
+
+ _pitch = _movePitch = pitchParam;
+ _roll = _moveRoll = rollParam;
+ turnToYaw(yawParam);
+}
+
+void Actor::pointAt(const Math::Vector3d &pos) {
Math::Angle y, p, r;
calculateOrientation(pos, &p, &y, &r);
- turnTo(p, y, r, snap);
+ setSmoothTurns(true);
+ setRot(_pitch, y, _roll);
}
bool Actor::singleTurnTo(const Math::Vector3d &pos) {
+ setSmoothTurns(true);
Math::Angle y, p, r;
calculateOrientation(pos, &p, &y, &r);
+ _movePitch = p;
+ _moveRoll = r;
- float turnAmt = g_grim->getPerSecond(_turnRate) * _timeScale;
- bool done = animTurn(turnAmt, y, &_yaw) == 0;
- done = animTurn(turnAmt, p, &_pitch) == 0 && done;
- done = animTurn(turnAmt, r, &_roll) == 0 && done;
- _moveYaw = _yaw;
- _movePitch = _pitch;
- _moveRoll = _roll;
- _singleTurning = !done;
+ // The original engines ignore time scale here
+ float maxStep = g_grim->getPerSecond(_turnRate);
+ Math::Angle step = turnHeadingToYaw(y, maxStep);
+ return ABS(step.getDegrees()) < maxStep;
+}
- return done;
+Math::Angle Actor::turnHeadingToYaw(const Math::Angle &yaw, float maxStep) {
+ float step;
+ if (g_grim->getGameType() == GType_GRIM) {
+ Math::Angle d = yaw - _moveYaw;
+ d.normalize(-180);
+ step = MIN(ABS(d.getDegrees()), maxStep);
+ if (d < 0)
+ step = -step;
+ } else {
+ Math::Angle a = yaw;
+ Math::Angle b = _moveYaw;
+ a.normalize(0);
+ b.normalize(0);
+ step = a.getDegrees() - b.getDegrees();
+ if (step > 180.f)
+ step -= 360.f;
+ if (step > maxStep)
+ step = maxStep;
+ }
+ turnToYaw(_moveYaw + step);
+ return step;
+}
+
+void Actor::walkVector(const Math::Angle &yaw) {
+ setSmoothTurns(true);
+ float maxStep = 2.f * g_grim->getPerSecond(_turnRate);
+ bool walk;
+ if (g_grim->getGameType() == GType_GRIM) {
+ Math::Angle d = yaw - _moveYaw;
+ d.normalize(-180);
+ walk = ABS(d.getDegrees()) < 90.f;
+ turnHeadingToYaw(yaw, maxStep);
+ } else {
+ Math::Angle step = turnHeadingToYaw(yaw, maxStep);
+ walk = ABS((int)step.getDegrees()) < 65;
+ }
+ if (walk)
+ walkForward();
}
-void Actor::turnTo(const Math::Angle &pitchParam, const Math::Angle &yawParam, const Math::Angle &rollParam, bool snap) {
- _movePitch = pitchParam;
- _moveRoll = rollParam;
- _moveYaw = yawParam;
- _turnRateMultiplier = (snap ? 5.f : 1.f);
- if (_yaw != yawParam || _pitch != pitchParam || _roll != rollParam) {
- _turning = true;
- } else
- _turning = false;
+void Actor::turnToYaw(const Math::Angle &yaw) {
+ _moveYaw = yaw;
}
void Actor::walkTo(const Math::Vector3d &p) {
+ setSmoothTurns(true);
if (p == _pos)
_pathWalking = false;
else {
@@ -770,20 +847,13 @@ bool Actor::hasWalked() const {
}
bool Actor::isTurning() const {
- if (g_grim->getGameType() == GType_MONKEY4)
- if (_singleTurning)
- return true;
- if (_turning)
- return true;
-
- if (_lastTurnDir != 0 || _currTurnDir != 0)
- return true;
-
- return false;
+ return _yawLeft != 0.f;
}
void Actor::stopTurning() {
- _turning = false;
+ _moveYaw = _yaw;
+ _movePitch = _pitch;
+ _moveRoll = _roll;
if (_lastTurnDir != 0)
getTurnChore(_lastTurnDir)->stop(true);
@@ -872,11 +942,12 @@ void Actor::walkForwardEMI(float dist, bool backwards) {
turn += turnMargin;
}
if (turn != 0.f)
- turnTo(0, _moveYaw.getDegrees() + turn, 0, true);
+ turnToYaw(_moveYaw.getDegrees() + turn);
}
}
void Actor::walkForward() {
+ setSmoothTurns(true);
float dist = g_grim->getPerSecond(_walkRate) * _timeScale;
// Limit the amount of the movement per frame, otherwise with low fps
// scripts that use WalkActorForward and proximity may break.
@@ -988,7 +1059,7 @@ void Actor::walkForward() {
ei.angleWithEdge += (float)1.0f;
- turnTo(0, _moveYaw + ei.angleWithEdge * turnDir, 0, true);
+ turnToYaw(_moveYaw + ei.angleWithEdge * turnDir);
if (oldDist <= dist + 0.001f) {
// If we didn't move at all, keep trying a couple more times
@@ -1012,7 +1083,7 @@ Math::Vector3d Actor::getSimplePuckVector() const {
}
return Math::Vector3d(yaw.getSine(), 0, yaw.getCosine());
} else {
- return Math::Vector3d(-_yaw.getSine(), _yaw.getCosine(), 0);
+ return Math::Vector3d(-_moveYaw.getSine(), _moveYaw.getCosine(), 0);
}
}
@@ -1159,14 +1230,15 @@ void Actor::stopAllChores(bool ignoreLoopingChores) {
void Actor::turn(int dir) {
_pathWalking = false;
- float delta = g_grim->getPerSecond(_turnRate) * dir * _timeScale;
- if (g_grim->getGameType() == GType_MONKEY4) {
- delta = -delta;
+ setSmoothTurns(true);
+
+ // Grim ignores the key while a smooth turn is still more than two steps behind
+ if (g_grim->getGameType() == GType_GRIM) {
+ float delta = g_grim->getPerSecond(_turnRate) * dir * _timeScale;
+ if (ABS(_yawLeft) > ABS(2.f * delta))
+ return;
}
- _moveYaw = _moveYaw + delta;
- _turning = true;
- _turnRateMultiplier = 5.f;
- _currTurnDir = dir;
+ _currTurnDir = (dir > 0 ? 1 : -1);
}
Math::Angle Actor::getYawTo(const Actor *a) const {
@@ -1559,8 +1631,10 @@ Costume *Actor::findCostume(const Common::String &n) {
void Actor::setFollowBoxes(bool follow) {
_followBoxes = follow;
- if (follow)
+ if (follow) {
_hasFollowedBoxes = true;
+ setSmoothTurns(true);
+ }
}
void Actor::updateWalk() {
@@ -1579,15 +1653,12 @@ void Actor::updateWalk() {
if (_path.empty()) {
_pathWalking = false;
_pos = destPos;
- // It seems that we need to allow an already active turning motion to
- // continue or else turning actors away from barriers won't work right
- _turning = false;
return;
}
}
_walkedCur = true;
- turnTo(destPos, true);
+ turnTo(destPos);
// In EMI, if the actor faces more than 80 degrees away from where it's
// walking, it turns in place before moving.
@@ -1603,6 +1674,101 @@ void Actor::updateWalk() {
_pos += dir * walkAmt;
}
+void Actor::updateMovement() {
+ if (_smoothTurns && _currTurnDir != 0 && !_pathWalking) {
+ float delta = g_grim->getPerSecond(_turnRate) * _currTurnDir * _timeScale;
+ // EMI applies the time scale twice
+ if (g_grim->getGameType() == GType_GRIM)
+ _moveYaw += delta;
+ else
+ _moveYaw -= delta * _timeScale;
+ }
+
+ if (_pathWalking) {
+ updateWalk();
+ }
+
+ if (_smoothTurns) {
+ int eased = updateEasedYaw();
+ if (eased != 0 && _currTurnDir == 0) {
+ _currTurnDir = g_grim->getGameType() == GType_GRIM ? eased : -eased;
+ }
+ }
+
+ // Only a puck oriented actor tilts here
+ float tiltAmt = g_grim->getPerSecond(_turnRate);
+ animTurn(tiltAmt, _movePitch, &_pitch);
+ animTurn(tiltAmt, _moveRoll, &_roll);
+
+ updateMoveChores();
+}
+
+int Actor::updateEasedYaw() {
+ Math::Angle d = _moveYaw - _yaw;
+ d.normalize(-180);
+ float left = ABS(d.getDegrees());
+ if (left < 0.5f) {
+ _yawLeft = 0.f;
+ return 0;
+ }
+ _yawLeft = left;
+
+ float step = left;
+ float turnAmt = g_grim->getPerSecond(_turnRate) * _timeScale;
+ if (turnAmt > 0.f && turnAmt < left)
+ step = (left - turnAmt) * 0.1f + turnAmt;
+ if (d > 0) {
+ _yaw += step;
+ return 1;
+ }
+ _yaw -= step;
+ return -1;
+}
+
+void Actor::updateMoveChores() {
+ const uint fadeTime = g_grim->getGameType() == GType_GRIM ? 130 : 250;
+
+ if (_walkedCur)
+ _currTurnDir = 0;
+
+ // A chore is stopped in the frame it is no longer wanted, not while it
+ // fades out: an EMI chore still plays then and would never end
+ if (_walkChore.isValid()) {
+ if (_walkedCur) {
+ if (!_walkChore.isPlaying())
+ _walkChore.playLooping(true, fadeTime);
+ } else if (_walkedLast && _walkChore.isPlaying()) {
+ _walkChore.stop(true, fadeTime);
+ }
+ }
+
+ ActionChore *turnChores[2] = { &_leftTurnChore, &_rightTurnChore };
+ for (int i = 0; i < 2; ++i) {
+ if (!turnChores[i]->isValid())
+ continue;
+ bool wanted = (i == 0 ? _currTurnDir > 0 : _currTurnDir < 0);
+ bool wantedLast = (i == 0 ? _lastTurnDir > 0 : _lastTurnDir < 0);
+ if (wanted) {
+ if (!turnChores[i]->isPlaying())
+ turnChores[i]->playLooping(true, fadeTime);
+ } else if (wantedLast && turnChores[i]->isPlaying()) {
+ turnChores[i]->stop(true, fadeTime);
+ }
+ }
+
+ if (_restChore.isValid()) {
+ if (g_grim->getGameType() == GType_MONKEY4) {
+ if (!_restChore.isPlaying())
+ _restChore.playLooping();
+ } else if (!_walkedCur && _currTurnDir == 0) {
+ if (!_restChore.isPlaying())
+ _restChore.playLooping(true, fadeTime);
+ } else if (_restChore.isPlaying()) {
+ _restChore.stop(true, fadeTime);
+ }
+ }
+}
+
void Actor::update(uint frameTime) {
Set *set = g_grim->getCurrSet();
// Snap actor to walkboxes if following them. This might be
@@ -1629,86 +1795,7 @@ void Actor::update(uint frameTime) {
}
}
- if (_turning) {
- float turnAmt = g_grim->getPerSecond(_turnRate) * _turnRateMultiplier * _timeScale;
- _currTurnDir = animTurn(turnAmt, _moveYaw, &_yaw);
- if (g_grim->getGameType() == GType_MONKEY4) {
- _currTurnDir = -_currTurnDir;
- }
- int p = animTurn(turnAmt, _movePitch, &_pitch);
- int r = animTurn(turnAmt, _moveRoll, &_roll);
- if (_currTurnDir == 0 && p == 0 && r == 0) {
- _turning = false;
- _turnRateMultiplier = 1.f;
- }
- }
-
- if (_pathWalking) {
- updateWalk();
- }
-
- if (_walkChore.isValid()) {
- if (_walkedCur) {
- if (!_walkChore.isPlaying()) {
- _walkChore.playLooping(true);
- }
- if (g_grim->getGameType() == GType_GRIM && _restChore.isPlaying()) {
- _restChore.stop(true);
- }
- } else {
- if (_walkedLast && _walkChore.isPlaying()) {
- _walkChore.stop(true);
- if (!_restChore.isPlaying()) {
- _restChore.playLooping(true);
- }
- }
- }
- }
-
- if (_leftTurnChore.isValid()) {
- if (_walkedCur || _walkedLast)
- _currTurnDir = 0;
-
- if (g_grim->getGameType() == GType_GRIM && _restChore.isValid()) {
- if (_currTurnDir != 0) {
- if (getTurnChore(_currTurnDir)->isPlaying() && _restChore.isPlaying()) {
- _restChore.stop(true, 500);
- }
- } else if (_lastTurnDir != 0) {
- if (!_walkedCur && getTurnChore(_lastTurnDir)->isPlaying()) {
- _restChore.playLooping(true);
- }
- }
- }
-
- if (_lastTurnDir != 0 && _lastTurnDir != _currTurnDir) {
- getTurnChore(_lastTurnDir)->stop(true);
- }
- if (_currTurnDir != 0 && _currTurnDir != _lastTurnDir) {
- getTurnChore(_currTurnDir)->playLooping(true, 500);
- if (_currTurnDir == 1) {
- // When turning to the left, ensure that the components of the right turn chore
- // are fading out (or stopped).
- // This is necessary because the left turn chore typically contains both the
- // left turn and right turn keyframe components. The above call to playLooping
- // will thus start fading in both of the components, overriding the right turn's
- // fade out that was started before.
- // The left turn chore's keys will eventually stop the right turn keyframe from
- // playing, but the stopping will be instantaneous. To get a smooth transition,
- // we want to keep fading out the right turn. The chore's "stop" key will be
- // ignored when the keyframe is fading out (see KeyframeComponent::stop()).
- _rightTurnChore.stop(true);
- }
- }
- } else {
- _currTurnDir = 0;
- }
-
- // The rest chore might have been stopped because of a
- // StopActorChore(nil). Restart it if so.
- if (!_walkedCur && _currTurnDir == 0 && !_restChore.isPlaying()) {
- _restChore.playLooping(g_grim->getGameType() == GType_GRIM);
- }
+ updateMovement();
_walkedLast = _walkedCur;
_walkedCur = false;
diff --git a/engines/grim/actor.h b/engines/grim/actor.h
index 038166fbe75..0aeb047f44b 100644
--- a/engines/grim/actor.h
+++ b/engines/grim/actor.h
@@ -189,33 +189,25 @@ public:
bool hasWalked() const;
/**
- * Sets the rotation of thes actor in the 3D scene.
- * The effect is not immediate, the actor will slowly rotate
- * to the destination orientation.
+ * Turn the actor towards a point in space.
+ * The heading is set at once; an actor that turns smoothly rotates
+ * to it over the following frames.
*
- * @param pitch The rotation of the x axis
- * @param yaw The rotation of the z axis
- * @param roll The rotation of the y axis
- * @param snap If true tells the actor to increate its turn speed.
- * @see getPitch
- * @see getYaw
- * @see getRoll
+ * @param pos The position the actor should turn to.
+ * @see turnToYaw
* @see setRot
- * @see turn
- * @see isTurning
*/
- void turnTo(const Math::Angle &pitch, const Math::Angle &yaw, const Math::Angle &roll, bool snap = false);
+ void turnTo(const Math::Vector3d &pos);
/**
- * Turn the actor towards a point in space.
- * The effect is not immediate, the actor will slowly rotate
- * to the destination orientation.
+ * Turn the heading toward a yaw and walk forward, as WalkActorVector does.
+ * The heading turns by at most twice the turn rate per call. Grim walks
+ * once the yaw is less than 90 degrees from the heading, EMI unless the
+ * heading had to turn 65 degrees or more.
*
- * @param pos The position the actor should turn to.
- * @param snap If true tells the actor to increate its turn speed.
- * @see turnTo
- * @see setRot
+ * @param yaw The direction to walk in
+ * @see walkForward
*/
- void turnTo(const Math::Vector3d &pos, bool snap = false);
+ void walkVector(const Math::Angle &yaw);
/**
* Turn the actor towards a point in space, by an amount defined by the turn rate.
* This function does not make an actor point at the given position, but it makes
@@ -227,6 +219,37 @@ public:
* @see setRot
*/
bool singleTurnTo(const Math::Vector3d &pos);
+ /**
+ * Turn the actor to a yaw, keeping the destination pitch and roll.
+ *
+ * @param yaw The rotation of the z axis
+ * @see turnTo
+ */
+ void turnToYaw(const Math::Angle &yaw);
+ /**
+ * Set the rotation of the actor as SetActorRot does. If smooth is true and
+ * the actor turns smoothly, the yaw turns to its new value, otherwise the
+ * whole rotation is set at once.
+ *
+ * @param pitch The rotation of the x axis
+ * @param yaw The rotation of the z axis
+ * @param roll The rotation of the y axis
+ * @param smooth If true the actor turns to the yaw
+ * @see setRot
+ * @see turnTo
+ */
+ void setRotFromScript(const Math::Angle &pitch, const Math::Angle &yaw, const Math::Angle &roll, bool smooth);
+ /**
+ * Point the actor towards a point in space at once.
+ *
+ * @param pos The position the actor should face.
+ * @see setRot
+ */
+ void pointAt(const Math::Vector3d &pos);
+ /**
+ * Set whether the actor turns smoothly, see _smoothTurns.
+ */
+ void setSmoothTurns(bool smooth);
/**
* Returns true if the actor is turning.
*
@@ -252,15 +275,6 @@ public:
* @see isTurning
*/
void setRot(const Math::Angle &pitch, const Math::Angle &yaw, const Math::Angle &roll);
- /**
- * Turn the actor towards a point in space.
- * The effect is immediate.
- *
- * @param pos The position the actor should turn to.
- * @see turnTo
- * @see setRot
- */
- void setRot(const Math::Vector3d &pos);
/**
* Turns the actor by the given parameter on the z axis.
* The actual movement depends also on the turn rate.
@@ -590,6 +604,10 @@ private:
void collisionHandlerCallback(Actor *other) const;
void updateWalk();
void walkForwardEMI(float dist, bool backwards);
+ void updateMovement();
+ Math::Angle turnHeadingToYaw(const Math::Angle &yaw, float maxStep);
+ int updateEasedYaw();
+ void updateMoveChores();
void addShadowPlane(const char *n, Set *scene, int shadowId);
bool shouldDrawShadow(int shadowId);
void stopTalking();
@@ -636,9 +654,6 @@ private:
ObjectPtr<LipSync> _lipSync;
Common::List<Costume *> _costumeStack;
- // Variables for gradual turning
- bool _turning;
- bool _singleTurning;
// NOTE: The movement direction is separate from the direction
// the actor's model is facing. The model's direction is gradually
// updated to match the movement direction. This produces a smooth
@@ -647,8 +662,6 @@ private:
Math::Angle _moveYaw;
Math::Angle _movePitch;
Math::Angle _moveRoll;
- // This is used to increase momentarily the turn rate when needed
- float _turnRateMultiplier;
// Variables for walking to a point
bool _pathWalking;
@@ -689,6 +702,9 @@ private:
ActionChore _leftTurnChore, _rightTurnChore;
int _lastTurnDir, _currTurnDir;
+ bool _smoothTurns;
+ float _yawLeft;
+
ActionChore _talkChore[10];
int _talkAnim;
diff --git a/engines/grim/emi/lua_v2.h b/engines/grim/emi/lua_v2.h
index fbf48219b7f..fc83a2d32b6 100644
--- a/engines/grim/emi/lua_v2.h
+++ b/engines/grim/emi/lua_v2.h
@@ -49,7 +49,6 @@ protected:
DECLARE_LUA_OPCODE(UnloadActor);
DECLARE_LUA_OPCODE(SetActorWalkRate) override;
DECLARE_LUA_OPCODE(GetActorWalkRate) override;
- DECLARE_LUA_OPCODE(SetActorTurnRate) override;
DECLARE_LUA_OPCODE(SetReverb);
DECLARE_LUA_OPCODE(LockBackground);
DECLARE_LUA_OPCODE(UnLockBackground);
diff --git a/engines/grim/emi/lua_v2_actor.cpp b/engines/grim/emi/lua_v2_actor.cpp
index e3876dcdab5..bda601d898f 100644
--- a/engines/grim/emi/lua_v2_actor.cpp
+++ b/engines/grim/emi/lua_v2_actor.cpp
@@ -159,22 +159,6 @@ void Lua_V2::GetActorWalkRate() {
lua_pushnumber(actor->getWalkRate() * 0.3048780560493469);
}
-void Lua_V2::SetActorTurnRate() {
- lua_Object actorObj = lua_getparam(1);
- lua_Object rateObj = lua_getparam(2);
-
- if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R'))
- return;
- if (!lua_isnumber(rateObj))
- return;
-
- Actor *actor = getactor(actorObj);
- float rate = lua_getnumber(rateObj); // FIXME verify negate values of rate
-
- // special handling of value 1 only used for voodoo chair
- actor->setTurnRate((rate == 1) ? 100 : rate);
-}
-
void Lua_V2::LockChoreSet() {
lua_Object choreObj = lua_getparam(1);
@@ -1048,10 +1032,7 @@ void Lua_V2::WalkActorVector() {
Math::Angle yaw = cameraYaw + adjustYaw;
- // set the new direction or walk forward
- if (actor2->getYaw() != yaw)
- actor2->turnTo(0, yaw, 0, true);
- actor2->walkForward();
+ actor2->walkVector(yaw);
}
void Lua_V2::EnableActorPuck() {
@@ -1064,10 +1045,8 @@ void Lua_V2::EnableActorPuck() {
if (!actor)
return;
- bool enable = getbool(2);
-
- // FIXME: Implement.
- warning("Lua_V2::EnableActorPuck: stub, actor: %s enable: %s", actor->getName().c_str(), enable ? "TRUE" : "FALSE");
+ bool enable = (int)lua_getnumber(lua_getparam(2)) != 0;
+ actor->setSmoothTurns(enable);
}
// Helper function, not called from LUA directly
diff --git a/engines/grim/lua_v1_actor.cpp b/engines/grim/lua_v1_actor.cpp
index e582e02b015..d782d838434 100644
--- a/engines/grim/lua_v1_actor.cpp
+++ b/engines/grim/lua_v1_actor.cpp
@@ -343,11 +343,8 @@ void Lua_V1::SetActorRot() {
float pitch = lua_getnumber(p);
float yaw = lua_getnumber(y);
float roll = lua_getnumber(r);
- if (getbool(5)) {
- actor->turnTo(pitch, yaw, roll, true);
- } else {
- actor->setRot(pitch, yaw, roll);
- }
+ bool smooth = getbool(5);
+ actor->setRotFromScript(pitch, yaw, roll, smooth);
}
void Lua_V1::GetActorRot() {
@@ -427,6 +424,7 @@ void Lua_V1::GetActorYawToPoint() {
Math::Vector3d yawVector(x, y, z);
+ actor->setSmoothTurns(true);
lua_pushnumber(actor->getYawTo(yawVector).getDegrees());
}
@@ -488,8 +486,8 @@ void Lua_V1::SetActorTurnRate() {
return;
Actor *actor = getactor(actorObj);
- float rate = lua_getnumber(rateObj); // FIXME verify negate values of rate
- actor->setTurnRate(rate);
+ float rate = lua_getnumber(rateObj);
+ actor->setTurnRate(ABS(rate));
}
void Lua_V1::WalkActorForward() {
@@ -709,7 +707,6 @@ void Lua_V1::TurnActor() {
Actor *actor = getactor(actorObj);
int dir = (int)lua_getnumber(dirObj);
- // TODO verify. need clear mode walking
actor->turn(dir);
}
@@ -1212,7 +1209,7 @@ void Lua_V1::PointActorAt() {
// Find the vector pointing from the actor to the desired location
Math::Vector3d turnToVector(x, y, z);
- actor->setRot(turnToVector);
+ actor->pointAt(turnToVector);
}
void Lua_V1::WalkActorVector() {
@@ -1251,11 +1248,7 @@ void Lua_V1::WalkActorVector() {
// yaw is offset from forward by 180 degrees
yaw -= 180.0f;
- // set the new direction or walk forward
- if (actor2->getYaw() != yaw)
- actor2->turnTo(0, yaw, 0);
- else
- actor2->walkForward();
+ actor2->walkVector(yaw);
}
/* Set the pitch of the actor to the requested value,
diff --git a/engines/grim/savegame.cpp b/engines/grim/savegame.cpp
index 98594ddc4f7..8c6bcdca85b 100644
--- a/engines/grim/savegame.cpp
+++ b/engines/grim/savegame.cpp
@@ -34,7 +34,7 @@ namespace Grim {
#define SAVEGAME_FOOTERTAG 'ESAV'
uint SaveGame::SAVEGAME_MAJOR_VERSION = 22;
-uint SaveGame::SAVEGAME_MINOR_VERSION = 31;
+uint SaveGame::SAVEGAME_MINOR_VERSION = 32;
SaveGame *SaveGame::openForLoading(const Common::String &filename) {
Common::InSaveFile *inSaveFile = g_system->getSavefileManager()->openForLoading(filename);
More information about the Scummvm-git-logs
mailing list