Show More
Commit Description:
Add timers for Simulation and various engines...
Commit Description:
Add timers for Simulation and various engines Starting to add additional timers for different stages of the process of updating in order to get more insight into what is slowing it down. The update takes 9ms, which is much longer than it used to. Engine-specific timers are coming later.
File last commit:
Show/Diff file:
Action:
FNA/src/Content/ContentReaders/DictionaryReader.cs
106 lines | 2.1 KiB | text/x-csharp | CSharpLexer
#region License
/* FNA - XNA4 Reimplementation for Desktop Platforms
* Copyright 2009-2020 Ethan Lee and the MonoGame Team
*
* Released under the Microsoft Public License.
* See LICENSE for details.
*/
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
#endregion
namespace Microsoft.Xna.Framework.Content
{
internal class DictionaryReader<TKey, TValue> : ContentTypeReader<Dictionary<TKey, TValue>>
{
#region Public Properties
public override bool CanDeserializeIntoExistingObject
{
get
{
return true;
}
}
#endregion
#region Private Variables
ContentTypeReader keyReader;
ContentTypeReader valueReader;
Type keyType;
Type valueType;
#endregion
#region Public Constructor
public DictionaryReader()
{
}
#endregion
#region Protected Initialization Method
protected internal override void Initialize(ContentTypeReaderManager manager)
{
keyType = typeof(TKey);
valueType = typeof(TValue);
keyReader = manager.GetTypeReader(keyType);
valueReader = manager.GetTypeReader(valueType);
}
#endregion
#region Protected Read Method
protected internal override Dictionary<TKey, TValue> Read(ContentReader input, Dictionary<TKey, TValue> existingInstance)
{
int count = input.ReadInt32();
Dictionary<TKey, TValue> dictionary = existingInstance;
if (dictionary == null)
{
dictionary = new Dictionary<TKey, TValue>(count);
}
else
{
dictionary.Clear();
}
for (int i = 0; i < count; i += 1)
{
TKey key;
TValue value;
if (keyType.IsValueType)
{
key = input.ReadObject<TKey>(keyReader);
}
else
{
int readerType = input.Read7BitEncodedInt();
key = (readerType > 0) ? input.ReadObject<TKey>(input.TypeReaders[readerType - 1]) : default(TKey);
}
if (valueType.IsValueType)
{
value = input.ReadObject<TValue>(valueReader);
}
else
{
int readerType = input.Read7BitEncodedInt();
value = (readerType > 0) ? input.ReadObject<TValue>(input.TypeReaders[readerType - 1]) : default(TValue);
}
dictionary.Add(key, value);
}
return dictionary;
}
#endregion
}
}