|
al_stop_timer when lost focus? |
duncan perham
Member #15,403
November 2013
|
I notice that when debugging, the timer is still running (because its on a seperate thread). Problem is, when the game resumes it trys to catch up on lost time giving like 400 fps for a while. Is there anyway to make it pause when it loses focus? |
Aikei_c
Member #14,871
January 2013
|
You can use ALLEGRO_EVENT_DISPLAY_SWITCH_OUT and ALLEGRO_EVENT_DISPLAY_SWITCH_IN. |
duncan perham
Member #15,403
November 2013
|
Thanks for the ideas, the problem is, I have no control over the timing other than to set it to whatever FPS I want. al_wait_for_event(queue,&event); it seems that the al_wait_for_event just spams ALLEGRO_EVENT_TIMER events until it catches up. It dosent seem to realise that focus was lost. |
l j
Member #10,584
January 2009
|
Handle the ALLEGRO_EVENT_DISPLAY_SWITCH_OUT and ALLEGRO_EVENT_DISPLAY_SWITCH_IN events. if (event.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) al_stop_timer(timer); else if (event.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN) al_start_timer(timer);
|
duncan perham
Member #15,403
November 2013
|
unfortunatley taron, that wont work, as the debugger stops the main thread before it can send the switchout event, so the timer just keeps counting. It does work as a pause when the game dosent have focus, ie alt tab out etc. The debugger breaking into the game dosent give it a chance to respond as it freezes the main thread, but while its being debugged the update commands are still being added because the timming thread is still running!. If that sort of code was embeded into the timing thread it would work great. But I dont think it is. So the only other solution I can think of is... if there is someway of detecting that there is a few hundred events sitting on the que, then ignoring all the update events. al_flush_event_queue(ALLEGRO_EVENT_QUEUE *queue). well I set it up like this........... al_wait_for_event(queue,&event); which seems to do the trick, since I set the FPS as 60, I am assuming that the timer counts 60 times a second?. In theory, it should only ever flush the Que when teh debugger stops the code. If anyone has any better ideas let me know. |
Aikei_c
Member #14,871
January 2013
|
Aa I said, you can store the time of last run through the loop and check if the difference between the current time and last run time is too big. And do anything you want if it is. Like flushing the event queue. |
|