Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 237


Ignore:
Timestamp:
Nov 21, 2007, 6:08:34 PM (17 years ago)
Author:
scheusso
Message:

synchronisable

Location:
code/branches/network/src/network
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/Makefile

    r230 r237  
    2727Server.o: Server.cc
    2828        ${CC} -c Server.cc -g ${INC}
     29Synchronisable.o: Synchronisable.cc
     30        ${CC} -c Synchronisable.cc -g ${INC}
    2931
    3032clean:
  • code/branches/network/src/network/Makefile.tardis

    r200 r237  
    11all: server client
    22
    3 CC=g++-3.4
     3CC=g++-4.1.1
    44
    5 BOOST_INC=/usr/pack/boost-1.33.1-mo/i686-debian-linux3.1/include/
    6 BOOST_LIB=/usr/pack/boost-1.33.1-mo/i686-debian-linux3.1/lib/
     5BOOST_INC=/usr/pack/boost-1.34.1-sd/i686-debian-linux3.1/include/boost-1_34_1/
     6BOOST_LIB=/usr/pack/boost-1.34.1-sd/i686-debian-linux3.1/lib/
    77MAIN_INC=..
    88ENET_INC=/usr/pack/enet-2007-sd/include/
     
    1212
    1313# Link command:
    14 server: clean PacketBuffer.o ConnectionManager.o dummyserver.o
    15         ${CC} ConnectionManager.o dummyserver.o PacketBuffer.o -o server -lenet -lboost_thread-gcc-mt -g ${INC} ${LIB} -Wl,-rpath,${BOOST_LIB} -Wl,-rpath,${ENET_LIB}
     14server: clean PacketBuffer.o ConnectionManager.o dummyserver.o PacketGenerator.o PacketDecoder.o
     15        ${CC} ConnectionManager.o dummyserver.o PacketBuffer.o PacketDecoder.o PacketGenerator.o -o server -lenet -lboost_thread-gcc41-mt -g ${INC} ${LIB} -Wl,-rpath,${BOOST_LIB} -Wl,-rpath,${ENET_LIB}
    1616
    1717dummyserver.o:
    18         ${CC} -c dummyserver.cc -o dummyserver.o -g ${INC} -pthread
     18        ${CC} -c dummyserver.cc -o dummyserver.o -g ${INC}
    1919# Compilation commands:
    2020
    2121ConnectionManager.o:
    22         ${CC} -c ConnectionManager.cc -o ConnectionManager.o -g ${INC} -pthread
     22        ${CC} -c ConnectionManager.cc -o ConnectionManager.o -g ${INC}
    2323
    2424PacketBuffer.o:
    25         ${CC} -c PacketBuffer.cc -o PacketBuffer.o -g ${INC} -pthread
     25        ${CC} -c PacketBuffer.cc -o PacketBuffer.o -g ${INC}
     26PacketGenerator.o: PacketGenerator.cc
     27        ${CC} -c PacketGenerator.cc -o PacketGenerator.o -g ${INC}
     28PacketDecoder.o: PacketDecoder.cc
     29        ${CC} -c PacketDecoder.cc -o PacketDecoder.o -g ${INC}
    2630
    2731clean:
    2832        rm -rf *.o
    2933
    30 client:
    31         ${CC} dummyclient.cc -o client -lenet ${LIB} ${INC} -Wl,-rpath,${BOOST_LIB} -pthread
     34client: dummyclient.cc PacketDecoder.o PacketGenerator.o
     35        ${CC} PacketGenerator.o PacketDecoder.o dummyclient.cc -o client -lenet ${LIB} ${INC} -Wl,-rpath,${BOOST_LIB}
  • code/branches/network/src/network/PacketDecoder.cc

    r223 r237  
    100100{
    101101        cout << "data id: " << data->id << endl;
     102        cout << "blablabla" << endl;
    102103        cout << "data:    " << data->message << endl;
    103104}
  • code/branches/network/src/network/Synchronisable.cc

    r230 r237  
    1616Synchronisable::Synchronisable()
    1717{
     18  registerAllVariables();
    1819}
    1920
     
    2122Synchronisable::~Synchronisable()
    2223{
     24 
    2325}
    2426
     27void Synchronisable::registerVar(const void *var, int size){
     28  synchronisableVariable temp={size, var};
     29  syncList.push_back(temp);
     30}
     31syncData Synchronisable::getData(){
     32  std::list<synchronisableVariable>::iterator i;
     33  int totalsize=0;
     34  //figure out size of data to be allocated
     35  for(i=syncList.begin(); i!=syncList.end(); i++){
     36    // increase size (size of variable and size of size of variable ;)
     37    totalsize+=sizeof(int)+i->size;
     38  }
     39  syncData retVal;
     40  retVal.objectID=this->objectID;
     41  retVal.classID=this->classID;
     42  retVal.length=totalsize;
     43  // allocate memory
     44  retVal.data = (unsigned char *)malloc(totalsize);
     45  // copy to location
     46  for(int n=0, i=syncList.begin(); n<totalsize && i!=syncList.end(); i++){
     47    std::memcpy(retVal.data+n, i->size, sizeof(int));
     48    n+=sizeof(int);
     49    std::memcpy(retVal.data+n, *(*i.var), *i.size);
     50    n+=i->size;
     51  }
     52  return retVal;
     53}
     54bool Synchronisable::updateData(syncData vars){
     55  unsigned char *data=vars.data;
     56  std::list<synchronisableVariable>::iterator i;
     57  for(i=syncList.begin(); i!=syncList.end(); i++){
     58    if((int)*data==i->size){
     59      data+=sizeof(int);
     60      memcpy(i->data, data, i->size);
     61      data+=i->size;
     62    } else
     63      return false; //there was some problem with registerVar
     64  }
     65}
    2566
    2667}
  • code/branches/network/src/network/Synchronisable.h

    r230 r237  
    1313#define NETWORKSYNCHRONISABLE_H
    1414
     15#include <list>
     16
    1517namespace network {
    1618
     19 
     20struct syncData{
     21  int length;
     22  int classID;
     23  int objectID;
     24  unsigned char *data;
     25};
     26
     27typedef struct synchronisableVariable{
     28  int size;
     29  const void *var;
     30}SYNCVAR;
     31
     32 
    1733/**
    1834 * This class is the base class of all the Objects in the universe that need to be synchronised over the network
     
    2238class Synchronisable{
    2339public:
    24     Synchronisable();
     40  Synchronisable();
    2541
    26     ~Synchronisable();
     42  ~Synchronisable();
     43  int objectID;
     44  int classID;
     45   
     46  void registerVar(const void *var, int size);
     47  syncData getData();
     48  bool updateData(syncData vars);
     49  virtual void registerAllVariables();
    2750
     51private:
     52  std::list<SYNCVAR> syncList;
    2853};
    2954
Note: See TracChangeset for help on using the changeset viewer.