Rename species to generation
This commit is contained in:
parent
3414f38c3a
commit
f3f2547724
10 changed files with 31 additions and 31 deletions
|
|
@ -76,8 +76,8 @@ const main = async () => {
|
||||||
|
|
||||||
const updateCounters = () => {
|
const updateCounters = () => {
|
||||||
elements.counters.innerHTML = `FPS: ${deltaTimeCalculator.fps.toFixed(2)}
|
elements.counters.innerHTML = `FPS: ${deltaTimeCalculator.fps.toFixed(2)}
|
||||||
Gen1: ${game?.aliveAgentCounts.currentGenerationCount ?? 0}
|
current gen: ${game?.aliveAgentCounts.currentGenerationCount ?? 0}
|
||||||
Gen2: ${game?.aliveAgentCounts.nextGenerationCount ?? 0}`;
|
next gen: ${game?.aliveAgentCounts.nextGenerationCount ?? 0}`;
|
||||||
window.requestAnimationFrame(updateCounters);
|
window.requestAnimationFrame(updateCounters);
|
||||||
};
|
};
|
||||||
updateCounters();
|
updateCounters();
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if agents[id].species % 2 == 0 {
|
if agents[id].generation % 2 == 0 {
|
||||||
atomicAdd(&counters.evenGenerationAlive, 1);
|
atomicAdd(&counters.evenGenerationAlive, 1);
|
||||||
} else {
|
} else {
|
||||||
atomicAdd(&counters.oddGenerationAlive, 1);
|
atomicAdd(&counters.oddGenerationAlive, 1);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,6 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if length(settings.center - agents[id].position) < settings.radius {
|
if length(settings.center - agents[id].position) < settings.radius {
|
||||||
agents[id].species = settings.nextGenerationId;
|
agents[id].generation = settings.nextGenerationId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
struct Agent {
|
struct Agent {
|
||||||
position: vec2<f32>,
|
position: vec2<f32>,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
species: f32,
|
generation: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@group(1) @binding(1) var<storage, read_write> agents: array<Agent>;
|
@group(1) @binding(1) var<storage, read_write> agents: array<Agent>;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { vec2 } from 'gl-matrix';
|
||||||
export interface Agent {
|
export interface Agent {
|
||||||
position: vec2;
|
position: vec2;
|
||||||
angle: number;
|
angle: number;
|
||||||
species: number;
|
generation: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AGENT_SIZE_IN_BYTES = 4 * Float32Array.BYTES_PER_ELEMENT;
|
export const AGENT_SIZE_IN_BYTES = 4 * Float32Array.BYTES_PER_ELEMENT;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
||||||
// even generation id -> red channel
|
// even generation id -> red channel
|
||||||
// odd generation id -> green 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 trailForward = sense(agent.position, agent.angle, settings.sensorOffset, 0);
|
||||||
let trailLeft = sense(agent.position, agent.angle, settings.sensorOffset, settings.sensorAngle);
|
let trailLeft = sense(agent.position, agent.angle, settings.sensorOffset, settings.sensorAngle);
|
||||||
|
|
@ -81,18 +81,18 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
||||||
|
|
||||||
if(isFromEvenGeneration) {
|
if(isFromEvenGeneration) {
|
||||||
if next.r < next.g {
|
if next.r < next.g {
|
||||||
if agent.species == settings.nextGenerationId {
|
if agent.generation == settings.nextGenerationId {
|
||||||
// agent.species -= 1;
|
// agent.generation -= 1;
|
||||||
} else {
|
} else {
|
||||||
agent.species += 1;
|
agent.generation += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if next.g < next.r {
|
if next.g < next.r {
|
||||||
if agent.species == settings.nextGenerationId {
|
if agent.generation == settings.nextGenerationId {
|
||||||
// agent.species -= 1;
|
// agent.generation -= 1;
|
||||||
} else {
|
} else {
|
||||||
agent.species += 1;
|
agent.generation += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ export class RenderPipeline {
|
||||||
|
|
||||||
public setParameters({
|
public setParameters({
|
||||||
brushColor,
|
brushColor,
|
||||||
speciesAColor,
|
evenGenerationColor,
|
||||||
speciesBColor,
|
oddGenerationColor,
|
||||||
clarity,
|
clarity,
|
||||||
}: RenderSettings) {
|
}: RenderSettings) {
|
||||||
this.device.queue.writeBuffer(
|
this.device.queue.writeBuffer(
|
||||||
|
|
@ -63,9 +63,9 @@ export class RenderPipeline {
|
||||||
new Float32Array([
|
new Float32Array([
|
||||||
...brushColor,
|
...brushColor,
|
||||||
0, //padding
|
0, //padding
|
||||||
...speciesAColor,
|
...evenGenerationColor,
|
||||||
0, //padding
|
0, //padding
|
||||||
...speciesBColor,
|
...oddGenerationColor,
|
||||||
clarity,
|
clarity,
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { vec3 } from 'gl-matrix';
|
||||||
|
|
||||||
export interface RenderSettings {
|
export interface RenderSettings {
|
||||||
brushColor: vec3;
|
brushColor: vec3;
|
||||||
speciesAColor: vec3;
|
evenGenerationColor: vec3;
|
||||||
speciesBColor: vec3;
|
oddGenerationColor: vec3;
|
||||||
clarity: number;
|
clarity: number;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
struct Settings {
|
struct Settings {
|
||||||
brushColor: vec3<f32>,
|
brushColor: vec3<f32>,
|
||||||
speciesAColor: vec3<f32>,
|
evenGenerationColor: vec3<f32>,
|
||||||
speciesBColor: vec3<f32>,
|
oddGenerationColor: vec3<f32>,
|
||||||
clarity: f32,
|
clarity: f32,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -16,12 +16,12 @@ fn fragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
|
||||||
|
|
||||||
let backgroundColor = vec3(0.9) + 0.075 * random.r;
|
let backgroundColor = vec3(0.9) + 0.075 * random.r;
|
||||||
|
|
||||||
let speciesAStrength = clamp(pow(traces.r, settings.clarity), 0, 1);
|
let evenGenerationStrength = clamp(pow(traces.r, settings.clarity), 0, 1);
|
||||||
let speciesBStrength = clamp(pow(traces.g, settings.clarity), 0, 1);
|
let oddGenerationStrength = clamp(pow(traces.g, settings.clarity), 0, 1);
|
||||||
let brushStrength = traces.a;
|
let brushStrength = traces.a;
|
||||||
|
|
||||||
let agentColor = step(speciesAStrength, speciesBStrength) * settings.speciesBColor * speciesBStrength + step(speciesBStrength, speciesAStrength) * settings.speciesAColor * speciesAStrength;
|
let agentColor = step(evenGenerationStrength, oddGenerationStrength) * settings.oddGenerationColor * oddGenerationStrength + step(oddGenerationStrength, evenGenerationStrength) * settings.evenGenerationColor * evenGenerationStrength;
|
||||||
let agentStrength = speciesAStrength + speciesBStrength;
|
let agentStrength = evenGenerationStrength + oddGenerationStrength;
|
||||||
|
|
||||||
let rgbColor = sqrt(
|
let rgbColor = sqrt(
|
||||||
mix(agentColor, settings.brushColor * brushStrength, clamp(brushStrength - agentStrength, 0, 1))
|
mix(agentColor, settings.brushColor * brushStrength, clamp(brushStrength - agentStrength, 0, 1))
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@ export const settings: GameLoopSettings &
|
||||||
DiffusionSettings &
|
DiffusionSettings &
|
||||||
RenderSettings = {
|
RenderSettings = {
|
||||||
agentCount: 4_000_000, // requires restart
|
agentCount: 4_000_000, // requires restart
|
||||||
initialDeadRatio: 0.2, // requires restart
|
|
||||||
|
|
||||||
aggressionFactor: 0.5, // requires restart
|
aggressionFactor: 0.5, // requires restart
|
||||||
nextGenerationSpawnRadius: 50,
|
nextGenerationSpawnRadius: 1,
|
||||||
|
nextGenerationSpawnInterval: 2,
|
||||||
|
|
||||||
renderSpeed: 5,
|
renderSpeed: 10,
|
||||||
simulatedDelayMs: 0,
|
simulatedDelayMs: 0,
|
||||||
|
|
||||||
brushWidth: 20,
|
brushWidth: 20,
|
||||||
|
|
@ -43,7 +43,7 @@ export const settings: GameLoopSettings &
|
||||||
decayRateBrush: 0.995, // inverse
|
decayRateBrush: 0.995, // inverse
|
||||||
|
|
||||||
brushColor: palette.blue,
|
brushColor: palette.blue,
|
||||||
speciesAColor: palette.yellow,
|
evenGenerationColor: palette.yellow,
|
||||||
speciesBColor: palette.purple,
|
oddGenerationColor: palette.purple,
|
||||||
clarity: 3,
|
clarity: 1,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue