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
*/
export function getIdFromObject(obj, ident) {
if (!obj) {
return null;
}
const ids = Object.keys(obj);
for (let i = 0; i < ids.length; i += 1) {
const key = ids[i];

View File

@ -91,7 +91,7 @@ function getCanvasArgs(canvas, prevCoords) {
/*
* parse url hash and sets view to coordinates
* @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) {
const { hash } = window.location;
@ -102,7 +102,11 @@ function getViewFromURL(canvases) {
let canvasId = getIdFromObject(canvases, canvasIdent);
if (!canvasId || (!window.ssv?.backupurl && canvases[canvasId].ed)) {
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;
@ -129,7 +133,7 @@ function getViewFromURL(canvases) {
const initialState = {
canvasId: null,
canvasIdent: 'xx',
canvases: null,
canvases: {},
canvasSize: 65536,
historicalCanvasSize: 65536,
is3D: null,
@ -196,10 +200,10 @@ export default function canvasReducer(
case 'RELOAD_URL': {
const { canvases } = state;
if (!canvases) {
const urlState = getViewFromURL(canvases);
if (!urlState) {
return state;
}
const urlState = getViewFromURL(canvases);
if (urlState.canvasId !== state.canvasId) {
const { canvasId } = urlState;
const canvas = canvases[canvasId];

View File

@ -370,6 +370,19 @@ class Renderer3D extends Renderer {
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() {
if (!this.threeRenderer) {
return;
@ -388,7 +401,6 @@ class Renderer3D extends Renderer {
) {
this.centerChunk = centerChunk;
this.forceNextRender = true;
console.log('new cc', this.centerChunk);
}
}
@ -400,39 +412,21 @@ class Renderer3D extends Renderer {
this.reloadChunks();
}
if (this.forceNextRender) {
if (this.lol !== 'force') {
console.log(this.lol, this.lola);
this.lol = 'force';
this.lola = 0;
if (process?.env.NODE_ENV === 'development') {
if (this.forceNextRender) {
this.debug('force');
} else if (this.forceNextSubrender) {
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.forceNextRender = false;
this.forceNextSubrender = false;
} else {
if (this.lol !== 'skip') {
console.log(this.lol, this.lola);
this.lol = 'skip';
this.lola = 0;
}
this.lola += 1;
} else if (process?.env.NODE_ENV === 'development') {
this.debug('skip');
}
}