Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8036 in orxonox.OLD for branches/network/src/world_entities


Ignore:
Timestamp:
May 31, 2006, 4:33:31 PM (18 years ago)
Author:
patrick
Message:

cr: network spawning points implemented and new group introduced

Location:
branches/network/src/world_entities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/spawning_point.cc

    r7357 r8036  
    2020#include "util/loading/factory.h"
    2121
     22#include "world_entity.h"
     23
    2224#include "compiler.h"
     25
     26#include <map>
    2327
    2428
     
    2630 *  constructor
    2731 */
    28 SpawningPoint::SpawningPoint (ClassID classID, const Vector& position)
     32SpawningPoint::SpawningPoint (ClassID classid, const Vector& position)
    2933{
    3034  this->setAbsCoor(position);
    31   this->classID = classID;
     35  this->classid = classid;
    3236  this->mode = SPT_ALL_AT_ONCE;
    3337  this->delay = 0;
     
    4044 *  standard constructor
    4145 */
    42 SpawningPoint::SpawningPoint (const Vector& position, ClassID classID, SpawningPointMode mode, float delay)
     46SpawningPoint::SpawningPoint (const Vector& position, ClassID classid, SpawningPointMode mode, float delay)
    4347{
    4448  this->setAbsCoor(position);
    45   this->classID = classID;
     49  this->classid = classid;
    4650  this->mode = mode;
    4751  this->delay = delay;
     
    9094
    9195
     96
     97/**
     98 * pushes a world entity to the spawning queue
     99 *  @param entity WorldEntity to be added
     100 */
     101void SpawningPoint::pushEntity(WorldEntity* entity, float delay)
     102{
     103  this->queue[entity] = this->localTimer + delay;
     104}
     105
     106
    92107/**
    93108 *  spawn the entity
    94109 */
    95 void SpawningPoint::spawn()
     110void SpawningPoint::spawn(WorldEntity* entity)
    96111{
    97   PRINTF(5)("Spangingpoint creates a new Entity (id: %i, delay: %f, mode: %f)\n", this->classID,
    98             this->delay, this->mode);
     112  PRINTF(1)("Spawningpoint spawns new Entity (%s)\n", entity->getClassName());
     113
    99114
    100115  //BaseObject* spawningEntity = Factory::fabricate(this->classID);
    101 
    102 //   if( likely(this->world != NULL))
    103 //     this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity));
     116  //   if( likely(this->world != NULL))
     117  //     this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity));
    104118}
    105119
     
    114128{
    115129  this->localTimer += dt;
    116   if( this->localTimer > this->delay)
     130
     131  std::map<WorldEntity*, float>::iterator it = this->queue.begin();
     132  for( ; it != this->queue.end(); it++)
    117133  {
    118     this->spawn();
    119     this->localTimer = 0.0f;
     134    //
     135    if( it->second <= this->localTimer)
     136    {
     137      //spawn the player
     138      this->spawn(it->first);
     139    }
    120140  }
     141
    121142}
    122143
  • branches/network/src/world_entities/spawning_point.h

    r7370 r8036  
    99
    1010#include "world_entity.h"
     11
     12#include <map>
    1113
    1214class World;
     
    4345
    4446    /**  sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */
    45     void SpawningPoint::setSpawningEntity(ClassID classID) { this->classID = classID; }
     47    void SpawningPoint::setSpawningEntity(ClassID classid) { this->classid = classid; }
    4648    /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */
    4749    void SpawningPoint::setSpawningDelay(float delay) { this->delay = delay; }
     
    4951    void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; }
    5052
     53    void pushEntity(WorldEntity* entity, float delay = 0);
    5154
    5255    /** activates the spawning point */
    53     void activate() { this->bSpawning = true; }
     56    inline void activate() { this->bSpawning = true; }
    5457    /** deactivates the spawning point */
    55     void deactivate() { this->bSpawning = false; }
     58    inline void deactivate() { this->bSpawning = false; }
     59    inline bool isActive() const { return this->bSpawning; }
    5660
    5761
     
    6165
    6266  private:
    63     void spawn();
     67    void spawn(WorldEntity* entity);
    6468
    6569
    6670  private:
    67     float                     delay;                          //!< the timer that counts down until the next spawn
    68     float                     localTimer;                     //!< the local timer
    69     float                     seed;                           //!< the random seed of the position
    70     ClassID                   classID;                        //!< the classid of the entity to spawn
    71     SpawningPointMode         mode;                           //!< the mode of the spawning point
    72     ObjectManager::EntityList   queue;                          //!< queue of waiting WorldEntities to be spawned
    73     bool                      bSpawning;                      //!< flag to indicate if this spawning point is active or not
     71    float                           delay;                          //!< the timer that counts down until the next spawn
     72    float                           localTimer;                     //!< the local timer
     73    float                           seed;                           //!< the random seed of the position
     74    ClassID                         classid;                        //!< the classid of the entity to spawn
     75    SpawningPointMode               mode;                           //!< the mode of the spawning point
     76    std::map<WorldEntity*, float>   queue;                          //!< queue of waiting WorldEntities to be spawned
     77    bool                            bSpawning;                      //!< flag to indicate if this spawning point is active or not
    7478};
    7579
Note: See TracChangeset for help on using the changeset viewer.