mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 13:50:13 +00:00
MYST3: Use ticks to count time instead of frames
Ticks go by at 30 ticks per second, one tick every two frames. This halves the speed of all game controlled animations.
This commit is contained in:
parent
fef52b35c0
commit
c7811b2d25
@ -30,7 +30,7 @@ namespace Myst3 {
|
||||
|
||||
Ambient::Ambient(Myst3Engine *vm) :
|
||||
_vm(vm),
|
||||
_cueStartFrame(0) {
|
||||
_cueStartTick(0) {
|
||||
_cueSheet.reset();
|
||||
}
|
||||
|
||||
@ -146,11 +146,11 @@ uint32 Ambient::nextCueSound(uint32 id) {
|
||||
|
||||
void Ambient::updateCue() {
|
||||
if (_cueSheet.id) {
|
||||
if (!_cueStartFrame) {
|
||||
_cueStartFrame = _vm->_state->getFrameCount() + delayForCue(_cueSheet.id);
|
||||
if (!_cueStartTick) {
|
||||
_cueStartTick = _vm->_state->getTickCount() + delayForCue(_cueSheet.id);
|
||||
}
|
||||
if (_vm->_state->getFrameCount() >= _cueStartFrame) {
|
||||
_cueStartFrame = 0;
|
||||
if (_vm->_state->getTickCount() >= _cueStartTick) {
|
||||
_cueStartTick = 0;
|
||||
uint32 soundId = nextCueSound(_cueSheet.id);
|
||||
|
||||
uint heading;
|
||||
@ -166,7 +166,7 @@ void Ambient::updateCue() {
|
||||
|
||||
void Ambient::applySounds(uint32 fadeOutDelay) {
|
||||
// Reset the random sounds
|
||||
_cueStartFrame = 0;
|
||||
_cueStartTick = 0;
|
||||
if (!_cueSheet.id) {
|
||||
_vm->_sound->stopCue(fadeOutDelay);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ private:
|
||||
Common::Array<AmbientSound> _sounds;
|
||||
|
||||
AmbientSound _cueSheet;
|
||||
uint32 _cueStartFrame;
|
||||
uint32 _cueStartTick;
|
||||
};
|
||||
|
||||
} // End of namespace Myst3
|
||||
|
@ -540,7 +540,7 @@ void MagnetEffect::apply(Graphics::Surface *src, Graphics::Surface *dst, Graphic
|
||||
|
||||
ShakeEffect::ShakeEffect(Myst3Engine *vm) :
|
||||
Effect(vm),
|
||||
_lastFrame(0),
|
||||
_lastTick(0),
|
||||
_magnetEffectShakeStep(0),
|
||||
_pitchOffset(0),
|
||||
_headingOffset(0) {
|
||||
@ -565,8 +565,8 @@ bool ShakeEffect::update() {
|
||||
}
|
||||
|
||||
// Check if the effect needs to be updated
|
||||
uint frame = _vm->_state->getFrameCount();
|
||||
if (frame < _lastFrame + _vm->_state->getShakeEffectFramePeriod()) {
|
||||
uint tick = _vm->_state->getTickCount();
|
||||
if (tick < _lastTick + _vm->_state->getShakeEffectTickPeriod()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -602,7 +602,7 @@ bool ShakeEffect::update() {
|
||||
_headingOffset = (randomAmpl - ampl / 2.0) / 100.0;
|
||||
}
|
||||
|
||||
_lastFrame = frame;
|
||||
_lastTick = tick;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -667,7 +667,7 @@ bool ShieldEffect::loadPattern() {
|
||||
|
||||
ShieldEffect::ShieldEffect(Myst3Engine *vm):
|
||||
Effect(vm),
|
||||
_lastFrame(0),
|
||||
_lastTick(0),
|
||||
_amplitude(1.0),
|
||||
_amplitudeIncrement(1.0 / 64.0) {
|
||||
}
|
||||
@ -726,10 +726,10 @@ ShieldEffect *ShieldEffect::create(Myst3Engine *vm, uint32 id) {
|
||||
}
|
||||
|
||||
bool ShieldEffect::update() {
|
||||
if (_vm->_state->getFrameCount() == _lastFrame)
|
||||
if (_vm->_state->getTickCount() == _lastTick)
|
||||
return false;
|
||||
|
||||
_lastFrame = _vm->_state->getFrameCount();
|
||||
_lastTick = _vm->_state->getTickCount();
|
||||
|
||||
// Update the amplitude, varying between 1.0 and 4.0
|
||||
_amplitude += _amplitudeIncrement;
|
||||
|
@ -151,7 +151,7 @@ public:
|
||||
protected:
|
||||
ShakeEffect(Myst3Engine *vm);
|
||||
|
||||
uint32 _lastFrame;
|
||||
uint32 _lastTick;
|
||||
uint _magnetEffectShakeStep;
|
||||
float _pitchOffset;
|
||||
float _headingOffset;
|
||||
@ -188,7 +188,7 @@ protected:
|
||||
ShieldEffect(Myst3Engine *vm);
|
||||
bool loadPattern();
|
||||
|
||||
uint32 _lastFrame;
|
||||
uint32 _lastTick;
|
||||
float _amplitude;
|
||||
float _amplitudeIncrement;
|
||||
|
||||
|
@ -377,7 +377,7 @@ SimpleMovie::SimpleMovie(Myst3Engine *vm, uint16 id) :
|
||||
_synchronized(false) {
|
||||
_startFrame = 1;
|
||||
_endFrame = _bink.getFrameCount();
|
||||
_startEngineFrame = _vm->_state->getFrameCount();
|
||||
_startEngineTick = _vm->_state->getTickCount();
|
||||
}
|
||||
|
||||
bool SimpleMovie::update() {
|
||||
@ -413,7 +413,7 @@ bool SimpleMovie::update() {
|
||||
}
|
||||
} else {
|
||||
// Draw a movie frame each two engine frames
|
||||
int targetFrame = (_vm->_state->getFrameCount() - _startEngineFrame) >> 2;
|
||||
int targetFrame = (_vm->_state->getTickCount() - _startEngineTick) >> 1;
|
||||
if (_bink.getCurFrame() < targetFrame) {
|
||||
drawNextFrameToTexture();
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public:
|
||||
void setSynchronized(bool b) { _synchronized = b; }
|
||||
private:
|
||||
bool _synchronized;
|
||||
uint _startEngineFrame;
|
||||
uint _startEngineTick;
|
||||
};
|
||||
|
||||
// Used by the projectors on J'nanin, see puzzle #14
|
||||
|
@ -1406,7 +1406,7 @@ Common::Error Myst3Engine::loadGameState(Common::String fileName, TransitionType
|
||||
return Common::kUnknownError;
|
||||
}
|
||||
|
||||
void Myst3Engine::animateDirectionChange(float targetPitch, float targetHeading, uint16 scriptFrames) {
|
||||
void Myst3Engine::animateDirectionChange(float targetPitch, float targetHeading, uint16 scriptTicks) {
|
||||
float startPitch = _state->getLookAtPitch();
|
||||
float startHeading = _state->getLookAtHeading();
|
||||
|
||||
@ -1426,38 +1426,38 @@ void Myst3Engine::animateDirectionChange(float targetPitch, float targetHeading,
|
||||
}
|
||||
|
||||
// Compute animation duration in frames
|
||||
float numFrames;
|
||||
if (scriptFrames) {
|
||||
numFrames = scriptFrames;
|
||||
float numTicks;
|
||||
if (scriptTicks) {
|
||||
numTicks = scriptTicks;
|
||||
} else {
|
||||
numFrames = sqrt(pitchDistance * pitchDistance + headingDistance * headingDistance)
|
||||
numTicks = sqrt(pitchDistance * pitchDistance + headingDistance * headingDistance)
|
||||
* 30.0f / _state->getCameraMoveSpeed();
|
||||
|
||||
if (numFrames > 0.0f)
|
||||
numFrames += 10.0f;
|
||||
if (numTicks > 0.0f)
|
||||
numTicks += 10.0f;
|
||||
}
|
||||
|
||||
uint startFrame = _state->getFrameCount();
|
||||
uint startTick = _state->getTickCount();
|
||||
|
||||
// Draw animation
|
||||
if (numFrames != 0.0f) {
|
||||
if (numTicks != 0.0f) {
|
||||
while (1) {
|
||||
uint elapsedFrames = _state->getFrameCount() - startFrame;
|
||||
if (elapsedFrames >= numFrames)
|
||||
uint elapsedTicks = _state->getTickCount() - startTick;
|
||||
if (elapsedTicks >= numTicks)
|
||||
break;
|
||||
|
||||
float step;
|
||||
if (numFrames >= 15) {
|
||||
if (numTicks >= 15) {
|
||||
// Fast then slow movement
|
||||
if (elapsedFrames > numFrames / 2.0f)
|
||||
step = 1.0f - (numFrames - elapsedFrames) * (numFrames - elapsedFrames)
|
||||
/ (numFrames / 2.0f * numFrames / 2.0f) / 2.0f;
|
||||
if (elapsedTicks > numTicks / 2.0f)
|
||||
step = 1.0f - (numTicks - elapsedTicks) * (numTicks - elapsedTicks)
|
||||
/ (numTicks / 2.0f * numTicks / 2.0f) / 2.0f;
|
||||
else
|
||||
step = elapsedFrames * elapsedFrames / (numFrames / 2.0f * numFrames / 2.0f) / 2.0f;
|
||||
step = elapsedTicks * elapsedTicks / (numTicks / 2.0f * numTicks / 2.0f) / 2.0f;
|
||||
|
||||
} else {
|
||||
// Constant speed movement
|
||||
step = elapsedFrames / numFrames;
|
||||
step = elapsedTicks / numTicks;
|
||||
}
|
||||
|
||||
float nextPitch = startPitch + pitchDistance * step;
|
||||
|
@ -177,7 +177,7 @@ public:
|
||||
|
||||
void setMenuAction(uint16 action) { _menuAction = action; }
|
||||
|
||||
void animateDirectionChange(float pitch, float heading, uint16 speed);
|
||||
void animateDirectionChange(float pitch, float heading, uint16 scriptTicks);
|
||||
void getMovieLookAt(uint16 id, bool start, float &pitch, float &heading);
|
||||
|
||||
void processInput(bool lookOnly);
|
||||
|
@ -117,10 +117,10 @@ void Puzzles::run(uint16 id, uint16 arg0, uint16 arg1, uint16 arg2) {
|
||||
}
|
||||
|
||||
void Puzzles::_drawForVarHelper(int16 var, int32 startValue, int32 endValue) {
|
||||
uint startFrame = _vm->_state->getFrameCount();
|
||||
uint currentFrame = startFrame;
|
||||
uint startTick = _vm->_state->getTickCount();
|
||||
uint currentTick = startTick;
|
||||
uint numValues = abs(endValue - startValue);
|
||||
uint endFrame = startFrame + 2 * numValues;
|
||||
uint endTick = startTick + 2 * numValues;
|
||||
|
||||
int16 var2 = var;
|
||||
|
||||
@ -129,10 +129,10 @@ void Puzzles::_drawForVarHelper(int16 var, int32 startValue, int32 endValue) {
|
||||
if (var2 < 0)
|
||||
var2 = -var2 + 1;
|
||||
|
||||
if (startFrame < endFrame) {
|
||||
if (startTick < endTick) {
|
||||
int currentValue = -9999;
|
||||
while (1) {
|
||||
int nextValue = (currentFrame - startFrame) / 2;
|
||||
int nextValue = (currentTick - startTick) / 2;
|
||||
if (currentValue != nextValue) {
|
||||
currentValue = nextValue;
|
||||
|
||||
@ -148,9 +148,9 @@ void Puzzles::_drawForVarHelper(int16 var, int32 startValue, int32 endValue) {
|
||||
|
||||
_vm->processInput(true);
|
||||
_vm->drawFrame();
|
||||
currentFrame = _vm->_state->getFrameCount();
|
||||
currentTick = _vm->_state->getTickCount();
|
||||
|
||||
if (currentFrame > endFrame)
|
||||
if (currentTick > endTick)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -159,10 +159,10 @@ void Puzzles::_drawForVarHelper(int16 var, int32 startValue, int32 endValue) {
|
||||
_vm->_state->setVar(var2, endValue);
|
||||
}
|
||||
|
||||
void Puzzles::_drawXFrames(uint16 frames) {
|
||||
uint32 endFrame = _vm->_state->getFrameCount() + frames;
|
||||
void Puzzles::_drawXTicks(uint16 ticks) {
|
||||
uint32 endTick = _vm->_state->getTickCount() + ticks;
|
||||
|
||||
while (_vm->_state->getFrameCount() < endFrame) {
|
||||
while (_vm->_state->getTickCount() < endTick) {
|
||||
_vm->processInput(true);
|
||||
_vm->drawFrame();
|
||||
}
|
||||
@ -663,7 +663,7 @@ void Puzzles::pinball(int16 var) {
|
||||
// Launch sound
|
||||
_vm->_sound->playEffect(1021, 50);
|
||||
_drawForVarHelper(-34, 2, 15);
|
||||
_drawXFrames(30);
|
||||
_drawXTicks(30);
|
||||
|
||||
int32 leftSideFrame = 250;
|
||||
int32 rightSideFrame = 500;
|
||||
@ -686,7 +686,7 @@ void Puzzles::pinball(int16 var) {
|
||||
_vm->processInput(true);
|
||||
|
||||
// while (limit > renderCurrFrame);
|
||||
// limit = _vm->_state->getFrameCount() + 1;
|
||||
// limit = _vm->_state->getTickCount() + 1;
|
||||
|
||||
bool shouldRotate;
|
||||
if (leftToRightJumpCountDown >= 3 || rightToLeftJumpCountdown >= 3) {
|
||||
@ -778,7 +778,7 @@ void Puzzles::pinball(int16 var) {
|
||||
|
||||
if (ballShouldJump) {
|
||||
// sound fade stop 1025, 7
|
||||
_drawXFrames(30);
|
||||
_drawXTicks(30);
|
||||
|
||||
int32 jumpPositionLeft = 50 * ((leftSideFrame + 25) / 50);
|
||||
int32 jumpPositionRight = 50 * ((rightSideFrame + 25) / 50);
|
||||
@ -843,7 +843,7 @@ void Puzzles::pinball(int16 var) {
|
||||
_drawForVarHelper(-34, jumpStartFrame, jump->endFrame);
|
||||
|
||||
if (jumpType == 3) {
|
||||
_drawXFrames(6);
|
||||
_drawXTicks(6);
|
||||
_vm->_sound->playEffect(1028, 50);
|
||||
} else if (jumpType == 1 || jumpType == 4) {
|
||||
_vm->_state->setVar(26, jumpType);
|
||||
@ -860,7 +860,7 @@ void Puzzles::pinball(int16 var) {
|
||||
if (jumpType >= 2)
|
||||
ballCrashed = 1;
|
||||
|
||||
_drawXFrames(30);
|
||||
_drawXTicks(30);
|
||||
}
|
||||
|
||||
if (ballShouldExpire) {
|
||||
@ -875,7 +875,7 @@ void Puzzles::pinball(int16 var) {
|
||||
|
||||
// sound fade stop 1025, 7
|
||||
// Sound same as opcode 213 : 1005, 65, 0, 0, 5, 60, 20
|
||||
_drawXFrames(55);
|
||||
_drawXTicks(55);
|
||||
_vm->_sound->playEffect(1010, 50);
|
||||
|
||||
for (uint i = 0; i < ARRAYSIZE(ballExpireFrames); i++) {
|
||||
@ -890,7 +890,7 @@ void Puzzles::pinball(int16 var) {
|
||||
}
|
||||
}
|
||||
|
||||
_drawXFrames(15);
|
||||
_drawXTicks(15);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -966,7 +966,7 @@ void Puzzles::pinball(int16 var) {
|
||||
_vm->drawFrame();
|
||||
_vm->processInput(true);
|
||||
// while (limit > renderCurrFrame);
|
||||
// limit = _vm->_state->getFrameCount() + 1;
|
||||
// limit = _vm->_state->getTickCount() + 1;
|
||||
|
||||
if (!moviePlaying) {
|
||||
_vm->_state->setVar(26, jumpType);
|
||||
|
@ -92,7 +92,7 @@ private:
|
||||
void checkCanSave();
|
||||
|
||||
void _drawForVarHelper(int16 var, int32 startValue, int32 endValue);
|
||||
void _drawXFrames(uint16 frames);
|
||||
void _drawXTicks(uint16 ticks);
|
||||
};
|
||||
|
||||
} // End of namespace Myst3
|
||||
|
@ -207,7 +207,7 @@ Script::Script(Myst3Engine *vm):
|
||||
OP_2(165, changeNodeRoom, kValue, kValue );
|
||||
OP_3(166, changeNodeRoomAge, kValue, kValue, kValue );
|
||||
OP_0(168, uselessOpcode );
|
||||
OP_1(169, drawXFrames, kValue );
|
||||
OP_1(169, drawXTicks, kValue );
|
||||
OP_1(171, drawWhileCond, kCondition );
|
||||
OP_1(172, whileStart, kCondition );
|
||||
OP_0(173, whileEnd );
|
||||
@ -705,7 +705,7 @@ void Script::shakeEffectSet(Context &c, const Opcode &cmd) {
|
||||
uint16 period = _vm->_state->valueOrVarValue(cmd.args[1]);
|
||||
|
||||
_vm->_state->setShakeEffectAmpl(ampl);
|
||||
_vm->_state->setShakeEffectFramePeriod(period);
|
||||
_vm->_state->setShakeEffectTickPeriod(period);
|
||||
}
|
||||
|
||||
void Script::sunspotAdd(Context &c, const Opcode &cmd) {
|
||||
@ -2116,12 +2116,12 @@ void Script::changeNodeRoomAge(Context &c, const Opcode &cmd) {
|
||||
_vm->loadNode(cmd.args[2], cmd.args[1], cmd.args[0]);
|
||||
}
|
||||
|
||||
void Script::drawXFrames(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: Draw %d frames", cmd.op, cmd.args[0]);
|
||||
void Script::drawXTicks(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: Draw %d ticks", cmd.op, cmd.args[0]);
|
||||
|
||||
uint32 endFrame = _vm->_state->getFrameCount() + cmd.args[0];
|
||||
uint32 endTick = _vm->_state->getTickCount() + cmd.args[0];
|
||||
|
||||
while (_vm->_state->getFrameCount() < endFrame) {
|
||||
while (_vm->_state->getTickCount() < endTick) {
|
||||
_vm->processInput(true);
|
||||
_vm->drawFrame();
|
||||
}
|
||||
@ -2182,12 +2182,12 @@ void Script::runScriptWhileCondEachXFrames(Context &c, const Opcode &cmd) {
|
||||
if (firstStep > 100)
|
||||
firstStep /= 100;
|
||||
|
||||
uint nextScript = _vm->_state->getFrameCount() + firstStep;
|
||||
uint nextScript = _vm->_state->getTickCount() + firstStep;
|
||||
|
||||
while (_vm->_state->evaluate(cmd.args[0])) {
|
||||
|
||||
if (_vm->_state->getFrameCount() >= nextScript) {
|
||||
nextScript = _vm->_state->getFrameCount() + step;
|
||||
if (_vm->_state->getTickCount() >= nextScript) {
|
||||
nextScript = _vm->_state->getTickCount() + step;
|
||||
|
||||
_vm->runScriptsFromNode(cmd.args[1]);
|
||||
}
|
||||
@ -2274,18 +2274,18 @@ void Script::lookAtMovieStartInXFrames(Context &c, const Opcode &cmd) {
|
||||
_vm->animateDirectionChange(startPitch, startHeading, cmd.args[1]);
|
||||
}
|
||||
|
||||
void Script::runScriptForVarDrawFramesHelper(uint16 var, int32 startValue, int32 endValue, uint16 script, int32 numFrames) {
|
||||
if (numFrames < 0) {
|
||||
numFrames = -numFrames;
|
||||
uint startFrame = _vm->_state->getFrameCount();
|
||||
uint currentFrame = startFrame;
|
||||
uint endFrame = startFrame + numFrames;
|
||||
void Script::runScriptForVarDrawTicksHelper(uint16 var, int32 startValue, int32 endValue, uint16 script, int32 numTicks) {
|
||||
if (numTicks < 0) {
|
||||
numTicks = -numTicks;
|
||||
uint startTick = _vm->_state->getTickCount();
|
||||
uint currentTick = startTick;
|
||||
uint endTick = startTick + numTicks;
|
||||
uint numValues = abs(endValue - startValue);
|
||||
|
||||
if (startFrame < endFrame) {
|
||||
if (startTick < endTick) {
|
||||
int currentValue = -9999;
|
||||
while (1) {
|
||||
int nextValue = numValues * (currentFrame - startFrame) / numFrames;
|
||||
int nextValue = numValues * (currentTick - startTick) / numTicks;
|
||||
if (currentValue != nextValue) {
|
||||
currentValue = nextValue;
|
||||
|
||||
@ -2304,9 +2304,9 @@ void Script::runScriptForVarDrawFramesHelper(uint16 var, int32 startValue, int32
|
||||
|
||||
_vm->processInput(true);
|
||||
_vm->drawFrame();
|
||||
currentFrame = _vm->_state->getFrameCount();
|
||||
currentTick = _vm->_state->getTickCount();
|
||||
|
||||
if (currentFrame > endFrame)
|
||||
if (currentTick > endTick)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2314,7 +2314,7 @@ void Script::runScriptForVarDrawFramesHelper(uint16 var, int32 startValue, int32
|
||||
_vm->_state->setVar(var, endValue);
|
||||
} else {
|
||||
int currentValue = startValue;
|
||||
uint endFrame = 0;
|
||||
uint endTick = 0;
|
||||
|
||||
bool positiveDirection = endValue > startValue;
|
||||
|
||||
@ -2328,10 +2328,10 @@ void Script::runScriptForVarDrawFramesHelper(uint16 var, int32 startValue, int32
|
||||
if (script)
|
||||
_vm->runScriptsFromNode(script);
|
||||
|
||||
for (uint i = _vm->_state->getFrameCount(); i < endFrame; i = _vm->_state->getFrameCount())
|
||||
for (uint i = _vm->_state->getTickCount(); i < endTick; i = _vm->_state->getTickCount())
|
||||
_vm->drawFrame();
|
||||
|
||||
endFrame = _vm->_state->getFrameCount() + numFrames;
|
||||
endTick = _vm->_state->getTickCount() + numTicks;
|
||||
|
||||
currentValue += positiveDirection ? 1 : -1;
|
||||
}
|
||||
@ -2342,63 +2342,65 @@ void Script::runScriptForVar(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: For var %d from %d to %d, run script %d",
|
||||
cmd.op, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3]);
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3], 0);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3], 0);
|
||||
}
|
||||
|
||||
void Script::runScriptForVarEachXFrames(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: For var %d from %d to %d, run script %d every %d frames",
|
||||
cmd.op, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3], cmd.args[4]);
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3], cmd.args[4]);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3], cmd.args[4]);
|
||||
}
|
||||
|
||||
void Script::runScriptForVarStartVar(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: For var %d from var %d value to %d, run script %d",
|
||||
cmd.op, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3]);
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), cmd.args[2], cmd.args[3], 0);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), cmd.args[2], cmd.args[3], 0);
|
||||
}
|
||||
|
||||
void Script::runScriptForVarStartVarEachXFrames(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: For var %d from var %d value to %d, run script %d every %d frames",
|
||||
cmd.op, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3], cmd.args[4]);
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), cmd.args[2], cmd.args[3], cmd.args[4]);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), cmd.args[2], cmd.args[3], cmd.args[4]);
|
||||
}
|
||||
|
||||
void Script::runScriptForVarEndVar(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: For var %d from %d to var %d value, run script %d",
|
||||
cmd.op, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3]);
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], cmd.args[1], _vm->_state->getVar(cmd.args[2]), cmd.args[3], 0);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], cmd.args[1], _vm->_state->getVar(cmd.args[2]), cmd.args[3], 0);
|
||||
}
|
||||
|
||||
void Script::runScriptForVarEndVarEachXFrames(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: For var %d from var %d value to var %d value, run script %d every %d frames",
|
||||
cmd.op, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3], cmd.args[4]);
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], cmd.args[1], _vm->_state->getVar(cmd.args[2]), cmd.args[3], cmd.args[4]);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], cmd.args[1], _vm->_state->getVar(cmd.args[2]), cmd.args[3], cmd.args[4]);
|
||||
}
|
||||
|
||||
void Script::runScriptForVarStartEndVar(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: For var %d from var %d value to var %d value, run script %d",
|
||||
cmd.op, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3]);
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), _vm->_state->getVar(cmd.args[2]), cmd.args[3], 0);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), _vm->_state->getVar(cmd.args[2]),
|
||||
cmd.args[3], 0);
|
||||
}
|
||||
|
||||
void Script::runScriptForVarStartEndVarEachXFrames(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: For var %d from var %d value to var %d value, run script %d every %d frames",
|
||||
cmd.op, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3], cmd.args[4]);
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), _vm->_state->getVar(cmd.args[2]), cmd.args[3], cmd.args[4]);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), _vm->_state->getVar(cmd.args[2]),
|
||||
cmd.args[3], cmd.args[4]);
|
||||
}
|
||||
|
||||
void Script::drawFramesForVar(Context &c, const Opcode &cmd) {
|
||||
debugC(kDebugScript, "Opcode %d: For var %d from %d to %d, every %d frames",
|
||||
cmd.op, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3]);
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], cmd.args[1], cmd.args[2], 0, -cmd.args[3]);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], cmd.args[1], cmd.args[2], 0, -cmd.args[3]);
|
||||
}
|
||||
|
||||
void Script::drawFramesForVarEachTwoFrames(Context &c, const Opcode &cmd) {
|
||||
@ -2407,7 +2409,7 @@ void Script::drawFramesForVarEachTwoFrames(Context &c, const Opcode &cmd) {
|
||||
|
||||
uint numFrames = 2 * (-1 - abs(cmd.args[2] - cmd.args[1]));
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], cmd.args[1], cmd.args[2], 0, numFrames);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], cmd.args[1], cmd.args[2], 0, numFrames);
|
||||
}
|
||||
|
||||
void Script::drawFramesForVarStartEndVarEachTwoFrames(Context &c, const Opcode &cmd) {
|
||||
@ -2416,7 +2418,8 @@ void Script::drawFramesForVarStartEndVarEachTwoFrames(Context &c, const Opcode &
|
||||
|
||||
uint numFrames = 2 * (-1 - abs(cmd.args[2] - cmd.args[1]));
|
||||
|
||||
runScriptForVarDrawFramesHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), _vm->_state->getVar(cmd.args[2]), 0, numFrames);
|
||||
runScriptForVarDrawTicksHelper(cmd.args[0], _vm->_state->getVar(cmd.args[1]), _vm->_state->getVar(cmd.args[2]), 0,
|
||||
numFrames);
|
||||
}
|
||||
|
||||
void Script::runScript(Context &c, const Opcode &cmd) {
|
||||
|
@ -98,7 +98,7 @@ private:
|
||||
void runOp(Context &c, const Opcode &op);
|
||||
void goToElse(Context &c);
|
||||
|
||||
void runScriptForVarDrawFramesHelper(uint16 var, int32 startValue, int32 endValue, uint16 script, int32 numFrames);
|
||||
void runScriptForVarDrawTicksHelper(uint16 var, int32 startValue, int32 endValue, uint16 script, int32 numTicks);
|
||||
|
||||
DECLARE_OPCODE(badOpcode);
|
||||
DECLARE_OPCODE(uselessOpcode);
|
||||
@ -260,7 +260,8 @@ private:
|
||||
DECLARE_OPCODE(changeNode);
|
||||
DECLARE_OPCODE(changeNodeRoom);
|
||||
DECLARE_OPCODE(changeNodeRoomAge);
|
||||
DECLARE_OPCODE(drawXFrames);
|
||||
|
||||
DECLARE_OPCODE(drawXTicks);
|
||||
DECLARE_OPCODE(drawWhileCond);
|
||||
DECLARE_OPCODE(whileStart);
|
||||
DECLARE_OPCODE(whileEnd);
|
||||
|
@ -270,11 +270,11 @@ void Sound::setupNextSound(SoundNextCommand command, int16 controlVar, int16 sta
|
||||
_vm->_state->setSoundNextId(0);
|
||||
_vm->_state->setSoundNextIsLast(false);
|
||||
|
||||
uint32 controlLastFrame = _vm->_state->getVar(controlVar);
|
||||
uint32 controlLastTick = _vm->_state->getVar(controlVar);
|
||||
int32 playingSoundId = _vm->_state->getVar(controlVar + 1) >> 16;
|
||||
int32 soundDelay = _vm->_state->getVar(controlVar + 1) & 0xFFFF;
|
||||
|
||||
if (!controlLastFrame) {
|
||||
if (!controlLastTick) {
|
||||
if (!playSeveralSounds) {
|
||||
for (int16 i = startSoundId; i < startSoundId + soundCount; i++) {
|
||||
int16 soundVarValue = _vm->_state->getVar(i);
|
||||
@ -290,17 +290,17 @@ void Sound::setupNextSound(SoundNextCommand command, int16 controlVar, int16 sta
|
||||
return;
|
||||
}
|
||||
|
||||
uint currentFrame = _vm->_state->getFrameCount();
|
||||
if (currentFrame == controlLastFrame) {
|
||||
uint currentTick = _vm->_state->getTickCount();
|
||||
if (currentTick == controlLastTick) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentFrame < controlLastFrame) {
|
||||
if (currentTick < controlLastTick) {
|
||||
soundDelay = 0;
|
||||
} else if (currentFrame > controlLastFrame + 10) {
|
||||
} else if (currentTick > controlLastTick + 10) {
|
||||
soundDelay -= 10;
|
||||
} else {
|
||||
soundDelay -= currentFrame - controlLastFrame;
|
||||
soundDelay -= currentTick - controlLastTick;
|
||||
}
|
||||
|
||||
if (soundDelay < 0) {
|
||||
@ -308,7 +308,7 @@ void Sound::setupNextSound(SoundNextCommand command, int16 controlVar, int16 sta
|
||||
}
|
||||
|
||||
if (soundDelay) {
|
||||
_vm->_state->setVar(controlVar, currentFrame);
|
||||
_vm->_state->setVar(controlVar, currentTick);
|
||||
_vm->_state->setVar(controlVar + 1, soundDelay | (playingSoundId << 16));
|
||||
return;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ GameState::GameState(Myst3Engine *vm):
|
||||
VAR(69, MenuSavedNode, false)
|
||||
|
||||
VAR(70, SecondsCountdown, false)
|
||||
VAR(71, FrameCountdown, false)
|
||||
VAR(71, TickCountdown, false)
|
||||
|
||||
// Counters, unused by the game scripts
|
||||
VAR(76, CounterUnk76, false)
|
||||
@ -148,7 +148,7 @@ GameState::GameState(Myst3Engine *vm):
|
||||
VAR(111, MagnetEffectUnk3, false)
|
||||
|
||||
VAR(112, ShakeEffectAmpl, false)
|
||||
VAR(113, ShakeEffectFramePeriod, false)
|
||||
VAR(113, ShakeEffectTickPeriod, false)
|
||||
VAR(114, RotationEffectSpeed, false)
|
||||
VAR(115, SunspotIntensity, false)
|
||||
VAR(116, SunspotColor, false)
|
||||
@ -267,7 +267,7 @@ GameState::GameState(Myst3Engine *vm):
|
||||
|
||||
// Amateria ambient sound / movie counters (XXXX 1001 and XXXX 1002)
|
||||
VAR(406, AmateriaSecondsCounter, false)
|
||||
VAR(407, AmateriaFramesCounter, false)
|
||||
VAR(407, AmateriaTicksCounter, false)
|
||||
|
||||
VAR(444, ResonanceRingsSolved, false)
|
||||
|
||||
@ -710,12 +710,10 @@ void GameState::updateFrameCounters() {
|
||||
if (!_data.gameRunning)
|
||||
return;
|
||||
|
||||
int32 frameCountdown = getFrameCountdown();
|
||||
if (frameCountdown > 0)
|
||||
setFrameCountdown(--frameCountdown);
|
||||
|
||||
if (getAmateriaFramesCounter() > 0)
|
||||
setAmateriaFramesCounter(getAmateriaFramesCounter() - 1);
|
||||
if (_data.currentFrame % 2 == 0) {
|
||||
// One game tick every two frames
|
||||
updateTickCounters();
|
||||
}
|
||||
|
||||
uint32 currentTime = g_system->getMillis();
|
||||
if (currentTime > _data.nextSecondsUpdate || ABS<int32>(_data.nextSecondsUpdate - currentTime) > 2000) {
|
||||
@ -735,24 +733,38 @@ void GameState::updateFrameCounters() {
|
||||
if (hasVarMenuAttractCountDown() && getMenuAttractCountDown() > 0)
|
||||
setMenuAttractCountDown(getMenuAttractCountDown() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void GameState::updateTickCounters() {
|
||||
int32 tickCountdown = getTickCountdown();
|
||||
if (tickCountdown > 0)
|
||||
setTickCountdown(--tickCountdown);
|
||||
|
||||
if (getAmateriaTicksCounter() > 0)
|
||||
setAmateriaTicksCounter(getAmateriaTicksCounter() - 1);
|
||||
|
||||
if (getSweepEnabled()) {
|
||||
if (getSweepValue() + getSweepStep() > getSweepMax()) {
|
||||
setSweepValue(getSweepMax());
|
||||
if (getSweepValue() + getSweepStep() > getSweepMax()) {
|
||||
setSweepValue(getSweepMax());
|
||||
|
||||
if (getSweepStep() > 0) {
|
||||
setSweepStep(-getSweepStep());
|
||||
}
|
||||
} else if (getSweepValue() + getSweepStep() < getSweepMin()) {
|
||||
setSweepValue(getSweepMin());
|
||||
if (getSweepStep() > 0) {
|
||||
setSweepStep(-getSweepStep());
|
||||
}
|
||||
} else if (getSweepValue() + getSweepStep() < getSweepMin()) {
|
||||
setSweepValue(getSweepMin());
|
||||
|
||||
if (getSweepStep() < 0) {
|
||||
setSweepStep(-getSweepStep());
|
||||
if (getSweepStep() < 0) {
|
||||
setSweepStep(-getSweepStep());
|
||||
}
|
||||
} else {
|
||||
setSweepValue(getSweepValue() + getSweepStep());
|
||||
}
|
||||
} else {
|
||||
setSweepValue(getSweepValue() + getSweepStep());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint GameState::getTickCount() const {
|
||||
// There is one game tick every two frames
|
||||
return _data.currentFrame >> 1;
|
||||
}
|
||||
|
||||
bool GameState::isZipDestinationAvailable(uint16 node, uint16 room) {
|
||||
|
@ -84,7 +84,7 @@ public:
|
||||
DECLARE_VAR(MenuSavedNode)
|
||||
|
||||
DECLARE_VAR(SecondsCountdown)
|
||||
DECLARE_VAR(FrameCountdown)
|
||||
DECLARE_VAR(TickCountdown)
|
||||
|
||||
DECLARE_VAR(SweepEnabled)
|
||||
DECLARE_VAR(SweepValue)
|
||||
@ -122,7 +122,7 @@ public:
|
||||
DECLARE_VAR(MagnetEffectUnk3)
|
||||
|
||||
DECLARE_VAR(ShakeEffectAmpl)
|
||||
DECLARE_VAR(ShakeEffectFramePeriod)
|
||||
DECLARE_VAR(ShakeEffectTickPeriod)
|
||||
DECLARE_VAR(RotationEffectSpeed)
|
||||
DECLARE_VAR(SunspotIntensity)
|
||||
DECLARE_VAR(SunspotColor)
|
||||
@ -228,7 +228,7 @@ public:
|
||||
DECLARE_VAR(TeslaMovieStart)
|
||||
|
||||
DECLARE_VAR(AmateriaSecondsCounter)
|
||||
DECLARE_VAR(AmateriaFramesCounter)
|
||||
DECLARE_VAR(AmateriaTicksCounter)
|
||||
|
||||
DECLARE_VAR(ResonanceRingsSolved)
|
||||
|
||||
@ -306,7 +306,7 @@ public:
|
||||
DECLARE_VAR(StateCanSave)
|
||||
|
||||
void updateFrameCounters();
|
||||
uint getFrameCount() { return _data.currentFrame; }
|
||||
uint getTickCount() const;
|
||||
|
||||
ViewType getViewType() { return static_cast<ViewType>(_data.currentNodeType); }
|
||||
void setViewType(ViewType t) { _data.currentNodeType = t; }
|
||||
@ -417,6 +417,8 @@ private:
|
||||
static void syncFloat(Common::Serializer &s, float &val,
|
||||
Common::Serializer::Version minVersion = 0,
|
||||
Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
|
||||
|
||||
void updateTickCounters();
|
||||
};
|
||||
|
||||
} // End of namespace Myst3
|
||||
|
@ -54,12 +54,12 @@ Transition::~Transition() {
|
||||
}
|
||||
|
||||
int Transition::computeDuration() {
|
||||
int durationFrames = 30 * (100 - ConfMan.getInt("transition_speed")) / 100;
|
||||
int durationTicks = 30 * (100 - ConfMan.getInt("transition_speed")) / 100;
|
||||
if (_type == kTransitionZip) {
|
||||
durationFrames >>= 1;
|
||||
durationTicks >>= 1;
|
||||
}
|
||||
|
||||
return durationFrames;
|
||||
return durationTicks;
|
||||
}
|
||||
|
||||
void Transition::playSound() {
|
||||
@ -76,10 +76,10 @@ void Transition::draw(TransitionType type) {
|
||||
// Play the transition sound
|
||||
playSound();
|
||||
|
||||
int durationFrames = computeDuration();
|
||||
int durationTicks = computeDuration();
|
||||
|
||||
// Got any transition to draw?
|
||||
if (!_sourceScreenshot || type == kTransitionNone || durationFrames == 0) {
|
||||
if (!_sourceScreenshot || type == kTransitionNone || durationTicks == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -94,15 +94,15 @@ void Transition::draw(TransitionType type) {
|
||||
delete target;
|
||||
|
||||
// Compute the start and end frames for the animation
|
||||
int startFrame = _vm->_state->getFrameCount();
|
||||
uint endFrame = startFrame + durationFrames;
|
||||
int startTick = _vm->_state->getTickCount();
|
||||
uint endTick = startTick + durationTicks;
|
||||
|
||||
// Draw each step until completion
|
||||
int completion = 0;
|
||||
while (_vm->_state->getFrameCount() <= endFrame || completion < 100) {
|
||||
while (_vm->_state->getTickCount() <= endTick || completion < 100) {
|
||||
_frameLimiter->startFrame();
|
||||
|
||||
completion = CLIP<int>(100 * (_vm->_state->getFrameCount() - startFrame) / durationFrames, 0, 100);
|
||||
completion = CLIP<int>(100 * (_vm->_state->getTickCount() - startTick) / durationTicks, 0, 100);
|
||||
|
||||
drawStep(targetTexture, sourceTexture, completion);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user