Index: orxonox/trunk/src/world.h
===================================================================
--- orxonox/trunk/src/world.h	(revision 2077)
+++ orxonox/trunk/src/world.h	(revision 2190)
@@ -1,26 +1,16 @@
-/**
-  Class representating the game-world
-  
-  It contains a list of players (if multiplayer game), a list of Non-Player-Characters (nps), a list of Environment Entities. All this things together are building the orxonox-world. This class also handels the story-line (track), the world start/stop, init/uninit abilities. It is the middle point of every orxonox world.
-*/
+/*! 
+    \file world.h
+    \brief Holds and manages all game data
+*/ 
 
 #ifndef WORLD_H
 #define WORLD_H
 
-class Player;
-class NPC;
-class Environment;
+#include "stdincl.h"
+
+class Track;
 class WorldEntity;
 
-template<class T> class List;
-
-
-
-//! World Class
-/**
-  Class for World representation
-  
-  It contains a list of players (if multiplayer game), a list of Non-Player-Characters (nps), a list of Environment Entities. All this things together are building the orxonox-world. This class also handels the story-line (track), the world start/stop, init/uninit abilities. It is the middle point of every orxonox world.
-*/
+//! The game environment
 class World {
 
@@ -29,68 +19,89 @@
   ~World ();
 
+	template<typename T> 
+	  T* spawn(Location* loc, WorldEntity* owner);	// template to be able to spawn any derivation of WorldEntity
+	template<typename T> 
+	  T* spawn(Placement* plc, WorldEntity* owner);
 
-
-  float primitiveMove; //!< deprecated, do not use
-
-  Player *localPlayer; //!< a pointer to the local player object
-  Player *player1;     //!< a pointer to the second player object
-  Player *player2;     //!< a pointer to the third player object 
-
-  /*
-  struct playerList {
-    playerList* next;
-    Player* player;
-    int number;
-  };
-  playerList* lastPlayer;
-
-  struct npcList {
-    npcList* next;
-    NPC* npc;
-    int number;
-  };
-  npcList* lastNPC;
-
-  struct envList {
-    envList* next;
-    Environment* env;
-    int number;
-  };
-  envList* lastEnv;
-  */
-
-
-  void loadWorld();
-  void unloadWorld();
-  void pauseWorld();
-  void saveGameState(char* filename);
-  
-
-  bool addPlayer(Player* player);
-  bool removePlayer(Player* player);
-  Player* getLocalPlayer();
-  bool addNPC(NPC* npc);
-  bool removeNPC(NPC* npc);
-  bool addEnv(Environment* env);
-  bool removeEnv(Environment* env);
-
-  
-  void drawWorld(void);
-  void initEnvironement(void);
-  void setWorldStep(float step);
-  void updateWorld(void);
-  void detectCollision(void);
-  void testThaTest(void);
-
+	void time_slice (Uint32 deltaT);
+	void collide ();
+	void draw ();
+	void update ();	// maps Locations to Placements
+	void calc_camera_pos (Location* loc, Placement* plc);
+	
+	void unload ();
+	
+	void load_debug_level ();
+	
  private:
-  float surface[120][120]; //!< deprecated: used to build a surface
-  float step; //!< this is the step
-
-  List<WorldEntity*> *playerList; //!< the list of players, usualy very short
-  List<WorldEntity*> *npcList;  //!< list of non player characters (npc)
-  List<WorldEntity*> *envList;  //!< list of environment objects
-
+ 
+	List<WorldEntity>* entities;
+	
+		// base level data
+	Track* track;
+	Uint32 tracklen;
+	Vector* pathnodes;
 
 };
 
+/**
+    \brief spawn a new WorldEntity at a Location
+    \param loc: the Location where the Entity should be spawned
+    \param owner: a pointer to the parent of the Entity
+    \return a pointer to the new WorldEntity or NULL if there was an error
+    
+    You can use this function to spawn any derivation of WorldEntity you want, just specify the desired
+    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
+    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
+    works with both free and bound WorldEntities.
+*/ 
+template<typename T> T* World::spawn(Location* loc = NULL, WorldEntity* owner = NULL)
+{
+	Location zeroloc;
+	T* entity = new T();
+	entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
+	if( loc == NULL)
+	{
+		zeroloc.dist = 0;
+		zeroloc.part = 0;
+		zeroloc.pos = Vector();
+		zeroloc.rot = Quaternion();
+		loc = &zeroloc;
+	}
+	entity->init (loc, owner);
+	if (entity->bFree)
+	{
+		track[loc->part].map_coords( loc, entity->get_placement());
+	}
+	entity->post_spawn ();
+	return entity;
+}
+
+/**
+    \brief spawn a new WorldEntity at a Placement
+    \param lplc: the placement where the Entity should be spawned
+    \param owner: a pointer to the parent of the Entity
+    \return a pointer to the new WorldEntity or NULL if there was an error
+    
+    You can use this function to spawn any FREE derivation of WorldEntity you want, just specify the desired
+    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
+    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
+    works with free WorldEntities only, you will provoke an error message if you try to spawn a bound Entity with 
+    a Placement.
+*/ 
+template<typename T> T* World::spawn(Placement* plc, WorldEntity* owner = NULL)
+{
+	T* entity = new T();
+	entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
+	entity->init (plc, owner);
+	if (!entity->bFree)
+	{
+		printf("Can't spawn unfree entity with placement\n"); 
+		entities->remove( (WorldEntity*)entity, LIST_FIND_FW);
+		return NULL;
+	}
+	entity->post_spawn ();
+	return entity;
+}
+
 #endif
