Sign in to follow this  

[C++] Timestep Issue (?)

This topic is 3462 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

Hey everyone, I am currently having an issue with a very simple program I am writing. The program creates a sprite and, based on input, can rotate the sprite in 360 degrees and based on rotation propel the sprite forward in the direction of rotation. (Think Asteroids) The issue occurs when I run the application and begin moving the sprite around. Every second or so I get a hiccup in movement, depending on the FPS of the application. At 1000 FPS the program seems to run smoothly but just looking at the image as I fly it around my eyes can't focus on the image. When the FPS are reduced to anything below 1000, be it on a different computer at max ability or when I choke my FPS on my gaming system, the movement gets more and more sluggish and jittery. From other help I have received in the chat and just personal experimentation with the code I have done the following: - Multiplied any coordinate translations by a delta value (time since last logic update) I would also like to note that I am use Haaf's Game Engine (HGE) and the way this engine works is that the FrameFunc (logic update) and RenderFunc (rendering update) is called consecutively as many times per frame as possible. So for every logic update--there is a render. Hope you guys can help me out and I am willing to provide code/executables if requested. Appreciate your time in advance.

Share this post


Link to post
Share on other sites
Quote:
Please post the code that handles the movement and the code that calculates the time delta.


The time delta code is an engine-created code. The movement code is here:

void CSprite::Update( float dt )
{
if( hge->Input_GetKeyState( HGEK_LEFT ) )
{
rotation += 5.0f * dt;
if( rotation >= ( 2 * M_PI ) )
rotation = 0;
}
if( hge->Input_GetKeyState( HGEK_RIGHT ) )
{
rotation -= 5.0f * dt;
if( rotation <= 0 )
rotation = (2 * M_PI);
}
if( hge->Input_GetKeyState( HGEK_UP ) )
{
if( velocity < MAX_VELOCITY )
velocity += 10.0f;
if( velocity > MAX_VELOCITY )
velocity = MAX_VELOCITY;
}
if( hge->Input_GetKeyState( HGEK_DOWN ) )
{
if( velocity > 0 )
velocity -= 10.0f;
if( velocity < 0 )
velocity = 0;
}

posX = posX - ( velocity * sin(rotation) ) * dt;
posY = posY - ( velocity * cos(rotation) ) * dt;

//Update Position
quad.v[0].x = posX - 32; quad.v[0].y = posY - 32;
quad.v[1].x = posX + 32; quad.v[1].y = posY - 32;
quad.v[2].x = posX + 32; quad.v[2].y = posY + 32;
quad.v[3].x = posX - 32; quad.v[3].y = posY + 32;
}


Thanks for taking the time to reply and assist.

Share this post


Link to post
Share on other sites
After tampering with the HGE samples I found that the problem I have persists even in the samples. I don't think I will be using this engine any longer. Sorry to waste anyone's time.

Share this post


Link to post
Share on other sites

This topic is 3462 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this