From 841e2d34242418ed0c86a6d8d3a4a97faa085ae6 Mon Sep 17 00:00:00 2001 From: Vladimir Menshakov Date: Tue, 5 Jan 2010 22:09:16 +0000 Subject: separate timers for mark, scene and messages. svn-id: r47056 --- engines/teenagent/actor.cpp | 12 ++--- engines/teenagent/actor.h | 2 +- engines/teenagent/animation.h | 2 +- engines/teenagent/inventory.cpp | 4 +- engines/teenagent/scene.cpp | 114 +++++++++++++++++++++------------------- engines/teenagent/scene.h | 2 +- engines/teenagent/teenagent.cpp | 21 +++++--- 7 files changed, 84 insertions(+), 73 deletions(-) (limited to 'engines/teenagent') diff --git a/engines/teenagent/actor.cpp b/engines/teenagent/actor.cpp index 71c5caebb0..7872b33d9e 100644 --- a/engines/teenagent/actor.cpp +++ b/engines/teenagent/actor.cpp @@ -31,7 +31,7 @@ namespace TeenAgent { Actor::Actor() : head_index(0), idle_type(0) {} //idle animation lists at dseg: 0x6540 -Common::Rect Actor::renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, uint zoom) { +Common::Rect Actor::renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, uint zoom) { static Common::RandomSource random; if (index == 0) { idle_type = random.getRandomNumber(2); @@ -41,7 +41,8 @@ Common::Rect Actor::renderIdle(Graphics::Surface *surface, const Common::Point & Resources * res = Resources::instance(); byte *frames_idle; do { - frames_idle = res->dseg.ptr(res->dseg.get_word(0x6540 + idle_type * 2)) + index++; + frames_idle = res->dseg.ptr(res->dseg.get_word(0x6540 + idle_type * 2)) + index; + index += delta_frame; if (*frames_idle == 0) { idle_type = random.getRandomNumber(2); debug(0, "switched to idle animation %u[loop]", idle_type); @@ -100,11 +101,9 @@ Common::Rect Actor::render(Graphics::Surface *surface, const Common::Point &posi Surface *s = NULL, *head = NULL; - if (delta_frame == 0) { - index = 0; //static animation - } - bool mirror = orientation == kActorLeft; + index += delta_frame; + switch (orientation) { case kActorLeft: case kActorRight: @@ -146,7 +145,6 @@ Common::Rect Actor::render(Graphics::Surface *surface, const Common::Point &posi default: return Common::Rect(); } - index += delta_frame; if (s == NULL) { warning("no surface, skipping"); return Common::Rect(); diff --git a/engines/teenagent/actor.h b/engines/teenagent/actor.h index 3edace362e..1afe2c3d33 100644 --- a/engines/teenagent/actor.h +++ b/engines/teenagent/actor.h @@ -33,7 +33,7 @@ class Actor : public Animation { public: Actor(); Common::Rect render(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, bool head, uint zoom); - Common::Rect renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, uint zoom); + Common::Rect renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, uint zoom); }; } // End of namespace TeenAgent diff --git a/engines/teenagent/animation.h b/engines/teenagent/animation.h index f77fbcf679..31c3fa7eaf 100644 --- a/engines/teenagent/animation.h +++ b/engines/teenagent/animation.h @@ -42,7 +42,7 @@ public: void free(); Surface *firstFrame(); - Surface *currentFrame(int dt = 1); + Surface *currentFrame(int dt); uint16 currentIndex() const { return index; } void resetIndex() { index = 0; } diff --git a/engines/teenagent/inventory.cpp b/engines/teenagent/inventory.cpp index 47d99e3abc..af7f219206 100644 --- a/engines/teenagent/inventory.cpp +++ b/engines/teenagent/inventory.cpp @@ -254,9 +254,9 @@ void Inventory::Item::render(Inventory *inventory, InventoryObject *obj, Graphic animation.load(inventory->items, Animation::kTypeInventory); } if (hovered) { - Surface *s = animation.currentFrame(); + Surface *s = animation.currentFrame(1); if (animation.currentIndex() == 0) - s = animation.currentFrame(); + s = animation.currentFrame(1); if (s != NULL) s->render(dst, rect.left + 1, rect.top + 1); } else { diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp index 61a99c3732..015b2ac9c1 100644 --- a/engines/teenagent/scene.cpp +++ b/engines/teenagent/scene.cpp @@ -532,21 +532,23 @@ int Scene::lookupZoom(uint y) const { } -bool Scene::render() { +bool Scene::render(bool tick_game, bool tick_mark, uint32 message_delta) { Resources *res = Resources::instance(); bool busy; bool restart; + uint32 game_delta = tick_game? 1: 0; + uint32 mark_delta = tick_mark? 1: 0; do { restart = false; busy = processEventQueue(); - if (_fade_timer) { + if (_fade_timer && game_delta != 0) { if (_fade_timer > 0) { - --_fade_timer; + _fade_timer -= game_delta; setPalette(_fade_timer); } else { - ++_fade_timer; + _fade_timer += game_delta; setPalette(_fade_timer + 4); } } @@ -556,7 +558,7 @@ bool Scene::render() { _system->fillScreen(0); ///\todo: optimize me Graphics::Surface *surface = _system->lockScreen(); - res->font7.render(surface, current_event.dst.x, current_event.dst.y--, current_event.message, current_event.color); + res->font7.render(surface, current_event.dst.x, current_event.dst.y -= game_delta, current_event.message, current_event.color); _system->unlockScreen(); if (current_event.dst.y < -(int)current_event.timer) @@ -568,11 +570,12 @@ bool Scene::render() { } if (!message.empty() && message_timer != 0) { - if (--message_timer == 0) { + if (message_timer <= message_delta) { clearMessage(); nextEvent(); continue; - } + } else + message_timer -= message_delta; } if (current_event.type == SceneEvent::kCreditsMessage) { @@ -609,7 +612,7 @@ bool Scene::render() { for (byte i = 0; i < 4; ++i) { Animation *a = custom_animation + i; - Surface *s = a->currentFrame(); + Surface *s = a->currentFrame(game_delta); if (s != NULL) { if (!a->ignore) busy = true; @@ -622,7 +625,7 @@ bool Scene::render() { custom_animation[i].free(); a->restart(); } - s = a->currentFrame(); + s = a->currentFrame(game_delta); } if (current_event.type == SceneEvent::kWaitLanAnimationFrame && current_event.slot == i) { @@ -667,19 +670,29 @@ bool Scene::render() { s->render(surface); } - Surface *mark = actor_animation.currentFrame(); - if (mark == NULL) { - if (!hide_actor) { - actor_animation.free(); - uint zoom = lookupZoom(position.y); + Surface *mark = actor_animation.currentFrame(game_delta); + if (!hide_actor && mark == NULL) { + actor_animation.free(); + uint zoom = lookupZoom(position.y); + + if (!path.empty()) { + const Common::Point &destination = path.front(); + Common::Point dp(destination.x - position.x, destination.y - position.y); + + int o; + if (ABS(dp.x) > ABS(dp.y)) + o = dp.x > 0 ? kActorRight : kActorLeft; + else { + o = dp.y > 0 ? kActorDown : kActorUp; + } - if (!path.empty()) { + if (tick_mark) { int speed_x; switch(teenagent.currentIndex()) { case 6: speed_x = 10; break; - case 8: + case 7: speed_x = 1; break; default: @@ -687,53 +700,44 @@ bool Scene::render() { break; } speed_x = speed_x * zoom / 256; - int speed_y = 1 * zoom / 256; + int speed_y = (o == kActorDown || o == kActorUp? 2: 1) * zoom / 256; if (speed_x == 0) speed_x = 1; if (speed_y == 0) speed_y = 1; - - const Common::Point &destination = path.front(); - Common::Point dp(destination.x - position.x, destination.y - position.y); - - int o; - if (ABS(dp.x) > ABS(dp.y)) - o = dp.x > 0 ? kActorRight : kActorLeft; - else { - o = dp.y > 0 ? kActorDown : kActorUp; - speed_y *= 2; - } - + position.y += (ABS(dp.y) < speed_y? dp.y: SIGN(dp.y) * speed_y); position.x += (o == kActorDown || o == kActorUp)? (ABS(dp.x) < speed_y? dp.x: SIGN(dp.x) * speed_y): (ABS(dp.x) < speed_x? dp.x: SIGN(dp.x) * speed_x); - - _idle_timer = 0; - teenagent_idle.resetIndex(); - actor_animation_position = teenagent.render(surface, position, o, 1, false, zoom); - - if (position == destination) { - path.pop_front(); - if (path.empty()) { - if (orientation == 0) - orientation = o; //save last orientation - nextEvent(); - got_any_animation = true; - restart = true; - } - busy = true; - } else - busy = true; - } else { - ++_idle_timer; - if (_idle_timer < 50) - actor_animation_position = teenagent.render(surface, position, orientation, 0, actor_talking, zoom); - else - actor_animation_position = teenagent_idle.renderIdle(surface, position, orientation, zoom); } + + _idle_timer = 0; + teenagent_idle.resetIndex(); + actor_animation_position = teenagent.render(surface, position, o, mark_delta, false, zoom); + + if (tick_mark && position == destination) { + path.pop_front(); + if (path.empty()) { + if (orientation == 0) + orientation = o; //save last orientation + nextEvent(); + got_any_animation = true; + restart = true; + } + busy = true; + } else + busy = true; + } else { + teenagent.resetIndex(); + _idle_timer += mark_delta; + if (_idle_timer < 50) + actor_animation_position = teenagent.render(surface, position, orientation, 0, actor_talking, zoom); + else + actor_animation_position = teenagent_idle.renderIdle(surface, position, orientation, mark_delta, zoom); } } + if (restart) { _system->unlockScreen(); continue; @@ -825,7 +829,7 @@ bool Scene::render() { _engine->playSoundNow(sound.id); i = sounds.erase(i); } else { - --sound.delay; + sound.delay -= game_delta; ++i; } } @@ -910,7 +914,7 @@ bool Scene::processEventQueue() { message_animation = &actor_animation; debug(0, "async message %d-%d (slot %u)", message_first_frame, message_last_frame, current_event.slot); } else { - message_timer = current_event.timer? current_event.timer: messageDuration(message); + message_timer = current_event.timer? current_event.timer * 110: messageDuration(message); message_first_frame = message_last_frame = 0; } Common::Point p; @@ -1141,7 +1145,7 @@ uint Scene::messageDuration(const Common::String &str) { uint delay = 60 + (total_width * delay_delta) / 8; //debug(0, "delay = %u, delta: %u", delay, delay_delta); - return delay / 10; + return delay * 10; } diff --git a/engines/teenagent/scene.h b/engines/teenagent/scene.h index 3319c3e1f8..9177511795 100644 --- a/engines/teenagent/scene.h +++ b/engines/teenagent/scene.h @@ -127,7 +127,7 @@ public: void init(TeenAgentEngine *engine, OSystem *system); void init(int id, const Common::Point &pos); - bool render(); + bool render(bool tick_game, bool tick_mark, uint32 message_delta); int getId() const { return _id; } void warp(const Common::Point &point, byte orientation = 0); diff --git a/engines/teenagent/teenagent.cpp b/engines/teenagent/teenagent.cpp index e20e974d5c..ac399b269c 100644 --- a/engines/teenagent/teenagent.cpp +++ b/engines/teenagent/teenagent.cpp @@ -518,18 +518,27 @@ Common::Error TeenAgentEngine::run() { uint32 delta = new_timer - timer; timer = new_timer; - if (game_timer <= delta) { - bool b = scene->render(); + bool tick_game = game_timer <= delta; + if (tick_game) + game_timer = kGameDelay - ((delta - game_timer) % kGameDelay); + else + game_timer -= delta; + + bool tick_mark = mark_timer <= delta; + if (tick_mark) + mark_timer = kMarkDelay - ((delta - mark_timer) % kMarkDelay); + else + mark_timer -= delta; + + if (tick_game || tick_mark) { + bool b = scene->render(tick_game, tick_mark, delta); if (!inventory->active() && !b && action != kActionNone) { processObject(); action = kActionNone; dst_object = NULL; } - scene_busy = b; - game_timer = kGameDelay - ((delta - game_timer) % kGameDelay); - } else - game_timer -= delta; + } bool busy = inventory->active() || scene_busy; -- cgit v1.2.3