use of org.terasology.engine.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();
}
use of org.terasology.engine.entitySystem.entity.internal.EngineEntityManager in project Terasology by MovingBlocks.
the class CoreCommands method dumpEntities.
/**
* Writes out information on entities having specific components to a text file for debugging
* If no component names provided - writes out information on all entities
*
* @param componentNames string contains one or several component names, if more then one name
* provided - they must be braced with double quotes and all names separated
* by space
* @return String containing information about number of entities saved
* @throws IOException thrown when error with saving file occures
*/
@Command(shortDescription = "Writes out information on all entities to a JSON file for debugging", helpText = "Writes entity information out into a file named \"<timestamp>-entityDump.json\"." + " Supports list of component names, which will be used to only save entities that contains" + " one or more of those components. Names should be separated by spaces.")
public String dumpEntities(@CommandParam(value = "componentNames", required = false) String... componentNames) throws IOException {
int savedEntityCount;
EngineEntityManager engineEntityManager = (EngineEntityManager) entityManager;
PrefabSerializer prefabSerializer = new PrefabSerializer(engineEntityManager.getComponentLibrary(), engineEntityManager.getTypeSerializerLibrary());
WorldDumper worldDumper = new WorldDumper(engineEntityManager, prefabSerializer);
Path outFile = PathManager.getInstance().getHomePath().resolve(Instant.now() + "-entityDump.json");
if (componentNames.length == 0) {
savedEntityCount = worldDumper.save(outFile);
} else {
List<Class<? extends Component>> filterComponents = Arrays.stream(componentNames).map(// Trim off whitespace
String::trim).filter(// Remove empty strings
o -> !o.isEmpty()).map(// All component class names end with "component"
o -> o.toLowerCase().endsWith("component") ? o : o + "component").map(o -> Streams.stream(moduleManager.getEnvironment().getSubtypesOf(Component.class)).filter(e -> e.getSimpleName().equalsIgnoreCase(o)).findFirst()).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
if (!filterComponents.isEmpty()) {
savedEntityCount = worldDumper.save(outFile, filterComponents);
} else {
return "Could not find components matching given names";
}
}
return "Number of entities saved: " + savedEntityCount;
}
use of org.terasology.engine.entitySystem.entity.internal.EngineEntityManager in project Terasology by MovingBlocks.
the class InitialiseWorld method step.
@Override
public boolean step() {
BlockManager blockManager = context.get(BlockManager.class);
ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
context.put(WorldGeneratorPluginLibrary.class, new DefaultWorldGeneratorPluginLibrary(environment, context));
WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
verify(worldInfo.getWorldGenerator().isValid(), "Game manifest did not specify world type.");
if (worldInfo.getSeed() == null || worldInfo.getSeed().isEmpty()) {
FastRandom random = new FastRandom();
worldInfo.setSeed(random.nextString(16));
}
logger.info("World seed: \"{}\"", worldInfo.getSeed());
// TODO: Separate WorldRenderer from world handling in general
WorldGeneratorManager worldGeneratorManager = context.get(WorldGeneratorManager.class);
WorldGenerator worldGenerator;
try {
worldGenerator = WorldGeneratorManager.createGenerator(worldInfo.getWorldGenerator(), context);
// setting the world seed will create the world builder
worldGenerator.setWorldSeed(worldInfo.getSeed());
context.put(WorldGenerator.class, worldGenerator);
} catch (UnresolvedWorldGeneratorException e) {
logger.error("Unable to load world generator {}. Available world generators: {}", worldInfo.getWorldGenerator(), worldGeneratorManager.getWorldGenerators());
context.get(GameEngine.class).changeState(new StateMainMenu("Failed to resolve world generator."));
// We need to return true, otherwise the loading state will just call us again immediately
return true;
}
// Init. a new world
EngineEntityManager entityManager = (EngineEntityManager) context.get(EntityManager.class);
boolean writeSaveGamesEnabled = context.get(SystemConfig.class).writeSaveGamesEnabled.get();
// Gets save data from a normal save or from a recording if it is a replay
Path saveOrRecordingPath = getSaveOrRecordingPath();
StorageManager storageManager;
RecordAndReplaySerializer recordAndReplaySerializer = context.get(RecordAndReplaySerializer.class);
RecordAndReplayUtils recordAndReplayUtils = context.get(RecordAndReplayUtils.class);
RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
try {
storageManager = writeSaveGamesEnabled ? new ReadWriteStorageManager(saveOrRecordingPath, environment, entityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus) : new ReadOnlyStorageManager(saveOrRecordingPath, environment, entityManager, blockManager, extraDataManager);
} catch (IOException e) {
logger.error("Unable to create storage manager!", e);
context.get(GameEngine.class).changeState(new StateMainMenu("Unable to create storage manager!"));
// We need to return true, otherwise the loading state will just call us again immediately
return true;
}
context.put(StorageManager.class, storageManager);
LocalChunkProvider chunkProvider = new LocalChunkProvider(storageManager, entityManager, worldGenerator, blockManager, extraDataManager, Maps.newConcurrentMap());
RelevanceSystem relevanceSystem = new RelevanceSystem(chunkProvider);
context.put(RelevanceSystem.class, relevanceSystem);
context.get(ComponentSystemManager.class).register(relevanceSystem, "engine:relevanceSystem");
chunkProvider.setRelevanceSystem(relevanceSystem);
Block unloadedBlock = blockManager.getBlock(BlockManager.UNLOADED_ID);
WorldProviderCoreImpl worldProviderCore = new WorldProviderCoreImpl(worldInfo, chunkProvider, unloadedBlock, context);
EntityAwareWorldProvider entityWorldProvider = new EntityAwareWorldProvider(worldProviderCore, context);
WorldProvider worldProvider = new WorldProviderWrapper(entityWorldProvider, extraDataManager);
context.put(WorldProvider.class, worldProvider);
chunkProvider.setBlockEntityRegistry(entityWorldProvider);
context.put(BlockEntityRegistry.class, entityWorldProvider);
context.get(ComponentSystemManager.class).register(entityWorldProvider, "engine:BlockEntityRegistry");
DefaultCelestialSystem celestialSystem = new DefaultCelestialSystem(new BasicCelestialModel(), context);
context.put(CelestialSystem.class, celestialSystem);
context.get(ComponentSystemManager.class).register(celestialSystem);
Skysphere skysphere = new Skysphere(context);
BackdropProvider backdropProvider = skysphere;
context.put(BackdropProvider.class, backdropProvider);
RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
context.put(WorldRenderer.class, worldRenderer);
// TODO: These shouldn't be done here, nor so strongly tied to the world renderer
LocalPlayer localPlayer = new LocalPlayer();
localPlayer.setRecordAndReplayClasses(context.get(DirectionAndOriginPosRecorderList.class), context.get(RecordAndReplayCurrentStatus.class));
context.put(LocalPlayer.class, localPlayer);
context.put(Camera.class, worldRenderer.getActiveCamera());
return true;
}
use of org.terasology.engine.entitySystem.entity.internal.EngineEntityManager in project Terasology by MovingBlocks.
the class InitialiseSystems method step.
@Override
public boolean step() {
EngineEntityManager entityManager = (EngineEntityManager) context.get(EntityManager.class);
EventLibrary eventLibrary = context.get(EventLibrary.class);
BlockEntityRegistry blockEntityRegistry = context.get(BlockEntityRegistry.class);
context.get(NetworkSystem.class).connectToEntitySystem(entityManager, eventLibrary, blockEntityRegistry);
ComponentSystemManager csm = context.get(ComponentSystemManager.class);
csm.initialise();
return true;
}
Aggregations