TEEN: Use only one RandomSource and give that one a name.

This change ensures that only RandomSource is used which also is
registered with the event recorder. Moreover, it gets rid of a static
RandomSource instance inside Actor::renderIdle.
This commit is contained in:
Max Horn 2011-05-17 11:58:34 +02:00
parent 4cbe4ede66
commit 05a7b160b3
6 changed files with 18 additions and 13 deletions

View File

@ -31,10 +31,9 @@ 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, int delta_frame, uint zoom) {
static Common::RandomSource random;
Common::Rect Actor::renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, uint zoom, Common::RandomSource &rnd) {
if (index == 0) {
idle_type = random.getRandomNumber(2);
idle_type = rnd.getRandomNumber(2);
debug(0, "switched to idle animation %u", idle_type);
}
@ -44,7 +43,7 @@ Common::Rect Actor::renderIdle(Graphics::Surface *surface, const Common::Point &
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);
idle_type = rnd.getRandomNumber(2);
debug(0, "switched to idle animation %u[loop]", idle_type);
index = 3; //put 4th frame (base 1) if idle animation loops
}

View File

@ -22,6 +22,10 @@
#include "teenagent/animation.h"
#include "common/rect.h"
namespace Common {
class RandomSource;
}
namespace TeenAgent {
class Actor : public Animation {
@ -30,7 +34,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, int delta_frame, uint zoom);
Common::Rect renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, uint zoom, Common::RandomSource &rnd);
};
} // End of namespace TeenAgent

View File

@ -36,7 +36,7 @@ namespace TeenAgent {
void TeenAgentEngine::rejectMessage() {
Resources * res = Resources::instance();
//random reject message:
uint i = random.getRandomNumber(3);
uint i = _rnd.getRandomNumber(3);
//debug(0, "reject message: %s", (const char *)res->dseg.ptr(res->dseg.get_word(0x339e + 2 * i)));
displayMessage(res->dseg.get_word(0x339e + 2 * i));
}
@ -3004,7 +3004,7 @@ bool TeenAgentEngine::processCallback(uint16 addr) {
moveTo(153, 163, 4);
playActorAnimation(973);
if (CHECK_FLAG(0xDBC1, 0)) {
SET_FLAG(0xDBC1, random.getRandomNumber(5) + 1);
SET_FLAG(0xDBC1, _rnd.getRandomNumber(5) + 1);
}
loadScene(30, 18, 159, 2);
return true;

View File

@ -804,7 +804,7 @@ bool Scene::render(bool tick_game, bool tick_mark, uint32 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);
actor_animation_position = teenagent_idle.renderIdle(surface, position, orientation, mark_delta, zoom, _engine->_rnd);
}
}

View File

@ -47,7 +47,9 @@
namespace TeenAgent {
TeenAgentEngine::TeenAgentEngine(OSystem *system, const ADGameDescription *gd) : Engine(system), action(kActionNone), _gameDescription(gd) {
TeenAgentEngine::TeenAgentEngine(OSystem *system, const ADGameDescription *gd)
: Engine(system), action(kActionNone), _gameDescription(gd),
_rnd("teenagent") {
music = new MusicPlayer();
console = 0;
@ -396,8 +398,8 @@ bool TeenAgentEngine::showMetropolis() {
//generate colors matrix
memmove(colors + 320, colors + 480, 8480);
for(uint c = 0; c < 17; ++c) {
byte x = (random.getRandomNumber(184) + 5) & 0xff;
uint offset = 8800 + random.getRandomNumber(158);
byte x = (_rnd.getRandomNumber(184) + 5) & 0xff;
uint offset = 8800 + _rnd.getRandomNumber(158);
colors[offset++] = x;
colors[offset++] = x;
}

View File

@ -47,7 +47,7 @@ class Scene;
class MusicPlayer;
class Console;
class TeenAgentEngine: public Engine {
class TeenAgentEngine : public Engine {
public:
enum Action { kActionNone, kActionExamine, kActionUse };
@ -117,7 +117,7 @@ public:
void fadeOut();
void wait(uint16 frames);
Common::RandomSource random;
Common::RandomSource _rnd;
Scene *scene;
Inventory *inventory;