BulletSim: Use base class constructors for initialization of BSShape and other classes.
parent
22be36be69
commit
6c961d8add
|
@ -47,7 +47,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
|
||||||
*/
|
*/
|
||||||
public abstract class BSPhysObject : PhysicsActor
|
public abstract class BSPhysObject : PhysicsActor
|
||||||
{
|
{
|
||||||
protected void BaseInitialize(BSScene parentScene, uint localID, string name, string typeName)
|
protected BSPhysObject()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName)
|
||||||
{
|
{
|
||||||
PhysicsScene = parentScene;
|
PhysicsScene = parentScene;
|
||||||
LocalID = localID;
|
LocalID = localID;
|
||||||
|
|
|
@ -88,9 +88,9 @@ public sealed class BSPrim : BSPhysObject
|
||||||
|
|
||||||
public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
|
public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
|
||||||
OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
|
OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
|
||||||
|
: base(parent_scene, localID, primName, "BSPrim")
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
|
// m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
|
||||||
base.BaseInitialize(parent_scene, localID, primName, "BSPrim");
|
|
||||||
_physicsActorType = (int)ActorTypes.Prim;
|
_physicsActorType = (int)ActorTypes.Prim;
|
||||||
_position = pos;
|
_position = pos;
|
||||||
_size = size;
|
_size = size;
|
||||||
|
|
|
@ -683,7 +683,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
|
||||||
#region Taints
|
#region Taints
|
||||||
|
|
||||||
// Calls to the PhysicsActors can't directly call into the physics engine
|
// Calls to the PhysicsActors can't directly call into the physics engine
|
||||||
// because it might be busy. We delay changes to a known time.
|
// because it might be busy. We delay changes to a known time.
|
||||||
// We rely on C#'s closure to save and restore the context for the delegate.
|
// We rely on C#'s closure to save and restore the context for the delegate.
|
||||||
public void TaintedObject(String ident, TaintCallback callback)
|
public void TaintedObject(String ident, TaintCallback callback)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,213 +1,208 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Contributors, http://opensimulator.org/
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyrightD
|
* * Redistributions in binary form must reproduce the above copyrightD
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* * Neither the name of the OpenSimulator Project nor the
|
* * Neither the name of the OpenSimulator Project nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* 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
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace OpenSim.Region.Physics.BulletSPlugin
|
namespace OpenSim.Region.Physics.BulletSPlugin
|
||||||
{
|
{
|
||||||
public abstract class BSShape
|
public abstract class BSShape
|
||||||
{
|
{
|
||||||
public IntPtr ptr { get; set; }
|
public IntPtr ptr { get; set; }
|
||||||
public ShapeData.PhysicsShapeType type { get; set; }
|
public ShapeData.PhysicsShapeType type { get; set; }
|
||||||
public System.UInt64 key { get; set; }
|
public System.UInt64 key { get; set; }
|
||||||
public int referenceCount { get; set; }
|
public int referenceCount { get; set; }
|
||||||
public DateTime lastReferenced { get; set; }
|
public DateTime lastReferenced { get; set; }
|
||||||
|
|
||||||
protected void Initialize()
|
public BSShape()
|
||||||
{
|
{
|
||||||
ptr = IntPtr.Zero;
|
ptr = IntPtr.Zero;
|
||||||
type = ShapeData.PhysicsShapeType.SHAPE_UNKNOWN;
|
type = ShapeData.PhysicsShapeType.SHAPE_UNKNOWN;
|
||||||
key = 0;
|
key = 0;
|
||||||
referenceCount = 0;
|
referenceCount = 0;
|
||||||
lastReferenced = DateTime.Now;
|
lastReferenced = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a reference to a physical shape. Create if it doesn't exist
|
// Get a reference to a physical shape. Create if it doesn't exist
|
||||||
public static BSShape GetShapeReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
|
public static BSShape GetShapeReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
|
||||||
{
|
{
|
||||||
BSShape ret = null;
|
BSShape ret = null;
|
||||||
|
|
||||||
if (prim.PreferredPhysicalShape == ShapeData.PhysicsShapeType.SHAPE_AVATAR)
|
if (prim.PreferredPhysicalShape == ShapeData.PhysicsShapeType.SHAPE_AVATAR)
|
||||||
{
|
{
|
||||||
// an avatar capsule is close to a native shape (it is not shared)
|
// an avatar capsule is close to a native shape (it is not shared)
|
||||||
ret = BSShapeNative.GetReference(physicsScene, prim, ShapeData.PhysicsShapeType.SHAPE_AVATAR,
|
ret = BSShapeNative.GetReference(physicsScene, prim, ShapeData.PhysicsShapeType.SHAPE_AVATAR,
|
||||||
ShapeData.FixedShapeKey.KEY_CAPSULE);
|
ShapeData.FixedShapeKey.KEY_CAPSULE);
|
||||||
physicsScene.DetailLog("{0},BSShape.GetShapeReference,avatarCapsule,shape={1}", prim.LocalID, ret);
|
physicsScene.DetailLog("{0},BSShape.GetShapeReference,avatarCapsule,shape={1}", prim.LocalID, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compound shapes are handled special as they are rebuilt from scratch.
|
// Compound shapes are handled special as they are rebuilt from scratch.
|
||||||
// This isn't too great a hardship since most of the child shapes will already been created.
|
// This isn't too great a hardship since most of the child shapes will already been created.
|
||||||
if (ret == null && prim.PreferredPhysicalShape == ShapeData.PhysicsShapeType.SHAPE_COMPOUND)
|
if (ret == null && prim.PreferredPhysicalShape == ShapeData.PhysicsShapeType.SHAPE_COMPOUND)
|
||||||
{
|
{
|
||||||
// Getting a reference to a compound shape gets you the compound shape with the root prim shape added
|
// Getting a reference to a compound shape gets you the compound shape with the root prim shape added
|
||||||
ret = BSShapeCompound.GetReference(prim);
|
ret = BSShapeCompound.GetReference(prim);
|
||||||
physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, ret);
|
physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
ret = GetShapeReferenceNonSpecial(physicsScene, forceRebuild, prim);
|
ret = GetShapeReferenceNonSpecial(physicsScene, forceRebuild, prim);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
public static BSShape GetShapeReferenceNonSpecial(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
|
public static BSShape GetShapeReferenceNonSpecial(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public static BSShape GetShapeReferenceNonNative(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
|
public static BSShape GetShapeReferenceNonNative(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release the use of a physical shape.
|
// Release the use of a physical shape.
|
||||||
public abstract void Dereference(BSScene physicsScene);
|
public abstract void Dereference(BSScene physicsScene);
|
||||||
|
|
||||||
// All shapes have a static call to get a reference to the physical shape
|
// All shapes have a static call to get a reference to the physical shape
|
||||||
// protected abstract static BSShape GetReference();
|
// protected abstract static BSShape GetReference();
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
StringBuilder buff = new StringBuilder();
|
StringBuilder buff = new StringBuilder();
|
||||||
buff.Append("<p=");
|
buff.Append("<p=");
|
||||||
buff.Append(ptr.ToString("X"));
|
buff.Append(ptr.ToString("X"));
|
||||||
buff.Append(",s=");
|
buff.Append(",s=");
|
||||||
buff.Append(type.ToString());
|
buff.Append(type.ToString());
|
||||||
buff.Append(",k=");
|
buff.Append(",k=");
|
||||||
buff.Append(key.ToString("X"));
|
buff.Append(key.ToString("X"));
|
||||||
buff.Append(",c=");
|
buff.Append(",c=");
|
||||||
buff.Append(referenceCount.ToString());
|
buff.Append(referenceCount.ToString());
|
||||||
buff.Append(">");
|
buff.Append(">");
|
||||||
return buff.ToString();
|
return buff.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BSShapeNull : BSShape
|
public class BSShapeNull : BSShape
|
||||||
{
|
{
|
||||||
public BSShapeNull()
|
public BSShapeNull() : base()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
}
|
||||||
}
|
public static BSShape GetReference() { return new BSShapeNull(); }
|
||||||
public static BSShape GetReference() { return new BSShapeNull(); }
|
public override void Dereference(BSScene physicsScene) { /* The magic of garbage collection will make this go away */ }
|
||||||
public override void Dereference(BSScene physicsScene) { /* The magic of garbage collection will make this go away */ }
|
}
|
||||||
}
|
|
||||||
|
public class BSShapeNative : BSShape
|
||||||
public class BSShapeNative : BSShape
|
{
|
||||||
{
|
private static string LogHeader = "[BULLETSIM SHAPE NATIVE]";
|
||||||
private static string LogHeader = "[BULLETSIM SHAPE NATIVE]";
|
public BSShapeNative() : base()
|
||||||
public BSShapeNative()
|
{
|
||||||
{
|
}
|
||||||
base.Initialize();
|
public static BSShape GetReference(BSScene physicsScene, BSPhysObject prim,
|
||||||
}
|
ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey)
|
||||||
public static BSShape GetReference(BSScene physicsScene, BSPhysObject prim,
|
{
|
||||||
ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey)
|
// Native shapes are not shared and are always built anew.
|
||||||
{
|
return new BSShapeNative(physicsScene, prim, shapeType, shapeKey);
|
||||||
// Native shapes are not shared and are always built anew.
|
}
|
||||||
return new BSShapeNative(physicsScene, prim, shapeType, shapeKey);
|
|
||||||
}
|
private BSShapeNative(BSScene physicsScene, BSPhysObject prim,
|
||||||
|
ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey)
|
||||||
private BSShapeNative(BSScene physicsScene, BSPhysObject prim,
|
{
|
||||||
ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey)
|
ShapeData nativeShapeData = new ShapeData();
|
||||||
{
|
nativeShapeData.Type = shapeType;
|
||||||
ShapeData nativeShapeData = new ShapeData();
|
nativeShapeData.ID = prim.LocalID;
|
||||||
nativeShapeData.Type = shapeType;
|
nativeShapeData.Scale = prim.Scale;
|
||||||
nativeShapeData.ID = prim.LocalID;
|
nativeShapeData.Size = prim.Scale;
|
||||||
nativeShapeData.Scale = prim.Scale;
|
nativeShapeData.MeshKey = (ulong)shapeKey;
|
||||||
nativeShapeData.Size = prim.Scale;
|
nativeShapeData.HullKey = (ulong)shapeKey;
|
||||||
nativeShapeData.MeshKey = (ulong)shapeKey;
|
|
||||||
nativeShapeData.HullKey = (ulong)shapeKey;
|
|
||||||
|
if (shapeType == ShapeData.PhysicsShapeType.SHAPE_AVATAR)
|
||||||
|
{
|
||||||
if (shapeType == ShapeData.PhysicsShapeType.SHAPE_AVATAR)
|
ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale);
|
||||||
{
|
physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
|
||||||
ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale);
|
}
|
||||||
physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
|
else
|
||||||
}
|
{
|
||||||
else
|
ptr = BulletSimAPI.BuildNativeShape2(physicsScene.World.ptr, nativeShapeData);
|
||||||
{
|
}
|
||||||
ptr = BulletSimAPI.BuildNativeShape2(physicsScene.World.ptr, nativeShapeData);
|
if (ptr == IntPtr.Zero)
|
||||||
}
|
{
|
||||||
if (ptr == IntPtr.Zero)
|
physicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}",
|
||||||
{
|
LogHeader, prim.LocalID, shapeType);
|
||||||
physicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}",
|
}
|
||||||
LogHeader, prim.LocalID, shapeType);
|
type = shapeType;
|
||||||
}
|
key = (UInt64)shapeKey;
|
||||||
type = shapeType;
|
}
|
||||||
key = (UInt64)shapeKey;
|
// Make this reference to the physical shape go away since native shapes are not shared.
|
||||||
}
|
public override void Dereference(BSScene physicsScene)
|
||||||
// Make this reference to the physical shape go away since native shapes are not shared.
|
{
|
||||||
public override void Dereference(BSScene physicsScene)
|
// Native shapes are not tracked and are released immediately
|
||||||
{
|
physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this);
|
||||||
// Native shapes are not tracked and are released immediately
|
BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr);
|
||||||
physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this);
|
ptr = IntPtr.Zero;
|
||||||
BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr);
|
// Garbage collection will free up this instance.
|
||||||
ptr = IntPtr.Zero;
|
}
|
||||||
// Garbage collection will free up this instance.
|
}
|
||||||
}
|
|
||||||
}
|
public class BSShapeMesh : BSShape
|
||||||
|
{
|
||||||
public class BSShapeMesh : BSShape
|
private static string LogHeader = "[BULLETSIM SHAPE MESH]";
|
||||||
{
|
private static Dictionary<System.UInt64, BSShapeMesh> Meshes = new Dictionary<System.UInt64, BSShapeMesh>();
|
||||||
private static string LogHeader = "[BULLETSIM SHAPE MESH]";
|
|
||||||
private static Dictionary<System.UInt64, BSShapeMesh> Meshes = new Dictionary<System.UInt64, BSShapeMesh>();
|
public BSShapeMesh() : base()
|
||||||
|
{
|
||||||
public BSShapeMesh()
|
}
|
||||||
{
|
public static BSShape GetReference() { return new BSShapeNull(); }
|
||||||
base.Initialize();
|
public override void Dereference(BSScene physicsScene) { }
|
||||||
}
|
}
|
||||||
public static BSShape GetReference() { return new BSShapeNull(); }
|
|
||||||
public override void Dereference(BSScene physicsScene) { }
|
public class BSShapeHull : BSShape
|
||||||
}
|
{
|
||||||
|
private static string LogHeader = "[BULLETSIM SHAPE HULL]";
|
||||||
public class BSShapeHull : BSShape
|
private static Dictionary<System.UInt64, BSShapeHull> Hulls = new Dictionary<System.UInt64, BSShapeHull>();
|
||||||
{
|
|
||||||
private static string LogHeader = "[BULLETSIM SHAPE HULL]";
|
public BSShapeHull() : base()
|
||||||
private static Dictionary<System.UInt64, BSShapeHull> Hulls = new Dictionary<System.UInt64, BSShapeHull>();
|
{
|
||||||
|
}
|
||||||
public BSShapeHull()
|
public static BSShape GetReference() { return new BSShapeNull(); }
|
||||||
{
|
public override void Dereference(BSScene physicsScene) { }
|
||||||
base.Initialize();
|
}
|
||||||
}
|
|
||||||
public static BSShape GetReference() { return new BSShapeNull(); }
|
public class BSShapeCompound : BSShape
|
||||||
public override void Dereference(BSScene physicsScene) { }
|
{
|
||||||
}
|
private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]";
|
||||||
|
public BSShapeCompound() : base()
|
||||||
public class BSShapeCompound : BSShape
|
{
|
||||||
{
|
}
|
||||||
private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]";
|
public static BSShape GetReference(BSPhysObject prim)
|
||||||
public BSShapeCompound()
|
{
|
||||||
{
|
return new BSShapeNull();
|
||||||
base.Initialize();
|
}
|
||||||
}
|
public override void Dereference(BSScene physicsScene) { }
|
||||||
public static BSShape GetReference(BSPhysObject prim)
|
}
|
||||||
{
|
}
|
||||||
return new BSShapeNull();
|
|
||||||
}
|
|
||||||
public override void Dereference(BSScene physicsScene) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue