Changeset 247 for code/branches/network/src
- Timestamp:
- Nov 25, 2007, 11:06:13 PM (17 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Makefile
r237 r247 29 29 Synchronisable.o: Synchronisable.cc 30 30 ${CC} -c Synchronisable.cc -g ${INC} 31 GameStateManager.o: GameStateManager.cc 32 ${CC} -c GameStateManager.cc -g ${INC} 31 33 32 34 clean: -
code/branches/network/src/network/Makefile.tardis
r237 r247 28 28 PacketDecoder.o: PacketDecoder.cc 29 29 ${CC} -c PacketDecoder.cc -o PacketDecoder.o -g ${INC} 30 Synchronisable.o: Synchronisable.cc 31 ${CC} -c Synchronisable.cc -g ${INC} 32 GameStateManager.o: GameStateManager.cc 33 ${CC} -c GameStateManager.cc -g ${INC} 30 34 31 35 clean: -
code/branches/network/src/network/Synchronisable.cc
r245 r247 5 5 // 6 6 // 7 // Author: Oliver Scheuss, (C) 20077 // Author: Dumeni, Oliver Scheuss, (C) 2007 8 8 // 9 9 // Copyright: See COPYING file that comes with this distribution … … 14 14 namespace network { 15 15 16 /** 17 * Constructor: 18 * calls registarAllVariables, that has to be implemented by the inheriting classID 19 */ 16 20 Synchronisable::Synchronisable() 17 21 { 22 datasize=0; 18 23 registerAllVariables(); 19 24 } … … 25 30 } 26 31 32 /** 33 * This function is used to register a variable to be synchronized 34 * also counts the total datasize needed to save the variables 35 * @param var pointer to the variable 36 * @param size size of the datatype the variable consists of 37 */ 27 38 void Synchronisable::registerVar(const void *var, int size){ 39 // create temporary synch.Var struct 28 40 synchronisableVariable temp={size, var}; 41 // increase datasize 42 datasize+=sizeof(int)+size; 43 // push temp to syncList (at the bottom) 29 44 syncList.push_back(temp); 30 45 } 46 47 /** 48 * note: only use this function for debug use, because it's inefficient (in order to produce a gamestate, you have to copy the whole data again to another memory location after this process) 49 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct 50 * structure of the bitstream: 51 * (var1_size,var1,var2_size,var2,...) 52 * varx_size: size = sizeof(int) 53 * varx: size = varx_size 54 * @return data containing all variables and their sizes 55 */ 31 56 syncData Synchronisable::getData(){ 32 57 std::list<synchronisableVariable>::iterator i; … … 56 81 return retVal; 57 82 } 83 /** 84 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct 85 * Difference to the above function: 86 * takes a pointer to already allocated memory (must have at least getSize bytes length) 87 * structure of the bitstream: 88 * (var1_size,var1,var2_size,var2,...) 89 * varx_size: size = sizeof(int) 90 * varx: size = varx_size 91 * @return data containing all variables and their sizes 92 */ 93 syncData Synchronisable::getData(unsigned char *mem){ 94 std::list<synchronisableVariable>::iterator i; 95 syncData retVal; 96 retVal.objectID=this->objectID; 97 retVal.classID=this->classID; 98 retVal.length=datasize; 99 retVal.data=mem; 100 // copy to location 101 //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP 102 int n=0; 103 for(i=syncList.begin(); n<datasize && i!=syncList.end(); i++){ 104 //CHANGED: i->size TO (const void*)(&(i->size)) memcpy WANTS A CONST VOID* SO CONVERT INT TO CONST VOID* 105 std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int)); 106 n+=sizeof(int); 107 //CHANGED: i->var TO (const void*)(&(i->var)) SINCE var IS A POINTER, NO & BEFORE i 108 std::memcpy(retVal.data+n, (const void*)(i->var), i->size); 109 n+=i->size; 110 } 111 return retVal; 112 } 113 114 /** 115 * This function takes a syncData struct and takes it to update the variables 116 * @param vars data of the variables 117 * @return true/false 118 */ 58 119 bool Synchronisable::updateData(syncData vars){ 59 120 unsigned char *data=vars.data; … … 70 131 } 71 132 133 /** 134 * This function returns the total amount of bytes needed by getData to save the whole content of the variables 135 * @return amount of bytes 136 */ 137 int Synchronisable::getSize(){ 138 return datasize; 72 139 } 140 141 } -
code/branches/network/src/network/Synchronisable.h
r237 r247 10 10 // 11 11 // 12 #ifndef NETWORK SYNCHRONISABLE_H13 #define NETWORK SYNCHRONISABLE_H12 #ifndef NETWORK_SYNCHRONISABLE_H 13 #define NETWORK_SYNCHRONISABLE_H 14 14 15 15 #include <list> … … 46 46 void registerVar(const void *var, int size); 47 47 syncData getData(); 48 syncData getData(unsigned char *mem); 49 int getSize(); 48 50 bool updateData(syncData vars); 49 51 virtual void registerAllVariables(); … … 51 53 private: 52 54 std::list<SYNCVAR> syncList; 55 int datasize; 53 56 }; 54 57
Note: See TracChangeset
for help on using the changeset viewer.