From a2b5d45a52658fe80b686169d604394f42982e72 Mon Sep 17 00:00:00 2001 From: vHawk <48140945+vHawk@users.noreply.github.com> Date: Wed, 29 Jun 2022 15:45:31 +0300 Subject: [PATCH] Add obstacles --- src/App.ts | 23 +++++++++++++++++------ src/Config.ts | 4 ++-- src/GUI.ts | 17 +++++++++++++---- src/Renderer.ts | 4 ++-- src/index.html | 14 ++++++++++++++ src/scenes/ScreenScene.ts | 3 +-- src/shaders/antsCompute.frag | 30 ++++++++++++++++++++++-------- src/shaders/draw.frag | 14 +++++++++----- src/shaders/screenWorld.frag | 21 +++++++++++---------- src/shaders/world.frag | 14 ++++++++------ src/shaders/worldBlur.frag | 8 ++++---- 11 files changed, 103 insertions(+), 49 deletions(-) diff --git a/src/App.ts b/src/App.ts index cba9a9f..0b31c45 100644 --- a/src/App.ts +++ b/src/App.ts @@ -37,18 +37,29 @@ export default new class App { this.simulationStepsPerSecond = Config.simulationStepsPerSecond; this.updateSimulationInterval(); + + this.gui.on('antsCount', () => { + this.resetRenderer(); + }); + + this.gui.on('worldSize', () => { + this.resetRenderer(); + }); + + this.gui.on('simulationStepsPerSecond', () => { + this.simulationStepsPerSecond = Config.simulationStepsPerSecond; + this.updateSimulationInterval(); + }); + } + + private resetRenderer() { + this.renderer.reset(); } private updateSimulationInterval() { clearInterval(this.simInterval); this.simInterval = setInterval(() => { - if (Config.simulationStepsPerSecond !== this.simulationStepsPerSecond) { - this.simulationStepsPerSecond = Config.simulationStepsPerSecond; - this.updateSimulationInterval(); - return; - } - this.simulationStep(); this.simStarted = true; diff --git a/src/Config.ts b/src/Config.ts index 86f297a..51562f9 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -3,8 +3,8 @@ export default { antsCount: 64 ** 2, simulationStepsPerSecond: 60, scentThreshold: 0.01, - scentFadeOutFactor: 0.998, - scentBlurRadius: 0.2, + scentFadeOutFactor: 0.999, + scentBlurRadius: 0.1, scentMaxStorage: 1e6, scentPerMarker: 1000, antSpeed: 1, diff --git a/src/GUI.ts b/src/GUI.ts index 95ff06c..91c7268 100644 --- a/src/GUI.ts +++ b/src/GUI.ts @@ -1,17 +1,26 @@ import * as dat from 'dat.gui'; import Config from "./Config"; +import EventEmitter from "events"; -export default class GUI { +export default class GUI extends EventEmitter { private gui: dat.GUI = new dat.GUI({ width: 400 }); constructor() { + super(); + const simFolder = this.gui.addFolder('Simulation'); - simFolder.add(Config, 'worldSize', 256, 8096); - simFolder.add(Config, 'antsCount', 1, 1e6); - simFolder.add(Config, 'simulationStepsPerSecond', 1, 300); + simFolder.add(Config, 'worldSize', 256, 8096).onChange(() => { + this.emit('worldSize'); + }); + simFolder.add(Config, 'antsCount', 1, 1e6).onChange(() => { + this.emit('antsCount'); + }); + simFolder.add(Config, 'simulationStepsPerSecond', 1, 300).onChange(() => { + this.emit('simulationStepsPerSecond'); + }); const controlsFolder = this.gui.addFolder('Controls'); diff --git a/src/Renderer.ts b/src/Renderer.ts index 1462980..8289986 100644 --- a/src/Renderer.ts +++ b/src/Renderer.ts @@ -37,7 +37,7 @@ export default class Renderer { type: THREE.FloatType, depthBuffer: false, magFilter: THREE.NearestFilter, - minFilter: THREE.LinearFilter, + minFilter: THREE.NearestFilter, }), worldBlurredRenderTarget: new THREE.WebGLRenderTarget(Config.worldSize, Config.worldSize, { format: THREE.RGBAFormat, @@ -137,7 +137,7 @@ export default class Renderer { }; } - public destroy() { + public reset() { } diff --git a/src/index.html b/src/index.html index 9087f91..89288ee 100644 --- a/src/index.html +++ b/src/index.html @@ -9,9 +9,23 @@ margin: 0; overflow: hidden; } + + #info { + position: absolute; + top: 0; + left: 0; + width: 100%; + text-align: left; + font-family: monospace; + color: white; + padding: 16px; + text-shadow: 0 0 3px black; + pointer-events: none; + }
+