ASYLUM: - Added a waitForTimer() function, which can be used to properly do screen updates and changed frame delay. Game speed should be correct now

- Moved event checking to a separate function

git-svn-id: http://asylumengine.googlecode.com/svn/trunk@73 0bfb4aae-4ea4-11de-8d8d-752d95cf3e3c
This commit is contained in:
Filippos Karapetis 2009-06-13 13:40:48 +00:00 committed by Eugene Sandulenko
parent 7fa648f9a3
commit abc272106c
No known key found for this signature in database
GPG key ID: 014D387312D34F08
2 changed files with 33 additions and 23 deletions

View file

@ -115,41 +115,49 @@ Common::Error AsylumEngine::go() {
// DEBUG
uint32 lastUpdate = 0;
Common::EventManager *em = _system->getEventManager();
while (!shouldQuit()) {
Common::Event ev;
checkForEvent();
// Copy background image
_system->copyRectToScreen((byte *)_backBuffer.pixels, _backBuffer.w, 0, 0, _backBuffer.w, _backBuffer.h);
if (em->pollEvent(ev)) {
if (ev.type == Common::EVENT_KEYDOWN) {
if (ev.kbd.keycode == Common::KEYCODE_ESCAPE) {
// Push a quit event
Common::Event event;
event.type = Common::EVENT_QUIT;
g_system->getEventManager()->pushEvent(event);
}
//if (ev.kbd.keycode == Common::KEYCODE_RETURN)
} else if (ev.type == Common::EVENT_MOUSEMOVE) {
_mouseX = ev.mouse.x;
_mouseY = ev.mouse.y;
}
}
updateMainMenu();
if (_system->getMillis() - lastUpdate > 50) {
_system->updateScreen();
lastUpdate = _system->getMillis();
}
_system->delayMillis(10);
waitForTimer(50);
}
return Common::kNoError;
}
void AsylumEngine::waitForTimer(int msec_delay) {
uint32 start_time = _system->getMillis();
while (_system->getMillis() < start_time + msec_delay) {
checkForEvent();
_system->updateScreen();
_system->delayMillis(10);
}
}
void AsylumEngine::checkForEvent() {
Common::Event ev;
if (_system->getEventManager()->pollEvent(ev)) {
if (ev.type == Common::EVENT_KEYDOWN) {
if (ev.kbd.keycode == Common::KEYCODE_ESCAPE) {
// Push a quit event
Common::Event event;
event.type = Common::EVENT_QUIT;
g_system->getEventManager()->pushEvent(event);
}
//if (ev.kbd.keycode == Common::KEYCODE_RETURN)
} else if (ev.type == Common::EVENT_MOUSEMOVE) {
_mouseX = ev.mouse.x;
_mouseY = ev.mouse.y;
}
}
}
void AsylumEngine::showMainMenu() {
// main menu background
_resMgr->loadGraphic(1, 0, 0);

View file

@ -52,6 +52,8 @@ public:
void copyToBackBuffer(byte *buffer, int x, int y, int width, int height);
void copyRectToScreenWithTransparency(byte *buffer, int x, int y, int width, int height);
void checkForEvent();
void waitForTimer(int msec_delay);
private:
Common::Language _language;