Search in sources :

Example 1 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class AbstractState method initEntityAndComponentManagers.

protected void initEntityAndComponentManagers(boolean isHeadless) {
    verifyNotNull(context);
    CoreRegistry.setContext(context);
    // let's get the entity event system running
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
    eventSystem = context.get(EventSystem.class);
    context.put(Console.class, new ConsoleImpl(context));
    if (!isHeadless) {
        NUIManager nuiManager = new NUIManagerInternal((TerasologyCanvasRenderer) context.get(CanvasRenderer.class), context);
        context.put(NUIManager.class, nuiManager);
    }
    componentSystemManager = new ComponentSystemManager(context);
    context.put(ComponentSystemManager.class, componentSystemManager);
    componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
    componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) ConsoleSystem(org.terasology.engine.logic.console.ConsoleSystem) ConsoleImpl(org.terasology.engine.logic.console.ConsoleImpl) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) NUIManager(org.terasology.engine.rendering.nui.NUIManager) CoreCommands(org.terasology.engine.logic.console.commands.CoreCommands) NUIManagerInternal(org.terasology.engine.rendering.nui.internal.NUIManagerInternal) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager)

Example 2 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class EntitySystemSetupUtil method createEventSystem.

private static EventSystem createEventSystem(NetworkSystem networkSystem, PojoEntityManager entityManager, EntitySystemLibrary library, RecordedEventStore recordedEventStore, RecordAndReplaySerializer recordAndReplaySerializer, RecordAndReplayUtils recordAndReplayUtils, RecordAndReplayCurrentStatus recordAndReplayCurrentStatus) {
    EventSystem eventSystem;
    List<Class<?>> selectedClassesToRecord = createSelectedClassesToRecordList();
    if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.PREPARING_REPLAY) {
        eventSystem = new EventSystemReplayImpl(library.getEventLibrary(), networkSystem, entityManager, recordedEventStore, recordAndReplaySerializer, recordAndReplayUtils, selectedClassesToRecord, recordAndReplayCurrentStatus);
    } else {
        EventCatcher eventCatcher = new EventCatcher(selectedClassesToRecord, recordedEventStore);
        eventSystem = new EventSystemImpl(networkSystem.getMode().isAuthority());
        eventSystem = new NetworkEventSystemDecorator(eventSystem, networkSystem, library.getEventLibrary());
        eventSystem = new RecordingEventSystemDecorator(eventSystem, eventCatcher, recordAndReplayCurrentStatus);
    }
    return eventSystem;
}
Also used : EventCatcher(org.terasology.engine.recording.EventCatcher) NetworkEventSystemDecorator(org.terasology.engine.network.NetworkEventSystemDecorator) EventSystemReplayImpl(org.terasology.engine.recording.EventSystemReplayImpl) RecordingEventSystemDecorator(org.terasology.engine.recording.RecordingEventSystemDecorator) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) EventSystemImpl(org.terasology.engine.entitySystem.event.internal.EventSystemImpl)

Example 3 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem 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 TypeHandlerLibrary}</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) {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    ModuleEnvironment environment = moduleManager.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
    TypeHandlerLibrary typeHandlerLibrary = context.get(TypeHandlerLibrary.class);
    typeHandlerLibrary.addTypeHandler(EntityRef.class, new EntityRefTypeHandler(entityManager));
    entityManager.setTypeSerializerLibrary(typeHandlerLibrary);
    // 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());
    // Record and Replay
    RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    RecordAndReplayUtils recordAndReplayUtils = context.get(RecordAndReplayUtils.class);
    CharacterStateEventPositionMap characterStateEventPositionMap = context.get(CharacterStateEventPositionMap.class);
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = context.get(DirectionAndOriginPosRecorderList.class);
    RecordedEventStore recordedEventStore = new RecordedEventStore();
    RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, context.get(TypeRegistry.class));
    context.put(RecordAndReplaySerializer.class, recordAndReplaySerializer);
    // Event System
    EventSystem eventSystem = createEventSystem(networkSystem, entityManager, library, recordedEventStore, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    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 : PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) PrefabManager(org.terasology.engine.entitySystem.prefab.PrefabManager) PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) RecordedEventStore(org.terasology.engine.recording.RecordedEventStore) ModuleManager(org.terasology.engine.core.module.ModuleManager) TypeRegistry(org.terasology.reflection.TypeRegistry) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) PojoEntityManager(org.terasology.engine.entitySystem.entity.internal.PojoEntityManager) EntityRefTypeHandler(org.terasology.engine.persistence.typeHandling.extensionTypes.EntityRefTypeHandler) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) CharacterStateEventPositionMap(org.terasology.engine.recording.CharacterStateEventPositionMap)

Example 4 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testChangeComponentEventSentWhenSave.

@Test
public void testChangeComponentEventSentWhenSave() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    StringComponent comp = entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    entity1.saveComponent(comp);
    verify(eventSystem).send(entity1, OnChangedComponent.newInstance(), comp);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 5 with EventSystem

use of org.terasology.engine.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class LwjglPortlet method setupThreads.

public void setupThreads() {
    GameThread.reset();
    GameThread.setToCurrentThread();
    graphics.setThreadMode(LwjglGraphicsManager.ThreadMode.GAME_THREAD);
    EventSystem eventSystem = CoreRegistry.get(EventSystem.class);
    if (eventSystem != null) {
        eventSystem.setToCurrentThread();
    }
}
Also used : EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem)

Aggregations

EventSystem (org.terasology.engine.entitySystem.event.internal.EventSystem)10 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)6 Test (org.junit.jupiter.api.Test)5 StringComponent (org.terasology.unittest.stubs.StringComponent)5 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)1 PojoEntityManager (org.terasology.engine.entitySystem.entity.internal.PojoEntityManager)1 EventSystemImpl (org.terasology.engine.entitySystem.event.internal.EventSystemImpl)1 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)1 PrefabManager (org.terasology.engine.entitySystem.prefab.PrefabManager)1 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)1 ConsoleImpl (org.terasology.engine.logic.console.ConsoleImpl)1 ConsoleSystem (org.terasology.engine.logic.console.ConsoleSystem)1 CoreCommands (org.terasology.engine.logic.console.commands.CoreCommands)1 NetworkEventSystemDecorator (org.terasology.engine.network.NetworkEventSystemDecorator)1 NetworkSystem (org.terasology.engine.network.NetworkSystem)1 EntityRefTypeHandler (org.terasology.engine.persistence.typeHandling.extensionTypes.EntityRefTypeHandler)1 CharacterStateEventPositionMap (org.terasology.engine.recording.CharacterStateEventPositionMap)1 DirectionAndOriginPosRecorderList (org.terasology.engine.recording.DirectionAndOriginPosRecorderList)1