Search in sources :

Example 1 with EngineEntityManager

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

the class HeadlessEnvironment method setupStorageManager.

@Override
protected void setupStorageManager() throws IOException {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    EngineEntityManager engineEntityManager = context.get(EngineEntityManager.class);
    BlockManager blockManager = context.get(BlockManager.class);
    RecordAndReplaySerializer recordAndReplaySerializer = context.get(RecordAndReplaySerializer.class);
    Path savePath = PathManager.getInstance().getSavePath("world1");
    RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils();
    RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    context.put(BlockFamilyLibrary.class, new BlockFamilyLibrary(environment, context));
    ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
    context.put(StorageManager.class, new ReadWriteStorageManager(savePath, moduleManager.getEnvironment(), engineEntityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus));
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) Path(java.nio.file.Path) BlockManager(org.terasology.engine.world.block.BlockManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) BlockFamilyLibrary(org.terasology.engine.world.block.family.BlockFamilyLibrary) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager) ModuleManager(org.terasology.engine.core.module.ModuleManager) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer)

Example 2 with EngineEntityManager

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

the class TerasologyTestingEnvironment method setup.

@BeforeEach
public void setup() throws Exception {
    context.put(ModuleManager.class, moduleManager);
    RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    mockTime = mock(EngineTime.class);
    context.put(Time.class, mockTime);
    NetworkSystemImpl networkSystem = new NetworkSystemImpl(mockTime, context);
    context.put(Game.class, new Game());
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    engineEntityManager = context.get(EngineEntityManager.class);
    // 'mock' added to avoid hiding a field
    BlockManager mockBlockManager = context.get(BlockManager.class);
    ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
    RecordedEventStore recordedEventStore = new RecordedEventStore();
    RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils();
    context.put(RecordAndReplayUtils.class, recordAndReplayUtils);
    CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
    context.put(CharacterStateEventPositionMap.class, characterStateEventPositionMap);
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
    context.put(DirectionAndOriginPosRecorderList.class, directionAndOriginPosRecorderList);
    RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(engineEntityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, context.get(TypeRegistry.class));
    context.put(RecordAndReplaySerializer.class, recordAndReplaySerializer);
    Path savePath = PathManager.getInstance().getSavePath("world1");
    context.put(StorageManager.class, new ReadWriteStorageManager(savePath, moduleManager.getEnvironment(), engineEntityManager, mockBlockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus));
    ComponentSystemManager componentSystemManager = new ComponentSystemManager(context);
    context.put(ComponentSystemManager.class, componentSystemManager);
    LoadPrefabs prefabLoadStep = new LoadPrefabs(context);
    boolean complete = false;
    prefabLoadStep.begin();
    while (!complete) {
        complete = prefabLoadStep.step();
    }
    context.get(ComponentSystemManager.class).initialise();
    context.put(Console.class, new ConsoleImpl(context));
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) Path(java.nio.file.Path) ConsoleImpl(org.terasology.engine.logic.console.ConsoleImpl) EngineTime(org.terasology.engine.core.EngineTime) RecordedEventStore(org.terasology.engine.recording.RecordedEventStore) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) TypeRegistry(org.terasology.reflection.TypeRegistry) NetworkSystemImpl(org.terasology.engine.network.internal.NetworkSystemImpl) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) Game(org.terasology.engine.game.Game) LoadPrefabs(org.terasology.engine.core.modes.loadProcesses.LoadPrefabs) BlockManager(org.terasology.engine.world.block.BlockManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager) CharacterStateEventPositionMap(org.terasology.engine.recording.CharacterStateEventPositionMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with EngineEntityManager

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

the class WorldSerializerTest method testNotPersistedIfFlagedOtherwise.

@Test
public void testNotPersistedIfFlagedOtherwise() throws Exception {
    EngineEntityManager entityManager = context.get(EngineEntityManager.class);
    EntityBuilder entityBuilder = entityManager.newBuilder();
    PrefabSerializer prefabSerializer = new PrefabSerializer(entityManager.getComponentLibrary(), entityManager.getTypeSerializerLibrary());
    WorldSerializer worldSerializer = new WorldSerializerImpl(entityManager, prefabSerializer);
    entityBuilder.setPersistent(false);
    // just used to express that an entity got created
    @SuppressWarnings("unused") EntityRef entity = entityBuilder.build();
    EntityData.GlobalStore worldData = worldSerializer.serializeWorld(false);
    assertEquals(0, worldData.getEntityCount());
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) EntityData(org.terasology.protobuf.EntityData) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) WorldSerializerImpl(org.terasology.engine.persistence.serializers.WorldSerializerImpl) WorldSerializer(org.terasology.engine.persistence.serializers.WorldSerializer) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) PrefabSerializer(org.terasology.engine.persistence.serializers.PrefabSerializer) Test(org.junit.jupiter.api.Test)

Example 4 with EngineEntityManager

use of org.terasology.engine.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, extraDataManager);
    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();
    AABBfc aabb = chunk.getAABB();
    Vector3f positionInChunk = new Vector3f(aabb.minX(), aabb.minY(), aabb.minZ());
    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, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    restored.restoreEntities();
    EntityRef ref = newEntityManager.getEntity(id);
    assertTrue(ref.exists());
    assertTrue(ref.isActive());
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3f(org.joml.Vector3f) StorageManager(org.terasology.engine.persistence.StorageManager) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Example 5 with EngineEntityManager

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

the class AbstractState method createLocalPlayer.

protected static void createLocalPlayer(Context context) {
    EngineEntityManager entityManager = context.get(EngineEntityManager.class);
    EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
    LocalPlayer localPlayer = new LocalPlayer();
    localPlayer.setRecordAndReplayClasses(context.get(DirectionAndOriginPosRecorderList.class), context.get(RecordAndReplayCurrentStatus.class));
    context.put(LocalPlayer.class, localPlayer);
    localPlayer.setClientEntity(localPlayerEntity);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent)

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