@woosh/meep-engine 2.50.3 → 2.52.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 +13 -18
- package/editor/ecs/component/editors/Sampler2DEditor.js +2 -2
- package/editor/process/SymbolicDisplayProcess.js +1 -1
- package/editor/process/symbolic/buildThreeJSHelperEntity.js +1 -1
- package/editor/process/symbolic/makeCameraSymbolicDisplay.js +1 -1
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
- package/editor/process/symbolic/makeLightSymbolicDisplay.js +1 -1
- package/editor/process/symbolic/makePathSymbolicDisplay.js +1 -1
- package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +1 -1
- package/editor/view/ecs/components/GridObstacleController.js +2 -2
- package/editor/view/ecs/components/TerrainController.js +2 -2
- package/package.json +1 -1
- package/samples/terrain/editor.js +2 -2
- package/src/core/NumberFormat.js +0 -71
- package/src/core/UUID.spec.js +8 -0
- package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.d.ts +4 -0
- package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +58 -55
- package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.spec.js +54 -0
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +3 -3
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.spec.js +60 -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/bvh2/visual/convert_bvh_to_dot_format_string.js +2 -2
- package/src/core/cache/Cache.js +3 -5
- package/src/core/cache/CacheElement.js +1 -0
- package/src/core/geom/2d/quad-tree/PointQuadTree.js +10 -0
- package/src/core/geom/3d/aabb/aabb3_array_combine.js +3 -3
- package/src/core/geom/3d/aabb/aabb3_from_threejs_geometry.js +41 -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/graph/{convertGraphToDotString.js → convert_graph_to_dot_string.js} +1 -1
- package/src/core/graph/convert_graph_to_dot_string.spec.js +28 -0
- package/src/core/math/noise/sdnoise.js +5 -7
- package/src/core/math/noise/sdnoise.spec.js +87 -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/{Platform.js → browserInfo.js} +1 -5
- package/src/engine/ecs/EntityBuilder.js +3 -1
- package/src/engine/ecs/EntityBuilder.spec.js +21 -0
- package/src/engine/ecs/fow/FogOfWar.js +48 -54
- package/src/engine/ecs/gui/GUIElement.js +1 -1
- package/src/engine/ecs/gui/position/ViewportPosition.js +3 -3
- package/src/engine/ecs/{systems → renderable}/RenderSystem.d.ts +1 -1
- package/src/engine/ecs/{systems → renderable}/RenderSystem.js +10 -38
- package/src/engine/ecs/renderable/Renderable.d.ts +25 -0
- package/src/engine/ecs/{components → renderable}/Renderable.js +18 -83
- package/src/engine/ecs/renderable/Renderable.spec.js +10 -0
- package/src/engine/ecs/speaker/VoiceSystem.js +15 -9
- package/src/engine/ecs/terrain/ecs/TerrainClassifier.js +1 -1
- package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +3 -3
- package/src/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +3 -3
- package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +2 -2
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +2 -2
- package/src/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +2 -2
- package/src/engine/ecs/transform/Transform.js +1 -0
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
- package/src/engine/graphics/copy_transform_to_threejs_object.js +12 -0
- package/src/engine/graphics/debug/VisualSymbolLine.js +1 -1
- 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 +3 -21
- 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/highlight/renderer/makeGaussianBlurShader.js +1 -4
- package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.d.ts +1 -1
- package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.js +2 -2
- package/src/engine/graphics/ecs/mesh/applyTransformToThreeObject.js +2 -5
- 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/ribbon/RibbonPathBuilder.js +2 -2
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +0 -4
- package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +0 -2
- package/src/engine/graphics/geometry/buffered/computeBufferAttributeHash.js +1 -1
- package/src/engine/graphics/geometry/optimization/merge/prototypeGeometryMerge.js +1 -1
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -3
- package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -5
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +2 -2
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +2 -6
- 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 +4 -4
- package/src/engine/graphics/shaders/SoftOutlineShader.js +2 -4
- package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
- package/src/engine/graphics/texture/atlas/CachingTextureAtlas.spec.js +24 -0
- package/src/engine/graphics/texture/atlas/TextureAtlas.spec.js +46 -0
- package/src/engine/graphics/texture/sampler/SampleTraverser.js +1 -1
- package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
- package/src/engine/graphics/texture/sampler/bicubic.spec.js +13 -0
- package/src/engine/graphics/texture/sampler/differenceSampler.js +1 -1
- package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.js +5 -1
- package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.spec.js +183 -0
- package/src/engine/graphics/texture/sampler/filter/filter_lanczos3.js +20 -0
- package/src/engine/graphics/texture/sampler/filter/mitchell.js +0 -21
- package/src/engine/graphics/texture/sampler/filter/mitchell_v1.js +21 -0
- package/src/engine/graphics/texture/sampler/filter/sampler2d_scale_down_generic.js +17 -16
- package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +11 -9
- package/src/engine/graphics/texture/sampler/{scaleSampler2D.js → resize/sampler2d_scale.js} +8 -8
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale.spec.js +73 -0
- package/src/engine/graphics/texture/sampler/{sampler2_d_scale_down_lanczos.js → resize/sampler2d_scale_down_lanczos.js} +3 -24
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_lanczos.spec.js +29 -0
- package/src/engine/graphics/texture/sampler/{sampler2d_scale_down_linear.js → resize/sampler2d_scale_down_linear.js} +5 -5
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_linear.spec.js +44 -0
- package/src/engine/graphics/texture/sampler/resize/{sampler2d_downsample_mipmap.js → sampler2d_scale_down_mipmap.js} +2 -2
- package/src/engine/graphics/texture/sampler/resize/{sampler2d_downsample_mipmap.spec.js → sampler2d_scale_down_mipmap.spec.js} +2 -2
- package/src/engine/graphics/texture/sampler/{genericResampleSampler2D.js → resize/sampler2d_scale_generic.js} +16 -12
- package/src/engine/graphics/texture/sampler/{upsampleSampler2D.js → resize/sampler2d_scale_up_linear.js} +5 -2
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_up_linear.spec.js +14 -0
- package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.js +4 -2
- package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.spec.js +15 -0
- package/src/engine/graphics/texture/sampler/util/drawSamplerHTML.js +2 -2
- package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +46 -0
- package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.spec.js +108 -0
- package/src/engine/graphics/trail/TemporalPath.js +83 -78
- package/src/engine/graphics/trail/TemporalPath.spec.js +5 -0
- package/src/engine/graphics/trail/x/RibbonX.spec.js +5 -0
- package/src/engine/grid/components/GridObstacle.js +45 -25
- package/src/engine/grid/components/GridObstacle.spec.js +130 -1
- package/src/engine/grid/components/GridPosition.js +5 -17
- package/src/engine/grid/components/GridPosition2Transform.js +1 -70
- package/src/engine/grid/components/GridPosition2TransformSerializationAdapter.js +70 -0
- package/src/engine/input/devices/InputDeviceSwitch.spec.js +5 -0
- package/src/engine/input/ecs/{InputBinding.js → components/InputBinding.js} +1 -1
- package/src/engine/input/ecs/components/InputController.js +2 -2
- package/src/engine/input/ecs/ism/InputBinding.js +2 -2
- package/src/engine/input/ecs/util/TerrainCameraTargetSampler.js +1 -1
- package/src/engine/input/ecs/util/TopDownCameraControllerHelper.js +1 -1
- package/src/engine/intelligence/behavior/behavior_to_dot.spec.js +25 -0
- package/src/engine/intelligence/behavior/util/DelayBehavior.js +6 -4
- package/src/engine/intelligence/blackboard/Blackboard.d.ts +2 -0
- package/src/engine/intelligence/blackboard/Blackboard.js +36 -2
- package/src/engine/intelligence/blackboard/Blackboard.spec.js +49 -0
- package/src/engine/intelligence/blackboard/BlackboardSerializationAdapter.spec.js +2 -0
- package/src/engine/navigation/grid/{AStar.js → find_path_on_grid_astar.js} +21 -18
- package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +7 -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/engine/sound/ecs/SoundListenerSystem.js +1 -1
- package/src/generation/markers/debug/visualizeMarkers.js +1 -1
- package/src/generation/theme/TerrainLayerDescription.js +1 -1
- package/src/view/common/LabelView.js +3 -3
- package/src/engine/MeepSettings.js +0 -9
- package/src/engine/User.js +0 -28
- package/src/engine/UserController.js +0 -273
- package/src/engine/ecs/components/AABB.js +0 -33
- package/src/engine/ecs/components/AABBCollider.js +0 -15
- 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/Renderable.d.ts +0 -14
- package/src/engine/ecs/components/TargetAI.js +0 -11
- package/src/engine/ecs/components/ViewportMeshProjection.js +0 -18
- package/src/engine/ecs/grid/Sampler2DDecoder.js +0 -57
- package/src/engine/ecs/grid/makeTerrainGeometry.js +0 -110
- package/src/engine/ecs/systems/AABBColliderSystem.js +0 -61
- package/src/engine/ecs/systems/AABBSystem.js +0 -89
- 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/sampler/sampler2d_make_array_filler_function.js +0 -65
- package/src/engine/graphics/texture/sampler/sampler2d_scale_down_linear.spec.js +0 -17
- package/src/engine/graphics/trail/x/simulator/RibbonState.js +0 -10
- package/src/engine/grid/Grid.js +0 -131
- 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/grid/GridField.js +0 -328
- /package/src/{engine → core/primitives/array}/computeStridedIntegerArrayHash.js +0 -0
- /package/src/engine/ecs/{components → renderable}/RenderableFlags.js +0 -0
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import Vector2 from '../../../core/geom/Vector2.js';
|
|
2
|
-
import { clamp } from "../../../core/math/clamp.js";
|
|
3
|
-
import BinaryHeap from '../../../core/collection/heap/BinaryHeap.js';
|
|
4
|
-
import { assert } from "../../../core/assert.js";
|
|
5
|
-
import { gridAStarSearch } from "./AStar.js";
|
|
6
|
-
|
|
7
|
-
const blockValue = 255;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A kind of 2D data texture
|
|
11
|
-
* @deprecated prefer using {@link Sampler2D} instead, as it's more versatile and has wider feature set
|
|
12
|
-
*
|
|
13
|
-
* @param {Number} width
|
|
14
|
-
* @param {Number} height
|
|
15
|
-
* @constructor
|
|
16
|
-
*
|
|
17
|
-
* @property {Number} width
|
|
18
|
-
* @property {Number} height
|
|
19
|
-
* @property {Uint8Array} data
|
|
20
|
-
*/
|
|
21
|
-
function GridField(width, height) {
|
|
22
|
-
this.width = width;
|
|
23
|
-
this.height = height;
|
|
24
|
-
this.data = null;
|
|
25
|
-
|
|
26
|
-
if (height !== 0 && height !== 0) {
|
|
27
|
-
const byteSize = height * width;
|
|
28
|
-
this.data = new Uint8Array(byteSize);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const self = this;
|
|
32
|
-
|
|
33
|
-
Object.defineProperties(this, {
|
|
34
|
-
raw: {
|
|
35
|
-
set: function (val) {
|
|
36
|
-
console.warn("Deprecated, use .data accessor instead");
|
|
37
|
-
self.data = val;
|
|
38
|
-
},
|
|
39
|
-
get: function () {
|
|
40
|
-
console.warn("Deprecated, use .data accessor instead");
|
|
41
|
-
return self.data;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param {Number} value
|
|
50
|
-
*/
|
|
51
|
-
GridField.prototype.fill = function (value) {
|
|
52
|
-
this.data.fill(value);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
57
|
-
* @param {Number} x0
|
|
58
|
-
* @param {Number} y0
|
|
59
|
-
* @param {Number} x1
|
|
60
|
-
* @param {Number} y1
|
|
61
|
-
* @param {function(x:Number,y:Number,value:Number)} callback
|
|
62
|
-
*/
|
|
63
|
-
GridField.prototype.rectTraverse = function (x0, y0, x1, y1, callback) {
|
|
64
|
-
const width = this.width;
|
|
65
|
-
const height = this.height;
|
|
66
|
-
|
|
67
|
-
let x, y;
|
|
68
|
-
|
|
69
|
-
x0 = clamp(x0, 0, width - 1);
|
|
70
|
-
y0 = clamp(y0, 0, height - 1);
|
|
71
|
-
x1 = clamp(x1, x0, width - 1);
|
|
72
|
-
y1 = clamp(y1, y0, height - 1);
|
|
73
|
-
|
|
74
|
-
for (x = x0; x <= x1; x++) {
|
|
75
|
-
for (y = y0; y <= y1; y++) {
|
|
76
|
-
const index = this.point2index(x, y);
|
|
77
|
-
const value = this.data[index];
|
|
78
|
-
callback(x, y, value);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
*
|
|
85
|
-
* @param {Number} x0
|
|
86
|
-
* @param {Number} y0
|
|
87
|
-
* @param {Number} x1
|
|
88
|
-
* @param {Number} y1
|
|
89
|
-
* @param {Number} value
|
|
90
|
-
*/
|
|
91
|
-
GridField.prototype.rectSet = function (x0, y0, x1, y1, value) {
|
|
92
|
-
let x, y;
|
|
93
|
-
for (x = x0; x <= x1; x++) {
|
|
94
|
-
for (y = y0; y <= y1; y++) {
|
|
95
|
-
this.pointSet(x, y, value);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {Vector2} pos
|
|
103
|
-
*/
|
|
104
|
-
GridField.prototype.snapToNearestFreeCell = function (pos) {
|
|
105
|
-
const self = this;
|
|
106
|
-
const p = new Vector2().copy(pos).floor();
|
|
107
|
-
const target = p.clone();
|
|
108
|
-
const closed = [];
|
|
109
|
-
|
|
110
|
-
function score(index) {
|
|
111
|
-
self.index2point(index, p);
|
|
112
|
-
return p.distanceSqrTo(target);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const open = new BinaryHeap(score);
|
|
116
|
-
let current = this.point2index(p.x, p.y);
|
|
117
|
-
open.push(current);
|
|
118
|
-
const neighbors = [];
|
|
119
|
-
while (open.size() > 0) {
|
|
120
|
-
current = open.pop();
|
|
121
|
-
closed[current] = true;
|
|
122
|
-
if (this.data[current] !== blockValue) {
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
//add neighbours
|
|
126
|
-
neighbors.length = 0; //reset
|
|
127
|
-
this.calcNeighbors(current, neighbors);
|
|
128
|
-
const numNeighbors = neighbors.length;
|
|
129
|
-
for (let i = 0; i < numNeighbors; i++) {
|
|
130
|
-
const n = neighbors[i];
|
|
131
|
-
if (closed[n] !== void 0) {
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
open.push(n);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
this.index2point(current, pos);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
*
|
|
142
|
-
* @param {Number} index
|
|
143
|
-
* @param {function(index:Number, x:Number, y:Number)} visitor
|
|
144
|
-
*/
|
|
145
|
-
GridField.prototype.traverseNeighbors = function traverseNeighbors(index, visitor) {
|
|
146
|
-
const width = this.width;
|
|
147
|
-
const height = this.height;
|
|
148
|
-
|
|
149
|
-
const x = index % width;
|
|
150
|
-
const y = (index / width) | 0;
|
|
151
|
-
|
|
152
|
-
if (x > 0) {
|
|
153
|
-
visitor(index - 1, x, y);
|
|
154
|
-
}
|
|
155
|
-
if (x < width - 1) {
|
|
156
|
-
visitor(index + 1, x, y);
|
|
157
|
-
}
|
|
158
|
-
if (y > 0) {
|
|
159
|
-
visitor(index - width, x, y);
|
|
160
|
-
}
|
|
161
|
-
if (y < height - 1) {
|
|
162
|
-
visitor(index + width, x, y);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
*
|
|
168
|
-
* @param {Number} x
|
|
169
|
-
* @param {Number} y
|
|
170
|
-
* @returns {Number}
|
|
171
|
-
*/
|
|
172
|
-
GridField.prototype.read = function (x, y) {
|
|
173
|
-
const index = this.point2index(x, y);
|
|
174
|
-
return this.data[index];
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
*
|
|
179
|
-
* @param {Number} x
|
|
180
|
-
* @param {Number} y
|
|
181
|
-
* @param {Number} value
|
|
182
|
-
*/
|
|
183
|
-
GridField.prototype.pointAdd = function (x, y, value) {
|
|
184
|
-
const index = this.point2index(x, y);
|
|
185
|
-
this.data[index] += value;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
*
|
|
190
|
-
* @param {Number} x
|
|
191
|
-
* @param {Number} y
|
|
192
|
-
* @param {Number} value
|
|
193
|
-
*/
|
|
194
|
-
GridField.prototype.pointSet = function (x, y, value) {
|
|
195
|
-
const index = this.point2index(x, y);
|
|
196
|
-
this.data[index] = value;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
*
|
|
202
|
-
* @param {Number} x
|
|
203
|
-
* @param {Number} y
|
|
204
|
-
* @returns {Number}
|
|
205
|
-
*/
|
|
206
|
-
GridField.prototype.point2index = function (x, y) {
|
|
207
|
-
return x + y * this.width;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Paints with additive brush
|
|
212
|
-
* @param {Array.<Number>} bendPointIndexList
|
|
213
|
-
* @param {Number} value
|
|
214
|
-
*/
|
|
215
|
-
GridField.prototype.pathAdd = function pathAdd(bendPointIndexList, value) {
|
|
216
|
-
const indices = bendPointIndexList;
|
|
217
|
-
const length = indices.length;
|
|
218
|
-
|
|
219
|
-
//
|
|
220
|
-
if (length > 0) {
|
|
221
|
-
const pCurrent = new Vector2();
|
|
222
|
-
const pTarget = new Vector2();
|
|
223
|
-
let dx, dy;
|
|
224
|
-
this.index2point(indices[0], pCurrent);
|
|
225
|
-
this.pointAdd(pCurrent.x, pCurrent.y, value);
|
|
226
|
-
for (let i = 1; i < length; i++) {
|
|
227
|
-
this.index2point(indices[i], pTarget);
|
|
228
|
-
dx = pTarget.x - pCurrent.x;
|
|
229
|
-
dy = pTarget.y - pCurrent.y;
|
|
230
|
-
if (dx !== 0) {
|
|
231
|
-
//drop values to multiple of 1
|
|
232
|
-
dx /= Math.abs(dx);
|
|
233
|
-
while (pCurrent.x !== pTarget.x) {
|
|
234
|
-
pCurrent.x += dx;
|
|
235
|
-
this.pointAdd(pCurrent.x, pCurrent.y, value);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (dy !== 0) {
|
|
239
|
-
//drop values to multiple of 1
|
|
240
|
-
dy /= Math.abs(dy);
|
|
241
|
-
while (pCurrent.y !== pTarget.y) {
|
|
242
|
-
pCurrent.y += dy;
|
|
243
|
-
this.pointAdd(pCurrent.x, pCurrent.y, value);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
*
|
|
252
|
-
* @param {Number} index
|
|
253
|
-
* @param {Vector2} point
|
|
254
|
-
*/
|
|
255
|
-
GridField.prototype.index2point = function (index, point) {
|
|
256
|
-
const width = this.width;
|
|
257
|
-
|
|
258
|
-
point.set(index % width, Math.floor(index / width));
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
*
|
|
263
|
-
* @param {Number} index
|
|
264
|
-
* @param {Array.<Number>} result
|
|
265
|
-
*/
|
|
266
|
-
GridField.prototype.calcNeighbors = function (index, result) {
|
|
267
|
-
const width = this.width;
|
|
268
|
-
const height = this.height;
|
|
269
|
-
|
|
270
|
-
const x = index % width;
|
|
271
|
-
const y = (index / width) | 0;
|
|
272
|
-
if (x > 0) {
|
|
273
|
-
result.push(index - 1);
|
|
274
|
-
}
|
|
275
|
-
if (x < width - 1) {
|
|
276
|
-
result.push(index + 1);
|
|
277
|
-
}
|
|
278
|
-
if (y > 0) {
|
|
279
|
-
result.push(index - width);
|
|
280
|
-
}
|
|
281
|
-
if (y < height - 1) {
|
|
282
|
-
result.push(index + width);
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
*
|
|
289
|
-
* @param {Number} index1
|
|
290
|
-
* @param {Number} index2
|
|
291
|
-
* @returns {Number}
|
|
292
|
-
*/
|
|
293
|
-
GridField.prototype.manhattanDistanceByIndices = function (index1, index2) {
|
|
294
|
-
const width = this.width;
|
|
295
|
-
|
|
296
|
-
const x1 = index1 % width;
|
|
297
|
-
const y1 = Math.floor(index1 / width);
|
|
298
|
-
//
|
|
299
|
-
const x2 = index2 % width;
|
|
300
|
-
const y2 = Math.floor(index2 / width);
|
|
301
|
-
//
|
|
302
|
-
const dx = Math.abs(x1 - x2);
|
|
303
|
-
const dy = Math.abs(y1 - y2);
|
|
304
|
-
return dx + dy;
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
*
|
|
309
|
-
* @param {Vector2} start
|
|
310
|
-
* @param {Vector2} goal
|
|
311
|
-
* @param {Number} crossingPenalty
|
|
312
|
-
* @param {Number} bendPenalty
|
|
313
|
-
* @returns {Number[]} path of indices
|
|
314
|
-
*/
|
|
315
|
-
GridField.prototype.findPath = function (start, goal, crossingPenalty, bendPenalty) {
|
|
316
|
-
assert.notEqual(start, null, 'start is null');
|
|
317
|
-
assert.notEqual(start, undefined, 'start is undefined');
|
|
318
|
-
|
|
319
|
-
assert.notEqual(goal, null, 'goal is null');
|
|
320
|
-
assert.notEqual(goal, undefined, 'goal is undefined');
|
|
321
|
-
|
|
322
|
-
const startIndex = this.point2index(start.x, start.y);
|
|
323
|
-
const goalIndex = this.point2index(goal.x, goal.y);
|
|
324
|
-
|
|
325
|
-
return gridAStarSearch(this.field, this.width, this.height, startIndex, goalIndex, crossingPenalty, bendPenalty, 255);
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
export default GridField;
|
|
File without changes
|
|
File without changes
|