From 9ae5e459b437d7a51bfc48283cf5cd20e82989f9 Mon Sep 17 00:00:00 2001 From: David Saltares Date: Mon, 9 Nov 2015 09:29:37 +0000 Subject: [PATCH] Does not allocate memory inside Engine.updateFamilyMembership() #189 --- ashley/src/com/badlogic/ashley/core/Engine.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ashley/src/com/badlogic/ashley/core/Engine.java b/ashley/src/com/badlogic/ashley/core/Engine.java index d9026160..82e38a94 100644 --- a/ashley/src/com/badlogic/ashley/core/Engine.java +++ b/ashley/src/com/badlogic/ashley/core/Engine.java @@ -68,6 +68,8 @@ public class Engine { private ComponentOperationPool componentOperationsPool; private Array componentOperations; private ComponentOperationHandler componentOperationHandler; + + private BitsPool bitsPool = new BitsPool(); public Engine(){ entities = new Array(false, 16); @@ -322,8 +324,8 @@ public void update(float deltaTime){ private void updateFamilyMembership (Entity entity, boolean removing) { // Find families that the entity was added to/removed from, and fill // the bitmasks with corresponding listener bits. - Bits addListenerBits = new Bits(); - Bits removeListenerBits = new Bits(); + Bits addListenerBits = bitsPool.obtain(); + Bits removeListenerBits = bitsPool.obtain(); for (Family family : entityListenerMasks.keys()) { final int familyIndex = family.getIndex(); @@ -359,6 +361,8 @@ private void updateFamilyMembership (Entity entity, boolean removing) { ((EntityListenerData)items[i]).listener.entityAdded(entity); } + addListenerBits.clear(); + removeListenerBits.clear(); entityListeners.end(); notifying = false; } @@ -556,4 +560,11 @@ protected EntityOperation newObject() { return new EntityOperation(); } } + + private static class BitsPool extends Pool { + @Override + protected Bits newObject () { + return new Bits(); + } + } }