Performance optimization suggestions

ologon
Posts: 5
Joined: Thu Jun 16, 2011 11:44 am

Performance optimization suggestions

Post by ologon »

Hi!
I'm using Bullet physics with Ogre3d for my game after switching from Newton some months ago, and I'm very happy with it so far. :)

In my game there are 10 to 15 active rigid bodies in the scene and about 20 static objects. The simulation is pretty smooth and I have a stable
framerate of 60fps. However sometimes the simulation suddently becomes a bit "choppy", then it eventually comes back to normal.
I believe the bottleneck here is m_dynamicsWorld->stepSimulation(deltaTime, 7); function I'm using to step the world.
I've tried to use btAxisSweep instead of btDbvtBroadphase and set m_dynamicsWorld->setForceUpdateAllAABB(false); and it seemed to help
but the problem still exists.

Since the physics scene is relatively simple, I guess it shouldn't be hard to get some smooth simulation. Am I missing some optimization?

Thanks in advance! :)
ologon
Posts: 5
Joined: Thu Jun 16, 2011 11:44 am

Re: Performance optimization suggestions

Post by ologon »

Okay, doing some research around I found out that my problem is known as "temporal aliasing", so maybe it has nothing to do with performance. Basically my objects with linear velocity do not move smoothly all the time, but sometimes there's some slight but very annoying stuttering.

Here's how I implemented my game loop:

Code: Select all

	
        //Gameplay fixed Time step
	static float gameplayTS = 1.0f /60.0f; //60 FPS
	static float timeAcc = 0; //Accumulator

	//Run game loop first
        if(mWindow->isClosed() || mShutDown)
	{
		//User requested shutdown. Let's inform the game loop
		gameLoop(false, evt.timeSinceLastFrame);

		return false;
	}
	else
	{
		//Avoid spiral of death
		float stepTime = evt.timeSinceLastFrame > 0.25 ? 0.25 : evt.timeSinceLastFrame;

		//Bullet world needs to be updated every rendering frame for smooth simulation
		m_dynamicsWorld->stepSimulation(stepTime, 10);

		//Run at fixed framerate!
	        timeAcc += stepTime;
		while (timeAcc >= gameplayTS)
		{
		   gameLoop(true, gameplayTS); //Keep going!
		   timeAcc -= gameplayTS;
		}
	}
The gameplay runs at fixed 60 fps but stepsimulation gets called every frame, and since I'm using motion states everything should get interpolated :/
Without vsync everything looks fine, but stuttering still happens if it is enabled... any suggestion?
GameOn
Posts: 35
Joined: Mon Dec 27, 2010 10:46 pm

Re: Performance optimization suggestions

Post by GameOn »

When I begun using bulletphysics I've experienced what I believe is the exact same glitch you are experiencing.

Trying to run bullet with a framerate different than 60FPS or other settings set differently than what is set by default (like timestep for example) caused that.

...I just left everything as default since it was no big deal for me, but I'd be happy to read the solution to this problem.

Good luck pal !