/** * Adds the specified elements to the end of this bag. * <p> * If required, it also increases the capacity of the bag. * </p> * * @param other * elements to be added to this list */ public void addAll(IntBag other) { for (int i = 0; i < other.size(); i++) { add(other.data[i]); } }
/** * Adds the specified elements to the end of this bag. * <p> * If required, it also increases the capacity of the bag. * </p> * * @param other * elements to be added to this list */ public void addAll(IntBag other) { for (int i = 0; i < other.size(); i++) { add(other.data[i]); } }
public void setAll() { array.add("array"); bag.add("bag"); hashSet.add("hashSet"); arrayList.add("arrayList"); list.add("list"); hashMap.put("key", "map"); intBag.add(1); map.put("lock", "unlocked"); objectMap.put("obj", "map"); }
@Override public IntBag read(Json json, JsonValue jsonData, Class type) { recursionLevel++; IntBag bag = new IntBag(); if (recursionLevel == 1) { JsonValue entityArray = jsonData.child; JsonValue entity = entityArray; while (entity != null) { Entity e = json.readValue(Entity.class, entity.child); translatedIds.set(Integer.parseInt(entity.name), e); bag.add(e.getId()); entity = entity.next; } } else { for (JsonValue child = jsonData.child; child != null; child = child.next) { bag.add(json.readValue(Integer.class, child)); } } recursionLevel--; return bag; }
@Override public IntBag read(Json json, JsonValue jsonData, Class type) { recursionLevel++; IntBag bag = new IntBag(); if (recursionLevel == 1) { JsonValue entityArray = jsonData.child; JsonValue entity = entityArray; while (entity != null) { Entity e = json.readValue(Entity.class, entity.child); translatedIds.set(Integer.parseInt(entity.name), e); bag.add(e.getId()); entity = entity.next; } } else { for (JsonValue child = jsonData.child; child != null; child = child.next) { bag.add(json.readValue(Integer.class, child)); } } recursionLevel--; return bag; }
@Override public IntBag read(Json json, JsonValue jsonData, Class type) { recursionLevel++; IntBag bag = new IntBag(); if (recursionLevel == 1) { JsonValue entityArray = jsonData.child; JsonValue entity = entityArray; while (entity != null) { Entity e = json.readValue(Entity.class, entity.child); translatedIds.set(Integer.parseInt(entity.name), e); bag.add(e.getId()); entity = entity.next; } } else { for (JsonValue child = jsonData.child; child != null; child = child.next) { bag.add(json.readValue(Integer.class, child)); } } recursionLevel--; return bag; }
/** * Decodes the set bits as pairs of <code>entity id</code> and * {@link World#compositionId(int) compositionId}. The * destination{@link IntBag} is reset before the bits are * transposed. * * @param out decoded ints end up here * @return Same as out */ public IntBag toIntBagIdCid(ComponentManager cm, IntBag out) { out.setSize(0); if (isEmpty()) return out; for (int id = nextSetBit(0); id >= 0; id = nextSetBit(id + 1)) { out.add(id); out.add(cm.getIdentity(id)); } return out; }
void configureWith(int count) { poolIndex = 0; pool.setSize(0); pool.ensureCapacity(count); for (int i = 0; i < count; i++) { pool.add(world.create(archetype)); } Arrays.sort(pool.getData(), 0, pool.size()); }
void configureWith(int count) { poolIndex = 0; pool.setSize(0); pool.ensureCapacity(count); for (int i = 0; i < count; i++) { pool.add(world.create(archetype)); } Arrays.sort(pool.getData(), 0, pool.size()); }
static IntBag findPoint (TestData data, IntBag fill, Bag<TestData> testData) { for (int i = 0; i < testData.size(); i++) { TestData test = testData.get(i); if (test.contains(data.x, data.y)) { fill.add(test.id); } } fill.clear(); return fill; }
static IntBag find (TestData data, IntBag fill, Bag<TestData> testData) { for (int i = 0; i < testData.size(); i++) { TestData test = testData.get(i); if (test.overlaps(data.x, data.y, data.width, data.height)) { fill.add(test.id); } } fill.clear(); return fill; } }
@Override public IntBag read (Kryo kryo, Input input, Class<IntBag> aClass) { recursionLevel++; IntBag bag = new IntBag(); int count = input.readInt(); if (recursionLevel == 1) { for (int i = 0; i < count; i++) { int oldId = input.readInt(); Entity e = kryo.readObject(input, Entity.class); translatedIds.set(oldId, e); bag.add(e.getId()); } } else { for (int i = 0; i < count; i++) { bag.add(input.readInt()); } } recursionLevel--; return bag; }
@Override public IntBag read (Kryo kryo, Input input, Class<IntBag> aClass) { recursionLevel++; IntBag bag = new IntBag(); int count = input.readInt(); if (recursionLevel == 1) { for (int i = 0; i < count; i++) { int oldId = input.readInt(); Entity e = kryo.readObject(input, Entity.class); translatedIds.set(oldId, e); bag.add(e.getId()); } } else { for (int i = 0; i < count; i++) { bag.add(input.readInt()); } } recursionLevel--; return bag; }
/** * Decodes the set bits as integers. The destination * {@link IntBag} is reset before the bits are transposed. * * @param out decoded ints end up here * @return Same as out */ public IntBag toIntBag(IntBag out) { out.setSize(0); if (isEmpty()) return out; for (int id = nextSetBit(0); id >= 0; id = nextSetBit(id + 1)) { out.add(id); } return out; }
/** * Returns entity ids of entities that are inside {@link QuadTree}s that contain given point * * Returned entities must be filtered further as these results are not exact */ public IntBag get (IntBag fill, float x, float y) { if (bounds.contains(x, y)) { if (nodes[0] != null) { int index = indexOf(x, y, 0, 0); if (index != OUTSIDE) { nodes[index].get(fill, x, y, 0, 0); } } for (int i = 0; i < containers.size(); i++) { fill.add(containers.get(i).eid); } } return fill; }
/** * Returns entity ids of entities that are inside {@link QuadTree}s that contain given point * * Returned entities must be filtered further as these results are not exact */ public IntBag get (IntBag fill, float x, float y) { if (bounds.contains(x, y)) { if (nodes[0] != null) { int index = indexOf(x, y, 0, 0); if (index != OUTSIDE) { nodes[index].get(fill, x, y, 0, 0); } } for (int i = 0; i < containers.size(); i++) { fill.add(containers.get(i).eid); } } return fill; }
/** * Returns entity ids of entities that bounds contain given point */ public IntBag getExact (IntBag fill, float x, float y) { if (bounds.contains(x, y)) { if (nodes[0] != null) { int index = indexOf(x, y, 0, 0); if (index != OUTSIDE) { nodes[index].getExact(fill, x, y, 0, 0); } } for (int i = 0; i < containers.size(); i++) { Container c = containers.get(i); if (c.contains(x, y)) { fill.add(c.eid); } } } return fill; }
/** * Returns entity ids of entities that bounds contain given point */ public IntBag getExact (IntBag fill, float x, float y) { if (bounds.contains(x, y)) { if (nodes[0] != null) { int index = indexOf(x, y, 0, 0); if (index != OUTSIDE) { nodes[index].getExact(fill, x, y, 0, 0); } } for (int i = 0; i < containers.size(); i++) { Container c = containers.get(i); if (c.contains(x, y)) { fill.add(c.eid); } } } return fill; }
/** * Returns entity ids of entities that are inside {@link QuadTree}s that overlap given bounds * * Returned entities must be filtered further as these results are not exact */ public IntBag get (IntBag fill, float x, float y, float width, float height) { if (bounds.overlaps(x, y, width, height)) { if (nodes[0] != null) { int index = indexOf(x, y, width, height); if (index != OUTSIDE) { nodes[index].get(fill, x, y, width, height); } else { // if test bounds don't fully fit inside a node, we need to check them all for (int i = 0; i < nodes.length; i++) { nodes[i].get(fill, x, y, width, height); } } } for (int i = 0; i < containers.size(); i++) { Container c = containers.get(i); fill.add(c.eid); } } return fill; }
/** * Returns entity ids of entities that overlap given bounds */ public IntBag getExact (IntBag fill, float x, float y, float width, float height) { if (bounds.overlaps(x, y, width, height)) { if (nodes[0] != null) { int index = indexOf(x, y, width, height); if (index != OUTSIDE) { nodes[index].getExact(fill, x, y, width, height); } else { // if test bounds don't fully fit inside a node, we need to check them all for (int i = 0; i < nodes.length; i++) { nodes[i].getExact(fill, x, y, width, height); } } } for (int i = 0; i < containers.size(); i++) { Container c = containers.get(i); if (c.overlaps(x, y, width, height)) { fill.add(c.eid); } } } return fill; }