Skip to content

Commit

Permalink
ACCESS: Separate timer updates from frame updates, and overall delay …
Browse files Browse the repository at this point in the history
…cleanup
  • Loading branch information
dreammaster committed Dec 13, 2014
1 parent 781c6ff commit 547f3de
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 40 deletions.
4 changes: 1 addition & 3 deletions engines/access/access.cpp
Expand Up @@ -410,9 +410,7 @@ void AccessEngine::playVideo(int videoNum, const Common::Point &pt) {

while (!shouldQuit() && !_video->_videoEnd) {
_video->playVideo();

g_system->delayMillis(10);
_events->pollEvents();
_events->pollEventsAndWait();
}
}

Expand Down
6 changes: 2 additions & 4 deletions engines/access/amazon/amazon_game.cpp
Expand Up @@ -535,8 +535,7 @@ void AmazonEngine::startChapter(int chapter) {

// Wait loop
while (!shouldQuit() && !_events->isKeyMousePressed() && _timers[20]._flag) {
_events->pollEvents();
g_system->delayMillis(10);
_events->pollEventsAndWait();
}
}

Expand Down Expand Up @@ -576,8 +575,7 @@ void AmazonEngine::startChapter(int chapter) {

// Wait loop
while (!shouldQuit() && !_events->isKeyMousePressed() && _timers[20]._flag) {
_events->pollEvents();
g_system->delayMillis(10);
_events->pollEventsAndWait();
}
if (shouldQuit())
return;
Expand Down
3 changes: 0 additions & 3 deletions engines/access/amazon/amazon_logic.cpp
Expand Up @@ -687,10 +687,7 @@ void Plane::mWhileFly() {
++_pCount;

while (!_vm->shouldQuit() && events._vbCount > 0) {
// To be rewritten when NEWTIMER is done
events.checkForNextFrameCounter();
_vm->_sound->playSound(0);

events.pollEventsAndWait();
}
}
Expand Down
34 changes: 24 additions & 10 deletions engines/access/events.cpp
Expand Up @@ -47,6 +47,7 @@ EventsManager::EventsManager(AccessEngine *vm): _vm(vm) {
_cursorExitFlag = false;
_vbCount = 0;
_keyCode = Common::KEYCODE_INVALID;
_priorTimerTime = 0;
}

EventsManager::~EventsManager() {
Expand Down Expand Up @@ -124,9 +125,12 @@ bool EventsManager::isCursorVisible() {

void EventsManager::pollEvents(bool skipTimers) {
if (checkForNextFrameCounter()) {
nextFrame(skipTimers);
nextFrame();
}

if (checkForNextTimerUpdate() && !skipTimers)
nextTimer();

_wheelUp = _wheelDown = false;

Common::Event event;
Expand Down Expand Up @@ -233,7 +237,7 @@ void EventsManager::keyControl(Common::KeyCode keycode, bool isKeyDown) {

void EventsManager::pollEventsAndWait() {
pollEvents();
g_system->delayMillis(10);
delay();
}

bool EventsManager::checkForNextFrameCounter() {
Expand All @@ -250,20 +254,31 @@ bool EventsManager::checkForNextFrameCounter() {
return false;
}

void EventsManager::nextFrame(bool skipTimers) {
if (!skipTimers) {
// Update timers
_vm->_animation->updateTimers();
_vm->_timers.updateTimers();
bool EventsManager::checkForNextTimerUpdate() {
// Check for next timer update
uint32 milli = g_system->getMillis();
if ((milli - _priorTimerTime) >= GAME_TIMER_TIME) {
_priorTimerTime = milli;

return true;
}

return false;
}

void EventsManager::nextFrame() {
// Give time to the debugger
_vm->_debugger->onFrame();

// TODO: Refactor for dirty rects
_vm->_screen->updateScreen();
}

void EventsManager::nextTimer() {
_vm->_animation->updateTimers();
_vm->_timers.updateTimers();
}

void EventsManager::delay(int time) {
g_system->delayMillis(time);
}
Expand All @@ -288,8 +303,7 @@ bool EventsManager::isKeyPending() const {

void EventsManager::debounceLeft() {
while (_leftButton && !_vm->shouldQuit()) {
pollEvents();
g_system->delayMillis(10);
pollEventsAndWait();
}
}

Expand All @@ -301,7 +315,7 @@ void EventsManager::clearEvents() {
void EventsManager::waitKeyMouse() {
while (!_vm->shouldQuit() && !isKeyMousePressed()) {
pollEvents(true);
g_system->delayMillis(10);
delay();
}
}

Expand Down
11 changes: 7 additions & 4 deletions engines/access/events.h
Expand Up @@ -38,6 +38,7 @@ enum CursorType {

#define GAME_FRAME_RATE 100
#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE)
#define GAME_TIMER_TIME 15

class AccessEngine;

Expand All @@ -46,10 +47,14 @@ class EventsManager {
AccessEngine *_vm;
uint32 _frameCounter;
uint32 _priorFrameTime;
uint32 _priorTimerTime;
Common::KeyCode _keyCode;

Graphics::Surface _invCursor;
void nextFrame(bool skipTimers);
bool checkForNextFrameCounter();
bool checkForNextTimerUpdate();
void nextFrame();
void nextTimer();
void keyControl(Common::KeyCode keycode, bool isKeyDown);
public:
CursorType _cursorId;
Expand Down Expand Up @@ -117,16 +122,14 @@ class EventsManager {

bool isKeyPending() const;

void delay(int time);
void delay(int time = 5);

void debounceLeft();

void clearEvents();

void waitKeyMouse();

bool checkForNextFrameCounter();

Common::Point &getMousePos() { return _mousePos; }

Common::Point calcRawMouse();
Expand Down
9 changes: 3 additions & 6 deletions engines/access/inventory.cpp
Expand Up @@ -321,8 +321,7 @@ void InventoryManager::chooseItem() {

while (!_vm->shouldQuit()) {
// Check for events
events.pollEvents();
g_system->delayMillis(10);
events.pollEventsAndWait();

int selIndex;
// Poll events and wait for a click on a known area
Expand Down Expand Up @@ -414,8 +413,7 @@ void InventoryManager::combineItems() {
// Item drag handling loop if left button is held down
while (!_vm->shouldQuit() && events._leftButton) {
// Poll for events
events.pollEvents();
g_system->delayMillis(10);
events.pollEventsAndWait();

// Check positioning
if (lastMouse == events._mousePos)
Expand Down Expand Up @@ -485,8 +483,7 @@ void InventoryManager::zoomIcon(int zoomItem, int backItem, int zoomBox, bool sh
_invCoords[zoomBox].left + 46, _invCoords[zoomBox].top + 35);

while (!_vm->shouldQuit() && zoomScale != 0 && zoomScale != 256) {
_vm->_events->pollEvents();
g_system->delayMillis(5);
_vm->_events->pollEventsAndWait();

_vm->_buffer2.copyBlock(&_vm->_buffer1, boxRect);
if (backItem != -1) {
Expand Down
3 changes: 1 addition & 2 deletions engines/access/room.cpp
Expand Up @@ -81,9 +81,8 @@ void Room::doRoom() {

// Poll for events
_vm->_canSaveLoad = true;
_vm->_events->pollEvents();
_vm->_events->pollEventsAndWait();
_vm->_canSaveLoad = false;
g_system->delayMillis(5);

_vm->_player->walk();
_vm->_midi->midiRepeat();
Expand Down
4 changes: 2 additions & 2 deletions engines/access/screen.cpp
Expand Up @@ -158,7 +158,7 @@ void Screen::forceFadeOut() {
}

updatePalette();
g_system->delayMillis(10);
_vm->_events->pollEventsAndWait();
} while (repeatFlag && !_vm->shouldQuit());
}

Expand All @@ -180,7 +180,7 @@ void Screen::forceFadeIn() {
}

updatePalette();
g_system->delayMillis(10);
_vm->_events->pollEventsAndWait();
} while (repeatFlag);
}

Expand Down
9 changes: 3 additions & 6 deletions engines/access/scripts.cpp
Expand Up @@ -521,12 +521,11 @@ void Scripts::cmdSaveRect() {
}

void Scripts::cmdVideoEnded() {
_vm->_events->pollEvents();
_vm->_events->pollEventsAndWait();

if (_vm->_video->_videoEnd) {
cmdGoto();
} else {
g_system->delayMillis(10);
_data->skip(2);
}
}
Expand Down Expand Up @@ -731,8 +730,7 @@ void Scripts::cmdWait() {
_vm->_midi->midiRepeat();
charLoop();

_vm->_events->pollEvents();
g_system->delayMillis(10);
_vm->_events->pollEventsAndWait();
}

_vm->_events->debounceLeft();
Expand Down Expand Up @@ -819,8 +817,7 @@ void Scripts::cmdPlayVideoSound() {
_vm->_video->_soundFlag = true;
}

_vm->_events->pollEvents();
g_system->delayMillis(10);
_vm->_events->pollEventsAndWait();
}

void Scripts::cmdPrintWatch() {
Expand Down

0 comments on commit 547f3de

Please sign in to comment.