com.artemis.WorldConfiguration Java Examples

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

	int entityId = world.create();

	SequenceOperation seq = sequence(
		delayTick(1),
		operation(MySingleUseOperation.class)
	);
	seq.register(world, entityId);

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

	process(world);
	assertEquals(0, operatives(world).size());
	assertSame(seq, sequence());
}
 
Example #5
Source File: RepeatOperationTest.java    From artemis-odb-orion with Apache License 2.0 6 votes vote down vote up
@Test
public void repeated_operations_are_recycled() {
	IntArray instances = new IntArray();

	World world = new World(
		new WorldConfiguration()
			.register("instances", instances)
			.setSystem(OperationSystem.class));

	repeat(100,
		operation(SelfTrackingOperation.class)
	).register(world, world.create());

	process(world);
	assertEquals(2, instances.size);

	process(world); // just making sure nothing new happens
	assertEquals(2, instances.size);

	assertTrue(instances.contains(
		System.identityHashCode(operation(SelfTrackingOperation.class))));
}
 
Example #6
Source File: RepeatOperationTest.java    From artemis-odb-orion with Apache License 2.0 6 votes vote down vote up
@Test
public void repeat_thrice_over_one_frame() {
	World world = new World(
		new WorldConfiguration()
			.setSystem(OperationSystem.class));

	repeat(3, operation(InstantOperation.class))
		.register(world, world.create());

	assertEquals(0, InstantOperation.invocations);

	process(world);
	assertEquals(3, InstantOperation.invocations);

	process(world);
	assertEquals(3, InstantOperation.invocations);
}
 
Example #7
Source File: OperationTest.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
@Test(expected = MundaneWireException.class)
public void no_wire_failed_inject_test() {
	World world = new World(new WorldConfiguration()
		.setSystem(OperationSystem.class));

	operation(NoWireNoInjectOperation.class).register(world);

	process(world);
}
 
Example #8
Source File: OperationTest.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleUseOperation() {
	OperationSystem operationSystem = new OperationSystem();
	World world = new World(new WorldConfiguration()
		.setSystem(operationSystem));

	MySingleUseOperation op = operation(MySingleUseOperation.class);
	op.register(world, world.create());

	process(world);

	assertEquals(0, operatives(world).size());
	assertSame(op, operation(MySingleUseOperation.class));
}
 
Example #9
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 #10
Source File: RepeatOperationTest.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
@Test
public void repeat_thrice_over_three_frames() {
	int[] counter = new int[1];

	World world = new World(new WorldConfiguration()
		.register("counter", counter)
		.setSystem(OperationSystem.class));

	repeat(3,
		sequence(
			operation(SingleFrameOperation.class)
		)
	).register(world);

	assertEquals(0, counter[0]);

	process(world);
	assertEquals(1, counter[0]);

	process(world);
	assertEquals(2, counter[0]);

	process(world);
	assertEquals(3, counter[0]);

	process(world);
	assertEquals(3, counter[0]);
}
 
Example #11
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 #12
Source File: UniqueOperationTest.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
@Test
public void replace_non_entity_operation() {
	WorldConfiguration wc = new WorldConfiguration()
			.setSystem(OperationSystem.class);
	World world = new World(wc);

	unique("hello",
		sequence(
			delayTick(3),
			run(new Runnable() {
				@Override
				public void run() {
					fail();
				}
			})
		)
	).register(world);

	OperationTestUtil.process(world);
	assertFalse(bool2);

	unique("hello",
		run(new Runnable() {
			@Override
			public void run() {
				bool2 = true;
			}
		})
	).register(world);

	OperationTestUtil.process(world);
	OperationTestUtil.process(world);
	assertTrue(bool2);

	assertEquals(0, operatives(world).size());
}
 
Example #13
Source File: UniqueOperationTest.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
@Test
public void replace_operation() {
	WorldConfiguration wc = new WorldConfiguration()
			.setSystem(OperationSystem.class);
	World world = new World(wc);

	Entity e = world.createEntity();
	unique("hello",
		sequence(
			delayTick(3),
			run(new Runnable() {
				@Override
				public void run() {
					fail();
				}
			})
		)
	).register(e);

	OperationTestUtil.process(world);
	assertFalse(bool2);

	unique("hello",
		run(new Runnable() {
			@Override
			public void run() {
				bool2 = true;
			}
		})
	).register(e);

	OperationTestUtil.process(world);
	OperationTestUtil.process(world);
	assertTrue(bool2);


	assertEquals(0, operatives(world).size());
}
 
Example #14
Source File: UniqueOperationTest.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
@Test
public void run_single_operation() {
	WorldConfiguration wc = new WorldConfiguration()
			.setSystem(OperationSystem.class);
	World world = new World(wc);

	sequence(
		unique("hello",
			run(new Runnable() {
				@Override
				public void run() {
					bool1 = true;
				}
			})
		),
		run(new Runnable() {
			@Override
			public void run() {
				bool2 = true;
			}
		})
	).register(world.createEntity());

	OperationTestUtil.process(world);

	assertTrue(bool1);
	assertTrue(bool2);
}
 
Example #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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;
}
 
Example #23
Source File: GameScreen.java    From riiablo with Apache License 2.0 4 votes vote down vote up
protected WorldConfiguration getWorldConfiguration() {
  return getWorldConfigurationBuilder().build();
}