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();
}
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;
}
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);
}
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);
}
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);
}
Aggregations