Search in sources :

Example 16 with ReceiveEvent

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

the class ServerCharacterPredictionSystem method onPlayerInput.

@ReceiveEvent(components = { CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onPlayerInput(CharacterMoveInputEvent input, EntityRef entity) {
    CharacterCollider characterCollider = physics.getCharacterCollider(entity);
    if (characterCollider.isPending()) {
        logger.debug("Skipping input, collision not yet established");
        return;
    }
    CircularBuffer<CharacterStateEvent> stateBuffer = characterStates.get(entity);
    CharacterStateEvent lastState = stateBuffer.getLast();
    float delta = input.getDeltaMs() + lastState.getTime() - (time.getGameTimeInMs() + MAX_INPUT_OVERFLOW);
    if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.REPLAYING) {
        delta -= MAX_INPUT_OVERFLOW_REPLAY_INCREASE;
    }
    if (delta < 0) {
        CharacterStateEvent newState = stepState(input, lastState, entity);
        stateBuffer.add(newState);
        if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.REPLAYING) {
            characterStateEventPositionMap.updateCharacterStateEvent(newState);
        } else if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.RECORDING) {
            characterStateEventPositionMap.add(newState.getSequenceNumber(), newState.getPosition(), newState.getVelocity());
        }
        characterMovementSystemUtility.setToState(entity, newState);
        lastInputEvent.put(entity, input);
    } else {
        logger.warn("Received too much input from {}, dropping input. Delta difference: {}", entity, delta);
    }
}
Also used : CharacterCollider(org.terasology.engine.physics.engine.CharacterCollider) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 17 with ReceiveEvent

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

the class CharacterScalingSystem method onScaleByRequest.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void onScaleByRequest(ScaleByRequest request, EntityRef entity, CharacterMovementComponent movementComponent) {
    OnScaleEvent scaleEvent = new OnScaleEvent(movementComponent.height, movementComponent.height * request.getFactor());
    entity.send(scaleEvent);
    request.consume();
}
Also used : OnScaleEvent(org.terasology.engine.logic.characters.events.OnScaleEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 18 with ReceiveEvent

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

the class CharacterScalingSystem method onScaleToRequest.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void onScaleToRequest(ScaleToRequest request, EntityRef entity, CharacterMovementComponent movementComponent) {
    OnScaleEvent scaleEvent = new OnScaleEvent(movementComponent.height, request.getTargetValue());
    entity.send(scaleEvent);
    request.consume();
}
Also used : OnScaleEvent(org.terasology.engine.logic.characters.events.OnScaleEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 19 with ReceiveEvent

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

the class ServerCharacterPredictionSystem method onTeleport.

@ReceiveEvent(components = { CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onTeleport(CharacterTeleportEvent event, EntityRef entity) {
    CircularBuffer<CharacterStateEvent> stateBuffer = characterStates.get(entity);
    CharacterStateEvent lastState = stateBuffer.getLast();
    CharacterStateEvent newState = new CharacterStateEvent(lastState);
    newState.setPosition(new Vector3f(event.getTargetPosition()));
    newState.setTime(time.getGameTimeInMs());
    stateBuffer.add(newState);
    characterMovementSystemUtility.setToState(entity, newState);
}
Also used : Vector3f(org.joml.Vector3f) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 20 with ReceiveEvent

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

the class ServerCharacterPredictionSystem method onImpulse.

@ReceiveEvent(components = { CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onImpulse(CharacterImpulseEvent event, EntityRef entity) {
    Vector3f impulse = event.getDirection();
    CircularBuffer<CharacterStateEvent> stateBuffer = characterStates.get(entity);
    CharacterStateEvent lastState = stateBuffer.getLast();
    CharacterStateEvent newState = new CharacterStateEvent(lastState);
    newState.setVelocity(impulse.add(newState.getVelocity()));
    newState.setTime(time.getGameTimeInMs());
    newState.setGrounded(false);
    stateBuffer.add(newState);
    characterMovementSystemUtility.setToState(entity, newState);
}
Also used : Vector3f(org.joml.Vector3f) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)83 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)27 Vector3f (org.joml.Vector3f)18 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 Vector3i (org.joml.Vector3i)10 StaticSound (org.terasology.engine.audio.StaticSound)10 Vector3ic (org.joml.Vector3ic)9 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 ClientComponent (org.terasology.engine.network.ClientComponent)8 Quaternionf (org.joml.Quaternionf)6 BlockComponent (org.terasology.engine.world.block.BlockComponent)6 OnItemUseEvent (org.terasology.engine.logic.characters.events.OnItemUseEvent)5 Block (org.terasology.engine.world.block.Block)5 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)4 BlockRegion (org.terasology.engine.world.block.BlockRegion)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)3 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)3 Component (org.terasology.gestalt.entitysystem.component.Component)3 Method (java.lang.reflect.Method)2 Vector3fc (org.joml.Vector3fc)2