Skip to content

Commit

Permalink
Sync PP
Browse files Browse the repository at this point in the history
  • Loading branch information
signorpipo committed Nov 16, 2024
1 parent b91c55b commit dbf01e0
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 213 deletions.
4 changes: 2 additions & 2 deletions wle_pp/wle_pp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wle_pp/wle_pp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wle-pp",
"version": "0.7.2",
"version": "0.7.3",
"author": "Pipo",
"description": "A library for the Wonderland Engine",
"homepage": "https://github.com/signorpipo/wle-pp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ export class CharacterColliderWallSlideParams {
export class CharacterColliderSurfaceParams {

constructor() {
this.mySurfaceSnapEnabled = false;
this.mySurfaceSnapMaxDistance = 0;

this.mySurfacePopOutEnabled = false;
this.mySurfacePopOutMaxDistance = 0;

this.mySurfaceAngleToIgnore = 0;
Expand Down Expand Up @@ -507,10 +504,7 @@ CharacterColliderWallSlideParams.prototype.copy = function copy(other) {
};

CharacterColliderSurfaceParams.prototype.copy = function copy(other) {
this.mySurfaceSnapEnabled = other.mySurfaceSnapEnabled;
this.mySurfaceSnapMaxDistance = other.mySurfaceSnapMaxDistance;

this.mySurfacePopOutEnabled = other.mySurfacePopOutEnabled;
this.mySurfacePopOutMaxDistance = other.mySurfacePopOutMaxDistance;

this.mySurfaceAngleToIgnore = other.mySurfaceAngleToIgnore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ export function createSimplified(simplifiedCreationParams: Readonly<CharacterCol

outCharacterColliderSetup.myHorizontalCheckParams.myHorizontalCheckFeetDistanceToIgnore = simplifiedCreationParams.myMaxWalkableGroundStepHeight;

outCharacterColliderSetup.myGroundParams.mySurfaceSnapEnabled = simplifiedCreationParams.myMaxDistanceToSnapOnGround > 0;
outCharacterColliderSetup.myGroundParams.mySurfaceSnapMaxDistance = simplifiedCreationParams.myMaxDistanceToSnapOnGround;
outCharacterColliderSetup.myGroundParams.mySurfacePopOutEnabled = simplifiedCreationParams.myMaxDistanceToPopOutGround > 0;
outCharacterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance = simplifiedCreationParams.myMaxDistanceToPopOutGround;
outCharacterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance = Math.max(outCharacterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance, outCharacterColliderSetup.myHorizontalCheckParams.myHorizontalCheckFeetDistanceToIgnore);
outCharacterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance = Math.max(simplifiedCreationParams.myMaxDistanceToPopOutGround, outCharacterColliderSetup.myHorizontalCheckParams.myHorizontalCheckFeetDistanceToIgnore);

outCharacterColliderSetup.myGroundParams.myHorizontalMovementSurfaceAngleToIgnoreMaxHorizontalMovementLeft = simplifiedCreationParams.myRadius * 0.75;

Expand Down Expand Up @@ -119,9 +116,7 @@ export function createSimplified(simplifiedCreationParams: Readonly<CharacterCol
outCharacterColliderSetup.myHorizontalCheckParams.myHorizontalCheckHeadDistanceToIgnore = simplifiedCreationParams.myMaxWalkableCeilingStepHeight;

if (simplifiedCreationParams.myCheckCeilings) {
outCharacterColliderSetup.myCeilingParams.mySurfacePopOutEnabled = outCharacterColliderSetup.myGroundParams.mySurfacePopOutEnabled;
outCharacterColliderSetup.myCeilingParams.mySurfacePopOutMaxDistance = simplifiedCreationParams.myMaxDistanceToPopOutGround;
outCharacterColliderSetup.myCeilingParams.mySurfacePopOutMaxDistance = Math.max(outCharacterColliderSetup.myCeilingParams.mySurfacePopOutMaxDistance, outCharacterColliderSetup.myHorizontalCheckParams.myHorizontalCheckHeadDistanceToIgnore);
outCharacterColliderSetup.myCeilingParams.mySurfacePopOutMaxDistance = Math.max(simplifiedCreationParams.myMaxDistanceToPopOutGround, outCharacterColliderSetup.myHorizontalCheckParams.myHorizontalCheckHeadDistanceToIgnore);

outCharacterColliderSetup.myCeilingParams.myHorizontalMovementSurfaceAngleToIgnoreMaxHorizontalMovementLeft = outCharacterColliderSetup.myGroundParams.myHorizontalMovementSurfaceAngleToIgnoreMaxHorizontalMovementLeft;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,14 @@ export let convertCharacterColliderSetupToCollisionCheckParams = function () {
outCollisionCheckParams.myHorizontalBlockColliderType = characterColliderSetup.myHorizontalCheckParams.myHorizontalBlockColliderType;
outCollisionCheckParams.myVerticalBlockColliderType = characterColliderSetup.myVerticalCheckParams.myVerticalBlockColliderType;

outCollisionCheckParams.mySnapOnGroundEnabled = characterColliderSetup.myGroundParams.mySurfaceSnapEnabled;
outCollisionCheckParams.mySnapOnGroundEnabled = characterColliderSetup.myGroundParams.mySurfaceSnapMaxDistance > 0;
outCollisionCheckParams.mySnapOnGroundExtraDistance = characterColliderSetup.myGroundParams.mySurfaceSnapMaxDistance;
outCollisionCheckParams.mySnapOnCeilingEnabled = characterColliderSetup.myCeilingParams.mySurfaceSnapEnabled;
outCollisionCheckParams.mySnapOnCeilingEnabled = characterColliderSetup.myCeilingParams.mySurfaceSnapMaxDistance > 0;
outCollisionCheckParams.mySnapOnCeilingExtraDistance = characterColliderSetup.myCeilingParams.mySurfaceSnapMaxDistance;

outCollisionCheckParams.myGroundPopOutEnabled = characterColliderSetup.myGroundParams.mySurfacePopOutEnabled;
outCollisionCheckParams.myGroundPopOutEnabled = characterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance > 0;
outCollisionCheckParams.myGroundPopOutExtraDistance = characterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance;
outCollisionCheckParams.myCeilingPopOutEnabled = characterColliderSetup.myCeilingParams.mySurfacePopOutEnabled;
outCollisionCheckParams.myCeilingPopOutEnabled = characterColliderSetup.myCeilingParams.mySurfacePopOutMaxDistance > 0;
outCollisionCheckParams.myCeilingPopOutExtraDistance = characterColliderSetup.myCeilingParams.mySurfacePopOutMaxDistance;

outCollisionCheckParams.myGroundAngleToIgnore = characterColliderSetup.myGroundParams.mySurfaceAngleToIgnore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import { PlayerLocomotion, PlayerLocomotionParams } from "../player_locomotion.j

/**
* Tips
* - Be sure that your colliders has faces on both sides of the mesh, this helps the collision check which otherise might be able to move through walls
* - Be sure that your colliders have faces on both sides of the mesh, this helps the collision check which otherise might be able to move through walls
*/
export class PlayerLocomotionComponent extends Component {
public static override TypeName = "pp-player-locomotion";



@property.enum(["Smooth", "Teleport"], "Smooth")
private readonly _myDefaultLocomotionType!: number;

Expand Down Expand Up @@ -518,6 +516,10 @@ export class PlayerLocomotionComponent extends Component {
this._myActivateOnNextPostPoseUpdate = false;
}

if (!this._myPlayerLocomotion!.isStarted()) {
this._myPlayerLocomotion!.start();
}

if (!setPlayerLocomotionOnGlobals && Globals.hasPlayerLocomotion(this.engine) && Globals.getPlayerLocomotion(this.engine) != this._myPlayerLocomotion) return;

let startTime = 0;
Expand All @@ -535,10 +537,6 @@ export class PlayerLocomotionComponent extends Component {
PhysicsUtils.resetRaycastCount(this.engine.physics!);
}

if (!this._myPlayerLocomotion!.isStarted()) {
this._myPlayerLocomotion!.start();
}

this._myPlayerLocomotion!.update(dt);

if (this._myPerformanceLogEnabled && Globals.isDebugEnabled(this.engine)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export enum PlayerLocomotionType {
export class PlayerLocomotionParams {

public myDefaultLocomotionType: number = PlayerLocomotionType.SMOOTH;
public myAlwaysSmoothForNonVR: boolean = true;
public myAlwaysSmoothForNonVR: boolean = false;

/** Double press main hand thumbstick (default: left) to switch */
public mySwitchLocomotionTypeShortcutEnabled: boolean = true;
public mySwitchLocomotionTypeShortcutEnabled: boolean = false;

public myStartIdle: boolean = false;

Expand All @@ -59,7 +59,7 @@ export class PlayerLocomotionParams {

public myMaxSpeed: number = 0;
public myMaxRotationSpeed: number = 0;
public mySpeedSlowDownPercentageOnWallSlid: number = 1;
public mySpeedSlowDownPercentageOnWallSlid: number = 0;


public myGravityAcceleration: number = 0;
Expand All @@ -84,7 +84,7 @@ export class PlayerLocomotionParams {


public myMainHand: Handedness = Handedness.LEFT;
public myDirectionInvertForwardWhenUpsideDown: boolean = true;
public myDirectionInvertForwardWhenUpsideDown: boolean = false;
public myVRDirectionReferenceType: PlayerLocomotionDirectionReferenceType = PlayerLocomotionDirectionReferenceType.HEAD;
public myVRDirectionReferenceObject: Readonly<Object3D> | null = null;

Expand All @@ -101,7 +101,7 @@ export class PlayerLocomotionParams {
public myTeleportParableStartReferenceObject: Readonly<Object3D> | null = null;


public myResetRealOnStart: boolean = true;
public myResetRealOnStart: boolean = false;

/**
* #WARN With `_myResetRealOnStartFramesAmount` at `1` it can happen that you enter the session like 1 frame before the game load
Expand All @@ -115,7 +115,7 @@ export class PlayerLocomotionParams {
* For example, if u have a total fade at start and nothing can be seen aside the clear color for at least, let's say, 10 frames,
* you can set this to `3` safely, since there will be no visible stutter to be seen (beside the clear color)
*/
public myResetRealOnStartFramesAmount: number = 1;
public myResetRealOnStartFramesAmount: number = 0;

/** Can fix some head through floor issues, when you can move your head completely to the other side of the floor
If the floors are thick enough that this can't happen, you can leave this to false */
Expand All @@ -127,15 +127,15 @@ export class PlayerLocomotionParams {


/** Valid means, for example, that the real player has not moved inside a wall by moving in the real space */
public mySyncWithRealWorldPositionOnlyIfValid: boolean = true;
public mySyncWithRealWorldPositionOnlyIfValid: boolean = false;

/** Valid means, for example, that the real player has not moved inside a wall by moving in the real space */
public mySyncWithRealHeightOnlyIfValid: boolean = true;
public mySyncWithRealHeightOnlyIfValid: boolean = false;

public mySnapRealPositionToGround: boolean = false;
public myPreventRealFromColliding: boolean = false;

public myViewOcclusionInsideWallsEnabled: boolean = true;
public myViewOcclusionInsideWallsEnabled: boolean = false;
public myViewOcclusionLayerFlags: Readonly<PhysicsLayerFlags> = new PhysicsLayerFlags();

/**
Expand Down Expand Up @@ -227,7 +227,7 @@ export class PlayerLocomotionParams {
/** Main hand (default: left) select + thumbstick press, auto switch to smooth */
public myDebugFlyShortcutEnabled: boolean = false;

public myDebugFlyMaxSpeedMultiplier: number = 5;
public myDebugFlyMaxSpeedMultiplier: number = 0;

/** Main hand (default: left) thumbstick pressed while moving */
public myMoveThroughCollisionShortcutEnabled: boolean = false;
Expand All @@ -247,6 +247,7 @@ export class PlayerLocomotionParams {
public myEngine: Readonly<WonderlandEngine>;



constructor(engine: Readonly<WonderlandEngine> = Globals.getMainEngine()!) {
this.myEngine = engine;
}
Expand All @@ -256,9 +257,10 @@ export class PlayerLocomotionParams {
// #TODO Add lerped snap on vertical over like half a second to avoid the "snap effect"
// This could be done by detatching the actual vertical position of the player from the collision real one when a snap is detected above a certain threshold
// with a timer, after which the vertical position is just copied, while during the detatching is lerped toward the collision vertical one

/**
* Tips
* - Be sure that your colliders has faces on both sides of the mesh, this helps the collision check which otherise might be able to move through walls
* - Be sure that your colliders have faces on both sides of the mesh, this helps the collision check which otherise might be able to move through walls
*/
export class PlayerLocomotion {

Expand Down Expand Up @@ -333,6 +335,36 @@ export class PlayerLocomotion {
params.myTeleportCollisionCheckParamsCheck360 = true;
params.myTeleportCollisionCheckParamsGroundAngleToIgnore = this._myParams.myColliderMaxTeleportableGroundAngle;

params.mySyncEnabledFlagMap.set(PlayerTransformManagerSyncFlag.BODY_COLLIDING, true);
params.mySyncEnabledFlagMap.set(PlayerTransformManagerSyncFlag.HEAD_COLLIDING, true);
params.mySyncEnabledFlagMap.set(PlayerTransformManagerSyncFlag.FAR, true);
params.mySyncEnabledFlagMap.set(PlayerTransformManagerSyncFlag.FLOATING, true);
params.mySyncEnabledFlagMap.set(PlayerTransformManagerSyncFlag.HEIGHT_COLLIDING, true);

params.mySyncPositionFlagMap.set(PlayerTransformManagerSyncFlag.BODY_COLLIDING, true);
params.mySyncPositionFlagMap.set(PlayerTransformManagerSyncFlag.HEAD_COLLIDING, false);
params.mySyncPositionFlagMap.set(PlayerTransformManagerSyncFlag.FAR, true);
params.mySyncPositionFlagMap.set(PlayerTransformManagerSyncFlag.FLOATING, true);
params.mySyncPositionFlagMap.set(PlayerTransformManagerSyncFlag.HEIGHT_COLLIDING, false);

params.mySyncPositionHeadFlagMap.set(PlayerTransformManagerSyncFlag.BODY_COLLIDING, false);
params.mySyncPositionHeadFlagMap.set(PlayerTransformManagerSyncFlag.HEAD_COLLIDING, true);
params.mySyncPositionHeadFlagMap.set(PlayerTransformManagerSyncFlag.FAR, false);
params.mySyncPositionHeadFlagMap.set(PlayerTransformManagerSyncFlag.FLOATING, false);
params.mySyncPositionHeadFlagMap.set(PlayerTransformManagerSyncFlag.HEIGHT_COLLIDING, false);

params.mySyncRotationFlagMap.set(PlayerTransformManagerSyncFlag.BODY_COLLIDING, false);
params.mySyncRotationFlagMap.set(PlayerTransformManagerSyncFlag.HEAD_COLLIDING, false);
params.mySyncRotationFlagMap.set(PlayerTransformManagerSyncFlag.FAR, false);
params.mySyncRotationFlagMap.set(PlayerTransformManagerSyncFlag.FLOATING, false);
params.mySyncRotationFlagMap.set(PlayerTransformManagerSyncFlag.HEIGHT_COLLIDING, false);

params.mySyncHeightFlagMap.set(PlayerTransformManagerSyncFlag.BODY_COLLIDING, false);
params.mySyncHeightFlagMap.set(PlayerTransformManagerSyncFlag.HEAD_COLLIDING, false);
params.mySyncHeightFlagMap.set(PlayerTransformManagerSyncFlag.FAR, false);
params.mySyncHeightFlagMap.set(PlayerTransformManagerSyncFlag.FLOATING, false);
params.mySyncHeightFlagMap.set(PlayerTransformManagerSyncFlag.HEIGHT_COLLIDING, true);

params.myHeadCollisionBlockLayerFlags.copy(this._myParams.myViewOcclusionLayerFlags);
params.myHeadCollisionObjectsToIgnore.pp_copy(params.myMovementCollisionCheckParams.myHorizontalObjectsToIgnore as any);
const objectsEqualCallback = (first: Readonly<Object3D>, second: Readonly<Object3D>): boolean => first == second;
Expand Down Expand Up @@ -360,11 +392,9 @@ export class PlayerLocomotion {

if (!this._myParams.myViewOcclusionInsideWallsEnabled) {
params.mySyncEnabledFlagMap.set(PlayerTransformManagerSyncFlag.HEAD_COLLIDING, false);

params.myAlwaysSyncHeadPositionWithReal = true;

params.myUpdatePositionHeadValid = false;
params.myUpdateRealPositionHeadValid = false;
} else {
params.myUpdatePositionHeadValid = true;
}

params.myApplyRealToValidAdjustmentsToRealPositionToo = this._myParams.mySnapRealPositionToGround;
Expand Down Expand Up @@ -427,6 +457,10 @@ export class PlayerLocomotion {
params.myNeverResetRealRotationVR = false;
params.myNeverResetRealHeightVR = true;

params.myResetRealResetRotationIfUpChanged = true;
params.myResetHeadToFeetMoveTowardReal = true;
params.myResetHeadToFeetUpOffset = 0.25;

params.myDebugEnabled = false;

this._myPlayerTransformManager = new PlayerTransformManager(params);
Expand Down
Loading

0 comments on commit dbf01e0

Please sign in to comment.