@woosh/meep-engine 2.118.4 → 2.118.5

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.118.4",
8
+ "version": "2.118.5",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Based on Squirrel3 hash function by Squirrel Eiserloh
3
+ * Alex: Personally I found it to have low entropy, so I don't see it as very useful
3
4
  * @see GDC 2017 presentation on "Math for Game Programmers: Noise-Based RNG"
4
5
  * @param {number} value expected to be an integer, if not - it will be truncated to such
5
6
  * @returns {number} signed 32-bit integer
@@ -1 +1 @@
1
- {"version":3,"file":"squirrel3.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/hash/squirrel3.js"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,iCAHW,MAAM,GACJ,MAAM,CAYlB"}
1
+ {"version":3,"file":"squirrel3.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/hash/squirrel3.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,iCAHW,MAAM,GACJ,MAAM,CAYlB"}
@@ -4,6 +4,7 @@ const BIT_NOISE3 = 0x1B56C4E9;
4
4
 
5
5
  /**
6
6
  * Based on Squirrel3 hash function by Squirrel Eiserloh
7
+ * Alex: Personally I found it to have low entropy, so I don't see it as very useful
7
8
  * @see GDC 2017 presentation on "Math for Game Programmers: Noise-Based RNG"
8
9
  * @param {number} value expected to be an integer, if not - it will be truncated to such
9
10
  * @returns {number} signed 32-bit integer
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Random number generator based on Mersenne Twister sequence
3
+ * @param {number} seed
4
+ * @returns {function():number} RNG
5
+ */
6
+ export function seededRandom_MersenneTwister(seed: number): () => number;
7
+ //# sourceMappingURL=seededRandom_MersenneTwister.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seededRandom_MersenneTwister.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/random/seededRandom_MersenneTwister.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,mDAHW,MAAM,SACO,MAAM,CAmF7B"}
@@ -1,9 +1,11 @@
1
1
  /**
2
- * https://gist.github.com/banksean/300494
2
+ * Random number generator based on Mersenne Twister sequence
3
3
  * @param {number} seed
4
4
  * @returns {function():number} RNG
5
5
  */
6
- export function seededRandomMersenneTwister(seed) {
6
+ export function seededRandom_MersenneTwister(seed) {
7
+ // see https://gist.github.com/banksean/300494
8
+
7
9
  /* Period parameters */
8
10
  const N = 624;
9
11
  const M = 397;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Was originally written for TAA jitter sequence optimization in order to reduce maximum impulse
3
+ * @template T
4
+ * @param {T[]} sequence
5
+ * @param {number} dimensions
6
+ * @param {number} offset
7
+ * @param {number} count
8
+ * @param {function(address0:number, address1:number, sequence:T[]):number} cost_function
9
+ * @param {*} [cost_function_ctx]
10
+ */
11
+ export function optimize_cyclic_sequence_pairwise<T>(sequence: T[], dimensions: number, offset: number, count: number, cost_function: any, cost_function_ctx?: any): void;
12
+ //# sourceMappingURL=optimize_cyclic_sequence_pairwise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optimize_cyclic_sequence_pairwise.d.ts","sourceRoot":"","sources":["../../../../../src/engine/intelligence/optimization/optimize_cyclic_sequence_pairwise.js"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,gFANW,MAAM,UACN,MAAM,SACN,MAAM,qDAiFhB"}
@@ -0,0 +1,90 @@
1
+ import { assert } from "../../../core/assert.js";
2
+
3
+ /**
4
+ * Was originally written for TAA jitter sequence optimization in order to reduce maximum impulse
5
+ * @template T
6
+ * @param {T[]} sequence
7
+ * @param {number} dimensions
8
+ * @param {number} offset
9
+ * @param {number} count
10
+ * @param {function(address0:number, address1:number, sequence:T[]):number} cost_function
11
+ * @param {*} [cost_function_ctx]
12
+ */
13
+ export function optimize_cyclic_sequence_pairwise(
14
+ sequence,
15
+ dimensions,
16
+ offset,
17
+ count,
18
+ cost_function,
19
+ cost_function_ctx
20
+ ) {
21
+
22
+ assert.isNonNegativeInteger(dimensions, 'dimensions');
23
+ assert.isNonNegativeInteger(offset, 'offset');
24
+ assert.isNonNegativeInteger(count, 'count');
25
+
26
+ assert.isFunction(cost_function, 'cost_function');
27
+
28
+ let swaps = 0;
29
+
30
+ let distance_max = (count - 1) >>> 1;
31
+
32
+ function index_to_address(index) {
33
+ const wrapped_index = (index + count) % count;
34
+ return offset + wrapped_index * dimensions;
35
+ }
36
+
37
+ function move(from, to){
38
+ const i0 = index_to_address(from);
39
+ const i1 = index_to_address(to);
40
+
41
+ const clip = sequence.splice(i0, dimensions);
42
+ sequence.splice(i1, 0, ...clip);
43
+
44
+ }
45
+
46
+ function pair_cost(i0, i1){
47
+ return cost_function.call(cost_function_ctx, index_to_address(i0), index_to_address(i1), sequence)
48
+ }
49
+
50
+ main: do {
51
+ swaps = 0;
52
+
53
+ for (let from = 0; from < count; from++) {
54
+
55
+ for (let distance = -distance_max; distance <= distance_max; distance++) {
56
+ if (distance === 0) {
57
+ continue;
58
+ }
59
+
60
+ // estimate swap benefit
61
+ const to = from+distance;
62
+
63
+ const removal_gain = pair_cost(from-1, from+1) - (
64
+ pair_cost(from-1, from) + pair_cost(from, from+1)
65
+ );
66
+
67
+ move(from, to);
68
+
69
+ const insertion_gain = ( pair_cost(to-1, to) + pair_cost(to, to+1))
70
+ - pair_cost(to -1, to+1);
71
+
72
+ const move_cost =insertion_gain + removal_gain;
73
+
74
+ if (move_cost >= 0) {
75
+ // bad swap, undo
76
+
77
+ move(to, from);
78
+
79
+ continue;
80
+ }
81
+
82
+ swaps++;
83
+
84
+ continue main;
85
+ }
86
+ }
87
+
88
+ } while (swaps > 0);
89
+
90
+ }
@@ -1,19 +0,0 @@
1
- export class MersenneTwister {
2
- constructor(seed?: number);
3
- N: number;
4
- M: number;
5
- MATRIX_A: number;
6
- UPPER_MASK: number;
7
- LOWER_MASK: number;
8
- mt: any[];
9
- mti: number;
10
- init_genrand(s: any): void;
11
- init_by_array(init_key: any, key_length: any): void;
12
- genrand_int32(): number;
13
- genrand_int31(): number;
14
- genrand_real1(): number;
15
- random(): number;
16
- genrand_real3(): number;
17
- genrand_res53(): number;
18
- }
19
- //# sourceMappingURL=MersenneTwister.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MersenneTwister.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/random/MersenneTwister.js"],"names":[],"mappings":"AA8DA;IACI,2BAkBC;IAfG,UAAY;IACZ,UAAY;IACZ,iBAA0B;IAE1B,mBAA4B;IAE5B,mBAA4B;IAG5B,UAA2B;IAE3B,YAAqB;IAOzB,2BAaC;IAOD,oDAqCC;IAGD,wBAmCC;IAGD,wBAEC;IAGD,wBAGC;IAGD,iBAGC;IAGD,wBAGC;IAGD,wBAGC;CACJ"}
@@ -1,212 +0,0 @@
1
- /*
2
- I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
3
- so it's better encapsulated. Now you can have multiple random number generators
4
- and they won't stomp all over eachother's state.
5
-
6
- If you want to use this as a substitute for Math.random(), use the random()
7
- method like so:
8
-
9
- var m = new MersenneTwister();
10
- var randomNumber = m.random();
11
-
12
- You can also call the other genrand_{foo}() methods on the instance.
13
- If you want to use a specific seed in order to get a repeatable random
14
- sequence, pass an integer into the constructor:
15
- var m = new MersenneTwister(123);
16
- and that will always produce the same random sequence.
17
- Sean McCullough (banksean@gmail.com)
18
- */
19
-
20
- /*
21
- A C-program for MT19937, with initialization improved 2002/1/26.
22
- Coded by Takuji Nishimura and Makoto Matsumoto.
23
-
24
- Before using, initialize the state by using init_genrand(seed)
25
- or init_by_array(init_key, key_length).
26
-
27
- Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
28
- All rights reserved.
29
-
30
- Redistribution and use in source and binary forms, with or without
31
- modification, are permitted provided that the following conditions
32
- are met:
33
-
34
- 1. Redistributions of source code must retain the above copyright
35
- notice, this list of conditions and the following disclaimer.
36
-
37
- 2. Redistributions in binary form must reproduce the above copyright
38
- notice, this list of conditions and the following disclaimer in the
39
- documentation and/or other materials provided with the distribution.
40
-
41
- 3. The names of its contributors may not be used to endorse or promote
42
- products derived from this software without specific prior written
43
- permission.
44
-
45
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
47
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
49
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
50
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
51
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
52
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
53
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
54
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
55
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
-
57
-
58
- Any feedback is very welcome.
59
- http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
60
- email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
61
- */
62
-
63
- export class MersenneTwister {
64
- constructor(seed = new Date().getTime()) {
65
-
66
- /* Period parameters */
67
- this.N = 624;
68
- this.M = 397;
69
- this.MATRIX_A = 0x9908b0df;
70
- /* constant vector a */
71
- this.UPPER_MASK = 0x80000000;
72
- /* most significant w-r bits */
73
- this.LOWER_MASK = 0x7fffffff;
74
- /* least significant r bits */
75
-
76
- this.mt = new Array(this.N);
77
- /* the array for the state vector */
78
- this.mti = this.N + 1;
79
- /* mti==N+1 means mt[N] is not initialized */
80
-
81
- this.init_genrand(seed);
82
- }
83
-
84
- /* initializes mt[N] with a seed */
85
- init_genrand(s) {
86
- this.mt[0] = s >>> 0;
87
- for (this.mti = 1; this.mti < this.N; this.mti++) {
88
- const s = this.mt[this.mti - 1] ^ (this.mt[this.mti - 1] >>> 30);
89
- this.mt[this.mti] = (((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253)
90
- + this.mti;
91
- /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
92
- /* In the previous versions, MSBs of the seed affect */
93
- /* only MSBs of the array mt[]. */
94
- /* 2002/01/09 modified by Makoto Matsumoto */
95
- this.mt[this.mti] >>>= 0;
96
- /* for >32 bit machines */
97
- }
98
- }
99
-
100
- /* initialize by an array with array-length */
101
- /* init_key is the array for initializing keys */
102
- /* key_length is its length */
103
-
104
- /* slight change for C++, 2004/2/26 */
105
- init_by_array(init_key, key_length) {
106
- let i, j, k;
107
- this.init_genrand(19650218);
108
- i = 1;
109
- j = 0;
110
- k = (this.N > key_length ? this.N : key_length);
111
- for (; k; k--) {
112
- const s = this.mt[i - 1] ^ (this.mt[i - 1] >>> 30)
113
- this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1664525) << 16) + ((s & 0x0000ffff) * 1664525)))
114
- + init_key[j] + j;
115
- /* non linear */
116
- this.mt[i] >>>= 0;
117
- /* for WORDSIZE > 32 machines */
118
- i++;
119
- j++;
120
- if (i >= this.N) {
121
- this.mt[0] = this.mt[this.N - 1];
122
- i = 1;
123
- }
124
- if (j >= key_length) j = 0;
125
- }
126
- for (k = this.N - 1; k; k--) {
127
- const s = this.mt[i - 1] ^ (this.mt[i - 1] >>> 30);
128
- this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1566083941) << 16) + (s & 0x0000ffff) * 1566083941))
129
- - i;
130
- /* non linear */
131
- this.mt[i] >>>= 0;
132
- /* for WORDSIZE > 32 machines */
133
- i++;
134
- if (i >= this.N) {
135
- this.mt[0] = this.mt[this.N - 1];
136
- i = 1;
137
- }
138
- }
139
-
140
- this.mt[0] = 0x80000000;
141
- /* MSB is 1; assuring non-zero initial array */
142
- }
143
-
144
- /* generates a random number on [0,0xffffffff]-interval */
145
- genrand_int32() {
146
- let y;
147
- const mag01 = new Array(0x0, this.MATRIX_A);
148
- /* mag01[x] = x * MATRIX_A for x=0,1 */
149
-
150
- if (this.mti >= this.N) { /* generate N words at one time */
151
- let kk;
152
-
153
- if (this.mti === this.N + 1) /* if init_genrand() has not been called, */
154
- this.init_genrand(5489);
155
- /* a default initial seed is used */
156
-
157
- for (kk = 0; kk < this.N - this.M; kk++) {
158
- y = (this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK);
159
- this.mt[kk] = this.mt[kk + this.M] ^ (y >>> 1) ^ mag01[y & 0x1];
160
- }
161
- for (; kk < this.N - 1; kk++) {
162
- y = (this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK);
163
- this.mt[kk] = this.mt[kk + (this.M - this.N)] ^ (y >>> 1) ^ mag01[y & 0x1];
164
- }
165
- y = (this.mt[this.N - 1] & this.UPPER_MASK) | (this.mt[0] & this.LOWER_MASK);
166
- this.mt[this.N - 1] = this.mt[this.M - 1] ^ (y >>> 1) ^ mag01[y & 0x1];
167
-
168
- this.mti = 0;
169
- }
170
-
171
- y = this.mt[this.mti++];
172
-
173
- /* Tempering */
174
- y ^= (y >>> 11);
175
- y ^= (y << 7) & 0x9d2c5680;
176
- y ^= (y << 15) & 0xefc60000;
177
- y ^= (y >>> 18);
178
-
179
- return y >>> 0;
180
- }
181
-
182
- /* generates a random number on [0,0x7fffffff]-interval */
183
- genrand_int31() {
184
- return (this.genrand_int32() >>> 1);
185
- }
186
-
187
- /* generates a random number on [0,1]-real-interval */
188
- genrand_real1() {
189
- return this.genrand_int32() * (1.0 / 4294967295.0);
190
- /* divided by 2^32-1 */
191
- }
192
-
193
- /* generates a random number on [0,1)-real-interval */
194
- random() {
195
- return this.genrand_int32() * (1.0 / 4294967296.0);
196
- /* divided by 2^32 */
197
- }
198
-
199
- /* generates a random number on (0,1)-real-interval */
200
- genrand_real3() {
201
- return (this.genrand_int32() + 0.5) * (1.0 / 4294967296.0);
202
- /* divided by 2^32 */
203
- }
204
-
205
- /* generates a random number on [0,1) with 53-bit resolution*/
206
- genrand_res53() {
207
- const a = this.genrand_int32() >>> 5, b = this.genrand_int32() >>> 6;
208
- return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0);
209
- }
210
- }
211
-
212
- /* These real versions are due to Isaku Wada, 2002/01/09 added */
@@ -1,7 +0,0 @@
1
- /**
2
- * https://gist.github.com/banksean/300494
3
- * @param {number} seed
4
- * @returns {function():number} RNG
5
- */
6
- export function seededRandomMersenneTwister(seed: number): () => number;
7
- //# sourceMappingURL=seededRandomMersenneTwister.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"seededRandomMersenneTwister.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/random/seededRandomMersenneTwister.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,kDAHW,MAAM,SACO,MAAM,CAiF7B"}