Game Development Community

Frame-rate drop if the game is "inactive"

by Squall · in Torque 3D Beginner · 07/27/2010 (6:44 am) · 6 replies

Hi everyone,
Currently I have a problem with frame-rate drop if the game is "inactive", "inactive" means if I start the game in window mode, then I click outside that window so that it will become "inactive" and the frame-rate of the game will be capped at 5

i156.photobucket.com/albums/t1/nuivana/inactiveTorque.jpg


Since my project requires me to open multiple instances of the game at the same time, this problem is quite critical for me, so please share with me any possible solution to solve this. Thank you :)

#1
07/27/2010 (8:51 am)

In app/mainLoop.cpp, comment out tm->setBackground( !newFocus ). That should disable the switching to background mode which slows down the frequency of the time events.
#2
07/27/2010 (9:04 am)
Is the solution also valid for TGE?
#3
07/27/2010 (9:16 am)
Not 1:1 but it's there. The background state is determined by the platform backends. Look in the platform's TimeManager::process() implementation. On the Mac, there's a _MacCarbUpdateSleepTicks next to it where you can disable the background slow-down. On Windows, something similar should be there.
#4
07/27/2010 (9:52 am)
I found it. It was in Platform::process()
(winWindow.cc line 958)

Comment out this block of code:

HWND window = GetForegroundWindow();
   if (window && window != winState.appWindow && gWindowCreated)
   {
      // check to see if we are in the foreground or not
      // if not Sleep for a bit or until a Win32 message/input is recieved
      DWORD foregroundProcessId;
      GetWindowThreadProcessId(window, &foregroundProcessId);
      if (foregroundProcessId != winState.processId)
         MsgWaitForMultipleObjects(0, NULL, false, getBackgroundSleepTime(), QS_ALLINPUT);
   }
   // if there's no window, we sleep 1, otherwise we sleep 0
   else if(!Game->isJournalReading() && gWindowCreated )
      Sleep( 1 ); // give others some process time if necessary...
#5
07/27/2010 (9:55 am)
Or simply comment out this single line:

MsgWaitForMultipleObjects(0, NULL, false, getBackgroundSleepTime(), QS_ALLINPUT);
#6
07/28/2010 (5:25 am)
Wow Great !!! This really works !!!

Thanks you guys SO MUCH :)