-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsemsg.cpp
146 lines (112 loc) · 1.94 KB
/
parsemsg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
typedef unsigned char byte;
#define true 1
static byte *gpBuf;
static int giSize;
static int giRead;
static int giBadRead;
void BEGIN_READ(void *buf, int size)
{
giRead = 0;
giBadRead = 0;
giSize = size;
gpBuf = (byte*)buf;
}
int READ_CHAR(void)
{
int c;
if (giRead + 1 > giSize)
{
giBadRead = true;
return -1;
}
c = (signed char)gpBuf[giRead];
giRead++;
return c;
}
int READ_BYTE(void)
{
int c;
if (giRead + 1 > giSize)
{
giBadRead = true;
return -1;
}
c = (unsigned char)gpBuf[giRead];
giRead++;
return c;
}
int READ_SHORT(void)
{
int c;
if (giRead + 2 > giSize)
{
giBadRead = true;
return -1;
}
c = (short)(gpBuf[giRead] + (gpBuf[giRead + 1] << 8));
giRead += 2;
return c;
}
int READ_WORD(void)
{
return READ_SHORT();
}
int READ_LONG(void)
{
int c;
if (giRead + 4 > giSize)
{
giBadRead = true;
return -1;
}
c = gpBuf[giRead] + (gpBuf[giRead + 1] << 8) + (gpBuf[giRead + 2] << 16) + (gpBuf[giRead + 3] << 24);
giRead += 4;
return c;
}
float READ_FLOAT(void)
{
union
{
byte b[4];
float f;
int l;
} dat;
dat.b[0] = gpBuf[giRead];
dat.b[1] = gpBuf[giRead + 1];
dat.b[2] = gpBuf[giRead + 2];
dat.b[3] = gpBuf[giRead + 3];
giRead += 4;
// dat.l = LittleLong (dat.l);
return dat.f;
}
char* READ_STRING(void)
{
static char string[2048];
int l, c;
string[0] = 0;
l = 0;
do
{
if (giRead + 1 > giSize)
break; // no more characters
c = READ_CHAR();
if (c == -1 || c == 0)
break;
string[l] = c;
l++;
} while (l < sizeof(string) - 1);
string[l] = 0;
return string;
}
float READ_COORD(void)
{
return (float)(READ_SHORT() * (1.0 / 8));
}
float READ_ANGLE(void)
{
return (float)(READ_CHAR() * (360.0 / 256));
}
float READ_HIRESANGLE(void)
{
return (float)(READ_SHORT() * (360.0 / 65536));
}