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 int Current_display_mode;
88 extern ubyte gr_palette_faded_out;
89 extern int piggy_low_memory; // FROM PIGGY.C!
90 extern RECT ViewportRect;
91 extern int Joystick_calibrating;
93 // Game State and other Variables ---------------------------------------------
95 static char WinErrorMessage[512];
96 static BOOL WinErrorTrap = FALSE;
97 static BOOL GameShutdown = FALSE;
98 //static BOOL GameInitialized = FALSE;
99 static BOOL WinEnableMovies = TRUE;
102 // External Functions ---------------------------------------------------------
104 extern void grwin_gdi_realizepal(HDC hdc);
105 extern void grwin_cleanup_palette();
107 extern void GameLoop(int, int);
108 extern void game_setup(void);
109 extern void check_joystick_calibration();
110 extern void DDResizeViewport(void);
111 extern void SetWinMonoInfo(HWND hWnd, HINSTANCE hInstance);
113 extern void InitCD(char *arg);
114 extern void InitVideo(void);
115 extern void InitIO(void);
116 extern void InitData(void);
117 extern void InitSound(void);
118 extern void InitNetwork(void);
119 extern void InitDescent(void);
120 extern void InitPilot(void);
123 // Function Prototypes --------------------------------------------------------
125 int RunGame(int argc, char *argv[]);
126 int RestoreGameSurfaces(void);
127 void ValidateSystem(void);
128 void MakeCodeWritable(void);
129 int ParseArgs(char *argv[], LPSTR lpCmdLine);
130 void WErrorCatch(char *message);
132 void DoRegisterCheck(void);
135 void AppPaint(HWND hWnd, HDC hdc);
136 void AppSize(HWND hWnd);
137 void AppActivate(HWND hWnd, UINT wParam);
138 void AppQueryPalette(HWND hWnd);
139 void AppPaletteChange(HWND hWnd, UINT wParam);
140 void AppDisplayChange(HWND hWnd, int w, int h, int bpp);
141 BOOL AppHandleSystemKeys(UINT msg, UINT wParam, UINT lParam);
143 BOOL GameCheckMultiReactor();
145 LRESULT WINAPI _export DescentWndProc(HWND hWnd,UINT msg,UINT wParam,
150 // Initialization and Destruction
151 // ----------------------------------------------------------------------------
153 BOOL AppInit(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
155 // Create Application Window and Initialize WinG stuff.
165 if (FindArg("-logfile")) loginit("descentw.log");
171 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
172 wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(D2_ICON));
173 wc.lpszMenuName = NULL;
174 wc.lpszClassName = "DescentWndClass";
175 wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
176 wc.hInstance = hInst;
177 wc.style = CS_DBLCLKS;
178 wc.lpfnWndProc = (WNDPROC)DescentWndProc;
182 if (!RegisterClass(&wc)) return FALSE;
185 // Arrgh, make entire code segment writable for now.
186 // -codereadonly forces read only code (debug purposes)
188 if (!FindArg("-codereadonly"))
197 _hAppInstance = hInst;
198 _hAppWnd = CreateWindowEx(WS_EX_APPWINDOW,
201 WS_POPUP | WS_SYSMENU | WS_BORDER,
203 GetSystemMetrics(SM_CXSCREEN),
204 GetSystemMetrics(SM_CYSCREEN),
210 Assert(_hAppWnd != 0);
212 ShowWindow(_hAppWnd, SW_SHOWNORMAL);
213 UpdateWindow(_hAppWnd);
215 // Tell Descent Libraries about Windows
217 // LoadCursorWin(MOUSE_WAIT_CURSOR);
222 if (FindArg("-monodebug")) Mono_initialized = 1;
223 else // link to below line!
225 Mono_initialized = 0;
227 Mono_initialized = 1;
232 SetLibraryWinInfo(_hAppWnd, _hAppInstance);
235 mopen( 0, 9, 1, 78, 15, "Debug Spew");
236 mopen( 1, 2, 1, 78, 5, "Errors & Serious Warnings");
245 // HACK do this when the application is closing! restore the CD audio volume.
246 if (CD_audio_desktop_dev != -1)
247 auxSetVolume(CD_audio_desktop_dev, CD_audio_desktop_vol);
249 grwin_cleanup_palette();
251 LoadCursorWin(MOUSE_DEFAULT_CURSOR);
256 cprintf("\n\n%s", WinErrorMessage);
260 CloseWindow(_hAppWnd);
261 cprintf("\n\nDescent II for Win95 done...\n");
267 MessageBox(NULL, WinErrorMessage, "Descent II error", MB_OK);
275 CloseHandle(hDescent2Mutex2);
278 CloseHandle(hDescent2Mutex); // Destroy Mutex Object!
281 extern char CDROM_dir[30];
283 void DoRegisterCheck()
286 PROCESS_INFORMATION pi;
290 strcpy(filename, CDROM_dir);
291 strcat(filename, "regcard.exe");
293 memset(&si, 0, sizeof(si));
295 si.dwFlags = STARTF_USESHOWWINDOW;
296 si.wShowWindow = SW_SHOW;
298 flag = CreateProcess(
300 filename, NULL, NULL,
301 FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL,
305 dwval = WaitForInputIdle(pi.hProcess, INFINITE);
307 while (WaitForSingleObject(pi.hProcess, 0) != WAIT_OBJECT_0)
311 mprintf((1, "JOY.CPL process finished?\n"));
312 ShowWindow(_hAppWnd, SW_MAXIMIZE);
313 SetForegroundWindow(_hAppWnd);
318 // Game -----------------------------------------------------------------------
320 char commandline_help[] =
321 "Command-line options (case is not significant):\n"
323 " General Options:\n"
325 " -LowMem Lower animation detail for better performance with low memory\n"
326 " -NoLowMem Force high animation detail even when low memory\n"
327 " -Subtitles Turn on movie subtitles (English-only)\n"
329 " Input devices: -SpecialDevice\n"
331 " -IForce <n> Use Immersion tactile feedback joystick on port <n>\n"
335 " -NoSound Turns off sound & music\n"
336 " -NoMusic Disables music; sound effects remain enabled\n"
337 " -Sound22K Use 22KHz sounds, even if machine has less than 16 MB\n"
338 " -Sound11K Use 11KHz sounds, even if machine has more than 16 MB\n"
340 " Network & Modem:\n"
342 " -CtsRts Enables CTS/RTS handshaking during null-modem games\n"
343 " -NoNetwork Disables network drivers\n"
344 " -NoSerial Disables serial drivers\n"
345 " -Packets # Specifies the packets per second where # is the number of packets\n"
346 " -Shortpackets Turn on short packets\n"
347 " -Norankings Disable multiplayer ranking system\n"
348 " -Noredunancy suppresses duplicate messages such as \"You already have ....\"\n"
351 " -emul Certain video cards need this option in order to run game.\n"
352 " -ddemul If -emul doesn't work, use this option.\n";
354 print_commandline_help()
357 MessageBox(NULL, commandline_help, "Descent II Command-line Options", MB_OK);
360 int RunGame(int argc, char *argv[])
365 setbuf(stdout, NULL);
366 error_init(WErrorCatch, NULL);
369 if (FindArg("-stopwatch"))
377 // InitArgs(argc, argv);
390 if (!FindArg("-nonetwork"))
393 if (!FindArg("-noserial"))
396 AllowActivates = TRUE;
403 newdemo_start_playback("DESCENT.DEM");
404 if (Newdemo_state == ND_STATE_PLAYBACK )
405 Function_mode = FMODE_GAME;
408 // do this here because the demo code can do a longjmp when trying to
409 // autostart a demo from the main menu, never having gone into the game
412 while (Function_mode != FMODE_EXIT)
414 val = DoMessageStuff(&msg);
418 switch (Function_mode)
422 set_screen_mode(SCREEN_MENU);
425 newdemo_start_playback(NULL);
426 if (Newdemo_state != ND_STATE_PLAYBACK)
427 Error("No demo files were found for autodemo mode!");
430 DEFINE_SCREEN(Menu_pcx_name);
431 mprintf((1, "%s\n", Menu_pcx_name));
444 if ( Function_mode == FMODE_MENU )
445 songs_play_song( SONG_TITLE, 1 );
446 mprintf((0, "Function mode = %d\n", Function_mode));
452 dd_gr_set_current_canvas(NULL);
453 dd_gr_clear_canvas(BM_XRGB(0,0,0));
461 // Window Message Functions
462 // ----------------------------------------------------------------------------
464 void AppPaint(HWND hWnd, HDC hdc)
466 // grwin_gdi_realizepal(hdc);
470 void AppSize(HWND hWnd)
472 if (IsIconic(hWnd)) {
474 InvalidateRect(hWnd, NULL, TRUE);
476 else if (GetForegroundWindow() == hWnd) {
481 mprintf((0, "Resized window (%d,%d,%d,%d).\n", ViewportRect.left, ViewportRect.top, ViewportRect.right, ViewportRect.bottom));
485 void AppActivate(HWND hWnd, UINT wParam)
487 _AppActive = (BOOL)(wParam) && GetForegroundWindow()==hWnd && !IsIconic(hWnd);
490 mprintf((0, "Descent II is gaining Window focus.\n"));
491 cprintf("Descent II is gaining Window focus.\n");
494 mprintf((0, "Descent II is losing Window focus.\n"));
495 cprintf("Descent II is losing Window focus.\n");
498 // Must now unpause if paused and app is active now.
499 mprintf((0, "AppActivate: Active: %d, Paused: %d\n", _AppActive, _AppPaused));
501 if (_AppActive && AllowActivates && !_AppPaused)
505 else if (AllowActivates) {
512 void AppQueryPalette(HWND hWnd)
514 // if (!_DDFullScreen && _lpDDPalette && _lpDDSPrimary) {
515 // gr_palette_load(gr_palette);
517 mprintf((0, "QUERY PALETTE!\n"));
521 void AppCreate(HWND hWnd)
525 // Remove system menu components not good
526 hMenu = GetSystemMenu(hWnd, FALSE);
528 RemoveMenu(hMenu, SC_SIZE, MF_BYCOMMAND);
529 RemoveMenu(hMenu, SC_MOVE, MF_BYCOMMAND);
533 void AppPaletteChange(HWND hWnd, UINT wParam)
535 if ((HWND)wParam != hWnd) {
536 if (!_DDFullScreen) {
537 mprintf((0, "Palette changed!\n"));
539 mprintf((0, "Descent 2 is paused.\n"));
544 //static LPDIRECTDRAWSURFACE Page0Buffer = 0;
546 void AppDisplayChange(HWND hWnd, int w, int h, int bpp)
548 // mprintf((0, "Windows feels a display change coming...\n"));
552 BOOL AppHandleSystemKeys(UINT msg, UINT wParam, UINT lParam)
554 // Intercept ALT keystrokes
556 if (msg == WM_SYSKEYUP) {
557 mprintf((0,"ALT key down!"));
560 send_key_msg(msg, wParam, lParam);
562 if (wParam == VK_TAB || wParam == VK_ESCAPE) return FALSE;
568 int RestoreGameSurfaces()
570 if (dd_VR_offscreen_buffer) {
571 if (!dd_VR_offscreen_buffer->lpdds) return 1;
572 if (IDirectDrawSurface_Restore(dd_VR_offscreen_buffer->lpdds) != DD_OK) {
573 mprintf((1, "Warning: Unable to restore dd_VR_offscreen_buffer!\n"));
576 mprintf((0, "Restored dd_VR_offscreen_buffer\n"));
583 LRESULT WINAPI _export DescentWndProc(HWND hWnd,
589 //static int nTimer = 0;
598 if((wParam&0xFFF0)==SC_SCREENSAVE || (wParam&0xFFF0)==SC_MONITORPOWER)
601 if ((wParam&0xfff0)== SC_KEYMENU && _AppActive) {
602 mprintf((0, "W32: Bypassing system menu.\n"));
612 case WM_ACTIVATEAPP: // Application is losing focus.
613 AppActivate(hWnd, wParam);
616 case WM_QUERYNEWPALETTE:
617 AppQueryPalette(hWnd);
620 case WM_PALETTECHANGED:
621 AppPaletteChange(hWnd, wParam);
624 case WM_DISPLAYCHANGE: // Screen Mode is changing.
625 AppDisplayChange(hWnd, LOWORD(lParam), HIWORD(lParam), wParam);
630 if (AppHandleSystemKeys(msg, wParam,lParam))
636 if (wParam == VK_SNAPSHOT) {
637 mprintf((0, "Capture screen begins...\n"));
639 if (!clipboard_screenshot())
640 mprintf((1, "Failed to create clipboard screenshot!\n"));
643 // if (msg == WM_KEYDOWN && wParam == 0x49) ipx_debug_hold_packets = 1;
644 // if (msg == WM_KEYUP && wParam == 0x49) ipx_debug_hold_packets = 0;
646 send_key_msg(msg, wParam, lParam);
650 // hdc = BeginPaint(hWnd, &ps);
651 // AppPaint(hWnd, hdc);
652 // EndPaint(hWnd, &ps);
657 case MM_JOY1BUTTONDOWN:
658 case MM_JOY1BUTTONUP:
659 if (!_AppPaused && (_AppActive || !_DDFullScreen)) {
660 joy_handler_win(hWnd, msg, wParam, lParam);
665 mprintf((0, "Killing main window...\n"));
670 // digi_midi_debug();
671 mouse_win_callback(msg, wParam, lParam);
673 return DefWindowProc(hWnd, msg, wParam, lParam);
677 static char *WinArgs[64];
680 // ----------------------------------------------------------------------------
682 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine,
689 argc = ParseArgs(WinArgs, szCmdLine);
690 InitArgs(argc, WinArgs);
692 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) ) {
693 print_commandline_help();
694 set_exit_message("");
698 if (AppInit(hInst, hPrev, szCmdLine, nCmdShow)) {
699 retval = RunGame(argc, WinArgs);
707 // Low Level Routines
708 // ----------------------------------------------------------------------------
710 static char *NoMovieArg = "-nomovies";
711 static char *PathArg = "descentw.exe";
713 int ParseArgs(char *argv[], LPSTR lpCmdLine)
721 argv[argc++] = PathArg;
723 // while (lpCmdLine[i] == '-' || lpCmdLine[i] == '/' )
727 if (lpCmdLine[i] == ' ') i++;
729 argv[argc++] = &lpCmdLine[i];
731 while (lpCmdLine[i]!=' ' && lpCmdLine[i]!= 0) {
732 //mprintf((0, "%c", lpCmdLine[i]));
736 // mprintf((0, "Argument %s.\n", argv[argc-1]));
740 if (!WinEnableMovies)
741 argv[argc++] = NoMovieArg;
747 extern void rls_stretch_scanline_asm();
750 void MakeCodeWritable(void)
752 typedef DWORD __stdcall translator(DWORD);
755 BYTE *pImageBase = 0;
758 modCode = GetModuleHandle(0);
759 version = GetVersion();
761 // For Win32s we have to use undocumented features
762 if ((version < 0x80000000) || ((BYTE)version >=0x04)) {
764 pImageBase = (BYTE *)modCode;
767 MessageBox(NULL, "Descent II cannot run under Windows 3.x", "Descent II", MB_OK);
775 IMAGE_OPTIONAL_HEADER *pHeader =
776 (IMAGE_OPTIONAL_HEADER *)(pImageBase + ((IMAGE_DOS_HEADER *)pImageBase)->e_lfanew +
777 sizeof(IMAGE_NT_SIGNATURE) + sizeof(IMAGE_FILE_HEADER));
779 //@@ if (!VirtualProtect(pImageBase+pHeader->BaseOfCode, pHeader->SizeOfCode,
780 //@@ PAGE_READWRITE, &oldRights)) {
784 if (!VirtualProtect(rls_stretch_scanline_asm, 4096*2, PAGE_READWRITE, &oldRights)) {
785 MessageBox(NULL, "Unable to gain write access to requested page.", "Descent II Error", MB_OK);
789 // wsprintf(buf, "Start:%x FN1:%x",(DWORD)pImageBase+pHeader->BaseOfCode, (DWORD)rls_stretch_scanline_asm);
790 // MessageBox(NULL, buf, "Info", MB_OK);
795 void ValidateSystem()
799 version = GetVersion();
801 if ((version < 0x80000000) || ((BYTE)version >=0x04)) {
802 if ((version < 0x80000000) && ((BYTE)version >= 0x04)) {
803 Platform_system = WINNT_PLATFORM;
806 else Platform_system = WIN95_PLATFORM;
809 MessageBox(NULL, "Descent II will not run under Windows 3.x", "DESCENT II", MB_OK);
813 // Do the named mutex thingy.
815 HANDLE hMutex, hMutex2;
817 hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "BigRedStinksMutex");
819 hMutex2 = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "BigRedSucksMutex");
821 CloseHandle(hMutex2);
822 exit(1); // Don't even tell user he's trying to run a third copy
825 hDescent2Mutex2 = CreateMutex(NULL, FALSE, "BigRedSucksMutex");
826 if (!hDescent2Mutex2) {
827 MessageBox(NULL, "Unable to create second mutex object.", "Descent II error", MB_OK);
830 MessageBox(NULL, "You may only run one instance of Descent II at a time.",
831 "Descent II error", MB_OK);
835 hDescent2Mutex = CreateMutex(NULL, FALSE, "BigRedStinksMutex");
836 if (!hDescent2Mutex) {
837 MessageBox(NULL, "Unable to create mutex object.", "Descent II error", MB_OK);
841 // Do the Version ID thing for Beta testers
842 #if defined(RELEASE) && defined(VERSION_NAME) && !defined(NDEBUG)
846 sprintf(buf, "Descent II %s v%d.%d\n%s\n%s %s", VERSION_TYPE, Version_major, Version_minor,
847 VERSION_NAME, __DATE__, __TIME__);
848 MessageBox(NULL, buf, "Descent II beta information", MB_OK);
852 // Super memory check
854 MEMORYSTATUS memstat;
857 memset(&memstat, 0, sizeof(memstat));
858 memstat.dwLength = sizeof(memstat);
859 GlobalMemoryStatus(&memstat);
861 logentry("Memory: \n");
862 logentry(" MemoryLoad = %10d\n",memstat.dwMemoryLoad);
863 logentry(" TotalPhys = %10d\n",memstat.dwTotalPhys);
864 logentry(" AvailPhys = %10d\n",memstat.dwAvailPhys);
865 logentry(" TotalPageFile = %10d\n",memstat.dwTotalPageFile);
866 logentry(" AvailPageFile = %10d\n",memstat.dwAvailPageFile);
867 logentry(" TotalVirtual = %10d\n",memstat.dwTotalVirtual);
868 logentry(" AvailVirtual = %10d\n",memstat.dwAvailVirtual);
870 mem_free = memstat.dwTotalPhys;
872 // logentry(" mem_free = %10d\n",mem_free);
874 if ( mem_free < MIN_PHYSICAL_MEM_FREE) {
875 logentry("Using low memory option.\n");
876 piggy_low_memory = 1;
879 if ( memstat.dwAvailPageFile < MIN_VIRTUAL_MEM_FREE) {
880 MessageBox(NULL, "Not enough virtual memory.\n You need at least 16MB of free drive space.\n",
881 "Descent II Error", MB_OK);
885 if ( ((mem_free > SOUND_22K_CUTOFF) || FindArg("-sound22k")) && !FindArg("-sound11k") && !FindArg("-lowmem") ) {
886 logentry("Using 22KHz sounds\n");
887 digi_sample_rate = SAMPLE_RATE_22K;
889 logentry("Using 11KHz sounds\n");
890 digi_sample_rate = SAMPLE_RATE_11K;
896 int DoMessageStuff(MSG *msg)
901 if (PeekMessage(msg, NULL, 0, 0, PM_REMOVE)) {
902 if (msg->message == WM_QUIT) {
907 TranslateMessage(msg);
908 DispatchMessage(msg);
910 else if (!_AppPaused && (_AppActive || !_DDFullScreen)) {
914 if ((Game_mode & GM_MULTI)) {
915 if (Control_center_destroyed) {
916 ShowWindow(_hAppWnd, SW_MAXIMIZE);
918 SetForegroundWindow(_hAppWnd);
920 _RedrawScreen = TRUE;
922 else if (multi_menu_poll() == -1) {
923 ShowWindow(_hAppWnd, SW_MAXIMIZE);
926 if (GetForegroundWindow() == _hAppWnd) {
927 if (_AppPaused || !_AppActive) {
928 mprintf((0, "Descent2 Daemon...Pause: %d, Active %d\n",_AppPaused, _AppActive));
929 SetActiveWindow(_hAppWnd);
930 _RedrawScreen = FALSE;
935 SetForegroundWindow(_hAppWnd);
937 _RedrawScreen = FALSE;
942 mprintf((0, "Waiting...Pause: %d, Active %d\n",_AppPaused, _AppActive));
957 mprintf((0, "Entering Idle message loop...\n"));
961 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
962 if (msg.message == WM_QUIT) {
967 mprintf((0, "Retreiving message(0x%x:0x%x,0x%x) in idle loop.\n",msg.message, msg.wParam, msg.lParam));
969 TranslateMessage(&msg);
970 DispatchMessage(&msg);
978 void WinDelay(int msecs)
984 timeout = timeGetTime() + msecs;
986 while (timeout > timeGetTime())
988 DoMessageStuff(&msg);
989 if (msg.message == WM_QUIT) exit(0);
994 void WErrorCatch(char *message)
996 mprintf((1, "Bye Bye: %s\n", message));
998 strcpy(WinErrorMessage, message);
1002 logentry("%s", WinErrorMessage);
1003 CloseWindow(_hAppWnd);
1007 //static BOOL CursorVisible = TRUE;
1008 static HANDLE CursorHandle = NULL;
1011 void LoadCursorWin(int cursor)
1015 case MOUSE_DEFAULT_CURSOR:
1016 CursorHandle = LoadCursor(NULL, IDC_ARROW);
1019 case MOUSE_WAIT_CURSOR:
1020 CursorHandle = LoadCursor(NULL, IDC_WAIT);
1024 CursorHandle = NULL;
1027 SetCursor(CursorHandle);
1033 while (ShowCursor(FALSE) >=0);
1039 if (DD_Emulation) return;
1041 if (CursorHandle == NULL)
1042 LoadCursorWin(MOUSE_DEFAULT_CURSOR);
1044 while (ShowCursor(TRUE) < 0);
1049 // Descent 2 Shutdown and Restore functions
1050 // ----------------------------------------------------------------------------
1052 void SaveVideoState();
1053 void RestoreVideoState();
1055 static int Saved_Game_window_w;
1056 static int Saved_Game_window_h;
1057 static int SavedScreenMode = 0;
1059 extern int Digi_initialized;
1060 extern int Current_display_mode;
1061 extern BOOL WMVEPlaying, RMVEPlaying;
1062 extern int current_song_level;
1065 void RestoreScreenContext()
1067 if ( _SCRContext.bkg_filename != NULL ) {
1068 mprintf((0, "Loading background file...\n"));
1069 nm_draw_background1( _SCRContext.bkg_filename );
1071 gr_palette_load(gr_palette);
1077 if (GameShutdown) return;
1081 if (!Joystick_calibrating) joy_stop_poll();
1089 if (CD_audio_desktop_dev != -1)
1090 auxSetVolume(CD_audio_desktop_dev, CD_audio_desktop_vol);
1092 if (Function_mode == FMODE_GAME && !(Game_mode &GM_MULTI)) {
1096 mprintf((0, "WMVE: %d, RMVE: %d\n", WMVEPlaying, RMVEPlaying));
1098 if (WMVEPlaying) MovieShutdown();
1099 if (RMVEPlaying) MVE_rmHoldMovie();
1101 if (!WMVEPlaying) digi_reset();
1103 mprintf((0, "Descent 2 is asleep...\n"));
1105 GameShutdown = TRUE;
1111 if (!GameShutdown) return;
1113 if (!WMVEPlaying) digi_reset();
1117 if (CD_audio_desktop_dev != -1)
1118 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
1122 else if (RMVEPlaying) {
1124 // if (_lpDD) RestoreVideoState();
1125 dd_gr_init_screen();
1126 W95DisplayMode = -1;
1128 if (SavedScreenMode != -1)
1129 set_screen_mode(SavedScreenMode);
1131 if (CD_audio_desktop_dev != -1)
1132 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
1134 _RedrawScreen = TRUE;
1139 if (_lpDD) RestoreVideoState();
1141 if (CD_audio_desktop_dev != -1)
1142 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
1144 if (Function_mode == FMODE_MENU) songs_play_song(SONG_TITLE, 1);
1145 if (Function_mode == FMODE_GAME) {
1146 songs_play_level_song(current_song_level);
1153 if (Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) start_time();
1154 else if (Function_mode == FMODE_MENU)
1155 keyd_time_when_last_pressed = timer_get_fixed_seconds();
1158 if (!Joystick_calibrating) joy_start_poll();
1159 set_redbook_volume(Config_redbook_volume);
1160 mprintf((0, "...Descent 2 is awake!\n"));
1162 GameShutdown = FALSE;
1166 void SaveVideoState()
1168 // If in game mode, then restore window size
1169 if (Screen_mode == SCREEN_GAME) {
1170 Saved_Game_window_w = Game_window_w;
1171 Saved_Game_window_h = Game_window_h;
1175 SavedScreenMode = Screen_mode;
1180 void RestoreVideoState()
1182 // Just reinitialize screen state.
1183 dd_gr_init_screen();
1184 W95DisplayMode = -1;
1187 // If in game mode, then restore window size
1188 if (SavedScreenMode != -1)
1189 set_screen_mode(SavedScreenMode);
1191 if (SavedScreenMode == SCREEN_GAME) {
1192 Game_window_w = Saved_Game_window_w;
1193 Game_window_h = Saved_Game_window_h;
1196 if (Function_mode == FMODE_GAME) {
1197 load_palette(Current_level_palette,1,1);
1200 _RedrawScreen = TRUE;
1201 RestoreScreenContext();