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));
}
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();
}
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();
}
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));
}
}
}
}
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();
}
Aggregations