From d4910a4147c24d64077014b4e00cd67b348c939e Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Mon, 6 May 2024 22:11:03 -0600 Subject: [PATCH] Sort of estimate the size of undo entries --- js/game.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/js/game.js b/js/game.js index 61883ae..ebbfb7f 100644 --- a/js/game.js +++ b/js/game.js @@ -293,6 +293,19 @@ class UndoEntry { this.sokoban_changes[color] = count; } } + + estimate_size() { + // Based very roughly on Chromium's measurements, so, kinda whatever + let size = 112; // base size of an entry + size += 16 * Object.keys(this.level_props).length; + for (let [_, changes] of this.tile_changes) { + size += 64 + 32 * Object.entries(changes).length; + } + size += 96 + 32 * this.actor_splices.length; + + this.size = size; + return size; + } } @@ -2520,6 +2533,7 @@ export class Level extends LevelInterface { } } + this.pending_undo.estimate_size(); this.undo_buffer[this.undo_buffer_index] = this.pending_undo; this.pending_undo = new UndoEntry;