Search in sources :

Example 1 with NetworkSystem

use of org.terasology.network.NetworkSystem in project Terasology by MovingBlocks.

the class GameConfigurationMetric method fetchNetworkMode.

private void fetchNetworkMode() {
    NetworkSystem networkSystem = context.get(NetworkSystem.class);
    networkMode = networkSystem.getMode().toString();
}
Also used : NetworkSystem(org.terasology.network.NetworkSystem)

Example 2 with NetworkSystem

use of org.terasology.network.NetworkSystem in project Terasology by MovingBlocks.

the class RegisterBlocks method step.

@Override
public boolean step() {
    NetworkSystem networkSystem = context.get(NetworkSystem.class);
    WorldAtlas atlas = new WorldAtlasImpl(context.get(Config.class).getRendering().getMaxTextureAtlasResolution());
    context.put(WorldAtlas.class, atlas);
    BlockManagerImpl blockManager;
    if (networkSystem.getMode().isAuthority()) {
        blockManager = new BlockManagerImpl(atlas, context.get(AssetManager.class), true);
        blockManager.subscribe(context.get(NetworkSystem.class));
    } else {
        blockManager = new BlockManagerImpl(atlas, context.get(AssetManager.class), false);
    }
    context.put(BlockManager.class, blockManager);
    context.get(TypeSerializationLibrary.class).add(Block.class, new BlockTypeHandler(blockManager));
    context.get(TypeSerializationLibrary.class).add(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));
    blockManager.initialise(gameManifest.getRegisteredBlockFamilies(), gameManifest.getBlockIdMap());
    return true;
}
Also used : WorldAtlasImpl(org.terasology.world.block.tiles.WorldAtlasImpl) Config(org.terasology.config.Config) NetworkSystem(org.terasology.network.NetworkSystem) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) BlockTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.BlockTypeHandler) WorldAtlas(org.terasology.world.block.tiles.WorldAtlas) BlockManagerImpl(org.terasology.world.block.internal.BlockManagerImpl) BlockFamilyTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.BlockFamilyTypeHandler)

Example 3 with NetworkSystem

use of org.terasology.network.NetworkSystem 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 org.terasology.persistence.typeHandling.TypeSerializationLibrary}</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) {
    ModuleEnvironment environment = context.get(ModuleManager.class).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
    TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
    typeSerializationLibrary.add(EntityRef.class, new EntityRefTypeHandler(entityManager));
    entityManager.setTypeSerializerLibrary(typeSerializationLibrary);
    // 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());
    // Event System
    EventSystem eventSystem = new EventSystemImpl(library.getEventLibrary(), networkSystem);
    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 : OneOfProviderFactory(org.terasology.rendering.nui.properties.OneOfProviderFactory) PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) ModuleEnvironment(org.terasology.module.ModuleEnvironment) EntitySystemLibrary(org.terasology.entitySystem.metadata.EntitySystemLibrary) PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) PrefabManager(org.terasology.entitySystem.prefab.PrefabManager) NetworkSystem(org.terasology.network.NetworkSystem) EntityRefTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.EntityRefTypeHandler) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) ModuleManager(org.terasology.engine.module.ModuleManager) EventSystemImpl(org.terasology.entitySystem.event.internal.EventSystemImpl)

Example 4 with NetworkSystem

use of org.terasology.network.NetworkSystem 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);
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) Vector3fTypeHandler(org.terasology.persistence.typeHandling.mathTypes.Vector3fTypeHandler) NetworkSystem(org.terasology.network.NetworkSystem) SimpleUri(org.terasology.engine.SimpleUri) ComponentLibrary(org.terasology.entitySystem.metadata.ComponentLibrary) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) Quat4fTypeHandler(org.terasology.persistence.typeHandling.mathTypes.Quat4fTypeHandler) ContextImpl(org.terasology.context.internal.ContextImpl) ComponentSerializer(org.terasology.persistence.serializers.ComponentSerializer) Before(org.junit.Before)

Example 5 with NetworkSystem

use of org.terasology.network.NetworkSystem in project Terasology by MovingBlocks.

the class StorageManagerTest method setup.

@Before
public void setup() throws Exception {
    super.setup();
    JavaArchive homeArchive = ShrinkWrap.create(JavaArchive.class);
    FileSystem vfs = ShrinkWrapFileSystems.newFileSystem(homeArchive);
    PathManager.getInstance().useOverrideHomePath(temporaryFolder.getRoot().toPath());
    savePath = PathManager.getInstance().getSavePath("testSave");
    assert !Files.isRegularFile(vfs.getPath("global.dat"));
    entityManager = context.get(EngineEntityManager.class);
    moduleEnvironment = context.get(ModuleEnvironment.class);
    blockManager = context.get(BlockManager.class);
    biomeManager = context.get(BiomeManager.class);
    esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, biomeManager, false);
    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.setFamilyFactory(new SymmetricBlockFamilyFactory());
    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));
    BiomeManager mockBiomeManager = mock(BiomeManager.class);
    when(mockBiomeManager.getBiomes()).thenReturn(Collections.<Biome>emptyList());
    context.put(BiomeManager.class, mockBiomeManager);
    WorldProvider worldProvider = mock(WorldProvider.class);
    when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
    context.put(WorldProvider.class, worldProvider);
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) BiomeManager(org.terasology.world.biomes.BiomeManager) AssetManager(org.terasology.assets.management.AssetManager) NetworkSystem(org.terasology.network.NetworkSystem) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BlockFamilyDefinitionData(org.terasology.world.block.loader.BlockFamilyDefinitionData) ModuleEnvironment(org.terasology.module.ModuleEnvironment) BlockManager(org.terasology.world.block.BlockManager) FileSystem(java.nio.file.FileSystem) WorldProvider(org.terasology.world.WorldProvider) WorldInfo(org.terasology.world.internal.WorldInfo) Client(org.terasology.network.Client) ResourceUrn(org.terasology.assets.ResourceUrn) ChunkProvider(org.terasology.world.chunks.ChunkProvider) SymmetricBlockFamilyFactory(org.terasology.world.block.family.SymmetricBlockFamilyFactory) Before(org.junit.Before)

Aggregations

NetworkSystem (org.terasology.network.NetworkSystem)11 TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)5 Before (org.junit.Before)4 ContextImpl (org.terasology.context.internal.ContextImpl)3 ModuleManager (org.terasology.engine.module.ModuleManager)3 PojoPrefabManager (org.terasology.entitySystem.prefab.internal.PojoPrefabManager)3 ModuleEnvironment (org.terasology.module.ModuleEnvironment)3 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 PojoEntityManager (org.terasology.entitySystem.entity.internal.PojoEntityManager)2 EventSystemImpl (org.terasology.entitySystem.event.internal.EventSystemImpl)2 ComponentLibrary (org.terasology.entitySystem.metadata.ComponentLibrary)2 EntitySystemLibrary (org.terasology.entitySystem.metadata.EntitySystemLibrary)2 NetworkSystemImpl (org.terasology.network.internal.NetworkSystemImpl)2 BiomeManager (org.terasology.world.biomes.BiomeManager)2 FileSystem (java.nio.file.FileSystem)1 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)1 ResourceUrn (org.terasology.assets.ResourceUrn)1 AssetManager (org.terasology.assets.management.AssetManager)1 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)1 Config (org.terasology.config.Config)1