diff options
author | Justin Clark-Casey (justincc) | 2011-07-29 00:23:42 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-07-29 00:23:42 +0100 |
commit | 9c6227da661952ddc808e6c5fb0da5ebf774f0cb (patch) | |
tree | b16941ee7b3ffd8ca05dc60951c83f946d3853e5 /OpenSim/Region/Physics/OdePlugin | |
parent | When using osTeleportAgent() and osTeleportAvatar(), only teleport if the reg... (diff) | |
download | opensim-SC_OLD-9c6227da661952ddc808e6c5fb0da5ebf774f0cb.zip opensim-SC_OLD-9c6227da661952ddc808e6c5fb0da5ebf774f0cb.tar.gz opensim-SC_OLD-9c6227da661952ddc808e6c5fb0da5ebf774f0cb.tar.bz2 opensim-SC_OLD-9c6227da661952ddc808e6c5fb0da5ebf774f0cb.tar.xz |
refactor: unindent the OdeScene.Simulate() loop to ignore the long commented out ifs and locks
This is to make it more readable.
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 544 |
1 files changed, 274 insertions, 270 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index a307469..a6d737e 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs | |||
@@ -2687,320 +2687,321 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); | |||
2687 | //if (!ode.lockquery()) | 2687 | //if (!ode.lockquery()) |
2688 | //{ | 2688 | //{ |
2689 | // ode.dlock(world); | 2689 | // ode.dlock(world); |
2690 | try | ||
2691 | { | ||
2692 | // Insert, remove Characters | ||
2693 | bool processedtaints = false; | ||
2694 | 2690 | ||
2695 | lock (_taintedActors) | 2691 | try |
2696 | { | 2692 | { |
2697 | if (_taintedActors.Count > 0) | 2693 | // Insert, remove Characters |
2698 | { | 2694 | bool processedtaints = false; |
2699 | foreach (OdeCharacter character in _taintedActors) | ||
2700 | { | ||
2701 | character.ProcessTaints(timeStep); | ||
2702 | 2695 | ||
2703 | processedtaints = true; | 2696 | lock (_taintedActors) |
2704 | //character.m_collisionscore = 0; | 2697 | { |
2705 | } | 2698 | if (_taintedActors.Count > 0) |
2699 | { | ||
2700 | foreach (OdeCharacter character in _taintedActors) | ||
2701 | { | ||
2702 | character.ProcessTaints(timeStep); | ||
2706 | 2703 | ||
2707 | if (processedtaints) | 2704 | processedtaints = true; |
2708 | _taintedActors.Clear(); | 2705 | //character.m_collisionscore = 0; |
2709 | } | ||
2710 | } | 2706 | } |
2711 | 2707 | ||
2712 | // Modify other objects in the scene. | 2708 | if (processedtaints) |
2713 | processedtaints = false; | 2709 | _taintedActors.Clear(); |
2710 | } | ||
2711 | } | ||
2712 | |||
2713 | // Modify other objects in the scene. | ||
2714 | processedtaints = false; | ||
2714 | 2715 | ||
2715 | lock (_taintedPrimLock) | 2716 | lock (_taintedPrimLock) |
2717 | { | ||
2718 | foreach (OdePrim prim in _taintedPrimL) | ||
2719 | { | ||
2720 | if (prim.m_taintremove) | ||
2716 | { | 2721 | { |
2717 | foreach (OdePrim prim in _taintedPrimL) | 2722 | //Console.WriteLine("Simulate calls RemovePrimThreadLocked"); |
2718 | { | 2723 | RemovePrimThreadLocked(prim); |
2719 | if (prim.m_taintremove) | 2724 | } |
2720 | { | 2725 | else |
2721 | //Console.WriteLine("Simulate calls RemovePrimThreadLocked"); | 2726 | { |
2722 | RemovePrimThreadLocked(prim); | 2727 | //Console.WriteLine("Simulate calls ProcessTaints"); |
2723 | } | 2728 | prim.ProcessTaints(timeStep); |
2724 | else | 2729 | } |
2725 | { | 2730 | processedtaints = true; |
2726 | //Console.WriteLine("Simulate calls ProcessTaints"); | 2731 | prim.m_collisionscore = 0; |
2727 | prim.ProcessTaints(timeStep); | 2732 | |
2728 | } | 2733 | // This loop can block up the Heartbeat for a very long time on large regions. |
2729 | processedtaints = true; | 2734 | // We need to let the Watchdog know that the Heartbeat is not dead |
2730 | prim.m_collisionscore = 0; | 2735 | // NOTE: This is currently commented out, but if things like OAR loading are |
2731 | 2736 | // timing the heartbeat out we will need to uncomment it | |
2732 | // This loop can block up the Heartbeat for a very long time on large regions. | 2737 | //Watchdog.UpdateThread(); |
2733 | // We need to let the Watchdog know that the Heartbeat is not dead | 2738 | } |
2734 | // NOTE: This is currently commented out, but if things like OAR loading are | ||
2735 | // timing the heartbeat out we will need to uncomment it | ||
2736 | //Watchdog.UpdateThread(); | ||
2737 | } | ||
2738 | 2739 | ||
2739 | if (SupportsNINJAJoints) | 2740 | if (SupportsNINJAJoints) |
2740 | { | 2741 | { |
2741 | // Create pending joints, if possible | 2742 | // Create pending joints, if possible |
2742 | 2743 | ||
2743 | // joints can only be processed after ALL bodies are processed (and exist in ODE), since creating | 2744 | // joints can only be processed after ALL bodies are processed (and exist in ODE), since creating |
2744 | // a joint requires specifying the body id of both involved bodies | 2745 | // a joint requires specifying the body id of both involved bodies |
2745 | if (pendingJoints.Count > 0) | 2746 | if (pendingJoints.Count > 0) |
2747 | { | ||
2748 | List<PhysicsJoint> successfullyProcessedPendingJoints = new List<PhysicsJoint>(); | ||
2749 | //DoJointErrorMessage(joints_connecting_actor, "taint: " + pendingJoints.Count + " pending joints"); | ||
2750 | foreach (PhysicsJoint joint in pendingJoints) | ||
2751 | { | ||
2752 | //DoJointErrorMessage(joint, "taint: time to create joint with parms: " + joint.RawParams); | ||
2753 | string[] jointParams = joint.RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); | ||
2754 | List<IntPtr> jointBodies = new List<IntPtr>(); | ||
2755 | bool allJointBodiesAreReady = true; | ||
2756 | foreach (string jointParam in jointParams) | ||
2746 | { | 2757 | { |
2747 | List<PhysicsJoint> successfullyProcessedPendingJoints = new List<PhysicsJoint>(); | 2758 | if (jointParam == "NULL") |
2748 | //DoJointErrorMessage(joints_connecting_actor, "taint: " + pendingJoints.Count + " pending joints"); | ||
2749 | foreach (PhysicsJoint joint in pendingJoints) | ||
2750 | { | 2759 | { |
2751 | //DoJointErrorMessage(joint, "taint: time to create joint with parms: " + joint.RawParams); | 2760 | //DoJointErrorMessage(joint, "attaching NULL joint to world"); |
2752 | string[] jointParams = joint.RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); | 2761 | jointBodies.Add(IntPtr.Zero); |
2753 | List<IntPtr> jointBodies = new List<IntPtr>(); | 2762 | } |
2754 | bool allJointBodiesAreReady = true; | 2763 | else |
2755 | foreach (string jointParam in jointParams) | 2764 | { |
2765 | //DoJointErrorMessage(joint, "looking for prim name: " + jointParam); | ||
2766 | bool foundPrim = false; | ||
2767 | lock (_prims) | ||
2756 | { | 2768 | { |
2757 | if (jointParam == "NULL") | 2769 | foreach (OdePrim prim in _prims) // FIXME: inefficient |
2758 | { | ||
2759 | //DoJointErrorMessage(joint, "attaching NULL joint to world"); | ||
2760 | jointBodies.Add(IntPtr.Zero); | ||
2761 | } | ||
2762 | else | ||
2763 | { | 2770 | { |
2764 | //DoJointErrorMessage(joint, "looking for prim name: " + jointParam); | 2771 | if (prim.SOPName == jointParam) |
2765 | bool foundPrim = false; | ||
2766 | lock (_prims) | ||
2767 | { | 2772 | { |
2768 | foreach (OdePrim prim in _prims) // FIXME: inefficient | 2773 | //DoJointErrorMessage(joint, "found for prim name: " + jointParam); |
2774 | if (prim.IsPhysical && prim.Body != IntPtr.Zero) | ||
2769 | { | 2775 | { |
2770 | if (prim.SOPName == jointParam) | 2776 | jointBodies.Add(prim.Body); |
2771 | { | 2777 | foundPrim = true; |
2772 | //DoJointErrorMessage(joint, "found for prim name: " + jointParam); | 2778 | break; |
2773 | if (prim.IsPhysical && prim.Body != IntPtr.Zero) | 2779 | } |
2774 | { | 2780 | else |
2775 | jointBodies.Add(prim.Body); | 2781 | { |
2776 | foundPrim = true; | 2782 | DoJointErrorMessage(joint, "prim name " + jointParam + |
2777 | break; | 2783 | " exists but is not (yet) physical; deferring joint creation. " + |
2778 | } | 2784 | "IsPhysical property is " + prim.IsPhysical + |
2779 | else | 2785 | " and body is " + prim.Body); |
2780 | { | 2786 | foundPrim = false; |
2781 | DoJointErrorMessage(joint, "prim name " + jointParam + | 2787 | break; |
2782 | " exists but is not (yet) physical; deferring joint creation. " + | ||
2783 | "IsPhysical property is " + prim.IsPhysical + | ||
2784 | " and body is " + prim.Body); | ||
2785 | foundPrim = false; | ||
2786 | break; | ||
2787 | } | ||
2788 | } | ||
2789 | } | 2788 | } |
2790 | } | ||
2791 | if (foundPrim) | ||
2792 | { | ||
2793 | // all is fine | ||
2794 | } | ||
2795 | else | ||
2796 | { | ||
2797 | allJointBodiesAreReady = false; | ||
2798 | break; | ||
2799 | } | 2789 | } |
2800 | } | 2790 | } |
2801 | } | 2791 | } |
2802 | if (allJointBodiesAreReady) | 2792 | if (foundPrim) |
2803 | { | 2793 | { |
2804 | //DoJointErrorMessage(joint, "allJointBodiesAreReady for " + joint.ObjectNameInScene + " with parms " + joint.RawParams); | 2794 | // all is fine |
2805 | if (jointBodies[0] == jointBodies[1]) | ||
2806 | { | ||
2807 | DoJointErrorMessage(joint, "ERROR: joint cannot be created; the joint bodies are the same, body1==body2. Raw body is " + jointBodies[0] + ". raw parms: " + joint.RawParams); | ||
2808 | } | ||
2809 | else | ||
2810 | { | ||
2811 | switch (joint.Type) | ||
2812 | { | ||
2813 | case PhysicsJointType.Ball: | ||
2814 | { | ||
2815 | IntPtr odeJoint; | ||
2816 | //DoJointErrorMessage(joint, "ODE creating ball joint "); | ||
2817 | odeJoint = d.JointCreateBall(world, IntPtr.Zero); | ||
2818 | //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); | ||
2819 | d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); | ||
2820 | //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position); | ||
2821 | d.JointSetBallAnchor(odeJoint, | ||
2822 | joint.Position.X, | ||
2823 | joint.Position.Y, | ||
2824 | joint.Position.Z); | ||
2825 | //DoJointErrorMessage(joint, "ODE joint setting OK"); | ||
2826 | //DoJointErrorMessage(joint, "The ball joint's bodies are here: b0: "); | ||
2827 | //DoJointErrorMessage(joint, "" + (jointBodies[0] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[0]) : "fixed environment")); | ||
2828 | //DoJointErrorMessage(joint, "The ball joint's bodies are here: b1: "); | ||
2829 | //DoJointErrorMessage(joint, "" + (jointBodies[1] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[1]) : "fixed environment")); | ||
2830 | |||
2831 | if (joint is OdePhysicsJoint) | ||
2832 | { | ||
2833 | ((OdePhysicsJoint)joint).jointID = odeJoint; | ||
2834 | } | ||
2835 | else | ||
2836 | { | ||
2837 | DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); | ||
2838 | } | ||
2839 | } | ||
2840 | break; | ||
2841 | case PhysicsJointType.Hinge: | ||
2842 | { | ||
2843 | IntPtr odeJoint; | ||
2844 | //DoJointErrorMessage(joint, "ODE creating hinge joint "); | ||
2845 | odeJoint = d.JointCreateHinge(world, IntPtr.Zero); | ||
2846 | //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); | ||
2847 | d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); | ||
2848 | //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position); | ||
2849 | d.JointSetHingeAnchor(odeJoint, | ||
2850 | joint.Position.X, | ||
2851 | joint.Position.Y, | ||
2852 | joint.Position.Z); | ||
2853 | // We use the orientation of the x-axis of the joint's coordinate frame | ||
2854 | // as the axis for the hinge. | ||
2855 | |||
2856 | // Therefore, we must get the joint's coordinate frame based on the | ||
2857 | // joint.Rotation field, which originates from the orientation of the | ||
2858 | // joint's proxy object in the scene. | ||
2859 | |||
2860 | // The joint's coordinate frame is defined as the transformation matrix | ||
2861 | // that converts a vector from joint-local coordinates into world coordinates. | ||
2862 | // World coordinates are defined as the XYZ coordinate system of the sim, | ||
2863 | // as shown in the top status-bar of the viewer. | ||
2864 | |||
2865 | // Once we have the joint's coordinate frame, we extract its X axis (AtAxis) | ||
2866 | // and use that as the hinge axis. | ||
2867 | |||
2868 | //joint.Rotation.Normalize(); | ||
2869 | Matrix4 proxyFrame = Matrix4.CreateFromQuaternion(joint.Rotation); | ||
2870 | |||
2871 | // Now extract the X axis of the joint's coordinate frame. | ||
2872 | |||
2873 | // Do not try to use proxyFrame.AtAxis or you will become mired in the | ||
2874 | // tar pit of transposed, inverted, and generally messed-up orientations. | ||
2875 | // (In other words, Matrix4.AtAxis() is borked.) | ||
2876 | // Vector3 jointAxis = proxyFrame.AtAxis; <--- this path leadeth to madness | ||
2877 | |||
2878 | // Instead, compute the X axis of the coordinate frame by transforming | ||
2879 | // the (1,0,0) vector. At least that works. | ||
2880 | |||
2881 | //m_log.Debug("PHY: making axis: complete matrix is " + proxyFrame); | ||
2882 | Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame); | ||
2883 | //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis); | ||
2884 | //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis); | ||
2885 | d.JointSetHingeAxis(odeJoint, | ||
2886 | jointAxis.X, | ||
2887 | jointAxis.Y, | ||
2888 | jointAxis.Z); | ||
2889 | //d.JointSetHingeParam(odeJoint, (int)dParam.CFM, 0.1f); | ||
2890 | if (joint is OdePhysicsJoint) | ||
2891 | { | ||
2892 | ((OdePhysicsJoint)joint).jointID = odeJoint; | ||
2893 | } | ||
2894 | else | ||
2895 | { | ||
2896 | DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); | ||
2897 | } | ||
2898 | } | ||
2899 | break; | ||
2900 | } | ||
2901 | successfullyProcessedPendingJoints.Add(joint); | ||
2902 | } | ||
2903 | } | 2795 | } |
2904 | else | 2796 | else |
2905 | { | 2797 | { |
2906 | DoJointErrorMessage(joint, "joint could not yet be created; still pending"); | 2798 | allJointBodiesAreReady = false; |
2799 | break; | ||
2907 | } | 2800 | } |
2908 | } | 2801 | } |
2909 | foreach (PhysicsJoint successfullyProcessedJoint in successfullyProcessedPendingJoints) | 2802 | } |
2803 | if (allJointBodiesAreReady) | ||
2804 | { | ||
2805 | //DoJointErrorMessage(joint, "allJointBodiesAreReady for " + joint.ObjectNameInScene + " with parms " + joint.RawParams); | ||
2806 | if (jointBodies[0] == jointBodies[1]) | ||
2910 | { | 2807 | { |
2911 | //DoJointErrorMessage(successfullyProcessedJoint, "finalizing succesfully procsssed joint " + successfullyProcessedJoint.ObjectNameInScene + " parms " + successfullyProcessedJoint.RawParams); | 2808 | DoJointErrorMessage(joint, "ERROR: joint cannot be created; the joint bodies are the same, body1==body2. Raw body is " + jointBodies[0] + ". raw parms: " + joint.RawParams); |
2912 | //DoJointErrorMessage(successfullyProcessedJoint, "removing from pending"); | 2809 | } |
2913 | InternalRemovePendingJoint(successfullyProcessedJoint); | 2810 | else |
2914 | //DoJointErrorMessage(successfullyProcessedJoint, "adding to active"); | 2811 | { |
2915 | InternalAddActiveJoint(successfullyProcessedJoint); | 2812 | switch (joint.Type) |
2916 | //DoJointErrorMessage(successfullyProcessedJoint, "done"); | 2813 | { |
2814 | case PhysicsJointType.Ball: | ||
2815 | { | ||
2816 | IntPtr odeJoint; | ||
2817 | //DoJointErrorMessage(joint, "ODE creating ball joint "); | ||
2818 | odeJoint = d.JointCreateBall(world, IntPtr.Zero); | ||
2819 | //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); | ||
2820 | d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); | ||
2821 | //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position); | ||
2822 | d.JointSetBallAnchor(odeJoint, | ||
2823 | joint.Position.X, | ||
2824 | joint.Position.Y, | ||
2825 | joint.Position.Z); | ||
2826 | //DoJointErrorMessage(joint, "ODE joint setting OK"); | ||
2827 | //DoJointErrorMessage(joint, "The ball joint's bodies are here: b0: "); | ||
2828 | //DoJointErrorMessage(joint, "" + (jointBodies[0] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[0]) : "fixed environment")); | ||
2829 | //DoJointErrorMessage(joint, "The ball joint's bodies are here: b1: "); | ||
2830 | //DoJointErrorMessage(joint, "" + (jointBodies[1] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[1]) : "fixed environment")); | ||
2831 | |||
2832 | if (joint is OdePhysicsJoint) | ||
2833 | { | ||
2834 | ((OdePhysicsJoint)joint).jointID = odeJoint; | ||
2835 | } | ||
2836 | else | ||
2837 | { | ||
2838 | DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); | ||
2839 | } | ||
2840 | } | ||
2841 | break; | ||
2842 | case PhysicsJointType.Hinge: | ||
2843 | { | ||
2844 | IntPtr odeJoint; | ||
2845 | //DoJointErrorMessage(joint, "ODE creating hinge joint "); | ||
2846 | odeJoint = d.JointCreateHinge(world, IntPtr.Zero); | ||
2847 | //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); | ||
2848 | d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); | ||
2849 | //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position); | ||
2850 | d.JointSetHingeAnchor(odeJoint, | ||
2851 | joint.Position.X, | ||
2852 | joint.Position.Y, | ||
2853 | joint.Position.Z); | ||
2854 | // We use the orientation of the x-axis of the joint's coordinate frame | ||
2855 | // as the axis for the hinge. | ||
2856 | |||
2857 | // Therefore, we must get the joint's coordinate frame based on the | ||
2858 | // joint.Rotation field, which originates from the orientation of the | ||
2859 | // joint's proxy object in the scene. | ||
2860 | |||
2861 | // The joint's coordinate frame is defined as the transformation matrix | ||
2862 | // that converts a vector from joint-local coordinates into world coordinates. | ||
2863 | // World coordinates are defined as the XYZ coordinate system of the sim, | ||
2864 | // as shown in the top status-bar of the viewer. | ||
2865 | |||
2866 | // Once we have the joint's coordinate frame, we extract its X axis (AtAxis) | ||
2867 | // and use that as the hinge axis. | ||
2868 | |||
2869 | //joint.Rotation.Normalize(); | ||
2870 | Matrix4 proxyFrame = Matrix4.CreateFromQuaternion(joint.Rotation); | ||
2871 | |||
2872 | // Now extract the X axis of the joint's coordinate frame. | ||
2873 | |||
2874 | // Do not try to use proxyFrame.AtAxis or you will become mired in the | ||
2875 | // tar pit of transposed, inverted, and generally messed-up orientations. | ||
2876 | // (In other words, Matrix4.AtAxis() is borked.) | ||
2877 | // Vector3 jointAxis = proxyFrame.AtAxis; <--- this path leadeth to madness | ||
2878 | |||
2879 | // Instead, compute the X axis of the coordinate frame by transforming | ||
2880 | // the (1,0,0) vector. At least that works. | ||
2881 | |||
2882 | //m_log.Debug("PHY: making axis: complete matrix is " + proxyFrame); | ||
2883 | Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame); | ||
2884 | //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis); | ||
2885 | //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis); | ||
2886 | d.JointSetHingeAxis(odeJoint, | ||
2887 | jointAxis.X, | ||
2888 | jointAxis.Y, | ||
2889 | jointAxis.Z); | ||
2890 | //d.JointSetHingeParam(odeJoint, (int)dParam.CFM, 0.1f); | ||
2891 | if (joint is OdePhysicsJoint) | ||
2892 | { | ||
2893 | ((OdePhysicsJoint)joint).jointID = odeJoint; | ||
2894 | } | ||
2895 | else | ||
2896 | { | ||
2897 | DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); | ||
2898 | } | ||
2899 | } | ||
2900 | break; | ||
2901 | } | ||
2902 | successfullyProcessedPendingJoints.Add(joint); | ||
2917 | } | 2903 | } |
2918 | } | 2904 | } |
2919 | } | 2905 | else |
2920 | |||
2921 | if (processedtaints) | ||
2922 | //Console.WriteLine("Simulate calls Clear of _taintedPrim list"); | ||
2923 | _taintedPrimH.Clear(); | ||
2924 | _taintedPrimL.Clear(); | ||
2925 | } | ||
2926 | |||
2927 | // Move characters | ||
2928 | lock (_characters) | ||
2929 | { | ||
2930 | List<OdeCharacter> defects = new List<OdeCharacter>(); | ||
2931 | foreach (OdeCharacter actor in _characters) | ||
2932 | { | ||
2933 | if (actor != null) | ||
2934 | actor.Move(timeStep, defects); | ||
2935 | } | ||
2936 | if (0 != defects.Count) | ||
2937 | { | ||
2938 | foreach (OdeCharacter defect in defects) | ||
2939 | { | 2906 | { |
2940 | RemoveCharacter(defect); | 2907 | DoJointErrorMessage(joint, "joint could not yet be created; still pending"); |
2941 | } | 2908 | } |
2942 | } | 2909 | } |
2943 | } | 2910 | foreach (PhysicsJoint successfullyProcessedJoint in successfullyProcessedPendingJoints) |
2944 | |||
2945 | // Move other active objects | ||
2946 | lock (_activeprims) | ||
2947 | { | ||
2948 | foreach (OdePrim prim in _activeprims) | ||
2949 | { | 2911 | { |
2950 | prim.m_collisionscore = 0; | 2912 | //DoJointErrorMessage(successfullyProcessedJoint, "finalizing succesfully procsssed joint " + successfullyProcessedJoint.ObjectNameInScene + " parms " + successfullyProcessedJoint.RawParams); |
2951 | prim.Move(timeStep); | 2913 | //DoJointErrorMessage(successfullyProcessedJoint, "removing from pending"); |
2914 | InternalRemovePendingJoint(successfullyProcessedJoint); | ||
2915 | //DoJointErrorMessage(successfullyProcessedJoint, "adding to active"); | ||
2916 | InternalAddActiveJoint(successfullyProcessedJoint); | ||
2917 | //DoJointErrorMessage(successfullyProcessedJoint, "done"); | ||
2952 | } | 2918 | } |
2953 | } | 2919 | } |
2920 | } | ||
2954 | 2921 | ||
2955 | //if ((framecount % m_randomizeWater) == 0) | 2922 | if (processedtaints) |
2956 | // randomizeWater(waterlevel); | 2923 | //Console.WriteLine("Simulate calls Clear of _taintedPrim list"); |
2924 | _taintedPrimH.Clear(); | ||
2925 | _taintedPrimL.Clear(); | ||
2926 | } | ||
2957 | 2927 | ||
2958 | //int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests(); | 2928 | // Move characters |
2959 | m_rayCastManager.ProcessQueuedRequests(); | 2929 | lock (_characters) |
2930 | { | ||
2931 | List<OdeCharacter> defects = new List<OdeCharacter>(); | ||
2932 | foreach (OdeCharacter actor in _characters) | ||
2933 | { | ||
2934 | if (actor != null) | ||
2935 | actor.Move(timeStep, defects); | ||
2936 | } | ||
2937 | if (0 != defects.Count) | ||
2938 | { | ||
2939 | foreach (OdeCharacter defect in defects) | ||
2940 | { | ||
2941 | RemoveCharacter(defect); | ||
2942 | } | ||
2943 | } | ||
2944 | } | ||
2960 | 2945 | ||
2961 | collision_optimized(timeStep); | 2946 | // Move other active objects |
2947 | lock (_activeprims) | ||
2948 | { | ||
2949 | foreach (OdePrim prim in _activeprims) | ||
2950 | { | ||
2951 | prim.m_collisionscore = 0; | ||
2952 | prim.Move(timeStep); | ||
2953 | } | ||
2954 | } | ||
2962 | 2955 | ||
2963 | lock (_collisionEventPrim) | 2956 | //if ((framecount % m_randomizeWater) == 0) |
2964 | { | 2957 | // randomizeWater(waterlevel); |
2965 | foreach (PhysicsActor obj in _collisionEventPrim) | ||
2966 | { | ||
2967 | if (obj == null) | ||
2968 | continue; | ||
2969 | 2958 | ||
2970 | switch ((ActorTypes)obj.PhysicsActorType) | 2959 | //int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests(); |
2971 | { | 2960 | m_rayCastManager.ProcessQueuedRequests(); |
2972 | case ActorTypes.Agent: | ||
2973 | OdeCharacter cobj = (OdeCharacter)obj; | ||
2974 | cobj.AddCollisionFrameTime(100); | ||
2975 | cobj.SendCollisions(); | ||
2976 | break; | ||
2977 | case ActorTypes.Prim: | ||
2978 | OdePrim pobj = (OdePrim)obj; | ||
2979 | pobj.SendCollisions(); | ||
2980 | break; | ||
2981 | } | ||
2982 | } | ||
2983 | } | ||
2984 | 2961 | ||
2985 | //if (m_global_contactcount > 5) | 2962 | collision_optimized(timeStep); |
2986 | //{ | ||
2987 | // m_log.DebugFormat("[PHYSICS]: Contacts:{0}", m_global_contactcount); | ||
2988 | //} | ||
2989 | 2963 | ||
2990 | m_global_contactcount = 0; | 2964 | lock (_collisionEventPrim) |
2991 | 2965 | { | |
2992 | d.WorldQuickStep(world, ODE_STEPSIZE); | 2966 | foreach (PhysicsActor obj in _collisionEventPrim) |
2993 | d.JointGroupEmpty(contactgroup); | ||
2994 | //ode.dunlock(world); | ||
2995 | } | ||
2996 | catch (Exception e) | ||
2997 | { | 2967 | { |
2998 | m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e); | 2968 | if (obj == null) |
2999 | ode.dunlock(world); | 2969 | continue; |
2970 | |||
2971 | switch ((ActorTypes)obj.PhysicsActorType) | ||
2972 | { | ||
2973 | case ActorTypes.Agent: | ||
2974 | OdeCharacter cobj = (OdeCharacter)obj; | ||
2975 | cobj.AddCollisionFrameTime(100); | ||
2976 | cobj.SendCollisions(); | ||
2977 | break; | ||
2978 | case ActorTypes.Prim: | ||
2979 | OdePrim pobj = (OdePrim)obj; | ||
2980 | pobj.SendCollisions(); | ||
2981 | break; | ||
2982 | } | ||
3000 | } | 2983 | } |
2984 | } | ||
3001 | 2985 | ||
3002 | step_time -= ODE_STEPSIZE; | 2986 | //if (m_global_contactcount > 5) |
3003 | i++; | 2987 | //{ |
2988 | // m_log.DebugFormat("[PHYSICS]: Contacts:{0}", m_global_contactcount); | ||
2989 | //} | ||
2990 | |||
2991 | m_global_contactcount = 0; | ||
2992 | |||
2993 | d.WorldQuickStep(world, ODE_STEPSIZE); | ||
2994 | d.JointGroupEmpty(contactgroup); | ||
2995 | //ode.dunlock(world); | ||
2996 | } | ||
2997 | catch (Exception e) | ||
2998 | { | ||
2999 | m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e); | ||
3000 | ode.dunlock(world); | ||
3001 | } | ||
3002 | |||
3003 | step_time -= ODE_STEPSIZE; | ||
3004 | i++; | ||
3004 | //} | 3005 | //} |
3005 | //else | 3006 | //else |
3006 | //{ | 3007 | //{ |
@@ -3091,8 +3092,10 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); | |||
3091 | fwriter.WriteLine(header); | 3092 | fwriter.WriteLine(header); |
3092 | fwriter.Close(); | 3093 | fwriter.Close(); |
3093 | } | 3094 | } |
3095 | |||
3094 | d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); | 3096 | d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); |
3095 | } | 3097 | } |
3098 | |||
3096 | latertickcount = Util.EnvironmentTickCount() - tickCountFrameRun; | 3099 | latertickcount = Util.EnvironmentTickCount() - tickCountFrameRun; |
3097 | 3100 | ||
3098 | // OpenSimulator above does 10 fps. 10 fps = means that the main thread loop and physics | 3101 | // OpenSimulator above does 10 fps. 10 fps = means that the main thread loop and physics |
@@ -3694,6 +3697,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); | |||
3694 | //d.CloseODE(); | 3697 | //d.CloseODE(); |
3695 | } | 3698 | } |
3696 | } | 3699 | } |
3700 | |||
3697 | public override Dictionary<uint, float> GetTopColliders() | 3701 | public override Dictionary<uint, float> GetTopColliders() |
3698 | { | 3702 | { |
3699 | Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); | 3703 | Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); |