# Conflicts:
#	demo/libs/framework/framework.min.js
This commit is contained in:
yhh
2020-11-03 10:10:03 +08:00
16 changed files with 148 additions and 49 deletions
+1 -1
View File
@@ -31,7 +31,7 @@
data-content-width="640" data-content-width="640"
data-content-height="1136" data-content-height="1136"
data-multi-fingered="2" data-multi-fingered="2"
data-show-fps="true" data-show-log="false" data-show-fps="false" data-show-log="false"
data-show-fps-style="x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9"> data-show-fps-style="x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9">
</div> </div>
<script> <script>
+1 -1
View File
@@ -280,7 +280,7 @@ declare module es {
planner: ActionPlanner; planner: ActionPlanner;
static create(planner: ActionPlanner): WorldState; static create(planner: ActionPlanner): WorldState;
constructor(planner: ActionPlanner, values: number, dontcare: number); constructor(planner: ActionPlanner, values: number, dontcare: number);
set(conditionId: number, value: boolean): boolean; set(conditionId: number | string, value: boolean): boolean;
equals(other: WorldState): boolean; equals(other: WorldState): boolean;
describe(planner: ActionPlanner): string; describe(planner: ActionPlanner): string;
} }
+10 -6
View File
@@ -1008,7 +1008,7 @@ var es;
return null; return null;
}; };
AStarStorage.prototype.hasOpened = function () { AStarStorage.prototype.hasOpened = function () {
return this._numClosed > 0; return this._numOpened > 0;
}; };
AStarStorage.prototype.removeOpened = function (node) { AStarStorage.prototype.removeOpened = function (node) {
if (this._numOpened > 0) if (this._numOpened > 0)
@@ -1330,6 +1330,9 @@ var es;
return new WorldState(planner, 0, -1); return new WorldState(planner, 0, -1);
}; };
WorldState.prototype.set = function (conditionId, value) { WorldState.prototype.set = function (conditionId, value) {
if (typeof conditionId == "string") {
return this.set(this.planner.findConditionNameIndex(conditionId), value);
}
this.values = value ? (this.values | (1 << conditionId)) : (this.values & ~(1 << conditionId)); this.values = value ? (this.values | (1 << conditionId)) : (this.values & ~(1 << conditionId));
this.dontCare ^= (1 << conditionId); this.dontCare ^= (1 << conditionId);
return true; return true;
@@ -1513,7 +1516,6 @@ var es;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
this.startDebugUpdate();
es.Time.update(egret.getTimer()); es.Time.update(egret.getTimer());
es.Input.update(); es.Input.update();
if (!this._scene) return [3, 2]; if (!this._scene) return [3, 2];
@@ -1537,9 +1539,7 @@ var es;
_a.sent(); _a.sent();
this.addChild(this._scene); this.addChild(this._scene);
_a.label = 2; _a.label = 2;
case 2: case 2: return [4, this.draw()];
this.endDebugUpdate();
return [4, this.draw()];
case 3: case 3:
_a.sent(); _a.sent();
return [2]; return [2];
@@ -4932,6 +4932,8 @@ var es;
ComponentList.prototype.deregisterAllComponents = function () { ComponentList.prototype.deregisterAllComponents = function () {
for (var i = 0; i < this._components.length; i++) { for (var i = 0; i < this._components.length; i++) {
var component = this._components.buffer[i]; var component = this._components.buffer[i];
if (!component)
continue;
if (component instanceof es.RenderableComponent) { if (component instanceof es.RenderableComponent) {
if (component.displayObject.parent) if (component.displayObject.parent)
component.displayObject.parent.removeChild(component.displayObject); component.displayObject.parent.removeChild(component.displayObject);
@@ -5001,6 +5003,8 @@ var es;
} }
}; };
ComponentList.prototype.handleRemove = function (component) { ComponentList.prototype.handleRemove = function (component) {
if (!component)
return;
if (component instanceof es.RenderableComponent) { if (component instanceof es.RenderableComponent) {
if (component.displayObject.parent) if (component.displayObject.parent)
component.displayObject.parent.removeChild(component.displayObject); component.displayObject.parent.removeChild(component.displayObject);
@@ -11318,7 +11322,7 @@ var es;
obj["reset"](); obj["reset"]();
} }
}; };
Pool._objectQueue = new Array(10); Pool._objectQueue = [];
return Pool; return Pool;
}()); }());
es.Pool = Pool; es.Pool = Pool;
File diff suppressed because one or more lines are too long
+2 -3
View File
@@ -17,7 +17,7 @@
"bin-debug/SampleHelpers/SampleScene.js", "bin-debug/SampleHelpers/SampleScene.js",
"bin-debug/Scenes/NinjaAdventure/ProjectileHitDetector.js", "bin-debug/Scenes/NinjaAdventure/ProjectileHitDetector.js",
"bin-debug/UI/loading/LoadingView.js", "bin-debug/UI/loading/LoadingView.js",
"bin-debug/Scenes/LineCasting/LineCastingScene.js", "bin-debug/Scenes/NinjaAdventure/CameraBounds.js",
"bin-debug/Fgui/loading/loadingBinder.js", "bin-debug/Fgui/loading/loadingBinder.js",
"bin-debug/Fgui/loading/UI_View_loading.js", "bin-debug/Fgui/loading/UI_View_loading.js",
"bin-debug/Fgui/sc/scBinder.js", "bin-debug/Fgui/sc/scBinder.js",
@@ -28,10 +28,9 @@
"bin-debug/Scenes/AnimatedTiles/AnimatedTilesScene.js", "bin-debug/Scenes/AnimatedTiles/AnimatedTilesScene.js",
"bin-debug/Scenes/EmptyScene/BasicScene.js", "bin-debug/Scenes/EmptyScene/BasicScene.js",
"bin-debug/Scenes/GOAP/GoapScene.js", "bin-debug/Scenes/GOAP/GoapScene.js",
"bin-debug/Scenes/GOAP/QuickAgent.js",
"bin-debug/Scenes/LineCasting/LineCaster.js", "bin-debug/Scenes/LineCasting/LineCaster.js",
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
"bin-debug/Main.js", "bin-debug/Main.js",
"bin-debug/Scenes/NinjaAdventure/CameraBounds.js",
"bin-debug/Scenes/NinjaAdventure/FireballProjectileController.js", "bin-debug/Scenes/NinjaAdventure/FireballProjectileController.js",
"bin-debug/Scenes/NinjaAdventure/Ninja.js", "bin-debug/Scenes/NinjaAdventure/Ninja.js",
"bin-debug/Scenes/NinjaAdventure/NinjaAdventureScene.js", "bin-debug/Scenes/NinjaAdventure/NinjaAdventureScene.js",
+108
View File
@@ -1,9 +1,117 @@
module samples { module samples {
export class MinerState {
public readonly maxFatigue = 10;
public readonly maxGold = 8;
public readonly maxThirst = 5;
public fatigue: number = 10;
public thirst: number = 0;
public gold: number = 0;
public goldInBank: number = 0;
public currentLocation: Location = Location.home;
}
export class GoapScene extends SampleScene { export class GoapScene extends SampleScene {
public _destinationLocation: Location;
public planner: es.ActionPlanner;
public _actionPlan: es.Action[];
public minerState: MinerState;
public initialize(): void { public initialize(): void {
super.initialize(); super.initialize();
// 在我们做任何事情之前,我们需要一个行动计划
this.planner = new es.ActionPlanner();
this.minerState = new MinerState();
// 设置我们的动作并将它们添加到计划器中
let sleep = new es.Action("sleep");
sleep.setPrecondition("fatigued", true);
sleep.setPostcondition("fatigued", false);
this.planner.addAction(sleep);
let drink = new es.Action("drink");
drink.setPrecondition("thirsty", true);
drink.setPostcondition("thirsty", false);
this.planner.addAction(drink);
let mine = new es.Action("mine");
mine.setPrecondition("hasenoughgold", false);
mine.setPostcondition("hasenoughgold", true);
this.planner.addAction(mine);
let depositGold = new es.Action("depositGold");
depositGold.setPrecondition("hasenoughgold", true);
depositGold.setPostcondition("hasenoughgold", false);
this.planner.addAction(depositGold);
// 制定一个计划,让我们从当前状态运行到目标状态
this._actionPlan = this.planner.plan(this.getWorldState(), this.getGoalState());
if (this._actionPlan != null && this._actionPlan.length > 0){
this.goTo();
console.log(`得到了一个行动计划与${this._actionPlan.length}行动`);
} else {
console.log(`没有满足我们目标的行动计划`);
}
}
private goTo(){
let action = this._actionPlan[this._actionPlan.length - 1].name;
switch (action){
case "sleep":
this._destinationLocation = Location.home;
break;
case "drink":
this._destinationLocation = Location.saloon;
break;
case "mine":
this._destinationLocation = Location.mine;
break;
case "depositeGold":
this._destinationLocation = Location.bank;
break;
}
if (this.minerState.currentLocation == this._destinationLocation){
} else {
this.minerState.currentLocation = Location.inTransit;
}
}
public getWorldState(): es.WorldState {
let worldState = this.planner.createWorldState();
worldState.set("fatigued", this.minerState.fatigue >= this.minerState.maxFatigue);
worldState.set("thirsty", this.minerState.thirst >= this.minerState.maxThirst);
worldState.set("hasenoughgold", this.minerState.gold >= this.minerState.maxGold);
return worldState;
}
public getGoalState(): es.WorldState {
let goalState = this.planner.createWorldState();
if (this.minerState.fatigue >= this.minerState.maxFatigue){
goalState.set("fatigued", false);
} else if(this.minerState.thirst >= this.minerState.maxThirst){
goalState.set("thirsty", false);
} else if(this.minerState.gold >= this.minerState.maxGold){
goalState.set("hasenoughgold", false);
} else {
goalState.set("hasenoughgold", true);
}
return goalState;
} }
} }
enum Location {
inTransit,
bank,
mine,
home,
saloon,
}
} }
-22
View File
@@ -1,22 +0,0 @@
module samples {
export class QuickAgent extends es.Agent {
private planner: es.ActionPlanner;
constructor(){
super();
this.planner = new es.ActionPlanner();
let action = new es.Action("scout");
action.setPrecondition("armedwithgun", true);
action.setPostcondition("enemyvisible", true);
this.planner.addAction(action);
}
public getWorldState(): es.WorldState {
let state = es.WorldState.create(this.planner);
return state;
}
public getGoalState(): es.WorldState {
return es.WorldState.create(this.planner);
}
}
}
+1 -1
View File
@@ -37,7 +37,7 @@ egret_native.egretStart = function () {
contentWidth: 640, contentWidth: 640,
contentHeight: 1136, contentHeight: 1136,
showPaintRect: false, showPaintRect: false,
showFPS: true, showFPS: false,
fpsStyles: "x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9", fpsStyles: "x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9",
showLog: false, showLog: false,
logFilter: "", logFilter: "",
+1 -1
View File
@@ -280,7 +280,7 @@ declare module es {
planner: ActionPlanner; planner: ActionPlanner;
static create(planner: ActionPlanner): WorldState; static create(planner: ActionPlanner): WorldState;
constructor(planner: ActionPlanner, values: number, dontcare: number); constructor(planner: ActionPlanner, values: number, dontcare: number);
set(conditionId: number, value: boolean): boolean; set(conditionId: number | string, value: boolean): boolean;
equals(other: WorldState): boolean; equals(other: WorldState): boolean;
describe(planner: ActionPlanner): string; describe(planner: ActionPlanner): string;
} }
+10 -6
View File
@@ -1008,7 +1008,7 @@ var es;
return null; return null;
}; };
AStarStorage.prototype.hasOpened = function () { AStarStorage.prototype.hasOpened = function () {
return this._numClosed > 0; return this._numOpened > 0;
}; };
AStarStorage.prototype.removeOpened = function (node) { AStarStorage.prototype.removeOpened = function (node) {
if (this._numOpened > 0) if (this._numOpened > 0)
@@ -1330,6 +1330,9 @@ var es;
return new WorldState(planner, 0, -1); return new WorldState(planner, 0, -1);
}; };
WorldState.prototype.set = function (conditionId, value) { WorldState.prototype.set = function (conditionId, value) {
if (typeof conditionId == "string") {
return this.set(this.planner.findConditionNameIndex(conditionId), value);
}
this.values = value ? (this.values | (1 << conditionId)) : (this.values & ~(1 << conditionId)); this.values = value ? (this.values | (1 << conditionId)) : (this.values & ~(1 << conditionId));
this.dontCare ^= (1 << conditionId); this.dontCare ^= (1 << conditionId);
return true; return true;
@@ -1513,7 +1516,6 @@ var es;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
this.startDebugUpdate();
es.Time.update(egret.getTimer()); es.Time.update(egret.getTimer());
es.Input.update(); es.Input.update();
if (!this._scene) return [3, 2]; if (!this._scene) return [3, 2];
@@ -1537,9 +1539,7 @@ var es;
_a.sent(); _a.sent();
this.addChild(this._scene); this.addChild(this._scene);
_a.label = 2; _a.label = 2;
case 2: case 2: return [4, this.draw()];
this.endDebugUpdate();
return [4, this.draw()];
case 3: case 3:
_a.sent(); _a.sent();
return [2]; return [2];
@@ -4932,6 +4932,8 @@ var es;
ComponentList.prototype.deregisterAllComponents = function () { ComponentList.prototype.deregisterAllComponents = function () {
for (var i = 0; i < this._components.length; i++) { for (var i = 0; i < this._components.length; i++) {
var component = this._components.buffer[i]; var component = this._components.buffer[i];
if (!component)
continue;
if (component instanceof es.RenderableComponent) { if (component instanceof es.RenderableComponent) {
if (component.displayObject.parent) if (component.displayObject.parent)
component.displayObject.parent.removeChild(component.displayObject); component.displayObject.parent.removeChild(component.displayObject);
@@ -5001,6 +5003,8 @@ var es;
} }
}; };
ComponentList.prototype.handleRemove = function (component) { ComponentList.prototype.handleRemove = function (component) {
if (!component)
return;
if (component instanceof es.RenderableComponent) { if (component instanceof es.RenderableComponent) {
if (component.displayObject.parent) if (component.displayObject.parent)
component.displayObject.parent.removeChild(component.displayObject); component.displayObject.parent.removeChild(component.displayObject);
@@ -11318,7 +11322,7 @@ var es;
obj["reset"](); obj["reset"]();
} }
}; };
Pool._objectQueue = new Array(10); Pool._objectQueue = [];
return Pool; return Pool;
}()); }());
es.Pool = Pool; es.Pool = Pool;
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -55,7 +55,7 @@ module es {
} }
public hasOpened(): boolean { public hasOpened(): boolean {
return this._numClosed > 0; return this._numOpened > 0;
} }
public removeOpened(node: AStarNode){ public removeOpened(node: AStarNode){
+5 -1
View File
@@ -36,7 +36,11 @@ module es {
this.dontCare = dontcare; this.dontCare = dontcare;
} }
public set(conditionId: number, value: boolean): boolean { public set(conditionId: number | string, value: boolean): boolean {
if (typeof conditionId == "string"){
return this.set(this.planner.findConditionNameIndex(conditionId), value);
}
this.values = value ? (this.values | (1 << conditionId)) : (this.values & ~(1 << conditionId)); this.values = value ? (this.values | (1 << conditionId)) : (this.values & ~(1 << conditionId));
this.dontCare ^= (1 << conditionId); this.dontCare ^= (1 << conditionId);
return true; return true;
+2 -2
View File
@@ -232,7 +232,7 @@ module es {
} }
protected async update() { protected async update() {
this.startDebugUpdate(); // this.startDebugUpdate();
// 更新我们所有的系统管理器 // 更新我们所有的系统管理器
Time.update(egret.getTimer()); Time.update(egret.getTimer());
@@ -266,7 +266,7 @@ module es {
} }
} }
this.endDebugUpdate(); // this.endDebugUpdate();
await this.draw(); await this.draw();
} }
+2
View File
@@ -75,6 +75,7 @@ module es {
for (let i = 0; i < this._components.length; i++) { for (let i = 0; i < this._components.length; i++) {
let component = this._components.buffer[i]; let component = this._components.buffer[i];
if (!component) continue;
// 处理渲染层列表 // 处理渲染层列表
if (component instanceof RenderableComponent) { if (component instanceof RenderableComponent) {
if (component.displayObject.parent) if (component.displayObject.parent)
@@ -161,6 +162,7 @@ module es {
} }
public handleRemove(component: Component) { public handleRemove(component: Component) {
if (!component) return;
// 处理渲染层列表 // 处理渲染层列表
if (component instanceof RenderableComponent) { if (component instanceof RenderableComponent) {
if (component.displayObject.parent) if (component.displayObject.parent)
+1 -1
View File
@@ -3,7 +3,7 @@ module es {
* *
*/ */
export class Pool<T> { export class Pool<T> {
private static _objectQueue = new Array(10); private static _objectQueue = [];
/** /**
* 使cacheCount对象填充缓存 * 使cacheCount对象填充缓存