Пример #1
0
        public static string To <T>(T obj)
        {
            Type type   = typeof(T);
            var  output = new StringBuilder();

            output.Append("<?xml version=\"1.0\"?>\n");

            XMLTypeHandler handler = XMLHelpers.GetTypeHandler(type);

            if (handler == null)
            {
                return(null);
            }
            handler.Serialize(obj, output);
            return(output.ToString());
        }
Пример #2
0
        protected override void RenderContent(RenderComposer composer)
        {
            ImGui.Text(UnmanagedMemoryAllocator.GetDebugInformation());

            var assetBytes = 0;

            foreach (Asset asset in Engine.AssetLoader.LoadedAssets)
            {
                assetBytes += asset.ByteSize;
            }

            ImGui.Text($"Assets Rough Estimate: {Helpers.FormatByteAmountAsString(assetBytes)}");
            var totalBytes = 0;

            for (var i = 0; i < Texture.AllTextures.Count; i++)
            {
                Texture texture  = Texture.AllTextures[i];
                int     byteSize = (int)(texture.Size.X * texture.Size.Y) * Gl.PixelTypeToByteCount(texture.PixelType) *
                                   Gl.PixelFormatToComponentCount(texture.PixelFormat);
                totalBytes += byteSize;
            }

            ImGui.Text($"Texture Memory Estimate: {Helpers.FormatByteAmountAsString(totalBytes)}");
            ImGui.Text($"Audio Buffer Memory: {Helpers.FormatByteAmountAsString(AudioLayer.MetricAllocatedDataBlocks)}");
            ImGui.Text($"Managed Memory (Game): {Helpers.FormatByteAmountAsString(GC.GetTotalMemory(false))}");

            long usedRam     = _p.WorkingSet64;
            long usedRamMost = _p.PrivateMemorySize64;

            ImGui.Text($"Total Memory Used: {Helpers.FormatByteAmountAsString(usedRam)} | Allocated: {Helpers.FormatByteAmountAsString(usedRamMost)}");

            ImGui.NewLine();
            ImGui.BeginGroup();
            ImGui.BeginTabBar("TabBar");
            if (ImGui.BeginTabItem("Assets"))
            {
                ImGui.BeginChild("Assets", new Vector2(450, 500), true, ImGuiWindowFlags.HorizontalScrollbar);

                Asset[] loadedAssets = Engine.AssetLoader.LoadedAssets;
                IOrderedEnumerable <Asset> orderedEnum = loadedAssets.OrderByDescending(x => x.ByteSize);
                foreach (Asset asset in orderedEnum)
                {
                    float percent = (float)asset.ByteSize / assetBytes;
                    ImGui.Text($"{asset.Name} {Helpers.FormatByteAmountAsString(asset.ByteSize)} {percent * 100:0}%%");
                    ImGui.Text($"\t{asset.GetType()}");
                }

                ImGui.EndChild();
                ImGui.EndTabItem();
            }

            if (ImGui.BeginTabItem("XML Cache"))
            {
                ImGui.BeginChild("XMLType", new Vector2(450, 500), true, ImGuiWindowFlags.HorizontalScrollbar);

                LazyConcurrentDictionary <Type, XMLTypeHandler?> xmlCachedHandlers = XMLHelpers.Handlers;

                var counter = 0;
                foreach ((Type type, Lazy <XMLTypeHandler?> typeHandlerLazy) in xmlCachedHandlers)
                {
                    if (!typeHandlerLazy.IsValueCreated)
                    {
                        continue;
                    }

                    counter++;
                    ImGui.PushID(counter);

                    XMLTypeHandler typeHandler = typeHandlerLazy.Value !;
                    if (ImGui.TreeNode($"{typeHandler.TypeName} ({typeHandler.GetType().ToString().Replace("Emotion.Standard.XML.TypeHandlers.", "")})"))
                    {
                        ImGui.Text($"\t Full TypeName: {type}");
                        if (typeHandler is XMLComplexTypeHandler complexHandler)
                        {
                            ImGui.Text($"\t Fields: {complexHandler.FieldCount()}");
                        }

                        ImGui.TreePop();
                    }

                    ImGui.PopID();
                }

                ImGui.EndChild();
                ImGui.EndTabItem();
            }

            ImGui.EndTabBar();
            ImGui.EndGroup();
        }
Пример #3
0
        private static XMLTypeHandler TypeHandlerFactory(Type type)
        {
            type = GetOpaqueType(type, out bool opaque);

            // Index name.
            string typeName = GetTypeName(type);

            ResolvedTypes.TryAdd(typeName, new Lazy <Type>(type));

            XMLTypeHandler newHandler = null;

            // Trivial types.
            if (type.IsPrimitive)
            {
                newHandler = new XMLPrimitiveTypeHandler(type, opaque);
            }
            if (type.IsEnum)
            {
                newHandler = new XMLEnumTypeHandler(type, opaque);
            }
            if (type == StringType)
            {
                newHandler = new XMLStringTypeHandler(type);
            }

            // IEnumerable
            if (type.IsArray || type.GetInterface("IEnumerable") != null)
            {
                Type elementType;
                if (type.IsArray)
                {
                    elementType = type.GetElementType();
                    newHandler  = new XMLArrayTypeHandler(type, elementType);
                }
                else if (type.GetInterface("IList") != null)
                {
                    elementType = type.GetGenericArguments().FirstOrDefault();
                    newHandler  = new XMLListHandler(type, elementType);
                }
                else if (type.GetInterface("IDictionary") != null)
                {
                    // The dictionary is basically an array of key value types. Synthesize this here.
                    Type[] generics  = type.GetGenericArguments();
                    Type   keyType   = generics[0];
                    Type   valueType = generics[1];
                    elementType = KeyValuePairType.MakeGenericType(keyType, valueType);
                    newHandler  = new XMLDictionaryTypeHandler(type, elementType);
                }
            }

            // KeyValue
            if (type.IsGenericType && type.GetGenericTypeDefinition() == KeyValuePairType)
            {
                newHandler = new XMLKeyValueTypeHandler(type);
            }

            // Some other type, for sure a complex one.
            if (newHandler == null && type.IsValueType)
            {
                return(new XMLComplexValueTypeHandler(type, opaque));
            }

            return(newHandler ?? new XMLComplexTypeHandler(type));
        }
Пример #4
0
        public static XMLFieldHandler ResolveFieldHandler(Type type, XMLReflectionHandler property)
        {
            XMLTypeHandler typeHandler = GetTypeHandler(type);

            return(typeHandler == null ? null : new XMLFieldHandler(property, typeHandler)); // TypeHandler is null if an excluded type.
        }