author | terom |
Mon, 22 Dec 2008 02:37:43 +0000 | |
changeset 387 | 294ce7ae8140 |
parent 300 | 417183866f35 |
child 391 | 59c2499fe7bb |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
#ifndef NETWORK_PACKET_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
2 |
#define NETWORK_PACKET_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
|
186 | 4 |
#include "Config.hh" |
300 | 5 |
#include "../Types.hh" |
186 | 6 |
#include "../Error.hh" |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
7 |
|
284 | 8 |
/** |
9 |
* Base class of errors thrown by NetworkPacket* methods |
|
10 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
11 |
class NetworkPacketError : public Error { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
12 |
public: |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
13 |
NetworkPacketError (const std::string &message) : Error(message) { } |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
14 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
15 |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
16 |
// forward-declare for write_packet |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
17 |
class NetworkPacketBuffer; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
18 |
|
284 | 19 |
/** |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
20 |
* Read-interface for network packets |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
21 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
22 |
class NetworkPacketInput { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
23 |
public: |
284 | 24 |
/** |
387
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
25 |
* Abstract method to get a pointer to \a len bytes of raw in-memory binary data, advancing the read offset |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
26 |
* |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
27 |
* @param len the number of bytes to consume |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
28 |
*/ |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
29 |
virtual const void* read_ptr (size_t len) = 0; |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
30 |
|
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
31 |
/** |
284 | 32 |
* Abstract method that copies len bytes from the packet to ptr, first testing that they exist |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
33 |
*/ |
284 | 34 |
virtual void read ( |
35 |
void *ptr, //<<< where to copy |
|
36 |
size_t len //<<< number of bytes to copy |
|
37 |
) = 0; |
|
387
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
38 |
|
284 | 39 |
/** |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
40 |
* Convenience function to read() and return the value of the given type |
284 | 41 |
* |
42 |
* @return T The value |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
43 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
44 |
template <typename T> T read_val (void); |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
284
diff
changeset
|
45 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
284
diff
changeset
|
46 |
// @{ |
284 | 47 |
/** |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
284
diff
changeset
|
48 |
* Collection of methods to write out simple types, these convert from network-endianness and return the value |
284 | 49 |
*/ |
50 |
||
51 |
/** 32-bit unsigned int */ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
52 |
uint32_t read_uint32 (void); |
284 | 53 |
|
54 |
/** 16-bit unsigned int */ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
55 |
uint16_t read_uint16 (void); |
284 | 56 |
|
57 |
/** 8-bit unsigned int */ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
58 |
uint8_t read_uint8 (void); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
59 |
|
284 | 60 |
/** 32-bit signed int */ |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
61 |
int32_t read_int32 (void); |
284 | 62 |
|
63 |
/** 16-bit signed int */ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
64 |
int16_t read_int16 (void); |
284 | 65 |
|
66 |
/** 8-bit signed int */ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
67 |
int8_t read_int8 (void); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
68 |
|
284 | 69 |
/** 32-bit float */ |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
70 |
float read_float32 (void); |
284 | 71 |
|
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
284
diff
changeset
|
72 |
// @} |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
73 |
|
284 | 74 |
/** |
75 |
* Read a Vector from the packet: |
|
76 |
* float32 vec_x |
|
77 |
* float32 vec_y |
|
78 |
* |
|
79 |
* @return Vector (vec_x, vec_y) |
|
80 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
81 |
Vector read_vector (void); |
387
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
82 |
|
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
83 |
/** |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
84 |
* Abstract method to get the number of input bytes remaining. |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
85 |
* |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
86 |
* @return number of input bytes still readable |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
87 |
*/ |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
88 |
virtual size_t tell_remaining (void) = 0; |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
89 |
}; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
90 |
|
284 | 91 |
/** |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
92 |
* Write-interface for network packets |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
93 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
94 |
class NetworkPacketOutput { |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
95 |
public: |
284 | 96 |
/** |
387
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
97 |
* Abstract method to get a pointer to \a len bytes of raw in-memory binary data, advancing the write offset |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
98 |
* |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
99 |
* @param len number of bytes to commit |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
100 |
*/ |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
101 |
virtual void* write_ptr (size_t len) = 0; |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
102 |
|
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
103 |
/** |
284 | 104 |
* Abstract method that copies len bytes from ptr to the packet, first testing that they fit |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
105 |
*/ |
284 | 106 |
virtual void write ( |
107 |
const void *ptr, //<<< where to copy from |
|
108 |
size_t len //<<< number of bytes to copy |
|
109 |
) = 0; |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
110 |
|
284 | 111 |
/** |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
112 |
* Convenience function to write() the value of the given type-value |
284 | 113 |
* |
114 |
* @param val The value |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
115 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
116 |
template <typename T> void write_val (const T &val); |
284 | 117 |
|
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
284
diff
changeset
|
118 |
// @{ |
284 | 119 |
/** |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
284
diff
changeset
|
120 |
* Collection of methods to write out simple types, these convert the given value to network-byte-order |
284 | 121 |
*/ |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
122 |
void write_uint32 (uint32_t val); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
123 |
void write_uint16 (uint16_t val); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
124 |
void write_uint8 (uint8_t val); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
125 |
void write_int32 (int32_t val); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
126 |
void write_int16 (int16_t val); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
127 |
void write_int8 (int8_t val); |
284 | 128 |
void write_float32 (float val); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
129 |
|
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
284
diff
changeset
|
130 |
// @{ |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
131 |
|
284 | 132 |
/** |
133 |
* Write a vector to the packet: |
|
134 |
* float32 vec_x |
|
135 |
* float32 vec_y |
|
136 |
* |
|
137 |
* @param vec a Vector(vec_x, vec_y) |
|
138 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
139 |
void write_vector (const Vector &vec); |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
140 |
|
284 | 141 |
/** |
142 |
* This write()s the contents of the given NetworkPacketBuffer to this packet. |
|
143 |
* |
|
144 |
* @param pkt the sub-packet to write() |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
145 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
146 |
void write_packet (const NetworkPacketBuffer &pkt); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
147 |
}; |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
148 |
|
284 | 149 |
/** |
150 |
* Implements an in-memory seekable buffer used by NetworkPackets |
|
151 |
* |
|
152 |
* @see NetworkPacketInput |
|
153 |
* @see NetworkPacketOutput |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
154 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
155 |
class NetworkPacketBuffer : public NetworkPacketInput, public NetworkPacketOutput { |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
156 |
protected: |
284 | 157 |
/** |
158 |
* Pointer to the packet data |
|
159 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
160 |
char *buf_ptr; |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
161 |
|
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
162 |
// the buffer size, the amount of data in the buffer, and the current read/write offset |
284 | 163 |
/** |
164 |
* The size of the memory region pointed to by buf_ptr |
|
165 |
*/ |
|
166 |
size_t buf_size; |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
167 |
|
284 | 168 |
/** |
169 |
* The number of bytes of read()-able data stored at buf_ptr |
|
170 |
*/ |
|
171 |
size_t data_size; |
|
172 |
||
173 |
/** |
|
174 |
* The current offset at which to run the next read/write |
|
175 |
*/ |
|
176 |
size_t offset; |
|
177 |
||
178 |
/** |
|
179 |
* Assert that the given number of bytes fits into the buffer at offset. Throws NetworkPacketError if not. |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
180 |
* |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
181 |
* The default implementation just checks offset and buf_size |
284 | 182 |
* |
183 |
* @param item_size the size of the item that should to be written |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
184 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
185 |
virtual void check_write_size (size_t item_size); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
186 |
|
284 | 187 |
/** |
188 |
* Assert that the given number of bytes is available from the buffer. Throws NetworkPacketError if not |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
189 |
* |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
190 |
* The default implementation just checks offset and data_size |
284 | 191 |
* |
192 |
* @param item_size the size of the item that should be read |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
193 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
194 |
virtual void check_read_size (size_t item_size); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
195 |
|
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
196 |
public: |
284 | 197 |
/** |
198 |
* Construct the NetworkPacketBuffer using the given buf_ptr, buf_size and data_size |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
199 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
200 |
NetworkPacketBuffer (char *buf_ptr, size_t buf_size, size_t data_size); |
387
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
201 |
|
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
202 |
/** |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
203 |
* Returns a read-only pointer to \a len bytes of internal buffer memory, calling check_read_size first and |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
204 |
* updating offset |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
205 |
* |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
206 |
* @param len number of bytes from the buffer to consume |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
207 |
*/ |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
208 |
virtual const void* read_ptr (size_t len); |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
209 |
|
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
210 |
/** |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
211 |
* Returns a read-write pointer to \a len bytes of internal buffer memory, calling check_write_size first and |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
212 |
* updating offset+data_size |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
213 |
* |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
214 |
* @param len number of bytes in the buffer to commit |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
215 |
*/ |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
216 |
virtual void* write_ptr (size_t len); |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
217 |
|
284 | 218 |
/** |
219 |
* Copy bytes from the packet buffer to ptr using memcpy(), calling check_read_size first. |
|
220 |
* |
|
221 |
* @param ptr where to copy the data to |
|
222 |
* @param len number of bytes to copy |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
223 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
224 |
virtual void read (void *ptr, size_t len); |
284 | 225 |
|
226 |
/** |
|
227 |
* Copy bytes from ptr to the packet buffer using memcpy(), calling check_write_size first |
|
228 |
* |
|
229 |
* @param ptr where to copy the data from |
|
230 |
* @param len number of bytes to copy |
|
231 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
232 |
virtual void write (const void *ptr, size_t len); |
387
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
233 |
|
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
234 |
/** |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
235 |
* Returns our data_size - read-offset |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
236 |
*/ |
294ce7ae8140
dirty implementation of compressed terrain array data
terom
parents:
300
diff
changeset
|
237 |
virtual size_t tell_remaining (void); |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
238 |
|
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
239 |
/* |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
240 |
* Accessor functions, used by the actual socket code to read/write the buffer |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
241 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
242 |
char* get_buf (void) { return buf_ptr; } |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
243 |
const char* get_buf (void) const { return buf_ptr; } |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
244 |
size_t get_data_size (void) const { return data_size; } |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
245 |
size_t get_buf_size (void) const { return buf_size; } |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
246 |
|
284 | 247 |
/** |
248 |
* If the contents of buf_ptr is replaced with a new packet, call this to update offset/data_size |
|
249 |
* |
|
250 |
* @param size new amount of data in the buffer |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
251 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
252 |
void set_data_size (size_t size) { offset = 0; data_size = size; } |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
253 |
}; |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
254 |
|
284 | 255 |
/** |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
256 |
* The common case is a packet that fits in a single UDP packet, so this just uses a static buffer of a fixed size, |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
257 |
* NETWORK_PACKET_SIZE. |
284 | 258 |
* |
259 |
* @see NetworkPacketBuffer |
|
260 |
* @see NETWORK_PACKET_SIZE |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
261 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
262 |
class NetworkPacket : public NetworkPacketBuffer { |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
263 |
private: |
284 | 264 |
/** |
265 |
* The static buffer, NETWORK_PACKET_SIZE bytes |
|
266 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
267 |
char _buf[NETWORK_PACKET_SIZE]; |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
268 |
|
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
269 |
public: |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
270 |
NetworkPacket (void); |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
271 |
}; |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
272 |
|
284 | 273 |
/** |
274 |
* This is intended for sending bigger packets via TCP; a buffer of the given size is allocated on the heap. |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
275 |
* |
284 | 276 |
* @see NetworkPacketBuffer |
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
277 |
*/ |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
278 |
class BigNetworkPacket : public NetworkPacketBuffer { |
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
279 |
public: |
284 | 280 |
/** |
281 |
* Allocates a buffer of the given size on the heap and uses it for NetworkPacketBuffer |
|
282 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
283 |
BigNetworkPacket (size_t size); |
202 | 284 |
|
285 |
private: |
|
284 | 286 |
/** |
287 |
* Object must not be copied |
|
288 |
*/ |
|
202 | 289 |
BigNetworkPacket (const BigNetworkPacket &pkt); |
290 |
BigNetworkPacket& operator= (const BigNetworkPacket &pkt); |
|
291 |
||
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
202
diff
changeset
|
292 |
public: |
284 | 293 |
/** |
294 |
* Frees the heap buffer |
|
295 |
*/ |
|
202 | 296 |
virtual ~BigNetworkPacket (void); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
297 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
298 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
299 |
#endif /* NETWORK_PACKET_HH */ |