From 75fc1b8f0bd2cc8ba9f448678d46db1e882b40a9 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sun, 17 Aug 2014 20:20:35 +0200 Subject: [PATCH] Turned a lot of other global objects into Currentons --- src/audio/sound_manager.hpp | 3 +- src/audio/stream_sound_source.cpp | 4 +- src/badguy/badguy.cpp | 16 +++--- src/badguy/bomb.cpp | 2 +- src/badguy/dart.cpp | 20 ++++---- src/badguy/darttrap.cpp | 4 +- src/badguy/dispenser.cpp | 4 +- src/badguy/flame.cpp | 8 +-- src/badguy/ghostflame.cpp | 4 +- src/badguy/ghosttree.cpp | 10 ++-- src/badguy/goldbomb.cpp | 6 +-- src/badguy/haywire.cpp | 8 +-- src/badguy/iceflame.cpp | 6 +-- src/badguy/jumpy.cpp | 4 +- src/badguy/kamikazesnowball.cpp | 6 +-- src/badguy/kugelblitz.cpp | 2 +- src/badguy/livefire.cpp | 4 +- src/badguy/mole.cpp | 18 +++---- src/badguy/mole_rock.cpp | 14 +++--- src/badguy/mrbomb.cpp | 6 +-- src/badguy/mriceblock.cpp | 20 ++++---- src/badguy/mrtree.cpp | 4 +- src/badguy/owl.cpp | 2 +- src/badguy/root.cpp | 2 +- src/badguy/short_fuse.cpp | 2 +- src/badguy/skullyhop.cpp | 6 +-- src/badguy/snail.cpp | 18 +++---- src/badguy/snowman.cpp | 6 +-- src/badguy/stalactite.cpp | 14 +++--- src/badguy/stumpy.cpp | 6 +-- src/badguy/toad.cpp | 6 +-- src/badguy/totem.cpp | 4 +- src/badguy/treewillowisp.cpp | 4 +- src/badguy/willowisp.cpp | 10 ++-- src/badguy/yeti.cpp | 8 +-- src/control/input_manager.hpp | 3 +- src/gui/menu.cpp | 2 +- src/gui/menu_manager.cpp | 2 +- src/object/ambient_sound.cpp | 6 +-- src/object/block.cpp | 4 +- src/object/bonus_block.cpp | 44 ++++++++-------- src/object/bouncy_coin.cpp | 2 +- src/object/brick.cpp | 4 +- src/object/bullet.cpp | 8 +-- src/object/candle.cpp | 4 +- src/object/coin.cpp | 20 ++++---- src/object/coin_rain.cpp | 2 +- src/object/endsequence_fireworks.cpp | 2 +- src/object/endsequence_walkleft.cpp | 2 +- src/object/endsequence_walkright.cpp | 2 +- src/object/explosion.cpp | 14 +++--- src/object/falling_coin.cpp | 2 +- src/object/firefly.cpp | 10 ++-- src/object/fireworks.cpp | 4 +- src/object/floating_image.cpp | 2 +- src/object/flower.cpp | 12 ++--- src/object/growup.cpp | 8 +-- src/object/icecrusher.cpp | 14 +++--- src/object/infoblock.cpp | 2 +- src/object/invisible_block.cpp | 6 +-- src/object/lantern.cpp | 12 ++--- src/object/light.cpp | 2 +- src/object/moving_sprite.cpp | 8 +-- src/object/player.cpp | 38 +++++++------- src/object/powerup.cpp | 18 +++---- src/object/pushbutton.cpp | 4 +- src/object/rainsplash.cpp | 4 +- src/object/rock.cpp | 8 +-- src/object/rusty_trampoline.cpp | 6 +-- src/object/smoke_cloud.cpp | 2 +- src/object/spotlight.cpp | 10 ++-- src/object/sprite_particle.cpp | 4 +- src/object/star.cpp | 2 +- src/object/thunderstorm.cpp | 8 +-- src/object/trampoline.cpp | 12 ++--- src/object/weak_block.cpp | 10 ++-- src/scripting/functions.cpp | 24 ++++----- src/sprite/sprite_manager.hpp | 3 +- src/supertux/game_manager.cpp | 4 +- src/supertux/game_session.cpp | 32 ++++++------ src/supertux/gameconfig.cpp | 8 +-- src/supertux/globals.cpp | 17 ++----- src/supertux/globals.hpp | 28 ++--------- src/supertux/level.cpp | 8 +-- src/supertux/levelintro.cpp | 6 +-- src/supertux/levelset_screen.cpp | 4 +- src/supertux/main.cpp | 78 ++++++++++------------------- src/supertux/main.hpp | 2 - src/supertux/menu/contrib_levelset_menu.cpp | 2 +- src/supertux/menu/joystick_menu.cpp | 26 +++++----- src/supertux/menu/joystick_menu.hpp | 4 +- src/supertux/menu/keyboard_menu.cpp | 12 ++--- src/supertux/menu/keyboard_menu.hpp | 6 ++- src/supertux/menu/language_menu.cpp | 10 ++-- src/supertux/menu/main_menu.cpp | 6 +-- src/supertux/menu/menu_storage.cpp | 4 +- src/supertux/menu/options_menu.cpp | 6 +-- src/supertux/menu/worldmap_menu.cpp | 2 +- src/supertux/player_status.cpp | 8 +-- src/supertux/resources.cpp | 57 ++++++--------------- src/supertux/resources.hpp | 4 +- src/supertux/screen_manager.cpp | 6 +-- src/supertux/screen_manager.hpp | 3 +- src/supertux/sector.cpp | 12 ++--- src/supertux/textscroller.cpp | 8 +-- src/supertux/tile_manager.hpp | 3 +- src/supertux/title_screen.cpp | 4 +- src/trigger/door.cpp | 10 ++-- src/trigger/switch.cpp | 6 +-- src/util/gettext.hpp | 7 ++- src/video/gl/gl_lightmap.cpp | 2 +- src/video/gl/gl_renderer.cpp | 8 --- src/video/gl/gl_video_system.cpp | 4 +- src/video/gl/gl_video_system.hpp | 3 ++ src/video/sdl/sdl_renderer.cpp | 3 -- src/video/sdl/sdl_video_system.cpp | 3 +- src/video/sdl/sdl_video_system.hpp | 3 ++ src/video/surface.cpp | 4 +- src/video/texture.hpp | 4 +- src/video/texture_manager.hpp | 3 +- src/worldmap/level.cpp | 2 +- src/worldmap/special_tile.cpp | 2 +- src/worldmap/sprite_change.cpp | 2 +- src/worldmap/teleporter.cpp | 2 +- src/worldmap/tux.cpp | 4 +- src/worldmap/worldmap.cpp | 20 ++++---- 126 files changed, 502 insertions(+), 577 deletions(-) diff --git a/src/audio/sound_manager.hpp b/src/audio/sound_manager.hpp index da042c639..8c699d4a5 100644 --- a/src/audio/sound_manager.hpp +++ b/src/audio/sound_manager.hpp @@ -26,13 +26,14 @@ #include #include "math/vector.hpp" +#include "util/currenton.hpp" class SoundFile; class SoundSource; class StreamSoundSource; class OpenALSoundSource; -class SoundManager +class SoundManager : public Currenton { public: SoundManager(); diff --git a/src/audio/stream_sound_source.cpp b/src/audio/stream_sound_source.cpp index 2c060598d..e813b7d7d 100644 --- a/src/audio/stream_sound_source.cpp +++ b/src/audio/stream_sound_source.cpp @@ -30,13 +30,13 @@ StreamSoundSource::StreamSoundSource() : alGenBuffers(STREAMFRAGMENTS, buffers); SoundManager::check_al_error("Couldn't allocate audio buffers: "); //add me to update list - sound_manager->register_for_update( this ); + SoundManager::current()->register_for_update( this ); } StreamSoundSource::~StreamSoundSource() { //don't update me any longer - sound_manager->remove_from_update( this ); + SoundManager::current()->remove_from_update( this ); file.reset(); stop(); alDeleteBuffers(STREAMFRAGMENTS, buffers); diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index b0ffd2059..0b397c95e 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -53,8 +53,8 @@ BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name_, int layer_) : { start_position = bbox.p1; - sound_manager->preload("sounds/squish.wav"); - sound_manager->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/squish.wav"); + SoundManager::current()->preload("sounds/fall.wav"); dir = (start_dir == AUTO) ? LEFT : start_dir; } @@ -79,8 +79,8 @@ BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite { start_position = bbox.p1; - sound_manager->preload("sounds/squish.wav"); - sound_manager->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/squish.wav"); + SoundManager::current()->preload("sounds/fall.wav"); dir = (start_dir == AUTO) ? LEFT : start_dir; } @@ -112,8 +112,8 @@ BadGuy::BadGuy(const Reader& reader, const std::string& sprite_name_, int layer_ reader.get("dead-script", dead_script); - sound_manager->preload("sounds/squish.wav"); - sound_manager->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/squish.wav"); + SoundManager::current()->preload("sounds/fall.wav"); dir = (start_dir == AUTO) ? LEFT : start_dir; } @@ -386,7 +386,7 @@ BadGuy::kill_squished(GameObject& object) { if (!is_active()) return; - sound_manager->play("sounds/squish.wav", get_pos()); + SoundManager::current()->play("sounds/squish.wav", get_pos()); physic.enable_gravity(true); physic.set_velocity_x(0); physic.set_velocity_y(0); @@ -406,7 +406,7 @@ BadGuy::kill_fall() { if (!is_active()) return; - sound_manager->play("sounds/fall.wav", get_pos()); + SoundManager::current()->play("sounds/fall.wav", get_pos()); physic.set_velocity_y(0); physic.set_acceleration_y(0); physic.enable_gravity(true); diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index a16a9f03d..629b75b57 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -32,7 +32,7 @@ Bomb::Bomb(const Vector& pos, Direction dir_, std::string custom_sprite /*= "ima set_action(dir_ == LEFT ? "ticking-left" : "ticking-right", 1); countMe = false; - ticking = sound_manager->create_sound_source("sounds/fizz.wav"); + ticking = SoundManager::current()->create_sound_source("sounds/fizz.wav"); ticking->set_position(get_pos()); ticking->set_looping(true); ticking->set_gain(2.0); diff --git a/src/badguy/dart.cpp b/src/badguy/dart.cpp index c75bea182..37389fca5 100644 --- a/src/badguy/dart.cpp +++ b/src/badguy/dart.cpp @@ -34,9 +34,9 @@ Dart::Dart(const Reader& reader) : { physic.enable_gravity(false); countMe = false; - sound_manager->preload(DART_SOUND); - sound_manager->preload("sounds/darthit.wav"); - sound_manager->preload("sounds/stomp.wav"); + SoundManager::current()->preload(DART_SOUND); + SoundManager::current()->preload("sounds/darthit.wav"); + SoundManager::current()->preload("sounds/stomp.wav"); } Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent_ = 0) : @@ -46,9 +46,9 @@ Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent_ = 0) : { physic.enable_gravity(false); countMe = false; - sound_manager->preload(DART_SOUND); - sound_manager->preload("sounds/darthit.wav"); - sound_manager->preload("sounds/stomp.wav"); + SoundManager::current()->preload(DART_SOUND); + SoundManager::current()->preload("sounds/darthit.wav"); + SoundManager::current()->preload("sounds/stomp.wav"); } Dart::~Dart() @@ -75,7 +75,7 @@ Dart::initialize() void Dart::activate() { - sound_source = sound_manager->create_sound_source(DART_SOUND); + sound_source = SoundManager::current()->create_sound_source(DART_SOUND); sound_source->set_position(get_pos()); sound_source->set_looping(true); sound_source->set_gain(1.0); @@ -100,7 +100,7 @@ Dart::active_update(float elapsed_time) void Dart::collision_solid(const CollisionHit& ) { - sound_manager->play("sounds/darthit.wav", get_pos()); + SoundManager::current()->play("sounds/darthit.wav", get_pos()); remove_me(); } @@ -111,7 +111,7 @@ Dart::collision_badguy(BadGuy& badguy, const CollisionHit& ) if (&badguy == parent) { return FORCE_MOVE; } - sound_manager->play("sounds/stomp.wav", get_pos()); + SoundManager::current()->play("sounds/stomp.wav", get_pos()); remove_me(); badguy.kill_fall(); return ABORT_MOVE; @@ -120,7 +120,7 @@ Dart::collision_badguy(BadGuy& badguy, const CollisionHit& ) HitResponse Dart::collision_player(Player& player, const CollisionHit& hit) { - sound_manager->play("sounds/stomp.wav", get_pos()); + SoundManager::current()->play("sounds/stomp.wav", get_pos()); remove_me(); return BadGuy::collision_player(player, hit); } diff --git a/src/badguy/darttrap.cpp b/src/badguy/darttrap.cpp index c07d447e3..3885cb684 100644 --- a/src/badguy/darttrap.cpp +++ b/src/badguy/darttrap.cpp @@ -39,7 +39,7 @@ DartTrap::DartTrap(const Reader& reader) : reader.get("fire-delay", fire_delay); reader.get("ammo", ammo); countMe = false; - sound_manager->preload("sounds/dartfire.wav"); + SoundManager::current()->preload("sounds/dartfire.wav"); if (start_dir == AUTO) { log_warning << "Setting a DartTrap's direction to AUTO is no good idea" << std::endl; } state = IDLE; set_colgroup_active(COLGROUP_DISABLED); @@ -96,7 +96,7 @@ DartTrap::fire() float py = get_pos().y; py += MUZZLE_Y; - sound_manager->play("sounds/dartfire.wav", get_pos()); + SoundManager::current()->play("sounds/dartfire.wav", get_pos()); Sector::current()->add_object(new Dart(Vector(px, py), dir, this)); state = IDLE; sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index 542d0f550..e3deca06a 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -39,7 +39,7 @@ Dispenser::Dispenser(const Reader& reader) : type() { set_colgroup_active(COLGROUP_MOVING_STATIC); - sound_manager->preload("sounds/squish.wav"); + SoundManager::current()->preload("sounds/squish.wav"); reader.get("cycle", cycle); reader.get("badguy", badguys); random = false; // default @@ -111,7 +111,7 @@ Dispenser::collision_squished(GameObject& object) if (player){ player->bounce(*this); } - sound_manager->play("sounds/squish.wav", get_pos()); + SoundManager::current()->play("sounds/squish.wav", get_pos()); broken = true; return true; } diff --git a/src/badguy/flame.cpp b/src/badguy/flame.cpp index 0539577de..66ce6d316 100644 --- a/src/badguy/flame.cpp +++ b/src/badguy/flame.cpp @@ -35,7 +35,7 @@ Flame::Flame(const Reader& reader) : radius(100), speed(2), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")), + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")), sound_source() { reader.get("radius", radius); @@ -43,7 +43,7 @@ Flame::Flame(const Reader& reader) : bbox.set_pos(Vector(start_position.x + cos(angle) * radius, start_position.y + sin(angle) * radius)); countMe = false; - sound_manager->preload(FLAME_SOUND); + SoundManager::current()->preload(FLAME_SOUND); set_colgroup_active(COLGROUP_TOUCHABLE); @@ -85,7 +85,7 @@ Flame::draw(DrawingContext& context) void Flame::activate() { - sound_source = sound_manager->create_sound_source(FLAME_SOUND); + sound_source = SoundManager::current()->create_sound_source(FLAME_SOUND); sound_source->set_position(get_pos()); sound_source->set_looping(true); sound_source->set_gain(2.0); @@ -108,7 +108,7 @@ Flame::kill_fall() void Flame::freeze() { - sound_manager->play("sounds/sizzle.ogg", get_pos()); + SoundManager::current()->play("sounds/sizzle.ogg", get_pos()); sprite->set_action("fade", 1); Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", bbox.get_middle(), ANCHOR_MIDDLE, Vector(0, -150), Vector(0,0), LAYER_BACKGROUNDTILES+2)); set_group(COLGROUP_DISABLED); diff --git a/src/badguy/ghostflame.cpp b/src/badguy/ghostflame.cpp index 843f9d848..d5a717066 100644 --- a/src/badguy/ghostflame.cpp +++ b/src/badguy/ghostflame.cpp @@ -33,7 +33,7 @@ Ghostflame::Ghostflame(const Reader& reader) : radius(100), speed(2), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { reader.get("radius", radius); reader.get("speed", speed); @@ -41,7 +41,7 @@ Ghostflame::Ghostflame(const Reader& reader) : start_position.y + sin(angle) * radius)); countMe = false; //TODO: get unique death sound - sound_manager->preload("sounds/fizz.wav"); + SoundManager::current()->preload("sounds/fizz.wav"); set_colgroup_active(COLGROUP_TOUCHABLE); diff --git a/src/badguy/ghosttree.cpp b/src/badguy/ghosttree.cpp index 8ae325902..4e8832be1 100644 --- a/src/badguy/ghosttree.cpp +++ b/src/badguy/ghosttree.cpp @@ -53,10 +53,10 @@ GhostTree::GhostTree(const Reader& lisp) : suck_lantern(0), willowisps() { - glow_sprite = sprite_manager->create("images/creatures/ghosttree/ghosttree-glow.sprite"); + glow_sprite = SpriteManager::current()->create("images/creatures/ghosttree/ghosttree-glow.sprite"); set_colgroup_active(COLGROUP_TOUCHABLE); - sound_manager->preload("sounds/tree_howling.ogg"); - sound_manager->preload("sounds/tree_suck.ogg"); + SoundManager::current()->preload("sounds/tree_howling.ogg"); + SoundManager::current()->preload("sounds/tree_suck.ogg"); } GhostTree::~GhostTree() @@ -93,7 +93,7 @@ GhostTree::active_update(float elapsed_time) if (mystate == STATE_IDLE) { if(colorchange_timer.check()) { - sound_manager->play("sounds/tree_howling.ogg", get_pos()); + SoundManager::current()->play("sounds/tree_howling.ogg", get_pos()); suck_timer.start(3); treecolor = (treecolor + 1) % 3; @@ -112,7 +112,7 @@ GhostTree::active_update(float elapsed_time) if(suck_timer.check()) { Color col = glow_sprite->get_color(); - sound_manager->play("sounds/tree_suck.ogg", get_pos()); + SoundManager::current()->play("sounds/tree_suck.ogg", get_pos()); std::vector::iterator iter; for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) { TreeWillOWisp *willo = *iter; diff --git a/src/badguy/goldbomb.cpp b/src/badguy/goldbomb.cpp index 3569fe3a0..67c8002e4 100644 --- a/src/badguy/goldbomb.cpp +++ b/src/badguy/goldbomb.cpp @@ -38,7 +38,7 @@ GoldBomb::GoldBomb(const Reader& reader) : max_drop_height = 16; //Prevent stutter when Tux jumps on Gold Bomb - sound_manager->preload("sounds/explosion.wav"); + SoundManager::current()->preload("sounds/explosion.wav"); //Check if we need another sprite if( !reader.get( "sprite", sprite_name ) ){ @@ -49,7 +49,7 @@ GoldBomb::GoldBomb(const Reader& reader) : return; } //Replace sprite - sprite = sprite_manager->create( sprite_name ); + sprite = SpriteManager::current()->create( sprite_name ); } void @@ -114,7 +114,7 @@ GoldBomb::collision_squished(GameObject& object) if (player) player->bounce(*this); - ticking = sound_manager->create_sound_source("sounds/fizz.wav"); + ticking = SoundManager::current()->create_sound_source("sounds/fizz.wav"); ticking->set_position(get_pos()); ticking->set_looping(true); ticking->set_gain(2.0); diff --git a/src/badguy/haywire.cpp b/src/badguy/haywire.cpp index 9620b70f4..f3d7242b2 100644 --- a/src/badguy/haywire.cpp +++ b/src/badguy/haywire.cpp @@ -42,7 +42,7 @@ Haywire::Haywire(const Reader& reader) : max_drop_height = 16; //Prevent stutter when Tux jumps on Mr Bomb - sound_manager->preload("sounds/explosion.wav"); + SoundManager::current()->preload("sounds/explosion.wav"); //Check if we need another sprite if( !reader.get( "sprite", sprite_name ) ){ @@ -53,7 +53,7 @@ Haywire::Haywire(const Reader& reader) : return; } //Replace sprite - sprite = sprite_manager->create( sprite_name ); + sprite = SpriteManager::current()->create( sprite_name ); } HitResponse @@ -96,12 +96,12 @@ Haywire::collision_squished(GameObject& object) time_until_explosion = TIME_EXPLOSION; is_exploding = true; - ticking = sound_manager->create_sound_source("sounds/fizz.wav"); + ticking = SoundManager::current()->create_sound_source("sounds/fizz.wav"); ticking->set_position(get_pos()); ticking->set_looping(true); ticking->set_reference_distance(32); ticking->play(); - grunting = sound_manager->create_sound_source("sounds/grunts.ogg"); + grunting = SoundManager::current()->create_sound_source("sounds/grunts.ogg"); grunting->set_position(get_pos()); grunting->set_looping(true); grunting->set_reference_distance(32); diff --git a/src/badguy/iceflame.cpp b/src/badguy/iceflame.cpp index 46b5e8597..630da0a44 100644 --- a/src/badguy/iceflame.cpp +++ b/src/badguy/iceflame.cpp @@ -33,14 +33,14 @@ Iceflame::Iceflame(const Reader& reader) : radius(100), speed(2), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { reader.get("radius", radius); reader.get("speed", speed); bbox.set_pos(Vector(start_position.x + cos(angle) * radius, start_position.y + sin(angle) * radius)); countMe = false; - sound_manager->preload("sounds/sizzle.ogg"); + SoundManager::current()->preload("sounds/sizzle.ogg"); set_colgroup_active(COLGROUP_TOUCHABLE); @@ -86,7 +86,7 @@ Iceflame::kill_fall() void Iceflame::ignite() { - sound_manager->play("sounds/sizzle.ogg", get_pos()); + SoundManager::current()->play("sounds/sizzle.ogg", get_pos()); sprite->set_action("fade", 1); Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", bbox.get_middle(), ANCHOR_MIDDLE, Vector(0, -150), Vector(0,0), LAYER_BACKGROUNDTILES+2)); set_group(COLGROUP_DISABLED); diff --git a/src/badguy/jumpy.cpp b/src/badguy/jumpy.cpp index 6b04ebbb4..7a6eaaadd 100644 --- a/src/badguy/jumpy.cpp +++ b/src/badguy/jumpy.cpp @@ -30,7 +30,7 @@ Jumpy::Jumpy(const Reader& reader) : groundhit_pos_set(false) { // TODO create a nice sound for this... - //sound_manager->preload("sounds/skid.wav"); + //SoundManager::current()->preload("sounds/skid.wav"); } void @@ -57,7 +57,7 @@ Jumpy::hit(const CollisionHit& chit) physic.set_velocity_y((frozen || get_state() == STATE_FALLING) ? 0 : JUMPYSPEED); // TODO create a nice sound for this... - //sound_manager->play("sounds/skid.wav"); + //SoundManager::current()->play("sounds/skid.wav"); } else if(chit.top) { physic.set_velocity_y(0); } diff --git a/src/badguy/kamikazesnowball.cpp b/src/badguy/kamikazesnowball.cpp index b82a53311..49ae58239 100644 --- a/src/badguy/kamikazesnowball.cpp +++ b/src/badguy/kamikazesnowball.cpp @@ -32,14 +32,14 @@ namespace{ KamikazeSnowball::KamikazeSnowball(const Reader& reader) : BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite") { - sound_manager->preload(SPLAT_SOUND); + SoundManager::current()->preload(SPLAT_SOUND); set_action (dir == LEFT ? "left" : "right", /* loops = */ -1); } KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d) : BadGuy(pos, d, "images/creatures/snowball/kamikaze-snowball.sprite") { - sound_manager->preload(SPLAT_SOUND); + SoundManager::current()->preload(SPLAT_SOUND); set_action (dir == LEFT ? "left" : "right", /* loops = */ -1); } @@ -74,7 +74,7 @@ void KamikazeSnowball::kill_collision() { sprite->set_action(dir == LEFT ? "collision-left" : "collision-right"); - sound_manager->play(SPLAT_SOUND, get_pos()); + SoundManager::current()->play(SPLAT_SOUND, get_pos()); physic.set_velocity_x(0); physic.set_velocity_y(0); physic.enable_gravity(true); diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index 7437ca370..da2c6e024 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -42,7 +42,7 @@ Kugelblitz::Kugelblitz(const Reader& reader) : direction(), state(), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light.sprite")) { reader.get("x", start_position.x); sprite->set_action("falling"); diff --git a/src/badguy/livefire.cpp b/src/badguy/livefire.cpp index d62d036f5..55c91ad6e 100644 --- a/src/badguy/livefire.cpp +++ b/src/badguy/livefire.cpp @@ -25,7 +25,7 @@ LiveFire::LiveFire(const Reader& reader) : WalkingBadguy(reader, "images/creatures/livefire/livefire.sprite", "left", "right"), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-medium.sprite")), + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-medium.sprite")), death_sound("sounds/fall.wav"), state(STATE_WALKING) { @@ -131,7 +131,7 @@ LiveFire::is_flammable() const void LiveFire::kill_fall() { - sound_manager->play(death_sound, get_pos()); + SoundManager::current()->play(death_sound, get_pos()); // throw a puff of smoke Vector ppos = bbox.get_middle(); Vector pspeed = Vector(0, -150); diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index 2921ddbeb..f6ab193cc 100644 --- a/src/badguy/mole.cpp +++ b/src/badguy/mole.cpp @@ -36,9 +36,9 @@ Mole::Mole(const Reader& reader) : throw_timer() { physic.enable_gravity(false); - sound_manager->preload("sounds/fall.wav"); - sound_manager->preload("sounds/squish.wav"); - sound_manager->preload("sounds/dartfire.wav"); + SoundManager::current()->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/squish.wav"); + SoundManager::current()->preload("sounds/dartfire.wav"); } Mole::Mole(const Vector& pos) : @@ -48,9 +48,9 @@ Mole::Mole(const Vector& pos) : throw_timer() { physic.enable_gravity(false); - sound_manager->preload("sounds/fall.wav"); - sound_manager->preload("sounds/squish.wav"); - sound_manager->preload("sounds/dartfire.wav"); + SoundManager::current()->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/squish.wav"); + SoundManager::current()->preload("sounds/dartfire.wav"); } void @@ -63,7 +63,7 @@ void Mole::kill_fall() { set_state(DEAD); - sound_manager->play("sounds/fall.wav", get_pos()); + SoundManager::current()->play("sounds/fall.wav", get_pos()); run_dead_script(); } @@ -80,7 +80,7 @@ Mole::collision_squished(GameObject& ) return true; set_state(DEAD); - sound_manager->play("sounds/squish.wav", get_pos()); + SoundManager::current()->play("sounds/squish.wav", get_pos()); run_dead_script(); return true; } @@ -95,7 +95,7 @@ Mole::throw_rock() float vx = cos(angle) * THROW_VELOCITY; float vy = -sin(angle) * THROW_VELOCITY; - sound_manager->play("sounds/dartfire.wav", get_pos()); + SoundManager::current()->play("sounds/dartfire.wav", get_pos()); Sector::current()->add_object(new MoleRock(Vector(px, py), Vector(vx, vy), this)); } diff --git a/src/badguy/mole_rock.cpp b/src/badguy/mole_rock.cpp index 6b259704c..b4ef0bf03 100644 --- a/src/badguy/mole_rock.cpp +++ b/src/badguy/mole_rock.cpp @@ -27,8 +27,8 @@ MoleRock::MoleRock(const Reader& reader) : { physic.enable_gravity(true); countMe = false; - sound_manager->preload("sounds/darthit.wav"); - sound_manager->preload("sounds/stomp.wav"); + SoundManager::current()->preload("sounds/darthit.wav"); + SoundManager::current()->preload("sounds/stomp.wav"); } MoleRock::MoleRock(const Vector& pos, const Vector& velocity, const BadGuy* parent_ = 0) : @@ -38,8 +38,8 @@ MoleRock::MoleRock(const Vector& pos, const Vector& velocity, const BadGuy* pare { physic.enable_gravity(true); countMe = false; - sound_manager->preload("sounds/darthit.wav"); - sound_manager->preload("sounds/stomp.wav"); + SoundManager::current()->preload("sounds/darthit.wav"); + SoundManager::current()->preload("sounds/stomp.wav"); } MoleRock::~MoleRock() @@ -78,7 +78,7 @@ MoleRock::active_update(float elapsed_time) void MoleRock::collision_solid(const CollisionHit& ) { - sound_manager->play("sounds/darthit.wav", get_pos()); + SoundManager::current()->play("sounds/darthit.wav", get_pos()); remove_me(); } @@ -89,7 +89,7 @@ MoleRock::collision_badguy(BadGuy& badguy, const CollisionHit& ) if (&badguy == parent) { return FORCE_MOVE; } - sound_manager->play("sounds/stomp.wav", get_pos()); + SoundManager::current()->play("sounds/stomp.wav", get_pos()); remove_me(); badguy.kill_fall(); return ABORT_MOVE; @@ -98,7 +98,7 @@ MoleRock::collision_badguy(BadGuy& badguy, const CollisionHit& ) HitResponse MoleRock::collision_player(Player& player, const CollisionHit& hit) { - sound_manager->play("sounds/stomp.wav", get_pos()); + SoundManager::current()->play("sounds/stomp.wav", get_pos()); remove_me(); return BadGuy::collision_player(player, hit); } diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 4acf89878..d9688ddbb 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -34,7 +34,7 @@ MrBomb::MrBomb(const Reader& reader) : grabbed = false; //Prevent stutter when Tux jumps on Mr Bomb - sound_manager->preload("sounds/explosion.wav"); + SoundManager::current()->preload("sounds/explosion.wav"); //Check if we need another sprite if( !reader.get( "sprite", sprite_name ) ){ @@ -45,7 +45,7 @@ MrBomb::MrBomb(const Reader& reader) : return; } //Replace sprite - sprite = sprite_manager->create( sprite_name ); + sprite = SpriteManager::current()->create( sprite_name ); } /* MrBomb created by a dispenser always gets default sprite atm.*/ @@ -56,7 +56,7 @@ MrBomb::MrBomb(const Vector& pos, Direction d) : walk_speed = 80; max_drop_height = 16; grabbed = false; - sound_manager->preload("sounds/explosion.wav"); + SoundManager::current()->preload("sounds/explosion.wav"); } HitResponse diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index c46e925b3..f87539b79 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -39,9 +39,9 @@ MrIceBlock::MrIceBlock(const Reader& reader) : { walk_speed = 80; max_drop_height = 600; - sound_manager->preload("sounds/iceblock_bump.wav"); - sound_manager->preload("sounds/stomp.wav"); - sound_manager->preload("sounds/kick.wav"); + SoundManager::current()->preload("sounds/iceblock_bump.wav"); + SoundManager::current()->preload("sounds/stomp.wav"); + SoundManager::current()->preload("sounds/kick.wav"); } MrIceBlock::MrIceBlock(const Vector& pos, Direction d) : @@ -53,9 +53,9 @@ MrIceBlock::MrIceBlock(const Vector& pos, Direction d) : { walk_speed = 80; max_drop_height = 600; - sound_manager->preload("sounds/iceblock_bump.wav"); - sound_manager->preload("sounds/stomp.wav"); - sound_manager->preload("sounds/kick.wav"); + SoundManager::current()->preload("sounds/iceblock_bump.wav"); + SoundManager::current()->preload("sounds/stomp.wav"); + SoundManager::current()->preload("sounds/kick.wav"); } void @@ -106,7 +106,7 @@ MrIceBlock::collision_solid(const CollisionHit& hit) case ICESTATE_KICKED: { if((hit.right && dir == RIGHT) || (hit.left && dir == LEFT)) { dir = (dir == LEFT) ? RIGHT : LEFT; - sound_manager->play("sounds/iceblock_bump.wav", get_pos()); + SoundManager::current()->play("sounds/iceblock_bump.wav", get_pos()); physic.set_velocity_x(-physic.get_velocity_x()*.975); } this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1); @@ -238,7 +238,7 @@ MrIceBlock::set_state(IceState state_, bool up) if(up) { physic.set_velocity_y(-KICKSPEED); } else { - sound_manager->play("sounds/stomp.wav", get_pos()); + SoundManager::current()->play("sounds/stomp.wav", get_pos()); physic.set_velocity_x(0); physic.set_velocity_y(0); } @@ -246,7 +246,7 @@ MrIceBlock::set_state(IceState state_, bool up) flat_timer.start(4); break; case ICESTATE_KICKED: - sound_manager->play("sounds/kick.wav", get_pos()); + SoundManager::current()->play("sounds/kick.wav", get_pos()); physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED); this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1); @@ -294,7 +294,7 @@ SmartBlock::SmartBlock(const Reader& reader) : MrIceBlock(reader) { max_drop_height = 16; - sprite = sprite_manager->create("images/creatures/mr_iceblock/smart_block/smart_block.sprite"); + sprite = SpriteManager::current()->create("images/creatures/mr_iceblock/smart_block/smart_block.sprite"); } /* EOF */ diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index cc8feb883..74c46a567 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -38,7 +38,7 @@ MrTree::MrTree(const Reader& reader) { walk_speed = TREE_SPEED; max_drop_height = 16; - sound_manager->preload("sounds/mr_tree.ogg"); + SoundManager::current()->preload("sounds/mr_tree.ogg"); } bool @@ -59,7 +59,7 @@ MrTree::collision_squished(GameObject& object) Sector::current()->add_object(stumpy); // give Feedback - sound_manager->play("sounds/mr_tree.ogg", get_pos()); + SoundManager::current()->play("sounds/mr_tree.ogg", get_pos()); Player* player = dynamic_cast(&object); if (player) player->bounce(*this); diff --git a/src/badguy/owl.cpp b/src/badguy/owl.cpp index f31fe9ca7..54c9433a8 100644 --- a/src/badguy/owl.cpp +++ b/src/badguy/owl.cpp @@ -143,7 +143,7 @@ Owl::collision_squished(GameObject&) void Owl::kill_fall() { - sound_manager->play("sounds/fall.wav", get_pos()); + SoundManager::current()->play("sounds/fall.wav", get_pos()); physic.set_velocity_y(0); physic.set_acceleration_y(0); physic.enable_gravity(true); diff --git a/src/badguy/root.cpp b/src/badguy/root.cpp index 58ecfa5b1..8e5423df0 100644 --- a/src/badguy/root.cpp +++ b/src/badguy/root.cpp @@ -29,7 +29,7 @@ Root::Root(const Vector& pos) : offset_y(0), hatch_timer() { - base_sprite = sprite_manager->create("images/creatures/ghosttree/root-base.sprite"); + base_sprite = SpriteManager::current()->create("images/creatures/ghosttree/root-base.sprite"); base_sprite->set_action("appearing", 1); base_sprite->set_animation_loops(1); // TODO: necessary because set_action ignores loops for default action physic.enable_gravity(false); diff --git a/src/badguy/short_fuse.cpp b/src/badguy/short_fuse.cpp index 8b07a3eed..0bd6472f4 100644 --- a/src/badguy/short_fuse.cpp +++ b/src/badguy/short_fuse.cpp @@ -44,7 +44,7 @@ ShortFuse::ShortFuse(const Reader& reader) : return; } //Replace sprite - sprite = sprite_manager->create( sprite_name ); + sprite = SpriteManager::current()->create( sprite_name ); } void diff --git a/src/badguy/skullyhop.cpp b/src/badguy/skullyhop.cpp index 2d2fc8943..7f1d7becb 100644 --- a/src/badguy/skullyhop.cpp +++ b/src/badguy/skullyhop.cpp @@ -32,7 +32,7 @@ SkullyHop::SkullyHop(const Reader& reader) : recover_timer(), state() { - sound_manager->preload( SKULLYHOP_SOUND ); + SoundManager::current()->preload( SKULLYHOP_SOUND ); } SkullyHop::SkullyHop(const Vector& pos, Direction d) : @@ -40,7 +40,7 @@ SkullyHop::SkullyHop(const Vector& pos, Direction d) : recover_timer(), state() { - sound_manager->preload( SKULLYHOP_SOUND ); + SoundManager::current()->preload( SKULLYHOP_SOUND ); } void @@ -71,7 +71,7 @@ const float HORIZONTAL_SPEED = 220; /**< x-speed when jumping */ physic.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); const float VERTICAL_SPEED = -450; /**< y-speed when jumping */ physic.set_velocity_y(VERTICAL_SPEED); - sound_manager->play( SKULLYHOP_SOUND, get_pos()); + SoundManager::current()->play( SKULLYHOP_SOUND, get_pos()); } state = newState; diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index 7592c158f..f0f62f209 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -37,9 +37,9 @@ Snail::Snail(const Reader& reader) : { walk_speed = 80; max_drop_height = 600; - sound_manager->preload("sounds/iceblock_bump.wav"); - sound_manager->preload("sounds/stomp.wav"); - sound_manager->preload("sounds/kick.wav"); + SoundManager::current()->preload("sounds/iceblock_bump.wav"); + SoundManager::current()->preload("sounds/stomp.wav"); + SoundManager::current()->preload("sounds/kick.wav"); } Snail::Snail(const Vector& pos, Direction d) : @@ -50,9 +50,9 @@ Snail::Snail(const Vector& pos, Direction d) : { walk_speed = 80; max_drop_height = 600; - sound_manager->preload("sounds/iceblock_bump.wav"); - sound_manager->preload("sounds/stomp.wav"); - sound_manager->preload("sounds/kick.wav"); + SoundManager::current()->preload("sounds/iceblock_bump.wav"); + SoundManager::current()->preload("sounds/stomp.wav"); + SoundManager::current()->preload("sounds/kick.wav"); } void @@ -159,7 +159,7 @@ Snail::collision_solid(const CollisionHit& hit) return; case STATE_KICKED: if(hit.left || hit.right) { - sound_manager->play("sounds/iceblock_bump.wav", get_pos()); + SoundManager::current()->play("sounds/iceblock_bump.wav", get_pos()); if( ( dir == LEFT && hit.left ) || ( dir == RIGHT && hit.right) ){ dir = (dir == LEFT) ? RIGHT : LEFT; @@ -251,12 +251,12 @@ Snail::collision_squished(GameObject& object) kill_fall(); return true; } - sound_manager->play("sounds/stomp.wav", get_pos()); + SoundManager::current()->play("sounds/stomp.wav", get_pos()); be_flat(); break; case STATE_FLAT: - sound_manager->play("sounds/kick.wav", get_pos()); + SoundManager::current()->play("sounds/kick.wav", get_pos()); { MovingObject* movingobject = dynamic_cast(&object); if (movingobject && (movingobject->get_pos().x < get_pos().x)) { diff --git a/src/badguy/snowman.cpp b/src/badguy/snowman.cpp index c6b974775..7edc1c14e 100644 --- a/src/badguy/snowman.cpp +++ b/src/badguy/snowman.cpp @@ -26,7 +26,7 @@ Snowman::Snowman(const Reader& reader) : WalkingBadguy(reader, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right") { walk_speed = 40; - sound_manager->preload("sounds/pop.ogg"); + SoundManager::current()->preload("sounds/pop.ogg"); } void @@ -58,7 +58,7 @@ Snowman::collision_bullet(Bullet& bullet, const CollisionHit& hit) // fire bullets destroy snowman's body loose_head(); - sound_manager->play("sounds/pop.ogg", get_pos()); // this could be a different sound + SoundManager::current()->play("sounds/pop.ogg", get_pos()); // this could be a different sound bullet.remove_me(); return ABORT_MOVE; @@ -78,7 +78,7 @@ Snowman::collision_squished(GameObject& object) if (player) player->bounce(*this); - sound_manager->play("sounds/pop.ogg", get_pos()); + SoundManager::current()->play("sounds/pop.ogg", get_pos()); loose_head(); diff --git a/src/badguy/stalactite.cpp b/src/badguy/stalactite.cpp index 5e6e83753..84febaedf 100644 --- a/src/badguy/stalactite.cpp +++ b/src/badguy/stalactite.cpp @@ -35,9 +35,9 @@ Stalactite::Stalactite(const Reader& lisp) : { countMe = false; set_colgroup_active(COLGROUP_TOUCHABLE); - sound_manager->preload("sounds/cracking.wav"); - sound_manager->preload("sounds/sizzle.ogg"); - sound_manager->preload("sounds/icecrash.ogg"); + SoundManager::current()->preload("sounds/cracking.wav"); + SoundManager::current()->preload("sounds/sizzle.ogg"); + SoundManager::current()->preload("sounds/icecrash.ogg"); } void @@ -52,7 +52,7 @@ Stalactite::active_update(float elapsed_time) && player->get_bbox().p1.y < bbox.p2.y + SHAKE_RANGE_Y) { timer.start(SHAKE_TIME); state = STALACTITE_SHAKING; - sound_manager->play("sounds/cracking.wav", get_pos()); + SoundManager::current()->play("sounds/cracking.wav", get_pos()); } } } else if(state == STALACTITE_SHAKING) { @@ -76,7 +76,7 @@ Stalactite::squish() physic.set_velocity_y(0); set_state(STATE_SQUISHED); sprite->set_action("squished"); - sound_manager->play("sounds/icecrash.ogg", get_pos()); + SoundManager::current()->play("sounds/icecrash.ogg", get_pos()); set_group(COLGROUP_MOVING_ONLY_STATIC); run_dead_script(); } @@ -129,8 +129,8 @@ Stalactite::collision_bullet(Bullet& bullet, const CollisionHit& ) state = STALACTITE_SHAKING; bullet.remove_me(); if(bullet.get_type() == FIRE_BONUS) - sound_manager->play("sounds/sizzle.ogg", get_pos()); - sound_manager->play("sounds/cracking.wav", get_pos()); + SoundManager::current()->play("sounds/sizzle.ogg", get_pos()); + SoundManager::current()->play("sounds/cracking.wav", get_pos()); } return FORCE_MOVE; diff --git a/src/badguy/stumpy.cpp b/src/badguy/stumpy.cpp index 5a61070c8..7eb6c4e76 100644 --- a/src/badguy/stumpy.cpp +++ b/src/badguy/stumpy.cpp @@ -35,7 +35,7 @@ Stumpy::Stumpy(const Reader& reader) : { walk_speed = STUMPY_SPEED; max_drop_height = 16; - sound_manager->preload("sounds/mr_treehit.ogg"); + SoundManager::current()->preload("sounds/mr_treehit.ogg"); } Stumpy::Stumpy(const Vector& pos, Direction d) : @@ -45,7 +45,7 @@ Stumpy::Stumpy(const Vector& pos, Direction d) : { walk_speed = STUMPY_SPEED; max_drop_height = 16; - sound_manager->preload("sounds/mr_treehit.ogg"); + SoundManager::current()->preload("sounds/mr_treehit.ogg"); invincible_timer.start(INVINCIBLE_TIME); } @@ -87,7 +87,7 @@ Stumpy::collision_squished(GameObject& object) // if we're still invincible, we ignore the hit if (mystate == STATE_INVINCIBLE) { - sound_manager->play("sounds/mr_treehit.ogg", get_pos()); + SoundManager::current()->play("sounds/mr_treehit.ogg", get_pos()); Player* player = dynamic_cast(&object); if (player) player->bounce(*this); return true; diff --git a/src/badguy/toad.cpp b/src/badguy/toad.cpp index f70f87a81..2314e102e 100644 --- a/src/badguy/toad.cpp +++ b/src/badguy/toad.cpp @@ -33,7 +33,7 @@ Toad::Toad(const Reader& reader) : recover_timer(), state() { - sound_manager->preload(HOP_SOUND); + SoundManager::current()->preload(HOP_SOUND); } Toad::Toad(const Vector& pos, Direction d) : @@ -41,7 +41,7 @@ Toad::Toad(const Vector& pos, Direction d) : recover_timer(), state() { - sound_manager->preload(HOP_SOUND); + SoundManager::current()->preload(HOP_SOUND); } void @@ -68,7 +68,7 @@ Toad::set_state(ToadState newState) sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right"); physic.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED); physic.set_velocity_y(VERTICAL_SPEED); - sound_manager->play( HOP_SOUND, get_pos()); + SoundManager::current()->play( HOP_SOUND, get_pos()); } else if (newState == FALLING) { Player* player = get_nearest_player(); diff --git a/src/badguy/totem.cpp b/src/badguy/totem.cpp index 70bd8503d..5941a1b69 100644 --- a/src/badguy/totem.cpp +++ b/src/badguy/totem.cpp @@ -33,7 +33,7 @@ Totem::Totem(const Reader& reader) : carrying(0), carried_by(0) { - sound_manager->preload( LAND_ON_TOTEM_SOUND ); + SoundManager::current()->preload( LAND_ON_TOTEM_SOUND ); } Totem::~Totem() @@ -222,7 +222,7 @@ Totem::jump_on(Totem* target) this->initialize(); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); - sound_manager->play( LAND_ON_TOTEM_SOUND , get_pos()); + SoundManager::current()->play( LAND_ON_TOTEM_SOUND , get_pos()); this->synchronize_with(target); } diff --git a/src/badguy/treewillowisp.cpp b/src/badguy/treewillowisp.cpp index 5ca187e1d..3de20e03d 100644 --- a/src/badguy/treewillowisp.cpp +++ b/src/badguy/treewillowisp.cpp @@ -42,7 +42,7 @@ TreeWillOWisp::TreeWillOWisp(GhostTree* tree_, const Vector& pos, tree(tree_), suck_target() { - sound_manager->preload(TREEWILLOSOUND); + SoundManager::current()->preload(TREEWILLOSOUND); this->radius = radius_; this->angle = 0; @@ -58,7 +58,7 @@ TreeWillOWisp::~TreeWillOWisp() void TreeWillOWisp::activate() { - sound_source = sound_manager->create_sound_source(TREEWILLOSOUND); + sound_source = SoundManager::current()->create_sound_source(TREEWILLOSOUND); sound_source->set_position(get_pos()); sound_source->set_looping(true); sound_source->set_gain(2.0); diff --git a/src/badguy/willowisp.cpp b/src/badguy/willowisp.cpp index 7cc348a58..282595efb 100644 --- a/src/badguy/willowisp.cpp +++ b/src/badguy/willowisp.cpp @@ -46,7 +46,7 @@ WillOWisp::WillOWisp(const Reader& reader) : flyspeed(), track_range(), vanish_range(), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { bool running = false; flyspeed = FLYSPEED; @@ -72,8 +72,8 @@ WillOWisp::WillOWisp(const Reader& reader) : } countMe = false; - sound_manager->preload(SOUNDFILE); - sound_manager->preload("sounds/warp.wav"); + SoundManager::current()->preload(SOUNDFILE); + SoundManager::current()->preload("sounds/warp.wav"); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); lightsprite->set_color(Color(0.0f, 0.2f, 0.0f)); @@ -159,7 +159,7 @@ WillOWisp::active_update(float elapsed_time) void WillOWisp::activate() { - sound_source = sound_manager->create_sound_source(SOUNDFILE); + sound_source = SoundManager::current()->create_sound_source(SOUNDFILE); sound_source->set_position(get_pos()); sound_source->set_looping(true); sound_source->set_gain(2.0); @@ -226,7 +226,7 @@ WillOWisp::collision_player(Player& player, const CollisionHit& ) { } else { GameSession::current()->respawn(target_sector, target_spawnpoint); } - sound_manager->play("sounds/warp.wav"); + SoundManager::current()->play("sounds/warp.wav"); return CONTINUE; } diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index f7f8a4d7a..e958d53b5 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -62,8 +62,8 @@ Yeti::Yeti(const Reader& reader) : { hit_points = INITIAL_HITPOINTS; countMe = false; - sound_manager->preload("sounds/yeti_gna.wav"); - sound_manager->preload("sounds/yeti_roar.wav"); + SoundManager::current()->preload("sounds/yeti_gna.wav"); + SoundManager::current()->preload("sounds/yeti_roar.wav"); hud_head = Surface::create("images/creatures/yeti/hudlife.png"); } @@ -126,7 +126,7 @@ Yeti::active_update(float elapsed_time) break; case BE_ANGRY: if(state_timer.check()) { - sound_manager->play("sounds/yeti_gna.wav"); + SoundManager::current()->play("sounds/yeti_gna.wav"); physic.set_velocity_y(STOMP_VY); sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left"); } @@ -205,7 +205,7 @@ void Yeti::take_hit(Player& ) if(safe_timer.started()) return; - sound_manager->play("sounds/yeti_roar.wav"); + SoundManager::current()->play("sounds/yeti_roar.wav"); hit_points--; if(hit_points <= 0) { diff --git a/src/control/input_manager.hpp b/src/control/input_manager.hpp index 1a0736c06..8b7ec190e 100644 --- a/src/control/input_manager.hpp +++ b/src/control/input_manager.hpp @@ -25,6 +25,7 @@ #include #include +#include "util/currenton.hpp" #include "util/reader_fwd.hpp" #include "util/writer_fwd.hpp" @@ -36,7 +37,7 @@ class KeyboardManager; class KeyboardMenu; class Menu; -class InputManager final +class InputManager final : public Currenton { private: friend class KeyboardMenu; diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index be3b20820..a329e2533 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -180,7 +180,7 @@ Menu::process_input() } MenuAction menuaction = MENU_ACTION_NONE; - Controller* controller = g_input_manager->get_controller(); + Controller* controller = InputManager::current()->get_controller(); /** check main input controller... */ if(controller->pressed(Controller::UP)) { menuaction = MENU_ACTION_UP; diff --git a/src/gui/menu_manager.cpp b/src/gui/menu_manager.cpp index 89087b1b5..9a34c98c0 100644 --- a/src/gui/menu_manager.cpp +++ b/src/gui/menu_manager.cpp @@ -258,7 +258,7 @@ MenuManager::set_menu(std::unique_ptr menu) } // just to be sure... - g_input_manager->reset(); + InputManager::current()->reset(); } void diff --git a/src/object/ambient_sound.cpp b/src/object/ambient_sound.cpp index c2e9f55c2..14539e61f 100644 --- a/src/object/ambient_sound.cpp +++ b/src/object/ambient_sound.cpp @@ -89,7 +89,7 @@ AmbientSound::AmbientSound(const Reader& lisp) : lisp.get("silence_distance",silence_distance); sound_source.reset(); // not playing at the beginning - sound_manager->preload(sample); + SoundManager::current()->preload(sample); latency=0; } @@ -127,7 +127,7 @@ AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std: silence_distance = 1/distance_factor; sound_source = 0; // not playing at the beginning - sound_manager->preload(sample); + SoundManager::current()->preload(sample); latency=0; } @@ -151,7 +151,7 @@ void AmbientSound::start_playing() { try { - sound_source = sound_manager->create_sound_source(sample); + sound_source = SoundManager::current()->create_sound_source(sample); if(!sound_source) throw std::runtime_error("file not found"); diff --git a/src/object/block.cpp b/src/object/block.cpp index dd1272f6b..1e242710f 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -42,8 +42,8 @@ Block::Block(SpritePtr newsprite) : { bbox.set_size(32, 32.1f); set_group(COLGROUP_STATIC); - sound_manager->preload("sounds/upgrade.wav"); - sound_manager->preload("sounds/brick.wav"); + SoundManager::current()->preload("sounds/upgrade.wav"); + SoundManager::current()->preload("sounds/brick.wav"); } Block::~Block() diff --git a/src/object/bonus_block.cpp b/src/object/bonus_block.cpp index b3f80baeb..dbcc20c07 100644 --- a/src/object/bonus_block.cpp +++ b/src/object/bonus_block.cpp @@ -40,7 +40,7 @@ #include BonusBlock::BonusBlock(const Vector& pos, int data) : - Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")), + Block(SpriteManager::current()->create("images/objects/bonus_block/bonusblock.sprite")), contents(), object(0), hit_counter(1), @@ -57,7 +57,7 @@ BonusBlock::BonusBlock(const Vector& pos, int data) : case 4: contents = CONTENT_1UP; break; case 5: contents = CONTENT_ICEGROW; break; case 6: contents = CONTENT_LIGHT; - sound_manager->preload("sounds/switch.ogg"); + SoundManager::current()->preload("sounds/switch.ogg"); lightsprite=Surface::create("/images/objects/lightmap_light/bonusblock_light.png"); break; case 7: contents = CONTENT_TRAMPOLINE; @@ -82,7 +82,7 @@ BonusBlock::BonusBlock(const Vector& pos, int data) : } BonusBlock::BonusBlock(const Reader& lisp) : - Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")), + Block(SpriteManager::current()->create("images/objects/bonus_block/bonusblock.sprite")), contents(), object(0), hit_counter(1), @@ -102,7 +102,7 @@ BonusBlock::BonusBlock(const Reader& lisp) : iter.value()->get(pos.y); } else if(token == "sprite") { iter.value()->get(sprite_name); - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); } else if(token == "count") { iter.value()->get(hit_counter); } else if(token == "script") { @@ -126,7 +126,7 @@ BonusBlock::BonusBlock(const Reader& lisp) : contents = CONTENT_SCRIPT; } else if(contentstring == "light") { contents = CONTENT_LIGHT; - sound_manager->preload("sounds/switch.ogg"); + SoundManager::current()->preload("sounds/switch.ogg"); } else if(contentstring == "trampoline") { contents = CONTENT_TRAMPOLINE; } else if(contentstring == "rain") { @@ -200,7 +200,7 @@ void BonusBlock::try_open(Player *player) { if(sprite->get_action() == "empty") { - sound_manager->play("sounds/brick.wav"); + SoundManager::current()->play("sounds/brick.wav"); return; } @@ -235,7 +235,7 @@ BonusBlock::try_open(Player *player) get_pos(), new Flower(FIRE_BONUS)); sector->add_object(riser); } - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); break; } @@ -249,21 +249,21 @@ BonusBlock::try_open(Player *player) get_pos(), new Flower(ICE_BONUS)); sector->add_object(riser); } - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); break; } case CONTENT_STAR: { sector->add_object(new Star(get_pos() + Vector(0, -32), direction)); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); break; } case CONTENT_1UP: { sector->add_object(new OneUp(get_pos(), direction)); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); break; } @@ -272,7 +272,7 @@ BonusBlock::try_open(Player *player) SpecialRiser* riser = new SpecialRiser(get_pos(), object); object = 0; sector->add_object(riser); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); break; } @@ -285,28 +285,28 @@ BonusBlock::try_open(Player *player) sprite->set_action("off"); else sprite->set_action("on"); - sound_manager->play("sounds/switch.ogg"); + SoundManager::current()->play("sounds/switch.ogg"); break; } case CONTENT_TRAMPOLINE: { SpecialRiser* riser = new SpecialRiser(get_pos(), new Trampoline(get_pos(), false)); sector->add_object(riser); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); break; } case CONTENT_RAIN: { hit_counter = 1; // multiple hits of coin rain is not allowed Sector::current()->add_object(new CoinRain(get_pos(), true)); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); break; } case CONTENT_EXPLODE: { hit_counter = 1; // multiple hits of coin explode is not allowed Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, -40))); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); break; } } @@ -329,7 +329,7 @@ void BonusBlock::try_drop(Player *player) { if(sprite->get_action() == "empty") { - sound_manager->play("sounds/brick.wav"); + SoundManager::current()->play("sounds/brick.wav"); return; } @@ -367,7 +367,7 @@ BonusBlock::try_drop(Player *player) case CONTENT_FIREGROW: { sector->add_object(new PowerUp(get_pos() + Vector(0, 32), "images/powerups/fireflower/fireflower.sprite")); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); countdown = true; break; } @@ -375,7 +375,7 @@ BonusBlock::try_drop(Player *player) case CONTENT_ICEGROW: { sector->add_object(new PowerUp(get_pos() + Vector(0, 32), "images/powerups/iceflower/iceflower.sprite")); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); countdown = true; break; } @@ -383,7 +383,7 @@ BonusBlock::try_drop(Player *player) case CONTENT_STAR: { sector->add_object(new Star(get_pos() + Vector(0, 32), direction)); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); countdown = true; break; } @@ -391,7 +391,7 @@ BonusBlock::try_drop(Player *player) case CONTENT_1UP: { sector->add_object(new OneUp(get_pos(), DOWN)); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); countdown = true; break; } @@ -402,7 +402,7 @@ BonusBlock::try_drop(Player *player) object->set_pos(get_pos() + Vector(0, 32)); sector->add_object(object); object = 0; - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); countdown = true; break; } @@ -429,7 +429,7 @@ BonusBlock::try_drop(Player *player) { hit_counter = 1; // multiple hits of coin explode is not allowed Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, 40))); - sound_manager->play("sounds/upgrade.wav"); + SoundManager::current()->play("sounds/upgrade.wav"); countdown = true; break; } diff --git a/src/object/bouncy_coin.cpp b/src/object/bouncy_coin.cpp index 12b3148e9..6e956735d 100644 --- a/src/object/bouncy_coin.cpp +++ b/src/object/bouncy_coin.cpp @@ -31,7 +31,7 @@ BouncyCoin::BouncyCoin(const Vector& pos, bool emerge) : emerge_distance(0) { timer.start(LIFE_TIME); - sprite = sprite_manager->create("images/objects/coin/coin.sprite"); + sprite = SpriteManager::current()->create("images/objects/coin/coin.sprite"); if(emerge) { emerge_distance = sprite->get_height(); diff --git a/src/object/brick.cpp b/src/object/brick.cpp index 8e85da787..4b2b90c1e 100644 --- a/src/object/brick.cpp +++ b/src/object/brick.cpp @@ -28,7 +28,7 @@ #include "supertux/sector.hpp" Brick::Brick(const Vector& pos, int data, const std::string& spriteName) - : Block(sprite_manager->create(spriteName)), breakable(false), + : Block(SpriteManager::current()->create(spriteName)), breakable(false), coin_counter(0) { bbox.set_pos(pos); @@ -84,7 +84,7 @@ Brick::try_break(Player* player) if(sprite->get_action() == "empty") return; - sound_manager->play("sounds/brick.wav"); + SoundManager::current()->play("sounds/brick.wav"); Sector* sector = Sector::current(); Player& player_one = *(sector->player); if(coin_counter > 0) { diff --git a/src/object/bullet.cpp b/src/object/bullet.cpp index c6a486774..46c5260a5 100644 --- a/src/object/bullet.cpp +++ b/src/object/bullet.cpp @@ -32,23 +32,23 @@ Bullet::Bullet(const Vector& pos, float xm, int dir, BonusType type_) : life_count(3), sprite(), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")), + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")), type(type_) { float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM; physic.set_velocity_x(speed + xm); if(type == FIRE_BONUS) { - sprite = sprite_manager->create("images/objects/bullets/firebullet.sprite"); + sprite = SpriteManager::current()->create("images/objects/bullets/firebullet.sprite"); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); lightsprite->set_color(Color(0.3f, 0.1f, 0.0f)); } else if(type == ICE_BONUS) { life_count = 10; - sprite = sprite_manager->create("images/objects/bullets/icebullet.sprite"); + sprite = SpriteManager::current()->create("images/objects/bullets/icebullet.sprite"); } else { log_warning << "Bullet::Bullet called with unknown BonusType" << std::endl; life_count = 10; - sprite = sprite_manager->create("images/objects/bullets/firebullet.sprite"); + sprite = SpriteManager::current()->create("images/objects/bullets/firebullet.sprite"); } bbox.set_pos(pos); diff --git a/src/object/candle.cpp b/src/object/candle.cpp index a3b8f1517..84535f64a 100644 --- a/src/object/candle.cpp +++ b/src/object/candle.cpp @@ -28,8 +28,8 @@ Candle::Candle(const Reader& lisp) burning(true), flicker(true), lightcolor(1.0f, 1.0f, 1.0f), - candle_light_1(sprite_manager->create("images/objects/candle/candle-light-1.sprite")), - candle_light_2(sprite_manager->create("images/objects/candle/candle-light-2.sprite")) + candle_light_1(SpriteManager::current()->create("images/objects/candle/candle-light-1.sprite")), + candle_light_2(SpriteManager::current()->create("images/objects/candle/candle-light-2.sprite")) { lisp.get("name", name); lisp.get("burning", burning); diff --git a/src/object/coin.cpp b/src/object/coin.cpp index d3cc16398..cf82ff3f1 100644 --- a/src/object/coin.cpp +++ b/src/object/coin.cpp @@ -33,7 +33,7 @@ Coin::Coin(const Vector& pos) from_tilemap(false), physic() { - sound_manager->preload("sounds/coin.wav"); + SoundManager::current()->preload("sounds/coin.wav"); } Coin::Coin(const Vector& pos, TileMap* tilemap) @@ -49,7 +49,7 @@ Coin::Coin(const Vector& pos, TileMap* tilemap) offset = pos - v; } - sound_manager->preload("sounds/coin.wav"); + SoundManager::current()->preload("sounds/coin.wav"); } Coin::Coin(const Reader& reader) @@ -69,7 +69,7 @@ Coin::Coin(const Reader& reader) set_pos(v); } - sound_manager->preload("sounds/coin.wav"); + SoundManager::current()->preload("sounds/coin.wav"); } void @@ -149,11 +149,11 @@ Coin::collect() } sound_timer.start(1); - SoundSource* soundSource = sound_manager->create_sound_source("sounds/coin.wav"); + SoundSource* soundSource = SoundManager::current()->create_sound_source("sounds/coin.wav"); soundSource->set_position(get_pos()); soundSource->set_pitch(pitch); soundSource->play(); - sound_manager->manage_source(soundSource); + SoundManager::current()->manage_source(soundSource); */ Sector::current()->player->get_status()->add_coins(1); Sector::current()->add_object(new BouncyCoin(get_pos())); @@ -178,7 +178,7 @@ HeavyCoin::HeavyCoin(const Vector& pos, const Vector& init_velocity) physic() { physic.enable_gravity(true); - sound_manager->preload("sounds/coin2.ogg"); + SoundManager::current()->preload("sounds/coin2.ogg"); set_group(COLGROUP_MOVING); physic.set_velocity(init_velocity); } @@ -188,7 +188,7 @@ HeavyCoin::HeavyCoin(const Reader& reader) physic() { physic.enable_gravity(true); - sound_manager->preload("sounds/coin2.ogg"); + SoundManager::current()->preload("sounds/coin2.ogg"); set_group(COLGROUP_MOVING); } @@ -207,7 +207,7 @@ HeavyCoin::collision_solid(const CollisionHit& hit) if(hit.bottom) { if(physic.get_velocity_y() > clink_threshold) - sound_manager->play("sounds/coin2.ogg"); + SoundManager::current()->play("sounds/coin2.ogg"); if(physic.get_velocity_y() > 200) {// lets some coins bounce physic.set_velocity_y(-99); }else{ @@ -217,12 +217,12 @@ HeavyCoin::collision_solid(const CollisionHit& hit) } if(hit.right || hit.left) { if(physic.get_velocity_x() > clink_threshold || physic.get_velocity_x() < clink_threshold) - sound_manager->play("sounds/coin2.ogg"); + SoundManager::current()->play("sounds/coin2.ogg"); physic.set_velocity_x(-physic.get_velocity_x()); } if(hit.top) { if(physic.get_velocity_y() < clink_threshold) - sound_manager->play("sounds/coin2.ogg"); + SoundManager::current()->play("sounds/coin2.ogg"); physic.set_velocity_y(-physic.get_velocity_y()); } } diff --git a/src/object/coin_rain.cpp b/src/object/coin_rain.cpp index 05426e62f..c3b10e5d7 100644 --- a/src/object/coin_rain.cpp +++ b/src/object/coin_rain.cpp @@ -32,7 +32,7 @@ CoinRain::CoinRain(const Vector& pos, bool emerge) : counter(0), drop(0) { - sprite = sprite_manager->create("images/objects/coin/coin.sprite"); + sprite = SpriteManager::current()->create("images/objects/coin/coin.sprite"); if(emerge) { emerge_distance = sprite->get_height(); diff --git a/src/object/endsequence_fireworks.cpp b/src/object/endsequence_fireworks.cpp index 2e4f8308a..f2f0ba435 100644 --- a/src/object/endsequence_fireworks.cpp +++ b/src/object/endsequence_fireworks.cpp @@ -40,7 +40,7 @@ void EndSequenceFireworks::starting() { EndSequence::starting(); - endsequence_timer.start(7.3f * g_screen_manager->get_speed()); + endsequence_timer.start(7.3f * ScreenManager::current()->get_speed()); Sector::current()->add_object(new Fireworks()); } diff --git a/src/object/endsequence_walkleft.cpp b/src/object/endsequence_walkleft.cpp index 19e2041d3..268db7042 100644 --- a/src/object/endsequence_walkleft.cpp +++ b/src/object/endsequence_walkleft.cpp @@ -41,7 +41,7 @@ EndSequenceWalkLeft::starting() { EndSequence::starting(); last_x_pos = -1; - endsequence_timer.start(7.3f * g_screen_manager->get_speed()); + endsequence_timer.start(7.3f * ScreenManager::current()->get_speed()); } void diff --git a/src/object/endsequence_walkright.cpp b/src/object/endsequence_walkright.cpp index 1631c166f..6a52ddd94 100644 --- a/src/object/endsequence_walkright.cpp +++ b/src/object/endsequence_walkright.cpp @@ -41,7 +41,7 @@ EndSequenceWalkRight::starting() { EndSequence::starting(); last_x_pos = -1; - endsequence_timer.start(7.3f * g_screen_manager->get_speed()); + endsequence_timer.start(7.3f * ScreenManager::current()->get_speed()); } void diff --git a/src/object/explosion.cpp b/src/object/explosion.cpp index 12d164eb5..828f02bb1 100644 --- a/src/object/explosion.cpp +++ b/src/object/explosion.cpp @@ -35,10 +35,10 @@ Explosion::Explosion(const Vector& pos) : push(false), state(STATE_WAITING), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-large.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-large.sprite")) { - sound_manager->preload("sounds/explosion.wav"); - sound_manager->preload("sounds/firecracker.ogg"); + SoundManager::current()->preload("sounds/explosion.wav"); + SoundManager::current()->preload("sounds/firecracker.ogg"); set_pos(get_pos() - (get_bbox().get_middle() - get_pos())); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); lightsprite->set_color(Color(0.6f, 0.6f, 0.6f)); @@ -50,10 +50,10 @@ Explosion::Explosion(const Reader& reader) : push(false), state(STATE_WAITING), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-large.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-large.sprite")) { - sound_manager->preload("sounds/explosion.wav"); - sound_manager->preload("sounds/firecracker.ogg"); + SoundManager::current()->preload("sounds/explosion.wav"); + SoundManager::current()->preload("sounds/firecracker.ogg"); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); lightsprite->set_color(Color(0.6f, 0.6f, 0.6f)); } @@ -68,7 +68,7 @@ Explosion::explode() set_action(hurt ? "default" : "pop", 1); sprite->set_animation_loops(1); //TODO: this is necessary because set_action will not set "loops" when "action" is the default action sprite->set_angle(graphicsRandom.randf(0, 360)); // a random rotation on the sprite to make explosions appear more random - sound_manager->play(hurt ? "sounds/explosion.wav" : "sounds/firecracker.ogg", get_pos()); + SoundManager::current()->play(hurt ? "sounds/explosion.wav" : "sounds/firecracker.ogg", get_pos()); #if 0 // spawn some particles diff --git a/src/object/falling_coin.cpp b/src/object/falling_coin.cpp index 66b2c2ef0..ffa221c6e 100644 --- a/src/object/falling_coin.cpp +++ b/src/object/falling_coin.cpp @@ -25,7 +25,7 @@ FallingCoin::FallingCoin(const Vector& start_position, const int vel_x) : sprite() { pos = start_position; - sprite = sprite_manager->create("images/objects/coin/coin.sprite"); + sprite = SpriteManager::current()->create("images/objects/coin/coin.sprite"); physic.set_velocity_y(-800); physic.set_velocity_x(vel_x); } diff --git a/src/object/firefly.cpp b/src/object/firefly.cpp index 44e60c5da..a7198ec47 100644 --- a/src/object/firefly.cpp +++ b/src/object/firefly.cpp @@ -43,16 +43,16 @@ Firefly::Firefly(const Reader& lisp) : return; } //Replace sprite - sprite = sprite_manager->create( sprite_name ); + sprite = SpriteManager::current()->create( sprite_name ); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); reactivate(); //Load sound if( sprite_name.find("vbell", 0) == std::string::npos ) { - sound_manager->preload("sounds/savebell_low.wav"); + SoundManager::current()->preload("sounds/savebell_low.wav"); } else { - sound_manager->preload("sounds/savebell2.wav"); + SoundManager::current()->preload("sounds/savebell2.wav"); } } @@ -93,10 +93,10 @@ Firefly::collision(GameObject& other, const CollisionHit& ) } if( sprite_name.find("vbell", 0) == std::string::npos ) { - sound_manager->play("sounds/savebell2.wav"); + SoundManager::current()->play("sounds/savebell2.wav"); } else { - sound_manager->play("sounds/savebell_low.wav"); + SoundManager::current()->play("sounds/savebell_low.wav"); } sprite->set_action("ringing"); diff --git a/src/object/fireworks.cpp b/src/object/fireworks.cpp index c5ec447af..bd1814e37 100644 --- a/src/object/fireworks.cpp +++ b/src/object/fireworks.cpp @@ -27,7 +27,7 @@ Fireworks::Fireworks() : timer() { timer.start(.2f); - sound_manager->preload("sounds/fireworks.wav"); + SoundManager::current()->preload("sounds/fireworks.wav"); } Fireworks::~Fireworks() @@ -52,7 +52,7 @@ Fireworks::update(float ) sector->add_object(new Particles(pos, 0, 360, Vector(140, 140), Vector(0, 0), 45, Color(red, green, 0), 3, 1.3f, LAYER_FOREGROUND1+1)); - sound_manager->play("sounds/fireworks.wav"); + SoundManager::current()->play("sounds/fireworks.wav"); timer.start(graphicsRandom.randf(1.0, 1.5)); } } diff --git a/src/object/floating_image.cpp b/src/object/floating_image.cpp index 40d37402c..1bb0fe2a5 100644 --- a/src/object/floating_image.cpp +++ b/src/object/floating_image.cpp @@ -20,7 +20,7 @@ #include "supertux/globals.hpp" FloatingImage::FloatingImage(const std::string& spritefile) : - sprite(sprite_manager->create(spritefile)), + sprite(SpriteManager::current()->create(spritefile)), layer(LAYER_FOREGROUND1 + 1), visible(false), anchor(ANCHOR_MIDDLE), diff --git a/src/object/flower.cpp b/src/object/flower.cpp index 3f18845ac..d823ed7b1 100644 --- a/src/object/flower.cpp +++ b/src/object/flower.cpp @@ -25,19 +25,19 @@ Flower::Flower(BonusType _type) : sprite(), drawing_effect(NO_EFFECT), light(1.0f,1.0f,1.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { bbox.set_size(32, 32); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); if(type == FIRE_BONUS) { - sprite = sprite_manager->create("images/powerups/fireflower/fireflower.sprite"); - sound_manager->preload("sounds/fire-flower.wav"); + sprite = SpriteManager::current()->create("images/powerups/fireflower/fireflower.sprite"); + SoundManager::current()->preload("sounds/fire-flower.wav"); lightsprite->set_color(Color(0.3f, 0.0f, 0.0f)); } else if(type == ICE_BONUS) { - sprite = sprite_manager->create("images/powerups/iceflower/iceflower.sprite"); - sound_manager->preload("sounds/fire-flower.wav"); + sprite = SpriteManager::current()->create("images/powerups/iceflower/iceflower.sprite"); + SoundManager::current()->preload("sounds/fire-flower.wav"); lightsprite->set_color(Color(0.0f, 0.1f, 0.2f)); } else { assert(false); @@ -80,7 +80,7 @@ Flower::collision(GameObject& other, const CollisionHit& ) if(!player->add_bonus(type, true)) return FORCE_MOVE; - sound_manager->play("sounds/fire-flower.wav"); + SoundManager::current()->play("sounds/fire-flower.wav"); remove_me(); return ABORT_MOVE; } diff --git a/src/object/growup.cpp b/src/object/growup.cpp index 4e49494b4..50d16ea48 100644 --- a/src/object/growup.cpp +++ b/src/object/growup.cpp @@ -26,12 +26,12 @@ GrowUp::GrowUp(Direction direction) : MovingSprite(Vector(0,0), "images/powerups/egg/egg.sprite", LAYER_OBJECTS, COLGROUP_MOVING), physic(), light(0.0f,0.0f,0.0f), - shadesprite(sprite_manager->create("images/powerups/egg/egg.sprite")), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")) + shadesprite(SpriteManager::current()->create("images/powerups/egg/egg.sprite")), + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { physic.enable_gravity(true); physic.set_velocity_x((direction == LEFT)?-100:100); - sound_manager->preload("sounds/grow.ogg"); + SoundManager::current()->preload("sounds/grow.ogg"); //shadow to remain in place as egg rolls shadesprite->set_action("shadow"); //set light for glow effect @@ -89,7 +89,7 @@ GrowUp::collision(GameObject& other, const CollisionHit& hit ) return ABORT_MOVE; } - sound_manager->play("sounds/grow.ogg"); + SoundManager::current()->play("sounds/grow.ogg"); remove_me(); return ABORT_MOVE; diff --git a/src/object/icecrusher.cpp b/src/object/icecrusher.cpp index e8374ff60..d2fcf5c80 100644 --- a/src/object/icecrusher.cpp +++ b/src/object/icecrusher.cpp @@ -52,7 +52,7 @@ IceCrusher::IceCrusher(const Reader& reader) : { // TODO: icecrusher hitting deserves its own sounds- // one for hitting the ground, one for hitting Tux - sound_manager->preload("sounds/brick.wav"); + SoundManager::current()->preload("sounds/brick.wav"); start_position = get_bbox().p1; set_state(state, true); @@ -61,11 +61,11 @@ IceCrusher::IceCrusher(const Reader& reader) : if (sprite_width >= 128.0) ic_size = LARGE; - lefteye = sprite_manager->create(sprite_name); + lefteye = SpriteManager::current()->create(sprite_name); lefteye->set_action("lefteye"); - righteye = sprite_manager->create(sprite_name); + righteye = SpriteManager::current()->create(sprite_name); righteye->set_action("righteye"); - whites = sprite_manager->create(sprite_name); + whites = SpriteManager::current()->create(sprite_name); whites->set_action("whites"); } @@ -114,7 +114,7 @@ IceCrusher::collision(GameObject& other, const CollisionHit& hit) /* If the other object is the player, and the collision is at the bottom of * the ice crusher, hurt the player. */ if (player && hit.bottom) { - sound_manager->play("sounds/brick.wav"); + SoundManager::current()->play("sounds/brick.wav"); if(player->is_invincible()) { if (state == CRUSHING) set_state(RECOVERING); @@ -143,7 +143,7 @@ IceCrusher::collision_solid(const CollisionHit& hit) if (ic_size == LARGE) { cooldown_timer = PAUSE_TIME_LARGE; Sector::current()->camera->shake (/* frequency = */ .125f, /* x = */ 0.0, /* y = */ 16.0); - sound_manager->play("sounds/brick.wav"); + SoundManager::current()->play("sounds/brick.wav"); // throw some particles, bigger and more for large icecrusher for(int j = 0; j < 9; j++) { @@ -160,7 +160,7 @@ IceCrusher::collision_solid(const CollisionHit& hit) else { cooldown_timer = PAUSE_TIME_NORMAL; Sector::current()->camera->shake (/* frequency = */ .1f, /* x = */ 0.0, /* y = */ 8.0); - sound_manager->play("sounds/brick.wav"); + SoundManager::current()->play("sounds/brick.wav"); // throw some particles for(int j = 0; j < 5; j++) { diff --git a/src/object/infoblock.cpp b/src/object/infoblock.cpp index c8ef30660..2bbb42f77 100644 --- a/src/object/infoblock.cpp +++ b/src/object/infoblock.cpp @@ -33,7 +33,7 @@ const float HEIGHT = 200; } InfoBlock::InfoBlock(const Reader& lisp) : - Block(sprite_manager->create("images/objects/bonus_block/infoblock.sprite")), + Block(SpriteManager::current()->create("images/objects/bonus_block/infoblock.sprite")), message(), shown_pct(0), dest_pct(0), diff --git a/src/object/invisible_block.cpp b/src/object/invisible_block.cpp index 6fc64ea91..3f4a8c59b 100644 --- a/src/object/invisible_block.cpp +++ b/src/object/invisible_block.cpp @@ -22,11 +22,11 @@ #include "supertux/constants.hpp" InvisibleBlock::InvisibleBlock(const Vector& pos) : - Block(sprite_manager->create("images/objects/bonus_block/invisibleblock.sprite")), + Block(SpriteManager::current()->create("images/objects/bonus_block/invisibleblock.sprite")), visible(false) { bbox.set_pos(pos); - sound_manager->preload("sounds/brick.wav"); + SoundManager::current()->preload("sounds/brick.wav"); } void @@ -62,7 +62,7 @@ InvisibleBlock::collision(GameObject& other, const CollisionHit& hit_) void InvisibleBlock::hit(Player& player) { - sound_manager->play("sounds/brick.wav"); + SoundManager::current()->play("sounds/brick.wav"); if(visible) return; diff --git a/src/object/lantern.cpp b/src/object/lantern.cpp index bde417162..798ccb438 100644 --- a/src/object/lantern.cpp +++ b/src/object/lantern.cpp @@ -33,10 +33,10 @@ Lantern::Lantern(const Reader& reader) : std::vector vColor; reader.get("color", vColor); lightcolor = Color(vColor); - lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite"); + lightsprite = SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light.sprite"); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); updateColor(); - sound_manager->preload("sounds/willocatch.wav"); + SoundManager::current()->preload("sounds/willocatch.wav"); } Lantern::Lantern(const Vector& pos) : @@ -44,10 +44,10 @@ Lantern::Lantern(const Vector& pos) : lightcolor(0.0f, 0.0f, 0.0f), lightsprite() { - lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite"); + lightsprite = SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light.sprite"); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); updateColor(); - sound_manager->preload("sounds/willocatch.wav"); + SoundManager::current()->preload("sounds/willocatch.wav"); } Lantern::~Lantern() @@ -84,7 +84,7 @@ HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) { WillOWisp* wow = dynamic_cast(&other); if (wow) { // collided with WillOWisp while grabbed and unlit - sound_manager->play("sounds/willocatch.wav"); + SoundManager::current()->play("sounds/willocatch.wav"); lightcolor = Color(0,1,0); updateColor(); wow->vanish(); @@ -92,7 +92,7 @@ HitResponse Lantern::collision(GameObject& other, const CollisionHit& hit) { TreeWillOWisp* twow = dynamic_cast(&other); if (twow) { // collided with TreeWillOWisp while grabbed and unlit - sound_manager->play("sounds/willocatch.wav"); + SoundManager::current()->play("sounds/willocatch.wav"); lightcolor = twow->get_color(); updateColor(); twow->vanish(); diff --git a/src/object/light.cpp b/src/object/light.cpp index 92a193482..34ebea85b 100644 --- a/src/object/light.cpp +++ b/src/object/light.cpp @@ -23,7 +23,7 @@ Light::Light(const Vector& center, const Color& color_) : color(color_), sprite() { - sprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite"); + sprite = SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light.sprite"); } Light::~Light() diff --git a/src/object/moving_sprite.cpp b/src/object/moving_sprite.cpp index a9d877a0f..7d4f708f0 100644 --- a/src/object/moving_sprite.cpp +++ b/src/object/moving_sprite.cpp @@ -28,7 +28,7 @@ MovingSprite::MovingSprite(const Vector& pos, const std::string& sprite_name_, layer(layer_) { bbox.set_pos(pos); - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); set_group(collision_group); } @@ -42,7 +42,7 @@ MovingSprite::MovingSprite(const Reader& reader, const Vector& pos, int layer_, if (!reader.get("sprite", sprite_name)) throw std::runtime_error("no sprite name set"); - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); set_group(collision_group); } @@ -56,7 +56,7 @@ MovingSprite::MovingSprite(const Reader& reader, const std::string& sprite_name_ reader.get("y", bbox.p1.y); reader.get("sprite", this->sprite_name); - sprite = sprite_manager->create(this->sprite_name); + sprite = SpriteManager::current()->create(this->sprite_name); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); set_group(collision_group); } @@ -71,7 +71,7 @@ MovingSprite::MovingSprite(const Reader& reader, int layer_, CollisionGroup coll if (!reader.get("sprite", sprite_name)) throw std::runtime_error("no sprite name set"); - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); set_group(collision_group); } diff --git a/src/object/player.cpp b/src/object/player.cpp index 8a09076fe..ab375d7e0 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -160,23 +160,23 @@ Player::Player(PlayerStatus* _player_status, const std::string& name_) : climbing(0) { this->name = name_; - controller = g_input_manager->get_controller(); + controller = InputManager::current()->get_controller(); scripting_controller.reset(new CodeController()); // if/when we have complete penny gfx, we can // load those instead of Tux's sprite in the // constructor - sprite = sprite_manager->create("images/creatures/tux/tux.sprite"); + sprite = SpriteManager::current()->create("images/creatures/tux/tux.sprite"); airarrow = Surface::create("images/engine/hud/airarrow.png"); idle_timer.start(IDLE_TIME[0]/1000.0f); - sound_manager->preload("sounds/bigjump.wav"); - sound_manager->preload("sounds/jump.wav"); - sound_manager->preload("sounds/hurt.wav"); - sound_manager->preload("sounds/kill.wav"); - sound_manager->preload("sounds/skid.wav"); - sound_manager->preload("sounds/flip.wav"); - sound_manager->preload("sounds/invincible_start.ogg"); - sound_manager->preload("sounds/splash.ogg"); + SoundManager::current()->preload("sounds/bigjump.wav"); + SoundManager::current()->preload("sounds/jump.wav"); + SoundManager::current()->preload("sounds/hurt.wav"); + SoundManager::current()->preload("sounds/kill.wav"); + SoundManager::current()->preload("sounds/skid.wav"); + SoundManager::current()->preload("sounds/flip.wav"); + SoundManager::current()->preload("sounds/invincible_start.ogg"); + SoundManager::current()->preload("sounds/splash.ogg"); init(); } @@ -550,7 +550,7 @@ Player::handle_horizontal_input() // let's skid! if(fabs(vx)>SKID_XM && !skidding_timer.started()) { skidding_timer.start(SKID_TIME); - sound_manager->play("sounds/skid.wav"); + SoundManager::current()->play("sounds/skid.wav"); // dust some particles Sector::current()->add_object( new Particles( @@ -644,7 +644,7 @@ Player::do_backflip() { backflip_direction = (dir == LEFT)?(+1):(-1); backflipping = true; do_jump(-580); - sound_manager->play("sounds/flip.wav"); + SoundManager::current()->play("sounds/flip.wav"); backflip_timer.start(TUX_BACKFLIP_TIME); } @@ -661,9 +661,9 @@ Player::do_jump(float yspeed) { // play sound if (is_big()) { - sound_manager->play("sounds/bigjump.wav"); + SoundManager::current()->play("sounds/bigjump.wav"); } else { - sound_manager->play("sounds/jump.wav"); + SoundManager::current()->play("sounds/jump.wav"); } } @@ -1185,7 +1185,7 @@ Player::collision_tile(uint32_t tile_attributes) if( tile_attributes & Tile::WATER ){ swimming = true; no_water = false; - sound_manager->play( "sounds/splash.ogg" ); + SoundManager::current()->play( "sounds/splash.ogg" ); } } #endif @@ -1285,7 +1285,7 @@ Player::collision(GameObject& other, const CollisionHit& hit) void Player::make_invincible() { - sound_manager->play("sounds/invincible_start.ogg"); + SoundManager::current()->play("sounds/invincible_start.ogg"); invincible_timer.start(TUX_INVINCIBLE_TIME); Sector::current()->play_music(HERRING_MUSIC); } @@ -1307,7 +1307,7 @@ Player::kill(bool completely) physic.set_velocity_x(0); if(!completely && is_big()) { - sound_manager->play("sounds/hurt.wav"); + SoundManager::current()->play("sounds/hurt.wav"); if(player_status->bonus == FIRE_BONUS || player_status->bonus == ICE_BONUS) { @@ -1326,7 +1326,7 @@ Player::kill(bool completely) duck = false; } } else { - sound_manager->play("sounds/kill.wav"); + SoundManager::current()->play("sounds/kill.wav"); // do not die when in edit mode if (edit_mode) { @@ -1362,7 +1362,7 @@ Player::kill(bool completely) // TODO: need nice way to handle players dying in co-op mode Sector::current()->effect->fade_out(3.0); - sound_manager->stop_music(3.0); + SoundManager::current()->stop_music(3.0); } } diff --git a/src/object/powerup.cpp b/src/object/powerup.cpp index 09feaafb0..686b4072d 100644 --- a/src/object/powerup.cpp +++ b/src/object/powerup.cpp @@ -34,14 +34,14 @@ PowerUp::PowerUp(const Reader& lisp) : script(), no_physics(), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { lisp.get("script", script); no_physics = false; lisp.get("disable-physics", no_physics); physic.enable_gravity(true); - sound_manager->preload("sounds/grow.ogg"); - sound_manager->preload("sounds/fire-flower.wav"); + SoundManager::current()->preload("sounds/grow.ogg"); + SoundManager::current()->preload("sounds/fire-flower.wav"); //set default light for glow effect for standard sprites lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); lightsprite->set_color(Color(0.0f, 0.0f, 0.0f)); @@ -63,11 +63,11 @@ PowerUp::PowerUp(const Vector& pos, const std::string& sprite_name_) : script(), no_physics(false), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { physic.enable_gravity(true); - sound_manager->preload("sounds/grow.ogg"); - sound_manager->preload("sounds/fire-flower.wav"); + SoundManager::current()->preload("sounds/grow.ogg"); + SoundManager::current()->preload("sounds/fire-flower.wav"); //set default light for glow effect for standard sprites lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); lightsprite->set_color(Color(0.0f, 0.0f, 0.0f)); @@ -111,15 +111,15 @@ PowerUp::collision(GameObject& other, const CollisionHit&) if (sprite_name == "images/powerups/egg/egg.sprite") { if(!player->add_bonus(GROWUP_BONUS, true)) return FORCE_MOVE; - sound_manager->play("sounds/grow.ogg"); + SoundManager::current()->play("sounds/grow.ogg"); } else if (sprite_name == "images/powerups/fireflower/fireflower.sprite") { if(!player->add_bonus(FIRE_BONUS, true)) return FORCE_MOVE; - sound_manager->play("sounds/fire-flower.wav"); + SoundManager::current()->play("sounds/fire-flower.wav"); } else if (sprite_name == "images/powerups/iceflower/iceflower.sprite") { if(!player->add_bonus(ICE_BONUS, true)) return FORCE_MOVE; - sound_manager->play("sounds/fire-flower.wav"); + SoundManager::current()->play("sounds/fire-flower.wav"); } else if (sprite_name == "images/powerups/star/star.sprite") { player->make_invincible(); } else if (sprite_name == "images/powerups/1up/1up.sprite") { diff --git a/src/object/pushbutton.cpp b/src/object/pushbutton.cpp index 19cc9f9aa..e5b7175e4 100644 --- a/src/object/pushbutton.cpp +++ b/src/object/pushbutton.cpp @@ -35,7 +35,7 @@ PushButton::PushButton(const Reader& lisp) : script(), state(OFF) { - sound_manager->preload(BUTTON_SOUND); + SoundManager::current()->preload(BUTTON_SOUND); set_action("off", -1); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); @@ -69,7 +69,7 @@ PushButton::collision(GameObject& other, const CollisionHit& hit) set_pos(get_pos() + Vector(0, old_bbox_height - new_bbox_height)); // play sound - sound_manager->play(BUTTON_SOUND); + SoundManager::current()->play(BUTTON_SOUND); // run script std::istringstream stream(script); diff --git a/src/object/rainsplash.cpp b/src/object/rainsplash.cpp index d03b014f4..dcb6b4f1c 100644 --- a/src/object/rainsplash.cpp +++ b/src/object/rainsplash.cpp @@ -23,8 +23,8 @@ RainSplash::RainSplash(Vector pos, bool vertical) : { frame = 0; position = pos; - if (vertical) sprite = sprite_manager->create("images/objects/particles/rainsplash-vertical.sprite"); - else sprite = sprite_manager->create("images/objects/particles/rainsplash.sprite"); + if (vertical) sprite = SpriteManager::current()->create("images/objects/particles/rainsplash-vertical.sprite"); + else sprite = SpriteManager::current()->create("images/objects/particles/rainsplash.sprite"); } RainSplash::~RainSplash() { diff --git a/src/object/rock.cpp b/src/object/rock.cpp index 48dee0040..8f60e661d 100644 --- a/src/object/rock.cpp +++ b/src/object/rock.cpp @@ -30,7 +30,7 @@ Rock::Rock(const Vector& pos, std::string spritename) : grabbed(), last_movement() { - sound_manager->preload(ROCK_SOUND); + SoundManager::current()->preload(ROCK_SOUND); on_ground = false; grabbed = false; set_group(COLGROUP_MOVING_STATIC); @@ -43,7 +43,7 @@ Rock::Rock(const Reader& reader) : grabbed(), last_movement() { - sound_manager->preload(ROCK_SOUND); + SoundManager::current()->preload(ROCK_SOUND); on_ground = false; grabbed = false; set_group(COLGROUP_MOVING_STATIC); @@ -56,7 +56,7 @@ Rock::Rock(const Reader& reader, std::string spritename) : grabbed(), last_movement() { - sound_manager->preload(ROCK_SOUND); + SoundManager::current()->preload(ROCK_SOUND); on_ground = false; grabbed = false; set_group(COLGROUP_MOVING_STATIC); @@ -87,7 +87,7 @@ Rock::collision_solid(const CollisionHit& hit) physic.set_velocity(0, 0); if(hit.bottom && !on_ground && !grabbed) { - sound_manager->play(ROCK_SOUND, get_pos()); + SoundManager::current()->play(ROCK_SOUND, get_pos()); on_ground = true; } } diff --git a/src/object/rusty_trampoline.cpp b/src/object/rusty_trampoline.cpp index 002af2427..f378d0df6 100644 --- a/src/object/rusty_trampoline.cpp +++ b/src/object/rusty_trampoline.cpp @@ -37,7 +37,7 @@ RustyTrampoline::RustyTrampoline(const Reader& lisp) : Rock(lisp, "images/objects/rusty-trampoline/rusty-trampoline.sprite"), portable(true), counter(3) { - sound_manager->preload(BOUNCE_SOUND); + SoundManager::current()->preload(BOUNCE_SOUND); lisp.get("counter", counter); lisp.get("portable", portable); //do we really need this? @@ -76,7 +76,7 @@ RustyTrampoline::collision(GameObject& other, const CollisionHit& hit) vy = VY_BOUNCE; } player->get_physic().set_velocity_y(vy); - sound_manager->play(BOUNCE_SOUND); + SoundManager::current()->play(BOUNCE_SOUND); counter--; if (counter > 0) { sprite->set_action("swinging", 1); @@ -95,7 +95,7 @@ RustyTrampoline::collision(GameObject& other, const CollisionHit& hit) if(hit.top && vy >= 0) { vy = VY_BOUNCE; walking_badguy->set_velocity_y(vy); - sound_manager->play(BOUNCE_SOUND); + SoundManager::current()->play(BOUNCE_SOUND); counter--; if (counter > 0) { sprite->set_action("swinging", 1); diff --git a/src/object/smoke_cloud.cpp b/src/object/smoke_cloud.cpp index 734a029ee..ef7fc20db 100644 --- a/src/object/smoke_cloud.cpp +++ b/src/object/smoke_cloud.cpp @@ -25,7 +25,7 @@ SmokeCloud::SmokeCloud(const Vector& pos) : position(pos) { timer.start(.3f); - sprite = sprite_manager->create("images/objects/particles/stomp.sprite"); + sprite = SpriteManager::current()->create("images/objects/particles/stomp.sprite"); } SmokeCloud::~SmokeCloud() diff --git a/src/object/spotlight.cpp b/src/object/spotlight.cpp index 429c800f6..2055b0e2c 100644 --- a/src/object/spotlight.cpp +++ b/src/object/spotlight.cpp @@ -40,11 +40,11 @@ Spotlight::Spotlight(const Reader& lisp) : color = Color( vColor ); } - center = sprite_manager->create("images/objects/spotlight/spotlight_center.sprite"); - base = sprite_manager->create("images/objects/spotlight/spotlight_base.sprite"); - lights = sprite_manager->create("images/objects/spotlight/spotlight_lights.sprite"); - lightcone = sprite_manager->create("images/objects/spotlight/lightcone.sprite"); - light = sprite_manager->create("images/objects/spotlight/light.sprite"); + center = SpriteManager::current()->create("images/objects/spotlight/spotlight_center.sprite"); + base = SpriteManager::current()->create("images/objects/spotlight/spotlight_base.sprite"); + lights = SpriteManager::current()->create("images/objects/spotlight/spotlight_lights.sprite"); + lightcone = SpriteManager::current()->create("images/objects/spotlight/lightcone.sprite"); + light = SpriteManager::current()->create("images/objects/spotlight/light.sprite"); } diff --git a/src/object/sprite_particle.cpp b/src/object/sprite_particle.cpp index 82e70fa15..028520799 100644 --- a/src/object/sprite_particle.cpp +++ b/src/object/sprite_particle.cpp @@ -33,10 +33,10 @@ SpriteParticle::SpriteParticle(std::string sprite_name, std::string action, acceleration(acceleration_), drawing_layer(drawing_layer_), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-tiny.sprite")), + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-tiny.sprite")), glow(false) { - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); if (!sprite.get()) throw std::runtime_error("Could not load sprite "+sprite_name); sprite->set_action(action, 1); sprite->set_animation_loops(1); //TODO: this is necessary because set_action will not set "loops" when "action" is the default action diff --git a/src/object/star.cpp b/src/object/star.cpp index 36a2b2096..66f82114a 100644 --- a/src/object/star.cpp +++ b/src/object/star.cpp @@ -31,7 +31,7 @@ Star::Star(const Vector& pos, Direction direction) : MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING), physic(), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { physic.set_velocity((direction == LEFT) ? -STAR_SPEED : STAR_SPEED, INITIALJUMP); //set light for glow effect diff --git a/src/object/thunderstorm.cpp b/src/object/thunderstorm.cpp index 793d6ab3f..187a4c30d 100644 --- a/src/object/thunderstorm.cpp +++ b/src/object/thunderstorm.cpp @@ -46,8 +46,8 @@ Thunderstorm::Thunderstorm(const Reader& reader) : } layer = reader_get_layer (reader, /* default = */ LAYER_BACKGROUNDTILES-1); - sound_manager->preload("sounds/thunder.wav"); - sound_manager->preload("sounds/lightning.wav"); + SoundManager::current()->preload("sounds/thunder.wav"); + SoundManager::current()->preload("sounds/lightning.wav"); if (running) { running = false; // else start() is ignored @@ -118,7 +118,7 @@ Thunderstorm::stop() void Thunderstorm::thunder() { - sound_manager->play("sounds/thunder.wav"); + SoundManager::current()->play("sounds/thunder.wav"); } void @@ -131,7 +131,7 @@ Thunderstorm::lightning() void Thunderstorm::flash() { - sound_manager->play("sounds/lightning.wav"); + SoundManager::current()->play("sounds/lightning.wav"); flash_display_timer.start(FLASH_DISPLAY_TIME); } diff --git a/src/object/trampoline.cpp b/src/object/trampoline.cpp index 9d4e12a13..b1c2fbc5a 100644 --- a/src/object/trampoline.cpp +++ b/src/object/trampoline.cpp @@ -36,14 +36,14 @@ Trampoline::Trampoline(const Reader& lisp) : Rock(lisp, "images/objects/trampoline/trampoline.sprite"), portable(true) { - sound_manager->preload(TRAMPOLINE_SOUND); + SoundManager::current()->preload(TRAMPOLINE_SOUND); //Check if this trampoline is not portable if(lisp.get("portable", portable)) { if(!portable) { //we need another sprite sprite_name = "images/objects/trampoline/trampoline_fix.sprite"; - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); sprite->set_action("normal"); } } @@ -53,10 +53,10 @@ Trampoline::Trampoline(const Vector& pos, bool port) : Rock(pos, "images/objects/trampoline/trampoline.sprite"), portable(port) { - sound_manager->preload(TRAMPOLINE_SOUND); + SoundManager::current()->preload(TRAMPOLINE_SOUND); if(!port) { sprite_name = "images/objects/trampoline/trampoline_fix.sprite"; - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); sprite->set_action("normal"); } } @@ -89,7 +89,7 @@ Trampoline::collision(GameObject& other, const CollisionHit& hit) vy = VY_INITIAL; } player->get_physic().set_velocity_y(vy); - sound_manager->play(TRAMPOLINE_SOUND); + SoundManager::current()->play(TRAMPOLINE_SOUND); sprite->set_action("swinging", 1); return FORCE_MOVE; } @@ -102,7 +102,7 @@ Trampoline::collision(GameObject& other, const CollisionHit& hit) if(hit.top && vy >= 0) { vy = VY_INITIAL; walking_badguy->set_velocity_y(vy); - sound_manager->play(TRAMPOLINE_SOUND); + SoundManager::current()->play(TRAMPOLINE_SOUND); sprite->set_action("swinging", 1); return FORCE_MOVE; } diff --git a/src/object/weak_block.cpp b/src/object/weak_block.cpp index 3a3f07edf..834dc5fdb 100644 --- a/src/object/weak_block.cpp +++ b/src/object/weak_block.cpp @@ -33,14 +33,14 @@ WeakBlock::WeakBlock(const Reader& lisp) : MovingSprite(lisp, "images/objects/weak_block/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL), linked(true), light(0.0f,0.0f,0.0f), - lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite")) + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { sprite->set_action("normal"); //Check if this weakblock destroys adjacent weakblocks if(lisp.get("linked", linked)){ if(! linked){ sprite_name = "images/objects/weak_block/meltbox.sprite"; - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); sprite->set_action("normal"); } } @@ -48,7 +48,7 @@ WeakBlock::WeakBlock(const Reader& lisp) lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); lightsprite->set_color(Color(0.3f, 0.2f, 0.1f)); } else if(sprite_name == "images/objects/weak_block/meltbox.sprite") - sound_manager->preload("sounds/sizzle.ogg"); + SoundManager::current()->preload("sounds/sizzle.ogg"); } HitResponse @@ -129,7 +129,7 @@ WeakBlock::update(float ) sprite->set_action("disintegrating", 1); spreadHit(); set_group(COLGROUP_DISABLED); - lightsprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light-tiny.sprite"); + lightsprite = SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-tiny.sprite"); lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); lightsprite->set_color(Color(0.3f, 0.2f, 0.1f)); } @@ -170,7 +170,7 @@ WeakBlock::startBurning() state = STATE_BURNING; sprite->set_action("burning", 1); if(sprite_name == "images/objects/weak_block/meltbox.sprite") - sound_manager->play("sounds/sizzle.ogg"); + SoundManager::current()->play("sounds/sizzle.ogg"); } void diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index af907e37d..216aeb693 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -66,37 +66,37 @@ void wait(HSQUIRRELVM vm, float seconds) void wait_for_screenswitch(HSQUIRRELVM vm) { - g_screen_manager->m_waiting_threads.add(vm); + ScreenManager::current()->m_waiting_threads.add(vm); } void exit_screen() { - g_screen_manager->pop_screen(); + ScreenManager::current()->pop_screen(); } void fadeout_screen(float seconds) { - g_screen_manager->set_screen_fade(std::unique_ptr(new FadeOut(seconds))); + ScreenManager::current()->set_screen_fade(std::unique_ptr(new FadeOut(seconds))); } void shrink_screen(float dest_x, float dest_y, float seconds) { - g_screen_manager->set_screen_fade(std::unique_ptr(new ShrinkFade(Vector(dest_x, dest_y), seconds))); + ScreenManager::current()->set_screen_fade(std::unique_ptr(new ShrinkFade(Vector(dest_x, dest_y), seconds))); } void abort_screenfade() { - g_screen_manager->set_screen_fade(std::unique_ptr()); + ScreenManager::current()->set_screen_fade(std::unique_ptr()); } std::string translate(const std::string& text) { - return dictionary_manager->get_dictionary().translate(text); + return g_dictionary_manager->get_dictionary().translate(text); } void display_text_file(const std::string& filename) { - g_screen_manager->push_screen(std::unique_ptr(new TextScroller(filename))); + ScreenManager::current()->push_screen(std::unique_ptr(new TextScroller(filename))); } void load_worldmap(const std::string& filename) @@ -109,7 +109,7 @@ void load_worldmap(const std::string& filename) } else { - g_screen_manager->push_screen(std::unique_ptr(new WorldMap(filename, WorldMap::current()->get_savegame()))); + ScreenManager::current()->push_screen(std::unique_ptr(new WorldMap(filename, WorldMap::current()->get_savegame()))); } } @@ -121,7 +121,7 @@ void load_level(const std::string& filename) } else { - g_screen_manager->push_screen(std::unique_ptr(new GameSession(filename, GameSession::current()->get_savegame()))); + ScreenManager::current()->push_screen(std::unique_ptr(new GameSession(filename, GameSession::current()->get_savegame()))); } } @@ -205,12 +205,12 @@ bool validate_sector_player() void play_music(const std::string& filename) { - sound_manager->play_music(filename); + SoundManager::current()->play_music(filename); } void play_sound(const std::string& filename) { - sound_manager->play(filename); + SoundManager::current()->play(filename); } void grease() @@ -282,7 +282,7 @@ void set_gamma(float gamma) void quit() { - g_screen_manager->quit(); + ScreenManager::current()->quit(); } int rand() diff --git a/src/sprite/sprite_manager.hpp b/src/sprite/sprite_manager.hpp index d769f1d92..070a29420 100644 --- a/src/sprite/sprite_manager.hpp +++ b/src/sprite/sprite_manager.hpp @@ -22,10 +22,11 @@ #include #include "sprite/sprite_ptr.hpp" +#include "util/currenton.hpp" class SpriteData; -class SpriteManager +class SpriteManager : public Currenton { private: typedef std::map Sprites; diff --git a/src/supertux/game_manager.cpp b/src/supertux/game_manager.cpp index 45215d362..1692a84d4 100644 --- a/src/supertux/game_manager.cpp +++ b/src/supertux/game_manager.cpp @@ -54,7 +54,7 @@ GameManager::start_level(std::unique_ptr world, const std::string& level_ std::unique_ptr screen(new LevelsetScreen(m_world->get_basedir(), level_filename, *m_savegame)); - g_screen_manager->push_screen(std::move(screen)); + ScreenManager::current()->push_screen(std::move(screen)); } void @@ -66,7 +66,7 @@ GameManager::start_worldmap(std::unique_ptr world) m_savegame.reset(new Savegame(m_world->get_savegame_filename())); m_savegame->load(); - g_screen_manager->push_screen(std::unique_ptr( + ScreenManager::current()->push_screen(std::unique_ptr( new worldmap::WorldMap(m_world->get_worldmap_filename(), *m_savegame))); } diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index 0e621bdaf..8b0794c71 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -55,7 +55,7 @@ GameSession::GameSession(const std::string& levelfile_, Savegame& savegame, Stat pause_menu_frame(), end_sequence(0), game_pause(false), - speed_before_pause(g_screen_manager->get_speed()), + speed_before_pause(ScreenManager::current()->get_speed()), levelfile(levelfile_), reset_sector(), reset_pos(), @@ -96,7 +96,7 @@ GameSession::restart_level() game_pause = false; end_sequence = 0; - g_input_manager->reset(); + InputManager::current()->reset(); currentsector = 0; @@ -125,11 +125,11 @@ GameSession::restart_level() } } catch(std::exception& e) { log_fatal << "Couldn't start level: " << e.what() << std::endl; - g_screen_manager->pop_screen(); + ScreenManager::current()->pop_screen(); return (-1); } - sound_manager->stop_music(); + SoundManager::current()->stop_music(); currentsector->play_music(LEVEL_MUSIC); if(capture_file != "") { @@ -244,8 +244,8 @@ GameSession::toggle_pause() // pause if (!game_pause && !MenuManager::instance().is_active()) { - speed_before_pause = g_screen_manager->get_speed(); - g_screen_manager->set_speed(0); + speed_before_pause = ScreenManager::current()->get_speed(); + ScreenManager::current()->set_speed(0); MenuManager::instance().set_menu(MenuStorage::GAME_MENU); game_pause = true; } @@ -257,7 +257,7 @@ void GameSession::abort_level() { MenuManager::instance().clear_menu_stack(); - g_screen_manager->pop_screen(); + ScreenManager::current()->pop_screen(); currentsector->player->set_bonus(bonus_at_start); PlayerStatus *currentStatus = m_savegame.get_player_status(); currentStatus->coins = coins_at_start; @@ -349,7 +349,7 @@ GameSession::process_events() // save input for demo? if(capture_demo_stream != 0) { - Controller *controller = g_input_manager->get_controller(); + Controller *controller = InputManager::current()->get_controller(); capture_demo_stream ->put(controller->hold(Controller::LEFT)); capture_demo_stream ->put(controller->hold(Controller::RIGHT)); capture_demo_stream ->put(controller->hold(Controller::UP)); @@ -404,7 +404,7 @@ GameSession::setup() int total_stats_to_be_collected = level->stats.total_coins + level->stats.total_badguys + level->stats.total_secrets; if ((!levelintro_shown) && (total_stats_to_be_collected > 0)) { levelintro_shown = true; - g_screen_manager->push_screen(std::unique_ptr(new LevelIntro(level.get(), best_level_statistics))); + ScreenManager::current()->push_screen(std::unique_ptr(new LevelIntro(level.get(), best_level_statistics))); } } @@ -417,12 +417,12 @@ void GameSession::update(float elapsed_time) { // handle controller - if(g_input_manager->get_controller()->pressed(Controller::PAUSE_MENU)) + if(InputManager::current()->get_controller()->pressed(Controller::PAUSE_MENU)) { on_escape_press(); } - if(g_input_manager->get_controller()->pressed(Controller::CHEAT_MENU)) + if(InputManager::current()->get_controller()->pressed(Controller::CHEAT_MENU)) { if (!MenuManager::instance().is_active()) { @@ -435,7 +435,7 @@ GameSession::update(float elapsed_time) // Unpause the game if the menu has been closed if (game_pause && !MenuManager::instance().is_active()) { - g_screen_manager->set_speed(speed_before_pause); + ScreenManager::current()->set_speed(speed_before_pause); game_pause = false; } @@ -475,7 +475,7 @@ GameSession::update(float elapsed_time) } // update sounds - if (currentsector && currentsector->camera) sound_manager->set_listener_position(currentsector->camera->get_center()); + if (currentsector && currentsector->camera) SoundManager::current()->set_listener_position(currentsector->camera->get_center()); /* Handle music: */ if (end_sequence) @@ -515,7 +515,7 @@ GameSession::finish(bool win) } } - g_screen_manager->pop_screen(); + ScreenManager::current()->pop_screen(); } void @@ -575,12 +575,12 @@ GameSession::start_sequence(const std::string& sequencename) } /* slow down the game for end-sequence */ - g_screen_manager->set_speed(0.5f); + ScreenManager::current()->set_speed(0.5f); currentsector->add_object(end_sequence); end_sequence->start(); - sound_manager->play_music("music/leveldone.ogg", false); + SoundManager::current()->play_music("music/leveldone.ogg", false); currentsector->player->set_winning(); // Stop all clocks. diff --git a/src/supertux/gameconfig.cpp b/src/supertux/gameconfig.cpp index 2ddadb8d3..f7fa917c3 100644 --- a/src/supertux/gameconfig.cpp +++ b/src/supertux/gameconfig.cpp @@ -95,8 +95,8 @@ Config::load() } const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control"); - if(config_control_lisp && g_input_manager) { - g_input_manager->read(*config_control_lisp); + if(config_control_lisp && InputManager::current()) { + InputManager::current()->read(*config_control_lisp); } const lisp::Lisp* config_addons_lisp = config_lisp->get_lisp("addons"); @@ -141,9 +141,9 @@ Config::save() writer.write("music_enabled", music_enabled); writer.end_list("audio"); - if(g_input_manager) { + if(InputManager::current()) { writer.start_list("control"); - g_input_manager->write(writer); + InputManager::current()->write(writer); writer.end_list("control"); } diff --git a/src/supertux/globals.cpp b/src/supertux/globals.cpp index 7f1a9f850..d6d4d758a 100644 --- a/src/supertux/globals.cpp +++ b/src/supertux/globals.cpp @@ -15,29 +15,20 @@ // along with this program. If not, see . #include "supertux/globals.hpp" + #include -InputManager* g_input_manager = 0; -tinygettext::DictionaryManager* dictionary_manager = 0; +#include "supertux/gameconfig.hpp" int SCREEN_WIDTH; int SCREEN_HEIGHT; -ScreenManager* g_screen_manager = 0; - -TextureManager* texture_manager = 0; - -SoundManager* sound_manager = 0; - -Config* g_config = 0; +std::unique_ptr g_config; float game_time = 0; float real_time = 0; -TileManager* tile_manager = NULL; -TileSet* current_tileset = NULL; - -SpriteManager* sprite_manager = NULL; +TileSet* current_tileset = NULL; float g_game_speed = 1.0f; diff --git a/src/supertux/globals.hpp b/src/supertux/globals.hpp index 6aca5eb48..f1894ef6f 100644 --- a/src/supertux/globals.hpp +++ b/src/supertux/globals.hpp @@ -17,16 +17,11 @@ #ifndef HEADER_SUPERTUX_SUPERTUX_GLOBALS_HPP #define HEADER_SUPERTUX_SUPERTUX_GLOBALS_HPP +#include + typedef struct SDL_Surface SDL_Surface; namespace tinygettext { class DictionaryManager; } class Config; -class InputManager; -class PlayerStatus; -class ScreenManager; -class SoundManager; -class SpriteManager; -class TextureManager; -class TileManager; class TileSet; /** The width of the display (this is a logical value, not the @@ -39,28 +34,13 @@ extern int SCREEN_WIDTH; shrink or scale things) */ extern int SCREEN_HEIGHT; -// global variables -extern InputManager* g_input_manager; - -extern ScreenManager* g_screen_manager; - -extern TextureManager* texture_manager; - -extern SoundManager* sound_manager; - -extern Config* g_config; - -extern tinygettext::DictionaryManager* dictionary_manager; +extern std::unique_ptr g_config; extern float game_time; extern float real_time; -extern TileManager *tile_manager; - /** this is only set while loading a map */ -extern TileSet *current_tileset; - -extern SpriteManager* sprite_manager; +extern TileSet* current_tileset; extern float g_game_speed; diff --git a/src/supertux/level.cpp b/src/supertux/level.cpp index 73f3a6ff1..2a3674e01 100644 --- a/src/supertux/level.cpp +++ b/src/supertux/level.cpp @@ -70,14 +70,14 @@ Level::load(const std::string& filepath) level->get("version", version); if(version == 1) { log_info << "[" << filepath << "] level uses old format: version 1" << std::endl; - tileset = tile_manager->get_tileset("images/tiles.strf"); + tileset = TileManager::current()->get_tileset("images/tiles.strf"); load_old_format(*level); return; } const lisp::Lisp* tilesets_lisp = level->get_lisp("tilesets"); if(tilesets_lisp != NULL) { - tileset = tile_manager->parse_tileset_definition(*tilesets_lisp).release(); + tileset = TileManager::current()->parse_tileset_definition(*tilesets_lisp).release(); free_tileset = true; } std::string tileset_name; @@ -85,12 +85,12 @@ Level::load(const std::string& filepath) if(tileset != NULL) { log_warning << "[" << filepath << "] multiple tilesets specified in level" << std::endl; } else { - tileset = tile_manager->get_tileset(tileset_name); + tileset = TileManager::current()->get_tileset(tileset_name); } } /* load default tileset */ if(tileset == NULL) { - tileset = tile_manager->get_tileset("images/tiles.strf"); + tileset = TileManager::current()->get_tileset("images/tiles.strf"); } current_tileset = tileset; diff --git a/src/supertux/levelintro.cpp b/src/supertux/levelintro.cpp index d20a4a7b4..82b9651d5 100644 --- a/src/supertux/levelintro.cpp +++ b/src/supertux/levelintro.cpp @@ -36,7 +36,7 @@ LevelIntro::LevelIntro(const Level* level_, const Statistics* best_level_statist player_sprite_vy(0), player_sprite_jump_timer() { - player_sprite = sprite_manager->create("images/creatures/tux/tux.sprite"); + player_sprite = SpriteManager::current()->create("images/creatures/tux/tux.sprite"); player_sprite->set_action("small-walk-right"); player_sprite_jump_timer.start(graphicsRandom.randf(5,10)); } @@ -53,14 +53,14 @@ LevelIntro::setup() void LevelIntro::update(float elapsed_time) { - Controller *controller = g_input_manager->get_controller(); + Controller *controller = InputManager::current()->get_controller(); // Check if it's time to exit the screen if(controller->pressed(Controller::JUMP) || controller->pressed(Controller::ACTION) || controller->pressed(Controller::MENU_SELECT) || controller->pressed(Controller::PAUSE_MENU)) { - g_screen_manager->pop_screen(std::unique_ptr(new FadeOut(0.1))); + ScreenManager::current()->pop_screen(std::unique_ptr(new FadeOut(0.1))); } player_sprite_py += player_sprite_vy * elapsed_time; diff --git a/src/supertux/levelset_screen.cpp b/src/supertux/levelset_screen.cpp index 9ce906ccf..dde3cd251 100644 --- a/src/supertux/levelset_screen.cpp +++ b/src/supertux/levelset_screen.cpp @@ -73,7 +73,7 @@ LevelsetScreen::setup() // this gets called when the GameSession is done and we return back to the m_savegame.set_levelset_state(m_basedir, m_level_filename, m_solved); m_savegame.save(); - g_screen_manager->pop_screen(); + ScreenManager::current()->pop_screen(); } else { @@ -81,7 +81,7 @@ LevelsetScreen::setup() std::unique_ptr screen(new GameSession(FileSystem::join(m_basedir, m_level_filename), m_savegame)); - g_screen_manager->push_screen(std::move(screen)); + ScreenManager::current()->push_screen(std::move(screen)); } } diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 7054f37ce..1be3a0a9b 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -38,10 +38,11 @@ extern "C" { #include "physfs/physfs_file_system.hpp" #include "physfs/physfs_sdl.hpp" #include "scripting/squirrel_util.hpp" +#include "sprite/sprite_manager.hpp" +#include "supertux/command_line_arguments.hpp" #include "supertux/game_manager.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" -#include "supertux/command_line_arguments.hpp" #include "supertux/player_status.hpp" #include "supertux/resources.hpp" #include "supertux/screen_fade.hpp" @@ -54,15 +55,13 @@ extern "C" { #include "video/renderer.hpp" #include "worldmap/worldmap.hpp" -namespace { DrawingContext *context_pointer; } - void Main::init_config() { - g_config = new Config(); + g_config.reset(new Config); try { g_config->load(); - } catch(std::exception& e) { + } catch(const std::exception& e) { log_info << "Couldn't load config file: " << e.what() << ", using default settings" << std::endl; } } @@ -70,23 +69,23 @@ Main::init_config() void Main::init_tinygettext() { - dictionary_manager = new tinygettext::DictionaryManager(); + g_dictionary_manager.reset(new tinygettext::DictionaryManager); tinygettext::Log::set_log_info_callback(0); - dictionary_manager->set_filesystem(std::unique_ptr(new PhysFSFileSystem)); + g_dictionary_manager->set_filesystem(std::unique_ptr(new PhysFSFileSystem)); - dictionary_manager->add_directory("locale"); - dictionary_manager->set_charset("UTF-8"); + g_dictionary_manager->add_directory("locale"); + g_dictionary_manager->set_charset("UTF-8"); // Config setting "locale" overrides language detection if (g_config->locale != "") { - dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale)); + g_dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale)); } else { FL_Locale *locale; FL_FindLocale(&locale); tinygettext::Language language = tinygettext::Language::from_spec( locale->lang?locale->lang:"", locale->country?locale->country:"", locale->variant?locale->variant:""); FL_FreeLocale(&locale); - dictionary_manager->set_language(language); + g_dictionary_manager->set_language(language); } } @@ -233,24 +232,6 @@ Main::init_video() << " Area: " << g_config->aspect_size << std::endl; } -void -Main::init_audio() -{ - sound_manager = new SoundManager(); - - sound_manager->enable_sound(g_config->sound_enabled); - sound_manager->enable_music(g_config->music_enabled); -} - -void -Main::quit_audio() -{ - if(sound_manager != NULL) { - delete sound_manager; - sound_manager = NULL; - } -} - static Uint32 last_timelog_ticks = 0; static const char* last_timelog_component = 0; @@ -331,7 +312,7 @@ Main::run(int argc, char** argv) Console console; timelog("controller"); - g_input_manager = new InputManager(); + InputManager input_manager; timelog("commandline"); @@ -339,11 +320,12 @@ Main::run(int argc, char** argv) std::unique_ptr video_system = VideoSystem::create(g_config->video); DrawingContext context(video_system->get_renderer(), video_system->get_lightmap()); - context_pointer = &context; init_video(); timelog("audio"); - init_audio(); + SoundManager sound_manager; + sound_manager.enable_sound(g_config->sound_enabled); + sound_manager.enable_music(g_config->music_enabled); Console::current()->init_graphics(); @@ -351,7 +333,9 @@ Main::run(int argc, char** argv) scripting::init_squirrel(g_config->enable_script_debugger); timelog("resources"); - Resources::load_shared(); + TileManager tile_manager; + SpriteManager sprite_manager; + Resources resources; timelog("addons"); AddonManager::get_instance().load_addons(); @@ -361,7 +345,7 @@ Main::run(int argc, char** argv) const std::unique_ptr default_savegame(new Savegame(std::string())); GameManager game_manager; - g_screen_manager = new ScreenManager(); + ScreenManager screen_manager; init_rand(); @@ -379,7 +363,7 @@ Main::run(int argc, char** argv) if(g_config->start_level.size() > 4 && g_config->start_level.compare(g_config->start_level.size() - 5, 5, ".stwm") == 0) { - g_screen_manager->push_screen(std::unique_ptr( + ScreenManager::current()->push_screen(std::unique_ptr( new worldmap::WorldMap( FileSystem::basename(g_config->start_level), *default_savegame))); } else { @@ -394,13 +378,13 @@ Main::run(int argc, char** argv) if(g_config->record_demo != "") session->record_demo(g_config->record_demo); - g_screen_manager->push_screen(std::move(session)); + ScreenManager::current()->push_screen(std::move(session)); } } else { - g_screen_manager->push_screen(std::unique_ptr(new TitleScreen(*default_savegame))); + ScreenManager::current()->push_screen(std::unique_ptr(new TitleScreen(*default_savegame))); } - g_screen_manager->run(context); + ScreenManager::current()->run(context); } catch(std::exception& e) { log_fatal << "Unexpected exception: " << e.what() << std::endl; result = 1; @@ -409,26 +393,16 @@ Main::run(int argc, char** argv) result = 1; } - delete g_screen_manager; - g_screen_manager = NULL; - - Resources::unload_shared(); - quit_audio(); - if(g_config) g_config->save(); - delete g_config; - g_config = NULL; - delete g_input_manager; - g_input_manager = NULL; + g_config.reset(); + scripting::exit_squirrel(); - delete texture_manager; - texture_manager = NULL; + SDL_Quit(); PHYSFS_deinit(); - delete dictionary_manager; - dictionary_manager = nullptr; + g_dictionary_manager.reset(); return result; } diff --git a/src/supertux/main.hpp b/src/supertux/main.hpp index dc91929ce..c8b321eaa 100644 --- a/src/supertux/main.hpp +++ b/src/supertux/main.hpp @@ -26,14 +26,12 @@ class Main { private: - void init_audio(); void init_config(); void init_physfs(const char* argv0); void init_rand(); void init_sdl(); void init_tinygettext(); void init_video(); - void quit_audio(); public: /** We call it run() instead of main() as main collides with diff --git a/src/supertux/menu/contrib_levelset_menu.cpp b/src/supertux/menu/contrib_levelset_menu.cpp index b0197d401..f7e03733a 100644 --- a/src/supertux/menu/contrib_levelset_menu.cpp +++ b/src/supertux/menu/contrib_levelset_menu.cpp @@ -73,7 +73,7 @@ ContribLevelsetMenu::menu_action(MenuItem* item) { if (item->kind == MN_ACTION) { - sound_manager->stop_music(); + SoundManager::current()->stop_music(); // reload the World so that we have something that we can safely // std::move() around without wreaking the ContribMenu diff --git a/src/supertux/menu/joystick_menu.cpp b/src/supertux/menu/joystick_menu.cpp index 352e83bfe..48678fa2a 100644 --- a/src/supertux/menu/joystick_menu.cpp +++ b/src/supertux/menu/joystick_menu.cpp @@ -32,7 +32,7 @@ enum { } // namespace -JoystickMenu::JoystickMenu(InputManager* input_manager) : +JoystickMenu::JoystickMenu(InputManager& input_manager) : m_input_manager(input_manager), m_joysticks_available(false) { @@ -50,16 +50,16 @@ JoystickMenu::recreate_menu() add_hl(); add_toggle(MNID_AUTO_JOYSTICK_CFG, _("Manual Configuration"), - !m_input_manager->use_game_controller()) + !m_input_manager.use_game_controller()) ->set_help(_("Use manual configuration instead of SDL2's automatic GameController support")); - if (m_input_manager->use_game_controller()) + if (m_input_manager.use_game_controller()) { m_joysticks_available = false; } else { - if (m_input_manager->joystick_manager->joysticks.size() > 0) + if (m_input_manager.joystick_manager->joysticks.size() > 0) { m_joysticks_available = true; @@ -75,7 +75,7 @@ JoystickMenu::recreate_menu() add_controlfield(Controller::PEEK_UP, _("Peek Up")); add_controlfield(Controller::PEEK_DOWN, _("Peek Down")); - add_toggle(MNID_JUMP_WITH_UP, _("Jump with Up"), m_input_manager->joystick_manager->jump_with_up_joy); + add_toggle(MNID_JUMP_WITH_UP, _("Jump with Up"), m_input_manager.joystick_manager->jump_with_up_joy); } else { @@ -112,21 +112,21 @@ JoystickMenu::menu_action(MenuItem* item) if (0 <= item->id && item->id < Controller::CONTROLCOUNT) { item->change_input(_("Press Button")); - m_input_manager->joystick_manager->wait_for_joystick = item->id; + m_input_manager.joystick_manager->wait_for_joystick = item->id; } else if (item->id == MNID_JUMP_WITH_UP) { - m_input_manager->joystick_manager->jump_with_up_joy = item->toggled; + m_input_manager.joystick_manager->jump_with_up_joy = item->toggled; } else if (item->id == MNID_AUTO_JOYSTICK_CFG) { - m_input_manager->use_game_controller(!item->toggled); - m_input_manager->reset(); + m_input_manager.use_game_controller(!item->toggled); + m_input_manager.reset(); recreate_menu(); } else if(item->id == MNID_SCAN_JOYSTICKS) { - m_input_manager->reset(); + m_input_manager.reset(); recreate_menu(); } } @@ -134,9 +134,9 @@ JoystickMenu::menu_action(MenuItem* item) void JoystickMenu::refresh_menu_item(Controller::Control id) { - int button = m_input_manager->joystick_manager->reversemap_joybutton(id); - int axis = m_input_manager->joystick_manager->reversemap_joyaxis(id); - int hat_dir = m_input_manager->joystick_manager->reversemap_joyhat(id); + int button = m_input_manager.joystick_manager->reversemap_joybutton(id); + int axis = m_input_manager.joystick_manager->reversemap_joyaxis(id); + int hat_dir = m_input_manager.joystick_manager->reversemap_joyhat(id); if (button != -1) { diff --git a/src/supertux/menu/joystick_menu.hpp b/src/supertux/menu/joystick_menu.hpp index 469ed0da1..196abe6cb 100644 --- a/src/supertux/menu/joystick_menu.hpp +++ b/src/supertux/menu/joystick_menu.hpp @@ -24,7 +24,7 @@ class JoystickMenu : public Menu { public: - JoystickMenu(InputManager* input_manager); + JoystickMenu(InputManager& input_manager); virtual ~JoystickMenu(); void refresh(); @@ -37,7 +37,7 @@ private: void recreate_menu(); private: - InputManager* m_input_manager; + InputManager& m_input_manager; bool m_joysticks_available; private: diff --git a/src/supertux/menu/keyboard_menu.cpp b/src/supertux/menu/keyboard_menu.cpp index 052ed3db2..e1c4d28da 100644 --- a/src/supertux/menu/keyboard_menu.cpp +++ b/src/supertux/menu/keyboard_menu.cpp @@ -22,8 +22,8 @@ #include "supertux/globals.hpp" #include "util/gettext.hpp" -KeyboardMenu::KeyboardMenu(InputManager* _controller) : - controller(_controller) +KeyboardMenu::KeyboardMenu(InputManager& input_manager) : + m_input_manager(input_manager) { add_label(_("Setup Keyboard")); add_hl(); @@ -40,7 +40,7 @@ KeyboardMenu::KeyboardMenu(InputManager* _controller) : if (g_config->console_enabled) { add_controlfield(Controller::CONSOLE, _("Console")); } - add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->keyboard_manager->jump_with_up_kbd); + add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), m_input_manager.keyboard_manager->jump_with_up_kbd); add_hl(); add_back(_("Back")); refresh(); @@ -89,16 +89,16 @@ KeyboardMenu::menu_action(MenuItem* item) { if(item->id >= 0 && item->id < Controller::CONTROLCOUNT){ item->change_input(_("Press Key")); - controller->keyboard_manager->wait_for_key = item->id; + m_input_manager.keyboard_manager->wait_for_key = item->id; } else if( item->id == Controller::CONTROLCOUNT) { - controller->keyboard_manager->jump_with_up_kbd = item->toggled; + m_input_manager.keyboard_manager->jump_with_up_kbd = item->toggled; } } void KeyboardMenu::refresh() { - auto& kbd_mgr = controller->keyboard_manager; + auto& kbd_mgr = m_input_manager.keyboard_manager; get_item_by_id((int) Controller::UP).change_input(get_key_name( kbd_mgr->reversemap_key(Controller::UP))); diff --git a/src/supertux/menu/keyboard_menu.hpp b/src/supertux/menu/keyboard_menu.hpp index 83f8f5900..3230f3422 100644 --- a/src/supertux/menu/keyboard_menu.hpp +++ b/src/supertux/menu/keyboard_menu.hpp @@ -23,14 +23,16 @@ class KeyboardMenu : public Menu { +private: + InputManager& m_input_manager; + public: - KeyboardMenu(InputManager* controller); + KeyboardMenu(InputManager& input_manager); ~KeyboardMenu(); void refresh(); std::string get_key_name(SDL_Keycode key); void menu_action(MenuItem* item) override; - InputManager* controller; private: KeyboardMenu(const KeyboardMenu&); diff --git a/src/supertux/menu/language_menu.cpp b/src/supertux/menu/language_menu.cpp index 373b8fc17..e7ff52404 100644 --- a/src/supertux/menu/language_menu.cpp +++ b/src/supertux/menu/language_menu.cpp @@ -39,7 +39,7 @@ LanguageMenu::LanguageMenu() add_entry(MNID_LANGUAGE_ENGLISH, "English"); int mnid = MNID_LANGUAGE_NEXT; - std::set languages = dictionary_manager->get_languages(); + std::set languages = g_dictionary_manager->get_languages(); for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { add_entry(mnid++, i->get_name()); @@ -59,7 +59,7 @@ LanguageMenu::menu_action(MenuItem* item) tinygettext::Language language = tinygettext::Language::from_spec( locale->lang?locale->lang:"", locale->country?locale->country:"", locale->variant?locale->variant:""); FL_FreeLocale(&locale); - dictionary_manager->set_language(language); // set currently detected language + g_dictionary_manager->set_language(language); // set currently detected language g_config->locale = ""; // do auto detect every time on startup g_config->save(); MenuManager::instance().clear_menu_stack(); @@ -67,21 +67,21 @@ LanguageMenu::menu_action(MenuItem* item) else if (item->id == MNID_LANGUAGE_ENGLISH) // english { g_config->locale = "en"; - dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale)); + g_dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale)); g_config->save(); MenuManager::instance().clear_menu_stack(); } else { int mnid = MNID_LANGUAGE_NEXT; - std::set languages = dictionary_manager->get_languages(); + std::set languages = g_dictionary_manager->get_languages(); for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { if (item->id == mnid++) { g_config->locale = i->str(); - dictionary_manager->set_language(*i); + g_dictionary_manager->set_language(*i); g_config->save(); MenuManager::instance().clear_menu_stack(); break; diff --git a/src/supertux/menu/main_menu.cpp b/src/supertux/menu/main_menu.cpp index acd9b2991..8eb4d7aa8 100644 --- a/src/supertux/menu/main_menu.cpp +++ b/src/supertux/menu/main_menu.cpp @@ -75,13 +75,13 @@ MainMenu::menu_action(MenuItem* item) case MNID_CREDITS: MenuManager::instance().clear_menu_stack(); - g_screen_manager->push_screen(std::unique_ptr(new TextScroller("credits.txt")), + ScreenManager::current()->push_screen(std::unique_ptr(new TextScroller("credits.txt")), std::unique_ptr(new FadeOut(0.5))); break; case MNID_QUITMAINMENU: - g_screen_manager->quit(std::unique_ptr(new FadeOut(0.25))); - sound_manager->stop_music(0.25); + ScreenManager::current()->quit(std::unique_ptr(new FadeOut(0.25))); + SoundManager::current()->stop_music(0.25); break; } } diff --git a/src/supertux/menu/menu_storage.cpp b/src/supertux/menu/menu_storage.cpp index daf0474fe..67b76daa7 100644 --- a/src/supertux/menu/menu_storage.cpp +++ b/src/supertux/menu/menu_storage.cpp @@ -71,10 +71,10 @@ MenuStorage::create(MenuId menu_id) return std::unique_ptr(new ProfileMenu); case KEYBOARD_MENU: - return std::unique_ptr(new KeyboardMenu(g_input_manager)); + return std::unique_ptr(new KeyboardMenu(*InputManager::current())); case JOYSTICK_MENU: - return std::unique_ptr(new JoystickMenu(g_input_manager)); + return std::unique_ptr(new JoystickMenu(*InputManager::current())); case WORLDMAP_MENU: return std::unique_ptr(new WorldmapMenu); diff --git a/src/supertux/menu/options_menu.cpp b/src/supertux/menu/options_menu.cpp index dfa6f61c9..a3db0eb41 100644 --- a/src/supertux/menu/options_menu.cpp +++ b/src/supertux/menu/options_menu.cpp @@ -185,7 +185,7 @@ OptionsMenu::OptionsMenu(bool complete) } } - if (sound_manager->is_audio_enabled()) { + if (SoundManager::current()->is_audio_enabled()) { add_toggle(MNID_SOUND, _("Sound"), g_config->sound_enabled) ->set_help(_("Disable all sound effects")); add_toggle(MNID_MUSIC, _("Music"), g_config->music_enabled) @@ -280,7 +280,7 @@ OptionsMenu::menu_action(MenuItem* item) case MNID_SOUND: if(g_config->sound_enabled != is_toggled(MNID_SOUND)) { g_config->sound_enabled = !g_config->sound_enabled; - sound_manager->enable_sound(g_config->sound_enabled); + SoundManager::current()->enable_sound(g_config->sound_enabled); g_config->save(); } break; @@ -288,7 +288,7 @@ OptionsMenu::menu_action(MenuItem* item) case MNID_MUSIC: if(g_config->music_enabled != is_toggled(MNID_MUSIC)) { g_config->music_enabled = !g_config->music_enabled; - sound_manager->enable_music(g_config->music_enabled); + SoundManager::current()->enable_music(g_config->music_enabled); g_config->save(); } break; diff --git a/src/supertux/menu/worldmap_menu.cpp b/src/supertux/menu/worldmap_menu.cpp index f25232542..7210a29fd 100644 --- a/src/supertux/menu/worldmap_menu.cpp +++ b/src/supertux/menu/worldmap_menu.cpp @@ -45,7 +45,7 @@ WorldmapMenu::menu_action(MenuItem* item) case MNID_QUITWORLDMAP: MenuManager::instance().clear_menu_stack(); - g_screen_manager->pop_screen(); + ScreenManager::current()->pop_screen(); break; } } diff --git a/src/supertux/player_status.cpp b/src/supertux/player_status.cpp index 2a599254b..e2d1155d9 100644 --- a/src/supertux/player_status.cpp +++ b/src/supertux/player_status.cpp @@ -47,8 +47,8 @@ PlayerStatus::PlayerStatus() : reset(); coin_surface = Surface::create("images/engine/hud/coins-0.png"); - sound_manager->preload("sounds/coin.wav"); - sound_manager->preload("sounds/lifeup.wav"); + SoundManager::current()->preload("sounds/coin.wav"); + SoundManager::current()->preload("sounds/lifeup.wav"); } PlayerStatus::~PlayerStatus() @@ -69,9 +69,9 @@ PlayerStatus::add_coins(int count, bool play_sound) coins = std::min(coins + count, MAX_COINS); if(play_sound) { if(count >= 100) - sound_manager->play("sounds/lifeup.wav"); + SoundManager::current()->play("sounds/lifeup.wav"); else if (real_time > sound_played_time + 0.010) { - sound_manager->play("sounds/coin.wav"); + SoundManager::current()->play("sounds/coin.wav"); sound_played_time = real_time; } } diff --git a/src/supertux/resources.cpp b/src/supertux/resources.cpp index aed7571c9..012e3138a 100644 --- a/src/supertux/resources.cpp +++ b/src/supertux/resources.cpp @@ -20,7 +20,6 @@ #include "gui/mousecursor.hpp" #include "sprite/sprite_manager.hpp" #include "supertux/player_status.hpp" -#include "supertux/tile_manager.hpp" #include "video/font.hpp" MouseCursor* Resources::mouse_cursor = NULL; @@ -36,17 +35,15 @@ SurfacePtr Resources::back; SurfacePtr Resources::arrow_left; SurfacePtr Resources::arrow_right; -/* Load graphics/sounds shared between all levels: */ -void -Resources::load_shared() +Resources::Resources() { - /* Load the mouse-cursor */ + // Load the mouse-cursor mouse_cursor = new MouseCursor("images/engine/menu/mousecursor.png", "images/engine/menu/mousecursor-click.png", "images/engine/menu/mousecursor-link.png"); MouseCursor::set_current(mouse_cursor); - /* Load global images: */ + // Load global images: fixed_font.reset(new Font(Font::FIXED, "fonts/white.stf")); normal_font.reset(new Font(Font::VARIABLE, "fonts/white.stf")); small_font.reset(new Font(Font::VARIABLE, "fonts/white-small.stf", 1)); @@ -58,46 +55,22 @@ Resources::load_shared() back = Surface::create("images/engine/menu/arrow-back.png"); arrow_left = Surface::create("images/engine/menu/arrow-left.png"); arrow_right = Surface::create("images/engine/menu/arrow-right.png"); - - tile_manager = new TileManager(); - sprite_manager = new SpriteManager(); } -/* Free shared data: */ -void -Resources::unload_shared() +Resources::~Resources() { - /* Free menu images */ - if(checkbox != NULL) - checkbox.reset(); - if(checkbox_checked != NULL) - checkbox_checked.reset(); - if(back != NULL) - back.reset(); - if(arrow_left != NULL) - arrow_left.reset(); - if(arrow_right != NULL) - arrow_right.reset(); - - /* Free global images: */ - if(fixed_font != NULL) - fixed_font.reset(); - if(normal_font != NULL) - normal_font.reset(); - if(small_font != NULL) - small_font.reset(); - if(big_font != NULL) - big_font.reset(); - - /* Free tilesets */ - delete tile_manager; - tile_manager = 0; + // Free menu images + checkbox.reset(); + checkbox_checked.reset(); + back.reset(); + arrow_left.reset(); + arrow_right.reset(); - if(sprite_manager != NULL) - { - delete sprite_manager; - sprite_manager = NULL; - } + // Free global images: + fixed_font.reset(); + normal_font.reset(); + small_font.reset(); + big_font.reset(); /* Free mouse-cursor */ if(mouse_cursor != NULL) diff --git a/src/supertux/resources.hpp b/src/supertux/resources.hpp index 243947bd4..dcd9dcb50 100644 --- a/src/supertux/resources.hpp +++ b/src/supertux/resources.hpp @@ -41,8 +41,8 @@ public: static SurfacePtr arrow_right; public: - static void load_shared(); - static void unload_shared(); + Resources(); + ~Resources(); }; #endif diff --git a/src/supertux/screen_manager.cpp b/src/supertux/screen_manager.cpp index f680e7a7b..8453cbc4b 100644 --- a/src/supertux/screen_manager.cpp +++ b/src/supertux/screen_manager.cpp @@ -190,11 +190,11 @@ ScreenManager::update_gamelogic(float elapsed_time) void ScreenManager::process_events() { - g_input_manager->update(); + InputManager::current()->update(); SDL_Event event; while (SDL_PollEvent(&event)) { - g_input_manager->process_event(event); + InputManager::current()->process_event(event); m_menu_manager->event(event); @@ -365,7 +365,7 @@ ScreenManager::run(DrawingContext &context) draw(context); } - sound_manager->update(); + SoundManager::current()->update(); handle_screen_switch(); } diff --git a/src/supertux/screen_manager.hpp b/src/supertux/screen_manager.hpp index 53d02b1c2..59599c847 100644 --- a/src/supertux/screen_manager.hpp +++ b/src/supertux/screen_manager.hpp @@ -23,6 +23,7 @@ #include "scripting/thread_queue.hpp" #include "supertux/screen.hpp" +#include "util/currenton.hpp" class Console; class DrawingContext; @@ -34,7 +35,7 @@ class ScreenFade; /** * Manages, updates and draws all Screens, Controllers, Menus and the Console. */ -class ScreenManager +class ScreenManager : public Currenton { public: ScreenManager(); diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 86491e112..a87b900f4 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -90,7 +90,7 @@ Sector::Sector(Level* parent) : add_object(new DisplayEffect("Effect")); add_object(new TextObject("Text")); - sound_manager->preload("sounds/shoot.wav"); + SoundManager::current()->preload("sounds/shoot.wav"); // create a new squirrel table for the sector using namespace scripting; @@ -1468,7 +1468,7 @@ Sector::add_bullet(const Vector& pos, const PlayerStatus* player_status, float x new_bullet = new Bullet(pos, xm, dir, player_status->bonus); add_object(new_bullet); - sound_manager->play("sounds/shoot.wav"); + SoundManager::current()->play("sounds/shoot.wav"); return true; } @@ -1486,16 +1486,16 @@ Sector::play_music(MusicType type) currentmusic = type; switch(currentmusic) { case LEVEL_MUSIC: - sound_manager->play_music(music); + SoundManager::current()->play_music(music); break; case HERRING_MUSIC: - sound_manager->play_music("music/invincible.ogg"); + SoundManager::current()->play_music("music/invincible.ogg"); break; case HERRING_WARNING_MUSIC: - sound_manager->stop_music(TUX_INVINCIBLE_TIME_WARNING); + SoundManager::current()->stop_music(TUX_INVINCIBLE_TIME_WARNING); break; default: - sound_manager->play_music(""); + SoundManager::current()->play_music(""); break; } } diff --git a/src/supertux/textscroller.cpp b/src/supertux/textscroller.cpp index 17b848ea5..d09e32e8c 100644 --- a/src/supertux/textscroller.cpp +++ b/src/supertux/textscroller.cpp @@ -87,13 +87,13 @@ TextScroller::~TextScroller() void TextScroller::setup() { - sound_manager->play_music(music); + SoundManager::current()->play_music(music); } void TextScroller::update(float elapsed_time) { - Controller *controller = g_input_manager->get_controller(); + Controller* controller = InputManager::current()->get_controller(); if(controller->hold(Controller::UP)) { speed = -defaultspeed*5; } else if(controller->hold(Controller::DOWN)) { @@ -107,7 +107,7 @@ TextScroller::update(float elapsed_time) )&& !(controller->pressed(Controller::UP))) // prevent skipping if jump with up is enabled scroll += SCROLL; if(controller->pressed(Controller::PAUSE_MENU)) { - g_screen_manager->pop_screen(std::unique_ptr(new FadeOut(0.5))); + ScreenManager::current()->pop_screen(std::unique_ptr(new FadeOut(0.5))); } scroll += speed * elapsed_time; @@ -136,7 +136,7 @@ TextScroller::draw(DrawingContext& context) if(y < 0 && !fading ) { fading = true; - g_screen_manager->pop_screen(std::unique_ptr(new FadeOut(0.5))); + ScreenManager::current()->pop_screen(std::unique_ptr(new FadeOut(0.5))); } } diff --git a/src/supertux/tile_manager.hpp b/src/supertux/tile_manager.hpp index 6a5fcee5e..5e2ffd7e6 100644 --- a/src/supertux/tile_manager.hpp +++ b/src/supertux/tile_manager.hpp @@ -21,11 +21,12 @@ #include #include +#include "util/currenton.hpp" #include "util/reader_fwd.hpp" class TileSet; -class TileManager +class TileManager : public Currenton { private: typedef std::map > TileSets; diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index 052c9d9f1..27db44b1e 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -133,7 +133,7 @@ TitleScreen::draw(DrawingContext& context) void TitleScreen::update(float elapsed_time) { - g_screen_manager->set_speed(0.6f); + ScreenManager::current()->set_speed(0.6f); Sector* sector = titlesession->get_current_sector(); sector->update(elapsed_time); @@ -141,7 +141,7 @@ TitleScreen::update(float elapsed_time) // reopen menu if user closed it (so that the app doesn't close when user // accidently hit ESC) - if(!MenuManager::instance().is_active() && !g_screen_manager->has_pending_fadeout()) + if(!MenuManager::instance().is_active() && !ScreenManager::current()->has_pending_fadeout()) { MenuManager::instance().set_menu(MenuStorage::MAIN_MENU); } diff --git a/src/trigger/door.cpp b/src/trigger/door.cpp index 2bb4f71f2..442351191 100644 --- a/src/trigger/door.cpp +++ b/src/trigger/door.cpp @@ -41,11 +41,11 @@ Door::Door(const Reader& reader) : reader.get("script", script); - sprite = sprite_manager->create("images/objects/door/door.sprite"); + sprite = SpriteManager::current()->create("images/objects/door/door.sprite"); sprite->set_action("closed"); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); - sound_manager->preload("sounds/door.wav"); + SoundManager::current()->preload("sounds/door.wav"); } Door::Door(int x, int y, std::string sector, std::string spawnpoint) : @@ -60,11 +60,11 @@ Door::Door(int x, int y, std::string sector, std::string spawnpoint) : target_sector = sector; target_spawnpoint = spawnpoint; - sprite = sprite_manager->create("images/objects/door/door.sprite"); + sprite = SpriteManager::current()->create("images/objects/door/door.sprite"); sprite->set_action("closed"); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); - sound_manager->preload("sounds/door.wav"); + SoundManager::current()->preload("sounds/door.wav"); } Door::~Door() @@ -116,7 +116,7 @@ Door::event(Player& , EventType type) // if door was activated, start opening it if (type == EVENT_ACTIVATE) { state = OPENING; - sound_manager->play("sounds/door.wav"); + SoundManager::current()->play("sounds/door.wav"); sprite->set_action("opening", 1); } break; diff --git a/src/trigger/switch.cpp b/src/trigger/switch.cpp index 53662c72b..df292421b 100644 --- a/src/trigger/switch.cpp +++ b/src/trigger/switch.cpp @@ -39,11 +39,11 @@ Switch::Switch(const Reader& reader) : if (!reader.get("x", bbox.p1.x)) throw std::runtime_error("no x position set"); if (!reader.get("y", bbox.p1.y)) throw std::runtime_error("no y position set"); if (!reader.get("sprite", sprite_name)) throw std::runtime_error("no sprite name set"); - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); if (!reader.get("script", script)) throw std::runtime_error("no script set"); - sound_manager->preload( SWITCH_SOUND ); + SoundManager::current()->preload( SWITCH_SOUND ); } Switch::~Switch() @@ -96,7 +96,7 @@ Switch::event(Player& , EventType type) switch (state) { case OFF: sprite->set_action("turnon", 1); - sound_manager->play( SWITCH_SOUND ); + SoundManager::current()->play( SWITCH_SOUND ); state = TURN_ON; break; case TURN_ON: diff --git a/src/util/gettext.hpp b/src/util/gettext.hpp index f4186953a..d67c93bc4 100644 --- a/src/util/gettext.hpp +++ b/src/util/gettext.hpp @@ -19,9 +19,12 @@ #include #include +#include #include "supertux/globals.hpp" +extern std::unique_ptr g_dictionary_manager; + /* * If you need to do a nontrivial substitution of values into a pattern, use * boost::format rather than an ad-hoc concatenation. That way, translators can @@ -43,9 +46,9 @@ static inline std::string _(const std::string& message) { - if (dictionary_manager) + if (g_dictionary_manager) { - return dictionary_manager->get_dictionary().translate(message); + return g_dictionary_manager->get_dictionary().translate(message); } else { diff --git a/src/video/gl/gl_lightmap.cpp b/src/video/gl/gl_lightmap.cpp index 8df70db4a..b5251e076 100644 --- a/src/video/gl/gl_lightmap.cpp +++ b/src/video/gl/gl_lightmap.cpp @@ -67,7 +67,7 @@ GLLightmap::GLLightmap() : m_lightmap_uv_right = static_cast(m_lightmap_width) / static_cast(width); m_lightmap_uv_bottom = static_cast(m_lightmap_height) / static_cast(height); - texture_manager->register_texture(m_lightmap.get()); + TextureManager::current()->register_texture(m_lightmap.get()); } GLLightmap::~GLLightmap() diff --git a/src/video/gl/gl_renderer.cpp b/src/video/gl/gl_renderer.cpp index 734895ff9..213c94a1b 100644 --- a/src/video/gl/gl_renderer.cpp +++ b/src/video/gl/gl_renderer.cpp @@ -47,9 +47,6 @@ GLRenderer::GLRenderer() : SDL_GetCurrentDisplayMode(0, &mode); m_desktop_size = Size(mode.w, mode.h); - if(texture_manager != 0) - texture_manager->save_textures(); - if(g_config->try_vsync) { /* we want vsync for smooth scrolling */ if (SDL_GL_SetSwapInterval(-1) != 0) @@ -82,11 +79,6 @@ GLRenderer::GLRenderer() : // Init the projection matrix, viewport and stuff apply_config(); - if(texture_manager == 0) - texture_manager = new TextureManager(); - else - texture_manager->reload_textures(); - #ifndef GL_VERSION_ES_CM_1_0 GLenum err = glewInit(); if (GLEW_OK != err) diff --git a/src/video/gl/gl_video_system.cpp b/src/video/gl/gl_video_system.cpp index 935be6511..b19c9d968 100644 --- a/src/video/gl/gl_video_system.cpp +++ b/src/video/gl/gl_video_system.cpp @@ -20,10 +20,12 @@ #include "video/gl/gl_renderer.hpp" #include "video/gl/gl_surface_data.hpp" #include "video/gl/gl_texture.hpp" +#include "video/texture_manager.hpp" GLVideoSystem::GLVideoSystem() : m_renderer(new GLRenderer), - m_lightmap(new GLLightmap) + m_lightmap(new GLLightmap), + m_texture_manager(new TextureManager) { } diff --git a/src/video/gl/gl_video_system.hpp b/src/video/gl/gl_video_system.hpp index eab8a0895..34fbb8fbf 100644 --- a/src/video/gl/gl_video_system.hpp +++ b/src/video/gl/gl_video_system.hpp @@ -22,11 +22,14 @@ #include "video/video_system.hpp" +class TextureManager; + class GLVideoSystem : public VideoSystem { private: std::unique_ptr m_renderer; std::unique_ptr m_lightmap; + std::unique_ptr m_texture_manager; public: GLVideoSystem(); diff --git a/src/video/sdl/sdl_renderer.cpp b/src/video/sdl/sdl_renderer.cpp index c95ee4644..2ed479ec1 100644 --- a/src/video/sdl/sdl_renderer.cpp +++ b/src/video/sdl/sdl_renderer.cpp @@ -112,9 +112,6 @@ SDLRenderer::SDLRenderer() : log_info << "Max Texture Height: " << info.max_texture_height << std::endl; } - if(texture_manager == 0) - texture_manager = new TextureManager(); - g_config->window_size = Size(width, height); apply_config(); } diff --git a/src/video/sdl/sdl_video_system.cpp b/src/video/sdl/sdl_video_system.cpp index f0aae38b8..4bb6cef73 100644 --- a/src/video/sdl/sdl_video_system.cpp +++ b/src/video/sdl/sdl_video_system.cpp @@ -28,7 +28,8 @@ SDLVideoSystem::SDLVideoSystem() : m_renderer(new SDLRenderer), - m_lightmap(new SDLLightmap) + m_lightmap(new SDLLightmap), + m_texture_manager(new TextureManager) { } diff --git a/src/video/sdl/sdl_video_system.hpp b/src/video/sdl/sdl_video_system.hpp index 2445f4510..ecd22978a 100644 --- a/src/video/sdl/sdl_video_system.hpp +++ b/src/video/sdl/sdl_video_system.hpp @@ -22,11 +22,14 @@ #include "video/video_system.hpp" +class TextureManager; + class SDLVideoSystem : public VideoSystem { private: std::unique_ptr m_renderer; std::unique_ptr m_lightmap; + std::unique_ptr m_texture_manager; public: SDLVideoSystem(); diff --git a/src/video/surface.cpp b/src/video/surface.cpp index 2236f62d6..221429388 100644 --- a/src/video/surface.cpp +++ b/src/video/surface.cpp @@ -36,7 +36,7 @@ Surface::create(const std::string& file, const Rect& rect) } Surface::Surface(const std::string& file) : - texture(texture_manager->get(file)), + texture(TextureManager::current()->get(file)), surface_data(), rect(0, 0, Size(texture->get_image_width(), @@ -47,7 +47,7 @@ Surface::Surface(const std::string& file) : } Surface::Surface(const std::string& file, const Rect& rect_) : - texture(texture_manager->get(file, rect_)), + texture(TextureManager::current()->get(file, rect_)), surface_data(), rect(0, 0, Size(rect_.get_width(), rect_.get_height())), flipx(false) diff --git a/src/video/texture.hpp b/src/video/texture.hpp index 0a316cf63..76964a9fd 100644 --- a/src/video/texture.hpp +++ b/src/video/texture.hpp @@ -55,10 +55,10 @@ public: Texture() : cache_filename() {} virtual ~Texture() { - if (texture_manager && cache_filename != "") + if (TextureManager::current() && cache_filename != "") /* The cache entry is now useless: its weak pointer to us has been * cleared. Remove the entry altogether to save memory. */ - texture_manager->reap_cache_entry(cache_filename); + TextureManager::current()->reap_cache_entry(cache_filename); } virtual unsigned int get_texture_width() const = 0; diff --git a/src/video/texture_manager.hpp b/src/video/texture_manager.hpp index 52074ca6e..8124928f0 100644 --- a/src/video/texture_manager.hpp +++ b/src/video/texture_manager.hpp @@ -27,6 +27,7 @@ #include #include +#include "util/currenton.hpp" #include "video/glutil.hpp" #include "video/texture_ptr.hpp" @@ -34,7 +35,7 @@ class Texture; class GLTexture; class Rect; -class TextureManager +class TextureManager : public Currenton { public: TextureManager(); diff --git a/src/worldmap/level.cpp b/src/worldmap/level.cpp index ead77e211..85e987f21 100644 --- a/src/worldmap/level.cpp +++ b/src/worldmap/level.cpp @@ -50,7 +50,7 @@ LevelTile::LevelTile(const std::string& basedir_, const Reader& lisp) : std::string spritefile = "images/worldmap/common/leveldot.sprite"; lisp.get("sprite", spritefile); - sprite = sprite_manager->create(spritefile); + sprite = SpriteManager::current()->create(spritefile); lisp.get("extro-script", extro_script); diff --git a/src/worldmap/special_tile.cpp b/src/worldmap/special_tile.cpp index b51766b7c..ccd3ea3aa 100644 --- a/src/worldmap/special_tile.cpp +++ b/src/worldmap/special_tile.cpp @@ -43,7 +43,7 @@ SpecialTile::SpecialTile(const Reader& lisp) : if(!invisible) { std::string spritefile = ""; lisp.get("sprite", spritefile); - sprite = sprite_manager->create(spritefile); + sprite = SpriteManager::current()->create(spritefile); } lisp.get("map-message", map_message); diff --git a/src/worldmap/sprite_change.cpp b/src/worldmap/sprite_change.cpp index 705d5b45b..69525590e 100644 --- a/src/worldmap/sprite_change.cpp +++ b/src/worldmap/sprite_change.cpp @@ -37,7 +37,7 @@ SpriteChange::SpriteChange(const Reader& lisp) : std::string spritefile = ""; lisp.get("sprite", spritefile); - sprite = sprite_manager->create(spritefile); + sprite = SpriteManager::current()->create(spritefile); lisp.get("stay-action", stay_action); lisp.get("initial-stay-action", in_stay_action); diff --git a/src/worldmap/teleporter.cpp b/src/worldmap/teleporter.cpp index ab709d49a..41be7b08b 100644 --- a/src/worldmap/teleporter.cpp +++ b/src/worldmap/teleporter.cpp @@ -36,7 +36,7 @@ Teleporter::Teleporter(const Reader& lisp) : std::string spritefile = ""; if (lisp.get("sprite", spritefile)) { - sprite = sprite_manager->create(spritefile); + sprite = SpriteManager::current()->create(spritefile); } lisp.get("worldmap", worldmap); diff --git a/src/worldmap/tux.cpp b/src/worldmap/tux.cpp index 95c1c3dfd..561be822b 100644 --- a/src/worldmap/tux.cpp +++ b/src/worldmap/tux.cpp @@ -43,7 +43,7 @@ Tux::Tux(WorldMap* worldmap_) : moving(), ghost_mode() { - sprite = sprite_manager->create("images/worldmap/common/tux.sprite"); + sprite = SpriteManager::current()->create("images/worldmap/common/tux.sprite"); offset = 0; moving = false; @@ -291,7 +291,7 @@ Tux::tryContinueWalking(float elapsed_time) void Tux::updateInputDirection() { - Controller* controller_ = g_input_manager->get_controller(); + Controller* controller_ = InputManager::current()->get_controller(); if(controller_->hold(Controller::UP)) input_direction = D_NORTH; else if(controller_->hold(Controller::DOWN)) diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 90b5055fb..9f71f16eb 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -133,7 +133,7 @@ WorldMap::WorldMap(const std::string& filename, Savegame& savegame, const std::s sq_addref(global_vm, &worldmap_table); sq_pop(global_vm, 1); - sound_manager->preload("sounds/warp.wav"); + SoundManager::current()->preload("sounds/warp.wav"); // load worldmap objects load(filename); @@ -239,8 +239,8 @@ WorldMap::move_to_spawnpoint(const std::string& spawnpoint, bool pan) void WorldMap::change(const std::string& filename, const std::string& force_spawnpoint_) { - g_screen_manager->pop_screen(); - g_screen_manager->push_screen(std::unique_ptr(new WorldMap(filename, m_savegame, force_spawnpoint_))); + ScreenManager::current()->pop_screen(); + ScreenManager::current()->push_screen(std::unique_ptr(new WorldMap(filename, m_savegame, force_spawnpoint_))); } void @@ -265,7 +265,7 @@ WorldMap::load(const std::string& filename) const lisp::Lisp* tilesets_lisp = level_->get_lisp("tilesets"); if(tilesets_lisp != NULL) { - tileset = tile_manager->parse_tileset_definition(*tilesets_lisp).release(); + tileset = TileManager::current()->parse_tileset_definition(*tilesets_lisp).release(); free_tileset = true; } std::string tileset_name; @@ -273,12 +273,12 @@ WorldMap::load(const std::string& filename) if(tileset != NULL) { log_warning << "multiple tilesets specified in level_" << std::endl; } else { - tileset = tile_manager->get_tileset(tileset_name); + tileset = TileManager::current()->get_tileset(tileset_name); } } /* load default tileset */ if(tileset == NULL) { - tileset = tile_manager->get_tileset("images/worldmap.strf"); + tileset = TileManager::current()->get_tileset("images/worldmap.strf"); } current_tileset = tileset; @@ -632,7 +632,7 @@ WorldMap::update(float delta) } // handle input - Controller *controller = g_input_manager->get_controller(); + Controller *controller = InputManager::current()->get_controller(); bool enter_level = false; if(controller->pressed(Controller::ACTION) || controller->pressed(Controller::JUMP) @@ -659,7 +659,7 @@ WorldMap::update(float delta) change(teleporter->worldmap, teleporter->spawnpoint); } else { // TODO: an animation, camera scrolling or a fading would be a nice touch - sound_manager->play("sounds/warp.wav"); + SoundManager::current()->play("sounds/warp.wav"); tux->back_direction = D_NONE; move_to_spawnpoint(teleporter->spawnpoint, true); } @@ -698,7 +698,7 @@ WorldMap::update(float delta) // update state and savegame save_state(); - g_screen_manager->push_screen(std::unique_ptr(new GameSession(levelfile, m_savegame, &level_->statistics)), + ScreenManager::current()->push_screen(std::unique_ptr(new GameSession(levelfile, m_savegame, &level_->statistics)), std::unique_ptr(new ShrinkFade(shrinkpos, 1.0f))); in_level = true; } catch(std::exception& e) { @@ -904,7 +904,7 @@ WorldMap::draw_status(DrawingContext& context) void WorldMap::setup() { - sound_manager->play_music(music); + SoundManager::current()->play_music(music); MenuManager::instance().clear_menu_stack(); current_ = this; -- 2.11.0