@woosh/meep-engine 2.75.6 → 2.75.8
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/meep.cjs +268 -252
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +268 -252
- package/editor/ecs/component/createObjectEditor.js +2 -2
- package/package.json +1 -1
- package/src/core/geom/3d/frustum/read_three_planes_to_array.d.ts +3 -0
- package/src/core/model/object/ImmutableObjectPool.js +14 -5
- 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/terrain/ecs/layers/TerrainLayer.js +37 -31
- package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +8 -7
- 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/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- 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 -2
- package/src/engine/graphics/sh3/gi/prototypeSHGI.js +92 -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/core/geom/3d/frustum/read_frustum_planes_to_array.d.ts +0 -3
- 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/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/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/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,10 +1,10 @@
|
|
|
1
|
-
import { assert } from "
|
|
2
|
-
import { arrayQuickSort } from "
|
|
3
|
-
import Signal from "
|
|
4
|
-
import { AssetManager } from "
|
|
5
|
-
import { GameAssetType } from "
|
|
6
|
-
import { Sampler2D } from "
|
|
7
|
-
import { sampler2d_to_uint8_RGBA } from "
|
|
1
|
+
import { assert } from "../../../../core/assert.js";
|
|
2
|
+
import { arrayQuickSort } from "../../../../core/collection/array/arrayQuickSort.js";
|
|
3
|
+
import Signal from "../../../../core/events/signal/Signal.js";
|
|
4
|
+
import { AssetManager } from "../../../asset/AssetManager.js";
|
|
5
|
+
import { GameAssetType } from "../../../asset/GameAssetType.js";
|
|
6
|
+
import { Sampler2D } from "../sampler/Sampler2D.js";
|
|
7
|
+
import { sampler2d_to_uint8_RGBA } from "../sampler/sampler2d_to_uint8_RGBA.js";
|
|
8
8
|
import { compose_finger_print } from "./tile/compose_finger_print.js";
|
|
9
9
|
import { decompose_finger_print } from "./tile/decompose_finger_print.js";
|
|
10
10
|
import { VirtualTextureTile } from "./tile/VirtualTextureTile.js";
|
package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsage.js → VirtualTextureUsage.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { array_quick_sort_by_comparator, arrayQuickSort } from "
|
|
1
|
+
import { array_quick_sort_by_comparator, arrayQuickSort } from "../../../../core/collection/array/arrayQuickSort.js";
|
|
2
2
|
import { compose_tile_address } from "./tile/compose_tile_address.js";
|
|
3
3
|
import { decompose_finger_print } from "./tile/decompose_finger_print.js";
|
|
4
4
|
import { finger_print_to_tile_address } from "./tile/finger_print_to_tile_address.js";
|
|
@@ -12,13 +12,13 @@ import {
|
|
|
12
12
|
Vector4,
|
|
13
13
|
WebGLRenderTarget
|
|
14
14
|
} from "three";
|
|
15
|
-
import { assert } from "
|
|
16
|
-
import { array_copy } from "
|
|
17
|
-
import { clamp } from "
|
|
18
|
-
import { max2 } from "
|
|
19
|
-
import { generate_halton_jitter } from "
|
|
20
|
-
import { renderScreenSpace } from "
|
|
21
|
-
import { Sampler2D } from "
|
|
15
|
+
import { assert } from "../../../../core/assert.js";
|
|
16
|
+
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
17
|
+
import { clamp } from "../../../../core/math/clamp.js";
|
|
18
|
+
import { max2 } from "../../../../core/math/max2.js";
|
|
19
|
+
import { generate_halton_jitter } from "../../generate_halton_jitter.js";
|
|
20
|
+
import { renderScreenSpace } from "../../render/utils/renderScreenSpace.js";
|
|
21
|
+
import { Sampler2D } from "../sampler/Sampler2D.js";
|
|
22
22
|
import { VirtualTextureUsage } from "./VirtualTextureUsage.js";
|
|
23
23
|
import { fragment, vertex } from "./VirtualTextureUsageShader.js";
|
|
24
24
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CSS_ABSOLUTE_POSITIONING } from "
|
|
2
|
-
import { CanvasView } from "
|
|
3
|
-
import EmptyView from "
|
|
4
|
-
import { sampler2d_write_to_canvas_raw } from "
|
|
1
|
+
import { CSS_ABSOLUTE_POSITIONING } from "../../../../../view/CSS_ABSOLUTE_POSITIONING.js";
|
|
2
|
+
import { CanvasView } from "../../../../../view/elements/CanvasView.js";
|
|
3
|
+
import EmptyView from "../../../../../view/elements/EmptyView.js";
|
|
4
|
+
import { sampler2d_write_to_canvas_raw } from "../../sampler/sampler2d_write_to_canvas_raw.js";
|
|
5
5
|
|
|
6
6
|
export class ResidencyDebugView extends EmptyView {
|
|
7
7
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import LabelView from "
|
|
2
|
-
import EmptyView from "
|
|
1
|
+
import LabelView from "../../../../../view/common/LabelView.js";
|
|
2
|
+
import EmptyView from "../../../../../view/elements/EmptyView.js";
|
|
3
3
|
import { decompose_finger_print } from "../tile/decompose_finger_print.js";
|
|
4
4
|
import { tile_address_to_finger_print } from "../tile/tile_address_to_finger_print.js";
|
|
5
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { assert } from "
|
|
2
|
-
import LabelView from "
|
|
3
|
-
import { CSS_ABSOLUTE_POSITIONING } from "
|
|
4
|
-
import EmptyView from "
|
|
1
|
+
import { assert } from "../../../../../core/assert.js";
|
|
2
|
+
import LabelView from "../../../../../view/common/LabelView.js";
|
|
3
|
+
import { CSS_ABSOLUTE_POSITIONING } from "../../../../../view/CSS_ABSOLUTE_POSITIONING.js";
|
|
4
|
+
import EmptyView from "../../../../../view/elements/EmptyView.js";
|
|
5
5
|
import { decompose_finger_print } from "../tile/decompose_finger_print.js";
|
|
6
6
|
import { tile_address_to_finger_print } from "../tile/tile_address_to_finger_print.js";
|
|
7
7
|
|
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
WebGLRenderer
|
|
12
12
|
} from "three";
|
|
13
13
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
14
|
-
import Signal from "
|
|
15
|
-
import { CSS_ABSOLUTE_POSITIONING } from "
|
|
16
|
-
import EmptyView from "
|
|
17
|
-
import { AssetManager } from "
|
|
18
|
-
import { GameAssetType } from "
|
|
19
|
-
import { ImageRGBADataLoader } from "
|
|
20
|
-
import { buildCanvasViewFromTexture } from "
|
|
14
|
+
import Signal from "../../../../core/events/signal/Signal.js";
|
|
15
|
+
import { CSS_ABSOLUTE_POSITIONING } from "../../../../view/CSS_ABSOLUTE_POSITIONING.js";
|
|
16
|
+
import EmptyView from "../../../../view/elements/EmptyView.js";
|
|
17
|
+
import { AssetManager } from "../../../asset/AssetManager.js";
|
|
18
|
+
import { GameAssetType } from "../../../asset/GameAssetType.js";
|
|
19
|
+
import { ImageRGBADataLoader } from "../../../asset/loaders/image/ImageRGBADataLoader.js";
|
|
20
|
+
import { buildCanvasViewFromTexture } from "../../render/visibility/hiz/buildCanvasViewFromTexture.js";
|
|
21
21
|
import { VirtualTextureMaterial } from "./VirtualTextureMaterial.js";
|
|
22
22
|
import { VirtualTextureMemoryMapping } from "./VirtualTextureMemoryMapping.js";
|
|
23
23
|
import { VirtualTexturePage } from "./VirtualTexturePage.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { assert } from "
|
|
2
|
-
import { split_by_2 } from "
|
|
1
|
+
import { assert } from "../../../../../core/assert.js";
|
|
2
|
+
import { split_by_2 } from "../../../../../core/geom/3d/morton/split_by_2.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
@@ -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;
|