Skip to content

Commit

Permalink
Sync PP
Browse files Browse the repository at this point in the history
  • Loading branch information
signorpipo committed Nov 15, 2024
1 parent 8ce386a commit b91c55b
Show file tree
Hide file tree
Showing 27 changed files with 639 additions and 438 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.1",
"version": "0.7.2",
"author": "Pipo",
"description": "A library for the Wonderland Engine",
"homepage": "https://github.com/signorpipo/wle-pp",
Expand Down
6 changes: 3 additions & 3 deletions wle_pp/wle_pp/src/pp/cauldron/visual/visual_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export class VisualManager {

public setActive(active: boolean): void {
if (this._myActive != active) {
this._myActive = active;

if (!this._myActive) {
if (!active) {
this.clearAllVisualElements();
} else {
this._myVisualElementsParent = Globals.getSceneObjects(this._myEngine)?.myVisualElements ?? null;
}

this._myActive = active;
}
}

Expand Down
19 changes: 8 additions & 11 deletions wle_pp/wle_pp/src/pp/debug/components/debug_manager_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ export class DebugManagerComponent extends Component {
this._myInitDone = true;
}

start() {
update(dt) {
if (!this._myInitDone && Globals.isDebugEnabled(this.engine)) {
this._init();

if (this._myDebugManager != null && !Globals.hasDebugManager(this.engine)) {
Globals.setDebugManager(this._myDebugManager, this.engine);
}
} else if (this._myDebugManager != null && !Globals.hasDebugManager(this.engine) &&
Globals.isDebugEnabled(this.engine) && this._myCurrentActive != Globals.isDebugEnabled(this.engine)) {
Globals.setDebugManager(this._myDebugManager, this.engine);
}
}

update(dt) {
if (this._myDebugManager != null && Globals.getDebugManager(this.engine) == this._myDebugManager) {
if (this._myCurrentActive != Globals.isDebugEnabled(this.engine)) {
this._myCurrentActive = Globals.isDebugEnabled(this.engine);
Expand All @@ -46,14 +51,6 @@ export class DebugManagerComponent extends Component {
}

this._myDebugManager.update(dt);
} else if (!this._myInitDone && Globals.isDebugEnabled(this.engine)) {
this._init();
}
}

onActivate() {
if (this._myDebugManager != null && !Globals.hasDebugManager(this.engine)) {
Globals.setDebugManager(this._myDebugManager, this.engine);
}
}

Expand Down
11 changes: 6 additions & 5 deletions wle_pp/wle_pp/src/pp/debug/components/enable_debug_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ export class EnableDebugComponent extends Component {
_myEnable: Property.bool(true)
};

init() {
start() {
this._myHasDebugEnabled = this._myEnable;
this._myDebugEnabled = this._myEnable;
}

onActivate() {
if (!Globals.hasDebugEnabled(this.engine)) {
if (this._myHasDebugEnabled) {
Globals.setDebugEnabled(this._myDebugEnabled, this.engine);
}
}

onDeactivate() {
if (Globals.isDebugEnabled(this.engine) == this._myDebugEnabled) {
Globals.removeDebugEnabled(this.engine);
}
this._myHasDebugEnabled = Globals.hasDebugEnabled();
this._myDebugEnabled = Globals.isDebugEnabled();
Globals.removeDebugEnabled(this.engine);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ShowFPSComponent extends Component {
}

update(dt) {
if (Globals.isDebugEnabled(this.engine)) {
if (Globals.isDebugEnabled(this.engine) && Globals.getDebugVisualManager(this.engine) != null) {
this._myTotalDT += dt;
this._myFrames++;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class CharacterColliderSetupSimplifiedCreationParams {


public myCollectGroundInfo: boolean = false;
public myShouldSnapOnGround: boolean = false;
public myMaxDistanceToSnapOnGround: number = 0;
public myMaxDistanceToPopOutGround: number = 0;
public myMaxWalkableGroundAngle: number = 0;
public myMaxWalkableGroundStepHeight: number = 0;

Expand Down Expand Up @@ -86,11 +86,10 @@ export function createSimplified(simplifiedCreationParams: Readonly<CharacterCol

outCharacterColliderSetup.myHorizontalCheckParams.myHorizontalCheckFeetDistanceToIgnore = simplifiedCreationParams.myMaxWalkableGroundStepHeight;

outCharacterColliderSetup.myGroundParams.mySurfaceSnapEnabled = simplifiedCreationParams.myShouldSnapOnGround;
outCharacterColliderSetup.myGroundParams.mySurfaceSnapEnabled = simplifiedCreationParams.myMaxDistanceToSnapOnGround > 0;
outCharacterColliderSetup.myGroundParams.mySurfaceSnapMaxDistance = simplifiedCreationParams.myMaxDistanceToSnapOnGround;
outCharacterColliderSetup.myGroundParams.mySurfacePopOutEnabled = true;
outCharacterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance = simplifiedCreationParams.myMaxDistanceToSnapOnGround > 0 ?
simplifiedCreationParams.myMaxDistanceToSnapOnGround : (simplifiedCreationParams.myRadius > 0.1) ? 0.1 : 0.01;
outCharacterColliderSetup.myGroundParams.mySurfacePopOutEnabled = simplifiedCreationParams.myMaxDistanceToPopOutGround > 0;
outCharacterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance = simplifiedCreationParams.myMaxDistanceToPopOutGround;
outCharacterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance = Math.max(outCharacterColliderSetup.myGroundParams.mySurfacePopOutMaxDistance, outCharacterColliderSetup.myHorizontalCheckParams.myHorizontalCheckFeetDistanceToIgnore);

outCharacterColliderSetup.myGroundParams.myHorizontalMovementSurfaceAngleToIgnoreMaxHorizontalMovementLeft = simplifiedCreationParams.myRadius * 0.75;
Expand Down Expand Up @@ -121,7 +120,7 @@ export function createSimplified(simplifiedCreationParams: Readonly<CharacterCol

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

outCharacterColliderSetup.myCeilingParams.myHorizontalMovementSurfaceAngleToIgnoreMaxHorizontalMovementLeft = outCharacterColliderSetup.myGroundParams.myHorizontalMovementSurfaceAngleToIgnoreMaxHorizontalMovementLeft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class PlayerLocomotionComponent extends Component {
@property.bool(true)
private readonly _mySwitchLocomotionTypeShortcutEnabled!: boolean;

@property.bool(false)
private readonly _myStartIdle!: boolean;

@property.string("0, 0, 0, 0, 0, 0, 0, 0")
private readonly _myPhysicsBlockLayerFlags!: string;

Expand Down Expand Up @@ -211,12 +214,11 @@ export class PlayerLocomotionComponent extends Component {

/**
* To avoid occlusion issues when moving when touching a tilted ceiling (which is not commong anyway),
* this would be better to be less or equal than the feet radius of the character (usually half of {@link _myCharacterRadius})
* Increasing {@link _myColliderExtraHeight} can help reducing the view occlusion
* this value should be a bit lower than {@link _myCharacterFeetRadius}
*
* If you have a high camera near value, you might need to increase this value, even though the view occlusion might become more aggressive
*/
@property.float(0.15)
@property.float(0.145)
private readonly _myViewOcclusionHeadRadius!: number;

/**
Expand Down Expand Up @@ -295,6 +297,9 @@ export class PlayerLocomotionComponent extends Component {
@property.float(0.1)
private readonly _myColliderMaxDistanceToSnapOnGround!: number;

@property.float(0.2)
private readonly _myColliderMaxDistanceToPopOutGround!: number;

@property.float(0.1)
private readonly _myColliderMaxWalkableGroundStepHeight!: number;

Expand Down Expand Up @@ -371,7 +376,7 @@ export class PlayerLocomotionComponent extends Component {



private readonly _myPlayerLocomotion!: PlayerLocomotion;
private readonly _myPlayerLocomotion: PlayerLocomotion | null = null;

private _myRegisterToPostPoseUpdateOnNextUpdate: boolean = false;
private _myActivateOnNextPostPoseUpdate: boolean = false;
Expand All @@ -388,6 +393,7 @@ export class PlayerLocomotionComponent extends Component {
params.myDefaultLocomotionType = this._myDefaultLocomotionType;
params.myAlwaysSmoothForNonVR = this._myAlwaysSmoothForNonVR;
params.mySwitchLocomotionTypeShortcutEnabled = this._mySwitchLocomotionTypeShortcutEnabled;
params.myStartIdle = this._myStartIdle;

params.myDefaultHeight = this._myDefaultHeight;
params.myMinHeight = this._myMinHeight;
Expand Down Expand Up @@ -464,6 +470,7 @@ export class PlayerLocomotionComponent extends Component {
params.myColliderMaxTeleportableGroundAngle = this._myColliderMaxTeleportableGroundAngle < 0 ? null : this._myColliderMaxTeleportableGroundAngle;
params.myColliderSnapOnGround = this._myColliderSnapOnGround;
params.myColliderMaxDistanceToSnapOnGround = this._myColliderMaxDistanceToSnapOnGround;
params.myColliderMaxDistanceToPopOutGround = this._myColliderMaxDistanceToPopOutGround;
params.myColliderMaxWalkableGroundStepHeight = this._myColliderMaxWalkableGroundStepHeight;
params.myColliderMaxWalkableCeilingStepHeight = this._myColliderMaxWalkableCeilingStepHeight;
params.myColliderPreventFallingFromEdges = this._myColliderPreventFallingFromEdges;
Expand Down Expand Up @@ -504,13 +511,14 @@ export class PlayerLocomotionComponent extends Component {

if (manualUpdate) return;

let setPlayerLocomotionOnGlobals = false;
if (this._myActivateOnNextPostPoseUpdate) {
this._onActivate();
setPlayerLocomotionOnGlobals = this._onActivate();

this._myActivateOnNextPostPoseUpdate = false;
}

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

let startTime = 0;
if (this._myPerformanceLogEnabled && Globals.isDebugEnabled(this.engine)) {
Expand All @@ -527,11 +535,11 @@ export class PlayerLocomotionComponent extends Component {
PhysicsUtils.resetRaycastCount(this.engine.physics!);
}

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

this._myPlayerLocomotion.update(dt);
this._myPlayerLocomotion!.update(dt);

if (this._myPerformanceLogEnabled && Globals.isDebugEnabled(this.engine)) {
const endTime = window.performance.now();
Expand Down Expand Up @@ -559,9 +567,17 @@ export class PlayerLocomotionComponent extends Component {
console.log("Raycast count: " + PhysicsUtils.getRaycastCount(this.engine.physics!));
PhysicsUtils.resetRaycastCount(this.engine.physics!);
}

if (setPlayerLocomotionOnGlobals && !Globals.hasPlayerLocomotion(this.engine)) {
// This is done to only set the global when the locomotion is active and updated, so "ready"
Globals.setPlayerLocomotion(this._myPlayerLocomotion!, this.engine);
} else if (setPlayerLocomotionOnGlobals && Globals.getPlayerLocomotion(this.engine) != this._myPlayerLocomotion) {
// If someone in some way managed to set the globals, just deactivate this one, which was just being activated since the flag is true
this._myPlayerLocomotion!.setActive(false);
}
}

public getPlayerLocomotion(): PlayerLocomotion {
public getPlayerLocomotion(): PlayerLocomotion | null {
return this._myPlayerLocomotion;
}

Expand All @@ -582,15 +598,19 @@ export class PlayerLocomotionComponent extends Component {
}
}

private _onActivate(): void {
private _onActivate(): boolean {
let setPlayerLocomotionOnGlobals = false;

if (this._myPlayerLocomotion == null) {
this._start();
}

if (!Globals.hasPlayerLocomotion(this.engine)) {
this._myPlayerLocomotion.setActive(true);
Globals.setPlayerLocomotion(this._myPlayerLocomotion, this.engine);
this._myPlayerLocomotion!.setActive(true);
setPlayerLocomotionOnGlobals = true;
}

return setPlayerLocomotionOnGlobals;
}

private _getPhysicsBlockLayersFlags(): PhysicsLayerFlags {
Expand Down
Loading

0 comments on commit b91c55b

Please sign in to comment.