Sign in to follow this  
3Dgonewild

Bug in my timer....

Recommended Posts

3Dgonewild    174
Hi everyone! I'll explain where im having problems , but first lets start with some code ... //My timer cpp..
#include "SimpleTimer.hpp"

/*
static bool TimerStarted; : in header
static int StartTicks; : in header
*/
namespace Simple_Timer{
static void InitTimer()
{
TimerStarted = false;
StartTicks = 0;
}

void UpdateTimer()
{
TimerStarted=true;
StartTicks = (int)SDL_GetTicks();
}

int GetTimerTicks()
{
if (TimerStarted) return (int)(SDL_GetTicks() - StartTicks);
else
return 0;
}

};//simple timer namespace

Main loop:
Simple_Timer::InitTimer();

while ingame..
Simple_Timer::UpdateTimer();
Clear screen 
Handle events etc..

if key..
#define Speed 200.0f
GameData.ScrollMapHorizontal(Speed,Simple_Timer::GetTimerTicks());
end..

end while..

Scroll map function:
void ScrollMapHorizontal(float vel,Uint32 Ticks)
{
scroll_tiles.xposition += vel * Ticks/1000;
}


Now where im having problems.. When using the timer , the movement is choppy(Even with 200.0f as velocity!..insane..)!. The frames per second are 655++ without vsync & with vsync 60 , and every object that doesnt collides with "Camera" , simply it will not be rendered. Without using the timer , and with less moving speed(3.0f ,-3.0f) everything works fine. When locking the frames at 60fps , it also works fine... Of course thats not a solution , so could you guys help me to improve my timer? Thanks!

Share this post


Link to post
Share on other sites
3Dgonewild    174
**UPDATE**

I've changed the code a little..


if key..
#define Speed 500.0f
GameData.ScrollMapHorizontal(Speed,Simple_Timer::GetTimerTicks());
end..





void ScrollMapHorizontal(float vel,Uint32 Ticks)
{
scroll_tiles.xposition += (float)(vel * (float)(Ticks/1000.0f));
}




And its working on my 2 pcs.
But really setting velocity to 500.0f isn't dangerous?..
First time im messing with frame independent movement.
Usually i just lock the frames..

Share this post


Link to post
Share on other sites

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