equal
deleted
inserted
replaced
1 |
1 |
2 #include <cassert> |
2 #include <cassert> |
3 #include <cstring> |
3 #include <cstring> |
4 |
4 |
5 #include "Packet.hh" |
5 #include "Packet.hh" |
|
6 |
|
7 // XXX: assumes that sizeof(float32) == sizeof(int32); |
6 |
8 |
7 /* |
9 /* |
8 * NetworkPacketInput |
10 * NetworkPacketInput |
9 */ |
11 */ |
10 template <typename T> T NetworkPacketInput::read_val (void) { |
12 template <typename T> T NetworkPacketInput::read_val (void) { |
41 return read_val<int8_t>(); |
43 return read_val<int8_t>(); |
42 } |
44 } |
43 |
45 |
44 float NetworkPacketInput::read_float32 (void) { |
46 float NetworkPacketInput::read_float32 (void) { |
45 int32_t ival = read_int32(); |
47 int32_t ival = read_int32(); |
|
48 float fval; |
|
49 |
|
50 assert(sizeof(ival) == sizeof(fval)); |
46 |
51 |
47 return *((float *) &ival); |
52 memcpy(&fval, &ival, sizeof(float)); |
|
53 |
|
54 return fval; |
48 } |
55 } |
49 |
56 |
50 Vector NetworkPacketInput::read_vector (void) { |
57 Vector NetworkPacketInput::read_vector (void) { |
51 float fx = read_float32(); |
58 float fx = read_float32(); |
52 float fy = read_float32(); |
59 float fy = read_float32(); |
85 |
92 |
86 void NetworkPacketOutput::write_int8 (int8_t val) { |
93 void NetworkPacketOutput::write_int8 (int8_t val) { |
87 write_val<int8_t>(val); |
94 write_val<int8_t>(val); |
88 } |
95 } |
89 |
96 |
90 void NetworkPacketOutput::write_float32 (float val) { |
97 void NetworkPacketOutput::write_float32 (float fval) { |
91 write_int32(*((int32_t *) &val)); |
98 int32_t ival; |
|
99 |
|
100 assert(sizeof(ival) == sizeof(fval)); |
|
101 |
|
102 memcpy(&ival, &fval, sizeof(int32_t)); |
|
103 |
|
104 write_int32(ival); |
92 } |
105 } |
93 |
106 |
94 void NetworkPacketOutput::write_vector (const Vector &vec) { |
107 void NetworkPacketOutput::write_vector (const Vector &vec) { |
95 write_float32(vec.x); |
108 write_float32(vec.x); |
96 write_float32(vec.y); |
109 write_float32(vec.y); |