Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3620 in orxonox.OLD


Ignore:
Timestamp:
Mar 21, 2005, 5:37:58 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: added worldinterface, to enable all worldentities to access the entities list. so they can add entities themselfes. this is a nice hack

Location:
orxonox/trunk/src
Files:
7 edited

Legend:

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

    r3614 r3620  
    2020
    2121#include "orxonox.h"
     22
    2223#include "p_node.h"
    2324#include "null_parent.h"
     
    3334#include "terrain.h"
    3435#include "light.h"
     36
    3537#include "command_node.h"
    3638#include "glmenu_imagescreen.h"
     
    4143
    4244using namespace std;
     45
     46
     47WorldInterface* WorldInterface::singletonRef = 0;
     48
     49
     50/**
     51   \brief private constructor because of singleton
     52*/
     53WorldInterface::WorldInterface()
     54{
     55  this->worldIsInitialized = false;
     56  this->worldReference = NULL;
     57}
     58
     59/**
     60   \brief public deconstructor
     61*/
     62WorldInterface::~WorldInterface()
     63{
     64  this->singletonRef = NULL;
     65  this->worldIsInitialized = false;
     66  this->worldReference = NULL;
     67}
     68
     69/**
     70   \brief gets the singleton instance
     71   \returns singleton instance
     72*/
     73WorldInterface* WorldInterface::getInstance()
     74{
     75  if( singletonRef == NULL)
     76    singletonRef = new WorldInterface();
     77  return singletonRef;
     78}
     79
     80
     81/**
     82   \brief initializes the interface
     83   \param reference to the world
     84
     85   if the worldinterface is not initilizes, there wont be any
     86   useable interface
     87*/
     88void WorldInterface::init(World* world)
     89{
     90  this->worldReference = world;
     91  if( world!= NULL)
     92    {
     93      this->worldIsInitialized = true;
     94      PRINTF(3)("WorldInterface up and running\n");
     95    }
     96}
     97
     98
     99/**
     100   \brief gets the entity list from the world
     101   \return entity list
     102*/
     103tList<WorldEntity>* WorldInterface::getEntityList()
     104{
     105  if( this->worldIsInitialized)
     106    return this->worldReference->getEntities();
     107  PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n");
     108  return NULL;
     109}
     110
    43111
    44112
     
    76144  cn->reset();
    77145
     146  delete WorldInterface::getInstance();
     147
    78148  delete this->nullParent;
    79149  delete this->entities;
     
    89159  this->setClassName ("World");
    90160
     161
    91162  this->worldName = name;
    92163  this->debugWorldNr = worldID;
    93164  this->entities = new tList<WorldEntity>();
     165
     166  /* init the world interface */
     167  WorldInterface* wi = WorldInterface::getInstance();
     168  wi->init(this);
    94169
    95170  // Enable default GL stuff
     
    406481  SDL_Delay(500);
    407482  PRINTF(3)("World::releaseLoadScreen - end\n");
     483}
     484
     485
     486/**
     487   \brief gets the list of entities from the world
     488   \returns entity list
     489*/
     490tList<WorldEntity>* World::getEntities()
     491{
     492  return this->entities;
    408493}
    409494
  • orxonox/trunk/src/story_entities/world.h

    r3608 r3620  
    1212#include "p_node.h"
    1313
     14
     15class World;
     16class WorldEntity;
     17
     18//! The game world Interface
     19/**
     20   this is a singleton interface, that enables world_entities to access the
     21   world. for those objects, there is no easier way than over this interface!
     22*/
     23class WorldInterface : BaseObject {
     24
     25 public:
     26  ~WorldInterface();
     27  static WorldInterface* getInstance();
     28  void init(World* world);
     29  tList<WorldEntity>* getEntityList();
     30
     31 private:
     32  WorldInterface();
     33  static WorldInterface* singletonRef;    //!< singleton reference to this object
     34  bool worldIsInitialized;                //!< true if the world has been initialized
     35  World* worldReference;                  //!< this is a reference to the running world
     36
     37};
     38
     39
    1440class TrackManager;
    15 class WorldEntity;
    1641class Camera;
    1742class PNode;
     
    5075  /* command node functions */
    5176  bool command (Command* cmd);
     77
     78  tList<WorldEntity>* getEntities();
    5279
    5380  /* interface to world */
  • orxonox/trunk/src/world_entities/player.cc

    r3618 r3620  
    2020#include "player.h"
    2121
     22#include "track_manager.h"
     23#include "objModel.h"
     24#include "weapon.h"
     25#include "test_gun.h"
     26#include "world.h"
     27
     28#include "list.h"
    2229#include "stdincl.h"
    23 //#include "collision.h"
    24 #include "objModel.h"
    25 #include "list.h"
    26 #include "weapon.h"
    27 #include "track_manager.h"
    2830
    2931using namespace std;
     
    3335   \param isFree if the player is free
    3436*/
    35 Player::Player(bool isFree) : WorldEntity(isFree)
    36 {
    37   this->model = new OBJModel("../data/models/reaplow.obj");
     37Player::Player() : WorldEntity()
     38{
    3839  this->weapons = new tList<Weapon>();
    3940  this->activeWeapon = NULL;
    40 
     41  /*
     42    this is the debug player - actualy we would have to make a new
     43     class derivated from Player for each player. for now, we just use
     44     the player.cc for debug also
     45  */
     46  this->model = new OBJModel("../data/models/reaplow.obj");
    4147  travelSpeed = 15.0;
    4248  velocity = new Vector();
     
    4450  bFire = false;
    4551  acceleration = 10.0;
     52  //weapons:
     53  Weapon* wp = new TestGun();
     54  this->weapons->add(wp);
     55  this->activeWeapon = wp; 
    4656}
    4757
     
    5161Player::~Player ()
    5262{
    53   Weapon* w = this->weapons->enumerate();
    54   while( w != NULL)
    55     {
    56       delete w;
    57       w = this->weapons->nextElement();
    58     }
     63  /* do not delete the weapons, they are contained in the pnode tree
     64     and will be deleted there.
     65     this only frees the memory allocated to save the list.
     66  */
    5967  delete this->weapons;
    60  
    61   //delete this->velocity;
    6268}
    6369
     
    150156{
    151157  // player controlled movement
    152   this->move (time);
     158  this->move(time);
    153159  // weapon system manipulation
    154   this->fire();
     160  this->weapon();
    155161}
    156162
     
    190196   \brief weapon manipulation by the player
    191197*/
    192 void Player::fire()
     198void Player::weapon()
    193199{
    194200  if( this->bFire)
  • orxonox/trunk/src/world_entities/player.h

    r3608 r3620  
    1313class Weapon;
    1414class Vector;
     15class World;
    1516
    1617//! Basic controllable WorldEntity
     
    2021 
    2122 public:
    22   Player(bool isFree = false);
     23  Player();
    2324  virtual ~Player();
    2425
     
    4849  tList<Weapon>* weapons;//!< a list of weapon
    4950  Weapon* activeWeapon;  //!< the weapon that is currenty activated
     51  World* myWorld;        //!< reference to the world object
    5052
    5153  Vector* velocity;       //!< the velocity of the player.
     
    5456 
    5557  void move(float time);
    56   void fire(void);
     58  void weapon(void);
    5759 
    5860};
  • orxonox/trunk/src/world_entities/test_gun.cc

    r3618 r3620  
    7575*/
    7676void TestGun::fire()
    77 {}
     77{
     78  printf("TestGun::fire() - firing weapon now ---------------------------\n");
     79  //this->myWorld;
     80}
    7881
    7982
  • orxonox/trunk/src/world_entities/weapon.cc

    r3583 r3620  
    2323#include "objModel.h"
    2424#include "projectile.h"
     25#include "list.h"
     26#include "world.h"
    2527
    2628using namespace std;
     
    3335*/
    3436Weapon::Weapon () : WorldEntity()
    35 {}
     37{
     38  WorldInterface* wi = WorldInterface::getInstance();
     39  this->worldEntities = wi->getEntityList();
     40}
    3641
    3742
     
    174179*/
    175180void Weapon::fire()
    176 {}
     181{
     182 
     183}
    177184
    178185
  • orxonox/trunk/src/world_entities/weapon.h

    r3618 r3620  
    7676  Projectile* projectile;
    7777  //WeaponSound sound;
     78  tList<WorldEntity>* worldEntities;
    7879
    7980};
Note: See TracChangeset for help on using the changeset viewer.