UNPKG

the-world-engine

Version:

three.js based, unity like game engine for browser

1,475 lines (1,466 loc) 510 kB
(function(t, i) { typeof exports === "object" && typeof module !== "undefined" ? i(exports, require("three/src/Three"), require("three/src/math/MathUtils"), require("b2d"), require("three/examples/jsm/postprocessing/EffectComposer"), require("three/examples/jsm/postprocessing/RenderPass")) : typeof define === "function" && define.amd ? define("TWE", [ "exports", "three/src/Three", "three/src/math/MathUtils", "b2d", "three/examples/jsm/postprocessing/EffectComposer", "three/examples/jsm/postprocessing/RenderPass" ], i) : (t = typeof globalThis !== "undefined" ? globalThis : t || self, i(t.TWE = {}, t.THREE, t.THREE.MathUtils, t.B2D, t.EffectComposer, t.RenderPass)); })(this, (function(t, i, s, h, r, n) { "use strict"; (function() { function e() {} const t = { AABB: e, Abs: e, Acos: e, Alloc: e, AngularStiffness: e, AreaJoint: e, AreaJointDef: e, Asin: e, Assert: e, Atan2: e, BlockAllocator: e, Body: e, BodyDef: e, BroadPhase: e, BuoyancyController: e, CalculateParticleIterations: e, ChainAndCircleContact: e, ChainAndPolygonContact: e, ChainShape: e, CircleContact: e, CircleShape: e, Clamp: e, ClipSegmentToLine: e, ClipVertex: e, CollideCircles: e, CollideEdgeAndCircle: e, CollideEdgeAndPolygon: e, CollidePolygonAndCircle: e, CollidePolygons: e, Color: e, ConstantAccelController: e, ConstantForceController: e, Contact: e, ContactEdge: e, ContactFactory: e, ContactFeature: e, ContactFilter: e, ContactID: e, ContactImpulse: e, ContactListener: e, ContactManager: e, ContactPositionConstraint: e, ContactRegister: e, ContactSolver: e, ContactSolverDef: e, ContactVelocityConstraint: e, Controller: e, ControllerEdge: e, Cos: e, Counter: e, DegToRad: e, DestructionListener: e, Distance: e, DistanceInput: e, DistanceJoint: e, DistanceJointDef: e, DistanceOutput: e, DistanceProxy: e, Draw: e, DynamicTree: e, EdgeAndCircleContact: e, EdgeAndPolygonContact: e, EdgeShape: e, Filter: e, Fixture: e, FixtureDef: e, FixtureParticleQueryCallback: e, FixtureProxy: e, Free: e, FrictionJoint: e, FrictionJointDef: e, GearJoint: e, GearJointDef: e, GetPointStates: e, GravityController: e, GrowableBuffer: e, GrowableStack: e, InvSqrt: e, IsPowerOfTwo: e, IsValid: e, Island: e, Jacobian: e, Joint: e, JointDef: e, JointEdge: e, LinearStiffness: e, Log: e, MakeArray: e, MakeNullArray: e, MakeNumberArray: e, Manifold: e, ManifoldPoint: e, MassData: e, Mat22: e, Mat33: e, Max: e, Maybe: e, Min: e, MixFriction: e, MixRestitution: e, MixRestitutionThreshold: e, MotorJoint: e, MotorJointDef: e, MouseJoint: e, MouseJointDef: e, NextPowerOfTwo: e, Pair: e, ParseInt: e, ParseUInt: e, ParticleBodyContact: e, ParticleContact: e, ParticleDef: e, ParticleGroup: e, ParticleGroupDef: e, ParticleHandle: e, ParticlePair: e, ParticlePairSet: e, ParticleSystem: e, ParticleSystemDef: e, ParticleSystem_CompositeShape: e, ParticleSystem_ConnectionFilter: e, ParticleSystem_DestroyParticlesInShapeCallback: e, ParticleSystem_FixedSetAllocator: e, ParticleSystem_FixtureParticle: e, ParticleSystem_FixtureParticleSet: e, ParticleSystem_InsideBoundsEnumerator: e, ParticleSystem_JoinParticleGroupsFilter: e, ParticleSystem_ParticleListNode: e, ParticleSystem_ParticlePair: e, ParticleSystem_Proxy: e, ParticleSystem_ReactiveFilter: e, ParticleSystem_SolveCollisionCallback: e, ParticleSystem_UpdateBodyContactsCallback: e, ParticleSystem_UserOverridableBuffer: e, ParticleTriad: e, PolygonAndCircleContact: e, PolygonContact: e, PolygonShape: e, Position: e, PositionSolverManifold: e, Pow: e, PrismaticJoint: e, PrismaticJointDef: e, Profile: e, PulleyJoint: e, PulleyJointDef: e, QueryCallback: e, RadToDeg: e, Random: e, RandomRange: e, RayCastCallback: e, RayCastInput: e, RayCastOutput: e, RevoluteJoint: e, RevoluteJointDef: e, Rope: e, RopeDef: e, RopeTuning: e, Rot: e, SeparationFunction: e, Shape: e, ShapeCast: e, ShapeCastInput: e, ShapeCastOutput: e, Simplex: e, SimplexCache: e, SimplexVertex: e, Sin: e, SolverData: e, Sq: e, Sqrt: e, StackAllocator: e, StackQueue: e, Swap: e, Sweep: e, TOIInput: e, TOIOutput: e, TensorDampingController: e, TestOverlapAABB: e, TestOverlapShape: e, TimeOfImpact: e, TimeStep: e, Timer: e, Transform: e, TreeNode: e, Vec2: e, Vec2_zero: e, Vec3: e, Velocity: e, VelocityConstraintPoint: e, Version: e, VoronoiDiagram: e, VoronoiDiagram_Generator: e, VoronoiDiagram_Task: e, WeldJoint: e, WeldJointDef: e, WheelJoint: e, WheelJointDef: e, World: e, WorldManifold: e, _180_over_pi: e, _pi_over_180: e, aabbExtension: e, aabbMultiplier: e, angularSleepTolerance: e, angularSlop: e, barrierCollisionTime: e, baumgarte: e, branch: e, commit: e, dynamicBody: e, epsilon: e, epsilon_sq: e, get_g_blockSolve: e, gjk_reset: e, invalidParticleIndex: e, kinematicBody: e, lengthUnitsPerMeter: e, linearSleepTolerance: e, linearSlop: e, maxAngularCorrection: e, maxFloat: e, maxLinearCorrection: e, maxManifoldPoints: e, maxParticleForce: e, maxParticleIndex: e, maxParticlePressure: e, maxPolygonVertices: e, maxRotation: e, maxRotationSquared: e, maxSubSteps: e, maxTOIContacts: e, maxTranslation: e, maxTranslationSquared: e, maxTriadDistance: e, maxTriadDistanceSquared: e, minParticleSystemBufferCapacity: e, minParticleWeight: e, minPulleyLength: e, particleStride: e, pbdAngleBendingModel: e, pbdDistanceBendingModel: e, pbdHeightBendingModel: e, pbdStretchingModel: e, pbdTriangleBendingModel: e, pi: e, polygonRadius: e, set_g_blockSolve: e, springAngleBendingModel: e, staticBody: e, timeToSleep: e, toiBaumgarte: e, toi_reset: e, two_pi: e, version: e, xpbdAngleBendingModel: e, xpbdStretchingModel: e }; if (h === undefined) { h = t; } })(); var o = this && this.t || function() { var extendStatics = function(t, i) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, i) { t.__proto__ = i; } || function(t, i) { for (var s in i) if (Object.prototype.hasOwnProperty.call(i, s)) t[s] = i[s]; }; return extendStatics(t, i); }; return function(t, i) { if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null"); extendStatics(t, i); function __() { this.constructor = t; } t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __); }; }(); var a = function() { function ContainerIterator(t) { if (t === void 0) { t = 0; } this.iteratorType = t; } ContainerIterator.prototype.equals = function(t) { return this.o === t.o; }; return ContainerIterator; }(); var l = function() { function Base() { this.i = 0; } Object.defineProperty(Base.prototype, "length", { get: function() { return this.i; }, enumerable: false, configurable: true }); Base.prototype.size = function() { return this.i; }; Base.prototype.empty = function() { return this.i === 0; }; return Base; }(); var u = function(t) { o(Container, t); function Container() { return t !== null && t.apply(this, arguments) || this; } return Container; }(l); function throwIteratorAccessError() { throw new RangeError("Iterator access denied!"); } var c = this && this.t || function() { var extendStatics = function(t, i) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, i) { t.__proto__ = i; } || function(t, i) { for (var s in i) if (Object.prototype.hasOwnProperty.call(i, s)) t[s] = i[s]; }; return extendStatics(t, i); }; return function(t, i) { if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null"); extendStatics(t, i); function __() { this.constructor = t; } t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __); }; }(); var f = function() { function TreeNode(t, i, s) { if (s === void 0) { s = 1; } this.Y = undefined; this.Z = undefined; this.tt = undefined; this.p = t; this.H = i; this.ee = s; } TreeNode.prototype.L = function() { var t = this; var i = t.tt.tt === t; if (i && t.ee === 1) { t = t.Z; } else if (t.Y) { t = t.Y; while (t.Z) { t = t.Z; } } else { if (i) { return t.tt; } var s = t.tt; while (s.Y === t) { t = s; s = t.tt; } t = s; } return t; }; TreeNode.prototype.m = function() { var t = this; if (t.Z) { t = t.Z; while (t.Y) { t = t.Y; } return t; } else { var i = t.tt; while (i.Z === t) { t = i; i = t.tt; } if (t.Z !== i) { return i; } else return t; } }; TreeNode.prototype.te = function() { var t = this.tt; var i = this.Z; var s = i.Y; if (t.tt === this) t.tt = i; else if (t.Y === this) t.Y = i; else t.Z = i; i.tt = t; i.Y = this; this.tt = i; this.Z = s; if (s) s.tt = this; return i; }; TreeNode.prototype.ne = function() { var t = this.tt; var i = this.Y; var s = i.Z; if (t.tt === this) t.tt = i; else if (t.Y === this) t.Y = i; else t.Z = i; i.tt = t; i.Z = this; this.tt = i; this.Y = s; if (s) s.tt = this; return i; }; return TreeNode; }(); var d = function(t) { c(TreeNodeEnableIndex, t); function TreeNodeEnableIndex() { var i = t !== null && t.apply(this, arguments) || this; i.rt = 1; return i; } TreeNodeEnableIndex.prototype.te = function() { var i = t.prototype.te.call(this); this.ie(); i.ie(); return i; }; TreeNodeEnableIndex.prototype.ne = function() { var i = t.prototype.ne.call(this); this.ie(); i.ie(); return i; }; TreeNodeEnableIndex.prototype.ie = function() { this.rt = 1; if (this.Y) { this.rt += this.Y.rt; } if (this.Z) { this.rt += this.Z.rt; } }; return TreeNodeEnableIndex; }(f); var g = this && this.t || function() { var extendStatics = function(t, i) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, i) { t.__proto__ = i; } || function(t, i) { for (var s in i) if (Object.prototype.hasOwnProperty.call(i, s)) t[s] = i[s]; }; return extendStatics(t, i); }; return function(t, i) { if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null"); extendStatics(t, i); function __() { this.constructor = t; } t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __); }; }(); var m = function(t) { g(TreeContainer, t); function TreeContainer(i, s) { if (i === void 0) { i = function(t, i) { if (t < i) return -1; if (t > i) return 1; return 0; }; } if (s === void 0) { s = false; } var h = t.call(this) || this; h.rr = undefined; h.j = i; h.enableIndex = s; h.re = s ? d : f; h.u = new h.re; return h; } TreeContainer.prototype.$ = function(t, i) { var s = this.u; while (t) { var h = this.j(t.p, i); if (h < 0) { t = t.Z; } else if (h > 0) { s = t; t = t.Y; } else return t; } return s; }; TreeContainer.prototype.tr = function(t, i) { var s = this.u; while (t) { var h = this.j(t.p, i); if (h <= 0) { t = t.Z; } else { s = t; t = t.Y; } } return s; }; TreeContainer.prototype.er = function(t, i) { var s = this.u; while (t) { var h = this.j(t.p, i); if (h < 0) { s = t; t = t.Z; } else if (h > 0) { t = t.Y; } else return t; } return s; }; TreeContainer.prototype.nr = function(t, i) { var s = this.u; while (t) { var h = this.j(t.p, i); if (h < 0) { s = t; t = t.Z; } else { t = t.Y; } } return s; }; TreeContainer.prototype.se = function(t) { while (true) { var i = t.tt; if (i === this.u) return; if (t.ee === 1) { t.ee = 0; return; } if (t === i.Y) { var s = i.Z; if (s.ee === 1) { s.ee = 0; i.ee = 1; if (i === this.rr) { this.rr = i.te(); } else i.te(); } else { if (s.Z && s.Z.ee === 1) { s.ee = i.ee; i.ee = 0; s.Z.ee = 0; if (i === this.rr) { this.rr = i.te(); } else i.te(); return; } else if (s.Y && s.Y.ee === 1) { s.ee = 1; s.Y.ee = 0; s.ne(); } else { s.ee = 1; t = i; } } } else { var s = i.Y; if (s.ee === 1) { s.ee = 0; i.ee = 1; if (i === this.rr) { this.rr = i.ne(); } else i.ne(); } else { if (s.Y && s.Y.ee === 1) { s.ee = i.ee; i.ee = 0; s.Y.ee = 0; if (i === this.rr) { this.rr = i.ne(); } else i.ne(); return; } else if (s.Z && s.Z.ee === 1) { s.ee = 1; s.Z.ee = 0; s.te(); } else { s.ee = 1; t = i; } } } } }; TreeContainer.prototype.U = function(t) { if (this.i === 1) { this.clear(); return; } var i = t; while (i.Y || i.Z) { if (i.Z) { i = i.Z; while (i.Y) i = i.Y; } else { i = i.Y; } var s = t.p; t.p = i.p; i.p = s; var h = t.H; t.H = i.H; i.H = h; t = i; } if (this.u.Y === i) { this.u.Y = i.tt; } else if (this.u.Z === i) { this.u.Z = i.tt; } this.se(i); var r = i.tt; if (i === r.Y) { r.Y = undefined; } else r.Z = undefined; this.i -= 1; this.rr.ee = 0; if (this.enableIndex) { while (r !== this.u) { r.rt -= 1; r = r.tt; } } }; TreeContainer.prototype.ir = function(t) { var i = typeof t === "number" ? t : undefined; var s = typeof t === "function" ? t : undefined; var h = typeof t === "undefined" ? [] : undefined; var r = 0; var n = this.rr; var o = []; while (o.length || n) { if (n) { o.push(n); n = n.Y; } else { n = o.pop(); if (r === i) return n; h && h.push(n); s && s(n, r, this); r += 1; n = n.Z; } } return h; }; TreeContainer.prototype.fe = function(t) { while (true) { var i = t.tt; if (i.ee === 0) return; var s = i.tt; if (i === s.Y) { var h = s.Z; if (h && h.ee === 1) { h.ee = i.ee = 0; if (s === this.rr) return; s.ee = 1; t = s; continue; } else if (t === i.Z) { t.ee = 0; if (t.Y) { t.Y.tt = i; } if (t.Z) { t.Z.tt = s; } i.Z = t.Y; s.Y = t.Z; t.Y = i; t.Z = s; if (s === this.rr) { this.rr = t; this.u.tt = t; } else { var r = s.tt; if (r.Y === s) { r.Y = t; } else r.Z = t; } t.tt = s.tt; i.tt = t; s.tt = t; s.ee = 1; } else { i.ee = 0; if (s === this.rr) { this.rr = s.ne(); } else s.ne(); s.ee = 1; return; } } else { var h = s.Y; if (h && h.ee === 1) { h.ee = i.ee = 0; if (s === this.rr) return; s.ee = 1; t = s; continue; } else if (t === i.Y) { t.ee = 0; if (t.Y) { t.Y.tt = s; } if (t.Z) { t.Z.tt = i; } s.Z = t.Y; i.Y = t.Z; t.Y = s; t.Z = i; if (s === this.rr) { this.rr = t; this.u.tt = t; } else { var r = s.tt; if (r.Y === s) { r.Y = t; } else r.Z = t; } t.tt = s.tt; i.tt = t; s.tt = t; s.ee = 1; } else { i.ee = 0; if (s === this.rr) { this.rr = s.te(); } else s.te(); s.ee = 1; return; } } if (this.enableIndex) { i.ie(); s.ie(); t.ie(); } return; } }; TreeContainer.prototype.v = function(t, i, s) { if (this.rr === undefined) { this.i += 1; this.rr = new this.re(t, i, 0); this.rr.tt = this.u; this.u.tt = this.u.Y = this.u.Z = this.rr; return this.i; } var h; var r = this.u.Y; var n = this.j(r.p, t); if (n === 0) { r.H = i; return this.i; } else if (n > 0) { r.Y = new this.re(t, i); r.Y.tt = r; h = r.Y; this.u.Y = h; } else { var o = this.u.Z; var a = this.j(o.p, t); if (a === 0) { o.H = i; return this.i; } else if (a < 0) { o.Z = new this.re(t, i); o.Z.tt = o; h = o.Z; this.u.Z = h; } else { if (s !== undefined) { var l = s.o; if (l !== this.u) { var u = this.j(l.p, t); if (u === 0) { l.H = i; return this.i; } else if (u > 0) { var c = l.L(); var f = this.j(c.p, t); if (f === 0) { c.H = i; return this.i; } else if (f < 0) { h = new this.re(t, i); if (c.Z === undefined) { c.Z = h; h.tt = c; } else { l.Y = h; h.tt = l; } } } } } if (h === undefined) { h = this.rr; while (true) { var d = this.j(h.p, t); if (d > 0) { if (h.Y === undefined) { h.Y = new this.re(t, i); h.Y.tt = h; h = h.Y; break; } h = h.Y; } else if (d < 0) { if (h.Z === undefined) { h.Z = new this.re(t, i); h.Z.tt = h; h = h.Z; break; } h = h.Z; } else { h.H = i; return this.i; } } } } } if (this.enableIndex) { var g = h.tt; while (g !== this.u) { g.rt += 1; g = g.tt; } } this.fe(h); this.i += 1; return this.i; }; TreeContainer.prototype.ar = function(t, i) { while (t) { var s = this.j(t.p, i); if (s < 0) { t = t.Z; } else if (s > 0) { t = t.Y; } else return t; } return t || this.u; }; TreeContainer.prototype.clear = function() { this.i = 0; this.rr = undefined; this.u.tt = undefined; this.u.Y = this.u.Z = undefined; }; TreeContainer.prototype.updateKeyByIterator = function(t, i) { var s = t.o; if (s === this.u) { throwIteratorAccessError(); } if (this.i === 1) { s.p = i; return true; } var h = s.m().p; if (s === this.u.Y) { if (this.j(h, i) > 0) { s.p = i; return true; } return false; } var r = s.L().p; if (s === this.u.Z) { if (this.j(r, i) < 0) { s.p = i; return true; } return false; } if (this.j(r, i) >= 0 || this.j(h, i) <= 0) return false; s.p = i; return true; }; TreeContainer.prototype.eraseElementByPos = function(t) { if (t < 0 || t > this.i - 1) { throw new RangeError; } var i = this.ir(t); this.U(i); return this.i; }; TreeContainer.prototype.eraseElementByKey = function(t) { if (this.i === 0) return false; var i = this.ar(this.rr, t); if (i === this.u) return false; this.U(i); return true; }; TreeContainer.prototype.eraseElementByIterator = function(t) { var i = t.o; if (i === this.u) { throwIteratorAccessError(); } var s = i.Z === undefined; var h = t.iteratorType === 0; if (h) { if (s) t.next(); } else { if (!s || i.Y === undefined) t.next(); } this.U(i); return t; }; TreeContainer.prototype.getHeight = function() { if (this.i === 0) return 0; function traversal(t) { if (!t) return 0; return Math.max(traversal(t.Y), traversal(t.Z)) + 1; } return traversal(this.rr); }; return TreeContainer; }(u); var p = m; var C = this && this.t || function() { var extendStatics = function(t, i) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, i) { t.__proto__ = i; } || function(t, i) { for (var s in i) if (Object.prototype.hasOwnProperty.call(i, s)) t[s] = i[s]; }; return extendStatics(t, i); }; return function(t, i) { if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null"); extendStatics(t, i); function __() { this.constructor = t; } t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __); }; }(); var w = function(t) { C(TreeIterator, t); function TreeIterator(i, s, h) { var r = t.call(this, h) || this; r.o = i; r.u = s; if (r.iteratorType === 0) { r.pre = function() { if (this.o === this.u.Y) { throwIteratorAccessError(); } this.o = this.o.L(); return this; }; r.next = function() { if (this.o === this.u) { throwIteratorAccessError(); } this.o = this.o.m(); return this; }; } else { r.pre = function() { if (this.o === this.u.Z) { throwIteratorAccessError(); } this.o = this.o.m(); return this; }; r.next = function() { if (this.o === this.u) { throwIteratorAccessError(); } this.o = this.o.L(); return this; }; } return r; } Object.defineProperty(TreeIterator.prototype, "index", { get: function() { var t = this.o; var i = this.u.tt; if (t === this.u) { if (i) { return i.rt - 1; } return 0; } var s = 0; if (t.Y) { s += t.Y.rt; } while (t !== i) { var h = t.tt; if (t === h.Z) { s += 1; if (h.Y) { s += h.Y.rt; } } t = h; } return s; }, enumerable: false, configurable: true }); TreeIterator.prototype.isAccessible = function() { return this.o !== this.u; }; return TreeIterator; }(a); var v = w; var b = this && this.t || function() { var extendStatics = function(t, i) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, i) { t.__proto__ = i; } || function(t, i) { for (var s in i) if (Object.prototype.hasOwnProperty.call(i, s)) t[s] = i[s]; }; return extendStatics(t, i); }; return function(t, i) { if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null"); extendStatics(t, i); function __() { this.constructor = t; } t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __); }; }(); var y = this && this.h || function(t, i) { var s = { label: 0, sent: function() { if (n[0] & 1) throw n[1]; return n[1]; }, trys: [], ops: [] }, h, r, n, o; return o = { next: verb(0), throw: verb(1), return: verb(2) }, typeof Symbol === "function" && (o[Symbol.iterator] = function() { return this; }), o; function verb(t) { return function(i) { return step([ t, i ]); }; } function step(o) { if (h) throw new TypeError("Generator is already executing."); while (s) try { if (h = 1, r && (n = o[0] & 2 ? r["return"] : o[0] ? r["throw"] || ((n = r["return"]) && n.call(r), 0) : r.next) && !(n = n.call(r, o[1])).done) return n; if (r = 0, n) o = [ o[0] & 2, n.value ]; switch (o[0]) { case 0: case 1: n = o; break; case 4: s.label++; return { value: o[1], done: false }; case 5: s.label++; r = o[1]; o = [ 0 ]; continue; case 7: o = s.ops.pop(); s.trys.pop(); continue; default: if (!(n = s.trys, n = n.length > 0 && n[n.length - 1]) && (o[0] === 6 || o[0] === 2)) { s = 0; continue; } if (o[0] === 3 && (!n || o[1] > n[0] && o[1] < n[3])) { s.label = o[1]; break; } if (o[0] === 6 && s.label < n[1]) { s.label = n[1]; n = o; break; } if (n && s.label < n[2]) { s.label = n[2]; s.ops.push(o); break; } if (n[2]) s.ops.pop(); s.trys.pop(); continue; } o = i.call(t, s); } catch (t) { o = [ 6, t ]; r = 0; } finally { h = n = 0; } if (o[0] & 5) throw o[1]; return { value: o[0] ? o[1] : void 0, done: true }; } }; var M = function(t) { b(OrderedSetIterator, t); function OrderedSetIterator(i, s, h, r) { var n = t.call(this, i, s, r) || this; n.container = h; return n; } Object.defineProperty(OrderedSetIterator.prototype, "pointer", { get: function() { if (this.o === this.u) { throwIteratorAccessError(); } return this.o.p; }, enumerable: false, configurable: true }); OrderedSetIterator.prototype.copy = function() { return new OrderedSetIterator(this.o, this.u, this.container, this.iteratorType); }; return OrderedSetIterator; }(v); var x = function(t) { b(OrderedSet, t); function OrderedSet(i, s, h) { if (i === void 0) { i = []; } var r = t.call(this, s, h) || this; var n = r; i.forEach((function(t) { n.insert(t); })); return r; } OrderedSet.prototype.begin = function() { return new M(this.u.Y || this.u, this.u, this); }; OrderedSet.prototype.end = function() { return new M(this.u, this.u, this); }; OrderedSet.prototype.rBegin = function() { return new M(this.u.Z || this.u, this.u, this, 1); }; OrderedSet.prototype.rEnd = function() { return new M(this.u, this.u, this, 1); }; OrderedSet.prototype.front = function() { return this.u.Y ? this.u.Y.p : undefined; }; OrderedSet.prototype.back = function() { return this.u.Z ? this.u.Z.p : undefined; }; OrderedSet.prototype.lowerBound = function(t) { var i = this.$(this.rr, t); return new M(i, this.u, this); }; OrderedSet.prototype.upperBound = function(t) { var i = this.tr(this.rr, t); return new M(i, this.u, this); }; OrderedSet.prototype.reverseLowerBound = function(t) { var i = this.er(this.rr, t); return new M(i, this.u, this); }; OrderedSet.prototype.reverseUpperBound = function(t) { var i = this.nr(this.rr, t); return new M(i, this.u, this); }; OrderedSet.prototype.forEach = function(t) { this.ir((function(i, s, h) { t(i.p, s, h); })); }; OrderedSet.prototype.insert = function(t, i) { return this.v(t, undefined, i); }; OrderedSet.prototype.getElementByPos = function(t) { if (t < 0 || t > this.i - 1) { throw new RangeError; } var i = this.ir(t); return i.p; }; OrderedSet.prototype.find = function(t) { var i = this.ar(this.rr, t); return new M(i, this.u, this); }; OrderedSet.prototype.union = function(t) { var i = this; t.forEach((function(t) { i.insert(t); })); return this.i; }; OrderedSet.prototype[Symbol.iterator] = function() { var t, i, s; return y(this, (function(h) { switch (h.label) { case 0: t = this.i; i = this.ir(); s = 0; h.label = 1; case 1: if (!(s < t)) return [ 3, 4 ]; return [ 4, i[s].p ]; case 2: h.sent(); h.label = 3; case 3: ++s; return [ 3, 1 ]; case 4: return [ 2 ]; } })); }; return OrderedSet; }(p); var S = x; class MutIteratableCollection { constructor(t) { this._iterateCollection = null; this._collection = new S(undefined, t); this._insertBuffer = new S(undefined, t); this._insertBufferSwap = new S(undefined, t); this._deleteBuffer = new S(undefined, t); } get size() { return this._collection.size(); } insert(t) { t.isRemoved = false; if (this._iterateCollection !== null) { this._insertBuffer.insert(t); this._deleteBuffer.eraseElementByKey(t); } else this._collection.insert(t); } delete(t) { if (this._iterateCollection !== null) { t.isRemoved = true; this._insertBuffer.eraseElementByKey(t); this._deleteBuffer.insert(t); } else this._collection.eraseElementByKey(t); } clear() { this._collection.clear(); this._insertBuffer.clear(); this._deleteBuffer.clear(); } forEach(t) { this._iterateCollection = this._collection; this._iterateCollection.forEach((i => { if (!i.isRemoved) t(i); })); do { this._iterateCollection = this.flushBuffer(); this._iterateCollection.forEach((i => { if (!i.isRemoved) t(i); })); } while (0 < this._insertBuffer.size() || 0 < this._deleteBuffer.size()); this._iterateCollection = null; } flushBuffer() { this._iterateCollection = null; this._deleteBuffer.forEach((t => this.delete(t))); this._insertBuffer.forEach((t => this.insert(t))); const t = this._insertBuffer; this._insertBuffer = this._insertBufferSwap; this._insertBufferSwap = t; this._insertBuffer.clear(); this._deleteBuffer.clear(); return t; } } class ComponentEvent { constructor(t, i, s, h) { this.isRemoved = false; this._priority = s; this._eventId = t.generateEventId(); this._componentExecutionOrder = h; this._eventFunc = i; } static createAwakeEvent(t, i) { return new ComponentEvent(t, i, 0, 0); } static createStartEvent(t, i, s) { return new ComponentEvent(t, i, 2, s); } static createUpdateEvent(t, i, s) { return new ComponentEvent(t, i, 3, s); } static createOnEnableEvent(t, i, s) { return new ComponentEvent(t, i, 1, s); } static createOnDisableEvent(t, i, s) { return new ComponentEvent(t, i, 1, s); } static createOnDestroyEvent(t, i, s) { return new ComponentEvent(t, i, 4, s); } static createOnCollisionEnter2DEvent(t, i, s) { return new ComponentEvent(t, i, 1, s); } static createOnCollisionStay2DEvent(t, i, s) { return new ComponentEvent(t, i, 1, s); } static createOnCollisionExit2DEvent(t, i, s) { return new ComponentEvent(t, i, 1, s); } static createOnTriggerEnter2DEvent(t, i, s) { return new ComponentEvent(t, i, 1, s); } static createOnTriggerStay2DEvent(t, i, s) { return new ComponentEvent(t, i, 1, s); } static createOnTriggerExit2DEvent(t, i, s) { return new ComponentEvent(t, i, 1, s); } get invoke() { return this._eventFunc; } static comparator(t, i) { if (t._priority === i._priority) { if (t._componentExecutionOrder === i._componentExecutionOrder) { return t._eventId - i._eventId; } else { return t._componentExecutionOrder - i._componentExecutionOrder; } } return t._priority - i._priority; } } function isOnWorldMatrixUpdatedableComponent(t) { return t.onWorldMatrixUpdated !== undefined; } class GameObjectEventContainer { constructor() { this._matrixUpdateComponents = new Set; this._collisionEnter2DComponentEvents = new MutIteratableCollection(ComponentEvent.comparator); this._collisionStay2DComponentEvents = new MutIteratableCollection(ComponentEvent.comparator); this._collisionExit2DComponentEvents = new MutIteratableCollection(ComponentEvent.comparator); this._triggerEnter2DComponentEvents = new MutIteratableCollection(ComponentEvent.comparator); this._triggerStay2DComponentEvents = new MutIteratableCollection(ComponentEvent.comparator); this._triggerExit2DComponentEvents = new MutIteratableCollection(ComponentEvent.comparator); } registerComponent(t) { if (isOnWorldMatrixUpdatedableComponent(t)) { this._matrixUpdateComponents.add(t); } const i = t._engine_internal_componentEventContainer; if (i.onCollisionEnter2D) { this._collisionEnter2DComponentEvents.insert(i.onCollisionEnter2D); } if (i.onCollisionStay2D) { this._collisionStay2DComponentEvents.insert(i.onCollisionStay2D); } if (i.onCollisionExit2D) { this._collisionExit2DComponentEvents.insert(i.onCollisionExit2D); } if (i.onTriggerEnter2D) { this._triggerEnter2DComponentEvents.insert(i.onTriggerEnter2D); } if (i.onTriggerStay2D) { this._triggerStay2DComponentEvents.insert(i.onTriggerStay2D); } if (i.onTriggerExit2D) { this._triggerExit2DComponentEvents.insert(i.onTriggerExit2D); } } unregisterComponent(t) { if (isOnWorldMatrixUpdatedableComponent(t)) { this._matrixUpdateComponents.delete(t); } const i = t._engine_internal_componentEventContainer; if (i.onCollisionEnter2D) { this._collisionEnter2DComponentEvents.delete(i.onCollisionEnter2D); } if (i.onCollisionStay2D) { this._collisionStay2DComponentEvents.delete(i.onCollisionStay2D); } if (i.onCollisionExit2D) { this._collisionExit2DComponentEvents.delete(i.onCollisionExit2D); } if (i.onTriggerEnter2D) { this._triggerEnter2DComponentEvents.delete(i.onTriggerEnter2D); } if (i.onTriggerStay2D) { this._triggerStay2DComponentEvents.delete(i.onTriggerStay2D); } if (i.onTriggerExit2D) { this._triggerExit2DComponentEvents.delete(i.onTriggerExit2D); } } invokeOnWorldMatrixUpdated() { for (const t of this._matrixUpdateComponents) { t.onWorldMatrixUpdated(); } } invokeOnCollisionEnter2D(t) { if (this._collisionEnter2DComponentEvents.size === 0) return; this._collisionEnter2DComponentEvents.forEach((i => i.invoke(t))); } invokeOnCollisionStay2D(t) { if (this._collisionStay2DComponentEvents.size === 0) return; this._collisionStay2DComponentEvents.forEach((i => i.invoke(t))); } invokeOnCollisionExit2D(t) {