Search in sources :

Example 11 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class LoaderTest method testScreenInterrupted.

/**
 * Test interrupted.
 */
@Test
void testScreenInterrupted() {
    ScreenMock.setScreenWait(true);
    try {
        final AtomicReference<Throwable> exception = new AtomicReference<>();
        final Semaphore semaphore = new Semaphore(0);
        final Thread thread = new Thread() {

            @Override
            public void run() {
                final Screen screen = Graphics.createScreen(CONFIG);
                screen.start();
                screen.awaitReady();
            }
        };
        thread.setUncaughtExceptionHandler((t, throwable) -> {
            exception.set(throwable);
            semaphore.release();
        });
        thread.start();
        UtilTests.pause(ScreenMock.READY_TIMEOUT / 2);
        thread.interrupt();
        assertTimeout(ScreenMock.READY_TIMEOUT * 2, semaphore::acquire);
        assertEquals(LionEngineException.class.getName() + ": Unable to get screen ready !", exception.get().toString());
    } finally {
        ScreenMock.setScreenWait(false);
    }
}
Also used : Screen(com.b3dgs.lionengine.graphic.Screen) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.jupiter.api.Test)

Example 12 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class LoaderTest method testInterruptedUnchecked.

/**
 * Test interrupted unchecked exception.
 */
@Test
void testInterruptedUnchecked() {
    Graphics.setFactoryGraphic(new FactoryGraphicMock() {

        @Override
        public Screen createScreen(Config config) {
            return null;
        }
    });
    final AtomicReference<Throwable> exception = new AtomicReference<>();
    final Semaphore semaphore = new Semaphore(0);
    final Thread thread = new Thread() {

        @Override
        public void run() {
            final TaskFuture future = Loader.start(CONFIG, SequenceInterruptMock.class);
            future.await();
        }
    };
    thread.setUncaughtExceptionHandler((t, throwable) -> {
        exception.set(throwable);
        semaphore.release();
    });
    Verbose.info("*********************************** EXPECTED VERBOSE ***********************************");
    thread.start();
    assertTimeout(SequenceInterruptMock.PAUSE_MILLI * 2L, semaphore::acquire);
    assertTrue(exception.get().getCause() instanceof NullPointerException);
    Verbose.info("****************************************************************************************");
    Graphics.setFactoryGraphic(new FactoryGraphicMock());
}
Also used : Config(com.b3dgs.lionengine.Config) Screen(com.b3dgs.lionengine.graphic.Screen) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.jupiter.api.Test)

Example 13 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class Loader method handle.

/**
 * Handle the sequence with its screen until no more sequence to run.
 *
 * @param config The configuration used.
 * @param sequenceClass The the next sequence to start.
 * @param arguments The sequence arguments list if needed by its constructor.
 * @throws LionEngineException If an exception occurred.
 */
private static void handle(Config config, Class<? extends Sequencable> sequenceClass, Object... arguments) {
    final Screen screen = Graphics.createScreen(config);
    try {
        screen.start();
        screen.awaitReady();
        final Context context = new ContextWrapper(screen);
        Sequencable nextSequence = UtilSequence.create(sequenceClass, context, arguments);
        while (nextSequence != null) {
            final Sequencable sequence = nextSequence;
            final String sequenceName = sequence.getClass().getName();
            Verbose.info(SEQUENCE_START, sequenceName);
            sequence.start(screen);
            Verbose.info(SEQUENCE_END, sequenceName);
            nextSequence = sequence.getNextSequence();
            sequence.onTerminated(nextSequence != null);
        }
    } finally {
        screen.dispose();
        config.getDevices().forEach(InputDevice::close);
    }
}
Also used : Context(com.b3dgs.lionengine.Context) InputDevice(com.b3dgs.lionengine.InputDevice) Screen(com.b3dgs.lionengine.graphic.Screen)

Example 14 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class LoopExtrapolatedTest method testNoSyncFullscreen.

/**
 * Test without sync full screen.
 */
@Test
void testNoSyncFullscreen() {
    ScreenMock.setScreenWait(false);
    final Screen screen = new ScreenMock(new Config(new Resolution(320, 240, 0), 16, false));
    loop.notifyRateChanged(50);
    final Thread thread = getTask(screen);
    thread.start();
    assertTimeout(1000L, thread::join);
    assertEquals(maxTick.get(), tick.get());
    assertEquals(tick.get(), rendered.get());
    assertTrue(extrapolation.get().doubleValue() > 0, String.valueOf(extrapolation.get()));
    final int expectedRate = screen.getConfig().getOutput().getRate();
    assertTrue(computed.get() > expectedRate, String.valueOf(computed.get()));
}
Also used : Screen(com.b3dgs.lionengine.graphic.Screen) Config(com.b3dgs.lionengine.Config) ScreenMock(com.b3dgs.lionengine.graphic.ScreenMock) Resolution(com.b3dgs.lionengine.Resolution) Test(org.junit.jupiter.api.Test)

Example 15 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class LoopExtrapolatedTest method testUnready.

/**
 * Test with not ready screen.
 */
@Test
void testUnready() {
    ScreenMock.setScreenWait(true);
    try {
        final Screen screen = new ScreenMock(new Config(new Resolution(320, 240, 50), 16, true));
        final Thread thread = getTask(screen);
        thread.start();
        assertTimeout(1000L, latch::await);
        loop.stop();
        assertTimeout(1000L, thread::join);
        assertEquals(0, tick.get());
        assertEquals(0, rendered.get());
        assertNull(extrapolation.get());
        assertEquals(-1, computed.get());
    } finally {
        ScreenMock.setScreenWait(false);
    }
}
Also used : Screen(com.b3dgs.lionengine.graphic.Screen) Config(com.b3dgs.lionengine.Config) ScreenMock(com.b3dgs.lionengine.graphic.ScreenMock) Resolution(com.b3dgs.lionengine.Resolution) Test(org.junit.jupiter.api.Test)

Aggregations

Screen (com.b3dgs.lionengine.graphic.Screen)56 Config (com.b3dgs.lionengine.Config)47 Resolution (com.b3dgs.lionengine.Resolution)45 ScreenMock (com.b3dgs.lionengine.graphic.ScreenMock)45 Test (org.junit.jupiter.api.Test)26 Test (org.junit.Test)23 Semaphore (java.util.concurrent.Semaphore)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 InputDeviceKeyListener (com.b3dgs.lionengine.InputDeviceKeyListener)3 ScreenListener (com.b3dgs.lionengine.graphic.ScreenListener)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 FactoryGraphicMock (com.b3dgs.lionengine.graphic.FactoryGraphicMock)2 Context (com.b3dgs.lionengine.Context)1 InputDevice (com.b3dgs.lionengine.InputDevice)1