Skip to content

Commit

Permalink
STARTREK: Get animation timing working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Stewmath authored and sev- committed Aug 9, 2018
1 parent d375429 commit fc89135
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 40 deletions.
47 changes: 47 additions & 0 deletions engines/startrek/events.cpp
Expand Up @@ -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
}
Expand Down
48 changes: 9 additions & 39 deletions engines/startrek/startrek.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion engines/startrek/startrek.h
Expand Up @@ -116,7 +116,6 @@ class StarTrekEngine : public ::Engine {

// Running the game
Room *getRoom();
void pollSystemEvents();

void playSoundEffectIndex(int index);
void playSpeech(const Common::String &filename);
Expand All @@ -136,6 +135,7 @@ class StarTrekEngine : public ::Engine {

// Events
public:
void pollSystemEvents();
void initializeEventsAndMouse();
bool getNextEvent(TrekEvent *e);
void removeNextEvent();
Expand All @@ -156,6 +156,7 @@ class StarTrekEngine : public ::Engine {
Common::List<TrekEvent> _eventQueue;
bool _mouseMoveEventInQueue;
bool _tickEventInQueue;
uint32 _frameStartMillis;

public:
// Detection related functions
Expand Down

0 comments on commit fc89135

Please sign in to comment.