Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1232


Ignore:
Timestamp:
May 5, 2008, 1:19:22 AM (16 years ago)
Author:
scheusso
Message:

a lot of changes in order to make it possible to have mulpiple clients with each one a new ship
camera changes
object changes
synchronisable: backsyncronisation should be possible now
gamestatemanager/gamestateclient: functions for backsyncronisation
some changes in order to get the input system (the old one) on the client working
TODO something with the camera position is wrong at the moment (clientside)

Location:
code/branches/network3/src
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network3/src/network/Client.cc

    r1199 r1232  
    4040
    4141#include "Client.h"
     42#include "Synchronisable.h"
    4243#include "core/CoreIncludes.h"
    4344
     
    4748 
    4849  Client* Client::createSingleton(){
    49     if(!_sClient)
     50    if(!_sClient){
    5051      _sClient = new Client();
     52    }
    5153    return _sClient;
    5254  }
     
    112114  */
    113115  bool Client::establishConnection(){
     116    Synchronisable::setClient(true);
    114117    isConnected=client_connection.createConnection();
     118    /*if(isConnected){
     119      COUT(2) << "sending connectrequest" << std::endl;
     120      client_connection.addPacket(pck_gen.generateConnectRequest());
     121      client_connection.sendPackets();
     122    }else
     123      COUT(2) << "could not create connection" << std::endl;*/
    115124    return isConnected;
    116125  }
     
    249258    COUT(0) << "Server: " << data->message << std::endl;
    250259  }
     260 
     261  bool Client::processWelcome( welcome *w ){
     262    COUT(4) << "processing welcome message" << std::endl;
     263    clientID_ = w->clientID;
     264    shipID_ = w->shipID;
     265   
     266  }
    251267
    252268}
  • code/branches/network3/src/network/Client.h

    r1184 r1232  
    8383
    8484    bool sendPackets();
     85   
     86    int getShipID(){return shipID_;}
     87    int getClientID(){return clientID_;}
    8588
    8689    void tick(float time);
     
    103106    void processClassid(classid *clid);
    104107    void processChat( chat *data);
     108    bool processWelcome( welcome *w );
     109    int clientID_;     // this is the id the server gave to us
     110    int shipID_;
    105111  };
    106112
  • code/branches/network3/src/network/ClientInformation.h

    r1168 r1232  
    6767    ClientInformation *insertBefore(ClientInformation *ins);
    6868    ClientInformation *insertBack(ClientInformation *ins);
     69   
     70    // set functions
    6971    void setID(int clientID);
    7072    void setPeer(ENetPeer *peer);
    7173    void setGamestateID(int id);
     74    inline void setShipID(int id){ShipID_=id;}
     75   
     76    // get functions
     77    inline int getShipID(){return ShipID_;}
    7278    int getID();
     79    int getGamestateID();
    7380    ENetPeer *getPeer();
    74     int getGamestateID();
     81   
     82   
    7583    bool removeClient(int clientID);
    7684    bool removeClient(ENetPeer *peer);
     
    92100    int clientID_;
    93101    int gamestateID_;
     102    int ShipID_;   // this is the unique objectID
    94103    bool synched_;
    95104  };
  • code/branches/network3/src/network/ConnectionManager.cc

    r1168 r1232  
    4444
    4545#include "core/CoreIncludes.h"
     46#include "core/BaseObject.h"
     47#include "util/Math.h"
     48#include "objects/SpaceShip.h"
    4649#include "ClientInformation.h"
    4750#include "ConnectionManager.h"
     51#include "Synchronisable.h"
    4852
    4953namespace std
     
    179183        case ENET_EVENT_TYPE_CONNECT:
    180184          addClient(&event);
     185          //this is a workaround to ensure thread safety
     186          if(!addFakeConnectRequest(&event))
     187            COUT(3) << "Problem pushing fakeconnectRequest to queue" << std::endl;
    181188          COUT(5) << "Con.Man: connection event has occured" << std::endl;
    182189          break;
     
    237244  }
    238245
    239   //bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
    240   //  return clientDisconnect(*peer);
    241   //}
    242 
    243246  bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
    244247    COUT(4) << "removing client from list" << std::endl;
     
    260263    temp->setPeer(event->peer);
    261264    COUT(4) << "Con.Man: added client id: " << temp->getID() << std::endl;
    262     syncClassid(temp->getID());
    263     temp->setSynched(true);
    264265    return true;
    265266  }
     
    298299  }
    299300
    300 
    301 
    302   void ConnectionManager::addClientsObjectID( int clientID, int objectID ) {
    303     COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl;
    304     clientsShip.insert( std::make_pair( clientID, objectID ) );
    305   }
     301  bool ConnectionManager::createClient(int clientID){
     302    ClientInformation *temp = head_->findClient(clientID);
     303    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
     304    syncClassid(temp->getID());
     305    COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl;
     306    // TODO: this is only a hack, untill we have a possibility to define default player-join actions
     307    createShip(temp);
     308    COUT(4) << "created spaceship" << std::endl;
     309    temp->setSynched(true);
     310    COUT(4) << "sending welcome" << std::endl;
     311    sendWelcome(temp->getID(), temp->getShipID(), true);
     312    return true;
     313  }
     314 
     315  bool ConnectionManager::createShip(ClientInformation *client){
     316    orxonox::Identifier* id = ID("SpaceShip");
     317    if(!id){
     318      COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl;
     319      return false;
     320    }
     321    orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());
     322    no->setPosition(orxonox::Vector3(0,80,0));
     323    no->setScale(10);
     324    no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0));
     325    no->setMesh("assf3.mesh");
     326    no->setMaxSpeed(500);
     327    no->setMaxSideAndBackSpeed(50);
     328    no->setMaxRotation(1.0);
     329    no->setTransAcc(200);
     330    no->setRotAcc(3.0);
     331    no->setTransDamp(75);
     332    no->setRotDamp(1.0);
     333    no->setCamera("cam_"+client->getID());
     334    no->create();
     335   
     336    client->setShipID(no->objectID);
     337    return true;
     338  }
     339 
     340  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
     341    addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID);
     342    sendPackets();
     343  }
     344 
     345  bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){
     346    ENetEvent event;
     347    event.peer=ev->peer;
     348    event.packet = packet_gen.generateConnectRequest();
     349    return buffer.push(&event);
     350  }
     351 
     352 
     353//   int ConnectionManager::getNumberOfClients() {
     354//     
     355//     return clientsShip.size();
     356//   }
     357 
     358  /*void ConnectionManager::addClientsObjectID( int clientID, int objectID ) {
     359  COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl;
     360  clientsShip.insert( std::make_pair( clientID, objectID ) );
     361}
    306362
    307363  int ConnectionManager::getClientsShipID( int clientID ) {
    308     return clientsShip[clientID];
    309   }
     364  return clientsShip[clientID];
     365}
    310366
    311367  int ConnectionManager::getObjectsClientID( int objectID ) {
    312     std::map<int, int>::iterator iter;
    313     for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
    314       if( iter->second == objectID ) return iter->first;
    315     }
    316     return -99;
    317   }
     368  std::map<int, int>::iterator iter;
     369  for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
     370  if( iter->second == objectID ) return iter->first;
     371}
     372  return -99;
     373}
    318374
    319375  void ConnectionManager::deleteClientIDReg( int clientID ) {
    320     clientsShip.erase( clientID );
    321   }
     376  clientsShip.erase( clientID );
     377}
    322378
    323379  void ConnectionManager::deleteObjectIDReg( int objectID ) {
    324     std::map<int, int>::iterator iter = clientsShip.begin();
    325     for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
    326       if( iter->second == objectID ) break;
    327     }
    328     clientsShip.erase( iter->first );
    329   }
    330   int ConnectionManager::getNumberOfClients() {
    331     return clientsShip.size();
    332   }
    333 }
     380  std::map<int, int>::iterator iter = clientsShip.begin();
     381  for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
     382  if( iter->second == objectID ) break;
     383}
     384  clientsShip.erase( iter->first );
     385}*/
     386}
  • code/branches/network3/src/network/ConnectionManager.h

    r1168 r1232  
    7171  class ConnectionManager{
    7272  public:
     73    ConnectionManager();
    7374    ConnectionManager(ClientInformation *head);
    7475    ConnectionManager(int port, const char *address, ClientInformation *head);
     
    8485    bool sendPackets(ENetEvent *event);
    8586    bool sendPackets();
     87    bool createClient(int clientID);
    8688
    87     //##### for testing purpose only #####
    88     ConnectionManager();
    89     std::map<int, int> testGetClientsShip() {
    90       return clientsShip;
    91     }
    92     void testAddClientsShipID( int clientID, int objectID ) {
    93       addClientsObjectID( clientID, objectID );
    94     }
    95     int testGetClientsShipID( int clientID ) {
    96       return getClientsShipID( clientID );
    97     }
    98     int testGetObjectsClientID( int objectID ) {
    99        return getObjectsClientID( objectID );
    100     }
    101     void testDeleteClientsIDReg( int clientID ) {
    102       deleteClientIDReg( clientID );
    103     }
    104     void testDeleteObjectIDReg( int objectID ) {
    105       deleteObjectIDReg( objectID );
    106     }
    107     //##### for testing purpose only #####
    10889  private:
    10990    bool clientDisconnect(ENetPeer *peer);
    110     //bool clientDisconnect(ENetPeer peer);
    11191    bool processData(ENetEvent *event);
    11292    bool addClient(ENetEvent *event);
     
    11797    void syncClassid(int clientID);
    11898    ENetPeer *getClientPeer(int clientID);
     99    bool createShip(ClientInformation *client);
     100    bool sendWelcome(int clientID, int shipID, bool allowed);
     101    bool addFakeConnectRequest(ENetEvent *ev);
    119102    PacketBuffer buffer;
    120103    PacketGenerator packet_gen;
     
    126109    ClientInformation *head_;
    127110
     111   
     112//     int getNumberOfClients();
    128113    //functions to map what object every clients uses
    129     std::map<int, int> clientsShip;
     114    /*std::map<int, int> clientsShip;
    130115    void addClientsObjectID( int clientID, int objectID );
    131116    int getClientsShipID( int clientID );
    132117    int getObjectsClientID( int objectID );
    133118    void deleteClientIDReg( int clientID );
    134     void deleteObjectIDReg( int objectID );
    135     int getNumberOfClients();
     119    void deleteObjectIDReg( int objectID );*/
    136120  };
    137121
  • code/branches/network3/src/network/GameStateClient.cc

    r1200 r1232  
    8686    return false;
    8787  }
     88 
     89  GameStateCompressed *GameStateClient::popPartialGameState(){
     90    GameState *gs = getPartialSnapshot();
     91    return compress_(gs);
     92  }
     93 
    8894
    8995  /**
     
    137143          }
    138144          Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate());
    139           COUT(4) << "loadsnapshort: classid: " << sync.classID << " objectID: " << sync.objectID << " length: " << sync.length << std::endl;
     145          COUT(4) << "loadsnapshot: classid: " << sync.classID << " objectID: " << sync.objectID << " length: " << sync.length << std::endl;
    140146          no->objectID=sync.objectID;
    141147          no->classID=sync.classID;
    142           it=orxonox::ObjectList<Synchronisable>::end();
    143148          // update data and create object/entity...
    144149          if( !no->updateData(sync) )
     
    146151          if( !no->create() )
    147152            COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl;
     153          it=orxonox::ObjectList<Synchronisable>::end();
    148154        }
    149155      } else {
     
    159165  }
    160166
     167  GameState *GameStateClient::getPartialSnapshot(){
     168    //std::cout << "begin getSnapshot" << std::endl;
     169    //the size of the gamestate
     170    int totalsize=0;
     171    int memsize=0;
     172    //the size of one specific synchronisable
     173    int tempsize=0;
     174    // get the start of the Synchronisable list
     175    orxonox::Iterator<Synchronisable> it;
     176    // struct for return value of Synchronisable::getData()
     177    syncData sync;
     178
     179    GameState *retval=new GameState; //return value
     180    retval->id=reference->id;
     181    retval->diffed=false;
     182    retval->complete=false;
     183    COUT(4) << "G.ST.Client: producing partial gamestate with id: " << retval->id << std::endl;
     184    // offset of memory functions
     185    int offset=0, size=0;
     186    // get total size of gamestate
     187    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     188      if(!it->getBacksync())
     189        continue;
     190      size+=it->getSize(); // size of the actual data of the synchronisable
     191      size+=3*sizeof(int); // size of datasize, classID and objectID
     192    }
     193    //retval->data = (unsigned char*)malloc(size);
     194    retval->data = new unsigned char[size];
     195    if(!retval->data){
     196      COUT(2) << "GameStateClient: could not allocate memory" << std::endl;
     197      return NULL;
     198    }
     199    memsize=size;
     200    // go through all Synchronisables
     201    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     202      if(!it->getBacksync())
     203        continue;
     204      //get size of the synchronisable
     205      tempsize=it->getSize();
     206      // add place for data and 3 ints (length,classid,objectid)
     207      totalsize+=tempsize+3*sizeof(int);
     208      // allocate+tempsize additional space
     209      if(totalsize > size){
     210        COUT(3) << "G.St.Cl: need additional memory" << std::endl;
     211      }
     212
     213      // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length)
     214      sync=it->getData((retval->data)+offset+3*sizeof(int));
     215      memcpy(retval->data+offset, (void *)&(sync.length), sizeof(int));
     216      memcpy(retval->data+offset+sizeof(int), (void *)&(sync.objectID), sizeof(int));
     217      memcpy(retval->data+offset+2*sizeof(int), (void *)&(sync.classID), sizeof(int));
     218      // increase data pointer
     219      offset+=tempsize+3*sizeof(int);
     220    }
     221    retval->size=totalsize;
     222    COUT(5) << "G.ST.Cl: Gamestate size: " << totalsize << std::endl;
     223    COUT(5) << "G.ST.Cl: 'estimated' Gamestate size: " << size << std::endl;
     224    return retval;
     225  }
     226 
     227 
    161228  GameState *GameStateClient::undiff(GameState *old, GameState *diff) {
     229    if(!old || !diff)
     230      return NULL;
    162231    unsigned char *ap = old->data, *bp = diff->data;
    163232    int of=0; // pointers offset
     
    195264    r->diffed = false;
    196265    r->data = dp;
     266    r->complete = true;
    197267    return r;
    198268  }
    199269
    200   //##### ADDED FOR TESTING PURPOSE #####
    201   GameState* GameStateClient::testDecompress( GameStateCompressed* gc ) {
    202     return decompress( gc );
    203   }
    204  
    205   GameState* GameStateClient::testUndiff( GameState* g_old, GameState* g_diffed ) {
    206     return undiff( g_old, g_diffed );
    207   }
    208   //##### ADDED FOR TESTING PURPOSE #####
    209 
     270
     271
     272  GameStateCompressed *GameStateClient::compress_(GameState *a) {
     273    if(!a)
     274      return NULL;
     275    int size = a->size;
     276
     277    uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
     278    unsigned char *dest = new unsigned char[buffer];
     279    int retval;
     280    retval = compress( dest, &buffer, a->data, (uLong)size );
     281
     282    switch ( retval ) {
     283      case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
     284      case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl;
     285      return NULL;
     286      case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
     287      return NULL;
     288      case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl;
     289      return NULL;
     290    }
     291
     292    GameStateCompressed *compressedGamestate = new GameStateCompressed;
     293    compressedGamestate->compsize = buffer;
     294    compressedGamestate->normsize = size;
     295    compressedGamestate->id = a->id;
     296    compressedGamestate->data = dest;
     297    compressedGamestate->diffed = a->diffed;
     298    compressedGamestate->complete = a->complete;
     299    compressedGamestate->base_id = a->base_id;
     300    delete[] a->data;
     301    delete a;
     302    return compressedGamestate;
     303  }
     304 
     305 
    210306  GameState *GameStateClient::decompress(GameStateCompressed *a) {
    211307    //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
     
    238334    gamestate->base_id = a->base_id;
    239335    gamestate->diffed = a->diffed;
     336    gamestate->complete = a->complete;
    240337
    241338    delete[] a->data; //delete compressed data
     
    286383  }
    287384 
     385 
     386    //##### ADDED FOR TESTING PURPOSE #####
     387  GameState* GameStateClient::testDecompress( GameStateCompressed* gc ) {
     388    return decompress( gc );
     389  }
     390 
     391  GameState* GameStateClient::testUndiff( GameState* g_old, GameState* g_diffed ) {
     392    return undiff( g_old, g_diffed );
     393  }
     394  //##### ADDED FOR TESTING PURPOSE #####
     395 
     396 
    288397}
     398
  • code/branches/network3/src/network/GameStateClient.h

    r1199 r1232  
    4242
    4343#include <map>
    44 
     44//
    4545#include "NetworkPrereqs.h"
    4646#include "core/CorePrereqs.h"
    4747#include "PacketTypes.h"
     48
    4849
    4950namespace network
     
    5455    GameStateClient();
    5556    ~GameStateClient();
    56     //#### ADDED FOR TESTING PURPOSE ####
    57     GameState* testDecompress( GameStateCompressed* gc );
    58     GameState* testUndiff( GameState* g_old, GameState* g_diffed );
    59     //#### END TESTING PURPOSE ####
     57   
    6058    bool pushGameState(GameStateCompressed *compstate);
     59    GameStateCompressed *popPartialGameState();
    6160  private:
    6261    bool loadSnapshot(GameState *state);
     62    GameState *getPartialSnapshot();
    6363    void cleanup();
    6464    GameState *undiff(GameState *old, GameState *diff);
     65    GameStateCompressed *compress_(GameState *a);
    6566    GameState *decompress(GameStateCompressed *a);
    6667    GameState *decode(GameState *old, GameStateCompressed *diff);
     
    7273    int           last_diff_;
    7374    std::map<int, GameState *> gameStateMap;
     75   
     76   
     77   
     78   
     79  public:
     80    //#### ADDED FOR TESTING PURPOSE ####
     81    GameState* testDecompress( GameStateCompressed* gc );
     82    GameState* testUndiff( GameState* g_old, GameState* g_diffed );
     83    //#### END TESTING PURPOSE ####
    7484  };
    7585
  • code/branches/network3/src/network/GameStateManager.cc

    r1200 r1232  
    4646
    4747#include "core/CoreIncludes.h"
     48#include "core/BaseObject.h"
    4849#include "ClientInformation.h"
    4950#include "Synchronisable.h"
     
    122123    }
    123124  }
     125 
     126  bool GameStateManager::pushGameState( GameStateCompressed *gs, int clientID ){
     127    GameState *ugs = decompress(gs);
     128    return loadPartialSnapshot(ugs, clientID);
     129   
     130  }
    124131
    125132  /**
     
    188195    //#### bugfix
    189196    retval->diffed = false;
     197    retval->complete = true;
    190198    //std::cout << "end snapShot" << std::endl;
    191199    COUT(5) << "G.ST.Man: Gamestate size: " << totalsize << std::endl;
     
    194202  }
    195203
     204  bool GameStateManager::loadPartialSnapshot(GameState *state, int clientID){
     205    unsigned char *data=state->data;
     206    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
     207    // get the start of the Synchronisable list
     208    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
     209    syncData sync;
     210    // loop as long as we have some data ;)
     211    while(data < state->data+state->size){
     212      // prepare the syncData struct
     213      sync.length = *(int *)data;
     214      data+=sizeof(int);
     215      sync.objectID = *(int*)data;
     216      data+=sizeof(int);
     217      sync.classID = *(int*)data;
     218      data+=sizeof(int);
     219      sync.data = data;
     220      data+=sync.length;
     221
     222      while(it && it->objectID!=sync.objectID)
     223        ++it;
     224
     225
     226      if(!it){
     227        // the object does not exist yet
     228        //COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
     229        orxonox::Identifier* id = ID((unsigned int)sync.classID);
     230        if(!id){
     231          COUT(4) << "We could not identify a new object; classid: " << sync.classID << std::endl;
     232          continue;
     233        }
     234        Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate());
     235        COUT(4) << "loadpartialsnapshot (generating new object): classid: " << sync.classID << " objectID: " << sync.objectID << " length: " << sync.length << std::endl;
     236        no->objectID=sync.objectID;
     237        no->classID=sync.classID;
     238        it=orxonox::ObjectList<Synchronisable>::end();
     239        // update data and create object/entity...
     240        if( !no->updateData(sync) )
     241          COUT(1) << "We couldn't update the object: " << sync.objectID << std::endl;
     242        if( !no->create() )
     243          COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl;
     244      }else{
     245        // we have our object
     246        if(checkAccess(clientID, sync.objectID)){
     247          if(! it->updateData(sync))
     248            COUT(1) << "We couldn't update objectID: " \
     249              << sync.objectID << "; classID: " << sync.classID << std::endl;
     250        }else
     251          COUT(4) << "loadPartialSnapshot: no access to change objectID: " << sync.objectID << std::endl;
     252      }
     253      ++it;
     254    }
     255
     256    return true;
     257  }
     258 
     259 
    196260  //##### ADDED FOR TESTING PURPOSE #####
    197261  GameStateCompressed* GameStateManager::testCompress( GameState* g ) {
     
    269333    r->base_id = a->id;
    270334    r->data = dp;
     335    r->complete = true;
    271336    return r;
    272337  }
     
    307372    compressedGamestate->data = dest;
    308373    compressedGamestate->diffed = a->diffed;
     374    compressedGamestate->complete = a->complete;
    309375    compressedGamestate->base_id = a->base_id;
    310376    //COUT(5) << "G.St.Man: saved compressed data in GameStateCompressed:" << std::endl;
    311377    return compressedGamestate;
    312378  }
     379 
     380  GameState *GameStateManager::decompress(GameStateCompressed *a) {
     381    //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
     382    int normsize = a->normsize;
     383    int compsize = a->compsize;
     384    int bufsize;
     385    if(normsize < compsize)
     386      bufsize = compsize;
     387    else
     388      bufsize = normsize;
     389//     unsigned char* dest = (unsigned char*)malloc( bufsize );
     390    unsigned char *dest = new unsigned char[bufsize];
     391    int retval;
     392    uLongf length=normsize;
     393    //std::cout << "gamestateclient" << std::endl;
     394    //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl;
     395    retval = uncompress( dest, &length, a->data, (uLong)compsize );
     396    //std::cout << "length " << length << std::endl;
     397    switch ( retval ) {
     398      case Z_OK: COUT(4) << "successfully decompressed" << std::endl; break;
     399      case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL;
     400      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL;
     401      case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return NULL;
     402    }
     403
     404    GameState *gamestate = new GameState;
     405    gamestate->id = a->id;
     406    gamestate->size = normsize;
     407    gamestate->data = dest;
     408    gamestate->base_id = a->base_id;
     409    gamestate->diffed = a->diffed;
     410    gamestate->complete = a->complete;
     411
     412    delete[] a->data; //delete compressed data
     413    delete a; //we do not need the old (struct) gamestate anymore
     414
     415    return gamestate;
     416  }
     417 
    313418
    314419  void GameStateManager::ackGameState(int clientID, int gamestateID) {
     
    336441    COUT(4) << std::endl;
    337442  }
     443 
     444  bool GameStateManager::checkAccess(int clientID, int objectID){
     445    // currently we only check, wheter the object is the clients spaceship
     446    return head_->findClient(objectID)->getShipID()==objectID;
     447  }
    338448
    339449}
  • code/branches/network3/src/network/GameStateManager.h

    r1200 r1232  
    7171    GameStateManager(ClientInformation *head);
    7272    ~GameStateManager();
    73     //#### ADDED FOR TESTING PURPOSE ####
    74     GameStateCompressed* testCompress( GameState* g );
    75     GameState* testDiff( GameState* a, GameState* b );
    76     //#### END TESTING PURPOSE ####
     73   
    7774    void update();
    7875    GameStateCompressed *popGameState(int clientID);
     76    bool pushGameState(GameStateCompressed *gs, int clientID);
    7977    void ackGameState(int clientID, int gamestateID);
    8078  private:
    8179    void cleanup(); // "garbage handler"
    8280    GameState *getSnapshot();
     81    bool loadPartialSnapshot(GameState *state, int clientID);
    8382    GameStateCompressed *encode(GameState *a, GameState *b);
    8483    GameStateCompressed *encode(GameState *a);
    8584    GameState *diff(GameState *a, GameState *b);
    8685    GameStateCompressed *compress_(GameState *a);
     86    GameState *decompress(GameStateCompressed *a);
    8787    bool printGameStates();
     88    bool checkAccess(int clientID, int objectID);
    8889
    8990    std::map<int, GameState*> gameStateMap; //map gsID to gamestate*
     
    9293    ClientInformation *head_;
    9394    int id_;
     95   
     96   
     97   
     98   
     99  public:
     100    //#### ADDED FOR TESTING PURPOSE ####
     101    GameStateCompressed* testCompress( GameState* g );
     102    GameState* testDiff( GameState* a, GameState* b );
     103  //#### END TESTING PURPOSE ####
    94104  };
    95105
  • code/branches/network3/src/network/NetworkPrereqs.h

    r1168 r1232  
    7878  struct chat;
    7979  struct classid;
     80  struct welcome;
     81  struct connectRequest;
    8082  struct ClientList;
    8183  struct GameState;
  • code/branches/network3/src/network/PacketDecoder.cc

    r1199 r1232  
    5353  bool PacketDecoder::elaborate( ENetPacket* packet, int clientId )
    5454  {
    55     int client = clientId;
    56     COUT(5) << "PacketDecoder: clientId: " << client << std::endl; //control cout, not important, just debugging info
     55    COUT(5) << "PacketDecoder: clientId: " << clientId << std::endl; //control cout, not important, just debugging info
    5756    int id = (int)*packet->data; //the first 4 bytes are always the enet packet id
    5857    COUT(5) << "PacketDecoder: packet id: " << id << std::endl;
     
    6463    }
    6564    switch( id ) {
    66   case ACK:
    67     acknowledgement( packet, clientId );
    68     return true;
    69     break;
    70   case MOUSE:
    71     mousem( packet, clientId );
    72     return true;
    73     break;
    74   case KEYBOARD:
    75     keystrike( packet, clientId );
    76     return true;
    77     break;
    78   case CHAT:
    79     chatMessage( packet, clientId );
    80     return true;
    81     break;
    82   case GAMESTATE:
    83     gstate( packet );
    84     return true;
    85     break;
    86   case CLASSID:
    87     clid(packet);
    88     return true;
    89     break;
     65    case ACK:
     66      acknowledgement( packet, clientId );
     67      return true;
     68    case COMMAND:
     69      return command( packet, clientId );
     70    case MOUSE:
     71      mousem( packet, clientId );
     72      return true;
     73    case KEYBOARD:
     74      keystrike( packet, clientId );
     75      return true;
     76    case CHAT:
     77      chatMessage( packet, clientId );
     78      return true;
     79    case GAMESTATE:
     80      gstate( packet );
     81      return true;
     82    case CLASSID:
     83      clid(packet);
     84      return true;
     85    case WELCOME:
     86      return decodeWelcome( packet, clientId );
     87    case CONNECT:
     88      return decodeConnectRequest( packet, clientId );
    9089    }
    9190    return false;
     
    105104    //clean memory
    106105    enet_packet_destroy( packet );
     106  }
     107 
     108  bool PacketDecoder::command( ENetPacket* packet, int clientId ){
     109    int length = *(int*)((unsigned char *)packet->data+sizeof(int));
     110    void *data = (void *)new unsigned char[length];
     111    memcpy(data, (void *)(packet->data+2*sizeof(int)), length);
     112    return true;
    107113  }
    108114
     
    171177    //since the packetgenerator was changed, due to a new parameter, change this function too
    172178    memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+5*sizeof(int)), sizeof(bool));
     179    memcpy( (void*)&(currentState->complete), (const void*)(packet->data+5*sizeof(int)+sizeof(bool)), sizeof(bool));
    173180    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
    174181    if(currentState->compsize==0)
     
    178185      COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl;
    179186    //copy the GameStateCompressed data
    180     memcpy( (void*)(currentState->data), (const void*)(packet->data+5*sizeof( int ) + sizeof(bool)), currentState->compsize );
     187    memcpy( (void*)(currentState->data), (const void*)(packet->data+5*sizeof( int ) + 2*sizeof(bool)), currentState->compsize );
    181188
    182189    //clean memory
     
    198205    processClassid(cid);
    199206  }
     207 
     208 
     209  bool PacketDecoder::decodeWelcome( ENetPacket* packet, int clientID ){
     210    welcome *w = new welcome;
     211    w->allowed = ((welcome *)(packet->data))->allowed;
     212    w->shipID = ((welcome *)(packet->data))->shipID;
     213    w->clientID = ((welcome *)(packet->data))->clientID;
     214    w->id = ((welcome *)(packet->data))->id;
     215    enet_packet_destroy( packet );
     216    return processWelcome(w);
     217  }
     218 
     219  bool PacketDecoder::decodeConnectRequest( ENetPacket *packet, int clientID ){
     220    connectRequest *con = new connectRequest;
     221    con->id = ((connectRequest *)(packet->data))->id;
     222    enet_packet_destroy( packet );
     223    return processConnectRequest(con, clientID );
     224  }
    200225
    201226
     
    224249    return;
    225250  }
    226 
     251 
     252  bool PacketDecoder::processWelcome( welcome *w ){
     253    return true;
     254  }
     255 
     256  bool PacketDecoder::processConnectRequest( connectRequest *con, int clientID ){
     257    COUT(3) << "packetdecoder: processing connectRequest" << std::endl;
     258    return true;
     259  }
    227260
    228261  //these are some print functions for test stuff
  • code/branches/network3/src/network/PacketGenerator.cc

    r1180 r1232  
    6161    return packet;
    6262  }
     63 
     64  ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE )
     65  {
     66    void *stream = new char[dataLength + 2*sizeof(int)];
     67    if(!stream)
     68      return NULL;
     69    packet_id a = COMMAND;
     70    memcpy(stream, (void*)&a, sizeof(int));
     71    memcpy((unsigned char *)stream+sizeof(int), (void*)&dataLength, sizeof(int));
     72    memcpy((unsigned char *)stream+2*sizeof(int), data, dataLength);
     73    return enet_packet_create(stream, dataLength+2*sizeof(int), reliable);
     74  }
    6375
    6476  /*### mouseupdates */
     
    108120    //std::cout << "states->compsize " << states->compsize << std::endl;
    109121    int gid = GAMESTATE; //first assign the correct enet id
    110     int totalLen = 5*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory
     122    int totalLen = 5*sizeof( int ) + 2*sizeof(bool) + states->compsize; //calculate the total size of the datastream memory
    111123    //std::cout << "totalLen " << totalLen << std::endl;
    112     unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
     124    //unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
     125    unsigned char *data = new unsigned char[totalLen];
    113126    memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id
    114127    memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id
     
    118131    memcpy( (void*)(data+5*sizeof(int)), (const void*)&(states->diffed), sizeof(bool));
    119132    //place the GameStateCompressed data at the end of the enet datastream
    120     memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize );
     133    memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)&(states->complete), sizeof(bool) );
     134    memcpy( (void*)(data+5*sizeof( int ) + 2*sizeof(bool)), (const void*)states->data, states->compsize );
    121135    //create an enet packet with the generated bytestream
    122136    COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl;
     
    128142  ENetPacket* PacketGenerator::clid( int classid, std::string classname, int reliable )
    129143  {
    130     unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
     144    //unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
     145    unsigned char *data = new unsigned char[3*sizeof(int)+classname.length()+1];
    131146    std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl;
    132147    *(int *)data = CLASSID;
     
    137152    return packet;
    138153  }
     154 
     155  ENetPacket* PacketGenerator::generateWelcome( int clientID,int shipID, bool allowed , int reliable ){
     156    welcome *wc = new welcome;
     157    wc->id = WELCOME;
     158    wc->clientID = clientID;
     159    wc->shipID = shipID;
     160    wc->allowed = true;
     161    ENetPacket *packet = enet_packet_create( wc, sizeof(welcome), reliable);
     162    return packet;
     163  }
     164 
     165  ENetPacket* PacketGenerator::generateConnectRequest( int reliable ){
     166    connectRequest *con = new connectRequest;
     167    con->id=CONNECT;
     168    return enet_packet_create( con, sizeof(connectRequest), reliable);
     169  }
    139170
    140171}
  • code/branches/network3/src/network/PacketManager.h

    r1168 r1232  
    5454    //call one of this functions out of an instance of PacketGenerator to create a packet
    5555    ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE );
     56    ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE );
    5657    ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
    5758    ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
     
    5960    ENetPacket* gstate( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE );
    6061    ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
     62    ENetPacket* generateWelcome( int clientID,int shipID, bool allowed, int reliable = ENET_PACKET_FLAG_RELIABLE );
     63    ENetPacket* generateConnectRequest( int reliable = ENET_PACKET_FLAG_RELIABLE );
    6164  private:
    6265  };
     
    8588
    8689    void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
     90    bool command( ENetPacket* packet, int clientId );
    8791    void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
    8892    void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
     
    9094    void gstate( ENetPacket* packet );
    9195    void clid( ENetPacket *packet);
     96    bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
     97    bool decodeConnectRequest( ENetPacket *packet, int clientID = CLIENTID_CLIENT );
    9298
    9399    //process data
     
    96102    virtual void processAck( ack *data, int clientID);
    97103    virtual void processClassid( classid *cid);
     104    virtual bool processWelcome( welcome *w );
     105    virtual bool processConnectRequest( connectRequest *con, int clientID );
    98106    //virtual void processAck( ack *data);
    99107
  • code/branches/network3/src/network/PacketTypes.h

    r1168 r1232  
    4949    ACK,
    5050    MOUSE,
     51    COMMAND,
    5152    KEYBOARD,
    5253    CHAT,
    5354    GAMESTATE ,
    54     CLASSID
     55    CLASSID,
     56    WELCOME,
     57    CONNECT,
    5558  };
    5659
     
    6568    int size;                       //!< total size of data
    6669    // new ---- change functions
    67     int base_id;                  // if gamestate is diffed this is the id of the old gamestate (base)
     70    int base_id;                    // if gamestate is diffed this is the id of the old gamestate (base)
    6871    bool diffed;
     72    bool complete;                  // this determines, wheter all objects are in this gamestate (server) or only few objects (client)
    6973    unsigned char *data;            //!< pointer to data
    7074  };
     
    8387    int base_id;                  // if gamestate is diffed this is the id of the old gamestate (base)
    8488    bool diffed;
     89    bool complete;                  // this determines, wheter all objects are in this gamestate (server) or only few objects (client)
    8590    unsigned char *data;            //!< gamestate data
    8691  };
     
    116121  };
    117122
     123  struct welcome {
     124    int id;
     125    int clientID;
     126    int shipID;
     127    bool allowed;
     128  };
     129 
     130  struct connectRequest{
     131    int id;
     132  };
    118133}
    119134
  • code/branches/network3/src/network/Server.cc

    r1199 r1232  
    223223    gamestates->ackGameState(clientID, data->a);
    224224  }
     225 
     226  bool Server::processConnectRequest( connectRequest *con, int clientID ){
     227    COUT(4) << "processing connectRequest " << std::endl;
     228    //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
     229    connection->createClient(clientID);
     230  }
    225231
    226232}
  • code/branches/network3/src/network/Server.h

    r1168 r1232  
    7373    bool sendGameState();
    7474    void processAck( ack *data, int clientID);
     75    bool processConnectRequest( connectRequest *con, int clientID );
    7576    ConnectionManager *connection;
    7677    GameStateManager *gamestates;
  • code/branches/network3/src/network/Synchronisable.cc

    r1199 r1232  
    4848namespace network
    4949{
     50 
     51 
     52  int Synchronisable::state_=1; // detemines wheter we are server (default) or client
     53 
    5054  /**
    5155  * Constructor:
     
    6367  Synchronisable::~Synchronisable(){
    6468  }
     69 
     70  void Synchronisable::setClient(bool b){
     71    if(b) // client
     72      state_=0x2;
     73    else  // server
     74      state_=0x1;
     75  }
    6576
    6677  /**
     
    7081  * @param size size of the datatype the variable consists of
    7182  */
    72   void Synchronisable::registerVar(void *var, int size, variableType t){
     83  void Synchronisable::registerVar(void *var, int size, variableType t, int mode){
    7384    // create temporary synch.Var struct
    7485    synchronisableVariable *temp = new synchronisableVariable;
    7586    temp->size = size;
    7687    temp->var = var;
     88    temp->mode = mode;
    7789    temp->type = t;
    7890    COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl;
     
    153165    for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){
    154166      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
     167      if( ((*i)->mode & state_) == 0 )
     168        continue;  // this variable should only be received
    155169      switch((*i)->type){
    156170      case DATA:
     
    185199    COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl;
    186200    for(i=syncList->begin(); i!=syncList->end(); i++){
     201      if( ((*i)->mode ^ state_) == 0 )
     202        continue;  // this variable should only be sent
    187203      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
    188204      switch((*i)->type){
     
    212228    std::list<synchronisableVariable *>::iterator i;
    213229    for(i=syncList->begin(); i!=syncList->end(); i++){
     230      if( ((*i)->mode & state_) == 0 )
     231        continue;  // this variable should only be received, so dont add its size to the send-size
    214232      switch((*i)->type){
    215233      case DATA:
     
    226244    return tsize;
    227245  }
    228 
     246 
     247  void Synchronisable::setBacksync(bool sync){
     248    backsync_=sync;
     249  }
     250
     251  bool Synchronisable::getBacksync(){
     252    return backsync_;
     253  }
     254 
    229255}
  • code/branches/network3/src/network/Synchronisable.h

    r1180 r1232  
    6262  typedef struct synchronisableVariable{
    6363    int size;
     64    int mode; // this determines in which direction the variable gets synchronised
    6465    void *var;
    6566    variableType type;
     
    6970  /**
    7071  * This class is the base class of all the Objects in the universe that need to be synchronised over the network
    71   * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. Additionally it also has to provide a Constructor, that takes exactly the variables in this linked list.
     72   * Every class, t
     73  int mode;hat inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. Additionally it also has to provide a Constructor, that takes exactly the variables in this linked list.
    7274  * @author Oliver Scheuss
    7375  */
     
    7981    int classID;
    8082
    81     void registerVar(void *var, int size, variableType t);
     83    void registerVar(void *var, int size, variableType t, int mode=1);
    8284    //  syncData getData();
    8385    syncData getData(unsigned char *mem);
    8486    int getSize();
    8587    bool updateData(syncData vars);
     88    void setBacksync(bool sync);
     89    bool getBacksync();
    8690    virtual void registerAllVariables()=0;
    8791    virtual bool create()=0;
     92    static void setClient(bool b);
    8893  protected:
    8994    Synchronisable();
     
    9398    std::list<synchronisableVariable *> *syncList;
    9499    int datasize;
     100    static int state_; // detemines wheter we are server (default) or client
     101    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
    95102  };
    96103}
  • code/branches/network3/src/orxonox/Orxonox.cc

    r1184 r1232  
    326326    orxonoxHUD_->setEnergyDistr(20,20,60);
    327327    hudOverlay->show();
     328    setupInputSystem();
    328329
    329330    client_g->establishConnection();
     
    362363  }
    363364
    364   void Orxonox::createScene(void)
     365  void Orxonox::createScene()
    365366  {
    366367          // Init audio
  • code/branches/network3/src/orxonox/objects/Camera.cc

    r1212 r1232  
    127127    COUT(0) << "t " << this->targetNode_->getPosition() << std::endl;
    128128    if(this->positionNode_ != NULL)
    129       //this->cam_->setPosition(this->positionNode_->getPosition());
     129      this->cam_->setPosition(this->positionNode_->getPosition());
    130130    if(this->targetNode_ != NULL)
    131131      this->cam_->lookAt(this->targetNode_->getPosition());
     
    139139  {
    140140    this->bHasFocus_ = false;
     141    this->positionNode_->detachObject(cam_);
    141142  }
    142143
  • code/branches/network3/src/orxonox/objects/Model.cc

    r1174 r1232  
    7373        XMLPortParamLoadOnly(Model, "mesh", setMesh, xmlelement, mode);
    7474
    75         create();
     75        Model::create();
    7676    }
    7777
  • code/branches/network3/src/orxonox/objects/SpaceShip.cc

    r1212 r1232  
    8080
    8181        this->camNode_ = 0;
     82        this->camName_ = "camNode";
    8283
    8384        this->tt_ = 0;
     
    160161
    161162    void SpaceShip::registerAllVariables(){
    162 
    163 
    164 
     163      registerVar( &camName_, camName_.length()+1, network::STRING);
    165164    }
    166165
    167166    void SpaceShip::init()
    168167    {
    169         createCamera();
     168        COUT(4) << "================ \t\t\t\tspaceship::init" << std::endl;
    170169        // START CREATING THRUSTER
    171170        this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
     
    198197        this->greenNode_->setInheritScale(false);
    199198
     199        COUT(4) << "attaching red billboard" << std::endl;
    200200        this->redNode_->attachObject(this->redBillboard_.getBillboardSet());
    201201        this->redNode_->setScale(0.3, 0.3, 0.3);
    202202
     203        COUT(4) << "attaching green billboard" << std::endl;
    203204        this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet());
    204205        this->greenNode_->setScale(0.3, 0.3, 0.3);
     
    214215        this->chFarNode_->setInheritScale(false);
    215216
     217        COUT(4) << "attaching crosshair near billboard" << std::endl;
    216218        this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
    217219        this->chNearNode_->setScale(0.2, 0.2, 0.2);
    218220
     221        COUT(4) << "attaching crosshair far billboard" << std::endl;
    219222        this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
    220223        this->chFarNode_->setScale(0.4, 0.4, 0.4);
    221 
     224        COUT(4) << "attaching camera" << std::endl;
     225       
     226        createCamera();
    222227        // END of testing crosshair
    223228    }
     
    232237    void SpaceShip::loadParams(TiXmlElement* xmlElem)
    233238    {
     239      COUT(4) << "using loadparams" << std::endl;
    234240        Model::loadParams(xmlElem);
    235241        this->create();
     242        this->getFocus();
    236243/*
    237244        if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
     
    284291    void SpaceShip::setCamera(const std::string& camera)
    285292    {
     293      camName_=camera;
    286294      // change camera attributes here, if you want to ;)
     295    }
     296   
     297    void SpaceShip::getFocus(){
     298      COUT(4) << "requesting focus" << std::endl;
     299      if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID)
     300        CameraHandler::getInstance()->requestFocus(cam_);
     301     
    287302    }
    288303   
    289304    void SpaceShip::createCamera(){
    290       this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
    291       camNode_->setPosition(this->getNode()->getPosition() + Vector3(-50,0,10));
     305      COUT(4) << "begin camera creation" << std::endl;
     306      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
     307      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
     308      this->camNode_->setPosition(this->getNode()->getPosition() + Vector3(-50,0,10));
     309      COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
    292310/*
    293311//        node->setInheritOrientation(false);
     
    295313      cam->lookAt(Vector3(0,20,0));
    296314      cam->roll(Degree(0));
    297 */
     315      */COUT(4) << "creating new camera" << std::endl;
    298316      cam_ = new Camera(this->camNode_);
     317      COUT(4) << "setting target node" << std::endl;
    299318      cam_->setTargetNode(this->getNode());
    300       CameraHandler::getInstance()->requestFocus(cam_);
     319      // this only applies to clients
     320      if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID)
     321        CameraHandler::getInstance()->requestFocus(cam_);
    301322//        cam->setPosition(Vector3(0,-350,0));
    302323      //cam->roll(Degree(-90));
    303324
    304325      //this->camNode_->attachObject(cam);
    305      
     326      COUT(4) << "created camera" << std::endl;
    306327    }
    307328
     
    329350    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    330351    {
     352      COUT(4) << "using xmlport" << std::endl;
    331353        Model::XMLPort(xmlelement, mode);
    332354
     
    339361        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
    340362        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
     363       
     364        SpaceShip::create();
     365        getFocus();
    341366    }
    342367
     
    534559        }
    535560
    536         if(!network::Client::getSingleton()){
     561        if(!network::Client::getSingleton() || network::Client::getSingleton()->getShipID() == objectID){
    537562          if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
    538563              this->acceleration_.x = this->translationAcceleration_;
  • code/branches/network3/src/orxonox/objects/SpaceShip.h

    r1212 r1232  
    6363            void setTransDamp(float value);
    6464            void setRotDamp(float value);
     65           
     66            void getFocus();
    6567
    6668            static void setMaxSpeedTest(float value)
     
    8385
    8486            Ogre::SceneNode* camNode_;
    85             Camera* cam_;
     87            Camera* cam_; 
     88            std::string camName_;
     89
    8690
    8791            ParticleInterface* tt_;
  • code/branches/network3/src/orxonox/objects/WorldEntity.cc

    r1191 r1232  
    190190        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
    191191       
    192         //create();
     192        WorldEntity::create();
    193193    }
    194194
     
    197197    {
    198198      // register coordinates
    199       registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA);
    200       registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA);
    201       registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA);
     199      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA, 0x3);
     200      registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA, 0x3);
     201      registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA, 0x3);
    202202      // register orientation
    203       registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA);
    204       registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA);
    205       registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA);
    206       registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA);
     203      registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA, 0x3);
     204      registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA, 0x3);
     205      registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA, 0x3);
     206      registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA, 0x3);
    207207      // register velocity_
    208       registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA);
    209       registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA);
    210       registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA);
     208      registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA, 0x3);
     209      registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA, 0x3);
     210      registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA, 0x3);
    211211      // register rotationAxis/rate
    212       registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA);
    213       registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA);
    214       registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA);
    215       registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA);
     212      registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA, 0x3);
     213      registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA, 0x3);
     214      registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA, 0x3);
     215      registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA, 0x3);
    216216      // register scale of node
    217       registerVar( (void*) &(this->getScale().x), sizeof(this->getScale().x), network::DATA);
    218       registerVar( (void*) &(this->getScale().y), sizeof(this->getScale().y), network::DATA);
    219       registerVar( (void*) &(this->getScale().z), sizeof(this->getScale().z), network::DATA);
     217      registerVar( (void*) &(this->getScale().x), sizeof(this->getScale().x), network::DATA, 0x3);
     218      registerVar( (void*) &(this->getScale().y), sizeof(this->getScale().y), network::DATA, 0x3);
     219      registerVar( (void*) &(this->getScale().z), sizeof(this->getScale().z), network::DATA, 0x3);
    220220      //register staticity
    221       registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA);
     221      registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3);
     222      //register acceleration
     223      // register velocity_
     224      registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);
     225      registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);
     226      registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);
    222227    }
    223228
Note: See TracChangeset for help on using the changeset viewer.