aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
diff options
context:
space:
mode:
authorRobert Adams2012-12-31 16:22:45 -0800
committerRobert Adams2012-12-31 19:57:24 -0800
commit3d0fc708647ceb734385f90e2f22be9774e2171e (patch)
tree07fa083aa3507a16c4e094beb164f9b8312fe0a4 /OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
parentBulletSim: nearly complete in conversion from BulletSimAPI to BSAPITemplate. ... (diff)
downloadopensim-SC_OLD-3d0fc708647ceb734385f90e2f22be9774e2171e.zip
opensim-SC_OLD-3d0fc708647ceb734385f90e2f22be9774e2171e.tar.gz
opensim-SC_OLD-3d0fc708647ceb734385f90e2f22be9774e2171e.tar.bz2
opensim-SC_OLD-3d0fc708647ceb734385f90e2f22be9774e2171e.tar.xz
BulletSim: complete movement of BulletSimAPI functions to BSAPITemplate.
Update BulletSim DLLs and SOs with simplier step function interface.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs217
1 files changed, 158 insertions, 59 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index 6e68053..0355b94 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Reflection;
29using System.Runtime.InteropServices; 30using System.Runtime.InteropServices;
30using System.Security; 31using System.Security;
31using System.Text; 32using System.Text;
@@ -36,31 +37,102 @@ namespace OpenSim.Region.Physics.BulletSPlugin
36{ 37{
37public sealed class BSAPIUnman : BSAPITemplate 38public sealed class BSAPIUnman : BSAPITemplate
38{ 39{
39 /* 40
41// We pin the memory passed between the managed and unmanaged code.
42GCHandle m_paramsHandle;
43private GCHandle m_collisionArrayPinnedHandle;
44private GCHandle m_updateArrayPinnedHandle;
45
46// Handle to the callback used by the unmanaged code to call into the managed code.
47// Used for debug logging.
48// Need to store the handle in a persistant variable so it won't be freed.
49private BSAPICPP.DebugLogCallback m_DebugLogCallbackHandle;
50
51private BSScene PhysicsScene { get; set; }
52
53public override string BulletEngineName { get { return "BulletUnmanaged"; } }
54public override string BulletEngineVersion { get; protected set; }
55
56public BSAPIUnman(string paramName, BSScene physScene)
57{
58 PhysicsScene = physScene;
59 // Do something fancy with the paramName to get the right DLL implementation
60 // like "Bullet-2.80-OpenCL-Intel" loading the version for Intel based OpenCL implementation, etc.
61}
62
40// Initialization and simulation 63// Initialization and simulation
41public BulletWorld Initialize(Vector3 maxPosition, IntPtr parms, 64public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
42 int maxCollisions, IntPtr collisionArray, 65 int maxCollisions, ref CollisionDesc[] collisionArray,
43 int maxUpdates, IntPtr updateArray 66 int maxUpdates, ref EntityProperties[] updateArray
44 ); 67 )
68{
69 // Pin down the memory that will be used to pass object collisions and updates back from unmanaged code
70 m_paramsHandle = GCHandle.Alloc(parms, GCHandleType.Pinned);
71 m_collisionArrayPinnedHandle = GCHandle.Alloc(collisionArray, GCHandleType.Pinned);
72 m_updateArrayPinnedHandle = GCHandle.Alloc(updateArray, GCHandleType.Pinned);
45 73
46public bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); 74 // If Debug logging level, enable logging from the unmanaged code
75 m_DebugLogCallbackHandle = null;
76 if (BSScene.m_log.IsDebugEnabled || PhysicsScene.PhysicsLogging.Enabled)
77 {
78 BSScene.m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", BSScene.LogHeader);
79 if (PhysicsScene.PhysicsLogging.Enabled)
80 // The handle is saved in a variable to make sure it doesn't get freed after this call
81 m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLoggerPhysLog);
82 else
83 m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLogger);
84 }
47 85
48public void SetHeightMap(BulletWorld world, float[] heightmap); 86 // Get the version of the DLL
87 // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
88 // BulletEngineVersion = BulletSimAPI.GetVersion2();
89 BulletEngineVersion = "";
90
91 // Call the unmanaged code with the buffers and other information
92 return new BulletWorld(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(),
93 maxCollisions, m_collisionArrayPinnedHandle.AddrOfPinnedObject(),
94 maxUpdates, m_updateArrayPinnedHandle.AddrOfPinnedObject(),
95 m_DebugLogCallbackHandle));
49 96
50public void Shutdown(BulletWorld sim); 97}
51 98
52public int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, 99// Called directly from unmanaged code so don't do much
53 out int updatedEntityCount, 100private void BulletLogger(string msg)
54 out IntPtr updatedEntitiesPtr, 101{
55 out int collidersCount, 102 BSScene.m_log.Debug("[BULLETS UNMANAGED]:" + msg);
56 out IntPtr collidersPtr); 103}
104
105// Called directly from unmanaged code so don't do much
106private void BulletLoggerPhysLog(string msg)
107{
108 PhysicsScene.DetailLog("[BULLETS UNMANAGED]:" + msg);
109}
110
111 /*
112public void SetHeightMap(BulletWorld world, float[] heightmap);
57 113
58 */ 114 */
115public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
116 out int updatedEntityCount, out int collidersCount)
117{
118 return BSAPICPP.PhysicsStep2(world.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount);
119}
120
121public override void Shutdown(BulletWorld sim)
122{
123 BSAPICPP.Shutdown2(sim.ptr);
124}
125
59public override bool PushUpdate(BulletBody obj) 126public override bool PushUpdate(BulletBody obj)
60{ 127{
61 return BSAPICPP.PushUpdate2(obj.ptr); 128 return BSAPICPP.PushUpdate2(obj.ptr);
62} 129}
63 130
131public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value)
132{
133 return BSAPICPP.UpdateParameter2(world.ptr, localID, parm, value);
134}
135
64// ===================================================================================== 136// =====================================================================================
65// Mesh, hull, shape and body creation helper routines 137// Mesh, hull, shape and body creation helper routines
66public override BulletShape CreateMeshShape(BulletWorld world, 138public override BulletShape CreateMeshShape(BulletWorld world,
@@ -893,11 +965,81 @@ public override float GetMargin(BulletShape shape)
893 return BSAPICPP.GetMargin2(shape.ptr); 965 return BSAPICPP.GetMargin2(shape.ptr);
894} 966}
895 967
968// =====================================================================================
969// Debugging
970public override void DumpRigidBody(BulletWorld sim, BulletBody collisionObject)
971{
972 BSAPICPP.DumpRigidBody2(sim.ptr, collisionObject.ptr);
973}
974
975public override void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape)
976{
977 BSAPICPP.DumpCollisionShape2(sim.ptr, collisionShape.ptr);
978}
979
980public override void DumpMapInfo(BulletWorld sim, BulletHMapInfo mapInfo)
981{
982 BSAPICPP.DumpMapInfo2(sim.ptr, mapInfo.ptr);
983}
984
985public override void DumpConstraint(BulletWorld sim, BulletConstraint constrain)
986{
987 BSAPICPP.DumpConstraint2(sim.ptr, constrain.ptr);
988}
989
990public override void DumpActivationInfo(BulletWorld sim)
991{
992 BSAPICPP.DumpActivationInfo2(sim.ptr);
993}
994
995public override void DumpAllInfo(BulletWorld sim)
996{
997 BSAPICPP.DumpAllInfo2(sim.ptr);
998}
999
1000public override void DumpPhysicsStatistics(BulletWorld sim)
1001{
1002 BSAPICPP.DumpPhysicsStatistics2(sim.ptr);
1003}
1004
1005
1006// =====================================================================================
1007// =====================================================================================
1008// =====================================================================================
1009// =====================================================================================
1010// =====================================================================================
1011// The actual interface to the unmanaged code
896static class BSAPICPP 1012static class BSAPICPP
897{ 1013{
1014// ===============================================================================
1015// Link back to the managed code for outputting log messages
1016[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
1017public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
1018
1019// ===============================================================================
1020// Initialization and simulation
1021[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1022public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
1023 int maxCollisions, IntPtr collisionArray,
1024 int maxUpdates, IntPtr updateArray,
1025 DebugLogCallback logRoutine);
1026
1027[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1028public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
1029
1030[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1031public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
1032 out int updatedEntityCount, out int collidersCount);
1033
1034[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1035public static extern void Shutdown2(IntPtr sim);
1036
898[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 1037[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
899public static extern bool PushUpdate2(IntPtr obj); 1038public static extern bool PushUpdate2(IntPtr obj);
900 1039
1040[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1041public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
1042
901// ===================================================================================== 1043// =====================================================================================
902// Mesh, hull, shape and body creation helper routines 1044// Mesh, hull, shape and body creation helper routines
903[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 1045[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -1431,52 +1573,6 @@ public static extern void SetMargin2(IntPtr shape, float val);
1431[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 1573[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1432public static extern float GetMargin2(IntPtr shape); 1574public static extern float GetMargin2(IntPtr shape);
1433 1575
1434}
1435}
1436
1437// ===============================================================================
1438// ===============================================================================
1439// ===============================================================================
1440// ===============================================================================
1441// ===============================================================================
1442// ===============================================================================
1443// ===============================================================================
1444// ===============================================================================
1445// ===============================================================================
1446// ===============================================================================
1447// ===============================================================================
1448// ===============================================================================
1449// ===============================================================================
1450static class BulletSimAPI {
1451// ===============================================================================
1452// Link back to the managed code for outputting log messages
1453[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
1454public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
1455
1456// ===============================================================================
1457// Initialization and simulation
1458[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1459public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
1460 int maxCollisions, IntPtr collisionArray,
1461 int maxUpdates, IntPtr updateArray,
1462 DebugLogCallback logRoutine);
1463
1464[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1465public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
1466
1467[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1468public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
1469
1470[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1471public static extern void Shutdown2(IntPtr sim);
1472
1473[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1474public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
1475 out int updatedEntityCount,
1476 out IntPtr updatedEntitiesPtr,
1477 out int collidersCount,
1478 out IntPtr collidersPtr);
1479
1480// ===================================================================================== 1576// =====================================================================================
1481// Debugging 1577// Debugging
1482[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 1578[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -1501,4 +1597,7 @@ public static extern void DumpAllInfo2(IntPtr sim);
1501public static extern void DumpPhysicsStatistics2(IntPtr sim); 1597public static extern void DumpPhysicsStatistics2(IntPtr sim);
1502 1598
1503} 1599}
1600
1601}
1602
1504} 1603}