aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorRobert Adams2012-11-18 22:58:36 -0800
committerRobert Adams2012-11-18 22:58:36 -0800
commit6c961d8addf5c6aad81165042e684e45429b3b21 (patch)
tree57142277399f50a0a44b4e7ab7eeaf9fc54f7004 /OpenSim/Region
parentBulletSim: fix the problem with flying being disabled when crossing region bo... (diff)
downloadopensim-SC_OLD-6c961d8addf5c6aad81165042e684e45429b3b21.zip
opensim-SC_OLD-6c961d8addf5c6aad81165042e684e45429b3b21.tar.gz
opensim-SC_OLD-6c961d8addf5c6aad81165042e684e45429b3b21.tar.bz2
opensim-SC_OLD-6c961d8addf5c6aad81165042e684e45429b3b21.tar.xz
BulletSim: Use base class constructors for initialization of BSShape and other classes.
Diffstat (limited to 'OpenSim/Region')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs5
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs2
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs2
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapes.cs421
4 files changed, 214 insertions, 216 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index e803072..991e5b1 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -47,7 +47,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
47 */ 47 */
48public abstract class BSPhysObject : PhysicsActor 48public abstract class BSPhysObject : PhysicsActor
49{ 49{
50 protected void BaseInitialize(BSScene parentScene, uint localID, string name, string typeName) 50 protected BSPhysObject()
51 {
52 }
53 protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName)
51 { 54 {
52 PhysicsScene = parentScene; 55 PhysicsScene = parentScene;
53 LocalID = localID; 56 LocalID = localID;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 14eb505..500c84a 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -88,9 +88,9 @@ public sealed class BSPrim : BSPhysObject
88 88
89 public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, 89 public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
90 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) 90 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
91 : base(parent_scene, localID, primName, "BSPrim")
91 { 92 {
92 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); 93 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
93 base.BaseInitialize(parent_scene, localID, primName, "BSPrim");
94 _physicsActorType = (int)ActorTypes.Prim; 94 _physicsActorType = (int)ActorTypes.Prim;
95 _position = pos; 95 _position = pos;
96 _size = size; 96 _size = size;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 1cc607a..2fee95e 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -683,7 +683,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
683 #region Taints 683 #region Taints
684 684
685 // Calls to the PhysicsActors can't directly call into the physics engine 685 // Calls to the PhysicsActors can't directly call into the physics engine
686 // because it might be busy. We delay changes to a known time. 686 // because it might be busy. We delay changes to a known time.
687 // We rely on C#'s closure to save and restore the context for the delegate. 687 // We rely on C#'s closure to save and restore the context for the delegate.
688 public void TaintedObject(String ident, TaintCallback callback) 688 public void TaintedObject(String ident, TaintCallback callback)
689 { 689 {
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index 5e2c4a8..d59a486 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -1,213 +1,208 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD 9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Linq; 30using System.Linq;
31using System.Text; 31using System.Text;
32 32
33namespace OpenSim.Region.Physics.BulletSPlugin 33namespace OpenSim.Region.Physics.BulletSPlugin
34{ 34{
35public abstract class BSShape 35public abstract class BSShape
36{ 36{
37 public IntPtr ptr { get; set; } 37 public IntPtr ptr { get; set; }
38 public ShapeData.PhysicsShapeType type { get; set; } 38 public ShapeData.PhysicsShapeType type { get; set; }
39 public System.UInt64 key { get; set; } 39 public System.UInt64 key { get; set; }
40 public int referenceCount { get; set; } 40 public int referenceCount { get; set; }
41 public DateTime lastReferenced { get; set; } 41 public DateTime lastReferenced { get; set; }
42 42
43 protected void Initialize() 43 public BSShape()
44 { 44 {
45 ptr = IntPtr.Zero; 45 ptr = IntPtr.Zero;
46 type = ShapeData.PhysicsShapeType.SHAPE_UNKNOWN; 46 type = ShapeData.PhysicsShapeType.SHAPE_UNKNOWN;
47 key = 0; 47 key = 0;
48 referenceCount = 0; 48 referenceCount = 0;
49 lastReferenced = DateTime.Now; 49 lastReferenced = DateTime.Now;
50 } 50 }
51 51
52 // Get a reference to a physical shape. Create if it doesn't exist 52 // Get a reference to a physical shape. Create if it doesn't exist
53 public static BSShape GetShapeReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) 53 public static BSShape GetShapeReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
54 { 54 {
55 BSShape ret = null; 55 BSShape ret = null;
56 56
57 if (prim.PreferredPhysicalShape == ShapeData.PhysicsShapeType.SHAPE_AVATAR) 57 if (prim.PreferredPhysicalShape == ShapeData.PhysicsShapeType.SHAPE_AVATAR)
58 { 58 {
59 // an avatar capsule is close to a native shape (it is not shared) 59 // an avatar capsule is close to a native shape (it is not shared)
60 ret = BSShapeNative.GetReference(physicsScene, prim, ShapeData.PhysicsShapeType.SHAPE_AVATAR, 60 ret = BSShapeNative.GetReference(physicsScene, prim, ShapeData.PhysicsShapeType.SHAPE_AVATAR,
61 ShapeData.FixedShapeKey.KEY_CAPSULE); 61 ShapeData.FixedShapeKey.KEY_CAPSULE);
62 physicsScene.DetailLog("{0},BSShape.GetShapeReference,avatarCapsule,shape={1}", prim.LocalID, ret); 62 physicsScene.DetailLog("{0},BSShape.GetShapeReference,avatarCapsule,shape={1}", prim.LocalID, ret);
63 } 63 }
64 64
65 // Compound shapes are handled special as they are rebuilt from scratch. 65 // Compound shapes are handled special as they are rebuilt from scratch.
66 // This isn't too great a hardship since most of the child shapes will already been created. 66 // This isn't too great a hardship since most of the child shapes will already been created.
67 if (ret == null && prim.PreferredPhysicalShape == ShapeData.PhysicsShapeType.SHAPE_COMPOUND) 67 if (ret == null && prim.PreferredPhysicalShape == ShapeData.PhysicsShapeType.SHAPE_COMPOUND)
68 { 68 {
69 // Getting a reference to a compound shape gets you the compound shape with the root prim shape added 69 // Getting a reference to a compound shape gets you the compound shape with the root prim shape added
70 ret = BSShapeCompound.GetReference(prim); 70 ret = BSShapeCompound.GetReference(prim);
71 physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, ret); 71 physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, ret);
72 } 72 }
73 73
74 if (ret == null) 74 if (ret == null)
75 ret = GetShapeReferenceNonSpecial(physicsScene, forceRebuild, prim); 75 ret = GetShapeReferenceNonSpecial(physicsScene, forceRebuild, prim);
76 76
77 return ret; 77 return ret;
78 } 78 }
79 public static BSShape GetShapeReferenceNonSpecial(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) 79 public static BSShape GetShapeReferenceNonSpecial(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
80 { 80 {
81 return null; 81 return null;
82 } 82 }
83 public static BSShape GetShapeReferenceNonNative(BSScene physicsScene, bool forceRebuild, BSPhysObject prim) 83 public static BSShape GetShapeReferenceNonNative(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
84 { 84 {
85 return null; 85 return null;
86 } 86 }
87 87
88 // Release the use of a physical shape. 88 // Release the use of a physical shape.
89 public abstract void Dereference(BSScene physicsScene); 89 public abstract void Dereference(BSScene physicsScene);
90 90
91 // All shapes have a static call to get a reference to the physical shape 91 // All shapes have a static call to get a reference to the physical shape
92 // protected abstract static BSShape GetReference(); 92 // protected abstract static BSShape GetReference();
93 93
94 public override string ToString() 94 public override string ToString()
95 { 95 {
96 StringBuilder buff = new StringBuilder(); 96 StringBuilder buff = new StringBuilder();
97 buff.Append("<p="); 97 buff.Append("<p=");
98 buff.Append(ptr.ToString("X")); 98 buff.Append(ptr.ToString("X"));
99 buff.Append(",s="); 99 buff.Append(",s=");
100 buff.Append(type.ToString()); 100 buff.Append(type.ToString());
101 buff.Append(",k="); 101 buff.Append(",k=");
102 buff.Append(key.ToString("X")); 102 buff.Append(key.ToString("X"));
103 buff.Append(",c="); 103 buff.Append(",c=");
104 buff.Append(referenceCount.ToString()); 104 buff.Append(referenceCount.ToString());
105 buff.Append(">"); 105 buff.Append(">");
106 return buff.ToString(); 106 return buff.ToString();
107 } 107 }
108} 108}
109 109
110public class BSShapeNull : BSShape 110public class BSShapeNull : BSShape
111{ 111{
112 public BSShapeNull() 112 public BSShapeNull() : base()
113 { 113 {
114 base.Initialize(); 114 }
115 } 115 public static BSShape GetReference() { return new BSShapeNull(); }
116 public static BSShape GetReference() { return new BSShapeNull(); } 116 public override void Dereference(BSScene physicsScene) { /* The magic of garbage collection will make this go away */ }
117 public override void Dereference(BSScene physicsScene) { /* The magic of garbage collection will make this go away */ } 117}
118} 118
119 119public class BSShapeNative : BSShape
120public class BSShapeNative : BSShape 120{
121{ 121 private static string LogHeader = "[BULLETSIM SHAPE NATIVE]";
122 private static string LogHeader = "[BULLETSIM SHAPE NATIVE]"; 122 public BSShapeNative() : base()
123 public BSShapeNative() 123 {
124 { 124 }
125 base.Initialize(); 125 public static BSShape GetReference(BSScene physicsScene, BSPhysObject prim,
126 } 126 ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey)
127 public static BSShape GetReference(BSScene physicsScene, BSPhysObject prim, 127 {
128 ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey) 128 // Native shapes are not shared and are always built anew.
129 { 129 return new BSShapeNative(physicsScene, prim, shapeType, shapeKey);
130 // Native shapes are not shared and are always built anew. 130 }
131 return new BSShapeNative(physicsScene, prim, shapeType, shapeKey); 131
132 } 132 private BSShapeNative(BSScene physicsScene, BSPhysObject prim,
133 133 ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey)
134 private BSShapeNative(BSScene physicsScene, BSPhysObject prim, 134 {
135 ShapeData.PhysicsShapeType shapeType, ShapeData.FixedShapeKey shapeKey) 135 ShapeData nativeShapeData = new ShapeData();
136 { 136 nativeShapeData.Type = shapeType;
137 ShapeData nativeShapeData = new ShapeData(); 137 nativeShapeData.ID = prim.LocalID;
138 nativeShapeData.Type = shapeType; 138 nativeShapeData.Scale = prim.Scale;
139 nativeShapeData.ID = prim.LocalID; 139 nativeShapeData.Size = prim.Scale;
140 nativeShapeData.Scale = prim.Scale; 140 nativeShapeData.MeshKey = (ulong)shapeKey;
141 nativeShapeData.Size = prim.Scale; 141 nativeShapeData.HullKey = (ulong)shapeKey;
142 nativeShapeData.MeshKey = (ulong)shapeKey; 142
143 nativeShapeData.HullKey = (ulong)shapeKey; 143
144 144 if (shapeType == ShapeData.PhysicsShapeType.SHAPE_AVATAR)
145 145 {
146 if (shapeType == ShapeData.PhysicsShapeType.SHAPE_AVATAR) 146 ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale);
147 { 147 physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
148 ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale); 148 }
149 physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); 149 else
150 } 150 {
151 else 151 ptr = BulletSimAPI.BuildNativeShape2(physicsScene.World.ptr, nativeShapeData);
152 { 152 }
153 ptr = BulletSimAPI.BuildNativeShape2(physicsScene.World.ptr, nativeShapeData); 153 if (ptr == IntPtr.Zero)
154 } 154 {
155 if (ptr == IntPtr.Zero) 155 physicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}",
156 { 156 LogHeader, prim.LocalID, shapeType);
157 physicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}", 157 }
158 LogHeader, prim.LocalID, shapeType); 158 type = shapeType;
159 } 159 key = (UInt64)shapeKey;
160 type = shapeType; 160 }
161 key = (UInt64)shapeKey; 161 // Make this reference to the physical shape go away since native shapes are not shared.
162 } 162 public override void Dereference(BSScene physicsScene)
163 // Make this reference to the physical shape go away since native shapes are not shared. 163 {
164 public override void Dereference(BSScene physicsScene) 164 // Native shapes are not tracked and are released immediately
165 { 165 physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this);
166 // Native shapes are not tracked and are released immediately 166 BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr);
167 physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this); 167 ptr = IntPtr.Zero;
168 BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr); 168 // Garbage collection will free up this instance.
169 ptr = IntPtr.Zero; 169 }
170 // Garbage collection will free up this instance. 170}
171 } 171
172} 172public class BSShapeMesh : BSShape
173 173{
174public class BSShapeMesh : BSShape 174 private static string LogHeader = "[BULLETSIM SHAPE MESH]";
175{ 175 private static Dictionary<System.UInt64, BSShapeMesh> Meshes = new Dictionary<System.UInt64, BSShapeMesh>();
176 private static string LogHeader = "[BULLETSIM SHAPE MESH]"; 176
177 private static Dictionary<System.UInt64, BSShapeMesh> Meshes = new Dictionary<System.UInt64, BSShapeMesh>(); 177 public BSShapeMesh() : base()
178 178 {
179 public BSShapeMesh() 179 }
180 { 180 public static BSShape GetReference() { return new BSShapeNull(); }
181 base.Initialize(); 181 public override void Dereference(BSScene physicsScene) { }
182 } 182}
183 public static BSShape GetReference() { return new BSShapeNull(); } 183
184 public override void Dereference(BSScene physicsScene) { } 184public class BSShapeHull : BSShape
185} 185{
186 186 private static string LogHeader = "[BULLETSIM SHAPE HULL]";
187public class BSShapeHull : BSShape 187 private static Dictionary<System.UInt64, BSShapeHull> Hulls = new Dictionary<System.UInt64, BSShapeHull>();
188{ 188
189 private static string LogHeader = "[BULLETSIM SHAPE HULL]"; 189 public BSShapeHull() : base()
190 private static Dictionary<System.UInt64, BSShapeHull> Hulls = new Dictionary<System.UInt64, BSShapeHull>(); 190 {
191 191 }
192 public BSShapeHull() 192 public static BSShape GetReference() { return new BSShapeNull(); }
193 { 193 public override void Dereference(BSScene physicsScene) { }
194 base.Initialize(); 194}
195 } 195
196 public static BSShape GetReference() { return new BSShapeNull(); } 196public class BSShapeCompound : BSShape
197 public override void Dereference(BSScene physicsScene) { } 197{
198} 198 private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]";
199 199 public BSShapeCompound() : base()
200public class BSShapeCompound : BSShape 200 {
201{ 201 }
202 private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]"; 202 public static BSShape GetReference(BSPhysObject prim)
203 public BSShapeCompound() 203 {
204 { 204 return new BSShapeNull();
205 base.Initialize(); 205 }
206 } 206 public override void Dereference(BSScene physicsScene) { }
207 public static BSShape GetReference(BSPhysObject prim) 207}
208 { 208}
209 return new BSShapeNull();
210 }
211 public override void Dereference(BSScene physicsScene) { }
212}
213}