Here is a excerpt from log (one game update) when things run fine:
23:39:10: Application: NewtonWorldRayCast (from [16.475594 -8.053022 0.000019] to [16.475594 -9.853023 0.000019]) took 12 us
23:39:10: Application: NewtonWorldRayCast (from [-1.995628 2.947838 0.001547] to [-1.995628 1.147838 0.001547]) took 9 us
23:39:10: Application: NewtonWorldRayCast (from [-47.896816 -0.555944 0.000000] to [-47.896816 -2.355944 0.000000]) took 8 us
23:39:10: Application: NewtonWorldRayCast (from [-53.223907 -3.053026 -0.000001] to [-53.223907 -4.853026 -0.000001]) took 7 us
23:39:10: Application: NewtonWorldRayCast (from [-40.020599 -0.052151 0.000031] to [-40.020599 -1.852150 0.000031]) took 8 us
23:39:10: Application: NewtonWorldRayCast (from [-46.649170 4.947819 0.000009] to [-46.649170 3.147819 0.000009]) took 8 us
23:39:10: Application: NewtonWorldRayCast (from [-44.017715 -0.052149 0.000023] to [-44.017715 -1.852149 0.000023]) took 8 us
23:39:10: Application: NewtonWorldRayCast (from [21.178715 3.721332 -0.000002] to [10.027609 -7.302128 -0.000000]) took 56 us
23:39:10: Application: NewtonWorldRayCast (from [21.178715 3.721332 -0.000002] to [10.027609 -8.052128 -0.000000]) took 12 us
23:39:10: Application: NewtonWorldRayCast (from [21.178715 3.721332 -0.000002] to [10.027609 -8.802128 -0.000000]) took 12 us
23:39:10: Application: NewtonWorldRayCast (from [21.178715 3.721332 -0.000002] to [17.224497 -7.303022 0.000022]) took 11 us
23:39:10: Application: NewtonWorldRayCast (from [21.178715 3.721332 -0.000002] to [17.224497 -8.053022 0.000022]) took 11 us
23:39:10: Application: NewtonWorldRayCast (from [21.178715 3.721332 -0.000002] to [17.224497 -8.803022 0.000022]) took 10 us
23:39:10: Application: NewtonWorldRayCast (from [21.178715 3.721332 -0.000002] to [-2.744302 3.697837 0.001540]) took 11 us
And here is same thing right after the frame rate suddenly drops:
23:39:10: Application: NewtonWorldRayCast (from [10.827609 -8.052128 -0.000000] to [10.827609 -9.852128 -0.000000]) took 29 us
23:39:10: Application: NewtonWorldRayCast (from [16.424498 -8.053022 0.000022] to [16.424498 -9.853023 0.000022]) took 12 us
23:39:10: Application: NewtonWorldRayCast (from [-1.944302 2.947837 0.001540] to [-1.944302 1.147837 0.001540]) took 9 us
23:39:10: Application: NewtonWorldRayCast (from [-47.861340 -0.529313 0.000000] to [-47.861340 -2.329313 0.000000]) took 8 us
23:39:10: Application: NewtonWorldRayCast (from [-53.172516 -3.053027 -0.000001] to [-53.172516 -4.853026 -0.000001]) took 7 us
23:39:10: Application: NewtonWorldRayCast (from [-40.071751 -0.052151 0.000032] to [-40.071751 -1.852151 0.000032]) took 9 us
23:39:10: Application: NewtonWorldRayCast (from [-46.700562 4.947817 0.000013] to [-46.700562 3.147817 0.000013]) took 7 us
23:39:10: Application: NewtonWorldRayCast (from [-44.069107 -0.052150 0.000023] to [-44.069107 -1.852150 0.000023]) took 8 us
23:39:10: Application: NewtonWorldRayCast (from [21.091616 3.696302 -0.000014] to [10.079002 -7.302128 -0.000000]) took 21332 us
23:39:10: Application: NewtonWorldRayCast (from [21.091616 3.696302 -0.000014] to [10.079002 -8.052128 -0.000000]) took 21265 us
23:39:10: Application: NewtonWorldRayCast (from [21.091616 3.696302 -0.000014] to [10.079002 -8.802128 -0.000000]) took 21262 us
23:39:10: Application: NewtonWorldRayCast (from [21.091616 3.696302 -0.000014] to [17.173349 -7.303022 0.000025]) took 2514 us
23:39:10: Application: NewtonWorldRayCast (from [21.091616 3.696302 -0.000014] to [17.173349 -8.053022 0.000025]) took 2492 us
23:39:10: Application: NewtonWorldRayCast (from [21.091616 3.696302 -0.000014] to [17.173349 -8.803022 0.000025]) took 2489 us
23:39:10: Application: NewtonWorldRayCast (from [21.091616 3.696302 -0.000014] to [-2.692965 3.697837 0.001533]) took 448 us
My scene consists of a static body with compound collision (the level) and a number of dynamic bodies (players, etc.) with primitive collisions. The first half of the logged ray casts are for my character controllers detecting ground, latter half is for visibility checks between characters.
The game is configured to run everything in a single thread so there is no game code running in parallel with the ray casts. The problem occurs quite systematically when characters get close enough to each other to start making visibility tests using ray casts. For a little while those ray casts are really fast, then suddenly they start taking 20+ ms each. After a while things return to normal and ray casts are fast again. I don't see any significant changes taking place in the scene when the slowdown occurs.
First thing I checked is my ray cast callback. It gets usually called only once per ray and I don't see anything there that could suddenly block or waste tens of milliseconds:
- Code: Select all
Ogre::Real Simulator::newtonRayCallback(const NewtonBody* body, const Ogre::Real* normal,
int collision, void* userdata, Ogre::Real param)
{
if(param < 0.0f || param > 1.0f)
{
return 0.0f; // Intersection parameter outside of line segment -> abort ray cast
}
TRayCallbackUserData* data = (TRayCallbackUserData*)userdata;
// Update contact data
data->m_Contact->m_Movable = (Movable*)NewtonBodyGetUserData(body);
data->m_Contact->m_Normal[0] = normal[0];
data->m_Contact->m_Normal[1] = normal[1];
data->m_Contact->m_Normal[2] = normal[2];
data->m_Contact->m_Distance = data->m_SegmentLength * param;
data->m_Contact->m_Point = data->m_Origin + data->m_Segment * param;
// Continue tracing (only look for contacts closer than this one)
return param;
}
Any ideas on what might be going on here are welcome.