[kinda solved] Bad performance in Release Mode
I have a very strange problem:
while everything is fine in debug mode, the performance suddenly drops in release, as soon as I create a fast-moving body (or make the player run in a pile of boxes).
I update the OgreNewt::World with this code I stole somewhere:
mWorldElapsed += time;
int count = 0;
if ((mWorldElapsed > mWorldUpdate) && (mWorldElapsed < (1.0f)) )
{
while (mWorldElapsed > mWorldUpdate)
{
mWorld->update( mWorldUpdate );
mWorldElapsed -= mWorldUpdate;
count++;
}
}
else
{
if (mWorldElapsed < mWorldUpdate)
{
// not enough time has passed this loop, so ignore for now.
}
else
{
mWorld->update( mWorldElapsed );
count++;
mWorldElapsed = 0.0f; // reset the elapsed time so we don't become "eternally behind".
}
}
they are initialised as following:
mWorldUpdate = (Ogre::Real)(1.0f / (Ogre::Real)UPDATE_FRAMERATE);
mWorldElapsed = 0.0f;
with UPDATE_FRAMERATE = 120
Framerates are about 560 fps in release and ~30 in debug mode. I would guess something about float precision problems, but no idea where...
albino
16-12-2007 16:40:46
why dont you just use
physicsWorld->update(600);
albino
16-12-2007 19:05:53
i use this code
while (sim->getCurrentState() != SHUTDOWN)
{
handler->processInput();
physics->updatePhysics();
world->update();
// run the message pump (Eihort)
Ogre::WindowEventUtilities::messagePump();
ogre->renderOneFrame();
if (window->isClosed())
break;
}
and in the updatePhysics() function i have
void Physics::updatePhysics()
{
physWorld->update(600);
}
works fine for me
that seems strange... i thought you have to pass the time since last frame (in seconds) to the update function... well, i have nothing to lose, so i can try this as well...
\€dit: no, same problem. i am firing ellipsoids for testing (mass=5, velocity=10), the first one flys as expected, the second causes alerady a little lag, the third a greater lag, and the fourth the ultimate lag of death
albino
16-12-2007 19:11:05
well
void OgreNewt::World::update ( Ogre::Real t_step )
update the world by the specified time_step.
this function is clamped between values representing fps [60,600]. if you pass a smaller value, it is internally clamped to 60fps. likewise a value higher than 600fps is treated as 600fs.
is what ogrenewt library says
as i understood it, framerate of 60 means 1/60 of a second. 600 is greater than that, so it is considered 1/60. Try to use 60 inf the function, it should have the same result
albino
16-12-2007 19:22:59
ye i was testing if it changes anything if i set it as 60 or 600
but didnt see much difference
guess we have to wait for walaber...
walaber
16-12-2007 22:05:05
update() takes values in SECOND, but the value is clamped internally between (1/600) and (1/60), correspinding to 60 - 600 fps.
if you pass ANY number larger than 1/60, internally it will just use 1/60, so passing it update(60) and update(600) are the same.
to get back to the original question, you need to look at what is causing the slowdown... do you have a very large stack of objects that you are shooting at, or some other obvious reason?
also, that loop can cause problems because it will keep getting further and further "behind" until you drrop below 1fps.
try changing the last part of the first line:
if ((mWorldElapsed > mWorldUpdate) && (mWorldElapsed < (1.0f)) )
to something like
if ((mWorldElapsed > mWorldUpdate) && (mWorldElapsed < (1.0f / 20.0f)) )
that means it will perform multiple loops to try and keep the physics running at realttime rates, but if the fps drops below 20fps, it will just update once per loop until it catches up.
feel free to ask if you still have questions.
ok, seems like i understood the fps thing right...
and for the reason: no real idea...
i just tried it in a level with just a plane and nothing else. I got about 3000 fps, and it took a little longer until i could see the lag. but i discovered something: my player has the mesh of the ninja, and i make it play the attack animation once if he shoots. in release mode he doesn't stop for some reason...
maybe it has nothing to do with newton... on the other hand, it was around the world->update() part where it needed the most time
*push*
seems to be the fault of my missile class. if i spawn some bodies directly and tell them to fly with velocity=10, it works perfectly. I'll have a closer look later, guess i have no choice but comment out line for line until i've found the problem...
ok, i made it work, but i have absolutely no idea how...
i just removed my code, and reconstructed it. perhaps its about in what order i set position, velocity, material group and so on... i suppose that was a classic case of evil code...
edit: i do update this way now:
mWorldElapsed += time;
while(mWorldElapsed > mWorldUpdate)
{
mWorld->update(mWorldUpdate);
mWorldElapsed -= mWorldUpdate;
}