Search in sources :

Example 6 with EngineEntityManager

use of org.terasology.entitySystem.entity.internal.EngineEntityManager in project Terasology by MovingBlocks.

the class StorageManagerTest method testEntitySurvivesStorageInChunkStore.

@Test
public void testEntitySurvivesStorageInChunkStore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, biomeManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    EntityRef entity = entityManager.create();
    long id = entity.getId();
    LocationComponent locationComponent = new LocationComponent();
    Vector3f positionInChunk = new Vector3f(chunk.getAABB().getMin());
    positionInChunk.x += 1;
    positionInChunk.y += 1;
    positionInChunk.z += 1;
    locationComponent.setWorldPosition(positionInChunk);
    entity.addComponent(locationComponent);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, false);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    restored.restoreEntities();
    EntityRef ref = newEntityManager.getEntity(id);
    assertTrue(ref.exists());
    assertTrue(ref.isActive());
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3f(org.terasology.math.geom.Vector3f) StorageManager(org.terasology.persistence.StorageManager) Chunk(org.terasology.world.chunks.Chunk) ChunkProvider(org.terasology.world.chunks.ChunkProvider) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Example 7 with EngineEntityManager

use of org.terasology.entitySystem.entity.internal.EngineEntityManager in project Terasology by MovingBlocks.

the class StorageManagerTest method testReferenceRemainsValidOverStorageRestoral.

@Test
public void testReferenceRemainsValidOverStorageRestoral() throws Exception {
    EntityRef someEntity = entityManager.create();
    character.addComponent(new EntityRefComponent(someEntity));
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, false);
    newSM.loadGlobalStore();
    PlayerStore restored = newSM.loadPlayerStore(PLAYER_ID);
    restored.restoreEntities();
    assertTrue(restored.getCharacter().getComponent(EntityRefComponent.class).entityRef.exists());
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) EntityRefComponent(org.terasology.entitySystem.stubs.EntityRefComponent) PlayerStore(org.terasology.persistence.PlayerStore) StorageManager(org.terasology.persistence.StorageManager) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 8 with EngineEntityManager

use of org.terasology.entitySystem.entity.internal.EngineEntityManager in project Terasology by MovingBlocks.

the class StorageManagerTest method testGlobalEntitiesStoredAndRestored.

@Test
public void testGlobalEntitiesStoredAndRestored() throws Exception {
    EntityRef entity = entityManager.create(new StringComponent("Test"));
    long entityId = entity.getId();
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, false);
    newSM.loadGlobalStore();
    List<EntityRef> entities = Lists.newArrayList(newEntityManager.getEntitiesWith(StringComponent.class));
    assertEquals(1, entities.size());
    assertEquals(entityId, entities.get(0).getId());
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) StringComponent(org.terasology.entitySystem.stubs.StringComponent) StorageManager(org.terasology.persistence.StorageManager) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 9 with EngineEntityManager

use of org.terasology.entitySystem.entity.internal.EngineEntityManager 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.entitySystem.entity.internal.EngineEntityManager) EventLibrary(org.terasology.entitySystem.metadata.EventLibrary) EngineTime(org.terasology.engine.EngineTime) EntityRef(org.terasology.entitySystem.entity.EntityRef) NetworkSystemImpl(org.terasology.network.internal.NetworkSystemImpl) Test(org.junit.Test)

Example 10 with EngineEntityManager

use of org.terasology.entitySystem.entity.internal.EngineEntityManager 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.entitySystem.entity.internal.EngineEntityManager) EventLibrary(org.terasology.entitySystem.metadata.EventLibrary) EngineTime(org.terasology.engine.EngineTime) NetworkSystemImpl(org.terasology.network.internal.NetworkSystemImpl) Test(org.junit.Test)

Aggregations

EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)13 Test (org.junit.Test)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)5 StorageManager (org.terasology.persistence.StorageManager)5 Path (java.nio.file.Path)3 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)3 EngineTime (org.terasology.engine.EngineTime)3 EventLibrary (org.terasology.entitySystem.metadata.EventLibrary)3 NetworkSystemImpl (org.terasology.network.internal.NetworkSystemImpl)3 ReadWriteStorageManager (org.terasology.persistence.internal.ReadWriteStorageManager)3 Before (org.junit.Before)2 ModuleManager (org.terasology.engine.module.ModuleManager)2 EntityManager (org.terasology.entitySystem.entity.EntityManager)2 NetworkSystem (org.terasology.network.NetworkSystem)2 ChunkStore (org.terasology.persistence.ChunkStore)2 PrefabSerializer (org.terasology.persistence.serializers.PrefabSerializer)2 BiomeManager (org.terasology.world.biomes.BiomeManager)2 BlockManager (org.terasology.world.block.BlockManager)2 IOException (java.io.IOException)1 ContextImpl (org.terasology.context.internal.ContextImpl)1