⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i_pm.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 2 页
字号:
	 WinSendMsg( this->hwndFrame, WM_SetVideoMode,
		     (MPARAM)WS_FullScreenDive, 0 );
      CONS_Printf("Switching fullscreen mode...\n");
      break;
   case ID_MAXMODE:            // switch to max desktop size
      WinSendMsg( this->hwndFrame, WM_SetVideoMode, (MPARAM)WS_MaxDesktopDive, 0);
      CONS_Printf("Switching to max desktop size mode...\n");
      break;
   case ID_EXIT:
      /* Post to quit the dispatch message loop. */
      WinPostMsg( this->hwndFrame, WM_CLOSE, 0, 0 );
      break;

   case ID_NEWTEXT:
      WinSetWindowText( this->hwndFrame, this->title);
      break;

   case ID_PALINIT:
#ifdef USE_PALETTE_MGR
      CreatePalette(this);
#else
      RealizePalette(this);
#endif
      break;
   case ID_SWMOUSE:
      //SwitchMouseUse(this, (BOOL)mp2);
      break;
   default:
      bHandled = FALSE;
      break;
   }

   return bHandled;
} /* WindowCommands */


//
// handle main window events
//
MRESULT EXPENTRY DoomWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
   BOOL      bHandled = TRUE;
   PWINDATA  this;              /* Pointer to window data               */
   ULONG     rc;
   MCI_GENERIC_PARMS    GenericParms;
   event_t   ev;

   /* Get the pointer to window data
   */
   this = (PWINDATA)WinQueryWindowULong (hwnd, 0);
   if (this) {
      switch( msg) {

      case WM_ERASEBACKGROUND:
         return (MRESULT) 1;

      case WM_NotifyVideoModeChange:
         PrepareForModeChange(this, mp1, mp2);
         break;

      case MM_MCINOTIFY:
         printf( "DoomWindowProc: MM_MCINOTIFY\n");
         if (SHORT1FROMMP( mp1)==MCI_NOTIFY_SUCCESSFUL &&
             SHORT1FROMMP( mp2)==this->usMidiID &&
             SHORT2FROMMP( mp2)==MCI_PLAY &&
             this->looping) {
            printf( "WindowProc:MM_MCINOTIFY MCI_PLAY midi loop again\n");
            ShutdownMIDI( this);
            OpenMIDI( this);
            PlayMIDI( this, this->looping);      // play again
         }
         break;

      case MM_MCIPASSDEVICE:
            // Check if we are gaining or passing use of the amp-mixer device
         printf( "DoomWindowProc: MM_MCIPASSDEVICE\n");
         if (SHORT1FROMMP( mp2)==MCI_GAINING_USE)
            this->fPassedDevice = FALSE;
         else
            this->fPassedDevice = TRUE;
         break;

      case WM_ACTIVATE:
            // Check if this window is the active window and if we have passed
            // use of the Amp-Mixer device. If yes, then send MCI_ACQUIREDEVICE
            // message.
         if ((BOOL)mp1 && this->fPassedDevice && this->usDartID) {
            printf( "WindowProc: send MCI_ACQUIREDEVICE\n");
            GenericParms.hwndCallback = hwnd;
            rc = mciSendCommand( this->usDartID,
                                 MCI_ACQUIREDEVICE,
                                 MCI_NOTIFY | MCI_ACQUIRE_QUEUE,
                                 (PVOID) &GenericParms,
                                 0);
            if (rc)
               MciError( rc);
            rc = mciSendCommand( this->usMidiID,
                                 MCI_ACQUIREDEVICE,
                                 MCI_NOTIFY | MCI_ACQUIRE_QUEUE,
                                 (PVOID) &GenericParms,
                                 0);
            if (rc)
               MciError( rc);
         }

         // if losing focus, pause game
         if ((BOOL)mp1 == FALSE) {
            ev.data1 = KEY_PAUSE;
            ev.type = ev_keydown;
            D_PostEvent (&ev);
         }
         break;

      case WM_CHAR:
         if (PostCharEvent(this, CHARMSG(&msg)))
            return TRUE;
         break;

      case WM_COMMAND:
         bHandled = WindowCommands(this, msg, mp1, mp2);
         break;

      case WM_VRNDISABLED:
         WindowSetBlit(this, 0);
         break;

      case WM_VRNENABLED:
         WindowSetBlit(this, 1);
         break;

      case WM_REALIZEPALETTE:
            /* This tells DIVE that the physical palette may have changed.
            */
         if (this->ulColorBits==8)
            DiveSetDestinationPalette( this->hDive, 0, this->ulNumColors, 0);
         break;

      case WM_CLOSE:
            /* Post to quit the dispatch message loop.
            */
#ifdef DEBUG
         printf( "DoomWindowProc: WM_CLOSE\n");
#endif
         WindowSetBlit( this, 0);
         WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
         ev.data1 = KEY_ESCAPE;      //to exit network synchronization
         ev.type = ev_keydown;
         D_PostEvent (&ev);
         break;

      default:
         bHandled = FALSE;
         break;
      }
   } else {
      bHandled = FALSE;
      printf( "DoomWindowProc: this is NULL (msg#%x)\n", msg);
   }


   if (!bHandled)       // Let PM handle this message.
      return WinDefWindowProc ( hwnd, msg, mp1, mp2 );

   return ( FALSE );
}

void     DoomThread( void*arg)
{
   HAB    hab = WinInitialize ( 0 );
   HMQ    hmq = WinCreateMsgQueue( hab, 0 );

   // currently starts DirectInput 
   CONS_Printf ("I_StartupSystem() ...\n");
   I_StartupSystem();

   // startup Doom Legacy
   CONS_Printf ("D_DoomMain() ...\n");
   D_DoomMain (); 
   CONS_Printf ("Entering main app loop...\n");

   // never return
   D_DoomLoop ();
}

//
// init PM window
//
void     InitPMSession( void* arg)
{
   QMSG      qmsg;
   ULONG     flCreate;
   PSZ       pszMyWindow = "DoomLegacy2";
   PSZ       pszTitleText = "Doom LEGACY";

   /* Initialize the presentation manager, and create a message queue.
   */
   pmData->hab = WinInitialize ( 0 );
   pmData->hmq = WinCreateMsgQueue( pmData->hab, 0 );
   pmData->ulToEnd = 0;

      // Register a window class, and create a standard window.
   WinRegisterClass( pmData->hab, pszMyWindow, DoomWindowProc, 0, sizeof(ULONG) );
   flCreate = FCF_TASKLIST | FCF_TITLEBAR | FCF_ICON | FCF_DLGBORDER |
              FCF_MINMAX | FCF_SHELLPOSITION;

   pmData->hwndFrame = WinCreateStdWindow ( HWND_DESKTOP,
                                              0, &flCreate,
                                              pszMyWindow,
                                              pszTitleText,
                                              WS_SYNCPAINT,
                                              0, ID_MAINWND,
                                              &(pmData->hwndClient));

   WinSetWindowULong( pmData->hwndClient, 0, (ULONG)pmData);

#if 0
      // start Doom/2 thread
   pmData->tidDoomThread = _beginthread( DoomThread, 0L, 64*1024L, (void*) NULL);
   DosSetPriority( PRTYS_THREAD, PRTYC_IDLETIME,  1, pmData->tidDoomThread);
      // start blit thread
   if (M_CheckParm( "-blitthread")) {
      pmData->tidBlitThread = _beginthread( BlitThread, 0L, 64*1024L, (void*)pmData);
      DosSetPriority( PRTYS_THREAD, PRTYC_IDLETIME, 1, pmData->tidBlitThread);
      //DosSetPriority( PRTYS_THREAD, PRTYC_TIMECRITICAL,  -1, pmData->tidBlitThread);
      //DosSetPriority( PRTYS_THREAD, PRTYC_REGULAR,  1, pmData->tidBlitThread);
   }
#endif

      // set window default size
   pmData->ulWidth  = 320;
   pmData->ulHeight = 200;
   SnapWindow( pmData, pmData->ulWidth, pmData->ulHeight);

      // Turn on visible region notification.
   WinSetVisibleRegionNotify ( pmData->hwndClient, TRUE );

      // set the flag for the first time simulation of palette of bitmap data
   pmData->fChgSrcPalette = FALSE;
   pmData->fDataInProcess = TRUE;

      // show main window
   WinShowWindow( pmData->hwndFrame, TRUE);

#if 0
      // While there are still messages, dispatch them.
   while ( WinGetMsg ( pmData->hab, &qmsg, 0, 0, 0 ) )
      WinDispatchMsg ( pmData->hab, &qmsg );

      // notify exit to other threads
   pmData->ulToEnd = 1;
#endif
}


void     ShutdownPMSession( void)
{
#if 0
      // wait end of threads
   if (pmData->tidDoomThread)
      DosWaitThread( &(pmData->tidDoomThread), DCWW_WAIT);
   if (pmData->tidBlitThread)
      DosWaitThread( &(pmData->tidBlitThread), DCWW_WAIT);
#endif

      // Turn off visible region notificationm tidy up, and terminate.
   WinSetVisibleRegionNotify ( pmData->hwndClient, FALSE );

      // Process for termination
   WinDestroyWindow( pmData->hwndFrame );
   WinDestroyMsgQueue( pmData->hmq);
   WinTerminate( pmData->hab);

#ifdef DEBUG
   printf( "ShutdownPMSession: DONE\n");
#endif
}

void     I_StartupPMSession( void)
{
   APIRET rc;

      // Allocate a buffer for the window data
   pmData = (PWINDATA) malloc (sizeof(WINDATA));
   memset( pmData, 0, sizeof(WINDATA));

      // create owned event mutex
   rc = DosCreateMutexSem( SEM32_EVENTMUTEX, &pmData->hmtxEventSem, 0, 0);
   if (rc) {
      printf( "main: can't create mutex rc=%x\n", (unsigned int) rc);
   }

      // verify test fps flag
   if (M_CheckParm( "-testfps"))
      pmData->fCheckFps = TRUE;

      // init PM
   InitPMSession( NULL);
   I_AddExitFunc(ShutdownPMSession);
/*
      // shutdown PM
   ShutdownPMSession();
*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -