forked from PopRe/Pop-World-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.h
359 lines (302 loc) · 9.48 KB
/
engine.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
Alacn
http://alacn.dnsalias.org:8080/
*/
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "ddraw.lib")
#define D3D_OVERLOADS
#include <ddraw.h>
#include <d3d.h>
#include <vector>
#include "Pop.h"
#define COLOR_RENDER_BG 0x007CF0
#define COLOR_GRID 0x000000
#define COLOR_SELECTED 0xFFFFFF
#define PI 3.141592f
#define TORAD(d) ((d) * PI / 180.0f)
#define TODEG(r) ((r) * 180.0f / PI)
#define CURXTO3D(x) ((float)x / ((float)dwScreenWidth / 2.0f) - 1.0f)
#define CURYTO3D(y) (1.0f - (float)y / ((float)dwScreenHeight / 2.0f))
#define SZ_ENGINE_CONFIG "popedt.dat"
#define SZ_ENGINE_TMP_MAP "tmp.dat"
#define SZ_ENGINE_FPS "%s - %dx%dx%d - %.3f fps - %d ms"
#define SZ_ENGINE_RELEASE_REF "Ref: %s: %d"
#define SZ_ENGINE_RELEASE_REF_D3DDEVICE "D3DDevice"
#define SZ_ENGINE_RELEASE_REF_DDSPRIMARY "DDSPrimary"
#define SZ_ENGINE_RELEASE_REF_DDSBACKBUFFER "DDSBackBuffer"
#define SZ_ENGINE_RELEASE_REF_DDSZBUFFER "DDSZBuffer"
#define SZ_ENGINE_RELEASE_REF_D3D "D3D"
#define SZ_ENGINE_RELEASE_REF_DD "DD"
#define SZ_ENGINE_CREATE "Creating Engine: %dx%dx%d %s - %s"
#define SZ_ENGINE_DESTROY "Engine Destroyed"
#define SZ_ENGINE_MODE_FS "FullScreen"
#define SZ_ENGINE_MODE_WIN "Windowed"
#define SZ_ERR_ENGINE_DIRECTDRAWCREATEEX "DirectDrawCreateEx: 0x%X"
#define SZ_ERR_ENGINE_SETCOOPERATIVELEVEL "SetCooperativeLevel: 0x%X"
#define SZ_ERR_ENGINE_SETDISPLAYMODE "SetDisplayMode: 0x%X"
#define SZ_ERR_ENGINE_PRIMARYSURFACE "Create Primary Surface: 0x%X"
#define SZ_ERR_ENGINE_CREATECLIPPER "CreateClipper: 0x%X"
#define SZ_ERR_ENGINE_CLIPPER_SETHWND "Clipper->SetHWnd: 0x%X"
#define SZ_ERR_ENGINE_SETCLIPPER "SetClipper: 0x%X"
#define SZ_ERR_ENGINE_BACKBUFFER "BackBuffer: 0x%X"
#define SZ_ERR_ENGINE_QUERYINTERFACE_D3D "QueryInterface->D3D: 0x%X"
#define SZ_ERR_ENGINE_ENUMZBUFFER "EnumZBuffer: 0x%X"
#define SZ_ERR_ENGINE_ZBUFFER "ZBuffer: 0x%X"
#define SZ_ERR_ENGINE_ADDATTACHEDSURFACE_ZBUFFER "AddAttachedSurface->ZBuffer: 0x%X"
#define SZ_ERR_ENGINE_CREATEDEVICE "CreateDevice: 0x%X"
#define SZ_ERR_ENGINE_SETVIEWPORT "SetViewPort: 0x%X"
#define SZ_ERR_ENGINE_ENUMTEXTUREFORMATS "Cannot find texture with %d bit depth"
#define SZ_ERR_ENGINE_CREATETEXTURE "Create Texture %s: 0x%X"
#define SZ_ERR_ENGINE_GETDC "%s - GetDC: 0x%X"
#define SZ_ERR_ENGINE_RELEASEDC "%s - ReleaseDC: 0x%X"
#define SZ_ERR_ENGINE_BLT "%s - Blt: 0x%X"
#define SZ_ERR_ENGINE_BEGINSCENE "BeginScene: 0x%X"
#define SZ_ERR_ENGINE_ENDSCENE "EndScene: 0x%X"
#define SZ_ERR_ENGINE_CLEAR "Clear: 0x%X"
#define SZ_ERR_ENGINE_LOADTEXTURE "LoadTexture Failed: %s"
#define SZ_ERR_ENGINE_CREATEDC "CreateDC: %s"
#define SZ_ERR_ENGINE_RESTORE_FAILED "Restore Surface Failed: 0x%X"
#define SZ_ERR_CREATEFILE "CreateFile Failed: %s"
#define SZ_ERR_READERROR "Read Error at: %s"
#define SZ_ERR_WRITEERROR "Write Error at: %s"
#define SZ_ERR_MAGIC_MISMATCH "LEVEL3 Keyword not found, reverting to Level2 format: %s"
#define GROUND_X_SIZE 128
#define GROUND_Z_SIZE 128
#define GROUND_BLOCK_HEIGHT 0.005f
#define VIEW_RANGE 30
#define VIEW_RANGE_2 60
#define VIEW_RANGE_CLICK_MIN 10 // VIEW_RANGE -+ 20
#define VIEW_RANGE_CLICK_MAX 50
#define VIEW_RANGE_CLICK 20
#define SPHERE_RATIO 0.01f
#define GROUND_HEIGHT_MAX 0x0700
#define MINIMAP_TEXTURE_SIZE 128
#define PERSON_TEXTURE_SIZE 64
#define TEXTURE_SIZE 32
#if USE_FOG
#if USE_NEW_VIEW
#define FOG_START 30.0f
#define FOG_END 35.0f
#else
#define FOG_START 20.0f
#define FOG_END 25.0f
#endif
#endif
#define LIGHT_Y 15.0f
#define SPEED_POS_X 0.00000000007f
#define SPEED_POS_Y 0.00000000007f
#define SPEED_POS_Z 0.00000000007f
#define SPEED_ROT_X 0.0000000007f
#define SPEED_ROT_Y 0.0000000007f
#define SPEED_ROT_Z 0.0000000007f
#define SPEED_POS_Y_ZOOM 0.00000000021f
#define MIN_POS_Y 5.5f
#define MAX_SPERICAL_POS_Y 20.0f
#define MAX_POS_Y 30.0f
#define MIN_ROT_X 35.0f
#define MAX_ROT_X 85.0f
#define MINIMAP_Z 5.0f
#define MINIMAP_X_ORIENTATION 1.0f
#define MINIMAP_Y_ORIENTATION -1.0f
#define MINIMAP_X_SPACE 0.75f
#define MINIMAP_Y_SPACE -0.75f
// Engine Flags
#define EF_FRAMERATE (1 << 0)
#define EF_DITHER (1 << 1)
#define EF_TEXTURE_FILTER (1 << 2)
#define EF_WIREFRAME_LAND (1 << 3)
#define EF_WIREFRAME_OBJS (1 << 4)
#define EF_SHOW_GRID (1 << 5)
#define EF_GRID_SEE_THROUGH (1 << 6)
#define EF_TRANSPARENT_MINIMAP (1 << 7)
#define EF_SHOW_MINIMAP (1 << 8)
#define EF_HIDE_OBJECTS (1 << 9)
#define EF_BOUNDINGBOX (1 << 10)
#define EF_HIDE_OBJS_ON_MINIMAP (1 << 11)
#define EF_SHOW_MARKERS (1 << 12)
#define LEVEL_FORMAT_MODE_V2 0
#define LEVEL_FORMAT_MODE_V3 1
#define ENGINE_UPDATE_TIMER 500
struct GROUNDHEIGHT
{
float height;
DWORD color;
};
struct TEXTURE
{
TEXTURE *Next,
*Prev;
LPDIRECTDRAWSURFACE7 lpDDSTexture;
WORD Width,
Height;
char *Name;
WORD Resource;
};
struct BOUND_BOX
{
float minX,
minY,
minZ,
maxX,
maxY,
maxZ;
D3DVERTEX v[8];
};
struct OBJ3D_PART
{
OBJ3D_PART *Next,
*Prev;
D3DMATERIAL7 Mtrl;
TEXTURE *texture;
WORD VertsCount;
D3DVERTEX *Verts;
};
struct OBJ3D
{
OBJ3D *Next,
*Prev;
OBJ3D_PART *Parts;
BOUND_BOX BoundBox;
};
struct SCREEN_INFO
{
SCREEN_INFO *Next,
*Prev;
DWORD Width,
Height,
Depth;
};
struct DEVICE_INFO
{
DEVICE_INFO *Next,
*Prev;
char *szName;
GUID guid;
bool fHw;
};
#define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1)
struct COLORVERTEX
{
float x,
y,
z;
float nx,
ny,
nz;
DWORD color;
float tu,
tv;
};
enum MOUSEBUTTON
{
MouseButtonLeft,
MouseButtonRight,
MouseButtonMiddle
};
extern char szLevel[MAX_PATH];
extern DWORD dwEngineFlags,
dwScreenWidth,
dwScreenHeight,
dwScreenDepth,
dwScreenWidthN,
dwScreenHeightN;
extern char szDeviceName[STR_SIZE];
extern GUID guidDevice;
extern bool fHwDevice;
extern LPDIRECTDRAW7 lpDD;
extern LPDIRECTDRAWSURFACE7 lpDDSPrimary,
lpDDSBackBuffer;
extern LEVELDATv3 *leveldat;
extern LPDIRECT3DDEVICE7 lpD3DDevice;
extern WORD wEngineGround[GROUND_X_SIZE * GROUND_Z_SIZE],
ThingsIndices[MAX_V2_THINGS];
extern MARKER Markers[256];
extern int MarkerSelected;
extern LEVELVERSION LevelVersion;
extern float fEnginePosX,
fEnginePosY,
fEnginePosZ,
fEngineRotX,
fEngineRotY,
fEngineRotZ;
extern int GroundEditBrushSize,
PreviousBrushSize,
GroundEditBrushSpeed,
ObjectsCount,
LevelFormatMode;
extern TEXTURE *Textures;
extern OBJ3D *Objs3D;
extern THING *Things,
*ThingSelected,
*ThingLink;
extern SCREEN_INFO *ScreenInfo;
extern DEVICE_INFO *DeviceInfo;
extern bool bEngineSleep,
fEngineEditLand,
fEngineEditObjs,
fEngineEditMarkers,
fCaptured,
fLandEditUpdate,
fFlatten,
fSmooth,
fRaise,
fLower,
fNewMarkerAdded,
fPaintDecorations,
fBrushMaxSize;
extern POINT ptCursor,
ptCaptured;
extern MOUSEBUTTON MouseButton;
extern DWORD LANDSCAPE_COLORS[256];
extern std::vector<THINGSAVE> Objects;
long EnginePrepare();
long EngineFinish();
long EngineCreate();
long EngineDestroy();
long EngineRestore();
long EngineInitialize();
void EngineGetPick(D3DVECTOR *vPickRayOrig, D3DVECTOR *vPickRayDir);
int EngineTriangleIntersect(D3DVECTOR orig, D3DVECTOR dir, D3DVECTOR v0, D3DVECTOR v1, D3DVECTOR v2);
int EngineTriangleIntersect(D3DVECTOR orig, D3DVECTOR dir, D3DVERTEX v0, D3DVERTEX v1, D3DVERTEX v2);
bool EngineGetIntersectMapSquare(D3DVECTOR orig, D3DVECTOR dir, int *sx, int *sz, float *ex, float *ez);
long EngineUpdateFrame();
long EngineDrawFrameRate();
long EngineDrawLandscape();
long EngineDrawObjects();
long EngineDrawMiniMap();
long EngineLoadLevel(char *filename);
long EngineSaveLevel(char *filename);
long EngineLoadLevelV3(char *filename);
long EngineSaveLevelV3(char *filename);
long EngineUpdateView();
WORD EngineGetGroundHeight(int x, int z);
void EngineSetGroundHeight(int x, int z, WORD h);
long EngineUpdateKeys();
long EngineUpdateMiniMap();
TEXTURE* EngineCreateTexture(WORD Width, WORD Height, char *Name, WORD Resource);
long EngineDestroyTexture(TEXTURE *texture);
long EngineTextureCreateSurface(TEXTURE *texture);
long EngineTextureDestroySurface(TEXTURE *texture);
long EngineLoadTexture(TEXTURE *texture);
long EngineRestoreTextures();
long EngineReLoadAllTextures();
long EngineUnLoadAllTextures();
bool EngineLoadObjects();
bool EngineDestroyObjects();
long EngineDrawObj3D(OBJ3D *obj, float x, float y, float z, DWORD angle);
void EngineSetTreeType();
void EngineNewMap();
void EngineLoadConfig();
void EngineSaveConfig();
long __stdcall EnumModes(LPDDSURFACEDESC2 ddsd, void*);
long __stdcall EnumDevices(char *szDescription, char *szDeviceName, LPD3DDEVICEDESC7 lpD3DDeviceDesc, void*);
void EngineMouseSetCapture();
void EngineMouseReleaseCapture();
void EngineMouseLDown();
void EngineMouseLUp();
void EngineMouseRDown();
void EngineMouseRUp();
void EngineMouseWheel(int delta);
bool IsNotNeutral(THING *t);
void CopyToClipboard(HWND hwnd, const std::string& s);