spoint 0.1.29 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/app.js +23 -21
- package/package.json +1 -1
package/client/app.js
CHANGED
|
@@ -1022,12 +1022,13 @@ const client = new PhysicsNetworkClient({
|
|
|
1022
1022
|
const a = evaluateAppModule(d.code)
|
|
1023
1023
|
if (a?.client) {
|
|
1024
1024
|
appModules.set(d.app, a.client)
|
|
1025
|
+
_appModuleList = [...appModules.values()]
|
|
1025
1026
|
if (a.client.setup) try { a.client.setup(engineCtx) } catch (e) { console.error('[app-setup]', d.app, e.message) }
|
|
1026
1027
|
}
|
|
1027
1028
|
},
|
|
1028
1029
|
onAssetUpdate: () => {},
|
|
1029
1030
|
onAppEvent: (payload) => {
|
|
1030
|
-
for (
|
|
1031
|
+
for (let _i = 0; _i < _appModuleList.length; _i++) { const mod = _appModuleList[_i]; if (mod.onEvent) try { mod.onEvent(payload, engineCtx) } catch (e) { console.error('[app-event]', e.message) } }
|
|
1031
1032
|
},
|
|
1032
1033
|
onHotReload: () => { sessionStorage.setItem('cam', JSON.stringify(cam.save())); location.reload() },
|
|
1033
1034
|
debug: false
|
|
@@ -1098,7 +1099,7 @@ function initInputHandler() {
|
|
|
1098
1099
|
setTimeout(() => {
|
|
1099
1100
|
xrBaseReferenceSpace = renderer.xr.getReferenceSpace()
|
|
1100
1101
|
if (!xrBaseReferenceSpace) return
|
|
1101
|
-
const local =
|
|
1102
|
+
const local = playerStates.get(client.playerId)
|
|
1102
1103
|
if (local?.position) {
|
|
1103
1104
|
const headHeight = local.crouch ? 1.1 : 1.6
|
|
1104
1105
|
const pos = { x: -local.position[0], y: -(local.position[1] + headHeight), z: -local.position[2] }
|
|
@@ -1227,7 +1228,7 @@ function startInputLoop() {
|
|
|
1227
1228
|
inputHandler.pulse('right', 0.5, 100)
|
|
1228
1229
|
}
|
|
1229
1230
|
lastShootState = input.shoot
|
|
1230
|
-
const local =
|
|
1231
|
+
const local = playerStates.get(client.playerId)
|
|
1231
1232
|
if (local) {
|
|
1232
1233
|
if (local.health < lastHealth) {
|
|
1233
1234
|
inputHandler.pulse('left', 0.8, 200)
|
|
@@ -1235,7 +1236,7 @@ function startInputLoop() {
|
|
|
1235
1236
|
}
|
|
1236
1237
|
lastHealth = local.health
|
|
1237
1238
|
}
|
|
1238
|
-
for (
|
|
1239
|
+
for (let _i = 0; _i < _appModuleList.length; _i++) { const mod = _appModuleList[_i]; if (mod.onInput) try { mod.onInput(input, engineCtx) } catch (e) { console.error('[app-input]', e.message) } }
|
|
1239
1240
|
client.sendInput(input)
|
|
1240
1241
|
}, 1000 / 60)
|
|
1241
1242
|
}
|
|
@@ -1248,8 +1249,8 @@ document.addEventListener('pointerlockchange', () => {
|
|
|
1248
1249
|
else document.removeEventListener('mousemove', cam.onMouseMove)
|
|
1249
1250
|
})
|
|
1250
1251
|
renderer.domElement.addEventListener('wheel', cam.onWheel, { passive: false })
|
|
1251
|
-
renderer.domElement.addEventListener('mousedown', (e) => { for (
|
|
1252
|
-
renderer.domElement.addEventListener('mouseup', (e) => { for (
|
|
1252
|
+
renderer.domElement.addEventListener('mousedown', (e) => { for (let _i = 0; _i < _appModuleList.length; _i++) { const mod = _appModuleList[_i]; if (mod.onMouseDown) try { mod.onMouseDown(e, engineCtx) } catch (ex) {} } })
|
|
1253
|
+
renderer.domElement.addEventListener('mouseup', (e) => { for (let _i = 0; _i < _appModuleList.length; _i++) { const mod = _appModuleList[_i]; if (mod.onMouseUp) try { mod.onMouseUp(e, engineCtx) } catch (ex) {} } })
|
|
1253
1254
|
renderer.domElement.addEventListener('contextmenu', (e) => e.preventDefault())
|
|
1254
1255
|
window.addEventListener('resize', () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight) })
|
|
1255
1256
|
|
|
@@ -1290,7 +1291,7 @@ function loadQueuedModels() {
|
|
|
1290
1291
|
try {
|
|
1291
1292
|
const buffer = e.target.result
|
|
1292
1293
|
gltfLoader.parse(buffer, '', (gltf) => {
|
|
1293
|
-
const local =
|
|
1294
|
+
const local = playerStates.get(client.playerId)
|
|
1294
1295
|
if (!local) return
|
|
1295
1296
|
const sy = Math.sin(cam.yaw), cy = Math.cos(cam.yaw)
|
|
1296
1297
|
const spawnDist = 1.0
|
|
@@ -1361,6 +1362,7 @@ document.addEventListener('drop', (e) => {
|
|
|
1361
1362
|
})
|
|
1362
1363
|
|
|
1363
1364
|
let smoothDt = 1 / 60
|
|
1365
|
+
let _appModuleList = []
|
|
1364
1366
|
function animate(timestamp) {
|
|
1365
1367
|
const now = timestamp || performance.now()
|
|
1366
1368
|
const rawDt = Math.min((now - lastFrameTime) / 1000, 0.1)
|
|
@@ -1370,22 +1372,22 @@ function animate(timestamp) {
|
|
|
1370
1372
|
fpsFrames++
|
|
1371
1373
|
if (now - fpsLast >= 1000) { fpsDisplay = fpsFrames; fpsFrames = 0; fpsLast = now }
|
|
1372
1374
|
const lerpFactor = 1.0 - Math.exp(-16.0 * frameDt)
|
|
1373
|
-
|
|
1375
|
+
playerTargets.forEach((target, id) => {
|
|
1374
1376
|
const mesh = playerMeshes.get(id)
|
|
1375
|
-
if (!mesh)
|
|
1377
|
+
if (!mesh) return
|
|
1376
1378
|
const ps = playerStates.get(id)
|
|
1377
1379
|
const vx = ps?.velocity?.[0] || 0, vy = ps?.velocity?.[1] || 0, vz = ps?.velocity?.[2] || 0
|
|
1378
1380
|
const goalX = target.x + vx * frameDt, goalY = target.y + vy * frameDt, goalZ = target.z + vz * frameDt
|
|
1379
1381
|
mesh.position.x += (goalX - mesh.position.x) * lerpFactor
|
|
1380
1382
|
mesh.position.y += (goalY - mesh.position.y) * lerpFactor
|
|
1381
1383
|
mesh.position.z += (goalZ - mesh.position.z) * lerpFactor
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
|
+
})
|
|
1385
|
+
playerAnimators.forEach((animator, id) => {
|
|
1384
1386
|
const ps = playerStates.get(id)
|
|
1385
|
-
if (!ps)
|
|
1387
|
+
if (!ps) return
|
|
1386
1388
|
animator.update(frameDt, ps.velocity, ps.onGround, ps.health, ps._aiming || false, ps.crouch || 0)
|
|
1387
1389
|
const mesh = playerMeshes.get(id)
|
|
1388
|
-
if (!mesh)
|
|
1390
|
+
if (!mesh) return
|
|
1389
1391
|
const vx = ps.velocity?.[0] || 0, vz = ps.velocity?.[2] || 0
|
|
1390
1392
|
if (vx * vx + vz * vz > 0.25) mesh.userData.lastYaw = Math.atan2(vx, vz)
|
|
1391
1393
|
if (mesh.userData.lastYaw !== undefined) {
|
|
@@ -1403,16 +1405,16 @@ function animate(timestamp) {
|
|
|
1403
1405
|
}
|
|
1404
1406
|
if (features?._headBone) features._headBone.rotation.x = -(ps.lookPitch || 0) * 0.6
|
|
1405
1407
|
}
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
+
})
|
|
1409
|
+
entityMeshes.forEach((mesh) => {
|
|
1408
1410
|
if (mesh.userData.spin) mesh.rotation.y += mesh.userData.spin * frameDt
|
|
1409
1411
|
if (mesh.userData.hover) {
|
|
1410
1412
|
mesh.userData.hoverTime = (mesh.userData.hoverTime || 0) + frameDt
|
|
1411
1413
|
const child = mesh.children[0]
|
|
1412
1414
|
if (child) child.position.y = Math.sin(mesh.userData.hoverTime * 2) * mesh.userData.hover
|
|
1413
1415
|
}
|
|
1414
|
-
}
|
|
1415
|
-
for (
|
|
1416
|
+
})
|
|
1417
|
+
for (let _i = 0; _i < _appModuleList.length; _i++) { const mod = _appModuleList[_i]; if (mod.onFrame) try { mod.onFrame(frameDt, engineCtx) } catch (e) {} }
|
|
1416
1418
|
if (engineCtx.facial) engineCtx.facial.update(frameDt)
|
|
1417
1419
|
uiTimer += frameDt
|
|
1418
1420
|
if (latestState && uiTimer >= 0.25) { uiTimer = 0; renderAppUI(latestState) }
|
|
@@ -1442,15 +1444,15 @@ function animate(timestamp) {
|
|
|
1442
1444
|
const speed = Math.sqrt(local.velocity[0] ** 2 + local.velocity[2] ** 2)
|
|
1443
1445
|
isMoving = speed > 0.5
|
|
1444
1446
|
}
|
|
1445
|
-
updateVignette(frameDt, isMoving)
|
|
1447
|
+
updateVignette(frameDt, isMoving)
|
|
1446
1448
|
|
|
1447
1449
|
if (arEnabled) {
|
|
1448
1450
|
const xrFrame = renderer.xr.getFrame()
|
|
1449
1451
|
if (xrFrame) {
|
|
1450
1452
|
arControls.update(xrFrame, camera, scene)
|
|
1451
|
-
const
|
|
1452
|
-
if (
|
|
1453
|
-
arControls.setInitialFPSPosition(
|
|
1453
|
+
const arLocal = playerStates.get(client.playerId)
|
|
1454
|
+
if (arLocal?.position && !arControls.anchorPlaced) {
|
|
1455
|
+
arControls.setInitialFPSPosition(arLocal.position, cam.yaw)
|
|
1454
1456
|
}
|
|
1455
1457
|
}
|
|
1456
1458
|
}
|