initialize store.canvas.canvases as empty object,

more if-developemt for Renderer3D debug messages, to make webpack cut it
out better in production
This commit is contained in:
HF 2024-01-21 16:41:32 +01:00
parent e4566462bf
commit e497023777
3 changed files with 31 additions and 36 deletions

View File

@ -155,9 +155,6 @@ export function getOffsetOfPixel(
* @return key * @return key
*/ */
export function getIdFromObject(obj, ident) { export function getIdFromObject(obj, ident) {
if (!obj) {
return null;
}
const ids = Object.keys(obj); const ids = Object.keys(obj);
for (let i = 0; i < ids.length; i += 1) { for (let i = 0; i < ids.length; i += 1) {
const key = ids[i]; const key = ids[i];

View File

@ -91,7 +91,7 @@ function getCanvasArgs(canvas, prevCoords) {
/* /*
* parse url hash and sets view to coordinates * parse url hash and sets view to coordinates
* @param canvases Object with all canvas information * @param canvases Object with all canvas information
* @return incomplete state based on URL * @return incomplete state based on URL, null if failed
*/ */
function getViewFromURL(canvases) { function getViewFromURL(canvases) {
const { hash } = window.location; const { hash } = window.location;
@ -102,7 +102,11 @@ function getViewFromURL(canvases) {
let canvasId = getIdFromObject(canvases, canvasIdent); let canvasId = getIdFromObject(canvases, canvasIdent);
if (!canvasId || (!window.ssv?.backupurl && canvases[canvasId].ed)) { if (!canvasId || (!window.ssv?.backupurl && canvases[canvasId].ed)) {
canvasId = DEFAULT_CANVAS_ID; canvasId = DEFAULT_CANVAS_ID;
canvasIdent = canvases[DEFAULT_CANVAS_ID].ident; const canvas = canvases[DEFAULT_CANVAS_ID];
if (!canvas) {
return null;
}
canvasIdent = canvas.ident;
} }
const is3D = !!canvases[canvasId].v; const is3D = !!canvases[canvasId].v;
@ -129,7 +133,7 @@ function getViewFromURL(canvases) {
const initialState = { const initialState = {
canvasId: null, canvasId: null,
canvasIdent: 'xx', canvasIdent: 'xx',
canvases: null, canvases: {},
canvasSize: 65536, canvasSize: 65536,
historicalCanvasSize: 65536, historicalCanvasSize: 65536,
is3D: null, is3D: null,
@ -196,10 +200,10 @@ export default function canvasReducer(
case 'RELOAD_URL': { case 'RELOAD_URL': {
const { canvases } = state; const { canvases } = state;
if (!canvases) { const urlState = getViewFromURL(canvases);
if (!urlState) {
return state; return state;
} }
const urlState = getViewFromURL(canvases);
if (urlState.canvasId !== state.canvasId) { if (urlState.canvasId !== state.canvasId) {
const { canvasId } = urlState; const { canvasId } = urlState;
const canvas = canvases[canvasId]; const canvas = canvases[canvasId];

View File

@ -370,6 +370,19 @@ class Renderer3D extends Renderer {
this.objects = newObjects; this.objects = newObjects;
} }
debug(ident) {
if (process?.env.NODE_ENV !== 'development') {
return;
}
if (this.lol !== ident) {
// eslint-disable-next-line no-console
console.log(this.lol, this.lola);
this.lol = ident;
this.lola = 0;
}
this.lola += 1;
}
render() { render() {
if (!this.threeRenderer) { if (!this.threeRenderer) {
return; return;
@ -388,7 +401,6 @@ class Renderer3D extends Renderer {
) { ) {
this.centerChunk = centerChunk; this.centerChunk = centerChunk;
this.forceNextRender = true; this.forceNextRender = true;
console.log('new cc', this.centerChunk);
} }
} }
@ -400,39 +412,21 @@ class Renderer3D extends Renderer {
this.reloadChunks(); this.reloadChunks();
} }
if (this.forceNextRender) { if (process?.env.NODE_ENV === 'development') {
if (this.lol !== 'force') { if (this.forceNextRender) {
console.log(this.lol, this.lola); this.debug('force');
this.lol = 'force'; } else if (this.forceNextSubrender) {
this.lola = 0; this.debug('sub');
} else if (controlUpdate) {
this.debug('upd');
} }
this.lola += 1;
} else if (this.forceNextSubrender) {
if (this.lol !== 'sub') {
console.log(this.lol, this.lola);
this.lol = 'sub';
this.lola = 0;
}
this.lola += 1;
} else if (controlUpdate) {
if (this.lol !== 'update') {
console.log(this.lol, this.lola);
this.lol = 'update';
this.lola = 0;
}
this.lola += 1;
} }
this.threeRenderer.render(this.scene, this.camera); this.threeRenderer.render(this.scene, this.camera);
this.forceNextRender = false; this.forceNextRender = false;
this.forceNextSubrender = false; this.forceNextSubrender = false;
} else { } else if (process?.env.NODE_ENV === 'development') {
if (this.lol !== 'skip') { this.debug('skip');
console.log(this.lol, this.lola);
this.lol = 'skip';
this.lola = 0;
}
this.lola += 1;
} }
} }