split up context, rebuild

This commit is contained in:
Brian Beck 2025-11-25 23:44:37 -08:00
parent 1db338f855
commit 91111f8986
15 changed files with 51 additions and 29 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,7 @@
2:I[9766,[],""] 2:I[9766,[],""]
3:I[8924,[],""] 3:I[8924,[],""]
4:I[1959,[],"ClientPageRoot"] 4:I[1959,[],"ClientPageRoot"]
5:I[1222,["367","static/chunks/b536a0f1-05ee2c75df4a3b9d.js","831","static/chunks/bd904a5c-3aea2adebde6f067.js","664","static/chunks/a3cd4a83-5c5b758da206345b.js","794","static/chunks/f6211eb1-4f3105d2434536dc.js","413","static/chunks/1329d575-16915d95397758f8.js","749","static/chunks/749-d375ce6a5d05b15b.js","974","static/chunks/app/page-d55096a5cdf8744d.js"],"default"] 5:I[1222,["367","static/chunks/b536a0f1-05ee2c75df4a3b9d.js","831","static/chunks/bd904a5c-3aea2adebde6f067.js","664","static/chunks/a3cd4a83-5c5b758da206345b.js","794","static/chunks/f6211eb1-4f3105d2434536dc.js","413","static/chunks/1329d575-16915d95397758f8.js","749","static/chunks/749-d375ce6a5d05b15b.js","974","static/chunks/app/page-1d80ebcf53b20763.js"],"default"]
8:I[4431,[],"OutletBoundary"] 8:I[4431,[],"OutletBoundary"]
a:I[5278,[],"AsyncMetadataOutlet"] a:I[5278,[],"AsyncMetadataOutlet"]
c:I[4431,[],"ViewportBoundary"] c:I[4431,[],"ViewportBoundary"]
@ -10,7 +10,7 @@ e:I[4431,[],"MetadataBoundary"]
f:"$Sreact.suspense" f:"$Sreact.suspense"
11:I[7150,[],""] 11:I[7150,[],""]
:HL["/t2-mapper/_next/static/css/71910d47103c2b82.css","style"] :HL["/t2-mapper/_next/static/css/71910d47103c2b82.css","style"]
0:{"P":null,"b":"GES-iHcopYCN0QbsPTVOa","p":"/t2-mapper","c":["",""],"i":false,"f":[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",["$","$1","c",{"children":[[["$","link","0",{"rel":"stylesheet","href":"/t2-mapper/_next/static/css/71910d47103c2b82.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"children":["$","$L2",null,{"parallelRouterKey":"children","error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L3",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":404}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],[]],"forbidden":"$undefined","unauthorized":"$undefined"}]}]}]]}],{"children":["__PAGE__",["$","$1","c",{"children":[["$","$L4",null,{"Component":"$5","searchParams":{},"params":{},"promises":["$@6","$@7"]}],null,["$","$L8",null,{"children":["$L9",["$","$La",null,{"promise":"$@b"}]]}]]}],{},null,false]},null,false],["$","$1","h",{"children":[null,[["$","$Lc",null,{"children":"$Ld"}],null],["$","$Le",null,{"children":["$","div",null,{"hidden":true,"children":["$","$f",null,{"fallback":null,"children":"$L10"}]}]}]]}],false]],"m":"$undefined","G":["$11",[]],"s":false,"S":true} 0:{"P":null,"b":"MfKrWH0yW4dA6XW3Li2xh","p":"/t2-mapper","c":["",""],"i":false,"f":[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",["$","$1","c",{"children":[[["$","link","0",{"rel":"stylesheet","href":"/t2-mapper/_next/static/css/71910d47103c2b82.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"children":["$","$L2",null,{"parallelRouterKey":"children","error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L3",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":404}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],[]],"forbidden":"$undefined","unauthorized":"$undefined"}]}]}]]}],{"children":["__PAGE__",["$","$1","c",{"children":[["$","$L4",null,{"Component":"$5","searchParams":{},"params":{},"promises":["$@6","$@7"]}],null,["$","$L8",null,{"children":["$L9",["$","$La",null,{"promise":"$@b"}]]}]]}],{},null,false]},null,false],["$","$1","h",{"children":[null,[["$","$Lc",null,{"children":"$Ld"}],null],["$","$Le",null,{"children":["$","div",null,{"hidden":true,"children":["$","$f",null,{"fallback":null,"children":"$L10"}]}]}]]}],false]],"m":"$undefined","G":["$11",[]],"s":false,"S":true}
6:{} 6:{}
7:"$0:f:0:1:2:children:1:props:children:0:props:params" 7:"$0:f:0:1:2:children:1:props:children:0:props:params"
d:[["$","meta","0",{"charSet":"utf-8"}],["$","meta","1",{"name":"viewport","content":"width=device-width, initial-scale=1"}]] d:[["$","meta","0",{"charSet":"utf-8"}],["$","meta","1",{"name":"viewport","content":"width=device-width, initial-scale=1"}]]

View file

@ -4,7 +4,7 @@ import { PositionalAudio, Vector3 } from "three";
import { ConsoleObject, getPosition, getProperty } from "../mission"; import { ConsoleObject, getPosition, getProperty } from "../mission";
import { audioToUrl } from "../loaders"; import { audioToUrl } from "../loaders";
import { useAudio } from "./AudioContext"; import { useAudio } from "./AudioContext";
import { useSettings } from "./SettingsProvider"; import { useDebug, useSettings } from "./SettingsProvider";
import { FloatingLabel } from "./FloatingLabel"; import { FloatingLabel } from "./FloatingLabel";
// Global audio buffer cache // Global audio buffer cache
@ -37,7 +37,7 @@ export const AudioEmitter = memo(function AudioEmitter({
}: { }: {
object: ConsoleObject; object: ConsoleObject;
}) { }) {
const { debugMode } = useSettings(); const { debugMode } = useDebug();
const fileName = getProperty(object, "fileName")?.value ?? ""; const fileName = getProperty(object, "fileName")?.value ?? "";
const volume = parseFloat(getProperty(object, "volume")?.value ?? "1"); const volume = parseFloat(getProperty(object, "volume")?.value ?? "1");
const minDistance = parseFloat( const minDistance = parseFloat(

View file

@ -1,10 +1,10 @@
import { Stats, Html } from "@react-three/drei"; import { Stats, Html } from "@react-three/drei";
import { useSettings } from "./SettingsProvider"; import { useDebug } from "./SettingsProvider";
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import { AxesHelper } from "three"; import { AxesHelper } from "three";
export function DebugElements() { export function DebugElements() {
const { debugMode } = useSettings(); const { debugMode } = useDebug();
const axesRef = useRef<AxesHelper>(null); const axesRef = useRef<AxesHelper>(null);
useEffect(() => { useEffect(() => {

View file

@ -8,7 +8,7 @@ import {
} from "../shaderMaterials"; } from "../shaderMaterials";
import { MeshStandardMaterial } from "three"; import { MeshStandardMaterial } from "three";
import { setupColor } from "../textureUtils"; import { setupColor } from "../textureUtils";
import { useSettings } from "./SettingsProvider"; import { useDebug } from "./SettingsProvider";
import { useShapeInfo } from "./ShapeInfoProvider"; import { useShapeInfo } from "./ShapeInfoProvider";
import { FloatingLabel } from "./FloatingLabel"; import { FloatingLabel } from "./FloatingLabel";
@ -71,7 +71,7 @@ export type StaticShapeType = "StaticShape" | "TSStatic" | "Item" | "Turret";
export const ShapeModel = memo(function ShapeModel() { export const ShapeModel = memo(function ShapeModel() {
const { shapeName } = useShapeInfo(); const { shapeName } = useShapeInfo();
const { debugMode } = useSettings(); const { debugMode } = useDebug();
const { nodes } = useStaticShape(shapeName); const { nodes } = useStaticShape(shapeName);
const hullBoneIndices = useMemo(() => { const hullBoneIndices = useMemo(() => {

View file

@ -1,5 +1,5 @@
import { getResourceList } from "../manifest"; import { getResourceList } from "../manifest";
import { useSettings } from "./SettingsProvider"; import { useControls, useDebug, useSettings } from "./SettingsProvider";
const excludeMissions = new Set([ const excludeMissions = new Set([
"SkiFree", "SkiFree",
@ -23,15 +23,13 @@ export function InspectorControls({
const { const {
fogEnabled, fogEnabled,
setFogEnabled, setFogEnabled,
speedMultiplier,
setSpeedMultiplier,
fov, fov,
setFov, setFov,
audioEnabled, audioEnabled,
setAudioEnabled, setAudioEnabled,
debugMode,
setDebugMode,
} = useSettings(); } = useSettings();
const { speedMultiplier, setSpeedMultiplier } = useControls();
const { debugMode, setDebugMode } = useDebug();
return ( return (
<div <div

View file

@ -10,6 +10,8 @@ import {
getScale, getScale,
} from "../mission"; } from "../mission";
import { setupColor } from "../textureUtils"; import { setupColor } from "../textureUtils";
import { FloatingLabel } from "./FloatingLabel";
import { useDebug } from "./SettingsProvider";
const FALLBACK_URL = `${BASE_URL}/black.png`; const FALLBACK_URL = `${BASE_URL}/black.png`;
@ -55,6 +57,7 @@ function InteriorMesh({ node }: { node: Mesh }) {
export const InteriorModel = memo( export const InteriorModel = memo(
({ interiorFile }: { interiorFile: string }) => { ({ interiorFile }: { interiorFile: string }) => {
const { nodes } = useInterior(interiorFile); const { nodes } = useInterior(interiorFile);
const { debugMode } = useDebug();
return ( return (
<group rotation={[0, -Math.PI / 2, 0]}> <group rotation={[0, -Math.PI / 2, 0]}>
@ -66,6 +69,7 @@ export const InteriorModel = memo(
.map(([name, node]: [string, any]) => ( .map(([name, node]: [string, any]) => (
<InteriorMesh key={name} node={node} /> <InteriorMesh key={name} node={node} />
))} ))}
{debugMode ? <FloatingLabel>{interiorFile}</FloatingLabel> : null}
</group> </group>
); );
} }

View file

@ -3,7 +3,7 @@ import { Vector3 } from "three";
import { useFrame, useThree } from "@react-three/fiber"; import { useFrame, useThree } from "@react-three/fiber";
import { KeyboardControls, useKeyboardControls } from "@react-three/drei"; import { KeyboardControls, useKeyboardControls } from "@react-three/drei";
import { PointerLockControls } from "three-stdlib"; import { PointerLockControls } from "three-stdlib";
import { useSettings } from "./SettingsProvider"; import { useControls } from "./SettingsProvider";
enum Controls { enum Controls {
forward = "forward", forward = "forward",
@ -19,7 +19,7 @@ const MIN_SPEED_ADJUSTMENT = 0.05;
const MAX_SPEED_ADJUSTMENT = 0.5; const MAX_SPEED_ADJUSTMENT = 0.5;
function CameraMovement() { function CameraMovement() {
const { speedMultiplier, setSpeedMultiplier } = useSettings(); const { speedMultiplier, setSpeedMultiplier } = useControls();
const [subscribe, getKeys] = useKeyboardControls<Controls>(); const [subscribe, getKeys] = useKeyboardControls<Controls>();
const { camera, gl } = useThree(); const { camera, gl } = useThree();
const controlsRef = useRef<PointerLockControls | null>(null); const controlsRef = useRef<PointerLockControls | null>(null);

View file

@ -9,6 +9,8 @@ import {
} from "react"; } from "react";
const SettingsContext = createContext(null); const SettingsContext = createContext(null);
const DebugContext = createContext(null);
const ControlsContext = createContext(null);
type PersistedSettings = { type PersistedSettings = {
fogEnabled?: boolean; fogEnabled?: boolean;
@ -22,6 +24,14 @@ export function useSettings() {
return useContext(SettingsContext); return useContext(SettingsContext);
} }
export function useDebug() {
return useContext(DebugContext);
}
export function useControls() {
return useContext(ControlsContext);
}
export function SettingsProvider({ children }: { children: ReactNode }) { export function SettingsProvider({ children }: { children: ReactNode }) {
const [fogEnabled, setFogEnabled] = useState(true); const [fogEnabled, setFogEnabled] = useState(true);
const [speedMultiplier, setSpeedMultiplier] = useState(1); const [speedMultiplier, setSpeedMultiplier] = useState(1);
@ -29,20 +39,26 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
const [audioEnabled, setAudioEnabled] = useState(false); const [audioEnabled, setAudioEnabled] = useState(false);
const [debugMode, setDebugMode] = useState(false); const [debugMode, setDebugMode] = useState(false);
const value = useMemo( const settingsContext = useMemo(
() => ({ () => ({
fogEnabled, fogEnabled,
setFogEnabled, setFogEnabled,
speedMultiplier,
setSpeedMultiplier,
fov, fov,
setFov, setFov,
audioEnabled, audioEnabled,
setAudioEnabled, setAudioEnabled,
debugMode,
setDebugMode,
}), }),
[fogEnabled, speedMultiplier, fov, audioEnabled, debugMode, setDebugMode] [fogEnabled, speedMultiplier, fov, audioEnabled]
);
const debugContext = useMemo(
() => ({ debugMode, setDebugMode }),
[debugMode, setDebugMode]
);
const controlsContext = useMemo(
() => ({ speedMultiplier, setSpeedMultiplier }),
[speedMultiplier, setSpeedMultiplier]
); );
// Read persisted settings from localStoarge. // Read persisted settings from localStoarge.
@ -103,8 +119,12 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
}, [fogEnabled, speedMultiplier, fov, audioEnabled, debugMode]); }, [fogEnabled, speedMultiplier, fov, audioEnabled, debugMode]);
return ( return (
<SettingsContext.Provider value={value}> <SettingsContext.Provider value={settingsContext}>
{children} <DebugContext.Provider value={debugContext}>
<ControlsContext.Provider value={controlsContext}>
{children}
</ControlsContext.Provider>
</DebugContext.Provider>
</SettingsContext.Provider> </SettingsContext.Provider>
); );
} }

View file

@ -27,7 +27,7 @@ import {
setupMask, setupMask,
updateTerrainTextureShader, updateTerrainTextureShader,
} from "../textureUtils"; } from "../textureUtils";
import { useSettings } from "./SettingsProvider"; import { useDebug } from "./SettingsProvider";
const DEFAULT_SQUARE_SIZE = 8; const DEFAULT_SQUARE_SIZE = 8;
@ -52,7 +52,7 @@ function BlendedTerrainTextures({
textureNames: string[]; textureNames: string[];
alphaMaps: Uint8Array[]; alphaMaps: Uint8Array[];
}) { }) {
const { debugMode } = useSettings(); const { debugMode } = useDebug();
const baseTextures = useTexture( const baseTextures = useTexture(
textureNames.map((name) => terrainTextureToUrl(name)), textureNames.map((name) => terrainTextureToUrl(name)),