Changed ObjectFactory code so that it works properly when building SuperTux as library
authorgrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Fri, 27 Nov 2009 22:57:32 +0000 (22:57 +0000)
committergrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Fri, 27 Nov 2009 22:57:32 +0000 (22:57 +0000)
git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6142 837edb03-e0f3-0310-88ca-d4d4e8b29345

80 files changed:
src/badguy/angrystone.cpp
src/badguy/bouncing_snowball.cpp
src/badguy/captainsnowball.cpp
src/badguy/crystallo.cpp
src/badguy/dart.cpp
src/badguy/darttrap.cpp
src/badguy/dispenser.cpp
src/badguy/fish.cpp
src/badguy/flame.cpp
src/badguy/flyingsnowball.cpp
src/badguy/ghosttree.cpp
src/badguy/igel.cpp
src/badguy/jumpy.cpp
src/badguy/kamikazesnowball.cpp
src/badguy/kugelblitz.cpp
src/badguy/mole.cpp
src/badguy/mole_rock.cpp
src/badguy/mrbomb.cpp
src/badguy/mriceblock.cpp
src/badguy/mrrocket.cpp
src/badguy/mrtree.cpp
src/badguy/plant.cpp
src/badguy/poisonivy.cpp
src/badguy/skullyhop.cpp
src/badguy/smartball.cpp
src/badguy/snail.cpp
src/badguy/snowball.cpp
src/badguy/spidermite.cpp
src/badguy/spiky.cpp
src/badguy/sspiky.cpp
src/badguy/stalactite.cpp
src/badguy/stumpy.cpp
src/badguy/toad.cpp
src/badguy/totem.cpp
src/badguy/walkingleaf.cpp
src/badguy/willowisp.cpp
src/badguy/yeti.cpp
src/badguy/yeti_stalactite.cpp
src/badguy/zeekling.cpp
src/object/ambient_sound.cpp
src/object/background.cpp
src/object/bicycle_platform.cpp
src/object/bonus_block.cpp
src/object/candle.cpp
src/object/coin.cpp
src/object/decal.cpp
src/object/explosion.cpp
src/object/firefly.cpp
src/object/gradient.cpp
src/object/hurting_platform.cpp
src/object/icecrusher.cpp
src/object/infoblock.cpp
src/object/invisible_wall.cpp
src/object/ispy.cpp
src/object/lantern.cpp
src/object/level_time.cpp
src/object/magicblock.cpp
src/object/platform.cpp
src/object/pneumatic_platform.cpp
src/object/powerup.cpp
src/object/pushbutton.cpp
src/object/rock.cpp
src/object/scripted_object.cpp
src/object/skull_tile.cpp
src/object/spotlight.cpp
src/object/thunderstorm.cpp
src/object/tilemap.cpp
src/object/trampoline.cpp
src/object/unstable_tile.cpp
src/object/weak_block.cpp
src/object/wind.cpp
src/supertux/object_factory.cpp
src/supertux/object_factory.hpp
src/supertux/sector.cpp
src/trigger/climbable.cpp
src/trigger/door.cpp
src/trigger/scripttrigger.cpp
src/trigger/secretarea_trigger.cpp
src/trigger/sequence_trigger.cpp
src/trigger/switch.cpp

index 4875f76..b6defc4 100644 (file)
@@ -162,6 +162,4 @@ AngryStone::active_update(float elapsed_time) {
 
 }
 
-IMPLEMENT_FACTORY(AngryStone, "angrystone");
-
 /* EOF */
index 2328841..72995bf 100644 (file)
@@ -74,6 +74,4 @@ BouncingSnowball::collision_badguy(BadGuy& , const CollisionHit& hit)
   return CONTINUE;
 }
 
-IMPLEMENT_FACTORY(BouncingSnowball, "bouncingsnowball");
-
 /* EOF */
index 4eeaa13..34b287a 100644 (file)
@@ -95,6 +95,4 @@ CaptainSnowball::collision_squished(GameObject& object)
   return true;
 }
 
-IMPLEMENT_FACTORY(CaptainSnowball, "captainsnowball");
-
 /* EOF */
index 7273d4d..443478f 100644 (file)
@@ -63,6 +63,4 @@ Crystallo::collision_squished(GameObject& object)
   return true;
 }
 
-IMPLEMENT_FACTORY(Crystallo, "crystallo");
-
 /* EOF */
index 1bba323..10f8ea1 100644 (file)
@@ -125,6 +125,4 @@ Dart::collision_player(Player& player, const CollisionHit& hit)
   return BadGuy::collision_player(player, hit);
 }
 
-IMPLEMENT_FACTORY(Dart, "dart");
-
 /* EOF */
index de0bada..b31f2e8 100644 (file)
@@ -102,6 +102,4 @@ DartTrap::fire()
   sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
 }
 
-IMPLEMENT_FACTORY(DartTrap, "darttrap");
-
 /* EOF */
index f7c49ed..d19815f 100644 (file)
@@ -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 */
index 8ff95bb..c8bf809 100644 (file)
@@ -154,6 +154,4 @@ Fish::is_freezable() const
   return true;
 }
 
-IMPLEMENT_FACTORY(Fish, "fish");
-
 /* EOF */
index afe2562..ff3c062 100644 (file)
@@ -74,6 +74,4 @@ Flame::kill_fall()
 {
 }
 
-IMPLEMENT_FACTORY(Flame, "flame");
-
 /* EOF */
index 3813056..564e76e 100644 (file)
@@ -121,6 +121,4 @@ FlyingSnowBall::active_update(float elapsed_time)
   }
 }
 
-IMPLEMENT_FACTORY(FlyingSnowBall, "flyingsnowball");
-
 /* EOF */
index cc8e492..9def461 100644 (file)
@@ -269,6 +269,4 @@ GhostTree::spawn_lantern() {
   Sector::current()->add_object(lantern);
 }
 
-IMPLEMENT_FACTORY(GhostTree, "ghosttree");
-
 /* EOF */
index 382aff4..41c3543 100644 (file)
@@ -116,6 +116,4 @@ Igel::collision_squished(GameObject& )
   return false;
 }
 
-IMPLEMENT_FACTORY(Igel, "igel");
-
 /* EOF */
index ad63c49..6e4e92e 100644 (file)
@@ -108,6 +108,4 @@ Jumpy::is_freezable() const
   return true;
 }
 
-IMPLEMENT_FACTORY(Jumpy, "jumpy");
-
 /* EOF */
index 5cec886..daadd93 100644 (file)
@@ -92,6 +92,4 @@ KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit)
   return ABORT_MOVE;
 }
 
-IMPLEMENT_FACTORY(KamikazeSnowball, "kamikazesnowball");
-
 /* EOF */
index 2e304bb..14b0239 100644 (file)
@@ -209,6 +209,4 @@ Kugelblitz::try_activate()
   }
 }
 
-IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz");
-
 /* EOF */
index 1391d2a..291d86e 100644 (file)
@@ -165,6 +165,4 @@ Mole::set_state(MoleState new_state)
   state = new_state;
 }
 
-IMPLEMENT_FACTORY(Mole, "mole");
-
 /* EOF */
index efe5e00..9b3c0a6 100644 (file)
@@ -101,6 +101,4 @@ MoleRock::collision_player(Player& player, const CollisionHit& hit)
   return BadGuy::collision_player(player, hit);
 }
 
-IMPLEMENT_FACTORY(MoleRock, "mole_rock");
-
 /* EOF */
index 67efd64..9614e74 100644 (file)
@@ -143,6 +143,4 @@ MrBomb::is_portable() const
   return frozen;
 }
 
-IMPLEMENT_FACTORY(MrBomb, "mrbomb");
-
 /* EOF */
index 4d3bca7..9cc320a 100644 (file)
@@ -286,6 +286,4 @@ MrIceBlock::is_portable() const
   return ice_state == ICESTATE_FLAT;
 }
 
-IMPLEMENT_FACTORY(MrIceBlock, "mriceblock");
-
 /* EOF */
index 23ac5bc..02fea0c 100644 (file)
@@ -77,6 +77,4 @@ MrRocket::collision_solid(const CollisionHit& hit)
   }
 }
 
-IMPLEMENT_FACTORY(MrRocket, "mrrocket");
-
 /* EOF */
index eb91e5b..9a04e6c 100644 (file)
@@ -93,6 +93,4 @@ MrTree::collision_squished(GameObject& object)
   return true;
 }
 
-IMPLEMENT_FACTORY(MrTree, "mrtree");
-
 /* EOF */
index 2bf14ff..a2276d3 100644 (file)
@@ -104,6 +104,4 @@ Plant::active_update(float elapsed_time) {
 
 }
 
-IMPLEMENT_FACTORY(Plant, "plant");
-
 /* EOF */
index 742ec4a..5b28671 100644 (file)
@@ -54,6 +54,4 @@ PoisonIvy::collision_squished(GameObject& object)
   return true;
 }
 
-IMPLEMENT_FACTORY(PoisonIvy, "poisonivy");
-
 /* EOF */
index 647ac53..a401cd6 100644 (file)
@@ -141,6 +141,4 @@ SkullyHop::active_update(float elapsed_time)
   }
 }
 
-IMPLEMENT_FACTORY(SkullyHop, "skullyhop");
-
 /* EOF */
index 43bde17..ad566d6 100644 (file)
@@ -41,6 +41,4 @@ SmartBall::collision_squished(GameObject& object)
   return true;
 }
 
-IMPLEMENT_FACTORY(SmartBall, "smartball");
-
 /* EOF */
index 797e06e..95d1dcd 100644 (file)
@@ -249,6 +249,4 @@ Snail::collision_squished(GameObject& object)
   return true;
 }
 
-IMPLEMENT_FACTORY(Snail, "snail");
-
 /* EOF */
index 92769c7..7629a4f 100644 (file)
@@ -39,6 +39,4 @@ SnowBall::collision_squished(GameObject& object)
   return true;
 }
 
-IMPLEMENT_FACTORY(SnowBall, "snowball");
-
 /* EOF */
index a608033..389d70e 100644 (file)
@@ -86,6 +86,4 @@ SpiderMite::active_update(float elapsed_time)
   }
 }
 
-IMPLEMENT_FACTORY(SpiderMite, "spidermite");
-
 /* EOF */
index e0e060b..3e4297f 100644 (file)
@@ -39,6 +39,4 @@ Spiky::is_freezable() const
   return true;
 }
 
-IMPLEMENT_FACTORY(Spiky, "spiky");
-
 /* EOF */
index 63a311c..7f0fde9 100644 (file)
@@ -111,6 +111,4 @@ SSpiky::is_freezable() const
   return true;
 }
 
-IMPLEMENT_FACTORY(SSpiky, "sspiky");
-
 /* EOF */
index 3622003..3c63bea 100644 (file)
@@ -144,6 +144,4 @@ Stalactite::deactivate()
     remove_me();
 }
 
-IMPLEMENT_FACTORY(Stalactite, "stalactite");
-
 /* EOF */
index cdf2878..1ad03a6 100644 (file)
@@ -159,6 +159,4 @@ Stumpy::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
   return CONTINUE;
 }
 
-IMPLEMENT_FACTORY(Stumpy, "stumpy");
-
 /* EOF */
index 429e71f..9925739 100644 (file)
@@ -155,6 +155,4 @@ Toad::active_update(float elapsed_time)
 
 }
 
-IMPLEMENT_FACTORY(Toad, "toad");
-
 /* EOF */
index 15e56b5..068472e 100644 (file)
@@ -261,6 +261,4 @@ Totem::synchronize_with(Totem* base)
   physic.set_velocity_y(base->physic.get_velocity_y());
 }
 
-IMPLEMENT_FACTORY(Totem, "totem");
-
 /* EOF */
index 3df2c2a..2593137 100644 (file)
@@ -41,6 +41,4 @@ WalkingLeaf::collision_squished(GameObject& object)
   return true;
 }
 
-IMPLEMENT_FACTORY(WalkingLeaf, "walkingleaf");
-
 /* EOF */
index 7549593..748a443 100644 (file)
@@ -292,6 +292,4 @@ WillOWisp::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
   scripting::unexpose_object(vm, table_idx, name);
 }
 
-IMPLEMENT_FACTORY(WillOWisp, "willowisp");
-
 /* EOF */
index d56e3a5..26cdfb1 100644 (file)
@@ -310,6 +310,4 @@ Yeti::collision_solid(const CollisionHit& hit)
   }
 }
 
-IMPLEMENT_FACTORY(Yeti, "yeti");
-
 /* EOF */
index 6673a27..12a925e 100644 (file)
@@ -51,6 +51,4 @@ YetiStalactite::active_update(float elapsed_time)
   Stalactite::active_update(elapsed_time);
 }
 
-IMPLEMENT_FACTORY(YetiStalactite, "yeti_stalactite");
-
 /* EOF */
index 69cba10..90b30bb 100644 (file)
@@ -195,6 +195,4 @@ Zeekling::active_update(float elapsed_time) {
   }
 }
 
-IMPLEMENT_FACTORY(Zeekling, "zeekling");
-
 /* EOF */
index 63c26f2..d0d651b 100644 (file)
@@ -264,6 +264,4 @@ AmbientSound::get_pos_y() const
   return position.y;
 }
 
-IMPLEMENT_FACTORY(AmbientSound, "ambient_sound");
-
 /* EOF */
index 59a8871..f74b748 100644 (file)
@@ -117,6 +117,4 @@ Background::draw(DrawingContext& context)
   context.pop_transform();
 }
 
-IMPLEMENT_FACTORY(Background, "background");
-
 /* EOF */
index c66ee3e..f38f6d1 100644 (file)
@@ -127,6 +127,4 @@ BicyclePlatform::update(float elapsed_time)
   }
 }
 
-IMPLEMENT_FACTORY(BicyclePlatform, "bicycle-platform");
-
 /* EOF */
index 55481d7..f09cef2 100644 (file)
@@ -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<MovingObject*> (game_object);
         if(object == 0)
           throw std::runtime_error(
@@ -227,6 +227,4 @@ Block::break_me()
   remove_me();
 }
 
-IMPLEMENT_FACTORY(BonusBlock, "bonusblock");
-
 /* EOF */
index 23c1685..e2899cb 100644 (file)
@@ -110,6 +110,4 @@ Candle::set_burning(bool burning)
   }
 }
 
-IMPLEMENT_FACTORY(Candle, "candle");
-
 /* EOF */
index 5bf7450..9977ff8 100644 (file)
@@ -125,6 +125,4 @@ Coin::collision(GameObject& other, const CollisionHit& )
   return ABORT_MOVE;
 }
 
-IMPLEMENT_FACTORY(Coin, "coin");
-
 /* EOF */
index 0811389..af7a8f7 100644 (file)
@@ -36,6 +36,4 @@ Decal::~Decal()
 {
 }
 
-IMPLEMENT_FACTORY(Decal, "decal");
-
 /* EOF */
index 3c40c25..94a40d1 100644 (file)
@@ -99,6 +99,4 @@ Explosion::collision(GameObject& other, const CollisionHit& )
   return ABORT_MOVE;
 }
 
-IMPLEMENT_FACTORY(Explosion, "explosion");
-
 /* EOF */
index 2241a3c..8804999 100644 (file)
@@ -90,6 +90,4 @@ Firefly::collision(GameObject& other, const CollisionHit& )
   return ABORT_MOVE;
 }
 
-IMPLEMENT_FACTORY(Firefly, "firefly");
-
 /* EOF */
index 896f30b..7e325b1 100644 (file)
@@ -72,6 +72,4 @@ Gradient::draw(DrawingContext& context)
   context.pop_transform();
 }
 
-IMPLEMENT_FACTORY(Gradient, "gradient");
-
 /* EOF */
index 95601fd..84395b3 100644 (file)
@@ -44,6 +44,4 @@ HurtingPlatform::collision(GameObject& other, const CollisionHit& )
   return FORCE_MOVE;
 }
 
-IMPLEMENT_FACTORY(HurtingPlatform, "hurting_platform");
-
 /* EOF */
index 1d7663f..de27a77 100644 (file)
@@ -161,6 +161,4 @@ IceCrusher::found_victim()
   return false;
 }
 
-IMPLEMENT_FACTORY(IceCrusher, "icecrusher");
-
 /* EOF */
index 475d7d3..3f558df 100644 (file)
@@ -194,6 +194,4 @@ InfoBlock::hide_message()
   dest_pct = 0;
 }
 
-IMPLEMENT_FACTORY(InfoBlock, "infoblock");
-
 /* EOF */
index beb41a9..788ced3 100644 (file)
@@ -36,6 +36,4 @@ InvisibleWall::collision(GameObject& , const CollisionHit& )
   return FORCE_MOVE;
 }
 
-IMPLEMENT_FACTORY(InvisibleWall, "invisible_wall");
-
 /* EOF */
index 5a7092e..d69266a 100644 (file)
@@ -197,6 +197,4 @@ Ispy::update(float )
   }
 }
 
-IMPLEMENT_FACTORY(Ispy, "ispy");
-
 /* EOF */
index 065f537..fcdc675 100644 (file)
@@ -130,6 +130,4 @@ Lantern::is_open()
   return ((grabbed) && lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0);
 }
 
-IMPLEMENT_FACTORY(Lantern, "lantern");
-
 /* EOF */
index 6f096b0..8cc4d09 100644 (file)
@@ -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 */
index 2b9ffe2..072ddc8 100644 (file)
@@ -160,6 +160,4 @@ MagicBlock::collision(GameObject& /*other*/, const CollisionHit& /*hit*/)
   return FORCE_MOVE;
 }
 
-IMPLEMENT_FACTORY(MagicBlock, "magicblock");
-
 /* EOF */
index 2575edc..aa03923 100644 (file)
@@ -144,6 +144,4 @@ Platform::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
   scripting::unexpose_object(vm, table_idx, name);
 }
 
-IMPLEMENT_FACTORY(Platform, "platform");
-
 /* EOF */
index 839ddda..99fd2c6 100644 (file)
@@ -111,6 +111,4 @@ PneumaticPlatform::update(float elapsed_time)
   }
 }
 
-IMPLEMENT_FACTORY(PneumaticPlatform, "pneumatic-platform");
-
 /* EOF */
index f4af4ab..a5e384a 100644 (file)
@@ -86,6 +86,4 @@ PowerUp::update(float elapsed_time)
     movement = physic.get_movement(elapsed_time);
 }
 
-IMPLEMENT_FACTORY(PowerUp, "powerup");
-
 /* EOF */
index 027274f..07190c2 100644 (file)
@@ -75,6 +75,4 @@ PushButton::collision(GameObject& other, const CollisionHit& hit)
   return FORCE_MOVE;
 }
 
-IMPLEMENT_FACTORY(PushButton, "pushbutton");
-
 /* EOF */
index 99d7c2c..fd59162 100644 (file)
@@ -137,6 +137,5 @@ Rock::ungrab(MovingObject& , Direction dir)
   grabbed = false;
 }
 
-IMPLEMENT_FACTORY(Rock, "rock");
 
 /* EOF */
index 726a21b..1a43a3a 100644 (file)
@@ -207,6 +207,4 @@ ScriptedObject::collision(GameObject& , const CollisionHit& )
   return FORCE_MOVE;
 }
 
-IMPLEMENT_FACTORY(ScriptedObject, "scriptedobject");
-
 /* EOF */
index 996b127..5ad5eab 100644 (file)
@@ -78,6 +78,4 @@ SkullTile::update(float elapsed_time)
   hit = false;
 }
 
-IMPLEMENT_FACTORY(SkullTile, "skull_tile");
-
 /* EOF */
index 1947766..3735639 100644 (file)
@@ -88,6 +88,4 @@ Spotlight::draw(DrawingContext& context)
   context.pop_target();
 }
 
-IMPLEMENT_FACTORY(Spotlight, "spotlight");
-
 /* EOF */
index 6a8aeff..b6abf87 100644 (file)
@@ -142,6 +142,4 @@ Thunderstorm::electrify()
   Sector::current()->add_object(new Electrifier(76, 1422, 0.5));
 }
 
-IMPLEMENT_FACTORY(Thunderstorm, "thunderstorm");
-
 /* EOF */
index fd5747c..3825545 100644 (file)
@@ -401,7 +401,6 @@ TileMap::get_alpha()
 {
   return this->current_alpha;
 }
-  
-IMPLEMENT_FACTORY(TileMap, "tilemap");
 
 /* EOF */
index e097dcd..c93d349 100644 (file)
@@ -122,6 +122,4 @@ Trampoline::is_portable() const
   return Rock::is_portable() && portable;
 }
 
-IMPLEMENT_FACTORY(Trampoline, "trampoline");
-
 /* EOF */
index 5141036..79d6b2a 100644 (file)
@@ -71,6 +71,4 @@ UnstableTile::update(float elapsed_time)
   }
 }
 
-IMPLEMENT_FACTORY(UnstableTile, "unstable_tile");
-
 /* EOF */
index 7dd0810..eae7d0c 100644 (file)
@@ -110,6 +110,5 @@ WeakBlock::spreadHit()
   }
 }
 
-IMPLEMENT_FACTORY(WeakBlock, "weak_block");
 
 /* EOF */
index 2e6cd85..0072fe2 100644 (file)
@@ -120,6 +120,4 @@ Wind::stop()
   blowing = false;
 }
 
-IMPLEMENT_FACTORY(Wind, "wind");
-
 /* EOF */
index ea2b35d..fe6cb08 100644 (file)
 #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>("angrystone");
+  add_factory<BouncingSnowball>("bouncingsnowball");
+  add_factory<CaptainSnowball>("captainsnowball");
+  add_factory<Crystallo>("crystallo");
+  add_factory<Dart>("dart");
+  add_factory<DartTrap>("darttrap");
+  add_factory<Dispenser>("dispenser");
+  add_factory<Fish>("fish");
+  add_factory<Flame>("flame");
+  add_factory<FlyingSnowBall>("flyingsnowball");
+  add_factory<GhostTree>("ghosttree");
+  add_factory<Igel>("igel");
+  add_factory<Jumpy>("jumpy");
+  add_factory<KamikazeSnowball>("kamikazesnowball");
+  add_factory<Kugelblitz>("kugelblitz");
+  add_factory<Mole>("mole");
+  add_factory<MoleRock>("mole_rock");
+  add_factory<MrBomb>("mrbomb");
+  add_factory<MrIceBlock>("mriceblock");
+  add_factory<MrRocket>("mrrocket");
+  add_factory<MrTree>("mrtree");
+  add_factory<Plant>("plant");
+  add_factory<PoisonIvy>("poisonivy");
+  add_factory<SSpiky>("sspiky");
+  add_factory<SkullyHop>("skullyhop");
+  add_factory<SmartBall>("smartball");
+  add_factory<Snail>("snail");
+  add_factory<SnowBall>("snowball");
+  add_factory<SpiderMite>("spidermite");
+  add_factory<Spiky>("spiky");
+  add_factory<Stalactite>("stalactite");
+  add_factory<Stumpy>("stumpy");
+  add_factory<Toad>("toad");
+  add_factory<Totem>("totem");
+  add_factory<WalkingLeaf>("walkingleaf");
+  add_factory<WillOWisp>("willowisp");
+  add_factory<Yeti>("yeti");
+  add_factory<YetiStalactite>("yeti_stalactite");
+  add_factory<Zeekling>("zeekling");
+
+  // other objects
+  add_factory<AmbientSound>("ambient_sound");
+  add_factory<Background>("background");
+  add_factory<BicyclePlatform>("bicycle-platform");
+  add_factory<BonusBlock>("bonusblock");
+  add_factory<Candle>("candle");
+  add_factory<Coin>("coin");
+  add_factory<Decal>("decal");
+  add_factory<Explosion>("explosion");
+  add_factory<Firefly>("firefly");
+  add_factory<Gradient>("gradient");
+  add_factory<HurtingPlatform>("hurting_platform");
+  add_factory<IceCrusher>("icecrusher");
+  add_factory<InfoBlock>("infoblock");
+  add_factory<InvisibleWall>("invisible_wall");
+  add_factory<Ispy>("ispy");
+  add_factory<Lantern>("lantern");
+  add_factory<LevelTime>("leveltime");
+  add_factory<MagicBlock>("magicblock");
+  add_factory<Platform>("platform");
+  add_factory<PneumaticPlatform>("pneumatic-platform");
+  add_factory<PowerUp>("powerup");
+  add_factory<PushButton>("pushbutton");
+  add_factory<Rock>("rock");
+  add_factory<ScriptedObject>("scriptedobject");
+  add_factory<SkullTile>("skull_tile");
+  add_factory<Spotlight>("spotlight");
+  add_factory<Thunderstorm>("thunderstorm");
+  add_factory<TileMap>("tilemap");
+  add_factory<Trampoline>("trampoline");
+  add_factory<UnstableTile>("unstable_tile");
+  add_factory<WeakBlock>("weak_block");
+  add_factory<Wind>("wind");
+
+  // trigger
+  add_factory<Climbable>("climbable");
+  add_factory<Door>("door");
+  add_factory<ScriptTrigger>("scripttrigger");
+  add_factory<SecretAreaTrigger>("secretarea");
+  add_factory<SequenceTrigger>("sequencetrigger");
+  add_factory<Switch>("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;
 }
 
index 8b97831..b734a1f 100644 (file)
@@ -19,6 +19,7 @@
 #define HEADER_SUPERTUX_SUPERTUX_OBJECT_FACTORY_HPP
 
 #include <map>
+#include <assert.h>
 
 #include "supertux/direction.hpp"
 #include "util/reader_fwd.hpp"
 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 C>
+class ConcreteObjectFactory : public AbstractObjectFactory
+{
+public:
+  ConcreteObjectFactory() {}  
+  ~ConcreteObjectFactory() {}
 
-  typedef std::map<std::string, Factory*> 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<std::string, AbstractObjectFactory*> 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<class C>
+  void add_factory(const char* name)
+  {
+    assert(factories.find(name) == factories.end());
+    factories[name] = new ConcreteObjectFactory<C>();
+  }
+  void init_factories();
+};
 
 #endif
 
index 053a0b6..8d83f5b 100644 (file)
@@ -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;
index fc0cd67..dd8d944 100644 (file)
@@ -114,6 +114,4 @@ Climbable::may_climb(Player& player)
   return true;
 }
 
-IMPLEMENT_FACTORY(Climbable, "climbable");
-
 /* EOF */
index 59091f7..c1418d8 100644 (file)
@@ -147,6 +147,4 @@ Door::collision(GameObject& other, const CollisionHit& hit)
   return TriggerBase::collision(other, hit);
 }
 
-IMPLEMENT_FACTORY(Door, "door");
-
 /* EOF */
index 50aa75f..db1e308 100644 (file)
@@ -71,6 +71,4 @@ ScriptTrigger::event(Player& , EventType type)
   Sector::current()->run_script(stream, "ScriptTrigger");
 }
 
-IMPLEMENT_FACTORY(ScriptTrigger, "scripttrigger");
-
 /* EOF */
index 182e78f..0f4aac8 100644 (file)
@@ -96,6 +96,4 @@ SecretAreaTrigger::event(Player& , EventType type)
   }
 }
 
-IMPLEMENT_FACTORY(SecretAreaTrigger, "secretarea");
-
 /* EOF */
index 7491a08..0398e5f 100644 (file)
@@ -55,6 +55,4 @@ SequenceTrigger::event(Player& player, EventType type)
   }
 }
 
-IMPLEMENT_FACTORY(SequenceTrigger, "sequencetrigger");
-
 /* EOF */
index 329a50f..a1cd864 100644 (file)
@@ -107,6 +107,4 @@ Switch::event(Player& , EventType type)
 
 }
 
-IMPLEMENT_FACTORY(Switch, "switch");
-
 /* EOF */