@woosh/meep-engine 2.75.7 → 2.75.9
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/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +1052 -1234
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +1052 -1234
- package/editor/actions/concrete/ModifyPatchSampler2DAction.js +6 -3
- package/editor/actions/concrete/PatchTerrainTextureAction.js +6 -3
- package/editor/ecs/component/createObjectEditor.js +2 -2
- package/editor/process/EditorProcess.js +12 -16
- package/editor/process/ProcessEngine.js +9 -10
- package/package.json +1 -1
- package/src/core/binary/dec2hex.js +1 -1
- package/src/{engine/ecs/ik/IKMath.js → core/geom/vec3/v3_computeOffsetVector.js} +1 -1
- package/src/core/math/newton_solver_1d.js +13 -4
- package/src/core/math/solveQuadratic.js +5 -3
- package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
- package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
- package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
- package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
- package/src/core/math/spline/interpolate_bicubic.js +12 -0
- package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
- package/src/core/model/object/ImmutableObjectPool.js +14 -5
- package/src/engine/control/ControlContext.js +25 -27
- package/src/engine/ecs/EntityManager.js +12 -9
- package/src/engine/ecs/EntityObserver.js +26 -22
- package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
- package/src/engine/ecs/components/Motion.js +5 -7
- package/src/engine/ecs/components/SerializationMetadata.js +5 -3
- package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
- package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
- package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
- package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
- package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
- package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
- package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
- package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
- package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
- package/src/engine/ecs/parent/EntityNode.js +39 -37
- package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
- package/src/engine/ecs/storage/BinaryBufferDeSerializer.js +7 -9
- package/src/engine/ecs/storage/BinaryBufferSerializer.js +15 -16
- package/src/engine/ecs/storage/binary/BinaryClassUpgrader.js +10 -59
- package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +14 -15
- package/src/engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js +3 -3
- package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +60 -62
- package/src/engine/ecs/storage/binary/executeBinaryClassUpgraderChain.js +46 -0
- package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter.js +2 -2
- package/src/engine/ecs/system/SystemEntityContext.js +25 -23
- package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
- package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
- package/src/engine/ecs/terrain/ecs/layers/TerrainLayer.js +37 -31
- package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +8 -7
- package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
- package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
- package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
- package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
- package/src/engine/graphics/render/RendererPool.js +36 -40
- package/src/engine/graphics/render/buffer/FrameBuffer.js +25 -24
- package/src/engine/graphics/render/buffer/RenderGraph.js +21 -21
- 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/frame_graph/IRenderContext.js +31 -1
- package/src/engine/graphics/render/frame_graph/RenderGraph.js +5 -5
- package/src/engine/graphics/render/frame_graph/RenderTarget.js +9 -0
- package/src/engine/graphics/render/frame_graph/RenderTextureManager.js +57 -0
- package/src/engine/graphics/render/frame_graph/ResourceEntry.js +7 -5
- package/src/engine/graphics/render/frame_graph/TextureDescriptor.js +48 -33
- package/src/engine/graphics/render/frame_graph/TextureInitialState.js +14 -0
- package/src/engine/graphics/render/frame_graph/sample/deferred/CopyPass.js +20 -0
- package/src/engine/graphics/render/frame_graph/sample/deferred/LightingPass.js +4 -0
- package/src/engine/graphics/render/frame_graph/sample/deferred/run.js +34 -6
- package/src/engine/graphics/render/frame_graph/webgl/WebGLRenderContext.js +34 -0
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +3 -6
- package/src/engine/graphics/sh3/gi/prototypeSHGI.js +92 -0
- package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
- package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
- package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
- package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
- package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
- package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
- package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
- package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
- package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMemoryMapping.js → VirtualTextureMemoryMapping.js} +2 -26
- package/src/engine/graphics/texture/virtual/{v2/VirtualTexturePage.js → VirtualTexturePage.js} +10 -10
- package/src/engine/graphics/texture/virtual/{v2/VirtualTextureTileLoader.js → VirtualTextureTileLoader.js} +7 -7
- package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsage.js → VirtualTextureUsage.js} +1 -1
- package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageUpdater.js → VirtualTextureUsageUpdater.js} +7 -7
- package/src/engine/graphics/texture/virtual/{v2/debug → debug}/ResidencyDebugView.js +4 -4
- package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsageDebugView.js +2 -2
- package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsagePyramidDebugView.js +4 -4
- package/src/engine/graphics/texture/virtual/{v2/prototype.js → prototype.js} +7 -7
- package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_finger_print.js +1 -1
- package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_tile_address.js +2 -2
- package/src/engine/graphics/texture/virtual/{v2/tile → tile}/tile_address_to_finger_print.js +1 -1
- package/src/engine/navigation/ecs/components/Path.js +10 -9
- package/src/engine/physics/computeInterceptPoint.js +44 -0
- package/src/engine/plugin/EnginePlugin.js +1 -2
- package/src/engine/ecs/components/AlignToVelocity.js +0 -9
- package/src/engine/ecs/components/CharacterController.js +0 -31
- package/src/engine/ecs/components/PhysicalBody.js +0 -51
- package/src/engine/ecs/components/Steering.js +0 -111
- package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
- package/src/engine/ecs/storage/json/Blueprint.js +0 -129
- package/src/engine/ecs/storage/json/EntityFactory.js +0 -207
- package/src/engine/ecs/storage/json/JSONDeSerializer.js +0 -148
- package/src/engine/ecs/storage/json/JSONSerializer.js +0 -132
- package/src/engine/ecs/storage/json/README.md +0 -5
- package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
- package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
- package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
- package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
- package/src/engine/ecs/systems/SteeringSystem.js +0 -171
- package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
- package/src/engine/ecs/systems/TagSystem.js +0 -31
- package/src/engine/graphics/render/webgpu/sample/MeshInstance.js +0 -108
- package/src/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +0 -71
- package/src/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +0 -39
- package/src/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +0 -21
- package/src/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +0 -41
- package/src/engine/graphics/render/webgpu/sample/main.js +0 -605
- package/src/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +0 -9
- package/src/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +0 -30
- package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
- package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
- package/src/engine/graphics/texture/virtual/TileOperation.js +0 -13
- package/src/engine/graphics/texture/virtual/TileTree.js +0 -150
- package/src/engine/graphics/texture/virtual/TileTree.spec.js +0 -58
- package/src/engine/graphics/texture/virtual/TileUsage.js +0 -137
- package/src/engine/graphics/texture/virtual/VirtualTexture.js +0 -238
- package/src/engine/graphics/texture/virtual/VirtualTexture.spec.js +0 -39
- package/src/engine/graphics/texture/virtual/page/TilePage.js +0 -148
- package/src/engine/graphics/texture/virtual/page/TilePageSlot.js +0 -36
- package/src/engine/graphics/texture/virtual/tile/Tile.js +0 -44
- package/src/engine/graphics/texture/virtual/tile/Tile.spec.js +0 -11
- package/src/engine/graphics/texture/virtual/tile/TileAddress.js +0 -63
- package/src/engine/graphics/texture/virtual/tile/TileAddress.spec.js +0 -30
- package/src/engine/graphics/texture/virtual/tile/TileLoader.js +0 -178
- package/src/engine/graphics/texture/virtual/tile/TileRequest.js +0 -40
- package/src/engine/graphics/texture/virtual/tile/TileStatus.js +0 -10
- package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
- /package/src/engine/graphics/texture/virtual/{v2/NOTES.md → NOTES.md} +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMaterial.js → VirtualTextureMaterial.js} +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageShader.js → VirtualTextureUsageShader.js} +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/VirtualTextureTile.js +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/decompose_finger_print.js +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/finger_print_to_tile_address.js +0 -0
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { BinaryClassSerializationAdapter } from "../storage/binary/BinaryClassSerializationAdapter.js";
|
|
2
|
-
import Steering from "./Steering.js";
|
|
3
|
-
|
|
4
|
-
export class SteeringSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
5
|
-
|
|
6
|
-
klass = Steering;
|
|
7
|
-
version = 0;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param {BinaryBuffer} buffer
|
|
12
|
-
* @param {Steering} value
|
|
13
|
-
*/
|
|
14
|
-
serialize(buffer, value) {
|
|
15
|
-
buffer.writeFloat32(value.maxSpeed);
|
|
16
|
-
buffer.writeFloat32(value.rotationSpeed);
|
|
17
|
-
|
|
18
|
-
value.destination.toBinaryBufferFloat32(buffer);
|
|
19
|
-
value.targetMargin.toBinaryBufferFloat32_EqualityEncoded(buffer);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {BinaryBuffer} buffer
|
|
25
|
-
* @param {Steering} value
|
|
26
|
-
*/
|
|
27
|
-
deserialize(buffer, value) {
|
|
28
|
-
value.maxSpeed = buffer.readFloat32();
|
|
29
|
-
value.rotationSpeed = buffer.readFloat32();
|
|
30
|
-
|
|
31
|
-
value.destination.fromBinaryBufferFloat32(buffer);
|
|
32
|
-
value.targetMargin.fromBinaryBufferFloat32_EqualityEncoded(buffer);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 30/04/2014.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import EntityFactory from './EntityFactory.js';
|
|
7
|
-
import { FunctionCompiler } from "../../../../core/function/FunctionCompiler.js";
|
|
8
|
-
|
|
9
|
-
function Blueprint() {
|
|
10
|
-
this.element = [];
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @type {EntityFactory|null}
|
|
14
|
-
*/
|
|
15
|
-
this.factory = null;
|
|
16
|
-
this.buildCallback = null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param settings
|
|
22
|
-
* @param {function(problem:string)} problemCallback
|
|
23
|
-
*/
|
|
24
|
-
Blueprint.prototype.verifyBuildSettings = function (settings, problemCallback) {
|
|
25
|
-
const factoryComponents = this.factory.components;
|
|
26
|
-
|
|
27
|
-
for (const typeName of Object.keys(settings)) {
|
|
28
|
-
const matchFound = factoryComponents.find(function (spec) {
|
|
29
|
-
return spec.componentClass.typeName === typeName;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
if (!matchFound) {
|
|
33
|
-
problemCallback(`factory has no component '${typeName}', found in the settings`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
Blueprint.prototype.compile = function () {
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @param {Object} settings
|
|
45
|
-
* @returns {Number}
|
|
46
|
-
*/
|
|
47
|
-
Blueprint.prototype.buildEntity = function (settings) {
|
|
48
|
-
return this.factory.create(this.buildCallback(settings, this.systemMap));
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
*
|
|
53
|
-
* @param {EntityManager} entityManager
|
|
54
|
-
* @returns {object}
|
|
55
|
-
*/
|
|
56
|
-
function buildSystemMap(entityManager) {
|
|
57
|
-
const result = {};
|
|
58
|
-
|
|
59
|
-
const systems = entityManager.systems;
|
|
60
|
-
const systemCount = systems.length;
|
|
61
|
-
|
|
62
|
-
for (let i = 0; i < systemCount; i++) {
|
|
63
|
-
const system = systems[i];
|
|
64
|
-
|
|
65
|
-
const componentClass = system.componentClass;
|
|
66
|
-
|
|
67
|
-
if (componentClass === null) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const typeName = componentClass.typeName;
|
|
72
|
-
|
|
73
|
-
if (typeName === undefined) {
|
|
74
|
-
console.error("Component class has no type name: ", componentClass);
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (result.hasOwnProperty(typeName)) {
|
|
79
|
-
console.error("Duplicate component class name: ", componentClass, result[typeName]);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
result[typeName] = system;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
*
|
|
91
|
-
* @param {object} json
|
|
92
|
-
* @param {EntityManager} entityManager
|
|
93
|
-
*/
|
|
94
|
-
Blueprint.prototype.fromJSON = function (json, entityManager) {
|
|
95
|
-
this.factory = new EntityFactory();
|
|
96
|
-
|
|
97
|
-
const dataset = entityManager.dataset;
|
|
98
|
-
|
|
99
|
-
this.factory.fromJSON(json.components, dataset);
|
|
100
|
-
this.factory.compile(dataset);
|
|
101
|
-
|
|
102
|
-
this.systemMap = buildSystemMap(entityManager);
|
|
103
|
-
|
|
104
|
-
//get setup function
|
|
105
|
-
const setupFunctionBody = json.setup !== undefined ? json.setup : "";
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//make build callback
|
|
109
|
-
const buildCallbackParameters = this.factory.components.map(function (spec) {
|
|
110
|
-
return spec.componentClass.typeName;
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
let buildCallbackBody = this.factory.components.map(function (spec) {
|
|
114
|
-
const name = spec.componentClass.typeName;
|
|
115
|
-
const settingsVar = "$settings." + name;
|
|
116
|
-
const systemVar = "$systems." + name;
|
|
117
|
-
|
|
118
|
-
return "if(" + settingsVar + " !== undefined){ " + name + ".fromJSON(" + settingsVar + ", " + systemVar + ");}";
|
|
119
|
-
}).concat(setupFunctionBody).join('\n');
|
|
120
|
-
|
|
121
|
-
buildCallbackBody = "return function(" + buildCallbackParameters.join(', ') + "){\n" + buildCallbackBody + "\n};";
|
|
122
|
-
|
|
123
|
-
this.buildCallback = FunctionCompiler.INSTANCE.compile({
|
|
124
|
-
args: ['$settings', '$systems'],
|
|
125
|
-
code: buildCallbackBody
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export default Blueprint;
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 25/08/2015.
|
|
3
|
-
*/
|
|
4
|
-
import { FunctionCompiler } from "../../../../core/function/FunctionCompiler.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function ComponentSpec(options) {
|
|
8
|
-
this.componentClass = options.componentClass;
|
|
9
|
-
this.defaults = options.defaults;
|
|
10
|
-
this.systemId = null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function EntityFactory() {
|
|
14
|
-
this.isCompiled = false;
|
|
15
|
-
this.components = [];
|
|
16
|
-
this.dataset = null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @param {EntityComponentDataset} dataset
|
|
21
|
-
*/
|
|
22
|
-
EntityFactory.prototype.compile = function (dataset) {
|
|
23
|
-
this.dataset = dataset;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Signature of generated function:
|
|
27
|
-
* dataset, callback, ComponentClass0, ComponentClass1, ..., ComponentClassN, options0, options1, ... , optionsN
|
|
28
|
-
* where options0 to optionsN is a set of options for a specific component identified by N in the same order as they appear in EntityFactory.components
|
|
29
|
-
*/
|
|
30
|
-
const generatedFunctionParameterNames = ["dataset", "callback"]
|
|
31
|
-
.concat(this.components.map(function (spec, index) {
|
|
32
|
-
return varNameComponentClass(index);
|
|
33
|
-
}))
|
|
34
|
-
.concat(this.components.map(function (spec, index) {
|
|
35
|
-
return varNameComponentOptions(index);
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
//set systemIDs
|
|
39
|
-
this.components.forEach(function (spec) {
|
|
40
|
-
spec.systemId = dataset.computeComponentTypeIndex(spec.componentClass);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
function varNameComponentInstance(index) {
|
|
44
|
-
return "componentInstance" + index;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function varNameComponentClass(index) {
|
|
48
|
-
return "ComponentClass" + index;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function varNameComponentOptions(index) {
|
|
52
|
-
return "options" + index;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const strShallowCopyWithDefaults = [
|
|
56
|
-
"function shallowCopyWithDefaults(options, defaults){",
|
|
57
|
-
" var result = {};",
|
|
58
|
-
" var propertyName;",
|
|
59
|
-
" for(propertyName in options){",
|
|
60
|
-
" if(options.hasOwnProperty(propertyName)){",
|
|
61
|
-
" result[propertyName] = options[propertyName];",
|
|
62
|
-
" }",
|
|
63
|
-
" }",
|
|
64
|
-
" for(propertyName in defaults){",
|
|
65
|
-
" if(defaults.hasOwnProperty(propertyName) && !result.hasOwnProperty(propertyName)){",
|
|
66
|
-
" result[propertyName] = defaults[propertyName];",
|
|
67
|
-
" }",
|
|
68
|
-
" }",
|
|
69
|
-
"}"
|
|
70
|
-
].join("\n");
|
|
71
|
-
|
|
72
|
-
//create a function that would generate and populate entity
|
|
73
|
-
const snipComponentInstancing = this.components.map(function (spec, index) {
|
|
74
|
-
return "var " + varNameComponentInstance(index) + " = new " + varNameComponentClass(index) + "(" + varNameComponentOptions(index) + ");"
|
|
75
|
-
}).join("\n");
|
|
76
|
-
|
|
77
|
-
//TODO see if we might get some performance boost if we sort instantiation order based on what we know about systems
|
|
78
|
-
const snipComponentPopulation = this.components.map(function (spec, index) {
|
|
79
|
-
return "dataset.addComponentToEntityByIndex(entity, " + spec.systemId + ", " + varNameComponentInstance(index) + ");";
|
|
80
|
-
}).join("\n");
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
const snipComponentInvokeCallback = "if(callback !== void 0){ callback(" + this.components.map(function (spec, index) {
|
|
84
|
-
return varNameComponentInstance(index);
|
|
85
|
-
}).join(",") + ");}";
|
|
86
|
-
|
|
87
|
-
const snipFunctionBody = [
|
|
88
|
-
//header
|
|
89
|
-
strShallowCopyWithDefaults,
|
|
90
|
-
//instantiate all components with correct options
|
|
91
|
-
snipComponentInstancing,
|
|
92
|
-
snipComponentInvokeCallback,
|
|
93
|
-
//create entity
|
|
94
|
-
"var entity = dataset.createEntity();",
|
|
95
|
-
//populate with components
|
|
96
|
-
snipComponentPopulation,
|
|
97
|
-
//finaly return entity
|
|
98
|
-
"return entity;"
|
|
99
|
-
].join("\n");
|
|
100
|
-
|
|
101
|
-
this.compiledFunction = FunctionCompiler.INSTANCE.compile({
|
|
102
|
-
args: generatedFunctionParameterNames,
|
|
103
|
-
code: snipFunctionBody
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
//pre-compute first part of parameters
|
|
107
|
-
this.compiledFunctionParams = [dataset, null]
|
|
108
|
-
.concat(this.components.map(function (spec) {
|
|
109
|
-
return spec.componentClass;
|
|
110
|
-
}))
|
|
111
|
-
.concat(this.components.map(function (spec) {
|
|
112
|
-
return spec.defaults;
|
|
113
|
-
}));
|
|
114
|
-
|
|
115
|
-
this.isCompiled = true;
|
|
116
|
-
|
|
117
|
-
return this;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
EntityFactory.prototype.hasComponent = function (componentClass) {
|
|
121
|
-
return this.getComponentSpec(componentClass) !== void 0;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
EntityFactory.prototype.getComponentSpec = function (componentClass) {
|
|
125
|
-
let i = 0;
|
|
126
|
-
const l = this.components.length;
|
|
127
|
-
for (; i < l; i++) {
|
|
128
|
-
const spec = this.components[i];
|
|
129
|
-
if (spec.componentClass === componentClass) {
|
|
130
|
-
return spec;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
EntityFactory.prototype.setDefaults = function (componentClass, defaults) {
|
|
136
|
-
const spec = this.getComponentSpec(componentClass);
|
|
137
|
-
if (spec !== void 0) {
|
|
138
|
-
spec.defaults = defaults;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
*
|
|
144
|
-
* @param {function} componentClass
|
|
145
|
-
* @param {*} [defaults]
|
|
146
|
-
* @returns {EntityFactory}
|
|
147
|
-
*/
|
|
148
|
-
EntityFactory.prototype.add = function (componentClass, defaults) {
|
|
149
|
-
let spec = this.getComponentSpec(componentClass);
|
|
150
|
-
if (spec === void 0) {
|
|
151
|
-
//component is not registered yet
|
|
152
|
-
spec = new ComponentSpec({
|
|
153
|
-
componentClass: componentClass,
|
|
154
|
-
defaults: defaults
|
|
155
|
-
});
|
|
156
|
-
this.components.push(spec);
|
|
157
|
-
} else {
|
|
158
|
-
//just set the defaults
|
|
159
|
-
spec.defaults = defaults;
|
|
160
|
-
}
|
|
161
|
-
return this;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
*
|
|
166
|
-
* @param {Object} json
|
|
167
|
-
* @param {EntityComponentDataset} dataset
|
|
168
|
-
*/
|
|
169
|
-
EntityFactory.prototype.fromJSON = function (json, dataset) {
|
|
170
|
-
let i = 0;
|
|
171
|
-
const l = json.length;
|
|
172
|
-
for (; i < l; i++) {
|
|
173
|
-
const element = json[i];
|
|
174
|
-
const typeName = element.type;
|
|
175
|
-
const componentClass = dataset.getComponentClassByName(typeName);
|
|
176
|
-
|
|
177
|
-
if (componentClass === null) {
|
|
178
|
-
throw new Error('Failed to find class with name "' + typeName + '"');
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const parameters = element.parameters;
|
|
182
|
-
|
|
183
|
-
this.add(componentClass, parameters);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
EntityFactory.prototype.__getComponentSpecIndexByClass = function (componentClass) {
|
|
188
|
-
let i = 0;
|
|
189
|
-
const l = this.components.length;
|
|
190
|
-
for (; i < l; i++) {
|
|
191
|
-
const spec = this.components[i];
|
|
192
|
-
if (spec.componentClass === componentClass) {
|
|
193
|
-
return i;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* @param {callback} callback
|
|
200
|
-
*/
|
|
201
|
-
EntityFactory.prototype.create = function (callback) {
|
|
202
|
-
const params = this.compiledFunctionParams;
|
|
203
|
-
params[1] = callback;
|
|
204
|
-
return this.compiledFunction.apply(null, params);
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
export default EntityFactory;
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 12/10/2016.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import Blueprint from './Blueprint.js';
|
|
7
|
-
import { assert } from "../../../../core/assert.js";
|
|
8
|
-
import { countTask } from "../../../../core/process/task/util/countTask.js";
|
|
9
|
-
import { emptyTask } from "../../../../core/process/task/util/emptyTask.js";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {Object<string, Blueprint>} blueprints
|
|
14
|
-
* @param {Object} descriptors
|
|
15
|
-
* @param {EntityManager} entityManager
|
|
16
|
-
* @returns {Task}
|
|
17
|
-
*/
|
|
18
|
-
function loadEntitiesByBlueprints(blueprints, descriptors, entityManager) {
|
|
19
|
-
console.time("populateEntities");
|
|
20
|
-
|
|
21
|
-
let task;
|
|
22
|
-
if (descriptors === undefined) {
|
|
23
|
-
//return NO-OP equivalent of a task
|
|
24
|
-
task = emptyTask();
|
|
25
|
-
} else {
|
|
26
|
-
task = countTask(0, descriptors.length, function (i) {
|
|
27
|
-
const descriptor = descriptors[i];
|
|
28
|
-
|
|
29
|
-
const bluePrintName = descriptor.blueprint;
|
|
30
|
-
|
|
31
|
-
const blueprint = blueprints[bluePrintName];
|
|
32
|
-
|
|
33
|
-
if (blueprint === undefined) {
|
|
34
|
-
console.error(`Could not build build entity, blueprint '${bluePrintName}' not found. Descriptor: `, descriptor, 'skipping...');
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const entity = blueprint.buildEntity(descriptor.parameters);
|
|
39
|
-
|
|
40
|
-
//process mixins
|
|
41
|
-
const mixins = descriptor.mixins;
|
|
42
|
-
if (typeof mixins === "object") {
|
|
43
|
-
processMixins(entity, mixins, entityManager);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
task.on.completed.add(function () {
|
|
49
|
-
console.timeEnd("populateEntities");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return task;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
57
|
-
* @param descriptor
|
|
58
|
-
* @param {EntityManager} entityManager
|
|
59
|
-
* @returns {Blueprint}
|
|
60
|
-
*/
|
|
61
|
-
function buildBluePrint(descriptor, entityManager) {
|
|
62
|
-
const blueprint = new Blueprint();
|
|
63
|
-
blueprint.fromJSON(descriptor, entityManager);
|
|
64
|
-
blueprint.compile();
|
|
65
|
-
return blueprint;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
*
|
|
70
|
-
* @param {number} entity
|
|
71
|
-
* @param {Object<string,Object>} mixins
|
|
72
|
-
* @param {EntityManager} entityManager
|
|
73
|
-
*/
|
|
74
|
-
function processMixins(entity, mixins, entityManager) {
|
|
75
|
-
for (let componentTypeName in mixins) {
|
|
76
|
-
const ComponentClass = entityManager.getComponentClassByName(componentTypeName);
|
|
77
|
-
|
|
78
|
-
assert.notEqual(ComponentClass, null, "Component class must not be null");
|
|
79
|
-
assert.notEqual(ComponentClass, undefined, "Component class must not be undefined");
|
|
80
|
-
assert.equal(typeof ComponentClass, "object", `Component class must be of type "object", instead was "${typeof ComponentClass}"`);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const component = new ComponentClass();
|
|
84
|
-
const options = mixins[componentTypeName];
|
|
85
|
-
|
|
86
|
-
component.fromJSON(options);
|
|
87
|
-
|
|
88
|
-
entityManager.addComponentToEntity(entity, component);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
* @param descriptors
|
|
95
|
-
* @param {EntityManager} entityManager
|
|
96
|
-
* @returns {Object<string,Blueprint>}
|
|
97
|
-
*/
|
|
98
|
-
function buildBlueprints(descriptors, entityManager) {
|
|
99
|
-
assert.notEqual(descriptors, undefined, 'descriptors are undefined');
|
|
100
|
-
assert.notEqual(descriptors, null, 'descriptors are null');
|
|
101
|
-
assert.typeOf(descriptors, 'object', 'descriptors');
|
|
102
|
-
|
|
103
|
-
const result = {};
|
|
104
|
-
|
|
105
|
-
for (let name in descriptors) {
|
|
106
|
-
if (descriptors.hasOwnProperty(name)) {
|
|
107
|
-
const descriptor = descriptors[name];
|
|
108
|
-
|
|
109
|
-
let blueprint;
|
|
110
|
-
try {
|
|
111
|
-
blueprint = buildBluePrint(descriptor, entityManager);
|
|
112
|
-
} catch (e) {
|
|
113
|
-
console.error("Failed to build blueprint '" + name + "'", e);
|
|
114
|
-
throw e;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
result[name] = blueprint;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function JSONDeSerializer() {
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
JSONDeSerializer.buildBluePrint = buildBluePrint;
|
|
129
|
-
|
|
130
|
-
JSONDeSerializer.buildBlueprints = buildBlueprints;
|
|
131
|
-
|
|
132
|
-
JSONDeSerializer.loadEntitiesByBlueprints = loadEntitiesByBlueprints;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
*
|
|
136
|
-
* @param {Object} json
|
|
137
|
-
* @param {EntityManager} entityManager
|
|
138
|
-
* @returns {Task}
|
|
139
|
-
*/
|
|
140
|
-
JSONDeSerializer.prototype.process = function (json, entityManager) {
|
|
141
|
-
|
|
142
|
-
const blueprints = buildBlueprints(json.blueprints, entityManager);
|
|
143
|
-
const taskLoadEntities = loadEntitiesByBlueprints(blueprints, json.objects, entityManager);
|
|
144
|
-
|
|
145
|
-
return taskLoadEntities;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export default JSONDeSerializer;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 12/10/2016.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function JSONSerializer() {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {EntityComponentDataset} entityDataset
|
|
14
|
-
* @returns {{blueprints, objects: Array}}
|
|
15
|
-
*/
|
|
16
|
-
JSONSerializer.prototype.process = function (entityDataset) {
|
|
17
|
-
console.time('serializing');
|
|
18
|
-
|
|
19
|
-
const blueprintsHash = {};
|
|
20
|
-
const objects = [];
|
|
21
|
-
|
|
22
|
-
let blueprintCount = 0;
|
|
23
|
-
|
|
24
|
-
function computeBlueprintHash(components, componentCount) {
|
|
25
|
-
let hash = "";
|
|
26
|
-
let i = 0;
|
|
27
|
-
for (; i < componentCount; i++) {
|
|
28
|
-
const component = components[i];
|
|
29
|
-
hash += component.constructor.typeName + "#";
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
return hash;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function createBlueprint(components, componentCount) {
|
|
36
|
-
const blueprint = {};
|
|
37
|
-
const blueprintComponents = [];
|
|
38
|
-
let i = 0;
|
|
39
|
-
for (; i < componentCount; i++) {
|
|
40
|
-
const component = components[i];
|
|
41
|
-
const ComponentClass = component.constructor;
|
|
42
|
-
const typeName = ComponentClass.typeName;
|
|
43
|
-
if (typeName === undefined) {
|
|
44
|
-
console.error("typeName is not defined for component class " + ComponentClass);
|
|
45
|
-
}
|
|
46
|
-
blueprintComponents.push({
|
|
47
|
-
type: typeName
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
blueprint.components = blueprintComponents;
|
|
51
|
-
blueprint.id = (blueprintCount++);
|
|
52
|
-
|
|
53
|
-
return blueprint;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function obtainBlueprint(components, componentCount) {
|
|
57
|
-
const blueprintId = computeBlueprintHash(components, componentCount);
|
|
58
|
-
|
|
59
|
-
let blueprint = blueprintsHash[blueprintId];
|
|
60
|
-
if (blueprint === undefined) {
|
|
61
|
-
blueprint = createBlueprint(components, componentCount, blueprintId);
|
|
62
|
-
blueprintsHash[blueprintId] = blueprint;
|
|
63
|
-
}
|
|
64
|
-
return blueprint;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function isEmptyObject(o) {
|
|
68
|
-
let result = true;
|
|
69
|
-
if (typeof o === 'object') {
|
|
70
|
-
for (let p in o) {
|
|
71
|
-
if (o.hasOwnProperty(p)) {
|
|
72
|
-
result = false;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
result = false;
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const serializableComponentTypes = entityDataset.getComponentTypeMap().filter(function (componentClass) {
|
|
83
|
-
return componentClass.serializable !== false;
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
entityDataset.traverseEntitiesCompactedFiltered(serializableComponentTypes, function (entity, components, componentCount) {
|
|
89
|
-
const blueprint = obtainBlueprint(components, componentCount);
|
|
90
|
-
|
|
91
|
-
const objectParameters = {};
|
|
92
|
-
const object = {
|
|
93
|
-
blueprint: blueprint.id
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
let i = 0;
|
|
97
|
-
for (; i < componentCount; i++) {
|
|
98
|
-
const component = components[i];
|
|
99
|
-
if (typeof component.toJSON !== 'function') {
|
|
100
|
-
console.error("toJSON is not a function", component);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const json = component.toJSON();
|
|
104
|
-
if (!isEmptyObject(json)) {
|
|
105
|
-
objectParameters[component.constructor.typeName] = json;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (!isEmptyObject(objectParameters)) {
|
|
109
|
-
object.parameters = objectParameters;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
objects.push(object);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
//rebuild blueprints into ID based structure
|
|
117
|
-
const blueprints = {};
|
|
118
|
-
for (let h in blueprintsHash) {
|
|
119
|
-
const blueprint = blueprintsHash[h];
|
|
120
|
-
blueprints[blueprint.id] = blueprint;
|
|
121
|
-
//remove id
|
|
122
|
-
delete blueprint.id;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
console.timeEnd('serializing');
|
|
126
|
-
return {
|
|
127
|
-
blueprints: blueprints,
|
|
128
|
-
objects: objects
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export default JSONSerializer;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 19/03/2015.
|
|
3
|
-
*/
|
|
4
|
-
import { System } from '../System.js';
|
|
5
|
-
import AlignToVelocity from '../components/AlignToVelocity.js';
|
|
6
|
-
import { Transform } from '../transform/Transform.js';
|
|
7
|
-
import Motion from '../components/Motion.js';
|
|
8
|
-
import Vector3 from "../../../core/geom/Vector3.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class AlignToVelocitySystem extends System {
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
this.dependencies = [AlignToVelocity];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
add(aabb, entity) {
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
remove(component) {
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
update(timeDelta) {
|
|
26
|
-
const em = this.entityManager;
|
|
27
|
-
const MotionType = em.getOwnerSystemIdByComponentClass(Motion);
|
|
28
|
-
const PhysicsBodyType = em.getOwnerSystemIdByComponentClass(PhysicsBody);
|
|
29
|
-
const velocity = new Vector3();
|
|
30
|
-
em.traverseEntities([AlignToVelocity, Transform], function (align, transform, entity) {
|
|
31
|
-
//find velocity
|
|
32
|
-
const motion = em.getComponentByType(entity, MotionType);
|
|
33
|
-
if (motion !== null) {
|
|
34
|
-
velocity.copy(motion.velocity);
|
|
35
|
-
} else {
|
|
36
|
-
const body = em.getComponentByType(entity, PhysicsBodyType);
|
|
37
|
-
if (body !== null) {
|
|
38
|
-
velocity.copy(body.velocity);
|
|
39
|
-
} else {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const delta = velocity.sub(transform.position);
|
|
44
|
-
//set transform rotation based on velocity
|
|
45
|
-
Transform.adjustRotation(transform.rotation, delta, align.angularSpeed * timeDelta);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
export default AlignToVelocitySystem;
|