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.
46 #define MIN_VIRTUAL_MEM_FREE (16 * (1024*1024))
47 #define MIN_PHYSICAL_MEM_FREE (16 * (1024*1024))
48 #define SOUND_22K_CUTOFF (16 *1024*1024) // 8.0 MB
51 // Globals --------------------------------------------------------------------
53 HWND _hAppWnd; // Descent Window
54 HINSTANCE _hAppInstance;
55 int _DDraw = 0; // No DirectX
56 char *_OffscreenCanvasBits; // Pointer to Offscreen Canvas Bits.
57 BOOL _AppActive = FALSE; // Is application active?
58 BOOL _AppPaused = FALSE; // Shall we run game?
59 BOOL _AppInit = FALSE; // Is application initialized?
60 BOOL _RedrawScreen=FALSE; // Shall we force a redraw of the screen?
61 SCREEN_CONTEXT _SCRContext;
63 HANDLE hDescent2Mutex = NULL; // handle to determine whether D2 is already running
64 HANDLE hDescent2Mutex2 = NULL;
66 BOOL AllowActivates = FALSE;
68 // HACK, to keep original CD audio vol.
69 DWORD CD_audio_desktop_vol = 0;
70 int CD_audio_desktop_dev = -1;
74 int Platform_system=0;
77 extern int Mono_initialized;
78 extern int WinEnableInt3;
79 extern int DD_Emulation;
80 extern int Skip_briefing_screens; // So we can skip the briefing
81 extern int digi_system_initialized;
82 extern int framerate_on;
83 extern ubyte gr_palette_faded_out;
84 extern int piggy_low_memory; // FROM PIGGY.C!
85 extern RECT ViewportRect;
86 extern int Joystick_calibrating;
88 // Game State and other Variables ---------------------------------------------
90 static char WinErrorMessage[512];
91 static BOOL WinErrorTrap = FALSE;
92 static BOOL GameShutdown = FALSE;
93 //static BOOL GameInitialized = FALSE;
94 static BOOL WinEnableMovies = TRUE;
97 // External Functions ---------------------------------------------------------
99 extern void grwin_gdi_realizepal(HDC hdc);
100 extern void grwin_cleanup_palette();
102 extern void GameLoop(int, int);
103 extern void game_setup(void);
104 extern void check_joystick_calibration();
105 extern void DDResizeViewport(void);
106 extern void SetWinMonoInfo(HWND hWnd, HINSTANCE hInstance);
108 extern void InitCD(char *arg);
109 extern void InitVideo(void);
110 extern void InitIO(void);
111 extern void InitData(void);
112 extern void InitSound(void);
113 extern void InitNetwork(void);
114 extern void InitDescent(void);
115 extern void InitPilot(void);
118 // Function Prototypes --------------------------------------------------------
120 int RunGame(int argc, char *argv[]);
121 int RestoreGameSurfaces(void);
122 void ValidateSystem(void);
123 void MakeCodeWritable(void);
124 int ParseArgs(char *argv[], LPSTR lpCmdLine);
125 void WErrorCatch(char *message);
127 void DoRegisterCheck(void);
130 void AppPaint(HWND hWnd, HDC hdc);
131 void AppSize(HWND hWnd);
132 void AppActivate(HWND hWnd, UINT wParam);
133 void AppQueryPalette(HWND hWnd);
134 void AppPaletteChange(HWND hWnd, UINT wParam);
135 void AppDisplayChange(HWND hWnd, int w, int h, int bpp);
136 BOOL AppHandleSystemKeys(UINT msg, UINT wParam, UINT lParam);
138 BOOL GameCheckMultiReactor();
140 LRESULT WINAPI _export DescentWndProc(HWND hWnd,UINT msg,UINT wParam,
145 // Initialization and Destruction
146 // ----------------------------------------------------------------------------
148 BOOL AppInit(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
150 // Create Application Window and Initialize WinG stuff.
160 if (FindArg("-logfile")) loginit("descentw.log");
166 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
167 wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(D2_ICON));
168 wc.lpszMenuName = NULL;
169 wc.lpszClassName = "DescentWndClass";
170 wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
171 wc.hInstance = hInst;
172 wc.style = CS_DBLCLKS;
173 wc.lpfnWndProc = (WNDPROC)DescentWndProc;
177 if (!RegisterClass(&wc)) return FALSE;
180 // Arrgh, make entire code segment writable for now.
181 // -codereadonly forces read only code (debug purposes)
183 if (!FindArg("-codereadonly"))
192 _hAppInstance = hInst;
193 _hAppWnd = CreateWindowEx(WS_EX_APPWINDOW,
196 WS_POPUP | WS_SYSMENU | WS_BORDER,
198 GetSystemMetrics(SM_CXSCREEN),
199 GetSystemMetrics(SM_CYSCREEN),
205 Assert(_hAppWnd != 0);
207 ShowWindow(_hAppWnd, SW_SHOWNORMAL);
208 UpdateWindow(_hAppWnd);
210 // Tell Descent Libraries about Windows
212 // LoadCursorWin(MOUSE_WAIT_CURSOR);
217 if (FindArg("-monodebug")) Mono_initialized = 1;
218 else // link to below line!
220 Mono_initialized = 0;
222 Mono_initialized = 1;
227 SetLibraryWinInfo(_hAppWnd, _hAppInstance);
230 mopen( 0, 9, 1, 78, 15, "Debug Spew");
231 mopen( 1, 2, 1, 78, 5, "Errors & Serious Warnings");
240 // HACK do this when the application is closing! restore the CD audio volume.
241 if (CD_audio_desktop_dev != -1)
242 auxSetVolume(CD_audio_desktop_dev, CD_audio_desktop_vol);
244 grwin_cleanup_palette();
246 LoadCursorWin(MOUSE_DEFAULT_CURSOR);
251 cprintf("\n\n%s", WinErrorMessage);
255 CloseWindow(_hAppWnd);
256 cprintf("\n\nDescent II for Win95 done...\n");
262 MessageBox(NULL, WinErrorMessage, "Descent II error", MB_OK);
270 CloseHandle(hDescent2Mutex2);
273 CloseHandle(hDescent2Mutex); // Destroy Mutex Object!
276 extern char CDROM_dir[30];
278 void DoRegisterCheck()
281 PROCESS_INFORMATION pi;
285 strcpy(filename, CDROM_dir);
286 strcat(filename, "regcard.exe");
288 memset(&si, 0, sizeof(si));
290 si.dwFlags = STARTF_USESHOWWINDOW;
291 si.wShowWindow = SW_SHOW;
293 flag = CreateProcess(
295 filename, NULL, NULL,
296 FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL,
300 dwval = WaitForInputIdle(pi.hProcess, INFINITE);
302 while (WaitForSingleObject(pi.hProcess, 0) != WAIT_OBJECT_0)
306 mprintf((1, "JOY.CPL process finished?\n"));
307 ShowWindow(_hAppWnd, SW_MAXIMIZE);
308 SetForegroundWindow(_hAppWnd);
313 // Game -----------------------------------------------------------------------
315 char commandline_help[] =
316 "Command-line options (case is not significant):\n"
318 " General Options:\n"
320 " -LowMem Lower animation detail for better performance with low memory\n"
321 " -NoLowMem Force high animation detail even when low memory\n"
322 " -Subtitles Turn on movie subtitles (English-only)\n"
324 " Input devices: -SpecialDevice\n"
326 " -IForce <n> Use Immersion tactile feedback joystick on port <n>\n"
330 " -NoSound Turns off sound & music\n"
331 " -NoMusic Disables music; sound effects remain enabled\n"
332 " -Sound22K Use 22KHz sounds, even if machine has less than 16 MB\n"
333 " -Sound11K Use 11KHz sounds, even if machine has more than 16 MB\n"
335 " Network & Modem:\n"
337 " -CtsRts Enables CTS/RTS handshaking during null-modem games\n"
338 " -NoNetwork Disables network drivers\n"
339 " -NoSerial Disables serial drivers\n"
340 " -Packets # Specifies the packets per second where # is the number of packets\n"
341 " -Shortpackets Turn on short packets\n"
342 " -Norankings Disable multiplayer ranking system\n"
343 " -Noredunancy suppresses duplicate messages such as \"You already have ....\"\n"
346 " -emul Certain video cards need this option in order to run game.\n"
347 " -ddemul If -emul doesn't work, use this option.\n";
349 print_commandline_help()
352 MessageBox(NULL, commandline_help, "Descent II Command-line Options", MB_OK);
355 int RunGame(int argc, char *argv[])
360 setbuf(stdout, NULL);
361 error_init(WErrorCatch, NULL);
364 if (FindArg("-stopwatch"))
372 // InitArgs(argc, argv);
385 if (!FindArg("-nonetwork"))
388 if (!FindArg("-noserial"))
391 AllowActivates = TRUE;
398 newdemo_start_playback("DESCENT.DEM");
399 if (Newdemo_state == ND_STATE_PLAYBACK )
400 Function_mode = FMODE_GAME;
403 // do this here because the demo code can do a longjmp when trying to
404 // autostart a demo from the main menu, never having gone into the game
407 while (Function_mode != FMODE_EXIT)
409 val = DoMessageStuff(&msg);
413 switch (Function_mode)
417 set_screen_mode(SCREEN_MENU);
420 newdemo_start_playback(NULL);
421 if (Newdemo_state != ND_STATE_PLAYBACK)
422 Error("No demo files were found for autodemo mode!");
425 DEFINE_SCREEN(Menu_pcx_name);
426 mprintf((1, "%s\n", Menu_pcx_name));
439 if ( Function_mode == FMODE_MENU )
440 songs_play_song( SONG_TITLE, 1 );
441 mprintf((0, "Function mode = %d\n", Function_mode));
447 dd_gr_set_current_canvas(NULL);
448 dd_gr_clear_canvas(BM_XRGB(0,0,0));
456 // Window Message Functions
457 // ----------------------------------------------------------------------------
459 void AppPaint(HWND hWnd, HDC hdc)
461 // grwin_gdi_realizepal(hdc);
465 void AppSize(HWND hWnd)
467 if (IsIconic(hWnd)) {
469 InvalidateRect(hWnd, NULL, TRUE);
471 else if (GetForegroundWindow() == hWnd) {
476 mprintf((0, "Resized window (%d,%d,%d,%d).\n", ViewportRect.left, ViewportRect.top, ViewportRect.right, ViewportRect.bottom));
480 void AppActivate(HWND hWnd, UINT wParam)
482 _AppActive = (BOOL)(wParam) && GetForegroundWindow()==hWnd && !IsIconic(hWnd);
485 mprintf((0, "Descent II is gaining Window focus.\n"));
486 cprintf("Descent II is gaining Window focus.\n");
489 mprintf((0, "Descent II is losing Window focus.\n"));
490 cprintf("Descent II is losing Window focus.\n");
493 // Must now unpause if paused and app is active now.
494 mprintf((0, "AppActivate: Active: %d, Paused: %d\n", _AppActive, _AppPaused));
496 if (_AppActive && AllowActivates && !_AppPaused)
500 else if (AllowActivates) {
507 void AppQueryPalette(HWND hWnd)
509 // if (!_DDFullScreen && _lpDDPalette && _lpDDSPrimary) {
510 // gr_palette_load(gr_palette);
512 mprintf((0, "QUERY PALETTE!\n"));
516 void AppCreate(HWND hWnd)
520 // Remove system menu components not good
521 hMenu = GetSystemMenu(hWnd, FALSE);
523 RemoveMenu(hMenu, SC_SIZE, MF_BYCOMMAND);
524 RemoveMenu(hMenu, SC_MOVE, MF_BYCOMMAND);
528 void AppPaletteChange(HWND hWnd, UINT wParam)
530 if ((HWND)wParam != hWnd) {
531 if (!_DDFullScreen) {
532 mprintf((0, "Palette changed!\n"));
534 mprintf((0, "Descent 2 is paused.\n"));
539 //static LPDIRECTDRAWSURFACE Page0Buffer = 0;
541 void AppDisplayChange(HWND hWnd, int w, int h, int bpp)
543 // mprintf((0, "Windows feels a display change coming...\n"));
547 BOOL AppHandleSystemKeys(UINT msg, UINT wParam, UINT lParam)
549 // Intercept ALT keystrokes
551 if (msg == WM_SYSKEYUP) {
552 mprintf((0,"ALT key down!"));
555 send_key_msg(msg, wParam, lParam);
557 if (wParam == VK_TAB || wParam == VK_ESCAPE) return FALSE;
563 int RestoreGameSurfaces()
565 if (dd_VR_offscreen_buffer) {
566 if (!dd_VR_offscreen_buffer->lpdds) return 1;
567 if (IDirectDrawSurface_Restore(dd_VR_offscreen_buffer->lpdds) != DD_OK) {
568 mprintf((1, "Warning: Unable to restore dd_VR_offscreen_buffer!\n"));
571 mprintf((0, "Restored dd_VR_offscreen_buffer\n"));
578 LRESULT WINAPI _export DescentWndProc(HWND hWnd,
584 //static int nTimer = 0;
593 if((wParam&0xFFF0)==SC_SCREENSAVE || (wParam&0xFFF0)==SC_MONITORPOWER)
596 if ((wParam&0xfff0)== SC_KEYMENU && _AppActive) {
597 mprintf((0, "W32: Bypassing system menu.\n"));
607 case WM_ACTIVATEAPP: // Application is losing focus.
608 AppActivate(hWnd, wParam);
611 case WM_QUERYNEWPALETTE:
612 AppQueryPalette(hWnd);
615 case WM_PALETTECHANGED:
616 AppPaletteChange(hWnd, wParam);
619 case WM_DISPLAYCHANGE: // Screen Mode is changing.
620 AppDisplayChange(hWnd, LOWORD(lParam), HIWORD(lParam), wParam);
625 if (AppHandleSystemKeys(msg, wParam,lParam))
631 if (wParam == VK_SNAPSHOT) {
632 mprintf((0, "Capture screen begins...\n"));
634 if (!clipboard_screenshot())
635 mprintf((1, "Failed to create clipboard screenshot!\n"));
638 // if (msg == WM_KEYDOWN && wParam == 0x49) ipx_debug_hold_packets = 1;
639 // if (msg == WM_KEYUP && wParam == 0x49) ipx_debug_hold_packets = 0;
641 send_key_msg(msg, wParam, lParam);
645 // hdc = BeginPaint(hWnd, &ps);
646 // AppPaint(hWnd, hdc);
647 // EndPaint(hWnd, &ps);
652 case MM_JOY1BUTTONDOWN:
653 case MM_JOY1BUTTONUP:
654 if (!_AppPaused && (_AppActive || !_DDFullScreen)) {
655 joy_handler_win(hWnd, msg, wParam, lParam);
660 mprintf((0, "Killing main window...\n"));
665 // digi_midi_debug();
666 mouse_win_callback(msg, wParam, lParam);
668 return DefWindowProc(hWnd, msg, wParam, lParam);
672 static char *WinArgs[64];
675 // ----------------------------------------------------------------------------
677 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine,
684 argc = ParseArgs(WinArgs, szCmdLine);
685 InitArgs(argc, WinArgs);
687 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) ) {
688 print_commandline_help();
689 set_exit_message("");
693 if (AppInit(hInst, hPrev, szCmdLine, nCmdShow)) {
694 retval = RunGame(argc, WinArgs);
702 // Low Level Routines
703 // ----------------------------------------------------------------------------
705 static char *NoMovieArg = "-nomovies";
706 static char *PathArg = "descentw.exe";
708 int ParseArgs(char *argv[], LPSTR lpCmdLine)
716 argv[argc++] = PathArg;
718 // while (lpCmdLine[i] == '-' || lpCmdLine[i] == '/' )
722 if (lpCmdLine[i] == ' ') i++;
724 argv[argc++] = &lpCmdLine[i];
726 while (lpCmdLine[i]!=' ' && lpCmdLine[i]!= 0) {
727 //mprintf((0, "%c", lpCmdLine[i]));
731 // mprintf((0, "Argument %s.\n", argv[argc-1]));
735 if (!WinEnableMovies)
736 argv[argc++] = NoMovieArg;
742 extern void rls_stretch_scanline_asm();
745 void MakeCodeWritable(void)
747 typedef DWORD __stdcall translator(DWORD);
750 BYTE *pImageBase = 0;
753 modCode = GetModuleHandle(0);
754 version = GetVersion();
756 // For Win32s we have to use undocumented features
757 if ((version < 0x80000000) || ((BYTE)version >=0x04)) {
759 pImageBase = (BYTE *)modCode;
762 MessageBox(NULL, "Descent II cannot run under Windows 3.x", "Descent II", MB_OK);
770 IMAGE_OPTIONAL_HEADER *pHeader =
771 (IMAGE_OPTIONAL_HEADER *)(pImageBase + ((IMAGE_DOS_HEADER *)pImageBase)->e_lfanew +
772 sizeof(IMAGE_NT_SIGNATURE) + sizeof(IMAGE_FILE_HEADER));
774 //@@ if (!VirtualProtect(pImageBase+pHeader->BaseOfCode, pHeader->SizeOfCode,
775 //@@ PAGE_READWRITE, &oldRights)) {
779 if (!VirtualProtect(rls_stretch_scanline_asm, 4096*2, PAGE_READWRITE, &oldRights)) {
780 MessageBox(NULL, "Unable to gain write access to requested page.", "Descent II Error", MB_OK);
784 // wsprintf(buf, "Start:%x FN1:%x",(DWORD)pImageBase+pHeader->BaseOfCode, (DWORD)rls_stretch_scanline_asm);
785 // MessageBox(NULL, buf, "Info", MB_OK);
790 void ValidateSystem()
794 version = GetVersion();
796 if ((version < 0x80000000) || ((BYTE)version >=0x04)) {
797 if ((version < 0x80000000) && ((BYTE)version >= 0x04)) {
798 Platform_system = WINNT_PLATFORM;
801 else Platform_system = WIN95_PLATFORM;
804 MessageBox(NULL, "Descent II will not run under Windows 3.x", "DESCENT II", MB_OK);
808 // Do the named mutex thingy.
810 HANDLE hMutex, hMutex2;
812 hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "BigRedStinksMutex");
814 hMutex2 = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "BigRedSucksMutex");
816 CloseHandle(hMutex2);
817 exit(1); // Don't even tell user he's trying to run a third copy
820 hDescent2Mutex2 = CreateMutex(NULL, FALSE, "BigRedSucksMutex");
821 if (!hDescent2Mutex2) {
822 MessageBox(NULL, "Unable to create second mutex object.", "Descent II error", MB_OK);
825 MessageBox(NULL, "You may only run one instance of Descent II at a time.",
826 "Descent II error", MB_OK);
830 hDescent2Mutex = CreateMutex(NULL, FALSE, "BigRedStinksMutex");
831 if (!hDescent2Mutex) {
832 MessageBox(NULL, "Unable to create mutex object.", "Descent II error", MB_OK);
836 // Do the Version ID thing for Beta testers
837 #if defined(RELEASE) && defined(VERSION_NAME) && !defined(NDEBUG)
841 sprintf(buf, "Descent II %s v%d.%d\n%s\n%s %s", VERSION_TYPE, Version_major, Version_minor,
842 VERSION_NAME, __DATE__, __TIME__);
843 MessageBox(NULL, buf, "Descent II beta information", MB_OK);
847 // Super memory check
849 MEMORYSTATUS memstat;
852 memset(&memstat, 0, sizeof(memstat));
853 memstat.dwLength = sizeof(memstat);
854 GlobalMemoryStatus(&memstat);
856 logentry("Memory: \n");
857 logentry(" MemoryLoad = %10d\n",memstat.dwMemoryLoad);
858 logentry(" TotalPhys = %10d\n",memstat.dwTotalPhys);
859 logentry(" AvailPhys = %10d\n",memstat.dwAvailPhys);
860 logentry(" TotalPageFile = %10d\n",memstat.dwTotalPageFile);
861 logentry(" AvailPageFile = %10d\n",memstat.dwAvailPageFile);
862 logentry(" TotalVirtual = %10d\n",memstat.dwTotalVirtual);
863 logentry(" AvailVirtual = %10d\n",memstat.dwAvailVirtual);
865 mem_free = memstat.dwTotalPhys;
867 // logentry(" mem_free = %10d\n",mem_free);
869 if ( mem_free < MIN_PHYSICAL_MEM_FREE) {
870 logentry("Using low memory option.\n");
871 piggy_low_memory = 1;
874 if ( memstat.dwAvailPageFile < MIN_VIRTUAL_MEM_FREE) {
875 MessageBox(NULL, "Not enough virtual memory.\n You need at least 16MB of free drive space.\n",
876 "Descent II Error", MB_OK);
880 if ( ((mem_free > SOUND_22K_CUTOFF) || FindArg("-sound22k")) && !FindArg("-sound11k") && !FindArg("-lowmem") ) {
881 logentry("Using 22KHz sounds\n");
882 digi_sample_rate = SAMPLE_RATE_22K;
884 logentry("Using 11KHz sounds\n");
885 digi_sample_rate = SAMPLE_RATE_11K;
891 int DoMessageStuff(MSG *msg)
896 if (PeekMessage(msg, NULL, 0, 0, PM_REMOVE)) {
897 if (msg->message == WM_QUIT) {
902 TranslateMessage(msg);
903 DispatchMessage(msg);
905 else if (!_AppPaused && (_AppActive || !_DDFullScreen)) {
909 if ((Game_mode & GM_MULTI)) {
910 if (Control_center_destroyed) {
911 ShowWindow(_hAppWnd, SW_MAXIMIZE);
913 SetForegroundWindow(_hAppWnd);
915 _RedrawScreen = TRUE;
917 else if (multi_menu_poll() == -1) {
918 ShowWindow(_hAppWnd, SW_MAXIMIZE);
921 if (GetForegroundWindow() == _hAppWnd) {
922 if (_AppPaused || !_AppActive) {
923 mprintf((0, "Descent2 Daemon...Pause: %d, Active %d\n",_AppPaused, _AppActive));
924 SetActiveWindow(_hAppWnd);
925 _RedrawScreen = FALSE;
930 SetForegroundWindow(_hAppWnd);
932 _RedrawScreen = FALSE;
937 mprintf((0, "Waiting...Pause: %d, Active %d\n",_AppPaused, _AppActive));
952 mprintf((0, "Entering Idle message loop...\n"));
956 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
957 if (msg.message == WM_QUIT) {
962 mprintf((0, "Retreiving message(0x%x:0x%x,0x%x) in idle loop.\n",msg.message, msg.wParam, msg.lParam));
964 TranslateMessage(&msg);
965 DispatchMessage(&msg);
973 void WinDelay(int msecs)
979 timeout = timeGetTime() + msecs;
981 while (timeout > timeGetTime())
983 DoMessageStuff(&msg);
984 if (msg.message == WM_QUIT) exit(0);
989 void WErrorCatch(char *message)
991 mprintf((1, "Bye Bye: %s\n", message));
993 strcpy(WinErrorMessage, message);
997 logentry("%s", WinErrorMessage);
998 CloseWindow(_hAppWnd);
1002 //static BOOL CursorVisible = TRUE;
1003 static HANDLE CursorHandle = NULL;
1006 void LoadCursorWin(int cursor)
1010 case MOUSE_DEFAULT_CURSOR:
1011 CursorHandle = LoadCursor(NULL, IDC_ARROW);
1014 case MOUSE_WAIT_CURSOR:
1015 CursorHandle = LoadCursor(NULL, IDC_WAIT);
1019 CursorHandle = NULL;
1022 SetCursor(CursorHandle);
1028 while (ShowCursor(FALSE) >=0);
1034 if (DD_Emulation) return;
1036 if (CursorHandle == NULL)
1037 LoadCursorWin(MOUSE_DEFAULT_CURSOR);
1039 while (ShowCursor(TRUE) < 0);
1044 // Descent 2 Shutdown and Restore functions
1045 // ----------------------------------------------------------------------------
1047 void SaveVideoState();
1048 void RestoreVideoState();
1050 static int Saved_Game_window_w;
1051 static int Saved_Game_window_h;
1052 static int SavedScreenMode = 0;
1054 extern int Digi_initialized;
1055 extern BOOL WMVEPlaying, RMVEPlaying;
1056 extern int current_song_level;
1059 void RestoreScreenContext()
1061 if ( _SCRContext.bkg_filename != NULL ) {
1062 mprintf((0, "Loading background file...\n"));
1063 nm_draw_background1( _SCRContext.bkg_filename );
1065 gr_palette_load(gr_palette);
1071 if (GameShutdown) return;
1075 if (!Joystick_calibrating) joy_stop_poll();
1083 if (CD_audio_desktop_dev != -1)
1084 auxSetVolume(CD_audio_desktop_dev, CD_audio_desktop_vol);
1086 if (Function_mode == FMODE_GAME && !(Game_mode &GM_MULTI)) {
1090 mprintf((0, "WMVE: %d, RMVE: %d\n", WMVEPlaying, RMVEPlaying));
1092 if (WMVEPlaying) MovieShutdown();
1093 if (RMVEPlaying) MVE_rmHoldMovie();
1095 if (!WMVEPlaying) digi_reset();
1097 mprintf((0, "Descent 2 is asleep...\n"));
1099 GameShutdown = TRUE;
1105 if (!GameShutdown) return;
1107 if (!WMVEPlaying) digi_reset();
1111 if (CD_audio_desktop_dev != -1)
1112 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
1116 else if (RMVEPlaying) {
1118 // if (_lpDD) RestoreVideoState();
1119 dd_gr_init_screen();
1120 W95DisplayMode = -1;
1122 if (SavedScreenMode != -1)
1123 set_screen_mode(SavedScreenMode);
1125 if (CD_audio_desktop_dev != -1)
1126 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
1128 _RedrawScreen = TRUE;
1133 if (_lpDD) RestoreVideoState();
1135 if (CD_audio_desktop_dev != -1)
1136 auxGetVolume(CD_audio_desktop_dev, &CD_audio_desktop_vol);
1138 if (Function_mode == FMODE_MENU) songs_play_song(SONG_TITLE, 1);
1139 if (Function_mode == FMODE_GAME) {
1140 songs_play_level_song(current_song_level);
1147 if (Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) start_time();
1148 else if (Function_mode == FMODE_MENU)
1149 keyd_time_when_last_pressed = timer_get_fixed_seconds();
1152 if (!Joystick_calibrating) joy_start_poll();
1153 set_redbook_volume(Config_redbook_volume.intval);
1154 mprintf((0, "...Descent 2 is awake!\n"));
1156 GameShutdown = FALSE;
1160 void SaveVideoState()
1162 // If in game mode, then restore window size
1163 if (Screen_mode == SCREEN_GAME) {
1164 Saved_Game_window_w = Game_window_w;
1165 Saved_Game_window_h = Game_window_h;
1169 SavedScreenMode = Screen_mode;
1174 void RestoreVideoState()
1176 // Just reinitialize screen state.
1177 dd_gr_init_screen();
1178 W95DisplayMode = -1;
1181 // If in game mode, then restore window size
1182 if (SavedScreenMode != -1)
1183 set_screen_mode(SavedScreenMode);
1185 if (SavedScreenMode == SCREEN_GAME) {
1186 Game_window_w = Saved_Game_window_w;
1187 Game_window_h = Saved_Game_window_h;
1190 if (Function_mode == FMODE_GAME) {
1191 load_palette(Current_level_palette,1,1);
1194 _RedrawScreen = TRUE;
1195 RestoreScreenContext();