Search in sources :

Example 11 with Handler

use of com.b3dgs.lionengine.game.feature.Handler in project lionengine by b3dgs.

the class LauncherModelTest method testLauncherDelay.

/**
 * Test the launcher with delay.
 *
 * @throws InterruptedException If error.
 */
@Test
void testLauncherDelay() throws InterruptedException {
    final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia, 100);
    final Setup setup = new Setup(launcherMedia);
    final Launcher launcher = UtilLaunchable.createLauncher(services, setup, featurable);
    final AtomicBoolean fired = new AtomicBoolean();
    final AtomicReference<Launchable> firedLaunchable = new AtomicReference<>();
    launcher.addListener(UtilLaunchable.createListener(fired));
    launcher.addListener(UtilLaunchable.createListener(firedLaunchable));
    assertTimeout(1000L, () -> {
        while (!launcher.fire()) {
            launcher.update(1.0);
        }
    });
    final Handler handler = services.get(Handler.class);
    launcher.update(1.0);
    handler.update(1.0);
    assertEquals(0, handler.size());
    assertTrue(fired.get());
    assertNull(firedLaunchable.get());
    assertTimeout(1000L, () -> {
        while (firedLaunchable.get() == null) {
            launcher.update(1.0);
            handler.update(1.0);
        }
    });
    assertEquals(1, handler.size());
    firedLaunchable.set(null);
    handler.removeAll();
    handler.update(1.0);
    assertEquals(0, handler.size());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Media(com.b3dgs.lionengine.Media) Handler(com.b3dgs.lionengine.game.feature.Handler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Test(org.junit.jupiter.api.Test)

Example 12 with Handler

use of com.b3dgs.lionengine.game.feature.Handler in project lionengine by b3dgs.

the class LauncherModelTest method testLauncherInitial.

/**
 * Test the launcher with initial speed.
 *
 * @throws InterruptedException If error.
 */
@Test
void testLauncherInitial() throws InterruptedException {
    final AtomicBoolean fired = new AtomicBoolean();
    final AtomicReference<Launchable> firedLaunchable = new AtomicReference<>();
    launcher.addListener(UtilLaunchable.createListener(fired));
    launcher.addListener(UtilLaunchable.createListener(firedLaunchable));
    final Force force = new Force(1.0, 2.0);
    assertTimeout(1000L, () -> {
        while (!launcher.fire(force)) {
            launcher.update(1.0);
            continue;
        }
    });
    assertTrue(fired.get());
    assertNotNull(firedLaunchable.get());
    final Transformable transformable = firedLaunchable.get().getFeature(Transformable.class);
    assertEquals(2.0, transformable.getX());
    assertEquals(4.0, transformable.getY());
    final Handler handler = services.get(Handler.class);
    handler.update(1.0);
    assertEquals(1, handler.size());
    handler.removeAll();
    handler.update(1.0);
    assertEquals(0, handler.size());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Force(com.b3dgs.lionengine.game.Force) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Handler(com.b3dgs.lionengine.game.feature.Handler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 13 with Handler

use of com.b3dgs.lionengine.game.feature.Handler in project lionengine by b3dgs.

the class ProducerModelTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    services.add(new Handler(services));
    services.add(new SourceResolutionProvider() {

        @Override
        public int getWidth() {
            return 0;
        }

        @Override
        public int getHeight() {
            return 0;
        }

        @Override
        public int getRate() {
            return 50;
        }
    });
    producer = new ProducerModel(services, setup);
    producer.prepare(object);
}
Also used : Handler(com.b3dgs.lionengine.game.feature.Handler) SourceResolutionProvider(com.b3dgs.lionengine.graphic.engine.SourceResolutionProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Handler (com.b3dgs.lionengine.game.feature.Handler)13 Test (org.junit.jupiter.api.Test)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 Media (com.b3dgs.lionengine.Media)4 Factory (com.b3dgs.lionengine.game.feature.Factory)4 Setup (com.b3dgs.lionengine.game.feature.Setup)4 Transformable (com.b3dgs.lionengine.game.feature.Transformable)4 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)4 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Localizable (com.b3dgs.lionengine.Localizable)2 Force (com.b3dgs.lionengine.game.Force)2 Services (com.b3dgs.lionengine.game.feature.Services)2 ContextMock (com.b3dgs.lionengine.ContextMock)1 Medias (com.b3dgs.lionengine.Medias)1 Resolution (com.b3dgs.lionengine.Resolution)1 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)1 UtilAssert.assertFalse (com.b3dgs.lionengine.UtilAssert.assertFalse)1 UtilAssert.assertNotNull (com.b3dgs.lionengine.UtilAssert.assertNotNull)1