Merge branch 'master' of https://github.com/esengine/egret-framework
# Conflicts: # demo/libs/framework/framework.min.js
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@
|
||||
data-content-width="640"
|
||||
data-content-height="1136"
|
||||
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">
|
||||
</div>
|
||||
<script>
|
||||
|
||||
Vendored
+1
-1
@@ -280,7 +280,7 @@ declare module es {
|
||||
planner: ActionPlanner;
|
||||
static create(planner: ActionPlanner): WorldState;
|
||||
constructor(planner: ActionPlanner, values: number, dontcare: number);
|
||||
set(conditionId: number, value: boolean): boolean;
|
||||
set(conditionId: number | string, value: boolean): boolean;
|
||||
equals(other: WorldState): boolean;
|
||||
describe(planner: ActionPlanner): string;
|
||||
}
|
||||
|
||||
@@ -1008,7 +1008,7 @@ var es;
|
||||
return null;
|
||||
};
|
||||
AStarStorage.prototype.hasOpened = function () {
|
||||
return this._numClosed > 0;
|
||||
return this._numOpened > 0;
|
||||
};
|
||||
AStarStorage.prototype.removeOpened = function (node) {
|
||||
if (this._numOpened > 0)
|
||||
@@ -1330,6 +1330,9 @@ var es;
|
||||
return new WorldState(planner, 0, -1);
|
||||
};
|
||||
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.dontCare ^= (1 << conditionId);
|
||||
return true;
|
||||
@@ -1513,7 +1516,6 @@ var es;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
this.startDebugUpdate();
|
||||
es.Time.update(egret.getTimer());
|
||||
es.Input.update();
|
||||
if (!this._scene) return [3, 2];
|
||||
@@ -1537,9 +1539,7 @@ var es;
|
||||
_a.sent();
|
||||
this.addChild(this._scene);
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
this.endDebugUpdate();
|
||||
return [4, this.draw()];
|
||||
case 2: return [4, this.draw()];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [2];
|
||||
@@ -4932,6 +4932,8 @@ var es;
|
||||
ComponentList.prototype.deregisterAllComponents = function () {
|
||||
for (var i = 0; i < this._components.length; i++) {
|
||||
var component = this._components.buffer[i];
|
||||
if (!component)
|
||||
continue;
|
||||
if (component instanceof es.RenderableComponent) {
|
||||
if (component.displayObject.parent)
|
||||
component.displayObject.parent.removeChild(component.displayObject);
|
||||
@@ -5001,6 +5003,8 @@ var es;
|
||||
}
|
||||
};
|
||||
ComponentList.prototype.handleRemove = function (component) {
|
||||
if (!component)
|
||||
return;
|
||||
if (component instanceof es.RenderableComponent) {
|
||||
if (component.displayObject.parent)
|
||||
component.displayObject.parent.removeChild(component.displayObject);
|
||||
@@ -11318,7 +11322,7 @@ var es;
|
||||
obj["reset"]();
|
||||
}
|
||||
};
|
||||
Pool._objectQueue = new Array(10);
|
||||
Pool._objectQueue = [];
|
||||
return Pool;
|
||||
}());
|
||||
es.Pool = Pool;
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+2
-3
@@ -17,7 +17,7 @@
|
||||
"bin-debug/SampleHelpers/SampleScene.js",
|
||||
"bin-debug/Scenes/NinjaAdventure/ProjectileHitDetector.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/UI_View_loading.js",
|
||||
"bin-debug/Fgui/sc/scBinder.js",
|
||||
@@ -28,10 +28,9 @@
|
||||
"bin-debug/Scenes/AnimatedTiles/AnimatedTilesScene.js",
|
||||
"bin-debug/Scenes/EmptyScene/BasicScene.js",
|
||||
"bin-debug/Scenes/GOAP/GoapScene.js",
|
||||
"bin-debug/Scenes/GOAP/QuickAgent.js",
|
||||
"bin-debug/Scenes/LineCasting/LineCaster.js",
|
||||
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
|
||||
"bin-debug/Main.js",
|
||||
"bin-debug/Scenes/NinjaAdventure/CameraBounds.js",
|
||||
"bin-debug/Scenes/NinjaAdventure/FireballProjectileController.js",
|
||||
"bin-debug/Scenes/NinjaAdventure/Ninja.js",
|
||||
"bin-debug/Scenes/NinjaAdventure/NinjaAdventureScene.js",
|
||||
|
||||
@@ -1,9 +1,117 @@
|
||||
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 {
|
||||
public _destinationLocation: Location;
|
||||
public planner: es.ActionPlanner;
|
||||
public _actionPlan: es.Action[];
|
||||
|
||||
public minerState: MinerState;
|
||||
|
||||
public initialize(): void {
|
||||
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,
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ egret_native.egretStart = function () {
|
||||
contentWidth: 640,
|
||||
contentHeight: 1136,
|
||||
showPaintRect: false,
|
||||
showFPS: true,
|
||||
showFPS: false,
|
||||
fpsStyles: "x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9",
|
||||
showLog: false,
|
||||
logFilter: "",
|
||||
|
||||
Vendored
+1
-1
@@ -280,7 +280,7 @@ declare module es {
|
||||
planner: ActionPlanner;
|
||||
static create(planner: ActionPlanner): WorldState;
|
||||
constructor(planner: ActionPlanner, values: number, dontcare: number);
|
||||
set(conditionId: number, value: boolean): boolean;
|
||||
set(conditionId: number | string, value: boolean): boolean;
|
||||
equals(other: WorldState): boolean;
|
||||
describe(planner: ActionPlanner): string;
|
||||
}
|
||||
|
||||
+10
-6
@@ -1008,7 +1008,7 @@ var es;
|
||||
return null;
|
||||
};
|
||||
AStarStorage.prototype.hasOpened = function () {
|
||||
return this._numClosed > 0;
|
||||
return this._numOpened > 0;
|
||||
};
|
||||
AStarStorage.prototype.removeOpened = function (node) {
|
||||
if (this._numOpened > 0)
|
||||
@@ -1330,6 +1330,9 @@ var es;
|
||||
return new WorldState(planner, 0, -1);
|
||||
};
|
||||
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.dontCare ^= (1 << conditionId);
|
||||
return true;
|
||||
@@ -1513,7 +1516,6 @@ var es;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
this.startDebugUpdate();
|
||||
es.Time.update(egret.getTimer());
|
||||
es.Input.update();
|
||||
if (!this._scene) return [3, 2];
|
||||
@@ -1537,9 +1539,7 @@ var es;
|
||||
_a.sent();
|
||||
this.addChild(this._scene);
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
this.endDebugUpdate();
|
||||
return [4, this.draw()];
|
||||
case 2: return [4, this.draw()];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [2];
|
||||
@@ -4932,6 +4932,8 @@ var es;
|
||||
ComponentList.prototype.deregisterAllComponents = function () {
|
||||
for (var i = 0; i < this._components.length; i++) {
|
||||
var component = this._components.buffer[i];
|
||||
if (!component)
|
||||
continue;
|
||||
if (component instanceof es.RenderableComponent) {
|
||||
if (component.displayObject.parent)
|
||||
component.displayObject.parent.removeChild(component.displayObject);
|
||||
@@ -5001,6 +5003,8 @@ var es;
|
||||
}
|
||||
};
|
||||
ComponentList.prototype.handleRemove = function (component) {
|
||||
if (!component)
|
||||
return;
|
||||
if (component instanceof es.RenderableComponent) {
|
||||
if (component.displayObject.parent)
|
||||
component.displayObject.parent.removeChild(component.displayObject);
|
||||
@@ -11318,7 +11322,7 @@ var es;
|
||||
obj["reset"]();
|
||||
}
|
||||
};
|
||||
Pool._objectQueue = new Array(10);
|
||||
Pool._objectQueue = [];
|
||||
return Pool;
|
||||
}());
|
||||
es.Pool = Pool;
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -55,7 +55,7 @@ module es {
|
||||
}
|
||||
|
||||
public hasOpened(): boolean {
|
||||
return this._numClosed > 0;
|
||||
return this._numOpened > 0;
|
||||
}
|
||||
|
||||
public removeOpened(node: AStarNode){
|
||||
|
||||
@@ -36,7 +36,11 @@ module es {
|
||||
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.dontCare ^= (1 << conditionId);
|
||||
return true;
|
||||
|
||||
@@ -232,7 +232,7 @@ module es {
|
||||
}
|
||||
|
||||
protected async update() {
|
||||
this.startDebugUpdate();
|
||||
// this.startDebugUpdate();
|
||||
|
||||
// 更新我们所有的系统管理器
|
||||
Time.update(egret.getTimer());
|
||||
@@ -266,7 +266,7 @@ module es {
|
||||
}
|
||||
}
|
||||
|
||||
this.endDebugUpdate();
|
||||
// this.endDebugUpdate();
|
||||
|
||||
await this.draw();
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ module es {
|
||||
for (let i = 0; i < this._components.length; i++) {
|
||||
let component = this._components.buffer[i];
|
||||
|
||||
if (!component) continue;
|
||||
// 处理渲染层列表
|
||||
if (component instanceof RenderableComponent) {
|
||||
if (component.displayObject.parent)
|
||||
@@ -161,6 +162,7 @@ module es {
|
||||
}
|
||||
|
||||
public handleRemove(component: Component) {
|
||||
if (!component) return;
|
||||
// 处理渲染层列表
|
||||
if (component instanceof RenderableComponent) {
|
||||
if (component.displayObject.parent)
|
||||
|
||||
@@ -3,7 +3,7 @@ module es {
|
||||
* 用于池任何对象
|
||||
*/
|
||||
export class Pool<T> {
|
||||
private static _objectQueue = new Array(10);
|
||||
private static _objectQueue = [];
|
||||
|
||||
/**
|
||||
* 预热缓存,使用最大的cacheCount对象填充缓存
|
||||
|
||||
Reference in New Issue
Block a user