Browse Source

Breaking change: the Sequencer now accept int and not enum to avoid boxing

improve sequencer code
add comments
tags/Rel2b2
sebas77 6 years ago
parent
commit
21dcf2d39d
2 changed files with 21 additions and 10 deletions
  1. +5
    -5
      Svelto.ECS/Context/Factories/GameObjectFactory.cs
  2. +16
    -5
      Svelto.ECS/ECS/Sequencer.cs

+ 5
- 5
Svelto.ECS/Context/Factories/GameObjectFactory.cs View File

@@ -39,17 +39,17 @@ namespace Svelto.Context
return go;
}

/// <summary>
/// Register a prefab to be built later using a string ID.
/// </summary>
/// <param name="prefab">original prefab</param>
virtual public GameObject Build(GameObject prefab)
public virtual GameObject Build(GameObject prefab)
{
var copy = Object.Instantiate(prefab) as GameObject;

return copy;
}

/// <summary>
/// Register a prefab to be built later using a string ID.
/// </summary>
/// <param name="prefab">original prefab</param>
public void RegisterPrefab(GameObject prefab, string prefabName, GameObject parent = null)
{
var objects = new GameObject[2];


+ 16
- 5
Svelto.ECS/ECS/Sequencer.cs View File

@@ -1,14 +1,25 @@
using System;
using Steps = System.Collections.Generic.Dictionary<Svelto.ECS.IEngine, System.Collections.Generic.Dictionary<System.Enum, Svelto.ECS.IStep[]>>;
using System.Collections.Generic;

namespace Svelto.ECS
{
public class Steps : Dictionary<IEngine, Dictionary<int, IStep[]>>
{}

public class To : Dictionary<int, IStep[]>
{
public void Add(IStep engine)
{
Add(Condition.always, new [] {engine});
}
}
public interface IStep
{ }

public interface IStep<T>:IStep
{
void Step(ref T token, Enum condition);
void Step(ref T token, int condition);
}

public class Sequencer
@@ -23,7 +34,7 @@ namespace Svelto.ECS
Next(engine, ref param, Condition.always);
}

public void Next<T>(IEngine engine, ref T param, Enum condition)
public void Next<T>(IEngine engine, ref T param, int condition)
{
var tos = _steps[engine];
var steps = tos[condition];
@@ -37,8 +48,8 @@ namespace Svelto.ECS
}

//you can inherit from Condition and add yours
public enum Condition
public class Condition
{
always
public const int always = 0;
}
}

Loading…
Cancel
Save