|
A simple egg timer |
Samuel Henderson
Member #3,757
August 2003
|
I have a very simple question and I hope there is a very simple answer. I am trying to make a simple egg timer that will keep track of and display the number of seconds elapsed since pressing a "start timer" button. I'm just wondering what the best way of modifying my timing routine (which is the one mention in the manual FAQ) to count the seconds and then update the number of seconds on the screen. I suppose the screen only needs to be redrawn every 1 second, but would it be better if the screen was drawn at a normal rate? I tried doing some googling for C++ timing routines and time counters and such, most of came up involved using <ctime> and "for (time_t t = time() + 5; time() < t; ) {}" or "Sleep(ms_to_sleep);" Either way, I figured there is probably a better way in my case. Anyways, here is the code thus far...
This works great! Except it does nothing of what I want it to do ================================================= |
KnightWhoSaysNi
Member #7,339
June 2006
|
I think this will count the seconds since the program started. I am still new to allegro though.
|
Samuel Henderson
Member #3,757
August 2003
|
I'll give that a shot Knight [edit] I'm thinking now maybe I want it a bit more granular since I see how slow 1 second really is. [edit 2] Hmm.. I just noticed that the timer does not keep running when my computer is locked... this is going to be a bit of a problem. Is there a simple way to have the app run even while windows is locked? [edit 3] I think I may have just figured it out... what I can do is: at the start of program before the main loop get the current time and store that in a variable, in the main loop I can then subtract the value stored in that variable from the current time and store the result in seccount or whatever. I don't see any reason why this won't work, but I am too tired to test it right now. ================================================= |
Audric
Member #907
January 2001
|
The program is probably considered "switched in the background". If this is the case, it will not "beep" when the eggs are cooked, because execution does not continue at all. edit: ahh, I was thinking of an alarm type, with countdown...If you only need the elapsed time, locked computer is no problem. |
Samuel Henderson
Member #3,757
August 2003
|
Quote: edit: ahh, I was thinking of an alarm type, with countdown...If you only need the elapsed time, locked computer is no problem. I guess I should actually do both. I should have the egg timer function for counting down, as well as a stopwatch for counting up. Then the user can just select which option they want. edit: where would I be calling these functions? ================================================= |
BAF
Member #2,981
December 2002
|
Why are you using allegro for this? You'd probably have better luck with the whole running in the background thing using C#/it's GUI (if you're on windows), or if you won't want that, just use wx or something. (I mentioned C# because for an app like this, it would be easier). |
Samuel Henderson
Member #3,757
August 2003
|
I think I got it... I just want to make sure... edit: edit 2: ================================================= |
BAF
Member #2,981
December 2002
|
Bump |
Samuel Henderson
Member #3,757
August 2003
|
Ahh crap. I think I started the thread as the wrong type, I don't have the option for cookies even on a fresh post. Ahh well.... cookies go to: KnightWhoSaysNi, Audric and BAF for helping out! ================================================= |
|