Win32GameEngine.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // When we are alt-tabbed out... the MilesAudioManager seems to go into a coma sometimes
  95. // and not regain focus properly when we come back. This seems to wake it up nicely.
  96. AudioAffect aa = (AudioAffect)0x10;
  97. TheAudio->setVolume(TheAudio->getVolume( aa ), aa );
  98. }
  99. // allow windows to perform regular windows maintenance stuff like msgs
  100. serviceWindowsOS();
  101. } // end update
  102. //-------------------------------------------------------------------------------------------------
  103. /** This function may be called from within this application to let
  104. * Microsoft Windows do its message processing and dispatching. Presumeably
  105. * we would call this at least once each time around the game loop to keep
  106. * Windows services from backing up */
  107. //-------------------------------------------------------------------------------------------------
  108. void Win32GameEngine::serviceWindowsOS( void )
  109. {
  110. MSG msg;
  111. Int returnValue;
  112. //
  113. // see if we have any messages to process, a NULL window handle tells the
  114. // OS to look at the main window associated with the calling thread, us!
  115. //
  116. while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
  117. {
  118. // get the message
  119. returnValue = GetMessage( &msg, NULL, 0, 0 );
  120. // this is one possible way to check for quitting conditions as a message
  121. // of WM_QUIT will cause GetMessage() to return 0
  122. /*
  123. if( returnValue == 0 )
  124. {
  125. setQuitting( true );
  126. break;
  127. }
  128. */
  129. TheMessageTime = msg.time;
  130. // translate and dispatch the message
  131. TranslateMessage( &msg );
  132. DispatchMessage( &msg );
  133. TheMessageTime = 0;
  134. } // end while
  135. } // end ServiceWindowsOS