From 2f242a10daee5d95510c43f686f83e3bfb9e3f50 Mon Sep 17 00:00:00 2001 From: Peter Kohaut Date: Sat, 15 Dec 2018 22:40:07 +0100 Subject: BLADERUNNER: Added time control and game pausing --- engines/bladerunner/ui/elevator.cpp | 9 +++++---- engines/bladerunner/ui/end_credits.cpp | 6 +++--- engines/bladerunner/ui/esper.cpp | 29 ++++++++++++++++------------- engines/bladerunner/ui/kia.cpp | 5 +++-- engines/bladerunner/ui/kia_section_load.cpp | 4 ++-- engines/bladerunner/ui/kia_section_save.cpp | 4 ++-- engines/bladerunner/ui/scores.cpp | 3 ++- engines/bladerunner/ui/ui_check_box.cpp | 4 ++-- engines/bladerunner/ui/ui_image_picker.cpp | 10 ++++++++-- engines/bladerunner/ui/ui_image_picker.h | 2 +- engines/bladerunner/ui/ui_input_box.cpp | 4 ++-- engines/bladerunner/ui/ui_scroll_box.cpp | 12 ++++++------ engines/bladerunner/ui/vk.cpp | 17 +++++++++-------- 13 files changed, 61 insertions(+), 48 deletions(-) (limited to 'engines/bladerunner/ui') diff --git a/engines/bladerunner/ui/elevator.cpp b/engines/bladerunner/ui/elevator.cpp index c7432368f2..64164f442d 100644 --- a/engines/bladerunner/ui/elevator.cpp +++ b/engines/bladerunner/ui/elevator.cpp @@ -29,6 +29,7 @@ #include "bladerunner/mouse.h" #include "bladerunner/shape.h" #include "bladerunner/script/script.h" +#include "bladerunner/time.h" #include "bladerunner/ui/ui_image_picker.h" #include "bladerunner/vqa_player.h" @@ -156,7 +157,7 @@ int Elevator::activate(int elevatorId) { open(); - // TODO: time->lock(); + _vm->_time->pause(); _buttonClicked = -1; do { @@ -177,7 +178,7 @@ int Elevator::activate(int elevatorId) { _isOpen = false; - // TODO: time->unlock(); + _vm->_time->resume(); return _buttonClicked; } @@ -281,7 +282,7 @@ void Elevator::setupDescription(int actorId, int sentenceId) { _sentenceId = sentenceId; // TODO: Use proper timer - _timeSpeakDescription = _vm->getTotalPlayTime() + 600; + _timeSpeakDescription = _vm->_time->current() + 600; } void Elevator::resetDescription() { @@ -291,7 +292,7 @@ void Elevator::resetDescription() { } void Elevator::tickDescription() { - int now = _vm->getTotalPlayTime(); + int now = _vm->_time->current(); if (_actorId <= 0 || now < _timeSpeakDescription) { return; } diff --git a/engines/bladerunner/ui/end_credits.cpp b/engines/bladerunner/ui/end_credits.cpp index 6d964d0290..096f8988bb 100644 --- a/engines/bladerunner/ui/end_credits.cpp +++ b/engines/bladerunner/ui/end_credits.cpp @@ -95,7 +95,7 @@ void EndCredits::show() { _vm->_vqaStopIsRequested = false; double position = 0.0; - uint32 timeLast = _vm->getTotalPlayTime(); + uint32 timeLast = _vm->getTotalPlayTime(); // Original game is using system timer while (!_vm->_vqaStopIsRequested && !_vm->shouldQuit()) { if (position >= textPositions[textCount - 1]) { @@ -106,12 +106,12 @@ void EndCredits::show() { _vm->handleEvents(); if (!_vm->_gameIsRunning) { - timeLast = _vm->getTotalPlayTime(); + timeLast = _vm->getTotalPlayTime(); // Original game is using system timer continue; } - uint32 timeNow = _vm->getTotalPlayTime(); + uint32 timeNow = _vm->getTotalPlayTime(); // Original game is using system timer position += (double)(timeNow - timeLast) * 0.05f; timeLast = timeNow; diff --git a/engines/bladerunner/ui/esper.cpp b/engines/bladerunner/ui/esper.cpp index 6803ce5c5c..51c64f6bc9 100644 --- a/engines/bladerunner/ui/esper.cpp +++ b/engines/bladerunner/ui/esper.cpp @@ -35,6 +35,7 @@ #include "bladerunner/shape.h" #include "bladerunner/script/esper_script.h" #include "bladerunner/text_resource.h" +#include "bladerunner/time.h" #include "bladerunner/ui/ui_image_picker.h" #include "bladerunner/vqa_player.h" @@ -82,7 +83,8 @@ void ESPER::open(Graphics::Surface *surface) { _vm->_mouse->enable(); } - //TODO: time->lock() + _vm->_time->pause(); + _ambientVolume = _vm->_ambientSounds->getVolume(); _vm->_ambientSounds->setVolume(_ambientVolume / 2); @@ -151,7 +153,8 @@ void ESPER::close() { _vm->closeArchive("MODE.MIX"); - //TODO: time->unlock() + _vm->_time->resume(); + _vm->_ambientSounds->setVolume(_ambientVolume); _vm->_scene->resume(); reset(); @@ -533,8 +536,8 @@ void ESPER::setStatePhoto(EsperPhotoStates state) { void ESPER::wait(int timeout) { if (!_isWaiting) { _isWaiting = true; - uint timeEnd = timeout + _vm->getTotalPlayTime(); - while (_vm->_gameIsRunning && _vm->getTotalPlayTime() < timeEnd) { + int timeEnd = timeout + _vm->_time->current(); + while (_vm->_gameIsRunning && (_vm->_time->current() < timeEnd)) { _vm->gameTick(); } _isWaiting = false; @@ -652,7 +655,7 @@ void ESPER::draw(Graphics::Surface &surface) { void ESPER::drawPhotoOpening(Graphics::Surface &surface) { bool needMoreZooming = true; - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if (timeNow >= _timePhotoOpeningNext) { _photoOpeningWidth = MIN(_photoOpeningWidth + 8, _screen.right - 1); _photoOpeningHeight = MIN(_photoOpeningHeight + 7, _screen.bottom - 1); @@ -682,7 +685,7 @@ void ESPER::drawPhotoOpening(Graphics::Surface &surface) { bool ESPER::drawSelectionZooming(Graphics::Surface &surface) { bool zooming = false; bool needMoreZooming = true; - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if (timeNow > _timeSelectionZoomNext) { zooming = true; _selection.left += _selectionDelta.left; @@ -713,7 +716,7 @@ bool ESPER::drawSelectionZooming(Graphics::Surface &surface) { bool ESPER::drawSelectionBlinking(Graphics::Surface &surface) { bool needMoreBlinking = true; - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if (timeNow > _timeSelectionBlinkingNext) { _timeSelectionBlinkingNext = timeNow + 100; _selectionBlinkingStyle ^= 1; @@ -731,7 +734,7 @@ bool ESPER::drawSelectionBlinking(Graphics::Surface &surface) { } void ESPER::drawPhotoZooming(Graphics::Surface &surface) { - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if ((timeNow > _timeZoomNext) && (_zoomStep < _zoomSteps)) { _flash = true; @@ -799,7 +802,7 @@ void ESPER::drawPhotoZooming(Graphics::Surface &surface) { } void ESPER::drawPhotoSharpening(Graphics::Surface &surface) { - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); bool needMoreSharpening = true; if (timeNow >= _timePhotoOpeningNext) { _photoOpeningWidth = MIN(_photoOpeningWidth + 8, _screen.right - 1); @@ -840,7 +843,7 @@ void ESPER::drawPhotoSharpening(Graphics::Surface &surface) { } void ESPER::drawPhotoZoomOut(Graphics::Surface &surface) { - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if (timeNow >= _timeZoomOutNext) { _timeZoomOutNext = timeNow + 300; @@ -882,7 +885,7 @@ void ESPER::drawVideoZooming(Graphics::Surface &surface) { bool flash = false; bool advanceFrame = false; - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if (timeNow > _timeZoomNext) { _timeZoomNext = timeNow + 300; playSound(419, 25); @@ -907,7 +910,7 @@ void ESPER::drawVideoZooming(Graphics::Surface &surface) { void ESPER::drawVideoZoomOut(Graphics::Surface &surface) { bool flash = false; bool advanceFrame = false; - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if (timeNow > _timeZoomNext && _vqaLastFrame > 0) { _timeZoomNext = timeNow + 300; playSound(419, 25); @@ -1379,7 +1382,7 @@ void ESPER::tickSound() { } void ESPER::tickScroll() { - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if (timeNow <= _timeScrollNext) { return; } diff --git a/engines/bladerunner/ui/kia.cpp b/engines/bladerunner/ui/kia.cpp index 6bea198b7c..bd0402847b 100644 --- a/engines/bladerunner/ui/kia.cpp +++ b/engines/bladerunner/ui/kia.cpp @@ -38,6 +38,7 @@ #include "bladerunner/settings.h" #include "bladerunner/slice_renderer.h" #include "bladerunner/text_resource.h" +#include "bladerunner/time.h" #include "bladerunner/ui/kia_log.h" #include "bladerunner/ui/kia_section_base.h" #include "bladerunner/ui/kia_section_clues.h" @@ -665,7 +666,7 @@ void KIA::init() { } _vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(501), 70, 0, 0, 50, 0); - // TODO: time->lock(); + _vm->_time->pause(); } void KIA::unload() { @@ -703,7 +704,7 @@ void KIA::unload() { _currentSectionId = kKIASectionNone; - // TODO: Unfreeze game time + _vm->_time->resume(); if (!_vm->_settings->isLoadingGame() && _vm->_gameIsRunning) { _vm->_scene->resume(); diff --git a/engines/bladerunner/ui/kia_section_load.cpp b/engines/bladerunner/ui/kia_section_load.cpp index bbc3c74c68..bada5a1415 100644 --- a/engines/bladerunner/ui/kia_section_load.cpp +++ b/engines/bladerunner/ui/kia_section_load.cpp @@ -74,7 +74,7 @@ void KIASectionLoad::open() { _scrollBox->addLine(_vm->_textOptions->getText(29), _newGameHardLineId, 0); // Hard _hoveredLineId = -1; - _timeLast = _vm->getTotalPlayTime(); + _timeLast = _vm->getTotalPlayTime(); // Original game is using system timer _timeLeft = 800; } @@ -108,7 +108,7 @@ void KIASectionLoad::draw(Graphics::Surface &surface){ _hoveredLineId = selectedLineId; } - uint32 now = _vm->getTotalPlayTime(); + uint32 now = _vm->getTotalPlayTime(); // Original game is using system timer if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size()) { if (_timeLeft) { uint32 timeDiff = now - _timeLast; diff --git a/engines/bladerunner/ui/kia_section_save.cpp b/engines/bladerunner/ui/kia_section_save.cpp index 997cb75778..b042dc8097 100644 --- a/engines/bladerunner/ui/kia_section_save.cpp +++ b/engines/bladerunner/ui/kia_section_save.cpp @@ -121,7 +121,7 @@ void KIASectionSave::open() { } _hoveredLineId = -1; - _timeLast = _vm->getTotalPlayTime(); + _timeLast = _vm->getTotalPlayTime(); // Original game is using system timer _timeLeft = 800; } @@ -191,7 +191,7 @@ void KIASectionSave::draw(Graphics::Surface &surface){ _hoveredLineId = selectedLineId; } - uint32 now = _vm->getTotalPlayTime(); + uint32 now = _vm->getTotalPlayTime(); // Original game is using system timer if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size()) { if (_timeLeft) { uint32 timeDiff = now - _timeLast; diff --git a/engines/bladerunner/ui/scores.cpp b/engines/bladerunner/ui/scores.cpp index 8fc3378207..3879d81c4e 100644 --- a/engines/bladerunner/ui/scores.cpp +++ b/engines/bladerunner/ui/scores.cpp @@ -27,6 +27,7 @@ #include "bladerunner/savefile.h" #include "bladerunner/scene.h" #include "bladerunner/text_resource.h" +#include "bladerunner/time.h" #include "bladerunner/vqa_player.h" #include "common/keyboard.h" @@ -58,7 +59,7 @@ void Scores::open() { _vqaPlayer->setLoop(1, -1, 0, nullptr, nullptr); - // TODO: Freeze game time + _vm->_time->pause(); _txtScorers = new TextResource(_vm); _txtScorers->open("SCORERS"); diff --git a/engines/bladerunner/ui/ui_check_box.cpp b/engines/bladerunner/ui/ui_check_box.cpp index 39e120e883..631b9ba942 100644 --- a/engines/bladerunner/ui/ui_check_box.cpp +++ b/engines/bladerunner/ui/ui_check_box.cpp @@ -47,7 +47,7 @@ UICheckBox::UICheckBox(BladeRunnerEngine *vm, UIComponentCallback *valueChangedC _frame = 0; } - _timeLast = _vm->getTotalPlayTime(); + _timeLast = _vm->getTotalPlayTime(); // Original game is using system timer _rect = rect; _isChecked = isChecked; } @@ -56,7 +56,7 @@ UICheckBox::UICheckBox(BladeRunnerEngine *vm, UIComponentCallback *valueChangedC void UICheckBox::draw(Graphics::Surface &surface) { int shapeId; if (_rect.right > _rect.left && _rect.bottom > _rect.top) { - uint timeNow = _vm->getTotalPlayTime(); + uint timeNow = _vm->getTotalPlayTime(); // Original game is using system timer if (timeNow - _timeLast > 67) { int frameDelta = (timeNow - _timeLast) / 67u; _timeLast = timeNow; diff --git a/engines/bladerunner/ui/ui_image_picker.cpp b/engines/bladerunner/ui/ui_image_picker.cpp index 0e00bf0484..7055fe31d6 100644 --- a/engines/bladerunner/ui/ui_image_picker.cpp +++ b/engines/bladerunner/ui/ui_image_picker.cpp @@ -27,6 +27,7 @@ #include "bladerunner/font.h" #include "bladerunner/mouse.h" #include "bladerunner/shape.h" +#include "bladerunner/time.h" #include "common/rect.h" #include "common/str.h" @@ -226,7 +227,12 @@ void UIImagePicker::drawTooltip(Graphics::Surface &surface, int x, int y) { return; } - if (_hoveredImageIndex == -1 || _vm->_mouse->isDisabled() || !_images[_hoveredImageIndex].active || _vm->getTotalPlayTime() < _hoverStartTimestamp + 1000) { + if ( + (_hoveredImageIndex == -1) || + (_vm->_mouse->isDisabled()) || + (!_images[_hoveredImageIndex].active) || + (_vm->_time->current() < _hoverStartTimestamp + 1000) + ) { return; } @@ -293,7 +299,7 @@ bool UIImagePicker::handleMouseAction(int x, int y, bool down, bool up, bool ign } } } - _hoverStartTimestamp = _vm->getTotalPlayTime(); + _hoverStartTimestamp = _vm->_time->current(); _hoveredImageIndex = hoveredImageIndex; } diff --git a/engines/bladerunner/ui/ui_image_picker.h b/engines/bladerunner/ui/ui_image_picker.h index d5b18b2f0a..3d62192454 100644 --- a/engines/bladerunner/ui/ui_image_picker.h +++ b/engines/bladerunner/ui/ui_image_picker.h @@ -54,7 +54,7 @@ class UIImagePicker { int _imageCount; int _hoveredImageIndex; int _pressedImageIndex; - uint32 _hoverStartTimestamp; + int _hoverStartTimestamp; int _isButtonDown; Common::Array _images; diff --git a/engines/bladerunner/ui/ui_input_box.cpp b/engines/bladerunner/ui/ui_input_box.cpp index 466238f8d3..6b9388c767 100644 --- a/engines/bladerunner/ui/ui_input_box.cpp +++ b/engines/bladerunner/ui/ui_input_box.cpp @@ -43,7 +43,7 @@ UIInputBox::UIInputBox(BladeRunnerEngine *vm, UIComponentCallback *valueChangedC setText(text); _cursorIsVisible = false; - _timeLast = _vm->getTotalPlayTime(); + _timeLast = _vm->getTotalPlayTime(); // Original game is using system timer } void UIInputBox::draw(Graphics::Surface &surface) { @@ -60,7 +60,7 @@ void UIInputBox::draw(Graphics::Surface &surface) { surface.vLine(textHalfWidth + rectHalfWidth + 2, _rect.top, _rect.bottom - 1, 0x7FDD); // 11111 11110 11101 } - if (_vm->getTotalPlayTime() - _timeLast > 500) { + if (_vm->getTotalPlayTime() - _timeLast > 500) { // Original game is using system timer _timeLast = _vm->getTotalPlayTime(); _cursorIsVisible = !_cursorIsVisible; } diff --git a/engines/bladerunner/ui/ui_scroll_box.cpp b/engines/bladerunner/ui/ui_scroll_box.cpp index a030e534c5..d39e580cd3 100644 --- a/engines/bladerunner/ui/ui_scroll_box.cpp +++ b/engines/bladerunner/ui/ui_scroll_box.cpp @@ -62,7 +62,7 @@ UIScrollBox::UIScrollBox(BladeRunnerEngine *vm, UIScrollBoxCallback *lineSelecte _isVisible = false; _style = style; _center = center; - _timeLastScroll = _vm->getTotalPlayTime(); + _timeLastScroll = _vm->getTotalPlayTime(); // Original game is using system timer _timeLastCheckbox = _vm->getTotalPlayTime(); _timeLastHighlight = _vm->getTotalPlayTime(); @@ -113,7 +113,7 @@ void UIScrollBox::show() { _scrollAreaDownHover = false; _scrollBarHover = false; - _timeLastScroll = _vm->getTotalPlayTime(); + _timeLastScroll = _vm->getTotalPlayTime(); // Original game is using system timer _timeLastCheckbox = _vm->getTotalPlayTime(); _timeLastHighlight = _vm->getTotalPlayTime(); @@ -267,7 +267,7 @@ void UIScrollBox::handleMouseDown(bool alternateButton) { if (!alternateButton) { if (_scrollUpButtonHover) { _scrollUpButtonState = 2; - _timeLastScroll = _vm->getTotalPlayTime() - 160; + _timeLastScroll = _vm->getTotalPlayTime() - 160; // Original game is using system timer } else { _scrollUpButtonState = 1; } @@ -283,13 +283,13 @@ void UIScrollBox::handleMouseDown(bool alternateButton) { } if (_scrollAreaUpHover) { _scrollAreaUpState = 2; - _timeLastScroll = _vm->getTotalPlayTime() - 160; + _timeLastScroll = _vm->getTotalPlayTime() - 160; // Original game is using system timer } else { _scrollAreaUpState = 1; } if (_scrollAreaDownHover) { _scrollAreaDownState = 2; - _timeLastScroll = _vm->getTotalPlayTime() - 160; + _timeLastScroll = _vm->getTotalPlayTime() - 160; // Original game is using system timer } else { _scrollAreaDownState = 1; } @@ -321,7 +321,7 @@ int UIScrollBox::getSelectedLineData() { } void UIScrollBox::draw(Graphics::Surface &surface) { - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->getTotalPlayTime(); // Original game is using system timer // update scrolling if (_scrollUpButtonState == 2 && _scrollUpButtonHover) { diff --git a/engines/bladerunner/ui/vk.cpp b/engines/bladerunner/ui/vk.cpp index ae776b7e55..aa95b6bf9c 100644 --- a/engines/bladerunner/ui/vk.cpp +++ b/engines/bladerunner/ui/vk.cpp @@ -38,6 +38,7 @@ #include "bladerunner/script/vk_script.h" #include "bladerunner/slice_renderer.h" #include "bladerunner/text_resource.h" +#include "bladerunner/time.h" #include "bladerunner/ui/ui_image_picker.h" #include "bladerunner/vqa_player.h" @@ -198,7 +199,7 @@ void VK::tick() { _vm->blitToScreen(_vm->_surfaceFront); _vm->_system->delayMillis(10); - if (_isClosing && (int)_vm->getTotalPlayTime() >= _timeClose && !_script->isInsideScript()) { + if (_isClosing && _vm->_time->current() >= _timeClose && !_script->isInsideScript()) { close(); _vm->_mouse->enable(); reset(); @@ -250,8 +251,8 @@ void VK::playSpeechLine(int actorId, int sentenceId, float duration) { } if (duration > 0.0f && !_vm->_speechSkipped) { - int timeEnd = duration * 1000.0f + _vm->getTotalPlayTime(); - while (timeEnd > (int)_vm->getTotalPlayTime() && _vm->_gameIsRunning) { + int timeEnd = duration * 1000.0f + _vm->_time->current(); + while ((timeEnd > _vm->_time->current()) && _vm->_gameIsRunning) { _vm->gameTick(); } } @@ -265,7 +266,7 @@ void VK::subjectReacts(int intensity, int humanResponse, int replicantResponse, humanResponse = CLIP(humanResponse, -20, 20); replicantResponse = CLIP(replicantResponse, -20, 20); - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if (intensity > 0) { _needleValueTarget = 78 * intensity / 100; @@ -509,7 +510,7 @@ void VK::draw() { Graphics::Surface &surface = _vm->_surfaceFront; - int timeNow = _vm->getTotalPlayTime(); + int timeNow = _vm->_time->current(); if (_isAdjusting && !_testStarted && !_vm->isMouseButtonDown()) { _isAdjusting = false; @@ -670,7 +671,7 @@ void VK::draw() { void VK::drawNeedle(Graphics::Surface &surface) { int x = _needleValue + 165; - if ((int)_vm->getTotalPlayTime() >= _timeNextNeedleOscillate && x > 165) { + if ((_vm->_time->current() >= _timeNextNeedleOscillate) && (x > 165)) { x = CLIP(x + (int)_vm->_rnd.getRandomNumberRng(0, 4) - 2, 165, 245); } @@ -851,7 +852,7 @@ void VK::stopAdjustement() { void VK::animateAdjustment(int target) { _adjustmentTarget = MAX(target - 4, 154); _adjustmentDelta = (_adjustmentTarget - _adjustment) / 5; - _timeNextAdjustementStep = _vm->getTotalPlayTime() + 50; + _timeNextAdjustementStep = _vm->_time->current() + 50; } void VK::setAdjustment(int x) { @@ -920,7 +921,7 @@ void VK::askQuestion(int intensity) { } else if (!_isClosing && !_script->isInsideScript()) { _isClosing = true; _vm->_mouse->disable(); - _timeClose = _vm->getTotalPlayTime() + 3000; + _timeClose = _vm->_time->current() + 3000; } } -- cgit v1.2.3