Jump to content


Delays, and wait times...


12 replies to this topic

#1 adribin

    New Member

  • Members
  • Pip
  • 5 posts

Posted 14 February 2003 - 05:01 PM

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.

#2 donBerto

    Senior Member

  • Members
  • PipPipPipPip
  • 369 posts

Posted 14 February 2003 - 05:37 PM

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.
Imagine.

#3 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 14 February 2003 - 06:09 PM

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.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#4 abcd_z

    New Member

  • Members
  • Pip
  • 6 posts

Posted 14 February 2003 - 06:10 PM

are you talking about the function: timeGetTime() ?

#5 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 14 February 2003 - 06:33 PM

maybe getTickCount()?
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#6 Amithran

    Member

  • Members
  • PipPip
  • 32 posts

Posted 14 February 2003 - 11:27 PM

	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.


#7 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 15 February 2003 - 09:02 AM

that's the code I'd use, clean and simple, and doesn't pause the whole demo.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#8 donBerto

    Senior Member

  • Members
  • PipPipPipPip
  • 369 posts

Posted 15 February 2003 - 03:49 PM

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:
Imagine.

#9 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 15 February 2003 - 04:19 PM

unless you do that in another thread
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#10 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 17 February 2003 - 05:40 PM

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?..:)
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#11 CyraX

    Valued Member

  • Members
  • PipPipPip
  • 144 posts

Posted 18 February 2003 - 01:44 PM

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_

#12 Dia

    DevMaster Staff

  • Administrators
  • 1097 posts

Posted 18 February 2003 - 05:55 PM

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.

#13 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 18 February 2003 - 06:43 PM

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.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users