From b8c9cd0163effd0d8cc91166550a48a5623623ee Mon Sep 17 00:00:00 2001 From: sebas77 Date: Sun, 29 Jan 2017 17:09:56 +0000 Subject: [PATCH] Svelto.ECS is now UWP compatible --- Context/ContextNotifier.cs | 15 +- Context/Unity.meta | 9 - DataStructures/SerializableDictionary.cs | 183 ------------------ DataStructures/SerializableDictionary.cs.meta | 7 - DataStructures/WeakReference.cs | 3 +- ECS/EnginesRoot.cs | 9 +- .../EngineProfiler/EngineProfilerInspector.cs | 5 - .../ProfilerEditorLayout.cs.meta | 2 +- Utilities/DesignByContract.cs | 126 ++---------- Utilities/Print.cs | 11 +- Utilities/WeakActionStruct.cs | 21 ++ 11 files changed, 67 insertions(+), 324 deletions(-) delete mode 100644 Context/Unity.meta delete mode 100644 DataStructures/SerializableDictionary.cs delete mode 100644 DataStructures/SerializableDictionary.cs.meta diff --git a/Context/ContextNotifier.cs b/Context/ContextNotifier.cs index 88d56f6..8c54f35 100644 --- a/Context/ContextNotifier.cs +++ b/Context/ContextNotifier.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; -using Svelto.DataStructures; +using WeakReferenceI = Svelto.DataStructures.WeakReference; +using WeakReferenceD = Svelto.DataStructures.WeakReference; namespace Svelto.Context { @@ -8,14 +9,14 @@ namespace Svelto.Context { public ContextNotifier() { - _toInitialize = new List>(); - _toDeinitialize = new List>(); + _toInitialize = new List(); + _toDeinitialize = new List(); } public void AddFrameworkDestructionListener(IWaitForFrameworkDestruction obj) { if (_toDeinitialize != null) - _toDeinitialize.Add(new WeakReference(obj)); + _toDeinitialize.Add(new WeakReferenceD(obj)); else throw new Exception("An object is expected to be initialized after the framework has been deinitialized. Type: " + obj.GetType()); } @@ -23,7 +24,7 @@ namespace Svelto.Context public void AddFrameworkInitializationListener(IWaitForFrameworkInitialization obj) { if (_toInitialize != null) - _toInitialize.Add(new WeakReference(obj)); + _toInitialize.Add(new WeakReferenceI(obj)); else throw new Exception("An object is expected to be initialized after the framework has been initialized. Type: " + obj.GetType()); } @@ -68,7 +69,7 @@ namespace Svelto.Context _toInitialize = null; } - List> _toDeinitialize; - List> _toInitialize; + List _toDeinitialize; + List _toInitialize; } } diff --git a/Context/Unity.meta b/Context/Unity.meta deleted file mode 100644 index 75e174f..0000000 --- a/Context/Unity.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 14144568b327bbe40876c12a777e5f05 -folderAsset: yes -timeCreated: 1434752394 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/DataStructures/SerializableDictionary.cs b/DataStructures/SerializableDictionary.cs deleted file mode 100644 index 93aae33..0000000 --- a/DataStructures/SerializableDictionary.cs +++ /dev/null @@ -1,183 +0,0 @@ -#define XML_ENABLED - -using System; -using System.Runtime.Serialization; -#if XML_ENABLED -using System.Xml; -using System.Xml.Serialization; -#endif -using System.Collections.Generic; - -[Serializable()] -public struct KeyValueSerialization -{ - public TKey Key; - public TVal Value; -} - -[Serializable()] -public class SerializableDictionary : Dictionary, -#if XML_ENABLED -IXmlSerializable, -#endif -ISerializable -{ - #region Constants - private const string DictionaryNodeName = "Dictionary"; - private const string ItemNodeName = "Item"; - private const string KeyNodeName = "Key"; - private const string ValueNodeName = "Value"; - #endregion - #region Constructors - public SerializableDictionary() - { - } - - public SerializableDictionary(IDictionary dictionary) - : base(dictionary) - { - } - - public SerializableDictionary(IEqualityComparer comparer) - : base(comparer) - { - } - - public SerializableDictionary(int capacity) - : base(capacity) - { - } - - public SerializableDictionary(IDictionary dictionary, IEqualityComparer comparer) - : base(dictionary, comparer) - { - } - - public SerializableDictionary(int capacity, IEqualityComparer comparer) - : base(capacity, comparer) - { - } - - #endregion - #region ISerializable Members - - public SerializableDictionary(SerializationInfo info, StreamingContext context) - { - int itemCount = info.GetInt32("count"); - - for (int i = 0; i < itemCount; i++) - { - KeyValueSerialization kvp = (KeyValueSerialization)info.GetValue(String.Format("Im{0}", i), typeof(KeyValueSerialization)); - - this.Add(kvp.Key, kvp.Value); - } - } - - void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("count", this.Count); - int itemIdx = 0; - foreach (KeyValuePair kvp in this) - { - KeyValueSerialization kvs = new KeyValueSerialization(); - kvs.Key = kvp.Key; - kvs.Value = kvp.Value; - - info.AddValue(String.Format("Im{0}", itemIdx), kvs, typeof(KeyValueSerialization)); - itemIdx++; - } - } - - #endregion - #if XML_ENABLED - #region IXmlSerializable Members - - void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer) - { - //writer.WriteStartElement(DictionaryNodeName); - foreach (KeyValuePair kvp in this) - { - writer.WriteStartElement(ItemNodeName); - writer.WriteStartElement(KeyNodeName); - KeySerializer.Serialize(writer, kvp.Key); - writer.WriteEndElement(); - writer.WriteStartElement(ValueNodeName); - ValueSerializer.Serialize(writer, kvp.Value); - writer.WriteEndElement(); - writer.WriteEndElement(); - } - //writer.WriteEndElement(); - } - - void IXmlSerializable.ReadXml(System.Xml.XmlReader reader) - { - if (reader.IsEmptyElement) - { - return; - } - - // Move past container - if (!reader.Read()) - { - throw new XmlException("Error in Deserialization of Dictionary"); - } - - //reader.ReadStartElement(DictionaryNodeName); - while (reader.NodeType != XmlNodeType.EndElement) - { - reader.ReadStartElement(ItemNodeName); - reader.ReadStartElement(KeyNodeName); - TKey key = (TKey)KeySerializer.Deserialize(reader); - reader.ReadEndElement(); - reader.ReadStartElement(ValueNodeName); - TVal value = (TVal)ValueSerializer.Deserialize(reader); - reader.ReadEndElement(); - reader.ReadEndElement(); - this.Add(key, value); - reader.MoveToContent(); - } - //reader.ReadEndElement(); - - reader.ReadEndElement(); // Read End Element to close Read of containing node - } - - System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema() - { - return null; - } - - #endregion - #region Private Properties - - protected XmlSerializer ValueSerializer - { - get - { - if (valueSerializer == null) - { - valueSerializer = new XmlSerializer(typeof(TVal)); - } - return valueSerializer; - } - } - - private XmlSerializer KeySerializer - { - get - { - if (keySerializer == null) - { - keySerializer = new XmlSerializer(typeof(TKey)); - } - return keySerializer; - } - } - - #endregion - #region Private Members - private XmlSerializer keySerializer = null; - private XmlSerializer valueSerializer = null; - #endregion - #endif -} - diff --git a/DataStructures/SerializableDictionary.cs.meta b/DataStructures/SerializableDictionary.cs.meta deleted file mode 100644 index 8ec8a55..0000000 --- a/DataStructures/SerializableDictionary.cs.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: b4a9cb2903cd07946a8650aeefb8d853 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} diff --git a/DataStructures/WeakReference.cs b/DataStructures/WeakReference.cs index 4a8d018..a3310ec 100644 --- a/DataStructures/WeakReference.cs +++ b/DataStructures/WeakReference.cs @@ -50,10 +50,11 @@ namespace Svelto.DataStructures public WeakReference(T target, bool trackResurrection) : base(target, trackResurrection) { } - +#if !NETFX_CORE protected WeakReference(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } public static class WeakReferenceUtility diff --git a/ECS/EnginesRoot.cs b/ECS/EnginesRoot.cs index 6d43243..104e9dc 100644 --- a/ECS/EnginesRoot.cs +++ b/ECS/EnginesRoot.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using Svelto.DataStructures; using UnityEngine; +using WeakReference = Svelto.DataStructures.WeakReference; #if ENGINE_PROFILER_ENABLED && UNITY_EDITOR using Svelto.ECS.Profiler; @@ -30,7 +31,7 @@ namespace Svelto.ECS public EnginesRoot() { _nodeEngines = new Dictionary>>(); - _engineRootWeakReference = new WeakReference(this); + _engineRootWeakReference = new WeakReference(this); _otherEnginesReferences = new FasterList(); _nodesDB = new Dictionary>(); @@ -122,7 +123,7 @@ namespace Svelto.ECS return; } - var baseType = engine.GetType().BaseType; +/* var baseType = engine.GetType().BaseType; if (baseType.IsGenericType) { var genericType = baseType.GetGenericTypeDefinition(); @@ -133,7 +134,7 @@ namespace Svelto.ECS return; } - } + }*/ _otherEnginesReferences.Add(engine); } @@ -314,7 +315,7 @@ namespace Svelto.ECS FasterList _nodesToAdd; FasterList _groupNodesToAdd; - WeakReference _engineRootWeakReference; + WeakReference _engineRootWeakReference; //integrated pooling system //add debug panel like Entitas has diff --git a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs index f613f61..1ac387a 100644 --- a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs +++ b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs @@ -27,11 +27,6 @@ namespace Svelto.ECS.Profiler static string _systemNameSearchTerm = string.Empty; - float _axisUpperBounds = 2f; - - string updateTitle = "Update".PadRight(15, ' '); - string lateUpdateTitle = "Late".PadRight(13, ' '); - string fixedupdateTitle = "Fixed".PadRight(15, ' '); string minTitle = "Min".PadRight(15, ' '); string maxTitle = "Max".PadRight(15, ' '); string avgTitle = "Avg".PadRight(15, ' '); diff --git a/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta b/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta index 77f5e52..489305b 100644 --- a/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta +++ b/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1c9cf391ddfdd92429ce90eeb73a936a +guid: 3e961e5c8cc40064fa25092d835d1a80 timeCreated: 1462527509 licenseType: Pro MonoImporter: diff --git a/Utilities/DesignByContract.cs b/Utilities/DesignByContract.cs index f69b621..d34861e 100644 --- a/Utilities/DesignByContract.cs +++ b/Utilities/DesignByContract.cs @@ -349,113 +349,29 @@ namespace DesignByContract #endregion // Implementation - #region Obsolete - - /// - /// Precondition check. - /// - [Obsolete("Set Check.UseAssertions = true and then call Check.Require")] - [Conditional("DBC_CHECK_ALL"), - Conditional("DBC_CHECK_INVARIANT"), - Conditional("DBC_CHECK_POSTCONDITION"), - Conditional("DBC_CHECK_PRECONDITION")] - public static void RequireTrace(bool assertion, string message) - { - Trace.Assert(assertion, "Precondition: " + message); - } - - - /// - /// Precondition check. - /// - [Obsolete("Set Check.UseAssertions = true and then call Check.Require")] - [Conditional("DBC_CHECK_ALL"), - Conditional("DBC_CHECK_INVARIANT"), - Conditional("DBC_CHECK_POSTCONDITION"), - Conditional("DBC_CHECK_PRECONDITION")] - public static void RequireTrace(bool assertion) - { - Trace.Assert(assertion, "Precondition failed."); - } - - /// - /// Postcondition check. - /// - [Obsolete("Set Check.UseAssertions = true and then call Check.Ensure")] - [Conditional("DBC_CHECK_ALL"), - Conditional("DBC_CHECK_INVARIANT"), - Conditional("DBC_CHECK_POSTCONDITION")] - public static void EnsureTrace(bool assertion, string message) - { - Trace.Assert(assertion, "Postcondition: " + message); - } - - /// - /// Postcondition check. - /// - [Obsolete("Set Check.UseAssertions = true and then call Check.Ensure")] - [Conditional("DBC_CHECK_ALL"), - Conditional("DBC_CHECK_INVARIANT"), - Conditional("DBC_CHECK_POSTCONDITION")] - public static void EnsureTrace(bool assertion) - { - Trace.Assert(assertion, "Postcondition failed."); - } - - /// - /// Invariant check. - /// - [Obsolete("Set Check.UseAssertions = true and then call Check.Invariant")] - [Conditional("DBC_CHECK_ALL"), - Conditional("DBC_CHECK_INVARIANT")] - public static void InvariantTrace(bool assertion, string message) - { - Trace.Assert(assertion, "Invariant: " + message); - } - - /// - /// Invariant check. - /// - [Obsolete("Set Check.UseAssertions = true and then call Check.Invariant")] - [Conditional("DBC_CHECK_ALL"), - Conditional("DBC_CHECK_INVARIANT")] - public static void InvariantTrace(bool assertion) - { - Trace.Assert(assertion, "Invariant failed."); - } - - /// - /// Assertion check. - /// - [Obsolete("Set Check.UseAssertions = true and then call Check.Assert")] - [Conditional("DBC_CHECK_ALL")] - public static void AssertTrace(bool assertion, string message) - { - Trace.Assert(assertion, "Assertion: " + message); - } - - /// - /// Assertion check. - /// - [Obsolete("Set Check.UseAssertions = true and then call Check.Assert")] - [Conditional("DBC_CHECK_ALL")] - public static void AssertTrace(bool assertion) - { - Trace.Assert(assertion, "Assertion failed."); - } - #endregion // Obsolete - } // End Check - #region Exceptions - - /// - /// Exception raised when a contract is broken. - /// Catch this exception type if you wish to differentiate between - /// any DesignByContract exception and other runtime exceptions. - /// - /// - public class DesignByContractException : ApplicationException + internal class Trace + { + internal static void Assert(bool assertion, string v) + { +#if NETFX_CORE + System.Diagnostics.Contracts.Contract.Assert(assertion, v); +#else + System.Diagnostics.Trace.Assert(assertion, v); +#endif + } + } + + #region Exceptions + + /// + /// Exception raised when a contract is broken. + /// Catch this exception type if you wish to differentiate between + /// any DesignByContract exception and other runtime exceptions. + /// + /// + public class DesignByContractException : ApplicationException { protected DesignByContractException() {} protected DesignByContractException(string message) : base(message) {} diff --git a/Utilities/Print.cs b/Utilities/Print.cs index b3c8e9a..6a64d26 100644 --- a/Utilities/Print.cs +++ b/Utilities/Print.cs @@ -148,8 +148,11 @@ namespace Utility toPrint = _stringBuilder.ToString(); } - +#if !NETFX_CORE logger.Log(toPrint, showCurrentStack == true ? new StackTrace().ToString() : null, LogType.Error); +#else + logger.Log(toPrint, null, LogType.Error); +#endif } public static void LogError(string txt, string stack) @@ -200,6 +203,7 @@ namespace Utility /// public static void SystemLog(string txt) { +#if !NETFX_CORE string toPrint; lock (_stringBuilder) @@ -216,10 +220,13 @@ namespace Utility toPrint = _stringBuilder.ToString(); } -#if !UNITY_EDITOR +#if !UNITY_EDITOR System.Console.WriteLine(toPrint); #else UnityEngine.Debug.Log(toPrint); +#endif +#else + UnityEngine.Debug.Log(txt); #endif } } diff --git a/Utilities/WeakActionStruct.cs b/Utilities/WeakActionStruct.cs index 17158e1..163f5f3 100644 --- a/Utilities/WeakActionStruct.cs +++ b/Utilities/WeakActionStruct.cs @@ -12,10 +12,17 @@ namespace BetterWeakEvents public WeakAction(Action listener) { ObjectRef = GCHandle.Alloc(listener.Target, GCHandleType.Weak); +#if !NETFX_CORE Method = listener.Method; if (Method.DeclaringType.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Length != 0) throw new ArgumentException("Cannot create weak event to anonymous method with closure."); +#else + Method = listener.GetMethodInfo(); + + if (CustomAttributeExtensions.IsDefined(Method, typeof(CompilerGeneratedAttribute), false) == false) + throw new ArgumentException("Cannot create weak event to anonymous method with closure."); +#endif } public bool Invoke(T1 data1, T2 data2) @@ -49,10 +56,17 @@ namespace BetterWeakEvents public WeakAction(Action listener) { ObjectRef = GCHandle.Alloc(listener.Target, GCHandleType.Weak); +#if !NETFX_CORE Method = listener.Method; if (Method.DeclaringType.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Length != 0) throw new ArgumentException("Cannot create weak event to anonymous method with closure."); +#else + Method = listener.GetMethodInfo(); + + if (CustomAttributeExtensions.IsDefined(Method, typeof(CompilerGeneratedAttribute), false) == false) + throw new ArgumentException("Cannot create weak event to anonymous method with closure."); +#endif } public bool Invoke(T data) @@ -86,10 +100,17 @@ namespace BetterWeakEvents public WeakAction(Action listener) { ObjectRef = GCHandle.Alloc(listener.Target, GCHandleType.Weak); +#if !NETFX_CORE Method = listener.Method; if (Method.DeclaringType.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Length != 0) throw new ArgumentException("Cannot create weak event to anonymous method with closure."); +#else + Method = listener.GetMethodInfo(); + + if (CustomAttributeExtensions.IsDefined(Method, typeof(CompilerGeneratedAttribute), false) == false) + throw new ArgumentException("Cannot create weak event to anonymous method with closure."); +#endif } public bool Invoke()