From: mathnerd314 Date: Sun, 21 Feb 2010 23:18:32 +0000 (+0000) Subject: * Split systemRandom into graphicsRandom (particles, eye candy, etc.) and gameRandom... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=df4ad0c752e2f8d6c6db820b77cda1f795bc584f;p=supertux.git * Split systemRandom into graphicsRandom (particles, eye candy, etc.) and gameRandom (important things; shouldn't be used much) * Camera doesn't move Tux around anymore * Use assertions instead of NDEBUG * Tilemap movement is reported correctly according to a boolean (still not perfect CD however) git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6382 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- diff --git a/TODO b/TODO index 29d011b45..5f8d17f62 100644 --- a/TODO +++ b/TODO @@ -78,9 +78,6 @@ TODO * file naming is inconsistent: some times we use '_' to separate words, sometimes we don't -* get rid of NDEBUG and conditional compilation, these should be - reserved for a few tiny cases, not spread all over the code - * collect all manager classes into globals.hpp * more moving directories around? diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index 732e732fc..32498562d 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -183,7 +183,7 @@ Dispenser::launch_badguy() if (badguys.size() > 1) { if (random) { - next_badguy = systemRandom.rand(badguys.size()); + next_badguy = gameRandom.rand(badguys.size()); } else { next_badguy++; diff --git a/src/badguy/flyingsnowball.cpp b/src/badguy/flyingsnowball.cpp index 564e76e50..2ad19e45f 100644 --- a/src/badguy/flyingsnowball.cpp +++ b/src/badguy/flyingsnowball.cpp @@ -52,8 +52,8 @@ FlyingSnowBall::initialize() void FlyingSnowBall::activate() { - puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX)); - normal_propeller_speed = systemRandom.randf(0.95, 1.05); + puff_timer.start(gameRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX)); + normal_propeller_speed = gameRandom.randf(0.95, 1.05); } bool @@ -111,12 +111,12 @@ FlyingSnowBall::active_update(float elapsed_time) // spawn smoke puffs if (puff_timer.check()) { Vector ppos = bbox.get_middle(); - Vector pspeed = Vector(systemRandom.randf(-10, 10), 150); + Vector pspeed = Vector(gameRandom.randf(-10, 10), 150); Vector paccel = Vector(0,0); Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1)); - puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX)); + puff_timer.start(gameRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX)); - normal_propeller_speed = systemRandom.randf(0.95, 1.05); + normal_propeller_speed = gameRandom.randf(0.95, 1.05); physic.set_velocity_y(physic.get_velocity_y() - 50); } } diff --git a/src/badguy/ghosttree.cpp b/src/badguy/ghosttree.cpp index 9def4616e..89ff2df63 100644 --- a/src/badguy/ghosttree.cpp +++ b/src/badguy/ghosttree.cpp @@ -116,7 +116,7 @@ GhostTree::active_update(float elapsed_time) for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) { TreeWillOWisp *willo = *iter; if(willo->get_color() == col) { - willo->start_sucking(get_bbox().get_middle() + SUCK_TARGET_OFFSET + Vector(systemRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD), systemRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD))); + willo->start_sucking(get_bbox().get_middle() + SUCK_TARGET_OFFSET + Vector(gameRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD), gameRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD))); } } mystate = STATE_SUCKING; diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index b3eee3723..6b6e81e1c 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -105,8 +105,8 @@ Kugelblitz::hit(const CollisionHit& hit) sprite->set_action("flying"); physic.set_velocity_y(0); //Set random initial speed and direction - direction = systemRandom.rand(2)? 1: -1; - int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction; + direction = gameRandom.rand(2)? 1: -1; + int speed = (BASE_SPEED + (gameRandom.rand(RAND_SPEED))) * direction; physic.set_velocity_x(speed); movement_timer.start(MOVETIME); lifetime.start(LIFETIME); @@ -128,7 +128,7 @@ Kugelblitz::active_update(float elapsed_time) if (groundhit_pos_set) { if (movement_timer.check()) { if (direction == 1) direction = -1; else direction = 1; - int speed = (BASE_SPEED + (systemRandom.rand(RAND_SPEED))) * direction; + int speed = (BASE_SPEED + (gameRandom.rand(RAND_SPEED))) * direction; physic.set_velocity_x(speed); movement_timer.start(MOVETIME); } diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index 302d089bb..c9a40cd35 100644 --- a/src/badguy/mole.cpp +++ b/src/badguy/mole.cpp @@ -88,7 +88,7 @@ Mole::throw_rock() float px = get_bbox().get_middle().x; float py = get_bbox().get_middle().y; - float angle = systemRandom.rand(90 - 15, 90 + 15) * (M_PI / 180); + float angle = gameRandom.rand(90 - 15, 90 + 15) * (M_PI / 180); float vx = cos(angle) * THROW_VELOCITY; float vy = -sin(angle) * THROW_VELOCITY; diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index f21a926ec..8c688d4bb 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -61,8 +61,8 @@ MrTree::collision_squished(GameObject& object) // TODO: provide convenience function in MovingSprite or MovingObject? for (int px = (int)stumpy->get_bbox().p1.x; px < (int)stumpy->get_bbox().p2.x; px+=10) { Vector ppos = Vector(px, stumpy->get_bbox().p1.y-5); - float angle = systemRandom.randf(-M_PI_2, M_PI_2); - float velocity = systemRandom.randf(45, 90); + float angle = graphicsRandom.randf(-M_PI_2, M_PI_2); + float velocity = graphicsRandom.randf(45, 90); float vx = sin(angle)*velocity; float vy = -cos(angle)*velocity; Vector pspeed = Vector(vx, vy); diff --git a/src/badguy/poisonivy.cpp b/src/badguy/poisonivy.cpp index 5b28671c6..334746557 100644 --- a/src/badguy/poisonivy.cpp +++ b/src/badguy/poisonivy.cpp @@ -42,8 +42,8 @@ PoisonIvy::collision_squished(GameObject& object) // TODO: provide convenience function in MovingSprite or MovingObject? for (int i = 0; i < 3; i++) { Vector ppos = bbox.get_middle(); - float angle = systemRandom.randf(-M_PI_2, M_PI_2); - float velocity = systemRandom.randf(350, 400); + float angle = graphicsRandom.randf(-M_PI_2, M_PI_2); + float velocity = graphicsRandom.randf(350, 400); float vx = sin(angle)*velocity; float vy = -cos(angle)*velocity; Vector pspeed = Vector(vx, vy); diff --git a/src/badguy/skullyhop.cpp b/src/badguy/skullyhop.cpp index c76bace33..f7a1c6738 100644 --- a/src/badguy/skullyhop.cpp +++ b/src/badguy/skullyhop.cpp @@ -59,7 +59,7 @@ SkullyHop::set_state(SkullyHopState newState) physic.set_velocity_y(0); sprite->set_action(dir == LEFT ? "standing-left" : "standing-right"); - float recover_time = systemRandom.randf(MIN_RECOVER_TIME,MAX_RECOVER_TIME); + float recover_time = gameRandom.randf(MIN_RECOVER_TIME,MAX_RECOVER_TIME); recover_timer.start(recover_time); } else if (newState == CHARGING) { diff --git a/src/badguy/stalactite.cpp b/src/badguy/stalactite.cpp index 449b59264..a5f688a90 100644 --- a/src/badguy/stalactite.cpp +++ b/src/badguy/stalactite.cpp @@ -50,7 +50,7 @@ Stalactite::active_update(float elapsed_time) } } } else if(state == STALACTITE_SHAKING) { - shake_delta = Vector(systemRandom.rand(-3,3), 0); + shake_delta = Vector(graphicsRandom.rand(-3,3), 0); if(timer.check()) { state = STALACTITE_FALLING; physic.enable_gravity(true); diff --git a/src/badguy/stumpy.cpp b/src/badguy/stumpy.cpp index 218d871f3..8c47c6636 100644 --- a/src/badguy/stumpy.cpp +++ b/src/badguy/stumpy.cpp @@ -102,8 +102,8 @@ Stumpy::collision_squished(GameObject& object) // TODO: provide convenience function in MovingSprite or MovingObject? for (int i = 0; i < 25; i++) { Vector ppos = bbox.get_middle(); - float angle = systemRandom.randf(-M_PI_2, M_PI_2); - float velocity = systemRandom.randf(45, 90); + float angle = graphicsRandom.randf(-M_PI_2, M_PI_2); + float velocity = graphicsRandom.randf(45, 90); float vx = sin(angle)*velocity; float vy = -cos(angle)*velocity; Vector pspeed = Vector(vx, vy); diff --git a/src/badguy/zeekling.cpp b/src/badguy/zeekling.cpp index 8c64887bb..1c49add59 100644 --- a/src/badguy/zeekling.cpp +++ b/src/badguy/zeekling.cpp @@ -34,7 +34,7 @@ Zeekling::Zeekling(const Reader& reader) : last_self_pos() { state = FLYING; - speed = systemRandom.rand(130, 171); + speed = gameRandom.rand(130, 171); physic.enable_gravity(false); } @@ -48,7 +48,7 @@ Zeekling::Zeekling(const Vector& pos, Direction d) : last_self_pos() { state = FLYING; - speed = systemRandom.rand(130, 171); + speed = gameRandom.rand(130, 171); physic.enable_gravity(false); } diff --git a/src/math/random_generator.cpp b/src/math/random_generator.cpp index 7a1c6d158..fe4086b04 100644 --- a/src/math/random_generator.cpp +++ b/src/math/random_generator.cpp @@ -41,7 +41,8 @@ #include "math/random_generator.hpp" -RandomGenerator systemRandom; // global random number generator +RandomGenerator graphicsRandom; // graphic RNG +RandomGenerator gameRandom; // game RNG RandomGenerator::RandomGenerator() : initialized(), diff --git a/src/math/random_generator.hpp b/src/math/random_generator.hpp index ea8f3bd17..526b59698 100644 --- a/src/math/random_generator.hpp +++ b/src/math/random_generator.hpp @@ -126,7 +126,10 @@ private: RandomGenerator& operator=(const RandomGenerator&); }; -extern RandomGenerator systemRandom; +// Use for random particle fx or whatever +extern RandomGenerator graphicsRandom; +// Use for game-changing random numbers +extern RandomGenerator gameRandom; #endif //__RANDOM_GENERATOR__ diff --git a/src/object/broken_brick.cpp b/src/object/broken_brick.cpp index c907f14ea..4f88d6a08 100644 --- a/src/object/broken_brick.cpp +++ b/src/object/broken_brick.cpp @@ -46,7 +46,7 @@ void BrokenBrick::draw(DrawingContext& context) { sprite->draw_part(context, - Vector(systemRandom.rand(16), systemRandom.rand(16)), Vector(16, 16), + Vector(graphicsRandom.rand(16), graphicsRandom.rand(16)), Vector(16, 16), position, LAYER_OBJECTS + 1); } diff --git a/src/object/candle.cpp b/src/object/candle.cpp index 1123ce0bb..fe140f2bb 100644 --- a/src/object/candle.cpp +++ b/src/object/candle.cpp @@ -51,7 +51,7 @@ Candle::draw(DrawingContext& context) context.push_target(); context.set_target(DrawingContext::LIGHTMAP); // draw approx. 1 in 10 frames darker. Makes the candle flicker - if (systemRandom.rand(10) != 0) { + if (gameRandom.rand(10) != 0) { context.draw_surface(candle_light_1, pos, layer); } else { context.draw_surface(candle_light_2, pos, layer); diff --git a/src/object/cloud_particle_system.cpp b/src/object/cloud_particle_system.cpp index e1a7a5eb1..2cbbca273 100644 --- a/src/object/cloud_particle_system.cpp +++ b/src/object/cloud_particle_system.cpp @@ -33,10 +33,10 @@ CloudParticleSystem::CloudParticleSystem() : // create some random clouds for(size_t i=0; i<15; ++i) { CloudParticle* particle = new CloudParticle; - particle->pos.x = systemRandom.rand(static_cast(virtual_width)); - particle->pos.y = systemRandom.rand(static_cast(virtual_height)); + particle->pos.x = graphicsRandom.rand(static_cast(virtual_width)); + particle->pos.y = graphicsRandom.rand(static_cast(virtual_height)); particle->texture = cloudimage; - particle->speed = -systemRandom.randf(25.0, 54.0); + particle->speed = -graphicsRandom.randf(25.0, 54.0); particles.push_back(particle); } diff --git a/src/object/comet_particle_system.cpp b/src/object/comet_particle_system.cpp index a2fd295b5..bd8cbfbc9 100644 --- a/src/object/comet_particle_system.cpp +++ b/src/object/comet_particle_system.cpp @@ -32,12 +32,12 @@ CometParticleSystem::CometParticleSystem() size_t cometcount = 2; for(size_t i=0; ipos.x = systemRandom.rand(int(virtual_width)); - particle->pos.y = systemRandom.rand(int(virtual_height)); - int cometsize = systemRandom.rand(2); + particle->pos.x = graphicsRandom.rand(int(virtual_width)); + particle->pos.y = graphicsRandom.rand(int(virtual_height)); + int cometsize = graphicsRandom.rand(2); particle->texture = cometimages[cometsize]; do { - particle->speed = (cometsize+1)*30 + systemRandom.randf(3.6); + particle->speed = (cometsize+1)*30 + graphicsRandom.randf(3.6); } while(particle->speed < 1); particle->speed *= 10; // gravity @@ -73,7 +73,7 @@ void CometParticleSystem::update(float elapsed_time) if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)) { Sector::current()->add_object(new Bomb(particle->pos, LEFT)); } - int new_x = systemRandom.rand(int(virtual_width)) + int(abs_x); + int new_x = graphicsRandom.rand(int(virtual_width)) + int(abs_x); int new_y = 0; //FIXME: Don't move particles over solid tiles particle->pos.x = new_x; diff --git a/src/object/explosion.cpp b/src/object/explosion.cpp index 77d6b17e8..25a114829 100644 --- a/src/object/explosion.cpp +++ b/src/object/explosion.cpp @@ -55,8 +55,8 @@ Explosion::explode() // TODO: provide convenience function in MovingSprite or MovingObject? for (int i = 0; i < 100; i++) { Vector ppos = bbox.get_middle(); - float angle = systemRandom.randf(-M_PI_2, M_PI_2); - float velocity = systemRandom.randf(450, 900); + float angle = graphicsRandom.randf(-M_PI_2, M_PI_2); + float velocity = graphicsRandom.randf(450, 900); float vx = sin(angle)*velocity; float vy = -cos(angle)*velocity; Vector pspeed = Vector(vx, vy); diff --git a/src/object/firefly.cpp b/src/object/firefly.cpp index 88049995c..93901642d 100644 --- a/src/object/firefly.cpp +++ b/src/object/firefly.cpp @@ -73,8 +73,8 @@ Firefly::collision(GameObject& other, const CollisionHit& ) // TODO: provide convenience function in MovingSprite or MovingObject? for (int i = 0; i < 5; i++) { Vector ppos = bbox.get_middle(); - float angle = systemRandom.randf(-M_PI_2, M_PI_2); - float velocity = systemRandom.randf(450, 900); + float angle = graphicsRandom.randf(-M_PI_2, M_PI_2); + float velocity = graphicsRandom.randf(450, 900); float vx = sin(angle)*velocity; float vy = -cos(angle)*velocity; Vector pspeed = Vector(vx, vy); diff --git a/src/object/fireworks.cpp b/src/object/fireworks.cpp index a903fa8d9..c5ec447af 100644 --- a/src/object/fireworks.cpp +++ b/src/object/fireworks.cpp @@ -40,11 +40,11 @@ Fireworks::update(float ) if(timer.check()) { Sector* sector = Sector::current(); Vector pos = sector->camera->get_translation(); - pos += Vector(systemRandom.randf(SCREEN_WIDTH), - systemRandom.randf(SCREEN_HEIGHT/2)); + pos += Vector(graphicsRandom.randf(SCREEN_WIDTH), + graphicsRandom.randf(SCREEN_HEIGHT/2)); - float red = systemRandom.randf(1.0); - float green = systemRandom.randf(1.0); + float red = graphicsRandom.randf(1.0); + float green = graphicsRandom.randf(1.0); //float red = 0.7; //float green = 0.9; (void) red; @@ -53,7 +53,7 @@ Fireworks::update(float ) Vector(0, 0), 45, Color(red, green, 0), 3, 1.3f, LAYER_FOREGROUND1+1)); sound_manager->play("sounds/fireworks.wav"); - timer.start(systemRandom.randf(1.0, 1.5)); + timer.start(graphicsRandom.randf(1.0, 1.5)); } } diff --git a/src/object/ghost_particle_system.cpp b/src/object/ghost_particle_system.cpp index b5373cbb4..efbac1fb2 100644 --- a/src/object/ghost_particle_system.cpp +++ b/src/object/ghost_particle_system.cpp @@ -35,11 +35,11 @@ GhostParticleSystem::GhostParticleSystem() size_t ghostcount = 2; for(size_t i=0; ipos.x = systemRandom.randf(virtual_width); - particle->pos.y = systemRandom.randf(SCREEN_HEIGHT); - int size = systemRandom.rand(2); + particle->pos.x = graphicsRandom.randf(virtual_width); + particle->pos.y = graphicsRandom.randf(SCREEN_HEIGHT); + int size = graphicsRandom.rand(2); particle->texture = ghosts[size]; - particle->speed = systemRandom.randf(std::max(50, (size * 10)), 180 + (size * 10)); + particle->speed = graphicsRandom.randf(std::max(50, (size * 10)), 180 + (size * 10)); particles.push_back(particle); } } @@ -63,7 +63,7 @@ void GhostParticleSystem::update(float elapsed_time) particle->pos.x -= particle->speed * elapsed_time; if(particle->pos.y > SCREEN_HEIGHT) { particle->pos.y = fmodf(particle->pos.y , virtual_height); - particle->pos.x = systemRandom.rand(static_cast(virtual_width)); + particle->pos.x = graphicsRandom.rand(static_cast(virtual_width)); } } } diff --git a/src/object/particles.cpp b/src/object/particles.cpp index 910136b6b..d4b1c11d7 100644 --- a/src/object/particles.cpp +++ b/src/object/particles.cpp @@ -48,7 +48,7 @@ Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, Particle* particle = new Particle; particle->pos = epicenter; - float angle = systemRandom.rand(min_angle, max_angle) + float angle = graphicsRandom.rand(min_angle, max_angle) * (M_PI / 180); // convert to radius (radians?) particle->vel.x = /*fabs*/(sin(angle)) * initial_velocity.x; // if(angle >= M_PI && angle < M_PI*2) diff --git a/src/object/player.cpp b/src/object/player.cpp index 3cc8a3c61..2ffa8ec30 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -392,9 +392,9 @@ Player::update(float elapsed_time) // when invincible, spawn particles if (invincible_timer.started()) { - if (systemRandom.rand(0, 2) == 0) { - float px = systemRandom.randf(bbox.p1.x+0, bbox.p2.x-0); - float py = systemRandom.randf(bbox.p1.y+0, bbox.p2.y-0); + if (graphicsRandom.rand(0, 2) == 0) { + float px = graphicsRandom.randf(bbox.p1.x+0, bbox.p2.x-0); + float py = graphicsRandom.randf(bbox.p1.y+0, bbox.p2.y-0); Vector ppos = Vector(px, py); Vector pspeed = Vector(0, 0); Vector paccel = Vector(0, 0); @@ -1286,8 +1286,8 @@ Player::kill(bool completely) { // the numbers: starting x, starting y, velocity y Sector::current()->add_object(new FallingCoin(get_pos() + - Vector(systemRandom.rand(5), systemRandom.rand(-32,18)), - systemRandom.rand(-100,100))); + Vector(graphicsRandom.rand(5), graphicsRandom.rand(-32,18)), + graphicsRandom.rand(-100,100))); } player_status->coins -= std::max(player_status->coins/10, 25); } @@ -1330,7 +1330,7 @@ Player::move(const Vector& vector) } void -Player::check_bounds(Camera* camera) +Player::check_bounds() { /* Keep tux in sector bounds: */ if (get_pos().x < 0) { @@ -1350,17 +1350,6 @@ Player::check_bounds(Camera* camera) kill(true); return; } - - // can happen if back scrolling is disabled - if(get_pos().x < camera->get_translation().x) { - set_pos(Vector(camera->get_translation().x, get_pos().y)); - } - if(get_pos().x >= camera->get_translation().x + SCREEN_WIDTH - bbox.get_width()) - { - set_pos(Vector( - camera->get_translation().x + SCREEN_WIDTH - bbox.get_width(), - get_pos().y)); - } } void diff --git a/src/object/player.hpp b/src/object/player.hpp index 4d63ef912..b59345561 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -96,7 +96,7 @@ public: } void kill(bool completely); - void check_bounds(Camera* camera); + void check_bounds(); void move(const Vector& vector); virtual bool add_bonus(const std::string& bonus); diff --git a/src/object/pulsing_light.cpp b/src/object/pulsing_light.cpp index 75848d870..2fff27cf3 100644 --- a/src/object/pulsing_light.cpp +++ b/src/object/pulsing_light.cpp @@ -29,7 +29,7 @@ PulsingLight::PulsingLight(const Vector& center, float cycle_len, float min_alph assert(cycle_len > 0); // start with random phase offset - t = systemRandom.randf(0.0, cycle_len); + t = gameRandom.randf(0.0, cycle_len); } PulsingLight::~PulsingLight() diff --git a/src/object/rain_particle_system.cpp b/src/object/rain_particle_system.cpp index bb9d7d8ce..4beda1c9c 100644 --- a/src/object/rain_particle_system.cpp +++ b/src/object/rain_particle_system.cpp @@ -32,12 +32,12 @@ RainParticleSystem::RainParticleSystem() size_t raindropcount = size_t(virtual_width/6.0); for(size_t i=0; ipos.x = systemRandom.rand(int(virtual_width)); - particle->pos.y = systemRandom.rand(int(virtual_height)); - int rainsize = systemRandom.rand(2); + particle->pos.x = graphicsRandom.rand(int(virtual_width)); + particle->pos.y = graphicsRandom.rand(int(virtual_height)); + int rainsize = graphicsRandom.rand(2); particle->texture = rainimages[rainsize]; do { - particle->speed = (rainsize+1)*45 + systemRandom.randf(3.6); + particle->speed = (rainsize+1)*45 + graphicsRandom.randf(3.6); } while(particle->speed < 1); particle->speed *= 10; // gravity @@ -84,7 +84,7 @@ void RainParticleSystem::update(float elapsed_time) Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical)); } */ } - int new_x = systemRandom.rand(int(virtual_width)) + int(abs_x); + int new_x = graphicsRandom.rand(int(virtual_width)) + int(abs_x); int new_y = 0; //FIXME: Don't move particles over solid tiles particle->pos.x = new_x; diff --git a/src/object/skull_tile.cpp b/src/object/skull_tile.cpp index 5ad5eabd5..9aff79fc6 100644 --- a/src/object/skull_tile.cpp +++ b/src/object/skull_tile.cpp @@ -49,7 +49,7 @@ SkullTile::draw(DrawingContext& context) Vector pos = get_pos(); // shaking if(timer.get_timegone() > CRACKTIME) { - pos.x += systemRandom.rand(-3, 3); + pos.x += graphicsRandom.rand(-3, 3); } sprite->draw(context, pos, layer); diff --git a/src/object/snow_particle_system.cpp b/src/object/snow_particle_system.cpp index d2037c410..9dedc5e91 100644 --- a/src/object/snow_particle_system.cpp +++ b/src/object/snow_particle_system.cpp @@ -51,23 +51,23 @@ SnowParticleSystem::SnowParticleSystem() : size_t snowflakecount = size_t(virtual_width/10.0); for(size_t i=0; ipos.x = systemRandom.randf(virtual_width); - particle->pos.y = systemRandom.randf(SCREEN_HEIGHT); - particle->anchorx = particle->pos.x + (systemRandom.randf(-0.5, 0.5) * 16); + particle->pos.x = graphicsRandom.randf(virtual_width); + particle->pos.y = graphicsRandom.randf(SCREEN_HEIGHT); + particle->anchorx = particle->pos.x + (graphicsRandom.randf(-0.5, 0.5) * 16); // drift will change with wind gusts - particle->drift_speed = systemRandom.randf(-0.5, 0.5) * 0.3; + particle->drift_speed = graphicsRandom.randf(-0.5, 0.5) * 0.3; particle->wobble = 0.0; particle->texture = snowimages[snowsize]; particle->flake_size = powf(snowsize+3,4); // since it ranges from 0 to 2 - particle->speed = 2 * (1 + (2 - snowsize)/2 + systemRandom.randf(1.8)) * 10; // gravity + particle->speed = 2 * (1 + (2 - snowsize)/2 + graphicsRandom.randf(1.8)) * 10; // gravity // Spinning - particle->angle = systemRandom.randf(360.0); - particle->spin_speed = systemRandom.randf(-SNOW::SPIN_SPEED,SNOW::SPIN_SPEED); + particle->angle = graphicsRandom.randf(360.0); + particle->spin_speed = graphicsRandom.randf(-SNOW::SPIN_SPEED,SNOW::SPIN_SPEED); particles.push_back(particle); } @@ -95,9 +95,9 @@ void SnowParticleSystem::update(float elapsed_time) // stop wind gust_current_velocity = 0; // new wind strength - gust_onset = systemRandom.randf(-SNOW::WIND_SPEED, SNOW::WIND_SPEED); + gust_onset = graphicsRandom.randf(-SNOW::WIND_SPEED, SNOW::WIND_SPEED); } - timer.start(systemRandom.randf(SNOW::STATE_LENGTH)); + timer.start(graphicsRandom.randf(SNOW::STATE_LENGTH)); } // Update velocities @@ -129,12 +129,12 @@ void SnowParticleSystem::update(float elapsed_time) // Falling particle->pos.y += particle->speed * elapsed_time; // Drifting (speed approaches wind at a rate dependent on flake size) - particle->drift_speed += (gust_current_velocity - particle->drift_speed) / particle->flake_size + systemRandom.randf(-SNOW::EPSILON,SNOW::EPSILON); + particle->drift_speed += (gust_current_velocity - particle->drift_speed) / particle->flake_size + graphicsRandom.randf(-SNOW::EPSILON,SNOW::EPSILON); particle->anchorx += particle->drift_speed * elapsed_time; // Wobbling (particle approaches anchorx) particle->pos.x += particle->wobble * elapsed_time; anchor_delta = (particle->anchorx - particle->pos.x); - particle->wobble += (SNOW::WOBBLE_FACTOR * anchor_delta) + systemRandom.randf(-SNOW::EPSILON, SNOW::EPSILON); + particle->wobble += (SNOW::WOBBLE_FACTOR * anchor_delta) + graphicsRandom.randf(-SNOW::EPSILON, SNOW::EPSILON); particle->wobble *= SNOW::WOBBLE_DECAY; // Spinning particle->angle += particle->spin_speed * elapsed_time; diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index 43a100f27..23b3fee07 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -185,7 +185,7 @@ TileMap::update(float elapsed_time) // if we have a path to follow, follow it if (walker.get()) { Vector v = walker->advance(elapsed_time); - movement = Vector(v.x-get_offset().x, std::max(0.0f,v.y-get_offset().y)); + movement = v - get_offset(); set_offset(v); } } diff --git a/src/object/tilemap.hpp b/src/object/tilemap.hpp index c2b61dd05..28f9407d4 100644 --- a/src/object/tilemap.hpp +++ b/src/object/tilemap.hpp @@ -76,9 +76,13 @@ public: Vector get_offset() const { return offset; } - const Vector& get_movement() const + Vector get_movement(bool actual = false) const { - return movement; + if(actual) { + return movement; + } else { + return Vector(movement.x, std::max(0.0f,movement.y)); + } } Path *get_path() diff --git a/src/object/wind.cpp b/src/object/wind.cpp index 49c5a9730..6dc3e0496 100644 --- a/src/object/wind.cpp +++ b/src/object/wind.cpp @@ -60,9 +60,9 @@ Wind::update(float elapsed_time) if (!blowing) return; // TODO: nicer, configurable particles for wind? - if (systemRandom.rand(0, 100) < 20) { + if (graphicsRandom.rand(0, 100) < 20) { // emit a particle - Vector ppos = Vector(systemRandom.randf(bbox.p1.x+8, bbox.p2.x-8), systemRandom.randf(bbox.p1.y+8, bbox.p2.y-8)); + Vector ppos = Vector(graphicsRandom.randf(bbox.p1.x+8, bbox.p2.x-8), graphicsRandom.randf(bbox.p1.y+8, bbox.p2.y-8)); Vector pspeed = Vector(speed.x, speed.y); Sector::current()->add_object(new Particles(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f, LAYER_BACKGROUNDTILES+1)); diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 4fb1a6aa1..24b6b3329 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -282,7 +282,7 @@ void quit() int rand() { - return systemRandom.rand(); + return gameRandom.rand(); } void set_game_speed(float speed) @@ -310,7 +310,7 @@ void play_demo(const std::string& filename) } // Reset random seed g_config->random_seed = GameSession::current()->get_demo_random_seed(filename); - g_config->random_seed = systemRandom.srand(g_config->random_seed); + g_config->random_seed = gameRandom.srand(g_config->random_seed); GameSession::current()->restart_level(); GameSession::current()->play_demo(filename); } diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index d4df670f1..88f770460 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -132,8 +132,8 @@ GameSession::restart_level() if(capture_file != "") { int newSeed=0; // next run uses a new seed while (newSeed == 0) // which is the next non-zero random num. - newSeed = systemRandom.rand(); - g_config->random_seed = systemRandom.srand(newSeed); + newSeed = gameRandom.rand(); + g_config->random_seed = gameRandom.srand(newSeed); log_info << "Next run uses random seed " << g_config->random_seed <create("images/creatures/tux/tux.sprite"); player_sprite->set_action("small-walk-right"); - player_sprite_jump_timer.start(systemRandom.randf(5,10)); + player_sprite_jump_timer.start(graphicsRandom.randf(5,10)); } LevelIntro::~LevelIntro() @@ -69,7 +69,7 @@ LevelIntro::update(float elapsed_time) } if (player_sprite_jump_timer.check()) { player_sprite_vy = -300; - player_sprite_jump_timer.start(systemRandom.randf(2,3)); + player_sprite_jump_timer.start(graphicsRandom.randf(2,3)); } } diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 98a6cc3d6..ab5b4713f 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -420,7 +420,9 @@ Main::init_sdl() void Main::init_rand() { - g_config->random_seed = systemRandom.srand(g_config->random_seed); + g_config->random_seed = gameRandom.srand(g_config->random_seed); + + graphicsRandom.srand(0); //const char *how = config->random_seed? ", user fixed.": ", from time()."; //log_info << "Using random seed " << config->random_seed << how << std::endl; diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index a724e8e85..65b0f0b80 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -514,15 +514,11 @@ Sector::add_object(GameObject* object) #ifndef NDEBUG for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) { - if(*i == object) { - assert("object already added to sector" == 0); - } + assert(*i != object); } for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i) { - if(*i == object) { - assert("object already added to sector" == 0); - } + assert(*i != object); } #endif @@ -652,7 +648,7 @@ Sector::get_active_region() void Sector::update(float elapsed_time) { - player->check_bounds(camera); + player->check_bounds(); /* update objects */ for(GameObjects::iterator i = gameobjects.begin(); @@ -1156,6 +1152,7 @@ int check_position_unisolid (const Rectf& obj_bbox, default: assert (23 == 42); + return POS_NON_SOLID; } /* delta_x, delta_y: Gradient aware version of SHIFT_DELTA. Here, we set the @@ -1281,7 +1278,7 @@ Sector::collision_tilemap(collision::Constraints* constraints, * in quotation marks because because the slope's gradient is taken * Also, this uses the movement relative to the tilemaps own movement * (if any). --octo */ - status = check_movement_unisolid (movement - solids->get_movement(), tile); + status = check_movement_unisolid (movement - solids->get_movement(true), tile); /* If zero is returned, the unisolid tile is non-solid. */ if (status == 0) continue; diff --git a/src/video/color.hpp b/src/video/color.hpp index 05d176c7c..a3c360eb3 100644 --- a/src/video/color.hpp +++ b/src/video/color.hpp @@ -38,9 +38,9 @@ public: blue(blue_), alpha(alpha_) { -#ifndef NDEBUG - check_color_ranges(); -#endif + assert(0 <= red && red <= 1.0); + assert(0 <= green && green <= 1.0); + assert(0 <= blue && blue <= 1.0); } Color(const std::vector& vals) : @@ -57,9 +57,9 @@ public: alpha = vals[3]; else alpha = 1.0; -#ifndef NDEBUG - check_color_ranges(); -#endif + assert(0 <= red && red <= 1.0); + assert(0 <= green && green <= 1.0); + assert(0 <= blue && blue <= 1.0); } bool operator==(const Color& other) const @@ -68,14 +68,6 @@ public: && alpha == other.alpha; } - void check_color_ranges() - { - if(red < 0 || red > 1.0 || green < 0 || green > 1.0 - || blue < 0 || blue > 1.0 - || alpha < 0 || alpha > 1.0) - log_warning << "color value out of range: " << red << ", " << green << ", " << blue << ", " << alpha << std::endl; - } - float greyscale() const { return red * 0.30 + green * 0.59 + blue * 0.11;