Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8820 in orxonox.OLD for branches/multi_player_map


Ignore:
Timestamp:
Jun 27, 2006, 12:37:58 PM (18 years ago)
Author:
rennerc
Message:

started implementing message based spawningpoint synchronisation

Location:
branches/multi_player_map/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/multi_player_map/src/lib/network/message_manager.h

    r8708 r8820  
    3232  MSGID_PREFEREDTEAM,
    3333  MSGID_CHANGENICKNAME,
    34   MSGID_CHATMESSAGE
     34  MSGID_CHATMESSAGE,
     35  MSGID_RESPAWN
    3536};
    3637
  • branches/multi_player_map/src/world_entities/spawning_point.cc

    r8802 r8820  
    2727#include "game_rules.h"
    2828
     29#include "shared_network_data.h"
     30
     31CREATE_FACTORY( SpawningPoint, CL_SPAWNING_POINT );
    2932
    3033/**
     
    3437{
    3538  this->setAbsCoor(position);
    36   this->classid = classid;
    37   this->mode = SPT_ALL_AT_ONCE;
    38   this->delay = 0;
    3939
    4040  this->init();
     
    4848{
    4949  this->setAbsCoor(position);
    50   this->classid = classid;
    51   this->mode = mode;
    52   this->delay = delay;
    5350
    5451  this->init();
     
    5653
    5754
     55SpawningPoint::SpawningPoint( const TiXmlElement * root )
     56{
     57  this->setAbsCoor( 0, 0, 0 );
     58
     59  this->init();
     60 
     61  if (root != NULL)
     62    this->loadParams(root);
     63}
    5864
    5965void SpawningPoint::init()
    6066{
    6167  this->setClassID(CL_SPAWNING_POINT, "SpawningPoint");
     68  PRINTF(0)("Created SpawningPoint\n");
    6269 
    6370  this->teamId = -1;
     71 
     72  MessageManager::getInstance()->registerMessageHandler( MSGID_RESPAWN, respawnMessageHandler, NULL );
    6473}
    6574
     
    8190  WorldEntity::loadParams(root);
    8291
    83   /* now load the frequency */
    84   LoadParam(root, "delay", this, SpawningPoint, setSpawningDelay)
    85       .describe("sets the delay of the spawning point");
    86      
    8792  /* load teamId */
    8893  LoadParam(root, "teamId", this, SpawningPoint, setTeamId)
    8994      .describe("sets teamId");
    90 
    91 
    92   /* now load the seed */
    93 //   LoadParam(root, "entity", this, SpawningPoint, setSpawningEntity)
    94 //       .describe("sets the spawning entity");
    95 
    96   /* now load the seed */
    97 /*  LoadParam(root, "classid", this, SpawningPoint, setSpawningEntity)
    98       .describe("sets the class id of the entity to spawn")
    99       .defaultValues(CL_WORLD_ENTITY);*/
    10095}
    10196
     
    110105  QueueEntry qe;
    111106  qe.entity = entity;
    112   qe.list = entity->getOMListNumber();
    113107  qe.respawnTime = this->localTimer + delay;
    114108 
     
    129123 
    130124  //TODO set camera (not smooth)
     125 
     126  if ( State::getGameRules() )
     127  {
     128    (State::getGameRules())->registerSpawn( entity );
     129  }
    131130}
    132131
     
    151150      this->spawn(it->entity);
    152151     
    153       it->entity->toList( it->list );
    154      
    155       if ( State::getGameRules() )
    156       {
    157         (State::getGameRules())->registerSpawn( it->entity );
    158       }
    159      
     152      if ( SharedNetworkData::getInstance()->isGameServer() )
     153        this->sendRespawnMessage( it->entity->getUniqueID() );
     154
    160155      std::list<QueueEntry>::iterator delit = it;
    161156      it++;
     
    179174 */
    180175void SpawningPoint::draw()
    181 {}
     176{
     177}
     178
     179void SpawningPoint::sendRespawnMessage( int uniqueId )
     180{
     181  byte * buf = new byte[2*INTSIZE];
     182 
     183  assert( Converter::intToByteArray( this->getUniqueID(), buf, INTSIZE ) == INTSIZE );
     184  assert( Converter::intToByteArray( uniqueId, buf + INTSIZE, INTSIZE ) == INTSIZE );
     185 
     186  MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     187}
     188
     189bool SpawningPoint::respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     190{
     191  if ( SharedNetworkData::getInstance()->isGameServer() )
     192  {
     193    PRINTF(2)("server received spawn message!\n");
     194    return true;
     195  }
     196   
     197  int spUniqueId;
     198  int uniqueId;
     199 
     200  if ( dataLength != 2*INTSIZE )
     201  {
     202    PRINTF(2)("spawn message has wrong size: %d\n", dataLength );
     203    return true;
     204  }
     205 
     206  assert( Converter::byteArrayToInt( data, &spUniqueId ) == INTSIZE );
     207  assert( Converter::byteArrayToInt( data+INTSIZE, &uniqueId ) == INTSIZE );
     208 
     209  //TODO find Playable and SpawningPoint and spawn Playable
     210 
     211  return true;
     212}
     213
  • branches/multi_player_map/src/world_entities/spawning_point.h

    r8802 r8820  
    1010#include "playable.h"
    1111
     12#include "message_manager.h"
     13
    1214#include <list>
    1315
     
    1921  float respawnTime;
    2022  WorldEntity * entity;
    21   OM_LIST list;
    2223};
    2324
     
    4344
    4445  public:
    45     SpawningPoint (ClassID classID, const Vector& position = Vector(0.0, 0.0, 0.0));
    46     SpawningPoint (const Vector& position, ClassID classID, SpawningPointMode type, float delay);
     46    SpawningPoint(const TiXmlElement* root = NULL);
     47    SpawningPoint(ClassID classID, const Vector& position = Vector(0.0, 0.0, 0.0));
     48    SpawningPoint(const Vector& position, ClassID classID, SpawningPointMode type, float delay);
    4749    virtual ~SpawningPoint ();
    4850    void init();
     
    5052    virtual void loadParams(const TiXmlElement* root);
    5153
    52     /**  sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */
    53     void SpawningPoint::setSpawningEntity(ClassID classid) { this->classid = classid; }
    54     /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */
    55     void SpawningPoint::setSpawningDelay(float delay) { this->delay = delay; }
    56     /** sets the spawning point mode @param mode: the mode */
    57     void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; }
    58    
    5954    inline int getTeamId(){ return this->teamId; }
    6055    inline void setTeamId( int teamId ){ this->teamId = teamId; }
     
    7570  private:
    7671    void spawn(WorldEntity* entity);
     72   
     73    void sendRespawnMessage( int uniqueId );
     74    static bool respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    7775
    7876
    7977  private:
    80     float                           delay;                          //!< the timer that counts down until the next spawn
    8178    float                           localTimer;                     //!< the local timer
    82     float                           seed;                           //!< the random seed of the position
    8379    int                             teamId;                         //!< only spawn players of this team
    84     ClassID                         classid;                        //!< the classid of the entity to spawn
    85     SpawningPointMode               mode;                           //!< the mode of the spawning point
    8680    std::list<QueueEntry>           queue;                          //!< queue of waiting WorldEntities to be spawned
    8781    bool                            bSpawning;                      //!< flag to indicate if this spawning point is active or not
Note: See TracChangeset for help on using the changeset viewer.