Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
netbuffer.h
Go to the documentation of this file.
1 #ifndef __NETBUFFER_H
2 #define __NETBUFFER_H
3 
4 #include <string.h>
5 #include "cmd/weapon_xml.h"
6 #include "gfx/vec.h"
7 #include "gfx/matrix.h"
8 #include "gfx/quaternion.h"
10 #include "cmd/unit_armorshield.h"
11 #include "gfxlib_struct.h"
12 
13 struct GFXColor;
14 std::string getSimpleString( std::string &input );
15 char getSimpleChar( std::string &input );
16 int getSimpleInt( std::string &input );
17 void addSimpleString( std::string &input, const std::string adder );
18 void addSimpleChar( std::string &input, const char adder );
19 void addSimpleInt( std::string &input, const int adder );
20 class NetBuffer
21 {
22  char *buffer;
23  unsigned int offset;
24  unsigned int size;
25  ObjSerial ver;
26 
27 public: NetBuffer();
28  NetBuffer( int bufsize );
29  NetBuffer( const char *buf, int bufsize );
30  ~NetBuffer();
31 
32  void Reset();
34  void setVersion( ObjSerial ver );
35  char * getData();
36  unsigned int getOffset() const
37  {
38  return offset;
39  } //useful to see if it's at the end of data
40 //Extends the buffer if we exceed its size
41  void resizeBuffer( unsigned int newsize );
42 //Check if there is still enough data for 'len' to be read in buffer
43  bool checkBuffer( int len, const char *fun );
44 
45  void addClientState( ClientState cs );
47  void addVector( Vector v );
48  Vector getVector();
49  void addQVector( QVector v );
51  void addColor( GFXColor col );
53  void addMatrix( Matrix m );
54  Matrix getMatrix();
55  void addQuaternion( Quaternion quat );
57  void addTransformation( Transformation trans );
59 
60 /*
61  * void addWeaponInfo( weapon_info wi)
62  * {
63  * wi.netswap();
64  * char * buf = NULL;
65  * int wi_size = 0;
66  * setWeaponInfoToBuffer( wi, buf, wi_size);
67  * resizeBuffer( offset+wi_size);
68  * memcpy( buffer+offset, buf, wi_size);
69  * offset += wi_size;
70  * delete buf;
71  * }
72  */
73 /*
74  * weapon_info getWeaponInfo()
75  * {
76  * int wisize=0;
77  * weapon_info tmp = getWeaponInfoFromBuffer( buffer+offset, wisize);
78  * tmp.netswap();
79  * offset += wisize;
80  * return tmp;
81  * }
82  */
83  void addShield( const Shield &shield );
84  Shield getShield();
85  void addArmor( const Armor &armor );
86  Armor getArmor();
87 
88  void addSerial( ObjSerial serial );
90  void addFloat( float f );
91  float getFloat();
92  void addFloat8( float f );
93  float getFloat8();
94  void addDouble( double d );
95  double getDouble();
96  void addShort( unsigned short s );
97  unsigned short getShort();
98  void addInt32( int i );
99  int getInt32();
100  void addUInt32( unsigned int i );
101  unsigned int getUInt32();
102  void addChar( char c );
103  char getChar();
104  void addType( unsigned char t );
105  bool checkType( unsigned char t );
106  unsigned char getType();
107  void addBuffer( const unsigned char *buf, int bufsize );
108  unsigned char * extAddBuffer( int bufsize );
109  unsigned char * getBuffer( int offt );
110 //Add and get a string with its length before the char * buffer part
111  void addString( const string &str );
112  string getString();
113 
115  void addGFXMaterial( const GFXMaterial &mat );
117  void addGFXLight( const GFXLight &light );
119  void addGFXLightLocal( const GFXLightLocal &light );
120 
121  unsigned int getDataLength();
122  unsigned int getSize();
123 };
124 
125 #endif
126