@woosh/meep-engine 2.110.15 → 2.111.1

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