From b08f473d758b69519fe265ba201acd4d4ee5be10 Mon Sep 17 00:00:00 2001 From: grumbel Date: Fri, 27 Nov 2009 22:57:32 +0000 Subject: [PATCH] Changed ObjectFactory code so that it works properly when building SuperTux as library git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6142 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/badguy/angrystone.cpp | 2 - src/badguy/bouncing_snowball.cpp | 2 - src/badguy/captainsnowball.cpp | 2 - src/badguy/crystallo.cpp | 2 - src/badguy/dart.cpp | 2 - src/badguy/darttrap.cpp | 2 - src/badguy/dispenser.cpp | 3 +- src/badguy/fish.cpp | 2 - src/badguy/flame.cpp | 2 - src/badguy/flyingsnowball.cpp | 2 - src/badguy/ghosttree.cpp | 2 - src/badguy/igel.cpp | 2 - src/badguy/jumpy.cpp | 2 - src/badguy/kamikazesnowball.cpp | 2 - src/badguy/kugelblitz.cpp | 2 - src/badguy/mole.cpp | 2 - src/badguy/mole_rock.cpp | 2 - src/badguy/mrbomb.cpp | 2 - src/badguy/mriceblock.cpp | 2 - src/badguy/mrrocket.cpp | 2 - src/badguy/mrtree.cpp | 2 - src/badguy/plant.cpp | 2 - src/badguy/poisonivy.cpp | 2 - src/badguy/skullyhop.cpp | 2 - src/badguy/smartball.cpp | 2 - src/badguy/snail.cpp | 2 - src/badguy/snowball.cpp | 2 - src/badguy/spidermite.cpp | 2 - src/badguy/spiky.cpp | 2 - src/badguy/sspiky.cpp | 2 - src/badguy/stalactite.cpp | 2 - src/badguy/stumpy.cpp | 2 - src/badguy/toad.cpp | 2 - src/badguy/totem.cpp | 2 - src/badguy/walkingleaf.cpp | 2 - src/badguy/willowisp.cpp | 2 - src/badguy/yeti.cpp | 2 - src/badguy/yeti_stalactite.cpp | 2 - src/badguy/zeekling.cpp | 2 - src/object/ambient_sound.cpp | 2 - src/object/background.cpp | 2 - src/object/bicycle_platform.cpp | 2 - src/object/bonus_block.cpp | 4 +- src/object/candle.cpp | 2 - src/object/coin.cpp | 2 - src/object/decal.cpp | 2 - src/object/explosion.cpp | 2 - src/object/firefly.cpp | 2 - src/object/gradient.cpp | 2 - src/object/hurting_platform.cpp | 2 - src/object/icecrusher.cpp | 2 - src/object/infoblock.cpp | 2 - src/object/invisible_wall.cpp | 2 - src/object/ispy.cpp | 2 - src/object/lantern.cpp | 2 - src/object/level_time.cpp | 2 - src/object/magicblock.cpp | 2 - src/object/platform.cpp | 2 - src/object/pneumatic_platform.cpp | 2 - src/object/powerup.cpp | 2 - src/object/pushbutton.cpp | 2 - src/object/rock.cpp | 1 - src/object/scripted_object.cpp | 2 - src/object/skull_tile.cpp | 2 - src/object/spotlight.cpp | 2 - src/object/thunderstorm.cpp | 2 - src/object/tilemap.cpp | 3 +- src/object/trampoline.cpp | 2 - src/object/unstable_tile.cpp | 2 - src/object/weak_block.cpp | 1 - src/object/wind.cpp | 2 - src/supertux/object_factory.cpp | 253 +++++++++++++++++++++++++++++++++++-- src/supertux/object_factory.hpp | 73 ++++++----- src/supertux/sector.cpp | 2 +- src/trigger/climbable.cpp | 2 - src/trigger/door.cpp | 2 - src/trigger/scripttrigger.cpp | 2 - src/trigger/secretarea_trigger.cpp | 2 - src/trigger/sequence_trigger.cpp | 2 - src/trigger/switch.cpp | 2 - 80 files changed, 287 insertions(+), 197 deletions(-) diff --git a/src/badguy/angrystone.cpp b/src/badguy/angrystone.cpp index 4875f76ad..b6defc4af 100644 --- a/src/badguy/angrystone.cpp +++ b/src/badguy/angrystone.cpp @@ -162,6 +162,4 @@ AngryStone::active_update(float elapsed_time) { } -IMPLEMENT_FACTORY(AngryStone, "angrystone"); - /* EOF */ diff --git a/src/badguy/bouncing_snowball.cpp b/src/badguy/bouncing_snowball.cpp index 2328841d4..72995bf1a 100644 --- a/src/badguy/bouncing_snowball.cpp +++ b/src/badguy/bouncing_snowball.cpp @@ -74,6 +74,4 @@ BouncingSnowball::collision_badguy(BadGuy& , const CollisionHit& hit) return CONTINUE; } -IMPLEMENT_FACTORY(BouncingSnowball, "bouncingsnowball"); - /* EOF */ diff --git a/src/badguy/captainsnowball.cpp b/src/badguy/captainsnowball.cpp index 4eeaa137c..34b287af2 100644 --- a/src/badguy/captainsnowball.cpp +++ b/src/badguy/captainsnowball.cpp @@ -95,6 +95,4 @@ CaptainSnowball::collision_squished(GameObject& object) return true; } -IMPLEMENT_FACTORY(CaptainSnowball, "captainsnowball"); - /* EOF */ diff --git a/src/badguy/crystallo.cpp b/src/badguy/crystallo.cpp index 7273d4d14..443478fa9 100644 --- a/src/badguy/crystallo.cpp +++ b/src/badguy/crystallo.cpp @@ -63,6 +63,4 @@ Crystallo::collision_squished(GameObject& object) return true; } -IMPLEMENT_FACTORY(Crystallo, "crystallo"); - /* EOF */ diff --git a/src/badguy/dart.cpp b/src/badguy/dart.cpp index 1bba323ca..10f8ea11a 100644 --- a/src/badguy/dart.cpp +++ b/src/badguy/dart.cpp @@ -125,6 +125,4 @@ Dart::collision_player(Player& player, const CollisionHit& hit) return BadGuy::collision_player(player, hit); } -IMPLEMENT_FACTORY(Dart, "dart"); - /* EOF */ diff --git a/src/badguy/darttrap.cpp b/src/badguy/darttrap.cpp index de0bada8a..b31f2e81e 100644 --- a/src/badguy/darttrap.cpp +++ b/src/badguy/darttrap.cpp @@ -102,6 +102,4 @@ DartTrap::fire() sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); } -IMPLEMENT_FACTORY(DartTrap, "darttrap"); - /* EOF */ diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index f7c49ed55..d19815f26 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -210,7 +210,7 @@ Dispenser::launch_badguy() else if (type == "rocketlauncher") spawnpoint = Vector(get_pos().x + (launchdir == LEFT ? -32 : 32), get_pos().y); - badguy_object = create_object(badguy, spawnpoint, launchdir); + badguy_object = ObjectFactory::instance().create(badguy, spawnpoint, launchdir); if (badguy_object) Sector::current()->add_object(badguy_object); @@ -240,6 +240,5 @@ Dispenser::is_freezable() const { return true; } -IMPLEMENT_FACTORY(Dispenser, "dispenser"); /* EOF */ diff --git a/src/badguy/fish.cpp b/src/badguy/fish.cpp index 8ff95bbf7..c8bf8093b 100644 --- a/src/badguy/fish.cpp +++ b/src/badguy/fish.cpp @@ -154,6 +154,4 @@ Fish::is_freezable() const return true; } -IMPLEMENT_FACTORY(Fish, "fish"); - /* EOF */ diff --git a/src/badguy/flame.cpp b/src/badguy/flame.cpp index afe2562c4..ff3c062d8 100644 --- a/src/badguy/flame.cpp +++ b/src/badguy/flame.cpp @@ -74,6 +74,4 @@ Flame::kill_fall() { } -IMPLEMENT_FACTORY(Flame, "flame"); - /* EOF */ diff --git a/src/badguy/flyingsnowball.cpp b/src/badguy/flyingsnowball.cpp index 381305625..564e76e50 100644 --- a/src/badguy/flyingsnowball.cpp +++ b/src/badguy/flyingsnowball.cpp @@ -121,6 +121,4 @@ FlyingSnowBall::active_update(float elapsed_time) } } -IMPLEMENT_FACTORY(FlyingSnowBall, "flyingsnowball"); - /* EOF */ diff --git a/src/badguy/ghosttree.cpp b/src/badguy/ghosttree.cpp index cc8e492cf..9def4616e 100644 --- a/src/badguy/ghosttree.cpp +++ b/src/badguy/ghosttree.cpp @@ -269,6 +269,4 @@ GhostTree::spawn_lantern() { Sector::current()->add_object(lantern); } -IMPLEMENT_FACTORY(GhostTree, "ghosttree"); - /* EOF */ diff --git a/src/badguy/igel.cpp b/src/badguy/igel.cpp index 382aff4c7..41c3543d5 100644 --- a/src/badguy/igel.cpp +++ b/src/badguy/igel.cpp @@ -116,6 +116,4 @@ Igel::collision_squished(GameObject& ) return false; } -IMPLEMENT_FACTORY(Igel, "igel"); - /* EOF */ diff --git a/src/badguy/jumpy.cpp b/src/badguy/jumpy.cpp index ad63c49a2..6e4e92e5c 100644 --- a/src/badguy/jumpy.cpp +++ b/src/badguy/jumpy.cpp @@ -108,6 +108,4 @@ Jumpy::is_freezable() const return true; } -IMPLEMENT_FACTORY(Jumpy, "jumpy"); - /* EOF */ diff --git a/src/badguy/kamikazesnowball.cpp b/src/badguy/kamikazesnowball.cpp index 5cec886e7..daadd9393 100644 --- a/src/badguy/kamikazesnowball.cpp +++ b/src/badguy/kamikazesnowball.cpp @@ -92,6 +92,4 @@ KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit) return ABORT_MOVE; } -IMPLEMENT_FACTORY(KamikazeSnowball, "kamikazesnowball"); - /* EOF */ diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index 2e304bb54..14b0239c5 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -209,6 +209,4 @@ Kugelblitz::try_activate() } } -IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz"); - /* EOF */ diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index 1391d2a80..291d86ef8 100644 --- a/src/badguy/mole.cpp +++ b/src/badguy/mole.cpp @@ -165,6 +165,4 @@ Mole::set_state(MoleState new_state) state = new_state; } -IMPLEMENT_FACTORY(Mole, "mole"); - /* EOF */ diff --git a/src/badguy/mole_rock.cpp b/src/badguy/mole_rock.cpp index efe5e00b3..9b3c0a6db 100644 --- a/src/badguy/mole_rock.cpp +++ b/src/badguy/mole_rock.cpp @@ -101,6 +101,4 @@ MoleRock::collision_player(Player& player, const CollisionHit& hit) return BadGuy::collision_player(player, hit); } -IMPLEMENT_FACTORY(MoleRock, "mole_rock"); - /* EOF */ diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 67efd6486..9614e742f 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -143,6 +143,4 @@ MrBomb::is_portable() const return frozen; } -IMPLEMENT_FACTORY(MrBomb, "mrbomb"); - /* EOF */ diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index 4d3bca794..9cc320ab5 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -286,6 +286,4 @@ MrIceBlock::is_portable() const return ice_state == ICESTATE_FLAT; } -IMPLEMENT_FACTORY(MrIceBlock, "mriceblock"); - /* EOF */ diff --git a/src/badguy/mrrocket.cpp b/src/badguy/mrrocket.cpp index 23ac5bc83..02fea0ce9 100644 --- a/src/badguy/mrrocket.cpp +++ b/src/badguy/mrrocket.cpp @@ -77,6 +77,4 @@ MrRocket::collision_solid(const CollisionHit& hit) } } -IMPLEMENT_FACTORY(MrRocket, "mrrocket"); - /* EOF */ diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index eb91e5bab..9a04e6c31 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -93,6 +93,4 @@ MrTree::collision_squished(GameObject& object) return true; } -IMPLEMENT_FACTORY(MrTree, "mrtree"); - /* EOF */ diff --git a/src/badguy/plant.cpp b/src/badguy/plant.cpp index 2bf14ffb7..a2276d3e7 100644 --- a/src/badguy/plant.cpp +++ b/src/badguy/plant.cpp @@ -104,6 +104,4 @@ Plant::active_update(float elapsed_time) { } -IMPLEMENT_FACTORY(Plant, "plant"); - /* EOF */ diff --git a/src/badguy/poisonivy.cpp b/src/badguy/poisonivy.cpp index 742ec4a7b..5b28671c6 100644 --- a/src/badguy/poisonivy.cpp +++ b/src/badguy/poisonivy.cpp @@ -54,6 +54,4 @@ PoisonIvy::collision_squished(GameObject& object) return true; } -IMPLEMENT_FACTORY(PoisonIvy, "poisonivy"); - /* EOF */ diff --git a/src/badguy/skullyhop.cpp b/src/badguy/skullyhop.cpp index 647ac53b2..a401cd639 100644 --- a/src/badguy/skullyhop.cpp +++ b/src/badguy/skullyhop.cpp @@ -141,6 +141,4 @@ SkullyHop::active_update(float elapsed_time) } } -IMPLEMENT_FACTORY(SkullyHop, "skullyhop"); - /* EOF */ diff --git a/src/badguy/smartball.cpp b/src/badguy/smartball.cpp index 43bde1781..ad566d6c9 100644 --- a/src/badguy/smartball.cpp +++ b/src/badguy/smartball.cpp @@ -41,6 +41,4 @@ SmartBall::collision_squished(GameObject& object) return true; } -IMPLEMENT_FACTORY(SmartBall, "smartball"); - /* EOF */ diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index 797e06ecd..95d1dcd60 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -249,6 +249,4 @@ Snail::collision_squished(GameObject& object) return true; } -IMPLEMENT_FACTORY(Snail, "snail"); - /* EOF */ diff --git a/src/badguy/snowball.cpp b/src/badguy/snowball.cpp index 92769c788..7629a4fc8 100644 --- a/src/badguy/snowball.cpp +++ b/src/badguy/snowball.cpp @@ -39,6 +39,4 @@ SnowBall::collision_squished(GameObject& object) return true; } -IMPLEMENT_FACTORY(SnowBall, "snowball"); - /* EOF */ diff --git a/src/badguy/spidermite.cpp b/src/badguy/spidermite.cpp index a608033ee..389d70e37 100644 --- a/src/badguy/spidermite.cpp +++ b/src/badguy/spidermite.cpp @@ -86,6 +86,4 @@ SpiderMite::active_update(float elapsed_time) } } -IMPLEMENT_FACTORY(SpiderMite, "spidermite"); - /* EOF */ diff --git a/src/badguy/spiky.cpp b/src/badguy/spiky.cpp index e0e060b46..3e4297fbf 100644 --- a/src/badguy/spiky.cpp +++ b/src/badguy/spiky.cpp @@ -39,6 +39,4 @@ Spiky::is_freezable() const return true; } -IMPLEMENT_FACTORY(Spiky, "spiky"); - /* EOF */ diff --git a/src/badguy/sspiky.cpp b/src/badguy/sspiky.cpp index 63a311c65..7f0fde9fd 100644 --- a/src/badguy/sspiky.cpp +++ b/src/badguy/sspiky.cpp @@ -111,6 +111,4 @@ SSpiky::is_freezable() const return true; } -IMPLEMENT_FACTORY(SSpiky, "sspiky"); - /* EOF */ diff --git a/src/badguy/stalactite.cpp b/src/badguy/stalactite.cpp index 36220033e..3c63bea43 100644 --- a/src/badguy/stalactite.cpp +++ b/src/badguy/stalactite.cpp @@ -144,6 +144,4 @@ Stalactite::deactivate() remove_me(); } -IMPLEMENT_FACTORY(Stalactite, "stalactite"); - /* EOF */ diff --git a/src/badguy/stumpy.cpp b/src/badguy/stumpy.cpp index cdf2878ac..1ad03a67c 100644 --- a/src/badguy/stumpy.cpp +++ b/src/badguy/stumpy.cpp @@ -159,6 +159,4 @@ Stumpy::collision_badguy(BadGuy& badguy, const CollisionHit& hit) return CONTINUE; } -IMPLEMENT_FACTORY(Stumpy, "stumpy"); - /* EOF */ diff --git a/src/badguy/toad.cpp b/src/badguy/toad.cpp index 429e71f7a..9925739fb 100644 --- a/src/badguy/toad.cpp +++ b/src/badguy/toad.cpp @@ -155,6 +155,4 @@ Toad::active_update(float elapsed_time) } -IMPLEMENT_FACTORY(Toad, "toad"); - /* EOF */ diff --git a/src/badguy/totem.cpp b/src/badguy/totem.cpp index 15e56b596..068472e6b 100644 --- a/src/badguy/totem.cpp +++ b/src/badguy/totem.cpp @@ -261,6 +261,4 @@ Totem::synchronize_with(Totem* base) physic.set_velocity_y(base->physic.get_velocity_y()); } -IMPLEMENT_FACTORY(Totem, "totem"); - /* EOF */ diff --git a/src/badguy/walkingleaf.cpp b/src/badguy/walkingleaf.cpp index 3df2c2aca..25931370b 100644 --- a/src/badguy/walkingleaf.cpp +++ b/src/badguy/walkingleaf.cpp @@ -41,6 +41,4 @@ WalkingLeaf::collision_squished(GameObject& object) return true; } -IMPLEMENT_FACTORY(WalkingLeaf, "walkingleaf"); - /* EOF */ diff --git a/src/badguy/willowisp.cpp b/src/badguy/willowisp.cpp index 754959398..748a4439c 100644 --- a/src/badguy/willowisp.cpp +++ b/src/badguy/willowisp.cpp @@ -292,6 +292,4 @@ WillOWisp::unexpose(HSQUIRRELVM vm, SQInteger table_idx) scripting::unexpose_object(vm, table_idx, name); } -IMPLEMENT_FACTORY(WillOWisp, "willowisp"); - /* EOF */ diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index d56e3a508..26cdfb174 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -310,6 +310,4 @@ Yeti::collision_solid(const CollisionHit& hit) } } -IMPLEMENT_FACTORY(Yeti, "yeti"); - /* EOF */ diff --git a/src/badguy/yeti_stalactite.cpp b/src/badguy/yeti_stalactite.cpp index 6673a272e..12a925ef8 100644 --- a/src/badguy/yeti_stalactite.cpp +++ b/src/badguy/yeti_stalactite.cpp @@ -51,6 +51,4 @@ YetiStalactite::active_update(float elapsed_time) Stalactite::active_update(elapsed_time); } -IMPLEMENT_FACTORY(YetiStalactite, "yeti_stalactite"); - /* EOF */ diff --git a/src/badguy/zeekling.cpp b/src/badguy/zeekling.cpp index 69cba10f3..90b30bbce 100644 --- a/src/badguy/zeekling.cpp +++ b/src/badguy/zeekling.cpp @@ -195,6 +195,4 @@ Zeekling::active_update(float elapsed_time) { } } -IMPLEMENT_FACTORY(Zeekling, "zeekling"); - /* EOF */ diff --git a/src/object/ambient_sound.cpp b/src/object/ambient_sound.cpp index 63c26f26c..d0d651ba0 100644 --- a/src/object/ambient_sound.cpp +++ b/src/object/ambient_sound.cpp @@ -264,6 +264,4 @@ AmbientSound::get_pos_y() const return position.y; } -IMPLEMENT_FACTORY(AmbientSound, "ambient_sound"); - /* EOF */ diff --git a/src/object/background.cpp b/src/object/background.cpp index 59a8871e3..f74b748ba 100644 --- a/src/object/background.cpp +++ b/src/object/background.cpp @@ -117,6 +117,4 @@ Background::draw(DrawingContext& context) context.pop_transform(); } -IMPLEMENT_FACTORY(Background, "background"); - /* EOF */ diff --git a/src/object/bicycle_platform.cpp b/src/object/bicycle_platform.cpp index c66ee3e6f..f38f6d194 100644 --- a/src/object/bicycle_platform.cpp +++ b/src/object/bicycle_platform.cpp @@ -127,6 +127,4 @@ BicyclePlatform::update(float elapsed_time) } } -IMPLEMENT_FACTORY(BicyclePlatform, "bicycle-platform"); - /* EOF */ diff --git a/src/object/bonus_block.cpp b/src/object/bonus_block.cpp index 55481d7e0..f09cef28f 100644 --- a/src/object/bonus_block.cpp +++ b/src/object/bonus_block.cpp @@ -89,7 +89,7 @@ BonusBlock::BonusBlock(const Reader& lisp) : } } else { if(contents == CONTENT_CUSTOM) { - GameObject* game_object = create_object(token, *(iter.lisp())); + GameObject* game_object = ObjectFactory::instance().create(token, *(iter.lisp())); object = dynamic_cast (game_object); if(object == 0) throw std::runtime_error( @@ -227,6 +227,4 @@ Block::break_me() remove_me(); } -IMPLEMENT_FACTORY(BonusBlock, "bonusblock"); - /* EOF */ diff --git a/src/object/candle.cpp b/src/object/candle.cpp index 23c168597..e2899cb73 100644 --- a/src/object/candle.cpp +++ b/src/object/candle.cpp @@ -110,6 +110,4 @@ Candle::set_burning(bool burning) } } -IMPLEMENT_FACTORY(Candle, "candle"); - /* EOF */ diff --git a/src/object/coin.cpp b/src/object/coin.cpp index 5bf7450a0..9977ff855 100644 --- a/src/object/coin.cpp +++ b/src/object/coin.cpp @@ -125,6 +125,4 @@ Coin::collision(GameObject& other, const CollisionHit& ) return ABORT_MOVE; } -IMPLEMENT_FACTORY(Coin, "coin"); - /* EOF */ diff --git a/src/object/decal.cpp b/src/object/decal.cpp index 0811389f2..af7a8f7ea 100644 --- a/src/object/decal.cpp +++ b/src/object/decal.cpp @@ -36,6 +36,4 @@ Decal::~Decal() { } -IMPLEMENT_FACTORY(Decal, "decal"); - /* EOF */ diff --git a/src/object/explosion.cpp b/src/object/explosion.cpp index 3c40c2548..94a40d12f 100644 --- a/src/object/explosion.cpp +++ b/src/object/explosion.cpp @@ -99,6 +99,4 @@ Explosion::collision(GameObject& other, const CollisionHit& ) return ABORT_MOVE; } -IMPLEMENT_FACTORY(Explosion, "explosion"); - /* EOF */ diff --git a/src/object/firefly.cpp b/src/object/firefly.cpp index 2241a3c4a..88049995c 100644 --- a/src/object/firefly.cpp +++ b/src/object/firefly.cpp @@ -90,6 +90,4 @@ Firefly::collision(GameObject& other, const CollisionHit& ) return ABORT_MOVE; } -IMPLEMENT_FACTORY(Firefly, "firefly"); - /* EOF */ diff --git a/src/object/gradient.cpp b/src/object/gradient.cpp index 896f30b10..7e325b1ee 100644 --- a/src/object/gradient.cpp +++ b/src/object/gradient.cpp @@ -72,6 +72,4 @@ Gradient::draw(DrawingContext& context) context.pop_transform(); } -IMPLEMENT_FACTORY(Gradient, "gradient"); - /* EOF */ diff --git a/src/object/hurting_platform.cpp b/src/object/hurting_platform.cpp index 95601fd2a..84395b359 100644 --- a/src/object/hurting_platform.cpp +++ b/src/object/hurting_platform.cpp @@ -44,6 +44,4 @@ HurtingPlatform::collision(GameObject& other, const CollisionHit& ) return FORCE_MOVE; } -IMPLEMENT_FACTORY(HurtingPlatform, "hurting_platform"); - /* EOF */ diff --git a/src/object/icecrusher.cpp b/src/object/icecrusher.cpp index 1d7663f65..de27a7791 100644 --- a/src/object/icecrusher.cpp +++ b/src/object/icecrusher.cpp @@ -161,6 +161,4 @@ IceCrusher::found_victim() return false; } -IMPLEMENT_FACTORY(IceCrusher, "icecrusher"); - /* EOF */ diff --git a/src/object/infoblock.cpp b/src/object/infoblock.cpp index 475d7d34a..3f558dfe5 100644 --- a/src/object/infoblock.cpp +++ b/src/object/infoblock.cpp @@ -194,6 +194,4 @@ InfoBlock::hide_message() dest_pct = 0; } -IMPLEMENT_FACTORY(InfoBlock, "infoblock"); - /* EOF */ diff --git a/src/object/invisible_wall.cpp b/src/object/invisible_wall.cpp index beb41a9a2..788ced31a 100644 --- a/src/object/invisible_wall.cpp +++ b/src/object/invisible_wall.cpp @@ -36,6 +36,4 @@ InvisibleWall::collision(GameObject& , const CollisionHit& ) return FORCE_MOVE; } -IMPLEMENT_FACTORY(InvisibleWall, "invisible_wall"); - /* EOF */ diff --git a/src/object/ispy.cpp b/src/object/ispy.cpp index 5a7092ef9..d69266ae4 100644 --- a/src/object/ispy.cpp +++ b/src/object/ispy.cpp @@ -197,6 +197,4 @@ Ispy::update(float ) } } -IMPLEMENT_FACTORY(Ispy, "ispy"); - /* EOF */ diff --git a/src/object/lantern.cpp b/src/object/lantern.cpp index 065f53768..fcdc675f6 100644 --- a/src/object/lantern.cpp +++ b/src/object/lantern.cpp @@ -130,6 +130,4 @@ Lantern::is_open() return ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0); } -IMPLEMENT_FACTORY(Lantern, "lantern"); - /* EOF */ diff --git a/src/object/level_time.cpp b/src/object/level_time.cpp index 6f096b01f..8cc4d092b 100644 --- a/src/object/level_time.cpp +++ b/src/object/level_time.cpp @@ -123,6 +123,4 @@ LevelTime::set_time(float time_left) this->time_left = std::min(std::max(time_left, 0.0f), 999.0f); } -IMPLEMENT_FACTORY(LevelTime, "leveltime"); - /* EOF */ diff --git a/src/object/magicblock.cpp b/src/object/magicblock.cpp index 2b9ffe2a6..072ddc805 100644 --- a/src/object/magicblock.cpp +++ b/src/object/magicblock.cpp @@ -160,6 +160,4 @@ MagicBlock::collision(GameObject& /*other*/, const CollisionHit& /*hit*/) return FORCE_MOVE; } -IMPLEMENT_FACTORY(MagicBlock, "magicblock"); - /* EOF */ diff --git a/src/object/platform.cpp b/src/object/platform.cpp index 2575edcf2..aa0392375 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -144,6 +144,4 @@ Platform::unexpose(HSQUIRRELVM vm, SQInteger table_idx) scripting::unexpose_object(vm, table_idx, name); } -IMPLEMENT_FACTORY(Platform, "platform"); - /* EOF */ diff --git a/src/object/pneumatic_platform.cpp b/src/object/pneumatic_platform.cpp index 839ddda7d..99fd2c6f3 100644 --- a/src/object/pneumatic_platform.cpp +++ b/src/object/pneumatic_platform.cpp @@ -111,6 +111,4 @@ PneumaticPlatform::update(float elapsed_time) } } -IMPLEMENT_FACTORY(PneumaticPlatform, "pneumatic-platform"); - /* EOF */ diff --git a/src/object/powerup.cpp b/src/object/powerup.cpp index f4af4abe0..a5e384acc 100644 --- a/src/object/powerup.cpp +++ b/src/object/powerup.cpp @@ -86,6 +86,4 @@ PowerUp::update(float elapsed_time) movement = physic.get_movement(elapsed_time); } -IMPLEMENT_FACTORY(PowerUp, "powerup"); - /* EOF */ diff --git a/src/object/pushbutton.cpp b/src/object/pushbutton.cpp index 027274f51..07190c280 100644 --- a/src/object/pushbutton.cpp +++ b/src/object/pushbutton.cpp @@ -75,6 +75,4 @@ PushButton::collision(GameObject& other, const CollisionHit& hit) return FORCE_MOVE; } -IMPLEMENT_FACTORY(PushButton, "pushbutton"); - /* EOF */ diff --git a/src/object/rock.cpp b/src/object/rock.cpp index 99d7c2ca9..fd591623f 100644 --- a/src/object/rock.cpp +++ b/src/object/rock.cpp @@ -137,6 +137,5 @@ Rock::ungrab(MovingObject& , Direction dir) grabbed = false; } -IMPLEMENT_FACTORY(Rock, "rock"); /* EOF */ diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index 726a21ba6..1a43a3a45 100644 --- a/src/object/scripted_object.cpp +++ b/src/object/scripted_object.cpp @@ -207,6 +207,4 @@ ScriptedObject::collision(GameObject& , const CollisionHit& ) return FORCE_MOVE; } -IMPLEMENT_FACTORY(ScriptedObject, "scriptedobject"); - /* EOF */ diff --git a/src/object/skull_tile.cpp b/src/object/skull_tile.cpp index 996b127fa..5ad5eabd5 100644 --- a/src/object/skull_tile.cpp +++ b/src/object/skull_tile.cpp @@ -78,6 +78,4 @@ SkullTile::update(float elapsed_time) hit = false; } -IMPLEMENT_FACTORY(SkullTile, "skull_tile"); - /* EOF */ diff --git a/src/object/spotlight.cpp b/src/object/spotlight.cpp index 194776607..3735639ca 100644 --- a/src/object/spotlight.cpp +++ b/src/object/spotlight.cpp @@ -88,6 +88,4 @@ Spotlight::draw(DrawingContext& context) context.pop_target(); } -IMPLEMENT_FACTORY(Spotlight, "spotlight"); - /* EOF */ diff --git a/src/object/thunderstorm.cpp b/src/object/thunderstorm.cpp index 6a8aeff73..b6abf8709 100644 --- a/src/object/thunderstorm.cpp +++ b/src/object/thunderstorm.cpp @@ -142,6 +142,4 @@ Thunderstorm::electrify() Sector::current()->add_object(new Electrifier(76, 1422, 0.5)); } -IMPLEMENT_FACTORY(Thunderstorm, "thunderstorm"); - /* EOF */ diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index fd5747c52..3825545ec 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -401,7 +401,6 @@ TileMap::get_alpha() { return this->current_alpha; } - -IMPLEMENT_FACTORY(TileMap, "tilemap"); + /* EOF */ diff --git a/src/object/trampoline.cpp b/src/object/trampoline.cpp index e097dcd01..c93d3497b 100644 --- a/src/object/trampoline.cpp +++ b/src/object/trampoline.cpp @@ -122,6 +122,4 @@ Trampoline::is_portable() const return Rock::is_portable() && portable; } -IMPLEMENT_FACTORY(Trampoline, "trampoline"); - /* EOF */ diff --git a/src/object/unstable_tile.cpp b/src/object/unstable_tile.cpp index 51410366c..79d6b2a18 100644 --- a/src/object/unstable_tile.cpp +++ b/src/object/unstable_tile.cpp @@ -71,6 +71,4 @@ UnstableTile::update(float elapsed_time) } } -IMPLEMENT_FACTORY(UnstableTile, "unstable_tile"); - /* EOF */ diff --git a/src/object/weak_block.cpp b/src/object/weak_block.cpp index 7dd081061..eae7d0c4d 100644 --- a/src/object/weak_block.cpp +++ b/src/object/weak_block.cpp @@ -110,6 +110,5 @@ WeakBlock::spreadHit() } } -IMPLEMENT_FACTORY(WeakBlock, "weak_block"); /* EOF */ diff --git a/src/object/wind.cpp b/src/object/wind.cpp index 2e6cd85d8..0072fe2d9 100644 --- a/src/object/wind.cpp +++ b/src/object/wind.cpp @@ -120,6 +120,4 @@ Wind::stop() blowing = false; } -IMPLEMENT_FACTORY(Wind, "wind"); - /* EOF */ diff --git a/src/supertux/object_factory.cpp b/src/supertux/object_factory.cpp index ea2b35d3a..fe6cb0872 100644 --- a/src/supertux/object_factory.cpp +++ b/src/supertux/object_factory.cpp @@ -23,19 +23,256 @@ #include "util/reader.hpp" #include "supertux/object_factory.hpp" -GameObject* create_object(const std::string& name, const Reader& reader) +#include "badguy/angrystone.hpp" +#include "badguy/badguy.hpp" +#include "badguy/bomb.hpp" +#include "badguy/bouncing_snowball.hpp" +#include "badguy/captainsnowball.hpp" +#include "badguy/crystallo.hpp" +#include "badguy/dart.hpp" +#include "badguy/darttrap.hpp" +#include "badguy/dispenser.hpp" +#include "badguy/fish.hpp" +#include "badguy/flame.hpp" +#include "badguy/flyingsnowball.hpp" +#include "badguy/ghosttree.hpp" +#include "badguy/igel.hpp" +#include "badguy/jumpy.hpp" +#include "badguy/kamikazesnowball.hpp" +#include "badguy/kugelblitz.hpp" +#include "badguy/mole.hpp" +#include "badguy/mole_rock.hpp" +#include "badguy/mrbomb.hpp" +#include "badguy/mriceblock.hpp" +#include "badguy/mrrocket.hpp" +#include "badguy/mrtree.hpp" +#include "badguy/plant.hpp" +#include "badguy/poisonivy.hpp" +#include "badguy/root.hpp" +#include "badguy/skullyhop.hpp" +#include "badguy/smartball.hpp" +#include "badguy/snail.hpp" +#include "badguy/snowball.hpp" +#include "badguy/spidermite.hpp" +#include "badguy/spiky.hpp" +#include "badguy/sspiky.hpp" +#include "badguy/stalactite.hpp" +#include "badguy/stumpy.hpp" +#include "badguy/toad.hpp" +#include "badguy/totem.hpp" +#include "badguy/treewillowisp.hpp" +#include "badguy/walking_badguy.hpp" +#include "badguy/walkingleaf.hpp" +#include "badguy/willowisp.hpp" +#include "badguy/yeti.hpp" +#include "badguy/yeti_stalactite.hpp" +#include "badguy/zeekling.hpp" + +#include "object/ambient_sound.hpp" +#include "object/anchor_point.hpp" +#include "object/background.hpp" +#include "object/bicycle_platform.hpp" +#include "object/block.hpp" +#include "object/bonus_block.hpp" +#include "object/bouncy_coin.hpp" +#include "object/brick.hpp" +#include "object/broken_brick.hpp" +#include "object/bullet.hpp" +#include "object/camera.hpp" +#include "object/candle.hpp" +#include "object/cloud_particle_system.hpp" +#include "object/coin.hpp" +#include "object/comet_particle_system.hpp" +#include "object/decal.hpp" +#include "object/display_effect.hpp" +#include "object/electrifier.hpp" +#include "object/endsequence_fireworks.hpp" +#include "object/endsequence.hpp" +#include "object/endsequence_walkleft.hpp" +#include "object/endsequence_walkright.hpp" +#include "object/explosion.hpp" +#include "object/falling_coin.hpp" +#include "object/firefly.hpp" +#include "object/fireworks.hpp" +#include "object/floating_image.hpp" +#include "object/floating_text.hpp" +#include "object/flower.hpp" +#include "object/ghost_particle_system.hpp" +#include "object/gradient.hpp" +#include "object/growup.hpp" +#include "object/hurting_platform.hpp" +#include "object/icecrusher.hpp" +#include "object/infoblock.hpp" +#include "object/invisible_block.hpp" +#include "object/invisible_wall.hpp" +#include "object/ispy.hpp" +#include "object/lantern.hpp" +#include "object/level_time.hpp" +#include "object/light.hpp" +#include "object/magicblock.hpp" +#include "object/moving_sprite.hpp" +#include "object/oneup.hpp" +#include "object/particles.hpp" +#include "object/particlesystem.hpp" +#include "object/particlesystem_interactive.hpp" +#include "object/path.hpp" +#include "object/path_walker.hpp" +#include "object/platform.hpp" +#include "object/player.hpp" +#include "object/pneumatic_platform.hpp" +#include "object/portable.hpp" +#include "object/powerup.hpp" +#include "object/pulsing_light.hpp" +#include "object/pushbutton.hpp" +#include "object/rain_particle_system.hpp" +#include "object/rainsplash.hpp" +#include "object/rock.hpp" +#include "object/scripted_object.hpp" +#include "object/skull_tile.hpp" +#include "object/smoke_cloud.hpp" +#include "object/snow_particle_system.hpp" +#include "object/specialriser.hpp" +#include "object/spotlight.hpp" +#include "object/sprite_particle.hpp" +#include "object/star.hpp" +#include "object/text_object.hpp" +#include "object/thunderstorm.hpp" +#include "object/tilemap.hpp" +#include "object/trampoline.hpp" +#include "object/unstable_tile.hpp" +#include "object/weak_block.hpp" +#include "object/wind.hpp" + +#include "trigger/climbable.hpp" +#include "trigger/door.hpp" +#include "trigger/scripttrigger.hpp" +#include "trigger/secretarea_trigger.hpp" +#include "trigger/sequence_trigger.hpp" +#include "trigger/switch.hpp" + +ObjectFactory& +ObjectFactory::instance() +{ + static ObjectFactory instance_; + return instance_; +} + +ObjectFactory::ObjectFactory() : + factories() { - Factory::Factories::iterator i = Factory::get_factories().find(name); - if(i == Factory::get_factories().end()) { + init_factories(); +} + +ObjectFactory::~ObjectFactory() +{ +} + +void +ObjectFactory::init_factories() +{ + // badguys + add_factory("angrystone"); + add_factory("bouncingsnowball"); + add_factory("captainsnowball"); + add_factory("crystallo"); + add_factory("dart"); + add_factory("darttrap"); + add_factory("dispenser"); + add_factory("fish"); + add_factory("flame"); + add_factory("flyingsnowball"); + add_factory("ghosttree"); + add_factory("igel"); + add_factory("jumpy"); + add_factory("kamikazesnowball"); + add_factory("kugelblitz"); + add_factory("mole"); + add_factory("mole_rock"); + add_factory("mrbomb"); + add_factory("mriceblock"); + add_factory("mrrocket"); + add_factory("mrtree"); + add_factory("plant"); + add_factory("poisonivy"); + add_factory("sspiky"); + add_factory("skullyhop"); + add_factory("smartball"); + add_factory("snail"); + add_factory("snowball"); + add_factory("spidermite"); + add_factory("spiky"); + add_factory("stalactite"); + add_factory("stumpy"); + add_factory("toad"); + add_factory("totem"); + add_factory("walkingleaf"); + add_factory("willowisp"); + add_factory("yeti"); + add_factory("yeti_stalactite"); + add_factory("zeekling"); + + // other objects + add_factory("ambient_sound"); + add_factory("background"); + add_factory("bicycle-platform"); + add_factory("bonusblock"); + add_factory("candle"); + add_factory("coin"); + add_factory("decal"); + add_factory("explosion"); + add_factory("firefly"); + add_factory("gradient"); + add_factory("hurting_platform"); + add_factory("icecrusher"); + add_factory("infoblock"); + add_factory("invisible_wall"); + add_factory("ispy"); + add_factory("lantern"); + add_factory("leveltime"); + add_factory("magicblock"); + add_factory("platform"); + add_factory("pneumatic-platform"); + add_factory("powerup"); + add_factory("pushbutton"); + add_factory("rock"); + add_factory("scriptedobject"); + add_factory("skull_tile"); + add_factory("spotlight"); + add_factory("thunderstorm"); + add_factory("tilemap"); + add_factory("trampoline"); + add_factory("unstable_tile"); + add_factory("weak_block"); + add_factory("wind"); + + // trigger + add_factory("climbable"); + add_factory("door"); + add_factory("scripttrigger"); + add_factory("secretarea"); + add_factory("sequencetrigger"); + add_factory("switch"); +} + +GameObject* +ObjectFactory::create(const std::string& name, const Reader& reader) +{ + Factories::iterator i = factories.find(name); + + if (i == factories.end()) + { std::stringstream msg; msg << "No factory for object '" << name << "' found."; throw std::runtime_error(msg.str()); } - - return i->second->create_object(reader); + else + { + return i->second->create(reader); + } } -GameObject* create_object(const std::string& name, const Vector& pos, const Direction dir) +GameObject* +ObjectFactory::create(const std::string& name, const Vector& pos, const Direction dir) { std::stringstream lisptext; lisptext << "((x " << pos.x << ")" @@ -45,8 +282,8 @@ GameObject* create_object(const std::string& name, const Vector& pos, const Dire lisp::Parser parser; const lisp::Lisp* lisp = parser.parse(lisptext, "create_object"); - GameObject* object = create_object(name, *(lisp->get_car())); - + + GameObject* object = create(name, *(lisp->get_car())); return object; } diff --git a/src/supertux/object_factory.hpp b/src/supertux/object_factory.hpp index 8b978319c..b734a1f42 100644 --- a/src/supertux/object_factory.hpp +++ b/src/supertux/object_factory.hpp @@ -19,6 +19,7 @@ #define HEADER_SUPERTUX_SUPERTUX_OBJECT_FACTORY_HPP #include +#include #include "supertux/direction.hpp" #include "util/reader_fwd.hpp" @@ -26,54 +27,56 @@ class Vector; class GameObject; -class Factory +class AbstractObjectFactory { public: - virtual ~Factory() + virtual ~AbstractObjectFactory() { } /** Creates a new gameobject from a lisp node. * Remember to delete the objects later */ - virtual GameObject* create_object(const Reader& reader) = 0; + virtual GameObject* create(const Reader& reader) = 0; +}; + +template +class ConcreteObjectFactory : public AbstractObjectFactory +{ +public: + ConcreteObjectFactory() {} + ~ConcreteObjectFactory() {} - typedef std::map Factories; - static Factories &get_factories() + GameObject* create(const Reader& reader) { - static Factories object_factories; - return object_factories; + return new C(reader); } }; -GameObject* create_object(const std::string& name, const Reader& reader); -GameObject* create_object(const std::string& name, const Vector& pos, const Direction dir = AUTO); +class ObjectFactory +{ +public: + static ObjectFactory& instance(); + +private: + typedef std::map Factories; + Factories factories; -/** comment from Matze: - * Yes I know macros are evil, but in this specific case they save - * A LOT of typing and evil code duplication. - * I'll happily accept alternatives if someone can present me one that does - * not involve typing 4 or more lines for each object class - */ -#define IMPLEMENT_FACTORY(CLASS, NAME) \ - class INTERN_##CLASS##Factory : public Factory \ - { \ - public: \ - INTERN_##CLASS##Factory() \ - { \ - get_factories()[NAME] = this; \ - } \ - \ - ~INTERN_##CLASS##Factory() \ - { \ - get_factories().erase(NAME); \ - } \ - \ - virtual GameObject* create_object(const Reader& reader) \ - { \ - return new CLASS(reader); \ - } \ - }; \ - static INTERN_##CLASS##Factory factory_##CLASS +public: + ObjectFactory(); + ~ObjectFactory(); + + GameObject* create(const std::string& name, const Reader& reader); + GameObject* create(const std::string& name, const Vector& pos, const Direction dir = AUTO); + +private: + template + void add_factory(const char* name) + { + assert(factories.find(name) == factories.end()); + factories[name] = new ConcreteObjectFactory(); + } + void init_factories(); +}; #endif diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 053a0b6d7..8d83f5b77 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -172,7 +172,7 @@ Sector::parse_object(const std::string& name, const Reader& reader) return new Jumpy(reader); } else { try { - return create_object(name, reader); + return ObjectFactory::instance().create(name, reader); } catch(std::exception& e) { log_warning << e.what() << "" << std::endl; return 0; diff --git a/src/trigger/climbable.cpp b/src/trigger/climbable.cpp index fc0cd6790..dd8d944f0 100644 --- a/src/trigger/climbable.cpp +++ b/src/trigger/climbable.cpp @@ -114,6 +114,4 @@ Climbable::may_climb(Player& player) return true; } -IMPLEMENT_FACTORY(Climbable, "climbable"); - /* EOF */ diff --git a/src/trigger/door.cpp b/src/trigger/door.cpp index 59091f781..c1418d89d 100644 --- a/src/trigger/door.cpp +++ b/src/trigger/door.cpp @@ -147,6 +147,4 @@ Door::collision(GameObject& other, const CollisionHit& hit) return TriggerBase::collision(other, hit); } -IMPLEMENT_FACTORY(Door, "door"); - /* EOF */ diff --git a/src/trigger/scripttrigger.cpp b/src/trigger/scripttrigger.cpp index 50aa75f37..db1e308ef 100644 --- a/src/trigger/scripttrigger.cpp +++ b/src/trigger/scripttrigger.cpp @@ -71,6 +71,4 @@ ScriptTrigger::event(Player& , EventType type) Sector::current()->run_script(stream, "ScriptTrigger"); } -IMPLEMENT_FACTORY(ScriptTrigger, "scripttrigger"); - /* EOF */ diff --git a/src/trigger/secretarea_trigger.cpp b/src/trigger/secretarea_trigger.cpp index 182e78fbf..0f4aac818 100644 --- a/src/trigger/secretarea_trigger.cpp +++ b/src/trigger/secretarea_trigger.cpp @@ -96,6 +96,4 @@ SecretAreaTrigger::event(Player& , EventType type) } } -IMPLEMENT_FACTORY(SecretAreaTrigger, "secretarea"); - /* EOF */ diff --git a/src/trigger/sequence_trigger.cpp b/src/trigger/sequence_trigger.cpp index 7491a08b0..0398e5fea 100644 --- a/src/trigger/sequence_trigger.cpp +++ b/src/trigger/sequence_trigger.cpp @@ -55,6 +55,4 @@ SequenceTrigger::event(Player& player, EventType type) } } -IMPLEMENT_FACTORY(SequenceTrigger, "sequencetrigger"); - /* EOF */ diff --git a/src/trigger/switch.cpp b/src/trigger/switch.cpp index 329a50f33..a1cd864ca 100644 --- a/src/trigger/switch.cpp +++ b/src/trigger/switch.cpp @@ -107,6 +107,4 @@ Switch::event(Player& , EventType type) } -IMPLEMENT_FACTORY(Switch, "switch"); - /* EOF */ -- 2.11.0