Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Oct 25, 2004, 12:48:39 AM (21 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/world.cc

    r2551 r2636  
    3131    This creates a new empty world!
    3232*/
    33 World::World ()
    34 {
    35   entities = new List<WorldEntity>();
     33World::World (char* name)
     34{
     35  this->worldName = name;
     36  this->debugWorldNr = -1;
     37  this->entities = new List<WorldEntity>();
     38}
     39
     40World::World (int worldID)
     41{
     42  this->debugWorldNr = worldID;
     43  this->worldName = NULL;
     44  this->entities = new List<WorldEntity>();
    3645}
    3746
     
    4453  delete entities;
    4554}
     55
     56
     57/**
     58    \brief initialize the world before use.
     59*/
     60Error World::init()
     61{
     62  this->bPause = false;
     63}
     64
     65Error World::start()
     66{
     67  this->mainLoop();
     68}
     69
     70Error World::stop()
     71{
     72  this->bQuitCurrentGame = true;
     73  this->localCamera->setWorld(NULL);
     74}
     75
     76Error World::pause()
     77{
     78  this->isPaused = true;
     79}
     80
     81Error World::resume()
     82{
     83  this->isPaused = false;
     84}
     85
     86void World::load()
     87{
     88  if(this->debugWorldNr != -1)
     89    {
     90      switch(this->debugWorldNr)
     91        {
     92        case DEBUG_WORLD_0:
     93          {
     94            // create some path nodes
     95            this->pathnodes = new Vector[6];
     96            this->pathnodes[0] = Vector(0, 0, 0);
     97            this->pathnodes[1] = Vector(-100, 40, 0);
     98            this->pathnodes[2] = Vector(-100, 140, 0);
     99            this->pathnodes[3] = Vector(0, 180, 0);
     100            this->pathnodes[4] = Vector(100, 140, 0);
     101            this->pathnodes[5] = Vector(100, 40, 0);
     102           
     103            // create the tracks
     104            this->tracklen = 6;
     105            this->track = new Track[6];
     106            for( int i = 0; i < this->tracklen; i++)
     107              {
     108                this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]);
     109              }
     110           
     111            // create a player
     112            WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();
     113           
     114            // bind input
     115            Orxonox *orx = Orxonox::getInstance();
     116            orx->get_localinput()->bind (myPlayer);
     117           
     118            // bind camera
     119            this->localCamera = new Camera(this);
     120            this->getCamera()->bind (myPlayer);
     121            break;
     122          }
     123        case DEBUG_WORLD_1:
     124          {
     125            // create some path nodes
     126            this->pathnodes = new Vector[6];
     127            this->pathnodes[0] = Vector(0, 0, 0);
     128            this->pathnodes[1] = Vector(20, 10, 10);
     129            this->pathnodes[2] = Vector(40, 0, 10);
     130            this->pathnodes[3] = Vector(60, 10, 0);
     131            this->pathnodes[4] = Vector(80, 20, 10);
     132            this->pathnodes[5] = Vector(30, 50, 0);
     133           
     134            // create the tracks
     135            this->tracklen = 6;
     136            this->track = new Track[6];
     137            for( int i = 0; i < this->tracklen; i++)
     138              {
     139                this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]);
     140              }
     141           
     142            // create a player
     143            WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();
     144           
     145            // bind input
     146            Orxonox *orx = Orxonox::getInstance();
     147            orx->get_localinput()->bind (myPlayer);
     148           
     149            // bind camera
     150            this->localCamera = new Camera(this);
     151            this->getCamera()->bind (myPlayer);
     152            break;
     153          }
     154        default:
     155          printf("World::load() - no world with ID %i found", this->debugWorldNr );
     156        }
     157    }
     158  else if(this->worldName != NULL)
     159    {
     160
     161    }
     162}
     163
    46164
    47165/**
     
    254372}
    255373
    256 /**
    257    \brief loads a simple level for testing purposes
    258 */
    259 void World::load_debug_level()
    260 {
    261   // create some path nodes
    262   pathnodes = new Vector[6];
    263   pathnodes[0] = Vector(0, 0, 0);
    264   pathnodes[1] = Vector(-100, 40, 0);
    265   pathnodes[2] = Vector(-100, 140, 0);
    266   pathnodes[3] = Vector(0, 180, 0);
    267   pathnodes[4] = Vector(100, 140, 0);
    268   pathnodes[5] = Vector(100, 40, 0);   
    269  
    270   // create the tracks
    271   tracklen = 6;
    272   track = new Track[6];
    273   for( int i = 0; i < tracklen; i++)
    274     {
    275       track[i] = Track( i, (i+1)%tracklen, &pathnodes[i], &pathnodes[(i+1)%tracklen]);
    276     }
    277  
    278   // create a player
    279   WorldEntity* myPlayer = (WorldEntity*) spawn<Player>();
    280  
    281   // bind input
    282   Orxonox *orx = Orxonox::getInstance();
    283   orx->get_localinput()->bind (myPlayer);
    284  
    285   // bind camera
    286   orx->get_camera()->bind (myPlayer);
    287 }
     374
    288375
    289376/**
     
    295382  track[loc->part].map_camera (loc, plc);
    296383}
     384
     385
     386void World::setTrackLen(Uint32 len)
     387{
     388  this->tracklen = len;
     389}
     390
     391int World::getTrackLen()
     392{
     393  return this->tracklen;
     394}
     395
     396
     397void World::mainLoop()
     398{
     399  this->lastFrame = SDL_GetTicks();
     400  this->bQuitOrxonox = false;
     401  this->bQuitCurrentGame = false;
     402  printf("World|Entering main loop\n");
     403  while(!this->bQuitOrxonox && !this->bQuitCurrentGame) /* pause pause pause ?!?!?*/
     404    {
     405      // Network
     406      synchronize();
     407      // Process input
     408      handle_input();
     409      // Process time
     410      time_slice();
     411      // Process collision
     412      collision();
     413      // Draw
     414      display();
     415    }
     416  printf("World|Exiting the main loop\n");
     417}
     418
     419/**
     420   \brief synchronize local data with remote data
     421*/
     422void World::synchronize ()
     423{
     424  // Get remote input
     425  // Update synchronizables
     426}
     427
     428/**
     429   \brief run all input processing
     430*/
     431void World::handle_input ()
     432{
     433  // localinput
     434  Orxonox::getInstance()->get_localinput()->process();
     435  // remoteinput
     436}
     437
     438/**
     439   \brief advance the timeline
     440*/
     441void World::time_slice ()
     442{
     443  Uint32 currentFrame = SDL_GetTicks();
     444  if(!this->bPause)
     445    {
     446      Uint32 dt = currentFrame - this->lastFrame;
     447      /*
     448      if(dt > 0)
     449        {
     450          float fps = 1000/dt;
     451          printf("fps = %f\n", fps);
     452        }
     453      else
     454        {
     455          printf("fps = 1000\n");
     456        }
     457      */
     458      this->time_slice (dt);
     459      this->update ();
     460      this->localCamera->time_slice (dt);
     461    }
     462  this->lastFrame = currentFrame;
     463}
     464
     465/**
     466   \brief compute collision detection
     467*/
     468void World::collision ()
     469{
     470  this->collide ();
     471}
     472
     473/**
     474   \brief handle keyboard commands that are not meant for WorldEntities
     475   \param cmd: the command to handle
     476   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
     477*/
     478bool World::system_command (Command* cmd)
     479{
     480  if( !strcmp( cmd->cmd, "quit"))
     481    {
     482      if( !cmd->bUp) this->bQuitOrxonox = true;
     483      return true;
     484    }
     485  return false;
     486}
     487
     488/**
     489        \brief render the current frame
     490*/
     491void World::display ()
     492{
     493  // clear buffer
     494  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     495  // set camera
     496  this->localCamera->apply ();
     497  // draw world
     498  this->draw();
     499  // draw HUD
     500  // flip buffers
     501  SDL_GL_SwapBuffers();
     502}
     503
     504Camera* World::getCamera()
     505{
     506  return this->localCamera;
     507}
Note: See TracChangeset for help on using the changeset viewer.