Delays, and wait times...

Dbe920fcb98c5bd73bc49c0f378819bf
0
adribin 101 Feb 14, 2003 at 17:01

What are some methods of creating pauses, and wait times? I tried to use the c++ system(“PAUSE”) but when I run an open gl program with that a cmd window pops up and just sits there, so im guessing you cant use it….

I wanna decrement a shapes y position. so as in tetris, I want the shape to drop…then wait about 1 second then drop then wait then drop then wait. I know how to get the figure to drop alrady, just need methods of delaying the drops. Thnx in advance.

12 Replies

Please log in or register to post a reply.

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Feb 14, 2003 at 17:37

there’s a handful of ways to approach your problem and one of them, you mentioned.

using system(“pause”) is not what i’m talking about but the idea is the same. maybe you could make or use a time function and incorporate a while loop and have it run until time has ran for a certain amount of (milli|nano)seconds.

// pseudo code
void pause(int m_seconds)  // or whatever measure of time you want to use
{
    if (m_seconds <= 0)
        return;    // don't wait/pause

    unsigned int
        end_time,
        start_time = get_ticks();

    while ( (end_time - start_time) < m_seconds)
        end_time = get_ticks();

    // when end_time - start_time is greater than m_seconds,
    // the loop is broken, and the function ends.
}

I can’t remember if get_ticks() exists or not [in time.h] but there’s a function similar to it. and wherever you want to pause, you would just call your pause function.

hope that helps.

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Feb 14, 2003 at 18:09

another way is to have a global (or static, member, whatever) variable, and record the current time, as accurately as you can, in that variable. Then every loop you can check if the current time is 1 second more than that variable. If it is, 1 second has passed.

855b0d863f265e3c14dea094409fa320
0
abcd_z 101 Feb 14, 2003 at 18:10

are you talking about the function: timeGetTime() ?

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Feb 14, 2003 at 18:33

maybe getTickCount()?

Aebe30cac3048af2b72eaf832b698755
0
Amithran 101 Feb 14, 2003 at 23:27
    if( true ) { // some sort of expression to decide if you want to use slowdown
 static int lastUpdate; 
 static int speed = 120; // static speed, that way you can change it progmaticly
 if( lastUpdate + speed < GetTickCount() )
 {
    P_Update(); // if enough time has passed do updating
    lastUpdate = GetTickCount(); // and set last update time
 }
    }
         Render(); // I put render method out of this expression that way you always have smooth rendering.
         // none of your updating should actually be done in render any ways. This method allows you to have say
         // a player that moves once every 1 second, but still have more then 1 frame per second. Also allows for animations
         // between updates.
0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Feb 15, 2003 at 09:02

that’s the code I’d use, clean and simple, and doesn’t pause the whole demo.

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Feb 15, 2003 at 15:49

oops, i only showed one example - my bad. yeah, the code i showed above would pause THE ENTIRE program, AMITHRAN’s code would be asychronous.

:yes:

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Feb 15, 2003 at 16:19

unless you do that in another thread

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Feb 17, 2003 at 17:40

Sleep(milliseconds) ? :D

then again, your demo will not be touchable during this time. no problem really for a fullscreen app (except you want to quit during that sleep:D), but so what?..:)

590e8bdac8129bd87b188df15e62d0e5
0
CyraX 101 Feb 18, 2003 at 13:44

Typically I would do the following.
The game, is a state machine. All the entities that would change the game state would be collected and none of them would be modified while sleeping. Thus if I am walking in a game - that is just walking in a scenerio.
Entities that modify the game state - My x,y,z coordinates. If I pause… I would say

x = x+ movment_x;
y= y+movment_y;
z= z+movement_z;

Render(x,y,z); // This would have hte camera position.

whenever I want to pause… I would assign movement_? = 0; // By default
This would ensure that nothing in the game changes. Basically the “pause” is game state _NO_CHANGE_

Fdbdc4176840d77fe6a8deca457595ab
0
dk 158 Feb 18, 2003 at 17:55

Cryax, your method would be good for simple demos where movement is controlled by a simple variable, which is a very good idea.

However, when one is dealing with movement and motion using physical equations then you could have

dt = 0 // time between each fram = 0

which would make everything stop too.

Just an idea.

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Feb 18, 2003 at 18:43

also, looking at your original post, you want to avoid using system wherever it is physically possible, as it is a very good way of losing portability quickly. 99% of the time there is a better way anyway.