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