Search in sources :

Example 1 with TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.

the class NetworkSystemImpl method connectToEntitySystem.

@Override
public void connectToEntitySystem(EngineEntityManager newEntityManager, EventLibrary newEventLibrary, BlockEntityRegistry blockEntityRegistry) {
    if (this.entityManager != null) {
        this.entityManager.unsubscribe(this);
    }
    this.entityManager = newEntityManager;
    this.entityManager.subscribeForChanges(this);
    this.blockManager = context.get(BlockManager.class);
    this.biomeManager = context.get(BiomeManager.class);
    this.ownershipHelper = new OwnershipHelper(newEntityManager.getComponentLibrary());
    this.storageManager = context.get(StorageManager.class);
    this.eventLibrary = newEventLibrary;
    this.componentLibrary = entityManager.getComponentLibrary();
    context.get(ComponentSystemManager.class).register(new NetworkEntitySystem(this), "engine:networkEntitySystem");
    TypeSerializationLibrary typeSerializationLibrary = new TypeSerializationLibrary(entityManager.getTypeSerializerLibrary());
    typeSerializationLibrary.add(EntityRef.class, new NetEntityRefTypeHandler(this, blockEntityRegistry));
    // TODO: Add network override types here (that use id lookup tables)
    eventSerializer = new EventSerializer(eventLibrary, typeSerializationLibrary);
    entitySerializer = new NetworkEntitySerializer(newEntityManager, entityManager.getComponentLibrary(), typeSerializationLibrary);
    entitySerializer.setComponentSerializeCheck(new NetComponentSerializeCheck());
    if (mode == NetworkMode.CLIENT) {
        entityManager.setEntityRefStrategy(new NetworkClientRefStrategy(this));
        applySerializationTables();
    }
    if (server != null) {
        server.connectToEntitySystem(newEntityManager, entitySerializer, eventSerializer, blockEntityRegistry);
    }
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) OwnershipHelper(org.terasology.entitySystem.entity.internal.OwnershipHelper) BlockManager(org.terasology.world.block.BlockManager) StorageManager(org.terasology.persistence.StorageManager) NetworkEntitySerializer(org.terasology.persistence.serializers.NetworkEntitySerializer) NetComponentSerializeCheck(org.terasology.network.serialization.NetComponentSerializeCheck) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) NetEntityRefTypeHandler(org.terasology.network.serialization.NetEntityRefTypeHandler) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) EventSerializer(org.terasology.persistence.serializers.EventSerializer)

Example 2 with TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.

the class EnvironmentSwitchHandler method handleSwitchToGameEnvironment.

@SuppressWarnings("unchecked")
public void handleSwitchToGameEnvironment(Context context) {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    CopyStrategyLibrary copyStrategyLibrary = context.get(CopyStrategyLibrary.class);
    copyStrategyLibrary.clear();
    for (Class<? extends CopyStrategy> copyStrategy : moduleManager.getEnvironment().getSubtypesOf(CopyStrategy.class)) {
        if (copyStrategy.getAnnotation(RegisterCopyStrategy.class) == null) {
            continue;
        }
        Class<?> targetType = ReflectionUtil.getTypeParameterForSuper(copyStrategy, CopyStrategy.class, 0);
        if (targetType != null) {
            registerCopyStrategy(copyStrategyLibrary, targetType, copyStrategy);
        } else {
            logger.error("Cannot register CopyStrategy '{}' - unable to determine target type", copyStrategy);
        }
    }
    ReflectFactory reflectFactory = context.get(ReflectFactory.class);
    TypeSerializationLibrary typeSerializationLibrary = TypeSerializationLibrary.createDefaultLibrary(reflectFactory, copyStrategyLibrary);
    typeSerializationLibrary.add(CollisionGroup.class, new CollisionGroupTypeHandler(context.get(CollisionGroupManager.class)));
    context.put(TypeSerializationLibrary.class, typeSerializationLibrary);
    // Entity System Library
    EntitySystemLibrary library = new EntitySystemLibrary(context, typeSerializationLibrary);
    context.put(EntitySystemLibrary.class, library);
    ComponentLibrary componentLibrary = library.getComponentLibrary();
    context.put(ComponentLibrary.class, componentLibrary);
    context.put(EventLibrary.class, library.getEventLibrary());
    context.put(ClassMetaLibrary.class, new ClassMetaLibraryImpl(context));
    registerComponents(componentLibrary, moduleManager.getEnvironment());
    registerTypeHandlers(context, typeSerializationLibrary, moduleManager.getEnvironment());
    BlockFamilyFactoryRegistry blockFamilyFactoryRegistry = context.get(BlockFamilyFactoryRegistry.class);
    loadFamilies((DefaultBlockFamilyFactoryRegistry) blockFamilyFactoryRegistry, moduleManager.getEnvironment());
    ModuleAwareAssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class);
    /*
         * The registering of the prefab formats is done in this method, because it needs to be done before
         * the environment of the asset manager gets changed.
         *
         * It can't be done before this method gets called because the ComponentLibrary isn't
         * existing then yet.
         */
    unregisterPrefabFormats(assetTypeManager);
    registeredPrefabFormat = new PrefabFormat(componentLibrary, typeSerializationLibrary);
    assetTypeManager.registerCoreFormat(Prefab.class, registeredPrefabFormat);
    registeredPrefabDeltaFormat = new PrefabDeltaFormat(componentLibrary, typeSerializationLibrary);
    assetTypeManager.registerCoreDeltaFormat(Prefab.class, registeredPrefabDeltaFormat);
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
}
Also used : ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) PrefabFormat(org.terasology.entitySystem.prefab.internal.PrefabFormat) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) PrefabDeltaFormat(org.terasology.entitySystem.prefab.internal.PrefabDeltaFormat) ModuleManager(org.terasology.engine.module.ModuleManager) RegisterCopyStrategy(org.terasology.reflection.copy.RegisterCopyStrategy) CollisionGroupTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.CollisionGroupTypeHandler) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) EntitySystemLibrary(org.terasology.entitySystem.metadata.EntitySystemLibrary) ComponentLibrary(org.terasology.entitySystem.metadata.ComponentLibrary) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) DefaultBlockFamilyFactoryRegistry(org.terasology.world.block.family.DefaultBlockFamilyFactoryRegistry) BlockFamilyFactoryRegistry(org.terasology.world.block.family.BlockFamilyFactoryRegistry)

Example 3 with TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.

the class EntitySystemSetupUtil method addReflectionBasedLibraries.

public static void addReflectionBasedLibraries(Context context) {
    ReflectionReflectFactory reflectFactory = new ReflectionReflectFactory();
    context.put(ReflectFactory.class, reflectFactory);
    CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
    context.put(CopyStrategyLibrary.class, copyStrategyLibrary);
    TypeSerializationLibrary typeSerializationLibrary = TypeSerializationLibrary.createDefaultLibrary(reflectFactory, copyStrategyLibrary);
    context.put(TypeSerializationLibrary.class, typeSerializationLibrary);
    EntitySystemLibrary library = new EntitySystemLibrary(context, typeSerializationLibrary);
    context.put(EntitySystemLibrary.class, library);
    context.put(ComponentLibrary.class, library.getComponentLibrary());
    context.put(EventLibrary.class, library.getEventLibrary());
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) EntitySystemLibrary(org.terasology.entitySystem.metadata.EntitySystemLibrary) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary)

Example 4 with TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary 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 5 with TypeSerializationLibrary

use of org.terasology.persistence.typeHandling.TypeSerializationLibrary 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)

Aggregations

TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)13 ModuleManager (org.terasology.engine.module.ModuleManager)5 EntitySystemLibrary (org.terasology.entitySystem.metadata.EntitySystemLibrary)5 CopyStrategyLibrary (org.terasology.reflection.copy.CopyStrategyLibrary)5 Before (org.junit.Before)4 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)4 ContextImpl (org.terasology.context.internal.ContextImpl)4 PojoPrefabManager (org.terasology.entitySystem.prefab.internal.PojoPrefabManager)4 NetworkSystem (org.terasology.network.NetworkSystem)4 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)4 ReflectionReflectFactory (org.terasology.reflection.reflect.ReflectionReflectFactory)4 SimpleUri (org.terasology.engine.SimpleUri)3 ComponentLibrary (org.terasology.entitySystem.metadata.ComponentLibrary)3 Test (org.junit.Test)2 PojoEntityManager (org.terasology.entitySystem.entity.internal.PojoEntityManager)2 EventSystemImpl (org.terasology.entitySystem.event.internal.EventSystemImpl)2 Prefab (org.terasology.entitySystem.prefab.Prefab)2 PrefabData (org.terasology.entitySystem.prefab.PrefabData)2 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)2 PrefabFormat (org.terasology.entitySystem.prefab.internal.PrefabFormat)2