Skip to content

Commit 7e5f65c

Browse files
fix(gta): keep scenic views above roofs and clean mobile HUD
中文:远景镜头避开建筑屋顶,修复移动端调试信息重叠,并在生产环境隐藏诊断 HUD。
1 parent 7dd9bb5 commit 7e5f65c

5 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎packages/app/src/components/gta/gta-game.css‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,10 @@
435435
.gta-map-panel button {
436436
margin: 4px;
437437
}
438+
@media (max-width: 700px) {
439+
.gta-performance {
440+
top: 3.7rem;
441+
left: 0.7rem;
442+
font-size: 9px;
443+
}
444+
}

‎packages/app/src/components/gta/gta-game.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,13 @@ export function GtaGame({ locale = 'en' }: { locale?: 'en' | 'zh' }) {
570570
</span>
571571
</div>
572572
</header>
573-
<output
574-
ref={performanceHud}
575-
className="gta-performance"
576-
aria-label={locale === 'zh' ? '渲染性能' : 'Rendering performance'}
577-
/>
573+
{process.env.NODE_ENV !== 'production' && (
574+
<output
575+
ref={performanceHud}
576+
className="gta-performance"
577+
aria-label={locale === 'zh' ? '渲染性能' : 'Rendering performance'}
578+
/>
579+
)}
578580
<div className="gta-objective">
579581
<small>
580582
{view.explorer

‎packages/app/src/components/gta/gta-geography.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import {
77
STREETS_SF,
88
streetRoute,
99
} from './gta-geography';
10-
import { blocked, DESTINATIONS, JOBS, START } from './gta-world';
10+
import { blocked, cameraClearanceHeight, DESTINATIONS, JOBS, START } from './gta-world';
1111

1212
describe('San Paloma geography', () => {
13+
it('keeps scenic cameras above rooftops without lifting cameras over clear roads', () => {
14+
expect(cameraClearanceHeight({ x: -125, z: 1850 }, 20)).toBe(31);
15+
expect(cameraClearanceHeight({ x: -125, z: 1850 }, 500)).toBe(500);
16+
expect(cameraClearanceHeight({ x: 0, z: 1850 }, 20)).toBe(20);
17+
});
1318
it('uses the SF survey instead of an invented rectangular grid', () => {
1419
expect(FOOTPRINTS.length).toBeGreaterThan(1800);
1520
expect(STREETS_SF.length).toBeGreaterThan(600);

‎packages/app/src/components/gta/gta-renderer.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as T from 'three';
22
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
33
import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
4-
import { JOBS, lanePoint, type Point } from './gta-world';
4+
import { cameraClearanceHeight, JOBS, lanePoint, type Point } from './gta-world';
55
import { target, type CityState } from './gta-engine';
66
import { clonePedestrian, createPedestrianAnimation, rigPedestrian } from './gta-pedestrian';
77
import { ARCHITECTURE_ASSET_COUNT, loadArchitecture } from './gta-architecture';
@@ -348,13 +348,16 @@ export async function createCityRenderer(
348348
? 0.2
349349
: 10 + Math.abs(s.car.speed) * 0.05;
350350
const height = scenic
351-
? 15 + landmarkHeight * 0.2
351+
? landmarkHeight > 100
352+
? landmarkHeight + 60
353+
: 15 + landmarkHeight * 0.2
352354
: s.onFoot
353355
? 3.1
354356
: s.camera === 1
355357
? 1.6
356358
: 5.2;
357359
tmp.set(s.player.x - Math.sin(a) * dist, height, s.player.z - Math.cos(a) * dist);
360+
if (scenic) tmp.y = cameraClearanceHeight({ x: tmp.x, z: tmp.z }, tmp.y);
358361
if (snap) camera.position.copy(tmp);
359362
else camera.position.lerp(tmp, 0.14);
360363
camera.lookAt(

‎packages/app/src/components/gta/gta-world.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ export function blocked(p: Point, radius = 1.2) {
5858
return true;
5959
return false;
6060
}
61+
export function cameraClearanceHeight(p: Point, minimumHeight: number) {
62+
let height = minimumHeight;
63+
for (const b of cells.get(`${Math.floor(p.x / 50)},${Math.floor(p.z / 50)}`) ?? []) {
64+
if (b.h + 15 > height && inside(p, b.ring)) height = b.h + 15;
65+
}
66+
return height;
67+
}
6168
export const DESTINATIONS = [
6269
{ ...START, en: "Oren's Hummus", zh: "Oren's Hummus" },
6370
{ ...nearestRoadPoint(BAY_LANDMARKS[1]), en: 'Ferry Building', zh: '渡轮大厦' },

0 commit comments

Comments
 (0)