diff options
author | Thanasis Antoniou | 2019-07-17 19:08:43 +0300 |
---|---|---|
committer | Thanasis Antoniou | 2019-07-17 19:09:15 +0300 |
commit | caa4578add35021bfbb00b5f81359592402096a3 (patch) | |
tree | 2133b0dd3f4e71324bafc1ca65699ba79483e512 /engines/bladerunner/ui | |
parent | d1ff73cbb381db1876e2dbdf0457c9efc76fcd1a (diff) | |
download | scummvm-rg350-caa4578add35021bfbb00b5f81359592402096a3.tar.gz scummvm-rg350-caa4578add35021bfbb00b5f81359592402096a3.tar.bz2 scummvm-rg350-caa4578add35021bfbb00b5f81359592402096a3.zip |
BLADERUNNER: Use unsigned 32bit diff for time durations
Diffstat (limited to 'engines/bladerunner/ui')
24 files changed, 363 insertions, 304 deletions
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..7ad73ceea2 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(_playerVisualizerState - timeDiffDiv48, 0u); } } else { if (_playerVisualizerState < 2) { - _playerVisualizerState = MIN(_playerVisualizerState + timeDiffDiv48, 2); + _playerVisualizerState = MIN(_playerVisualizerState + timeDiffDiv48, 2u); } } if ( _playerSliceModelId != -1 || _playerPhotographId != -1 || _playerImage.getPixels() != nullptr) { if (_playerVqaFrame < 8) { - int newVqaFrame = MIN(timeDiffDiv48 + _playerVqaFrame, 8); + int newVqaFrame = MIN(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(_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..935c53f98a 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(_frame + frameDelta, 5u); } else { - _frame = MAX(_frame - frameDelta, 0); + _frame = (_frame < frameDelta) ? 0 : MAX(_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); |