Universe.Physics.OpenDynamicsEngine.ODEPhysicsScene.Simulate C# (CSharp) Method

Simulate() public method

This is our main simulate loop It's thread locked by a Mutex in the scene. It holds Collisions, it instructs ODE to step through the physical reactions It moves the objects around in memory It calls the methods that report back to the object owners.. (scenepresence, SceneObjectGroup)
public Simulate ( float timeElapsed ) : void
timeElapsed float
return void
        public override void Simulate(float timeElapsed)
        {
            step_time += timeElapsed;
            IsLocked = true;
            int nodesteps = 0;

            if (step_time > 0.5f)
                step_time = 0.5f; //Don't get ODE stuck in an eternal processing loop with huge step times

            while (step_time > 0.0f && nodesteps < 10)
            {
                try
                {
                    NoParam del;
                    while (SimulationChangesQueue.TryDequeue(out del) && m_scene.ShouldRunHeartbeat)
                        try {  del(); } catch { }

                    // Move characters
                    foreach (
                        ODESpecificAvatar actor in _characters.Where(actor => actor != null).Cast<ODESpecificAvatar>())
                        actor.Move(ODE_STEPSIZE);

                    // Move other active objects
                    lock (_activeprimsLock)
                        foreach (ODEPrim prim in _activeprims)
                            prim.Move(ODE_STEPSIZE);

                    if (m_rayCastManager != null)
                        m_rayCastManager.ProcessQueuedRequests();

                    if (!DisableCollisions)
                        Collision_optimized(timeElapsed);

                    d.WorldQuickStep(world, ODE_STEPSIZE);
                    d.JointGroupEmpty(contactgroup);
                }
                catch (Exception e)
                {
                    MainConsole.Instance.ErrorFormat("[ODE Physics]: {0}, {1}, {2}", e, e.TargetSite, e);
                }

                step_time -= ODE_STEPSIZE;
                nodesteps++;
            }

            IsLocked = false;

            PhysicsActor prm;
            while (RemoveQueue.TryDequeue(out prm))
            {
                ODEPrim p = (ODEPrim) prm;
                p.SetPrimForRemoval();
            }
// dup of removequeue??
            //while (DeleteQueue.TryDequeue(out prm))
            //{
            //    UniverseODEPrim p = (UniverseODEPrim) prm;
            //    p.setPrimForDeletion();
            //}

            if (!DisableCollisions)
            {
                foreach (ODECharacter av in _characters.Where(av => av != null))
                    av.SendCollisions();
                lock (_collisionEventListLock)
                {
                    foreach (PhysicsActor obj in _collisionEventDictionary.Values.Where(obj => obj != null))
                        obj.SendCollisions();
                }
            }

            foreach (ODECharacter actor in _characters.Where(actor => actor != null))
                actor.UpdatePositionAndVelocity(nodesteps*ODE_STEPSIZE);

            lock (_activeprimsLock)
            {
                foreach (ODEPrim actor in _activeprims.Where(actor => actor.IsPhysical))
                    actor.UpdatePositionAndVelocity(nodesteps*ODE_STEPSIZE);
            }
        }