59 static LARGE_INTEGER perf_freq;
60 static LARGE_INTEGER perf_cnt1;
61 static LARGE_INTEGER perf_cnt2;
66 : world(0), video_factory(0), video(0), video_settings(0), soundcard(0),
67 gamma(128), max_tex_size(2048), screen(0), totaltime(0),
68 hInst(0), hwnd(0), frame_rate(0), frame_count(0), frame_count0(0),
69 frame_time(0), frame_time0(0), gui_seconds(0), content(0),
70 status(
Game::OK), exit_code(0), window_style(0), avi_file(0)
172 if (game && game->
video) {
187 if (game && game->
video) {
200 if (game && n >= 64 && n <= 4096)
240 Game::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline,
int nCmdShow)
245 Print(
" Initializing Game\n");
250 Panic(
"Could not initialize the application.");
255 Panic(
"No video settings specified");
263 Panic(
" Windows 95 and 98 are no longer supported. Please update to Windows XP or higher.");
266 Panic(
" D3D not available under WinNT 4");
269 Panic(
" Insufficient DirectX detected (Dx9 IS REQUIRED)");
277 Print(
"\n Initializing instance...\n");
280 Panic(
"Could not initialize the instance.");
286 Print(
" Initializing content...\n");
289 Print(
" Initializing game...\n");
292 Panic(
"Could not initialize the game.");
306 LOGBRUSH brush = { BS_SOLID, RGB(0,0,0), 0 };
309 brush.lbColor = RGB(255,255,255);
313 wc.style = CS_HREDRAW | CS_VREDRAW;
314 wc.lpfnWndProc = (WNDPROC)
WndProc;
317 wc.hInstance = hInstance;
318 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(100));
319 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
321 wc.hbrBackground = CreateBrushIndirect(&brush);
326 if (RegisterClass(&wc) == 0) {
327 DWORD
err = GetLastError();
333 Print(
"WARNING: Register Window Class: %08x\n", err);
348 QueryPerformanceFrequency(&perf_freq);
349 QueryPerformanceCounter(&perf_cnt1);
352 int screenx = GetSystemMetrics(SM_CXSCREEN);
353 int screeny = GetSystemMetrics(SM_CYSCREEN);
369 if (s_width < screenx)
370 x_offset = (screenx - s_width) / 2;
372 if (s_height < screeny)
373 y_offset = (screeny - s_height) / 2;
377 rctmp.left = x_offset;
378 rctmp.top = y_offset;
379 rctmp.right = x_offset + s_width;
380 rctmp.bottom = y_offset + s_height;
382 window_style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |
383 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE;
396 rctmp.right - rctmp.left,
397 rctmp.bottom - rctmp.top,
406 Panic(
"Could not create window\n");
410 Print(
" Window created.\n");
413 ShowWindow(
hwnd, nCmdShow);
425 Print(
" Instance initialized.\n");
440 Print(
" Init Video...\n");
446 if (!video->IsHardware()) {
450 Panic(
"3D Hardware Not Found");
454 else if (video->GetVideoSettings()) {
474 Print(
" Reset Video...\n");
485 Panic(
"Could not re-create Video Interface.");
489 Print(
" Re-created video object.\n");
501 Panic(
"Could not re-create Screen object.");
505 Print(
" Re-created screen object.\n");
508 Print(
" WARNING: could not set video background color to Black\n");
510 screen->ClearAllFrames(
true);
513 Print(
" Re-established requested video parameters.\n");
516 Print(
" Refreshed texture bitmaps.\n\n");
538 if (client_old.right - client_old.left !=
540 client_old.bottom - client_old.top !=
664 SetWindowLong(
hwnd, GWL_STYLE, WS_POPUP|WS_SYSMENU|WS_VISIBLE);
681 Print(
" InitGame() - server mode.\n");
686 Panic(
"Could not set up the palette.");
690 Print(
" Palette loaded.\n");
694 Panic(
"Could not create the Video Interface.");
698 Print(
" Created video object.\n");
705 Panic(
"Could not create the Screen object.");
709 Print(
" Created screen object.\n");
712 Print(
" WARNING: could not set video background color to Black\n");
717 Print(
" Established requested video parameters.\n\n");
738 int n = filename->
indexOf(
'_');
788 WORD NumberOfEntries;
789 PALETTEENTRY Entries[256];
791 } Palette = { 0x300, 256 };
799 Print(
" Could not open file '%s'\n", fname);
803 memcpy(&palheader, block, 24);
804 memcpy((
char*) Palette.Entries, (block+24), 256*4);
806 for (
int i = 0; i < 256; i++) {
807 *pal++ = Palette.Entries[i];
815 Print(
" Could not open file '%s'\n", fname);
819 memcpy(inv, block, 32768);
834 Print(
"+====================================================================+\n");
836 Print(
"+====================================================================+\n");
840 if (PeekMessage(&msg,
hwnd, 0, 0, PM_REMOVE)) {
841 if (msg.message == WM_QUIT)
844 TranslateMessage(&msg);
845 DispatchMessage(&msg);
861 Print(
"\n\n*** Game::Exit()\n");
868 if (msg)
Print(
"*** PANIC: %s\n", msg);
869 else Print(
"*** PANIC! ***\n");
871 if (!msg) msg =
"Unspecified fatal error.";
872 sprintf_s(
panicbuf,
"%s\nThis game will now terminate.", msg);
917 bool wait_for_windows_events =
true;
935 wait_for_windows_events =
false;
942 QueryPerformanceCounter(&perf_cnt2);
944 double freq = (double) (perf_freq.QuadPart);
945 double msec = (double) (perf_cnt2.QuadPart - perf_cnt1.QuadPart);
958 perf_cnt1 = perf_cnt2;
960 return wait_for_windows_events;
983 frame_time = new_time;
1035 Panic(
"Screen refresh failed.");
1079 if (game && game->
video)
1088 if (game && game->
video)
1101 static DWORD last_shot = 0;
1102 static DWORD shot_num = 1;
1106 if (!name && (
real_time - last_shot) < 1000)
1118 for (
int i = 0; i < shot_list.
size(); i++) {
1119 Text* s = shot_list[i];
1122 sscanf_s(s->
data()+1,
"%d", &n);
1123 if (shot_num <= (DWORD) n)
1131 strcpy_s(filename, name);
1133 sprintf_s(filename,
"A%d.PCX", shot_num++);
1139 pcx.
Save((
char*) filename);
1167 for (
int i = 0; i < avi_list.
size(); i++) {
1168 Text* s = avi_list[i];
1171 sscanf_s(s->
data()+1,
"%d", &n);
1172 if (avi_num <= (DWORD) n)
1180 strcpy_s(filename, name);
1182 sprintf_s(filename,
"A%d.avi", avi_num);
1241 Print(
"Performance Data:\n");
1242 Print(
"-----------------\n");
1244 Print(
" Time: %d msec\n", totaltime);
1252 Print(
"Performance Statistics:\n");
1253 Print(
"-----------------------\n");
1269 #ifndef WM_MOUSEWHEEL
1270 #define WM_MOUSEWHEEL 0x20A
1273 LRESULT CALLBACK
WndProc(HWND hwnd, UINT message, WPARAM uParam, LPARAM lParam)
1277 if (uParam == VK_TAB || uParam == VK_F4)
1278 return DefWindowProc(hwnd, message, uParam, lParam);
1283 return MNC_CLOSE << 16;
1285 case WM_ACTIVATEAPP:
1292 if (!game || !game->
OnPaint())
1293 return DefWindowProc(hwnd, message, uParam, lParam);
1298 return DefWindowProc(hwnd, message, uParam, lParam);
1307 case WM_ENTERSIZEMOVE:
1315 if (game && game->
hwnd != NULL ) {
1318 if (uParam == SIZE_MINIMIZED) {
1324 else if (uParam == SIZE_MAXIMIZED) {
1333 else if (uParam == SIZE_RESTORED) {
1354 case WM_EXITSIZEMOVE:
1362 case WM_ENTERMENULOOP:
1367 case WM_EXITMENULOOP:
1388 Mouse::x = LOWORD(lParam);
1389 Mouse::y = HIWORD(lParam);
1392 case WM_LBUTTONDOWN:
1396 case WM_LBUTTONDBLCLK:
1404 case WM_MBUTTONDOWN:
1408 case WM_MBUTTONDBLCLK:
1416 case WM_RBUTTONDOWN:
1420 case WM_RBUTTONDBLCLK:
1430 int w = (int) (uParam >> 16);
1431 if (w > 32000) w -= 65536;
1442 return DefWindowProc(hwnd, message, uParam, lParam);
1453 static int vkins = 0;
1454 static int vkext = 0;
1466 if (vkey < 1)
return;
1470 if (GetAsyncKeyState(VK_SHIFT))
1473 if (GetAsyncKeyState(VK_CONTROL))
1476 if (GetAsyncKeyState(VK_MENU))
1479 vkbuf[vkins] = vkey;
1480 vkshiftbuf[vkins++] = shift;
1485 if (vkins == vkext) {
1495 if (vkins == vkext)
return 0;
1497 int result = vkbuf[vkext++];
1507 if (vkins == vkext)
return 0;
1510 shift = vkshiftbuf[vkext++];
1523 vsprintf_s(
ErrBuf, fmt, (
char *)(&fmt+1));
1537 return timeGetTime();
1557 if (comp > 0 && comp <= 100)