com.artemis.utils.Bag Java Examples

The following examples show how to use com.artemis.utils.Bag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenderSystem.java    From Bomberman_libGdx with MIT License 6 votes vote down vote up
@Override
protected void processSystem() {
    Bag<Entity> entities = getEntities();
    
    Sort sort = Sort.instance();
    sort.sort(entities, new Comparator<Entity>() {
        @Override
        public int compare(Entity o1, Entity o2) {
            Transform t1 = mTransform.get(o1);
            Transform t2 = mTransform.get(o2);
            if (t1.z < t2.z) {
                return 1;
            }
            else if (t1.z > t2.z) {
                return -1;
            }
            else {
                return 0;
            }
        }
    });
    
    for (Entity e : entities) {
        process(e);
    }
}
 
Example #2
Source File: DispersedIntervalEntitySystem.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the entities processed by this {@link DispersedIntervalEntitySystem}. Warning: do not delete entities from
 * this bag.
 *
 * @return {@link DispersedIntervalEntitySystem}'s entity bag, as matched by {@link Aspect}.
 */
public Bag<Entity> getEntities() {
    if (shouldSyncEntities) {
        int oldSize = entities.size();
        entities.setSize(0);
        IntBag entityIds = subscription.getEntities();
        int[] ids = entityIds.getData();
        for (int i = 0; i < entityIds.size(); i++) {
            entities.add(world.getEntity(ids[i]));
        }

        if (oldSize > entities.size()) {
            Arrays.fill(entities.getData(), entities.size(), oldSize, null);
        }

        shouldSyncEntities = false;
    }

    return entities;
}
 
Example #3
Source File: ProfilerInvocationStrategy.java    From riiablo with Apache License 2.0 5 votes vote down vote up
private void processProfileSystems(Bag<BaseSystem> systems) {
  final Object[] systemsData = systems.getData();
  for (int i = 0, s = systems.size(); s > i; i++) {
    if (disabled.get(i))
      continue;

    updateEntityStates();
    processProfileSystem(profilers[i], (BaseSystem) systemsData[i]);
  }

  updateEntityStates();
}
 
Example #4
Source File: EntityManglerSystem.java    From entity-system-benchmarks with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
	public EntityManglerSystem(long seed, int entityCount) {
		// 4096 entities = 256 compositions, 262144 = 2048
		int entityPermutations = (int)Math.sqrt(entityCount * 16);
		rng = new Random(seed);
		ENTITY_COUNT = entityCount;
		RENEW = ENTITY_COUNT / 4;

		ArrayList<Integer> idsList = new ArrayList<Integer>();
		for (int i = 0; ENTITY_COUNT > i; i++)
			idsList.add(i);
		Collections.shuffle(idsList);
		
		ids = new int[ENTITY_COUNT];
		for (int i = 0; ids.length > i; i++)
			ids[i] = idsList.get(i);
//		ids[i] = (int)(rng.nextFloat() * ENTITY_COUNT);


		types = new Bag<Class<? extends Component>>();
		types.add(Comp1.class);
		types.add(Comp2.class);
		types.add(Comp3.class);
		types.add(Comp4.class);
		types.add(Comp5.class);
		types.add(Comp6.class);
		types.add(Comp7.class);
		types.add(Comp8.class);
		types.add(Comp9.class);
		types.add(Comp10.class);
		types.add(Comp11.class);
		types.add(Comp12.class);

		permutations = new Archetype[entityPermutations];

		
		cmp = new int[ENTITY_COUNT * 4];
		for (int i = 0; cmp.length > i; i++)
			cmp[i] = (int)(rng.nextFloat() * permutations.length);
	}
 
Example #5
Source File: EntityManglerSystem.java    From entity-system-benchmarks with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
	public EntityManglerSystem(long seed, int entityCount) {
		// 4096 entities = 256 compositions, 262144 = 2048
		int entityPermutations = (int)Math.sqrt(entityCount * 16);
		rng = new Random(seed);
		ENTITY_COUNT = entityCount;
		RENEW = ENTITY_COUNT / 4;

		ArrayList<Integer> idsList = new ArrayList<Integer>();
		for (int i = 0; ENTITY_COUNT > i; i++)
			idsList.add(i);
		Collections.shuffle(idsList);
		
		ids = new int[ENTITY_COUNT];
		for (int i = 0; ids.length > i; i++)
			ids[i] = idsList.get(i);
//		ids[i] = (int)(rng.nextFloat() * ENTITY_COUNT);
		
		
		types = new Bag<Class<? extends Component>>();
		types.add(Comp1.class);
		types.add(Comp2.class);
		types.add(Comp3.class);
		types.add(Comp4.class);
		types.add(Comp5.class);
		types.add(Comp6.class);
		types.add(Comp7.class);
		types.add(Comp8.class);
		types.add(Comp9.class);
		types.add(Comp10.class);
		types.add(Comp11.class);
		types.add(Comp12.class);

		permutations = new Archetype[entityPermutations];

		
		cmp = new int[ENTITY_COUNT * 4];
		for (int i = 0; cmp.length > i; i++)
			cmp[i] = (int)(rng.nextFloat() * permutations.length);
	}
 
Example #6
Source File: EntityManglerSystem.java    From entity-system-benchmarks with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public EntityManglerSystem(long seed, int entityCount) {
	// 4096 entities = 256 compositions, 262144 = 2048
	entityPermutations = (int)Math.sqrt(entityCount * 16);
	rng = new Random(seed);
	ENTITY_COUNT = entityCount;
	RENEW = ENTITY_COUNT / 4;

	ArrayList<Integer> idsList = new ArrayList<Integer>();
	for (int i = 0; ENTITY_COUNT > i; i++)
		idsList.add(i);
	Collections.shuffle(idsList);
	
	ids = new int[ENTITY_COUNT];
	for (int i = 0; ids.length > i; i++)
		ids[i] = idsList.get(i);

	types = new Bag<Class<? extends Component>>();
	types.add(Comp1.class);
	types.add(Comp2.class);
	types.add(Comp3.class);
	types.add(Comp4.class);
	types.add(Comp5.class);
	types.add(Comp6.class);
	types.add(Comp7.class);
	types.add(Comp8.class);
	types.add(Comp9.class);
	types.add(Comp10.class);
	types.add(Comp11.class);
	types.add(Comp12.class);

	permutations = new Bag[entityPermutations];

	cmp = new int[ENTITY_COUNT * 4];
	for (int i = 0; cmp.length > i; i++)
		cmp[i] = (int)(rng.nextFloat() * permutations.length);
}
 
Example #7
Source File: EntityManglerSystem.java    From entity-system-benchmarks with Apache License 2.0 5 votes vote down vote up
@Override
protected void initialize() {
	for (int i = 0; permutations.length > i; i++) {
		Bag<Class<? extends Component>> components = new Bag<Class<? extends Component>>();
		for (int classIndex = 0, s = (int)(rng.nextFloat() * 7) + 3; s > classIndex; classIndex++) {
			components.add(types.get((int)(rng.nextFloat() * types.size())));
		}
		permutations[i] = components;
	}
	
	for (int i = 0; ENTITY_COUNT > i; i++)
		createEntity();
}
 
Example #8
Source File: EntityManglerSystem.java    From entity-system-benchmarks with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private final void createEntity() {
	Entity e = world.createEntity();
	Bag<Class<? extends Component>> components = permutations[cmp[cmpIndex++]];
	if (cmpIndex == cmp.length) cmpIndex = 0;
	
	Object[] data = components.getData();
	for (int i = 0, s = components.size(); s > i; i++) {
		e.addComponent(newInstance(data[i]));
	}
	e.addToWorld();
}
 
Example #9
Source File: EntityManglerSystem.java    From entity-system-benchmarks with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
	public EntityManglerSystem(long seed, int entityCount) {
		// 4096 entities = 256 compositions, 262144 = 2048
		int entityPermutations = (int)Math.sqrt(entityCount * 16);
		rng = new Random(seed);
		ENTITY_COUNT = entityCount;
		RENEW = ENTITY_COUNT / 4;

		ArrayList<Integer> idsList = new ArrayList<Integer>();
		for (int i = 0; ENTITY_COUNT > i; i++)
			idsList.add(i);
		Collections.shuffle(idsList);
		
		ids = new int[ENTITY_COUNT];
		for (int i = 0; ids.length > i; i++)
			ids[i] = idsList.get(i);
//		ids[i] = (int)(rng.nextFloat() * ENTITY_COUNT);
		
		
		types = new Bag<Class<? extends Component>>();
		types.add(Comp1.class);
		types.add(Comp2.class);
		types.add(Comp3.class);
		types.add(Comp4.class);
		types.add(Comp5.class);
		types.add(Comp6.class);
		types.add(Comp7.class);
		types.add(Comp8.class);
		types.add(Comp9.class);
		types.add(Comp10.class);
		types.add(Comp11.class);
		types.add(Comp12.class);

		permutations = new Archetype[entityPermutations];

		
		cmp = new int[ENTITY_COUNT * 4];
		for (int i = 0; cmp.length > i; i++)
			cmp[i] = (int)(rng.nextFloat() * permutations.length);
	}
 
Example #10
Source File: MdxWorld.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new world
 *
 * @param configuration The configuration to be applied
 */
public MdxWorld(WorldConfiguration configuration) {
    super(configuration);
    renderingSystemsBag = new Bag<>();
    mdxInvocationStrategy = new MdxInvocationStrategy();

    for (BaseSystem system : configuration.systems) {
        if (system instanceof RenderingSystem) {
            renderingSystemsBag.add((RenderingSystem) system);
        }
    }

    setInvocationStrategy(mdxInvocationStrategy);
}
 
Example #11
Source File: MdxInvocationStrategy.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
protected void render(Bag<RenderingSystem> systemsBag, Graphics g) {
    Object[] systems = systemsBag.getData();
    for (int i = 0, s = systemsBag.size(); s > i; i++) {
        if (disabled.get(i)) {
            continue;
        }
        updateEntityStates();

        RenderingSystem system = (RenderingSystem) systems[i];
        system.renderSystem(g);
    }
}