Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2822 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Nov 12, 2004, 1:33:25 AM (20 years ago)
Author:
patrick
Message:

orxonox/trunk/src: changed list to template again, will add an iterator soon. fixed a graphics bug, that was realy painful to track.

Location:
orxonox/trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/array.h

    r2811 r2822  
    66#include <GL/gl.h>
    77#include <GL/glu.h>
    8 #include <fstream.h>
     8#include <fstream>
    99class Array
    1010{
  • orxonox/trunk/src/list.h

    r2816 r2822  
    5757};
    5858
     59
     60template<class T> class tList
     61{
     62 private:
     63  struct listElement
     64  {
     65    listElement* prev;
     66    T* curr;
     67    listElement* next;
     68  };
     69
     70  Uint32 size;
     71  listElement* first;
     72  listElement* last;
     73  listElement* currentEl;
     74 
     75 public:
     76  tList ();
     77  ~tList ();
     78 
     79
     80  void add(WorldEntity* entity);
     81  void remove(WorldEntity* entity);
     82  void clear();
     83  T* firstElement();
     84  bool isEmpty();
     85  int getSize();
     86  T* enumerate();
     87  T* nextElement();
     88  T* toArray();
     89  void debug();
     90};
     91
     92
     93template<class T>
     94tList<T>::tList ()
     95{
     96  this->first = NULL;
     97  this->last = NULL;
     98  this->size = 0;
     99}
     100
     101template<class T>
     102tList<T>::~tList ()
     103{}
     104
     105template<class T>
     106void tList<T>::add(WorldEntity* entity)
     107{
     108  printf("tList<T>::add() \n");
     109  listElement* el = new listElement;
     110  el->prev = this->last;
     111  el->curr = entity;
     112  el->next = NULL;
     113
     114  this->last = el;
     115
     116  if(this->size == 0) this->first = el;
     117  else el->prev->next = el;
     118  this->size++;
     119}
     120
     121
     122template<class T>
     123void tList<T>::remove(WorldEntity* entity)
     124{
     125  this->currentEl = this->first;
     126  listElement* te;
     127  while( this->currentEl != NULL)
     128    {
     129      if( this->currentEl->curr == entity)
     130        {
     131          printf("tList<T>::remove() - object found\n");
     132         
     133          if( this->currentEl->prev  == NULL ) this->first = this->currentEl->next;
     134          else this->currentEl->prev->next = this->currentEl->next;
     135
     136          if( this->currentEl->next == NULL) this->last = this->currentEl->prev;
     137          else this->currentEl->next->prev = this->currentEl->prev;
     138
     139          te = this->currentEl->next;
     140          delete this->currentEl;
     141          this->currentEl = te;
     142          return;
     143        }
     144      this->currentEl = this->currentEl->next;
     145    }
     146}
     147
     148
     149template<class T>
     150void tList<T>::clear()
     151{
     152  printf("tList<T>::clear() - clearing all world objects, releasing mem\n");
     153  this->currentEl = this->first;
     154  while(this->currentEl != NULL)
     155    {
     156      listElement* le = this->currentEl->next;
     157      delete this->currentEl->curr;
     158      delete this->currentEl;
     159      this->currentEl = le;
     160    }
     161  this->first = NULL;
     162  this->last = NULL;
     163  this->size = 0;
     164}
     165
     166
     167template<class T>
     168T* tList<T>::firstElement()
     169{
     170  return this->first->curr;
     171}
     172
     173
     174template<class T>
     175bool tList<T>::isEmpty()
     176{
     177  return (this->size==0)?true:false;
     178}
     179
     180
     181template<class T>
     182int tList<T>::getSize()
     183{
     184  return this->size;
     185}
     186
     187
     188template<class T>
     189T* tList<T>::enumerate()
     190{
     191  if(this->size == 0) return NULL;
     192  this->currentEl = this->first;
     193  return this->currentEl->curr;
     194}
     195
     196
     197template<class T>
     198T* tList<T>::nextElement()
     199{
     200  if(this->size == 0) return NULL;
     201  this->currentEl = this->currentEl->next;
     202  if(this->currentEl == NULL) return NULL;
     203  return this->currentEl->curr;
     204}
     205
     206
     207template<class T>
     208T* tList<T>::toArray()
     209{}
     210
    59211#endif
  • orxonox/trunk/src/material.h

    r2811 r2822  
    77#include <GL/glu.h>
    88#include <stdlib.h>
    9 #include <fstream.h>
     9#include <fstream>
    1010
    1111class Material
  • orxonox/trunk/src/object.h

    r2811 r2822  
    88#include "material.h"
    99#include <fstream.h>
     10
    1011
    1112class Object
  • orxonox/trunk/src/world.cc

    r2819 r2822  
    3636  this->worldName = name;
    3737  this->debugWorldNr = -1;
    38   this->entities = new List();
     38  this->entities = new tList<WorldEntity>();
    3939}
    4040
     
    4343  this->debugWorldNr = worldID;
    4444  this->worldName = NULL;
    45   this->entities = new List();
     45  this->entities = new tList<WorldEntity>();
    4646}
    4747
     
    134134            this->spawn(env, plc);
    135135
    136             this->entities->debug();
    137136            break;
    138137          }
     
    331330 
    332331  // draw entities
    333   List *l;
    334332  WorldEntity* entity;
    335333 
    336   l = entities;
    337   entity = l->enumerate();
     334  entity = this->entities->enumerate();
    338335  while( entity != NULL )
    339336    {
    340       entity->draw();
    341       entity = l->nextElement();
     337      if( entity->bDraw ) entity->draw();
     338      entity = this->entities->nextElement();
    342339    }
    343340 
     
    502499      display();
    503500 
    504       for(int i = 0; i < 1000000; i++){}
     501      //for(int i = 0; i < 1000000; i++){}
    505502
    506503    }
  • orxonox/trunk/src/world.h

    r2816 r2822  
    5454  void spawn(WorldEntity* entity, Placement* plc);
    5555
    56   List* entities;
     56  tList<WorldEntity>* entities;
    5757 
    5858  // base level data
  • orxonox/trunk/src/world_entity.cc

    r2190 r2822  
    3636WorldEntity::WorldEntity (bool isFree) : bFree(isFree)
    3737{
    38         collisioncluster = NULL;
    39         owner = NULL;
     38  this->bDraw = true;
     39  collisioncluster = NULL;
     40  owner = NULL;
    4041}
    4142
     
    4546WorldEntity::~WorldEntity ()
    4647{
    47         if( collisioncluster != NULL) delete collisioncluster;
     48  if( collisioncluster != NULL) delete collisioncluster;
    4849}
    4950
    5051/**
    51         \brief get the Location of the WorldEntity
    52         \return a pointer to location
     52   \brief get the Location of the WorldEntity
     53   \return a pointer to location
    5354*/
    5455Location* WorldEntity::get_location ()
    5556{
    56         return &loc;
     57  return &loc;
    5758}
    5859
    5960/**
    60         \brief get the Placement of the WorldEntity
    61         \return a pointer to placement
     61   \brief get the Placement of the WorldEntity
     62   \return a pointer to placement
    6263*/
    6364Placement* WorldEntity::get_placement ()
    6465{
    65         return &place;
     66  return &place;
    6667}
    6768
    6869/**
    69         \brief query whether the WorldEntity in question is free
    70         \return true if the WorldEntity is free or false if it isn't
     70   \brief query whether the WorldEntity in question is free
     71   \return true if the WorldEntity is free or false if it isn't
    7172*/
    7273bool WorldEntity::isFree ()
     
    7677
    7778/**
    78         \brief set the WorldEntity's collision hull
    79         \param newhull: a pointer to a completely assembled CollisionCluster
    80        
    81         Any previously assigned collision hull will be deleted on reassignment
     79   \brief set the WorldEntity's collision hull
     80   \param newhull: a pointer to a completely assembled CollisionCluster
     81   
     82   Any previously assigned collision hull will be deleted on reassignment
    8283*/
    8384void WorldEntity::set_collision (CollisionCluster* newhull)
    8485{
    85         if( newhull == NULL) return;
    86         if( collisioncluster != NULL) delete collisioncluster;
    87         collisioncluster = newhull;
     86  if( newhull == NULL) return;
     87  if( collisioncluster != NULL) delete collisioncluster;
     88  collisioncluster = newhull;
    8889}
    8990
    9091/**
    91         \brief this method is called every frame
    92         \param time: the time in seconds that has passed since the last tick
    93        
    94         Handle all stuff that should update with time inside this method (movement, animation, etc.)
     92   \brief this method is called every frame
     93   \param time: the time in seconds that has passed since the last tick
     94   
     95   Handle all stuff that should update with time inside this method (movement, animation, etc.)
    9596*/
    9697void WorldEntity::tick(float time)
     
    100101/**
    101102   \brief the entity is drawn onto the screen with this function
    102 
     103   
    103104   This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn.
    104105*/
     
    108109
    109110/**
    110         \brief this function is called, when two entities collide
    111         \param other: the world entity with whom it collides
    112         \param ownhitflags: flags to the CollisionCluster subsections that registered an impact
    113         \param otherhitflags: flags to the CollisionCluster subsections of the other entity that registered an impact
     111   \brief this function is called, when two entities collide
     112   \param other: the world entity with whom it collides
     113   \param ownhitflags: flags to the CollisionCluster subsections that registered an impact
     114   \param otherhitflags: flags to the CollisionCluster subsections of the other entity that registered an impact
    114115
    115         Implement behaviour like damage application or other miscellaneous collision stuff in this function
     116   Implement behaviour like damage application or other miscellaneous collision stuff in this function
    116117*/
    117118void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {}
     
    135136
    136137/**
    137         \brief basic initialisation for bound Entities
     138   \brief basic initialisation for bound Entities
    138139*/
    139140void WorldEntity::init( Location* spawnloc, WorldEntity* spawnowner)
    140141{
    141         loc = *spawnloc;
    142         owner = spawnowner;
     142  loc = *spawnloc;
     143  owner = spawnowner;
    143144}
    144145
    145146/**
    146         \brief basic initialisation for free Entities
     147   \brief basic initialisation for free Entities
    147148*/
    148149void WorldEntity::init( Placement* spawnplc, WorldEntity* spawnowner)
    149150{
    150         place = *spawnplc;
    151         owner = spawnowner;
     151  place = *spawnplc;
     152  owner = spawnowner;
    152153}
    153154
    154155/**
    155         \brief this is called immediately after the Entity has been constructed and initialized
    156        
    157         Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
    158         DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
     156   \brief this is called immediately after the Entity has been constructed and initialized
     157   
     158   Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
     159   DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
    159160*/
    160161void WorldEntity::post_spawn ()
     
    163164
    164165/**
    165         \brief this handles incoming command messages
    166         \param cmd: a pointer to the incoming Command structure
    167        
    168         Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used
    169         to send commands from one WorldEntity to another.
     166   \brief this handles incoming command messages
     167   \param cmd: a pointer to the incoming Command structure
     168   
     169   Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used
     170   to send commands from one WorldEntity to another.
    170171*/
    171172void WorldEntity::command (Command* cmd)
     
    174175
    175176/**
    176         \brief this is called by the local Camera to determine the point it should look at on the WorldEntity
    177         \param locbuf: a pointer to the buffer to fill with a location to look at
     177   \brief this is called by the local Camera to determine the point it should look at on the WorldEntity
     178   \param locbuf: a pointer to the buffer to fill with a location to look at
    178179       
    179         You may put any Location you want into locbuf, the Camera will determine via the corresponding Track how
    180         to look at the location you return with this.
     180   You may put any Location you want into locbuf, the Camera will determine via the corresponding Track how
     181   to look at the location you return with this.
    181182*/
    182183void WorldEntity::get_lookat (Location* locbuf)
     
    185186
    186187/**
    187         \brief this method is called by the world if the WorldEntity leaves valid gamespace
    188        
    189         For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
    190         place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
     188   \brief this method is called by the world if the WorldEntity leaves valid gamespace
     189   
     190   For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
     191   place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
    191192*/
    192193void WorldEntity::left_world ()
Note: See TracChangeset for help on using the changeset viewer.