Index: orxonox/trunk/src/orxonox.cc
===================================================================
--- orxonox/trunk/src/orxonox.cc	(revision 2551)
+++ orxonox/trunk/src/orxonox.cc	(revision 2636)
@@ -29,4 +29,5 @@
 #include "data_tank.h"
 #include "command_node.h"
+#include "game_loader.h"
 #include <string.h>
 
@@ -34,5 +35,5 @@
 
 /**
-	\brief create a new Orxonox
+   \brief create a new Orxonox
 */
 Orxonox::Orxonox ()
@@ -42,13 +43,13 @@
 
 /**
-	\brief remove Orxonox from memory
+   \brief remove Orxonox from memory
 */
 Orxonox::~Orxonox () 
 {
-	Orxonox::singleton_ref = NULL;
-	if( world != NULL) delete world;
-	if( localinput != NULL) delete world;
-	if( localcamera != NULL) delete localcamera;
-	if( resources != NULL) delete resources;
+  Orxonox::singleton_ref = NULL;
+  if( world != NULL) delete world;
+  if( localinput != NULL) delete world;
+  if( localcamera != NULL) delete localcamera;
+  if( resources != NULL) delete resources;
 }
 
@@ -65,63 +66,63 @@
 
 /**
-	\brief this finds the config file
-	
-	Since the config file varies from user to user and since one may want to specify different config files
-	for certain occasions or platforms this function finds the right config file for every occasion and stores
-	it's path and name into configfilename
+   \brief this finds the config file
+   
+   Since the config file varies from user to user and since one may want to specify different config files
+   for certain occasions or platforms this function finds the right config file for every occasion and stores
+   it's path and name into configfilename
 */
 void Orxonox::get_config_file (int argc, char** argv)
 {
-/*	char* path;
-	#ifdef __WIN32__
-	path = getenv("");
-	#else
-	path = getenv("HOME");
-	#endif
-	
-	if( path != NULL) strcpy (configfilename, path);
-	else strcpy (configfilename, "./");
-	strcat (configfilename, "/.orxonox.conf");*/
-	
-	strcpy (configfilename, "orxonox.conf");
-}
-
-/**
-	\brief initialize Orxonox with command line
+  /*	char* path;
+    #ifdef __WIN32__
+    path = getenv("");
+    #else
+    path = getenv("HOME");
+    #endif
+    
+    if( path != NULL) strcpy (configfilename, path);
+    else strcpy (configfilename, "./");
+    strcat (configfilename, "/.orxonox.conf");*/
+  
+  strcpy (configfilename, "orxonox.conf");
+}
+
+/**
+   \brief initialize Orxonox with command line
 */
 int Orxonox::init (int argc, char** argv)
 {
-		// parse command line
-		// config file
-		
-	get_config_file (argc, argv);
-	
-		// initialize SDL
+  // parse command line
+  // config file
+  
+  get_config_file (argc, argv);
+  
+  // initialize SDL
   printf("> Initializing SDL\n");
   if( SDL_Init (SDL_INIT_EVERYTHING) == -1)
-  {
-    printf ("Could not SDL_Init(): %s\n", SDL_GetError());
-    return -1;
-  }
-  
-  	// initialize everything
+    {
+      printf ("Could not SDL_Init(): %s\n", SDL_GetError());
+      return -1;
+    }
+  
+  // initialize everything
   printf("> Initializing video\n");
-	if( init_video () == -1) return -1;
+  if( init_video () == -1) return -1;
   printf("> Initializing sound\n");
-	if( init_sound () == -1) return -1;
+  if( init_sound () == -1) return -1;
   printf("> Initializing input\n");
-	if( init_input () == -1) return -1;
+  if( init_input () == -1) return -1;
   printf("> Initializing networking\n");
-	if( init_networking () == -1) return -1;
+  if( init_networking () == -1) return -1;
   printf("> Initializing resources\n");
-	if( init_resources () == -1) return -1;
-  printf("> Initializing world\n");
-	if( init_world () == -1) return -1;
-	
-	return 0;
-}
-
-/**
-	\brief initializes SDL and OpenGL
+  if( init_resources () == -1) return -1;
+  //printf("> Initializing world\n");
+  //if( init_world () == -1) return -1; PB: world will be initialized when started
+  
+  return 0;
+}
+
+/**
+   \brief initializes SDL and OpenGL
 */
 int Orxonox::init_video () 
@@ -161,70 +162,88 @@
   
   // create camera
-  localcamera = new Camera();
-  
-  return 0;
-}
-
-/**
-	\brief initializes the sound engine
+  localcamera = new Camera(world);
+  
+  return 0;
+}
+
+/**
+   \brief initializes the sound engine
 */
 int Orxonox::init_sound () 
 {
-	printf("Not yet implemented\n");
-	return 0;
-}
-
-/**
-	\brief initializes input functions
+  printf("Not yet implemented\n");
+  return 0;
+}
+
+/**
+   \brief initializes input functions
 */
 int Orxonox::init_input () 
 {
-	// create localinput
-	localinput = new CommandNode( configfilename);
-	
-	return 0;
-}
-
-/**
-	\brief initializes network system
+  // create localinput
+  localinput = new CommandNode( configfilename);
+  
+  return 0;
+}
+
+/**
+   \brief initializes network system
 */
 int Orxonox::init_networking () 
 {
-	printf("Not yet implemented\n");
-	return 0;
-}
-
-/**
-	\brief initializes and loads resource files
+  printf("Not yet implemented\n");
+  return 0;
+}
+
+/**
+   \brief initializes and loads resource files
 */
 int Orxonox::init_resources () 
 {
-	printf("Not yet implemented\n");
-	return 0;
-}
-
-/**
-	\brief initializes the world
+  printf("Not yet implemented\n");
+  return 0;
+}
+
+/**
+   \brief initializes the world
 */
 int Orxonox::init_world () 
 {
-	world = new World();
-	
-	// TO DO: replace this with a menu/intro
-	world->load_debug_level();
-	
-	return 0;
-}
-
-/**
-	\brief exits Orxonox
+  //world = new World();
+  
+  // TO DO: replace this with a menu/intro
+  //world->load_debug_level();
+  
+  return 0;
+}
+
+
+/**
+   \brief starts the orxonox game or menu
+
+   here is the central orxonox state manager. There are currently two states
+   - menu
+   - game-play
+   both states manage their states themselfs again.
+*/
+void Orxonox::start()
+{
+  
+  this->gameLoader = GameLoader::getInstance();
+  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
+  this->gameLoader->init();
+  this->gameLoader->start();
+}
+
+/**
+   \brief exits Orxonox
 */
 void Orxonox::quitGame() 
 {
-	bQuitOrxonox = true;
-}
-
-/**
-	\brief this runs all of Orxonox
+  bQuitOrxonox = true;
+}
+
+/**
+   \brief this runs all of Orxonox
 */
 void Orxonox::mainLoop()
@@ -236,6 +255,4 @@
   while( !bQuitOrxonox)
     {
-      printf("<==");
-
       // Network
       synchronize();
@@ -248,6 +265,4 @@
       // Draw
       display();
-
-      printf(">\n");
     }
   printf("Orxonox|Exiting the main loop\n");
@@ -255,33 +270,33 @@
 
 /**
-	\brief handles sprecial events from localinput
-	\param event: an event not handled by the CommandNode 
+   \brief handles sprecial events from localinput
+   \param event: an event not handled by the CommandNode 
 */
 void Orxonox::event_handler (SDL_Event* event)
 {
-	// Handle special events such as reshape, quit, focus changes
-}
-
-/**
-	\brief synchronize local data with remote data
+  // Handle special events such as reshape, quit, focus changes
+}
+
+/**
+   \brief synchronize local data with remote data
 */
 void Orxonox::synchronize ()
 {
-	// Get remote input
-	// Update synchronizables
-}
-
-/**
-	\brief run all input processing
+  // Get remote input
+  // Update synchronizables
+}
+
+/**
+   \brief run all input processing
 */
 void Orxonox::handle_input ()
 {
-	// localinput
-		localinput->process();
-	// remoteinput
-}
-
-/**
-	\brief advance the timeline
+  // localinput
+  localinput->process();
+  // remoteinput
+}
+
+/**
+   \brief advance the timeline
 */
 void Orxonox::time_slice ()
@@ -295,5 +310,5 @@
 	{
 	  float fps = 1000/dt;
-	  printf("%f", fps);
+	  printf("fps = %f\n", fps);
 	}
       
@@ -306,82 +321,84 @@
 
 /**
-	\brief compute collision detection
+   \brief compute collision detection
 */
 void Orxonox::collision ()
 {
-	world->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
+  world->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 Orxonox::system_command (Command* cmd)
 {
-	if( !strcmp( cmd->cmd, "quit"))
-	{
-		if( !cmd->bUp) bQuitOrxonox = true;
-		return true;
-	}
-	return false;
-}
-
-/**
-	\brief render the current frame
+  if( !strcmp( cmd->cmd, "quit"))
+    {
+      if( !cmd->bUp) this->gameLoader->stop();
+      return true;
+    }
+  return false;
+}
+
+/**
+   \brief render the current frame
 */
 void Orxonox::display ()
 {
-		// clear buffer
-	glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-		// set camera
-	localcamera->apply ();
-		// draw world
-	world->draw ();
-		// draw HUD
-		// flip buffers
-	SDL_GL_SwapBuffers();
-}
-
-/**
-	\brief retrieve a pointer to the local Camera
-	\return a pointer to localcamera
+  // clear buffer
+  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+  // set camera
+  localcamera->apply ();
+  // draw world
+  world->draw ();
+  // draw HUD
+  // flip buffers
+  SDL_GL_SwapBuffers();
+}
+
+/**
+   \brief retrieve a pointer to the local Camera
+   \return a pointer to localcamera
 */
 Camera* Orxonox::get_camera ()
 {
-	return localcamera;
-}
-
-/**
-	\brief retrieve a pointer to the local CommandNode
-	\return a pointer to localinput
+  return localcamera;
+}
+
+/**
+   \brief retrieve a pointer to the local CommandNode
+   \return a pointer to localinput
 */
 CommandNode* Orxonox::get_localinput ()
 {
-	return localinput;
-}
-
-/**
-	\brief retrieve a pointer to the local World
-	\return a pointer to world
+  return localinput;
+}
+
+/**
+   \brief retrieve a pointer to the local World
+   \return a pointer to world
 */
 World* Orxonox::get_world ()
 {
-	return world;
+  return world;
 }
 
 int main (int argc, char** argv) 
 {  
-	printf(">>> Starting Orxonox <<<\n");
+  printf(">>> Starting Orxonox <<<\n");
   Orxonox *orx = Orxonox::getInstance();
   
   if( (*orx).init(argc, argv) == -1)
-  {
-    printf("! Orxonox initialization failed\n");
-    return -1;
-  }
-	
-  (*orx).mainLoop();
-
+    {
+      printf("! Orxonox initialization failed\n");
+      return -1;
+    }
+  
+  //(*orx).mainLoop();
+
+  orx->start();
+  
   //delete orx;
   
