@woosh/meep-engine 2.51.0 → 2.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/editor/actions/concrete/WriteGridValueAction.js +1 -1
- package/editor/ecs/component/prototypeObjectEditor.js +1 -1
- package/editor/process/ObstacleGridDisplayProcess.js +2 -2
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
- package/editor/tools/GridPaintTool.js +2 -2
- package/package.json +4 -3
- package/samples/generation/SampleGenerator0.js +1 -1
- package/samples/generation/generators/interactive/mir_generator_place_buff_objects.js +1 -1
- package/samples/generation/generators/mir_generator_place_bases.js +1 -1
- package/samples/generation/generators/mir_generator_place_road_decorators.js +1 -1
- package/samples/generation/generators/mir_generator_place_starting_point.js +1 -1
- package/samples/generation/main.js +2 -2
- package/samples/generation/rules/matcher_play_area.js +1 -1
- package/samples/generation/rules/matcher_tag_occupied.js +1 -1
- package/samples/generation/rules/matcher_tag_traversable.js +1 -1
- package/samples/generation/themes/SampleTheme0.js +5 -5
- package/src/core/NumberFormat.js +0 -71
- package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +1 -0
- package/src/core/bvh2/bvh3/query/BVHQueryAny.js +16 -0
- package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +5 -5
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +2 -3
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.spec.js +22 -0
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.spec.js +64 -0
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +2 -3
- package/src/core/collection/table/RowFirstTableSpec.js +8 -4
- package/src/core/geom/3d/aabb/aabb3_from_threejs_geometry.js +41 -0
- package/src/core/geom/3d/matrix/MATRIX_4_IDENTITY.spec.js +10 -0
- package/src/core/geom/3d/topology/struct/TopoMesh.js +3 -2
- package/src/core/geom/3d/topology/struct/prototypeBinaryTopology.js +4 -4
- package/src/core/geom/Vector2.d.ts +9 -0
- package/src/core/geom/Vector2.js +8 -22
- package/src/core/geom/Vector2.spec.js +153 -0
- package/src/core/model/ModuleRegistry.js +2 -4
- package/src/core/model/ModuleRegistry.spec.js +31 -0
- package/src/core/model/reactive/js/compileReactiveToJS.spec.js +14 -0
- package/src/core/model/reactive/model/logic/ReactiveAnd.spec.js +31 -1
- package/src/core/model/reactive/model/logic/ReactiveOr.spec.js +53 -0
- package/src/core/model/stat/LinearModifier.js +2 -2
- package/src/core/model/stat/LinearModifier.spec.js +62 -0
- package/src/core/model/stat/Stat.js +12 -0
- package/src/core/model/stat/Stat.spec.js +36 -0
- package/src/core/primitives/array/computeStridedIntegerArrayHash.spec.js +28 -0
- package/src/core/primitives/numbers/number_format_by_thousands.js +14 -0
- package/src/core/primitives/numbers/number_pretty_print.js +49 -0
- package/src/core/primitives/strings/computeStringHash.spec.js +12 -5
- package/src/core/process/BaseProcess.js +8 -8
- package/src/engine/Clock.js +30 -29
- package/src/engine/Clock.spec.js +26 -0
- package/src/engine/Engine.spec.js +4 -0
- package/src/engine/ecs/EntityBuilder.js +3 -1
- package/src/engine/ecs/EntityBuilder.spec.js +21 -0
- package/src/engine/ecs/EntityComponentDataset.js +1 -1
- package/src/engine/ecs/EntityObserver.spec.js +1 -1
- package/src/engine/ecs/dynamic_actions/actions/definition/{WhiteToBlackboardActionDescription.js → WriteToBlackboardActionDescription.js} +2 -2
- package/src/engine/ecs/dynamic_actions/actions/definition/deserializeActionFromJSON.js +2 -2
- package/src/engine/ecs/gui/GUIElement.js +1 -1
- package/src/engine/ecs/gui/position/ViewportPosition.js +3 -3
- package/src/engine/ecs/guid/GUIDSerializationAdapter.spec.js +21 -0
- package/src/engine/ecs/parent/EntityNode.js +1 -1
- package/src/engine/ecs/parent/EntityNode.spec.js +104 -0
- package/src/engine/ecs/speaker/Voice.js +4 -0
- package/src/engine/ecs/team/Team.js +0 -44
- package/src/engine/ecs/team/TeamSerializationAdapter.js +46 -0
- package/src/engine/ecs/terrain/ecs/TerrainClassifier.js +1 -1
- package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +1 -1
- package/src/engine/ecs/transform/Transform.js +2 -1
- package/src/engine/ecs/transform/Transform.spec.js +24 -0
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +2 -6
- package/src/engine/graphics/ecs/animation/animator/graph/AnimationGraph.spec.js +5 -0
- package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +24 -25
- package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.spec.js +5 -0
- package/src/engine/graphics/ecs/decal/DecalSystem.js +2 -20
- package/src/engine/graphics/ecs/decal/v2/Decal.js +32 -32
- package/src/engine/graphics/ecs/decal/v2/Decal.spec.js +5 -0
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +4 -2
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +4 -33
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +8 -4
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.spec.js +5 -0
- package/src/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +0 -12
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
- package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +2 -4
- package/src/engine/graphics/geometry/buffered/computeBufferAttributeHash.js +1 -1
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +0 -2
- package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -6
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -6
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +2 -2
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +4 -8
- package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +2 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +6 -1
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +2 -2
- package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
- package/src/engine/graphics/texture/TextureBackedMemoryRegion.js +4 -1
- package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
- package/src/engine/graphics/texture/sampler/filter/filter_lanczos3.js +7 -2
- package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +3 -23
- package/src/engine/grid/grid2transform/GridPosition2Transform.js +122 -0
- package/src/engine/grid/grid2transform/GridPosition2TransformSerializationAdapter.js +70 -0
- package/src/engine/grid/grid2transform/GridPosition2TransformSerializationUpgrader_0_1.js +40 -0
- package/src/engine/grid/{systems → grid2transform}/GridPosition2TransformSystem.js +3 -3
- package/src/engine/grid/{components → obstacle}/GridObstacle.js +45 -25
- package/src/engine/grid/obstacle/GridObstacle.spec.js +175 -0
- package/src/engine/grid/{components → position}/GridPosition.js +6 -14
- package/src/engine/grid/{systems → position}/GridPositionSystem.js +1 -1
- package/src/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
- package/src/engine/input/devices/PointerDevice.spec.js +5 -0
- package/src/engine/navigation/ecs/components/computeCatmullRomSpline.js +5 -1
- package/src/engine/navigation/ecs/path_following/PathFollower.js +40 -32
- package/src/engine/navigation/ecs/path_following/PathFollower.spec.js +27 -0
- package/src/engine/plugin/EnginePlugin.js +12 -14
- package/src/engine/plugin/EnginePlugin.spec.js +5 -0
- package/src/engine/plugin/EnginePluginManager.js +18 -22
- package/src/engine/scene/transitionToScene.js +12 -1
- package/src/engine/simulation/Ticker.js +1 -1
- package/src/generation/filtering/CellFilter.js +6 -9
- package/src/generation/filtering/boolean/CellFilterLiteralBoolean.js +1 -4
- package/src/generation/filtering/core/CellFilterBinaryOperation.js +12 -15
- package/src/generation/filtering/core/CellFilterOperationTertiary.js +15 -19
- package/src/generation/filtering/numeric/CellFilterLiteralFloat.js +6 -9
- package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainObstacle.js +1 -1
- package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.js +2 -2
- package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +1 -1
- package/src/generation/markers/actions/MarkerNodeActionEntityPlacement.js +1 -1
- package/src/generation/theme/TerrainLayerDescription.js +1 -1
- package/src/view/common/LabelView.js +3 -3
- package/src/engine/ecs/components/AimController.js +0 -18
- package/src/engine/ecs/components/Attacker.js +0 -13
- package/src/engine/ecs/components/MeshCollider.js +0 -15
- package/src/engine/ecs/components/RangedAttack.js +0 -12
- package/src/engine/ecs/components/TargetAI.js +0 -11
- package/src/engine/ecs/components/ViewportMeshProjection.js +0 -18
- package/src/engine/ecs/systems/AimControllerSystem.js +0 -63
- package/src/engine/ecs/systems/AttackerSystem.js +0 -67
- package/src/engine/ecs/systems/MeshColliderSystem.js +0 -47
- package/src/engine/ecs/systems/MonsterAISystem.js +0 -163
- package/src/engine/ecs/systems/MortalitySystem.js +0 -46
- package/src/engine/ecs/systems/RangedAttackSystem.js +0 -132
- package/src/engine/ecs/systems/SerializationMetadataSystem.js +0 -10
- package/src/engine/ecs/systems/TargetAISystem.js +0 -107
- package/src/engine/ecs/systems/ViewportMeshProjectionSystem.js +0 -68
- package/src/engine/graphics/particles/ParticleEmitterLibrary.js +0 -87
- package/src/engine/graphics/texture/ExportCanvasAsPNG.js +0 -7
- package/src/engine/grid/components/GridObstacle.spec.js +0 -46
- package/src/engine/grid/components/GridPosition2Transform.js +0 -232
- package/src/engine/grid/components/ViewportGridProjection.js +0 -20
- package/src/engine/grid/systems/GridObstacleSystem.js +0 -58
- package/src/engine/grid/systems/ViewportGridProjectionSystem.js +0 -105
- package/src/engine/navigation/PathFinder.js +0 -172
- package/src/engine/navigation/PathWorker.js +0 -78
- package/src/engine/navigation/ecs/systems/PathFinderSystem.js +0 -63
- package/src/engine/navigation/ecs/systems/PathSystem.js +0 -19
- package/src/engine/navigation/funnel/Funnel.js +0 -196
- package/src/generation/ZoneNode.js +0 -9
- /package/{src/generation → samples/generation/grid}/GridTags.js +0 -0
- /package/src/{engine → core/primitives/array}/computeStridedIntegerArrayHash.js +0 -0
- /package/src/engine/grid/{components → grid2transform}/GridPosition2TransformFlags.js +0 -0
- /package/src/engine/grid/{components → obstacle}/GridObstacleSerializationAdapter.js +0 -0
- /package/src/engine/grid/{components → position}/GridPositionSerializationAdapter.js +0 -0
- /package/src/engine/grid/{components → position}/GridPositionSerializationUpdater_0_1.js +0 -0
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 30/06/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import Attacker from '../components/Attacker.js';
|
|
6
|
-
import { Transform } from '../transform/Transform.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class AttackerSystem extends System {
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
|
|
13
|
-
this.dependencies = [Attacker];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
add(component, entity) {
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
remove(component, entity) {
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
update(timeDelta) {
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @type {EntityManager}
|
|
26
|
-
*/
|
|
27
|
-
const em = this.entityManager;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {Attacker} attacker
|
|
32
|
-
* @param {Transform} transform
|
|
33
|
-
* @param entity
|
|
34
|
-
*/
|
|
35
|
-
function visitEntity(attacker, transform, entity) {
|
|
36
|
-
const target = attacker.target;
|
|
37
|
-
if (target === null) {
|
|
38
|
-
return; //no target
|
|
39
|
-
}
|
|
40
|
-
//check distance between attacker and the target
|
|
41
|
-
const targetTransform = em.getComponent(target, Transform);
|
|
42
|
-
if (targetTransform === null) {
|
|
43
|
-
//target doesn't have transform
|
|
44
|
-
attacker.target = null; //drop target
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (transform.position.distanceTo(targetTransform.position) > attacker.range) {
|
|
48
|
-
return; //target is too far
|
|
49
|
-
}
|
|
50
|
-
const delay = attacker.delay;
|
|
51
|
-
let time = attacker.timerValue + timeDelta;
|
|
52
|
-
if (time > delay) {
|
|
53
|
-
let attacks = Math.floor(time / delay);
|
|
54
|
-
time %= delay;
|
|
55
|
-
while (attacks-- > 0) {
|
|
56
|
-
em.sendEvent(entity, "attack", target);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
attacker.timerValue = time;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
em.traverseEntities([Attacker, Transform], visitEntity);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export default AttackerSystem;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by hdnha on 7/24/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import Tag from '../components/Tag.js';
|
|
6
|
-
import { Transform } from '../transform/Transform.js';
|
|
7
|
-
import Renderable from '../renderable/Renderable.js';
|
|
8
|
-
import MeshCollider from '../components/MeshCollider.js';
|
|
9
|
-
import { Raycaster } from "three";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class MeshColliderSystem extends System {
|
|
13
|
-
constructor() {
|
|
14
|
-
super();
|
|
15
|
-
|
|
16
|
-
this.dependencies = [MeshCollider];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
add(component, entity) {
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
remove(component) {
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
update(timeDelta) {
|
|
26
|
-
const entityManager = this.entityManager;
|
|
27
|
-
entityManager.traverseEntities([Transform, MeshCollider], function (transform, meshCollider, entity) {
|
|
28
|
-
const delta = transform.position.clone().sub(transform.previousPosition);
|
|
29
|
-
const length = delta.length();
|
|
30
|
-
let raycaster = new Raycaster(transform.previousPosition, delta.normalize(), 0, length);
|
|
31
|
-
if (!raycaster) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
entityManager.traverseEntities([Tag, Renderable], function (tag, renderable, otherEntity) {
|
|
35
|
-
if (meshCollider.tags.indexOf(tag.name) != -1) {
|
|
36
|
-
const objects = raycaster.intersectObject(renderable.mesh);
|
|
37
|
-
if (objects.length > 0) {
|
|
38
|
-
entityManager.sendEvent(entity, "collision", otherEntity);
|
|
39
|
-
return false; //stop traversal
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default MeshColliderSystem;
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 12/08/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import { Transform } from '../transform/Transform.js';
|
|
6
|
-
import MonsterAI from '../components/MonsterAI.js';
|
|
7
|
-
import Tag from '../components/Tag.js';
|
|
8
|
-
import PathFollower from '../../navigation/ecs/path_following/PathFollower.js';
|
|
9
|
-
import Steering from '../components/Steering.js';
|
|
10
|
-
import Attacker from '../components/Attacker.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class MonsterAISystem extends System {
|
|
14
|
-
constructor(pathFinder) {
|
|
15
|
-
super();
|
|
16
|
-
this.pathFinder = pathFinder;
|
|
17
|
-
|
|
18
|
-
this.dependencies = [MonsterAI];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
add(component, entity) {
|
|
22
|
-
const pathFinder = this.pathFinder;
|
|
23
|
-
const em = this.entityManager;
|
|
24
|
-
em.addEntityEventListener(entity, "spawned", function () {
|
|
25
|
-
//reset current path
|
|
26
|
-
const pf = em.getComponent(entity, PathFollower);
|
|
27
|
-
pf.path = null;
|
|
28
|
-
gotoDefensePoint(em, pathFinder, entity);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
remove(component) {
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
update(timeDelta) {
|
|
36
|
-
const em = this.entityManager;
|
|
37
|
-
const pathFinder = this.pathFinder;
|
|
38
|
-
em.traverseEntities([MonsterAI, Attacker, Transform], function (ai, attacker, transform, entity) {
|
|
39
|
-
const target = attacker.target;
|
|
40
|
-
if (target !== null) {
|
|
41
|
-
//there is a target
|
|
42
|
-
const targetTransform = em.getComponent(target, Transform);
|
|
43
|
-
if (targetTransform === null) {
|
|
44
|
-
gotoDefensePoint(em, pathFinder, entity);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
//check the distance
|
|
48
|
-
const distance = transform.position.distanceTo(targetTransform.position);
|
|
49
|
-
if (distance <= ai.chaseDistance) {
|
|
50
|
-
//check if path exists
|
|
51
|
-
pathFinder.findPath(transform.position, targetTransform.position, 2, function (path) {
|
|
52
|
-
//find length of the path
|
|
53
|
-
if (path !== null && pathLength(path) < ai.chaseDistance) {
|
|
54
|
-
const pathFollower = em.getComponent(entity, PathFollower);
|
|
55
|
-
if (pathFollower !== null) {
|
|
56
|
-
pathFollower.path = path;
|
|
57
|
-
pathFollower.lastIndex = 0;
|
|
58
|
-
//stop steering
|
|
59
|
-
const steering = em.getComponent(entity, Steering);
|
|
60
|
-
steering.destination = null;
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
gotoDefensePoint(em, pathFinder, entity);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
gotoDefensePoint(em, pathFinder, entity);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
function pointsEqual(p1, p2) {
|
|
76
|
-
return p1.x === p2.x && p1.y === p2.y && p1.z === p2.z;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function navigateTo(em, entity, target, pathFinder) {
|
|
80
|
-
const pathFollower = em.getComponent(entity, PathFollower);
|
|
81
|
-
const steering = em.getComponent(entity, Steering);
|
|
82
|
-
const source = em.getComponent(entity, Transform);
|
|
83
|
-
|
|
84
|
-
//check if already going to the right place
|
|
85
|
-
const path = pathFollower.path;
|
|
86
|
-
let pathLength;
|
|
87
|
-
if (path !== null && path !== void 0 && (pathLength = path.length, pathLength > 0)) {
|
|
88
|
-
const lastPointOfPath = path[pathLength - 1];
|
|
89
|
-
if (pointsEqual(lastPointOfPath, target.position)) {
|
|
90
|
-
return;// already following thr right path
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//find new path
|
|
95
|
-
if (target !== null && !pathFollower.lock) {
|
|
96
|
-
pathFollower.lock = true;
|
|
97
|
-
pathFinder.findPath(source.position, target.position, 2, function (path) {
|
|
98
|
-
//reset path
|
|
99
|
-
pathFollower.path = path;
|
|
100
|
-
pathFollower.lastIndex = 0;
|
|
101
|
-
//stop steering
|
|
102
|
-
steering.destination = null;
|
|
103
|
-
//release lock
|
|
104
|
-
pathFollower.lock = false;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* finds nearest (straight line distance) entity with matching tag and navigates to it
|
|
111
|
-
* @param em
|
|
112
|
-
* @param pathFinder
|
|
113
|
-
* @param entity
|
|
114
|
-
* @param tagName
|
|
115
|
-
*/
|
|
116
|
-
function gotoTag(em, pathFinder, entity, tagName) {
|
|
117
|
-
let target = null;
|
|
118
|
-
let d = Math.POSITIVE_INFINITY;
|
|
119
|
-
const sourceTransform = em.getComponent(entity, Transform);
|
|
120
|
-
const sourcePosition = sourceTransform.position;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
*
|
|
124
|
-
* @param {Tag} tag
|
|
125
|
-
* @param {Transform} transform
|
|
126
|
-
*/
|
|
127
|
-
function visitTag(tag, transform) {
|
|
128
|
-
if (tag.contains(tagName)) {
|
|
129
|
-
const distanceToSquared = transform.position.distanceToSquared(sourcePosition);
|
|
130
|
-
if (target === null || distanceToSquared < d) {
|
|
131
|
-
target = transform;
|
|
132
|
-
d = distanceToSquared;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
em.traverseEntities([Tag, Transform], visitTag);
|
|
138
|
-
navigateTo(em, entity, target, pathFinder);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function pathLength(path) {
|
|
142
|
-
let result = 0;
|
|
143
|
-
if (path === void 0) {
|
|
144
|
-
return 0;
|
|
145
|
-
}
|
|
146
|
-
const l = path.length - 1;
|
|
147
|
-
if (l >= 1) {
|
|
148
|
-
let c = path[0], p;
|
|
149
|
-
for (let i = 1; i < l; i++) {
|
|
150
|
-
p = c;
|
|
151
|
-
c = path[i];
|
|
152
|
-
result += p.distanceTo(c);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function gotoDefensePoint(entityManager, pathFinder, entity) {
|
|
159
|
-
|
|
160
|
-
gotoTag(entityManager, pathFinder, entity, "DefensePoint");
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export default MonsterAISystem;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* User: Alex Goldring
|
|
3
|
-
* Date: 17/6/2014
|
|
4
|
-
* Time: 21:27
|
|
5
|
-
*/
|
|
6
|
-
import { System } from '../System.js';
|
|
7
|
-
import Mortality from '../components/Mortality.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class MortalitySystem extends System {
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
|
|
14
|
-
this.dependencies = [Mortality];
|
|
15
|
-
//
|
|
16
|
-
this.__handlers = [];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
reset() {
|
|
20
|
-
this.__handlers = [];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
link(component, entity) {
|
|
24
|
-
const entityManager = this.entityManager;
|
|
25
|
-
const h = function () {
|
|
26
|
-
component.actions.forEach(function (action) {
|
|
27
|
-
action(entity, entityManager);
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
this.__handlers[entity] = h;
|
|
31
|
-
entityManager.addEntityEventListener(entity, "death", h);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
unlink(component, entity) {
|
|
35
|
-
const handlers = this.__handlers;
|
|
36
|
-
const handler = handlers[entity];
|
|
37
|
-
this.entityManager.removeEntityEventListener(entity, "death", handler);
|
|
38
|
-
delete handlers[entity];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
update(timeDelta) {
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
export default MortalitySystem;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 13/08/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import { Transform } from '../transform/Transform.js';
|
|
6
|
-
import RangedAttack from '../components/RangedAttack.js';
|
|
7
|
-
import PhysicalBody from '../components/PhysicalBody.js';
|
|
8
|
-
import Motion from '../components/Motion.js';
|
|
9
|
-
import Renderable from '../renderable/Renderable.js';
|
|
10
|
-
import { Matrix4 as ThreeMatrix4, Vector3 as ThreeVector3 } from 'three';
|
|
11
|
-
import { solveQuadratic } from "../../../core/math/solveQuadratic.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Return the firing solution for a projectile starting at 'src' with
|
|
15
|
-
* velocity 'v', to hit a target, 'dst'.
|
|
16
|
-
*
|
|
17
|
-
* @param Vector3 source position of shooter
|
|
18
|
-
* @param Vector3 target position of target
|
|
19
|
-
* @param Vector3 targetVelocity velocity of target object
|
|
20
|
-
* @param Vector3 sourceSpeed speed of projectile
|
|
21
|
-
* @return Vector3 Coordinate at which to fire (and where intercept occurs)
|
|
22
|
-
*/
|
|
23
|
-
const intercept = (function () {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const toTarget = new ThreeVector3();
|
|
27
|
-
const v0 = new ThreeVector3();
|
|
28
|
-
|
|
29
|
-
function intercept(source, target, targetVelocity, sourceSpeed) {
|
|
30
|
-
toTarget.copy(target).sub(source);
|
|
31
|
-
// Get quadratic equation components
|
|
32
|
-
const a = targetVelocity.dot(targetVelocity) - sourceSpeed * sourceSpeed;
|
|
33
|
-
const b = 2 * targetVelocity.dot(toTarget);
|
|
34
|
-
const c = toTarget.dot(toTarget);
|
|
35
|
-
|
|
36
|
-
// Solve quadratic
|
|
37
|
-
const ts = [];
|
|
38
|
-
const root_count = solveQuadratic(ts, 0, a, b, c); // See quad(), below
|
|
39
|
-
|
|
40
|
-
// Find smallest positive solution
|
|
41
|
-
let sol = null;
|
|
42
|
-
if (root_count > 0) {
|
|
43
|
-
const t0 = ts[0], t1 = ts[1];
|
|
44
|
-
let t = Math.min(t0, t1);
|
|
45
|
-
if (t < 0) t = Math.max(t0, t1);
|
|
46
|
-
if (t > 0) {
|
|
47
|
-
v0.copy(targetVelocity).multiplyScalar(t).add(target);
|
|
48
|
-
sol = v0;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return sol;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return intercept;
|
|
56
|
-
})();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
class RangedAttackSystem extends System {
|
|
60
|
-
constructor() {
|
|
61
|
-
super();
|
|
62
|
-
|
|
63
|
-
this.dependencies = [RangedAttack];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
add(component, entity) {
|
|
67
|
-
const em = this.entityManager;
|
|
68
|
-
em.addEntityEventListener(entity, "attack", function (target) {
|
|
69
|
-
//get transform
|
|
70
|
-
const targetTransform = em.getComponent(target, Transform);
|
|
71
|
-
if (targetTransform === null) {
|
|
72
|
-
//target no longer exists
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const sourceTransform = em.getComponent(entity, Transform);
|
|
76
|
-
//get projectile
|
|
77
|
-
const projectileBuilder = component.factory();
|
|
78
|
-
const projectileTransform = projectileBuilder.getComponent(Transform);
|
|
79
|
-
//get delta between source and target
|
|
80
|
-
const sourcePosition = sourceTransform.position.clone().add(component.projectileOffset);
|
|
81
|
-
let targetPosition = targetTransform.position.clone();
|
|
82
|
-
|
|
83
|
-
//check if target has a mesh
|
|
84
|
-
const renderable = em.getComponent(target, Renderable);
|
|
85
|
-
if (renderable !== null) {
|
|
86
|
-
targetPosition.add(renderable.center);
|
|
87
|
-
}
|
|
88
|
-
//check if target is moving
|
|
89
|
-
const motion = em.getComponent(target, Motion);
|
|
90
|
-
if (motion !== null) {
|
|
91
|
-
//correct targeting, with respect to motion
|
|
92
|
-
const interceptPosition = intercept(sourcePosition, targetPosition, motion.velocity, component.speed);
|
|
93
|
-
if (interceptPosition !== null) {
|
|
94
|
-
//if there is a valid solution, use it
|
|
95
|
-
targetPosition = interceptPosition;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const velocity = targetPosition.clone().sub(sourcePosition).normalize().multiplyScalar(component.speed);
|
|
99
|
-
//move projectile to source transform
|
|
100
|
-
projectileTransform.position.copy(sourcePosition);
|
|
101
|
-
//align rotation
|
|
102
|
-
const matrix4 = new ThreeMatrix4();
|
|
103
|
-
const up = new ThreeVector3(0, 1, 0);
|
|
104
|
-
matrix4.lookAt(sourcePosition, targetPosition, up);
|
|
105
|
-
projectileTransform.rotation.setFromRotationMatrix(matrix4);
|
|
106
|
-
|
|
107
|
-
//set physical body
|
|
108
|
-
const physicalBody = projectileBuilder.getComponent(PhysicalBody);
|
|
109
|
-
if (physicalBody !== null && physicalBody !== void 0) {
|
|
110
|
-
const body = physicalBody.body;
|
|
111
|
-
body.position.copy(sourcePosition);
|
|
112
|
-
body.linearVelocity.copy(velocity);
|
|
113
|
-
}
|
|
114
|
-
//motion of component
|
|
115
|
-
const pMotion = projectileBuilder.getComponent(Motion);
|
|
116
|
-
if (pMotion !== null) {
|
|
117
|
-
pMotion.velocity.copy(velocity);
|
|
118
|
-
}
|
|
119
|
-
//build
|
|
120
|
-
let projectileEntity = projectileBuilder.build(em);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
remove(component) {
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
update(timeDelta) {
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
export default RangedAttackSystem;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { System } from "../System.js";
|
|
2
|
-
import { SerializationMetadata } from "../components/SerializationMetadata.js";
|
|
3
|
-
|
|
4
|
-
export class SerializationMetadataSystem extends System {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
7
|
-
|
|
8
|
-
this.dependencies = [SerializationMetadata];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 30/06/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import TargetAI from '../components/TargetAI.js';
|
|
6
|
-
import Attacker from '../components/Attacker.js';
|
|
7
|
-
import { Transform } from '../transform/Transform.js';
|
|
8
|
-
import Tag from '../components/Tag.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TargetAISystem extends System {
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
this.dependencies = [TargetAI];
|
|
16
|
-
|
|
17
|
-
this.entityManager = null;
|
|
18
|
-
this.managedTargets = [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
reset() {
|
|
22
|
-
this.managedTargets = [];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
startup(entityManager, readyCallback, errorCallback) {
|
|
26
|
-
this.entityManager = entityManager;
|
|
27
|
-
const self = this;
|
|
28
|
-
entityManager.on.entityRemoved.add(function (entity) {
|
|
29
|
-
//check if it's a managed entity
|
|
30
|
-
const managedTarget = self.managedTargets[entity];
|
|
31
|
-
if (managedTarget !== void 0) {
|
|
32
|
-
managedTarget.target = null;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
readyCallback();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
remove(component, entity) {
|
|
39
|
-
if (component.target !== null) {
|
|
40
|
-
delete this.managedTargets[component.target];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
update(timeDelta) {
|
|
45
|
-
const self = this;
|
|
46
|
-
//go through target pickers
|
|
47
|
-
const em = this.entityManager;
|
|
48
|
-
em.traverseEntities([TargetAI, Attacker, Transform], function (picker, attacker, source, entity) {
|
|
49
|
-
const sourcePosition = source.global.position;
|
|
50
|
-
let targetEntity = attacker.target;
|
|
51
|
-
let targetPosition;
|
|
52
|
-
if (targetEntity !== null) {
|
|
53
|
-
const targetTransform = em.getComponent(targetEntity, Transform);
|
|
54
|
-
if (targetTransform === null) {
|
|
55
|
-
//target entity no longer exists
|
|
56
|
-
loseTarget(em, entity, attacker, self);
|
|
57
|
-
} else {
|
|
58
|
-
targetPosition = targetTransform.global.position;
|
|
59
|
-
const d = targetPosition.distanceTo(sourcePosition);
|
|
60
|
-
if (d > picker.range) {
|
|
61
|
-
//reset target if too far
|
|
62
|
-
loseTarget(em, entity, attacker, self);
|
|
63
|
-
} else {
|
|
64
|
-
//we already have a decent target
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (attacker.target === null) {
|
|
70
|
-
let range = picker.range;
|
|
71
|
-
const tags = picker.tags;
|
|
72
|
-
//find a new nearest target
|
|
73
|
-
em.traverseEntities([Tag, Transform], function (tag, transform, entity) {
|
|
74
|
-
if (!tag.containsOneOf(tags)) {
|
|
75
|
-
//not a tag we care about
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
//check distance
|
|
79
|
-
let d = transform.global.position.distanceTo(sourcePosition);
|
|
80
|
-
if (d < range) {
|
|
81
|
-
range = d; //reduce search radius
|
|
82
|
-
targetEntity = entity;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
if (targetEntity !== null) {
|
|
86
|
-
gainTarget(em, entity, attacker, targetEntity, self);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
function loseTarget(em, entity, attacker, ts) {
|
|
95
|
-
const oldTarget = attacker.target;
|
|
96
|
-
attacker.target = null;
|
|
97
|
-
em.sendEvent(entity, "target-lost", oldTarget);
|
|
98
|
-
delete ts.managedTargets[oldTarget];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function gainTarget(em, entity, attacker, target, ts) {
|
|
102
|
-
attacker.target = target;
|
|
103
|
-
em.sendEvent(entity, "target-gained", target);
|
|
104
|
-
ts.managedTargets[target] = attacker;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export default TargetAISystem;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 18/12/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import { Transform } from '../transform/Transform.js';
|
|
6
|
-
import Renderable from '../renderable/Renderable.js';
|
|
7
|
-
import GeometryBVH from '../components/GeometryBVH.js';
|
|
8
|
-
import ViewportMeshProjection from '../components/ViewportMeshProjection.js';
|
|
9
|
-
import { Vector3 as ThreeVector3 } from 'three';
|
|
10
|
-
|
|
11
|
-
class VMPS extends System {
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {GraphicsEngine} graphicsEngine
|
|
15
|
-
* @constructor
|
|
16
|
-
*/
|
|
17
|
-
constructor(graphicsEngine) {
|
|
18
|
-
super();
|
|
19
|
-
this.graphicEngine = graphicsEngine;
|
|
20
|
-
|
|
21
|
-
this.dependencies = [ViewportMeshProjection];
|
|
22
|
-
|
|
23
|
-
//small number
|
|
24
|
-
this.update = (function () {
|
|
25
|
-
const source = new ThreeVector3();
|
|
26
|
-
const target = new ThreeVector3();
|
|
27
|
-
|
|
28
|
-
function update(timeDelta) {
|
|
29
|
-
const ge = this.graphicEngine;
|
|
30
|
-
const em = this.entityManager;
|
|
31
|
-
em.traverseEntities([ViewportMeshProjection, Transform], function (p, t, e) {
|
|
32
|
-
const v2 = p.position;
|
|
33
|
-
const geometryBVH = em.getComponent(p.entity, GeometryBVH);
|
|
34
|
-
if (geometryBVH !== null) {
|
|
35
|
-
//bvh exists
|
|
36
|
-
ge.viewportProjectionRay(v2.x, v2.y, source, target);
|
|
37
|
-
geometryBVH.raycast(source, target, function (point) {
|
|
38
|
-
if (t.position.distanceToSquared(point) > EPSILON) {
|
|
39
|
-
t.position.copy(point);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
} else {
|
|
43
|
-
//no bvh, use mesh directly
|
|
44
|
-
const renderable = em.getComponent(p.entity, Renderable);
|
|
45
|
-
const hits = ge.intersectObjectUnderViewportPoint(v2.x, v2.y, renderable.mesh, true);
|
|
46
|
-
if (hits !== void 0 && hits.length > 0) {
|
|
47
|
-
//take first hit
|
|
48
|
-
const hit = hits[0];
|
|
49
|
-
const point = hit.point;
|
|
50
|
-
if (t.position.distanceToSquared(point) > EPSILON) {
|
|
51
|
-
t.position.copy(point);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return update;
|
|
61
|
-
})();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const EPSILON = 0.00001;
|
|
67
|
-
|
|
68
|
-
export default VMPS;
|