Jump to content
  • Advertisement
Sign in to follow this  
Bluseed

Sleep!!

This topic is 4542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im simply trying to pause the game for a quick second. But before it pauses i want it to put the ball in the right place, but its pausing before the ball is reset to (0,0).
void RestartGame()
{

	Ball.x = 0.0f;
	Ball.y = 0.0f;

	Sleep(1000);
	//Random Ball Angle
}

Share this post


Link to post
Share on other sites
Advertisement
What is Ball? Are you drawing the changes before you Sleep()? "Random Ball Angle"?

You need to give us more information.

Share this post


Link to post
Share on other sites
How are you rendering ball? Chances are it is resetting the position, but you don't see it because Sleep blocks the next frame from being rendered.

Share this post


Link to post
Share on other sites
I recommend aginst using Sleep() at all. Just write your own function to idle for a certein amount of time, like this one (c++):

#include <time.h>

void idle(int seconds)
{
clock_t start = clock();
while ( clock() - start < seconds * CLK_TCK ) {}
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Scet
How are you rendering ball? Chances are it is resetting the position, but you don't see it because Sleep blocks the next frame from being rendered.

Quoted for emphasis.

void RestartGame()
{

Ball.x = 0.0f;
Ball.y = 0.0f;

RenderBall(); // or whatever

Sleep(1000);
//Random Ball Angle
}


Share this post


Link to post
Share on other sites
Dammit this is so stupid, i dont get it!!!

this is how im rendering it!?

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();

//Texture
glBindTexture(GL_TEXTURE_2D, texture[filter]);

//Sphere
glTranslatef(Ball.x,Ball.y,-15.0f);
glRotatef(Xrot,0.0f,0.0f,1.0f);
gluSphere(quadratic,0.5,32,32); // Draw A Sphere With A Radius Of 1 And 16 Longitude And 16 Latitude Segments

glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


glTranslatef(PaddleX,PaddleY,-15.0f);
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);

// Right Face
glNormal3f( 1.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( -0.7f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( -0.7f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( -0.7f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( -0.7f, -1.0f, 1.0f);

// Top Face
glNormal3f( 0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.9f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.9f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f, 1.0f, -1.0f);

// Bottom Face
glNormal3f( 0.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.7f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.7f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);


glEnd();

glLoadIdentity();


glTranslatef(PaddleX2,PaddleY2,-15.0f);
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);

// Right Face
glNormal3f( 1.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( -1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( -1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( -1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( -1.0f, -1.0f, 1.0f);

// Top Face
glNormal3f( 0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.7f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.7f, 1.0f, -1.0f);

// Bottom Face
glNormal3f( 0.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.7f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.7f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);


glEnd();


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//EndTexture
glBindTexture(GL_TEXTURE_2D, 0);


//Text
glColor3f(1.0f,1.0f,1.0f);
glTranslatef(-8.1f,5.6f,-15.0f);
glRasterPos2f(0.0f, 0.0f);


glPrint("SphereX - %f SphereY - %f ", Ball.x ,Ball.y); // Print GL Text To The Screen

glLoadIdentity();

//Text
glColor3f(1.0f,1.0f,1.0f);
glTranslatef(-8.1f,5.3f,-15.0f);
glRasterPos2f(0.0f, 0.0f);


glPrint("Player1 - %d Player2 - %d ", Player1Score ,Player2Score); // Print GL Text To The Screen


glLoadIdentity();

//Text
glColor3f(1.0f,1.0f,0.0f);
glTranslatef(-8.1f,5.0f,-15.0f);
glRasterPos2f(0.0f, 0.0f);


glPrint("Distance - %f Distance - %f blnCollide - %d", Distance, Distance2, blnBallY);

glLoadIdentity();

//Text
glColor3f(0.3f,0.3f,1.0f);
glTranslatef(-8.1f,4.7f,-15.0f);
glRasterPos2f(0.0f, 0.0f);


glPrint("XVelocity - %f YVelocity - %f", Ball.xv, Ball.yv);

glColor3f(1.0f,1.0f,1.0f);
glLoadIdentity();

if (blnCollide == true || blnCollide2 == true)
{
glLoadIdentity();

//Text
glColor3f(1.0f,1.0f,1.0f);
glTranslatef(-8.1f,4.4f,-15.0f);
glRasterPos2f(0.0f, 0.0f);


glPrint("Collision Detected");

}

EnemyAI();

if (blnMoveBall == true)
{
moveBall();
blnRestart = false;
}

if (blnRestart == true)
{
idle(1);

blnMoveBall = true;
blnRestart = false;
}

Collide(PaddleX - 1.0f,PaddleY,Ball.x,Ball.y);
Collide2(PaddleX2,PaddleY2,Ball.x,Ball.y);

return TRUE; // Everything Went OK
}



Does that make any sense?

Share this post


Link to post
Share on other sites
Quote:
Original post by Driv3MeFar
I recommend aginst using Sleep() at all.

care to provide a reason, or should we just assume you have some secret knowledge as to why Sleep is bad?
Quote:
Original post by Driv3MeFarJust write your own function to idle for a certein amount of time, like this one (c++):
#include <time.h>

void idle(int seconds)
{
clock_t start = clock();
while ( clock() - start < seconds * CLK_TCK ) {}
}


that is not a sleep or an idle function. That is a wasteCpuCyclesInAPointlessTightLoop function.

Do you actually know what Sleep() does? Sleep yields the current thread allowing other processes/threads to use the cpu. At best your "idle" function will be optimised out and at worst it'll just hog the cpu.

to the OP, are you using seperate threads to render the ball?

Share this post


Link to post
Share on other sites
Not how but when. :)

The existing code changes the data about the ball, and then causes everything to pause. The reason you don't see the ball move is because the pause happens after the change in data but *before* the ball is drawn again. After the pause, the ball draws (eventually, depending on what else the code does), now in the updated position.

So you need to reorder some stuff, and likely redesign part or all of the game loop. Do not just hack it. You will regret doing so.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!