I've spent the entire day trying out game loops all over the internet, the "Bullet canonical game loop" included. They seem to work fine sure, the animation plays smoothly, the logic updates consistently. But bullet... just stutters everywhere, the simulation is still accurate, there's no tunnelling, but it just doesn't look smooth at all. This isn't a walking over terrain thing. It's a rigid-body moving through empty space thing. I can't understand what I'm doing wrong.
Here's the current code. Yeah, it's an interop assembly but it all runs on one WinMain() thread. (The message pump has been shoved inside input->update())
Code: Select all
void Engine1system::Run(SceneTick^ tick)
{
const unsigned int TickMs = 32;
unsigned long time_physics_prev = 0, time_physics_curr = 0;
unsigned long time_gameclock = 0;
physics->m_clock.reset();
while(graphics->Render())
{
time_physics_curr = physics->m_clock.getTimeMilliseconds();
float deltaTime = ((float)(time_physics_curr - time_physics_prev))/1000.0;
time_physics_prev = time_physics_curr;
physics->dynamicsWorld->stepSimulation(deltaTime, 10);
System::Collections::Generic::LinkedList<AnimChannelInstance^>::Enumerator i = AnimList->GetEnumerator();
while(i.MoveNext())
{
i.Current->AddTime(deltaTime);
}
long long dt = physics->m_clock.getTimeMilliseconds() - time_gameclock;
while(dt >= TickMs)
{
dt -= TickMs;
time_gameclock += TickMs;
input->Update();
//tick(); // Game logic. Makes no difference enabled or disabled.
}
}
}
I hope I'm not a pain in the ass with all these help topics - here's work in progress to make it seem less futile :D