Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1098


Ignore:
Timestamp:
Apr 17, 2008, 2:35:51 PM (16 years ago)
Author:
rgrieder
Message:

merged network branch into new network2 branch (from trunk)

Location:
code/branches/network2
Files:
29 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/branches/network2/CMakeLists.txt

    r1085 r1098  
    3636
    3737# global compiler/linker flags. force -O2!
    38 SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O2 -Wall -g -ggdb")
    39 SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O2 -Wall -g -ggdb")
     38SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O0 -Wall -g -ggdb")
     39SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
    4040SET(CMAKE_LD_FLAGS "$ENV{LDFLAGS}")
    4141SET(CMAKE_EXE_LINKER_FLAGS " --no-undefined")
  • code/branches/network2/bin/levels/sample.oxw

    r1089 r1098  
    99  </audio-->
    1010
    11 <Ambient colourvalue="1,1,1" />
    12 <Skybox src="Orxonox/StarSkyBox" />
     11<!--Ambient colourvalue="1,1,1" />
     12<Skybox src="Orxonox/StarSkyBox" /-->
    1313
    1414<SpaceShip camera="true" position="0,0,0" scale="10" yawpitchroll="-90,-90,0" mesh="assf3.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />
    1515
    16 <NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
     16<!--NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
    1717<NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
    1818<NPC position="0,-100,500" scale="1" mesh="razor.mesh"/>
    1919<NPC position="0,-200,450" scale="1" mesh="razor.mesh"/>
    20 <NPC position="100,0,400" scale="1" mesh="razor.mesh"/>
     20<NPC position="100,0,400" scale="1" mesh="razor.mesh"/-->
    2121
    2222<!--Model name="starship" position="200,0,500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
     
    3131</Model-->
    3232
    33 <Model position="-200,1000,500" scale="10" mesh="hoover_body.mesh" yawpitchroll="-90,-90,0" />
     33<!--Model position="-200,1000,500" scale="10" mesh="hoover_body.mesh" yawpitchroll="-90,-90,0" />
    3434<Model position="-200,1000,500" scale="10" mesh="hoover_gear0.mesh" yawpitchroll="-90,-90,0" />
    3535<Model position="-200,1000,500" scale="10" mesh="hoover_gear1.mesh" yawpitchroll="-90,-90,0" />
    3636<Model position="-200,1000,500" scale="10" mesh="hoover_gear2.mesh" yawpitchroll="-90,-90,0" />
    37 <Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" />
     37<Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" /-->
    3838
    3939
  • code/branches/network2/src/network/CMakeLists.txt

    r1070 r1098  
    1111  Server.cc
    1212  Synchronisable.cc
    13   dummyserver3.cc
    1413)
    1514
     
    3029# build those parts only on request.
    3130IF(NETWORK_TESTING_ENABLED)
     31  ##### test for gamestate stuff #####
     32  SET( TEST_SRC_FILES
     33    ConnectionManager.cc
     34    GameStateManager.cc
     35    PacketBuffer.cc
     36    PacketDecoder.cc
     37    PacketGenerator.cc
     38    ClientConnection.cc
     39    ClientInformation.cc
     40    diffTest.cc
     41    GameStateClient.cc
     42    Server.cc
     43    Client.cc 
     44    Synchronisable.cc 
     45  )
     46
     47  ADD_EXECUTABLE(networktest ${TEST_SRC_FILES})
     48  TARGET_LINK_LIBRARIES( networktest
     49    ${OGRE_LIBRARIES}
     50    network
     51    ${ENet_LIBRARY}
     52    ${ZLIB_LIBRARY}
     53    ${WINDOWS_ENET_DEPENDENCIES}
     54  )
     55  ##### end test for gamestate stuff #####
     56ENDIF(NETWORK_TESTING_ENABLED)
     57IF(BLABLA)
    3258  SET( CHATCLIENT_SRC_FILES
    3359    ClientConnection.cc
     
    95121    ${WINDOWS_ENET_DEPENDENCIES}
    96122  )
    97 ENDIF(NETWORK_TESTING_ENABLED)
     123ENDIF(BLABLA)
     124
  • code/branches/network2/src/network/Client.cc

    r1062 r1098  
    205205    if(id!=NULL)
    206206      id->setNetworkID(clid->clid);
    207     COUT(4) << "received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;
     207    COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;
    208208    return;
    209209  }
  • code/branches/network2/src/network/ClientConnection.cc

    r1062 r1098  
    8787
    8888  ENetPacket *ClientConnection::getPacket() {
    89     ENetAddress address;
     89    ENetAddress address; //sems that address is not needed
    9090    return getPacket(address);
    9191  }
     
    162162      case ENET_EVENT_TYPE_CONNECT:
    163163      case ENET_EVENT_TYPE_RECEIVE:
    164         COUT(5) << "receiver-Thread: got new packet" << std::endl;
    165         processData(&event);
     164        COUT(5) << "Cl.Con: receiver-Thread while loop: got new packet" << std::endl;
     165        if ( !processData(&event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;
    166166        break;
    167167      case ENET_EVENT_TYPE_DISCONNECT:
     
    203203  bool ClientConnection::establishConnection() {
    204204    ENetEvent event;
    205     // connect to peer
     205    // connect to peer (server is type ENetPeer*)
    206206    server = enet_host_connect(client, &serverAddress, NETWORK_CLIENT_CHANNELS);
    207207    if(server==NULL)
     
    218218
    219219  bool ClientConnection::processData(ENetEvent *event) {
    220     COUT(5) << "got packet, pushing to queue" << std::endl;
     220    COUT(5) << "Cl.Con: got packet, pushing to queue" << std::endl;
    221221    // just add packet to the buffer
    222222    // this can be extended with some preprocessing
  • code/branches/network2/src/network/ClientInformation.cc

    r1062 r1098  
    190190  * This function should only be applied to the head of the list
    191191  * @param clientID id to look for
    192   * @return pointer to the element in the list or 0 if the search was unsuccessfull
     192  * @return pointer to the last element in the list or 0 if the search was unsuccessfull
    193193  */
    194194  ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
     
    196196    if (temp->head)
    197197      temp=temp->next();
    198     while(temp!=0 && temp->getID()!=clientID){
     198    //bugfix: temp to temp->next(), get last elem if not found, not segflt
     199    while(temp->next()!=0 && temp->getID()!=clientID){
    199200      temp = temp->next();
    200201    }
     
    211212  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
    212213    ClientInformation *temp = this;
    213     while(temp!=0){
     214    //bugfix: temp to temp->next(), get last elem if not found, not segflt
     215    while(temp->next()!=0){
    214216      if(temp->head){
    215217        temp = temp->next();
  • code/branches/network2/src/network/ClientInformation.h

    r1062 r1098  
    7575    bool removeClient(int clientID);
    7676    bool removeClient(ENetPeer *peer);
     77    //## add bool mask-function eventually
    7778    ClientInformation *findClient(int clientID, bool look_backwards=false);
     79    //## add bool mask-function eventually
    7880    ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
    7981
  • code/branches/network2/src/network/ConnectionManager.cc

    r1064 r1098  
    6060{
    6161  boost::thread_group network_threads;
    62 
     62 
     63  ConnectionManager::ConnectionManager(){}
     64 
    6365  ConnectionManager::ConnectionManager(ClientInformation *head) {
    6466    quit=false;
     
    8890      return NULL;
    8991  }
    90 
     92/**
     93This function only pops the first element in PacketBuffer (first in first out)
     94used by processQueue in Server.cc
     95*/
    9196  ENetPacket *ConnectionManager::getPacket(int &clientID) {
    9297    ENetAddress address;
     
    174179        case ENET_EVENT_TYPE_CONNECT:
    175180          addClient(&event);
     181          COUT(5) << "Con.Man: connection event has occured" << std::endl;
    176182          break;
    177183        case ENET_EVENT_TYPE_RECEIVE:
    178184          //std::cout << "received data" << std::endl;
     185          COUT(5) << "Con.Man: receive event has occured" << std::endl;
    179186          processData(&event);
    180187          break;
     
    191198    enet_host_destroy(server);
    192199  }
    193 
     200 
     201  //### added some bugfixes here, but we cannot test them because
     202  //### the server crashes everytime because of some gamestates
     203  //### (trying to resolve that now)
    194204  void ConnectionManager::disconnectClients() {
    195205    ENetEvent event;
     
    199209      temp = temp->next();
    200210    }
    201     temp = temp->next();
     211    //bugfix: might be the reason why server crashes when clients disconnects
     212    //temp = temp->next();
     213    temp = head_->next();
    202214    while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) > 0){
    203215      switch (event.type)
    204216      {
    205       case ENET_EVENT_TYPE_NONE:
    206       case ENET_EVENT_TYPE_CONNECT:
     217      case ENET_EVENT_TYPE_NONE: break;
     218      case ENET_EVENT_TYPE_CONNECT: break;
    207219      case ENET_EVENT_TYPE_RECEIVE:
    208220        enet_packet_destroy(event.packet);
    209221        break;
    210222      case ENET_EVENT_TYPE_DISCONNECT:
    211         std::cout << "disconnecting client" << std::endl;
     223        COUT(4) << "disconnecting all clients" << std::endl;
    212224        delete head_->findClient(&(event.peer->address));
     225        //maybe needs bugfix: might also be a reason for the server to crash
    213226        temp = temp->next();
    214227        break;
     
    229242
    230243  bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
     244    COUT(4) << "removing client from list" << std::endl;
    231245    return head_->removeClient(peer);
    232246  }
    233 
     247/**
     248This function adds a client that connects to the clientlist of the server
     249NOTE: if you change this, don't forget to change the test function
     250addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid
     251*/
    234252  bool ConnectionManager::addClient(ENetEvent *event) {
    235253    ClientInformation *temp = head_->insertBack(new ClientInformation);
    236     if(temp->prev()->head)
     254    if(temp->prev()->head) { //not good if you use anything else than insertBack
     255      temp->prev()->setID(0); //bugfix: not necessary but usefull
    237256      temp->setID(1);
     257    }
    238258    else
    239259      temp->setID(temp->prev()->getID()+1);
    240260    temp->setPeer(event->peer);
    241     std::cout << "added client id: " << temp->getID() << std::endl;
     261    COUT(4) << "Con.Man: added client id: " << temp->getID() << std::endl;
    242262    syncClassid(temp->getID());
    243263    temp->setSynched(true);
     
    268288      classname = id->getName();
    269289      network_id = id->getNetworkID();
    270       COUT(4) << "network_id: " << network_id << ", classname: " << classname << std::endl;
     290      COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
    271291
    272292      addPacket(packet_gen.clid( (int)network_id, classname ), clientID);
     
    275295    }
    276296    sendPackets();
     297    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
    277298  }
    278299
     
    289310
    290311  int ConnectionManager::getObjectsClientID( int objectID ) {
    291     std::map<int, int>::iterator iter = clientsShip.begin();
    292     while( iter != clientsShip.end() ) {
     312    std::map<int, int>::iterator iter;
     313    for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
    293314      if( iter->second == objectID ) return iter->first;
    294315    }
     
    302323  void ConnectionManager::deleteObjectIDReg( int objectID ) {
    303324    std::map<int, int>::iterator iter = clientsShip.begin();
    304     while( iter != clientsShip.end() ) {
     325    for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
    305326      if( iter->second == objectID ) break;
    306327    }
    307328    clientsShip.erase( iter->first );
    308329  }
    309 
     330  int ConnectionManager::getNumberOfClients() {
     331    return clientsShip.size();
     332  }
    310333}
  • code/branches/network2/src/network/ConnectionManager.h

    r1062 r1098  
    8484    bool sendPackets(ENetEvent *event);
    8585    bool sendPackets();
     86
     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 #####
    86108  private:
    87109    bool clientDisconnect(ENetPeer *peer);
     
    111133    void deleteClientIDReg( int clientID );
    112134    void deleteObjectIDReg( int objectID );
     135    int getNumberOfClients();
    113136  };
    114 
    115 
    116 
    117 
    118 
    119 
    120 
    121137
    122138}
  • code/branches/network2/src/network/GameStateClient.cc

    r1062 r1098  
    3232
    3333#include "core/CoreIncludes.h"
     34#include "core/BaseObject.h"
    3435#include "Synchronisable.h"
    3536
    3637namespace network
    3738{
     39  struct GameStateItem{
     40    GameState *state;
     41    int id;
     42  };
     43 
    3844  GameStateClient::GameStateClient() {
     45    COUT(5) << "this: " << this << std::endl;
    3946  }
    4047
     
    4451  bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
    4552    GameState *gs;
    46     if(compstate->diffed)
    47       gs = decode(reference, compstate);
     53    if(compstate->diffed){
     54      while(compstate->base_id > gameStateList.front()->id){
     55        // clean up old gamestates
     56        free(gameStateList.front()->data);
     57        // TODO: critical section
     58        delete gameStateList.front();
     59        gameStateList.pop();
     60      }
     61      if(compstate->base_id!=gameStateList.front()->id){
     62        COUT(4) << "pushGameState: no reference found to diff" << std::endl;
     63        return false;
     64      }
     65      gs = decode(gameStateList.front(), compstate);
     66    }
    4867    else
    4968      gs = decode(compstate);
     
    95114
    96115        if(!it){
    97           COUT(5) << "classid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
    98           Synchronisable *no = (Synchronisable*)(ID((unsigned int) sync.classID)->fabricate());
     116          COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
     117          Synchronisable *no = dynamic_cast<Synchronisable *>(ID((unsigned int) sync.classID)->fabricate());
    99118          no->objectID=sync.objectID;
    100119          no->classID=sync.classID;
    101120          it=orxonox::ObjectList<Synchronisable>::end();
    102121          // update data and create object/entity...
    103           if( !no->updateData(sync) && !no->create() )
    104             COUT(1) << "We couldn't create/update the object: " << sync.objectID << std::endl;
    105           ++it;
     122          if( !no->updateData(sync) )
     123            COUT(1) << "We couldn't update the object: " << sync.objectID << std::endl;
     124          if( !no->create() )
     125            COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl;
    106126        }
    107127      } else {
     
    154174  }
    155175
     176  //##### ADDED FOR TESTING PURPOSE #####
     177  GameState* GameStateClient::testDecompress( GameStateCompressed* gc ) {
     178    return decompress( gc );
     179  }
     180 
     181  GameState* GameStateClient::testUndiff( GameState* g_old, GameState* g_diffed ) {
     182    return undiff( g_old, g_diffed );
     183  }
     184  //##### ADDED FOR TESTING PURPOSE #####
     185
    156186  GameState *GameStateClient::decompress(GameStateCompressed *a) {
     187    //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
    157188    int normsize = a->normsize;
    158189    int compsize = a->compsize;
     
    173204      case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL;
    174205      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL;
    175       case Z_DATA_ERROR: COUT(2) << "data corrupted" << std::endl; return NULL;
     206      case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return NULL;
    176207    }
    177208
     
    189220
    190221  GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) {
    191     GameState *t = decompress(x);
    192     return undiff(a, t);
     222    GameState *t = decode(x);
     223    gameStateList.push(t);
     224    //return undiff(a, t);
     225    return t;
    193226  }
    194227
    195228  GameState *GameStateClient::decode(GameStateCompressed *x) {
    196     GameState *t = decompress(x);
     229    //GameState *t = decompress(x);
     230    GameState *t = new GameState;
     231    t->base_id = x->base_id;
     232    t->id = x->id;
     233    t->diffed = x->diffed;
     234    t->data = x->data;
     235    t->size = x->normsize;
     236    gameStateList.push(t);
    197237    return t;
    198238  }
  • code/branches/network2/src/network/GameStateClient.h

    r1062 r1098  
    4141#define _GameStateClient_H__
    4242
     43#include <queue>
     44
    4345#include "NetworkPrereqs.h"
    4446#include "core/CorePrereqs.h"
    45 #include "GameStateManager.h"
     47#include "PacketTypes.h"
    4648
    4749namespace network
     
    5254    GameStateClient();
    5355    ~GameStateClient();
     56    //#### ADDED FOR TESTING PURPOSE ####
     57    GameState* testDecompress( GameStateCompressed* gc );
     58    GameState* testUndiff( GameState* g_old, GameState* g_diffed );
     59    //#### END TESTING PURPOSE ####
    5460    bool pushGameState(GameStateCompressed *compstate);
    5561  private:
     
    6167    void removeObject(orxonox::Iterator<Synchronisable> &it);
    6268
    63     GameState *reference;
     69    GameState     *reference;
     70    std::queue<GameState *> gameStateList;
    6471  };
    6572
  • code/branches/network2/src/network/GameStateManager.cc

    r1064 r1098  
    6060
    6161  void GameStateManager::update(){
     62    cleanup();
    6263    reference = getSnapshot(id);
    6364    gameStateMap.insert(std::pair<int, GameState*>(id, reference));
     
    6667    return;
    6768  }
     69 
     70 
     71  /**
     72   * this function is used to keep the memory usage low
     73   * it tries to delete all the unused gamestates
     74   *
     75   *
     76   */
     77  void GameStateManager::cleanup(){
     78    std::map<int,int>::iterator it = gameStateUsed.begin();
     79    while(it!=gameStateUsed.end()){
     80      if( (*it).second <= 0 ){
     81        free(gameStateMap[(*it).first]->data);
     82        delete gameStateMap[(*it).first];
     83        gameStateMap.erase((*it).first);
     84        gameStateUsed.erase(it++);
     85      }else  //as soon as we got a used gamestate break here because we could use newer gamestates in future
     86        break;
     87    }
     88  }
    6889
    6990  GameStateCompressed *GameStateManager::popGameState(int clientID) {
     91    //why are we searching the same client's gamestate id as we searched in
     92    //Server::sendGameState?
    7093    int gID = head_->findClient(clientID)->getGamestateID();
    71     COUT(4) << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl;
    72     if(gID!=GAMESTATEID_INITIAL){
     94    COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id << " diffed from: " << gID << " (not diffed yet)" << std::endl;
     95   
     96    //chose wheather the next gamestate is the first or not
     97    if(gID != GAMESTATEID_INITIAL){
    7398      GameState *client = gameStateMap[gID];
    7499      GameState *server = reference;
     
    90115  GameState *GameStateManager::getSnapshot(int id)
    91116  {
     117    //std::cout << "begin getSnapshot" << std::endl;
    92118    //the size of the gamestate
    93119    int totalsize=0;
     
    102128    GameState *retval=new GameState; //return value
    103129    retval->id=id++;
    104     COUT(4) << "producing gamestate with id: " << retval->id << std::endl;
     130    COUT(4) << "G.ST.Man: producing gamestate with id: " << retval->id << std::endl;
    105131    // reserve a little memory and increase it later on
    106     COUT(5) << "mallocing" << std::endl;
     132    COUT(5) << "G.ST.Man: mallocing: " << memsize << std::endl;
    107133    retval->data = (unsigned char*)malloc(memsize);
    108     COUT(5) << "malloced" << std::endl;
     134    COUT(5) << "G.ST.Man: malloced: " << memsize << std::endl;
    109135
    110136    // offset of memory functions
     
    112138    // go through all Synchronisables
    113139    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     140      //std::cout << "begin inner loop" << std::endl;
    114141      //std::cout << "gamestatemanager: in for loop" << std::endl;
    115142      //get size of the synchronisable
    116143      tempsize=it->getSize();
    117 //       COUT(5) << "size of temp gamestate: " << tempsize << std::endl;
     144      //COUT(5) << "size of temp gamestate: " << tempsize << std::endl;
    118145      //COUT(2) << "size of synchronisable: " << tempsize << std::endl;
    119146      // add place for data and 3 ints (length,classid,objectid)
    120147      totalsize+=tempsize+3*sizeof(int);
    121148      //std::cout << "totalsize: " << totalsize << std::endl;
     149      //COUT(5) << "G.St.Man: current totalsize=" << totalsize << std::endl;
     150      //COUT(5) << "G.St.Man: current it->classID=" << it->classID << " it->objectID=" << it->objectID << std::endl;
    122151      // allocate additional space
    123       if(totalsize+tempsize>memsize){
    124         if(tempsize<1000){
     152      if((totalsize+tempsize) > memsize){
     153        COUT(5) << "G.St.Man: need additional memory" << std::endl;
     154        if(tempsize < 1000){
    125155          retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
    126156          memsize+=1000;
     
    129159          memsize+=tempsize+1000;
    130160        }
     161        COUT(5) << "G.St.Man: additional space allocation finished" << std::endl;
    131162      }
    132163
    133164      // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length)
    134165      sync=it->getData((retval->data)+offset+3*sizeof(int));
    135       *(retval->data+offset)=(unsigned char)sync.length;
    136       *(retval->data+offset+sizeof(int))=(unsigned char)sync.objectID;
    137       *(retval->data+offset+2*sizeof(int))=(unsigned char)sync.classID;
     166      memcpy(retval->data+offset, (void *)&sync.length, sizeof(int));
     167      //*(retval->data+offset)=sync.length;
     168      memcpy(retval->data+offset+sizeof(int), (void *)&sync.objectID, sizeof(int));
     169      //*(retval->data+offset+sizeof(int))=sync.objectID;
     170      memcpy(retval->data+offset+2*sizeof(int), (void *)&sync.classID, sizeof(int));
     171      //*(retval->data+offset+2*sizeof(int))=sync.classID;
    138172      // increase data pointer
    139173      offset+=tempsize+3*sizeof(int);
    140     }
    141     COUT(5) << "Gamestate size: " << totalsize << std::endl;
     174      //std::cout << "end inner loop" << std::endl;
     175    }
    142176    retval->size=totalsize;
     177    //#### bugfix
     178    retval->diffed = false;
     179    //std::cout << "end snapShot" << std::endl;
     180    COUT(5) << "G.ST.Man: Gamestate size: " << totalsize << std::endl;
    143181    return retval;
    144182  }
    145183
     184  //##### ADDED FOR TESTING PURPOSE #####
     185  GameStateCompressed* GameStateManager::testCompress( GameState* g ) {
     186    return compress_( g );
     187  }
     188
     189  GameState* GameStateManager::testDiff( GameState* a, GameState* b ) {
     190    return diff( a, b );
     191  }
     192  //##### END TESTING PURPOSE #####
     193
    146194  GameStateCompressed *GameStateManager::encode(GameState *a, GameState *b) {
     195    COUT(5) << "G.St.Man: this will be a DIFFED gamestate" << std::endl;
    147196    //GameState r = diff(a,b);
    148197    //r.diffed = true;
    149198    GameState *r = b;
    150199    r->diffed = false;
    151     return compress_(r);
     200    //return compress_(r);
     201    GameStateCompressed *g = new GameStateCompressed;
     202    g->base_id = b->base_id;
     203    g->id = b->id;
     204    g->diffed = b->diffed;
     205    g->data = b->data;
     206    g->normsize = b->size;
     207    g->compsize = b->size;
     208    return g;
    152209  }
    153210
    154211  GameStateCompressed *GameStateManager::encode(GameState *a) {
     212    COUT(5) << "G.St.Man: this will be a not diffed gamestate" << std::endl;
    155213    a->diffed=false;
    156     return compress_(a);
     214    GameStateCompressed *g = new GameStateCompressed;
     215    g->base_id = a->base_id;
     216    g->id = a->id;
     217    g->diffed = a->diffed;
     218    g->data = a->data;
     219    g->normsize = a->size;
     220    g->compsize = a->size;
     221    return g;
    157222  }
    158223
     
    189254    r->size = dest_length;
    190255    r->diffed = true;
     256    r->base_id = a->id;
    191257    r->data = dp;
    192258    return r;
     
    194260
    195261  GameStateCompressed *GameStateManager::compress_(GameState *a) {
    196     COUT(5) << "compressing gamestate" << std::endl;
     262    //COUT(4) << "G.St.Man: compressing gamestate" << std::endl;
     263
     264    //COUT(4) << "G.St.Man: a: id: " << a->id << " base_id: " << a->base_id << " size: " << a->size << " diffed: " << a->diffed << std::endl;
    197265    int size = a->size;
     266
    198267    uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
     268    //COUT(4) << "size: " << size << ", buffer: " << buffer << std::endl;
    199269    unsigned char* dest = (unsigned char*)malloc( buffer );
     270    //COUT(4) << "dest: " << dest << std::endl;
    200271    int retval;
    201272    //std::cout << "before ziped " << buffer << std::endl;
    202273    retval = compress( dest, &buffer, a->data, (uLong)size );
     274    //COUT(4) << "bloablabla aft3er compress" << std::endl;
    203275    //std::cout << "after ziped " << buffer << std::endl;
    204276
    205277    switch ( retval ) {
    206       case Z_OK: COUT(5) << "successfully compressed" << std::endl; break;
    207       case Z_MEM_ERROR: COUT(1) << "not enough memory available in gamestate.compress" << std::endl;
     278      case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
     279      case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl;
    208280      return NULL;
    209       case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer in gamestate.compress" << std::endl;
     281      case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
    210282      return NULL;
    211       case Z_DATA_ERROR: COUT(2) << "decompress: data corrupted in gamestate.compress" << std::endl;
     283      case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl;
    212284      return NULL;
    213285    }
     
    221293    compressedGamestate->data = dest;
    222294    compressedGamestate->diffed = a->diffed;
    223 
     295    compressedGamestate->base_id = a->base_id;
     296    //COUT(5) << "G.St.Man: saved compressed data in GameStateCompressed:" << std::endl;
    224297    return compressedGamestate;
    225298  }
  • code/branches/network2/src/network/GameStateManager.h

    r1062 r1098  
    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 ####
    7377    void update();
    7478    GameStateCompressed *popGameState(int clientID);
     
    7680    int id;
    7781  private:
     82    void cleanup(); // "garbage handler"
    7883    GameState *getSnapshot(int id);
    7984    GameStateCompressed *encode(GameState *a, GameState *b);
  • code/branches/network2/src/network/PacketBuffer.cc

    r1062 r1098  
    6161      last=first;
    6262      last->next=NULL;
    63       // change this!!!!!!!
     63      // change this!!!!!!! 
    6464      last->packet = ev->packet;
    65       last->address = ev->peer->address;
     65      //last->address = ev->peer->address;
    6666    } else {
    6767      //insert a new element at the bottom
     
    7272      // save the packet to the new element
    7373      last->packet = ev->packet;
    74       last->address = ev->peer->address;
     74      //last->address = ev->peer->address;
    7575    }
    76     return true;
     76    // pseudo bugfix: added a return false statement for error handling
     77    if ( last->packet == ev->packet ) return true;
     78    return false;
    7779  }
    7880
     81  //returns the first element in the list without deleting it but
     82  //moving first pointer to next element
    7983  ENetPacket *PacketBuffer::pop() {
    8084    boost::mutex::scoped_lock lock(networkPacketBufferMutex);
  • code/branches/network2/src/network/PacketDecoder.cc

    r1064 r1098  
    5454  {
    5555    int client = clientId;
    56     COUT(5) << "clientId: " << client << std::endl; //control cout, not important, just debugging info
     56    COUT(5) << "PacketDecoder: clientId: " << client << std::endl; //control cout, not important, just debugging info
    5757    int id = (int)*packet->data; //the first 4 bytes are always the enet packet id
    58     COUT(5) << "packet id: " << id << std::endl;
    59 //     COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl;
     58    COUT(5) << "PacketDecoder: packet id: " << id << std::endl;
     59    //COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl;
     60
     61    if ( packet == NULL ) {
     62      COUT(4) << "PacketDecoder: no packets->packetbuffer queue is empty" << std::endl;
     63      return false;
     64    }
    6065    switch( id ) {
    6166  case ACK:
     
    95100
    96101
    97     COUT(5) << "got ack id: " << a->id << std::endl;
     102    COUT(5) << "PacketDecoder: got ack id: " << a->id << std::endl;
    98103    processAck( a, clientId ); //debug info
    99104
     
    149154    currentState = new GameStateCompressed;
    150155    if(currentState == NULL){
    151       COUT(3) << "could not generate new GameStateCompressed" << std::endl;
     156      COUT(3) << "PacketDecoder: could not generate new GameStateCompressed" << std::endl;
    152157      return;
    153158    }
     
    159164    //currentState->id = *((int *)packet->data+sizeof(int));
    160165    memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) );
    161     COUT(5) << "decoder: received gs id: " << currentState->id << std::endl;
     166    COUT(5) << "PacketDecoder: received gs id: " << currentState->id << std::endl;
    162167//     std::cout << "id: " << currentState->id << std::endl;
    163168    //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th
     
    168173    //size of uncompressed data
    169174    memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) );
     175    memcpy( (void*)&(currentState->base_id), (const void*)(packet->data+4*sizeof( int )), sizeof( int ) );
    170176    //currentState->normsize = (int)*(data+3*sizeof(int));
    171177//     std::cout << "normsize. " << currentState->normsize << std::endl;
    172178    //since the packetgenerator was changed, due to a new parameter, change this function too
    173     memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+4*sizeof(int)), sizeof(bool));
     179    memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+5*sizeof(int)), sizeof(bool));
    174180    //currentState->diffed = (bool)*(data+4*sizeof(int));
    175181//     std::cout << "diffed: " << currentState->diffed << std::endl;
    176182    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
    177183    if(currentState->compsize==0)
    178       COUT(2) << "compsize is 0" << std::endl;
     184      COUT(2) << "PacketDecoder: compsize is 0" << std::endl;
    179185    currentState->data = (unsigned char*)(malloc( currentState->compsize ));
    180186    if(currentState->data==NULL)
    181       COUT(2) << "Gamestatepacket-decoder: memory leak" << std::endl;
     187      COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl;
    182188    //copy the GameStateCompressed data
    183189    //std::cout << "packet size (enet): " << packet->dataLength << std::endl;
     
    199205    void *data  = (void *)cid->message;
    200206    memcpy(data, (const void*)(packet->data+3*sizeof(int)), cid->length);
    201     COUT(4) << "classid: " << cid->clid << ", name: " << cid->message << std::endl;
     207    COUT(4) << "PacketDecoder: classid: " << cid->clid << ", name: " << cid->message << std::endl;
    202208    enet_packet_destroy( packet );
    203209    processClassid(cid);
     
    214220  void PacketDecoder::processGamestate( GameStateCompressed *state )
    215221  {
     222    COUT(5) << "PacketDecoder: processing Gamestate" << std::endl;
     223    //printGamestate( state );
    216224  }
    217225
  • code/branches/network2/src/network/PacketGenerator.cc

    r1062 r1098  
    5252  ENetPacket* PacketGenerator::acknowledgement( int state, int reliable )
    5353  {
    54     COUT(4) << "generating new acknowledgement, id: " << state << std::endl;
     54    COUT(4) << "PacketGenerator: generating new acknowledgement, id: " << state << std::endl;
    5555    ack* ackreq = new ack;
    5656    ackreq->id = ACK;
     
    6565  ENetPacket* PacketGenerator::mousem( double x, double y, int reliable )
    6666  {
    67     COUT(4) << "generating new mouse" << std::endl;
     67    COUT(4) << "PacketGenerator: generating new mouse" << std::endl;
    6868    mouse* mousemove = new mouse;
    6969    mousemove->id = MOUSE;
     
    7979  ENetPacket* PacketGenerator::keystrike( char press, int reliable )
    8080  {
    81     COUT(4) << "generating new keyboard" << std::endl;
     81    COUT(4) << "PacketGenerator: generating new keyboard" << std::endl;
    8282    keyboard* key = new keyboard;
    8383    key->id = KEYBOARD;
     
    115115    memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int));
    116116    memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int));
    117     memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->diffed), sizeof(bool));
    118     /*(int)*(data) = gid;
    119     (int)*(data+sizeof(int)) = states->id;
    120     //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream
    121     (int)*(data+2*sizeof(int)) = states->compsize;
    122     //this is the uncompressed size of GameStateCompressed data
    123     (int)*(data+3*sizeof(int)) = states->normsize;
    124     //since there is a new parameter inside GameStateCompressed, change this function to create packet
    125     (bool)*(data+4*sizeof(int)) = states->diffed;*/
     117    memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->base_id), sizeof(int));
     118    memcpy( (void*)(data+5*sizeof(int)), (const void*)&(states->diffed), sizeof(bool));
    126119    //place the GameStateCompressed data at the end of the enet datastream
    127     memcpy( (void*)(data+4*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize );
     120    memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize );
    128121    //create an enet packet with the generated bytestream
    129122    ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
     
    135128  {
    136129    unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
    137     std::cout << "classid: " << classid << ", name: " << classname << std::endl;
     130    std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl;
    138131    *(int *)data = CLASSID;
    139132    *((int *)data+1) = classname.length()+1;
  • code/branches/network2/src/network/PacketTypes.h

    r1056 r1098  
    6565    int size;                       //!< total size of data
    6666    // new ---- change functions
     67    int base_id;                  // if gamestate is diffed this is the id of the old gamestate (base)
    6768    bool diffed;
    6869    unsigned char *data;            //!< pointer to data
     
    8081    int normsize;                   //!< size of uncompressed data
    8182    // new ----- change functions
     83    int base_id;                  // if gamestate is diffed this is the id of the old gamestate (base)
    8284    bool diffed;
    8385    unsigned char *data;            //!< gamestate data
  • code/branches/network2/src/network/Server.cc

    r1062 r1098  
    124124  bool Server::sendMSG(const char *msg) {
    125125    ENetPacket *packet = packet_gen.chatMessage(msg);
    126     std::cout <<"adding Packets" << std::endl;
     126    COUT(4) <<"Server: adding Packets" << std::endl;
    127127    connection->addPacketAll(packet);
    128128    //std::cout <<"added packets" << std::endl;
    129129    if (connection->sendPackets()){
    130       std::cout << "Sucessfully" << std::endl;
     130      COUT(4) << "Server: Sucessfully" << std::endl;
    131131      return true;
    132132    }
     
    155155    while(!connection->queueEmpty()){
    156156      //std::cout << "Client " << clientID << " sent: " << std::endl;
     157      //clientID here is a reference to grab clientID from ClientInformation
    157158      packet = connection->getPacket(clientID);
    158       elaborate(packet, clientID);
     159      //if statement to catch case that packetbuffer is empty
     160      if( !elaborate(packet, clientID) )
     161        COUT(4) << "Server: PacketBuffer empty" << std::endl;
    159162    }
    160163  }
     
    165168  void Server::updateGamestate() {
    166169    gamestates->update();
     170    COUT(4) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
    167171    //std::cout << "updated gamestate, sending it" << std::endl;
    168172    //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
    169       sendGameState();
     173    sendGameState();
     174    COUT(4) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
    170175    //std::cout << "sent gamestate" << std::endl;
    171176  }
     
    175180  */
    176181  bool Server::sendGameState() {
    177     COUT(5) << "starting sendGameState" << std::endl;
     182    COUT(5) << "Server: starting function sendGameState" << std::endl;
    178183    ClientInformation *temp = clients;
    179184    bool added=false;
    180     while(temp!=NULL){
     185    while(temp != NULL){
    181186      if(temp->head){
    182187        temp=temp->next();
     188        //think this works without continue
    183189        continue;
    184190      }
    185191      if( !(temp->getSynched()) ){
    186         COUT(5) << "not sending gamestate" << std::endl;
     192        COUT(5) << "Server: not sending gamestate" << std::endl;
    187193        temp=temp->next();
     194        //think this works without continue
    188195        continue;
    189196      }
    190       COUT(5) << "doing gamestate gamestate preparation" << std::endl;
    191       int gid = temp->getGamestateID();
    192       int cid = temp->getID();
    193       COUT(5) << "server, got acked (gamestate) ID: " << gid << std::endl;
     197      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
     198      int gid = temp->getGamestateID(); //get gamestate id
     199      int cid = temp->getID(); //get client id
     200      COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl;
    194201      GameStateCompressed *gs = gamestates->popGameState(cid);
    195202      if(gs==NULL){
    196         COUT(2) << "could not generate gamestate" << std::endl;
     203        COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
    197204        return false;
    198205      }
    199206      //std::cout << "adding gamestate" << std::endl;
    200       connection->addPacket(packet_gen.gstate(gs), cid);
     207      if ( !(connection->addPacket(packet_gen.gstate(gs), cid)) )
     208        COUT(4) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;
    201209      //std::cout << "added gamestate" << std::endl;
    202210      added=true;
    203211      temp=temp->next();
    204212    }
    205     if(added)
     213    if(added) {
     214      //std::cout << "send gamestates from server.cc in sendGameState" << std::endl;
    206215      return connection->sendPackets();
    207     COUT(5) << "had no gamestates to send" << std::endl;
     216    }
     217    COUT(5) << "Server: had no gamestates to send" << std::endl;
    208218    return false;
    209219  }
    210220
    211221  void Server::processAck( ack *data, int clientID) {
    212     COUT(5) << "processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl;
     222    COUT(5) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl;
    213223    clients->findClient(clientID)->setGamestateID(data->a);
    214224  }
  • code/branches/network2/src/network/Synchronisable.cc

    r1062 r1098  
    5757    datasize=0;
    5858    objectID=idCounter++;
     59    syncList = new std::list<synchronisableVariable *>;
    5960    //registerAllVariables();
    6061  }
     
    7172  void Synchronisable::registerVar(const void *var, int size, variableType t){
    7273    // create temporary synch.Var struct
    73     synchronisableVariable temp={size, var, t};
     74    synchronisableVariable *temp = new synchronisableVariable;
     75    temp->size = size;
     76    temp->var = var;
     77    temp->type = t;
     78    COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl;
    7479    // increase datasize
    7580    datasize+=sizeof(int)+size;
    76     // push temp to syncList (at the bottom)
    77     syncList.push_back(temp);
     81    //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl;
     82    COUT(5) << "Syncronisable::objectID: " << objectID << " this: " << this << " name: " << this->getIdentifier()->getName() << " networkID: " << this->getIdentifier()->getNetworkID() << std::endl;
     83    syncList->push_back(temp);
    7884  }
    7985
     
    9197  //   int totalsize=0;
    9298  //   //figure out size of data to be allocated
    93   //   for(i=syncList.begin(); i!=syncList.end(); i++){
     99  //   for(i=syncList->begin(); i!=syncList->end(); i++){
    94100  //     // increase size (size of variable and size of size of variable ;)
    95101  //     if(i->type == STRING)
     
    107113  //   //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP
    108114  //   int n=0;
    109   //   for(i=syncList.begin(); n<totalsize && i!=syncList.end(); i++){
     115  //   for(i=syncList->begin(); n<totalsize && i!=syncList->end(); i++){
    110116  //     std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
    111117  //     n+=sizeof(int);
     
    134140  */
    135141  syncData Synchronisable::getData(unsigned char *mem){
    136     std::list<synchronisableVariable>::iterator i;
     142    //std::cout << "inside getData" << std::endl;
     143    std::list<synchronisableVariable *>::iterator i;
    137144    syncData retVal;
    138145    retVal.objectID=this->objectID;
     
    141148    retVal.data=mem;
    142149    // copy to location
    143     int n=0;
    144     for(i=syncList.begin(); n<datasize && i!=syncList.end(); ++i){
    145       //COUT(2) << "size of variable: " << i->size << std::endl;
     150    int n=0; //offset
     151    for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){
    146152      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
    147       memcpy( (void *)(retVal.data+n), (const void*)&(i->size), sizeof(int) );
     153      memcpy( (void *)(retVal.data+n), (const void *)&((*i)->size), sizeof(int) );
    148154      n+=sizeof(int);
    149       switch(i->type){
     155      switch((*i)->type){
    150156      case DATA:
    151         std::memcpy( (void *)(retVal.data+n), (const void*)(i->var), i->size);
    152         n+=i->size;
     157        std::memcpy( (void *)(retVal.data+n), (const void*)((*i)->var), (*i)->size);
     158        n+=(*i)->size;
    153159        break;
    154160      case STRING:
    155         std::memcpy( retVal.data+n, (const void*)( ( (std::string *) i->var)->c_str()), ( (std::string *)i->var )->length()+1);
    156         n+=((std::string *) i->var)->length()+1;
     161        std::memcpy( retVal.data+n, (const void*)( ( (std::string *) (*i)->var)->c_str()), (*i)->size);
     162        n+=(*i)->size;
    157163        break;
    158164      }
     
    168174  bool Synchronisable::updateData(syncData vars){
    169175    unsigned char *data=vars.data;
    170     std::list<synchronisableVariable>::iterator i;
    171     for(i=syncList.begin(); i!=syncList.end(); i++){
    172       if((int)*data==i->size || i->type==STRING){
    173         switch(i->type){
    174       case DATA:
    175         data+=sizeof(int);
    176         memcpy((void*)i->var, data, i->size);
    177         data+=i->size;
    178         break;
    179       case STRING:
    180         i->size = (int)*data;
    181         data+=sizeof(int);
    182         *((std::string *)i->var) = std::string((const char*)data);
    183         data += i->size;
    184         break;
     176    std::list<synchronisableVariable *>::iterator i;
     177    if(syncList->empty()){
     178      COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
     179      return false;
     180    }
     181    COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " synchronising data" << std::endl;
     182    for(i=syncList->begin(); i!=syncList->end(); i++){
     183      COUT(5) << "element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
     184      if(*(int *)data==(*i)->size || (*i)->type==STRING){
     185        switch((*i)->type){
     186        case DATA:
     187          data+=sizeof(int);
     188          memcpy((void*)(*i)->var, data, (*i)->size);
     189          data+=(*i)->size;
     190          break;
     191        case STRING:
     192          (*i)->size = *(int *)data;
     193          data+=sizeof(int);
     194          *((std::string *)((*i)->var)) = std::string((const char*)data);
     195          data += (*i)->size;
     196          break;
    185197        }
    186198      } else
     
    196208  int Synchronisable::getSize(){
    197209    int tsize=0;
    198     std::list<synchronisableVariable>::iterator i;
    199     for(i=syncList.begin(); i!=syncList.end(); i++){
    200       switch(i->type){
    201     case DATA:
    202       tsize+=sizeof(int);
    203       tsize+=i->size;
    204       break;
    205     case STRING:
    206       tsize+=sizeof(int);
    207       tsize+=((std::string *)i->var)->length()+1;
    208       break;
     210    std::list<synchronisableVariable *>::iterator i;
     211    for(i=syncList->begin(); i!=syncList->end(); i++){
     212      switch((*i)->type){
     213      case DATA:
     214        tsize+=sizeof(int);
     215        tsize+=(*i)->size;
     216        break;
     217      case STRING:
     218        tsize+=sizeof(int);
     219        (*i)->size=((std::string *)(*i)->var)->length()+1;
     220        tsize+=(*i)->size;
     221        break;
    209222      }
    210223    }
  • code/branches/network2/src/network/Synchronisable.h

    r1062 r1098  
    7575  public:
    7676
    77       virtual ~Synchronisable();
     77    virtual ~Synchronisable();
    7878    int objectID;
    7979    int classID;
     
    9191    /*  bool removeObject(Iterator<Synchronisable> it);*/
    9292
    93     std::list<SYNCVAR> syncList;
     93    std::list<synchronisableVariable *> *syncList;
    9494    int datasize;
    9595  };
  • code/branches/network2/src/orxonox/Orxonox.cc

    r1092 r1098  
    305305    hudOverlay->show();
    306306
    307     client_g->establishConnection();
     307    if( !client_g->establishConnection() )
     308      COUT(1) <<"CLIENT COULD NOT ESTABLISH CONNECTION" << std::endl;
    308309    client_g->tick(0);
    309310
  • code/branches/network2/src/orxonox/objects/Ambient.cc

    r1064 r1098  
    5757        RegisterObject(Ambient);
    5858        Ambient::instance_s = this;
     59        registerAllVariables();
    5960    }
    6061
     
    6364    }
    6465
     66    bool Ambient::create(){
     67      Orxonox::getSingleton()->getSceneManager()->setAmbientLight(ambientLight_);
     68      return true;
     69    }
     70   
     71    void Ambient::registerAllVariables(){
     72      registerVar(&ambientLight_, sizeof(ColourValue), network::DATA);
     73     
     74    }
     75   
    6576    void Ambient::loadParams(TiXmlElement* xmlElem)
    6677    {
     
    8394   {
    8495        GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour);
     96      ambientLight_=colour;     
    8597   }
    8698
     
    96108
    97109        XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, mode);
     110        create();
    98111    }
    99112}
  • code/branches/network2/src/orxonox/objects/Ambient.h

    r1056 r1098  
    3434#include "util/Math.h"
    3535#include "core/BaseObject.h"
     36#include "network/Synchronisable.h"
    3637
    3738namespace orxonox
    3839{
    39     class _OrxonoxExport Ambient : public BaseObject
     40    class _OrxonoxExport Ambient : public BaseObject, network::Synchronisable
    4041    {
    4142        public:
     
    4647            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4748            void setAmbientLight(const ColourValue& colour);
     49            bool create();
     50            void registerAllVariables();
    4851
    4952            static void setAmbientLightTest(const ColourValue& colour)
     
    5255        private:
    5356            static Ambient* instance_s;
     57            ColourValue ambientLight_;
    5458
    5559    };
  • code/branches/network2/src/orxonox/objects/Model.cc

    r1064 r1098  
    8282
    8383    bool Model::create(){
    84       WorldEntity::create();
     84      if(!WorldEntity::create())
     85        return false;
    8586      if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0))
    8687      {
    8788        this->mesh_.setMesh(meshSrc_);
    8889        this->attachObject(this->mesh_.getEntity());
    89         COUT(4) << "Loader: Created model" << std::endl;
     90        COUT(4) << "Loader (Model.cc): Created model" << std::endl;
    9091      }
    9192      return true;
     
    9394
    9495    void Model::registerAllVariables(){
    95       WorldEntity::registerAllVariables();
     96//       WorldEntity::registerAllVariables();
     97      COUT(5) << "Model.cc:registering new meshsrc with size: " << meshSrc_.length()+1 << " this: " << this << std::endl;
    9698      registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING);
    9799    }
  • code/branches/network2/src/orxonox/objects/NPC.cc

    r1056 r1098  
    4040    RegisterObject(NPC);
    4141    movable_ = true;
     42    registerAllVariables();
    4243  }
    4344
     
    5960    this->translate(location);
    6061    movable_ = movable;
     62  }
     63 
     64  void NPC::registerAllVariables(){
     65    Model::registerAllVariables();
     66    registerVar(&movable_, sizeof(movable_), network::DATA);
     67  }
     68 
     69  bool NPC::create(){
     70    Model::create();
     71    return true;
    6172  }
    6273
  • code/branches/network2/src/orxonox/objects/NPC.h

    r1056 r1098  
    5252      void update();
    5353      void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable);
     54      void registerAllVariables();
     55      bool create();
    5456
    5557    private:
  • code/branches/network2/src/orxonox/objects/Skybox.cc

    r1064 r1098  
    4747    {
    4848        RegisterObject(Skybox);
     49        registerAllVariables();
    4950    }
    5051
     
    5758        if (xmlElem->Attribute("src"))
    5859        {
    59                 std::string skyboxSrc = xmlElem->Attribute("src");
    60                 this->setSkybox(skyboxSrc);
     60                skyboxSrc_ = xmlElem->Attribute("src");
     61        this->create();
    6162
    62                 COUT(4) << "Loader: Set skybox: "<< skyboxSrc << std::endl << std::endl;
     63                COUT(4) << "Loader: Set skybox: "<< skyboxSrc_ << std::endl << std::endl;
    6364        }
    6465   }
     
    6970   }
    7071
     72   void Skybox::setSkyboxSrc(std::string src){
     73     skyboxSrc_ = src;
     74   }
     75   
    7176    /**
    7277        @brief XML loading and saving.
     
    8085
    8186        XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, mode);
     87        XMLPortParamLoadOnly(Skybox, "src", setSkyboxSrc, xmlelement, loading);
     88        create();
    8289    }
     90   
     91    bool Skybox::create(){
     92      this->setSkybox(skyboxSrc_);
     93      return true;
     94    }
     95   
     96    void Skybox::registerAllVariables(){
     97      registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING);
     98    }
     99   
    83100}
  • code/branches/network2/src/orxonox/objects/Skybox.h

    r1056 r1098  
    3333
    3434#include "core/BaseObject.h"
     35#include "network/Synchronisable.h"
    3536
    3637namespace orxonox
    3738{
    38     class _OrxonoxExport Skybox : public BaseObject
     39    class _OrxonoxExport Skybox : public BaseObject, public network::Synchronisable
    3940    {
    4041        public:
     
    4546            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4647            void setSkybox(const std::string& skyboxname);
     48           
     49            bool create();
     50            void registerAllVariables();
     51            void setSkyboxSrc(std::string src);
    4752
    4853        private:
     54            std::string skyboxSrc_;
    4955
    5056
  • code/branches/network2/src/orxonox/objects/WorldEntity.cc

    r1064 r1098  
    7272        }
    7373    }
     74   
    7475
    7576    WorldEntity::~WorldEntity()
     
    162163*/
    163164    }
     165   
    164166
    165167    void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll)
     
    188190
    189191        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
     192       
     193        //create();
    190194    }
    191195
Note: See TracChangeset for help on using the changeset viewer.