Add individuals metadata

This commit is contained in:
2022-02-18 13:36:11 +08:00
parent a3791eecd1
commit b9ffe91f8f
3 changed files with 32 additions and 5 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ class ClassicRenderer extends BasicRenderer<{}, IClassicRendererParams> {
*/ */
private lastScale: number = 0; private lastScale: number = 0;
private readonly cubeRadius = 2**.5; private readonly cubeRadius = 2**.5;
private readonly farFogLine = 2.5; private readonly farFogLine = 2.2;
/** /**
* 对象储池数组 * 对象储池数组
+10 -4
View File
@@ -15,11 +15,17 @@ class Group {
* 创建个体 * 创建个体
* @param count 创建数量 * @param count 创建数量
*/ */
public new(count: number = 1): this { public new(count: number = 1): Individual {
let newIndividual: Individual | undefined;
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
this.individuals.add(new Individual(this)); newIndividual = new Individual(this);
this.individuals.add(newIndividual);
}
if (newIndividual) {
return newIndividual;
} else {
return new Individual(this);
} }
return this;
} }
/** /**
@@ -101,7 +107,7 @@ class Group {
} }
/** /**
* 运行效果器 * 执行行为影响
* @param * @param
*/ */
public runner(t: number): void { public runner(t: number): void {
+21
View File
@@ -1,4 +1,5 @@
import type { Group } from "./Group"; import type { Group } from "./Group";
import { ObjectID } from "./Renderer";
/** /**
* 群中的个体类型 * 群中的个体类型
@@ -108,6 +109,26 @@ class Individual {
public distanceTo(position: Individual | number[]): number { public distanceTo(position: Individual | number[]): number {
return Individual.vectorLength(this.vectorTo(position)); return Individual.vectorLength(this.vectorTo(position));
} }
/**
* 保存提供给 Behavior 使用的数据
*/
private metaData: Map<ObjectID, any> = new Map();
/**
* 获取元数据
*/
public getData<T = any>(key: ObjectID): T {
return this.metaData.get(key);
}
/**
* 设置元数据
*/
public setData<T = any>(key: ObjectID, value: T): T {
this.metaData.set(key, value);
return value;
}
} }
export default Individual; export default Individual;