refactor: tile rendering

This commit is contained in:
cha0s 2021-03-26 15:05:59 -05:00
parent db223e6d23
commit 5942272b93

View File

@ -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;