Re: [Dev-C++] Sleep / for specified time delay :( ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Robert A. <ral...@gm...> - 2009-02-04 10:45:44
|
Please for the sake of yourself and the sanity of anyone who later may need to debug or modify your code. Please keep it simple and flexible by following two rules. 1) Create a customer Function, for example customerSleep(X) where X is clock ticks, nano seconds, seconds, minutes, etc... what ever you need. 2a) Check the major standards for something that does what you need and use that if at all possible in side your customer function. 2b)I would suggest posix standard, sleep if you don't need a precise delay, otherwise use the timeout feature of poll system call. 3c)If for some reason neither of those work, use something for your OS. Following rule 1 will mean that you only need to make adjustments in one place if you need to fix/change or port the delay to another platform, or version, etc... Following the second rule will mean that it's more likely you won't need to make a fixes/changes for bugs or ports. Hope this helps, Robert On Wed, Feb 4, 2009 at 4:54 AM, Frederico Marques <the...@ho...> wrote: > Hey... > (* first, for those u are C++ coders, i apologize, i'll be murdering C++ > below... if you have a faint heart, please look away! :P *) > You can either use Sleep for windows... which works very well for most > cases, or you can do something like : > > snippet : > --------------------------------------------------------- > #include <time.h> > > class DeltaTime { > clock_t init; > unsigned delta; > public : > DeltaTime( float sec = 1 ) { setDelta( sec ); } > void setDelta( float sec ) { delta = CLK_TCK * sec; } > void start() { init = clock(); } > bool timeout() { return clock() - init >= delta; } > void wait() { while (!timeout()) ; } > } > -------------------------------------------------------------------- > > Usage : > snippet : > -------------------------------------------------------------------- > > DeltaTime timer( 10 ) ; > timer.start(); > timer.wait(); > -------------------------------------------------------------------- > > > Of course u can tweak it to make it more "easy" ... and, you can > introduce some linked list of function pointers, that iterate while the code > is in wait/timeout. Its "limitless" ^^. > > > Frederico Marques > > > > > > ________________________________ > Date: Tue, 3 Feb 2009 22:06:55 +0200 > From: gx...@gm... > To: dev...@li... > Subject: [Dev-C++] Sleep / for specified time delay :( ? > > Hi, > > I want to make a delay/pause in C++, in Dev-C++... Does somebody know how to > do that ? An example ? > > Thanks. > > > ________________________________ > Diversão em dobro: compartilhe fotos enquanto conversa usando o Windows Live > Messenger. > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with > Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code > to > build responsive, highly engaging applications that combine the power of > local > resources and data with the reach of the web. Download the Adobe AIR SDK and > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > |