#include <alc.h>
#include "math/vector.hpp"
+#include "util/currenton.hpp"
class SoundFile;
class SoundSource;
class StreamSoundSource;
class OpenALSoundSource;
-class SoundManager
+class SoundManager : public Currenton<SoundManager>
{
public:
SoundManager();
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);
{
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;
}
{
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;
}
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;
}
{
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);
{
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);
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);
{
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) :
{
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()
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);
void
Dart::collision_solid(const CollisionHit& )
{
- sound_manager->play("sounds/darthit.wav", get_pos());
+ SoundManager::current()->play("sounds/darthit.wav", get_pos());
remove_me();
}
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;
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);
}
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);
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");
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
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;
}
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);
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);
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);
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);
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);
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);
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()
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;
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<TreeWillOWisp*>::iterator iter;
for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) {
TreeWillOWisp *willo = *iter;
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 ) ){
return;
}
//Replace sprite
- sprite = sprite_manager->create( sprite_name );
+ sprite = SpriteManager::current()->create( sprite_name );
}
void
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);
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 ) ){
return;
}
//Replace sprite
- sprite = sprite_manager->create( sprite_name );
+ sprite = SpriteManager::current()->create( sprite_name );
}
HitResponse
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);
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);
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);
groundhit_pos_set(false)
{
// TODO create a nice sound for this...
- //sound_manager->preload("sounds/skid.wav");
+ //SoundManager::current()->preload("sounds/skid.wav");
}
void
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);
}
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);
}
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);
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");
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)
{
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);
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) :
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
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();
}
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;
}
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));
}
{
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) :
{
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()
void
MoleRock::collision_solid(const CollisionHit& )
{
- sound_manager->play("sounds/darthit.wav", get_pos());
+ SoundManager::current()->play("sounds/darthit.wav", get_pos());
remove_me();
}
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;
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);
}
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 ) ){
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.*/
walk_speed = 80;
max_drop_height = 16;
grabbed = false;
- sound_manager->preload("sounds/explosion.wav");
+ SoundManager::current()->preload("sounds/explosion.wav");
}
HitResponse
{
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) :
{
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
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);
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);
}
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);
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 */
{
walk_speed = TREE_SPEED;
max_drop_height = 16;
- sound_manager->preload("sounds/mr_tree.ogg");
+ SoundManager::current()->preload("sounds/mr_tree.ogg");
}
bool
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<Player*>(&object);
if (player) player->bounce(*this);
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);
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);
return;
}
//Replace sprite
- sprite = sprite_manager->create( sprite_name );
+ sprite = SpriteManager::current()->create( sprite_name );
}
void
recover_timer(),
state()
{
- sound_manager->preload( SKULLYHOP_SOUND );
+ SoundManager::current()->preload( SKULLYHOP_SOUND );
}
SkullyHop::SkullyHop(const Vector& pos, Direction d) :
recover_timer(),
state()
{
- sound_manager->preload( SKULLYHOP_SOUND );
+ SoundManager::current()->preload( SKULLYHOP_SOUND );
}
void
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;
{
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) :
{
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
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;
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<MovingObject*>(&object);
if (movingobject && (movingobject->get_pos().x < get_pos().x)) {
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
// 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;
if (player)
player->bounce(*this);
- sound_manager->play("sounds/pop.ogg", get_pos());
+ SoundManager::current()->play("sounds/pop.ogg", get_pos());
loose_head();
{
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
&& 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) {
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();
}
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;
{
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) :
{
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);
}
// 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<Player*>(&object);
if (player) player->bounce(*this);
return true;
recover_timer(),
state()
{
- sound_manager->preload(HOP_SOUND);
+ SoundManager::current()->preload(HOP_SOUND);
}
Toad::Toad(const Vector& pos, Direction d) :
recover_timer(),
state()
{
- sound_manager->preload(HOP_SOUND);
+ SoundManager::current()->preload(HOP_SOUND);
}
void
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();
carrying(0),
carried_by(0)
{
- sound_manager->preload( LAND_ON_TOTEM_SOUND );
+ SoundManager::current()->preload( LAND_ON_TOTEM_SOUND );
}
Totem::~Totem()
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);
}
tree(tree_),
suck_target()
{
- sound_manager->preload(TREEWILLOSOUND);
+ SoundManager::current()->preload(TREEWILLOSOUND);
this->radius = radius_;
this->angle = 0;
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);
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;
}
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));
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);
} else {
GameSession::current()->respawn(target_sector, target_spawnpoint);
}
- sound_manager->play("sounds/warp.wav");
+ SoundManager::current()->play("sounds/warp.wav");
return CONTINUE;
}
{
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");
}
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");
}
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) {
#include <vector>
#include <memory>
+#include "util/currenton.hpp"
#include "util/reader_fwd.hpp"
#include "util/writer_fwd.hpp"
class KeyboardMenu;
class Menu;
-class InputManager final
+class InputManager final : public Currenton<InputManager>
{
private:
friend class KeyboardMenu;
}
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;
}
// just to be sure...
- g_input_manager->reset();
+ InputManager::current()->reset();
}
void
lisp.get("silence_distance",silence_distance);
sound_source.reset(); // not playing at the beginning
- sound_manager->preload(sample);
+ SoundManager::current()->preload(sample);
latency=0;
}
silence_distance = 1/distance_factor;
sound_source = 0; // not playing at the beginning
- sound_manager->preload(sample);
+ SoundManager::current()->preload(sample);
latency=0;
}
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");
{
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()
#include <stdexcept>
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),
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;
}
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),
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") {
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") {
BonusBlock::try_open(Player *player)
{
if(sprite->get_action() == "empty") {
- sound_manager->play("sounds/brick.wav");
+ SoundManager::current()->play("sounds/brick.wav");
return;
}
get_pos(), new Flower(FIRE_BONUS));
sector->add_object(riser);
}
- sound_manager->play("sounds/upgrade.wav");
+ SoundManager::current()->play("sounds/upgrade.wav");
break;
}
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;
}
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;
}
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;
}
}
BonusBlock::try_drop(Player *player)
{
if(sprite->get_action() == "empty") {
- sound_manager->play("sounds/brick.wav");
+ SoundManager::current()->play("sounds/brick.wav");
return;
}
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;
}
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;
}
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;
}
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;
}
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;
}
{
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;
}
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();
#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);
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) {
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);
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);
from_tilemap(false),
physic()
{
- sound_manager->preload("sounds/coin.wav");
+ SoundManager::current()->preload("sounds/coin.wav");
}
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)
set_pos(v);
}
- sound_manager->preload("sounds/coin.wav");
+ SoundManager::current()->preload("sounds/coin.wav");
}
void
}
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()));
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);
}
physic()
{
physic.enable_gravity(true);
- sound_manager->preload("sounds/coin2.ogg");
+ SoundManager::current()->preload("sounds/coin2.ogg");
set_group(COLGROUP_MOVING);
}
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{
}
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());
}
}
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();
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());
}
{
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
{
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
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));
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));
}
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
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);
}
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");
}
}
}
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");
timer()
{
timer.start(.2f);
- sound_manager->preload("sounds/fireworks.wav");
+ SoundManager::current()->preload("sounds/fireworks.wav");
}
Fireworks::~Fireworks()
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));
}
}
#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),
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);
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;
}
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
return ABORT_MOVE;
}
- sound_manager->play("sounds/grow.ogg");
+ SoundManager::current()->play("sounds/grow.ogg");
remove_me();
return ABORT_MOVE;
{
// 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);
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");
}
/* 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);
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++)
{
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++)
{
}
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),
#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
void
InvisibleBlock::hit(Player& player)
{
- sound_manager->play("sounds/brick.wav");
+ SoundManager::current()->play("sounds/brick.wav");
if(visible)
return;
std::vector<float> 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) :
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()
WillOWisp* wow = dynamic_cast<WillOWisp*>(&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();
TreeWillOWisp* twow = dynamic_cast<TreeWillOWisp*>(&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();
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()
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);
}
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);
}
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);
}
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);
}
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();
}
// 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(
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);
}
// 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");
}
}
if( tile_attributes & Tile::WATER ){
swimming = true;
no_water = false;
- sound_manager->play( "sounds/splash.ogg" );
+ SoundManager::current()->play( "sounds/splash.ogg" );
}
}
#endif
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);
}
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) {
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) {
// 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);
}
}
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));
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));
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") {
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());
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);
{
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() {
grabbed(),
last_movement()
{
- sound_manager->preload(ROCK_SOUND);
+ SoundManager::current()->preload(ROCK_SOUND);
on_ground = false;
grabbed = false;
set_group(COLGROUP_MOVING_STATIC);
grabbed(),
last_movement()
{
- sound_manager->preload(ROCK_SOUND);
+ SoundManager::current()->preload(ROCK_SOUND);
on_ground = false;
grabbed = false;
set_group(COLGROUP_MOVING_STATIC);
grabbed(),
last_movement()
{
- sound_manager->preload(ROCK_SOUND);
+ SoundManager::current()->preload(ROCK_SOUND);
on_ground = false;
grabbed = false;
set_group(COLGROUP_MOVING_STATIC);
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;
}
}
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?
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);
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);
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()
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");
}
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
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
}
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
void
Thunderstorm::thunder()
{
- sound_manager->play("sounds/thunder.wav");
+ SoundManager::current()->play("sounds/thunder.wav");
}
void
void
Thunderstorm::flash()
{
- sound_manager->play("sounds/lightning.wav");
+ SoundManager::current()->play("sounds/lightning.wav");
flash_display_timer.start(FLASH_DISPLAY_TIME);
}
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");
}
}
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");
}
}
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;
}
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;
}
: 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");
}
}
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
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));
}
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
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<ScreenFade>(new FadeOut(seconds)));
+ ScreenManager::current()->set_screen_fade(std::unique_ptr<ScreenFade>(new FadeOut(seconds)));
}
void shrink_screen(float dest_x, float dest_y, float seconds)
{
- g_screen_manager->set_screen_fade(std::unique_ptr<ScreenFade>(new ShrinkFade(Vector(dest_x, dest_y), seconds)));
+ ScreenManager::current()->set_screen_fade(std::unique_ptr<ScreenFade>(new ShrinkFade(Vector(dest_x, dest_y), seconds)));
}
void abort_screenfade()
{
- g_screen_manager->set_screen_fade(std::unique_ptr<ScreenFade>());
+ ScreenManager::current()->set_screen_fade(std::unique_ptr<ScreenFade>());
}
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<Screen>(new TextScroller(filename)));
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(new TextScroller(filename)));
}
void load_worldmap(const std::string& filename)
}
else
{
- g_screen_manager->push_screen(std::unique_ptr<Screen>(new WorldMap(filename, WorldMap::current()->get_savegame())));
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(new WorldMap(filename, WorldMap::current()->get_savegame())));
}
}
}
else
{
- g_screen_manager->push_screen(std::unique_ptr<Screen>(new GameSession(filename, GameSession::current()->get_savegame())));
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(new GameSession(filename, GameSession::current()->get_savegame())));
}
}
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()
void quit()
{
- g_screen_manager->quit();
+ ScreenManager::current()->quit();
}
int rand()
#include <string>
#include "sprite/sprite_ptr.hpp"
+#include "util/currenton.hpp"
class SpriteData;
-class SpriteManager
+class SpriteManager : public Currenton<SpriteManager>
{
private:
typedef std::map<std::string, SpriteData*> Sprites;
std::unique_ptr<Screen> 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
m_savegame.reset(new Savegame(m_world->get_savegame_filename()));
m_savegame->load();
- g_screen_manager->push_screen(std::unique_ptr<Screen>(
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(
new worldmap::WorldMap(m_world->get_worldmap_filename(),
*m_savegame)));
}
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(),
game_pause = false;
end_sequence = 0;
- g_input_manager->reset();
+ InputManager::current()->reset();
currentsector = 0;
}
} 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 != "") {
// 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;
}
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;
// 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));
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<Screen>(new LevelIntro(level.get(), best_level_statistics)));
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(new LevelIntro(level.get(), best_level_statistics)));
}
}
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())
{
// 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;
}
}
// 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)
}
}
- g_screen_manager->pop_screen();
+ ScreenManager::current()->pop_screen();
}
void
}
/* 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.
}
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");
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");
}
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "supertux/globals.hpp"
+
#include <tinygettext/tinygettext.hpp>
-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<Config> 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;
#ifndef HEADER_SUPERTUX_SUPERTUX_GLOBALS_HPP
#define HEADER_SUPERTUX_SUPERTUX_GLOBALS_HPP
+#include <memory>
+
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
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<Config> 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;
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;
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;
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));
}
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<ScreenFade>(new FadeOut(0.1)));
+ ScreenManager::current()->pop_screen(std::unique_ptr<ScreenFade>(new FadeOut(0.1)));
}
player_sprite_py += player_sprite_vy * elapsed_time;
// 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
{
std::unique_ptr<Screen> 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));
}
}
#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"
#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;
}
}
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<tinygettext::FileSystem>(new PhysFSFileSystem));
+ g_dictionary_manager->set_filesystem(std::unique_ptr<tinygettext::FileSystem>(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);
}
}
<< " 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;
Console console;
timelog("controller");
- g_input_manager = new InputManager();
+ InputManager input_manager;
timelog("commandline");
std::unique_ptr<VideoSystem> 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();
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();
const std::unique_ptr<Savegame> default_savegame(new Savegame(std::string()));
GameManager game_manager;
- g_screen_manager = new ScreenManager();
+ ScreenManager screen_manager;
init_rand();
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<Screen>(
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(
new worldmap::WorldMap(
FileSystem::basename(g_config->start_level), *default_savegame)));
} else {
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<Screen>(new TitleScreen(*default_savegame)));
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(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;
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;
}
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
{
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
} // namespace
-JoystickMenu::JoystickMenu(InputManager* input_manager) :
+JoystickMenu::JoystickMenu(InputManager& input_manager) :
m_input_manager(input_manager),
m_joysticks_available(false)
{
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;
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
{
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();
}
}
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)
{
class JoystickMenu : public Menu
{
public:
- JoystickMenu(InputManager* input_manager);
+ JoystickMenu(InputManager& input_manager);
virtual ~JoystickMenu();
void refresh();
void recreate_menu();
private:
- InputManager* m_input_manager;
+ InputManager& m_input_manager;
bool m_joysticks_available;
private:
#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();
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();
{
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)));
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&);
add_entry(MNID_LANGUAGE_ENGLISH, "English");
int mnid = MNID_LANGUAGE_NEXT;
- std::set<tinygettext::Language> languages = dictionary_manager->get_languages();
+ std::set<tinygettext::Language> languages = g_dictionary_manager->get_languages();
for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); i++)
{
add_entry(mnid++, i->get_name());
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();
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<tinygettext::Language> languages = dictionary_manager->get_languages();
+ std::set<tinygettext::Language> languages = g_dictionary_manager->get_languages();
for (std::set<tinygettext::Language>::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;
case MNID_CREDITS:
MenuManager::instance().clear_menu_stack();
- g_screen_manager->push_screen(std::unique_ptr<Screen>(new TextScroller("credits.txt")),
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(new TextScroller("credits.txt")),
std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
break;
case MNID_QUITMAINMENU:
- g_screen_manager->quit(std::unique_ptr<ScreenFade>(new FadeOut(0.25)));
- sound_manager->stop_music(0.25);
+ ScreenManager::current()->quit(std::unique_ptr<ScreenFade>(new FadeOut(0.25)));
+ SoundManager::current()->stop_music(0.25);
break;
}
}
return std::unique_ptr<Menu>(new ProfileMenu);
case KEYBOARD_MENU:
- return std::unique_ptr<Menu>(new KeyboardMenu(g_input_manager));
+ return std::unique_ptr<Menu>(new KeyboardMenu(*InputManager::current()));
case JOYSTICK_MENU:
- return std::unique_ptr<Menu>(new JoystickMenu(g_input_manager));
+ return std::unique_ptr<Menu>(new JoystickMenu(*InputManager::current()));
case WORLDMAP_MENU:
return std::unique_ptr<Menu>(new WorldmapMenu);
}
}
- 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)
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;
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;
case MNID_QUITWORLDMAP:
MenuManager::instance().clear_menu_stack();
- g_screen_manager->pop_screen();
+ ScreenManager::current()->pop_screen();
break;
}
}
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()
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;
}
}
#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;
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));
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)
static SurfacePtr arrow_right;
public:
- static void load_shared();
- static void unload_shared();
+ Resources();
+ ~Resources();
};
#endif
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);
draw(context);
}
- sound_manager->update();
+ SoundManager::current()->update();
handle_screen_switch();
}
#include "scripting/thread_queue.hpp"
#include "supertux/screen.hpp"
+#include "util/currenton.hpp"
class Console;
class DrawingContext;
/**
* Manages, updates and draws all Screens, Controllers, Menus and the Console.
*/
-class ScreenManager
+class ScreenManager : public Currenton<ScreenManager>
{
public:
ScreenManager();
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;
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;
}
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;
}
}
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)) {
)&& !(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<ScreenFade>(new FadeOut(0.5)));
+ ScreenManager::current()->pop_screen(std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
}
scroll += speed * elapsed_time;
if(y < 0 && !fading ) {
fading = true;
- g_screen_manager->pop_screen(std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
+ ScreenManager::current()->pop_screen(std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
}
}
#include <memory>
#include <string>
+#include "util/currenton.hpp"
#include "util/reader_fwd.hpp"
class TileSet;
-class TileManager
+class TileManager : public Currenton<TileManager>
{
private:
typedef std::map<std::string, std::unique_ptr<TileSet> > TileSets;
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);
// 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);
}
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) :
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()
// 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;
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()
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:
#include <tinygettext/tinygettext.hpp>
#include <assert.h>
+#include <memory>
#include "supertux/globals.hpp"
+extern std::unique_ptr<tinygettext::DictionaryManager> 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
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
{
m_lightmap_uv_right = static_cast<float>(m_lightmap_width) / static_cast<float>(width);
m_lightmap_uv_bottom = static_cast<float>(m_lightmap_height) / static_cast<float>(height);
- texture_manager->register_texture(m_lightmap.get());
+ TextureManager::current()->register_texture(m_lightmap.get());
}
GLLightmap::~GLLightmap()
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)
// 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)
#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)
{
}
#include "video/video_system.hpp"
+class TextureManager;
+
class GLVideoSystem : public VideoSystem
{
private:
std::unique_ptr<Renderer> m_renderer;
std::unique_ptr<Lightmap> m_lightmap;
+ std::unique_ptr<TextureManager> m_texture_manager;
public:
GLVideoSystem();
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();
}
SDLVideoSystem::SDLVideoSystem() :
m_renderer(new SDLRenderer),
- m_lightmap(new SDLLightmap)
+ m_lightmap(new SDLLightmap),
+ m_texture_manager(new TextureManager)
{
}
#include "video/video_system.hpp"
+class TextureManager;
+
class SDLVideoSystem : public VideoSystem
{
private:
std::unique_ptr<Renderer> m_renderer;
std::unique_ptr<Lightmap> m_lightmap;
+ std::unique_ptr<TextureManager> m_texture_manager;
public:
SDLVideoSystem();
}
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(),
}
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)
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;
#include <vector>
#include <boost/weak_ptr.hpp>
+#include "util/currenton.hpp"
#include "video/glutil.hpp"
#include "video/texture_ptr.hpp"
class GLTexture;
class Rect;
-class TextureManager
+class TextureManager : public Currenton<TextureManager>
{
public:
TextureManager();
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);
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);
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);
std::string spritefile = "";
if (lisp.get("sprite", spritefile)) {
- sprite = sprite_manager->create(spritefile);
+ sprite = SpriteManager::current()->create(spritefile);
}
lisp.get("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;
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))
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);
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<Screen>(new WorldMap(filename, m_savegame, force_spawnpoint_)));
+ ScreenManager::current()->pop_screen();
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(new WorldMap(filename, m_savegame, force_spawnpoint_)));
}
void
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;
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;
}
// 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)
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);
}
// update state and savegame
save_state();
- g_screen_manager->push_screen(std::unique_ptr<Screen>(new GameSession(levelfile, m_savegame, &level_->statistics)),
+ ScreenManager::current()->push_screen(std::unique_ptr<Screen>(new GameSession(levelfile, m_savegame, &level_->statistics)),
std::unique_ptr<ScreenFade>(new ShrinkFade(shrinkpos, 1.0f)));
in_level = true;
} catch(std::exception& e) {
void
WorldMap::setup()
{
- sound_manager->play_music(music);
+ SoundManager::current()->play_music(music);
MenuManager::instance().clear_menu_stack();
current_ = this;