From 5942272b930ea8edcc164ce899bc1401c3ecc6b8 Mon Sep 17 00:00:00 2001 From: cha0s Date: Fri, 26 Mar 2021 15:05:59 -0500 Subject: [PATCH] refactor: tile rendering --- packages/universe/src/components/play/renderable/index.jsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/universe/src/components/play/renderable/index.jsx b/packages/universe/src/components/play/renderable/index.jsx index a1fafde..75265ff 100644 --- a/packages/universe/src/components/play/renderable/index.jsx +++ b/packages/universe/src/components/play/renderable/index.jsx @@ -17,6 +17,7 @@ const ticker = () => {}; const RoomStage = () => { const selfEntity = useSelfEntity(); const [container] = useState(new Container()); + const [roomView, setRoomView] = useState(); const [viewport] = useState([320, 180]); const room = useRoom(); useEffect(() => { @@ -27,19 +28,21 @@ const RoomStage = () => { return undefined; } const roomView = new RoomView(room, renderer); + setRoomView(roomView); container.addChild(roomView); return () => { container.removeChild(roomView); }; }, [container, room]); useEffect(() => { - if (!room || !selfEntity || !selfEntity.camera) { + if (!roomView || !selfEntity || !selfEntity.camera) { return undefined; } const {camera} = selfEntity; const halfViewport = Vector.scale(viewport, 0.5); camera.realPosition = camera.position; const onCameraRealOffsetChanged = () => { + roomView.renderChunksForExtent(camera.rectangle); container.pivot = Vector.sub(halfViewport, Vector.scale(camera.realOffset, -1)); }; const onCameraRotationChanged = () => { @@ -59,7 +62,7 @@ const RoomStage = () => { camera.off('rotationChanged', onCameraRotationChanged); camera.off('scaleChanged', onCameraScaleChanged); }; - }, [container, room, selfEntity, viewport]); + }, [container, roomView, selfEntity, viewport]); useEffect(() => { if (!room) { return undefined;