Browse Source

Make the framework more unity agnostic

tags/Rel1
sebas77 7 years ago
parent
commit
e8ff87871a
10 changed files with 83 additions and 33 deletions
  1. +2
    -0
      Context/Factories/GameObjectFactory.cs
  2. +2
    -0
      Context/Factories/MonoBehaviourFactory.cs
  3. +2
    -2
      Context/ICompositionRoot.cs
  4. +2
    -0
      Context/UnityContext.cs
  5. +2
    -3
      DataStructures/FasterList.cs
  6. +1
    -2
      DataStructures/ThreadSafeDictionary.cs
  7. +25
    -10
      DataStructures/WeakReference.cs
  8. +4
    -4
      ECS/EntityDescriptor.cs
  9. +1
    -1
      Utilities/DesignByContract.cs
  10. +42
    -11
      Utilities/Print.cs

+ 2
- 0
Context/Factories/GameObjectFactory.cs View File

@@ -1,3 +1,4 @@
#if UNITY_5 || UNITY_5_3_OR_NEWER
using System.Collections.Generic;
using UnityEngine;

@@ -61,3 +62,4 @@ namespace Svelto.Context
Dictionary<string, GameObject[]> _prefabs;
}
}
#endif

+ 2
- 0
Context/Factories/MonoBehaviourFactory.cs View File

@@ -1,3 +1,4 @@
#if UNITY_5 || UNITY_5_3_OR_NEWER
#region

using System;
@@ -18,3 +19,4 @@ namespace Svelto.Context
}
}
}
#endif

+ 2
- 2
Context/ICompositionRoot.cs View File

@@ -1,3 +1,4 @@
#if UNITY_5 || UNITY_5_3_OR_NEWER
namespace Svelto.Context
{
public interface ICompositionRoot
@@ -7,5 +8,4 @@ namespace Svelto.Context
void OnContextDestroyed();
}
}


#endif

+ 2
- 0
Context/UnityContext.cs View File

@@ -1,3 +1,4 @@
#if UNITY_5 || UNITY_5_3_OR_NEWER
using System.Collections;
using Svelto.Context;
using UnityEngine;
@@ -42,3 +43,4 @@ public class UnityContext<T>: UnityContext where T:class, ICompositionRoot, new(

T _applicationRoot;
}
#endif

+ 2
- 3
DataStructures/FasterList.cs View File

@@ -2,7 +2,6 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;

namespace Svelto.DataStructures
{
@@ -766,14 +765,14 @@ namespace Svelto.DataStructures

void AllocateMore()
{
var newList = new T[Mathf.Max(_buffer.Length << 1, MIN_SIZE)];
var newList = new T[Math.Max(_buffer.Length << 1, MIN_SIZE)];
if (_count > 0) _buffer.CopyTo(newList, 0);
_buffer = newList;
}

void AllocateMore(int newSize)
{
var oldLength = Mathf.Max(_buffer.Length, MIN_SIZE);
var oldLength = Math.Max(_buffer.Length, MIN_SIZE);

while (oldLength < newSize)
oldLength <<= 1;


+ 1
- 2
DataStructures/ThreadSafeDictionary.cs View File

@@ -1,5 +1,4 @@

using System;
using System.Collections.Generic;
using System.Threading;

@@ -11,7 +10,7 @@ namespace Svelto.DataStructures
/// </summary>
/// <typeparam name = "TKey"></typeparam>
/// <typeparam name = "TValue"></typeparam>
[Serializable]
public class ThreadSafeDictionary<TKey, TValue>
{
public ThreadSafeDictionary(int v)


+ 25
- 10
DataStructures/WeakReference.cs View File

@@ -1,5 +1,4 @@
using System;
using System.Runtime.Serialization;
/// <span class="code-SummaryComment"><summary></span>
/// Represents a weak reference, which references an object while still allowing
/// that object to be reclaimed by garbage collection.
@@ -8,7 +7,7 @@ using System.Runtime.Serialization;

namespace Svelto.DataStructures
{
[Serializable]
#if !NETFX_CORE
public class WeakReference<T>
: WeakReference where T : class
{
@@ -50,15 +49,31 @@ 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
#else
public class WeakReference<T> : System.WeakReference where T : class
{
public static bool IsValid(this WeakReference obj) { return obj != null && obj.IsAlive == true && obj.Target != null; }
public bool IsValid { get { return Target != null && IsAlive == true; } }

public new T Target
{
get
{
return (T)base.Target;
}
set
{
base.Target = value;
}
}

public WeakReference(T target)
: base(target)
{ }

public WeakReference(T target, bool trackResurrection)
: base(target, trackResurrection)
{ }
}
#endif
}

+ 4
- 4
ECS/EntityDescriptor.cs View File

@@ -2,9 +2,6 @@ using System;
using System.Collections.Generic;
using System.Reflection;
using Svelto.DataStructures;
#if NETFX_CORE
using BindingFlags = System.Reflection.BindingFlags;
#endif

namespace Svelto.ECS
{
@@ -33,8 +30,11 @@ namespace Svelto.ECS
{
var implementor = implementors[index];
if (implementor == null)
{
Utility.Console.LogWarning(
"Null implementor, are you using a wild GetComponents<Monobehaviour> to fetch it? ").FastConcat(ToString()));
"Null implementor, are you using a wild GetComponents<Monobehaviour> to fetch it? "
.FastConcat(ToString()));
}
else
{
if (implementor is IRemoveEntityComponent)


+ 1
- 1
Utilities/DesignByContract.cs View File

@@ -371,7 +371,7 @@ namespace DesignByContract
/// any DesignByContract exception and other runtime exceptions.
///
/// </summary>
public class DesignByContractException : ApplicationException
public class DesignByContractException : Exception
{
protected DesignByContractException() {}
protected DesignByContractException(string message) : base(message) {}


+ 42
- 11
Utilities/Print.cs View File

@@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.Text;
using UnityEngine;

public static class FastConcatUtility
{
@@ -101,8 +100,8 @@ namespace Utility
{
void Log (string txt, string stack = null, LogType type = LogType.Log);
}
public class SlowLogger : ILogger
#if UNITY_5 || UNITY_5_3_OR_NEWER
public class SlowLoggerUnity : ILogger
{
public void Log(string txt, string stack = null, LogType type = LogType.Log)
{
@@ -123,12 +122,45 @@ namespace Utility
}
}
}
#endif
public class SimpleLogger : ILogger
{
public void Log(string txt, string stack = null, LogType type = LogType.Log)
{
switch (type)
{
case LogType.Log:
Console.SystemLog(stack != null ? txt.FastConcat(stack) : txt);
break;
case LogType.Exception:
Console.SystemLog("Log of exceptions not supported");
break;
case LogType.Warning:
Console.SystemLog(stack != null ? txt.FastConcat(stack) : txt);
break;
case LogType.Error:
Console.SystemLog(stack != null ? txt.FastConcat(stack) : txt);
break;
}
}
}

public enum LogType
{
Log,
Exception,
Warning,
Error
}

public static class Console
{
static StringBuilder _stringBuilder = new StringBuilder(256);

public static ILogger logger = new SlowLogger();
#if UNITY_5 || UNITY_5_3_OR_NEWER
public static ILogger logger = new SlowLoggerUnity();
#else
public static ILogger logger = new SimpleLogger();
#endif
public static volatile bool BatchLog = false;

public static void Log(string txt)
@@ -167,17 +199,18 @@ namespace Utility

logger.Log(toPrint, stack, LogType.Error);
}

public static void LogException(Exception e)
{
#if UNITY_5 || UNITY_5_3_OR_NEWER
LogException(e, null);
#endif
}
#if UNITY_5 || UNITY_5_3_OR_NEWER
public static void LogException(Exception e, UnityEngine.Object obj)
{
UnityEngine.Debug.LogException(e, obj);
}
#endif
public static void LogWarning(string txt)
{
string toPrint;
@@ -217,13 +250,11 @@ 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
}
}


Loading…
Cancel
Save