Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

orxonox/trunk/src: new list implemented

Location:
orxonox/trunk/src
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.am

    r2811 r2816  
    66
    77bin_PROGRAMS=orxonox
    8 orxonox_SOURCES=orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc game_loader.cc campaign.cc story_entity.cc object.cc array.cc material.cc
    98
    10 noinst_HEADERS=ability.h data_tank.h npc.h stdincl.h ai.h environment.h orxonox.h synchronisable.h base_entity.h error.h player.h track.h camera.h ini_parser.h power_up.h vector.h collision.h keynames.h proto_class.h world.h command_node.h list.h shoot_laser.h world_entity.h coordinates.h message_structures.h shoot_rocket.h object.h array.h material.h
     9orxonox_SOURCES=orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc game_loader.cc campaign.cc story_entity.cc object.cc environment.cc array.cc material.cc list.cc
     10noinst_HEADERS=ability.h data_tank.h npc.h stdincl.h ai.h environment.h orxonox.h synchronisable.h base_entity.h error.h player.h track.h camera.h ini_parser.h power_up.h vector.h collision.h keynames.h proto_class.h world.h command_node.h list.h shoot_laser.h world_entity.h coordinates.h message_structures.h shoot_rocket.h object.h array.h material.h list_template.h
     11
    1112
    1213
  • orxonox/trunk/src/Makefile.in

    r2811 r2816  
    5858        track.$(OBJEXT) base_entity.$(OBJEXT) game_loader.$(OBJEXT) \
    5959        campaign.$(OBJEXT) story_entity.$(OBJEXT) object.$(OBJEXT) \
    60         array.$(OBJEXT) material.$(OBJEXT)
     60        environment.$(OBJEXT) array.$(OBJEXT) material.$(OBJEXT) \
     61        list.$(OBJEXT)
    6162orxonox_OBJECTS = $(am_orxonox_OBJECTS)
    6263orxonox_LDADD = $(LDADD)
     
    6970@AMDEP_TRUE@    ./$(DEPDIR)/command_node.Po \
    7071@AMDEP_TRUE@    ./$(DEPDIR)/data_tank.Po \
     72@AMDEP_TRUE@    ./$(DEPDIR)/environment.Po \
    7173@AMDEP_TRUE@    ./$(DEPDIR)/game_loader.Po \
    7274@AMDEP_TRUE@    ./$(DEPDIR)/ini_parser.Po ./$(DEPDIR)/keynames.Po \
    73 @AMDEP_TRUE@    ./$(DEPDIR)/material.Po ./$(DEPDIR)/object.Po \
    74 @AMDEP_TRUE@    ./$(DEPDIR)/orxonox.Po ./$(DEPDIR)/player.Po \
    75 @AMDEP_TRUE@    ./$(DEPDIR)/story_entity.Po ./$(DEPDIR)/track.Po \
    76 @AMDEP_TRUE@    ./$(DEPDIR)/vector.Po ./$(DEPDIR)/world.Po \
    77 @AMDEP_TRUE@    ./$(DEPDIR)/world_entity.Po
     75@AMDEP_TRUE@    ./$(DEPDIR)/list.Po ./$(DEPDIR)/material.Po \
     76@AMDEP_TRUE@    ./$(DEPDIR)/object.Po ./$(DEPDIR)/orxonox.Po \
     77@AMDEP_TRUE@    ./$(DEPDIR)/player.Po ./$(DEPDIR)/story_entity.Po \
     78@AMDEP_TRUE@    ./$(DEPDIR)/track.Po ./$(DEPDIR)/vector.Po \
     79@AMDEP_TRUE@    ./$(DEPDIR)/world.Po ./$(DEPDIR)/world_entity.Po
    7880CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
    7981        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
     
    165167AM_CXXFLAGS = "-I/usr/X11R6/include"
    166168AM_LDFLAGS = "-L/usr/Mesa-6.0.1/lib  -L/usr/X11R6/lib -lXt -lX11" $(MWINDOWS)
    167 orxonox_SOURCES = orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc game_loader.cc campaign.cc story_entity.cc object.cc array.cc material.cc
    168 noinst_HEADERS = ability.h data_tank.h npc.h stdincl.h ai.h environment.h orxonox.h synchronisable.h base_entity.h error.h player.h track.h camera.h ini_parser.h power_up.h vector.h collision.h keynames.h proto_class.h world.h command_node.h list.h shoot_laser.h world_entity.h coordinates.h message_structures.h shoot_rocket.h object.h array.h material.h
     169orxonox_SOURCES = orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc game_loader.cc campaign.cc story_entity.cc object.cc environment.cc array.cc material.cc list.cc
     170noinst_HEADERS = ability.h data_tank.h npc.h stdincl.h ai.h environment.h orxonox.h synchronisable.h base_entity.h error.h player.h track.h camera.h ini_parser.h power_up.h vector.h collision.h keynames.h proto_class.h world.h command_node.h list.h shoot_laser.h world_entity.h coordinates.h message_structures.h shoot_rocket.h object.h array.h material.h list_template.h
    169171all: all-am
    170172
     
    240242@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/command_node.Po@am__quote@
    241243@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/data_tank.Po@am__quote@
     244@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/environment.Po@am__quote@
    242245@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/game_loader.Po@am__quote@
    243246@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ini_parser.Po@am__quote@
    244247@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keynames.Po@am__quote@
     248@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
    245249@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/material.Po@am__quote@
    246250@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/object.Po@am__quote@
  • orxonox/trunk/src/campaign.cc

    r2636 r2816  
    2727Campaign::Campaign ()
    2828{
    29   this->entities = new List<StoryEntity>();
     29  this->entities = new ListTemplate<StoryEntity>();
    3030  this->isInit = false;
    3131}
     
    144144StoryEntity* Campaign::getStoryEntity(Uint32 storyID)
    145145{
    146   List<StoryEntity>* l;
     146  ListTemplate<StoryEntity>* l;
    147147  StoryEntity* entity;
    148148  l = this->entities->get_next(); 
  • orxonox/trunk/src/campaign.h

    r2636 r2816  
    3333
    3434 private:
    35   List<StoryEntity>* entities;
     35  ListTemplate<StoryEntity>* entities;
    3636  bool running;
    3737
  • orxonox/trunk/src/command_node.cc

    r2636 r2816  
    1111   ### File Specific:
    1212   main-programmer: Christian Meyer
    13    co-programmer: ...
     13   co-programmer: Patrick Boenzli
    1414*/
    1515
     
    3333CommandNode::CommandNode (int ID)
    3434{
    35   bound = new List<WorldEntity>();
     35  bound = new List();
    3636  aliases = NULL;
    3737  netID = ID;
     
    4848  bLocalInput = true;
    4949  netID = 0;
    50   bound = new List<WorldEntity>();
     50  bound = new List();
    5151  load_bindings (filename);
    5252}
     
    5959  if( aliases != NULL) free (aliases);
    6060  if( bound != NULL) delete bound;
     61}
     62
     63
     64void CommandNode::reset()
     65{
     66  this->bound->clear();
    6167}
    6268
     
    123129void CommandNode::bind (WorldEntity* entity)
    124130{
    125   bound->add (entity, LIST_ADD_NEXT, true);
     131  bound->add (entity);
    126132}
    127133
     
    132138void CommandNode::unbind (WorldEntity* entity)
    133139{
    134   bound->remove (entity, LIST_FIND_FW);
     140  bound->remove (entity);
    135141}
    136142
     
    214220}
    215221
     222
    216223void CommandNode::process_network ()
    217224{
     
    219226}
    220227
     228
    221229void CommandNode::relay (Command* cmd)
    222230{
    223   //printf("CommandNode|relay()\n");
    224   List<WorldEntity>* plist = bound;
    225231 
    226232  Orxonox *orx = Orxonox::getInstance();
     
    231237  if( bLocalInput) send_over_network (cmd);
    232238 
    233   while( (plist = plist->get_next()) != NULL)
    234     {
    235       plist->get_object()->command (cmd);
    236     }
    237 }
     239  WorldEntity* entity = bound->enumerate();
     240  while(  entity != NULL)
     241    {
     242      entity->command (cmd);
     243      entity = bound->nextElement();
     244    }
     245}
     246
    238247
    239248/**
  • orxonox/trunk/src/command_node.h

    r2190 r2816  
    1919//! Key aliasing structure
    2020/**
    21         This structure contains the key aliasing information, e.g. the command strings that
    22         have been bound to the keys.
     21   This structure contains the key aliasing information, e.g. the command strings that
     22   have been bound to the keys.
    2323*/
    2424typedef struct
    2525{
    26         char keys[N_STD_KEYS][CMD_LENGHT];
    27         char buttons[N_BUTTONS][CMD_LENGHT];
     26  char keys[N_STD_KEYS][CMD_LENGHT];
     27  char buttons[N_BUTTONS][CMD_LENGHT];
    2828} KeyBindings;
    2929
    3030//! Command Node
    3131/**
    32         This class gathers all incoming SDL_Events and processes them. Keyboard, mouse and joystick input is
    33         captured and translated into command messages which are passed down to the bound WorldEntities (via WorldEntity::command()).
    34         Other SDL_Events are passed to Orxonox::event_handler() to deal with them. If the CommandNode has been created
    35         with bLocalInput set to false, it will query the network class for incoming commands that match his netID and pass
    36         them on to it's WorldEntities.
     32   This class gathers all incoming SDL_Events and processes them. Keyboard, mouse and joystick input is
     33   captured and translated into command messages which are passed down to the bound WorldEntities (via WorldEntity::command()).
     34   Other SDL_Events are passed to Orxonox::event_handler() to deal with them. If the CommandNode has been created
     35   with bLocalInput set to false, it will query the network class for incoming commands that match his netID and pass
     36   them on to it's WorldEntities.
    3737*/
    3838class CommandNode {
    3939 private:
    40         bool bLocalInput;       //!< Identifies the CommandNode that processes local input
    41         int netID;      //!< Unique identifier that is used to determine between remote CommandNodes
    42         KeyBindings* aliases;
    43         List<WorldEntity>* bound;       //!< List of WorldEntites that recieve commands from this CommandNode
    44         Sint32 coord[2];
    45        
    46         void relay (Command* cmd);
    47         int* name_to_index (char* name);
    48         void process_local ();
    49         void process_network ();
    50         void send_over_network (Command* cmd);
    51        
     40  bool bLocalInput;     //!< Identifies the CommandNode that processes local input
     41  int netID;    //!< Unique identifier that is used to determine between remote CommandNodes
     42  KeyBindings* aliases;
     43  List* bound;  //!< List of WorldEntites that recieve commands from this CommandNode
     44  Sint32 coord[2];
     45 
     46
     47  void relay (Command* cmd);
     48  int* name_to_index (char* name);
     49  void process_local ();
     50  void process_network ();
     51  void send_over_network (Command* cmd);
     52 
    5253 public:
    5354  CommandNode (int ID);
    5455  CommandNode (char* filename);
    5556  ~CommandNode ();
    56  
     57
     58  void reset(); 
    5759  void load_bindings (char* filename);
    5860  void bind (WorldEntity* entity);
  • orxonox/trunk/src/environment.cc

    r2036 r2816  
    1616*/
    1717
    18 #include <iostream>
    19 #include <GL/glut.h>
    20 #include <stdlib.h>
    21 
    22 #include "data_tank.h"
    2318
    2419#include "environment.h"
     20#include "stdincl.h"
     21#include "world_entity.h"
     22#include "vector.h"
    2523
    2624using namespace std;
     
    3028#define LEVEL_LENGTH 500
    3129
    32 Environment::Environment ()
    33   : WorldEntity()
     30Environment::Environment () : WorldEntity()
    3431{
    3532
     
    6057Environment::~Environment () {}
    6158
     59void Environment::tick (float time) {}
    6260
     61void Environment::hit (WorldEntity* weapon, Vector loc) {}
     62
     63void Environment::destroy () {}
     64
     65void Environment::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags) {}
     66
     67void Environment::draw ()
     68{
     69  printf("Environment::draw()");
     70
     71  glMatrixMode(GL_MODELVIEW);
     72  glLoadIdentity();
     73  float matrix[4][4];
     74 
     75  glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
     76  get_placement()->w.matrix (matrix);
     77  glMultMatrixf ((float*)matrix);
     78
     79  glBegin(GL_TRIANGLES);
     80  glColor3f(1,1,1);
     81  glVertex3f(0,0,0.5);
     82  glVertex3f(-0.5,0,-1);
     83  glVertex3f(0.5,0,-1);
     84 
     85  glVertex3f(0,0,0.5);
     86  glVertex3f(0,0.5,-1);
     87  glVertex3f(0,-0.5,-1);
     88  glEnd();
     89   
     90  glBegin(GL_QUADS);
     91  glColor3f(0,0,1);
     92  glVertex3f(0.5,0.5,-1);
     93  glVertex3f(0.5,-0.5,-1);
     94  glVertex3f(-0.5,-0.5,-1);
     95  glVertex3f(-0.5,0.5,-1);
     96  glEnd();
     97}
     98
     99/*
    63100void Environment::paint()
    64101{
    65   /*
     102 
    66103  glPushMatrix();
    67104  //glScalef(0.5, 0.5, 1.0);
     
    95132 
    96133  glPopMatrix();
    97   */
     134 
    98135}
    99136
     
    103140}
    104141
     142*/
  • orxonox/trunk/src/environment.h

    r2036 r2816  
    1 
    2 
    3 
    41#ifndef ENVIRONEMENT_H
    52#define ENVIRONEMENT_H
    63
    7 
    84#include "world_entity.h"
    95
    10 class Environment : public WorldEntity {
     6
     7class Environment : public WorldEntity
     8{
     9  friend class World;
    1110
    1211 private:
     
    2120  ~Environment ();
    2221
    23   void paint(void);
    24   void drawEnvironment(void);
    25   void setEnvPosition(void);
    26   void getEnvPosition(void);
     22 
     23  virtual void tick (float time);
     24  virtual void hit (WorldEntity* weapon, Vector loc);
     25  virtual void destroy ();
     26  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
     27  virtual void draw ();
    2728
    2829};
  • orxonox/trunk/src/list.h

    r2636 r2816  
    1 /*
    2    orxonox - the future of 3D-vertical-scrollers
    3 
    4    Copyright (C) 2004 orx
    5 
    6    This program is free software; you can redistribute it and/or modify
    7    it under the terms of the GNU General Public License as published by
    8    the Free Software Foundation; either version 2, or (at your option)
    9    any later version.
    10 
    11    ### File Specific:
    12    main-programmer: Christian Meyer
    13 
    14    ADDONS/FIXES:
    15  
    16    Patrick Boenzli     :          Implemented getSize() function
    17 */
    18 
    19 
    20 /*!
    21   \file list.h
    22   \brief Contains a template for a doubly linked list
    23 */
    241
    252#ifndef LIST_H
    263#define LIST_H
    274
    28 #include "stdlib.h"
     5#include "stdincl.h"
    296
    307//! An enum to list all the modes available when adding an object to a List
    31 enum ADDMODE {LIST_ADD_NEXT, LIST_ADD_PREV, LIST_ADD_FIRST, LIST_ADD_LAST};
     8//enum ADDMODE {LIST_ADD_FIRST, LIST_ADD_LAST};
    329//! An enum to list the two searching directions available when removing an object from a List
    33 enum FINDMODE {LIST_FIND_BW, LIST_FIND_FW};
     10//enum FINDMODE {LIST_FIND_BW, LIST_FIND_FW};
    3411
    35 //! A generic doubly linked list
    36 template<class T> class List
    37 {
    38   T* object;
    39   List<T>* next;
    40   List<T>* prev;
    41   bool bReference;
    42   int size;
    43  
     12
     13
     14class WorldEntity;
     15
     16class List {
     17
    4418 public:
    45   List (T* obj, List<T>* n, List<T>* p, bool bRef);
     19  List ();
    4620  ~List ();
    47  
    48   int add (T* obj, ADDMODE mode, bool bRef);
    49   T* get_object();
    50   List<T>* get_next ();
    51   List<T>* get_previous ();
    52   List<T>* get_last ();
    53   List<T>* get_first ();
    54   void set_next (List<T>* ptr);
    55   void set_prev (List<T>* ptr);
    56   int remove (T* obj, FINDMODE mode);
     21
     22  void add(WorldEntity* entity);
     23  void remove(WorldEntity* entity);
     24  void clear();
     25  WorldEntity* firstElement();
     26  bool isEmpty();
    5727  int getSize();
     28  WorldEntity* enumerate();
     29  WorldEntity* nextElement();
     30  WorldEntity* toArray();
     31  void debug();
     32
     33 private:
     34  struct listElement
     35  {
     36    listElement* prev;
     37    WorldEntity* curr;
     38    listElement* next;
     39  };
     40  Uint32 size;
     41  listElement* first;
     42  listElement* last;
     43  listElement* currentEl;
     44
     45
    5846};
    5947
     48class Iterator
     49{
    6050
    61 /**
    62   \brief Standard constructor
    63  
    64   Call this without any parameters to generate a new List which can be filled with content.
    65   DO NOT create a List element that contains an object on your own, you'll lose the data
    66   contained in that object and will have trouble removing the list from your memory.
    67 */
    68 template<class T>
    69 List<T>::List (T* obj = NULL, List<T>* n = NULL, List<T>* p = NULL, bool bRef = false)
    70 {
    71   object = obj;
    72   next = n;
    73   prev = p;
    74   bReference = bRef;
    75   if(obj != NULL)
    76     ++size;
    77 }
     51 public:
     52  bool hasNext();
     53  WorldEntity* next();
    7854
    79 /**
    80   \brief Standard destructor
    81  
    82   Call this on the initially generated base List element to remove the whole List from the memory.
    83   You can safely do this to any List element you want without messing up the rest of the List, but keep in mind
    84   that the contained object will be deleted as well when bRef had been set to false.
    85 */
    86 template<class T>
    87 List<T>::~List ()
    88 {
    89   if (object == NULL) // deleted foot node => disband the list
    90   {
    91     while( next != NULL)
    92     {
    93       delete next;
    94     }
    95     while( prev != NULL)
    96     {
    97       delete prev;
    98     }
    99   }
    100   else
    101   {
    102     if (prev != NULL) prev->set_next (next);
    103     if (next != NULL) next->set_prev (prev);
    104     if (!bReference) delete object;
    105   }
    106 }
    107  
    108 /**
    109   \brief Add an object to the List
    110   \param obj: A pointer to an allocated object
    111   \param mode: A Value of ADDMODE (default: LIST_ADD_NEXT)
    112   \param bRef: Sets whether the element is serving as a storage point or a simple listing (default: false)
    113   \return 0 if the operation succeded, -1 if the element could not be added
    114  
    115   This adds a new List element to the chain. The mode parameter can be used to specify
    116   the location where the element should be added. LIST_ADD_NEXT will add the new element directly
    117   after the base element. LIST_ADD_PREV will add the new element directly before the base element.
    118   LIST_ADD_FIRST will add the element at the beginning of the List whereas LIST_ADD_LAST will add
    119   it to the end of the chain. If the bRef parameter is set to true, the object pointer will not be deleted
    120   when the element containing that object is deleted, thus the List can be used for temporary listings as
    121   well as permanent data storage.
    122 */
    123 template<class T>
    124 int List<T>::add (T* obj, ADDMODE mode = LIST_ADD_NEXT, bool bRef = false)
    125 {
    126   List<T>* p;
    127   if( obj == NULL) return -1;
    128   switch (mode)
    129   {
    130     case LIST_ADD_NEXT:
    131       p = new List<T>( obj, next, this, bRef);
    132       if( next != NULL) next->set_prev (p);
    133       next = p;
    134       break;
    135     case LIST_ADD_PREV:
    136       p = new List<T>( obj, this, prev, bRef);
    137       if( prev != NULL) prev->set_next (p);
    138       prev = p;
    139       break;
    140     case LIST_ADD_FIRST:
    141       if (prev == NULL) prev = new List<T> (obj, this, NULL, bRef);
    142       else return prev->add (obj, mode, bRef);
    143       break;
    144     case LIST_ADD_LAST:
    145       if (next == NULL) next = new List<T> (obj, NULL, this, bRef);
    146       else return next->add (obj, mode, bRef);
    147       break;
    148     default:
    149         return -1;
    150       break;
    151   }
    152   ++size;
    153   return 0;
    154 }
     55 private:
    15556
    156 /**
    157   \brief Get the next element of the List
    158   \return The List element after the current List element
    159 */
    160 template<class T>
    161 List<T>* List<T>::get_next ()
    162 {
    163   return next;
    164 }
    165  
    166 /**
    167   \brief Get the previous element of the List
    168   \return The List element before the current List element
    169 */
    170 template<class T>
    171 List<T>* List<T>::get_previous ()
    172 {
    173   return prev;
    174 }
    175 
    176 /**
    177   \brief Get the last element of the List
    178   \return The last List element
    179 */
    180 template<class T>
    181 List<T>* List<T>::get_last ()
    182 {
    183   if (next == NULL) return this;
    184   else return next->get_last();
    185 }
    186 
    187 /**
    188   \brief Get the first element of the List
    189   \return The first List element
    190 */
    191 template<class T>
    192 List<T>* List<T>::get_first ()
    193 {
    194   if (prev == NULL) return this;
    195   else return prev->get_first();
    196 }
    197 
    198 /**
    199   \brief Removes a certain element from the List
    200   \param obj: A pointer to the object that should be removed
    201   \param mode: A value of FINDMODE
    202   \return 0 if the element was found and removed, -1 if the element was not found
    203  
    204   This searches the part of the List specified with mode for the object in question.
    205   When the object is found it is deleted and the List element is removed from the chain.
    206   If mode is LIST_FIND_FW all elements AFTER the base element are searched, if mode is
    207   LIST_FIND_BW all elements BEFORE the base element are searched. Note that the object
    208   contained within the List element is NOT deleted when bRef was set to true.
    209 */
    210 template<class T>
    211 int List<T>::remove (T* obj, FINDMODE mode = LIST_FIND_FW)
    212 {
    213   if (obj == NULL) return -1;
    214   else
    215   {
    216     switch (mode)
    217     {
    218       case LIST_FIND_BW:
    219         if (prev == NULL) return -1;
    220         else
    221         {
    222           if( prev->get_object() == obj)
    223           {
    224             delete prev;
    225           }
    226           else
    227           {
    228             return prev->remove( obj, mode);
    229           }
    230         }
    231         break;
    232       case LIST_FIND_FW:
    233         if (next == NULL) return -1;
    234         else
    235         {
    236           if( next->get_object() == obj)
    237           {
    238             delete next;
    239           }
    240           else
    241           {
    242             return next->remove( obj, mode);
    243           }
    244         }
    245         break;
    246       default:
    247         return -1;
    248     }
    249   }
    250   --size;
    251   return 0;
    252 }
    253 
    254 /**
    255   \brief Set the next element of a List element
    256   \param ptr: A pointer to the new next element
    257    
    258   Sets the next element of a List element... Better not touch this, it can really mess up a List.
    259 */
    260 template<class T>
    261 void List<T>::set_next (List<T>* ptr)
    262 {
    263   next = ptr;
    264 }
    265 
    266 /**
    267   \brief Set the prev element of a List element
    268   \param ptr: A pointer to the new previous element
    269    
    270   Sets the previous element of a List element... Better not touch this, it can really mess up a List.
    271 */
    272 template<class T>
    273 void List<T>::set_prev (List<T>* ptr)
    274 {
    275   prev = ptr;
    276 }
    277 
    278 /**
    279   \brief Get the pointer to the object the element is containing
    280   \return The contained object (will be NULL if called on the base element).
    281 */
    282 template<class T>
    283 T* List<T>::get_object()
    284 {
    285   return object;
    286 }
    287 
    288 
    289 /**
    290   \brief Returns the current size of the List
    291   \return Size of List
    292 */
    293 template<class T>
    294 int List<T>::getSize()
    295 {
    296   return this->size;
    297 }
     57};
    29858
    29959#endif
    300 
  • orxonox/trunk/src/player.cc

    r2811 r2816  
    6161void Player::post_spawn ()
    6262{
    63         travel_speed = 15.0;
    64         velocity = Vector();
    65         bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
    66         bFire = false;
    67         acceleration = 10.0;
    68         set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
     63  travel_speed = 15.0;
     64  velocity = Vector();
     65  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
     66  bFire = false;
     67  acceleration = 10.0;
     68  set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
    6969}
    7070
     
    112112  //  glCallList (objectList);
    113113
     114 
    114115 
    115116  //printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
  • orxonox/trunk/src/stdincl.h

    r2636 r2816  
    1515#include "coordinates.h"
    1616#include "list.h"
     17#include "list_template.h"
    1718#include "error.h"
    1819#include "message_structures.h"
  • orxonox/trunk/src/vector.cc

    r2551 r2816  
    3333{
    3434  Vector r;
    35  
     35
    3636  r.x = x + v.x;
    3737  r.y = y + v.y;
  • 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}
  • orxonox/trunk/src/world.h

    r2731 r2816  
    4949  bool system_command (Command* cmd);
    5050  Camera* getCamera();
    51   //private:
    5251
    5352  void spawn(WorldEntity* entity);
     53  void spawn(WorldEntity* entity, Location* loc);
     54  void spawn(WorldEntity* entity, Placement* plc);
    5455
    55   List<WorldEntity>* entities;
     56  List* entities;
    5657 
    5758  // base level data
Note: See TracChangeset for help on using the changeset viewer.