• Advertisement
Sign in to follow this  

Bug in my timer....

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

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
Advertisement
**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
Sign in to follow this  

  • Advertisement