Example #1
0
        public void ApplyFieldValues(CSComponent component, IntPtr fieldValuePtr)
        {
            // FIXME: This will need to be optimized, specifically to use uint key hashes for value lookup

            fieldMap.CopyVariantMap(fieldValuePtr);

            foreach (var field in InspectorFields)
            {
                if (fieldMap.Contains(field.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;
                    }
                }
            }
        }
Example #2
0
        void AddCSComponent(CSComponent csc)
        {
            CSComponentInfo info;

            if (!CSComponentCore.csinfoLookup.TryGetValue(csc.GetType(), out info))
            {
                Log.Error("Scene.HandleComponentAdded - unable to get CSComponentInfo");
                return;
            }

            List <CSComponent> cslist;

            if (!cscomponents.TryGetValue(info, out cslist))
            {
                cslist = cscomponents[info] = new List <CSComponent>();
            }

            if (cslist.Contains(csc))
            {
                throw new InvalidOperationException("Scene.HandleComponentAdded - CSComponent already added to component list");
            }

            cslist.Add(csc);

            if (!csc.started)
            {
                if (cscomponentStart.Contains(csc))
                {
                    throw new InvalidOperationException("Scene.HandleComponentAdded CSComponent already added to start list");
                }


                cscomponentStart.Add(csc);
            }
        }
Example #3
0
        public void RegisterInstance(CSComponent component)
        {
            Instances.Add(component);

            if (StartMethod != null)
            {
                StartList.Add(component);
            }
        }
Example #4
0
        void HandleCSComponentLoad(CSComponentLoadEvent e)
        {
            var scriptMap = e.scriptMap;

            // Get the NativeInstance as an IntPtr, otherwise we would be wrapping as a CSComponent
            IntPtr csnative = scriptMap.GetVoidPtr("NativeInstance");

            IntPtr fieldValues = IntPtr.Zero;

            if (scriptMap.Contains("FieldValues"))
            {
                fieldValues = scriptMap.GetVoidPtr("FieldValues");
            }

            CSComponentInfo csinfo;

            if (!CSComponentCore.componentCache.TryGetValue(e.ClassName, out csinfo))
            {
                Log.Error("Scene.HandleCSComponentLoad - unable to find CSComponent in cache for classname: " + e.ClassName);
                return;
            }

            var component = CSComponent.LoadCreateInstance(csinfo.Type, csnative);

            if (component == null)
            {
                Log.Error("Scene.HandleCSComponentLoad - unable to create CSComponent for classname: " + e.ClassName);
                return;
            }

            if (fieldValues != IntPtr.Zero)
            {
                csinfo.ApplyFieldValues(component, fieldValues);
            }

            AddCSComponent(component);
        }
Example #5
0
 public static void RegisterInstance(CSComponent component)
 {
     instance.csinfoLookup[component.GetType()].RegisterInstance(component);
 }
        public void ApplyFieldValues(CSComponent component, IntPtr fieldValuePtr)
        {
#if ATOMIC_DESKTOP || ATOMIC_MOBILE
            fieldMap.CopyVariantMap(fieldValuePtr);

            foreach (var field in InspectorFields)
            {
                if (fieldMap.Contains(field.Name))
                {
                    var fieldType = field.FieldType;

                    if (fieldType.IsEnum)
                    {
                        field.SetValue(component, fieldMap.GetInt(field.Name));
                        continue;
                    }

                    if (!fieldType.IsArray)
                    {
                        SetFieldValue(component, field);
                    }
                    else
                    {
                        fieldMap.GetVariantVector(field.Name, arrayMarshal);

                        var   elementType = fieldType.GetElementType();
                        uint  sz          = arrayMarshal.Size;
                        Array array       = Array.CreateInstance(elementType, sz);

                        var typeCode = Type.GetTypeCode(elementType);

                        for (uint i = 0; i < sz; i++)
                        {
                            var variant = arrayMarshal[i];

                            // FIXME: This will need to be optimized, specifically to use uint key hashes for value lookup
                            switch (typeCode)
                            {
                            case TypeCode.Boolean:
                                array.SetValue((bool)variant.GetBool(), i);
                                break;

                            case TypeCode.Int32:
                                array.SetValue(variant.GetInt(), i);
                                break;

                            case TypeCode.UInt32:
                                array.SetValue(variant.GetUInt(), i);
                                break;

                            case TypeCode.Single:
                                array.SetValue(variant.GetFloat(), i);
                                break;

                            case TypeCode.String:
                                array.SetValue(variant.GetString(), i);
                                break;

                            default:

                                if (elementType == typeof(Vector3))
                                {
                                    array.SetValue(variant.GetVector3(), i);
                                }
                                else if (elementType == typeof(Vector2))
                                {
                                    array.SetValue(variant.GetVector2(), i);
                                }
                                else if (elementType == typeof(Quaternion))
                                {
                                    array.SetValue(variant.GetQuaternion(), i);
                                }
                                else if (elementType == typeof(Color))
                                {
                                    array.SetValue(variant.GetColor(), i);
                                }
                                else if (elementType.IsSubclassOf(typeof(Resource)))
                                {
                                    array.SetValue(variant.GetResource(), i);
                                }
                                break;
                            }
                        }

                        field.SetValue(component, array);
                    }
                }
            }
#endif
        }
Example #7
0
 public static void RegisterCSComponent(CSComponent component)
 {
     // register (holds a reference)
     liveComponents [component.RefID] = component;
 }
Example #8
0
        // 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 static void RegisterCSComponent(CSComponent component)
		{
			// register (holds a reference)
			liveComponents [component.RefID] = component;
		}
        public void ApplyFieldValues(CSComponent component, IntPtr fieldValuePtr)
        {
            // FIXME: This will need to be optimized, specifically to use uint key hashes for value lookup

            #if ATOMIC_DESKTOP || ATOMIC_MOBILE

            fieldMap.CopyVariantMap(fieldValuePtr);

            foreach (var field in InspectorFields)
            {
                if (fieldMap.Contains(field.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;
                    }
                }
            }

            #endif
        }
Example #11
0
        void AddCSComponent(CSComponent csc)
        {
            CSComponentInfo info;

            if (!CSComponentCore.csinfoLookup.TryGetValue(csc.GetType(), out info))
            {
                Log.Error("Scene.HandleComponentAdded - unable to get CSComponentInfo");
                return;
            }

            List<CSComponent> cslist;

            if (!cscomponents.TryGetValue(info, out cslist))
            {
                cslist = cscomponents[info] = new List<CSComponent>();
            }

            if (cslist.Contains(csc))
            {
                throw new InvalidOperationException("Scene.HandleComponentAdded - CSComponent already added to component list");
            }

            cslist.Add(csc);

            if (cscomponentStart.Contains(csc))
            {
                throw new InvalidOperationException("Scene.HandleComponentAdded CSComponent already added to start list");
            }

            if (csc.started)
            {
                throw new InvalidOperationException("Scene.HandleComponentAdded CSComponent already started");
            }

            cscomponentStart.Add(csc);

        }
        public void RegisterInstance(CSComponent component)
        {
            Instances.Add(component);

            if (StartMethod != null)
            {
                StartList.Add(component);
            }
        }
 public static void RegisterInstance(CSComponent component)
 {
     instance.csinfoLookup[component.GetType()].RegisterInstance(component);
 }