-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathzdbsp.h
281 lines (232 loc) · 5.55 KB
/
zdbsp.h
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#ifndef __ZDBSP_H__
#define __ZDBSP_H__
#ifdef _MSC_VER
#pragma once
#endif
#include <limits.h>
#include <exception>
#include <stdexcept>
#ifdef _MSC_VER
typedef unsigned __int32 uint32_t;
typedef __int32 int32_t;
#else
#include <stdint.h>
#endif
#define ZDBSP_VERSION "1.19"
enum EBlockmapMode
{
EBM_Rebuild,
EBM_Create0
};
enum ERejectMode
{
ERM_DontTouch,
ERM_CreateZeroes,
ERM_Create0,
ERM_Rebuild
};
extern const char *Map;
extern const char *InName;
extern const char *OutName;
extern bool BuildNodes, BuildGLNodes, ConformNodes, GLOnly, WriteComments;
extern bool NoPrune;
extern EBlockmapMode BlockmapMode;
extern ERejectMode RejectMode;
extern int MaxSegs;
extern int SplitCost;
extern int AAPreference;
extern bool CheckPolyobjs;
extern bool ShowMap;
extern bool CompressNodes, CompressGLNodes, ForceCompression, V5GLNodes;
extern bool HaveSSE1, HaveSSE2;
extern int SSELevel;
#define FIXED_MAX INT_MAX
#define FIXED_MIN INT_MIN
#define FRACBITS 16
typedef int fixed_t;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef signed short SWORD;
#ifdef _WIN32
typedef unsigned long DWORD;
#else
typedef uint32_t DWORD;
#endif
typedef uint32_t angle_t;
angle_t PointToAngle (fixed_t x, fixed_t y);
static const WORD NO_MAP_INDEX = 0xffff;
static const DWORD NO_INDEX = 0xffffffff;
static const angle_t ANGLE_MAX = 0xffffffff;
static const DWORD DWORD_MAX = 0xffffffff;
static const angle_t ANGLE_180 = (1u<<31);
static const angle_t ANGLE_EPSILON = 5000;
void Warn (const char *format, ...);
#if defined(_MSC_VER) && !defined(__clang__) && defined(_M_IX86)
#pragma warning (disable: 4035)
inline fixed_t Scale (fixed_t a, fixed_t b, fixed_t c)
{
__asm mov eax,a
__asm mov ecx,c
__asm imul b
__asm idiv ecx
}
inline fixed_t DivScale30 (fixed_t a, fixed_t b)
{
__asm mov edx,a
__asm sar edx,2
__asm mov eax,a
__asm shl eax,30
__asm idiv b
}
inline fixed_t MulScale30 (fixed_t a, fixed_t b)
{
__asm mov eax,a
__asm imul b
__asm shrd eax,edx,30
}
inline fixed_t DMulScale32 (fixed_t a, fixed_t b, fixed_t c, fixed_t d)
{
__asm mov eax,a
__asm imul b
__asm mov ebx,eax
__asm mov eax,c
__asm mov esi,edx
__asm imul d
__asm add eax,ebx
__asm adc edx,esi
__asm mov eax,edx
}
#pragma warning (default: 4035)
#elif defined(__GNUC__) && defined(__i386__)
#ifdef __clang__
inline fixed_t Scale (fixed_t a, fixed_t b, fixed_t c)
{
fixed_t result, dummy;
asm volatile
("imull %3\n\t"
"idivl %4"
: "=a" (result),
"=&d" (dummy)
: "a" (a),
"r" (b),
"r" (c)
: "%cc"
);
return result;
}
inline fixed_t DivScale30 (fixed_t a, fixed_t b)
{
fixed_t result, dummy;
asm volatile
("idivl %4"
: "=a" (result),
"=d" (dummy)
: "a" (a<<30),
"d" (a>>2),
"r" (b) \
: "%cc");
return result;
}
#else
inline fixed_t Scale (fixed_t a, fixed_t b, fixed_t c)
{
fixed_t result, dummy;
asm volatile
("imull %3\n\t"
"idivl %4"
: "=a,a,a,a,a,a" (result),
"=&d,&d,&d,&d,d,d" (dummy)
: "a,a,a,a,a,a" (a),
"m,r,m,r,d,d" (b),
"r,r,m,m,r,m" (c)
: "%cc"
);
return result;
}
inline fixed_t DivScale30 (fixed_t a, fixed_t b)
{
fixed_t result, dummy;
asm volatile
("idivl %4"
: "=a,a" (result),
"=d,d" (dummy)
: "a,a" (a<<30),
"d,d" (a>>2),
"r,m" (b) \
: "%cc");
return result;
}
#endif
inline fixed_t MulScale30 (fixed_t a, fixed_t b)
{
return ((int64_t)a * b) >> 30;
}
inline fixed_t DMulScale30 (fixed_t a, fixed_t b, fixed_t c, fixed_t d)
{
return (((int64_t)a * b) + ((int64_t)c * d)) >> 30;
}
inline fixed_t DMulScale32 (fixed_t a, fixed_t b, fixed_t c, fixed_t d)
{
return (((int64_t)a * b) + ((int64_t)c * d)) >> 32;
}
#else
inline fixed_t Scale (fixed_t a, fixed_t b, fixed_t c)
{
return (fixed_t)(double(a)*double(b)/double(c));
}
inline fixed_t DivScale30 (fixed_t a, fixed_t b)
{
return (fixed_t)(double(a)/double(b)*double(1<<30));
}
inline fixed_t MulScale30 (fixed_t a, fixed_t b)
{
return (fixed_t)(double(a)*double(b)/double(1<<30));
}
inline fixed_t DMulScale30 (fixed_t a, fixed_t b, fixed_t c, fixed_t d)
{
return (fixed_t)((double(a)*double(b)+double(c)*double(d))/double(1<<30));
}
inline fixed_t DMulScale32 (fixed_t a, fixed_t b, fixed_t c, fixed_t d)
{
return (fixed_t)((double(a)*double(b)+double(c)*double(d))/4294967296.0);
}
#endif
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#define LittleShort(x) CFSwapInt16LittleToHost(x)
#define LittleLong(x) CFSwapInt32LittleToHost(x)
#else
#ifdef __BIG_ENDIAN__
// Swap 16bit, that is, MSB and LSB byte.
// No masking with 0xFF should be necessary.
inline short LittleShort (short x)
{
return (short)((((unsigned short)x)>>8) | (((unsigned short)x)<<8));
}
inline unsigned short LittleShort (unsigned short x)
{
return (unsigned short)((x>>8) | (x<<8));
}
// Swapping 32bit.
inline unsigned int LittleLong (unsigned int x)
{
return (unsigned int)(
(x>>24)
| ((x>>8) & 0xff00)
| ((x<<8) & 0xff0000)
| (x<<24));
}
inline int LittleLong (int x)
{
return (int)(
(((unsigned int)x)>>24)
| ((((unsigned int)x)>>8) & 0xff00)
| ((((unsigned int)x)<<8) & 0xff0000)
| (((unsigned int)x)<<24));
}
#else
#define LittleShort(x) (x)
#define LittleLong(x) (x)
#endif // __BIG_ENDIAN__
#endif // __APPLE__
#endif //__ZDBSP_H__