Changeset 9406 in orxonox.OLD for trunk/src/lib/network/synchronizeable_var
- Timestamp:
- Jul 24, 2006, 11:09:47 AM (18 years ago)
- Location:
- trunk/src/lib/network/synchronizeable_var
- Files:
-
- 15 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/synchronizeable_var/synchronizeable_bool.cc
r7954 r9406 16 16 17 17 #include "synchronizeable_bool.h" 18 #include <cassert> 18 19 19 20 … … 44 45 { 45 46 assert( maxLength >= 1 ); 46 47 47 48 buf[0] = ( *vPtrIn ) ? 1 : 0; 48 49 49 50 return 1; 50 51 } … … 59 60 { 60 61 assert( maxLength >= 1 ); 61 62 62 63 bool oldVal = *vPtrOut; 63 64 64 65 *vPtrOut = buf[0] != 0; 65 66 66 67 setHasChanged( oldVal != *vPtrOut ); 67 68 68 69 return 1; 69 70 } -
trunk/src/lib/network/synchronizeable_var/synchronizeable_bool.h
r7954 r9406 2 2 * @file synchronizeable_int.h 3 3 * @brief Definition of SynchronizeableInt 4 */ 5 6 #include "synchronizeable_var/synchronizeable_var.h" 4 */ 7 5 8 6 #ifndef _SYNCHRONIZEABLE_BOOL_H 9 7 #define _SYNCHRONIZEABLE_BOOL_H 10 8 9 #include "synchronizeable_var.h" 10 11 11 class SynchronizeableBool : public SynchronizeableVar { 12 12 13 13 public: 14 SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );14 SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 15 15 virtual ~SynchronizeableBool(); 16 16 17 17 virtual int writeToBuf( byte * buf, int maxLength ); 18 18 virtual int readFromBuf( byte * buf, int maxLength ); 19 19 20 20 /** 21 21 * check if writeToBuf will return the same size every time … … 23 23 */ 24 24 virtual bool hasStaticSize(){ return true; }; 25 25 26 26 virtual void debug(); 27 27 28 28 private: 29 29 bool * vPtrIn; //!< pointer to data (read) -
trunk/src/lib/network/synchronizeable_var/synchronizeable_float.cc
r7954 r9406 17 17 #include "synchronizeable_float.h" 18 18 #include "converter.h" 19 #include <cassert> 19 20 20 21 … … 46 47 { 47 48 int res = Converter::floatToByteArray( *vPtrIn, buf, maxLength ); 48 49 49 50 assert( res == FLOATSIZE ); 50 51 51 52 return res; 52 53 } … … 61 62 { 62 63 assert( maxLength >= FLOATSIZE ); 63 64 64 65 float oldVal = *vPtrOut; 65 66 66 67 int res = Converter::byteArrayToFloat( buf, vPtrOut ); 67 68 68 69 setHasChanged( oldVal != *vPtrOut ); 69 70 70 71 assert( res == FLOATSIZE ); 71 72 72 73 return res; 73 74 } -
trunk/src/lib/network/synchronizeable_var/synchronizeable_float.h
r7954 r9406 2 2 * @file synchronizeable_float.h 3 3 * @brief Definition of SynchronizeableFloat 4 */4 */ 5 5 6 #include "synchronizeable_var/synchronizeable_var.h"7 6 8 7 #ifndef _SYNCHRONIZEABLE_FLOAT_H 9 8 #define _SYNCHRONIZEABLE_FLOAT_H 10 9 10 #include "synchronizeable_var.h" 11 11 12 class SynchronizeableFloat : public SynchronizeableVar { 12 13 13 14 public: 14 SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );15 SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 15 16 virtual ~SynchronizeableFloat(); 16 17 17 18 virtual int writeToBuf( byte * buf, int maxLength ); 18 19 virtual int readFromBuf( byte * buf, int maxLength ); 19 20 20 21 /** 21 22 * check if writeToBuf will return the same size every time … … 23 24 */ 24 25 virtual bool hasStaticSize(){ return true; }; 25 26 26 27 virtual void debug(); 27 28 28 29 private: 29 30 float * vPtrIn; //!< pointer to data (read) -
trunk/src/lib/network/synchronizeable_var/synchronizeable_int.cc
r7954 r9406 18 18 #include "converter.h" 19 19 20 #include <cassert> 20 21 21 22 /** … … 46 47 { 47 48 int res = Converter::intToByteArray( *vPtrIn, buf, maxLength ); 48 49 49 50 assert( res == INTSIZE ); 50 51 51 52 return res; 52 53 } … … 61 62 { 62 63 assert( maxLength >= INTSIZE ); 63 64 64 65 int oldVal = *vPtrOut; 65 66 66 67 int res = Converter::byteArrayToInt( buf, vPtrOut ); 67 68 68 69 setHasChanged( oldVal != *vPtrOut ); 69 70 70 71 assert( res == INTSIZE ); 71 72 72 73 return res; 73 74 } -
trunk/src/lib/network/synchronizeable_var/synchronizeable_int.h
r7954 r9406 4 4 */ 5 5 6 #include "synchronizeable_var/synchronizeable_var.h"7 6 8 7 #ifndef _SYNCHRONIZEABLE_INT_H 9 8 #define _SYNCHRONIZEABLE_INT_H 10 9 10 #include "synchronizeable_var.h" 11 11 12 class SynchronizeableInt : public SynchronizeableVar { 12 13 13 14 public: 14 SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );15 SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 15 16 virtual ~SynchronizeableInt(); 16 17 17 18 virtual int writeToBuf( byte * buf, int maxLength ); 18 19 virtual int readFromBuf( byte * buf, int maxLength ); 19 20 20 21 /** 21 22 * check if writeToBuf will return the same size every time … … 23 24 */ 24 25 virtual bool hasStaticSize(){ return true; }; 25 26 26 27 virtual void debug(); 27 28 28 29 protected: 29 30 int * vPtrIn; //!< pointer to data (read) -
trunk/src/lib/network/synchronizeable_var/synchronizeable_quaternion.cc
r7954 r9406 17 17 #include "synchronizeable_quaternion.h" 18 18 #include "converter.h" 19 #include <cassert> 19 20 20 21 … … 98 99 assert( res > 0 ); 99 100 n += res; 100 101 101 102 Quaternion oldVal = *vPtrOut; 102 103 103 104 *vPtrOut = Quaternion( Vector(x, y, z), w ); 104 105 105 106 setHasChanged( ! ( oldVal == *vPtrOut ) ); 106 107 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_quaternion.h
r7954 r9406 4 4 */ 5 5 6 #include "synchronizeable_var/synchronizeable_var.h"7 8 6 #ifndef _SYNCHRONIZEABLE_QUATERNION_H 9 7 #define _SYNCHRONIZEABLE_QUATERNION_H 8 9 #include "synchronizeable_var.h" 10 10 11 11 #include "quaternion.h" … … 14 14 15 15 public: 16 SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );16 SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 17 17 virtual ~SynchronizeableQuaternion(); 18 18 19 19 virtual int writeToBuf( byte * buf, int maxLength ); 20 20 virtual int readFromBuf( byte * buf, int maxLength ); 21 21 22 22 /** 23 23 * check if writeToBuf will return the same size every time … … 25 25 */ 26 26 virtual bool hasStaticSize(){ return true; }; 27 27 28 28 virtual void debug(); 29 29 30 30 private: 31 31 Quaternion * vPtrIn; //!< pointer to data (read) -
trunk/src/lib/network/synchronizeable_var/synchronizeable_string.cc
r8147 r9406 17 17 #include "synchronizeable_string.h" 18 18 #include "converter.h" 19 #include <cassert> 19 20 20 21 … … 46 47 { 47 48 int res = Converter::stringToByteArray( *vPtrIn, buf, maxLength ); 48 49 49 50 assert( res > 0 ); 50 51 assert( res == vPtrIn->length()+INTSIZE ); 51 52 52 53 return res; 54 } 55 56 int SynchronizeableString::getSize() 57 { 58 return vPtrIn->length()+INTSIZE; 53 59 } 54 60 … … 62 68 { 63 69 std::string oldVal = *vPtrOut; 64 70 65 71 int res = Converter::byteArrayToString( buf, *vPtrOut, maxLength ); 66 72 67 73 setHasChanged( oldVal != *vPtrOut ); 68 74 69 75 if ( res < 0 ) 70 76 { … … 72 78 } 73 79 assert( res > 0 ); 74 80 75 81 return res; 76 82 } … … 94 100 { 95 101 std::string t; 96 102 97 103 int res = Converter::byteArrayToString( buf, t, maxLength ); 98 104 99 105 assert( res > 0 ); 100 106 101 107 return res; 102 108 } -
trunk/src/lib/network/synchronizeable_var/synchronizeable_string.h
r7954 r9406 4 4 */ 5 5 6 #include "synchronizeable_var/synchronizeable_var.h"7 #include "converter.h"8 9 6 #ifndef _SYNCHRONIZEABLE_STRING_H 10 7 #define _SYNCHRONIZEABLE_STRING_H 8 9 #include "synchronizeable_var.h" 11 10 12 11 #include <string> … … 15 14 16 15 public: 17 SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );16 SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 18 17 virtual ~SynchronizeableString(); 19 18 20 19 virtual int writeToBuf( byte * buf, int maxLength ); 21 20 virtual int readFromBuf( byte * buf, int maxLength ); 22 23 21 22 24 23 /** 25 24 * check if writeToBuf will return the same size every time … … 27 26 */ 28 27 virtual bool hasStaticSize(){ return false; }; 29 30 virtual int getSize() { return vPtrIn->length()+INTSIZE; }31 28 29 virtual int getSize(); 30 32 31 virtual int getSizeFromBuf( byte * buf, int maxLength ); 33 32 34 33 virtual void debug(); 35 34 36 35 private: 37 36 std::string * vPtrIn; //!< pointer to data (read) -
trunk/src/lib/network/synchronizeable_var/synchronizeable_uint.h
r7954 r9406 4 4 */ 5 5 6 #include "synchronizeable_var/synchronizeable_int.h"7 6 8 7 #ifndef _SYNCHRONIZEABLE_UINT_H 9 8 #define _SYNCHRONIZEABLE_UINT_H 10 9 10 #include "synchronizeable_int.h" 11 11 12 class SynchronizeableUInt : public SynchronizeableInt { 12 13 13 14 public: 14 SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );15 SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 15 16 virtual ~SynchronizeableUInt(); 16 17 17 18 virtual void debug(); 18 19 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_var.cc
r7954 r9406 16 16 17 17 #include "synchronizeable_var.h" 18 18 #include "netdefs.h" 19 #include <cassert> 19 20 20 21 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_var.h
r7954 r9406 7 7 #define _SYNCHRONIZEABLE_VAR_H 8 8 9 #include "nettypes.h" 9 10 #include <string> 10 #include "netdefs.h"11 #include <assert.h>12 11 13 12 enum { 14 PERMISSION_SERVER = 1, 15 PERMISSION_OWNER = 2, 16 PERMISSION_ALL = 4 13 PERMISSION_MASTER_SERVER = 1, 14 PERMISSION_PROXY_SERVER = 2, 15 PERMISSION_OWNER = 4, 16 PERMISSION_ALL = 8 17 17 }; 18 18 … … 20 20 21 21 public: 22 SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = PERMISSION_ SERVER, int priority = 0 );22 SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 23 23 virtual ~SynchronizeableVar(); 24 24 … … 28 28 */ 29 29 inline bool beWatched(){ return this->bWatched; } 30 31 /** 30 31 /** 32 32 * set flag if synchronizeable wants to be informed on changes 33 33 */ … … 96 96 */ 97 97 inline void resetPriority() { this->priority = this->realPriority; } 98 98 99 99 /** 100 100 * reads actual size from buffer. this is used when size is not constant … … 104 104 */ 105 105 virtual inline int getSizeFromBuf( byte * buf, int maxLength ){ return this->getSize(); } 106 106 107 107 /** 108 108 * set variable id … … 110 110 */ 111 111 inline void setVarId( int id ){ this->varId = id; } 112 113 /** 112 113 /** 114 114 * get variable id 115 115 * @return variable id 116 116 */ 117 117 inline int getVarId(){ return varId; } 118 118 119 119 /** 120 120 * set hasChanged … … 122 122 */ 123 123 inline void setHasChanged( bool changed ){ this->changed = changed; } 124 125 /** 124 125 /** 126 126 * get hasChanged 127 127 * @return variable id 128 128 */ 129 129 inline bool getHasChanged(){ return changed; } 130 130 131 131 /** 132 132 * print out variable value … … 137 137 private: 138 138 bool bWatched; //!< true if synchronizeable wants to be informed on changes 139 139 140 140 int permission; //!< who is allowed to change this var 141 141 int priority; //!< priority assigned to var 142 142 int realPriority; //!< priority assigned to var, increased every time not sent 143 143 int varId; //!< id to identify varables 144 144 145 145 bool changed; //!< true if last readFromBuf changed anything 146 146 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_vector.cc
r7954 r9406 17 17 #include "synchronizeable_vector.h" 18 18 #include "converter.h" 19 #include <cassert> 19 20 20 21 … … 79 80 int res; 80 81 int n = 0; 81 82 82 83 Vector oldVec = *vPtrOut; 83 84 … … 95 96 96 97 *vPtrOut = Vector( x, y, z ); 97 98 98 99 setHasChanged( !(*vPtrOut == oldVec) ); 99 100 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_vector.h
r7954 r9406 4 4 */ 5 5 6 #include "synchronizeable_var/synchronizeable_var.h"7 8 6 #ifndef _SYNCHRONIZEABLE_VECTOR_H 9 7 #define _SYNCHRONIZEABLE_VECTOR_H 8 9 #include "synchronizeable_var.h" 10 10 11 11 #include "vector.h" … … 14 14 15 15 public: 16 SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );16 SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 17 17 virtual ~SynchronizeableVector(); 18 18 19 19 virtual int writeToBuf( byte * buf, int maxLength ); 20 20 virtual int readFromBuf( byte * buf, int maxLength ); 21 21 22 22 /** 23 23 * check if writeToBuf will return the same size every time … … 25 25 */ 26 26 virtual bool hasStaticSize(){ return true; } 27 27 28 28 virtual void debug(); 29 29 30 30 private: 31 31 Vector * vPtrIn; //!< pointer to data (read)
Note: See TracChangeset
for help on using the changeset viewer.