Tips and Tricks - ALT+TAB and CPU usage

Posted By: Lion_Ts

Tips and Tricks - ALT+TAB and CPU usage - 09/09/05 17:09

Hi!
Look at this:

No game pausing:
cpu usage ~97%

Freezing funcs only:
cpu usage ~60%
Code:

var wndf=0;
starter pause_game_at_alt_tab() //pause game on loose focus
{
while (1)
{
if (window_focus == 0){
if (!wndf){
wndf=1;
// camera.visible=off;
// fps_max=4;
freeze_mode = 1;
}
}else{
if (wndf){
freeze_mode = 0;
// fps_max=40;
// camera.visible=on;
wndf=0;
}
}
wait(1);
}
}


restrict fps:
cpu usage ~7%
Code:

var wndf=0;
starter pause_game_at_alt_tab() //pause game on loose focus
{
while (1)
{
if (window_focus == 0){
if (!wndf){
wndf=1;
// camera.visible=off;
fps_max=4;
freeze_mode = 1;
}
}else{
if (wndf){
freeze_mode = 0;
fps_max=40;
// camera.visible=on;
wndf=0;
}
}
wait(1);
}
}


disable camera:
cpu usage ~0% !
Code:

var wndf=0;
starter pause_game_at_alt_tab() //pause game on loose focus
{
while (1)
{
if (window_focus == 0){
if (!wndf){
wndf=1;
camera.visible=off;
fps_max=4;
freeze_mode = 1;
}
}else{
if (wndf){
freeze_mode = 0;
fps_max=40;
camera.visible=on;
wndf=0;
}
}
wait(1);
}
}


Ok, if you read this, you understand now, for low cpu usage catch loose focus event and disable your camera.
Posted By: TripleX

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/09/05 17:28

thanks a lot! Interesting tricks... I'll try it out today evening!
If this is true it should belong to the wiki
Posted By: Lion_Ts

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/09/05 17:52

It's true. I'm playing with this, when think: "what exceccive task do it with my cpu, when I'm in IDE ?". Then I tried to disable camera and framerate - that's it ! It's useful for windowed mode with automatic game pausing when task swiched, I think.
Posted By: FRAJO

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/09/05 17:59

Cool. I'll integrate it in my game!
Posted By: fogman

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/09/05 18:06

Jep, useful codesnippet.

Very short and easy, itīs strange that no one had this idea before.
Congratulations
Posted By: Lion_Ts

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/09/05 18:18

Quote:

Jep, useful codesnippet.
Very short and easy, itīs strange that no one had this idea before.
Congratulations



I think many people has this code, but may be they just forget to post this one ?
Posted By: TripleX

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/09/05 20:20

nope the most people havn't cared about the cpu usage if windows_focus is 0

By the way, it works. thy
Posted By: Mr Wurm

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/10/05 12:30

Yep, I for one knew about that one, used it when I got so few frames in the menu, navigating with a mouse pointer was a pain in the ... . Disabling the camera, since the view was covered anyways was a lifesaver there.
Posted By: Lion_Ts

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/10/05 18:09

Quote:

nope the most people havn't cared about the cpu usage if windows_focus is 0
By the way, it works. thy



Thank you, TripleX, for compliment.
Posted By: Inestical

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/12/05 07:22

wow, nice code comes very handy ^^
Posted By: Lion_Ts

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/14/05 11:57

Snippet placed to the WIKI on "C-script snippets" branch.
Posted By: Matt_Coles

Re: Tips and Tricks - ALT+TAB and CPU usage - 09/15/05 10:53

very nice
© 2024 lite-C Forums