problem trying to sync motion...

Hi, i have a class to sync the movement in my opengl apps (different pc’s, same speed…), suddenly it doesnt work right with computers faster than mine, can anyone help me find out the mistake?

 
class sync
{
public:
	float targetfps;
	float fps;
	LARGE_INTEGER tickspersecond;
	LARGE_INTEGER currentticks;
	LARGE_INTEGER framedelay;

	float speedfactor;
	void init(float);
	void SetSpeedFactor();
};

void sync::init(float tfps)
{
	targetfps=tfps;
	QueryPerformanceCounter(&framedelay);
	QueryPerformanceCounter(&tickspersecond);
}

void sync::SetSpeedFactor()
{
	QueryPerformanceCounter(&currentticks);
	speedfactor=(float)(currentticks.QuadPart-framedelay.QuadPart)/((float)tickspersecond.QuadPart/targetfps);
	fps=targetfps/speedfactor;
	if (speedfactor <= 0) 
		speedfactor=1;
	framedelay=currentticks;
}
 

thanks!
[edit]
i call init at the beginning of the program and setspeedfactor, every frame, then i multiply everything by speedfactor, for example:
glTranslatef(movement*sync.speedfactor,0,0);

zukko,
I don’t know about the detail of your code, but I think the following line should be:

QueryPerformanceCounter(&tickspersecond);

to

QueryPerformanceFrequency(&tickspersecond);

==song==

This is vague. Can you explain what you are doing instead of putting such codes we know nothing about how it really does and how it is used in the network ?

thanks songho!! it was a very dumb mistake :stuck_out_tongue:
jide, its a class for time based movement instead of frame based movement.