2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: descentw.c,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $";
17 #pragma on (unreferenced)
50 #define MIN_VIRTUAL_MEM_FREE (16 * (1024*1024))
51 #define MIN_PHYSICAL_MEM_FREE (16 * (1024*1024))
52 #define SOUND_22K_CUTOFF (16 *1024*1024) // 8.0 MB
55 // Globals --------------------------------------------------------------------
57 HWND _hAppWnd; // Descent Window
58 HINSTANCE _hAppInstance;
59 int _DDraw = 0; // No DirectX
60 char *_OffscreenCanvasBits; // Pointer to Offscreen Canvas Bits.
61 BOOL _AppActive = FALSE; // Is application active?
62 BOOL _AppPaused = FALSE; // Shall we run game?
63 BOOL _AppInit = FALSE; // Is application initialized?
64 BOOL _RedrawScreen=FALSE; // Shall we force a redraw of the screen?
65 SCREEN_CONTEXT _SCRContext;
67 HANDLE hDescent2Mutex = NULL; // handle to determine whether D2 is already running
68 HANDLE hDescent2Mutex2 = NULL;
70 BOOL AllowActivates = FALSE;
72 // HACK, to keep original CD audio vol.
73 DWORD CD_audio_desktop_vol = 0;
74 int CD_audio_desktop_dev = -1;
78 int Platform_system=0;
81 extern int Mono_initialized;
82 extern int WinEnableInt3;
83 extern int DD_Emulation;
84 extern int Skip_briefing_screens; // So we can skip the briefing
85 extern int digi_system_initialized;
86 extern int framerate_on;
87 extern ubyte gr_palette_faded_out;
88 extern int piggy_low_memory; // FROM PIGGY.C!
89 extern RECT ViewportRect;
90 extern int Joystick_calibrating;
92 // Game State and other Variables ---------------------------------------------
94 static char WinErrorMessage[512];
95 static BOOL WinErrorTrap = FALSE;
96 static BOOL GameShutdown = FALSE;
97 //static BOOL GameInitialized = FALSE;
98 static BOOL WinEnableMovies = TRUE;
101 // External Functions ---------------------------------------------------------
103 extern void grwin_gdi_realizepal(HDC hdc);
104 extern void grwin_cleanup_palette();
106 extern void GameLoop(int, int);
107 extern void game_setup(void);
108 extern void check_joystick_calibration();
109 extern void DDResizeViewport(void);
110 extern void SetWinMonoInfo(HWND hWnd, HINSTANCE hInstance);
112 extern void InitCD(char *arg);
113 extern void InitVideo(void);
114 extern void InitIO(void);
115 extern void InitData(void);
116 extern void InitSound(void);
117 extern void InitNetwork(void);
118 extern void InitDescent(void);
119 extern void InitPilot(void);
122 // Function Prototypes --------------------------------------------------------
124 int RunGame(int argc, char *argv[]);
125 int RestoreGameSurfaces(void);
126 void ValidateSystem(void);
127 void MakeCodeWritable(void);
128 int ParseArgs(char *argv[], LPSTR lpCmdLine);
129 void WErrorCatch(char *message);
131 void DoRegisterCheck(void);
134 void AppPaint(HWND hWnd, HDC hdc);
135 void AppSize(HWND hWnd);
136 void AppActivate(HWND hWnd, UINT wParam);
137 void AppQueryPalette(HWND hWnd);
138 void AppPaletteChange(HWND hWnd, UINT wParam);
139 void AppDisplayChange(HWND hWnd, int w, int h, int bpp);
140 BOOL AppHandleSystemKeys(UINT msg, UINT wParam, UINT lParam);
142 BOOL GameCheckMultiReactor();
144 LRESULT WINAPI _export DescentWndProc(HWND hWnd,UINT msg,UINT wParam,
149 // Initialization and Destruction
150 // ----------------------------------------------------------------------------
152 BOOL AppInit(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
154 // Create Application Window and Initialize WinG stuff.
164 if (FindArg("-logfile")) loginit("descentw.log");
170 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
171 wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(D2_ICON));
172 wc.lpszMenuName = NULL;
173 wc.lpszClassName = "DescentWndClass";
174 wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
175 wc.hInstance = hInst;
176 wc.style = CS_DBLCLKS;
177 wc.lpfnWndProc = (WNDPROC)DescentWndProc;
181 if (!RegisterClass(&wc)) return FALSE;
184 // Arrgh, make entire code segment writable for now.
185 // -codereadonly forces read only code (debug purposes)
187 if (!FindArg("-codereadonly"))
196 _hAppInstance = hInst;
197 _hAppWnd = CreateWindowEx(WS_EX_APPWINDOW,
200 WS_POPUP | WS_SYSMENU | WS_BORDER,
202 GetSystemMetrics(SM_CXSCREEN),
203 GetSystemMetrics(SM_CYSCREEN),
209 Assert(_hAppWnd != 0);
211 ShowWindow(_hAppWnd, SW_SHOWNORMAL);
212 UpdateWindow(_hAppWnd);
214 // Tell Descent Libraries about Windows
216 // LoadCursorWin(MOUSE_WAIT_CURSOR);
221 if (FindArg("-monodebug")) Mono_initialized = 1;
222 else // link to below line!
224 Mono_initialized = 0;
226 Mono_initialized = 1;
231 SetLibraryWinInfo(_hAppWnd, _hAppInstance);
234 mopen( 0, 9, 1, 78, 15, "Debug Spew");
235 mopen( 1, 2, 1, 78, 5, "Errors & Serious Warnings");
244 // HACK do this when the application is closing! restore the CD audio volume.
245 if (CD_audio_desktop_dev != -1)
246 auxSetVolume(CD_audio_desktop_dev, CD_audio_desktop_vol);
248 grwin_cleanup_palette();
250 LoadCursorWin(MOUSE_DEFAULT_CURSOR);
255 cprintf("\n\n%s", WinErrorMessage);
259 CloseWindow(_hAppWnd);
260 cprintf("\n\nDescent II for Win95 done...\n");
266 MessageBox(NULL, WinErrorMessage, "Descent II error", MB_OK);
274 CloseHandle(hDescent2Mutex2);
277 CloseHandle(hDescent2Mutex); // Destroy Mutex Object!
280 extern char CDROM_dir[30];
282 void DoRegisterCheck()
285 PROCESS_INFORMATION pi;
289 strcpy(filename, CDROM_dir);
290 strcat(filename, "regcard.exe");
292 memset(&si, 0, sizeof(si));
294 si.dwFlags = STARTF_USESHOWWINDOW;
295 si.wShowWindow = SW_SHOW;
297 flag = CreateProcess(
299 filename, NULL, NULL,
300 FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL,
304 dwval = WaitForInputIdle(pi.hProcess, INFINITE);
306 while (WaitForSingleObject(pi.hProcess, 0) != WAIT_OBJECT_0)
310 mprintf((1, "JOY.CPL process finished?\n"));
311 ShowWindow(_hAppWnd, SW_MAXIMIZE);
312 SetForegroundWindow(_hAppWnd);
317 // Game -----------------------------------------------------------------------
319 char commandline_help[] =
320 "Command-line options (case is not significant):\n"
322 " General Options:\n"
324 " -LowMem Lower animation detail for better performance with low memory\n"
325 " -NoLowMem Force high animation detail even when low memory\n"
326 " -Subtitles Turn on movie subtitles (English-only)\n"
328 " Input devices: -SpecialDevice\n"
330 " -IForce <n> Use Immersion tactile feedback joystick on port <n>\n"
334 " -NoSound Turns off sound & music\n"
335 " -NoMusic Disables music; sound effects remain enabled\n"
336 " -Sound22K Use 22KHz sounds, even if machine has less than 16 MB\n"
337 " -Sound11K Use 11KHz sounds, even if machine has more than 16 MB\n"
339 " Network & Modem:\n"
341 " -CtsRts Enables CTS/RTS handshaking during null-modem games\n"
342 " -NoNetwork Disables network drivers\n"
343 " -NoSerial Disables serial drivers\n"
344 " -Packets # Specifies the packets per second where # is the number of packets\n"
345 " -Shortpackets Turn on short packets\n"
346 " -Norankings Disable multiplayer ranking system\n"
347 " -Noredunancy suppresses duplicate messages such as \"You already have ....\"\n"
350 " -emul Certain video cards need this option in order to run game.\n"
351 " -ddemul If -emul doesn't work, use this option.\n";
353 print_commandline_help()
356 MessageBox(NULL, commandline_help, "Descent II Command-line Options", MB_OK);
359 int RunGame(int argc, char *argv[])
364 setbuf(stdout, NULL);
365 error_init(WErrorCatch, NULL);
368 if (FindArg("-stopwatch"))
376 // InitArgs(argc, argv);
389 if (!FindArg("-nonetwork"))
392 if (!FindArg("-noserial"))
395 AllowActivates = TRUE;
402 newdemo_start_playback("DESCENT.DEM");
403 if (Newdemo_state == ND_STATE_PLAYBACK )
404 Function_mode = FMODE_GAME;
407 // do this here because the demo code can do a longjmp when trying to
408 // autostart a demo from the main menu, never having gone into the game
411 while (Function_mode != FMODE_EXIT)
413 val = DoMessageStuff(&msg);
417 switch (Function_mode)
421 set_screen_mode(SCREEN_MENU);
424 newdemo_start_playback(NULL);
425 if (Newdemo_state != ND_STATE_PLAYBACK)
426 Error("No demo files were found for autodemo mode!");
429 DEFINE_SCREEN(Menu_pcx_name);
430 mprintf((1, "%s\n", Menu_pcx_name));
443 if ( Function_mode == FMODE_MENU )
444 songs_play_song( SONG_TITLE, 1 );
445 mprintf((0, "Function mode = %d\n", Function_mode));
451 dd_gr_set_current_canvas(NULL);
452 dd_gr_clear_canvas(BM_XRGB(0,0,0));
460 // Window Message Functions
461 // ----------------------------------------------------------------------------
463 void AppPaint(HWND hWnd, HDC hdc)
465 // grwin_gdi_realizepal(hdc);
469 void AppSize(HWND hWnd)
471 if (IsIconic(hWnd)) {
473 InvalidateRect(hWnd, NULL, TRUE);
475 else if (GetForegroundWindow() == hWnd) {
480 mprintf((0, "Resized window (%d,%d,%d,%d).\n", ViewportRect.left, ViewportRect.top, ViewportRect.right, ViewportRect.bottom));
484 void AppActivate(HWND hWnd, UINT wParam)
486 _AppActive = (BOOL)(wParam) && GetForegroundWindow()==hWnd && !IsIconic(hWnd);
489 mprintf((0, "Descent II is gaining Window focus.\n"));
490 cprintf("Descent II is gaining Window focus.\n");
493 mprintf((0, "Descent II is losing Window focus.\n"));
494 cprintf("Descent II is losing Window focus.\n");
497 // Must now unpause if paused and app is active now.
498 mprintf((0, "AppActivate: Active: %d, Paused: %d\n", _AppActive, _AppPaused));
500 if (_AppActive && AllowActivates && !_AppPaused)
504 else if (AllowActivates) {
511 void AppQueryPalette(HWND hWnd)
513 // if (!_DDFullScreen && _lpDDPalette && _lpDDSPrimary) {
514 // gr_palette_load(gr_palette);
516 mprintf((0, "QUERY PALETTE!\n"));
520 void AppCreate(HWND hWnd)
524 // Remove system menu components not good
525 hMenu = GetSystemMenu(hWnd, FALSE);
527 RemoveMenu(hMenu, SC_SIZE, MF_BYCOMMAND);
528 RemoveMenu(hMenu, SC_MOVE, MF_BYCOMMAND);
532 void AppPaletteChange(HWND hWnd, UINT wParam)
534 if ((HWND)wParam != hWnd) {
535 if (!_DDFullScreen) {
536 mprintf((0, "Palette changed!\n"));
538 mprintf((0, "Descent 2 is paused.\n"));
543 //static LPDIRECTDRAWSURFACE Page0Buffer = 0;
545 void AppDisplayChange(HWND hWnd, int w, int h, int bpp)
547 // mprintf((0, "Windows feels a display change coming...\n"));
551 BOOL AppHandleSystemKeys(UINT msg, UINT wParam, UINT lParam)
553 // Intercept ALT keystrokes
555 if (msg == WM_SYSKEYUP) {
556 mprintf((0,"ALT key down!"));
559 send_key_msg(msg, wParam, lParam);
561 if (wParam == VK_TAB || wParam == VK_ESCAPE) return FALSE;
567 int RestoreGameSurfaces()
569 if (dd_VR_offscreen_buffer) {
570 if (!dd_VR_offscreen_buffer->lpdds) return 1;
571 if (IDirectDrawSurface_Restore(dd_VR_offscreen_buffer->lpdds) != DD_OK) {
572 mprintf((1, "Warning: Unable to restore dd_VR_offscreen_buffer!\n"));
575 mprintf((0, "Restored dd_VR_offscreen_buffer\n"));
582 LRESULT WINAPI _export DescentWndProc(HWND hWnd,
588 //static int nTimer = 0;
597 if((wParam&0xFFF0)==SC_SCREENSAVE || (wParam&0xFFF0)==SC_MONITORPOWER)
600 if ((wParam&0xfff0)== SC_KEYMENU && _AppActive) {
601 mprintf((0, "W32: Bypassing system menu.\n"));
611 case WM_ACTIVATEAPP: // Application is losing focus.
612 AppActivate(hWnd, wParam);
615 case WM_QUERYNEWPALETTE:
616 AppQueryPalette(hWnd);
619 case WM_PALETTECHANGED:
620 AppPaletteChange(hWnd, wParam);
623 case WM_DISPLAYCHANGE: // Screen Mode is changing.
624 AppDisplayChange(hWnd, LOWORD(lParam), HIWORD(lParam), wParam);
629 if (AppHandleSystemKeys(msg, wParam,lParam))
635 if (wParam == VK_SNAPSHOT) {
636 mprintf((0, "Capture screen begins...\n"));
638 if (!clipboard_screenshot())
639 mprintf((1, "Failed to create clipboard screenshot!\n"));
642 // if (msg == WM_KEYDOWN && wParam == 0x49) ipx_debug_hold_packets = 1;
643 // if (msg == WM_KEYUP && wParam == 0x49) ipx_debug_hold_packets = 0;
645 send_key_msg(msg, wParam, lParam);
649 // hdc = BeginPaint(hWnd, &ps);
650 // AppPaint(hWnd, hdc);
651 // EndPaint(hWnd, &ps);
656 case MM_JOY1BUTTONDOWN:
657 case MM_JOY1BUTTONUP:
658 if (!_AppPaused && (_AppActive || !_DDFullScreen)) {
659 joy_handler_win(hWnd, msg, wParam, lParam);
664 mprintf((0, "Killing main window...\n"));
669 // digi_midi_debug();
670 mouse_win_callback(msg, wParam, lParam);
672 return DefWindowProc(hWnd, msg, wParam, lParam);
676 static char *WinArgs[64];
679 // ----------------------------------------------------------------------------
681 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine,
688 argc = ParseArgs(WinArgs, szCmdLine);
689 InitArgs(argc, WinArgs);
691 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) ) {
692 print_commandline_help();
693 set_exit_message("");
697 if (AppInit(hInst, hPrev, szCmdLine, nCmdShow)) {
698 retval = RunGame(argc, WinArgs);
706 // Low Level Routines
707 // ----------------------------------------------------------------------------
709 static char *NoMovieArg = "-nomovies";
710 static char *PathArg = "descentw.exe";
712 int ParseArgs(char *argv[], LPSTR lpCmdLine)
720 argv[argc++] = PathArg;
722 // while (lpCmdLine[i] == '-' || lpCmdLine[i] == '/' )
726 if (lpCmdLine[i] == ' ') i++;
728 argv[argc++] = &lpCmdLine[i];
730 while (lpCmdLine[i]!=' ' && lpCmdLine[i]!= 0) {
731 //mprintf((0, "%c", lpCmdLine[i]));
735 // mprintf((0, "Argument %s.\n", argv[argc-1]));
739 if (!WinEnableMovies)
740 argv[argc++] = NoMovieArg;
746 extern void rls_stretch_scanline_asm();
749 void MakeCodeWritable(void)
751 typedef DWORD __stdcall translator(DWORD);
754 BYTE *pImageBase = 0;
757 modCode = GetModuleHandle(0);
758 version = GetVersion();
760 // For Win32s we have to use undocumented features
761 if ((version < 0x80000000) || ((BYTE)version >=0x04)) {
763 pImageBase = (BYTE *)modCode;
766 MessageBox(NULL, "Descent II cannot run under Windows 3.x", "Descent II", MB_OK);
774 IMAGE_OPTIONAL_HEADER *pHeader =
775 (IMAGE_OPTIONAL_HEADER *)(pImageBase + ((IMAGE_DOS_HEADER *)pImageBase)->e_lfanew +
776 sizeof(IMAGE_NT_SIGNATURE) + sizeof(IMAGE_FILE_HEADER));
778 //@@ if (!VirtualProtect(pImageBase+pHeader->BaseOfCode, pHeader->SizeOfCode,
779 //@@ PAGE_READWRITE, &oldRights)) {
783 if (!VirtualProtect(rls_stretch_scanline_asm, 4096*2, PAGE_READWRITE, &oldRights)) {
784 MessageBox(NULL, "Unable to gain write access to requested page.", "Descent II Error", MB_OK);
788 // wsprintf(buf, "Start:%x FN1:%x",(DWORD)pImageBase+pHeader->BaseOfCode, (DWORD)rls_stretch_scanline_asm);
789 // MessageBox(NULL, buf, "Info", MB_OK);
794 void ValidateSystem()
798 version = GetVersion();
800 if ((version < 0x80000000) || ((BYTE)version >=0x04)) {
801 if ((version < 0x80000000) && ((BYTE)version >= 0x04)) {
802 Platform_system = WINNT_PLATFORM;
805 else Platform_system = WIN95_PLATFORM;
808 MessageBox(NULL, "Descent II will not run under Windows 3.x", "DESCENT II", MB_OK);
812 // Do the named mutex thingy.
814 HANDLE hMutex, hMutex2;
816 hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "BigRedStinksMutex");
818 hMutex2 = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "BigRedSucksMutex");
820 CloseHandle(hMutex2);
821 exit(1); // Don't even tell user he's trying to run a third copy
824 hDescent2Mutex2 = CreateMutex(NULL, FALSE, "BigRedSucksMutex");
825 if (!hDescent2Mutex2) {
826 MessageBox(NULL, "Unable to create second mutex object.", "Descent II error", MB_OK);
829 MessageBox(NULL, "You may only run one instance of Descent II at a time.",
830 "Descent II error", MB_OK);
834 hDescent2Mutex = CreateMutex(NULL, FALSE, "BigRedStinksMutex");
835 if (!hDescent2Mutex) {
836 MessageBox(NULL, "Unable to create mutex object.", "Descent II error", MB_OK);
840 // Do the Version ID thing for Beta testers
841 #if defined(RELEASE) && defined(VERSION_NAME) && !defined(NDEBUG)
845 sprintf(buf, "Descent II %s v%d.%d\n%s\n%s %s", VERSION_TYPE, Version_major, Version_minor,
846 VERSION_NAME, __DATE__, __TIME__);
847 MessageBox(NULL, buf, "Descent II beta information", MB_OK);
851 // Super memory check
853 MEMORYSTATUS memstat;
856 memset(&memstat, 0, sizeof(memstat));
857 memstat.dwLength = sizeof(memstat);
858 GlobalMemoryStatus(&memstat);
860 logentry("Memory: \n");
861 logentry(" MemoryLoad = %10d\n",memstat.dwMemoryLoad);
862 logentry(" TotalPhys = %10d\n",memstat.dwTotalPhys);
863 logentry(" AvailPhys = %10d\n",memstat.dwAvailPhys);
864 logentry(" TotalPageFile = %10d\n",memstat.dwTotalPageFile);
865 logentry(" AvailPageFile = %10d\n",memstat.dwAvailPageFile);
866 logentry(" TotalVirtual = %10d\n",memstat.dwTotalVirtual);
867 logentry(" AvailVirtual = %10d\n",memstat.dwAvailVirtual);
869 mem_free = memstat.dwTotalPhys;
871 // logentry(" mem_free = %10d\n",mem_free);
873 if ( mem_free < MIN_PHYSICAL_MEM_FREE) {
874 logentry("Using low memory option.\n");
875 piggy_low_memory = 1;
878 if ( memstat.dwAvailPageFile < MIN_VIRTUAL_MEM_FREE) {
879 MessageBox(NULL, "Not enough virtual memory.\n You need at least 16MB of free drive space.\n",
880 "Descent II Error", MB_OK);
884 if ( ((mem_free > SOUND_22K_CUTOFF) || FindArg("-sound22k")) && !FindArg("-sound11k") && !FindArg("-lowmem") ) {
885 logentry("Using 22KHz sounds\n");
886 digi_sample_rate = SAMPLE_RATE_22K;
888 logentry("Using 11KHz sounds\n");
889 digi_sample_rate = SAMPLE_RATE_11K;
895 int DoMessageStuff(MSG *msg)
900 if (PeekMessage(msg, NULL, 0, 0, PM_REMOVE)) {
901 if (msg->message == WM_QUIT) {
906 TranslateMessage(msg);
907 DispatchMessage(msg);
909 else if (!_AppPaused && (_AppActive || !_DDFullScreen)) {
913 if ((Game_mode & GM_MULTI)) {
914 if (Control_center_destroyed) {
915 ShowWindow(_hAppWnd, SW_MAXIMIZE);
917 SetForegroundWindow(_hAppWnd);
919 _RedrawScreen = TRUE;
921 else if (multi_menu_poll() == -1) {
922 ShowWindow(_hAppWnd, SW_MAXIMIZE);
925 if (GetForegroundWindow() == _hAppWnd) {
926 if (_AppPaused || !_AppActive) {
927 mprintf((0, "Descent2 Daemon...Pause: %d, Active %d\n",_AppPaused, _AppActive));
928 SetActiveWindow(_hAppWnd);
929 _RedrawScreen = FALSE;
934 SetForegroundWindow(_hAppWnd);
936 _RedrawScreen = FALSE;
941 mprintf((0, "Waiting...Pause: %d, Active %d\n",_AppPaused, _AppActive));
956 mprintf((0, "Entering Idle message loop...\n"));
960 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
961 if (msg.message == WM_QUIT) {
966 mprintf((0, "Retreiving message(0x%x:0x%x,0x%x) in idle loop.\n",msg.message, msg.wParam, msg.lParam));
968 TranslateMessage(&msg);
969 DispatchMessage(&msg);
977 void WinDelay(int msecs)
983 timeout = timeGetTime() + msecs;
985 while (timeout > timeGetTime())
987 DoMessageStuff(&msg);
988 if (msg.message == WM_QUIT) exit(0);
993 void WErrorCatch(char *message)
995 mprintf((1, "Bye Bye: %s\n", message));
997 strcpy(WinErrorMessage, message);
1001 logentry("%s", WinErrorMessage);
1002 CloseWindow(_hAppWnd);
1006 //static BOOL CursorVisible = TRUE;
1007 static HANDLE CursorHandle = NULL;
1010 void LoadCursorWin(int cursor)
1014 case MOUSE_DEFAULT_CURSOR:
1015 CursorHandle = LoadCursor(NULL, IDC_ARROW);
1018 case MOUSE_WAIT_CURSOR:
1019 CursorHandle = LoadCursor(NULL, IDC_WAIT);
1023 CursorHandle = NULL;
1026 SetCursor(CursorHandle);
1032 while (ShowCursor(FALSE) >=0);
1038 if (DD_Emulation) return;
1040 if (CursorHandle == NULL)
1041 LoadCursorWin(MOUSE_DEFAULT_CURSOR);
1043 while (ShowCursor(TRUE) < 0);
1048 // Descent 2 Shutdown and Restore functions
1049 // ----------------------------------------------------------------------------
1051 void SaveVideoState();
1052 void RestoreVideoState();
1054 static int Saved_Game_window_w;
1055 static int Saved_Game_window_h;
1056 static int SavedScreenMode = 0;
1058 extern int Digi_initialized;
1059 extern BOOL WMVEPlaying, RMVEPlaying;
1060 extern int current_song_level;
1063 void RestoreScreenContext()
1065 if ( _SCRContext.bkg_filename != NULL ) {
1066 mprintf((0, "Loading background file...\n"));
1067 nm_draw_background1( _SCRContext.bkg_filename );
1069 gr_palette_load(gr_palette);
1075 if (GameShutdown) return;
1079 if (!Joystick_calibrating) joy_stop_poll();
1087 if (CD_audio_desktop_dev != -1)
1088 auxSetVolume(CD_audio_desktop_dev, CD_audio_desktop_vol);
1090 if (Function_mode == FMODE_GAME && !(Game_mode &GM_MULTI)) {
1094 mprintf((0, "WMVE: %d, RMVE: %d\n", WMVEPlaying, RMVEPlaying));
1096 if (WMVEPlaying) MovieShutdown();
1097 if (RMVEPlaying) MVE_rmHoldMovie();
1099 if (!WMVEPlaying) digi_reset();
1101 mprintf((0, "Descent 2 is asleep...\n"));
1103 GameShutdown = TRUE;
1109 if (!GameShutdown) return;
1111 if (!WMVEPlaying) digi_reset();
1115 if (CD_audio_desktop_dev != -1)
1116 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
1120 else if (RMVEPlaying) {
1122 // if (_lpDD) RestoreVideoState();
1123 dd_gr_init_screen();
1124 W95DisplayMode = -1;
1126 if (SavedScreenMode != -1)
1127 set_screen_mode(SavedScreenMode);
1129 if (CD_audio_desktop_dev != -1)
1130 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
1132 _RedrawScreen = TRUE;
1137 if (_lpDD) RestoreVideoState();
1139 if (CD_audio_desktop_dev != -1)
1140 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
1142 if (Function_mode == FMODE_MENU) songs_play_song(SONG_TITLE, 1);
1143 if (Function_mode == FMODE_GAME) {
1144 songs_play_level_song(current_song_level);
1151 if (Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) start_time();
1152 else if (Function_mode == FMODE_MENU)
1153 keyd_time_when_last_pressed = timer_get_fixed_seconds();
1156 if (!Joystick_calibrating) joy_start_poll();
1157 set_redbook_volume(Config_redbook_volume);
1158 mprintf((0, "...Descent 2 is awake!\n"));
1160 GameShutdown = FALSE;
1164 void SaveVideoState()
1166 // If in game mode, then restore window size
1167 if (Screen_mode == SCREEN_GAME) {
1168 Saved_Game_window_w = Game_window_w;
1169 Saved_Game_window_h = Game_window_h;
1173 SavedScreenMode = Screen_mode;
1178 void RestoreVideoState()
1180 // Just reinitialize screen state.
1181 dd_gr_init_screen();
1182 W95DisplayMode = -1;
1185 // If in game mode, then restore window size
1186 if (SavedScreenMode != -1)
1187 set_screen_mode(SavedScreenMode);
1189 if (SavedScreenMode == SCREEN_GAME) {
1190 Game_window_w = Saved_Game_window_w;
1191 Game_window_h = Saved_Game_window_h;
1194 if (Function_mode == FMODE_GAME) {
1195 load_palette(Current_level_palette,1,1);
1198 _RedrawScreen = TRUE;
1199 RestoreScreenContext();