aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Stewart2018-05-12 20:48:39 -0400
committerEugene Sandulenko2018-08-09 08:37:30 +0200
commitfc89135a16439c7d3b2268038a691e8aa8d6ee50 (patch)
tree3630f711315389ba231947796fe0cddaf27bee03
parentd375429abef0109a483970975b053292efa4bd6e (diff)
downloadscummvm-rg350-fc89135a16439c7d3b2268038a691e8aa8d6ee50.tar.gz
scummvm-rg350-fc89135a16439c7d3b2268038a691e8aa8d6ee50.tar.bz2
scummvm-rg350-fc89135a16439c7d3b2268038a691e8aa8d6ee50.zip
STARTREK: Get animation timing working properly
-rw-r--r--engines/startrek/events.cpp47
-rw-r--r--engines/startrek/startrek.cpp48
-rw-r--r--engines/startrek/startrek.h3
3 files changed, 58 insertions, 40 deletions
diff --git a/engines/startrek/events.cpp b/engines/startrek/events.cpp
index a37ae8c7a4..02b0112136 100644
--- a/engines/startrek/events.cpp
+++ b/engines/startrek/events.cpp
@@ -23,9 +23,56 @@
namespace StarTrek {
+void StarTrekEngine::pollSystemEvents() {
+ Common::Event event;
+ TrekEvent trekEvent;
+
+ while (_eventMan->pollEvent(event)) {
+ trekEvent.mouse = event.mouse;
+ trekEvent.kbd = event.kbd;
+
+ switch (event.type) {
+ case Common::EVENT_QUIT:
+ _system->quit();
+ break;
+
+ case Common::EVENT_MOUSEMOVE:
+ trekEvent.type = TREKEVENT_MOUSEMOVE;
+ addEventToQueue(trekEvent);
+ break;
+ case Common::EVENT_LBUTTONDOWN:
+ trekEvent.type = TREKEVENT_LBUTTONDOWN;
+ addEventToQueue(trekEvent);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (_eventQueue.empty()) {
+ int delay = 1000/18.206 - (_system->getMillis() - _frameStartMillis);
+
+ _clockTicks++;
+ while (delay < 0) { // Check if we're behind...
+ delay += 1000/18.206;
+ _clockTicks++;
+ }
+ _system->delayMillis(delay);
+
+ _frameStartMillis = _system->getMillis();
+
+ TrekEvent tickEvent;
+ tickEvent.type = TREKEVENT_TICK;
+ tickEvent.tick = _clockTicks;
+ addEventToQueue(tickEvent);
+ }
+
+}
+
void StarTrekEngine::initializeEventsAndMouse() {
_mouseMoveEventInQueue = false;
_tickEventInQueue = false;
+ _frameStartMillis = _system->getMillis();
// TODO: mouse
}
diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp
index 8b05a5a3d2..c1c9336968 100644
--- a/engines/startrek/startrek.cpp
+++ b/engines/startrek/startrek.cpp
@@ -134,6 +134,8 @@ Common::Error StarTrekEngine::runGameMode(int mode) {
_gameMode = GAMEMODE_BRIDGE;
while (true) {
+ TrekEvent event;
+
if (_gameMode != _lastGameMode) {
// Cleanup previous game mode
switch (_lastGameMode) {
@@ -183,10 +185,13 @@ Common::Error StarTrekEngine::runGameMode(int mode) {
// Run current game mode
switch (_gameMode) {
case GAMEMODE_BRIDGE:
+ popNextEvent(&event);
//runBridge();
break;
case GAMEMODE_AWAYMISSION:
+ popNextEvent(&event);
+ _system->updateScreen();
//runAwayMission();
break;
@@ -280,42 +285,6 @@ Room *StarTrekEngine::getRoom() {
return _room;
}
-void StarTrekEngine::pollSystemEvents() {
- Common::Event event;
- TrekEvent trekEvent;
-
- while (_eventMan->pollEvent(event)) {
- trekEvent.mouse = event.mouse;
- trekEvent.kbd = event.kbd;
-
- switch (event.type) {
- case Common::EVENT_QUIT:
- _system->quit();
- break;
-
- case Common::EVENT_MOUSEMOVE:
- trekEvent.type = TREKEVENT_MOUSEMOVE;
- addEventToQueue(trekEvent);
- break;
- case Common::EVENT_LBUTTONDOWN:
- trekEvent.type = TREKEVENT_LBUTTONDOWN;
- addEventToQueue(trekEvent);
- break;
- default:
- break;
- }
- }
-
- // FIXME: get the actual duration of a tick right
- _clockTicks++;
- TrekEvent tickEvent;
- tickEvent.type = TREKEVENT_TICK;
- tickEvent.tick = _clockTicks;
- addEventToQueue(tickEvent);
-
- _system->delayMillis(1000/60);
-}
-
void StarTrekEngine::playSoundEffectIndex(int index) {
switch (index) {
case 0x04:
@@ -423,7 +392,7 @@ void StarTrekEngine::updateObjectAnimations() {
switch (object->animType) {
case 0:
case 2:
- if (object->frameToStartNextAnim >= _frameIndex) {
+ if (_frameIndex >= object->frameToStartNextAnim) {
int nextAnimIndex = 0; // TODO: "chooseNextAnimFrame" function
object->animFile->seek(18 + nextAnimIndex + object->animFrame * 22, SEEK_SET);
byte nextAnimFrame = object->animFile->readByte();
@@ -459,17 +428,18 @@ void StarTrekEngine::updateObjectAnimations() {
memset(object->animationString4, 0, 16);
strncpy(object->animationString4, animFrameFilename, 15);
- object->animFile->seek(10, SEEK_SET);
+ object->animFile->seek(10 + object->animFrame * 22, SEEK_SET);
uint16 xOffset = object->animFile->readUint16();
uint16 yOffset = object->animFile->readUint16();
uint16 basePriority = object->animFile->readUint16();
+ uint16 frames = object->animFile->readUint16();
sprite->pos.x = xOffset + object->field5e;
sprite->pos.y = yOffset + object->field60;
sprite->drawPriority = _gfx->getPriValue(0, yOffset + object->field60) + basePriority;
sprite->bitmapChanged = true;
- object->frameToStartNextAnim = object->animFile->readUint16() + _frameIndex;
+ object->frameToStartNextAnim = frames + _frameIndex;
}
}
break;
diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h
index 6cb175c689..921d655f38 100644
--- a/engines/startrek/startrek.h
+++ b/engines/startrek/startrek.h
@@ -116,7 +116,6 @@ public:
// Running the game
Room *getRoom();
- void pollSystemEvents();
void playSoundEffectIndex(int index);
void playSpeech(const Common::String &filename);
@@ -136,6 +135,7 @@ public:
// Events
public:
+ void pollSystemEvents();
void initializeEventsAndMouse();
bool getNextEvent(TrekEvent *e);
void removeNextEvent();
@@ -156,6 +156,7 @@ private:
Common::List<TrekEvent> _eventQueue;
bool _mouseMoveEventInQueue;
bool _tickEventInQueue;
+ uint32 _frameStartMillis;
public:
// Detection related functions