场景搜索包含特定组件的实体列表

This commit is contained in:
yhh
2021-03-26 17:36:50 +08:00
parent d2915fe30c
commit 8b5bc444f1
5 changed files with 180 additions and 36 deletions

View File

@@ -34,26 +34,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
@@ -74,6 +54,26 @@ var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
var es;
(function (es) {
/**
@@ -1468,6 +1468,19 @@ var es;
Scene.prototype.findComponentsOfType = function (type) {
return this.entities.findComponentsOfType(type);
};
/**
* 返回场景中包含特定组件的实体列表
* @param type
* @returns
*/
Scene.prototype.findEntitiesOfComponent = function () {
var types = [];
for (var _i = 0; _i < arguments.length; _i++) {
types[_i] = arguments[_i];
}
var _a;
return (_a = this.entities).findEntitesOfComponent.apply(_a, __spread(types));
};
/**
* 在场景中添加一个EntitySystem处理器
* @param processor 处理器
@@ -4322,6 +4335,71 @@ var es;
}
return comps;
};
/**
* 返回场景中包含特定组件的实体列表
* @param types
* @returns
*/
EntityList.prototype.findEntitesOfComponent = function () {
var types = [];
for (var _i = 0; _i < arguments.length; _i++) {
types[_i] = arguments[_i];
}
var e_13, _a, e_14, _b;
var entities = [];
for (var i = 0; i < this._entities.length; i++) {
if (this._entities[i].enabled) {
var meet = true;
try {
for (var types_1 = __values(types), types_1_1 = types_1.next(); !types_1_1.done; types_1_1 = types_1.next()) {
var type = types_1_1.value;
var hasComp = this._entities[i].hasComponent(type);
if (!hasComp) {
meet = false;
break;
}
}
}
catch (e_13_1) { e_13 = { error: e_13_1 }; }
finally {
try {
if (types_1_1 && !types_1_1.done && (_a = types_1.return)) _a.call(types_1);
}
finally { if (e_13) throw e_13.error; }
}
if (meet) {
entities.push(this._entities[i]);
}
}
}
for (var i = 0; i < this._entitiesToAdded.getCount(); i++) {
var entity = this._entitiesToAdded.toArray()[i];
if (entity.enabled) {
var meet = true;
try {
for (var types_2 = __values(types), types_2_1 = types_2.next(); !types_2_1.done; types_2_1 = types_2.next()) {
var type = types_2_1.value;
var hasComp = entity.hasComponent(type);
if (!hasComp) {
meet = false;
break;
}
}
}
catch (e_14_1) { e_14 = { error: e_14_1 }; }
finally {
try {
if (types_2_1 && !types_2_1.done && (_b = types_2.return)) _b.call(types_2);
}
finally { if (e_14) throw e_14.error; }
}
if (meet) {
entities.push(entity);
}
}
}
return entities;
};
return EntityList;
}());
es.EntityList = EntityList;
@@ -7231,7 +7309,7 @@ var es;
* @param layerMask
*/
SpatialHash.prototype.overlapRectangle = function (rect, results, layerMask) {
var e_13, _a;
var e_15, _a;
this._overlapTestBox.updateBox(rect.width, rect.height);
this._overlapTestBox.position = rect.location;
var resultCounter = 0;
@@ -7262,12 +7340,12 @@ var es;
return resultCounter;
}
}
catch (e_13_1) { e_13 = { error: e_13_1 }; }
catch (e_15_1) { e_15 = { error: e_15_1 }; }
finally {
try {
if (potentials_1_1 && !potentials_1_1.done && (_a = potentials_1.return)) _a.call(potentials_1);
}
finally { if (e_13) throw e_13.error; }
finally { if (e_15) throw e_15.error; }
}
return resultCounter;
};
@@ -7279,7 +7357,7 @@ var es;
* @param layerMask
*/
SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) {
var e_14, _a;
var e_16, _a;
var bounds = new es.Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2);
this._overlapTestCircle.radius = radius;
this._overlapTestCircle.position = circleCenter;
@@ -7312,12 +7390,12 @@ var es;
return resultCounter;
}
}
catch (e_14_1) { e_14 = { error: e_14_1 }; }
catch (e_16_1) { e_16 = { error: e_16_1 }; }
finally {
try {
if (potentials_2_1 && !potentials_2_1.done && (_a = potentials_2.return)) _a.call(potentials_2);
}
finally { if (e_14) throw e_14.error; }
finally { if (e_16) throw e_16.error; }
}
return resultCounter;
};
@@ -11477,7 +11555,7 @@ var linq;
* 创建一个Set从一个Enumerable.List< T>。
*/
List.prototype.toSet = function () {
var e_15, _a;
var e_17, _a;
var result = new Set();
try {
for (var _b = __values(this._elements), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -11485,12 +11563,12 @@ var linq;
result.add(x);
}
}
catch (e_15_1) { e_15 = { error: e_15_1 }; }
catch (e_17_1) { e_17 = { error: e_17_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_15) throw e_15.error; }
finally { if (e_17) throw e_17.error; }
}
return result;
};
@@ -11739,7 +11817,7 @@ var es;
* 计算可见性多边形并返回三角形扇形的顶点减去中心顶点。返回的数组来自ListPool
*/
VisibilityComputer.prototype.end = function () {
var e_16, _a;
var e_18, _a;
var output = es.ListPool.obtain();
this.updateSegments();
this._endPoints.sort(this._radialComparer.compare);
@@ -11778,12 +11856,12 @@ var es;
}
}
}
catch (e_16_1) { e_16 = { error: e_16_1 }; }
catch (e_18_1) { e_18 = { error: e_18_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_16) throw e_16.error; }
finally { if (e_18) throw e_18.error; }
}
}
VisibilityComputer._openSegments.clear();
@@ -11899,7 +11977,7 @@ var es;
* 处理片段,以便我们稍后对它们进行分类
*/
VisibilityComputer.prototype.updateSegments = function () {
var e_17, _a;
var e_19, _a;
try {
for (var _b = __values(this._segments), _c = _b.next(); !_c.done; _c = _b.next()) {
var segment = _c.value;
@@ -11917,12 +11995,12 @@ var es;
segment.p2.begin = !segment.p1.begin;
}
}
catch (e_17_1) { e_17 = { error: e_17_1 }; }
catch (e_19_1) { e_19 = { error: e_19_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_17) throw e_17.error; }
finally { if (e_19) throw e_19.error; }
}
// 如果我们有一个聚光灯,我们需要存储前两个段的角度。
// 这些是光斑的边界,我们将用它们来过滤它们之外的任何顶点。