@woosh/meep-engine 2.34.6 → 2.34.10

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/core/assert.js CHANGED
@@ -268,7 +268,10 @@ assert.isFunction = function (value, name = 'value') {
268
268
  */
269
269
  assert.isNonNegativeInteger = function (value, name = 'value') {
270
270
  assert.isNumber(value, name);
271
- assert.greaterThanOrEqual(value, 0, `${name} must be >= 0, instead was ${value}`);
271
+
272
+ if (value < 0) {
273
+ throw new Error(`${name} must be >= 0, instead was ${value}`);
274
+ }
272
275
 
273
276
  if (!Number.isInteger(value)) {
274
277
  throw new Error(`${name} must be an integer, instead was ${value}`);
@@ -472,11 +472,11 @@ BitSet.prototype.get = function (bitIndex) {
472
472
  const byteOffset = bitIndex >> 5;
473
473
  const bitOffset = bitIndex & 31;
474
474
 
475
- const byte = this.__data_uint32[byteOffset];
475
+ const word = this.__data_uint32[byteOffset];
476
476
 
477
- const maskedValue = byte & (1 << bitOffset);
477
+ const masked_word = word & (1 << bitOffset);
478
478
 
479
- return maskedValue !== 0;
479
+ return masked_word !== 0;
480
480
  };
481
481
 
482
482
  /**
@@ -0,0 +1,12 @@
1
+ import Task from "../task/Task";
2
+ import TaskGroup from "../task/TaskGroup";
3
+
4
+ export default class ConcurrentExecutor {
5
+ constructor(quietTime: number, workTime: number)
6
+
7
+ runGroup(t: TaskGroup): void
8
+
9
+ run(t: Task): void
10
+
11
+ runMany(tasks: Task[]): void
12
+ }
@@ -0,0 +1,18 @@
1
+ import Signal from "../../events/signal/Signal";
2
+
3
+ export abstract class ITask {
4
+ readonly name: string
5
+ readonly on: {
6
+ started: Signal,
7
+ completed: Signal,
8
+ failed: Signal
9
+ }
10
+
11
+ promise(): Promise<void>
12
+
13
+ getExecutedCpuTime(): number
14
+
15
+ getEstimatedDuration(): number
16
+
17
+ computeProgress(): number
18
+ }
@@ -0,0 +1,5 @@
1
+ import {ITask} from "./ITask";
2
+
3
+ export default class Task extends ITask {
4
+ readonly isTask:boolean
5
+ }
@@ -0,0 +1,5 @@
1
+ import {ITask} from "./ITask";
2
+
3
+ export default class TaskGroup extends ITask{
4
+
5
+ }
@@ -9,6 +9,7 @@ import {EntityManager} from "./ecs/EntityManager";
9
9
  import View from "../view/View";
10
10
  import Ticker from "./simulation/Ticker";
11
11
  import {EnginePluginManager} from "./plugin/EnginePluginManager";
12
+ import ConcurrentExecutor from "../core/process/executor/ConcurrentExecutor";
12
13
 
13
14
  export interface IEngineInitializationOptions {
14
15
  entityManager?: EntityManager
@@ -27,6 +28,7 @@ export default class Engine {
27
28
  public readonly assetManager: AssetManager
28
29
  public readonly ticker: Ticker
29
30
  public readonly plugins: EnginePluginManager
31
+ public readonly executor: ConcurrentExecutor
30
32
 
31
33
  public start(): Promise<any>
32
34
 
package/engine/Engine.js CHANGED
@@ -82,6 +82,12 @@ class Engine {
82
82
  */
83
83
  this.performance = new MetricCollection();
84
84
 
85
+ /**
86
+ *
87
+ * @type {ConcurrentExecutor}
88
+ */
89
+ this.executor = new ConcurrentExecutor(0, 10);
90
+
85
91
  this.__using_external_entity_manager = entityManager !== undefined;
86
92
 
87
93
  //setup entity component system
@@ -179,7 +185,6 @@ class Engine {
179
185
 
180
186
  this.settings = new EngineSettings();
181
187
 
182
- this.executor = new ConcurrentExecutor(0, 10);
183
188
 
184
189
  this.services = {
185
190
  compression: new CompressionService()
@@ -6,17 +6,19 @@ import {AssetTransformer} from "./AssetTransformer";
6
6
  export class AssetManager {
7
7
  public readonly crossOriginConfig: CrossOriginConfig
8
8
 
9
- public promise<T>(path: string, type: string): Promise<Asset<T>>
9
+ promise<T>(path: string, type: string): Promise<Asset<T>>
10
10
 
11
- public remove(path: string, type: string): boolean
11
+ remove(path: string, type: string): boolean
12
12
 
13
- public clear(): void
13
+ clear(): void
14
14
 
15
- public registerLoader<T>(type: string, loader: AssetLoader<T>): Promise<void>
15
+ registerLoader<T>(type: string, loader: AssetLoader<T>): Promise<void>
16
16
 
17
- public unregisterLoader(type: string): Promise<void>
17
+ unregisterLoader(type: string): Promise<void>
18
18
 
19
- public registerTransformer<T extends Asset<X>, X = any>(type: string, transformer: AssetTransformer<T>): void
19
+ getLoaderByType<T>(type: string): AssetLoader<T> | undefined
20
20
 
21
- public unregisterTransformer<T extends Asset<X>, X = any>(type: string, transformer: AssetTransformer<T>): boolean
21
+ registerTransformer<T extends Asset<X>, X = any>(type: string, transformer: AssetTransformer<T>): void
22
+
23
+ unregisterTransformer<T extends Asset<X>, X = any>(type: string, transformer: AssetTransformer<T>): boolean
22
24
  }
@@ -2,7 +2,7 @@
2
2
  * Transfer bitmap contents to Sampler2D, effectively moving data to CPU, making it readable
3
3
  * @param {WebGL2RenderingContext} gl
4
4
  * @param {Sampler2D} sampler
5
- * @param {ImageBitmap} bitmap
5
+ * @param {ImageBitmap|ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} bitmap
6
6
  */
7
7
  export function bitmap2sampler_gl(gl, sampler, bitmap) {
8
8
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
@@ -15,5 +15,11 @@ export function bitmap2sampler_gl(gl, sampler, bitmap) {
15
15
  throw new Error(`Expected sampler.itemSize to be 4, instead was '${sampler.itemSize}'`);
16
16
  }
17
17
 
18
- gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, sampler.data);
18
+ /**
19
+ *
20
+ * @type {Uint8ClampedArray}
21
+ */
22
+ const target_data = sampler.data;
23
+
24
+ gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, target_data);
19
25
  }
@@ -78,6 +78,9 @@ export function textureImagesEqual(a, b) {
78
78
  if (a.src === b.src) {
79
79
  //same source
80
80
  return true;
81
+ } else {
82
+ // different source, assume images are different too
83
+ return false;
81
84
  }
82
85
  }
83
86
 
@@ -2,6 +2,7 @@ import { computeImageBitmapHash } from "./computeImageBitmapHash.js";
2
2
  import { computeHashIntegerArray } from "../../../../core/collection/array/computeHashIntegerArray.js";
3
3
  import { computeHashFloat } from "../../../../core/math/hash/computeHashFloat.js";
4
4
  import { murmur3_32 } from "../../../../core/math/hash/murmur3_32.js";
5
+ import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
5
6
 
6
7
  /**
7
8
  *
@@ -20,6 +21,11 @@ function vector2Hash(v) {
20
21
  */
21
22
  const data_cache = new WeakMap();
22
23
 
24
+ /**
25
+ *
26
+ * @param {ImageBitmap|HTMLImageElement|{data,width:number,height:number}} image
27
+ * @return {number}
28
+ */
23
29
  export function computeImageDataHash(image) {
24
30
  const cached_value = data_cache.get(image);
25
31
 
@@ -31,6 +37,8 @@ export function computeImageDataHash(image) {
31
37
 
32
38
  if (image instanceof ImageBitmap) {
33
39
  result = computeImageBitmapHash(image);
40
+ } else if (image instanceof HTMLImageElement) {
41
+ result = computeStringHash(image.src);
34
42
  }
35
43
 
36
44
  let width = 0;
@@ -40,4 +40,6 @@ export class EntityComponentDataset {
40
40
  public sendEvent<T>(entity: number, name: string, event?: T);
41
41
 
42
42
  public getComponentClassByName<T>(name: string): Type<T>;
43
+
44
+ getAnyComponent<T>(type: Type<T>): { entity: number, component: T | null }
43
45
  }
@@ -1057,7 +1057,7 @@ export class EntityComponentDataset {
1057
1057
  if (!ENV_PRODUCTION) {
1058
1058
  assert.isArray(classes, "classes");
1059
1059
  // assert.notOk(classes.some((c, i) => classes.indexOf(c) !== i), 'classes contains duplicates');
1060
- assert.typeOf(visitor, "function", "visitor");
1060
+ assert.isFunction(visitor, "visitor");
1061
1061
  }
1062
1062
 
1063
1063
  let entityIndex, i;
@@ -1093,18 +1093,23 @@ export class EntityComponentDataset {
1093
1093
 
1094
1094
  const entityOccupancy = this.entityOccupancy;
1095
1095
 
1096
+ const component_type_count = this.componentTypeCount;
1097
+ const component_occupancy = this.componentOccupancy;
1098
+ const components = this.components;
1099
+
1096
1100
  entity_loop: for (entityIndex = entityOccupancy.nextSetBit(0); entityIndex !== -1; entityIndex = entityOccupancy.nextSetBit(entityIndex + 1)) {
1097
- const componentOccupancyAddress = entityIndex * this.componentTypeCount;
1101
+ const componentOccupancyAddress = entityIndex * component_type_count;
1102
+
1098
1103
  for (i = 0; i < numClasses; i++) {
1099
1104
  const componentIndex = indices[i];
1100
1105
 
1101
- const componentPresent = this.componentOccupancy.get(componentOccupancyAddress + componentIndex);
1106
+ const componentPresent = component_occupancy.get(componentOccupancyAddress + componentIndex);
1102
1107
 
1103
1108
  if (!componentPresent) {
1104
1109
  continue entity_loop;
1105
1110
  }
1106
1111
 
1107
- args[i] = this.components[componentIndex][entityIndex];
1112
+ args[i] = components[componentIndex][entityIndex];
1108
1113
  }
1109
1114
 
1110
1115
  args[numClasses] = entityIndex;
@@ -184,10 +184,11 @@ export class IncrementalDeltaSet {
184
184
  */
185
185
  push(element) {
186
186
  //check if element is already in the set
187
- const i = this.elements.indexOf(element); //TODO this can probably be done faster. Maybe use a bloom filter? or some kind of a hash
187
+ const elements = this.elements;
188
+ const i = elements.indexOf(element); //TODO this can probably be done faster. Maybe use a bloom filter? or some kind of a hash
188
189
 
189
190
  if (i === -1) {
190
- this.elements.push(element);
191
+ elements.push(element);
191
192
  this.size++;
192
193
 
193
194
  this.onAdded.send1(element);
@@ -95,7 +95,7 @@ export class VisibilityComputer {
95
95
  * @param {Object3D} object3d
96
96
  */
97
97
  __includeObject(object3d) {
98
- assert.equal(object3d.isObject3D, true, `expected isObject3D to be true, instead was '${object3d.isObject3D}'`);
98
+ assert.equal(object3d.isObject3D, true, 'object3d.isObject3D !== true');
99
99
 
100
100
  // mark object, this is a hack, needs to be fixed at some point
101
101
  object3d[SOURCE_RENDER_LAYER_PROPERTY] = this.__activeLayer;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "productName": "Meep",
6
6
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.34.6",
8
+ "version": "2.34.10",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",