Skip to content

Commit 2db3db0

Browse files
committed
feat: implement FPS visibility toggle and enhance pathfinding with connector avoidance zones
- Implemented setFpsVisible method in Renderer3D to control stats display visibility - Added buildConnectorAvoidZones function to create comprehensive avoidance zones around connectors - Expanded avoidance zones to include shaft centers, access entrances, and corridor paths with sampling - Enhanced path smoothing with turn penalty weight parameter and layer-specific obstacle filtering
1 parent d899ea7 commit 2db3db0

7 files changed

Lines changed: 542 additions & 231 deletions

File tree

src/core/renderer3d.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,11 @@ class Renderer3D {
493493
setLayerVisibilityInScene(this, index, visible);
494494
}
495495

496-
setFpsVisible() {}
496+
setFpsVisible(visible) {
497+
if (this.statsManager) {
498+
this.statsManager.setVisible(visible);
499+
}
500+
}
497501

498502
/**
499503
* 设置障碍物可见性

src/core/workers/hierarchy/multiLayerBuilder.js

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,61 @@ function preCalculateConnectors(width, height, layerCount, options) {
2929
const entranceAngle = rng.random() * Math.PI * 2;
3030
const accessX = x + Math.cos(entranceAngle) * 15; // radius = 15
3131
const accessY = y + Math.sin(entranceAngle) * 15;
32-
connectors.push({ x, y, type, radius: 15, entranceAngle, accessX, accessY });
32+
connectors.push({
33+
x,
34+
y,
35+
type,
36+
radius: 15,
37+
entranceAngle,
38+
accessX,
39+
accessY,
40+
});
3341
}
3442

3543
return connectors;
3644
}
3745

46+
// 构建连接器周围及通道方向上的避让区域,用于障碍生成时绕开通道
47+
function buildConnectorAvoidZones(connectors) {
48+
const zones = [];
49+
if (!Array.isArray(connectors) || connectors.length === 0) {
50+
return zones;
51+
}
52+
53+
const shaftRadius = 17; // 竖井中心避让半径
54+
const accessRadius = 25; // access 入口周围避让半径
55+
const corridorLength = 60; // 通道总长度
56+
const corridorStep = 20; // 采样步长:20 -> 40 -> 60
57+
const corridorRadius = 25; // 通道半宽
58+
59+
for (let i = 0; i < connectors.length; i++) {
60+
const c = connectors[i];
61+
if (!c) continue;
62+
63+
const angle = typeof c.entranceAngle === 'number' ? c.entranceAngle : 0;
64+
const cos = Math.cos(angle);
65+
const sin = Math.sin(angle);
66+
const baseRadius = typeof c.radius === 'number' ? c.radius : 15;
67+
const ax =
68+
typeof c.accessX === 'number' ? c.accessX : c.x + cos * baseRadius;
69+
const ay =
70+
typeof c.accessY === 'number' ? c.accessY : c.y + sin * baseRadius;
71+
72+
zones.push({ x: c.x, y: c.y, radius: shaftRadius });
73+
zones.push({ x: ax, y: ay, radius: accessRadius });
74+
75+
for (let d = corridorStep; d <= corridorLength; d += corridorStep) {
76+
zones.push({
77+
x: ax + cos * d,
78+
y: ay + sin * d,
79+
radius: corridorRadius,
80+
});
81+
}
82+
}
83+
84+
return zones;
85+
}
86+
3887
/**
3988
* 生成单层障碍物
4089
*/
@@ -49,8 +98,9 @@ function generateLayerObstacles(
4998
const layerRng = new SeededRandom(
5099
(options.seed || Date.now()) + layerIdx * 100,
51100
);
101+
const avoidZones = buildConnectorAvoidZones(connectors);
52102
return generateObstacles(width, height, obstacleCount, layerRng, {
53-
avoidZones: connectors,
103+
avoidZones,
54104
padding: 2,
55105
});
56106
}
@@ -90,7 +140,7 @@ export function buildLayers(
90140
// 2. 逐层构建
91141
for (let i = 0; i < layerCount; i++) {
92142
let layerObstacles;
93-
143+
94144
// 如果是第一层且提供了初始障碍物,直接使用
95145
if (i === 0 && initialObstacles) {
96146
layerObstacles = initialObstacles;
@@ -111,7 +161,7 @@ export function buildLayers(
111161
x: c.accessX,
112162
y: c.accessY,
113163
id: `${idx}-access`, // ID will be prefixed with L{layer}- in buildLayer
114-
type: 'connector-access'
164+
type: 'connector-access',
115165
}));
116166

117167
const layer = buildLayer(
@@ -122,7 +172,7 @@ export function buildLayers(
122172
baseZones,
123173
mode,
124174
options,
125-
fixedPoints // Pass fixed points
175+
fixedPoints, // Pass fixed points
126176
);
127177
layer.obstacles = layerObstacles;
128178
layers.push(layer);

0 commit comments

Comments
 (0)