Win32GameEngine.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: W3DGameEngine.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, April 2001
  25. // Description:
  26. // Implementation of the Win32 game engine, this is the highest level of
  27. // the game application, it creates all the devices we will use for the game
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////
  29. #include <windows.h>
  30. #include "Win32Device/Common/Win32GameEngine.h"
  31. #include "Common/PerfTimer.h"
  32. #include "GameNetwork/LANAPICallbacks.h"
  33. extern DWORD TheMessageTime;
  34. //-------------------------------------------------------------------------------------------------
  35. /** Constructor for Win32GameEngine */
  36. //-------------------------------------------------------------------------------------------------
  37. Win32GameEngine::Win32GameEngine()
  38. {
  39. // Stop blue screen
  40. m_previousErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
  41. }
  42. //-------------------------------------------------------------------------------------------------
  43. /** Destructor for Win32GameEngine */
  44. //-------------------------------------------------------------------------------------------------
  45. Win32GameEngine::~Win32GameEngine()
  46. {
  47. // restore it (this isn't really necessary, but feels good.)
  48. SetErrorMode( m_previousErrorMode );
  49. }
  50. //-------------------------------------------------------------------------------------------------
  51. /** Initialize the game engine */
  52. //-------------------------------------------------------------------------------------------------
  53. void Win32GameEngine::init( void )
  54. {
  55. // extending functionality
  56. GameEngine::init();
  57. } // end init
  58. //-------------------------------------------------------------------------------------------------
  59. /** Reset the system */
  60. //-------------------------------------------------------------------------------------------------
  61. void Win32GameEngine::reset( void )
  62. {
  63. // extending functionality
  64. GameEngine::reset();
  65. } // end reset
  66. //-------------------------------------------------------------------------------------------------
  67. /** Update the game engine by updating the GameClient and
  68. * GameLogic singletons. */
  69. //-------------------------------------------------------------------------------------------------
  70. void Win32GameEngine::update( void )
  71. {
  72. // call the engine normal update
  73. GameEngine::update();
  74. extern HWND ApplicationHWnd;
  75. if (ApplicationHWnd && ::IsIconic(ApplicationHWnd)) {
  76. while (ApplicationHWnd && ::IsIconic(ApplicationHWnd)) {
  77. // We are alt-tabbed out here. Sleep a bit, & process windows
  78. // so that we can become un-alt-tabbed out.
  79. Sleep(5);
  80. serviceWindowsOS();
  81. if (TheLAN != NULL) {
  82. // BGC - need to update TheLAN so we can process and respond to other
  83. // people's messages who may not be alt-tabbed out like we are.
  84. TheLAN->setIsActive(isActive());
  85. TheLAN->update();
  86. }
  87. // If we are running a multiplayer game, keep running the logic.
  88. // There is code in the client to skip client redraw if we are
  89. // iconic. jba.
  90. if (TheGameEngine->getQuitting() || TheGameLogic->isInInternetGame() || TheGameLogic->isInLanGame()) {
  91. break; // keep running.
  92. }
  93. }
  94. }
  95. // allow windows to perform regular windows maintenance stuff like msgs
  96. serviceWindowsOS();
  97. } // end update
  98. //-------------------------------------------------------------------------------------------------
  99. /** This function may be called from within this application to let
  100. * Microsoft Windows do its message processing and dispatching. Presumeably
  101. * we would call this at least once each time around the game loop to keep
  102. * Windows services from backing up */
  103. //-------------------------------------------------------------------------------------------------
  104. void Win32GameEngine::serviceWindowsOS( void )
  105. {
  106. MSG msg;
  107. Int returnValue;
  108. //
  109. // see if we have any messages to process, a NULL window handle tells the
  110. // OS to look at the main window associated with the calling thread, us!
  111. //
  112. while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
  113. {
  114. // get the message
  115. returnValue = GetMessage( &msg, NULL, 0, 0 );
  116. // this is one possible way to check for quitting conditions as a message
  117. // of WM_QUIT will cause GetMessage() to return 0
  118. /*
  119. if( returnValue == 0 )
  120. {
  121. setQuitting( true );
  122. break;
  123. }
  124. */
  125. TheMessageTime = msg.time;
  126. // translate and dispatch the message
  127. TranslateMessage( &msg );
  128. DispatchMessage( &msg );
  129. TheMessageTime = 0;
  130. } // end while
  131. } // end ServiceWindowsOS