Browse Source

Svelto.ECS is now UWP compatible

tags/Rel1
sebas77 7 years ago
parent
commit
b8c9cd0163
11 changed files with 67 additions and 324 deletions
  1. +8
    -7
      Context/ContextNotifier.cs
  2. +0
    -9
      Context/Unity.meta
  3. +0
    -183
      DataStructures/SerializableDictionary.cs
  4. +0
    -7
      DataStructures/SerializableDictionary.cs.meta
  5. +2
    -1
      DataStructures/WeakReference.cs
  6. +5
    -4
      ECS/EnginesRoot.cs
  7. +0
    -5
      ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs
  8. +1
    -1
      ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta
  9. +21
    -105
      Utilities/DesignByContract.cs
  10. +9
    -2
      Utilities/Print.cs
  11. +21
    -0
      Utilities/WeakActionStruct.cs

+ 8
- 7
Context/ContextNotifier.cs View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Svelto.DataStructures;
using WeakReferenceI = Svelto.DataStructures.WeakReference<Svelto.Context.IWaitForFrameworkInitialization>;
using WeakReferenceD = Svelto.DataStructures.WeakReference<Svelto.Context.IWaitForFrameworkDestruction>;

namespace Svelto.Context
{
@@ -8,14 +9,14 @@ namespace Svelto.Context
{
public ContextNotifier()
{
_toInitialize = new List<WeakReference<IWaitForFrameworkInitialization>>();
_toDeinitialize = new List<WeakReference<IWaitForFrameworkDestruction>>();
_toInitialize = new List<WeakReferenceI>();
_toDeinitialize = new List<WeakReferenceD>();
}

public void AddFrameworkDestructionListener(IWaitForFrameworkDestruction obj)
{
if (_toDeinitialize != null)
_toDeinitialize.Add(new WeakReference<IWaitForFrameworkDestruction>(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<IWaitForFrameworkInitialization>(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<WeakReference<IWaitForFrameworkDestruction>> _toDeinitialize;
List<WeakReference<IWaitForFrameworkInitialization>> _toInitialize;
List<WeakReferenceD> _toDeinitialize;
List<WeakReferenceI> _toInitialize;
}
}

+ 0
- 9
Context/Unity.meta View File

@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 14144568b327bbe40876c12a777e5f05
folderAsset: yes
timeCreated: 1434752394
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

+ 0
- 183
DataStructures/SerializableDictionary.cs View File

@@ -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<TKey, TVal>
{
public TKey Key;
public TVal Value;
}

[Serializable()]
public class SerializableDictionary<TKey, TVal> : Dictionary<TKey, TVal>,
#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<TKey, TVal> dictionary)
: base(dictionary)
{
}
public SerializableDictionary(IEqualityComparer<TKey> comparer)
: base(comparer)
{
}
public SerializableDictionary(int capacity)
: base(capacity)
{
}
public SerializableDictionary(IDictionary<TKey, TVal> dictionary, IEqualityComparer<TKey> comparer)
: base(dictionary, comparer)
{
}
public SerializableDictionary(int capacity, IEqualityComparer<TKey> 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<TKey, TVal> kvp = (KeyValueSerialization<TKey, TVal>)info.GetValue(String.Format("Im{0}", i), typeof(KeyValueSerialization<TKey, TVal>));
this.Add(kvp.Key, kvp.Value);
}
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("count", this.Count);
int itemIdx = 0;
foreach (KeyValuePair<TKey, TVal> kvp in this)
{
KeyValueSerialization<TKey, TVal> kvs = new KeyValueSerialization<TKey, TVal>();
kvs.Key = kvp.Key;
kvs.Value = kvp.Value;
info.AddValue(String.Format("Im{0}", itemIdx), kvs, typeof(KeyValueSerialization<TKey, TVal>));
itemIdx++;
}
}
#endregion
#if XML_ENABLED
#region IXmlSerializable Members
void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
{
//writer.WriteStartElement(DictionaryNodeName);
foreach (KeyValuePair<TKey, TVal> 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
}


+ 0
- 7
DataStructures/SerializableDictionary.cs.meta View File

@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: b4a9cb2903cd07946a8650aeefb8d853
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

+ 2
- 1
DataStructures/WeakReference.cs View File

@@ -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


+ 5
- 4
ECS/EnginesRoot.cs View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using Svelto.DataStructures;
using UnityEngine;
using WeakReference = Svelto.DataStructures.WeakReference<Svelto.ECS.EnginesRoot>;

#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR
using Svelto.ECS.Profiler;
@@ -30,7 +31,7 @@ namespace Svelto.ECS
public EnginesRoot()
{
_nodeEngines = new Dictionary<Type, FasterList<INodeEngine<INode>>>();
_engineRootWeakReference = new WeakReference<EnginesRoot>(this);
_engineRootWeakReference = new WeakReference(this);
_otherEnginesReferences = new FasterList<IEngine>();

_nodesDB = new Dictionary<Type, FasterList<INode>>();
@@ -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<INode> _nodesToAdd;
FasterList<INode> _groupNodesToAdd;

WeakReference<EnginesRoot> _engineRootWeakReference;
WeakReference _engineRootWeakReference;

//integrated pooling system
//add debug panel like Entitas has


+ 0
- 5
ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs View File

@@ -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, ' ');


+ 1
- 1
ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 1c9cf391ddfdd92429ce90eeb73a936a
guid: 3e961e5c8cc40064fa25092d835d1a80
timeCreated: 1462527509
licenseType: Pro
MonoImporter:


+ 21
- 105
Utilities/DesignByContract.cs View File

@@ -349,113 +349,29 @@ namespace DesignByContract

#endregion // Implementation

#region Obsolete

/// <summary>
/// Precondition check.
/// </summary>
[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);
}


/// <summary>
/// Precondition check.
/// </summary>
[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.");
}
/// <summary>
/// Postcondition check.
/// </summary>
[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);
}

/// <summary>
/// Postcondition check.
/// </summary>
[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.");
}
/// <summary>
/// Invariant check.
/// </summary>
[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);
}

/// <summary>
/// Invariant check.
/// </summary>
[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.");
}

/// <summary>
/// Assertion check.
/// </summary>
[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);
}

/// <summary>
/// Assertion check.
/// </summary>
[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

/// <summary>
/// Exception raised when a contract is broken.
/// Catch this exception type if you wish to differentiate between
/// any DesignByContract exception and other runtime exceptions.
///
/// </summary>
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

/// <summary>
/// Exception raised when a contract is broken.
/// Catch this exception type if you wish to differentiate between
/// any DesignByContract exception and other runtime exceptions.
///
/// </summary>
public class DesignByContractException : ApplicationException
{
protected DesignByContractException() {}
protected DesignByContractException(string message) : base(message) {}


+ 9
- 2
Utilities/Print.cs View File

@@ -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
/// <param name="txt"></param>
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
}
}


+ 21
- 0
Utilities/WeakActionStruct.cs View File

@@ -12,10 +12,17 @@ namespace BetterWeakEvents
public WeakAction(Action<T1, T2> 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<T> 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()


Loading…
Cancel
Save