diff --git a/App/fluss.html b/App/fluss.html index c595605..579a5e7 100644 --- a/App/fluss.html +++ b/App/fluss.html @@ -164,13 +164,22 @@ function initGame() { } // === FLUSS-GEOMETRIE === -// Abstand eines Tiles (r,c) zum Fluss (kontinuierlich, nicht nur ganzzahlig) +// Distance-Cache: wird einmal pro Tick aktualisiert statt pro Frame pro Tile +let distCache = [] +function rebuildDistCache() { + for (let r = 0; r < ROWS; r++) { + if (!distCache[r]) distCache[r] = [] + for (let c = 0; c < COLS; c++) distCache[r][c] = _calcDist(r, c) + } +} function distToRiver(r, c) { - // Naechster Punkt auf der Flusslinie + if (distCache[r] && distCache[r][c] !== undefined) return distCache[r][c] + return _calcDist(r, c) +} +function _calcDist(r, c) { let minD = 999 for (let i = 0; i < ROWS; i++) { const rc = riverColSmooth[i] - // Segment von Zeile i zu i+1 if (i < ROWS - 1) { const rc2 = riverColSmooth[i + 1] // Punkt-zu-Segment Abstand (vereinfacht: nehme naechsten Endpunkt) @@ -192,6 +201,10 @@ function isRiverTile(r, c) { function tick() { if (gameOver) return year++ + rebuildDistCache() // Cache neu bauen (einmal pro Tick statt pro Frame pro Tile) + + // EventLog cappen + if (eventLog.length > 50) eventLog.length = 50 // 1. Einkommen let income = 0, totalPop = 0, totalFood = 0