Generate agents

This commit is contained in:
Andras Schmelczer 2023-05-21 11:03:37 +01:00
commit 7e8ca4b16f
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
10 changed files with 368 additions and 89 deletions

View file

@ -8,7 +8,7 @@ import shader from './agent.wgsl';
export class AgentPipeline {
private static readonly WORKGROUP_SIZE = 64;
private static readonly UNIFORM_COUNT = 5;
private static readonly UNIFORM_COUNT = 6;
private readonly bindGroupLayout: GPUBindGroupLayout;
private readonly pipeline: GPUComputePipeline;
@ -21,7 +21,7 @@ export class AgentPipeline {
public constructor(
private readonly device: GPUDevice,
private readonly commonState: CommonState,
private readonly agentsBuffer: GPUBuffer
private readonly agentsBuffer: GPUBuffer // doesn't get destroyed
) {
this.bindGroupLayout = device.createBindGroupLayout(AgentPipeline.bindGroupLayout);
@ -47,7 +47,8 @@ export class AgentPipeline {
turnSpeed,
sensorOffsetAngle,
sensorOffsetDistance,
}: AgentSettings) {
nextGenerationAggression,
}: AgentSettings & { nextGenerationAggression: number }) {
this.device.queue.writeBuffer(
this.uniforms,
0,
@ -57,6 +58,7 @@ export class AgentPipeline {
turnSpeed,
(sensorOffsetAngle * Math.PI) / 180,
sensorOffsetDistance,
nextGenerationAggression,
])
);
}
@ -118,7 +120,6 @@ export class AgentPipeline {
public destroy() {
this.uniforms.destroy();
this.agentsBuffer.destroy();
}
private static get bindGroupLayout(): GPUBindGroupLayoutDescriptor {