Search in sources :

Example 6 with RecordAndReplayCurrentStatus

use of org.terasology.engine.recording.RecordAndReplayCurrentStatus in project Terasology by MovingBlocks.

the class OwnershipHelperTest method setup.

@BeforeEach
public void setup() {
    ContextImpl context = new ContextImpl();
    context.put(ModuleManager.class, moduleManager);
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    context.put(NetworkSystem.class, networkSystem);
    context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
    CoreRegistry.setContext(context);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ContextImpl(org.terasology.engine.context.internal.ContextImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with RecordAndReplayCurrentStatus

use of org.terasology.engine.recording.RecordAndReplayCurrentStatus in project Terasology by MovingBlocks.

the class StorageManagerTest method setup.

@BeforeEach
public void setup(@TempDir Path tempHome) throws Exception {
    super.setup();
    PathManager.getInstance().useOverrideHomePath(tempHome);
    savePath = PathManager.getInstance().getSavePath("testSave");
    assert !Files.isRegularFile(tempHome.resolve("global.dat"));
    entityManager = context.get(EngineEntityManager.class);
    moduleEnvironment = mock(ModuleEnvironment.class);
    blockManager = context.get(BlockManager.class);
    extraDataManager = context.get(ExtraBlockDataManager.class);
    ModuleManager moduleManager = mock(ModuleManager.class);
    when(moduleManager.getEnvironment()).thenReturn(moduleEnvironment);
    RecordedEventStore recordedEventStore = new RecordedEventStore();
    recordAndReplayUtils = new RecordAndReplayUtils();
    CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
    recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, mock(TypeRegistry.class));
    recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    context.put(StorageManager.class, esm);
    this.character = entityManager.create();
    Client client = createClientMock(PLAYER_ID, character);
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    when(networkSystem.getPlayers()).thenReturn(Arrays.asList(client));
    context.put(NetworkSystem.class, networkSystem);
    AssetManager assetManager = context.get(AssetManager.class);
    BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
    data.setBlockFamily(SymmetricFamily.class);
    assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
    assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
    testBlock = context.get(BlockManager.class).getBlock("test:testblock");
    testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");
    context.put(ChunkProvider.class, mock(ChunkProvider.class));
    WorldProvider worldProvider = mock(WorldProvider.class);
    when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
    context.put(WorldProvider.class, worldProvider);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.gestalt.assets.management.AssetManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) RecordedEventStore(org.terasology.engine.recording.RecordedEventStore) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) ModuleManager(org.terasology.engine.core.module.ModuleManager) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) BlockManager(org.terasology.engine.world.block.BlockManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) WorldProvider(org.terasology.engine.world.WorldProvider) WorldInfo(org.terasology.engine.world.internal.WorldInfo) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) Client(org.terasology.engine.network.Client) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) CharacterStateEventPositionMap(org.terasology.engine.recording.CharacterStateEventPositionMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with RecordAndReplayCurrentStatus

use of org.terasology.engine.recording.RecordAndReplayCurrentStatus in project Terasology by MovingBlocks.

the class EntitySystemSetupUtil method addEntityManagementRelatedClasses.

/**
 * Objects for the following classes must be available in the context:
 * <ul>
 * <li>{@link ModuleEnvironment}</li>
 * <li>{@link NetworkSystem}</li>
 * <li>{@link ReflectFactory}</li>
 * <li>{@link CopyStrategyLibrary}</li>
 * <li>{@link TypeHandlerLibrary}</li>
 * </ul>
 * <p>
 * The method will make objects for the following classes available in the context:
 * <ul>
 * <li>{@link EngineEntityManager}</li>
 * <li>{@link ComponentLibrary}</li>
 * <li>{@link EventLibrary}</li>
 * <li>{@link PrefabManager}</li>
 * <li>{@link EventSystem}</li>
 * </ul>
 */
public static void addEntityManagementRelatedClasses(Context context) {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    ModuleEnvironment environment = moduleManager.getEnvironment();
    NetworkSystem networkSystem = context.get(NetworkSystem.class);
    // Entity Manager
    PojoEntityManager entityManager = new PojoEntityManager();
    context.put(EntityManager.class, entityManager);
    context.put(EngineEntityManager.class, entityManager);
    // Standard serialization library
    TypeHandlerLibrary typeHandlerLibrary = context.get(TypeHandlerLibrary.class);
    typeHandlerLibrary.addTypeHandler(EntityRef.class, new EntityRefTypeHandler(entityManager));
    entityManager.setTypeSerializerLibrary(typeHandlerLibrary);
    // Prefab Manager
    PrefabManager prefabManager = new PojoPrefabManager(context);
    entityManager.setPrefabManager(prefabManager);
    context.put(PrefabManager.class, prefabManager);
    EntitySystemLibrary library = context.get(EntitySystemLibrary.class);
    entityManager.setComponentLibrary(library.getComponentLibrary());
    // Record and Replay
    RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    RecordAndReplayUtils recordAndReplayUtils = context.get(RecordAndReplayUtils.class);
    CharacterStateEventPositionMap characterStateEventPositionMap = context.get(CharacterStateEventPositionMap.class);
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = context.get(DirectionAndOriginPosRecorderList.class);
    RecordedEventStore recordedEventStore = new RecordedEventStore();
    RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, context.get(TypeRegistry.class));
    context.put(RecordAndReplaySerializer.class, recordAndReplaySerializer);
    // Event System
    EventSystem eventSystem = createEventSystem(networkSystem, entityManager, library, recordedEventStore, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    entityManager.setEventSystem(eventSystem);
    context.put(EventSystem.class, eventSystem);
    // TODO: Review - NodeClassLibrary related to the UI for behaviours. Should not be here and probably not even in the CoreRegistry
    context.put(OneOfProviderFactory.class, new OneOfProviderFactory());
    registerComponents(library.getComponentLibrary(), environment);
    registerEvents(entityManager.getEventSystem(), environment);
}
Also used : PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) PrefabManager(org.terasology.engine.entitySystem.prefab.PrefabManager) PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) RecordedEventStore(org.terasology.engine.recording.RecordedEventStore) ModuleManager(org.terasology.engine.core.module.ModuleManager) TypeRegistry(org.terasology.reflection.TypeRegistry) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) PojoEntityManager(org.terasology.engine.entitySystem.entity.internal.PojoEntityManager) EntityRefTypeHandler(org.terasology.engine.persistence.typeHandling.extensionTypes.EntityRefTypeHandler) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) CharacterStateEventPositionMap(org.terasology.engine.recording.CharacterStateEventPositionMap)

Example 9 with RecordAndReplayCurrentStatus

use of org.terasology.engine.recording.RecordAndReplayCurrentStatus in project Terasology by MovingBlocks.

the class EntitySerializerTest method setupClass.

@BeforeAll
public static void setupClass() throws Exception {
    context = new ContextImpl();
    CoreRegistry.setContext(context);
    context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
    moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
    assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl) ContextImpl(org.terasology.engine.context.internal.ContextImpl) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with RecordAndReplayCurrentStatus

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

Aggregations

RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)14 ContextImpl (org.terasology.engine.context.internal.ContextImpl)8 ModuleManager (org.terasology.engine.core.module.ModuleManager)8 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)5 NetworkSystem (org.terasology.engine.network.NetworkSystem)5 DirectionAndOriginPosRecorderList (org.terasology.engine.recording.DirectionAndOriginPosRecorderList)5 RecordAndReplaySerializer (org.terasology.engine.recording.RecordAndReplaySerializer)5 RecordAndReplayUtils (org.terasology.engine.recording.RecordAndReplayUtils)5 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)5 ModuleAwareAssetTypeManagerImpl (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl)5 BeforeAll (org.junit.jupiter.api.BeforeAll)4 BlockManager (org.terasology.engine.world.block.BlockManager)4 ExtraBlockDataManager (org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager)4 Path (java.nio.file.Path)3 ReadWriteStorageManager (org.terasology.engine.persistence.internal.ReadWriteStorageManager)3 CharacterStateEventPositionMap (org.terasology.engine.recording.CharacterStateEventPositionMap)3 RecordedEventStore (org.terasology.engine.recording.RecordedEventStore)3 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)3