I don't know exactly what you are trying to achieve with the following
Code: Select all
if(m_TimeFactor > m_LastTimeFactor+0.01f) m_TimeFactor = m_LastTimeFactor + 0.01f;
if(m_TimeFactor < m_LastTimeFactor-0.01f) m_TimeFactor = m_LastTimeFactor - 0.01f;
It looks as though it is designed to soften the blow of jumpiness, but it loses the movement rate consistencey, which is not a good way to go on an MPG.
Maybe you could enlighten me. Also, by using floats I meant for values that have the possibility of being floats. Persumably when you divide m_TimeFactor by 100 this is for scaling movement?
anyway, I would have thought the code would look something like that, I haven't seen the tutorial so I don't know what kind of stuff it covers.
Code: Select all
//include etc
//Globals
//constants
const float MOVE_RATE_MOD = whatever float gives the best result
//variables
int iLastTime;
//function prototypes
float getMoveRateModifier();
int main()
{
//initialisation code
iLastTime = device -> getTime();
float fThisMoveDist;
while(device -> run())
{
fThisMoveDist = MOVE_RATE_MOD * getMoveRateModifier();
//use fThisMoveDist
//perhaps a timedelay in here would help to keep down the jumpiness?
}
}
float getMoveRateModifier()
{
int iTime = device -> getTime();
float fResult = (iTime - iLastTime) / 100; //I think this is what you'd want
iLastTime = iTime;
return fResult;
}
I haven't thought much about that code or compiled it, so there are probably a few mistakes (especially seeing as I only started C++ 2 months ago!). But that hopefully gives you the basic gist of my train of thought, also, where I used fThisMoveDist is where I assumed you should be using a float.
Hopefully this can be of some use
Edit:
Actually, having thought about it, you may want something like this...
Code: Select all
//include etc
//Globals
//constants
const float MOVE_RATE_MOD = whatever float gives the best result
const int TIME_TO_ELLAPSE = whichever time you want to ellapse between frames (in the same units as the device -> getTime() function is in.
//variables
int iLastTime;
//function prototypes
float getMoveRateModifier();
bool getIsNextFrame();
int main()
{
//initialisation code
iLastTime = device -> getTime();
float fThisMoveDist;
bool bDoneFrame = false;
while(device -> run())
{
if(!bDoneFrame)
{
//begin and end scene go in this if statement
fThisMoveDist = MOVE_RATE_MOD * getMoveRateModifier();
//use fThisMoveDist
bDoneFrame = true;
}
else
if(getIsNextFrame)
bDoneFrame = false;
}
}
//function definitions
float getMoveRateModifier()
{
int iTime = device -> getTime();
float fResult = (iTime - iLastTime) / 100; //I think this is what you'd want
iLastTime = iTime;
return fResult;
}
bool getIsNextFrame()
{
int iTime = device -> getTime();
if((iTime - iLastTime) >= TIME_TO_ELLAPSE)
return true;
return false;
}
This code will delay the next frame from being drawn until the system is ready, this will guarntee a consistent FPS on high perormance machines. The minimum FPS you should be going for is 24 FPS, so if you organise your game to run at 24FPS+ consistently using this method on a min spec machine the ga,e will work fine on other computers too. A below minimum spec computer will however have the problems you describe about jumpy movement (but they shouldn't really be running the game!).
Nocode has been comiled, if you have any problems implementing it (if you decide to do so) then just post here.