static private void initSubsystems() { registerSubsystem(NativeCore.WrapNative <Player> (csb_ClockworkEngine_GetSubsystem("Player"))); registerSubsystem(NativeCore.WrapNative <Graphics> (csb_ClockworkEngine_GetSubsystem("Graphics"))); registerSubsystem(NativeCore.WrapNative <Renderer> (csb_ClockworkEngine_GetSubsystem("Renderer"))); registerSubsystem(NativeCore.WrapNative <ResourceCache> (csb_ClockworkEngine_GetSubsystem("ResourceCache"))); }
public static bool RunFrame() { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); NativeCore.ReleaseExpiredNativeReferences(); return(clockworksharp_runframe()); }
public T Get <T>(string key) where T : RefCounted { checkValid(); // TODO: safe case IntPtr r = csb_Clockwork_VariantMap_GetInstance(native, key); return(r == IntPtr.Zero ? null : NativeCore.WrapNative <T> (r)); }
// This will need to be optimized public static void CSComponentApplyFields(IntPtr componentPtr, IntPtr fieldMapPtr) { NETVariantMap fieldMap = NativeCore.WrapNative <NETVariantMap>(fieldMapPtr);; CSComponent component = NativeCore.WrapNative <CSComponent>(componentPtr);; if (fieldMap == null || component == null) { return; } FieldInfo[] fields = componentClassFields[component.GetType()]; foreach (var field in fields) { if (fieldMap.Contains(field.Name)) { //Console.WriteLine("Applying: {0} {1}", field.Name, field.FieldType.Name); var fieldType = field.FieldType; if (fieldType.IsEnum) { field.SetValue(component, fieldMap.GetInt(field.Name)); continue; } switch (Type.GetTypeCode(fieldType)) { case TypeCode.Boolean: field.SetValue(component, fieldMap.GetBool(field.Name)); break; case TypeCode.Int32: field.SetValue(component, fieldMap.GetInt(field.Name)); break; case TypeCode.Single: field.SetValue(component, fieldMap.GetFloat(field.Name)); break; case TypeCode.String: field.SetValue(component, fieldMap.GetString(field.Name)); break; default: if (fieldType == typeof(Vector3)) { field.SetValue(component, fieldMap.GetVector3(field.Name)); } else if (fieldType == typeof(Quaternion)) { field.SetValue(component, fieldMap.GetQuaternion(field.Name)); } else if (fieldType.IsSubclassOf(typeof(Resource))) { field.SetValue(component, fieldMap.GetResourceFromRef(field.Name)); } else if (fieldType.IsSubclassOf(typeof(RefCounted))) { field.SetValue(component, fieldMap.GetPtr(field.Name)); } break; } } } }
public ScriptObject() { nativeInstance = NativeCore.RegisterNative(csb_Clockwork_CSScriptObject_Constructor(), this); }