@woosh/meep-engine 2.110.15 → 2.111.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/build/meep.cjs +442 -370
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +442 -370
  4. package/editor/tools/v2/BlenderCameraOrientationGizmo.js +4 -2
  5. package/package.json +1 -1
  6. package/src/core/events/signal/Signal.d.ts.map +1 -1
  7. package/src/core/events/signal/Signal.js +289 -255
  8. package/src/core/events/signal/SignalHandler.d.ts +7 -2
  9. package/src/core/events/signal/SignalHandler.d.ts.map +1 -1
  10. package/src/core/events/signal/SignalHandler.js +12 -6
  11. package/src/core/events/signal/signal_handler_list_find.d.ts +8 -0
  12. package/src/core/events/signal/signal_handler_list_find.d.ts.map +1 -0
  13. package/src/core/events/signal/signal_handler_list_find.js +23 -0
  14. package/src/core/events/signal/signal_handler_list_last.d.ts +7 -0
  15. package/src/core/events/signal/signal_handler_list_last.d.ts.map +1 -0
  16. package/src/core/events/signal/signal_handler_list_last.js +14 -0
  17. package/src/core/events/signal/signal_handler_list_validate.d.ts +8 -0
  18. package/src/core/events/signal/signal_handler_list_validate.d.ts.map +1 -0
  19. package/src/core/events/signal/signal_handler_list_validate.js +29 -0
  20. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleDescription.d.ts +2 -3
  21. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleDescription.d.ts.map +1 -1
  22. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleDescription.js +3 -3
  23. package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
  24. package/src/engine/graphics/ecs/camera/Camera.js +2 -2
  25. package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +1 -1
  26. package/src/engine/graphics/ecs/camera/CameraSystem.js +10 -2
  27. package/src/engine/graphics/ecs/camera/quaternion_invert_orientation.d.ts +7 -0
  28. package/src/engine/graphics/ecs/camera/quaternion_invert_orientation.d.ts.map +1 -0
  29. package/src/engine/graphics/ecs/camera/{InvertQuaternionOrientation.js → quaternion_invert_orientation.js} +6 -5
  30. package/src/engine/graphics/ecs/camera/InvertQuaternionOrientation.d.ts +0 -7
  31. package/src/engine/graphics/ecs/camera/InvertQuaternionOrientation.d.ts.map +0 -1
package/build/meep.cjs CHANGED
@@ -899,6 +899,36 @@ function m4_multiply(out, a, b) {
899
899
  out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
900
900
  }
901
901
 
902
+ /**
903
+ *
904
+ * @param {SignalHandler} first
905
+ * @param {function} handle
906
+ * @param {*} [thisArg]
907
+ */
908
+ function signal_handler_list_find(first, handle, thisArg) {
909
+ let n = first;
910
+
911
+ for (; ;) {
912
+
913
+ if (n.handle === handle && n.context === thisArg) {
914
+ return n;
915
+ }
916
+
917
+ n = n.next;
918
+
919
+ if (n === null) {
920
+ return null;
921
+ }
922
+ }
923
+ }
924
+
925
+ const SignalFlags = {
926
+ /**
927
+ * If set - signal will not invoke handlers when dispatched
928
+ */
929
+ Silent: 1
930
+ };
931
+
902
932
  /**
903
933
  *
904
934
  * @enum {number}
@@ -911,6 +941,18 @@ const SignalHandlerFlags = {
911
941
  };
912
942
 
913
943
  class SignalHandler {
944
+ /**
945
+ * Optional field. Used for forming linked lists of handlers
946
+ * @type {SignalHandler|null}
947
+ */
948
+ next = null;
949
+
950
+ /**
951
+ * @private
952
+ * @type {number|SignalHandlerFlags}
953
+ */
954
+ flags = 0;
955
+
914
956
  /**
915
957
  *
916
958
  * @param {function} handle
@@ -918,15 +960,9 @@ class SignalHandler {
918
960
  */
919
961
  constructor(handle, context) {
920
962
 
921
-
922
963
  this.handle = handle;
923
964
  this.context = context;
924
965
 
925
- /**
926
- * @private
927
- * @type {number|SignalHandlerFlags}
928
- */
929
- this.flags = 0;
930
966
  }
931
967
 
932
968
  /**
@@ -977,126 +1013,6 @@ class SignalHandler {
977
1013
  */
978
1014
  SignalHandler.prototype.isSignalHandler = true;
979
1015
 
980
- /**
981
- * Common dispatch stack
982
- * @readonly
983
- * @type {SignalHandler[]}
984
- */
985
- const dispatch_stack$1 = [];
986
- let dispatch_stack_top$1 = 0;
987
-
988
- /**
989
- *
990
- * @param {function} f
991
- * @param {*} context
992
- * @param {Array} args
993
- */
994
- function dispatchCallback(f, context, args) {
995
-
996
- try {
997
- f.apply(context, args);
998
- } catch (e) {
999
- }
1000
- }
1001
-
1002
- /**
1003
- *
1004
- * @param {SignalHandler[]} handlers
1005
- * @param {Array} [args]
1006
- */
1007
- function dispatchViaProxy(handlers, args) {
1008
- const length = handlers.length;
1009
-
1010
- const stack_pointer = dispatch_stack_top$1;
1011
- const stack_frame_end = stack_pointer + length;
1012
- dispatch_stack_top$1 = stack_frame_end;
1013
-
1014
- let i, h;
1015
- for (i = 0; i < length; i++) {
1016
- //copy to proxy
1017
- dispatch_stack$1[stack_pointer + i] = handlers[length - (i + 1)];
1018
- }
1019
-
1020
- for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
1021
- h = dispatch_stack$1[i];
1022
-
1023
- if (h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1024
- //handler should be cut
1025
- const p = handlers.indexOf(h);
1026
- handlers.splice(p, 1);
1027
- }
1028
-
1029
- dispatchCallback(h.handle, h.context, args);
1030
- }
1031
-
1032
- //drop stack frame
1033
- dispatch_stack_top$1 = stack_pointer;
1034
- }
1035
-
1036
- /**
1037
- *
1038
- * @param {SignalHandler[]} handlers
1039
- * @param {function} f
1040
- * @param {*} [thisArg]
1041
- * @returns {number} index of the handler, or -1 if not found
1042
- */
1043
- function findSignalHandlerIndexByHandle(handlers, f, thisArg) {
1044
- const l = handlers.length;
1045
-
1046
- for (let i = 0; i < l; i++) {
1047
- const signalHandler = handlers[i];
1048
-
1049
- if (signalHandler.handle === f) {
1050
-
1051
- if (thisArg !== undefined && thisArg !== signalHandler.context) {
1052
- //context variable doesn't match
1053
- continue;
1054
- }
1055
-
1056
- return i;
1057
- }
1058
- }
1059
-
1060
- return -1;
1061
- }
1062
-
1063
- /**
1064
- *
1065
- * @param {SignalHandler[]} handlers
1066
- * @param {function} f
1067
- * @param {*} ctx
1068
- * @returns {number} index of the handler, or -1 if not found
1069
- */
1070
- function findSignalHandlerIndexByHandleAndContext(handlers, f, ctx) {
1071
- const l = handlers.length;
1072
-
1073
- for (let i = 0; i < l; i++) {
1074
- const handler = handlers[i];
1075
-
1076
- if (handler.handle === f && handler.context === ctx) {
1077
- return i;
1078
- }
1079
-
1080
- }
1081
-
1082
- return -1;
1083
- }
1084
-
1085
- const SignalFlags = {
1086
- /**
1087
- * If set - signal will not invoke handlers when dispatched
1088
- */
1089
- Silent: 1
1090
- };
1091
-
1092
- /**
1093
- * Common dispatch stack
1094
- * @readonly
1095
- * @type {SignalHandler[]}
1096
- */
1097
- const dispatch_stack = [];
1098
- let dispatch_stack_top = 0;
1099
-
1100
1016
  /**
1101
1017
  * Signal is a type of event bus. You can subscribe to events using {@link add} method and dispatch using sendN method where N is the number of arguments you wish to pass
1102
1018
  * Signal is different from a normal event bus in that 1 signal corresponds to 1 event type. For example, in HTML you have `addEventListener` which lets you subscribe to any kind of event, let's use "mousedown" as a reference. Using a Signal you would instead have a signal corresponding to "mousedown" and dispatch this signal only for this event.
@@ -1104,10 +1020,11 @@ let dispatch_stack_top = 0;
1104
1020
  */
1105
1021
  class Signal {
1106
1022
  /**
1023
+ * Map is used to speed up lookup when removing handlers in case of large number of listeners.
1107
1024
  * @private
1108
- * @type {SignalHandler[]}
1025
+ * @type {Map<function,SignalHandler>}
1109
1026
  */
1110
- handlers = [];
1027
+ handlers = new Map();
1111
1028
 
1112
1029
  /**
1113
1030
  * Internal flag bitmask
@@ -1184,9 +1101,15 @@ class Signal {
1184
1101
  contains(handler, thisArg) {
1185
1102
  const handlers = this.handlers;
1186
1103
 
1187
- const i = findSignalHandlerIndexByHandle(handlers, handler, thisArg);
1104
+ const sh = handlers.get(handler);
1188
1105
 
1189
- return i !== -1;
1106
+ if (sh === undefined) {
1107
+ return false;
1108
+ }
1109
+
1110
+ const existing = signal_handler_list_find(sh, handler, thisArg);
1111
+
1112
+ return existing !== null;
1190
1113
  }
1191
1114
 
1192
1115
  mute() {
@@ -1202,7 +1125,7 @@ class Signal {
1202
1125
  * @returns {boolean}
1203
1126
  */
1204
1127
  hasHandlers() {
1205
- return this.handlers.length > 0;
1128
+ return this.handlers.size > 0;
1206
1129
  }
1207
1130
 
1208
1131
  /**
@@ -1216,7 +1139,7 @@ class Signal {
1216
1139
 
1217
1140
  handler.setFlag(SignalHandlerFlags.RemoveAfterExecution);
1218
1141
 
1219
- this.handlers.push(handler);
1142
+ this.#add_handler(handler);
1220
1143
  }
1221
1144
 
1222
1145
  /**
@@ -1226,15 +1149,36 @@ class Signal {
1226
1149
  */
1227
1150
  add(h, context) {
1228
1151
 
1229
- // if (!ENV_PRODUCTION) {
1230
- // if (this.handlers.length + 1 === 100) {
1231
- // console.error(`Number of handlers has is 100 now, possible leak detected`);
1232
- // }
1233
- // }
1234
-
1235
1152
  const handler = new SignalHandler(h, context);
1236
1153
 
1237
- this.handlers.push(handler);
1154
+ this.#add_handler(handler);
1155
+
1156
+ }
1157
+
1158
+ /**
1159
+ *
1160
+ * @param {SignalHandler} handler
1161
+ */
1162
+ #add_handler(handler) {
1163
+
1164
+ const f = handler.handle;
1165
+ const first = this.handlers.get(f);
1166
+
1167
+ if (first === undefined) {
1168
+ this.handlers.set(f, handler);
1169
+ } else {
1170
+
1171
+ handler.next = first;
1172
+ this.handlers.set(f,handler);
1173
+
1174
+ // const last = signal_handler_list_last(first);
1175
+
1176
+ // last.next = handler;
1177
+
1178
+ // assert.ok(signal_handler_list_validate(first, console.error), 'invalid configuration');
1179
+
1180
+ }
1181
+
1238
1182
  }
1239
1183
 
1240
1184
  /**
@@ -1245,11 +1189,44 @@ class Signal {
1245
1189
  */
1246
1190
  remove(h, thisArg) {
1247
1191
 
1248
- if (thisArg === undefined) {
1249
- return removeHandlerByHandler(this, h);
1250
- } else {
1251
- return removeHandlerByHandlerAndContext(this, h, thisArg);
1192
+ const first = this.handlers.get(h);
1193
+
1194
+ if (first === undefined) {
1195
+ return false;
1196
+ }
1197
+
1198
+ if (first.handle === h && first.context === thisArg) {
1199
+ if (first.next === null) {
1200
+ this.handlers.delete(h);
1201
+ } else {
1202
+ this.handlers.set(h, first.next);
1203
+ // assert.ok(signal_handler_list_validate(first.next, console.error), 'invalid configuration');
1204
+ }
1205
+
1206
+ return true;
1207
+ }
1208
+
1209
+ let previous = first;
1210
+ let n = first.next;
1211
+
1212
+ while (n !== null) {
1213
+
1214
+ if (n.handle === h && n.context === thisArg) {
1215
+
1216
+ previous.next = n.next;
1217
+
1218
+ // assert.ok(signal_handler_list_validate(first, console.error), 'invalid configuration');
1219
+
1220
+ return true;
1221
+
1222
+ }
1223
+
1224
+ previous = n;
1225
+ n = n.next;
1226
+
1252
1227
  }
1228
+
1229
+ return false;
1253
1230
  }
1254
1231
 
1255
1232
  /**
@@ -1260,8 +1237,58 @@ class Signal {
1260
1237
  * @deprecated
1261
1238
  */
1262
1239
  removeAll() {
1263
- const handlers = this.handlers;
1264
- handlers.splice(0, handlers.length);
1240
+ this.handlers.clear();
1241
+ }
1242
+
1243
+ /**
1244
+ *
1245
+ * @param {SignalHandler} handler
1246
+ */
1247
+ #remove_handler_internal(handler) {
1248
+
1249
+ const first = this.handlers.get(handler.handle);
1250
+
1251
+ if (first === undefined) {
1252
+ // nothing
1253
+ return false;
1254
+ }
1255
+
1256
+ // special case for first
1257
+ if (first === handler) {
1258
+
1259
+ if (first.next === null) {
1260
+ // was the only one
1261
+ this.handlers.delete(handler.handle);
1262
+ } else {
1263
+ this.handlers.set(handler.handle, first.next);
1264
+ // assert.ok(signal_handler_list_validate(first.next, console.error), 'invalid configuration');
1265
+ }
1266
+
1267
+ return true;
1268
+ }
1269
+
1270
+ let previous = first;
1271
+ let n = first.next;
1272
+
1273
+ while (n !== null) {
1274
+
1275
+ const next = n.next;
1276
+
1277
+ if (n === handler) {
1278
+ previous.next = next;
1279
+
1280
+ // assert.ok(signal_handler_list_validate(first, console.error), 'invalid configuration');
1281
+
1282
+ return true;
1283
+ }
1284
+
1285
+ previous = n;
1286
+ n = next;
1287
+
1288
+ }
1289
+
1290
+ // not found
1291
+ return false;
1265
1292
  }
1266
1293
 
1267
1294
  /**
@@ -1274,10 +1301,38 @@ class Signal {
1274
1301
  return;
1275
1302
  }
1276
1303
 
1277
- dispatchViaProxy(this.handlers, args);
1304
+ const handlers = this.handlers;
1305
+
1306
+ for (const handle of handlers.values()) {
1307
+
1308
+ let _h = handle;
1309
+
1310
+ do {
1311
+
1312
+ const next = _h.next;
1313
+
1314
+ if (_h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1315
+ //handler should be cut
1316
+ this.#remove_handler_internal(_h);
1317
+ }
1318
+
1319
+ const _f = _h.handle;
1320
+
1321
+ try {
1322
+ _f.apply(_h.context, args);
1323
+ } catch (e) {
1324
+ }
1325
+
1326
+ _h = next;
1327
+
1328
+ } while (_h !== null);
1329
+
1330
+
1331
+ }
1278
1332
 
1279
1333
  }
1280
1334
 
1335
+
1281
1336
  /**
1282
1337
  * dispatch without a value.
1283
1338
  * Allows JS engine to optimize for monomorphic call sites
@@ -1290,41 +1345,33 @@ class Signal {
1290
1345
 
1291
1346
  const handlers = this.handlers;
1292
1347
 
1293
- const length = handlers.length;
1348
+ for (const handle of handlers.values()) {
1294
1349
 
1295
- const stack_pointer = dispatch_stack_top;
1296
- const stack_frame_end = stack_pointer + length;
1297
- dispatch_stack_top = stack_frame_end;
1350
+ let _h = handle;
1298
1351
 
1299
- let i, h;
1352
+ do {
1300
1353
 
1301
- // Copy handlers into a temp storage to preserve state during dispatch
1302
- for (i = 0; i < length; i++) {
1303
- //copy to proxy
1304
- dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
1305
- }
1354
+ const next = _h.next;
1306
1355
 
1307
- // Dispatch phase
1308
- for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
1309
- h = dispatch_stack[i];
1356
+ if (_h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1357
+ //handler should be cut
1358
+ this.#remove_handler_internal(_h);
1359
+ }
1310
1360
 
1311
- if (h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1312
- //handler should be cut
1313
- const p = handlers.indexOf(h);
1314
- handlers.splice(p, 1);
1315
- }
1361
+ const _f = _h.handle;
1362
+
1363
+ try {
1364
+ _f.call(_h.context);
1365
+ } catch (e) {
1366
+ }
1316
1367
 
1317
- const f = h.handle;
1368
+ _h = next;
1369
+
1370
+ } while (_h !== null);
1318
1371
 
1319
- try {
1320
- f.call(h.context);
1321
- } catch (e) {
1322
- }
1323
1372
 
1324
1373
  }
1325
1374
 
1326
- //drop stack frame
1327
- dispatch_stack_top = stack_pointer;
1328
1375
  }
1329
1376
 
1330
1377
  /**
@@ -1340,42 +1387,33 @@ class Signal {
1340
1387
 
1341
1388
  const handlers = this.handlers;
1342
1389
 
1343
- const length = handlers.length;
1390
+ for (const handle of handlers.values()) {
1344
1391
 
1345
- const stack_pointer = dispatch_stack_top;
1346
- const stack_frame_end = stack_pointer + length;
1347
- dispatch_stack_top = stack_frame_end;
1392
+ let _h = handle;
1348
1393
 
1394
+ do {
1349
1395
 
1350
- let i, h;
1396
+ const next = _h.next;
1351
1397
 
1352
- // Copy handlers into a temp storage to preserve state during dispatch
1353
- for (i = 0; i < length; i++) {
1354
- //copy to proxy
1355
- dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
1356
- }
1398
+ if (_h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1399
+ //handler should be cut
1400
+ this.#remove_handler_internal(_h);
1401
+ }
1357
1402
 
1358
- // Dispatch phase
1359
- for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
1360
- h = dispatch_stack[i];
1403
+ const _f = _h.handle;
1361
1404
 
1362
- if (h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1363
- //handler should be cut
1364
- const p = handlers.indexOf(h);
1365
- handlers.splice(p, 1);
1366
- }
1405
+ try {
1406
+ _f.call(_h.context, arg);
1407
+ } catch (e) {
1408
+ }
1367
1409
 
1368
- const f = h.handle;
1410
+ _h = next;
1411
+
1412
+ } while (_h !== null);
1369
1413
 
1370
- try {
1371
- f.call(h.context, arg);
1372
- } catch (e) {
1373
- }
1374
1414
 
1375
1415
  }
1376
1416
 
1377
- //drop stack frame
1378
- dispatch_stack_top = stack_pointer;
1379
1417
  }
1380
1418
 
1381
1419
  /**
@@ -1391,41 +1429,32 @@ class Signal {
1391
1429
 
1392
1430
  const handlers = this.handlers;
1393
1431
 
1394
- const length = handlers.length;
1432
+ for (const handle of handlers.values()) {
1395
1433
 
1396
- const stack_pointer = dispatch_stack_top;
1397
- const stack_frame_end = stack_pointer + length;
1398
- dispatch_stack_top = stack_frame_end;
1434
+ let _h = handle;
1399
1435
 
1400
- let i, h;
1436
+ do {
1401
1437
 
1402
- // Copy handlers into a temp storage to preserve state during dispatch
1403
- for (i = 0; i < length; i++) {
1404
- //copy to proxy
1405
- dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
1406
- }
1438
+ const next = _h.next;
1407
1439
 
1408
- // Dispatch phase
1409
- for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
1410
- h = dispatch_stack[i];
1440
+ if (_h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1441
+ //handler should be cut
1442
+ this.#remove_handler_internal(_h);
1443
+ }
1411
1444
 
1412
- if (h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1413
- //handler should be cut
1414
- const p = handlers.indexOf(h);
1415
- handlers.splice(p, 1);
1416
- }
1445
+ const _f = _h.handle;
1417
1446
 
1418
- const f = h.handle;
1447
+ try {
1448
+ _f.call(_h.context, a, b);
1449
+ } catch (e) {
1450
+ }
1419
1451
 
1420
- try {
1421
- f.call(h.context, a, b);
1422
- } catch (e) {
1423
- }
1452
+ _h = next;
1453
+
1454
+ } while (_h !== null);
1424
1455
 
1425
- }
1426
1456
 
1427
- //drop stack frame
1428
- dispatch_stack_top = stack_pointer;
1457
+ }
1429
1458
  }
1430
1459
 
1431
1460
  /**
@@ -1440,43 +1469,35 @@ class Signal {
1440
1469
  return;
1441
1470
  }
1442
1471
 
1472
+
1443
1473
  const handlers = this.handlers;
1444
1474
 
1445
- const length = handlers.length;
1475
+ for (const handle of handlers.values()) {
1446
1476
 
1447
- const stack_pointer = dispatch_stack_top;
1448
- const stack_frame_end = stack_pointer + length;
1449
- dispatch_stack_top = stack_frame_end;
1477
+ let _h = handle;
1450
1478
 
1451
- let i, h;
1479
+ do {
1452
1480
 
1453
- // Copy handlers into a temp storage to preserve state during dispatch
1454
- for (i = 0; i < length; i++) {
1455
- //copy to proxy
1456
- dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
1457
- }
1481
+ const next = _h.next;
1458
1482
 
1459
- // Dispatch phase
1460
- for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
1461
- h = dispatch_stack[i];
1483
+ if (_h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1484
+ //handler should be cut
1485
+ this.#remove_handler_internal(_h);
1486
+ }
1462
1487
 
1463
- if (h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1464
- //handler should be cut
1465
- const p = handlers.indexOf(h);
1466
- handlers.splice(p, 1);
1467
- }
1488
+ const _f = _h.handle;
1468
1489
 
1469
- const f = h.handle;
1490
+ try {
1491
+ _f.call(_h.context, a, b, c);
1492
+ } catch (e) {
1493
+ }
1470
1494
 
1471
- try {
1472
- f.call(h.context, a, b, c);
1473
- } catch (e) {
1474
- }
1495
+ _h = next;
1475
1496
 
1476
- }
1497
+ } while (_h !== null);
1477
1498
 
1478
- //drop stack frame
1479
- dispatch_stack_top = stack_pointer;
1499
+
1500
+ }
1480
1501
  }
1481
1502
 
1482
1503
  /**
@@ -1492,43 +1513,35 @@ class Signal {
1492
1513
  return;
1493
1514
  }
1494
1515
 
1516
+
1495
1517
  const handlers = this.handlers;
1496
1518
 
1497
- const length = handlers.length;
1519
+ for (const handle of handlers.values()) {
1498
1520
 
1499
- const stack_pointer = dispatch_stack_top;
1500
- const stack_frame_end = stack_pointer + length;
1501
- dispatch_stack_top = stack_frame_end;
1521
+ let _h = handle;
1502
1522
 
1503
- let i, h;
1523
+ do {
1504
1524
 
1505
- // Copy handlers into a temp storage to preserve state during dispatch
1506
- for (i = 0; i < length; i++) {
1507
- //copy to proxy
1508
- dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
1509
- }
1525
+ const next = _h.next;
1510
1526
 
1511
- // Dispatch phase
1512
- for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
1513
- h = dispatch_stack[i];
1527
+ if (_h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1528
+ //handler should be cut
1529
+ this.#remove_handler_internal(_h);
1530
+ }
1514
1531
 
1515
- if (h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1516
- //handler should be cut
1517
- const p = handlers.indexOf(h);
1518
- handlers.splice(p, 1);
1519
- }
1532
+ const _f = _h.handle;
1520
1533
 
1521
- const f = h.handle;
1534
+ try {
1535
+ _f.call(_h.context, a, b, c, d);
1536
+ } catch (e) {
1537
+ }
1522
1538
 
1523
- try {
1524
- f.call(h.context, a, b, c, d);
1525
- } catch (e) {
1526
- }
1539
+ _h = next;
1527
1540
 
1528
- }
1541
+ } while (_h !== null);
1529
1542
 
1530
- //drop stack frame
1531
- dispatch_stack_top = stack_pointer;
1543
+
1544
+ }
1532
1545
  }
1533
1546
 
1534
1547
  /**
@@ -1546,43 +1559,35 @@ class Signal {
1546
1559
  return;
1547
1560
  }
1548
1561
 
1562
+
1549
1563
  const handlers = this.handlers;
1550
1564
 
1551
- const length = handlers.length;
1565
+ for (const handle of handlers.values()) {
1552
1566
 
1553
- const stack_pointer = dispatch_stack_top;
1554
- const stack_frame_end = stack_pointer + length;
1555
- dispatch_stack_top = stack_frame_end;
1567
+ let _h = handle;
1556
1568
 
1557
- let i, h;
1569
+ do {
1558
1570
 
1559
- // Copy handlers into a temp storage to preserve state during dispatch
1560
- for (i = 0; i < length; i++) {
1561
- //copy to proxy
1562
- dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
1563
- }
1571
+ const next = _h.next;
1564
1572
 
1565
- // Dispatch phase
1566
- for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
1567
- h = dispatch_stack[i];
1573
+ if (_h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1574
+ //handler should be cut
1575
+ this.#remove_handler_internal(_h);
1576
+ }
1568
1577
 
1569
- if (h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1570
- //handler should be cut
1571
- const p = handlers.indexOf(h);
1572
- handlers.splice(p, 1);
1573
- }
1578
+ const _f = _h.handle;
1574
1579
 
1575
- const handle = h.handle;
1580
+ try {
1581
+ _f.call(_h.context, a, b, c, d, e, f);
1582
+ } catch (e) {
1583
+ }
1576
1584
 
1577
- try {
1578
- handle.call(h.context, a, b, c, d, e, f);
1579
- } catch (e) {
1580
- }
1585
+ _h = next;
1581
1586
 
1582
- }
1587
+ } while (_h !== null);
1583
1588
 
1584
- //drop stack frame
1585
- dispatch_stack_top = stack_pointer;
1589
+
1590
+ }
1586
1591
  }
1587
1592
 
1588
1593
  /**
@@ -1604,41 +1609,32 @@ class Signal {
1604
1609
 
1605
1610
  const handlers = this.handlers;
1606
1611
 
1607
- const length = handlers.length;
1612
+ for (const handle of handlers.values()) {
1608
1613
 
1609
- const stack_pointer = dispatch_stack_top;
1610
- const stack_frame_end = stack_pointer + length;
1611
- dispatch_stack_top = stack_frame_end;
1614
+ let _h = handle;
1612
1615
 
1613
- let i, handler;
1616
+ do {
1614
1617
 
1615
- // Copy handlers into a temp storage to preserve state during dispatch
1616
- for (i = 0; i < length; i++) {
1617
- //copy to proxy
1618
- dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
1619
- }
1618
+ const next = _h.next;
1620
1619
 
1621
- // Dispatch phase
1622
- for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
1623
- handler = dispatch_stack[i];
1620
+ if (_h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1621
+ //handler should be cut
1622
+ this.#remove_handler_internal(_h);
1623
+ }
1624
1624
 
1625
- if (handler.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
1626
- //handler should be cut
1627
- const p = handlers.indexOf(handler);
1628
- handlers.splice(p, 1);
1629
- }
1625
+ const _f = _h.handle;
1630
1626
 
1631
- const handle = handler.handle;
1627
+ try {
1628
+ _f.call(_h.context, a, b, c, d, e, f, g, h);
1629
+ } catch (e) {
1630
+ }
1632
1631
 
1633
- try {
1634
- handle.call(handler.context, a, b, c, d, e, f, g, h);
1635
- } catch (e) {
1636
- }
1632
+ _h = next;
1633
+
1634
+ } while (_h !== null);
1637
1635
 
1638
- }
1639
1636
 
1640
- //drop stack frame
1641
- dispatch_stack_top = stack_pointer;
1637
+ }
1642
1638
  }
1643
1639
 
1644
1640
  /**
@@ -1665,44 +1661,7 @@ class Signal {
1665
1661
  * @readonly
1666
1662
  * @type {boolean}
1667
1663
  */
1668
- Signal.prototype.isSignal = true;
1669
-
1670
- /**
1671
- *
1672
- * @param {Signal} signal
1673
- * @param {function} h
1674
- * @returns {boolean}
1675
- */
1676
- function removeHandlerByHandler(signal, h) {
1677
- const handlers = signal.handlers;
1678
- let i = findSignalHandlerIndexByHandle(handlers, h);
1679
-
1680
- if (i >= 0) {
1681
- handlers.splice(i, 1);
1682
- return true;
1683
- }
1684
-
1685
- return false;
1686
- }
1687
-
1688
- /**
1689
- *
1690
- * @param {Signal} signal
1691
- * @param {function} h
1692
- * @param {*} ctx
1693
- * @returns {boolean}
1694
- */
1695
- function removeHandlerByHandlerAndContext(signal, h, ctx) {
1696
- const handlers = signal.handlers;
1697
- const i = findSignalHandlerIndexByHandleAndContext(handlers, h, ctx);
1698
-
1699
- if (i >= 0) {
1700
- handlers.splice(i, 1);
1701
- return true;
1702
- }
1703
-
1704
- return false;
1705
- }
1664
+ Signal.prototype.isSignal = true;
1706
1665
 
1707
1666
  /**
1708
1667
  * Constrain a value to lie between specified min/max values
@@ -69810,7 +69769,6 @@ function frustum_from_camera(camera, result, update_projection = true) {
69810
69769
  result.setFromProjectionMatrix(matrix4);
69811
69770
  }
69812
69771
 
69813
- const m4_scratch = new Matrix4();
69814
69772
  const v3_scratch_0 = new Vector3$1();
69815
69773
  const v3_scratch_1 = new Vector3$1();
69816
69774
 
@@ -69819,7 +69777,7 @@ const v3_scratch_1 = new Vector3$1();
69819
69777
  * @param {Quaternion} output
69820
69778
  * @param {Quaternion} input
69821
69779
  */
69822
- function invertQuaternionOrientation(output, input) {
69780
+ function quaternion_invert_orientation(output, input) {
69823
69781
  const forward = v3_scratch_0;
69824
69782
  const up = v3_scratch_1;
69825
69783
 
@@ -69829,9 +69787,12 @@ function invertQuaternionOrientation(output, input) {
69829
69787
  forward.applyQuaternion(input);
69830
69788
  up.applyQuaternion(input);
69831
69789
 
69832
- m4_scratch.lookAt(Vector3$1.zero, forward, up);
69790
+ // point in the opposite direction
69791
+ forward.negate();
69833
69792
 
69834
- output.setFromRotationMatrix(m4_scratch);
69793
+ output.lookRotation(
69794
+ forward, up
69795
+ );
69835
69796
  }
69836
69797
 
69837
69798
  //
@@ -69907,7 +69868,7 @@ class Camera {
69907
69868
  * @param {Quaternion} input
69908
69869
  */
69909
69870
  getReciprocalRotation(output, input) {
69910
- invertQuaternionOrientation(output, input);
69871
+ quaternion_invert_orientation(output, input);
69911
69872
  }
69912
69873
 
69913
69874
  get clip_far() {
@@ -70186,6 +70147,8 @@ function update_camera_transform(camera) {
70186
70147
  threeUpdateTransform(three_camera);
70187
70148
  }
70188
70149
 
70150
+ const scratch_quat = new Quaternion$1();
70151
+
70189
70152
  /**
70190
70153
  *
70191
70154
  * @param {THREE.Camera} object
@@ -70198,7 +70161,11 @@ function three_camera_set_transform_rotation(object, rotation) {
70198
70161
  See: https://github.com/mrdoob/three.js/blob/412b99a7f26e117ea97f40eb53d010ab81aa3279/src/core/Object3D.js#L282
70199
70162
  */
70200
70163
 
70201
- invertQuaternionOrientation(object.quaternion, rotation);
70164
+ quaternion_invert_orientation(scratch_quat, rotation);
70165
+
70166
+ object.quaternion.set(
70167
+ scratch_quat.x, scratch_quat.y, scratch_quat.z, scratch_quat.w
70168
+ );
70202
70169
 
70203
70170
  object.rotation.setFromQuaternion(object.quaternion);
70204
70171
 
@@ -93739,6 +93706,55 @@ function promiseTask(promise, name) {
93739
93706
  });
93740
93707
  }
93741
93708
 
93709
+ /**
93710
+ *
93711
+ * @param {SignalHandler[]} handlers
93712
+ * @param {function} f
93713
+ * @param {*} [thisArg]
93714
+ * @returns {number} index of the handler, or -1 if not found
93715
+ */
93716
+ function findSignalHandlerIndexByHandle(handlers, f, thisArg) {
93717
+ const l = handlers.length;
93718
+
93719
+ for (let i = 0; i < l; i++) {
93720
+ const signalHandler = handlers[i];
93721
+
93722
+ if (signalHandler.handle === f) {
93723
+
93724
+ if (thisArg !== undefined && thisArg !== signalHandler.context) {
93725
+ //context variable doesn't match
93726
+ continue;
93727
+ }
93728
+
93729
+ return i;
93730
+ }
93731
+ }
93732
+
93733
+ return -1;
93734
+ }
93735
+
93736
+ /**
93737
+ *
93738
+ * @param {SignalHandler[]} handlers
93739
+ * @param {function} f
93740
+ * @param {*} ctx
93741
+ * @returns {number} index of the handler, or -1 if not found
93742
+ */
93743
+ function findSignalHandlerIndexByHandleAndContext(handlers, f, ctx) {
93744
+ const l = handlers.length;
93745
+
93746
+ for (let i = 0; i < l; i++) {
93747
+ const handler = handlers[i];
93748
+
93749
+ if (handler.handle === f && handler.context === ctx) {
93750
+ return i;
93751
+ }
93752
+
93753
+ }
93754
+
93755
+ return -1;
93756
+ }
93757
+
93742
93758
  /**
93743
93759
  * Matches a supplies component mask against a larger set
93744
93760
  * @param {BitSet} componentOccupancy
@@ -96843,6 +96859,62 @@ class SoundEngine {
96843
96859
  }
96844
96860
  }
96845
96861
 
96862
+ /**
96863
+ * Common dispatch stack
96864
+ * @readonly
96865
+ * @type {SignalHandler[]}
96866
+ */
96867
+ const dispatch_stack = [];
96868
+ let dispatch_stack_top = 0;
96869
+
96870
+ /**
96871
+ *
96872
+ * @param {function} f
96873
+ * @param {*} context
96874
+ * @param {Array} args
96875
+ */
96876
+ function dispatchCallback(f, context, args) {
96877
+
96878
+ try {
96879
+ f.apply(context, args);
96880
+ } catch (e) {
96881
+ }
96882
+ }
96883
+
96884
+ /**
96885
+ *
96886
+ * @param {SignalHandler[]} handlers
96887
+ * @param {Array} [args]
96888
+ */
96889
+ function dispatchViaProxy(handlers, args) {
96890
+ const length = handlers.length;
96891
+
96892
+ const stack_pointer = dispatch_stack_top;
96893
+ const stack_frame_end = stack_pointer + length;
96894
+ dispatch_stack_top = stack_frame_end;
96895
+
96896
+ let i, h;
96897
+ for (i = 0; i < length; i++) {
96898
+ //copy to proxy
96899
+ dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
96900
+ }
96901
+
96902
+ for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
96903
+ h = dispatch_stack[i];
96904
+
96905
+ if (h.getFlag(SignalHandlerFlags.RemoveAfterExecution)) {
96906
+ //handler should be cut
96907
+ const p = handlers.indexOf(h);
96908
+ handlers.splice(p, 1);
96909
+ }
96910
+
96911
+ dispatchCallback(h.handle, h.context, args);
96912
+ }
96913
+
96914
+ //drop stack frame
96915
+ dispatch_stack_top = stack_pointer;
96916
+ }
96917
+
96846
96918
  class SimpleStateMachineDescription {
96847
96919
  constructor() {
96848
96920
  this.__states = new BitSet();