use of org.terasology.entitySystem.entity.internal.EngineEntityManager in project Terasology by MovingBlocks.
the class CoreCommands method dumpEntities.
/**
* Writes out information on all entities to a text file for debugging
* @throws IOException thrown when error with saving file occures
*/
@Command(shortDescription = "Writes out information on all entities to a text file for debugging", helpText = "Writes entity information out into a file named \"entityDump.txt\".")
public void dumpEntities() throws IOException {
EngineEntityManager engineEntityManager = (EngineEntityManager) entityManager;
PrefabSerializer prefabSerializer = new PrefabSerializer(engineEntityManager.getComponentLibrary(), engineEntityManager.getTypeSerializerLibrary());
WorldDumper worldDumper = new WorldDumper(engineEntityManager, prefabSerializer);
worldDumper.save(PathManager.getInstance().getHomePath().resolve("entityDump.txt"));
}
use of org.terasology.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;
}
use of org.terasology.entitySystem.entity.internal.EngineEntityManager in project Terasology by MovingBlocks.
the class InitialiseWorld method step.
@Override
public boolean step() {
BlockManager blockManager = context.get(BlockManager.class);
BiomeManager biomeManager = context.get(BiomeManager.class);
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
context.put(WorldGeneratorPluginLibrary.class, new DefaultWorldGeneratorPluginLibrary(environment, context));
WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
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(Config.class).getSystem().isWriteSaveGamesEnabled();
Path savePath = PathManager.getInstance().getSavePath(gameManifest.getTitle());
StorageManager storageManager;
try {
storageManager = writeSaveGamesEnabled ? new ReadWriteStorageManager(savePath, environment, entityManager, blockManager, biomeManager) : new ReadOnlyStorageManager(savePath, environment, entityManager, blockManager, biomeManager);
} 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, biomeManager);
context.get(ComponentSystemManager.class).register(new RelevanceSystem(chunkProvider), "engine: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);
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;
BackdropRenderer backdropRenderer = skysphere;
context.put(BackdropProvider.class, backdropProvider);
context.put(BackdropRenderer.class, backdropRenderer);
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
context.put(LocalPlayer.class, new LocalPlayer());
context.put(Camera.class, worldRenderer.getActiveCamera());
return true;
}
use of org.terasology.entitySystem.entity.internal.EngineEntityManager in project Terasology by MovingBlocks.
the class ComponentSerializerTest method setup.
@Before
public void setup() {
context = new ContextImpl();
context.put(ModuleManager.class, moduleManager);
CoreRegistry.setContext(context);
TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary);
serializationLibrary.add(Vector3f.class, new Vector3fTypeHandler());
serializationLibrary.add(Quat4f.class, new Quat4fTypeHandler());
NetworkSystem networkSystem = mock(NetworkSystem.class);
context.put(NetworkSystem.class, networkSystem);
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
EngineEntityManager entityManager = context.get(EngineEntityManager.class);
entityManager.getComponentLibrary().register(new SimpleUri("test", "gettersetter"), GetterSetterComponent.class);
entityManager.getComponentLibrary().register(new SimpleUri("test", "string"), StringComponent.class);
entityManager.getComponentLibrary().register(new SimpleUri("test", "integer"), IntegerComponent.class);
ComponentLibrary componentLibrary = entityManager.getComponentLibrary();
componentSerializer = new ComponentSerializer(componentLibrary, serializationLibrary);
}
use of org.terasology.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());
}
Aggregations