a few changes to ubode managed/umanaged interface

This commit is contained in:
UbitUmarov
2022-08-08 23:34:29 +01:00
parent 1b928c9fbd
commit 0f052f775d
4 changed files with 65 additions and 55 deletions

View File

@@ -192,14 +192,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int AABBTestFn(IntPtr o1, IntPtr o2, ref AABB aabb);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int ColliderFn(IntPtr o1, IntPtr o2, int flags, out ContactGeom contact, int skip);
//[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
//internal delegate int ColliderFn(IntPtr o1, IntPtr o2, int flags, out ContactGeom contact, int skip);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GetAABBFn(IntPtr geom, out AABB aabb);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate ColliderFn GetColliderFnFn(int num);
//[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
//internal delegate ColliderFn GetColliderFnFn(int num);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void GeomDtorFn(IntPtr o);
@@ -246,6 +246,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
[StructLayout(LayoutKind.Sequential)]
//needed for Contact only, rest should use the class
internal struct ContactGeom
{
@@ -259,6 +260,21 @@ namespace OpenSim.Region.PhysicsModule.ubOde
internal static readonly int unmanagedSizeOf = Marshal.SizeOf(typeof(ContactGeom));
}
[StructLayout(LayoutKind.Sequential)]
internal class ContactGeomClass
{
internal Vector3 pos;
internal Vector3 normal;
internal dReal depth;
internal IntPtr g1;
internal IntPtr g2;
internal int side1;
internal int side2;
internal static readonly int unmanagedSizeOf = Marshal.SizeOf(typeof(ContactGeomClass));
}
/*
[StructLayout(LayoutKind.Sequential)]
internal struct GeomClass
{
@@ -268,7 +284,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
internal AABBTestFn aabb_test;
internal GeomDtorFn dtor;
}
*/
[StructLayout(LayoutKind.Sequential)]
internal struct JointFeedback
@@ -744,8 +760,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
[DllImport("ubode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCloseODE"), SuppressUnmanagedCodeSecurity]
internal static extern void CloseODE();
[DllImport("ubode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCollide"), SuppressUnmanagedCodeSecurity]
internal static extern int Collide(IntPtr o1, IntPtr o2, int flags, [In, Out] ContactGeom[] contact, int skip);
[DllImport("ubode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCollide"), SuppressUnmanagedCodeSecurity]
internal static extern int CollidePtr(IntPtr o1, IntPtr o2, int flags, IntPtr contactgeomarray, int skip);
@@ -808,8 +822,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
return CreateiGeom(classnum);
}
[DllImport("ubode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeomClass"), SuppressUnmanagedCodeSecurity]
internal static extern int CreateGeomClass(ref GeomClass classptr);
//[DllImport("ubode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeomClass"), SuppressUnmanagedCodeSecurity]
//internal static extern int CreateGeomClass(ref GeomClass classptr);
[DllImport("ubode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dCreateGeomTransform"), SuppressUnmanagedCodeSecurity]
internal static extern IntPtr CreateGeomTransform(IntPtr space);

View File

@@ -1014,8 +1014,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
y = tx * sin + y * cos;
}
internal bool Collide(IntPtr me, IntPtr other, bool reverse, ref SafeNativeMethods.ContactGeom contact,
ref SafeNativeMethods.ContactGeom altContact, ref bool useAltcontact, ref bool feetcollision)
internal bool Collide(IntPtr me, IntPtr other, bool reverse, ref SafeNativeMethods.ContactGeomClass contact,
ref SafeNativeMethods.ContactGeomClass altContact, ref bool useAltcontact, ref bool feetcollision)
{
feetcollision = false;
useAltcontact = false;
@@ -1094,7 +1094,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
IsColliding = true;
}
altContact = contact;
useAltcontact = true;
offset.Z -= 0.2f;
@@ -1115,6 +1114,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
if (tdp > 0.25f)
tdp = 0.25f;
altContact.pos = contact.pos;
//altContact.g1 = contact.g1;
//altContact.g2 = contact.g2;
//altContact.side1 = contact.side1;
//altContact.side2 = contact.side2;
altContact.depth = tdp;
if (reverse)

View File

@@ -472,14 +472,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
}
}
private bool GetCurContactGeom(int index, ref SafeNativeMethods.ContactGeom newcontactgeom)
private bool GetCurContactGeom(int index, ref SafeNativeMethods.ContactGeomClass newcontactgeom)
{
IntPtr ContactgeomsArray = m_scene.ContactgeomsArray;
if (ContactgeomsArray == IntPtr.Zero || index >= CollisionContactGeomsPerTest)
return false;
IntPtr contactptr = new IntPtr(ContactgeomsArray.ToInt64() + (Int64)(index * SafeNativeMethods.ContactGeom.unmanagedSizeOf));
newcontactgeom = (SafeNativeMethods.ContactGeom)Marshal.PtrToStructure(contactptr, typeof(SafeNativeMethods.ContactGeom));
IntPtr contactptr = new IntPtr(ContactgeomsArray.ToInt64() + (Int64)(index * SafeNativeMethods.ContactGeomClass.unmanagedSizeOf));
Marshal.PtrToStructure(contactptr, newcontactgeom);
return true;
}
@@ -508,7 +508,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
int count = 0;
try
{
count = SafeNativeMethods.CollidePtr(g1, g2, CollisionContactGeomsPerTest, m_scene.ContactgeomsArray, SafeNativeMethods.ContactGeom.unmanagedSizeOf);
count = SafeNativeMethods.CollidePtr(g1, g2, CollisionContactGeomsPerTest, m_scene.ContactgeomsArray, SafeNativeMethods.ContactGeomClass.unmanagedSizeOf);
}
catch (Exception e)
{
@@ -580,7 +580,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
break;
}
SafeNativeMethods.ContactGeom curcontact = new SafeNativeMethods.ContactGeom();
SafeNativeMethods.ContactGeomClass curcontact = new SafeNativeMethods.ContactGeomClass();
// closestHit for now only works for meshs, so must do it for others
if ((CurrentRayFilter & RayFilterFlags.ClosestHit) == 0)

View File

@@ -375,15 +375,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
}
catch
{
// i must RtC#FM
// i did!
}
// move to second level
SafeNativeMethods.SpaceSetSublevel(ActiveSpace, 1);
SafeNativeMethods.SpaceSetSublevel(CharsSpace, 1);
SafeNativeMethods.SpaceSetSublevel(StaticSpace, 1);
SafeNativeMethods.SpaceSetSublevel(GroundSpace, 1);
// move to high level
SafeNativeMethods.SpaceSetSublevel(ActiveSpace, 256);
SafeNativeMethods.SpaceSetSublevel(CharsSpace, 256);
SafeNativeMethods.SpaceSetSublevel(StaticSpace, 256);
SafeNativeMethods.SpaceSetSublevel(GroundSpace, 256);
SafeNativeMethods.GeomSetCategoryBits(ActiveSpace, (uint)(CollisionCategories.Space |
CollisionCategories.Geom |
@@ -407,8 +405,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
SafeNativeMethods.GeomSetCategoryBits(StaticSpace, (uint)(CollisionCategories.Space |
CollisionCategories.Geom |
// CollisionCategories.Land |
// CollisionCategories.Water |
//CollisionCategories.Land |
//CollisionCategories.Water |
CollisionCategories.Phantom |
CollisionCategories.VolumeDtc
));
@@ -424,7 +422,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
}
// checkThread();
//checkThread();
// Defaults
@@ -442,7 +440,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
gravityy = physicsconfig.GetFloat("world_gravityy", gravityy);
gravityz = physicsconfig.GetFloat("world_gravityz", gravityz);
// contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer);
//contactsurfacelayer = physicsconfig.GetFloat("world_contact_surface_layer", contactsurfacelayer);
ODE_STEPSIZE = physicsconfig.GetFloat("world_stepsize", ODE_STEPSIZE);
@@ -485,7 +483,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
HalfOdeStep = ODE_STEPSIZE * 0.5f;
odetimestepMS = (int)(1000.0f * ODE_STEPSIZE + 0.5f);
ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * SafeNativeMethods.ContactGeom.unmanagedSizeOf);
ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * SafeNativeMethods.ContactGeomClass.unmanagedSizeOf);
GlobalContactsArray = Marshal.AllocHGlobal((maxContactsbeforedeath + 100) * SafeNativeMethods.Contact.unmanagedSizeOf);
SharedTmpcontact.geom.g1 = IntPtr.Zero;
@@ -546,7 +544,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
#region Collision Detection
// sets a global contact for a joint for contactgeom , and base contact description)
private IntPtr CreateContacJoint(ref SafeNativeMethods.ContactGeom contactGeom,bool smooth)
private IntPtr CreateContacJoint(ref SafeNativeMethods.ContactGeomClass contactGeom,bool smooth)
{
if (m_global_contactcount >= maxContactsbeforedeath)
return IntPtr.Zero;
@@ -560,17 +558,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
SharedTmpcontact.geom.normal = contactGeom.normal;
IntPtr contact = new IntPtr(GlobalContactsArray.ToInt64() + (Int64)(m_global_contactcount * SafeNativeMethods.Contact.unmanagedSizeOf));
Marshal.StructureToPtr(SharedTmpcontact, contact, true);
Marshal.StructureToPtr(SharedTmpcontact, contact, false);
return SafeNativeMethods.JointCreateContactPtr(world, contactgroup, contact);
}
private bool GetCurContactGeom(int index, ref SafeNativeMethods.ContactGeom newcontactgeom)
private bool GetCurContactGeom(int index, ref SafeNativeMethods.ContactGeomClass newcontactgeom)
{
if (ContactgeomsArray == IntPtr.Zero || index >= contactsPerCollision)
return false;
IntPtr contactptr = new IntPtr(ContactgeomsArray.ToInt64() + (Int64)(index * SafeNativeMethods.ContactGeom.unmanagedSizeOf));
newcontactgeom = (SafeNativeMethods.ContactGeom)Marshal.PtrToStructure(contactptr, typeof(SafeNativeMethods.ContactGeom));
IntPtr contactptr = new IntPtr(ContactgeomsArray.ToInt64() + (Int64)(index * SafeNativeMethods.ContactGeomClass.unmanagedSizeOf));
Marshal.PtrToStructure(contactptr, newcontactgeom);
return true;
}
@@ -585,13 +583,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
private void near(IntPtr space, IntPtr g1, IntPtr g2)
{
// no lock here! It's invoked from within Simulate(), which is thread-locked
if (m_global_contactcount >= maxContactsbeforedeath)
return;
// Test if we're colliding a geom with a space.
// If so we have to drill down into the space recursively
if (g1 == IntPtr.Zero || g2 == IntPtr.Zero)
return;
@@ -607,34 +603,30 @@ namespace OpenSim.Region.PhysicsModule.ubOde
catch (AccessViolationException)
{
m_log.Warn("[PHYSICS]: Unable to collide test a space");
return;
}
//here one should check collisions of geoms inside a space
// but on each space we only should have geoms that not colide amoung each other
// so we don't dig inside spaces
return;
}
if (g1 == g2)
return; // Can't collide with yourself
// Figure out how many contact points we have
int count = 0;
try
{
if (g1 == g2)
return; // Can't collide with yourself
if (SafeNativeMethods.GeomGetCategoryBits(g1) == (uint)CollisionCategories.VolumeDtc ||
SafeNativeMethods.GeomGetCategoryBits(g2) == (uint)CollisionCategories.VolumeDtc)
{
int cflags = unchecked ((int)(1 | SafeNativeMethods.CONTACTS_UNIMPORTANT));
count = SafeNativeMethods.CollidePtr(g1, g2, cflags, ContactgeomsArray, SafeNativeMethods.ContactGeom.unmanagedSizeOf);
count = SafeNativeMethods.CollidePtr(g1, g2, cflags, ContactgeomsArray, SafeNativeMethods.ContactGeomClass.unmanagedSizeOf);
}
else
count = SafeNativeMethods.CollidePtr(g1, g2, contactsPerCollision, ContactgeomsArray, SafeNativeMethods.ContactGeom.unmanagedSizeOf);
count = SafeNativeMethods.CollidePtr(g1, g2, contactsPerCollision, ContactgeomsArray, SafeNativeMethods.ContactGeomClass.unmanagedSizeOf);
}
catch (SEHException)
{
m_log.Error("[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim.");
// ode.drelease(world);
//ode.drelease(world);
base.TriggerPhysicsBasedRestart();
}
catch (Exception e)
@@ -647,26 +639,25 @@ namespace OpenSim.Region.PhysicsModule.ubOde
if (count == 0)
return;
// get first contact
SafeNativeMethods.ContactGeom curContact = new SafeNativeMethods.ContactGeom();
if (!GetCurContactGeom(0, ref curContact))
return;
// try get physical actors
PhysicsActor p1;
if (!actor_name_map.TryGetValue(g1, out p1))
if (!actor_name_map.TryGetValue(g1, out PhysicsActor p1))
{
m_log.WarnFormat("[PHYSICS]: failed actor mapping for geom 1");
return;
}
PhysicsActor p2;
if (!actor_name_map.TryGetValue(g2, out p2))
if (!actor_name_map.TryGetValue(g2, out PhysicsActor p2))
{
m_log.WarnFormat("[PHYSICS]: failed actor mapping for geom 2");
return;
}
// get first contact
SafeNativeMethods.ContactGeomClass curContact = new SafeNativeMethods.ContactGeomClass();
if (!GetCurContactGeom(0, ref curContact))
return;
// do volume detection case
if ((p1.IsVolumeDtc || p2.IsVolumeDtc))
{
@@ -807,7 +798,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
SharedTmpcontact.surface.mu = mu;
SharedTmpcontact.surface.bounce = bounce;
SafeNativeMethods.ContactGeom altContact = new SafeNativeMethods.ContactGeom();
SafeNativeMethods.ContactGeomClass altContact = new SafeNativeMethods.ContactGeomClass();
bool useAltcontact;
bool noskip;