Search in sources :

Example 6 with EngineTime

use of org.terasology.engine.core.EngineTime in project Terasology by MovingBlocks.

the class NetworkOwnershipTest method setup.

@BeforeEach
public void setup() throws Exception {
    super.setup();
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    EngineTime mockTime = mock(EngineTime.class);
    networkSystem = new NetworkSystemImpl(mockTime, context);
    networkSystem.setContext(context);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = (PojoEntityManager) context.get(EntityManager.class);
    context.put(ComponentSystemManager.class, new ComponentSystemManager(context));
    entityManager.clear();
    client = mock(NetClient.class);
    NetworkComponent clientNetComp = new NetworkComponent();
    clientNetComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
    clientEntity = entityManager.create(clientNetComp);
    when(client.getEntity()).thenReturn(clientEntity);
    when(client.getId()).thenReturn("dummyID");
    networkSystem.mockHost();
    networkSystem.connectToEntitySystem(entityManager, context.get(EventLibrary.class), mock(BlockEntityRegistry.class));
    networkSystem.registerNetworkEntity(clientEntity);
    context.put(ServerConnectListManager.class, new ServerConnectListManager(context));
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EventLibrary(org.terasology.engine.entitySystem.metadata.EventLibrary) EngineTime(org.terasology.engine.core.EngineTime) BlockEntityRegistry(org.terasology.engine.world.BlockEntityRegistry) ModuleManager(org.terasology.engine.core.module.ModuleManager) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with EngineTime

use of org.terasology.engine.core.EngineTime in project Terasology by MovingBlocks.

the class TestNetwork method testNetwork.

@Test
public void testNetwork() throws Exception {
    EngineEntityManager entityManager = getEntityManager();
    EngineTime time = mock(EngineTime.class);
    NetworkSystem server = new NetworkSystemImpl(time, context);
    server.setContext(context);
    netSystems.add(server);
    server.connectToEntitySystem(entityManager, context.get(EventLibrary.class), null);
    server.host(7777, true);
    Thread.sleep(500);
    NetworkSystem client = new NetworkSystemImpl(time, context);
    client.setContext(context);
    netSystems.add(client);
    client.join("localhost", 7777);
    Thread.sleep(500);
    server.shutdown();
    client.shutdown();
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) EventLibrary(org.terasology.engine.entitySystem.metadata.EventLibrary) EngineTime(org.terasology.engine.core.EngineTime) NetworkSystemImpl(org.terasology.engine.network.internal.NetworkSystemImpl) Test(org.junit.jupiter.api.Test)

Example 8 with EngineTime

use of org.terasology.engine.core.EngineTime in project Terasology by MovingBlocks.

the class TestNetwork method testEntityNetworkIdChangedOnServerStart.

@Test
public void testEntityNetworkIdChangedOnServerStart() throws HostingFailedException {
    EngineEntityManager entityManager = getEntityManager();
    NetworkComponent netComp = new NetworkComponent();
    netComp.setNetworkId(122);
    EntityRef entity = entityManager.create(netComp);
    EngineTime time = mock(EngineTime.class);
    NetworkSystem server = new NetworkSystemImpl(time, context);
    server.setContext(context);
    netSystems.add(server);
    server.connectToEntitySystem(entityManager, context.get(EventLibrary.class), null);
    server.host(7777, true);
    assertFalse(122 == entity.getComponent(NetworkComponent.class).getNetworkId());
    server.shutdown();
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) EventLibrary(org.terasology.engine.entitySystem.metadata.EventLibrary) EngineTime(org.terasology.engine.core.EngineTime) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) NetworkSystemImpl(org.terasology.engine.network.internal.NetworkSystemImpl) Test(org.junit.jupiter.api.Test)

Example 9 with EngineTime

use of org.terasology.engine.core.EngineTime in project Terasology by MovingBlocks.

the class StateLoading method update.

@Override
public void update(float delta) {
    GameEngine gameEngine = context.get(GameEngine.class);
    EngineTime time = (EngineTime) context.get(Time.class);
    long startTime = time.getRealTimeInMs();
    while (current != null && time.getRealTimeInMs() - startTime < 20 && !gameEngine.hasPendingState()) {
        try {
            if (current.step()) {
                popStep();
            }
        } catch (Exception e) {
            logger.error("Error while loading {}", current, e);
            String errorMessage = String.format("Failed to load game. There was an error during \"%s\".", current == null ? "the last part" : current.getMessage());
            gameEngine.changeState(new StateMainMenu(errorMessage));
            CrashReporter.report(e, LoggingContext.getLoggingPath());
            return;
        }
    }
    if (current == null) {
        if (nuiManager != null) {
            nuiManager.closeScreen(loadingScreen);
            nuiManager.setHUDVisible(true);
        }
        context.get(GameEngine.class).changeState(new StateIngame(gameManifest, context));
    } else {
        float progressValue = (progress + current.getExpectedCost() * current.getProgress()) / maxProgress;
        if (nuiManager != null) {
            loadingScreen.updateStatus(current.getMessage(), progressValue);
            nuiManager.update(delta);
        }
        // chunk generation begins at the AwaitCharacterSpawn step
        if (current instanceof AwaitCharacterSpawn && !chunkGenerationStarted) {
            chunkGenerationStarted = true;
            // in case no chunks generate, this should be set for a basis
            timeLastChunkGenerated = time.getRealTimeInMs();
        }
        if (chunkGenerationStarted) {
            long timeSinceLastChunk = time.getRealTimeInMs() - timeLastChunkGenerated;
            long chunkGenerationTimeout = systemConfig.chunkGenerationFailTimeoutInMs.get();
            if (timeSinceLastChunk > chunkGenerationTimeout) {
                String errorMessage = "World generation timed out, check the log for more info";
                gameEngine.changeState(new StateMainMenu(errorMessage));
            }
        }
    }
}
Also used : EngineTime(org.terasology.engine.core.EngineTime) GameEngine(org.terasology.engine.core.GameEngine) EngineTime(org.terasology.engine.core.EngineTime) Time(org.terasology.engine.core.Time) AwaitCharacterSpawn(org.terasology.engine.core.modes.loadProcesses.AwaitCharacterSpawn)

Example 10 with EngineTime

use of org.terasology.engine.core.EngineTime in project Terasology by MovingBlocks.

the class PrepareWorld method begin.

@Override
public void begin() {
    worldRenderer = context.get(WorldRenderer.class);
    EngineTime time = (EngineTime) context.get(Time.class);
    startTime = time.getRealTimeInMs();
}
Also used : EngineTime(org.terasology.engine.core.EngineTime) EngineTime(org.terasology.engine.core.EngineTime) Time(org.terasology.engine.core.Time) WorldRenderer(org.terasology.engine.rendering.world.WorldRenderer)

Aggregations

EngineTime (org.terasology.engine.core.EngineTime)10 Time (org.terasology.engine.core.Time)6 EventLibrary (org.terasology.engine.entitySystem.metadata.EventLibrary)3 NetworkSystemImpl (org.terasology.engine.network.internal.NetworkSystemImpl)3 Test (org.junit.jupiter.api.Test)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 SystemConfig (org.terasology.engine.config.SystemConfig)1 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)1 GameEngine (org.terasology.engine.core.GameEngine)1 AwaitCharacterSpawn (org.terasology.engine.core.modes.loadProcesses.AwaitCharacterSpawn)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 Game (org.terasology.engine.game.Game)1 NetworkComponent (org.terasology.engine.network.NetworkComponent)1 NetworkSystem (org.terasology.engine.network.NetworkSystem)1 NUIManagerInternal (org.terasology.engine.rendering.nui.internal.NUIManagerInternal)1 TerasologyCanvasRenderer (org.terasology.engine.rendering.nui.internal.TerasologyCanvasRenderer)1 LoadingScreen (org.terasology.engine.rendering.nui.layers.mainMenu.loadingScreen.LoadingScreen)1 WorldRenderer (org.terasology.engine.rendering.world.WorldRenderer)1