Java Code Examples for com.artemis.World#process()

The following examples show how to use com.artemis.World#process() . 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: IfElseOperationTest.java    From artemis-odb-orion with Apache License 2.0 6 votes vote down vote up
@Test
public void ifElse_false_test() {
	World world = new World(new WorldConfiguration()
		.setSystem(new OperationSystem()));

	MySingleUseOperation trueOp = operation(MySingleUseOperation.class);
	MySingleUseOperation falseOp = operation(MySingleUseOperation.class);

	ifTrue(false, trueOp).elseDo(falseOp).register(world, world.create());

	world.delta = 1f;
	world.process();

	assertEquals(0, trueOp.timesRun);
	assertEquals(1, falseOp.timesRun);
}
 
Example 2
Source File: IfElseOperationTest.java    From artemis-odb-orion with Apache License 2.0 6 votes vote down vote up
@Test
public void ifElse_true_test() {
	World world = new World(new WorldConfiguration()
		.setSystem(new OperationSystem()));

	MySingleUseOperation trueOp = operation(MySingleUseOperation.class);
	MySingleUseOperation falseOp = operation(MySingleUseOperation.class);

	ifTrue(true, trueOp).elseDo(falseOp).register(world, world.create());

	world.delta = 1f;
	world.process();

	assertEquals(1, trueOp.timesRun);
	assertEquals(0, falseOp.timesRun);
}
 
Example 3
Source File: OperationTest.java    From artemis-odb-orion with Apache License 2.0 6 votes vote down vote up
@Test
public void test_hiearhical_clean_up() {
	World world = new World(new WorldConfiguration()
		.setSystem(OperationSystem.class));

	KillOperation killOperation = killEntity();

	sequence(
		sequence(
			sequence(
				parallel(
					sequence(),
					sequence(killOperation)
				)
			)
		)
	).register(world, world.create());

	world.delta = .25f;
	world.process();

	assertSame(killOperation, killEntity());
	assertNotSame(killOperation, killEntity());
}
 
Example 4
Source File: OperationsPluginTest.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
@Test
public void When_registering_operation_plugin_Should_register_operationsystem() {
    World world = new World(new WorldConfigurationBuilder()
            .dependsOn(OperationsPlugin.class)
            .build());
    Assert.assertNotNull(world.getSystem(OperationSystem.class));
    world.process();
}
 
Example 5
Source File: DelayTickTest.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
@Test
public void test_delay() {
	World w = new World(new WorldConfiguration()
		.setSystem(OperationSystem.class));

	DelayTickOperation op1 = delayTick(1);
	DelayTickOperation op2 = delayTick(2);
	DelayTickOperation op3 = delayTick(1);

	sequence(op1, op2, op3).register(w.createEntity());
	assertEquals(false, op1.isComplete());
	assertEquals(false, op2.isComplete());
	assertEquals(false, op3.isComplete());

	w.delta = .01f;
	w.process();
	assertEquals(true, op1.isComplete());
	assertEquals(false, op2.isComplete());
	assertEquals(false, op3.isComplete());

	w.delta = .01f;
	w.process();
	assertEquals(true, op1.isComplete());
	assertEquals(false, op2.isComplete());
	assertEquals(false, op3.isComplete());

	w.delta = .01f;
	w.process();
	assertEquals(true, op1.isComplete());
	assertEquals(true, op2.isComplete());
	assertEquals(false, op3.isComplete());

	w.delta = .01f;
	w.process();
	assertEquals(true, op1.isComplete());
	assertEquals(true, op2.isComplete());
	assertEquals(true, op3.isComplete());
}
 
Example 6
Source File: OperationTest.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
@Test
public void testWireInjection() {
	World world = new World(new WorldConfiguration()
			.setSystem(new GroupManager())
			.setSystem(new TagManager())
			.setSystem(new OperationSystem()));

	ManagerOperation action = operation(ManagerOperation.class);
	action.register(world, world.create());

	world.process();
	world.process();
}
 
Example 7
Source File: ArtemisBenchmark.java    From ashley with Apache License 2.0 4 votes vote down vote up
private void runWorldTest (World world) {
	for (int i = 0; i < Constants.FRAMES; ++i) {
		world.setDelta(Constants.DELTA_TIME);
		world.process();
	}
}
 
Example 8
Source File: OperationTest.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
private static void process(World world) {
	world.delta = 1f / 60f;
	world.process();
}
 
Example 9
Source File: OperationTest.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
@Test
public void testParallelProcessing() {
	OperationSystem operationSystem = new OperationSystem();
	World world = new World(new WorldConfiguration()
			.setSystem(operationSystem));

	DelayOperation[] ds = new DelayOperation[] {
		delay(0.25f),
		delay(0.25f),
		delay(0.25f),
		delay(0.75f)
	};

	parallel(ds[0], ds[1], ds[2], ds[3]).register(world, world.create());

	world.delta = 0.000001f;
	world.process();

	for (int i = 0; i < ds.length - 1; i++) {
		assertFalse(ds[i].isComplete());
		assertEquals(.25f, ds[i].remaining(), .001f);
	}

	world.delta = 0.15f;
	world.process();

	for (int i = 0; i < ds.length - 1; i++) {
		assertFalse(ds[i].isComplete());
		assertEquals(.25f - 0.15f, ds[i].remaining(), .001f);
	}
	assertEquals(.75f - 0.15f, ds[3].remaining(), .001f);

	world.delta = 0.5f;
	world.process();

	for (int i = 0; i < ds.length - 1; i++) {
		assertTrue(ds[i].isComplete());
		assertEquals(0f, ds[i].remaining(), 0.0001f);
	}
	assertEquals(0.75f - 0.65f, ds[3].remaining(), 0.0001f);
	assertFalse(ds[3].isComplete());

	world.delta = 0.5f;
	world.process();
	world.process();

	// orion should be evicted from the system here.
	assertEquals(0, operatives(world).size());
}
 
Example 10
Source File: OperationTest.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
@Test
	public void testSequentialProcessing() {

		OperationSystem operationSystem = new OperationSystem();
		World world = new World(new WorldConfiguration()
				.setSystem(operationSystem));

		DelayOperation[] ds = new DelayOperation[] {
			delay(0.25f),
			delay(0.25f),
			delay(0.25f),
			delay(0.25f)
		};

		sequence(ds[0], ds[1], ds[2], ds[3]).register(world, world.create());

		world.delta = 0;
		world.process();

		assertEquals(1, operatives(world).size());

		for (int i = 0; i < ds.length; i++) {
			assertFalse(ds[i].isComplete());
			assertEquals(.25f, ds[i].remaining(), .001f);
		}

		world.delta = 0.15f;
		world.process();

		assertFalse(ds[0].isComplete());
		assertEquals(.25f - 0.15f, ds[0].remaining(), .001f);
		for (int i = 1; i < ds.length; i++) {
			assertFalse(ds[i].isComplete());
			assertEquals(.25f, ds[i].remaining(), .001f);
		}

		world.delta = 0.75f;
		world.process();

		for (int i = 0; i < ds.length - 1; i++) {
			assertTrue(ds[i].isComplete());
			assertEquals(0f, ds[i].remaining(), 0.0000000f);
		}

		assertFalse(ds[3].isComplete());
		assertEquals(.25f - 0.15f, ds[3].remaining(), .001f);

		world.delta = 0.25f;
		world.process();
		world.process();

		// orion should be evicted from the system here.
		assertEquals(0, operatives(world).size());

//		assertEquals(0, operationSystem.getOperations().size);
	}
 
Example 11
Source File: OperationTestUtil.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
public static void process(World world) {
	world.delta = 1f / 60f;
	world.process();
}
 
Example 12
Source File: JsonSerializationTest.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
@Test
public void save_load_entity_with_operation() {
	String[] string = new String[1];
	int[] entity = new int[1];

	World world = new World(new WorldConfiguration()
		.register("string", string)
		.register("entity", entity)
		.setSystem(OperationSystem.class)
		.setSystem(WorldSerializationManager.class));

	WorldSerializationManager worldSerializer =
		world.getSystem(WorldSerializationManager.class);

	JsonArtemisSerializer backend = new JsonArtemisSerializer(world);
	backend.prettyPrint(true);
	InterpolationSerializer.registerAll(backend);
	backend.register(OperationTree.class, new OperationTreeSerializer());
	worldSerializer.setSerializer(backend);

	int e0 = world.create();
	int e1 = world.create();

	process(world);


	assertEquals(null, string[0]);
	assertEquals(0, entity[0]);

	sequence(
		delayTick(1),
		operation(EntityWriterOperation.class)
	).register(world, e1);

	process(world);
	String saveE1 = save(world, all(Operative.class));

	process(world);

	assertNotNull(string[0]);
	assertEquals(1, entity[0]);

	ByteArrayInputStream is = new ByteArrayInputStream(
			saveE1.getBytes(StandardCharsets.UTF_8));
	SaveFileFormat load = worldSerializer.load(is, SaveFileFormat.class);

	int e2 = load.entities.get(0);
	assertEquals(1, load.entities.size());
	assertNotEquals(e1, e2);

	// making sure values haven't changed due to loading
	assertNotNull(string[0]);
	assertEquals(1, entity[0]);

	world.process();

	assertNotNull(string[0]);
	assertEquals(e2, entity[0]);
}
 
Example 13
Source File: VoidEntityOperationTest.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
@Test
public void test_when_killing_entities() {
	World w = new World(new WorldConfiguration()
		.setSystem(new OperationSystem()));

	HiThereOperation op = operation(HiThereOperation.class).s("hi");
	HiThereOperation op2 = operation(HiThereOperation.class).s("hepp");

	HiThereOperation eOp = operation(HiThereOperation.class).s("eOp");
	HiThereOperation eOp2 = operation(HiThereOperation.class).s("eOp2");

	sequence(
		// 1
		delayTick(1),

		// 2
		op,
		delayTick(1),

		// 3
		delayTick(1),
		op2,

		// 4
		delayTick(1)
	).register(w);

	int entity = w.create();
	sequence(
		// 1
		delayTick(1),

		// 2
		eOp,
		delayTick(1),

		// 3
		delayTick(1),
		eOp2,

		// 4
		delayTick(1)
	).register(w, entity);

			// 1
	w.delta = .1f;
	w.process();

	assertEquals("hi", op.s);
	assertEquals("hepp", op2.s);
	assertEquals("eOp", eOp.s);
	assertEquals("eOp2", eOp2.s);

	// 2
	w.delta = .1f;
	w.process();

	assertEquals("hi!!!", op.s);
	assertEquals("hepp", op2.s);
	assertEquals("eOp!!!", eOp.s);
	assertEquals("eOp2", eOp2.s);

	// 3
	w.delta = .1f;
	w.delete(entity);
	w.process();

	assertEquals("hi!!!", op.s);
	assertEquals("hepp", op2.s);
	assertEquals(null, eOp.s); // reclaimed
	assertEquals(null, eOp2.s);

	w.delta = .1f;
	w.process(); // 4

	assertEquals("hi!!!", op.s);
	assertEquals("hepp!!!", op2.s);
	assertEquals(null, eOp.s); // reclaimed
	assertEquals(null, eOp2.s);
}
 
Example 14
Source File: ExecutorEndTest.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
@Test
public void end_test() {
	World world = new World(new WorldConfiguration()
		.setSystem(OperationSystem.class));

	FiniteOperation fo = operation(FiniteOperation.class);

	fo.register(world, world.create());

	world.process();

	assertEquals(1, fo.n);

	world.process();

	assertEquals(2, fo.n);

	world.process();

	assertEquals(-1, fo.n);
}
 
Example 15
Source File: KillOperationTest.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
@Test
public void kill_entity() {
	World world = new World(
		new WorldConfiguration()
			.setSystem(OperationSystem.class));

	EntityManager em = world.getEntityManager();

	int id1 = world.create();
	int id2 = world.create();
	int id3 = world.create();

	assertTrue(em.isActive(id1));
	assertTrue(em.isActive(id2));
	assertTrue(em.isActive(id3));

	// entity dies immediately
	killEntity().register(world, id1);


	// delete on 2nd frame
	sequence(
		delay(.25f),
		killEntity()
	).register(world, id2);

	// delete on 2nd frame
	sequence(
		delay(.25f),
		killEntity(),
		delay(.25f),
		operation(ThrowExceptionOperation.class)
	).register(world, id3);

	world.delta = .1f;
	world.process();

	assertFalse(em.isActive(id1));
	assertTrue(em.isActive(id2));
	assertTrue(em.isActive(id3));

	world.delta = .25f;
	world.process();

	assertFalse(em.isActive(id2));
	assertFalse(em.isActive(id3));

	world.delta = .25f;
	world.process();

	assertFalse(em.isActive(id3));
}
 
Example 16
Source File: IfElseOperationTest.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
@Test
public void ifFalse_test() {
	World world = new World(new WorldConfiguration()
		.setSystem(new OperationSystem()));

	MySingleUseOperation falseOp = operation(MySingleUseOperation.class);

	ifFalse(false, falseOp).register(world, world.create());

	world.delta = 1f;
	world.process();

	assertEquals(1, falseOp.timesRun);

	world.process();

	ifFalse(false, null).register(world, world.create());
	ifFalse(true, null).register(world, world.create());

	world.process();
	world.delta = 1f;
}
 
Example 17
Source File: IfElseOperationTest.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
@Test
public void ifTrue_test() {
	World world = new World(new WorldConfiguration()
		.setSystem(new OperationSystem()));

	MySingleUseOperation trueOp = operation(MySingleUseOperation.class);

	ifTrue(true, trueOp).register(world, world.create());

	world.delta = 1f;
	world.process();

	assertEquals(1, trueOp.timesRun);

	world.process();

	ifTrue(true, null).register(world, world.create());
	ifTrue(false, null).register(world, world.create());

	world.process();
	world.delta = 1f;
}