-
Notifications
You must be signed in to change notification settings - Fork 0
/
popedt.cpp
293 lines (236 loc) · 6.87 KB
/
popedt.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
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
/*
Alacn
http://alacn.dnsalias.org:8080/
*/
#include "std.h"
#include "popedt.h"
#include "log.h"
#include "commctrl.h"
#include "pop.h"
#include "engine.h"
#include "dialogs.h"
HWND hMainWnd;
HINSTANCE hInst;
RECT rcClient;
bool fActive,
fEngineActive,
fFullScreen;
BYTE bKeys[256];
char str[STR_SIZE],
str2[STR_SIZE],
str3[STR_SIZE],
szStartPath[STR_SIZE];
long rs;
DWORD dwRW;
long __stdcall WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
bool RegisterCreateMainWindow();
void ProcessCommandLine(char *cmdline);
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, char *szCmdLine, int)
{
hInst = hInstance;
dwScreenWidth = 640;
dwScreenHeight = 480;
dwScreenDepth = 16;
//guidDevice = IID_IDirect3DHALDevice;
//strcpy(szDeviceName, "Direct3D HAL");
guidDevice = IID_IDirect3DTnLHalDevice;
strcpy(szDeviceName, "Direct3D TnLHal");
fHwDevice = true;
fFullScreen = true;
GetCurrentDirectory(sizeof(szStartPath), szStartPath);
if(!RegisterCreateMainWindow()) return -1;
LogCreate();
EnginePrepare();
dwEngineFlags = EF_DITHER | EF_TEXTURE_FILTER | EF_TRANSPARENT_MINIMAP | EF_SHOW_MINIMAP;
EngineLoadConfig();
ProcessCommandLine(szCmdLine);
ShowWindow(hMainWnd, SW_SHOW);
UpdateWindow(hMainWnd);
SetFocus(hMainWnd);
fActive = true;
InitializeDialogs();
HACCEL hAcell = LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_ACCELERATOR));
_retry:
if FAILED(EngineCreate())
{
EngineDestroy();
if(guidDevice == IID_IDirect3DTnLHalDevice)
{
guidDevice = IID_IDirect3DHALDevice;
strcpy(szDeviceName, "Direct3D HAL");
goto _retry;
}
ModalMsg(SZ_ENGINE_FAILED, APPNAME, MB_ICONHAND);
if(!hDlgDevice) DlgDeviceToggle();
CenterDialog(hDlgDevice);
}
MenuBarToggle();
if(fEngineEditObjs) DlgObjectToggle();
SetFocus(hMainWnd);
if(hDlgDevice) SetFocus(hDlgDevice);
MSG Msg;
while(true)
{
if(PeekMessage(&Msg, 0, 0, 0, PM_NOREMOVE))
{
if(!GetMessage(&Msg, 0, 0, 0)) return Msg.wParam;
HWND hWnd = GetActiveWindow();
if(!TranslateAccelerator(hMainWnd, hAcell, &Msg))
{
if(hWnd == 0 || hWnd == hMainWnd || !IsDialogMessage(hWnd, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
}
else
{
if(fActive && fEngineActive)
{
if FAILED(rs = EngineUpdateFrame())
{
EngineDestroy();
ModalMsg(SZ_ENGINE_FAILED, APPNAME, MB_ICONHAND);
if(!hDlgDevice) DlgDeviceToggle();
CenterDialog(hDlgDevice);
}
}
else WaitMessage();
}
}
}
bool RegisterCreateMainWindow()
{
WNDCLASS wc;
wc.cbClsExtra =
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_CN));
wc.hInstance = hInst;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = APPNAME;
wc.lpszMenuName = 0;
wc.style = CS_DBLCLKS;
if(!RegisterClass(&wc))
{
MessageBox(0, SZ_CANNOT_REGISTER_CLASS, APPNAME, MB_ICONHAND);
return false;
}
hMainWnd = CreateWindowEx(0, APPNAME, APPNAME, WS_POPUP, 0, 0, 0, 0, 0, 0, hInst, 0);
if(!hMainWnd)
{
MessageBox(0, SZ_CANNOT_CREATE_WINDOW, APPNAME, MB_ICONHAND);
return false;
}
return true;
}
long __stdcall WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CLOSE:
FinishDialogs();
EngineDestroy();
EngineSaveConfig();
EngineFinish();
LogClose();
DestroyWindow(hMainWnd);
PostQuitMessage(0);
return 0;
case WM_SIZE:
if(wParam == SIZE_MAXHIDE || wParam == SIZE_MINIMIZED)
fActive = false;
else
fActive = true;
break;
case WM_MOVE:
if(!fFullScreen)
{
GetClientRect(hWnd, &rcClient);
POINT pt = {0, 0};
ClientToScreen(hWnd, &pt);
rcClient.left += pt.x;
rcClient.right += pt.x;
rcClient.top += pt.y;
rcClient.bottom += pt.y;
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_ACCEL_MENUBAR: MenuBarToggle(); break;
case ID_ACCEL_DLGBRUSH: DlgBrushToggle(); break;
case ID_ACCEL_DLGLIST: DlgListToggle(); break;
case ID_ACCEL_DLGDEVICE: DlgDeviceToggle(); break;
case ID_ACCEL_LAND: SetEditLand(); break;
case ID_ACCEL_OBJECTS: SetEditObjects(); break;
case ID_ACCEL_MARKERS: SetEditMarkers(); break;
case ID_ACCEL_HELP: ShowHelp(); break;
case ID_ACCEL_NEW: LevelNew(); break;
case ID_ACCEL_OPEN: LevelOpen(); break;
case ID_ACCEL_SAVE: LevelSave(); break;
case ID_ACCEL_SAVE_AS: LevelSaveAs(); break;
}
break;
case WM_KILLFOCUS:
memset(bKeys, 0, sizeof(bKeys));
break;
case WM_LBUTTONDOWN:
EngineMouseLDown();
break;
case WM_LBUTTONUP:
EngineMouseLUp();
break;
case WM_RBUTTONDOWN:
EngineMouseRDown();
break;
case WM_RBUTTONUP:
EngineMouseRUp();
break;
case WM_MOUSEWHEEL:
EngineMouseWheel((short)HIWORD(wParam));
break;
case WM_KEYDOWN:
if(wParam < sizeof(bKeys)) bKeys[LOWORD(wParam)] = 1;
switch(wParam)
{
case VK_ESCAPE:
PostMessage(hMainWnd, WM_CLOSE, 0, 0);
return 0;
}
break;
case WM_KEYUP:
if(wParam < sizeof(bKeys)) bKeys[LOWORD(wParam)] = 0;
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
void ProcessCommandLine(char *cmdline)
{
char *str, *strLimit;
str = cmdline;
strLimit = str + strlen(str);
while(str < strLimit)
{
char *strWord;
strWord = str;
while(str[0] != '\0' && str[0] != ' ') str++;
str[0] = '\0'; str++;
if(!strcmpi(strWord, "Win")) fFullScreen = false;
else if(!strcmpi(strWord, "fs")) fFullScreen = true;
else if(!strcmpi(strWord, "640x400")) { dwScreenWidth = 640; dwScreenHeight = 400; }
else if(!strcmpi(strWord, "640x480")) { dwScreenWidth = 640; dwScreenHeight = 480; }
else if(!strcmpi(strWord, "800x600")) { dwScreenWidth = 800; dwScreenHeight = 600; }
else if(!strcmpi(strWord, "1024x768")) { dwScreenWidth = 1024; dwScreenHeight = 768; }
else if(!strcmpi(strWord, "depth16")) dwScreenDepth = 16;
else if(!strcmpi(strWord, "depth32")) dwScreenDepth = 32;
else if(!strcmpi(strWord, "TnL")) { guidDevice = IID_IDirect3DTnLHalDevice; strcpy(szDeviceName, "TnL Hal"); fHwDevice = true; }
else if(!strcmpi(strWord, "HAL")) { guidDevice = IID_IDirect3DHALDevice; strcpy(szDeviceName, "Hal"); fHwDevice = true; }
else if(!strcmpi(strWord, "RGB")) { guidDevice = IID_IDirect3DRGBDevice; strcpy(szDeviceName, "RGB"); fHwDevice = false; }
else if(!strcmpi(strWord, "Ref")) { guidDevice = IID_IDirect3DRefDevice; strcpy(szDeviceName, "Ref"); fHwDevice = false; }
while(str < strLimit && str[0] == ' ') str++;
}
}