perf: reduce mobile rendering and cull offscreen characters and building tiles

This commit is contained in:
2026-11-03 10:43:01 +09:00
parent 4b27a8c209
commit e234baa4aa
17 changed files with 1689 additions and 109 deletions
+27 -2
View File
@@ -1,6 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { BoxGeometry, Group, Mesh, MeshBasicMaterial, Raycaster, Vector3 } from 'three';
import { BoxGeometry, Group, Mesh, MeshBasicMaterial, PerspectiveCamera, Raycaster, Vector3 } from 'three';
import { createServerClock } from '../src/multiplayer/clock.ts';
import { createRemotePlayers } from '../src/multiplayer/remotePlayers.ts';
import type { Sheep } from '../src/scene/sheep.ts';
@@ -16,6 +16,27 @@ test('server clock uses round trip midpoint and monotonic elapsed time', () => {
assert.equal(clock.now(), 1001020);
});
test('offscreen players skip posing but keep movement current and reappear when the camera turns', () => {
const scene = new Group(), camera = new PerspectiveCamera(60, 1, .1, 100);
let poses = 0;
const template = { group: new Group(), clone() { return { group: new Group(), setEquipment() {},
pose() { poses++; return true; }, dispose() {} } as unknown as Sheep; } } as Sheep;
const remote = createRemotePlayers(template, scene, () => 0);
const player: PlayerState = { id: 'other', nickname: '친구', x: 0, z: 10, yaw: 0, moving: false,
emote: 'idle', equipment: { umbrella: false, raincoat: false, hood: false }, updatedAt: 1000, emoteStartedAt: 1000 };
remote.synchronize([player], 'self');
for (let i = 0; i < 300; i++) remote.update(1 / 30, 1000 + i * 1000 / 30, camera);
assert.equal(poses, 0);
assert.equal(remote.get('other')!.visible, false);
remote.synchronize([{ ...player, x: 2, updatedAt: 11000 }], 'self');
remote.update(.2, 11200, camera);
assert.equal(remote.get('other')!.position.x, 2);
camera.lookAt(2, 0, 10);
assert.equal(remote.update(.03, 11230, camera), true);
assert.equal(poses, 1);
assert.equal(remote.get('other')!.visible, true);
});
test('companion selection picks visible players and chooses the nearest reachable unoccupied side', () => {
const scene = new Group();
const geometry = new BoxGeometry(1, 2, 1), material = new MeshBasicMaterial();
@@ -51,7 +72,8 @@ test('remote snapshot reconciles membership, equipment and interpolated motion w
let disposed = 0;
const template = { clone() { return { group: new Group(), setEquipment: (...v: boolean[]) => equipment.push(v),
pose: () => false, dispose() { this.group.removeFromParent(); disposed++; } } as unknown as Sheep; } } as Sheep;
const remote = createRemotePlayers(template, scene, () => 3);
let heightSamples = 0;
const remote = createRemotePlayers(template, scene, () => { heightSamples++; return 3; });
const player: PlayerState = { id: 'other', nickname: '방문자', x: 0, z: 0, yaw: 0, moving: false,
emote: 'idle', equipment: { umbrella: true, raincoat: true, hood: false, flashlight: true }, updatedAt: 1000, emoteStartedAt: 1000 };
remote.synchronize([player, { ...player, id: 'self' }], 'self');
@@ -63,6 +85,9 @@ test('remote snapshot reconciles membership, equipment and interpolated motion w
remote.update(.2, 1300);
assert.equal(scene.children[0].position.x, 1);
assert.equal(scene.children[0].position.y, 3);
const samplesAfterMoving = heightSamples;
for (let i = 0; i < 300; i++) remote.update(1 / 30, 1300 + i * 1000 / 30);
assert.equal(heightSamples, samplesAfterMoving, 'stationary players reuse their terrain height');
remote.synchronize([], 'self');
assert.equal(scene.children.length, 0);
assert.equal(disposed, 1);