(Algorithm) Pausing a game

Hello people,
I am trying to add a small function to allow me to pause the game I am making.
I measure the time elapsed using the following algorithm:

1. USE ""clock_t begin=clock();"" FOR SYSTEM TIME OF GAME BEGINNING.
2. USE ""cout<<(clock()-begin)/CLOCKS_PER_SEC;"" TO DISPLAY TIME ELAPSED IN SECONDS.

Now, if I want to pause, I would want to subtract the 'paused' time from the total time elapsed.Say,

clock_t pause, resume;

{
pause=clock();
.
.
.
resume=clock();
}

Then I would do
cout<<(clock()-begin-(resume-pause))/CLOCKS_PER_SEC;

This, though is what I want, works only once(I can pause only once).
I can use arrays of resume and pause, but it would still limit the number of times I can pause.

What I am looking for is a way to pause any number of times.
Thankyou
man sleep
1
2
3
4
5
6
7
8
9
clock_t totalPause = 0;

...

totalPause += (resume - pause);

...

cout << (clock() - begin - totalPause)/CLOCKS_PER_SEC;
Last edited on
Ah! So wonderful and elementary. Thanks a lot for waking up a brain dead guy.
Topic archived. No new replies allowed.