aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2011-05-17 11:58:34 +0200
committerMax Horn2011-05-17 12:17:26 +0200
commit05a7b160b396f0ffec50d597f5c980be235cbe7e (patch)
treeaa795f5728e9da579434db6f7a59a8e5e6962e5f
parent4cbe4ede66e65ec9289811eca2f5f62285174c8d (diff)
downloadscummvm-rg350-05a7b160b396f0ffec50d597f5c980be235cbe7e.tar.gz
scummvm-rg350-05a7b160b396f0ffec50d597f5c980be235cbe7e.tar.bz2
scummvm-rg350-05a7b160b396f0ffec50d597f5c980be235cbe7e.zip
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.
-rw-r--r--engines/teenagent/actor.cpp7
-rw-r--r--engines/teenagent/actor.h6
-rw-r--r--engines/teenagent/callbacks.cpp4
-rw-r--r--engines/teenagent/scene.cpp2
-rw-r--r--engines/teenagent/teenagent.cpp8
-rw-r--r--engines/teenagent/teenagent.h4
6 files changed, 18 insertions, 13 deletions
diff --git a/engines/teenagent/actor.cpp b/engines/teenagent/actor.cpp
index 870410b2c2..717c022c38 100644
--- a/engines/teenagent/actor.cpp
+++ b/engines/teenagent/actor.cpp
@@ -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
}
diff --git a/engines/teenagent/actor.h b/engines/teenagent/actor.h
index 5e13af10ea..9a7d395547 100644
--- a/engines/teenagent/actor.h
+++ b/engines/teenagent/actor.h
@@ -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
diff --git a/engines/teenagent/callbacks.cpp b/engines/teenagent/callbacks.cpp
index 8c8519e51b..ae498478a4 100644
--- a/engines/teenagent/callbacks.cpp
+++ b/engines/teenagent/callbacks.cpp
@@ -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;
diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp
index 54c3ce928d..ef18b95f5a 100644
--- a/engines/teenagent/scene.cpp
+++ b/engines/teenagent/scene.cpp
@@ -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);
}
}
diff --git a/engines/teenagent/teenagent.cpp b/engines/teenagent/teenagent.cpp
index d8cbae9fac..f076dbc0a1 100644
--- a/engines/teenagent/teenagent.cpp
+++ b/engines/teenagent/teenagent.cpp
@@ -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;
}
diff --git a/engines/teenagent/teenagent.h b/engines/teenagent/teenagent.h
index a376b379ba..bc802da8bc 100644
--- a/engines/teenagent/teenagent.h
+++ b/engines/teenagent/teenagent.h
@@ -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;