Browse Source

Merge branch 'master' of https://github.com/sebas77/Svelto-ECS

tags/Rel1
sebas77 7 years ago
parent
commit
228a1ec7bd
5 changed files with 13 additions and 196 deletions
  1. +7
    -2
      ECS/EnginesRoot.cs
  2. +4
    -127
      ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs
  3. +1
    -1
      ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta
  4. +0
    -65
      ECS/Profiler/EngineProfiler.cs
  5. +1
    -1
      ECS/note.txt

+ 7
- 2
ECS/EnginesRoot.cs View File

@@ -46,8 +46,13 @@ namespace Svelto.ECS
go.AddComponent<Scheduler>().OnTick += SubmitNodes;

#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR
GameObject debugEngineObject = new GameObject("Engine Debugger");
debugEngineObject.gameObject.AddComponent<EngineProfilerBehaviour>();
var debugEngineObject = GameObject.Find("Svelto.ECS.Profiler");
if (debugEngineObject == null)
{
debugEngineObject = new GameObject("Svelto.ECS.Profiler");
debugEngineObject.gameObject.AddComponent<EngineProfilerBehaviour>();
UnityEngine.Object.DontDestroyOnLoad(debugEngineObject);
}
#endif
}



+ 4
- 127
ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs View File

@@ -47,7 +47,6 @@ namespace Svelto.ECS.Profiler
EngineInfo[] engines = new EngineInfo[engineProfilerBehaviour.engines.Count];
engineProfilerBehaviour.engines.CopyTo(engines, 0);

DrawEnginesMonitor(engines);
DrawEngineList(engineProfilerBehaviour, engines);
EditorUtility.SetDirty(target);
}
@@ -84,20 +83,6 @@ namespace Svelto.ECS.Profiler
}
ProfilerEditorLayout.EndHorizontal();

_showTickEngines = EditorGUILayout.Foldout(_showTickEngines, "Engines Ticks");
if (_showTickEngines && ShouldShowSystems(engines))
{
ProfilerEditorLayout.BeginVerticalBox();
{
var systemsDrawn = DrawUpdateEngineInfos(engines);
if (systemsDrawn == 0)
{
EditorGUILayout.LabelField(string.Empty);
}
}
ProfilerEditorLayout.EndVertical();
}

_showAddEngines = EditorGUILayout.Foldout(_showAddEngines, "Engines Add");
if (_showAddEngines && ShouldShowSystems(engines))
{
@@ -129,94 +114,6 @@ namespace Svelto.ECS.Profiler
ProfilerEditorLayout.EndVertical();
}

void DrawEnginesMonitor(EngineInfo[] engines)
{
if (_enginesMonitor == null)
{
_enginesMonitor = new EnginesMonitor(SYSTEM_MONITOR_DATA_LENGTH);
_engineMonitorData = new Queue<float>(new float[SYSTEM_MONITOR_DATA_LENGTH]);
if (EditorApplication.update != Repaint)
{
EditorApplication.update += Repaint;
}
}
double totalDuration = 0;
for (int i = 0; i < engines.Length; i++)
{
totalDuration += engines[i].lastUpdateDuration;
}

ProfilerEditorLayout.BeginVerticalBox();
{
EditorGUILayout.LabelField("Execution duration", EditorStyles.boldLabel);

ProfilerEditorLayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Total", totalDuration.ToString());
}
ProfilerEditorLayout.EndHorizontal();

ProfilerEditorLayout.BeginHorizontal();
{
_axisUpperBounds = EditorGUILayout.FloatField("Axis Upper Bounds", _axisUpperBounds);
}
ProfilerEditorLayout.EndHorizontal();

if (!EditorApplication.isPaused)
{
if (_engineMonitorData.Count >= SYSTEM_MONITOR_DATA_LENGTH)
{
_engineMonitorData.Dequeue();
}

_engineMonitorData.Enqueue((float) totalDuration);
}
_enginesMonitor.Draw(_engineMonitorData.ToArray(), 80f, _axisUpperBounds);
}
ProfilerEditorLayout.EndVertical();
}

int DrawUpdateEngineInfos(EngineInfo[] engines)
{
if (_sortingOption != SORTING_OPTIONS.NONE)
{
SortUpdateEngines(engines);
}

string title =
updateTitle.FastConcat(lateUpdateTitle)
.FastConcat(fixedupdateTitle)
.FastConcat(minTitle)
.FastConcat(maxTitle);
EditorGUILayout.LabelField("Engine Name", title, EditorStyles.boldLabel);

int enginesDrawn = 0;
for (int i = 0; i < engines.Length; i++)
{
EngineInfo engineInfo = engines[i];

if (engineInfo.engineName.ToLower().Contains(_systemNameSearchTerm.ToLower()))
{
ProfilerEditorLayout.BeginHorizontal();
{
var avg = string.Format("{0:0.000}", engineInfo.averageUpdateDuration).PadRight(15);
var avgLate = string.Format("{0:0.000}", engineInfo.averageLateUpdateDuration).PadRight(15);
var avgFixed = string.Format("{0:0.000}", engineInfo.averageFixedUpdateDuration).PadRight(15);
var min = string.Format("{0:0.000}", engineInfo.minUpdateDuration).PadRight(15);
var max = string.Format("{0:0.000}", engineInfo.maxUpdateDuration);

string output = avg.FastConcat(avgLate).FastConcat(avgFixed).FastConcat(min).FastConcat(max);

EditorGUILayout.LabelField(engineInfo.engineName, output, GetEngineStyle());
}
ProfilerEditorLayout.EndHorizontal();

enginesDrawn += 1;
}
}
return enginesDrawn;
}

int DrawAddEngineInfos(EngineInfo[] engines)
{
if (_sortingOption != SORTING_OPTIONS.NONE)
@@ -303,28 +200,6 @@ namespace Svelto.ECS.Profiler
}

#region Sorting Engines
void SortUpdateEngines(EngineInfo[] engines)
{
switch (_sortingOption)
{
case SORTING_OPTIONS.AVERAGE:
Array.Sort(engines,
(engine1, engine2) => engine2.averageUpdateDuration.CompareTo(engine1.averageUpdateDuration));
break;
case SORTING_OPTIONS.MIN:
Array.Sort(engines,
(engine1, engine2) => engine2.minUpdateDuration.CompareTo(engine1.minUpdateDuration));
break;
case SORTING_OPTIONS.MAX:
Array.Sort(engines,
(engine1, engine2) => engine2.maxUpdateDuration.CompareTo(engine1.maxUpdateDuration));
break;
case SORTING_OPTIONS.NAME:
Array.Sort(engines, StringComparer.InvariantCulture);
break;
}
}

void SortAddEngines(EngineInfo[] engines)
{
switch (_sortingOption)
@@ -342,7 +217,8 @@ namespace Svelto.ECS.Profiler
(engine1, engine2) => engine2.maxAddDuration.CompareTo(engine1.maxAddDuration));
break;
case SORTING_OPTIONS.NAME:
Array.Sort(engines, StringComparer.InvariantCulture);
Array.Sort(engines,
(engine1, engine2) => String.Compare(engine1.engineName, engine2.engineName, StringComparison.Ordinal));
break;
}
}
@@ -364,7 +240,8 @@ namespace Svelto.ECS.Profiler
(engine1, engine2) => engine2.maxRemoveDuration.CompareTo(engine1.maxRemoveDuration));
break;
case SORTING_OPTIONS.NAME:
Array.Sort(engines, StringComparer.InvariantCulture);
Array.Sort(engines,
(engine1, engine2) => String.Compare(engine1.engineName, engine2.engineName, StringComparison.Ordinal));
break;
}
}


+ 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:


+ 0
- 65
ECS/Profiler/EngineProfiler.cs View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using Svelto.Ticker.Legacy;

//This profiler is based on the Entitas Visual Debugging tool
//https://github.com/sschmid/Entitas-CSharp
@@ -42,69 +40,6 @@ namespace Svelto.ECS.Profiler
}
}

public static void MonitorUpdateDuration(ITickable tickable)
{
if (tickable is INodeEngine<INode>)
{
EngineInfo info;
if (engineInfos.TryGetValue((tickable as INodeEngine<INode>).GetType(), out info))
{
_stopwatch.Reset();
_stopwatch.Start();
tickable.Tick(Time.deltaTime);
_stopwatch.Stop();

info.AddUpdateDuration(_stopwatch.Elapsed.TotalMilliseconds);
}
}
else
{
tickable.Tick(Time.deltaTime);
}
}

public static void MonitorUpdateDuration(IPhysicallyTickable tickable)
{
if (tickable is INodeEngine<INode>)
{
EngineInfo info;
if (engineInfos.TryGetValue((tickable as INodeEngine<INode>).GetType(), out info))
{
_stopwatch.Reset();
_stopwatch.Start();
tickable.PhysicsTick(Time.fixedDeltaTime);
_stopwatch.Stop();

info.AddFixedUpdateDuration(_stopwatch.Elapsed.TotalMilliseconds);
}
}
else
{
tickable.PhysicsTick(Time.fixedDeltaTime);
}
}

public static void MonitorUpdateDuration(ILateTickable tickable)
{
if (tickable is INodeEngine<INode>)
{
EngineInfo info;
if (engineInfos.TryGetValue((tickable as INodeEngine<INode>).GetType(), out info))
{
_stopwatch.Reset();
_stopwatch.Start();
tickable.LateTick(Time.deltaTime);
_stopwatch.Stop();

info.AddLateUpdateDuration(_stopwatch.Elapsed.TotalMilliseconds);
}
}
else
{
tickable.LateTick(Time.deltaTime);
}
}

public static void AddEngine(IEngine engine)
{
if (engineInfos.ContainsKey(engine.GetType()) == false)


+ 1
- 1
ECS/note.txt View File

@@ -1,7 +1,7 @@
systems do not hold component data, but only system states
systems cannot be injected
systems are SRP and OCP
systems communicates between component, mediators, producer/consumer, Svelto.ECS.Example.Observers. producer/consumer and observers must be defined in the layer of the engine.
systems communicates between component, mediators, producer/consumer, observers. producer/consumer and observers must be defined in the layer of the engine.
systems can have injected dependencies

components don't have logic


Loading…
Cancel
Save