Minimizing....
by George Ison · in Torque Game Builder · 12/20/2012 (9:28 am) · 8 replies
Hello all,
Quick question, what methods/callbacks/properties are available to deal with minimization of your game? Some of our publisher requirements require the game to pause and free up resources on minimize. The pause and memory management portion isn't an issue, but I'm not sure what events T2D has to allow me to know when the system has been minimized or is not in focus?
Any help would be greatly appreciated.
Thanks!
Quick question, what methods/callbacks/properties are available to deal with minimization of your game? Some of our publisher requirements require the game to pause and free up resources on minimize. The pause and memory management portion isn't an issue, but I'm not sure what events T2D has to allow me to know when the system has been minimized or is not in focus?
Any help would be greatly appreciated.
Thanks!
About the author
Love to engineer and develop just about anything. Our primary focus though is that of computer games and software tools.
#2
In file "winWindow.cc" right under the windowNotActive variable add another like so:
And wherever you find the windowNotActive being changed have the new variable change to the same value. Approximatly lines 905 and 918.
In file "main.cc" add this function and variable:
FYI: I tested it and it works.
I did not extern the original variable because VS did not like that. I did not want to mess with the original variable in case I break something.
The function is in main.cc because it VS didn't like it in the winWindow.cc file.
12/20/2012 (3:33 pm)
This was fairly easy to fix. GameDeactivate() and GameReactivate() don't return anything and I couldn't find anything that returned what we wanted.In file "winWindow.cc" right under the windowNotActive variable add another like so:
static bool windowNotActive = false; bool windowNotActiveE = false; //Add me.
And wherever you find the windowNotActive being changed have the new variable change to the same value. Approximatly lines 905 and 918.
In file "main.cc" add this function and variable:
//Added this function and related variables Dec,20/12. ~AK
extern bool windowNotActiveE;
ConsoleFunction( isWindowActive, bool, 1, 1, "This returns whether or not the window is active or not. (Minimized or not, focused or not focused)""@return true if not minimized or not in focus, false otherwise""@sa")
{
return !windowNotActiveE;
}FYI: I tested it and it works.
I did not extern the original variable because VS did not like that. I did not want to mess with the original variable in case I break something.
The function is in main.cc because it VS didn't like it in the winWindow.cc file.
#3
We have a game launching first week in Jan and have everything all set until our distributor slaps us with a monster requirements package at the end that I have for the most part taken care of, but they are very particular on being able to handle minimization events and T2D just didn't seem to have it by default.
12/20/2012 (11:05 pm)
Alpha... man thanks much for that. I'm not the best C++ dev for sure, most of the time poking around in the engine just causes me to wanna hang it up and realize Ill just never be that....LOL. I do alright when I'm creating from scratch(C++), but for me its an epic fail at trying to decipher larger code such as T2D. I guess I just need to spend more time with it and stay out of TorqueScript for a while....I do like Torquescript though; have been grinding it now for about 2 years I guess, just wish it was typed as sometimes I feel the type-lessness causes issues.We have a game launching first week in Jan and have everything all set until our distributor slaps us with a monster requirements package at the end that I have for the most part taken care of, but they are very particular on being able to handle minimization events and T2D just didn't seem to have it by default.
#4
I have this wonderful dream that I will one day fully document and decipher the source code of T2D. Then there will be no Torque problem I can't handle! Mwahahahahaa!!!
12/21/2012 (1:02 pm)
I'm really glad I can help. I'm no super-pro at c++ either but stuff like this I can handle. I have this wonderful dream that I will one day fully document and decipher the source code of T2D. Then there will be no Torque problem I can't handle! Mwahahahahaa!!!
#5
12/21/2012 (6:59 pm)
ahahaha I feel you friend. If your interested in working on some casual projects in the future, give me a shout. We use T2D for casuals and another language for mobiles. We have a nice little team :-)
#6
12/22/2012 (9:16 am)
I am really curious, does the client want minimize events because of the Windows 8 App Lifecycle Management? I.E. When the program goes out of scope it has a set amount of time to save the state in case Windows 8 decides to close the app to free up resources, so that when it comes back into scope it appears the app never closed?
#7
If you mean Client as in publisher, they want the programs to be able to handle different events, for example, a user locking their machine (WINDOW-L) while the game is playing, closing the lid on their laptop while the program is running and obviously minimizing the window to do other tasks. They are checking for things I would never have imagined, but I would assume there would have to be some reason to the madness. This is on any OS for that matter.
One of their standards is to handle these events gracefully, effectively putting the program to sleep (stop audio, pause and all that)without causing the user inconvenience or crashing. T2D does not handle this by default (it should provide some method to interact with during focus changes or window state changes). One of the hardest aspect for casual developers is the end user experience, the hand holding if you will. They are VERY particular in this realm, both in game-play and out.
AK's solution should work as it will give me a function to check for a state change, I am actually getting ready to implement it now. Although it seems I would need to continually monitor this function in order to be able to react in time to the event as it occurs. I believe I could throw it in my t2dSceneGraph::onUpdateSceneTick without to much issue.
@AK
Forgive my ignorance here but where did you find the documentation on creating console functions, I have some more ideas for this..lol.
***UPDATE***
Just wanted to let you know, I have implemented this and have built functions in TorqueScript to handle the state difference(pause, memory and such) and it does exactly what we needed, this looks to work wonderfully and is stable, good call AK.
12/24/2012 (9:56 am)
@RichardIf you mean Client as in publisher, they want the programs to be able to handle different events, for example, a user locking their machine (WINDOW-L) while the game is playing, closing the lid on their laptop while the program is running and obviously minimizing the window to do other tasks. They are checking for things I would never have imagined, but I would assume there would have to be some reason to the madness. This is on any OS for that matter.
One of their standards is to handle these events gracefully, effectively putting the program to sleep (stop audio, pause and all that)without causing the user inconvenience or crashing. T2D does not handle this by default (it should provide some method to interact with during focus changes or window state changes). One of the hardest aspect for casual developers is the end user experience, the hand holding if you will. They are VERY particular in this realm, both in game-play and out.
AK's solution should work as it will give me a function to check for a state change, I am actually getting ready to implement it now. Although it seems I would need to continually monitor this function in order to be able to react in time to the event as it occurs. I believe I could throw it in my t2dSceneGraph::onUpdateSceneTick without to much issue.
@AK
Forgive my ignorance here but where did you find the documentation on creating console functions, I have some more ideas for this..lol.
***UPDATE***
Just wanted to let you know, I have implemented this and have built functions in TorqueScript to handle the state difference(pause, memory and such) and it does exactly what we needed, this looks to work wonderfully and is stable, good call AK.
#8
So:
1). In main.cc, find
2). In main.cc, find
3). Somewhere in your game scripts (say, main.cs), add:
12/28/2012 (11:22 am)
As an alternative to constantly calling a ConsoleFunction to check the game window state, you could simply have GameReactivate() and GameDeactivate() execute a script function. Then you could plug in any code you need to run when the game is minimized in those script functions. So:
1). In main.cc, find
void GameReactivate(). At the end of the function (just before the closing bracket), add:
Con::executef(1, "onGameReactivate");
2). In main.cc, find
void GameDeactivate(). At the endof the function (just before the closing bracket), add:
Con::executef(1, "onGameDeactivate");
3). Somewhere in your game scripts (say, main.cs), add:
function onGameReactivate()
{
// place code that needs to run when the game reactivates here
// e.g. unpausing the game
}
function onGameDeactivate()
{
// place code that needs to run when the game deactivates here
// e.g. pausing the game
}
Torque 3D Owner Richard Baker Jr
Baker's Game Studio
GameDeactivate()
GameReactivate()
Between lines 670~710.
Should be able to trace it back from there. I didn't search deep for where the engine is getting the OS message for minimizing or whatnot.