IntBag.prototype.size=0; IntBag.prototype.clone = function() { var clone = new IntBag(); this.each(function(i, count) { clone.add(i, count);
/** * Get all subscribed entities of a subscriber. * * @param subscriber subscriber * @return all subscribed entities of a subscriber. */ public IntBag getEntitiesOf(T subscriber) { IntBag entities = subscriberEntities.get(subscriber); if (entities == null) { entities = new IntBag(); } return entities; }
public ImmutableIntBag getEntityIds(final String group) { IntBag identities = identitiesByGroup.get(group); if (identities == null) { identities = new IntBag(); identitiesByGroup.put(group, identities); } return identities; }
public ImmutableIntBag getEntityIds(final String group) { IntBag identities = identitiesByGroup.get(group); if (identities == null) { identities = new IntBag(); identitiesByGroup.put(group, identities); } return identities; }
public static void main(String[] args) { Scanner scan = new Scanner(System.in); int choice, size; System.out.println("Enter the size of an array : "); size = scan.nextInt(); ArrayList<Integer> bag = new ArrayList<Integer>(); // arrraylists do not have a size. They automatically expand or decrease IntBag intBag = new IntBag(bag, 30); // creates a new IntBag object }
IntBag bag = new IntBag(new ArrayList<Integer>(), 10); bag.setBag(new ArrayList<Integer>())
IntBag xNeighbors = new IntBag(8); IntBag yNeighbors = new IntBag(8); // Get moore neighbors Bag neigh = s.protonLayer.getMooreNeighbors(location.getX(), location.getY(), 1, Grid2D.BOUNDED, new Bag(), xNeighbors, yNeighbors ); for (int i = 0; i < xNeighbors.numObjs; i++) { System.out.print(" x = " + xNeighbors.get(i)); System.out.println(" : y = " + yNeighbors.get(i));}
public SaveFileFormat(IntBag entities) { this.entities = (entities != null) ? entities : new IntBag(); componentIdentifiers = new ComponentIdentifiers(); metadata = new Metadata(); metadata.version = Metadata.LATEST; }
public SaveFileFormat(IntBag entities) { this.entities = (entities != null) ? entities : new IntBag(); componentIdentifiers = new ComponentIdentifiers(); metadata = new Metadata(); metadata.version = Metadata.LATEST; }
@Setup(Level.Iteration) public void setup() { quadTree = new QuadTree(0, 0, treeSize, treeSize); testData = new Bag<>(entities); fill = new IntBag(); searchData = new Bag<>(1000); Random random = new Random(0); for (int id = 0; id < entities; id++) { TestData data = new TestData(); data.id = id; data.width = 0.025f + random.nextFloat() * 0.075f; data.height = 0.025f + random.nextFloat() * 0.075f; data.x = random.nextFloat() * (treeSize - data.width); data.y = random.nextFloat() * (treeSize - data.width); testData.add(data); quadTree.insert(data.id, data.x, data.y, data.width, data.height); } for (int id = 0; id < 1000; id++) { TestData search = new TestData(); search.width = 0.1f + random.nextFloat() * (treeSize * searchScale); search.height = 0.1f + random.nextFloat() * (treeSize * searchScale); search.x = random.nextFloat() * (treeSize - search.width); search.y = random.nextFloat() * (treeSize - search.height); searchData.add(search); } }
/** * Set the group of the entity. * * @param group group to add the entity into * @param e entity to add into the group */ public void add(Entity e, String group) { Bag<Entity> entities = entitiesByGroup.get(group); if (entities == null) { entities = new Bag<>(); entitiesByGroup.put(group, entities); } IntBag identities = identitiesByGroup.get(group); if (identities == null) { identities = new IntBag(); identitiesByGroup.put(group, identities); } if (!entities.contains(e)) { entities.add(e); identities.add(e.getId()); } Bag<String> groups = groupsByEntity.get(e); if (groups == null) { groups = new Bag<>(); groupsByEntity.put(e, groups); } if (!groups.contains(group)) { groups.add(group); } }
/** * Set the group of the entity. * * @param group group to add the entity into * @param e entity to add into the group */ public void add(Entity e, String group) { Bag<Entity> entities = entitiesByGroup.get(group); if (entities == null) { entities = new Bag<>(); entitiesByGroup.put(group, entities); } IntBag identities = identitiesByGroup.get(group); if (identities == null) { identities = new IntBag(); identitiesByGroup.put(group, identities); } if (!entities.contains(e)) { entities.add(e); identities.add(e.getId()); } Bag<String> groups = groupsByEntity.get(e); if (groups == null) { groups = new Bag<>(); groupsByEntity.put(e, groups); } if (!groups.contains(group)) { groups.add(group); } }
@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; }
/** * Subscribe T to entity. * <p/> * Does nothing if already subscribed. * * @param subscriber subscriber * @param entityId entity to subscribe. */ public void subscribe(T subscriber, int entityId) { // hook subscriber to entity. IntBag entities = subscriberEntities.get(subscriber); if (entities == null) { entities = new IntBag(); subscriberEntities.put(subscriber, entities); } if (!entities.contains(entityId)) { entities.add(entityId); } // hook entity to subscriber. Bag<T> subscribers = entitySubscribers.get(entityId); if (subscribers == null) { subscribers = new Bag<>(); entitySubscribers.set(entityId, subscribers); } if (!subscribers.contains(subscriber)) { subscribers.add(subscriber); } }
EntitySubscription(World world, Aspect.Builder builder) { extra = new SubscriptionExtra(builder.build(world), builder); activeEntityIds = new BitVector(); entities = new IntBag(); insertedIds = new BitVector(); removedIds = new BitVector(); EntityManager em = world.getEntityManager(); em.registerEntityStore(activeEntityIds); em.registerEntityStore(insertedIds); em.registerEntityStore(removedIds); }
EntitySubscription(World world, Aspect.Builder builder) { extra = new SubscriptionExtra(builder.build(world), builder); activeEntityIds = new BitVector(); entities = new IntBag(); insertedIds = new BitVector(); removedIds = new BitVector(); EntityManager em = world.getEntityManager(); em.registerEntityStore(activeEntityIds); em.registerEntityStore(insertedIds); em.registerEntityStore(removedIds); }
@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; }