diff options
52 files changed, 689 insertions, 609 deletions
diff --git a/engines/bladerunner/actor.cpp b/engines/bladerunner/actor.cpp index 84febccc2e..df78b00593 100644 --- a/engines/bladerunner/actor.cpp +++ b/engines/bladerunner/actor.cpp @@ -70,63 +70,63 @@ Actor::~Actor() { } void Actor::setup(int actorId) { - _id = actorId; - _setId = -1; + _id = actorId; + _setId = -1; - _position = Vector3(0.0, 0.0, 0.0); - _facing = 512; - _targetFacing = -1; - _walkboxId = -1; + _position = Vector3(0.0, 0.0, 0.0); + _facing = 512; + _targetFacing = -1; + _walkboxId = -1; _animationId = 0; _animationFrame = 0; _fps = 15; - _frameMs = 1000 / _fps; + _frameMs = 1000 / _fps; _mustReachWalkDestination = false; // Original's _inWalkLoop. Moved here from our constructor, since it's here in the original's init() - _isMoving = false; - _isTarget = false; - _inCombat = false; - _isInvisible = false; - _isImmuneToObstacles = false; - _isRetired = false; + _isMoving = false; + _isTarget = false; + _inCombat = false; + _isInvisible = false; + _isImmuneToObstacles = false; + _isRetired = false; - _width = 0; - _height = 0; - _retiredWidth = 0; - _retiredHeight = 0; - _scale = 1.0f; + _width = 0; + _height = 0; + _retiredWidth = 0; + _retiredHeight = 0; + _scale = 1.0f; - _timer4RemainDefault = 60000; + _timer4RemainDefault = 60000u; _movementTrackWalkingToWaypointId = -1; - _movementTrackDelayOnNextWaypoint = -1; + _movementTrackDelayOnNextWaypoint = (uint32)(-1); // original was -1, int for (int i = 0; i != kActorTimers; ++i) { - _timersLeft[i] = 0; + _timersLeft[i] = 0u; _timersLast[i] = _vm->_time->current(); } _timersLeft[kActorTimerClueExchange] = _timer4RemainDefault; // This was in original code. We need to init this timer in order to kick off periodic updates for acquireCluesByRelations - _honesty = 50; - _intelligence = 50; - _combatAggressiveness = 50; - _stability = 50; + _honesty = 50; + _intelligence = 50; + _combatAggressiveness = 50; + _stability = 50; - _currentHP = 50; - _maxHP = 50; + _currentHP = 50; + _maxHP = 50; - _damageAnimIfMoving = true; // Set to true (like in original). And moved here from our constructor, since it's here in the original's init(). + _damageAnimIfMoving = true; // Set to true (like in original). And moved here from our constructor, since it's here in the original's init(). - _goalNumber = -1; + _goalNumber = -1; _movementTrackPaused = false; _movementTrackNextWaypointId = -1; - _movementTrackNextDelay = -1; + _movementTrackNextDelay = (uint32)(-1); // original was -1, int _movementTrackNextAngle = -1; _movementTrackNextRunning = false; - _animationMode = -1; + _animationMode = -1; _screenRectangle = Common::Rect(-1, -1, -1, -1); _animationModeCombatIdle = kAnimationModeCombatIdle; @@ -220,18 +220,21 @@ void Actor::increaseFPS() { setFPS(fps); } -void Actor::timerStart(int timerId, int interval) { +void Actor::timerStart(int timerId, uint32 interval) { assert(timerId >= 0 && timerId < kActorTimers); + if ((int32)interval == -1 ) { + interval = 0u; + } _timersLeft[timerId] = interval; _timersLast[timerId] = _vm->_time->current(); } void Actor::timerReset(int timerId) { assert(timerId >= 0 && timerId < kActorTimers); - _timersLeft[timerId] = 0; + _timersLeft[timerId] = 0u; } -int Actor::timerLeft(int timerId) { +uint32 Actor::timerLeft(int timerId) { assert(timerId >= 0 && timerId < kActorTimers); return _timersLeft[timerId]; } @@ -243,16 +246,21 @@ void Actor::timersUpdate() { } void Actor::timerUpdate(int timerId) { - if (_timersLeft[timerId] == 0) { + if (_timersLeft[timerId] == 0u) { return; } uint32 timeNow = _vm->_time->current(); - int timeDiff = timeNow - _timersLast[timerId]; + uint32 timeDiff = timeNow - _timersLast[timerId]; // unsigned difference is intentional _timersLast[timerId] = timeNow; - _timersLeft[timerId] -= timeDiff; + // new check is safe-guard against old saves, _timersLeft should never have very big value anyway + if ((int32)_timersLeft[timerId] < 0 ) { + // this will make it 0u in the next command below + _timersLeft[timerId] = 0u; + } + _timersLeft[timerId] = (_timersLeft[timerId] < timeDiff) ? 0u : (_timersLeft[timerId] - timeDiff); - if (_timersLeft[timerId] <= 0) { + if (_timersLeft[timerId] == 0u) { // original check was <= 0 switch (timerId) { case kActorTimerAIScriptCustomTask0: // fall through @@ -261,15 +269,15 @@ void Actor::timerUpdate(int timerId) { case kActorTimerAIScriptCustomTask2: if (!_vm->_aiScripts->isInsideScript() && !_vm->_sceneScript->isInsideScript()) { _vm->_aiScripts->timerExpired(_id, timerId); - _timersLeft[timerId] = 0; + _timersLeft[timerId] = 0u; } else { - _timersLeft[timerId] = 1; + _timersLeft[timerId] = 1u; } break; case kActorTimerMovementTrack: - _timersLeft[kActorTimerMovementTrack] = 0; + _timersLeft[kActorTimerMovementTrack] = 0u; if (_movementTrack->isPaused()) { - _timersLeft[kActorTimerMovementTrack] = 1; + _timersLeft[kActorTimerMovementTrack] = 1u; } else { movementTrackNext(false); } @@ -292,7 +300,7 @@ void Actor::timerUpdate(int timerId) { setFPS(newFps); } } - _timersLeft[kActorTimerRunningStaminaFPS] = 200; + _timersLeft[kActorTimerRunningStaminaFPS] = 200u; break; } } @@ -302,7 +310,7 @@ void Actor::movementTrackNext(bool omitAiScript) { bool hasNextMovement; bool running; int angle; - int delay; + uint32 delay; int waypointId; Vector3 waypointPosition; bool arrived; @@ -332,9 +340,9 @@ void Actor::movementTrackNext(bool omitAiScript) { setAtXYZ(waypointPosition, angle, true, false, false); if (!delay) { - delay = 1; + delay = 1u; } - if (delay > 1) { + if ((int32)delay != -1 && delay > 1u) { changeAnimationMode(kAnimationModeIdle, false); } timerStart(kActorTimerMovementTrack, delay); @@ -372,13 +380,13 @@ void Actor::movementTrackUnpause() { void Actor::movementTrackWaypointReached() { if (!_movementTrack->isPaused() && _id != kActorMcCoy) { - if (_movementTrackWalkingToWaypointId >= 0 && _movementTrackDelayOnNextWaypoint >= 0) { + if (_movementTrackWalkingToWaypointId >= 0 && (int32)(_movementTrackDelayOnNextWaypoint) != -1) { // original was _movementTrackDelayOnNextWaypoint >= 0u if (!_movementTrackDelayOnNextWaypoint) { - _movementTrackDelayOnNextWaypoint = 1; + _movementTrackDelayOnNextWaypoint = 1u; } if (_vm->_aiScripts->reachedMovementTrackWaypoint(_id, _movementTrackWalkingToWaypointId)) { - int delay = _movementTrackDelayOnNextWaypoint; - if (delay > 1) { + uint32 delay = _movementTrackDelayOnNextWaypoint; + if (delay > 1u) { changeAnimationMode(kAnimationModeIdle, false); delay = _movementTrackDelayOnNextWaypoint; // todo: analyze if movement is changed in some aiscript->ChangeAnimationMode? } @@ -386,7 +394,7 @@ void Actor::movementTrackWaypointReached() { } } _movementTrackWalkingToWaypointId = -1; - _movementTrackDelayOnNextWaypoint = 0; + _movementTrackDelayOnNextWaypoint = 0u; } } @@ -604,17 +612,17 @@ void Actor::run() { } bool Actor::tick(bool forceDraw, Common::Rect *screenRect) { - int timeLeft = 0; + uint32 timeLeft = 0u; bool needsUpdate = false; if (_fps > 0) { timerUpdate(kActorTimerAnimationFrame); timeLeft = timerLeft(kActorTimerAnimationFrame); - needsUpdate = timeLeft <= 0; + needsUpdate = (timeLeft == 0); // original was <= 0, with timeLeft int } else if (_fps == 0) { needsUpdate = false; } else if (forceDraw) { needsUpdate = true; - timeLeft = 0; + timeLeft = 0u; } if (needsUpdate) { @@ -722,11 +730,11 @@ bool Actor::tick(bool forceDraw, Common::Rect *screenRect) { } if (needsUpdate) { - int nextFrameTime = timeLeft + _frameMs; + int nextFrameTime = (int)(timeLeft + _frameMs); // Should be ok if (nextFrameTime <= 0) { nextFrameTime = 1; } - timerStart(kActorTimerAnimationFrame, nextFrameTime); + timerStart(kActorTimerAnimationFrame, (uint32)nextFrameTime); } if (_targetFacing >= 0) { if (_targetFacing == _facing) { @@ -1417,7 +1425,7 @@ void Actor::save(SaveFileWriteStream &f) { uint32 now = _vm->_time->getPauseStart(); for (int i = 0; i < kActorTimers; ++i) { // this effectively stores the next timeDiff to be applied to timer i (in timerUpdate) - f.writeInt(now - _timersLast[i]); + f.writeInt(now - _timersLast[i]); // Unsigned difference is intentional } int actorCount = _vm->_gameInfo->getActorCount(); @@ -1446,7 +1454,7 @@ void Actor::load(SaveFileReadStream &f) { _position = f.readVector3(); _facing = f.readInt(); _targetFacing = f.readInt(); - _timer4RemainDefault = f.readInt(); + _timer4RemainDefault = (uint32)f.readInt(); _honesty = f.readInt(); _intelligence = f.readInt(); @@ -1460,7 +1468,7 @@ void Actor::load(SaveFileReadStream &f) { _movementTrackPaused = f.readBool(); _movementTrackNextWaypointId = f.readInt(); - _movementTrackNextDelay = f.readInt(); + _movementTrackNextDelay = (uint32)f.readInt(); _movementTrackNextAngle = f.readInt(); _movementTrackNextRunning = f.readBool(); @@ -1480,7 +1488,7 @@ void Actor::load(SaveFileReadStream &f) { _animationFrame = f.readInt(); _movementTrackWalkingToWaypointId = f.readInt(); - _movementTrackDelayOnNextWaypoint = f.readInt(); + _movementTrackDelayOnNextWaypoint = (uint32)f.readInt(); _screenRectangle = f.readRect(); _retiredWidth = f.readInt(); @@ -1491,17 +1499,17 @@ void Actor::load(SaveFileReadStream &f) { _scale = f.readFloat(); for (int i = 0; i < kActorTimers; ++i) { - _timersLeft[i] = f.readInt(); + _timersLeft[i] = (uint32)f.readInt(); } // Bugfix: Special initialization case for timer 4 (kActorTimerClueExchange) when its value is restored as 0 // This should be harmless, but will remedy any broken save-games where the timer 4 was saved as 0. - if (_timersLeft[kActorTimerClueExchange] == 0) { + if (_timersLeft[kActorTimerClueExchange] == 0u) { _timersLeft[kActorTimerClueExchange] = _timer4RemainDefault; } uint32 now = _vm->_time->getPauseStart(); for (int i = 0; i < kActorTimers; ++i) { - _timersLast[i] = now - f.readInt(); + _timersLast[i] = now - (uint32)(f.readInt()); // we require an unsigned difference here, since _timersLast is essentially keeping time } int actorCount = _vm->_gameInfo->getActorCount(); diff --git a/engines/bladerunner/actor.h b/engines/bladerunner/actor.h index 5f4884fa4e..a7336b78f7 100644 --- a/engines/bladerunner/actor.h +++ b/engines/bladerunner/actor.h @@ -73,7 +73,7 @@ private: int _walkboxId; int _cluesLimit; - int _timer4RemainDefault; + uint32 _timer4RemainDefault; // Flags bool _isTarget; @@ -86,14 +86,14 @@ private: bool _damageAnimIfMoving; // Movement - bool _movementTrackPaused; - int _movementTrackNextWaypointId; - int _movementTrackNextDelay; // probably not used - int _movementTrackNextAngle; // probably not used - bool _movementTrackNextRunning; + bool _movementTrackPaused; + int _movementTrackNextWaypointId; + uint32 _movementTrackNextDelay; // probably not used + int _movementTrackNextAngle; // probably not used + bool _movementTrackNextRunning; - int _movementTrackWalkingToWaypointId; - int _movementTrackDelayOnNextWaypoint; + int _movementTrackWalkingToWaypointId; + uint32 _movementTrackDelayOnNextWaypoint; // Animation int _width; @@ -110,8 +110,8 @@ private: int _retiredWidth; int _retiredHeight; - int _timersLeft[kActorTimers]; - int _timersLast[kActorTimers]; + uint32 _timersLeft[kActorTimers]; // this keeps time difference, and it is stored during save() (saveInt actually saves a uint32) + uint32 _timersLast[kActorTimers]; // this keeps actual time, and is not stored during save(), so it can be a uint32 float _scale; @@ -143,11 +143,11 @@ public: void setFPS(int fps); void increaseFPS(); - void timerStart(int timerId, int interval); - void timerReset(int timerId); - int timerLeft(int timerId); - void timersUpdate(); - void timerUpdate(int timerId); + void timerStart(int timerId, uint32 interval); + void timerReset(int timerId); + uint32 timerLeft(int timerId); + void timersUpdate(); + void timerUpdate(int timerId); void movementTrackNext(bool omitAiScript); void movementTrackPause(); diff --git a/engines/bladerunner/actor_dialogue_queue.cpp b/engines/bladerunner/actor_dialogue_queue.cpp index 627b0b1cb3..31cb9ad5a6 100644 --- a/engines/bladerunner/actor_dialogue_queue.cpp +++ b/engines/bladerunner/actor_dialogue_queue.cpp @@ -38,7 +38,7 @@ ActorDialogueQueue::Entry::Entry() { isNotPause = false; isPause = false; actorId = -1; - delay = -1; + delay = (uint32)(-1); // original was -1, int sentenceId = -1; animationMode = -1; } @@ -62,13 +62,13 @@ void ActorDialogueQueue::add(int actorId, int sentenceId, int animationMode) { entry.actorId = actorId; entry.sentenceId = sentenceId; entry.animationMode = animationMode; - entry.delay = -1; + entry.delay = (uint32)(-1); // original was -1, int _entries.push_back(entry); } } -void ActorDialogueQueue::addPause(int delay) { +void ActorDialogueQueue::addPause(uint32 delay) { if (_entries.size() < kMaxEntries) { Entry entry; entry.isNotPause = false; @@ -96,8 +96,8 @@ void ActorDialogueQueue::flush(int a1, bool callScript) { } if (_isPause) { _isPause = false; - _delay = 0; - _timeLast = 0; + _delay = 0u; + _timeLast = 0u; } clear(); if (callScript) { @@ -116,23 +116,23 @@ bool ActorDialogueQueue::isEmpty() { && _sentenceId == -1 \ && _animationMode == -1 \ && _animationModePrevious == -1 \ - && _delay == 0 \ - && _timeLast == 0; + && _delay == 0u \ + && _timeLast == 0u; } void ActorDialogueQueue::tick() { if (!_vm->_audioSpeech->isPlaying()) { if (_isPause) { - int time = _vm->_time->current(); - int timeDiff = time - _timeLast; + uint32 time = _vm->_time->current(); + uint32 timeDiff = time - _timeLast; // unsigned difference is intentional _timeLast = time; - _delay -= timeDiff; - if (_delay > 0) { + _delay = ((int32)_delay == -1 || (_delay < timeDiff) ) ? 0u : (_delay - timeDiff); + if (_delay > 0u) { return; } _isPause = false; - _delay = 0; - _timeLast = 0; + _delay = 0u; + _timeLast = 0u; if (_entries.empty()) { flush(0, true); } @@ -212,7 +212,7 @@ void ActorDialogueQueue::load(SaveFileReadStream &f) { e.actorId = f.readInt(); e.sentenceId = f.readInt(); e.animationMode = f.readInt(); - e.delay = f.readInt(); + e.delay = (uint32)f.readInt(); } f.skip((kMaxEntries - count) * 24); @@ -223,9 +223,8 @@ void ActorDialogueQueue::load(SaveFileReadStream &f) { _animationMode = f.readInt(); _animationModePrevious = f.readInt(); _isPause = f.readBool(); - _delay = f.readInt(); - - _timeLast = 0; + _delay = (uint32)f.readInt(); + _timeLast = 0u; } void ActorDialogueQueue::clear() { @@ -236,8 +235,8 @@ void ActorDialogueQueue::clear() { _animationMode = -1; _animationModePrevious = -1; _isPause = false; - _delay = 0; - _timeLast = 0; + _delay = 0u; + _timeLast = 0u; } } // End of namespace BladeRunner diff --git a/engines/bladerunner/actor_dialogue_queue.h b/engines/bladerunner/actor_dialogue_queue.h index bba900db7d..8ae3a0a2e0 100644 --- a/engines/bladerunner/actor_dialogue_queue.h +++ b/engines/bladerunner/actor_dialogue_queue.h @@ -35,12 +35,12 @@ class ActorDialogueQueue { static const uint kMaxEntries = 25; struct Entry { - bool isNotPause; - bool isPause; - int actorId; - int sentenceId; - int animationMode; - int delay; + bool isNotPause; + bool isPause; + int actorId; + int sentenceId; + int animationMode; + uint32 delay; Entry(); }; @@ -54,15 +54,15 @@ class ActorDialogueQueue { int _animationMode; int _animationModePrevious; bool _isPause; - int _delay; - int _timeLast; + uint32 _delay; + uint32 _timeLast; public: ActorDialogueQueue(BladeRunnerEngine *vm); ~ActorDialogueQueue(); void add(int actorId, int sentenceId, int animationMode); - void addPause(int delay); + void addPause(uint32 delay); void flush(int a1, bool callScript); bool isEmpty(); void tick(); diff --git a/engines/bladerunner/ambient_sounds.cpp b/engines/bladerunner/ambient_sounds.cpp index 7d0db4763e..8fe7a1c16a 100644 --- a/engines/bladerunner/ambient_sounds.cpp +++ b/engines/bladerunner/ambient_sounds.cpp @@ -67,7 +67,7 @@ static inline void sort(int &a, int &b) { void AmbientSounds::addSound( int sfxId, - int timeMin, int timeMax, + uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, @@ -101,7 +101,7 @@ void AmbientSounds::removeAllNonLoopingSounds(bool stopPlaying) { } } -void AmbientSounds::addSpeech(int actorId, int sentenceId, int timeMin, int timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk) { +void AmbientSounds::addSpeech(int actorId, int sentenceId, uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk) { sort(volumeMin, volumeMax); sort(panStartMin, panStartMax); sort(panEndMin, panEndMax); @@ -124,7 +124,7 @@ void AmbientSounds::playSpeech(int actorId, int sentenceId, int volume, int panS _vm->_audioPlayer->playAud(name, volume * _ambientVolume / 100, panStart, panEnd, priority, kAudioPlayerOverrideVolume, Audio::Mixer::kSpeechSoundType); } -void AmbientSounds::addLoopingSound(int sfxId, int volume, int pan, int delay) { +void AmbientSounds::addLoopingSound(int sfxId, int volume, int pan, uint32 delay) { const Common::String &name = _vm->_gameInfo->getSfxTrack(sfxId); int32 hash = MIXArchive::getHash(name); @@ -147,7 +147,7 @@ void AmbientSounds::addLoopingSound(int sfxId, int volume, int pan, int delay) { int actualVolumeStart = volume * _ambientVolume / 100; int actualVolumeEnd = actualVolumeStart; - if (delay > 0) { + if (delay > 0u) { actualVolumeStart = 0; } @@ -162,7 +162,7 @@ void AmbientSounds::addLoopingSound(int sfxId, int volume, int pan, int delay) { } } -void AmbientSounds::adjustLoopingSound(int sfxId, int volume, int pan, int delay) { +void AmbientSounds::adjustLoopingSound(int sfxId, int volume, int pan, uint32 delay) { int32 hash = MIXArchive::getHash(_vm->_gameInfo->getSfxTrack(sfxId)); int index = findLoopingTrackByHash(hash); @@ -178,7 +178,7 @@ void AmbientSounds::adjustLoopingSound(int sfxId, int volume, int pan, int delay } } -void AmbientSounds::removeLoopingSound(int sfxId, int delay) { +void AmbientSounds::removeLoopingSound(int sfxId, uint32 delay) { int32 hash = MIXArchive::getHash(_vm->_gameInfo->getSfxTrack(sfxId)); int index = findLoopingTrackByHash(hash); if (index >= 0) { @@ -186,7 +186,7 @@ void AmbientSounds::removeLoopingSound(int sfxId, int delay) { } } -void AmbientSounds::removeAllLoopingSounds(int delay) { +void AmbientSounds::removeAllLoopingSounds(uint32 delay) { for (int i = 0; i < kLoopingSounds; i++) { removeLoopingSoundByIndex(i, delay); } @@ -198,7 +198,8 @@ void AmbientSounds::tick() { for (int i = 0; i != kNonLoopingSounds; ++i) { NonLoopingSound &track = _nonLoopingSounds[i]; - if (!track.isActive || track.nextPlayTime > now) { + // unsigned difference is intentional + if (!track.isActive || now - track.nextPlayTimeStart < track.nextPlayTimeDiff) { continue; } @@ -219,7 +220,8 @@ void AmbientSounds::tick() { track.priority, kAudioPlayerOverrideVolume); - track.nextPlayTime = now + _vm->_rnd.getRandomNumberRng(track.timeMin, track.timeMax); + track.nextPlayTimeStart = now; + track.nextPlayTimeDiff = _vm->_rnd.getRandomNumberRng(track.timeMin, track.timeMax); } } @@ -229,13 +231,13 @@ void AmbientSounds::setVolume(int volume) { if (_loopingSounds[i].isActive && _loopingSounds[i].audioPlayerTrack != -1) { int newVolume = _loopingSounds[i].volume * volume / 100; if (_vm->_audioPlayer->isActive(_loopingSounds[i].audioPlayerTrack)) { - _vm->_audioPlayer->adjustVolume(_loopingSounds[i].audioPlayerTrack, newVolume, 1, false); + _vm->_audioPlayer->adjustVolume(_loopingSounds[i].audioPlayerTrack, newVolume, 1u, false); } else { _loopingSounds[i].audioPlayerTrack = _vm->_audioPlayer->playAud(_loopingSounds[i].name, 1, _loopingSounds[i].pan, _loopingSounds[i].pan, 99, kAudioPlayerLoop | kAudioPlayerOverrideVolume); if (_loopingSounds[i].audioPlayerTrack == -1) { removeLoopingSound(i, 0); } else { - _vm->_audioPlayer->adjustVolume(_loopingSounds[i].audioPlayerTrack, newVolume, 1, false); + _vm->_audioPlayer->adjustVolume(_loopingSounds[i].audioPlayerTrack, newVolume, 1u, false); } } } @@ -298,7 +300,7 @@ int AmbientSounds::findLoopingTrackByHash(int32 hash) const { void AmbientSounds::addSoundByName( const Common::String &name, - int timeMin, int timeMax, + uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, @@ -316,9 +318,10 @@ void AmbientSounds::addSoundByName( track.isActive = true; track.name = name; track.hash = MIXArchive::getHash(name); - track.timeMin = 1000 * timeMin; - track.timeMax = 1000 * timeMax; - track.nextPlayTime = now + _vm->_rnd.getRandomNumberRng(track.timeMin, track.timeMax); + track.timeMin = 1000u * timeMin; + track.timeMax = 1000u * timeMax; + track.nextPlayTimeStart = now; + track.nextPlayTimeDiff = _vm->_rnd.getRandomNumberRng(track.timeMin, track.timeMax); track.volumeMin = volumeMin; track.volumeMax = volumeMax; track.volume = 0; @@ -341,10 +344,10 @@ void AmbientSounds::removeNonLoopingSoundByIndex(int index, bool stopPlaying) { // track.field_45 = 0; } -void AmbientSounds::removeLoopingSoundByIndex(int index, int delay) { +void AmbientSounds::removeLoopingSoundByIndex(int index, uint32 delay) { LoopingSound &track = _loopingSounds[index]; if (track.isActive && track.audioPlayerTrack != -1 && _vm->_audioPlayer->isActive(track.audioPlayerTrack)) { - if (delay > 0) { + if (delay > 0u) { _vm->_audioPlayer->adjustVolume(track.audioPlayerTrack, 0, delay, false); } else { _vm->_audioPlayer->stop(track.audioPlayerTrack, false); @@ -409,10 +412,11 @@ void AmbientSounds::load(SaveFileReadStream &f) { track.hash = f.readSint32LE(); f.skip(4); // track.audioPlayerTrack is not used after load track.audioPlayerTrack = -1; - track.timeMin = f.readInt(); - track.timeMax = f.readInt(); + track.timeMin = (uint32)f.readInt(); + track.timeMax = (uint32)f.readInt(); f.skip(4); // track.nextPlayTime is not used after load - track.nextPlayTime = now + _vm->_rnd.getRandomNumberRng(track.timeMin, track.timeMax); + track.nextPlayTimeStart = now; + track.nextPlayTimeDiff = _vm->_rnd.getRandomNumberRng(track.timeMin, track.timeMax); track.volumeMin = f.readInt(); track.volumeMax = f.readInt(); track.volume = f.readInt(); @@ -442,7 +446,7 @@ void AmbientSounds::load(SaveFileReadStream &f) { if (track.audioPlayerTrack == -1) { removeLoopingSoundByIndex(i, 0); } else { - _vm->_audioPlayer->adjustVolume(track.audioPlayerTrack, _ambientVolume * track.volume / 100, 2, false); + _vm->_audioPlayer->adjustVolume(track.audioPlayerTrack, _ambientVolume * track.volume / 100, 2u, false); } } } diff --git a/engines/bladerunner/ambient_sounds.h b/engines/bladerunner/ambient_sounds.h index 06144d6076..73b8e7535d 100644 --- a/engines/bladerunner/ambient_sounds.h +++ b/engines/bladerunner/ambient_sounds.h @@ -42,9 +42,10 @@ class AmbientSounds { Common::String name; int32 hash; int audioPlayerTrack; - int timeMin; - int timeMax; - uint32 nextPlayTime; + uint32 timeMin; + uint32 timeMax; + uint32 nextPlayTimeStart; + uint32 nextPlayTimeDiff; int volumeMin; int volumeMax; int volume; @@ -76,7 +77,7 @@ public: void addSound( int sfxId, - int timeMin, int timeMax, + uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, @@ -87,7 +88,7 @@ public: void addSpeech( int actorId, int sentenceId, - int timeMin, int timeMax, + uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, @@ -95,12 +96,12 @@ public: void playSound(int sfxId, int volume, int panStart, int panEnd, int priority); void playSpeech(int actorId, int sentenceId, int volume, int panStart, int panEnd, int priority); - void addLoopingSound(int sfxId, int volume, int pan, int delay); - void adjustLoopingSound(int sfxId, int volume, int pan, int delay); + void addLoopingSound(int sfxId, int volume, int pan, uint32 delay); + void adjustLoopingSound(int sfxId, int volume, int pan, uint32 delay); // it seems there is little confusion in original code about delay parameter, // sometimes it is used as boolean in same way as stopPlaying from non looping - void removeLoopingSound(int sfxId, int delay); - void removeAllLoopingSounds(int delay); + void removeLoopingSound(int sfxId, uint32 delay); + void removeAllLoopingSounds(uint32 delay); void tick(); @@ -120,14 +121,14 @@ private: void addSoundByName( const Common::String &name, - int timeMin, int timeMax, + uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk); void removeNonLoopingSoundByIndex(int index, bool stopPlaying); - void removeLoopingSoundByIndex(int index, int delay); + void removeLoopingSoundByIndex(int index, uint32 delay); }; } // End of namespace BladeRunner diff --git a/engines/bladerunner/audio_mixer.cpp b/engines/bladerunner/audio_mixer.cpp index df3a36154e..c31ade8296 100644 --- a/engines/bladerunner/audio_mixer.cpp +++ b/engines/bladerunner/audio_mixer.cpp @@ -28,7 +28,6 @@ #include "audio/mixer.h" #include "common/timer.h" -//#include "common/debug.h" namespace BladeRunner { @@ -37,7 +36,7 @@ AudioMixer::AudioMixer(BladeRunnerEngine *vm) { for (int i = 0; i < kChannels; i++) { _channels[i].isPresent = false; } - _vm->getTimerManager()->installTimerProc(timerCallback, (1000 / kUpdatesPerSecond) * 1000 , this, "BladeRunnerAudioMixerTimer"); + _vm->getTimerManager()->installTimerProc(timerCallback, (1000 / kUpdatesPerSecond) * 1000, this, "BladeRunnerAudioMixerTimer"); } AudioMixer::~AudioMixer() { @@ -82,7 +81,7 @@ int AudioMixer::playMusic(Audio::RewindableAudioStream *stream, int volume, void return playInChannel(kMusicChannel, Audio::Mixer::kMusicSoundType, stream, 100, false, volume, 0, endCallback, callbackData); } -void AudioMixer::stop(int channel, int time) { +void AudioMixer::stop(int channel, uint32 time) { Common::StackLock lock(_mutex); if (_channels[channel].isPresent) { @@ -139,7 +138,7 @@ void AudioMixer::timerCallback(void *self) { ((AudioMixer *)self)->tick(); } -void AudioMixer::adjustVolume(int channel, int newVolume, int time) { +void AudioMixer::adjustVolume(int channel, int newVolume, uint32 time) { Common::StackLock lock(_mutex); if (_channels[channel].isPresent) { @@ -148,7 +147,7 @@ void AudioMixer::adjustVolume(int channel, int newVolume, int time) { } } -void AudioMixer::adjustPan(int channel, int newPan, int time) { +void AudioMixer::adjustPan(int channel, int newPan, uint32 time) { Common::StackLock lock(_mutex); if (_channels[channel].isPresent) { diff --git a/engines/bladerunner/audio_mixer.h b/engines/bladerunner/audio_mixer.h index bb43d57632..46467c636d 100644 --- a/engines/bladerunner/audio_mixer.h +++ b/engines/bladerunner/audio_mixer.h @@ -71,13 +71,13 @@ public: int play(Audio::Mixer::SoundType type, Audio::RewindableAudioStream *stream, int priority, bool loop, int volume, int pan, void(*endCallback)(int, void *), void *callbackData); int playMusic(Audio::RewindableAudioStream *stream, int volume, void(*endCallback)(int, void *), void *callbackData); - void stop(int channel, int delay); + void stop(int channel, uint32 delay); - void adjustVolume(int channel, int newVolume, int time); - void adjustPan(int channel, int newPan, int time); + void adjustVolume(int channel, int newVolume, uint32 time); + void adjustPan(int channel, int newPan, uint32 time); - void resume(int channel, int delay); - void pause(int channel, int delay); + void resume(int channel, uint32 delay); + void pause(int channel, uint32 delay); private: int playInChannel(int channel, Audio::Mixer::SoundType type, Audio::RewindableAudioStream *stream, int priority, bool loop, int volume, int pan, void(*endCallback)(int, void *), void *callbackData); diff --git a/engines/bladerunner/audio_player.cpp b/engines/bladerunner/audio_player.cpp index 4fb2fef5af..e5045f01d8 100644 --- a/engines/bladerunner/audio_player.cpp +++ b/engines/bladerunner/audio_player.cpp @@ -66,7 +66,7 @@ void AudioPlayer::stopAll() { } } -void AudioPlayer::adjustVolume(int track, int volume, int delay, bool overrideVolume) { +void AudioPlayer::adjustVolume(int track, int volume, uint32 delay, bool overrideVolume) { if (track < 0 || track >= kTracks || !_tracks[track].isActive || _tracks[track].channel == -1) { return; } @@ -77,16 +77,16 @@ void AudioPlayer::adjustVolume(int track, int volume, int delay, bool overrideVo } _tracks[track].volume = actualVolume; - _vm->_audioMixer->adjustVolume(_tracks[track].channel, actualVolume, 60 * delay); + _vm->_audioMixer->adjustVolume(_tracks[track].channel, actualVolume, 60u * delay); } -void AudioPlayer::adjustPan(int track, int pan, int delay) { +void AudioPlayer::adjustPan(int track, int pan, uint32 delay) { if (track < 0 || track >= kTracks || !_tracks[track].isActive || _tracks[track].channel == -1) { return; } _tracks[track].pan = pan; - _vm->_audioMixer->adjustPan(_tracks[track].channel, pan, 60 * delay); + _vm->_audioMixer->adjustPan(_tracks[track].channel, pan, 60u * delay); } void AudioPlayer::setVolume(int volume) { diff --git a/engines/bladerunner/audio_player.h b/engines/bladerunner/audio_player.h index a1823b7ffa..bb6f3f325c 100644 --- a/engines/bladerunner/audio_player.h +++ b/engines/bladerunner/audio_player.h @@ -70,8 +70,8 @@ public: bool isActive(int track) const; void stop(int track, bool immediately); void stopAll(); - void adjustVolume(int track, int volume, int delay, bool overrideVolume); - void adjustPan(int track, int pan, int delay); + void adjustVolume(int track, int volume, uint32 delay, bool overrideVolume); + void adjustPan(int track, int pan, uint32 delay); void setVolume(int volume); int getVolume() const; diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp index 412ef1da68..094d27e80f 100644 --- a/engines/bladerunner/bladerunner.cpp +++ b/engines/bladerunner/bladerunner.cpp @@ -584,7 +584,7 @@ bool BladeRunnerEngine::startup(bool hasSavegames) { _playerActor = _actors[_gameInfo->getPlayerId()]; _playerActor->setFPS(15); - _playerActor->timerStart(kActorTimerRunningStaminaFPS, 200); + _playerActor->timerStart(kActorTimerRunningStaminaFPS, 200u); _policeMaze = new PoliceMaze(this); @@ -1108,7 +1108,7 @@ void BladeRunnerEngine::gameTick() { void BladeRunnerEngine::actorsUpdate() { #if BLADERUNNER_ORIGINAL_BUGS #else - int timeNow = _time->current(); + uint32 timeNow = _time->current(); // Don't update actors more than 60 times per second if (timeNow - _actorUpdateTimeLast < 1000 / 60) { return; @@ -1321,9 +1321,10 @@ void BladeRunnerEngine::handleMouseAction(int x, int y, bool mainButton, bool bu x = CLIP(x, 0, 639); y = CLIP(y, 0, 479); - int timeNow = _time->current(); + uint32 timeNow = _time->current(); if (buttonDown) { + // unsigned difference is intentional _mouseClickTimeDiff = timeNow - _mouseClickTimeLast; _mouseClickTimeLast = timeNow; } @@ -1964,8 +1965,9 @@ void BladeRunnerEngine::playerDied() { _audioSpeech->stopSpeech(); #endif // BLADERUNNER_ORIGINAL_BUGS - int timeWaitEnd = _time->current() + 5000; - while (_time->current() < timeWaitEnd) { + uint32 timeWaitStart = _time->current(); + // unsigned difference is intentional + while (_time->current() - timeWaitStart < 5000u) { gameTick(); } diff --git a/engines/bladerunner/bladerunner.h b/engines/bladerunner/bladerunner.h index ceff3d70c4..3293741915 100644 --- a/engines/bladerunner/bladerunner.h +++ b/engines/bladerunner/bladerunner.h @@ -36,9 +36,9 @@ #include "graphics/surface.h" //TODO: change this to debugflag -#define BLADERUNNER_DEBUG_CONSOLE 0 +#define BLADERUNNER_DEBUG_CONSOLE 0 #define BLADERUNNER_ORIGINAL_SETTINGS 0 -#define BLADERUNNER_ORIGINAL_BUGS 0 +#define BLADERUNNER_ORIGINAL_BUGS 0 namespace Common { struct Event; @@ -108,13 +108,16 @@ class ZBuffer; class BladeRunnerEngine : public Engine { public: static const int kArchiveCount = 12; // +2 to original value (10) to accommodate for SUBTITLES.MIX and one extra resource file, to allow for capability of loading all VQAx.MIX and the MODE.MIX file (debug purposes) - static const int kActorCount = 100; + static const int kActorCount = 100; static const int kActorVoiceOver = kActorCount - 1; // Incremental number to keep track of significant revisions of the ScummVM bladerunner engine // that could potentially introduce incompatibilities with old save files or require special actions to restore compatibility // This is stored in game global variable "kVariableGameVersion" // Original (classic) save game files will have version number of 0 - static const int kBladeRunnerScummVMVersion = 1; // 1: alpha testing (since May 15, 2019) + // Values: + // 1: alpha testing (from May 15, 2019 to July 17, 2019) + // 2: all time code uses uint32 (since July 17 2019), + static const int kBladeRunnerScummVMVersion = 2; bool _gameIsRunning; bool _windowIsActive; @@ -214,8 +217,8 @@ public: int _walkSoundPan; int _runningActorId; - int _mouseClickTimeLast; - int _mouseClickTimeDiff; + uint32 _mouseClickTimeLast; + uint32 _mouseClickTimeDiff; int _walkingToExitId; bool _isInsideScriptExit; @@ -232,8 +235,8 @@ public: int _walkingToActorId; bool _isInsideScriptActor; - int _actorUpdateCounter; - int _actorUpdateTimeLast; + int _actorUpdateCounter; + uint32 _actorUpdateTimeLast; private: MIXArchive _archives[kArchiveCount]; diff --git a/engines/bladerunner/debugger.cpp b/engines/bladerunner/debugger.cpp index cd34aff85a..0951e4cfa9 100644 --- a/engines/bladerunner/debugger.cpp +++ b/engines/bladerunner/debugger.cpp @@ -858,12 +858,12 @@ bool Debugger::cmdTimer(int argc, const char **argv) { if (value == 0) { actor->timerReset(timer); } else { - actor->timerStart(timer, value); + actor->timerStart(timer, (uint32)value); } } for (int i = 0; i < 7; ++i) { - debugPrintf("actorTimer(%i, %i) = %i ms\n", actorId, i, actor->timerLeft(i)); + debugPrintf("actorTimer(%i, %i) = %u ms\n", actorId, i, actor->timerLeft(i)); } return true; diff --git a/engines/bladerunner/item_pickup.cpp b/engines/bladerunner/item_pickup.cpp index 797fc7c533..15904d4b32 100644 --- a/engines/bladerunner/item_pickup.cpp +++ b/engines/bladerunner/item_pickup.cpp @@ -46,7 +46,7 @@ void ItemPickup::setup(int animationId, int screenX, int screenY) { _animationId = animationId; _animationFrame = 0; _facing = 0.0; - _timeLeft = 3000; + _timeLeft = 3000u; _scale = 0; _screenX = CLIP(screenX, 40, 600); _screenY = CLIP(screenY, 40, 440); @@ -68,24 +68,25 @@ void ItemPickup::reset() { _facing = 0.0f; _scale = 1.0f; _animationFrame = 0; - _timeLeft = 0; - _timeLast = 0; + _timeLeft = 0u; + _timeLast = 0u; } void ItemPickup::tick() { - if (_timeLeft == 0) { + if (_timeLeft == 0u) { return; } - int timeNow = _vm->_time->currentSystem(); - int timeDiff = timeNow - _timeLast; + uint32 timeNow = _vm->_time->currentSystem(); + // unsigned difference is intentional + uint32 timeDiff = timeNow - _timeLast; _timeLast = timeNow; - timeDiff = MIN(MIN(timeDiff, 67), _timeLeft); - _timeLeft -= timeDiff; + timeDiff = MIN(MIN<uint32>(timeDiff, 67u), _timeLeft); + _timeLeft = (_timeLeft < timeDiff) ? 0 : (_timeLeft - timeDiff); - if (_timeLeft >= 2000) { + if (_timeLeft >= 2000u) { _scale = 1.0f - (((2000.0f - _timeLeft) / 1000.0f) * ((2000.0f - _timeLeft) / 1000.0f)); - } else if (_timeLeft < 1000) { + } else if (_timeLeft < 1000u) { _scale = 1.0f - (((1000.0f - _timeLeft) / 1000.0f) * ((1000.0f - _timeLeft) / 1000.0f)); } else { _scale = 1.0f; @@ -101,7 +102,7 @@ void ItemPickup::tick() { } void ItemPickup::draw() { - if (_timeLeft == 0) { + if (_timeLeft == 0u) { return; } diff --git a/engines/bladerunner/item_pickup.h b/engines/bladerunner/item_pickup.h index 0328bf428e..3a7595e7f8 100644 --- a/engines/bladerunner/item_pickup.h +++ b/engines/bladerunner/item_pickup.h @@ -40,8 +40,8 @@ class ItemPickup { float _facing; float _scale; int _animationFrame; - int _timeLeft; - int _timeLast; + uint32 _timeLeft; + uint32 _timeLast; Common::Rect _screenRect; public: diff --git a/engines/bladerunner/movement_track.cpp b/engines/bladerunner/movement_track.cpp index 322d92ef31..e5ccd2fad0 100644 --- a/engines/bladerunner/movement_track.cpp +++ b/engines/bladerunner/movement_track.cpp @@ -41,17 +41,17 @@ void MovementTrack::reset() { _paused = false; for (int i = 0; i < kSize; i++) { _entries[i].waypointId = -1; - _entries[i].delay = -1; + _entries[i].delay = (uint32)(-1); // original was -1, int _entries[i].angle = -1; _entries[i].run = false; } } -int MovementTrack::append(int waypointId, int delay, bool run) { +int MovementTrack::append(int waypointId, uint32 delay, bool run) { return append(waypointId, delay, -1, run); } -int MovementTrack::append(int waypointId, int delay, int angle, bool run) { +int MovementTrack::append(int waypointId, uint32 delay, int angle, bool run) { if (_lastIndex >= kSize) { return 0; } @@ -92,7 +92,7 @@ bool MovementTrack::hasNext() const { return _hasNext; } -bool MovementTrack::next(int *waypointId, int *delay, int *angle, bool *run) { +bool MovementTrack::next(int *waypointId, uint32 *delay, int *angle, bool *run) { if (_currentIndex < _lastIndex && _hasNext) { *waypointId = _entries[_currentIndex].waypointId; *delay = _entries[_currentIndex].delay; @@ -101,7 +101,7 @@ bool MovementTrack::next(int *waypointId, int *delay, int *angle, bool *run) { return true; } else { *waypointId = -1; - *delay = -1; + *delay = (uint32)(-1); // original was -1, int *angle = -1; *run = false; _hasNext = false; @@ -131,7 +131,7 @@ void MovementTrack::load(SaveFileReadStream &f) { for (int i = 0; i < kSize; ++i) { Entry &e = _entries[i]; e.waypointId = f.readInt(); - e.delay = f.readInt(); + e.delay = (uint32)f.readInt(); e.angle = f.readInt(); e.run = f.readBool(); } diff --git a/engines/bladerunner/movement_track.h b/engines/bladerunner/movement_track.h index 2eab4cdedb..4dd20f6c35 100644 --- a/engines/bladerunner/movement_track.h +++ b/engines/bladerunner/movement_track.h @@ -36,10 +36,10 @@ class MovementTrack { static const int kSize = 100; struct Entry { - int waypointId; - int delay; - int angle; - bool run; + int waypointId; + uint32 delay; + int angle; + bool run; }; int _currentIndex; @@ -51,15 +51,15 @@ class MovementTrack { public: MovementTrack(); ~MovementTrack(); - int append(int waypointId, int delay, bool run); - int append(int waypointId, int delay, int angle, bool run); + int append(int waypointId, uint32 delay, bool run); + int append(int waypointId, uint32 delay, int angle, bool run); void flush(); void repeat(); void pause(); void unpause(); bool isPaused() const; bool hasNext() const; - bool next(int *waypointId, int *delay, int *angle, bool *run); + bool next(int *waypointId, uint32 *delay, int *angle, bool *run); void save(SaveFileWriteStream &f); void load(SaveFileReadStream &f); diff --git a/engines/bladerunner/music.cpp b/engines/bladerunner/music.cpp index 081d9c15cf..59a4e5eae8 100644 --- a/engines/bladerunner/music.cpp +++ b/engines/bladerunner/music.cpp @@ -30,7 +30,6 @@ #include "bladerunner/game_constants.h" #include "common/timer.h" - namespace BladeRunner { Music::Music(BladeRunnerEngine *vm) { @@ -55,7 +54,7 @@ Music::~Music() { _vm->getTimerManager()->removeTimerProc(timerCallbackNext); } -bool Music::play(const Common::String &trackName, int volume, int pan, int timeFadeIn, int timePlay, int loop, int timeFadeOut) { +bool Music::play(const Common::String &trackName, int volume, int pan, uint32 timeFadeIn, uint32 timePlay, int loop, uint32 timeFadeOut) { //Common::StackLock lock(_mutex); if (_musicVolume <= 0) { @@ -64,7 +63,7 @@ bool Music::play(const Common::String &trackName, int volume, int pan, int timeF int volumeAdjusted = volume * _musicVolume / 100; int volumeStart = volumeAdjusted; - if (timeFadeIn > 0) { + if ((int32)timeFadeIn != -1 && timeFadeIn > 0u) { volumeStart = 1; } @@ -105,14 +104,14 @@ bool Music::play(const Common::String &trackName, int volume, int pan, int timeF return false; } - if (timeFadeIn > 0) { + if ((int32)timeFadeIn != -1 && timeFadeIn > 0u) { adjustVolume(volumeAdjusted, timeFadeIn); } _current.name = trackName; - if (timePlay > 0) { + if ((int32)timePlay != -1 && timePlay > 0u) { _vm->getTimerManager()->removeTimerProc(timerCallbackFadeOut); _vm->getTimerManager()->installTimerProc(timerCallbackFadeOut, timePlay * 1000 * 1000, this, "BladeRunnerMusicFadeoutTimer"); - } else if (timeFadeOut > 0) { + } else if ((int32)timeFadeOut != -1 && timeFadeOut > 0u) { _vm->getTimerManager()->removeTimerProc(timerCallbackFadeOut); _vm->getTimerManager()->installTimerProc(timerCallbackFadeOut, (_stream->getLength() - timeFadeOut * 1000) * 1000, this, "BladeRunnerMusicFadeoutTimer"); } @@ -126,7 +125,7 @@ bool Music::play(const Common::String &trackName, int volume, int pan, int timeF return true; } -void Music::stop(int delay) { +void Music::stop(uint32 delay) { Common::StackLock lock(_mutex); if (_channel < 0) { @@ -139,10 +138,10 @@ void Music::stop(int delay) { #endif _current.loop = false; - _vm->_audioMixer->stop(_channel, 60 * delay); + _vm->_audioMixer->stop(_channel, 60u * delay); } -void Music::adjust(int volume, int pan, int delay) { +void Music::adjust(int volume, int pan, uint32 delay) { if (volume != -1) { adjustVolume(_musicVolume * volume/ 100, delay); } @@ -201,17 +200,17 @@ void Music::load(SaveFileReadStream &f) { _current.name = f.readStringSz(13); _current.volume = f.readInt(); _current.pan = f.readInt(); - _current.timeFadeIn = f.readInt(); - _current.timePlay = f.readInt(); + _current.timeFadeIn = (uint32)f.readInt(); + _current.timePlay = (uint32)f.readInt(); _current.loop = f.readInt(); - _current.timeFadeOut = f.readInt(); + _current.timeFadeOut = (uint32)f.readInt(); _next.name = f.readStringSz(13); _next.volume = f.readInt(); _next.pan = f.readInt(); - _next.timeFadeIn = f.readInt(); - _next.timePlay = f.readInt(); + _next.timeFadeIn = (uint32)f.readInt(); + _next.timePlay = (uint32)f.readInt(); _next.loop = f.readInt(); - _next.timeFadeOut = f.readInt(); + _next.timeFadeOut = (uint32)f.readInt(); stop(2); if (_isPlaying) { @@ -236,13 +235,13 @@ void Music::load(SaveFileReadStream &f) { } } -void Music::adjustVolume(int volume, int delay) { +void Music::adjustVolume(int volume, uint32 delay) { if (_channel >= 0) { _vm->_audioMixer->adjustVolume(_channel, volume, delay); } } -void Music::adjustPan(int pan, int delay) { +void Music::adjustPan(int pan, uint32 delay) { if (_channel >= 0) { _vm->_audioMixer->adjustPan(_channel, pan, delay); } @@ -263,7 +262,7 @@ void Music::ended() { void Music::fadeOut() { _vm->getTimerManager()->removeTimerProc(timerCallbackFadeOut); if (_channel >= 0) { - _vm->_audioMixer->stop(_channel, 60 * _current.timeFadeOut); + _vm->_audioMixer->stop(_channel, 60u * _current.timeFadeOut); } } diff --git a/engines/bladerunner/music.h b/engines/bladerunner/music.h index b4dc284def..0717544643 100644 --- a/engines/bladerunner/music.h +++ b/engines/bladerunner/music.h @@ -38,10 +38,10 @@ class Music { Common::String name; int volume; int pan; - int timeFadeIn; - int timePlay; + uint32 timeFadeIn; + uint32 timePlay; int loop; - int timeFadeOut; + uint32 timeFadeOut; }; BladeRunnerEngine *_vm; @@ -61,9 +61,9 @@ public: Music(BladeRunnerEngine *vm); ~Music(); - bool play(const Common::String &trackName, int volume, int pan, int timeFadeIn, int timePlay, int loop, int timeFadeOut); - void stop(int delay); - void adjust(int volume, int pan, int delay); + bool play(const Common::String &trackName, int volume, int pan, uint32 timeFadeIn, uint32 timePlay, int loop, uint32 timeFadeOut); + void stop(uint32 delay); + void adjust(int volume, int pan, uint32 delay); bool isPlaying(); void setVolume(int volume); @@ -74,8 +74,8 @@ public: void load(SaveFileReadStream &f); private: - void adjustVolume(int volume, int delay); - void adjustPan(int pan, int delay); + void adjustVolume(int volume, uint32 delay); + void adjustPan(int pan, uint32 delay); void ended(); void fadeOut(); diff --git a/engines/bladerunner/savefile.cpp b/engines/bladerunner/savefile.cpp index 3caf3bd4f9..cf55cb038e 100644 --- a/engines/bladerunner/savefile.cpp +++ b/engines/bladerunner/savefile.cpp @@ -190,7 +190,7 @@ void SaveFileWriteStream::padBytes(int count) { } } -void SaveFileWriteStream::writeInt(int v) { +void SaveFileWriteStream::writeInt(int32 v) { writeUint32LE(v); } @@ -248,7 +248,7 @@ void SaveFileWriteStream::writeBoundingBox(const BoundingBox &v, bool serialized SaveFileReadStream::SaveFileReadStream(Common::SeekableReadStream &s) : _s(s) {} -int SaveFileReadStream::readInt() { +int32 SaveFileReadStream::readInt() { return readUint32LE(); } diff --git a/engines/bladerunner/savefile.h b/engines/bladerunner/savefile.h index b3a5f25417..2948ce64e0 100644 --- a/engines/bladerunner/savefile.h +++ b/engines/bladerunner/savefile.h @@ -94,7 +94,7 @@ public: void padBytes(int count); - void writeInt(int v); + void writeInt(int32 v); // this writes a 4 byte int (uses writeUint32LE) void writeFloat(float v); void writeBool(bool v); void writeStringSz(const Common::String &s, uint sz); @@ -117,7 +117,7 @@ public: int32 size() const override { return _s.size(); } bool seek(int32 offset, int whence = SEEK_SET) override { return _s.seek(offset, whence); } - int readInt(); + int32 readInt(); float readFloat(); bool readBool(); Common::String readStringSz(uint sz); diff --git a/engines/bladerunner/script/police_maze.cpp b/engines/bladerunner/script/police_maze.cpp index 68e2b672ed..028eca00b5 100644 --- a/engines/bladerunner/script/police_maze.cpp +++ b/engines/bladerunner/script/police_maze.cpp @@ -120,10 +120,10 @@ void PoliceMaze::setPauseState(bool state) { warning("PAUSE: %d", state); _isPaused = state; - uint32 t = _vm->_time->current(); + uint32 timeNow = _vm->_time->current(); for (int i = 0; i < kNumMazeTracks; i++) { - _tracks[i]->setTime(t); + _tracks[i]->setTime(timeNow); } } @@ -256,8 +256,8 @@ bool PoliceMazeTargetTrack::tick() { uint32 oldTime = _time; _time = _vm->_time->current(); - int32 timeDiff = _time - oldTime; - _timeLeftUpdate -= timeDiff; + uint32 timeDiff = _time - oldTime; // unsigned difference is intentional + _timeLeftUpdate = _timeLeftUpdate - (int32)timeDiff; // should be ok if (_timeLeftUpdate > 0) { return false; @@ -265,8 +265,9 @@ bool PoliceMazeTargetTrack::tick() { #if BLADERUNNER_ORIGINAL_BUGS #else + // here _timeLeftUpdate is <= 0 if (_vm->_settings->getDifficulty() > kGameDifficultyEasy) { - timeDiff = 0 - _timeLeftUpdate; + timeDiff = abs(_timeLeftUpdate); } #endif // BLADERUNNER_ORIGINAL_BUGS _timeLeftUpdate = 66; // update the target track 15 times per second @@ -282,7 +283,7 @@ bool PoliceMazeTargetTrack::tick() { if (_vm->_settings->getDifficulty() == kGameDifficultyEasy) { _timeLeftWait -= timeDiff; // original behavior } else { - _timeLeftWait -= (timeDiff + _timeLeftUpdate); // this deducts an amount >= 66 + _timeLeftWait = _timeLeftWait - (int32)(timeDiff + _timeLeftUpdate); // this deducts an amount >= 66 // should be ok } #endif // BLADERUNNER_ORIGINAL_BUGS if (_timeLeftWait > 0) { diff --git a/engines/bladerunner/script/script.cpp b/engines/bladerunner/script/script.cpp index a0c27ae431..d0355d3289 100644 --- a/engines/bladerunner/script/script.cpp +++ b/engines/bladerunner/script/script.cpp @@ -343,7 +343,7 @@ void ScriptBase::Actor_Says_With_Pause(int actorId, int sentenceId, float pause, } if (pause > 0.0f && !_vm->_actorSpeakStopIsRequested) { - Delay(pause * 1000); + Delay(pause * 1000u); } Player_Gains_Control(); @@ -929,11 +929,12 @@ int ScriptBase::Animation_Skip_To_Frame() { return 0; } -void ScriptBase::Delay(int miliseconds) { - debugC(kDebugScript, "Delay(%d)", miliseconds); +void ScriptBase::Delay(uint32 miliseconds) { + debugC(kDebugScript, "Delay(%u)", miliseconds); Player_Loses_Control(); - int endTime = _vm->_time->current() + miliseconds; - while (_vm->_gameIsRunning && (_vm->_time->current() < endTime)) { + uint32 startTime = _vm->_time->current(); + // unsigned difference is intentional + while (_vm->_gameIsRunning && (_vm->_time->current() - startTime < miliseconds)) { _vm->gameTick(); } Player_Gains_Control(); @@ -1138,18 +1139,18 @@ void ScriptBase::Footstep_Sound_Override_Off() { _vm->_scene->_set->resetFoodstepSoundOverride(); } -bool ScriptBase::Music_Play(int musicId, int volume, int pan, int timeFadeIn, int timePlay, int loop, int timeFadeOut) { - debugC(kDebugScript, "Music_Play(%d, %d, %d, %d, %d, %d, %d)", musicId, volume, pan, timeFadeIn, timePlay, loop, timeFadeOut); +bool ScriptBase::Music_Play(int musicId, int volume, int pan, uint32 timeFadeIn, uint32 timePlay, int loop, uint32 timeFadeOut) { + debugC(kDebugScript, "Music_Play(%d, %d, %d, %u, %u, %d, %u)", musicId, volume, pan, timeFadeIn, timePlay, loop, timeFadeOut); return _vm->_music->play(_vm->_gameInfo->getMusicTrack(musicId), volume, pan, timeFadeIn, timePlay, loop, timeFadeOut); } -void ScriptBase::Music_Adjust(int volume, int pan, int delay) { - debugC(kDebugScript, "Music_Adjust(%d, %d, %d)", volume, pan, delay); +void ScriptBase::Music_Adjust(int volume, int pan, uint32 delay) { + debugC(kDebugScript, "Music_Adjust(%d, %d, %u)", volume, pan, delay); _vm->_music->adjust(volume, pan, delay); } -void ScriptBase::Music_Stop(int delay) { - debugC(kDebugScript, "Music_Stop(%d)", delay); +void ScriptBase::Music_Stop(uint32 delay) { + debugC(kDebugScript, "Music_Stop(%u)", delay); _vm->_music->stop(delay); } @@ -1189,8 +1190,8 @@ void ScriptBase::Outtake_Play(int id, int noLocalization, int container) { _vm->outtakePlay(id, noLocalization, container); } -void ScriptBase::Ambient_Sounds_Add_Sound(int sfxId, int timeMin, int timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk) { - debugC(kDebugScript, "Ambient_Sounds_Add_Sound(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", sfxId, timeMin, timeMax, volumeMin, volumeMax, panStartMin, panStartMax, panEndMin, panEndMax, priority, unk); +void ScriptBase::Ambient_Sounds_Add_Sound(int sfxId, uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk) { + debugC(kDebugScript, "Ambient_Sounds_Add_Sound(%d, %u, %u, %d, %d, %d, %d, %d, %d, %d, %d)", sfxId, timeMin, timeMax, volumeMin, volumeMax, panStartMin, panStartMax, panEndMin, panEndMax, priority, unk); _vm->_ambientSounds->addSound(sfxId, timeMin, timeMax, volumeMin, volumeMax, panStartMin, panStartMax, panEndMin, panEndMax, priority, unk); } @@ -1199,8 +1200,8 @@ void ScriptBase::Ambient_Sounds_Remove_Sound(int sfxId, bool stopPlaying) { _vm->_ambientSounds->removeNonLoopingSound(sfxId, stopPlaying); } -void ScriptBase::Ambient_Sounds_Add_Speech_Sound(int actorId, int sentenceId, int timeMin, int timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk) { - debugC(kDebugScript, "Ambient_Sounds_Add_Speech_Sound(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", actorId, sentenceId, timeMin, timeMax, volumeMin, volumeMax, panStartMin, panStartMax, panEndMin, panEndMax, priority, unk); +void ScriptBase::Ambient_Sounds_Add_Speech_Sound(int actorId, int sentenceId, uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk) { + debugC(kDebugScript, "Ambient_Sounds_Add_Speech_Sound(%d, %d, %u, %u, %d, %d, %d, %d, %d, %d, %d, %d)", actorId, sentenceId, timeMin, timeMax, volumeMin, volumeMax, panStartMin, panStartMax, panEndMin, panEndMax, priority, unk); _vm->_ambientSounds->addSpeech(actorId, sentenceId, timeMin, timeMax, volumeMin, volumeMax, panStartMin, panStartMax, panEndMin, panEndMax, priority, unk); } @@ -1221,23 +1222,23 @@ void ScriptBase::Ambient_Sounds_Remove_All_Non_Looping_Sounds(bool stopPlaying) _vm->_ambientSounds->removeAllNonLoopingSounds(stopPlaying); } -void ScriptBase::Ambient_Sounds_Add_Looping_Sound(int sfxId, int volume, int pan, int delay) { - debugC(kDebugScript, "Ambient_Sounds_Add_Looping_Sound(%d, %d, %d, %d)", sfxId, volume, pan, delay); +void ScriptBase::Ambient_Sounds_Add_Looping_Sound(int sfxId, int volume, int pan, uint32 delay) { + debugC(kDebugScript, "Ambient_Sounds_Add_Looping_Sound(%d, %d, %d, %u)", sfxId, volume, pan, delay); _vm->_ambientSounds->addLoopingSound(sfxId, volume, pan, delay); } -void ScriptBase::Ambient_Sounds_Adjust_Looping_Sound(int sfxId, int volume, int pan, int delay) { - debugC(kDebugScript, "Ambient_Sounds_Adjust_Looping_Sound(%d, %d, %d, %d)", sfxId, volume, pan, delay); +void ScriptBase::Ambient_Sounds_Adjust_Looping_Sound(int sfxId, int volume, int pan, uint32 delay) { + debugC(kDebugScript, "Ambient_Sounds_Adjust_Looping_Sound(%d, %d, %d, %u)", sfxId, volume, pan, delay); _vm->_ambientSounds->adjustLoopingSound(sfxId, volume, pan, delay); } -void ScriptBase::Ambient_Sounds_Remove_Looping_Sound(int sfxId, int delay) { - debugC(kDebugScript, "Ambient_Sounds_Remove_Looping_Sound(%d, %d)", sfxId, delay); +void ScriptBase::Ambient_Sounds_Remove_Looping_Sound(int sfxId, uint32 delay) { + debugC(kDebugScript, "Ambient_Sounds_Remove_Looping_Sound(%d, %u)", sfxId, delay); _vm->_ambientSounds->removeLoopingSound(sfxId, delay); } -void ScriptBase::Ambient_Sounds_Remove_All_Looping_Sounds(int delay) { - debugC(kDebugScript, "Ambient_Sounds_Remove_All_Looping_Sounds(%d)", delay); +void ScriptBase::Ambient_Sounds_Remove_All_Looping_Sounds(uint32 delay) { + debugC(kDebugScript, "Ambient_Sounds_Remove_All_Looping_Sounds(%u)", delay); _vm->_ambientSounds->removeAllLoopingSounds(delay); } @@ -1656,8 +1657,8 @@ void ScriptBase::ADQ_Add(int actorId, int sentenceId, int animationMode) { _vm->_actorDialogueQueue->add(actorId, sentenceId, animationMode); } -void ScriptBase::ADQ_Add_Pause(int delay) { - debugC(kDebugScript, "ADQ_Add_Pause(%d)", delay); +void ScriptBase::ADQ_Add_Pause(uint32 delay) { + debugC(kDebugScript, "ADQ_Add_Pause(%u)", delay); _vm->_actorDialogueQueue->addPause(delay); } @@ -1683,10 +1684,10 @@ void ScriptBase::I_Sez(const char *str) { _vm->ISez(str); } -void ScriptBase::AI_Countdown_Timer_Start(int actorId, signed int timer, int seconds) { - debugC(kDebugScript, "AI_Countdown_Timer_Start(%d, %d, %d)", actorId, timer, seconds); +void ScriptBase::AI_Countdown_Timer_Start(int actorId, signed int timer, uint32 seconds) { + debugC(kDebugScript, "AI_Countdown_Timer_Start(%d, %d, %u)", actorId, timer, seconds); if (timer >= 0 && timer <= 2) { - _vm->_actors[actorId]->timerStart(timer, 1000 * seconds); + _vm->_actors[actorId]->timerStart(timer, 1000u * seconds); } } @@ -1713,24 +1714,24 @@ void ScriptBase::AI_Movement_Track_Repeat(int actorId) { _vm->_actors[actorId]->movementTrackNext(true); } -void ScriptBase::AI_Movement_Track_Append_Run_With_Facing(int actorId, int waypointId, int delay, int angle) { - debugC(kDebugScript, "AI_Movement_Track_Append_Run_With_Facing(%d, %d, %d, %d)", actorId, waypointId, delay, angle); - _vm->_actors[actorId]->_movementTrack->append(waypointId, delay * 1000, angle, true); +void ScriptBase::AI_Movement_Track_Append_Run_With_Facing(int actorId, int waypointId, uint32 delay, int angle) { + debugC(kDebugScript, "AI_Movement_Track_Append_Run_With_Facing(%d, %d, %u, %d)", actorId, waypointId, delay, angle); + _vm->_actors[actorId]->_movementTrack->append(waypointId, delay * 1000u, angle, true); } -void ScriptBase::AI_Movement_Track_Append_With_Facing(int actorId, int waypointId, int delay, int angle) { - debugC(kDebugScript, "AI_Movement_Track_Append_With_Facing(%d, %d, %d, %d)", actorId, waypointId, delay, angle); - _vm->_actors[actorId]->_movementTrack->append(waypointId, delay * 1000, angle, false); +void ScriptBase::AI_Movement_Track_Append_With_Facing(int actorId, int waypointId, uint32 delay, int angle) { + debugC(kDebugScript, "AI_Movement_Track_Append_With_Facing(%d, %d, %u, %d)", actorId, waypointId, delay, angle); + _vm->_actors[actorId]->_movementTrack->append(waypointId, delay * 1000u, angle, false); } -void ScriptBase::AI_Movement_Track_Append_Run(int actorId, int waypointId, int delay) { - debugC(kDebugScript, "AI_Movement_Track_Append_Run(%d, %d, %d)", actorId, waypointId, delay); - _vm->_actors[actorId]->_movementTrack->append(waypointId, delay * 1000, true); +void ScriptBase::AI_Movement_Track_Append_Run(int actorId, int waypointId, uint32 delay) { + debugC(kDebugScript, "AI_Movement_Track_Append_Run(%d, %d, %u)", actorId, waypointId, delay); + _vm->_actors[actorId]->_movementTrack->append(waypointId, delay * 1000u, true); } -void ScriptBase::AI_Movement_Track_Append(int actorId, int waypointId, int delay) { - debugC(kDebugScript, "AI_Movement_Track_Append(%d, %d, %d)", actorId, waypointId, delay); - _vm->_actors[actorId]->_movementTrack->append(waypointId, delay * 1000, false); +void ScriptBase::AI_Movement_Track_Append(int actorId, int waypointId, uint32 delay) { + debugC(kDebugScript, "AI_Movement_Track_Append(%d, %d, %u)", actorId, waypointId, delay); + _vm->_actors[actorId]->_movementTrack->append(waypointId, delay * 1000u, false); } void ScriptBase::AI_Movement_Track_Flush(int actorId) { diff --git a/engines/bladerunner/script/script.h b/engines/bladerunner/script/script.h index 3a31e49481..ac88458f42 100644 --- a/engines/bladerunner/script/script.h +++ b/engines/bladerunner/script/script.h @@ -140,7 +140,7 @@ protected: int Animation_Start(); int Animation_Stop(); int Animation_Skip_To_Frame(); - void Delay(int miliseconds); + void Delay(uint32 miliseconds); void Player_Loses_Control(); void Player_Gains_Control(); void Player_Set_Combat_Mode(bool activate); @@ -172,26 +172,26 @@ protected: void Footstep_Sounds_Set(int index, int value); void Footstep_Sound_Override_On(int footstepSoundOverride); void Footstep_Sound_Override_Off(); - bool Music_Play(int musicId, int volume, int pan, int timeFadeIn, int timePlay, int loop, int timeFadeOut); - void Music_Adjust(int volume, int pan, int delay); - void Music_Stop(int delay); + bool Music_Play(int musicId, int volume, int pan, uint32 timeFadeIn, uint32 timePlay, int loop, uint32 timeFadeOut); + void Music_Adjust(int volume, int pan, uint32 delay); + void Music_Stop(uint32 delay); bool Music_Is_Playing(); void Overlay_Play(const char *overlay, int loopId, bool loopForever, bool startNow, int a5); void Overlay_Remove(const char *overlay); void Scene_Loop_Set_Default(int loopId); void Scene_Loop_Start_Special(int sceneLoopMode, int loopId, bool immediately); void Outtake_Play(int id, int noLocalization = false, int container = -1); - void Ambient_Sounds_Add_Sound(int sfxId, int timeMin, int timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk); + void Ambient_Sounds_Add_Sound(int sfxId, uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk); void Ambient_Sounds_Remove_Sound(int sfxId, bool stopPlaying); - void Ambient_Sounds_Add_Speech_Sound(int actorId, int sentenceId, int timeMin, int timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk); + void Ambient_Sounds_Add_Speech_Sound(int actorId, int sentenceId, uint32 timeMin, uint32 timeMax, int volumeMin, int volumeMax, int panStartMin, int panStartMax, int panEndMin, int panEndMax, int priority, int unk); // Ambient_Sounds_Remove_Speech_Sound void Ambient_Sounds_Play_Sound(int sfxId, int volume, int panStart, int panEnd, int priority); void Ambient_Sounds_Play_Speech_Sound(int actorId, int sfxId, int volume, int panStart, int panEnd, int priority); void Ambient_Sounds_Remove_All_Non_Looping_Sounds(bool stopPlaying); - void Ambient_Sounds_Add_Looping_Sound(int sfxId, int volume, int pan, int delay); - void Ambient_Sounds_Adjust_Looping_Sound(int sfxId, int volume, int pan, int delay); - void Ambient_Sounds_Remove_Looping_Sound(int sfxId, int delay); - void Ambient_Sounds_Remove_All_Looping_Sounds(int delay); + void Ambient_Sounds_Add_Looping_Sound(int sfxId, int volume, int pan, uint32 delay); + void Ambient_Sounds_Adjust_Looping_Sound(int sfxId, int volume, int pan, uint32 delay); + void Ambient_Sounds_Remove_Looping_Sound(int sfxId, uint32 delay); + void Ambient_Sounds_Remove_All_Looping_Sounds(uint32 delay); void Setup_Scene_Information(float actorX, float actorY, float actorZ, int actorFacing); bool Dialogue_Menu_Appear(int x, int y); bool Dialogue_Menu_Disappear(); @@ -265,21 +265,21 @@ protected: void Set_Fog_Density(const char *fogName, float density); void ADQ_Flush(); void ADQ_Add(int actorId, int sentenceId, int animationMode); - void ADQ_Add_Pause(int delay); + void ADQ_Add_Pause(uint32 delay); void ADQ_Wait_For_All_Queued_Dialogue(); bool Game_Over(); void Autosave_Game(int textId); void I_Sez(const char *str); - void AI_Countdown_Timer_Start(int actorId, signed int timer, int seconds); + void AI_Countdown_Timer_Start(int actorId, signed int timer, uint32 seconds); void AI_Countdown_Timer_Reset(int actorId, int timer); void AI_Movement_Track_Unpause(int actorId); void AI_Movement_Track_Pause(int actorId); void AI_Movement_Track_Repeat(int actorId); - void AI_Movement_Track_Append_Run_With_Facing(int actorId, int waypointId, int delay, int angle); - void AI_Movement_Track_Append_With_Facing(int actorId, int waypointId, int delay, int angle); - void AI_Movement_Track_Append_Run(int actorId, int waypointId, int delay); - void AI_Movement_Track_Append(int actorId, int waypointId, int delay); + void AI_Movement_Track_Append_Run_With_Facing(int actorId, int waypointId, uint32 delay, int angle); + void AI_Movement_Track_Append_With_Facing(int actorId, int waypointId, uint32 delay, int angle); + void AI_Movement_Track_Append_Run(int actorId, int waypointId, uint32 delay); + void AI_Movement_Track_Append(int actorId, int waypointId, uint32 delay); void AI_Movement_Track_Flush(int actorId); void ESPER_Add_Photo(const char *name, int photoId, int shapeId); diff --git a/engines/bladerunner/script/vk_script.cpp b/engines/bladerunner/script/vk_script.cpp index 30dede7721..6c4de428a5 100644 --- a/engines/bladerunner/script/vk_script.cpp +++ b/engines/bladerunner/script/vk_script.cpp @@ -1948,7 +1948,7 @@ void VKScript::askRunciter(int questionId) { VK_Play_Speech_Line(kActorMcCoy, 7660, 0.5f); VK_Play_Speech_Line(kActorMcCoy, 7665, 0.5f); VK_Eye_Animates(1); - Delay(1500); + Delay(1500u); VK_Play_Speech_Line(kActorMcCoy, 8395, 0.5f); // M: You don't have anything to say? VK_Subject_Reacts(12, 8, 1, 0); VK_Play_Speech_Line(kActorRunciter, 1400, 0.5f); // R: What's the point @@ -2312,7 +2312,7 @@ void VKScript::askBulletBob(int questionId) { case 7470: // Low 15 VK_Subject_Reacts(50, -4, 0, -5); if (_vm->_cutContent) { - Delay(2000); + Delay(2000u); VK_Play_Speech_Line(kActorMcCoy, 8270, 0.5f); } VK_Play_Speech_Line(kActorBulletBob, 1240, 0.5f); diff --git a/engines/bladerunner/settings.cpp b/engines/bladerunner/settings.cpp index f86536e572..b4a0022e26 100644 --- a/engines/bladerunner/settings.cpp +++ b/engines/bladerunner/settings.cpp @@ -39,8 +39,8 @@ namespace BladeRunner { Settings::Settings(BladeRunnerEngine *vm) { _vm = vm; - _difficulty = 1; - _playerAgenda = 1; + _difficulty = kGameDifficultyMedium; + _playerAgenda = kPlayerAgendaNormal; _chapter = 1; _scene = -1; @@ -65,6 +65,7 @@ Settings::Settings(BladeRunnerEngine *vm) { _fullHDFrames = true; _mst3k = false; + // TODO: A bug? why is this set again here? _ammoType = 0; _ammoAmounts[0] = 0; _ammoAmounts[1] = 0; @@ -174,7 +175,7 @@ void Settings::addAmmo(int ammoType, int ammo) { } void Settings::decreaseAmmo() { - if (_difficulty == 0 || _ammoType == 0) { + if (_difficulty == kGameDifficultyEasy || _ammoType == 0) { return; } diff --git a/engines/bladerunner/time.cpp b/engines/bladerunner/time.cpp index ff7b6a78b5..ac2d6eac8b 100644 --- a/engines/bladerunner/time.cpp +++ b/engines/bladerunner/time.cpp @@ -34,16 +34,16 @@ Time::Time(BladeRunnerEngine *vm) { _start = currentSystem(); _pauseCount = 0; - _offset = 0; - _pauseStart = 0; + _offset = 0u; + _pauseStart = 0u; } -int Time::currentSystem() { +uint32 Time::currentSystem() { return _vm->getTotalPlayTime(); } -int Time::current() { - int time = currentSystem() - _offset; +uint32 Time::current() { + uint32 time = currentSystem() - _offset; return time - _start; } @@ -54,7 +54,7 @@ int Time::pause() { return ++_pauseCount; } -int Time::getPauseStart() { +uint32 Time::getPauseStart() { return _pauseStart; } @@ -75,7 +75,7 @@ bool Time::isLocked() { // TODO Explore if it would make sense to only use the Engine methods for time accounting (pauseEngine, get/setTotalPlatTime) // or do we need separated/independent time accounting and pausing? void Time::resetPauseStart() { - _offset = 0; + _offset = 0u; _pauseStart = current(); } diff --git a/engines/bladerunner/time.h b/engines/bladerunner/time.h index 48fa23a594..de48a112d1 100644 --- a/engines/bladerunner/time.h +++ b/engines/bladerunner/time.h @@ -23,6 +23,8 @@ #ifndef BLADERUNNER_TIME_H #define BLADERUNNER_TIME_H +#include "common/types.h" + namespace BladeRunner { class BladeRunnerEngine; @@ -30,18 +32,18 @@ class BladeRunnerEngine; class Time { BladeRunnerEngine *_vm; - int _start; + uint32 _start; int _pauseCount; - int _offset; - int _pauseStart; + uint32 _offset; + uint32 _pauseStart; public: Time(BladeRunnerEngine *vm); - int currentSystem(); - int current(); + uint32 currentSystem(); + uint32 current(); int pause(); - int getPauseStart(); + uint32 getPauseStart(); int resume(); bool isLocked(); void resetPauseStart(); diff --git a/engines/bladerunner/ui/elevator.cpp b/engines/bladerunner/ui/elevator.cpp index 2f7d7e1dff..a3f795263a 100644 --- a/engines/bladerunner/ui/elevator.cpp +++ b/engines/bladerunner/ui/elevator.cpp @@ -244,7 +244,7 @@ void Elevator::reset() { _imagePicker = nullptr; _actorId = -1; _sentenceId = -1; - _timeSpeakDescription = 0; + _timeSpeakDescriptionStart = 0u; _buttonClicked = false; } @@ -283,18 +283,19 @@ void Elevator::buttonFocus(int buttonId) { void Elevator::setupDescription(int actorId, int sentenceId) { _actorId = actorId; _sentenceId = sentenceId; - _timeSpeakDescription = _vm->_time->current() + 600; + _timeSpeakDescriptionStart = _vm->_time->current(); } void Elevator::resetDescription() { _actorId = -1; _sentenceId = -1; - _timeSpeakDescription = 0; + _timeSpeakDescriptionStart = 0u; } void Elevator::tickDescription() { - int now = _vm->_time->current(); - if (_actorId <= 0 || now < _timeSpeakDescription) { + uint32 now = _vm->_time->current(); + // unsigned difference is intentional + if (_actorId <= 0 || (now - _timeSpeakDescriptionStart < 600u)) { return; } diff --git a/engines/bladerunner/ui/elevator.h b/engines/bladerunner/ui/elevator.h index 96724430b0..6ed91ce799 100644 --- a/engines/bladerunner/ui/elevator.h +++ b/engines/bladerunner/ui/elevator.h @@ -41,7 +41,7 @@ class Elevator { UIImagePicker *_imagePicker; int _actorId; int _sentenceId; - int _timeSpeakDescription; + uint32 _timeSpeakDescriptionStart; public: Elevator(BladeRunnerEngine *vm); diff --git a/engines/bladerunner/ui/end_credits.cpp b/engines/bladerunner/ui/end_credits.cpp index 08cce2e172..57ea6b3e7c 100644 --- a/engines/bladerunner/ui/end_credits.cpp +++ b/engines/bladerunner/ui/end_credits.cpp @@ -109,7 +109,7 @@ void EndCredits::show() { } uint32 timeNow = _vm->_time->currentSystem(); - position += (double)(timeNow - timeLast) * 0.05f; + position += (double)(timeNow - timeLast) * 0.05f; // unsigned difference is intentional timeLast = timeNow; _vm->_surfaceFront.fillRect(Common::Rect(640, 480), 0); diff --git a/engines/bladerunner/ui/esper.cpp b/engines/bladerunner/ui/esper.cpp index 7913362091..3a4e8c9fc4 100644 --- a/engines/bladerunner/ui/esper.cpp +++ b/engines/bladerunner/ui/esper.cpp @@ -56,12 +56,12 @@ ESPER::ESPER(BladeRunnerEngine *vm) { _regionSelectedAck = false; _isDrawingSelection = false; - _isOpen = false; - _shapeButton = nullptr; - _shapeThumbnail = nullptr; - _vqaPlayerMain = nullptr; - _vqaPlayerPhoto = nullptr; - _script = nullptr; + _isOpen = false; + _shapeButton = nullptr; + _shapeThumbnail = nullptr; + _vqaPlayerMain = nullptr; + _vqaPlayerPhoto = nullptr; + _script = nullptr; reset(); @@ -363,7 +363,7 @@ void ESPER::resetData() { _flash = false; _isScrolling = false; - _timeScrollNext = 0; + _timeScrollNextStart = 0u; resetPhotos(); resetRegions(); @@ -398,7 +398,7 @@ void ESPER::resetViewport() { _zoom = _zoomVertical; _zoomMin = _zoom; - _timeZoomOutNext = 0; + _timeZoomOutNextStart = 0u; _viewportPositionX = kPhotoWidth / 2; _viewportPositionY = kPhotoHeight / 2; @@ -416,20 +416,22 @@ void ESPER::resetSelectionRect() { } void ESPER::resetSelectionBlinking() { - _selectionBlinkingCounter = 0; - _selectionBlinkingStyle = 0; - _timeSelectionBlinkingNext = 0; + _selectionBlinkingCounter = 0; + _selectionBlinkingStyle = 0; + _timeSelectionBlinkingNextStart = 0u; } void ESPER::resetPhotoZooming() { _zoomStep = 0; - _timeZoomNext = 0; + _timeZoomNextDiff = 0u; + _timeZoomNextStart = 0u; } void ESPER::resetPhotoOpening() { _photoOpeningWidth = _screen.left + 1; _photoOpeningHeight = _screen.top + 1; - _timePhotoOpeningNext = 0; + _timePhotoOpeningNextDiff = 0u; + _timePhotoOpeningNextStart = 0u; } void ESPER::updateViewport() { @@ -523,11 +525,13 @@ void ESPER::setStatePhoto(EsperPhotoStates state) { _statePhoto = state; } -void ESPER::wait(int timeout) { +void ESPER::wait(uint32 timeout) { if (!_isWaiting) { _isWaiting = true; - int timeEnd = timeout + _vm->_time->current(); - while (_vm->_gameIsRunning && (_vm->_time->current() < timeEnd)) { +// int timeEnd = timeout + _vm->_time->current(); + uint32 timeStart = _vm->_time->current(); + // unsigned difference is intentional + while (_vm->_gameIsRunning && (_vm->_time->current() - timeStart < timeout)) { _vm->gameTick(); } _isWaiting = false; @@ -645,16 +649,17 @@ void ESPER::draw(Graphics::Surface &surface) { void ESPER::drawPhotoOpening(Graphics::Surface &surface) { bool needMoreZooming = true; - int timeNow = _vm->_time->current(); - if (timeNow >= _timePhotoOpeningNext) { + uint32 timeNow = _vm->_time->current(); + // unsigned difference is intentional + if (timeNow - _timePhotoOpeningNextStart >= _timePhotoOpeningNextDiff) { _photoOpeningWidth = MIN(_photoOpeningWidth + 8, _screen.right - 1); _photoOpeningHeight = MIN(_photoOpeningHeight + 7, _screen.bottom - 1); if (_photoOpeningWidth == _screen.right - 1 && _photoOpeningHeight == _screen.bottom - 1) { needMoreZooming = false; } - - _timePhotoOpeningNext = timeNow + 20; + _timePhotoOpeningNextDiff = 20u; + _timePhotoOpeningNextStart = timeNow; } copyImageScale(&_surfacePhoto, _viewport, &surface, Common::Rect(_screen.left, _screen.top, _photoOpeningWidth, _photoOpeningHeight)); @@ -675,15 +680,16 @@ void ESPER::drawPhotoOpening(Graphics::Surface &surface) { bool ESPER::drawSelectionZooming(Graphics::Surface &surface) { bool zooming = false; bool needMoreZooming = true; - int timeNow = _vm->_time->current(); - if (timeNow > _timeSelectionZoomNext) { + uint32 timeNow = _vm->_time->current(); + // unsigned difference is intentional + if (timeNow - _timeSelectionZoomNextStart > 150u) { zooming = true; _selection.left += _selectionDelta.left; _selection.top += _selectionDelta.top; _selection.right += _selectionDelta.right; _selection.bottom += _selectionDelta.bottom; ++_selectionZoomStep; - _timeSelectionZoomNext = timeNow + 150; + _timeSelectionZoomNextStart = timeNow; if (_selectionZoomStep > kSelectionZoomSteps) { needMoreZooming = false; _selection.left = _selectionTarget.left; @@ -706,9 +712,10 @@ bool ESPER::drawSelectionZooming(Graphics::Surface &surface) { bool ESPER::drawSelectionBlinking(Graphics::Surface &surface) { bool needMoreBlinking = true; - int timeNow = _vm->_time->current(); - if (timeNow > _timeSelectionBlinkingNext) { - _timeSelectionBlinkingNext = timeNow + 100; + uint32 timeNow = _vm->_time->current(); + // unsigned difference is intentional + if (timeNow - _timeSelectionBlinkingNextStart > 100u) { + _timeSelectionBlinkingNextStart = timeNow; _selectionBlinkingStyle ^= 1; ++_selectionBlinkingCounter; if (_selectionBlinkingCounter > 10) { @@ -724,8 +731,9 @@ bool ESPER::drawSelectionBlinking(Graphics::Surface &surface) { } void ESPER::drawPhotoZooming(Graphics::Surface &surface) { - int timeNow = _vm->_time->current(); - if ((timeNow > _timeZoomNext) && (_zoomStep < _zoomSteps)) { + uint32 timeNow = _vm->_time->current(); + // unsigned difference is intentional + if ((timeNow - _timeZoomNextStart > _timeZoomNextDiff) && (_zoomStep < _zoomSteps)) { _flash = true; _viewportPositionXCurrent += _viewportPositionXDelta; @@ -754,7 +762,8 @@ void ESPER::drawPhotoZooming(Graphics::Surface &surface) { _viewportPositionY = _viewportPositionYTarget; } updateViewport(); - _timeZoomNext = timeNow + 300; + _timeZoomNextDiff = 300u; + _timeZoomNextStart = timeNow; } if (_zoomDelta >= 0.0f) { @@ -764,7 +773,8 @@ void ESPER::drawPhotoZooming(Graphics::Surface &surface) { } drawGrid(surface); - if ((timeNow > _timeZoomNext) && (_zoomStep >= _zoomSteps)) { + // unsigned difference is intentional + if ((timeNow - _timeZoomNextStart > _timeZoomNextDiff) && (_zoomStep >= _zoomSteps)) { if (_regionSelectedAck) { if (!_regions[_regionSelected].name.empty()) { if (_zoomDelta < 0.0f) { @@ -772,7 +782,7 @@ void ESPER::drawPhotoZooming(Graphics::Surface &surface) { _zoomDelta = (_zoom * 1.5f - _zoom) / (float)_zoomSteps; // 0.5f * _zoom ??? } setStatePhoto(kEsperPhotoStateVideoZooming); - _timeZoomNext += 300; + _timeZoomNextDiff += 300u; } else { _regionSelectedAck = false; _selection.left = viewportXToScreenX(_regions[_regionSelected].rectInner.left); @@ -792,9 +802,10 @@ void ESPER::drawPhotoZooming(Graphics::Surface &surface) { } void ESPER::drawPhotoSharpening(Graphics::Surface &surface) { - int timeNow = _vm->_time->current(); + uint32 timeNow = _vm->_time->current(); bool needMoreSharpening = true; - if (timeNow >= _timePhotoOpeningNext) { + // unsigned difference is intentional + if (timeNow - _timePhotoOpeningNextStart >= _timePhotoOpeningNextDiff) { _photoOpeningWidth = MIN(_photoOpeningWidth + 8, _screen.right - 1); _photoOpeningHeight = MIN(_photoOpeningHeight + 7, _screen.bottom - 1); @@ -802,7 +813,8 @@ void ESPER::drawPhotoSharpening(Graphics::Surface &surface) { needMoreSharpening = false; } - _timePhotoOpeningNext = timeNow + 50; + _timePhotoOpeningNextDiff = 50u; + _timePhotoOpeningNextStart = timeNow; } if (_regionSelectedAck && !_regions[_regionSelected].name.empty()) { @@ -833,9 +845,10 @@ void ESPER::drawPhotoSharpening(Graphics::Surface &surface) { } void ESPER::drawPhotoZoomOut(Graphics::Surface &surface) { - int timeNow = _vm->_time->current(); - if (timeNow >= _timeZoomOutNext) { - _timeZoomOutNext = timeNow + 300; + uint32 timeNow = _vm->_time->current(); + // unsigned difference is intentional + if (timeNow - _timeZoomOutNextStart >= 300u) { + _timeZoomOutNextStart = timeNow; if (_zoom > _zoomMin) { _zoom /= 1.3f; @@ -870,14 +883,17 @@ void ESPER::drawVideoZooming(Graphics::Surface &surface) { return; } - _timeZoomNext = 0; + _timeZoomNextDiff = 0u; + _timeZoomNextStart = 0u; } bool flash = false; bool advanceFrame = false; - int timeNow = _vm->_time->current(); - if (timeNow > _timeZoomNext) { - _timeZoomNext = timeNow + 300; + uint32 timeNow = _vm->_time->current(); + // unsigned difference is intentional + if (timeNow - _timeZoomNextStart > _timeZoomNextDiff) { + _timeZoomNextDiff = 300u; + _timeZoomNextStart = timeNow; playSound(kSfxBR031_1P, 25); flash = true; advanceFrame = true; @@ -901,9 +917,11 @@ void ESPER::drawVideoZooming(Graphics::Surface &surface) { void ESPER::drawVideoZoomOut(Graphics::Surface &surface) { bool flash = false; bool advanceFrame = false; - int timeNow = _vm->_time->current(); - if (timeNow > _timeZoomNext && _vqaLastFrame > 0) { - _timeZoomNext = timeNow + 300; + uint32 timeNow = _vm->_time->current(); + // unsigned difference is intentional + if (timeNow - _timeZoomNextStart > _timeZoomNextDiff && _vqaLastFrame > 0) { + _timeZoomNextDiff = 300u; + _timeZoomNextStart = timeNow; playSound(kSfxBR031_1P, 25); _vqaPlayerPhoto->seekToFrame(_vqaLastFrame); int nextFrame = _vqaPlayerPhoto->getFrameCount() / 4; @@ -928,7 +946,8 @@ void ESPER::drawVideoZoomOut(Graphics::Surface &surface) { } copyImageBlit(&_surfaceViewport, Common::Rect(0, 0, 0, 0), &surface, _screen); drawGrid(surface); - if (timeNow > _timeZoomNext && _vqaLastFrame <= 0) { + // unsigned difference is intentional + if (timeNow - _timeZoomNextStart > _timeZoomNextDiff && _vqaLastFrame <= 0) { _vqaPlayerPhoto->close(); delete _vqaPlayerPhoto; _vqaPlayerPhoto = nullptr; @@ -1368,11 +1387,12 @@ void ESPER::tickSound() { } void ESPER::tickScroll() { - int timeNow = _vm->_time->current(); - if (timeNow <= _timeScrollNext) { + uint32 timeNow = _vm->_time->current(); + // unsigned difference is intentional + if (timeNow - _timeScrollNextStart <= 300u) { return; } - _timeScrollNext = timeNow + 300; + _timeScrollNextStart = timeNow; if (_scrollingDirection == 0) { scrollUp(); @@ -1610,8 +1630,8 @@ void ESPER::goBack() { } void ESPER::prepareZoom() { - _selectionZoomStep = 0; - _timeSelectionZoomNext = 0; + _selectionZoomStep = 0; + _timeSelectionZoomNextStart = 0u; _selectionTarget = _selection; resetSelectionRect(); diff --git a/engines/bladerunner/ui/esper.h b/engines/bladerunner/ui/esper.h index 34648a38f4..33954cb34e 100644 --- a/engines/bladerunner/ui/esper.h +++ b/engines/bladerunner/ui/esper.h @@ -119,19 +119,20 @@ class ESPER { bool _isMouseDown; int _mouseOverScroll; - float _zoomHorizontal; - float _zoomVertical; - float _zoom; - float _zoomMin; - float _zoomTarget; - float _zoomDelta; - float _blur; - int _zoomSteps; - int _zoomStep; - int _timeZoomNext; - - bool _isZoomingOut; - int _timeZoomOutNext; + float _zoomHorizontal; + float _zoomVertical; + float _zoom; + float _zoomMin; + float _zoomTarget; + float _zoomDelta; + float _blur; + int _zoomSteps; + int _zoomStep; + uint32 _timeZoomNextDiff; + uint32 _timeZoomNextStart; + + bool _isZoomingOut; + uint32 _timeZoomOutNextStart; Common::Rect _screen; @@ -159,20 +160,21 @@ class ESPER { int _selectionCrosshairX; int _selectionCrosshairY; - int _selectionBlinkingCounter; - int _selectionBlinkingStyle; - int _timeSelectionBlinkingNext; + int _selectionBlinkingCounter; + int _selectionBlinkingStyle; + uint32 _timeSelectionBlinkingNextStart; - int _selectionZoomStep; - int _timeSelectionZoomNext; + int _selectionZoomStep; + uint32 _timeSelectionZoomNextStart; - int _photoOpeningWidth; - int _photoOpeningHeight; - int _timePhotoOpeningNext; + int _photoOpeningWidth; + int _photoOpeningHeight; + uint32 _timePhotoOpeningNextDiff; + uint32 _timePhotoOpeningNextStart; - bool _isScrolling; - int _scrollingDirection; - int _timeScrollNext; + bool _isScrolling; + int _scrollingDirection; + uint32 _timeScrollNextStart; int _soundId1; int _volume1; @@ -218,7 +220,7 @@ private: void setStateMain(EsperMainStates state); void setStatePhoto(EsperPhotoStates state); - void wait(int timeout); + void wait(uint32 timeout); void playSound(int soundId, int volume); void draw(Graphics::Surface &surface); diff --git a/engines/bladerunner/ui/kia.cpp b/engines/bladerunner/ui/kia.cpp index 666a8bd7ab..fe997d5543 100644 --- a/engines/bladerunner/ui/kia.cpp +++ b/engines/bladerunner/ui/kia.cpp @@ -227,8 +227,9 @@ void KIA::tick() { return; } - int timeNow = _vm->_time->currentSystem(); - int timeDiff = timeNow - _timeLast; + uint32 timeNow = _vm->_time->currentSystem(); + // unsigned difference is intentional + uint32 timeDiff = timeNow - _timeLast; if (_playerActorDialogueQueueSize == _playerActorDialogueQueuePosition) { _playerActorDialogueState = 0; @@ -255,22 +256,22 @@ void KIA::tick() { } } - int timeDiffDiv48 = (timeNow - _playerVqaTimeLast) / 48; - if (timeDiffDiv48 > 0) { + uint32 timeDiffDiv48 = (timeNow < _playerVqaTimeLast) ? 0u : (timeNow - _playerVqaTimeLast) / 48; + if (timeDiffDiv48 > 0u) { _playerVqaTimeLast = timeNow; if (_playerActorDialogueQueueSize == _playerActorDialogueQueuePosition || _playerSliceModelId != -1 || _playerPhotographId != -1 || _playerImage.getPixels() != nullptr) { if (_playerVisualizerState > 0) { - _playerVisualizerState = MAX(_playerVisualizerState - timeDiffDiv48, 0); + _playerVisualizerState = (_playerVisualizerState < timeDiffDiv48) ? 0u : MAX<uint32>(_playerVisualizerState - timeDiffDiv48, 0u); } } else { if (_playerVisualizerState < 2) { - _playerVisualizerState = MIN(_playerVisualizerState + timeDiffDiv48, 2); + _playerVisualizerState = MIN<uint32>(_playerVisualizerState + timeDiffDiv48, 2u); } } if ( _playerSliceModelId != -1 || _playerPhotographId != -1 || _playerImage.getPixels() != nullptr) { if (_playerVqaFrame < 8) { - int newVqaFrame = MIN(timeDiffDiv48 + _playerVqaFrame, 8); + int newVqaFrame = MIN<uint32>(timeDiffDiv48 + _playerVqaFrame, 8u); if (_playerVqaFrame <= 0 && newVqaFrame > 0) { _vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(kSfxMECHAN1), 100, 70, 70, 50, 0); } @@ -278,7 +279,7 @@ void KIA::tick() { } } else { if (_playerVqaFrame > 0) { - int newVqaFrame = MAX(_playerVqaFrame - timeDiffDiv48, 0); + int newVqaFrame = (_playerVqaFrame < timeDiffDiv48) ? 0 : MAX<uint32>(_playerVqaFrame - timeDiffDiv48, 0u); if (_playerVqaFrame >= 8 && newVqaFrame < 8) { _vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(kSfxMECHAN1C), 100, 70, 70, 50, 0); } diff --git a/engines/bladerunner/ui/kia.h b/engines/bladerunner/ui/kia.h index 47ea63946d..5c0204b5dd 100644 --- a/engines/bladerunner/ui/kia.h +++ b/engines/bladerunner/ui/kia.h @@ -78,16 +78,16 @@ class KIA { int _transitionId; - int _playerVqaTimeLast; + uint32 _playerVqaTimeLast; VQAPlayer *_playerVqaPlayer; - int _playerVqaFrame; - int _playerVisualizerState; + uint32 _playerVqaFrame; + uint32 _playerVisualizerState; int _playerPhotographId; Shape *_playerPhotograph; int _playerSliceModelId; float _playerSliceModelAngle; Graphics::Surface _playerImage; - int _timeLast; + uint32 _timeLast; ActorDialogueQueueEntry _playerActorDialogueQueue[kPlayerActorDialogueQueueCapacity]; int _playerActorDialogueQueuePosition; diff --git a/engines/bladerunner/ui/kia_section_diagnostic.cpp b/engines/bladerunner/ui/kia_section_diagnostic.cpp index 41ff43c282..662aef3621 100644 --- a/engines/bladerunner/ui/kia_section_diagnostic.cpp +++ b/engines/bladerunner/ui/kia_section_diagnostic.cpp @@ -71,7 +71,7 @@ void KIASectionDiagnostic::close() { } void KIASectionDiagnostic::draw(Graphics::Surface &surface) { - int timeNow = _vm->_time->currentSystem(); + uint32 timeNow = _vm->_time->currentSystem(); for (int i = 0; i < _text->getCount(); ++i) { int y = kLineHeight * i + 366 - _offset; @@ -91,7 +91,8 @@ void KIASectionDiagnostic::draw(Graphics::Surface &surface) { } // Timing fixed for 60Hz by ScummVM team - if (timeNow - _timeLast > 1000 / 60) { + // unsigned difference is intentional + if (timeNow - _timeLast > (1000u / 60u)) { ++_offset; if (_offset > kLineHeight * _text->getCount() + 366) { _offset = 0; diff --git a/engines/bladerunner/ui/kia_section_diagnostic.h b/engines/bladerunner/ui/kia_section_diagnostic.h index 0c518f2561..82365575d5 100644 --- a/engines/bladerunner/ui/kia_section_diagnostic.h +++ b/engines/bladerunner/ui/kia_section_diagnostic.h @@ -36,7 +36,7 @@ class KIASectionDiagnostic : public KIASectionBase { TextResource *_text; int _offset; - int _timeLast; + uint32 _timeLast; public: KIASectionDiagnostic(BladeRunnerEngine *vm); diff --git a/engines/bladerunner/ui/kia_section_load.cpp b/engines/bladerunner/ui/kia_section_load.cpp index 42ace56e0d..41f2e7e18f 100644 --- a/engines/bladerunner/ui/kia_section_load.cpp +++ b/engines/bladerunner/ui/kia_section_load.cpp @@ -44,8 +44,8 @@ KIASectionLoad::KIASectionLoad(BladeRunnerEngine *vm) : KIASectionBase(vm) { _scrollBox = new UIScrollBox(_vm, scrollBoxCallback, this, 1025, 0, true, Common::Rect(155, 158, 461, 346), Common::Rect(506, 160, 506, 350)); _uiContainer->add(_scrollBox); - _timeLast = 0; - _timeLeft = 0; + _timeLast = 0u; + _timeLeft = 0u; _hoveredLineId = -1; _displayingLineId = -1; @@ -86,7 +86,7 @@ void KIASectionLoad::open() { _hoveredLineId = -1; _timeLast = _vm->_time->currentSystem(); - _timeLeft = 800; + _timeLeft = 800u; } void KIASectionLoad::close() { @@ -105,7 +105,7 @@ void KIASectionLoad::draw(Graphics::Surface &surface) { if (_hoveredLineId != selectedLineId) { if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size() && _displayingLineId != selectedLineId) { - if (_timeLeft == 0) { + if (_timeLeft == 0u) { SaveStateDescriptor desc = SaveFileManager::queryMetaInfos(_vm->getTargetName(), selectedLineId); const Graphics::Surface *thumbnail = desc.getThumbnail(); if (thumbnail != nullptr) { @@ -115,7 +115,7 @@ void KIASectionLoad::draw(Graphics::Surface &surface) { } } else { _vm->_kia->playerReset(); - _timeLeft = 800; + _timeLeft = 800u; _displayingLineId = -1; } _hoveredLineId = selectedLineId; @@ -124,7 +124,7 @@ void KIASectionLoad::draw(Graphics::Surface &surface) { uint32 now = _vm->_time->currentSystem(); if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size() && _displayingLineId != selectedLineId) { if (_timeLeft) { - uint32 timeDiff = now - _timeLast; + uint32 timeDiff = now - _timeLast; // unsigned difference is intentional if (timeDiff >= _timeLeft) { SaveStateDescriptor desc = SaveFileManager::queryMetaInfos(_vm->getTargetName(), _saveList[selectedLineId].getSaveSlot()); const Graphics::Surface *thumbnail = desc.getThumbnail(); @@ -133,7 +133,7 @@ void KIASectionLoad::draw(Graphics::Surface &surface) { _displayingLineId = selectedLineId; } } else { - _timeLeft -= timeDiff; + _timeLeft = (_timeLeft < timeDiff) ? 0u : (_timeLeft - timeDiff); } } } diff --git a/engines/bladerunner/ui/kia_section_pogo.cpp b/engines/bladerunner/ui/kia_section_pogo.cpp index c5a325136e..cd0bb27efb 100644 --- a/engines/bladerunner/ui/kia_section_pogo.cpp +++ b/engines/bladerunner/ui/kia_section_pogo.cpp @@ -251,9 +251,10 @@ void KIASectionPogo::open() { void KIASectionPogo::draw(Graphics::Surface &surface) { // Timing fixed for 60Hz by ScummVM team - int timeNow = _vm->_time->currentSystem(); + uint32 timeNow = _vm->_time->currentSystem(); bool updateTimeout = false; - if (timeNow - _timeLast > 1000 / 60) { + // unsigned difference is intentional + if (timeNow - _timeLast > (1000u / 60u)) { updateTimeout = true; _timeLast = timeNow; } diff --git a/engines/bladerunner/ui/kia_section_pogo.h b/engines/bladerunner/ui/kia_section_pogo.h index 7392cde4cb..85ca29cbc7 100644 --- a/engines/bladerunner/ui/kia_section_pogo.h +++ b/engines/bladerunner/ui/kia_section_pogo.h @@ -41,7 +41,7 @@ class KIASectionPogo : public KIASectionBase { int _lineTimeouts[kLineCount]; int _lineOffsets[kLineCount]; - int _timeLast; + uint32 _timeLast; public: KIASectionPogo(BladeRunnerEngine *vm); diff --git a/engines/bladerunner/ui/kia_section_save.cpp b/engines/bladerunner/ui/kia_section_save.cpp index b0f35b9fda..e4a919040d 100644 --- a/engines/bladerunner/ui/kia_section_save.cpp +++ b/engines/bladerunner/ui/kia_section_save.cpp @@ -55,8 +55,8 @@ KIASectionSave::KIASectionSave(BladeRunnerEngine *vm) : KIASectionBase(vm) { _buttons = new UIImagePicker(_vm, 3); - _timeLast = 0; - _timeLeft = 0; + _timeLast = 0u; + _timeLeft = 0u; _state = kStateNormal; @@ -130,7 +130,7 @@ void KIASectionSave::open() { _hoveredLineId = -1; _timeLast = _vm->_time->currentSystem(); - _timeLeft = 800; + _timeLeft = 800u; } void KIASectionSave::close() { @@ -185,7 +185,7 @@ void KIASectionSave::draw(Graphics::Surface &surface) { if (selectedLineId != _hoveredLineId) { if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size() && _displayingLineId != selectedLineId) { - if (_timeLeft == 0) { + if (_timeLeft == 0u) { SaveStateDescriptor desc = SaveFileManager::queryMetaInfos(_vm->getTargetName(), selectedLineId); const Graphics::Surface *thumbnail = desc.getThumbnail(); if (thumbnail != nullptr) { @@ -195,7 +195,7 @@ void KIASectionSave::draw(Graphics::Surface &surface) { } } else { _vm->_kia->playerReset(); - _timeLeft = 800; + _timeLeft = 800u; _displayingLineId = -1; } _hoveredLineId = selectedLineId; @@ -204,7 +204,7 @@ void KIASectionSave::draw(Graphics::Surface &surface) { uint32 now = _vm->_time->currentSystem(); if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size() && _displayingLineId != selectedLineId) { if (_timeLeft) { - uint32 timeDiff = now - _timeLast; + uint32 timeDiff = now - _timeLast; // unsigned difference is intentional if (timeDiff >= _timeLeft) { SaveStateDescriptor desc = SaveFileManager::queryMetaInfos(_vm->getTargetName(), _saveList[selectedLineId].getSaveSlot()); const Graphics::Surface *thumbnail = desc.getThumbnail(); @@ -213,7 +213,7 @@ void KIASectionSave::draw(Graphics::Surface &surface) { _displayingLineId = selectedLineId; } } else { - _timeLeft -= timeDiff; + _timeLeft = (_timeLeft < timeDiff) ? 0u : (_timeLeft - timeDiff); } } } diff --git a/engines/bladerunner/ui/spinner.cpp b/engines/bladerunner/ui/spinner.cpp index b6269bbb50..cab2d67dee 100644 --- a/engines/bladerunner/ui/spinner.cpp +++ b/engines/bladerunner/ui/spinner.cpp @@ -293,7 +293,7 @@ void Spinner::reset() { _actorId = -1; _sentenceId = -1; - _timeSpeakDescription = 0; + _timeSpeakDescriptionStart = 0u; for (int i = 0; i != (int)_shapes.size(); ++i) { delete _shapes[i]; @@ -413,20 +413,21 @@ void Spinner::destinationFocus(int destinationImage) { void Spinner::setupDescription(int actorId, int sentenceId) { _actorId = actorId; _sentenceId = sentenceId; - _timeSpeakDescription = _vm->_time->current() + 600; + _timeSpeakDescriptionStart = _vm->_time->current(); } // copied from elevator.cpp code void Spinner::resetDescription() { _actorId = -1; _sentenceId = -1; - _timeSpeakDescription = 0; + _timeSpeakDescriptionStart = 0u; } // copied from elevator.cpp code void Spinner::tickDescription() { - int now = _vm->_time->current(); - if (_actorId <= 0 || now < _timeSpeakDescription) { + uint32 now = _vm->_time->current(); + // unsigned difference is intentional + if (_actorId <= 0 || (now - _timeSpeakDescriptionStart < 600u)) { return; } diff --git a/engines/bladerunner/ui/spinner.h b/engines/bladerunner/ui/spinner.h index 50a8be97b6..2fa0dc659c 100644 --- a/engines/bladerunner/ui/spinner.h +++ b/engines/bladerunner/ui/spinner.h @@ -54,7 +54,7 @@ class Spinner { int _actorId; int _sentenceId; - int _timeSpeakDescription; + uint32 _timeSpeakDescriptionStart; public: Spinner(BladeRunnerEngine *vm); diff --git a/engines/bladerunner/ui/ui_check_box.cpp b/engines/bladerunner/ui/ui_check_box.cpp index 76cecd227c..38fb86c679 100644 --- a/engines/bladerunner/ui/ui_check_box.cpp +++ b/engines/bladerunner/ui/ui_check_box.cpp @@ -44,9 +44,9 @@ UICheckBox::UICheckBox(BladeRunnerEngine *vm, UIComponentCallback *valueChangedC _style = style; if (isChecked) { - _frame = 5; + _frame = 5u; } else { - _frame = 0; + _frame = 0u; } _timeLast = _vm->_time->currentSystem(); @@ -57,39 +57,41 @@ UICheckBox::UICheckBox(BladeRunnerEngine *vm, UIComponentCallback *valueChangedC void UICheckBox::draw(Graphics::Surface &surface) { if (_rect.right > _rect.left && _rect.bottom > _rect.top) { - int shapeId; + uint32 shapeId; - uint timeNow = _vm->_time->currentSystem(); - if (timeNow - _timeLast > 67) { - int frameDelta = (timeNow - _timeLast) / 67u; + uint32 timeNow = _vm->_time->currentSystem(); + // unsigned difference is intentional + if (timeNow - _timeLast > 67u) { + // unsigned difference is intentional + uint32 frameDelta = (timeNow - _timeLast) / 67u; _timeLast = timeNow; if (_isChecked) { - _frame = MIN(_frame + frameDelta, 5); + _frame = MIN<uint32>(_frame + frameDelta, 5u); } else { - _frame = MAX(_frame - frameDelta, 0); + _frame = (_frame < frameDelta) ? 0 : MAX<uint32>(_frame - frameDelta, 0u); } } if (_style) { if (_frame || (_hasFocus && !_isPressed && _isEnabled)) { - if (_frame != 5 || (_hasFocus && !_isPressed && _isEnabled)) { - shapeId = _frame + 54; + if (_frame != 5u || (_hasFocus && !_isPressed && _isEnabled)) { + shapeId = _frame + 54u; } else { - shapeId = 53; + shapeId = 53u; } } else { - shapeId = 52; + shapeId = 52u; } } else { if (_frame || (_hasFocus && !_isPressed && _isEnabled)) { - if (_frame != 5 || (_hasFocus && !_isPressed && _isEnabled)) { - shapeId = _frame + 62; + if (_frame != 5u || (_hasFocus && !_isPressed && _isEnabled)) { + shapeId = _frame + 62u; } else { - shapeId = 61; + shapeId = 61u; } } else { - shapeId = 60; + shapeId = 60u; } } diff --git a/engines/bladerunner/ui/ui_check_box.h b/engines/bladerunner/ui/ui_check_box.h index 01ee555148..9b601ed698 100644 --- a/engines/bladerunner/ui/ui_check_box.h +++ b/engines/bladerunner/ui/ui_check_box.h @@ -36,9 +36,9 @@ class UICheckBox : public UIComponent { int _style; int _isEnabled; Common::Rect _rect; - int _frame; + uint32 _frame; int _isPressed; - uint _timeLast; + uint32 _timeLast; int _hasFocus; public: diff --git a/engines/bladerunner/ui/ui_image_picker.cpp b/engines/bladerunner/ui/ui_image_picker.cpp index 0b1a0dd204..e23fd2776e 100644 --- a/engines/bladerunner/ui/ui_image_picker.cpp +++ b/engines/bladerunner/ui/ui_image_picker.cpp @@ -167,7 +167,7 @@ void UIImagePicker::activate(UIImagePickerCallback *mouseInCallback, _mouseDownCallback = mouseDownCallback; _mouseUpCallback = mouseUpCallback; _callbackData = callbackData; - _hoverStartTimestamp = 0; + _hoverStartTimestamp = 0u; _isVisible = true; _hoveredImageIndex = -1; _pressedImageIndex = -1; @@ -180,7 +180,7 @@ void UIImagePicker::deactivate() { _mouseDownCallback = nullptr; _mouseUpCallback = nullptr; _callbackData = nullptr; - _hoverStartTimestamp = 0; + _hoverStartTimestamp = 0u; _isVisible = false; _hoveredImageIndex = -1; _pressedImageIndex = -1; @@ -228,8 +228,8 @@ void UIImagePicker::drawTooltip(Graphics::Surface &surface, int x, int y) { (_hoveredImageIndex == -1) || (_vm->_mouse->isDisabled()) || (!_images[_hoveredImageIndex].active) || - (_vm->_time->current() < _hoverStartTimestamp + 1000) - ) { + (_vm->_time->current() - _hoverStartTimestamp < 1000u) + ) { // unsigned difference is intentional (time difference) return; } @@ -352,7 +352,7 @@ void UIImagePicker::reset() { _isVisible = false; _hoveredImageIndex = -1; _pressedImageIndex = -1; - _hoverStartTimestamp = 0; + _hoverStartTimestamp = 0u; _isButtonDown = false; _mouseInCallback = nullptr; _mouseOutCallback = nullptr; diff --git a/engines/bladerunner/ui/ui_image_picker.h b/engines/bladerunner/ui/ui_image_picker.h index 3d62192454..29d59ba68c 100644 --- a/engines/bladerunner/ui/ui_image_picker.h +++ b/engines/bladerunner/ui/ui_image_picker.h @@ -50,12 +50,12 @@ class UIImagePicker { BladeRunnerEngine *_vm; - int _isVisible; - int _imageCount; - int _hoveredImageIndex; - int _pressedImageIndex; - int _hoverStartTimestamp; - int _isButtonDown; + int _isVisible; + int _imageCount; + int _hoveredImageIndex; + int _pressedImageIndex; + uint32 _hoverStartTimestamp; + int _isButtonDown; Common::Array<Image> _images; UIImagePickerCallback *_mouseInCallback; diff --git a/engines/bladerunner/ui/ui_input_box.h b/engines/bladerunner/ui/ui_input_box.h index ac58a6e4ed..3aa21f2e2f 100644 --- a/engines/bladerunner/ui/ui_input_box.h +++ b/engines/bladerunner/ui/ui_input_box.h @@ -42,7 +42,7 @@ class UIInputBox : public UIComponent { bool _cursorIsVisible; - int _timeLast; + uint32 _timeLast; public: UIInputBox(BladeRunnerEngine *vm, UIComponentCallback *valueChangedCallback, void *callbackData, Common::Rect rect, int maxLength, const Common::String &text); diff --git a/engines/bladerunner/ui/ui_scroll_box.cpp b/engines/bladerunner/ui/ui_scroll_box.cpp index 48796a29ba..b24aa89bac 100644 --- a/engines/bladerunner/ui/ui_scroll_box.cpp +++ b/engines/bladerunner/ui/ui_scroll_box.cpp @@ -129,7 +129,7 @@ UIScrollBox::UIScrollBox(BladeRunnerEngine *vm, UIScrollBoxCallback *lineSelecte _lines[i] = new Line(); _lines[i]->lineData = -1; _lines[i]->flags = 0x00; - _lines[i]->checkboxFrame = 5; + _lines[i]->checkboxFrame = 5u; } _mouseOver = false; @@ -316,7 +316,7 @@ void UIScrollBox::handleMouseDown(bool alternateButton) { if (!alternateButton) { if (_scrollUpButtonHover) { _scrollUpButtonState = 2; - _timeLastScroll = _vm->_time->currentSystem() - 160; + _timeLastScroll = _vm->_time->currentSystem() - 160u; } else { _scrollUpButtonState = 1; } @@ -332,13 +332,13 @@ void UIScrollBox::handleMouseDown(bool alternateButton) { } if (_scrollAreaUpHover) { _scrollAreaUpState = 2; - _timeLastScroll = _vm->_time->currentSystem() - 160; + _timeLastScroll = _vm->_time->currentSystem() - 160u; } else { _scrollAreaUpState = 1; } if (_scrollAreaDownHover) { _scrollAreaDownState = 2; - _timeLastScroll = _vm->_time->currentSystem() - 160; + _timeLastScroll = _vm->_time->currentSystem() - 160u; } else { _scrollAreaDownState = 1; } @@ -380,27 +380,31 @@ int UIScrollBox::getSelectedLineData() { } void UIScrollBox::draw(Graphics::Surface &surface) { - int timeNow = _vm->_time->currentSystem(); + uint32 timeNow = _vm->_time->currentSystem(); // update scrolling if (_scrollUpButtonState == 2 && _scrollUpButtonHover) { - if ((timeNow - _timeLastScroll) > 160) { + // unsigned difference is intentional + if ((timeNow - _timeLastScroll) > 160u) { scrollUp(); _timeLastScroll = timeNow; } } else if (_scrollDownButtonState == 2 && _scrollDownButtonHover) { - if ((timeNow - _timeLastScroll) > 160) { + // unsigned difference is intentional + if ((timeNow - _timeLastScroll) > 160u) { scrollDown(); _timeLastScroll = timeNow; } } else if (_scrollAreaUpState == 2 && _scrollAreaUpHover) { - if ((timeNow - _timeLastScroll) > 160) { + // unsigned difference is intentional + if ((timeNow - _timeLastScroll) > 160u) { _firstLineVisible -= _maxLinesVisible - 1; _firstLineVisible = CLIP(_firstLineVisible, 0, _lineCount - _maxLinesVisible); _timeLastScroll = timeNow; } } else if (_scrollAreaDownState == 2 && _scrollAreaDownHover) { - if ((timeNow - _timeLastScroll) > 160) { + // unsigned difference is intentional + if ((timeNow - _timeLastScroll) > 160u) { _firstLineVisible += _maxLinesVisible - 1; _firstLineVisible = CLIP(_firstLineVisible, 0, _lineCount - _maxLinesVisible); _timeLastScroll = timeNow; @@ -408,24 +412,25 @@ void UIScrollBox::draw(Graphics::Surface &surface) { } // update checkboxes - int timeDiffCheckBox = timeNow - _timeLastCheckbox; - if (timeDiffCheckBox > 67) { + // unsigned difference is intentional + uint32 timeDiffCheckBox = timeNow - _timeLastCheckbox; + if (timeDiffCheckBox > 67u) { _timeLastCheckbox = timeNow; for (int i = 0; i < _lineCount; ++i) { if (_lines[i]->flags & 0x01) { // has checkbox if (_lines[i]->flags & 0x02) { // checkbox checked - if (_lines[i]->checkboxFrame < 5) { - _lines[i]->checkboxFrame += timeDiffCheckBox / 67; + if (_lines[i]->checkboxFrame < 5u) { + _lines[i]->checkboxFrame += timeDiffCheckBox / 67u; } - if (_lines[i]->checkboxFrame > 5) { - _lines[i]->checkboxFrame = 5; + if (_lines[i]->checkboxFrame > 5u) { + _lines[i]->checkboxFrame = 5u; } } else { // checkbox not checked - if (_lines[i]->checkboxFrame > 0) { - _lines[i]->checkboxFrame -= timeDiffCheckBox / 67; + if (_lines[i]->checkboxFrame > 0u) { + _lines[i]->checkboxFrame = (_lines[i]->checkboxFrame < (timeDiffCheckBox / 67u)) ? 0u : _lines[i]->checkboxFrame - (timeDiffCheckBox / 67u); } - if (_lines[i]->checkboxFrame < 0) { - _lines[i]->checkboxFrame = 0; + if (_lines[i]->checkboxFrame == 0u) { // original was < 0, int + _lines[i]->checkboxFrame = 0u; } } } @@ -434,7 +439,8 @@ void UIScrollBox::draw(Graphics::Surface &surface) { // update highlight - if ((timeNow - _timeLastHighlight) > 67) { + // unsigned difference is intentional + if ((timeNow - _timeLastHighlight) > 67u) { _timeLastHighlight = timeNow; _highlightFrame = (_highlightFrame + 1) % 8; } @@ -497,8 +503,8 @@ void UIScrollBox::draw(Graphics::Surface &surface) { int checkboxShapeId = 0; if (_style == 0) { if (_lines[i]->checkboxFrame || v35) { - if (_lines[i]->checkboxFrame != 5 || v35) { - checkboxShapeId = _lines[i]->checkboxFrame + 62; + if (_lines[i]->checkboxFrame != 5u || v35) { + checkboxShapeId = _lines[i]->checkboxFrame + 62u; } else { checkboxShapeId = 61; } @@ -506,8 +512,8 @@ void UIScrollBox::draw(Graphics::Surface &surface) { checkboxShapeId = 60; } } else if (_lines[i]->checkboxFrame || v35) { - if (_lines[i]->checkboxFrame != 5 || v35) { - checkboxShapeId = _lines[i]->checkboxFrame + 54; + if (_lines[i]->checkboxFrame != 5u || v35) { + checkboxShapeId = _lines[i]->checkboxFrame + 54u; } else { checkboxShapeId = 53; } diff --git a/engines/bladerunner/ui/ui_scroll_box.h b/engines/bladerunner/ui/ui_scroll_box.h index 1cd2913525..2ac0701ee0 100644 --- a/engines/bladerunner/ui/ui_scroll_box.h +++ b/engines/bladerunner/ui/ui_scroll_box.h @@ -45,9 +45,9 @@ class UIScrollBox : public UIComponent { struct Line { Common::String text; - int lineData; - int flags; - int checkboxFrame; + int lineData; + int flags; + uint32 checkboxFrame; }; int _selectedLineState; @@ -75,9 +75,9 @@ class UIScrollBox : public UIComponent { int _style; bool _center; - int _timeLastScroll; - int _timeLastCheckbox; - int _timeLastHighlight; + uint32 _timeLastScroll; + uint32 _timeLastCheckbox; + uint32 _timeLastHighlight; int _highlightFrame; diff --git a/engines/bladerunner/ui/vk.cpp b/engines/bladerunner/ui/vk.cpp index e0b595cedc..1cacf31584 100644 --- a/engines/bladerunner/ui/vk.cpp +++ b/engines/bladerunner/ui/vk.cpp @@ -213,7 +213,8 @@ void VK::tick() { _vm->blitToScreen(_vm->_surfaceFront); _vm->_system->delayMillis(10); - if (_isClosing && _vm->_time->current() >= _timeClose && !_script->isInsideScript()) { + // unsigned difference is intentional + if (_isClosing && (_vm->_time->current() - _timeCloseStart >= 3000u) && !_script->isInsideScript()) { close(); _vm->_mouse->enable(); reset(); @@ -265,8 +266,9 @@ void VK::playSpeechLine(int actorId, int sentenceId, float duration) { } if (duration > 0.0f && !_vm->_actorSpeakStopIsRequested) { - int timeEnd = duration * 1000.0f + _vm->_time->current(); - while ((timeEnd > _vm->_time->current()) && _vm->_gameIsRunning) { + uint32 timeStart = _vm->_time->current(); + uint32 timeUntil = duration * 1000.0f; + while ((_vm->_time->current() - timeStart < timeUntil) && _vm->_gameIsRunning) { _vm->gameTick(); } } @@ -280,13 +282,13 @@ void VK::subjectReacts(int intensity, int humanResponse, int replicantResponse, humanResponse = CLIP(humanResponse, -20, 20); replicantResponse = CLIP(replicantResponse, -20, 20); - int timeNow = _vm->_time->current(); - bool closeVK = false; + uint32 timeNow = _vm->_time->current(); + bool closeVK = false; if (intensity > 0) { _needleValueTarget = 78 * intensity / 100; _needleValueDelta = (_needleValueTarget - _needleValue) / 10; - _timeNextNeedleStep = timeNow + 66; + _timeNextNeedleStepStart = timeNow; } if (humanResponse != 0) { @@ -309,7 +311,7 @@ void VK::subjectReacts(int intensity, int humanResponse, int replicantResponse, if (closeVK == true) { _isClosing = true; - _timeClose = timeNow + 3000; + _timeCloseStart = timeNow; _vm->_mouse->disable(); } } @@ -340,7 +342,7 @@ void VK::subjectReacts(int intensity, int humanResponse, int replicantResponse, if (closeVK == true) { _isClosing = true; - _timeClose = timeNow + 3000; + _timeCloseStart = timeNow; _vm->_mouse->disable(); } } @@ -368,7 +370,7 @@ void VK::subjectReacts(int intensity, int humanResponse, int replicantResponse, if (closeVK == true) { _isClosing = true; - _timeClose = timeNow + 3000; + _timeCloseStart = timeNow; _vm->_mouse->disable(); } } @@ -462,46 +464,49 @@ void VK::reset() { _needleValueTarget = 0; _needleValueDelta = 0; _needleValueMax = 0; - _timeNextNeedleStep = 0; - _timeNeedleReturn = 0; - _timeNextNeedleOscillate = 0; - - _humanProbability = 0; - _humanGauge = 0; - _humanGaugeTarget = 0; - _humanGaugeDelta = 0; - _timeNextHumanGaugeStep = 0; - - _replicantProbability = 0; - _replicantGauge = 0; - _replicantGaugeTarget = 0; - _replicantGaugeDelta = 0; - _timeNextReplicantGaugeStep = 0; + + _timeNextNeedleStepStart = 0u; + _timeNeedleReturnStart = 0u; + _timeNextNeedleOscillateStart = 0u; + + _humanProbability = 0; + _humanGauge = 0; + _humanGaugeTarget = 0; + _humanGaugeDelta = 0; + _timeNextHumanGaugeStepDiff = 0u; + _timeNextHumanGaugeStepStart = 0u; + + _replicantProbability = 0; + _replicantGauge = 0; + _replicantGaugeTarget = 0; + _replicantGaugeDelta = 0; + _timeNextReplicantGaugeStepDiff = 0u; + _timeNextReplicantGaugeStepStart = 0u; _anxiety = 0; - _blinkState = 0; - _timeNextBlink = 0; - _timeNextGaugesBlink = 0; - - _isClosing = false; - _timeClose = 0; - - _isAdjusting = false; - _adjustment = 154; - _adjustmentTarget = 154; - _adjustmentDelta = 0; - _timeNextAdjustementStep = 0; - - _eyeLineSelected = 1; - _eyeLineX = 315; - _eyeLineXLast = 315; - _eyeLineY = 281; - _eyeLineYLast = 281; - _eyeLineXDelta = 8; - _eyeLineYDelta = 8; - _timeNextEyeLineStep = 0; - _timeNextEyeLineStart = 0; + _blinkState = 0; + _timeNextBlinkStart = 0u; + _timeNextGaugesBlinkStart = 0u; + + _isClosing = false; + _timeCloseStart = 0u; + + _isAdjusting = false; + _adjustment = 154; + _adjustmentTarget = 154; + _adjustmentDelta = 0; + _timeNextAdjustementStepStart = 0u; + + _eyeLineSelected = 1; + _eyeLineX = 315; + _eyeLineXLast = 315; + _eyeLineY = 281; + _eyeLineYLast = 281; + _eyeLineXDelta = 8; + _eyeLineYDelta = 8; + _timeNextEyeLineStepStart = 0u; + _timeNextEyeLineStart = 0u; _soundTrackId1 = -1; _soundTrackId2 = -1; @@ -573,14 +578,15 @@ void VK::draw() { Graphics::Surface &surface = _vm->_surfaceFront; - int timeNow = _vm->_time->current(); + uint32 timeNow = _vm->_time->current(); if (_isAdjusting && !_testStarted && !_vm->isMouseButtonDown()) { _isAdjusting = false; } if (_vqaFrameMain >= 26) { - if (_isClosing && timeNow >= _timeNextGaugesBlink) { + // unsigned difference is intentional + if (_isClosing && timeNow - _timeNextGaugesBlinkStart >= 600u) { if (_blinkState) { _buttons->setImageShapeUp(6, nullptr); _buttons->setImageShapeUp(7, nullptr); @@ -596,12 +602,13 @@ void VK::draw() { } _blinkState = 1; } - _timeNextGaugesBlink = timeNow + 600; + _timeNextGaugesBlinkStart = timeNow; } _buttons->draw(surface); - if (_humanGaugeDelta != 0 && timeNow >= _timeNextHumanGaugeStep) { + // unsigned difference is intentional + if (_humanGaugeDelta != 0 && timeNow - _timeNextHumanGaugeStepStart >= _timeNextHumanGaugeStepDiff) { _humanGauge += _humanGaugeDelta; if ((_humanGaugeDelta > 0 && _humanGauge >= _humanGaugeTarget) @@ -613,17 +620,20 @@ void VK::draw() { if (_humanGaugeTarget != 0) { _humanGaugeTarget = 0; _humanGaugeDelta = -_humanGaugeDelta; - _timeNextHumanGaugeStep = timeNow + 500; + _timeNextHumanGaugeStepDiff = 500u; + _timeNextHumanGaugeStepStart = timeNow; } else { _humanGaugeDelta = 0; } } else { - _timeNextHumanGaugeStep = timeNow + 66; + _timeNextHumanGaugeStepDiff = 66u; + _timeNextHumanGaugeStepStart = timeNow; } } drawHumanGauge(surface); - if (_replicantGaugeDelta != 0 && timeNow >= _timeNextReplicantGaugeStep) { + // unsigned difference is intentional + if (_replicantGaugeDelta != 0 && timeNow - _timeNextReplicantGaugeStepStart >= _timeNextReplicantGaugeStepDiff) { _replicantGauge += _replicantGaugeDelta; if ((_replicantGaugeDelta > 0 && _replicantGauge >= _replicantGaugeTarget) @@ -635,17 +645,20 @@ void VK::draw() { if (_replicantGaugeTarget != 0) { _replicantGaugeTarget = 0; _replicantGaugeDelta = -_replicantGaugeDelta; - _timeNextReplicantGaugeStep = timeNow + 500; + _timeNextReplicantGaugeStepDiff = 500u; + _timeNextReplicantGaugeStepStart = timeNow; } else { _replicantGaugeDelta = 0; } } else { - _timeNextReplicantGaugeStep = timeNow + 66; + _timeNextReplicantGaugeStepDiff = 66u; + _timeNextReplicantGaugeStepStart = timeNow; } } drawReplicantGauge(surface); - if (!_calibrationStarted && _vqaFrameMain >= 59 && timeNow >= _timeNextBlink) { + // unsigned difference is intentional + if (!_calibrationStarted && _vqaFrameMain >= 59 && timeNow - _timeNextBlinkStart >= 600u) { if (_blinkState) { _buttons->setImageShapeUp(0, nullptr); _blinkState = false; @@ -654,10 +667,11 @@ void VK::draw() { _vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(kSfxVKBEEP1), 50, 0, 0, 50, 0); _blinkState = true; } - _timeNextBlink = timeNow + 600; + _timeNextBlinkStart = timeNow; } - if (_adjustmentDelta != 0 && timeNow >= _timeNextAdjustementStep) { + // unsigned difference is intentional + if (_adjustmentDelta != 0 && timeNow - _timeNextAdjustementStepStart >= 50u) { if (_adjustmentDelta > 0) { _adjustment += 3; if (_adjustment >= _adjustmentTarget) { @@ -675,7 +689,8 @@ void VK::draw() { } setAdjustmentFromMouse(); - if (_calibrationStarted && !_testStarted && timeNow >= _timeNextBlink) { + // unsigned difference is intentional + if (_calibrationStarted && !_testStarted && timeNow - _timeNextBlinkStart >= 600u) { if (_blinkState) { _buttons->setImageShapeUp(2, nullptr); _buttons->setImageShapeUp(3, nullptr); @@ -689,10 +704,11 @@ void VK::draw() { _vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(kSfxVKBEEP2), 33, 0, 0, 50, 0); } - _timeNextBlink = timeNow + 600; + _timeNextBlinkStart = timeNow; } - if (_needleValueDelta != 0 && timeNow >= _timeNextNeedleStep) { + // unsigned difference is intentional + if (_needleValueDelta != 0 && (timeNow - _timeNextNeedleStepStart >= 66u)) { if (_needleValueDelta > 0) { _needleValue += 4; if (_needleValue >= _needleValueTarget) { @@ -701,13 +717,14 @@ void VK::draw() { _needleValueDelta = -_needleValueDelta; _needleValueTarget = 0; - _timeNeedleReturn = timeNow + 1800; + _timeNeedleReturnStart = timeNow; if (!_testStarted) { animateAdjustment(_needleValueMax + 165); } } - } else if (timeNow >= _timeNeedleReturn) { + } else if (timeNow - _timeNeedleReturnStart >= 1800u) { + // unsigned difference is intentional _needleValue -= 4; if (_needleValue <= _needleValueTarget) { _needleValue = _needleValueTarget; @@ -715,14 +732,15 @@ void VK::draw() { } } _vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(kSfxBR027_3P), 20, 0, 0, 50, 0); - _timeNextNeedleStep = timeNow + 66; + _timeNextNeedleStepStart = timeNow; } drawNeedle(surface); drawEye(surface); drawEyeCrosshair(surface, timeNow); - if (timeNow >= _timeNextNeedleOscillate) { - _timeNextNeedleOscillate = timeNow + 66; + // unsigned difference is intentional + if (timeNow - _timeNextNeedleOscillateStart >= 66u) { + _timeNextNeedleOscillateStart = timeNow; } int mouseX, mouseY; _vm->_mouse->getXY(&mouseX, &mouseY); @@ -734,7 +752,8 @@ void VK::draw() { void VK::drawNeedle(Graphics::Surface &surface) { int x = _needleValue + 165; - if ((_vm->_time->current() >= _timeNextNeedleOscillate) && (x > 165)) { + // unsigned difference is intentional + if ((_vm->_time->current() - _timeNextNeedleOscillateStart >= 66u) && (x > 165)) { x = CLIP(x + (int)_vm->_rnd.getRandomNumberRng(0, 4) - 2, 165, 245); } @@ -759,7 +778,7 @@ void VK::drawEye(Graphics::Surface &surface) { surface.copyRectToSurface(_surfaceEye, 315, 281, Common::Rect(0, 0, _surfaceEye.w, _surfaceEye.h)); } -void VK::drawEyeCrosshair(Graphics::Surface &surface, int timeNow) { +void VK::drawEyeCrosshair(Graphics::Surface &surface, uint32 timeNow) { surface.drawLine(315, _eyeLineY, 486, _eyeLineY, surface.format.RGBToColor(16, 16, 64)); surface.drawLine(315, _eyeLineY - 1, 486, _eyeLineY - 1, surface.format.RGBToColor(16, 16, 64)); surface.drawLine(315, _eyeLineY, _vm->_rnd.getRandomNumberRng(10, 20) + 315, _eyeLineY, surface.format.RGBToColor(16, 16, 80)); @@ -774,13 +793,15 @@ void VK::drawEyeCrosshair(Graphics::Surface &surface, int timeNow) { surface.drawLine(_eyeLineX - 1, 396 - _vm->_rnd.getRandomNumberRng(10, 20), _eyeLineX - 1, 396, surface.format.RGBToColor(16, 16, 80)); surface.drawLine(_eyeLineX - 1, 281, _eyeLineX - 1, _vm->_rnd.getRandomNumberRng(10, 20) + 281, surface.format.RGBToColor(16, 16, 80)); - if (timeNow >= _timeNextEyeLineStart) { + // unsigned difference is intentional + if (timeNow - _timeNextEyeLineStart >= 1000u) { if (_eyeLineSelected) { if (_eyeLineYLast != _eyeLineY) { surface.drawLine(315, _eyeLineYLast, 486, _eyeLineYLast, surface.format.RGBToColor(16, 16, 32)); } _eyeLineYLast = _eyeLineY; - if (timeNow >= _timeNextEyeLineStep) { + // unsigned difference is intentional + if (timeNow - _timeNextEyeLineStepStart >= 50u) { _eyeLineY += _eyeLineYDelta; if (_eyeLineYDelta > 0) { if (_eyeLineY >= 396) { @@ -791,16 +812,17 @@ void VK::drawEyeCrosshair(Graphics::Surface &surface, int timeNow) { _eyeLineY = 281; _eyeLineYDelta = -_eyeLineYDelta; _eyeLineSelected = 0; - _timeNextEyeLineStart = timeNow + 1000; + _timeNextEyeLineStart = timeNow; } - _timeNextEyeLineStep = timeNow + 50; + _timeNextEyeLineStepStart = timeNow; } } else { if (_eyeLineXLast != _eyeLineX) { surface.drawLine(_eyeLineXLast, 281, _eyeLineXLast, 396, surface.format.RGBToColor(16, 16, 32)); } _eyeLineXLast = _eyeLineX; - if (timeNow >= _timeNextEyeLineStep) { + // unsigned difference is intentional + if (timeNow - _timeNextEyeLineStepStart >= 50u) { _eyeLineX += _eyeLineXDelta; if ( _eyeLineXDelta > 0) { if (_eyeLineX >= 486) { @@ -811,9 +833,9 @@ void VK::drawEyeCrosshair(Graphics::Surface &surface, int timeNow) { _eyeLineX = 315; _eyeLineXDelta = -_eyeLineXDelta; _eyeLineSelected = 1; - _timeNextEyeLineStart = timeNow + 1000; + _timeNextEyeLineStart = timeNow; } - _timeNextEyeLineStep = timeNow + 50; + _timeNextEyeLineStepStart = timeNow; } } } @@ -914,7 +936,7 @@ void VK::stopAdjustement() { void VK::animateAdjustment(int target) { _adjustmentTarget = MAX(target - 4, 154); _adjustmentDelta = (_adjustmentTarget - _adjustment) / 5; - _timeNextAdjustementStep = _vm->_time->current() + 50; + _timeNextAdjustementStepStart = _vm->_time->current(); } void VK::setAdjustment(int x) { @@ -1040,7 +1062,7 @@ void VK::askQuestion(int intensity) { ) { _isClosing = true; _vm->_mouse->disable(); - _timeClose = _vm->_time->current() + 3000; + _timeCloseStart = _vm->_time->current(); } } diff --git a/engines/bladerunner/ui/vk.h b/engines/bladerunner/ui/vk.h index d0b749363d..eeaee1b54d 100644 --- a/engines/bladerunner/ui/vk.h +++ b/engines/bladerunner/ui/vk.h @@ -55,13 +55,13 @@ class VK { VQAPlayer *_vqaPlayerMain; VQAPlayer *_vqaPlayerEye; - int _vqaFrameMain; + int _vqaFrameMain; bool _vqaLoopEnded; Graphics::Surface _surfaceEye; bool _isOpen; - int _actorId; + int _actorId; bool _calibrationStarted; bool _testStarted; @@ -77,50 +77,52 @@ class VK { int _calibrationRatio; int _calibrationCounter; - int _humanProbability; - int _humanGauge; - int _humanGaugeTarget; - int _humanGaugeDelta; - int _timeNextHumanGaugeStep; - - int _replicantProbability; - int _replicantGauge; - int _replicantGaugeTarget; - int _replicantGaugeDelta; - int _timeNextReplicantGaugeStep; - - int _anxiety; - - int _needleValue; - int _needleValueMax; - int _needleValueTarget; - int _needleValueDelta; - int _timeNextNeedleStep; - int _timeNextNeedleOscillate; - int _timeNeedleReturn; - - bool _isClosing; - int _timeClose; - - int _blinkState; - int _timeNextBlink; - int _timeNextGaugesBlink; - - bool _isAdjusting; - int _adjustment; - int _adjustmentTarget; - int _adjustmentDelta; - int _timeNextAdjustementStep; - - int _eyeLineSelected; - int _eyeLineX; - int _eyeLineXLast; - int _eyeLineY; - int _eyeLineYLast; - int _eyeLineXDelta; - int _eyeLineYDelta; - int _timeNextEyeLineStep; - int _timeNextEyeLineStart; + int _humanProbability; + int _humanGauge; + int _humanGaugeTarget; + int _humanGaugeDelta; + uint32 _timeNextHumanGaugeStepDiff; + uint32 _timeNextHumanGaugeStepStart; + + int _replicantProbability; + int _replicantGauge; + int _replicantGaugeTarget; + int _replicantGaugeDelta; + uint32 _timeNextReplicantGaugeStepDiff; + uint32 _timeNextReplicantGaugeStepStart; + + int _anxiety; + + int _needleValue; + int _needleValueMax; + int _needleValueTarget; + int _needleValueDelta; + uint32 _timeNextNeedleStepStart; + uint32 _timeNextNeedleOscillateStart; + uint32 _timeNeedleReturnStart; + + bool _isClosing; + uint32 _timeCloseStart; + + int _blinkState; + uint32 _timeNextBlinkStart; + uint32 _timeNextGaugesBlinkStart; + + bool _isAdjusting; + int _adjustment; + int _adjustmentTarget; + int _adjustmentDelta; + uint32 _timeNextAdjustementStepStart; + + int _eyeLineSelected; + int _eyeLineX; + int _eyeLineXLast; + int _eyeLineY; + int _eyeLineYLast; + int _eyeLineXDelta; + int _eyeLineYDelta; + uint32 _timeNextEyeLineStepStart; + uint32 _timeNextEyeLineStart; public: VK(BladeRunnerEngine *vm); @@ -154,7 +156,7 @@ private: void drawNeedle(Graphics::Surface &surface); void drawEye(Graphics::Surface &surface); - void drawEyeCrosshair(Graphics::Surface &surface, int timeNow); + void drawEyeCrosshair(Graphics::Surface &surface, uint32 timeNow); void drawMouse(Graphics::Surface &surface); void drawGauge(Graphics::Surface &surface, int value, int x, int y, int width); void drawHumanGauge(Graphics::Surface &surface); |