/// <summary> /// Links a C++ object to its C# wrapper. /// </summary> /// <param name='cppObj'> /// Pointer to the CppObject to register. /// </param> /// <param name='handle'> /// Handle of the C# object. /// </param> public static void registerWrapper(IntPtr cppObj, uint handle) { Console.WriteLine("[C#] NativeManagement.registerWrapper BEGIN"); GameObject gameObject = WrapperReg.getInstance().getObjectFromHandle(handle); if (cppObj != IntPtr.Zero) { // C# and C++ classes must have the same typeID to be bound //Console.WriteLine("[C#] NativeManagement.registerWrapper - native typeID : 0x" + NativeManagement.getTypeID(cppObj).ToString("X") + " - C# typeID : 0x" + gameObject.TypeID.ToString("X")); if (NativeManagement.getTypeID(cppObj) == gameObject.TypeID) { //Console.WriteLine("[C#] Register Wrapper : handle = " + handle); CKLBObjectScriptable_setScriptContext(cppObj, handle); } else { throw new CKLBException("C# object and C++ object don't have the same typeID, impossible to bind them."); } // Debug //uint handleResult = GameObject_getHandle(cppObj); //Console.WriteLine("Result : " + handleResult); } else { throw new CKLBExceptionNullCppObject(); } Console.WriteLine("[C#] NativeManagement.registerWrapper END"); }
/// <summary> /// Game object constructor /// It registers the typeID given in argument. /// </summary> /// <param name="typeID">typeID of the C# object.</param> public GameObject(uint typeID) { //Console.WriteLine("[C#] GameObject cctor BEGIN."); m_typeID = typeID; WrapperReg.getInstance().registerGameObject(this); m_cppObject = IntPtr.Zero; //Console.WriteLine("[C#] GameObject cctor END."); }
/// <summary> /// Destroys the C# object designated by handle. /// It can be called from C++. /// </summary> /// <param name='handle'> /// Handle of the C# object to destroy. /// </param> public static void destroyFromNative(uint handle) { GameObject obj = WrapperReg.getInstance().getObjectFromHandle(handle); if (obj != null) { WrapperReg.getInstance().unregisterGameObject(obj); obj.CppObject = IntPtr.Zero; obj.Dispose(); } }
public static void doCallBackFS(uint cbInfos, float float_1, IntPtr intptr_1) { uint callbackIndex = (cbInfos & 0xE0000000) >> 29; uint handle = cbInfos & 0x1FFFFFFF; GameObject obj = WrapperReg.getInstance().getObjectFromHandle(handle); if (0 <= callbackIndex && callbackIndex < GameObject.NBCALLBACKS) { FunctionPointerFS cb = (FunctionPointerFS)obj.getCallBack(callbackIndex); cb(float_1, intptr_1); } else { throw new CKLBException("Invalid index, it must be between 0 and " + (GameObject.NBCALLBACKS - 1) + "."); } }
public static bool doCallBackIIIP_retB(uint cbInfos, int int_1, int int_2, int int_3, IntPtr obj_1) { uint callbackIndex = (cbInfos & 0xE0000000) >> 29; uint handle = cbInfos & 0x1FFFFFFF; GameObject obj = WrapperReg.getInstance().getObjectFromHandle(handle); if (0 <= callbackIndex && callbackIndex < GameObject.NBCALLBACKS) { FunctionPointerIIIP_retB cb = (FunctionPointerIIIP_retB)obj.getCallBack(callbackIndex); return(cb(int_1, int_2, int_3, obj_1)); } else { throw new CKLBException("Invalid index, it must be between 0 and " + (GameObject.NBCALLBACKS - 1) + "."); } }
/// <summary> /// Dispose is called by the programmer to "free" the object. /// C# object instance stays alive but all internal data and ressources are freed. /// </summary> public virtual void Dispose() // Inherited classes with unmanaged resources have to dispose them first. { //Console.WriteLine("[C#] " + this + " is disposing."); Console.WriteLine("[C#] GameObject.Dispose BEGIN"); clearInternals(); if (m_handle != NULLHANDLER) { WrapperReg.getInstance().unregisterGameObject(this); } if (CppObject != IntPtr.Zero) { unbind(); } Console.WriteLine("[C#] GameObject.Dispose END"); }
/// <summary> /// Static equivalent of setDelegate /// </summary> /// <param name='handle'> /// handle of the object. Used to get the C# object associated. /// </param> /// <param name='anyDelegate'> /// Object got from a delegate /// </param> /// <param name='delegateName'> /// String designing the delegate name (if the class has only 1 delegate, it has a default value) /// </param> public static void staticSetDelegate(uint handle, Delegate delegatePtr, String delegateName) { WrapperReg.getInstance().getObjectFromHandle(handle).setDelegate(delegatePtr, delegateName); }