Skip to content

Commit

Permalink
Merge pull request #2961 from @flo
Browse files Browse the repository at this point in the history
Remove hackish and not multiplayer ready crouch visuals.
  • Loading branch information
oniatus authored Dec 21, 2017
2 parents 6b228e0 + 1c14c6d commit 9168c3a
Showing 1 changed file with 7 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -54,12 +54,10 @@
import org.terasology.logic.characters.GazeMountPointComponent;
import org.terasology.logic.characters.MovementMode;
import org.terasology.logic.characters.events.OnItemUseEvent;
import org.terasology.logic.characters.events.SetMovementModeEvent;
import org.terasology.logic.characters.interactions.InteractionUtil;
import org.terasology.logic.debug.MovementDebugCommands;
import org.terasology.logic.delay.DelayManager;
import org.terasology.logic.location.LocationComponent;
import org.terasology.logic.notifications.NotificationMessageEvent;
import org.terasology.logic.players.event.OnPlayerSpawnedEvent;
import org.terasology.math.AABB;
import org.terasology.math.Direction;
@@ -68,9 +66,7 @@
import org.terasology.math.geom.Vector3f;
import org.terasology.network.ClientComponent;
import org.terasology.network.NetworkSystem;
import org.terasology.physics.engine.CharacterCollider;
import org.terasology.physics.engine.PhysicsEngine;
import org.terasology.physics.engine.SweepCallback;
import org.terasology.registry.In;
import org.terasology.rendering.AABBRenderer;
import org.terasology.rendering.BlockOverlayRenderer;
@@ -84,8 +80,6 @@

import java.util.List;

import static org.terasology.logic.characters.KinematicCharacterMover.VERTICAL_PENETRATION_LEEWAY;

// TODO: This needs a really good cleanup
// TODO: Move more input stuff to a specific input system?
// TODO: Camera should become an entity/component, so it can follow the player naturally
@@ -121,13 +115,14 @@ public class LocalPlayerSystem extends BaseComponentSystem implements UpdateSubs
private boolean isAutoMove;
private boolean runPerDefault = true;
private boolean run = runPerDefault;
private boolean crouch;
private boolean crouchPerDefault = false;
private boolean crouch = false;

private boolean jump;
private float lookPitch;
private float lookPitchDelta;
private float lookYaw;
private float lookYawDelta;
private float crouchFraction = 0.5f;

@In
private Time time;
@@ -194,46 +189,6 @@ private void processInput(EntityRef entity, CharacterMovementComponent character
jump = false;
}

/**
* Reduces height and eyeHeight by crouchFraction and changes MovementMode.
*/
private void crouchPlayer(EntityRef entity) {
crouch = true;
ClientComponent clientComp = entity.getComponent(ClientComponent.class);
GazeMountPointComponent gazeMountPointComponent = clientComp.character.getComponent(GazeMountPointComponent.class);
float height = clientComp.character.getComponent(CharacterMovementComponent.class).height;
float eyeHeight = gazeMountPointComponent.translate.getY();
movementDebugCommands.playerHeight(localPlayer.getClientEntity(), height * crouchFraction);
movementDebugCommands.playerEyeHeight(localPlayer.getClientEntity(), eyeHeight * crouchFraction);
clientComp.character.send(new SetMovementModeEvent(MovementMode.CROUCHING));
}

/**
* Checks if there is an impenetrable block above,
* Raises a Notification "Cannot stand up here!" if present
* If not present, increases height and eyeHeight by crouchFraction and changes MovementMode.
*/
private void standPlayer(EntityRef entity) {
crouch = false;
ClientComponent clientComp = entity.getComponent(ClientComponent.class);
GazeMountPointComponent gazeMountPointComponent = clientComp.character.getComponent(GazeMountPointComponent.class);
float height = clientComp.character.getComponent(CharacterMovementComponent.class).height;
float eyeHeight = gazeMountPointComponent.translate.getY();
Vector3f pos = entity.getComponent(LocationComponent.class).getWorldPosition();
// Check for collision when rising
CharacterCollider collider = physics.getCharacterCollider(clientComp.character);
// height used below = (1 - crouch_fraction) * standing_height
Vector3f to = new Vector3f(pos.x, pos.y + (1 - crouchFraction) * height / crouchFraction, pos.z);
SweepCallback callback = collider.sweep(pos, to, VERTICAL_PENETRATION_LEEWAY, -1f);
if (callback.hasHit()) {
entity.send(new NotificationMessageEvent("Cannot stand up here!", entity));
return;
}
movementDebugCommands.playerHeight(localPlayer.getClientEntity(), height / crouchFraction);
movementDebugCommands.playerEyeHeight(localPlayer.getClientEntity(), eyeHeight / crouchFraction);
clientComp.character.send(new SetMovementModeEvent(MovementMode.WALKING));
}

// To check if a valid key has been assigned, either primary or secondary and return it
private Input getValidKey(List<Input> inputs) {
for (Input input : inputs) {
@@ -377,26 +332,16 @@ public void onToggleSpeedTemporarily(ToggleSpeedTemporarilyButton event, EntityR
// Crouches if button is pressed. Stands if button is released.
@ReceiveEvent(components = {ClientComponent.class}, priority = EventPriority.PRIORITY_NORMAL)
public void onCrouchTemporarily(CrouchButton event, EntityRef entity) {
ClientComponent clientComp = entity.getComponent(ClientComponent.class);
CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
if (event.isDown() && move.mode == MovementMode.WALKING) {
crouchPlayer(entity);
} else if (!event.isDown() && move.mode == MovementMode.CROUCHING) {
standPlayer(entity);
}
boolean toggle = event.isDown();
crouch = crouchPerDefault ^ toggle;
event.consume();
}

@ReceiveEvent(components = {ClientComponent.class}, priority = EventPriority.PRIORITY_NORMAL)
public void onCrouchMode(CrouchModeButton event, EntityRef entity) {
ClientComponent clientComp = entity.getComponent(ClientComponent.class);
CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
if (event.isDown()) {
if (move.mode == MovementMode.WALKING) {
crouchPlayer(entity);
} else if (move.mode == MovementMode.CROUCHING) {
standPlayer(entity);
}
crouchPerDefault = !crouchPerDefault;
crouch = !crouch;
}
event.consume();
}

0 comments on commit 9168c3a

Please sign in to comment.