Java Code Examples for com.badlogic.ashley.core.Engine#update()
The following examples show how to use
com.badlogic.ashley.core.Engine#update() .
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: IntervalIteratingTest.java From ashley with Apache License 2.0 | 6 votes |
@Test public void intervalSystem () { Engine engine = new Engine(); IntervalIteratingSystemSpy intervalSystemSpy = new IntervalIteratingSystemSpy(); ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(IntervalComponentSpy.class).get()); ComponentMapper<IntervalComponentSpy> im = ComponentMapper.getFor(IntervalComponentSpy.class); engine.addSystem(intervalSystemSpy); for (int i = 0; i < 10; ++i) { Entity entity = new Entity(); entity.add(new IntervalComponentSpy()); engine.addEntity(entity); } for (int i = 1; i <= 10; ++i) { engine.update(deltaTime); for (int j = 0; j < entities.size(); ++j) { assertEquals(i / 2, im.get(entities.get(j)).numUpdates); } } }
Example 2
Source File: IteratingSystemTest.java From ashley with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void shouldIterateEntitiesWithCorrectFamily () { final Engine engine = new Engine(); final Family family = Family.all(ComponentA.class, ComponentB.class).get(); final IteratingSystemMock system = new IteratingSystemMock(family); final Entity e = new Entity(); engine.addSystem(system); engine.addEntity(e); // When entity has ComponentA e.add(new ComponentA()); engine.update(deltaTime); assertEquals(0, system.numUpdates); // When entity has ComponentA and ComponentB system.numUpdates = 0; e.add(new ComponentB()); engine.update(deltaTime); assertEquals(1, system.numUpdates); // When entity has ComponentA, ComponentB and ComponentC system.numUpdates = 0; e.add(new ComponentC()); engine.update(deltaTime); assertEquals(1, system.numUpdates); // When entity has ComponentB and ComponentC system.numUpdates = 0; e.remove(ComponentA.class); e.add(new ComponentC()); engine.update(deltaTime); assertEquals(0, system.numUpdates); }
Example 3
Source File: SortedIteratingSystemTest.java From ashley with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void shouldIterateEntitiesWithCorrectFamily () { final Engine engine = new Engine(); final Family family = Family.all(OrderComponent.class, ComponentB.class).get(); final SortedIteratingSystemMock system = new SortedIteratingSystemMock(family); final Entity e = new Entity(); engine.addSystem(system); engine.addEntity(e); // When entity has OrderComponent e.add(new OrderComponent("A", 0)); engine.update(deltaTime); // When entity has OrderComponent and ComponentB e.add(new ComponentB()); system.expectedNames.addLast("A"); engine.update(deltaTime); // When entity has OrderComponent, ComponentB and ComponentC e.add(new ComponentC()); system.expectedNames.addLast("A"); engine.update(deltaTime); // When entity has ComponentB and ComponentC e.remove(OrderComponent.class); e.add(new ComponentC()); engine.update(deltaTime); }
Example 4
Source File: SortedIteratingSystemTest.java From ashley with Apache License 2.0 | 5 votes |
@Test public void entityOrder () { Engine engine = new Engine(); final Family family = Family.all(OrderComponent.class).get(); final SortedIteratingSystemMock system = new SortedIteratingSystemMock(family); engine.addSystem(system); Entity a = createOrderEntity("A", 0); Entity b = createOrderEntity("B", 1); Entity c = createOrderEntity("C", 3); Entity d = createOrderEntity("D", 2); engine.addEntity(a); engine.addEntity(b); engine.addEntity(c); system.expectedNames.addLast("A"); system.expectedNames.addLast("B"); system.expectedNames.addLast("C"); engine.update(0); engine.addEntity(d); system.expectedNames.addLast("A"); system.expectedNames.addLast("B"); system.expectedNames.addLast("D"); system.expectedNames.addLast("C"); engine.update(0); orderMapper.get(a).zLayer = 3; orderMapper.get(b).zLayer = 2; orderMapper.get(c).zLayer = 1; orderMapper.get(d).zLayer = 0; system.forceSort(); system.expectedNames.addLast("D"); system.expectedNames.addLast("C"); system.expectedNames.addLast("B"); system.expectedNames.addLast("A"); engine.update(0); }
Example 5
Source File: IntervalSystemTest.java From ashley with Apache License 2.0 | 5 votes |
@Test public void intervalSystem () { Engine engine = new Engine(); IntervalSystemSpy intervalSystemSpy = new IntervalSystemSpy(); engine.addSystem(intervalSystemSpy); for (int i = 1; i <= 10; ++i) { engine.update(deltaTime); assertEquals(i / 2, intervalSystemSpy.numUpdates); } }
Example 6
Source File: SystemPriorityTest.java From ashley with Apache License 2.0 | 5 votes |
public static void main (String[] args) { Engine engine = new Engine(); engine.addSystem(new SystemA(10)); engine.addSystem(new SystemB(5)); engine.addSystem(new SystemA(2)); engine.update(0); }
Example 7
Source File: AshleyBenchmark.java From ashley with Apache License 2.0 | 4 votes |
private void runEngineTest (Engine engine) { for (int i = 0; i < Constants.FRAMES; ++i) { engine.update(Constants.DELTA_TIME); } }