diff --git a/src/Config.ts b/src/Config.ts index 6f48bab..6a64d0a 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -2,7 +2,9 @@ const STORAGE_KEY = "ants-simulation-config"; const defaults = { worldSize: 1024, - antsCount: 12, + antsStartCount: 4, + antBudget: 512, + seedWorld: true, simulationStepsPerSecond: 60, scentThreshold: 0.01, scentFadeOutFactor: 0.001, diff --git a/src/GUI.ts b/src/GUI.ts index 7ae8f31..e23d068 100644 --- a/src/GUI.ts +++ b/src/GUI.ts @@ -26,10 +26,14 @@ class GUIController { .step(1) .onChange(() => this.saveAndEmit("reset")); simFolder - .add(Config, "antsCount", 0, 22) - .name("Ants count 2^") + .add(Config, "antsStartCount", 0, 64) + .name("Starting ants") .step(1) .onChange(() => this.saveAndEmit("reset")); + simFolder + .add(Config, "seedWorld") + .name("Seed home + food") + .onChange(() => this.saveAndEmit("reset")); simFolder .add(Config, "scentFadeOutFactor", 0, 0.01) .name("Pheromone evaporation factor") diff --git a/src/Renderer.ts b/src/Renderer.ts index d1b0d54..3374d96 100644 --- a/src/Renderer.ts +++ b/src/Renderer.ts @@ -72,7 +72,7 @@ export default class Renderer { } private initResources() { - const antTextureSize = Math.round(Math.sqrt(2 ** Config.antsCount)); + const antTextureSize = Math.ceil(Math.sqrt(Config.antBudget)); this.resources = { worldRenderTarget: new THREE.WebGLRenderTarget( @@ -325,7 +325,7 @@ export default class Renderer { } public reset(scenes: SceneCollection) { - const antTextureSize = Math.round(Math.sqrt(2 ** Config.antsCount)); + const antTextureSize = Math.ceil(Math.sqrt(Config.antBudget)); this.resources.worldRenderTarget.setSize( Config.worldSize, diff --git a/src/__tests__/constants.test.ts b/src/__tests__/constants.test.ts index 57ff24c..dfd0435 100644 --- a/src/__tests__/constants.test.ts +++ b/src/__tests__/constants.test.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from "bun:test"; +import { defaults } from "../Config"; import { MAT_AIR, MAT_DIRT, @@ -31,3 +32,22 @@ describe("material ID constants", () => { } }); }); + +describe("config defaults", () => { + test("antsStartCount is a direct count, not an exponent", () => { + expect(defaults.antsStartCount).toBe(4); + expect(defaults.antsStartCount).toBeLessThanOrEqual(64); + }); + + test("antBudget determines texture pool size", () => { + expect(defaults.antBudget).toBe(512); + }); + + test("seedWorld defaults to true", () => { + expect(defaults.seedWorld).toBe(true); + }); + + test("old antsCount key does not exist", () => { + expect("antsCount" in defaults).toBe(false); + }); +});