public bool Deallocate(Entity entity) { if (!IsValid(entity)) { return(false); } (int index, byte generation) = EntityUtil.DecomposeKey(entity); // Bump generation so the Entity key remains stale for a long time even // when the index portion is recycled. // if (++_generations[index] == 0) { // Ensure generation can never be 0, so we can find // invalid keys easily. // _generations[index] = 1; } // Recycle index. // _freeIndices.Add(index); return(true); }
public bool IsValid(Entity entity) { (int index, byte generation) = EntityUtil.DecomposeKey(entity); return(index >= 0 && index < _generations.Count && _generations[index] == generation); }