mirror of
https://github.com/sndrec/WebMonkeyBall.git
synced 2026-02-03 10:13:33 +00:00
clean up debug
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { mat3, vec3 } from 'gl-matrix';
|
||||
import { MatrixStack, atan2S16, atan2S16Detail, atan2S16Safe, clamp, sqrt, sumSq2, sumSq3, rsqrt, toS16 } from './math.js';
|
||||
import { MatrixStack, atan2S16, atan2S16Safe, clamp, sqrt, sumSq2, sumSq3, rsqrt, toS16 } from './math.js';
|
||||
import { smoothstep } from './animation.js';
|
||||
import { BALL_FLAGS, CAMERA_STATE, COLI_FLAGS } from './constants.js';
|
||||
|
||||
@@ -49,14 +49,7 @@ function applyMat3ToVec(out, mtx) {
|
||||
|
||||
function cameraFaceDirection(camera, lookDir) {
|
||||
camera.rotY = atan2S16(lookDir.x, lookDir.z) - 0x8000;
|
||||
const debug = (globalThis as any).__DETERMINISM_DEBUG__;
|
||||
if (debug) {
|
||||
debug.source = 'cameraRotX';
|
||||
}
|
||||
camera.rotX = atan2S16Safe(lookDir.y, sqrt(sumSq2(lookDir.x, lookDir.z)));
|
||||
if (debug) {
|
||||
debug.source = null;
|
||||
}
|
||||
camera.rotZ = 0;
|
||||
}
|
||||
|
||||
@@ -215,7 +208,6 @@ export class GameplayCamera {
|
||||
}
|
||||
|
||||
initReady(stageRuntime, startRotY, startPos, flyInFrames = 90) {
|
||||
const debug = (globalThis as any).__DETERMINISM_DEBUG__;
|
||||
if (stageRuntime?.stage?.format === 'smb2') {
|
||||
this.initReadySmb2(stageRuntime, startRotY, startPos, flyInFrames);
|
||||
return;
|
||||
@@ -240,13 +232,7 @@ export class GameplayCamera {
|
||||
tmpVec.y = this.unk54.y - tmpVec.y;
|
||||
tmpVec.z = this.unk54.z - tmpVec.z;
|
||||
this.unk6C = toS16(atan2S16(tmpVec.x, tmpVec.z) - 0x8000);
|
||||
if (debug) {
|
||||
debug.source = 'cameraUnk68';
|
||||
}
|
||||
this.unk68 = atan2S16Safe(tmpVec.y, sqrt(sumSq2(tmpVec.x, tmpVec.z)));
|
||||
if (debug) {
|
||||
debug.source = null;
|
||||
}
|
||||
this.unk70 = 0;
|
||||
|
||||
this.unk74.x = startPos.x;
|
||||
@@ -262,23 +248,7 @@ export class GameplayCamera {
|
||||
tmpVec.y = this.unk74.y - tmpVec.y;
|
||||
tmpVec.z = this.unk74.z - tmpVec.z;
|
||||
this.unk8C = toS16(atan2S16(tmpVec.x, tmpVec.z) - 0x8000) + 0x10000;
|
||||
if (debug) {
|
||||
debug.source = 'cameraUnk88';
|
||||
}
|
||||
this.unk88 = atan2S16Safe(tmpVec.y, sqrt(sumSq2(tmpVec.x, tmpVec.z)));
|
||||
if (debug) {
|
||||
debug.source = null;
|
||||
}
|
||||
if (debug?.cameraInit) {
|
||||
debug.cameraInit.push({
|
||||
mode: 'smb1',
|
||||
stageId: stageRuntime?.stage?.stageId ?? null,
|
||||
unk6C: this.unk6C,
|
||||
unk68: this.unk68,
|
||||
unk8C: this.unk8C,
|
||||
unk88: this.unk88,
|
||||
});
|
||||
}
|
||||
this.unk90 = 0;
|
||||
this.flags |= 1;
|
||||
this.timerCurr = flyInFrames;
|
||||
@@ -288,7 +258,6 @@ export class GameplayCamera {
|
||||
}
|
||||
|
||||
initReadySmb2(stageRuntime, startRotY, startPos, flyInFrames = 90) {
|
||||
const debug = (globalThis as any).__DETERMINISM_DEBUG__;
|
||||
this.reset();
|
||||
this.readyMode = 'smb2';
|
||||
const stageId = stageRuntime?.stage?.stageId ?? -1;
|
||||
@@ -319,13 +288,7 @@ export class GameplayCamera {
|
||||
tmpVec.y = this.unk54.y - tmpVec.y;
|
||||
tmpVec.z = this.unk54.z - tmpVec.z;
|
||||
this.unk6C = toS16(atan2S16(tmpVec.x, tmpVec.z) - 0x8000 + preset.yawOffset);
|
||||
if (debug) {
|
||||
debug.source = 'cameraUnk68';
|
||||
}
|
||||
this.unk68 = atan2S16Safe(tmpVec.y, sqrt(sumSq2(tmpVec.x, tmpVec.z)));
|
||||
if (debug) {
|
||||
debug.source = null;
|
||||
}
|
||||
this.unk70 = 0;
|
||||
|
||||
const pivotYOffset = (stageId === 0x15a ? 0 : 0.18) + 0.8;
|
||||
@@ -339,16 +302,6 @@ export class GameplayCamera {
|
||||
this.timerCurr = flyInFrames;
|
||||
this.timerMax = flyInFrames;
|
||||
this.state = CAMERA_STATE.READY_MAIN;
|
||||
if (debug?.cameraInit) {
|
||||
debug.cameraInit.push({
|
||||
mode: 'smb2',
|
||||
stageId,
|
||||
unk6C: this.unk6C,
|
||||
unk68: this.unk68,
|
||||
unk8C: this.unk8C,
|
||||
unk88: this.unk88,
|
||||
});
|
||||
}
|
||||
this.updateReadyMain(false, false);
|
||||
}
|
||||
|
||||
@@ -385,7 +338,6 @@ export class GameplayCamera {
|
||||
}
|
||||
|
||||
updateLevelMain(ball, paused) {
|
||||
const debug = (globalThis as any).__DETERMINISM_DEBUG__;
|
||||
if (paused) {
|
||||
return;
|
||||
}
|
||||
@@ -421,34 +373,7 @@ export class GameplayCamera {
|
||||
|
||||
let pitch = 0;
|
||||
if (ball.unk80 >= 60) {
|
||||
if (debug) {
|
||||
debug.source = 'cameraPitch';
|
||||
}
|
||||
pitch = atan2S16Safe(tmpVec.y, sqrt(sumSq2(tmpVec.x, tmpVec.z)));
|
||||
if (debug) {
|
||||
debug.source = null;
|
||||
}
|
||||
}
|
||||
if (debug?.cameraPitch) {
|
||||
if (this._debugPrevPitch === undefined) {
|
||||
this._debugPrevPitch = pitch;
|
||||
} else {
|
||||
const delta = toS16(pitch - this._debugPrevPitch);
|
||||
if (Math.abs(delta) >= 128) {
|
||||
const denom = sqrt(sumSq2(tmpVec.x, tmpVec.z));
|
||||
const detail = atan2S16Detail(tmpVec.y, denom);
|
||||
debug.cameraPitch.push({
|
||||
tick: debug.tick ?? null,
|
||||
pitch,
|
||||
prev: this._debugPrevPitch,
|
||||
delta,
|
||||
tmpVec: { x: tmpVec.x, y: tmpVec.y, z: tmpVec.z },
|
||||
denom,
|
||||
detail,
|
||||
});
|
||||
}
|
||||
this._debugPrevPitch = pitch;
|
||||
}
|
||||
}
|
||||
|
||||
let yaw = toS16(atan2S16(tmpVec.x, tmpVec.z) - 0x8000);
|
||||
@@ -506,21 +431,6 @@ export class GameplayCamera {
|
||||
this.unk10C = toS16(yaw - this.rotY);
|
||||
this.rotY = yaw;
|
||||
this.rotX = toS16(pitchSmoothed + 62208);
|
||||
if (debug?.cameraYaw) {
|
||||
if (this._debugYawCount === undefined) {
|
||||
this._debugYawCount = 0;
|
||||
}
|
||||
if (this._debugYawCount < 200) {
|
||||
debug.cameraYaw.push({
|
||||
tick: debug.tick ?? null,
|
||||
yaw,
|
||||
rotY: this.rotY,
|
||||
deltaYaw,
|
||||
tmpVec: { x: tmpVec.x, y: tmpVec.y, z: tmpVec.z },
|
||||
});
|
||||
this._debugYawCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
stack.fromTranslate(this.lookAt);
|
||||
stack.rotateY(this.rotY);
|
||||
@@ -540,7 +450,6 @@ export class GameplayCamera {
|
||||
}
|
||||
|
||||
updateLevelMainSmb2(ball, stageRuntime, paused) {
|
||||
const debug = (globalThis as any).__DETERMINISM_DEBUG__;
|
||||
if (paused) {
|
||||
return;
|
||||
}
|
||||
@@ -582,13 +491,7 @@ export class GameplayCamera {
|
||||
|
||||
let pitchRaw = 0;
|
||||
if (ball.unk80 >= 60) {
|
||||
if (debug) {
|
||||
debug.source = 'cameraPitchRaw';
|
||||
}
|
||||
pitchRaw = atan2S16Safe(tmpVec.y, sqrt(sumSq2(tmpVec.x, tmpVec.z)));
|
||||
if (debug) {
|
||||
debug.source = null;
|
||||
}
|
||||
}
|
||||
|
||||
let yaw = toS16(atan2S16(tmpVec.x, tmpVec.z) - 0x8000);
|
||||
|
||||
@@ -683,19 +683,6 @@ function collideBallWithTriFace(ball, tri) {
|
||||
function collideBallWithTriEdge(ball, ballPosTri, ballPrevPosTri, edge) {
|
||||
stack.push();
|
||||
stack.fromIdentity();
|
||||
const debug = (globalThis as any).__DETERMINISM_DEBUG__;
|
||||
if (debug?.edgeNormals) {
|
||||
const sum = Math.abs(edge.normal.x) + Math.abs(edge.normal.y);
|
||||
if (sum <= debug.edgeEps) {
|
||||
debug.edgeNormals.push({
|
||||
tick: debug.tick ?? null,
|
||||
normal: { x: edge.normal.x, y: edge.normal.y },
|
||||
edgeStart: { x: edge.start.x, y: edge.start.y },
|
||||
edgeEnd: { x: edge.end.x, y: edge.end.y },
|
||||
sum,
|
||||
});
|
||||
}
|
||||
}
|
||||
stack.translateXYZ(edge.start.x, edge.start.y, 0);
|
||||
const edgeNormalLenSq = sumSq2(edge.normal.x, edge.normal.y);
|
||||
if (edgeNormalLenSq > FLT_EPSILON) {
|
||||
|
||||
@@ -1862,10 +1862,6 @@ export class Game {
|
||||
}
|
||||
this.stageRuntime.goalHoldOpen = this.goalTimerFrames > 0;
|
||||
while (!this.pendingAdvance && this.accumulator >= this.fixedStep) {
|
||||
const debug = (globalThis as any).__DETERMINISM_DEBUG__;
|
||||
if (debug) {
|
||||
debug.tick = this.simTick;
|
||||
}
|
||||
const tickStart = this.simPerf.enabled ? nowMs() : 0;
|
||||
try {
|
||||
const ringoutActive = this.ringoutTimerFrames > 0;
|
||||
|
||||
120
src/math.ts
120
src/math.ts
@@ -94,36 +94,6 @@ function atanS16(value) {
|
||||
return result * sign;
|
||||
}
|
||||
|
||||
function atanS16WithDetail(value) {
|
||||
if (value === 0) {
|
||||
return { angle: 0, index: 0, raw: 0 };
|
||||
}
|
||||
let sign = 1;
|
||||
let x = value;
|
||||
if (x < 0) {
|
||||
sign = -1;
|
||||
x = -x;
|
||||
}
|
||||
if (x === 1) {
|
||||
return { angle: sign * 0x2000, index: 0, raw: 0x2000 };
|
||||
}
|
||||
let invert = false;
|
||||
if (x > 1) {
|
||||
x = 1 / x;
|
||||
invert = true;
|
||||
}
|
||||
x = f32(x);
|
||||
const index = atanIndex(x);
|
||||
const slope = ATAN_TABLE[index * 2];
|
||||
const intercept = ATAN_TABLE[index * 2 + 1];
|
||||
const angle = f32(f32(x * slope) + intercept);
|
||||
let result = roundToNearestEven(angle);
|
||||
if (invert) {
|
||||
result = 0x4000 - result;
|
||||
}
|
||||
return { angle: result * sign, index, raw: angle };
|
||||
}
|
||||
|
||||
export function atan2S16(y, x) {
|
||||
const yy = f32(y);
|
||||
const xx = f32(x);
|
||||
@@ -133,24 +103,13 @@ export function atan2S16(y, x) {
|
||||
const ay = Math.abs(yy);
|
||||
const ax = Math.abs(xx);
|
||||
let angle;
|
||||
let ratio = 0;
|
||||
let atanIndexUsed = -1;
|
||||
let atanRaw = 0;
|
||||
if (ay === ax) {
|
||||
angle = ay === 0 ? 0 : 0x2000;
|
||||
} else if (ay > ax) {
|
||||
ratio = ax / ay;
|
||||
const atanDetail = atanS16WithDetail(ratio);
|
||||
atanIndexUsed = atanDetail.index;
|
||||
atanRaw = atanDetail.raw;
|
||||
angle = atanDetail.angle;
|
||||
angle = atanS16(ax / ay);
|
||||
angle = 0x4000 - angle;
|
||||
} else {
|
||||
ratio = ay / ax;
|
||||
const atanDetail = atanS16WithDetail(ratio);
|
||||
atanIndexUsed = atanDetail.index;
|
||||
atanRaw = atanDetail.raw;
|
||||
angle = atanDetail.angle;
|
||||
angle = atanS16(ay / ax);
|
||||
}
|
||||
if (xx < 0) {
|
||||
if (yy >= 0) {
|
||||
@@ -161,30 +120,7 @@ export function atan2S16(y, x) {
|
||||
} else if (yy < 0) {
|
||||
angle = -angle;
|
||||
}
|
||||
const result = toS16(angle);
|
||||
const debug = (globalThis as any).__DETERMINISM_DEBUG__;
|
||||
if (debug?.atan2 && debug.remaining > 0) {
|
||||
const sum = Math.abs(yy) + Math.abs(xx);
|
||||
if (sum <= (debug.eps ?? 0)) {
|
||||
debug.remaining -= 1;
|
||||
if (debug.records) {
|
||||
const stack = debug.stack ? new Error().stack : null;
|
||||
debug.records.push({
|
||||
tick: debug.tick ?? null,
|
||||
source: debug.source ?? null,
|
||||
x: xx,
|
||||
y: yy,
|
||||
angle: result,
|
||||
sum,
|
||||
ratio,
|
||||
atanIndexUsed,
|
||||
atanRaw,
|
||||
stack,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return toS16(angle);
|
||||
}
|
||||
|
||||
export function atan2S16Safe(y, x, eps = EPSILON) {
|
||||
@@ -194,56 +130,6 @@ export function atan2S16Safe(y, x, eps = EPSILON) {
|
||||
return atan2S16(y, x);
|
||||
}
|
||||
|
||||
export function atan2S16Detail(y, x) {
|
||||
const yy = f32(y);
|
||||
const xx = f32(x);
|
||||
if (yy === 0 && xx === 0) {
|
||||
return {
|
||||
angle: 0,
|
||||
ratio: 0,
|
||||
atanIndexUsed: 0,
|
||||
atanRaw: 0,
|
||||
};
|
||||
}
|
||||
const ay = Math.abs(yy);
|
||||
const ax = Math.abs(xx);
|
||||
let angle;
|
||||
let ratio = 0;
|
||||
let atanIndexUsed = -1;
|
||||
let atanRaw = 0;
|
||||
if (ay === ax) {
|
||||
angle = ay === 0 ? 0 : 0x2000;
|
||||
} else if (ay > ax) {
|
||||
ratio = ax / ay;
|
||||
const atanDetail = atanS16WithDetail(ratio);
|
||||
atanIndexUsed = atanDetail.index;
|
||||
atanRaw = atanDetail.raw;
|
||||
angle = 0x4000 - atanDetail.angle;
|
||||
} else {
|
||||
ratio = ay / ax;
|
||||
const atanDetail = atanS16WithDetail(ratio);
|
||||
atanIndexUsed = atanDetail.index;
|
||||
atanRaw = atanDetail.raw;
|
||||
angle = atanDetail.angle;
|
||||
}
|
||||
|
||||
if (xx < 0) {
|
||||
if (yy >= 0) {
|
||||
angle = 0x8000 - angle;
|
||||
} else {
|
||||
angle = angle - 0x8000;
|
||||
}
|
||||
} else if (yy < 0) {
|
||||
angle = -angle;
|
||||
}
|
||||
return {
|
||||
angle: toS16(angle),
|
||||
ratio,
|
||||
atanIndexUsed,
|
||||
atanRaw,
|
||||
};
|
||||
}
|
||||
|
||||
export function sumSq2(x, y) {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
10
src/stage.ts
10
src/stage.ts
@@ -2523,18 +2523,8 @@ function updateGoalBag(bag, animGroups, gravity, holdOpen, stack, rng) {
|
||||
stack.fromRotateY(-bag.rotY);
|
||||
stack.rotateX(0);
|
||||
stack.tfVec(rotVec, rotVec);
|
||||
const debug = (globalThis as any).__DETERMINISM_DEBUG__;
|
||||
if (debug) {
|
||||
debug.source = 'goalBagRotX';
|
||||
}
|
||||
bag.rotX = atan2S16Safe(rotVec.z, rotVec.y) - 0x8000;
|
||||
if (debug) {
|
||||
debug.source = 'goalBagRotZ';
|
||||
}
|
||||
bag.rotZ = atan2S16Safe(rotVec.x, sqrt(sumSq2(rotVec.z, rotVec.y)));
|
||||
if (debug) {
|
||||
debug.source = null;
|
||||
}
|
||||
|
||||
updateGoalBagTransform(bag, stack);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user