Ogre Version: 14.3.4
Operating System: Win 10
Render System: DX11
Hey everyone!
In my journey to use Ogre in C# with SWIG bindings, I'm facing some problems. Until now, I was able to make some quick and dirty changes in the .i files so that SWIG generates the correct bindings. But now I have a big problem: C++ supports multiple inheritance, but C# doesn't. The class I'm trying to use is ParticleSystem, and this class inherits from both StringInterface and MovableObject. By default, SWIG takes the first base class—in this case, StringInterface—and uses it normally, but the second base class is ignored. The problem is, I need ParticleSystem to be a MovableObject; otherwise, I won't be able to attach it to a SceneNode and use it in my scene.
The solution that Mogre used was to transform StringInterface into an interface and use it in C# together with MovableObject.
Code: Select all
public interface IStringInterface
{
unsafe static implicit operator IStringInterface(Ogre.StringInterface* t)
{
//IL_003f: Expected I, but got I8
//IL_0060: Expected I, but got I8
//IL_0075: Expected I, but got I8
if (0L == (nint)t)
{
return null;
}
CLRObject* ptr = (CLRObject*)global::_003CModule_003E.__RTDynamicCast(t, 0, System.Runtime.CompilerServices.Unsafe.AsPointer(ref global::_003CModule_003E._003F_003F_R0_003FAVStringInterface_0040Ogre_0040_0040_00408), System.Runtime.CompilerServices.Unsafe.AsPointer(ref global::_003CModule_003E._003F_003F_R0_003FAVCLRObject_0040_0040_00408), 0);
if (0L == (nint)ptr)
{
throw new System.Exception("The native class that implements Ogre::StringInterface isn't a subclass of CLRObject. Cannot create the CLR wrapper object.");
}
ulong num = *(ulong*)((ulong)(nint)ptr + 8uL);
object obj;
if (num == 0L)
{
obj = null;
}
else
{
IntPtr intPtr = new IntPtr((void*)num);
obj = ((GCHandle)intPtr).Target;
}
if (null == obj)
{
((delegate* unmanaged[Cdecl, Cdecl]<IntPtr, void>)(*(ulong*)(*(long*)ptr + 8)))((nint)ptr);
num = *(ulong*)((ulong)(nint)ptr + 8uL);
if (num == 0L)
{
obj = null;
}
else
{
IntPtr intPtr2 = new IntPtr((void*)num);
obj = ((GCHandle)intPtr2).Target;
}
}
return (IStringInterface)obj;
}
unsafe static implicit operator Ogre.StringInterface*(IStringInterface t)
{
//IL_000e: Expected I, but got I8
//IL_000d->IL000d: Incompatible stack types: I vs I8
return (Ogre.StringInterface*)((t == null) ? 0 : ((nint)t._GetNativePtr()));
}
unsafe Ogre.StringInterface* _GetNativePtr();
[return: MarshalAs(UnmanagedType.U1)]
bool SetParameter(string name, string value);
void SetParameterList(Const_NameValuePairList paramList);
string GetParameter(string name);
void CopyParametersTo(IStringInterface dest);
}
I don't have much knowledge of SWIG, and I'm running out of solutions. Can anyone help?