Add tracking behaviot & current label & Optmi running func & test fish scene

This commit is contained in:
2022-04-10 16:51:13 +08:00
parent f8fbb70608
commit 0e1a070390
15 changed files with 273 additions and 33 deletions
+8 -3
View File
@@ -158,6 +158,11 @@ class Behavior<
*/
public parameter: IParameterValue<P>;
/**
* 指定当前群的 Key
*/
public currentGroupKey: Array<keyof P> = [];
/**
* 对象参数列表
*/
@@ -222,7 +227,7 @@ class Behavior<
* @param model 模型
* @param t 经过时间
*/
public effect(individual: Individual, group: Group, model: Model, t: number): void {};
public effect?: (individual: Individual, group: Group, model: Model, t: number) => void;
/**
* 作用影响于个体
@@ -231,7 +236,7 @@ class Behavior<
* @param model 模型
* @param t 经过时间
*/
public afterEffect(individual: Individual, group: Group, model: Model, t: number): void {};
public afterEffect?: (individual: Individual, group: Group, model: Model, t: number) => void;
/**
* 全部影响作用后
@@ -240,7 +245,7 @@ class Behavior<
* @param model 模型
* @param t 经过时间
*/
public finalEffect(individual: Individual, group: Group, model: Model, t: number): void {};
public finalEffect?: (individual: Individual, group: Group, model: Model, t: number) => void;
}
+31 -9
View File
@@ -1,6 +1,6 @@
import { Individual } from "@Model/Individual";
import { CtrlObject } from "@Model/CtrlObject";
import type { Behavior } from "@Model/Behavior";
import type { Behavior, IAnyBehavior } from "@Model/Behavior";
import { Label } from "@Model/Label";
import { Range } from "@Model/Range";
import { Model, ObjectID } from "@Model/Model";
@@ -308,7 +308,7 @@ class Group extends CtrlObject {
/**
* 行为列表
*/
public behaviors: Behavior[] = [];
public behaviors: IAnyBehavior[] = [];
/**
* 添加行为
@@ -358,15 +358,37 @@ class Group extends CtrlObject {
* @param
*/
public runner(t: number, effectType: "finalEffect" | "effect" | "afterEffect" ): void {
this.individuals.forEach((individual) => {
for(let j = 0; j < this.behaviors.length; j++) {
if (this.behaviors[j].isDeleted()) {
continue;
for(let j = 0; j < this.behaviors.length; j++) {
const behavior = this.behaviors[j];
if (behavior.isDeleted()) {
continue;
}
const runnerFunction = behavior[effectType];
if (!runnerFunction) {
continue;
}
for (let k = 0; k < behavior.currentGroupKey.length; k++) {
let parameterCache = behavior.parameter[
behavior.currentGroupKey[k] as string
];
if (Array.isArray(parameterCache?.objects)) {
parameterCache.objects = [this];
} else {
this.behaviors[j][effectType](individual, this, this.model, t);
parameterCache.objects = this;
}
}
});
}
this.individuals.forEach((individual) => {
runnerFunction(individual, this, this.model, t);
});
}
}
/**
+26 -6
View File
@@ -66,6 +66,11 @@ class Model extends Emitter<ModelEvent> {
*/
public allGroupLabel = new Label(this, "AllGroup").setBuildInLabel();
/**
* 内置标签-全部群标签
*/
public currentGroupLabel = new Label(this, "CurrentGroupLabel").setBuildInLabel();
/**
* 添加标签
*/
@@ -223,6 +228,7 @@ class Model extends Emitter<ModelEvent> {
public updateBehaviorParameter() {
for (let i = 0; i < this.behaviorPool.length; i++) {
const behavior = this.behaviorPool[i];
behavior.currentGroupKey = [];
for (let key in behavior.parameterOption) {
switch (behavior.parameterOption[key].type) {
@@ -236,11 +242,17 @@ class Model extends Emitter<ModelEvent> {
}
break;
case "CG":
case "G":
const dataG: IParamValue<"G"> = behavior.parameter[key];
const dataG: IParamValue<"CG"> = behavior.parameter[key];
dataG.objects = undefined;
if (dataG.picker instanceof Label && dataG.picker.id === this.currentGroupLabel.id) {
behavior.currentGroupKey.push(key);
dataG.objects = undefined;
}
if (dataG.picker instanceof Group && !dataG.picker.isDeleted()) {
else if (dataG.picker instanceof Group && !dataG.picker.isDeleted()) {
dataG.objects = dataG.picker;
}
break;
@@ -260,8 +272,9 @@ class Model extends Emitter<ModelEvent> {
}
break;
case "CLG":
case "LG":
const dataLG: IParamValue<"LG"> = behavior.parameter[key];
const dataLG: IParamValue<"CLG"> = behavior.parameter[key];
dataLG.objects = [];
if (dataLG.picker instanceof Group && !dataLG.picker.isDeleted()) {
@@ -269,9 +282,16 @@ class Model extends Emitter<ModelEvent> {
}
if (dataLG.picker instanceof Label && !dataLG.picker.isDeleted()) {
dataLG.objects = this.getObjectByLabel(dataLG.picker).filter((obj) => {
return obj instanceof Group;
}) as any;
if (dataLG.picker.id === this.currentGroupLabel.id) {
behavior.currentGroupKey.push(key);
dataLG.objects = [];
} else {
dataLG.objects = this.getObjectByLabel(dataLG.picker).filter((obj) => {
return obj instanceof Group;
}) as any;
}
}
break;
}
+5 -1
View File
@@ -22,6 +22,8 @@ type IMapObjectParamTypeKeyToType = {
"G": IObjectParamCacheType<Group | undefined>;
"LR": IObjectParamCacheType<Label | Range | undefined, Range[]>;
"LG": IObjectParamCacheType<Label | Group | undefined, Group[]>;
"CG": IObjectParamCacheType<Label | Group | undefined, Group | undefined>;
"CLG": IObjectParamCacheType<Label | Group | undefined, Group[]>;
}
type IMapVectorParamTypeKeyToType = {
@@ -41,7 +43,7 @@ type IParamValue<K extends IParamType> = AllMapType[K];
/**
* 特殊对象类型判定
*/
const objectTypeListEnumSet = new Set<string>(["R", "G", "LR", "LG"]);
const objectTypeListEnumSet = new Set<string>(["R", "G", "LR", "LG", "CG", "CLG"]);
/**
* 对象断言表达式
@@ -163,6 +165,7 @@ function getDefaultValue<P extends IParameter> (option: IParameterOption<P>): IP
defaultObj[key] = [0, 0, 0] as any;
break;
case "CG":
case "G":
case "R":
defaultObj[key] = {
@@ -171,6 +174,7 @@ function getDefaultValue<P extends IParameter> (option: IParameterOption<P>): IP
} as any;
break;
case "CLG":
case "LR":
case "LG":
defaultObj[key] = {