fix: synchronized updates
This commit is contained in:
parent
0e5fcc3ea3
commit
5d352bb367
|
@ -15,6 +15,7 @@ export default function Entities({monopolizers, particleWorker}) {
|
||||||
const [debug] = useDebug();
|
const [debug] = useDebug();
|
||||||
const [ecs] = useEcs();
|
const [ecs] = useEcs();
|
||||||
const containerRef = useRef();
|
const containerRef = useRef();
|
||||||
|
const latestTick = useRef();
|
||||||
const entities = useRef({});
|
const entities = useRef({});
|
||||||
const pool = useRef([]);
|
const pool = useRef([]);
|
||||||
const [mainEntity] = useMainEntity();
|
const [mainEntity] = useMainEntity();
|
||||||
|
@ -75,8 +76,10 @@ export default function Entities({monopolizers, particleWorker}) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
async function onMessage(diff) {
|
async function onMessage(diff) {
|
||||||
await ecs.apply(diff.data);
|
latestTick.current = Promise.resolve(latestTick.current).then(async () => {
|
||||||
updateEntities(diff.data);
|
await ecs.apply(diff.data);
|
||||||
|
updateEntities(diff.data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
particleWorker.addEventListener('message', onMessage);
|
particleWorker.addEventListener('message', onMessage);
|
||||||
return () => {
|
return () => {
|
||||||
|
|
|
@ -35,6 +35,7 @@ function Ui({disconnected}) {
|
||||||
// Key input.
|
// Key input.
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
const chatInputRef = useRef();
|
const chatInputRef = useRef();
|
||||||
|
const latestTick = useRef();
|
||||||
const gameRef = useRef();
|
const gameRef = useRef();
|
||||||
const [mainEntity, setMainEntity] = useMainEntity();
|
const [mainEntity, setMainEntity] = useMainEntity();
|
||||||
const [debug, setDebug] = useDebug();
|
const [debug, setDebug] = useDebug();
|
||||||
|
@ -320,8 +321,10 @@ function Ui({disconnected}) {
|
||||||
if (0 === Object.keys(payload.ecs).length) {
|
if (0 === Object.keys(payload.ecs).length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await ecs.apply(payload.ecs);
|
latestTick.current = Promise.resolve(latestTick.current).then(async () => {
|
||||||
client.emitter.invoke(':Ecs', payload.ecs);
|
await ecs.apply(payload.ecs);
|
||||||
|
client.emitter.invoke(':Ecs', payload.ecs);
|
||||||
|
});
|
||||||
}, [ecs]);
|
}, [ecs]);
|
||||||
usePacket('Tick', onTickPacket);
|
usePacket('Tick', onTickPacket);
|
||||||
const onEcsTick = useCallback((payload, ecs) => {
|
const onEcsTick = useCallback((payload, ecs) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user