I'm doing a little beginner c++ program based on the game of snap.
When i output the card objects to the console, because of the computers processing speed naturally, a whole list of the cards that were dealt just appears. I thought it might be nice if i could put a pause between each card deal so that a human could actually observe each card being dealt. Since i'm always working on both Linux and Windows and already had < ctime > included i came up with this little solution:
for(;;){
if( (difftime(time(0),lastDealTime)) > 0.5f){ //half second passed
cout << currentCard <<endl;
lastDealTime = time(0);
break;
}
}
At first i thought it had worked but then when i tried to speed up the dealing process later i realised that changing the control value of 0.5 (i was aiming for a card deal every half a second) didn't seem to have any effect.. i tried changing it to deal every 0.05 seconds and it made no difference, cards still seemed to be output every second i would guess.
Any observations as to why this wouldn't be working? Thanks!
time()
anddifftime()
have a resolution of a second, to there's no way to use them to manage intervals of less than a second; even for intervals of a second, they're not usable, since the jitter may be up to a second as well.In this case, the solution is to define some sort of timer class, with a system independent interface in the header file, but system dependent source files; depending on the system, you compile one source file or the other. Both Windows and Linux do have ways of managing time with higher resolution.