Skip to content

Commit

Permalink
Fixed #54
Browse files Browse the repository at this point in the history
  • Loading branch information
PixeyeHQ committed Jun 28, 2020
1 parent f5ffb58 commit a33968f
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 248 deletions.
115 changes: 0 additions & 115 deletions Editor/SceneProcessors/PostHandlePools.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Editor/SceneProcessors/PostHandlePools.cs.meta

This file was deleted.

16 changes: 8 additions & 8 deletions Runtime/Core/ImplActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Actor Create(string prefabID, Vector3 position = default, bool pooled = f
{
var transform = pooled ? layer.Obj.Create(Pool.Entities, prefabID, position) : layer.Obj.Create(prefabID, position);
var actor = transform.GetActor();
actor.isPooled = pooled;
// actor.isPooled = pooled;

actor.BootstrapCreated(layer);
return actor;
Expand All @@ -39,7 +39,7 @@ public Actor Create(string prefabID, Transform parent, Vector3 position = defaul
? layer.Obj.Create(Pool.Entities, prefabID, parent, position)
: layer.Obj.Create(prefabID, parent, position);
var actor = transform.GetActor();
actor.isPooled = pooled;
// actor.isPooled = pooled;
actor.BootstrapCreated(layer);
return actor;
}
Expand All @@ -49,7 +49,7 @@ public Actor Create(string prefabID, ModelComposer model, Vector3 position = def
{
var transform = pooled ? layer.Obj.Create(Pool.Entities, prefabID, position) : layer.Obj.Create(prefabID, position);
var actor = transform.GetActor();
actor.isPooled = pooled;
// actor.isPooled = pooled;

actor.BootstrapCreated(layer, model);
return actor;
Expand All @@ -63,7 +63,7 @@ public Actor Create(string prefabID, Transform parent, ModelComposer model, Vect
? layer.Obj.Create(Pool.Entities, prefabID, parent, position)
: layer.Obj.Create(prefabID, parent, position);
var actor = transform.GetActor();
actor.isPooled = pooled;
//actor.isPooled = pooled;

actor.BootstrapCreated(layer, model);
return actor;
Expand All @@ -78,7 +78,7 @@ public Actor Create(GameObject prefab, Vector3 position = default, bool pooled =
{
var transform = pooled ? layer.Obj.Create(Pool.Entities, prefab, position) : layer.Obj.Create(prefab, position);
var actor = transform.GetActor();
actor.isPooled = pooled;
//actor.isPooled = pooled;

actor.BootstrapCreated(layer);
return actor;
Expand All @@ -90,7 +90,7 @@ public Actor Create(GameObject prefab, Transform parent, Vector3 position = defa
var transform =
pooled ? layer.Obj.Create(Pool.Entities, prefab, parent, position) : layer.Obj.Create(prefab, parent, position);
var actor = transform.GetActor();
actor.isPooled = pooled;
//actor.isPooled = pooled;

actor.BootstrapCreated(layer);
return actor;
Expand All @@ -101,7 +101,7 @@ public Actor Create(GameObject prefab, ModelComposer model, Vector3 position = d
{
var transform = pooled ? layer.Obj.Create(Pool.Entities, prefab, position) : layer.Obj.Create(prefab, position);
var actor = transform.GetActor();
actor.isPooled = pooled;
//actor.isPooled = pooled;

actor.BootstrapCreated(layer, model);
return actor;
Expand All @@ -114,7 +114,7 @@ public Actor Create(GameObject prefab, Transform parent, ModelComposer model, Ve
var transform =
pooled ? layer.Obj.Create(Pool.Entities, prefab, parent, position) : layer.Obj.Create(prefab, parent, position);
var actor = transform.GetActor();
actor.isPooled = pooled;
//actor.isPooled = pooled;

actor.BootstrapCreated(layer, model);
return actor;
Expand Down
8 changes: 4 additions & 4 deletions Runtime/Core/ImplObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public T Create<T>(GameObject prefab, Vector3 startPosition = default, Quaternio
public Transform Create(int poolID, GameObject prefab, Transform parent, Vector3 startPosition = default,
Quaternion startRotation = default)
{
var tr = layer.pool.pools[poolID].Spawn(prefab, startPosition, startRotation, parent).transform;
var tr = layer.Pool.pools[poolID].Spawn(prefab, startPosition, startRotation, parent).transform;
SceneManager.MoveGameObjectToScene(tr.gameObject, layer.Scene);
return tr;
}
Expand All @@ -130,7 +130,7 @@ public T Create<T>(int poolID, GameObject prefab, Vector3 startPosition = defaul
public Transform Create(int poolID, GameObject prefab, Vector3 startPosition = default,
Quaternion startRotation = default)
{
var tr = layer.pool.pools[poolID].Spawn(prefab, startPosition, startRotation).transform;
var tr = layer.Pool.pools[poolID].Spawn(prefab, startPosition, startRotation).transform;

SceneManager.MoveGameObjectToScene(tr.gameObject, layer.Scene);
//tr.SetAsLastSibling();
Expand Down Expand Up @@ -174,15 +174,15 @@ public T Create<T>(string prefabID, Vector3 startPosition = default, Quaternion
public Transform Create(int poolID, string prefabID, Vector3 startPosition = default,
Quaternion startRotation = default)
{
var tr = layer.pool.pools[poolID].Spawn(Box.Get<GameObject>(prefabID), startPosition, startRotation).transform;
var tr = layer.Pool.pools[poolID].Spawn(Box.Get<GameObject>(prefabID), startPosition, startRotation).transform;
SceneManager.MoveGameObjectToScene(tr.gameObject, layer.Scene);
return tr;
}

public Transform Create(int poolID, string prefabID, Transform parent, Vector3 startPosition = default,
Quaternion startRotation = default)
{
return layer.pool.pools[poolID].Spawn(Box.Get<GameObject>(prefabID), startPosition, startRotation, parent)
return layer.Pool.pools[poolID].Spawn(Box.Get<GameObject>(prefabID), startPosition, startRotation, parent)
.transform;
}

Expand Down
2 changes: 1 addition & 1 deletion Runtime/Core/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public sealed class Layer
public int ID => id;

internal GameObject gameObject;
internal Pool pool;
public Pool Pool;

internal int id;
internal bool isReleasing = true;
Expand Down
93 changes: 4 additions & 89 deletions Runtime/Core/LayerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Pixeye.Actors
{
/// A scene point of entry. The developer defines here scene dependencies and processing that will work on the scene.
public abstract class Layer<T> : MonoBehaviour, IPooledLayer
public abstract class Layer<T> : MonoBehaviour
{
public static ProcessorUpdate Engine => InstanceInternal.self.Engine;
public static ImplEntity Entity => InstanceInternal.self.Entity;
Expand Down Expand Up @@ -52,10 +52,7 @@ void Start()

void ActivateActors()
{
for (var i = 0; i < nodes.Count; i++)
nodes[i].Populate(self);



var objs = gameObject.scene.GetRootGameObjects();
foreach (var obj in objs)
{
Expand Down Expand Up @@ -145,7 +142,7 @@ void Bootstrap()
self.processorCoroutine = new ProcessorCoroutine();
self.processorCoroutine.Bootstrap(self);

self.pool = Add<Pool>();
self.Pool = Add<Pool>();
self.Obj = Add<ImplObj>();

self.processorSignals = Add<ProcessorSignals>();
Expand Down Expand Up @@ -340,88 +337,6 @@ IEnumerator CoDelay()
public static void RemoveSignal(object signal) => InstanceInternal.self.processorSignals.Remove(signal);

#endregion


#region POOLING

[SerializeField, HideInInspector]
internal List<PoolNode> nodes = new List<PoolNode>();
#if UNITY_EDITOR
void IPooledLayer.ClearNodes()
{
for (int i = 0; i < nodes.Count; i++)
{
var n = nodes[i];
n.createdObjs.Clear();
n.prefab = null;
}

nodes.Clear();
}

void IPooledLayer.AddToNode(GameObject prefab, GameObject instance, int pool)
{
var id = prefab.GetInstanceID();
var nodesValid = nodes.FindValidNodes(id);
var conditionNodeCreate = true;
var nodesToKill = new List<int>();

for (var i = 0; i < nodesValid.Count; i++)
{
var node = nodes[nodesValid[i]];

var index = node.createdObjs.FindInstanceID(instance);
if (index != -1 && pool != node.pool)
{
node.createdObjs.RemoveAt(index);
}
else if (index == -1 && pool == node.pool)
{
conditionNodeCreate = false;
node.createdObjs.Add(instance);
}

if (index != -1 && pool == node.pool)
{
conditionNodeCreate = false;
}

if (node.createdObjs.Count == 0)
{
node.prefab = null;
nodesToKill.Add(nodesValid[i]);
}
}

for (var i = 0; i < nodesToKill.Count; i++)
{
nodes.RemoveAt(nodesToKill[i]);
}

if (conditionNodeCreate)
{
var node = new PoolNode();
node.id = id;
node.prefab = prefab;
node.pool = pool;
node.createdObjs = new List<GameObject>();
node.createdObjs.Add(instance);

nodes.Add(node);
}
}
#else
// we don't need these in the release so we leave them blank.
void IPooledLayer.ClearNodes()
{
}

void IPooledLayer.AddToNode(GameObject prefab, GameObject instance, int pool)
{

}
#endif

#endregion

}
}
2 changes: 1 addition & 1 deletion Runtime/Helpers/HelperGameObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static void Release(this GameObject o, int poolID = 0)
else
{
var layer = LayerKernel.Layers[o.gameObject.scene.buildIndex];
layer.pool.Despawn(poolID, o);
layer.Pool.Despawn(poolID, o);
}
}

Expand Down
10 changes: 0 additions & 10 deletions Runtime/Interfaces/IPooledLayer.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Runtime/Interfaces/IPooledLayer.cs.meta

This file was deleted.

Loading

0 comments on commit a33968f

Please sign in to comment.