Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Nov 11, 2004, 10:32:34 PM (20 years ago)
Author:
patrick
Message:

orxonox/trunk/src: new list implemented

File:
1 edited

Legend:

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

    r2811 r2816  
    2222#include "command_node.h"
    2323#include "camera.h"
     24#include "environment.h"
    2425
    2526using namespace std;
     
    3536  this->worldName = name;
    3637  this->debugWorldNr = -1;
    37   this->entities = new List<WorldEntity>();
     38  this->entities = new List();
    3839}
    3940
     
    4243  this->debugWorldNr = worldID;
    4344  this->worldName = NULL;
    44   this->entities = new List<WorldEntity>();
     45  this->entities = new List();
    4546}
    4647
     
    7475  this->bQuitCurrentGame = true;
    7576  this->localCamera->setWorld(NULL);
     77  this->entities->clear();
     78  Orxonox::getInstance()->get_localinput()->reset();
    7679  this->~World();
    7780}
     
    105108           
    106109            // create the tracks
    107             this->tracklen = 6;
    108             this->track = new Track[6];
     110            this->tracklen = 2;
     111            this->track = new Track[2];
    109112            for( int i = 0; i < this->tracklen; i++)
    110113              {
     
    113116           
    114117            // create a player
    115             //WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();
    116118            WorldEntity* myPlayer = new Player();
    117119            this->spawn(myPlayer);
     
    125127            this->localCamera = new Camera(this);
    126128            this->getCamera()->bind (myPlayer);
     129
     130            Placement* plc = new Placement;
     131            plc->r = Vector(100, 10, 10);
     132            plc->w = Quaternion();
     133            WorldEntity* env = new Environment();
     134            this->spawn(env, plc);
     135
     136            this->entities->debug();
    127137            break;
    128138          }
     
    260270void World::collide ()
    261271{
    262   List<WorldEntity> *a, *b;
     272  /*
     273  List *a, *b;
    263274  WorldEntity *aobj, *bobj;
    264  
    265   a = entities->get_next();
     275   
     276  a = entities;
    266277 
    267278  while( a != NULL)
    268279    {
    269       aobj = a->get_object();
     280      aobj = a->nextElement();
    270281      if( aobj->bCollide && aobj->collisioncluster != NULL)
    271282        {
    272           b = a->get_next();
     283          b = a->nextElement();
    273284          while( b != NULL )
    274285            {
    275               bobj = b->get_object();
     286              bobj = b->nextElement();
    276287              if( bobj->bCollide && bobj->collisioncluster != NULL )
    277288                {
     
    285296                  }
    286297                }
    287               b = b->get_next();
     298              b = b->nextElement();
    288299            }
    289300        }
    290       a = a->get_next();
    291     }
     301      a = a->enumerate();
     302    }
     303  */
    292304}
    293305
     
    300312 
    301313  // draw entities
    302   List<WorldEntity> *l;
     314  List *l;
    303315  WorldEntity* entity;
    304316 
    305   l = entities->get_next(); 
    306   while( l != NULL )
     317  l = entities;
     318  entity = l->enumerate();
     319  while( entity != NULL )
    307320    {
    308       entity = l->get_object();
    309321      if( entity->bDraw ) entity->draw();
    310       l = l->get_next();
     322      entity = l->nextElement();
    311323    }
    312324 
     
    328340void World::update ()
    329341{
    330   List<WorldEntity> *l;
     342  //List<WorldEntity> *l;
    331343  WorldEntity* entity;
    332344  Location* loc;
     
    334346  Uint32 t;
    335347 
    336   l = entities->get_next(); 
    337   while( l != NULL )
     348  //  l = entities->enumerate();
     349  entity = this->entities->enumerate();
     350  while( entity != NULL )
    338351    {
    339       entity = l->get_object();
     352
    340353     
    341354      if( !entity->isFree() )
     
    375388        }
    376389     
    377       l = l->get_next();
     390      entity = entities->nextElement();
    378391    }
    379392 
     
    386399void World::time_slice (Uint32 deltaT)
    387400{
    388   List<WorldEntity> *l;
     401  //List<WorldEntity> *l;
    389402  WorldEntity* entity;
    390403  float seconds = deltaT;
     
    392405  seconds /= 1000;
    393406 
    394   l = entities->get_next();
    395   while( l != NULL)
     407  entity = entities->enumerate();
     408  while( entity != NULL)
    396409    {
    397       entity = l->get_object();
    398410      entity->tick (seconds);
    399       l = l->get_next();
    400     }
    401  
     411      entity = entities->nextElement();
     412    }
     413
    402414  for( int i = 0; i < tracklen; i++) track[i].tick (seconds);
    403415}
     
    436448void World::debug()
    437449{
    438   List<WorldEntity> *l;
     450  //List<WorldEntity> *l;
    439451  WorldEntity* entity;
    440452 
    441453  printf("counting all entities\n");
    442   l = entities->get_next(); 
    443   while( l != NULL )
     454  printf("World::debug() - enumerate()\n");
     455  entity = entities->enumerate(); 
     456  while( entity != NULL )
    444457    {
    445       entity = l->get_object();
    446458      if( entity->bDraw ) printf("got an entity\n");
    447       l = l->get_next();
     459      entity = entities->nextElement();
    448460    }
    449461}
     
    470482      // Draw
    471483      display();
     484 
     485      for(int i = 0; i < 1000000; i++){}
     486
    472487    }
    473488  printf("World|Exiting the main loop\n");
     
    502517    {
    503518      Uint32 dt = currentFrame - this->lastFrame;
    504       /*
     519     
    505520      if(dt > 0)
    506521        {
     
    510525      else
    511526        {
    512           printf("fps = 1000\n");
    513         }
    514       */
     527          printf("fps = 1000 but 0ms!\n");
     528        }
     529     
    515530      this->time_slice (dt);
    516531      this->update ();
     
    570585  Location* loc = NULL;
    571586  WorldEntity* owner;
    572   //T* entity = new T();
    573   entities->add (entity, LIST_ADD_NEXT);
    574   //if( loc == NULL)
    575   //{
    576       zeroloc.dist = 0;
    577       zeroloc.part = 0;
    578       zeroloc.pos = Vector();
    579       zeroloc.rot = Quaternion();
    580       loc = &zeroloc;
    581       //}
     587
     588  entities->add (entity);
     589  zeroloc.dist = 0;
     590  zeroloc.part = 0;
     591  zeroloc.pos = Vector();
     592  zeroloc.rot = Quaternion();
     593  loc = &zeroloc;
    582594  entity->init (loc, owner);
    583595  if (entity->bFree)
     
    586598    }
    587599  entity->post_spawn ();
     600}
     601
     602
     603void World::spawn(WorldEntity* entity, Location* loc)
     604{
     605  Location zeroLoc;
     606  WorldEntity* owner;
     607  this->entities->add (entity);
     608  if( loc == NULL)
     609    {
     610      zeroLoc.dist = 0;
     611      zeroLoc.part = 0;
     612      zeroLoc.pos = Vector();
     613      zeroLoc.rot = Quaternion();
     614      loc = &zeroLoc;
     615    }
     616  entity->init (loc, owner);
     617  if (entity->bFree)
     618    {
     619      this->track[loc->part].map_coords( loc, entity->get_placement());
     620    }
     621  entity->post_spawn ();
    588622  //return entity;
    589623}
     624
     625
     626void World::spawn(WorldEntity* entity, Placement* plc)
     627{
     628  Placement zeroPlc;
     629  WorldEntity* owner;
     630  if( plc == NULL)
     631    {
     632      zeroPlc.r = Vector();
     633      zeroPlc.w = Quaternion();
     634      plc = &zeroPlc;
     635    }
     636  this->entities->add (entity);
     637  entity->init (plc, owner);
     638  entity->post_spawn ();
     639  //return entity;
     640}
Note: See TracChangeset for help on using the changeset viewer.