From f3f25477247a311eb2b25ddadfdd64502ef27e7a Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 21 May 2023 13:53:06 +0100 Subject: [PATCH] Rename species to generation --- src/index.ts | 4 ++-- .../agents/agent-generation/agent-counting.wgsl | 2 +- .../agents/agent-generation/agent-generation.wgsl | 2 +- .../agents/agent-generation/agent-schema.wgsl | 2 +- src/pipelines/agents/agent-generation/agent.ts | 2 +- src/pipelines/agents/agent.wgsl | 14 +++++++------- src/pipelines/render/render-pipeline.ts | 8 ++++---- src/pipelines/render/render-settings.ts | 4 ++-- src/pipelines/render/render.wgsl | 12 ++++++------ src/settings.ts | 12 ++++++------ 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/index.ts b/src/index.ts index 55feb7a..bb3c970 100644 --- a/src/index.ts +++ b/src/index.ts @@ -76,8 +76,8 @@ const main = async () => { const updateCounters = () => { elements.counters.innerHTML = `FPS: ${deltaTimeCalculator.fps.toFixed(2)} -Gen1: ${game?.aliveAgentCounts.currentGenerationCount ?? 0} -Gen2: ${game?.aliveAgentCounts.nextGenerationCount ?? 0}`; +current gen: ${game?.aliveAgentCounts.currentGenerationCount ?? 0} +next gen: ${game?.aliveAgentCounts.nextGenerationCount ?? 0}`; window.requestAnimationFrame(updateCounters); }; updateCounters(); diff --git a/src/pipelines/agents/agent-generation/agent-counting.wgsl b/src/pipelines/agents/agent-generation/agent-counting.wgsl index 5394e06..d5dc43f 100644 --- a/src/pipelines/agents/agent-generation/agent-counting.wgsl +++ b/src/pipelines/agents/agent-generation/agent-counting.wgsl @@ -13,7 +13,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3) { return; } - if agents[id].species % 2 == 0 { + if agents[id].generation % 2 == 0 { atomicAdd(&counters.evenGenerationAlive, 1); } else { atomicAdd(&counters.oddGenerationAlive, 1); diff --git a/src/pipelines/agents/agent-generation/agent-generation.wgsl b/src/pipelines/agents/agent-generation/agent-generation.wgsl index d34929e..e3c6069 100644 --- a/src/pipelines/agents/agent-generation/agent-generation.wgsl +++ b/src/pipelines/agents/agent-generation/agent-generation.wgsl @@ -15,6 +15,6 @@ fn main(@builtin(global_invocation_id) global_id: vec3) { } if length(settings.center - agents[id].position) < settings.radius { - agents[id].species = settings.nextGenerationId; + agents[id].generation = settings.nextGenerationId; } } diff --git a/src/pipelines/agents/agent-generation/agent-schema.wgsl b/src/pipelines/agents/agent-generation/agent-schema.wgsl index 4e749b4..b4eaa38 100644 --- a/src/pipelines/agents/agent-generation/agent-schema.wgsl +++ b/src/pipelines/agents/agent-generation/agent-schema.wgsl @@ -1,7 +1,7 @@ struct Agent { position: vec2, angle: f32, - species: f32, + generation: f32, } @group(1) @binding(1) var agents: array; diff --git a/src/pipelines/agents/agent-generation/agent.ts b/src/pipelines/agents/agent-generation/agent.ts index 92726be..b950f32 100644 --- a/src/pipelines/agents/agent-generation/agent.ts +++ b/src/pipelines/agents/agent-generation/agent.ts @@ -3,7 +3,7 @@ import { vec2 } from 'gl-matrix'; export interface Agent { position: vec2; angle: number; - species: number; + generation: number; } export const AGENT_SIZE_IN_BYTES = 4 * Float32Array.BYTES_PER_ELEMENT; diff --git a/src/pipelines/agents/agent.wgsl b/src/pipelines/agents/agent.wgsl index 049f211..bf7291e 100644 --- a/src/pipelines/agents/agent.wgsl +++ b/src/pipelines/agents/agent.wgsl @@ -31,7 +31,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3) { // even generation id -> red channel // odd generation id -> green channel - let isFromEvenGeneration = agent.species % 2 == 0; + let isFromEvenGeneration = agent.generation % 2 == 0; let trailForward = sense(agent.position, agent.angle, settings.sensorOffset, 0); let trailLeft = sense(agent.position, agent.angle, settings.sensorOffset, settings.sensorAngle); @@ -81,18 +81,18 @@ fn main(@builtin(global_invocation_id) global_id: vec3) { if(isFromEvenGeneration) { if next.r < next.g { - if agent.species == settings.nextGenerationId { - // agent.species -= 1; + if agent.generation == settings.nextGenerationId { + // agent.generation -= 1; } else { - agent.species += 1; + agent.generation += 1; } } } else { if next.g < next.r { - if agent.species == settings.nextGenerationId { - // agent.species -= 1; + if agent.generation == settings.nextGenerationId { + // agent.generation -= 1; } else { - agent.species += 1; + agent.generation += 1; } } } diff --git a/src/pipelines/render/render-pipeline.ts b/src/pipelines/render/render-pipeline.ts index 113d9fe..e086771 100644 --- a/src/pipelines/render/render-pipeline.ts +++ b/src/pipelines/render/render-pipeline.ts @@ -53,8 +53,8 @@ export class RenderPipeline { public setParameters({ brushColor, - speciesAColor, - speciesBColor, + evenGenerationColor, + oddGenerationColor, clarity, }: RenderSettings) { this.device.queue.writeBuffer( @@ -63,9 +63,9 @@ export class RenderPipeline { new Float32Array([ ...brushColor, 0, //padding - ...speciesAColor, + ...evenGenerationColor, 0, //padding - ...speciesBColor, + ...oddGenerationColor, clarity, ]) ); diff --git a/src/pipelines/render/render-settings.ts b/src/pipelines/render/render-settings.ts index e0f638f..34b418c 100644 --- a/src/pipelines/render/render-settings.ts +++ b/src/pipelines/render/render-settings.ts @@ -2,7 +2,7 @@ import { vec3 } from 'gl-matrix'; export interface RenderSettings { brushColor: vec3; - speciesAColor: vec3; - speciesBColor: vec3; + evenGenerationColor: vec3; + oddGenerationColor: vec3; clarity: number; } diff --git a/src/pipelines/render/render.wgsl b/src/pipelines/render/render.wgsl index 563b39c..a5c3321 100644 --- a/src/pipelines/render/render.wgsl +++ b/src/pipelines/render/render.wgsl @@ -1,7 +1,7 @@ struct Settings { brushColor: vec3, - speciesAColor: vec3, - speciesBColor: vec3, + evenGenerationColor: vec3, + oddGenerationColor: vec3, clarity: f32, }; @@ -16,12 +16,12 @@ fn fragment(@location(0) uv: vec2) -> @location(0) vec4 { let backgroundColor = vec3(0.9) + 0.075 * random.r; - let speciesAStrength = clamp(pow(traces.r, settings.clarity), 0, 1); - let speciesBStrength = clamp(pow(traces.g, settings.clarity), 0, 1); + let evenGenerationStrength = clamp(pow(traces.r, settings.clarity), 0, 1); + let oddGenerationStrength = clamp(pow(traces.g, settings.clarity), 0, 1); let brushStrength = traces.a; - let agentColor = step(speciesAStrength, speciesBStrength) * settings.speciesBColor * speciesBStrength + step(speciesBStrength, speciesAStrength) * settings.speciesAColor * speciesAStrength; - let agentStrength = speciesAStrength + speciesBStrength; + let agentColor = step(evenGenerationStrength, oddGenerationStrength) * settings.oddGenerationColor * oddGenerationStrength + step(oddGenerationStrength, evenGenerationStrength) * settings.evenGenerationColor * evenGenerationStrength; + let agentStrength = evenGenerationStrength + oddGenerationStrength; let rgbColor = sqrt( mix(agentColor, settings.brushColor * brushStrength, clamp(brushStrength - agentStrength, 0, 1)) diff --git a/src/settings.ts b/src/settings.ts index 9044db5..96c14cb 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -20,12 +20,12 @@ export const settings: GameLoopSettings & DiffusionSettings & RenderSettings = { agentCount: 4_000_000, // requires restart - initialDeadRatio: 0.2, // requires restart aggressionFactor: 0.5, // requires restart - nextGenerationSpawnRadius: 50, + nextGenerationSpawnRadius: 1, + nextGenerationSpawnInterval: 2, - renderSpeed: 5, + renderSpeed: 10, simulatedDelayMs: 0, brushWidth: 20, @@ -43,7 +43,7 @@ export const settings: GameLoopSettings & decayRateBrush: 0.995, // inverse brushColor: palette.blue, - speciesAColor: palette.yellow, - speciesBColor: palette.purple, - clarity: 3, + evenGenerationColor: palette.yellow, + oddGenerationColor: palette.purple, + clarity: 1, };