Permalink
Browse files

BLADERUNNER: Improved time management

This should fix thi issue with freezing actors after loading save game,
but works on new saves only. Game was not paused before saving
and wrong timer value got saved.
  • Loading branch information...
peterkohaut committed Feb 11, 2019
1 parent b14fbaa commit 6854ea3ddd83798a9045307763bbb346d8a1736b
@@ -274,7 +274,9 @@ Common::Error BladeRunnerEngine::saveGameState(int slot, const Common::String &d

BladeRunner::SaveFileManager::writeHeader(*saveFile, header);

_time->pause();
saveGame(*saveFile, thumbnail);
_time->resume();

saveFile->finalize();

@@ -285,6 +287,10 @@ Common::Error BladeRunnerEngine::saveGameState(int slot, const Common::String &d
return Common::kNoError;
}

void BladeRunnerEngine::pauseEngineIntern(bool pause) {
_mixer->pauseAll(pause);
}

Common::Error BladeRunnerEngine::run() {
Graphics::PixelFormat format = createRGB555();
initGraphics(640, 480, &format);
@@ -1113,7 +1119,7 @@ void BladeRunnerEngine::handleKeyUp(Common::Event &event) {
_kia->open(kKIASectionSettings);
break;
case Common::KEYCODE_SPACE:
// TODO: combat::switchCombatMode(&Combat);
_combat->change();
break;
default:
break;
@@ -1122,16 +1128,8 @@ void BladeRunnerEngine::handleKeyUp(Common::Event &event) {

void BladeRunnerEngine::handleKeyDown(Common::Event &event) {
if ((event.kbd.keycode == Common::KEYCODE_d) && (event.kbd.flags & Common::KBD_CTRL)) {
_time->pause();
getDebugger()->attach();
getDebugger()->onFrame();

_time->resume();

if (!_kia->isOpen() && !_spinner->isOpen() && !_elevator->isOpen() && !_esper->isOpen() && !_dialogueMenu->isOpen() && !_scores->isOpen()) {
_scene->resume();
}

return;
}

@@ -1968,32 +1966,12 @@ void BladeRunnerEngine::autoSaveGame(int textId, bool endgame) {
if (slot == -1) {
slot = maxSlot + 1;
}

Common::OutSaveFile *saveFile = BladeRunner::SaveFileManager::openForSaving(getTargetName(), slot);
if (saveFile == nullptr || saveFile->err()) {
delete saveFile;
}

BladeRunner::SaveFileHeader header;
if (endgame) {
header._name = "END_GAME_STATE";
saveGameState(slot, "END_GAME_STATE");
} else {
header._name = textAutoSave.getText(textId);
saveGameState(slot, textAutoSave.getText(textId));
}

BladeRunner::SaveFileManager::writeHeader(*saveFile, header);

Graphics::Surface thumbnail = generateThumbnail();

_time->pause();
saveGame(*saveFile, thumbnail);
_time->resume();

saveFile->finalize();

thumbnail.free();

delete saveFile;
}

void BladeRunnerEngine::ISez(const Common::String &str) {
@@ -236,8 +236,9 @@ class BladeRunnerEngine : public Engine {
Common::Error loadGameState(int slot) override;
bool canSaveGameStateCurrently() override;
Common::Error saveGameState(int slot, const Common::String &desc) override;
void pauseEngineIntern(bool pause) override;

Common::Error run();
Common::Error run() override;

bool startup(bool hasSavegames = false);
void initChapterAndScene();
@@ -42,6 +42,7 @@
#include "bladerunner/set.h"
#include "bladerunner/set_effects.h"
#include "bladerunner/text_resource.h"
#include "bladerunner/time.h"
#include "bladerunner/vector.h"
#include "bladerunner/view.h"
#include "bladerunner/vqa_decoder.h"
@@ -706,15 +707,17 @@ bool Debugger::cmdSave(int argc, const char **argv) {

Graphics::Surface thumbnail = _vm->generateThumbnail();

_vm->_time->pause();
_vm->saveGame(*saveFile, thumbnail);
_vm->_time->resume();

saveFile->finalize();

thumbnail.free();

delete saveFile;

return true;
return false;
}

void Debugger::drawDebuggerOverlay() {
@@ -27,6 +27,7 @@
#include "bladerunner/game_info.h"
#include "bladerunner/slice_animations.h"
#include "bladerunner/slice_renderer.h"
#include "bladerunner/time.h"
#include "bladerunner/zbuffer.h"

namespace BladeRunner {
@@ -56,7 +57,7 @@ void ItemPickup::setup(int animationId, int screenX, int screenY) {
int pan = (150 * _screenX - 48000) / 640;
_vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(335), 80, pan, pan, 50, 0);

_timeLast = _vm->getTotalPlayTime(); // Original game is using system timer
_timeLast = _vm->_time->currentSystem();
}

void ItemPickup::reset() {
@@ -75,7 +76,7 @@ void ItemPickup::tick() {
return;
}

int timeNow = _vm->getTotalPlayTime(); // Original game is using system timer
int timeNow = _vm->_time->currentSystem();
int timeDiff = timeNow - _timeLast;
_timeLast = timeNow;
timeDiff = MIN(MIN(timeDiff, 67), _timeLeft);
@@ -23,6 +23,7 @@
#include "bladerunner/slice_animations.h"

#include "bladerunner/bladerunner.h"
#include "bladerunner/time.h"

#include "common/debug.h"
#include "common/file.h"
@@ -182,7 +183,7 @@ void *SliceAnimations::getFramePtr(uint32 animation, uint32 frame) {
if (!_pages[page]._data)
error("Unable to locate page %d for animation %d frame %d", page, animation, frame);

_pages[page]._lastAccess = _vm->_system->getMillis();
_pages[page]._lastAccess = _vm->_time->currentSystem();

return (byte *)_pages[page]._data + pageOffset;
}
@@ -25,20 +25,25 @@
#include "bladerunner/bladerunner.h"

#include "common/timer.h"
#include "common/system.h"

namespace BladeRunner {

Time::Time(BladeRunnerEngine *vm) {
_vm = vm;

_start = _vm->getTotalPlayTime();
_start = currentSystem();
_pauseCount = 0;
_offset = 0;
_pauseStart = 0;
}

int Time::currentSystem() {
return _vm->getTotalPlayTime();
}

int Time::current() {
int time = _vm->getTotalPlayTime() - _offset;
int time = currentSystem() - _offset;
return time - _start;
}

@@ -38,6 +38,7 @@ class Time {
public:
Time(BladeRunnerEngine *vm);

int currentSystem();
int current();
int pause();
int getPauseStart();
@@ -33,6 +33,7 @@
#include "bladerunner/mouse.h"
#include "bladerunner/music.h"
#include "bladerunner/text_resource.h"
#include "bladerunner/time.h"
#include "bladerunner/ui/end_credits.h"

namespace BladeRunner {
@@ -95,7 +96,7 @@ void EndCredits::show() {
_vm->_vqaStopIsRequested = false;

double position = 0.0;
uint32 timeLast = _vm->getTotalPlayTime(); // Original game is using system timer
uint32 timeLast = _vm->_time->currentSystem();

while (!_vm->_vqaStopIsRequested && !_vm->shouldQuit()) {
if (position >= textPositions[textCount - 1]) {
@@ -106,12 +107,12 @@ void EndCredits::show() {
_vm->handleEvents();

if (!_vm->_windowIsActive) {
timeLast = _vm->getTotalPlayTime(); // Original game is using system timer
timeLast = _vm->_time->currentSystem();

continue;
}

uint32 timeNow = _vm->getTotalPlayTime(); // Original game is using system timer
uint32 timeNow = _vm->_time->currentSystem();
position += (double)(timeNow - timeLast) * 0.05f;
timeLast = timeNow;

@@ -73,14 +73,14 @@ KIA::KIA(BladeRunnerEngine *vm) {
_currentSectionId = kKIASectionNone;
_lastSectionIdKIA = kKIASectionCrimes;
_lastSectionIdOptions = kKIASectionSettings;
_playerVqaTimeLast = _vm->getTotalPlayTime();
_playerVqaTimeLast = _vm->_time->currentSystem();
_playerVqaFrame = 0;
_playerVisualizerState = 0;
_playerPhotographId = -1;
_playerPhotograph = nullptr;
_playerSliceModelId = -1;
_playerSliceModelAngle = 0.0f;
_timeLast = _vm->getTotalPlayTime();
_timeLast = _vm->_time->currentSystem();
_playerActorDialogueQueuePosition = 0;
_playerActorDialogueQueueSize = 0;
_playerActorDialogueState = 0;
@@ -223,7 +223,7 @@ void KIA::tick() {
return;
}

int timeNow = _vm->getTotalPlayTime();
int timeNow = _vm->_time->currentSystem();
int timeDiff = timeNow - _timeLast;

if (_playerActorDialogueQueueSize == _playerActorDialogueQueuePosition) {
@@ -650,8 +650,8 @@ void KIA::init() {

playerReset();
_playerVqaFrame = 0;
_playerVqaTimeLast = _vm->getTotalPlayTime();
_timeLast = _vm->getTotalPlayTime();
_playerVqaTimeLast = _vm->_time->currentSystem();
_timeLast = _vm->_time->currentSystem();

if (_vm->_gameFlags->query(kFlagKIAPrivacyAddon) && !_vm->_gameFlags->query(kFlagKIAPrivacyAddonIntro)) {
_vm->_gameFlags->set(kFlagKIAPrivacyAddonIntro);
@@ -26,6 +26,7 @@
#include "bladerunner/font.h"
#include "bladerunner/game_constants.h"
#include "bladerunner/text_resource.h"
#include "bladerunner/time.h"
#include "bladerunner/ui/kia.h"

namespace BladeRunner {
@@ -45,15 +46,15 @@ void KIASectionDiagnostic::open() {
}
_vm->_kia->playActorDialogue(kActorRunciter, 140);
_offset = 0;
_timeLast = _vm->getTotalPlayTime();
_timeLast = _vm->_time->currentSystem();
}

void KIASectionDiagnostic::close() {
delete _text;
}

void KIASectionDiagnostic::draw(Graphics::Surface &surface) {
int timeNow = _vm->getTotalPlayTime();
int timeNow = _vm->_time->currentSystem();

for (int i = 0; i < _text->getCount(); ++i) {
int y = kLineHeight * i + 366 - _offset;
@@ -27,6 +27,7 @@
#include "bladerunner/game_info.h"
#include "bladerunner/savefile.h"
#include "bladerunner/text_resource.h"
#include "bladerunner/time.h"
#include "bladerunner/ui/kia.h"
#include "bladerunner/ui/kia_shapes.h"
#include "bladerunner/ui/ui_container.h"
@@ -74,7 +75,7 @@ void KIASectionLoad::open() {
_scrollBox->addLine(_vm->_textOptions->getText(29), _newGameHardLineId, 0); // Hard

_hoveredLineId = -1;
_timeLast = _vm->getTotalPlayTime(); // Original game is using system timer
_timeLast = _vm->_time->currentSystem();
_timeLeft = 800;
}

@@ -108,7 +109,7 @@ void KIASectionLoad::draw(Graphics::Surface &surface){
_hoveredLineId = selectedLineId;
}

uint32 now = _vm->getTotalPlayTime(); // Original game is using system timer
uint32 now = _vm->_time->currentSystem();
if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size()) {
if (_timeLeft) {
uint32 timeDiff = now - _timeLast;
@@ -27,6 +27,7 @@
#include "bladerunner/font.h"
#include "bladerunner/game_info.h"
#include "bladerunner/text_resource.h"
#include "bladerunner/time.h"

namespace BladeRunner {

@@ -225,14 +226,14 @@ void KIASectionPogo::open() {
_lineOffsets[i] = 0;
}

_timeLast = _vm->getTotalPlayTime();
_timeLast = _vm->_time->currentSystem();

_vm->_audioPlayer->playAud(_vm->_gameInfo->getSfxTrack(319), 100, 0, 0, 50, 0);
}

void KIASectionPogo::draw(Graphics::Surface &surface) {
// Timing fixed for 60Hz by ScummVM team
int timeNow = _vm->getTotalPlayTime();
int timeNow = _vm->_time->currentSystem();
bool updateTimeout = false;
if (timeNow - _timeLast > 1000 / 60) {
updateTimeout = true;
@@ -28,6 +28,7 @@
#include "bladerunner/game_info.h"
#include "bladerunner/savefile.h"
#include "bladerunner/text_resource.h"
#include "bladerunner/time.h"
#include "bladerunner/ui/kia.h"
#include "bladerunner/ui/kia_shapes.h"
#include "bladerunner/ui/ui_container.h"
@@ -121,7 +122,7 @@ void KIASectionSave::open() {
}

_hoveredLineId = -1;
_timeLast = _vm->getTotalPlayTime(); // Original game is using system timer
_timeLast = _vm->_time->currentSystem();
_timeLeft = 800;
}

@@ -191,7 +192,7 @@ void KIASectionSave::draw(Graphics::Surface &surface){
_hoveredLineId = selectedLineId;
}

uint32 now = _vm->getTotalPlayTime(); // Original game is using system timer
uint32 now = _vm->_time->currentSystem();
if (selectedLineId >= 0 && selectedLineId < (int)_saveList.size()) {
if (_timeLeft) {
uint32 timeDiff = now - _timeLast;
@@ -25,6 +25,7 @@
#include "bladerunner/audio_player.h"
#include "bladerunner/bladerunner.h"
#include "bladerunner/game_info.h"
#include "bladerunner/time.h"
#include "bladerunner/ui/kia.h"
#include "bladerunner/ui/kia_shapes.h"

@@ -47,7 +48,7 @@ UICheckBox::UICheckBox(BladeRunnerEngine *vm, UIComponentCallback *valueChangedC
_frame = 0;
}

_timeLast = _vm->getTotalPlayTime(); // Original game is using system timer
_timeLast = _vm->_time->currentSystem();
_rect = rect;
_isChecked = isChecked;
}
@@ -56,7 +57,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(); // Original game is using system timer
uint timeNow = _vm->_time->currentSystem();
if (timeNow - _timeLast > 67) {
int frameDelta = (timeNow - _timeLast) / 67u;
_timeLast = timeNow;
Oops, something went wrong.

0 comments on commit 6854ea3

Please sign in to comment.