Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2636 in orxonox.OLD for orxonox/trunk/src/orxonox.cc


Ignore:
Timestamp:
Oct 25, 2004, 12:48:39 AM (20 years ago)
Author:
patrick
Message:
  • Added a GameLoader to the game. This enables orxonox to load a campaign consisting of multimple worlds and cinematics etc. However, cinematics are not yet implemented.

In the game you can jump from one level to the other by pressing x. Currently there are only two very simple levels defined. (DEBUG_LEVEL_0, DEBUG_LEVEL_1).

  • Added Error Handling structs to signal the error source and code
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/orxonox.cc

    r2551 r2636  
    2929#include "data_tank.h"
    3030#include "command_node.h"
     31#include "game_loader.h"
    3132#include <string.h>
    3233
     
    3435
    3536/**
    36         \brief create a new Orxonox
     37   \brief create a new Orxonox
    3738*/
    3839Orxonox::Orxonox ()
     
    4243
    4344/**
    44         \brief remove Orxonox from memory
     45   \brief remove Orxonox from memory
    4546*/
    4647Orxonox::~Orxonox ()
    4748{
    48         Orxonox::singleton_ref = NULL;
    49         if( world != NULL) delete world;
    50         if( localinput != NULL) delete world;
    51         if( localcamera != NULL) delete localcamera;
    52         if( resources != NULL) delete resources;
     49  Orxonox::singleton_ref = NULL;
     50  if( world != NULL) delete world;
     51  if( localinput != NULL) delete world;
     52  if( localcamera != NULL) delete localcamera;
     53  if( resources != NULL) delete resources;
    5354}
    5455
     
    6566
    6667/**
    67         \brief this finds the config file
    68        
    69         Since the config file varies from user to user and since one may want to specify different config files
    70         for certain occasions or platforms this function finds the right config file for every occasion and stores
    71         it's path and name into configfilename
     68   \brief this finds the config file
     69   
     70   Since the config file varies from user to user and since one may want to specify different config files
     71   for certain occasions or platforms this function finds the right config file for every occasion and stores
     72   it's path and name into configfilename
    7273*/
    7374void Orxonox::get_config_file (int argc, char** argv)
    7475{
    75 /*      char* path;
    76         #ifdef __WIN32__
    77         path = getenv("");
    78         #else
    79         path = getenv("HOME");
    80         #endif
    81        
    82         if( path != NULL) strcpy (configfilename, path);
    83         else strcpy (configfilename, "./");
    84         strcat (configfilename, "/.orxonox.conf");*/
    85        
    86         strcpy (configfilename, "orxonox.conf");
    87 }
    88 
    89 /**
    90         \brief initialize Orxonox with command line
     76  /*    char* path;
     77    #ifdef __WIN32__
     78    path = getenv("");
     79    #else
     80    path = getenv("HOME");
     81    #endif
     82   
     83    if( path != NULL) strcpy (configfilename, path);
     84    else strcpy (configfilename, "./");
     85    strcat (configfilename, "/.orxonox.conf");*/
     86 
     87  strcpy (configfilename, "orxonox.conf");
     88}
     89
     90/**
     91   \brief initialize Orxonox with command line
    9192*/
    9293int Orxonox::init (int argc, char** argv)
    9394{
    94                 // parse command line
    95                 // config file
    96                
    97         get_config_file (argc, argv);
    98        
    99                 // initialize SDL
     95  // parse command line
     96  // config file
     97 
     98  get_config_file (argc, argv);
     99 
     100  // initialize SDL
    100101  printf("> Initializing SDL\n");
    101102  if( SDL_Init (SDL_INIT_EVERYTHING) == -1)
    102   {
    103     printf ("Could not SDL_Init(): %s\n", SDL_GetError());
    104     return -1;
    105   }
    106  
    107         // initialize everything
     103    {
     104      printf ("Could not SDL_Init(): %s\n", SDL_GetError());
     105      return -1;
     106    }
     107 
     108  // initialize everything
    108109  printf("> Initializing video\n");
    109         if( init_video () == -1) return -1;
     110  if( init_video () == -1) return -1;
    110111  printf("> Initializing sound\n");
    111         if( init_sound () == -1) return -1;
     112  if( init_sound () == -1) return -1;
    112113  printf("> Initializing input\n");
    113         if( init_input () == -1) return -1;
     114  if( init_input () == -1) return -1;
    114115  printf("> Initializing networking\n");
    115         if( init_networking () == -1) return -1;
     116  if( init_networking () == -1) return -1;
    116117  printf("> Initializing resources\n");
    117         if( init_resources () == -1) return -1;
    118   printf("> Initializing world\n");
    119         if( init_world () == -1) return -1;
    120        
    121         return 0;
    122 }
    123 
    124 /**
    125         \brief initializes SDL and OpenGL
     118  if( init_resources () == -1) return -1;
     119  //printf("> Initializing world\n");
     120  //if( init_world () == -1) return -1; PB: world will be initialized when started
     121 
     122  return 0;
     123}
     124
     125/**
     126   \brief initializes SDL and OpenGL
    126127*/
    127128int Orxonox::init_video ()
     
    161162 
    162163  // create camera
    163   localcamera = new Camera();
    164  
    165   return 0;
    166 }
    167 
    168 /**
    169         \brief initializes the sound engine
     164  localcamera = new Camera(world);
     165 
     166  return 0;
     167}
     168
     169/**
     170   \brief initializes the sound engine
    170171*/
    171172int Orxonox::init_sound ()
    172173{
    173         printf("Not yet implemented\n");
    174         return 0;
    175 }
    176 
    177 /**
    178         \brief initializes input functions
     174  printf("Not yet implemented\n");
     175  return 0;
     176}
     177
     178/**
     179   \brief initializes input functions
    179180*/
    180181int Orxonox::init_input ()
    181182{
    182         // create localinput
    183         localinput = new CommandNode( configfilename);
    184        
    185         return 0;
    186 }
    187 
    188 /**
    189         \brief initializes network system
     183  // create localinput
     184  localinput = new CommandNode( configfilename);
     185 
     186  return 0;
     187}
     188
     189/**
     190   \brief initializes network system
    190191*/
    191192int Orxonox::init_networking ()
    192193{
    193         printf("Not yet implemented\n");
    194         return 0;
    195 }
    196 
    197 /**
    198         \brief initializes and loads resource files
     194  printf("Not yet implemented\n");
     195  return 0;
     196}
     197
     198/**
     199   \brief initializes and loads resource files
    199200*/
    200201int Orxonox::init_resources ()
    201202{
    202         printf("Not yet implemented\n");
    203         return 0;
    204 }
    205 
    206 /**
    207         \brief initializes the world
     203  printf("Not yet implemented\n");
     204  return 0;
     205}
     206
     207/**
     208   \brief initializes the world
    208209*/
    209210int Orxonox::init_world ()
    210211{
    211         world = new World();
    212        
    213         // TO DO: replace this with a menu/intro
    214         world->load_debug_level();
    215        
    216         return 0;
    217 }
    218 
    219 /**
    220         \brief exits Orxonox
     212  //world = new World();
     213 
     214  // TO DO: replace this with a menu/intro
     215  //world->load_debug_level();
     216 
     217  return 0;
     218}
     219
     220
     221/**
     222   \brief starts the orxonox game or menu
     223
     224   here is the central orxonox state manager. There are currently two states
     225   - menu
     226   - game-play
     227   both states manage their states themselfs again.
     228*/
     229void Orxonox::start()
     230{
     231 
     232  this->gameLoader = GameLoader::getInstance();
     233  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
     234  this->gameLoader->init();
     235  this->gameLoader->start();
     236}
     237
     238/**
     239   \brief exits Orxonox
    221240*/
    222241void Orxonox::quitGame()
    223242{
    224         bQuitOrxonox = true;
    225 }
    226 
    227 /**
    228         \brief this runs all of Orxonox
     243  bQuitOrxonox = true;
     244}
     245
     246/**
     247   \brief this runs all of Orxonox
    229248*/
    230249void Orxonox::mainLoop()
     
    236255  while( !bQuitOrxonox)
    237256    {
    238       printf("<==");
    239 
    240257      // Network
    241258      synchronize();
     
    248265      // Draw
    249266      display();
    250 
    251       printf(">\n");
    252267    }
    253268  printf("Orxonox|Exiting the main loop\n");
     
    255270
    256271/**
    257         \brief handles sprecial events from localinput
    258         \param event: an event not handled by the CommandNode
     272   \brief handles sprecial events from localinput
     273   \param event: an event not handled by the CommandNode
    259274*/
    260275void Orxonox::event_handler (SDL_Event* event)
    261276{
    262         // Handle special events such as reshape, quit, focus changes
    263 }
    264 
    265 /**
    266         \brief synchronize local data with remote data
     277  // Handle special events such as reshape, quit, focus changes
     278}
     279
     280/**
     281   \brief synchronize local data with remote data
    267282*/
    268283void Orxonox::synchronize ()
    269284{
    270         // Get remote input
    271         // Update synchronizables
    272 }
    273 
    274 /**
    275         \brief run all input processing
     285  // Get remote input
     286  // Update synchronizables
     287}
     288
     289/**
     290   \brief run all input processing
    276291*/
    277292void Orxonox::handle_input ()
    278293{
    279         // localinput
    280                 localinput->process();
    281         // remoteinput
    282 }
    283 
    284 /**
    285         \brief advance the timeline
     294  // localinput
     295  localinput->process();
     296  // remoteinput
     297}
     298
     299/**
     300   \brief advance the timeline
    286301*/
    287302void Orxonox::time_slice ()
     
    295310        {
    296311          float fps = 1000/dt;
    297           printf("%f", fps);
     312          printf("fps = %f\n", fps);
    298313        }
    299314     
     
    306321
    307322/**
    308         \brief compute collision detection
     323   \brief compute collision detection
    309324*/
    310325void Orxonox::collision ()
    311326{
    312         world->collide ();
    313 }
    314 
    315 /**
    316         \brief handle keyboard commands that are not meant for WorldEntities
    317         \param cmd: the command to handle
    318         \return true if the command was handled by the system or false if it may be passed to the WorldEntities
     327  world->collide ();
     328}
     329
     330/**
     331   \brief handle keyboard commands that are not meant for WorldEntities
     332   \param cmd: the command to handle
     333   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
    319334*/
    320335bool Orxonox::system_command (Command* cmd)
    321336{
    322         if( !strcmp( cmd->cmd, "quit"))
    323         {
    324                 if( !cmd->bUp) bQuitOrxonox = true;
    325                 return true;
    326         }
    327         return false;
    328 }
    329 
    330 /**
    331         \brief render the current frame
     337  if( !strcmp( cmd->cmd, "quit"))
     338    {
     339      if( !cmd->bUp) this->gameLoader->stop();
     340      return true;
     341    }
     342  return false;
     343}
     344
     345/**
     346   \brief render the current frame
    332347*/
    333348void Orxonox::display ()
    334349{
    335                 // clear buffer
    336         glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    337                 // set camera
    338         localcamera->apply ();
    339                 // draw world
    340         world->draw ();
    341                 // draw HUD
    342                 // flip buffers
    343         SDL_GL_SwapBuffers();
    344 }
    345 
    346 /**
    347         \brief retrieve a pointer to the local Camera
    348         \return a pointer to localcamera
     350  // clear buffer
     351  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     352  // set camera
     353  localcamera->apply ();
     354  // draw world
     355  world->draw ();
     356  // draw HUD
     357  // flip buffers
     358  SDL_GL_SwapBuffers();
     359}
     360
     361/**
     362   \brief retrieve a pointer to the local Camera
     363   \return a pointer to localcamera
    349364*/
    350365Camera* Orxonox::get_camera ()
    351366{
    352         return localcamera;
    353 }
    354 
    355 /**
    356         \brief retrieve a pointer to the local CommandNode
    357         \return a pointer to localinput
     367  return localcamera;
     368}
     369
     370/**
     371   \brief retrieve a pointer to the local CommandNode
     372   \return a pointer to localinput
    358373*/
    359374CommandNode* Orxonox::get_localinput ()
    360375{
    361         return localinput;
    362 }
    363 
    364 /**
    365         \brief retrieve a pointer to the local World
    366         \return a pointer to world
     376  return localinput;
     377}
     378
     379/**
     380   \brief retrieve a pointer to the local World
     381   \return a pointer to world
    367382*/
    368383World* Orxonox::get_world ()
    369384{
    370         return world;
     385  return world;
    371386}
    372387
    373388int main (int argc, char** argv)
    374389
    375         printf(">>> Starting Orxonox <<<\n");
     390  printf(">>> Starting Orxonox <<<\n");
    376391  Orxonox *orx = Orxonox::getInstance();
    377392 
    378393  if( (*orx).init(argc, argv) == -1)
    379   {
    380     printf("! Orxonox initialization failed\n");
    381     return -1;
    382   }
    383        
    384   (*orx).mainLoop();
    385 
     394    {
     395      printf("! Orxonox initialization failed\n");
     396      return -1;
     397    }
     398 
     399  //(*orx).mainLoop();
     400
     401  orx->start();
     402 
    386403  //delete orx;
    387404 
Note: See TracChangeset for help on using the changeset viewer.