Jun 04, 2020
links to the Louisiana Constitution, the Louisiana Legislature, the Code of Criminal. Procedure and other pertinent Louisiana legal material.
. Mason's Manual Of Legislative Procedure.pdf
by Mason's Manual Of Legislative Procedure at FreeBooksy
, FreeBooksy
Category:Documents
Category:Parliamentary authorityQ:
How to synchronize clock in C++ (os)?
I'm making a simulation game with C++ and a pixel array as the screen.
I also have a separate thread that update the animation frame by frame.
The game runs on the Window OS.
Now I want to make my game to be able to use time instead of frames for synchronizing events.
The idea was to use the clock function and save it in the variables for milliseconds.
Then at each frame update I get the current milliseconds and if the difference from the saved one is bigger than the tolerance value the system sleep for ms.
This way I have the possibility to choose how much time I want to sync with the system's clock.
I'm almost there but still I get a few glitches.
This is my code so far:
//The variable I want to use in the time
long long ms;
//How much tolerance should I set
static const unsigned long LONG_TOLERANCE = 200;
//Current Milliseconds
long long currms;
//The function that return the current milliseconds
long long getMillis(){
clock_t c = clock();
return (c-clock_t(start_millis)) / (double)CLOCKS_PER_SEC;
}
//My function that update the animation frame
void update() {
//Get the current milliseconds
currms = getMillis();
//Compare currms with saved millis
if((currms-ms)>LONG_TOLERANCE)
sleep(currms-ms);
}
The problem with this is that the system might not do the right thing if the tolerance value is too large.
In such a case the system might sleep for too long and a flicker effect occurs.
How can I fix this problem?
I'm new to programming so I apologize if the question is too dumb.
Thank you be359ba680
Related links:
Comments