Search in sources :

Example 1 with EventSerializer

use of org.terasology.engine.persistence.serializers.EventSerializer in project Terasology by MovingBlocks.

the class VectorEventSerializer method setup.

@BeforeEach
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    context.put(ReflectFactory.class, reflectFactory);
    context.put(CopyStrategyLibrary.class, copyStrategies);
    ModuleTypeRegistry typeRegistry = new ModuleTypeRegistry(moduleManager.getEnvironment());
    TypeHandlerLibrary typeHandlerLibrary = TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry);
    entitySystemLibrary = new EntitySystemLibrary(context, typeHandlerLibrary);
    serializer = new EventSerializer(entitySystemLibrary.getEventLibrary(), typeHandlerLibrary);
    registerEvent(Vector3fTestEvent.class);
    serializer.setIdMapping(eventMap);
}
Also used : ModuleTypeRegistry(org.terasology.reflection.ModuleTypeRegistry) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) EventSerializer(org.terasology.engine.persistence.serializers.EventSerializer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with EventSerializer

use of org.terasology.engine.persistence.serializers.EventSerializer 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.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");
    TypeHandlerLibrary typeHandlerLibrary = entityManager.getTypeSerializerLibrary().copy();
    typeHandlerLibrary.addTypeHandler(EntityRef.class, new NetEntityRefTypeHandler(this, blockEntityRegistry));
    // TODO: Add network override types here (that use id lookup tables)
    eventSerializer = new EventSerializer(eventLibrary, typeHandlerLibrary);
    entitySerializer = new NetworkEntitySerializer(newEntityManager, entityManager.getComponentLibrary(), typeHandlerLibrary);
    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 : OwnershipHelper(org.terasology.engine.entitySystem.entity.internal.OwnershipHelper) BlockManager(org.terasology.engine.world.block.BlockManager) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) StorageManager(org.terasology.engine.persistence.StorageManager) NetworkEntitySerializer(org.terasology.engine.persistence.serializers.NetworkEntitySerializer) NetComponentSerializeCheck(org.terasology.engine.network.serialization.NetComponentSerializeCheck) NetEntityRefTypeHandler(org.terasology.engine.network.serialization.NetEntityRefTypeHandler) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) EventSerializer(org.terasology.engine.persistence.serializers.EventSerializer)

Aggregations

EventSerializer (org.terasology.engine.persistence.serializers.EventSerializer)2 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 OwnershipHelper (org.terasology.engine.entitySystem.entity.internal.OwnershipHelper)1 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)1 NetComponentSerializeCheck (org.terasology.engine.network.serialization.NetComponentSerializeCheck)1 NetEntityRefTypeHandler (org.terasology.engine.network.serialization.NetEntityRefTypeHandler)1 StorageManager (org.terasology.engine.persistence.StorageManager)1 NetworkEntitySerializer (org.terasology.engine.persistence.serializers.NetworkEntitySerializer)1 BlockManager (org.terasology.engine.world.block.BlockManager)1 ModuleTypeRegistry (org.terasology.reflection.ModuleTypeRegistry)1