- Timestamp:
- Nov 21, 2007, 6:08:34 PM (17 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Makefile
r230 r237 27 27 Server.o: Server.cc 28 28 ${CC} -c Server.cc -g ${INC} 29 Synchronisable.o: Synchronisable.cc 30 ${CC} -c Synchronisable.cc -g ${INC} 29 31 30 32 clean: -
code/branches/network/src/network/Makefile.tardis
r200 r237 1 1 all: server client 2 2 3 CC=g++- 3.43 CC=g++-4.1.1 4 4 5 BOOST_INC=/usr/pack/boost-1.3 3.1-mo/i686-debian-linux3.1/include/6 BOOST_LIB=/usr/pack/boost-1.3 3.1-mo/i686-debian-linux3.1/lib/5 BOOST_INC=/usr/pack/boost-1.34.1-sd/i686-debian-linux3.1/include/boost-1_34_1/ 6 BOOST_LIB=/usr/pack/boost-1.34.1-sd/i686-debian-linux3.1/lib/ 7 7 MAIN_INC=.. 8 8 ENET_INC=/usr/pack/enet-2007-sd/include/ … … 12 12 13 13 # 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}14 server: 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} 16 16 17 17 dummyserver.o: 18 ${CC} -c dummyserver.cc -o dummyserver.o -g ${INC} -pthread18 ${CC} -c dummyserver.cc -o dummyserver.o -g ${INC} 19 19 # Compilation commands: 20 20 21 21 ConnectionManager.o: 22 ${CC} -c ConnectionManager.cc -o ConnectionManager.o -g ${INC} -pthread22 ${CC} -c ConnectionManager.cc -o ConnectionManager.o -g ${INC} 23 23 24 24 PacketBuffer.o: 25 ${CC} -c PacketBuffer.cc -o PacketBuffer.o -g ${INC} -pthread 25 ${CC} -c PacketBuffer.cc -o PacketBuffer.o -g ${INC} 26 PacketGenerator.o: PacketGenerator.cc 27 ${CC} -c PacketGenerator.cc -o PacketGenerator.o -g ${INC} 28 PacketDecoder.o: PacketDecoder.cc 29 ${CC} -c PacketDecoder.cc -o PacketDecoder.o -g ${INC} 26 30 27 31 clean: 28 32 rm -rf *.o 29 33 30 client: 31 ${CC} dummyclient.cc -o client -lenet ${LIB} ${INC} -Wl,-rpath,${BOOST_LIB} -pthread34 client: 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 100 100 { 101 101 cout << "data id: " << data->id << endl; 102 cout << "blablabla" << endl; 102 103 cout << "data: " << data->message << endl; 103 104 } -
code/branches/network/src/network/Synchronisable.cc
r230 r237 16 16 Synchronisable::Synchronisable() 17 17 { 18 registerAllVariables(); 18 19 } 19 20 … … 21 22 Synchronisable::~Synchronisable() 22 23 { 24 23 25 } 24 26 27 void Synchronisable::registerVar(const void *var, int size){ 28 synchronisableVariable temp={size, var}; 29 syncList.push_back(temp); 30 } 31 syncData 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 } 54 bool 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 } 25 66 26 67 } -
code/branches/network/src/network/Synchronisable.h
r230 r237 13 13 #define NETWORKSYNCHRONISABLE_H 14 14 15 #include <list> 16 15 17 namespace network { 16 18 19 20 struct syncData{ 21 int length; 22 int classID; 23 int objectID; 24 unsigned char *data; 25 }; 26 27 typedef struct synchronisableVariable{ 28 int size; 29 const void *var; 30 }SYNCVAR; 31 32 17 33 /** 18 34 * This class is the base class of all the Objects in the universe that need to be synchronised over the network … … 22 38 class Synchronisable{ 23 39 public: 24 40 Synchronisable(); 25 41 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(); 27 50 51 private: 52 std::list<SYNCVAR> syncList; 28 53 }; 29 54
Note: See TracChangeset
for help on using the changeset viewer.