use of org.terasology.engine.recording.RecordAndReplayUtils 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);
}
use of org.terasology.engine.recording.RecordAndReplayUtils 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));
}
use of org.terasology.engine.recording.RecordAndReplayUtils 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);
}
use of org.terasology.engine.recording.RecordAndReplayUtils 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));
}
use of org.terasology.engine.recording.RecordAndReplayUtils in project Terasology by MovingBlocks.
the class ExtrasMenuScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
RecordScreen recordScreen = getManager().createScreen(RecordScreen.ASSET_URI, RecordScreen.class);
ReplayScreen replayScreen = getManager().createScreen(ReplayScreen.ASSET_URI, ReplayScreen.class);
WidgetUtil.trySubscribe(this, "record", button -> {
recordAndReplayCurrentStatus.setStatus(RecordAndReplayStatus.PREPARING_RECORD);
RecordAndReplayUtils recordAndReplayUtils = engine.createChildContext().get(RecordAndReplayUtils.class);
recordScreen.setRecordAndReplayUtils(recordAndReplayUtils);
triggerForwardAnimation(recordScreen);
});
WidgetUtil.trySubscribe(this, "replay", button -> {
RecordAndReplayUtils recordAndReplayUtils = engine.createChildContext().get(RecordAndReplayUtils.class);
replayScreen.setRecordAndReplayUtils(recordAndReplayUtils);
recordAndReplayCurrentStatus.setStatus(RecordAndReplayStatus.PREPARING_REPLAY);
triggerForwardAnimation(replayScreen);
});
WidgetUtil.trySubscribe(this, "credits", button -> triggerForwardAnimation(CreditsScreen.ASSET_URI));
WidgetUtil.trySubscribe(this, "telemetry", button -> triggerForwardAnimation(TelemetryScreen.ASSET_URI));
WidgetUtil.trySubscribe(this, "crashReporter", widget -> CrashReporter.report(new Throwable("There is no error."), LoggingContext.getLoggingPath(), CrashReporter.MODE.ISSUE_REPORTER));
WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
}
Aggregations