Search in sources :

Example 6 with EngineEntityManager

use of org.terasology.engine.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, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    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.engine.entitySystem.entity.internal.EngineEntityManager) StringComponent(org.terasology.unittest.stubs.StringComponent) StorageManager(org.terasology.engine.persistence.StorageManager) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 7 with EngineEntityManager

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

the class StorageManagerTest method testChunkSurvivesStorageSaveAndRestore.

@Test
public void testChunkSurvivesStorageSaveAndRestore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.setBlock(0, 4, 2, testBlock2);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    when(chunkProvider.getChunk(ArgumentMatchers.any(Vector3ic.class))).thenReturn(chunk);
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    boolean storeChunkInZips = true;
    esm.setStoreChunksInZips(storeChunkInZips);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, extraDataManager, storeChunkInZips, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    assertNotNull(restored);
    assertEquals(CHUNK_POS, restored.getChunkPosition());
    assertNotNull(restored.getChunk());
    assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0));
    assertEquals(testBlock2, restored.getChunk().getBlock(0, 4, 2));
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) StorageManager(org.terasology.engine.persistence.StorageManager) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Example 8 with EngineEntityManager

use of org.terasology.engine.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, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    PlayerStore restored = newSM.loadPlayerStore(PLAYER_ID);
    restored.restoreEntities();
    assertTrue(restored.getCharacter().getComponent(EntityRefComponent.class).entityRef.exists());
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) EntityRefComponent(org.terasology.unittest.stubs.EntityRefComponent) PlayerStore(org.terasology.engine.persistence.PlayerStore) StorageManager(org.terasology.engine.persistence.StorageManager) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 9 with EngineEntityManager

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

the class ComponentSerializerTest method setup.

@BeforeEach
public void setup() {
    context = new ContextImpl();
    context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
    context.put(ModuleManager.class, moduleManager);
    CoreRegistry.setContext(context);
    Reflections reflections = new Reflections(getClass().getClassLoader());
    TypeHandlerLibrary serializationLibrary = new TypeHandlerLibraryImpl(reflections);
    serializationLibrary.addTypeHandler(Vector3f.class, new Vector3fTypeHandler());
    serializationLibrary.addTypeHandler(Quaternionf.class, new QuaternionfTypeHandler());
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager entityManager = context.get(EngineEntityManager.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "gettersetter"), GetterSetterComponent.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "string"), StringComponent.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "integer"), IntegerComponent.class);
    ComponentLibrary componentLibrary = entityManager.getComponentLibrary();
    componentSerializer = new ComponentSerializer(componentLibrary, serializationLibrary);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) QuaternionfTypeHandler(org.terasology.engine.persistence.typeHandling.mathTypes.QuaternionfTypeHandler) Vector3fTypeHandler(org.terasology.engine.persistence.typeHandling.mathTypes.Vector3fTypeHandler) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) NetworkSystem(org.terasology.engine.network.NetworkSystem) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ContextImpl(org.terasology.engine.context.internal.ContextImpl) TypeHandlerLibraryImpl(org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ComponentSerializer(org.terasology.engine.persistence.serializers.ComponentSerializer) Reflections(org.reflections.Reflections) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with EngineEntityManager

use of org.terasology.engine.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.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)

Aggregations

EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)14 Test (org.junit.jupiter.api.Test)7 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)7 StorageManager (org.terasology.engine.persistence.StorageManager)5 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)5 Path (java.nio.file.Path)4 BlockManager (org.terasology.engine.world.block.BlockManager)4 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)3 EngineTime (org.terasology.engine.core.EngineTime)3 ModuleManager (org.terasology.engine.core.module.ModuleManager)3 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)3 EventLibrary (org.terasology.engine.entitySystem.metadata.EventLibrary)3 NetworkSystem (org.terasology.engine.network.NetworkSystem)3 NetworkSystemImpl (org.terasology.engine.network.internal.NetworkSystemImpl)3 IOException (java.io.IOException)2 Vector3f (org.joml.Vector3f)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)2 ReadWriteStorageManager (org.terasology.engine.persistence.internal.ReadWriteStorageManager)2 DirectionAndOriginPosRecorderList (org.terasology.engine.recording.DirectionAndOriginPosRecorderList)2