Index: orxonox/trunk/src/world.cc
===================================================================
--- orxonox/trunk/src/world.cc	(revision 2551)
+++ orxonox/trunk/src/world.cc	(revision 2636)
@@ -31,7 +31,16 @@
     This creates a new empty world!
 */
-World::World ()
-{
-  entities = new List<WorldEntity>();
+World::World (char* name)
+{
+  this->worldName = name;
+  this->debugWorldNr = -1;
+  this->entities = new List<WorldEntity>();
+}
+
+World::World (int worldID)
+{
+  this->debugWorldNr = worldID;
+  this->worldName = NULL;
+  this->entities = new List<WorldEntity>();
 }
 
@@ -44,4 +53,113 @@
   delete entities;
 }
+
+
+/** 
+    \brief initialize the world before use.
+*/
+Error World::init()
+{
+  this->bPause = false;
+}
+
+Error World::start()
+{
+  this->mainLoop();
+}
+
+Error World::stop()
+{
+  this->bQuitCurrentGame = true;
+  this->localCamera->setWorld(NULL);
+}
+
+Error World::pause()
+{
+  this->isPaused = true;
+}
+
+Error World::resume()
+{
+  this->isPaused = false;
+}
+
+void World::load()
+{
+  if(this->debugWorldNr != -1)
+    {
+      switch(this->debugWorldNr)
+	{
+	case DEBUG_WORLD_0:
+	  {
+	    // create some path nodes
+	    this->pathnodes = new Vector[6];
+	    this->pathnodes[0] = Vector(0, 0, 0);
+	    this->pathnodes[1] = Vector(-100, 40, 0);
+	    this->pathnodes[2] = Vector(-100, 140, 0);
+	    this->pathnodes[3] = Vector(0, 180, 0);
+	    this->pathnodes[4] = Vector(100, 140, 0);
+	    this->pathnodes[5] = Vector(100, 40, 0);
+	    
+	    // create the tracks
+	    this->tracklen = 6;
+	    this->track = new Track[6];
+	    for( int i = 0; i < this->tracklen; i++)
+	      {
+		this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]);
+	      }
+	    
+	    // create a player
+	    WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();
+	    
+	    // bind input
+	    Orxonox *orx = Orxonox::getInstance();
+	    orx->get_localinput()->bind (myPlayer);
+	    
+	    // bind camera
+	    this->localCamera = new Camera(this);
+	    this->getCamera()->bind (myPlayer);	
+	    break;
+	  }
+	case DEBUG_WORLD_1:
+	  {
+	    // create some path nodes
+	    this->pathnodes = new Vector[6];
+	    this->pathnodes[0] = Vector(0, 0, 0);
+	    this->pathnodes[1] = Vector(20, 10, 10);
+	    this->pathnodes[2] = Vector(40, 0, 10);
+	    this->pathnodes[3] = Vector(60, 10, 0);
+	    this->pathnodes[4] = Vector(80, 20, 10);
+	    this->pathnodes[5] = Vector(30, 50, 0);
+	    
+	    // create the tracks
+	    this->tracklen = 6;
+	    this->track = new Track[6];
+	    for( int i = 0; i < this->tracklen; i++)
+	      {
+		this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]);
+	      }
+	    
+	    // create a player
+	    WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();
+	    
+	    // bind input
+	    Orxonox *orx = Orxonox::getInstance();
+	    orx->get_localinput()->bind (myPlayer);
+	    
+	    // bind camera
+	    this->localCamera = new Camera(this);
+	    this->getCamera()->bind (myPlayer);	
+	    break;
+	  }
+	default:
+	  printf("World::load() - no world with ID %i found", this->debugWorldNr );
+	}
+    }
+  else if(this->worldName != NULL)
+    {
+
+    }
+}
+
 
 /** 
@@ -254,36 +372,5 @@
 }
 
-/**
-   \brief loads a simple level for testing purposes
-*/
-void World::load_debug_level()
-{
-  // create some path nodes
-  pathnodes = new Vector[6];
-  pathnodes[0] = Vector(0, 0, 0);
-  pathnodes[1] = Vector(-100, 40, 0);
-  pathnodes[2] = Vector(-100, 140, 0);
-  pathnodes[3] = Vector(0, 180, 0);
-  pathnodes[4] = Vector(100, 140, 0);
-  pathnodes[5] = Vector(100, 40, 0);	
-  
-  // create the tracks
-  tracklen = 6;
-  track = new Track[6];
-  for( int i = 0; i < tracklen; i++)
-    {
-      track[i] = Track( i, (i+1)%tracklen, &pathnodes[i], &pathnodes[(i+1)%tracklen]);
-    }
-  
-  // create a player
-  WorldEntity* myPlayer = (WorldEntity*) spawn<Player>();
-  
-  // bind input
-  Orxonox *orx = Orxonox::getInstance();
-  orx->get_localinput()->bind (myPlayer);
-  
-  // bind camera
-  orx->get_camera()->bind (myPlayer);
-}
+
 
 /**
@@ -295,2 +382,126 @@
   track[loc->part].map_camera (loc, plc);
 }
+
+
+void World::setTrackLen(Uint32 len)
+{
+  this->tracklen = len;
+}
+
+int World::getTrackLen()
+{
+  return this->tracklen;
+}
+
+
+void World::mainLoop()
+{
+  this->lastFrame = SDL_GetTicks();
+  this->bQuitOrxonox = false;
+  this->bQuitCurrentGame = false;
+  printf("World|Entering main loop\n");
+  while(!this->bQuitOrxonox && !this->bQuitCurrentGame) /* pause pause pause ?!?!?*/
+    {
+      // Network
+      synchronize();
+      // Process input
+      handle_input();
+      // Process time
+      time_slice();
+      // Process collision
+      collision();
+      // Draw
+      display();
+    }
+  printf("World|Exiting the main loop\n");
+}
+
+/**
+   \brief synchronize local data with remote data
+*/
+void World::synchronize ()
+{
+  // Get remote input
+  // Update synchronizables
+}
+
+/**
+   \brief run all input processing
+*/
+void World::handle_input ()
+{
+  // localinput
+  Orxonox::getInstance()->get_localinput()->process();
+  // remoteinput
+}
+
+/**
+   \brief advance the timeline
+*/
+void World::time_slice ()
+{
+  Uint32 currentFrame = SDL_GetTicks();
+  if(!this->bPause)
+    {
+      Uint32 dt = currentFrame - this->lastFrame;
+      /*
+      if(dt > 0)
+	{
+	  float fps = 1000/dt;
+	  printf("fps = %f\n", fps);
+	}
+      else
+	{
+	  printf("fps = 1000\n");
+	}
+      */
+      this->time_slice (dt);
+      this->update ();
+      this->localCamera->time_slice (dt);
+    }
+  this->lastFrame = currentFrame;
+}
+
+/**
+   \brief compute collision detection
+*/
+void World::collision ()
+{
+  this->collide ();
+}
+
+/**
+   \brief handle keyboard commands that are not meant for WorldEntities
+   \param cmd: the command to handle
+   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
+*/
+bool World::system_command (Command* cmd)
+{
+  if( !strcmp( cmd->cmd, "quit"))
+    {
+      if( !cmd->bUp) this->bQuitOrxonox = true;
+      return true;
+    }
+  return false;
+}
+
+/**
+	\brief render the current frame
+*/
+void World::display ()
+{
+  // clear buffer
+  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+  // set camera
+  this->localCamera->apply ();
+  // draw world
+  this->draw();
+  // draw HUD
+  // flip buffers
+  SDL_GL_SwapBuffers();
+}
+
+Camera* World::getCamera()
+{
+  return this->localCamera;
+}
