
I've locked fps to 60, and set the NewtonUpdate to 60... now internally I don't know what this is doing but in render, frame rate is a stable 60, and vehicles are moving fluidly, 15 of them. If I revert to 1 vehicle, then way too fast again

Moderators: Sascha Willems, walaber
Repeat
Lock;
FTimer.Refresh;
UpdateWorld(FTimer.FrameTime);
Close := FCloseNow;
Unlock;
MySleep;//Sleep(1);
Until Close;
const TimeSlice : Extended = 1/60;
procedure TNewtonThread.UpdateWorld(FrameTime : Extended);
begin
IncF(FLastFrameTime,FrameTime);
If FLastFrameTime > 1 then
FLastFrameTime := 1;
If FLastFrameTime >= TimeSlice then
begin
if not FPaused then
begin
NewtonUpdate(FWorld, TimeSlice);
NewtonManager.UpdateMatrixes;
end;
FNewtTimer.Refresh;
FFPS := FNewtTimer.GetLowFPS;
DecF(FLastFrameTime,TimeSlice);
if FLastFrameTime < 0 then
FLastFrameTime := 0;
end;
end;
const float framerateCost = 1f / 60f;
float lastFrameTime = 0;
float frameTime = 0;
public void Simulate()
{
frameTime = _engine.GetTimeElapsed();
lastFrameTime = lastFrameTime + frameTime;
if (lastFrameTime > 1)
{
lastFrameTime = 1;
}
if (lastFrameTime >= framerateCost)
{
physics.Simulate(framerateCost);
}
lastFrameTime = lastFrameTime - framerateCost;
if (lastFrameTime < 0)
{
lastFrameTime = 0;
}
}
return QueryPerformanceCounter(out x);
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceCounter(
out long lpPerformanceCount);
long freq = 0;
public double GetFreq()
{
QueryPerformanceFrequency(out freq);
return freq;
}
long timer = 0;
public double GetTicks()
{
QueryPerformanceCounter(out timer);
return ((double)timer / (double)freq);
}
const float framerateCost = 1f / 60f;
double lastFrameTime = 0;
double frameTime = 0;
double newGetTicks = 0;
double oldGetTicks = 0;
public void Simulate()
{
_engine.GetFreq();
newGetTicks = _engine.GetTicks();
frameTime = (newGetTicks- oldGetTicks);
oldGetTicks = newGetTicks;
lastFrameTime = lastFrameTime + frameTime;
if (lastFrameTime > 1)
{
lastFrameTime = 1;
}
if (lastFrameTime >= framerateCost)
{
physics.Simulate(framerateCost);
}
lastFrameTime = lastFrameTime - framerateCost;
if (lastFrameTime < 0)
{
lastFrameTime = 0;
}
}
void physicsLoop()
{
int count;
while (true)
{
Simulate();
}
}
const float framerateConst = 1f / 60f;
double lastFrameTime = 0;
double frameTime = 0;
double newGetSeconds = 0;
double oldGetSeconds = 0;
public void Simulate()
{
newGetSeconds = _engine.GetSecondsSimulation();
frameTime = (newGetSeconds - oldGetSeconds);
oldGetSeconds = newGetSeconds;
lastFrameTime = lastFrameTime + frameTime;
if (lastFrameTime > 1)
{
lastFrameTime = 1;
}
if (lastFrameTime >= framerateConst)
{
physics.Simulate(framerateConst);
}
lastFrameTime = lastFrameTime - framerateConst;
if (lastFrameTime < 0)
{
lastFrameTime = 0;
}
}
Users browsing this forum: No registered users and 1 guest