Permalink
Browse files

BulletSim: Changes to terrain storage and management so mega-regions …

…work.

Moved all terrain code out of BSScene and into new BSTerrainManager.
Added logic to manage multiple terrains for mega-regions.
Added new functions to BulletSimAPI to match the library.
Moved all of the terrain creation and setup logic from C++ code to C# code.
    The unused code has not yet been removed from either place. Soon.
Moved checks for avatar above ground and in bounds into BSCharacter.
  • Loading branch information...
1 parent 7b6987c commit 7c140570db3b01eb83efc0d42a47715d3047e376 @radams1 radams1 committed Aug 26, 2012
@@ -226,16 +226,37 @@ private bool PositionSanityCheck()
bool ret = false;
// If below the ground, move the avatar up
- float terrainHeight = Scene.GetTerrainHeightAtXYZ(_position);
- if (_position.Z < terrainHeight)
+ float terrainHeight = Scene.TerrainManager.GetTerrainHeightAtXYZ(_position);
+ if (Position.Z < terrainHeight)
{
- DetailLog("{0},BSCharacter.PositionAdjustUnderGround,call,pos={1},orient={2}", LocalID, _position, _orientation);
- _position.Z = terrainHeight + 2.0f;
+ DetailLog("{0},BSCharacter.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight);
+ Vector3 newPos = _position;
+ newPos.Z = terrainHeight + 2.0f;
+ _position = newPos;
ret = true;
}
// TODO: check for out of bounds
+ return ret;
+ }
+ // A version of the sanity check that also makes sure a new position value is
+ // pushed back to the physics engine. This routine would be used by anyone
+ // who is not already pushing the value.
+ private bool PositionSanityCheck2()
+ {
+ bool ret = false;
+ if (PositionSanityCheck())
+ {
+ // The new position value must be pushed into the physics engine but we can't
+ // just assign to "Position" because of potential call loops.
+ _scene.TaintedObject("BSCharacter.PositionSanityCheck", delegate()
+ {
+ DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
+ BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
+ });
+ ret = true;
+ }
return ret;
}
@@ -500,9 +521,13 @@ public override void UpdateProperties(EntityProperties entprop)
// Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop.
// base.RequestPhysicsterseUpdate();
- DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
+ // Do some sanity checking for the avatar. Make sure it's above ground and inbounds.
+ PositionSanityCheck2();
+
+ float heightHere = Scene.TerrainManager.GetTerrainHeightAtXYZ(_position); // just for debug
+ DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}",
LocalID, entprop.Position, entprop.Rotation, entprop.Velocity,
- entprop.Acceleration, entprop.RotationalVelocity);
+ entprop.Acceleration, entprop.RotationalVelocity, heightHere);
}
// Called by the scene when a collision with this object is reported
@@ -48,11 +48,10 @@ public virtual void Dispose()
{
if (m_enabled)
{
- // BulletSimAPI.RemoveConstraint(m_world.ID, m_body1.ID, m_body2.ID);
+ m_enabled = false;
bool success = BulletSimAPI.DestroyConstraint2(m_world.Ptr, m_constraint.Ptr);
m_world.scene.DetailLog("{0},BSConstraint.Dispose,taint,body1={1},body2={2},success={3}", BSScene.DetailLogZero, m_body1.ID, m_body2.ID, success);
m_constraint.Ptr = System.IntPtr.Zero;
- m_enabled = false;
}
}
@@ -465,6 +465,7 @@ internal void ProcessTypeChange(Vehicle pType, float stepSize)
}
}//end SetDefaultsForType
+ // One step of the vehicle properties for the next 'pTimestep' seconds.
internal void Step(float pTimestep)
{
if (m_type == Vehicle.TYPE_NONE) return;
@@ -592,9 +593,9 @@ private void MoveLinear(float pTimestep)
}
// If below the terrain, move us above the ground a little.
- if (pos.Z < m_prim.Scene.GetTerrainHeightAtXYZ(pos))
+ if (pos.Z < m_prim.Scene.TerrainManager.GetTerrainHeightAtXYZ(pos))
{
- pos.Z = m_prim.Scene.GetTerrainHeightAtXYZ(pos) + 2;
+ pos.Z = m_prim.Scene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 2;
m_prim.Position = pos;
VDetailLog("{0},MoveLinear,terrainHeight,pos={1}", m_prim.LocalID, pos);
}
@@ -609,7 +610,7 @@ private void MoveLinear(float pTimestep)
}
if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0)
{
- m_VhoverTargetHeight = m_prim.Scene.GetTerrainHeightAtXY(pos.X, pos.Y) + m_VhoverHeight;
+ m_VhoverTargetHeight = m_prim.Scene.TerrainManager.GetTerrainHeightAtXY(pos.X, pos.Y) + m_VhoverHeight;
}
if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) != 0)
{
@@ -673,7 +674,7 @@ private void MoveLinear(float pTimestep)
{
grav.Z = (float)(grav.Z * 1.125);
}
- float terraintemp = m_prim.Scene.GetTerrainHeightAtXYZ(pos);
+ float terraintemp = m_prim.Scene.TerrainManager.GetTerrainHeightAtXYZ(pos);
float postemp = (pos.Z - terraintemp);
if (postemp > 2.5f)
{
@@ -1,58 +1,60 @@
-/*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyrightD
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-using OMV = OpenMetaverse;
-using OpenSim.Framework;
-using OpenSim.Region.Physics.Manager;
-
-namespace OpenSim.Region.Physics.BulletSPlugin
-{
-// Class to wrap all objects.
-// The rest of BulletSim doesn't need to keep checking for avatars or prims
-// unless the difference is significant.
-public abstract class BSPhysObject : PhysicsActor
-{
- public abstract BSLinkset Linkset { get; set; }
-
- public abstract void Collide(uint collidingWith, BSPhysObject collidee, ActorTypes type,
- OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth);
- public abstract void SendCollisions();
-
- // Return the object mass without calculating it or side effects
- public abstract float MassRaw { get; }
-
- public abstract BulletBody Body { get; set; }
- public abstract void ZeroMotion();
-
- public abstract void UpdateProperties(EntityProperties entprop);
-
- public abstract void Destroy();
-}
-}
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OMV = OpenMetaverse;
+using OpenSim.Framework;
+using OpenSim.Region.Physics.Manager;
+
+namespace OpenSim.Region.Physics.BulletSPlugin
+{
+// Class to wrap all objects.
+// The rest of BulletSim doesn't need to keep checking for avatars or prims
+// unless the difference is significant.
+public abstract class BSPhysObject : PhysicsActor
+{
+ public abstract BSLinkset Linkset { get; set; }
+
+ public abstract void Collide(uint collidingWith, BSPhysObject collidee, ActorTypes type,
+ OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth);
+ public abstract void SendCollisions();
+
+ // Return the object mass without calculating it or side effects
+ public abstract float MassRaw { get; }
+
+ public abstract BulletBody Body { get; set; }
+ public abstract void ZeroMotion();
+
+ public virtual void StepVehicle(float timeStep) { }
+
+ public abstract void UpdateProperties(EntityProperties entprop);
+
+ public abstract void Destroy();
+}
+}
@@ -377,7 +377,7 @@ public override void VehicleFlags(int param, bool remove)
// Called each simulation step to advance vehicle characteristics.
// Called from Scene when doing simulation step so we're in taint processing time.
- public void StepVehicle(float timeStep)
+ public override void StepVehicle(float timeStep)
{
if (IsPhysical)
_vehicle.Step(timeStep);
Oops, something went wrong. Retry.

0 comments on commit 7c14057

Please sign in to comment.