mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-04-26 06:45:45 +00:00
parallelize script loads
This commit is contained in:
parent
9d3554de02
commit
2f23934de0
17 changed files with 561 additions and 68 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Html } from "@react-three/drei";
|
||||
import picomatch from "picomatch";
|
||||
import { loadMission } from "../loaders";
|
||||
import { type ParsedMission } from "../mission";
|
||||
|
|
@ -12,7 +13,12 @@ import {
|
|||
runServer,
|
||||
TorqueObject,
|
||||
} from "../torqueScript";
|
||||
import { getResourceKey, getResourceList, getResourceMap } from "../manifest";
|
||||
import {
|
||||
getResourceKey,
|
||||
getResourceList,
|
||||
getResourceMap,
|
||||
getSourceAndPath,
|
||||
} from "../manifest";
|
||||
|
||||
const loadScript = createScriptLoader();
|
||||
// Shared cache for parsed scripts - survives runtime restarts
|
||||
|
|
@ -20,7 +26,12 @@ const scriptCache = createScriptCache();
|
|||
const fileSystem: FileSystemHandler = {
|
||||
findFiles: (pattern) => {
|
||||
const isMatch = picomatch(pattern, { nocase: true });
|
||||
return getResourceList().filter((path) => isMatch(path));
|
||||
return getResourceList()
|
||||
.filter((path) => isMatch(path))
|
||||
.map((resourceKey) => {
|
||||
const [sourcePath, actualPath] = getSourceAndPath(resourceKey);
|
||||
return actualPath;
|
||||
});
|
||||
},
|
||||
isFile: (resourcePath) => {
|
||||
const resourceKeys = getResourceMap();
|
||||
|
|
@ -75,12 +86,34 @@ function useExecutedMission(
|
|||
return missionGroup;
|
||||
}
|
||||
|
||||
function LoadingSpinner() {
|
||||
return (
|
||||
<Html>
|
||||
<div
|
||||
style={{
|
||||
position: "fixed",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
width: 48,
|
||||
height: 48,
|
||||
border: "4px solid rgba(255, 255, 255, 0.2)",
|
||||
borderTopColor: "white",
|
||||
borderRadius: "50%",
|
||||
animation: "spin 1s linear infinite",
|
||||
pointerEvents: "none",
|
||||
}}
|
||||
/>
|
||||
<style>{`@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } from { transform: translate(-50%, -50%) rotate(0deg); } }`}</style>
|
||||
</Html>
|
||||
);
|
||||
}
|
||||
|
||||
export const Mission = memo(function Mission({ name }: { name: string }) {
|
||||
const { data: parsedMission } = useParsedMission(name);
|
||||
const missionGroup = useExecutedMission(name, parsedMission);
|
||||
|
||||
if (!missionGroup) {
|
||||
return null;
|
||||
return <LoadingSpinner />;
|
||||
}
|
||||
|
||||
return <TickProvider>{renderObject(missionGroup)}</TickProvider>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue