From ad8f579e259d7ec34637155847f2efba66e758c5 Mon Sep 17 00:00:00 2001 From: "mwashumawayne@gmail.com" Date: Tue, 12 Sep 2023 17:32:57 +0300 Subject: [PATCH 01/28] Update:Added Composite.type setter and getter --- src/physics/bodies/composite.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/physics/bodies/composite.js b/src/physics/bodies/composite.js index 7864d0ea..c0aae8d8 100644 --- a/src/physics/bodies/composite.js +++ b/src/physics/bodies/composite.js @@ -130,6 +130,14 @@ class Composite { } return mass } + set type(x){ + for (var i = 0; i < this.bodies.length; i++) { + this.bodies[i].type = x + } + } + get type(x){ + return this.bodies[0]?.type + } /** * Density of a body. * From 74dc6b8288d260f521375f549cb35f40f709a708 Mon Sep 17 00:00:00 2001 From: "mwashumawayne@gmail.com" Date: Sat, 16 Sep 2023 18:57:56 +0300 Subject: [PATCH 02/28] Documentation:Fixed on body --- src/physics/bodies/body.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/bodies/body.js b/src/physics/bodies/body.js index bd99b960..82228c7f 100644 --- a/src/physics/bodies/body.js +++ b/src/physics/bodies/body.js @@ -203,7 +203,7 @@ class Body { * Whether the body should respond to collisions.If false,no collision response will occur but collision events will still be fired. * * @type boolean - * @default Settings.collisionResponsefired + * @default Settings.collisionResponse */ collisionResponse = Settings.collisionResponse /** From 9991ade7c6f054d5a2eec7dd54d93c732882783e Mon Sep 17 00:00:00 2001 From: "mwashumawayne@gmail.com" Date: Sat, 16 Sep 2023 20:47:04 +0300 Subject: [PATCH 03/28] New:ImageMaterial added to render --- src/render/material/ImageMaterial.js | 42 ++++++++++++++++++++++++++++ src/render/material/index.js | 3 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/render/material/ImageMaterial.js diff --git a/src/render/material/ImageMaterial.js b/src/render/material/ImageMaterial.js new file mode 100644 index 00000000..8f8a0e98 --- /dev/null +++ b/src/render/material/ImageMaterial.js @@ -0,0 +1,42 @@ +import { drawImage } from "../utils/canvasfunc.js" +/** + * + * @implements Material + */ +export class ImageMaterial { + /** + * @readonly + * @type Image + */ + image = null + /** + * + * @type number + */ + width = 100 + /** + * + * @type number + */ + height = 100 + /** + * @type Vector_like + */ + offset = { + x: 0, + y: 0 + } + /** + * @param {Image} img + */ + constructor(img) { + //TODO - Find a way to load images synchronously. + this.image = img + } + /** + * @param {CanvasRenderingContext2D} ctx + */ + render(ctx) { + ctx.drawImage(this.image, -this.offset.x, -this.offset.y, this.width, this.height) + } +} \ No newline at end of file diff --git a/src/render/material/index.js b/src/render/material/index.js index 84531320..f5b08576 100644 --- a/src/render/material/index.js +++ b/src/render/material/index.js @@ -1,4 +1,5 @@ export * from "./material.js" export * from "./BasicMaterial.js" export * from "./StaticImageMaterial.js" -export * from "./SpriteMaterial.js" \ No newline at end of file +export * from "./SpriteMaterial.js" +//export * from "./ImageMaterial.js" \ No newline at end of file From 71574ce505e1abf261076e6817f587d480186def Mon Sep 17 00:00:00 2001 From: "waynemwashuma@users.noreply.github.com" Date: Sat, 16 Sep 2023 20:56:03 +0300 Subject: [PATCH 04/28] Fix:Getter error on composite --- src/physics/bodies/composite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/bodies/composite.js b/src/physics/bodies/composite.js index c0aae8d8..69ebec6b 100644 --- a/src/physics/bodies/composite.js +++ b/src/physics/bodies/composite.js @@ -135,7 +135,7 @@ class Composite { this.bodies[i].type = x } } - get type(x){ + get type(){ return this.bodies[0]?.type } /** From 19f275ec317e05631450f0916e7a9058adc29b96 Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Sat, 16 Sep 2023 21:34:25 +0300 Subject: [PATCH 05/28] Update:Removed ImageMaterial as it is a dublicate of StaticImageMaterial --- src/render/material/ImageMaterial.js | 42 ---------------------------- src/render/material/index.js | 3 +- 2 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 src/render/material/ImageMaterial.js diff --git a/src/render/material/ImageMaterial.js b/src/render/material/ImageMaterial.js deleted file mode 100644 index 8f8a0e98..00000000 --- a/src/render/material/ImageMaterial.js +++ /dev/null @@ -1,42 +0,0 @@ -import { drawImage } from "../utils/canvasfunc.js" -/** - * - * @implements Material - */ -export class ImageMaterial { - /** - * @readonly - * @type Image - */ - image = null - /** - * - * @type number - */ - width = 100 - /** - * - * @type number - */ - height = 100 - /** - * @type Vector_like - */ - offset = { - x: 0, - y: 0 - } - /** - * @param {Image} img - */ - constructor(img) { - //TODO - Find a way to load images synchronously. - this.image = img - } - /** - * @param {CanvasRenderingContext2D} ctx - */ - render(ctx) { - ctx.drawImage(this.image, -this.offset.x, -this.offset.y, this.width, this.height) - } -} \ No newline at end of file diff --git a/src/render/material/index.js b/src/render/material/index.js index f5b08576..84531320 100644 --- a/src/render/material/index.js +++ b/src/render/material/index.js @@ -1,5 +1,4 @@ export * from "./material.js" export * from "./BasicMaterial.js" export * from "./StaticImageMaterial.js" -export * from "./SpriteMaterial.js" -//export * from "./ImageMaterial.js" \ No newline at end of file +export * from "./SpriteMaterial.js" \ No newline at end of file From e6c1597c7795bad361b7aa39cb11622bf447ed37 Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Sat, 16 Sep 2023 22:33:13 +0300 Subject: [PATCH 06/28] New:Added StaticImageMaterial.offset --- src/render/material/StaticImageMaterial.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/render/material/StaticImageMaterial.js b/src/render/material/StaticImageMaterial.js index f89fee5b..3815212f 100644 --- a/src/render/material/StaticImageMaterial.js +++ b/src/render/material/StaticImageMaterial.js @@ -19,9 +19,17 @@ export class StaticImageMaterial { * @type number */ height = 100 + /** + * @type Vector_like + */ + offset = { + x: 0, + y: 0 + } /** * @param {Image} img */ + constructor(img) { //TODO - Find a way to load images synchronously. this.image = img @@ -30,6 +38,6 @@ export class StaticImageMaterial { * @param {CanvasRenderingContext2D} ctx */ render(ctx) { - ctx.drawImage(this.image, -this.width / 2, -this.height / 2, this.width, this.height) + ctx.drawImage(this.image, this.offset.x, this.offset.y, this.width, this.height) } } \ No newline at end of file From 7a09d88257eb00b51e62181da975d4aac94e9353 Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Sun, 17 Sep 2023 19:29:39 +0300 Subject: [PATCH 07/28] Fix:When an entity is removed from a manager using Manager.remove(),it cannot be added to another manager due to warning --- src/manager/entity.js | 9 ++++++++- src/manager/manager.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/manager/entity.js b/src/manager/entity.js index 666d5dce..1b9d0592 100644 --- a/src/manager/entity.js +++ b/src/manager/entity.js @@ -73,6 +73,13 @@ class Entity { */ removeSelf() { if (this._global) this._global.remove(this) + } + /** + * This is an internal function,no need to use it. + * + * @package + */ + reset() { this.active = false this._global = null } @@ -242,7 +249,7 @@ class Entity { entity.addTag(a) }) for (var key in obj.comps) { - let c =new compList[key]().fromJSON(obj.comps[key]) + let c = new compList[key]().fromJSON(obj.comps[key]) entity.attach(key, c) } return entity diff --git a/src/manager/manager.js b/src/manager/manager.js index 376f5fe1..23e207ec 100644 --- a/src/manager/manager.js +++ b/src/manager/manager.js @@ -271,9 +271,9 @@ class Manager { remove(object) { let index = this.objects.indexOf(object) object.removeComponents() + object.reset() Utils.removeElement(this.objects, index) this.events.trigger("remove", object) - } /** * This removes all of the entities and components from the manager From a5e7993913655f12aebdd22e65d21265abe58f88 Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Sun, 17 Sep 2023 20:08:26 +0300 Subject: [PATCH 08/28] Fix:Manager.getEntitiesByTags() not returning the expected results --- src/manager/manager.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/manager/manager.js b/src/manager/manager.js index 23e207ec..6e16d5c9 100644 --- a/src/manager/manager.js +++ b/src/manager/manager.js @@ -501,6 +501,7 @@ class Manager { target.push(entities[i]) } } + return target } /** * Ignore this,im going to remove it and the rest of cloning utilities. From 2e31e6cd4ba36650140cf96ba6b1d3846fb29629 Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Sun, 17 Sep 2023 21:11:27 +0300 Subject: [PATCH 09/28] Fix: Potentially undefined behaviour in static Vector.lerp() --- src/math/vector.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/math/vector.js b/src/math/vector.js index bda4513f..434fa040 100644 --- a/src/math/vector.js +++ b/src/math/vector.js @@ -332,14 +332,14 @@ class Vector { return this.multiply(min / length) return this } - -toJson(){ - return this -} -fromJspn(obj){ - this.x = obj.x - this.y = obj.y -} + + toJson() { + return this + } + fromJson(obj) { + this.x = obj.x + this.y = obj.y + } [Symbol.iterator] = function*() { yield this.x @@ -434,7 +434,7 @@ fromJspn(obj){ */ static lerp(v1, v2, t, target = new Vector()) { target = target || new Vector() - return target.copy(v1).set( + return target.set( (v2.x - v1.x) * t + v1.x, (v2.y - v1.y) * t + v1.y ) From 89264aca21c055b27053a9f924d046c641e04be7 Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:23:20 +0300 Subject: [PATCH 10/28] Refactor:Remove unnecessary code --- src/utils/clock.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/clock.js b/src/utils/clock.js index 45fca3c6..e39ed93c 100644 --- a/src/utils/clock.js +++ b/src/utils/clock.js @@ -30,8 +30,8 @@ class Clock { this.dt = accumulate - this.lastcall || 0 //this.framerate = this.getFrameRate() this.lastcall = accumulate - this.delta = this.dt/1000 - return this.delta + + return this.dt/1000 } } export{ From 85a25b11a3b81dfcd3da09a70436f101b73a579b Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:35:26 +0300 Subject: [PATCH 11/28] Refactor:Cleanup --- src/manager/manager.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/manager/manager.js b/src/manager/manager.js index 6e16d5c9..cd8ec7b9 100644 --- a/src/manager/manager.js +++ b/src/manager/manager.js @@ -62,8 +62,6 @@ class Manager { world: null, renderer: null, input: null, - //TODO - cleanup this events prop - events: null, audio: null } /** From e403aeaa4bc7e0c351be1a412c628db5ce7da4c4 Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:35:49 +0300 Subject: [PATCH 12/28] Refactor:Removed server.js --- server.js | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 server.js diff --git a/server.js b/server.js deleted file mode 100644 index 6ebae346..00000000 --- a/server.js +++ /dev/null @@ -1,13 +0,0 @@ -const { log } = require('console'); -const express = require('express'); -const app = express(); -const path = require("path") -const http = require('http').createServer(app); -const PORT = 8080 - -app.use('/',express.static(__dirname + '/demos')) -app.use('/dist',express.static(__dirname + '/dist')) - -http.listen(PORT, function () { - console.log('listening on port::' + PORT); -}) \ No newline at end of file From 187313a2683f8fa55d64ae0fcdb3e04cf9655832 Mon Sep 17 00:00:00 2001 From: "mwashumawayne@gmail.com" Date: Sat, 14 Oct 2023 18:28:55 +0300 Subject: [PATCH 13/28] Added torque to body #new #update --- src/physics/bodies/body.js | 53 +++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/src/physics/bodies/body.js b/src/physics/bodies/body.js index 82228c7f..d3617afc 100644 --- a/src/physics/bodies/body.js +++ b/src/physics/bodies/body.js @@ -2,7 +2,7 @@ import { Vector, Angle, sq } from "../../math/index.js" import { Utils } from "../../utils/index.js" import { BoundingBox } from "../AABB/index.js" import { ObjType, Settings } from "../settings.js" -import {Shape} from "../shapes/index.js" +import { Shape } from "../shapes/index.js" let defaults = new Vector() /** @@ -52,6 +52,13 @@ class Body { * @type Angle */ _rotation = new Angle() + /** + * Torque of the body + * + * @private + * @type Angle + */ + _torque = new Angle() /** * Mass of the body. * @@ -382,6 +389,28 @@ class Body { set angularVelocity(x) { this.rotation.degree = x } + /** + * Torque of a body in degrees + * + * @type number + */ + get torque() { + return this._torque + } + set torque(x) { + this._torque.degree = x.degree + } + /** + * Angular acceleration of a body in degrees + * + * @type number + */ + get angularAcceleration() { + return this._torque.degree + } + set angularAcceleration(x) { + this._torque.degree = x + } /** * Sets an anchor that is relative to the center of the body into it.The anchor's world coordinates will be updated when the body too is updated. * @@ -469,26 +498,26 @@ class Body { } toJson() { let obj = { - id:this.id, + id: this.id, position: this.position.toJson(), velocity: this.velocity.toJson(), acceleration: this.acceleration.toJson(), orientation: this.orientation.toJson(), rotation: this.rotation.toJson(), shapes: [], - anchors:[], + anchors: [], collisionResponse: this.collisionResponse, allowSleep: this.allowSleep, type: this.CHAOS_OBJ_TYPE, phyType: this.type, mass: this.mass, - inertia:this.inertia, - autoUpdateBound:this.autoUpdateBound, - boundPadding:this.boundPadding, - aabbDetectionOnly:this.aabbDetectionOnly, - mask:this.mask + inertia: this.inertia, + autoUpdateBound: this.autoUpdateBound, + boundPadding: this.boundPadding, + aabbDetectionOnly: this.aabbDetectionOnly, + mask: this.mask } - this.anchors.forEach((a)=>{ + this.anchors.forEach((a) => { obj.anchors.push(a) }) this.shapes.forEach((a) => { @@ -497,9 +526,9 @@ class Body { return obj } //TODO - Add way to add shapes to body - fromJson(obj){ + fromJson(obj) { let shapes = [] - obj.shapes.forEach((shape)=>{ + obj.shapes.forEach((shape) => { shapes.push(Shape.fromJson(shape)) }) let body = this @@ -518,7 +547,7 @@ class Body { body.autoUpdateBound = obj.autoUpdateBound body.id = obj.id body.mask = obj.mask - obj.anchors.forEach((v)=>{ + obj.anchors.forEach((v) => { body.setAnchor(new Vector().fromJson(v)) }) } From b687c0cdf0d64c0af6205592384f3845c0c351b4 Mon Sep 17 00:00:00 2001 From: "mwashumawayne@gmail.com" Date: Sat, 14 Oct 2023 18:43:28 +0300 Subject: [PATCH 14/28] Updated verlet and euler intergrators to use torque #update --- src/physics/integrators/euler.js | 1 + src/physics/integrators/verlet.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/physics/integrators/euler.js b/src/physics/integrators/euler.js index ddb95ad0..cb9bc72f 100644 --- a/src/physics/integrators/euler.js +++ b/src/physics/integrators/euler.js @@ -15,6 +15,7 @@ class EulerSolver{ body.velocity.add(body.acceleration.multiply(dt)) a.copy(body.velocity) body.position.add(a.multiply(dt)) + body.angularVelocity += body.angularAcceleration * dt body.angle += body.angularVelocity * dt body.acceleration.set(0,0) } diff --git a/src/physics/integrators/verlet.js b/src/physics/integrators/verlet.js index 6deb7d86..3d2c0018 100644 --- a/src/physics/integrators/verlet.js +++ b/src/physics/integrators/verlet.js @@ -6,7 +6,7 @@ let velocity = new Vector() /** * Verlet intergration. * Used so that constraints can be stable at little performance cost. -*/ + */ class VerletSolver { /** * @param {Body} body @@ -19,8 +19,11 @@ class VerletSolver { body.acceleration.set(0, 0) body.velocity.add(acceleration) position.add(velocity.multiply(dt)).add(acceleration.multiply(dt)) + //body.velocity.add(acceleration) body.position = position + body.angularVelocity += body.angularAcceleration * dt * 0.5 body.angle += body.angularVelocity * dt + //body.angularVelocity += body.angularAcceleration * dt * 0.5 } } export { From 428ade3a13ffff4f2ecbbcca556a35fe654d4806 Mon Sep 17 00:00:00 2001 From: "mwashumawayne@gmail.com" Date: Sat, 14 Oct 2023 18:44:20 +0300 Subject: [PATCH 15/28] Fixed verlet intergrator #fix --- src/physics/integrators/verlet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/physics/integrators/verlet.js b/src/physics/integrators/verlet.js index 3d2c0018..68f6e2e2 100644 --- a/src/physics/integrators/verlet.js +++ b/src/physics/integrators/verlet.js @@ -19,11 +19,11 @@ class VerletSolver { body.acceleration.set(0, 0) body.velocity.add(acceleration) position.add(velocity.multiply(dt)).add(acceleration.multiply(dt)) - //body.velocity.add(acceleration) + body.velocity.add(acceleration) body.position = position body.angularVelocity += body.angularAcceleration * dt * 0.5 body.angle += body.angularVelocity * dt - //body.angularVelocity += body.angularAcceleration * dt * 0.5 + body.angularVelocity += body.angularAcceleration * dt * 0.5 } } export { From 1cc5559b5e5c89e248cb81156b98b6228a947f97 Mon Sep 17 00:00:00 2001 From: "mwashumawayne@gmail.com" Date: Sat, 14 Oct 2023 19:20:55 +0300 Subject: [PATCH 16/28] Created Narrowphase module #new --- src/physics/index.js | 3 +- src/physics/narrowphase/Narrowphase.js | 5 ++ src/physics/narrowphase/SATNarrowphase.js | 86 +++++++++++++++++++++++ src/physics/narrowphase/index.js | 2 + 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/physics/narrowphase/Narrowphase.js create mode 100644 src/physics/narrowphase/SATNarrowphase.js create mode 100644 src/physics/narrowphase/index.js diff --git a/src/physics/index.js b/src/physics/index.js index 68026b1e..89d118fa 100644 --- a/src/physics/index.js +++ b/src/physics/index.js @@ -4,4 +4,5 @@ export * from "./shapes/index.js" export * from "./bodies/index.js" export * from "./constraints/index.js" export * from "./world/index.js" -export * from "./broadphases/index.js" \ No newline at end of file +export * from "./broadphases/index.js" +export * from "./narrowphase/index.js" \ No newline at end of file diff --git a/src/physics/narrowphase/Narrowphase.js b/src/physics/narrowphase/Narrowphase.js new file mode 100644 index 00000000..174174dc --- /dev/null +++ b/src/physics/narrowphase/Narrowphase.js @@ -0,0 +1,5 @@ +export class NarrowPhase{ + records = new Map() + getCollisionPairs(contactList,clmds){ + } +} \ No newline at end of file diff --git a/src/physics/narrowphase/SATNarrowphase.js b/src/physics/narrowphase/SATNarrowphase.js new file mode 100644 index 00000000..280bab08 --- /dev/null +++ b/src/physics/narrowphase/SATNarrowphase.js @@ -0,0 +1,86 @@ +import { Vector, naturalizePair } from "../../math/index.js" +import { Utils } from "../../utils/index.js" +import { SAT } from "../SAT/index.js"; +import { ObjType } from "../settings.js" + +import { NarrowPhase } from "./Narrowphase.js" +import { Settings } from "../settings.js" + + +/** + * Uses the Separation Axis Theorem. + * Best when your body shapes have few vertices. + */ +export class SATNarrowPhase extends NarrowPhase { + /** + * @param {CollisionPair[]} contactList + * @param {Manifold[]} clmds + */ + getCollisionPairs(contactList, clmds) { + for (var i = 0; i < contactList.length; i++) { + let { a, b } = contactList[i] + a.sleeping = false + b.sleeping = false + let id = naturalizePair(a.id, b.id) + if (!this.records.has(id)) + this.records.set(id, { + bodyA: a, + bodyB: b, + contactData: { + lastOverlap: 0, + overlap: -Infinity, + done: false, + axis: new Vector(), + verticesA: [], + verticesB: [], + vertShapeA: null, + vertShapeB: null, + contactNo: 0, + shapes: [], + indexA: 0, + indexB: 0 + }, + stmp: -1, + impulse: 0, + persistent: false, + ca1: new Vector(), + ca2: new Vector(), + restitution: 0, + staticFriction: 0, + kineticFriction: 0, + velA: new Vector(), + velB: new Vector(), + rotA: 0, + rotB: 0 + }) + let manifold = this.records.get(id) + let collisionData = manifold.contactData + collisionData.overlap = -Infinity + collisionData.done = false + SAT.shapesInBodyCollided(a, b, collisionData) + if (collisionData.overlap < 0 || !collisionData.done) continue + if (collisionData.contactNo == 2) { + Vector.lerp( + collisionData.verticesA[0], + collisionData.verticesA[1], + 0.5, + manifold.ca1 + ).sub(a.position) + Vector.lerp( + collisionData.verticesB[0], + collisionData.verticesB[1], + 0.5, + manifold.ca2 + ).sub(b.position) + } else { + manifold.ca1.copy(collisionData.verticesA[0]).sub(a.position) + manifold.ca2.copy(collisionData.verticesB[0]).sub(b.position) + } + manifold.restitution = a.restitution < b.restitution ? a.restitution : b.restitution + manifold.staticFriction = a.staticFriction < b.staticFriction ? a.staticFriction : b.staticFriction + manifold.kineticFriction = a.kineticFriction < b.kineticFriction ? a.kineticFriction : b.kineticFriction + if (a.collisionResponse && b.collisionResponse) + clmds.push(manifold) + } + } +} \ No newline at end of file diff --git a/src/physics/narrowphase/index.js b/src/physics/narrowphase/index.js new file mode 100644 index 00000000..b6f5458b --- /dev/null +++ b/src/physics/narrowphase/index.js @@ -0,0 +1,2 @@ +export * from "./SATNarrowphase.js" +export * from "./Narrowphase.js" \ No newline at end of file From 8503a55762fce2994d7bfe9b7f99cd1682615363 Mon Sep 17 00:00:00 2001 From: "mwashumawayne@gmail.com" Date: Sat, 14 Oct 2023 19:59:31 +0300 Subject: [PATCH 17/28] Refactored the world to remove Narrophase code #cleanup #refactor --- src/physics/narrowphase/SATNarrowphase.js | 5 +- src/physics/world/index.js | 86 ++++------------------- 2 files changed, 16 insertions(+), 75 deletions(-) diff --git a/src/physics/narrowphase/SATNarrowphase.js b/src/physics/narrowphase/SATNarrowphase.js index 280bab08..9bd0c035 100644 --- a/src/physics/narrowphase/SATNarrowphase.js +++ b/src/physics/narrowphase/SATNarrowphase.js @@ -14,9 +14,9 @@ import { Settings } from "../settings.js" export class SATNarrowPhase extends NarrowPhase { /** * @param {CollisionPair[]} contactList - * @param {Manifold[]} clmds + * @param {Manifold[]} [clmds=[]] */ - getCollisionPairs(contactList, clmds) { + getCollisionPairs(contactList, clmds = []) { for (var i = 0; i < contactList.length; i++) { let { a, b } = contactList[i] a.sleeping = false @@ -82,5 +82,6 @@ export class SATNarrowPhase extends NarrowPhase { if (a.collisionResponse && b.collisionResponse) clmds.push(manifold) } + return clmds } } \ No newline at end of file diff --git a/src/physics/world/index.js b/src/physics/world/index.js index 78dc0761..adfa7649 100644 --- a/src/physics/world/index.js +++ b/src/physics/world/index.js @@ -1,12 +1,13 @@ import { EulerSolver, VerletSolver } from "../integrators/index.js"; import { PenetrationSolver, FrictionSolver, ImpulseSolver, ContactSolver } from "../solvers/index.js"; -import { Vector, naturalizePair }from "../../math/index.js" -import {Utils} from "../../utils/index.js" +import { Vector, naturalizePair } from "../../math/index.js" +import { Utils } from "../../utils/index.js" import { SAT } from "../SAT/index.js"; import { ObjType } from "../settings.js" //import {ctx} from "../../debug.js" import { NaiveBroadphase } from "../broadphases/index.js" +import { SATNarrowPhase } from "../narrowphase/index.js" import { Settings } from "../settings.js" /** @@ -107,12 +108,20 @@ class World { * @type Broadphase */ broadphase = null + /** + * This accurately tests body pairs to check + * for collision and outputs a manifold for each body pair. + * + * @type NarrowPhase + */ + narrowphase = null /** * @constructor World * */ constructor() { this.broadphase = new NaiveBroadphase(this) + this.narrowphase = new SATNarrowPhase() } set gravity(x) { if (typeof x === "object") @@ -131,76 +140,7 @@ class World { * @private */ narrowPhase() { - let - collisionData, - manifold - - for (var i = 0; i < this.contactList.length; i++) { - let { a, b } = this.contactList[i] - a.sleeping = false - b.sleeping = false - let id = naturalizePair(a.id, b.id) - if (!this.records.has(id)) - this.records.set(id, { - bodyA: a, - bodyB: b, - contactData: { - lastOverlap: 0, - overlap: -Infinity, - done: false, - axis: new Vector(), - verticesA: [], - verticesB: [], - vertShapeA: null, - vertShapeB: null, - contactNo: 0, - shapes: [], - indexA: 0, - indexB: 0 - }, - stmp: -1, - impulse: 0, - persistent: false, - ca1: new Vector(), - ca2: new Vector(), - restitution: 0, - staticFriction: 0, - kineticFriction: 0, - velA: new Vector(), - velB: new Vector(), - rotA: 0, - rotB: 0 - }) - manifold = this.records.get(id) - collisionData = manifold.contactData - collisionData.overlap = -Infinity - collisionData.done = false - SAT.shapesInBodyCollided(a, b, collisionData) - if (collisionData.overlap < 0 || !collisionData.done) continue - if (collisionData.contactNo == 2) { - Vector.lerp( - collisionData.verticesA[0], - collisionData.verticesA[1], - 0.5, - manifold.ca1 - ).sub(a.position) - Vector.lerp( - collisionData.verticesB[0], - collisionData.verticesB[1], - 0.5, - manifold.ca2 - ).sub(b.position) - } else { - manifold.ca1.copy(collisionData.verticesA[0]).sub(a.position) - manifold.ca2.copy(collisionData.verticesB[0]).sub(b.position) - } - manifold.restitution = a.restitution < b.restitution ? a.restitution : b.restitution - manifold.staticFriction = a.staticFriction < b.staticFriction ? a.staticFriction : b.staticFriction - manifold.kineticFriction = a.kineticFriction < b.kineticFriction ? a.kineticFriction : b.kineticFriction - if (a.collisionResponse && b.collisionResponse) - this.CLMDs.push(manifold) - - } + this.CLMDs = this.narrowphase.getCollisionPairs(this.contactList,[]) } /* * @private @@ -422,7 +362,7 @@ class World { removeContraint(constraint) { let arr = constraint.fixed ? this.fixedConstraits : this.constraints let temp = arr.pop() - if(constraint.index == arr.length) return constraint + if (constraint.index == arr.length) return constraint arr[constraint.index] = temp temp.index = constraint.index constraint.index = -1 From e3bd5261640d84e3e6eb30aae02ab2bbed90906d Mon Sep 17 00:00:00 2001 From: "mwashumawayne@gmail.com" Date: Sat, 14 Oct 2023 20:15:19 +0300 Subject: [PATCH 18/28] cleanup on the imports #cleanup --- src/physics/narrowphase/SATNarrowphase.js | 4 ---- src/physics/world/index.js | 5 +---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/physics/narrowphase/SATNarrowphase.js b/src/physics/narrowphase/SATNarrowphase.js index 9bd0c035..27d2d225 100644 --- a/src/physics/narrowphase/SATNarrowphase.js +++ b/src/physics/narrowphase/SATNarrowphase.js @@ -1,10 +1,6 @@ import { Vector, naturalizePair } from "../../math/index.js" -import { Utils } from "../../utils/index.js" import { SAT } from "../SAT/index.js"; -import { ObjType } from "../settings.js" - import { NarrowPhase } from "./Narrowphase.js" -import { Settings } from "../settings.js" /** diff --git a/src/physics/world/index.js b/src/physics/world/index.js index adfa7649..489f520b 100644 --- a/src/physics/world/index.js +++ b/src/physics/world/index.js @@ -1,11 +1,8 @@ import { EulerSolver, VerletSolver } from "../integrators/index.js"; import { PenetrationSolver, FrictionSolver, ImpulseSolver, ContactSolver } from "../solvers/index.js"; -import { Vector, naturalizePair } from "../../math/index.js" +import { Vector } from "../../math/index.js" import { Utils } from "../../utils/index.js" -import { SAT } from "../SAT/index.js"; import { ObjType } from "../settings.js" -//import {ctx} from "../../debug.js" - import { NaiveBroadphase } from "../broadphases/index.js" import { SATNarrowPhase } from "../narrowphase/index.js" import { Settings } from "../settings.js" From 1e65f3fb2f22961baefca42ed4f1b58b7259299e Mon Sep 17 00:00:00 2001 From: "94756970+waynemwashuma@users.noreply.github.com" <94756970+waynemwashuma@users.noreply.github.com> Date: Sat, 21 Oct 2023 21:27:43 +0300 Subject: [PATCH 19/28] Rebase,donno what im doin?? --- README.md | 37 +- configs/tsconfig.json | 1 + demos/box.js | 4 + demos/bridge.js | 20 +- demos/car.js | 2 +- demos/circle.js | 17 - demos/circlestack.js | 20 - demos/index.js | 14 +- demos/main.js | 2 +- demos/marterial.js | 55 - demos/particle.js | 17 - demos/pathfollower.js | 2 +- demos/pyramid.js | 2 +- demos/random.js | 2 +- demos/stacking.js | 2 +- dist/chaos.module.d.ts | 3179 +++++----------- dist/chaos.module.js | 3052 +++++---------- dist/chaos.umd.js | 3093 ++++++--------- docs/AI_agent.js.html | 11 +- docs/AI_behaviourManager.js.html | 5 +- docs/AI_behaviours_arrive.js.html | 4 +- docs/AI_behaviours_behaviour.js.html | 4 +- docs/AI_behaviours_evade.js.html | 4 +- docs/AI_behaviours_flocking.js.html | 50 +- docs/AI_behaviours_path.js.html | 40 +- docs/AI_behaviours_pursuit.js.html | 4 +- docs/AI_behaviours_seek.js.html | 11 +- docs/AI_behaviours_wandering.js.html | 4 +- docs/AI_manager.js.html | 4 +- docs/AI_paths_path.js.html | 183 - docs/Agent.html | 16 +- docs/AgentManager.html | 4 +- docs/AgentSprite.html | 774 ---- docs/Angle.html | 236 +- docs/ArriveBehaviour.html | 4 +- docs/AudioHandler.html | 112 +- docs/Ball.html | 202 +- docs/BasicMaterial.html | 586 --- docs/Behaviour.html | 4 +- docs/BehaviourManager.html | 92 +- docs/Body.html | 192 +- docs/BodySprite.html | 499 +-- docs/Bound.html | 4 +- docs/BoundingBox.html | 88 +- docs/BoundingCircle.html | 84 +- docs/Box.html | 202 +- docs/Broadphase.html | 4 +- docs/BufferGeometry_BufferGeometry.html | 215 -- docs/CamController_CamController.html | 215 -- docs/Circle.html | 166 +- docs/CircleGeometry_CircleGeometry.html | 215 -- docs/Clock.html | 4 +- docs/Component.html | 919 +---- docs/Composite.html | 14 +- docs/Constraint.html | 144 +- docs/DOMEventHandler.html | 4 +- docs/DistanceConstraint.html | 4 +- docs/Entity.html | 367 +- docs/EulerSolver.html | 4 +- docs/EvadeBehaviour.html | 4 +- docs/EventDispatcher.html | 4 +- docs/Flock.html | 72 +- docs/Geometry.html | 898 ----- docs/Grid.html | 4 +- docs/Group.html | 1278 ------- docs/Input.html | 4 +- docs/Keyboard.html | 6 +- docs/Line.html | 333 -- docs/Manager.html | 484 ++- docs/Material.html | 341 -- docs/Matrix2.html | 4 +- docs/Mouse.html | 139 +- docs/Movable.html | 121 +- docs/NaiveBroadphase.html | 67 +- docs/Node.html | 2854 -------------- docs/Particle.html | 547 +-- docs/ParticleSystemSprite.html | 1495 -------- docs/PathFollowing.html | 12 +- docs/Pool.html | 18 +- docs/Pursuit.html | 4 +- docs/Rectangle.html | 4 +- docs/Renderer.html | 232 +- docs/Renderer2D.html | 375 +- docs/RungeKuttaSolver.html | 4 +- docs/SeekBehaviour.html | 125 +- docs/Sfx.html | 4 +- docs/Shape.html | 174 +- docs/SpringConstraint.html | 4 +- docs/Sprite.html | 258 +- docs/SpriteMaterial.html | 1231 ------ docs/StaticImageMaterial.html | 581 --- docs/System.html | 554 ++- docs/Touch.html | 252 +- docs/Transform.html | 111 +- docs/Tree.html | 14 +- docs/Triangle.html | 182 +- docs/Vector.html | 420 +-- docs/VectorPool.html | 10 +- docs/VerletSolver.html | 4 +- docs/WanderBehaviour.html | 4 +- docs/WebGLRenderer.html | 242 +- docs/WebGPURenderer.html | 242 +- docs/World.html | 36 +- docs/audio_audio.js.html | 4 +- docs/audio_manager.js.html | 29 +- docs/dataStructures_pools_VectorPool.js.html | 75 - docs/dataStructures_pools_objectPool.js.html | 137 - docs/device_index.js.html | 6 +- docs/events_DOMEventHandler.js.html | 4 +- docs/events_eventDispatcher.js.html | 4 +- docs/events_eventHandlers.js.html | 12 +- docs/events_events.js.html | 4 +- docs/global.html | 3340 +++-------------- docs/index.html | 4 +- docs/inputs_input.js.html | 4 +- docs/inputs_keyboard.js.html | 15 +- docs/inputs_mouse.js.html | 55 +- docs/inputs_touch.js.html | 36 +- docs/manager_boundsComponent.js.html | 12 +- docs/manager_component.js.html | 68 +- docs/manager_entity.js.html | 44 +- docs/manager_manager.js.html | 33 +- docs/manager_movableComponent.js.html | 26 +- docs/manager_system.js.html | 4 +- docs/manager_transformComponent.js.html | 26 +- docs/math_angle.js.html | 31 +- docs/math_math.js.html | 4 +- docs/math_matrix.js.html | 4 +- docs/math_vector.js.html | 37 +- docs/module-Cookie.html | 4 +- docs/module-Session.html | 4 +- docs/module-Utils.html | 6 +- docs/physics_AABB_boundingBox.js.html | 33 +- docs/physics_AABB_boundingSphere.js.html | 20 +- docs/physics_AABB_overlap.js.html | 4 +- docs/physics_SAT_index.js.html | 4 +- docs/physics_bodies_ball.js.html | 4 +- docs/physics_bodies_body.js.html | 71 +- docs/physics_bodies_box.js.html | 4 +- docs/physics_bodies_composite.js.html | 64 +- docs/physics_broadphases_AABBTree.js.html | 4 +- docs/physics_broadphases_Naive.js.html | 11 +- docs/physics_broadphases_Quadtree.js.html | 110 +- docs/physics_broadphases_SpartialHash.js.html | 4 +- docs/physics_broadphases_broadphase.js.html | 4 +- docs/physics_constraints_constraint.js.html | 39 +- ...ics_constraints_distanceConstraint.js.html | 8 +- ...ysics_constraints_springConstraint.js.html | 8 +- docs/physics_integrators_euler.js.html | 4 +- docs/physics_integrators_rungeKutter.js.html | 4 +- docs/physics_integrators_verlet.js.html | 4 +- docs/physics_settings.js.html | 4 +- docs/physics_shapes_circle.js.html | 27 +- docs/physics_shapes_geometry.js.html | 147 - docs/physics_shapes_line.js.html | 74 - docs/physics_shapes_rectangle.js.html | 4 +- docs/physics_shapes_shape.js.html | 48 +- docs/physics_shapes_triangle.js.html | 4 +- docs/physics_solvers_contactSolver.js.html | 4 +- docs/physics_solvers_frictionSolver.js.html | 4 +- docs/physics_solvers_impulseSolver.js.html | 4 +- .../physics_solvers_penetrationSolver.js.html | 4 +- docs/physics_world_index.js.html | 17 +- docs/render_camController.js.html | 98 - docs/render_camera.js.html | 74 - docs/render_geometry_circlegeometry.js.html | 74 - docs/render_geometry_geometry.js.html | 79 - docs/render_material_BasicMaterial.js.html | 87 - docs/render_material_SpriteMaterial.js.html | 190 - ...ender_material_StaticImageMaterial.js.html | 85 - docs/render_material_material.js.html | 64 - docs/render_renderers_canvas.js.html | 152 +- docs/render_renderers_renderer.js.html | 17 +- docs/render_renderers_webgpurenderer.js.html | 4 +- docs/render_renderers_weglrenderer.js.html | 4 +- docs/render_sprites_AgentSprite.js.html | 41 +- docs/render_sprites_bodysprite.js.html | 78 +- docs/render_sprites_group.js.html | 47 +- docs/render_sprites_particleSystem.js.html | 115 +- docs/render_sprites_sprite.js.html | 96 +- docs/render_utils_canvasfunc.js.html | 158 - docs/storage_cookie.js.html | 4 +- docs/storage_localStorage.js.html | 4 +- docs/storage_sessionStorage.js.html | 4 +- docs/typedef_bounds.js.html | 4 +- docs/typedef_manifold.js.html | 4 +- docs/typedef_vectorlike.js.html | 4 +- docs/utils_clock.js.html | 4 +- docs/utils_common.js.html | 36 +- docs/utils_error.js.html | 4 +- docs/utils_pools_VectorPool.js.html | 4 +- docs/utils_pools_objectPool.js.html | 4 +- legacy/src/index.js | 6 + legacy/src/inputs/eventDispatcher.js | 31 + legacy/src/inputs/eventHandler.js | 41 + legacy/src/inputs/index.js | 6 + legacy/src/inputs/input.js | 28 + legacy/src/inputs/keyboard.js | 35 + legacy/src/inputs/mouse.js | 99 + legacy/src/inputs/touch.js | 41 + legacy/src/manager/component.js | 99 + legacy/src/manager/entity.js | 146 + legacy/src/manager/index.js | 3 + legacy/src/manager/manager.js | 102 + legacy/src/physics/AABB/AABB.js | 28 + legacy/src/physics/AABB/boundingBox.js | 92 + legacy/src/physics/AABB/boundingSphere.js | 27 + legacy/src/physics/AABB/index.js | 3 + legacy/src/physics/SAT/clutter.js | 92 + legacy/src/physics/SAT/index 1.js | 225 ++ legacy/src/physics/SAT/index.js | 172 + legacy/src/physics/SAT/last.js | 188 + legacy/src/physics/SAT/working.js | 228 ++ legacy/src/physics/bodies/ball.js | 17 + legacy/src/physics/bodies/body.js | 145 + legacy/src/physics/bodies/box.js | 17 + legacy/src/physics/bodies/heightMap.js | 23 + legacy/src/physics/bodies/index.js | 5 + legacy/src/physics/bodies/wall.js | 16 + .../physics/constraints/angleConstraint.js | 21 + legacy/src/physics/constraints/constraint.js | 16 + .../physics/constraints/distanceConstraint.js | 41 + legacy/src/physics/constraints/index.js | 4 + .../physics/constraints/springConstraint.js | 42 + legacy/src/physics/index.js | 6 + legacy/src/physics/integrators/euler.js | 14 + legacy/src/physics/integrators/index.js | 3 + legacy/src/physics/integrators/rungeKutter.js | 14 + legacy/src/physics/integrators/verlet.js | 22 + legacy/src/physics/shapes/circle.js | 60 + legacy/src/physics/shapes/geometry.js | 55 + legacy/src/physics/shapes/index.js | 6 + legacy/src/physics/shapes/line.js | 27 + legacy/src/physics/shapes/rectangle.js | 23 + legacy/src/physics/shapes/shape.js | 105 + legacy/src/physics/shapes/triangle.js | 12 + legacy/src/physics/solvers/contactSolver.js | 27 + legacy/src/physics/solvers/frictionSolver.js | 46 + legacy/src/physics/solvers/impulseSolver.js | 63 + legacy/src/physics/solvers/index.js | 4 + .../src/physics/solvers/penetrationSolver.js | 18 + legacy/src/physics/spartial.js | 11 + legacy/src/physics/utils/collisionManifold.js | 14 + legacy/src/physics/utils/pool.js | 7 + legacy/src/physics/world/index 1.js | 229 ++ legacy/src/physics/world/index.js | 217 ++ legacy/src/render/camera.js | 29 + legacy/src/render/index.js | 3 + legacy/src/render/meshes/bodyMesh.js | 23 + legacy/src/render/meshes/debugMesh.js | 40 + legacy/src/render/meshes/index.js | 3 + legacy/src/render/meshes/mesh.js | 45 + legacy/src/render/renderer.js | 81 + legacy/src/render/utils/index.js | 3 + legacy/src/render/utils/parallaxBackground.js | 26 + legacy/src/render/utils/particleSystem.js | 79 + legacy/src/render/utils/sprite.js | 92 + legacy/src/store/AABBTree.js | 15 + legacy/src/store/index.js | 3 + legacy/src/store/quadTree.js | 247 ++ legacy/src/store/spatialGrid.js | 12 + legacy/src/utils/accumulator.js | 22 + legacy/src/utils/clock.js | 22 + legacy/src/utils/degree.js | 27 + legacy/src/utils/generics.js | 20 + legacy/src/utils/idgenerator.js | 13 + legacy/src/utils/index.js | 6 + legacy/src/utils/math/index.js | 1 + legacy/src/utils/math/math.js | 38 + legacy/src/utils/matrix.js | 91 + legacy/src/utils/objectPool.js | 18 + legacy/src/utils/sort.js | 67 + legacy/src/utils/splines/bezier.js | 15 + legacy/src/utils/splines/catwellRom.js | 7 + legacy/src/utils/splines/hermite.js | 7 + .../src/utils/splines}/index.js | 0 legacy/src/utils/splines/linear.js | 9 + legacy/src/utils/vector.js | 170 + legacy/src/utils/vectorPool.js | 20 + package.json | 2 +- server.js | 13 + src/AI/agent.js | 7 +- src/AI/behaviourManager.js | 1 - src/AI/behaviours/seek.js | 7 - src/AI/paths/path.js | 51 +- src/dataStructures/index.js | 2 - src/dataStructures/indexedList.js | 20 - src/events/eventHandlers.js | 8 +- src/index.js | 3 +- src/inputs/mouse.js | 1 - src/inputs/touch.js | 26 +- src/manager/boundsComponent.js | 8 - src/manager/component.js | 64 +- src/manager/entity.js | 47 - src/manager/index.js | 3 +- src/manager/manager.js | 26 +- src/manager/movableComponent.js | 22 +- src/manager/transformComponent.js | 22 +- src/math/angle.js | 27 +- src/math/functions.js | 10 - src/math/index.js | 4 +- src/math/interpolation.js | 246 -- src/math/vector.js | 16 +- src/physics/AABB/boundingBox.js | 22 +- src/physics/AABB/boundingSphere.js | 14 - src/physics/bodies/body.js | 98 +- src/physics/bodies/composite.js | 8 - src/physics/bodies/index.js | 2 +- src/physics/broadphases/Naive.js | 3 - src/physics/broadphases/Quadtree.js | 13 +- src/physics/broadphases/index.js | 2 +- src/physics/constraints/constraint.js | 35 +- src/physics/index.js | 3 +- src/physics/integrators/euler.js | 1 - src/physics/integrators/verlet.js | 5 +- src/physics/narrowphase/Narrowphase.js | 5 - src/physics/narrowphase/SATNarrowphase.js | 83 - src/physics/narrowphase/index.js | 2 - src/physics/shapes/circle.js | 23 +- src/physics/shapes/geometry.js | 52 +- src/physics/shapes/line.js | 9 - src/physics/shapes/shape.js | 38 +- src/physics/world/index.js | 89 +- src/render/backgrounds/index.js | 2 +- src/render/camController.js | 48 - src/render/camera.js | 52 +- src/render/geometry/circlegeometry.js | 24 +- src/render/geometry/geometry.js | 28 +- src/render/index.js | 4 +- src/render/material/BasicMaterial.js | 45 +- src/render/material/ImageMaterial.js | 0 src/render/material/StaticImageMaterial.js | 43 - src/render/material/index.js | 4 +- src/render/material/material.js | 16 +- src/render/renderers/canvas.js | 39 +- src/render/renderers/renderer.js | 2 +- src/render/sprites/AgentSprite.js | 34 +- src/render/sprites/bodysprite.js | 17 +- src/render/sprites/group.js | 10 +- .../imagesprite.js} | 57 +- src/render/sprites/index.js | 7 +- src/render/sprites/particleSystem.js | 63 +- src/render/sprites/sprite.js | 82 +- src/render/sprites/staticimagesprite.js | 53 + src/render/utils/canvasfunc.js | 32 - src/utils/clock.js | 4 +- src/utils/common.js | 15 +- src/utils/index.js | 1 + .../pools/VectorPool.js | 0 src/utils/pools/index.js | 0 .../pools/objectPool.js | 0 351 files changed, 10358 insertions(+), 31030 deletions(-) delete mode 100644 demos/circle.js delete mode 100644 demos/circlestack.js delete mode 100644 demos/marterial.js delete mode 100644 demos/particle.js delete mode 100644 docs/AI_paths_path.js.html delete mode 100644 docs/AgentSprite.html delete mode 100644 docs/BasicMaterial.html delete mode 100644 docs/BufferGeometry_BufferGeometry.html delete mode 100644 docs/CamController_CamController.html delete mode 100644 docs/CircleGeometry_CircleGeometry.html delete mode 100644 docs/Geometry.html delete mode 100644 docs/Group.html delete mode 100644 docs/Line.html delete mode 100644 docs/Material.html delete mode 100644 docs/Node.html delete mode 100644 docs/ParticleSystemSprite.html delete mode 100644 docs/SpriteMaterial.html delete mode 100644 docs/StaticImageMaterial.html delete mode 100644 docs/dataStructures_pools_VectorPool.js.html delete mode 100644 docs/dataStructures_pools_objectPool.js.html delete mode 100644 docs/physics_shapes_geometry.js.html delete mode 100644 docs/physics_shapes_line.js.html delete mode 100644 docs/render_camController.js.html delete mode 100644 docs/render_camera.js.html delete mode 100644 docs/render_geometry_circlegeometry.js.html delete mode 100644 docs/render_geometry_geometry.js.html delete mode 100644 docs/render_material_BasicMaterial.js.html delete mode 100644 docs/render_material_SpriteMaterial.js.html delete mode 100644 docs/render_material_StaticImageMaterial.js.html delete mode 100644 docs/render_material_material.js.html delete mode 100644 docs/render_utils_canvasfunc.js.html create mode 100644 legacy/src/index.js create mode 100644 legacy/src/inputs/eventDispatcher.js create mode 100644 legacy/src/inputs/eventHandler.js create mode 100644 legacy/src/inputs/index.js create mode 100644 legacy/src/inputs/input.js create mode 100644 legacy/src/inputs/keyboard.js create mode 100644 legacy/src/inputs/mouse.js create mode 100644 legacy/src/inputs/touch.js create mode 100644 legacy/src/manager/component.js create mode 100644 legacy/src/manager/entity.js create mode 100644 legacy/src/manager/index.js create mode 100644 legacy/src/manager/manager.js create mode 100644 legacy/src/physics/AABB/AABB.js create mode 100644 legacy/src/physics/AABB/boundingBox.js create mode 100644 legacy/src/physics/AABB/boundingSphere.js create mode 100644 legacy/src/physics/AABB/index.js create mode 100644 legacy/src/physics/SAT/clutter.js create mode 100644 legacy/src/physics/SAT/index 1.js create mode 100644 legacy/src/physics/SAT/index.js create mode 100644 legacy/src/physics/SAT/last.js create mode 100644 legacy/src/physics/SAT/working.js create mode 100644 legacy/src/physics/bodies/ball.js create mode 100644 legacy/src/physics/bodies/body.js create mode 100644 legacy/src/physics/bodies/box.js create mode 100644 legacy/src/physics/bodies/heightMap.js create mode 100644 legacy/src/physics/bodies/index.js create mode 100644 legacy/src/physics/bodies/wall.js create mode 100644 legacy/src/physics/constraints/angleConstraint.js create mode 100644 legacy/src/physics/constraints/constraint.js create mode 100644 legacy/src/physics/constraints/distanceConstraint.js create mode 100644 legacy/src/physics/constraints/index.js create mode 100644 legacy/src/physics/constraints/springConstraint.js create mode 100644 legacy/src/physics/index.js create mode 100644 legacy/src/physics/integrators/euler.js create mode 100644 legacy/src/physics/integrators/index.js create mode 100644 legacy/src/physics/integrators/rungeKutter.js create mode 100644 legacy/src/physics/integrators/verlet.js create mode 100644 legacy/src/physics/shapes/circle.js create mode 100644 legacy/src/physics/shapes/geometry.js create mode 100644 legacy/src/physics/shapes/index.js create mode 100644 legacy/src/physics/shapes/line.js create mode 100644 legacy/src/physics/shapes/rectangle.js create mode 100644 legacy/src/physics/shapes/shape.js create mode 100644 legacy/src/physics/shapes/triangle.js create mode 100644 legacy/src/physics/solvers/contactSolver.js create mode 100644 legacy/src/physics/solvers/frictionSolver.js create mode 100644 legacy/src/physics/solvers/impulseSolver.js create mode 100644 legacy/src/physics/solvers/index.js create mode 100644 legacy/src/physics/solvers/penetrationSolver.js create mode 100644 legacy/src/physics/spartial.js create mode 100644 legacy/src/physics/utils/collisionManifold.js create mode 100644 legacy/src/physics/utils/pool.js create mode 100644 legacy/src/physics/world/index 1.js create mode 100644 legacy/src/physics/world/index.js create mode 100644 legacy/src/render/camera.js create mode 100644 legacy/src/render/index.js create mode 100644 legacy/src/render/meshes/bodyMesh.js create mode 100644 legacy/src/render/meshes/debugMesh.js create mode 100644 legacy/src/render/meshes/index.js create mode 100644 legacy/src/render/meshes/mesh.js create mode 100644 legacy/src/render/renderer.js create mode 100644 legacy/src/render/utils/index.js create mode 100644 legacy/src/render/utils/parallaxBackground.js create mode 100644 legacy/src/render/utils/particleSystem.js create mode 100644 legacy/src/render/utils/sprite.js create mode 100644 legacy/src/store/AABBTree.js create mode 100644 legacy/src/store/index.js create mode 100644 legacy/src/store/quadTree.js create mode 100644 legacy/src/store/spatialGrid.js create mode 100644 legacy/src/utils/accumulator.js create mode 100644 legacy/src/utils/clock.js create mode 100644 legacy/src/utils/degree.js create mode 100644 legacy/src/utils/generics.js create mode 100644 legacy/src/utils/idgenerator.js create mode 100644 legacy/src/utils/index.js create mode 100644 legacy/src/utils/math/index.js create mode 100644 legacy/src/utils/math/math.js create mode 100644 legacy/src/utils/matrix.js create mode 100644 legacy/src/utils/objectPool.js create mode 100644 legacy/src/utils/sort.js create mode 100644 legacy/src/utils/splines/bezier.js create mode 100644 legacy/src/utils/splines/catwellRom.js create mode 100644 legacy/src/utils/splines/hermite.js rename {src/dataStructures/pools => legacy/src/utils/splines}/index.js (100%) create mode 100644 legacy/src/utils/splines/linear.js create mode 100644 legacy/src/utils/vector.js create mode 100644 legacy/src/utils/vectorPool.js create mode 100644 server.js delete mode 100644 src/dataStructures/index.js delete mode 100644 src/dataStructures/indexedList.js delete mode 100644 src/math/functions.js delete mode 100644 src/math/interpolation.js delete mode 100644 src/physics/narrowphase/Narrowphase.js delete mode 100644 src/physics/narrowphase/SATNarrowphase.js delete mode 100644 src/physics/narrowphase/index.js delete mode 100644 src/render/camController.js create mode 100644 src/render/material/ImageMaterial.js delete mode 100644 src/render/material/StaticImageMaterial.js rename src/render/{material/SpriteMaterial.js => sprites/imagesprite.js} (71%) create mode 100644 src/render/sprites/staticimagesprite.js rename src/{dataStructures => utils}/pools/VectorPool.js (100%) create mode 100644 src/utils/pools/index.js rename src/{dataStructures => utils}/pools/objectPool.js (100%) diff --git a/README.md b/README.md index 97a4b4df..007c2e17 100644 --- a/README.md +++ b/README.md @@ -64,10 +64,7 @@ import * as CHAOS from "chaos-studio" ``` ### OR: -Get the [umd file](https://github.com/waynemwashuma/chaos-engine/dist) -from the dist folder of the [repository](https://github.com/waynemwashuma/chaos-engine), -put it in your root directory and add it to -your html page like so: +Get the umd file from the dist folder of the [repository](https://github.com/waynemwashuma/chaos-engine),put it in your root directory and add it to your html page like so: ```html @@ -101,7 +98,6 @@ game.registerSystem("renderer", renderer) game.registerSystem("world", world) //this binds the renderer to html. -//the canvas will be a child to the queried html element(renderer will attach it to the html element with id of "can") renderer.bindTo("#can") //This sets the width and height of the renderer to cover the entire screen. @@ -121,18 +117,18 @@ let box = CHAOS.Entity.Default(innerWidth / 2, 100) let boxBody = new CHAOS.Box(40, 40) //Creates a component that can be rendered onto the screen. -let boxSprite = new CHAOS.BodySprite() +let boxMesh = new CHAOS.BodySprite() //Adds the physics body to the entity. box.attach("body", boxBody) //Adds the sprite to the entity. -box.attach("sprite", boxSprite) +box.attach("sprite", boxMesh) //Adds the box to the game to be updated every frame. game.add(box) ``` -### Adding ground +### Adding groundhttp Now you should see a box falling into nothingness. Lets add ground it can land on. @@ -140,11 +136,11 @@ Lets add ground it can land on. //Creates an entity that we call ground on which we can add(attach) component to. let ground = CHAOS.Entity.Default(innerWidth / 2, innerHeight - 100) -//Creates a physics component to iteract physically with other entities +//Creates a component that can be rendered onto the screen. let groundBody = new CHAOS.Box(400, 20) //Adds the sprite to the entity. -let groundSprite = new CHAOS.BodySprite() +let groundMesh = new CHAOS.BodySprite() //sets the body to not move or respond to collisions. groundBody.type = CHAOS.Body.STATIC @@ -153,7 +149,7 @@ groundBody.type = CHAOS.Body.STATIC ground.attach("body", groundBody) //Adds the sprite to the entity. -ground.attach("sprite", groundSprite) +ground.attach("sprite", groundMesh) //Adds the ground to the game to be updated every frame. game.add(ground) @@ -162,7 +158,18 @@ game.add(ground) # **** WARNING **** -This is not yet a stable version hence dont rely on it to make production apps yet. +Upgrade from v0.0.0 to v0.1.0 as it is not yet stable + +Some of these include breaking changes like +the transfer from inheritance model to the +entity component systems model + +The legacy folder contains the last working +form of the inheritance model,check the differences between the last commit and it(many changes were realised between the two) + +Major changes were made during the last two months.Check the differences between legacy and src + +This is not yet a stable version hence dont rely on it to make production apps @@ -172,8 +179,10 @@ This is not yet a stable version hence dont rely on it to make production apps y - Stabilize the collision response to work well with large forces such as (gravity = 10000) - Stabilize rotational stacking in the physics engine - Add game state class for managing the game + + - Migrate some other parts of the code to the new model( Meshes for example )✅ - Add an animation system. - Add tutorials to this game engine + - Add documentation to every file in this project.✅ - Add appropriate demos to the project and get a website running for them 🟠 - - Add some error handling mechanisms 🟠 - - Add Serialization/Deserialization of objects(on the way) 🟠 \ No newline at end of file + - Add some error handling mechanisms 🟠 \ No newline at end of file diff --git a/configs/tsconfig.json b/configs/tsconfig.json index 7c2ce3e9..a05c719a 100644 --- a/configs/tsconfig.json +++ b/configs/tsconfig.json @@ -6,6 +6,7 @@ "declaration": true, "emitDeclarationOnly": true, "allowJs": true, + "outFile":"../dist/index.d.ts", "removeComments":true } } \ No newline at end of file diff --git a/demos/box.js b/demos/box.js index 186a23fc..73f46edb 100644 --- a/demos/box.js +++ b/demos/box.js @@ -1,6 +1,10 @@ import { + Vector, + DistanceConstraint, Entity, Box, + Ball, + Composite, BodySprite } from "/src/index.js" export function box(manager) { diff --git a/demos/bridge.js b/demos/bridge.js index 38f16b1c..d95ae85c 100644 --- a/demos/bridge.js +++ b/demos/bridge.js @@ -1,13 +1,14 @@ import { Vector, Manager, + DebugMesh, Box, Ball, - DistanceConstraint, + SpringConstraint, rand, Entity, BodySprite -} from "/src/index.js" +} from "/dist/chaos.module.js" export function bridge(manager) { let world = manager.getSystem("world") @@ -44,9 +45,7 @@ function createChain(x, y, w, h, number, spacing, pin1, pin2) { for (var i = 1; i < number; i++) { let chain = new Box(w, h) - let an1 = prev.setAnchor(new Vector(w/2,0)) - let an2 = prev.setAnchor(new Vector(w/2,0)) - let constraint = new DistanceConstraint(prev, chain, prev.getAnchor(an1),chain.getAnchor(an2)) + let constraint = new SpringConstraint(prev, chain, { x: w / 2, y: 0 }, { x: -w / 2, y: 0 }) bodies.push( Entity.Default(x * i, y) @@ -58,16 +57,15 @@ function createChain(x, y, w, h, number, spacing, pin1, pin2) { prev = chain } if (pin1) { - let an1 = pin1.get("body").setAnchor(new Vector(0,0)) - let an2 = bodies[0].get("body").setAnchor(new Vector(-w/2,0)) - let constraint = new DistanceConstraint(pin1.get("body"), bodies[0].get("body"), pin1.get("body").getAnchor(an1), bodies[0].get("body").getAnchor(an2)) + let constraint = new SpringConstraint(pin1.get("body"), bodies[0].get("body"), { x: 0, y: 0 }, { x: -w / 2, y: 0 }) constraints.push(constraint) pin1.get("body").mask.group = 1 } if (pin2) { - let an1 = pin2.get("body").setAnchor(new Vector(0,0)) - let an2 = bodies[bodies.length - 1].get("body").setAnchor(new Vector(w/2,0)) - let constraint = new DistanceConstraint(pin2.get("body"), bodies[bodies.length - 1].get("body"), pin2.get("body").getAnchor(an1), bodies[bodies.length - 1].get("body").getAnchor(an2)) + let constraint = new SpringConstraint( + pin2.get("body"), + bodies[bodies.length - 1].get("body"), { x: 0, y: 0 }, { x: w / 2, y: 0 } + ) constraints.push(constraint) pin2.get("body").mask.group = 1 } diff --git a/demos/car.js b/demos/car.js index 9781027c..933d5a5e 100644 --- a/demos/car.js +++ b/demos/car.js @@ -6,7 +6,7 @@ import { Ball, Composite, BodySprite -} from "/src/index.js"//"/src/index.js" +} from "/dist/chaos.module.js"//"/src/index.js" export function car(manager) { let world = manager.getSystem("world") diff --git a/demos/circle.js b/demos/circle.js deleted file mode 100644 index 08312a74..00000000 --- a/demos/circle.js +++ /dev/null @@ -1,17 +0,0 @@ -import { - Entity, - Ball, - BodySprite -} from "/src/index.js" - -export function circle(manager) { - let world = manager.getSystem("world") - - let box = Entity.Default(200,100) - let body = new Ball(20) - - box.attach("body",body) - .attach("sprite",new BodySprite()) - manager.add(box) - world.gravity = 980 -} \ No newline at end of file diff --git a/demos/circlestack.js b/demos/circlestack.js deleted file mode 100644 index 4a446742..00000000 --- a/demos/circlestack.js +++ /dev/null @@ -1,20 +0,0 @@ -import { - BodySprite, - Ball, - Entity -} from "/src/index.js" - - -export function circlestacking(manager) { - stack(200, 300,25, 8, 5, manager) - manager.getSystem("world").gravity = 980 -} - -function stack(x, y,r, no, spacing, manager) { - for (var i = 0; i < no; i++) { - let entity = Entity.Default(x, y + (r + spacing) * i) - .attach("body",new Ball(r)) - .attach("sprite",new BodySprite()) - manager.add(entity) - } -} \ No newline at end of file diff --git a/demos/index.js b/demos/index.js index 90cac198..0e79163e 100644 --- a/demos/index.js +++ b/demos/index.js @@ -5,21 +5,19 @@ import { pyramid } from "./pyramid.js" import { random } from "./random.js" import { constraint } from "./constraints.js" import { pathfollower } from "./pathfollower.js" -import { materials } from "./marterial.js" import { box } from "./box.js" -import { particle } from "./particle.js" -import { circle } from "./circle.js" -import { circlestacking } from "./circlestack.js" + import { Manager, Renderer2D, World, AgentManager, + DebugMesh, Entity, Box, BodySprite, Body -} from "/src/index.js" +} from "/dist/chaos.module.js" function createBoundingBox(x, y, w, h, t = 20) { let l1 = { @@ -91,7 +89,7 @@ export const demos = { window.onresize = () => { renderer.setViewport(innerWidth, innerHeight) } - //renderer.addUI(new DebugMesh(this.manager)) + renderer.addUI(new DebugMesh(this.manager)) }, setup: function(name) { this.manager.clear() @@ -114,7 +112,3 @@ demos.register("constraints",constraint) demos.register("pathfollower",pathfollower) demos.register("box",box) demos.register("random",random) -demos.register("materials",materials) -demos.register("particle",particle) -demos.register("circlestacking",circlestacking) -demos.register("circle",circle) \ No newline at end of file diff --git a/demos/main.js b/demos/main.js index aca5d750..aa98c652 100644 --- a/demos/main.js +++ b/demos/main.js @@ -3,7 +3,7 @@ import { demos } from "./index.js" demos.init("#can") -demos.setup("bridge") +demos.setup("box") let optionTab = document.querySelector("#options-checkbox") let demoOption = document.querySelector("#demos") diff --git a/demos/marterial.js b/demos/marterial.js deleted file mode 100644 index ee703111..00000000 --- a/demos/marterial.js +++ /dev/null @@ -1,55 +0,0 @@ -import { - Sprite, - BufferGeometry, - BasicMaterial, - StaticImageMaterial, - SpriteMaterial, - Material, - Vector, - Entity -} from "/src/index.js" -const assets = { - static: "./assets/static2.jpeg" -} - - -export function materials(manager) { - manager.clear() - let renderer = manager.getSystem("renderer") - let geometry = new BufferGeometry([ - new Vector(-50, -50), - new Vector(-50, 50), - new Vector(50, 50), - new Vector(50, -50) - ]) - - //Basic material - let material1 = new BasicMaterial() - let sprite1 = createsprite(60, 60, geometry, material1) - manager.add(sprite1) - - //Static Image material - let img = new Image() - img.src = assets.static - let material2 = new StaticImageMaterial(img) - let sprite2 = createsprite(170, 60, geometry, material2) - manager.add(sprite2) - - //Sprite material - let img2 = new Image() - img2.src = assets.static - - let material3 = new SpriteMaterial(img) - let sprite3 = createsprite(290, 60,geometry, material3) - manager.add(sprite3) - img2.onload = () => { - material3.setup(9, 6) - material3.frameRate = 1 / 10 - } -} - -function createsprite(x, y, geometry, material) { - let entity = Entity.Default(x, y) - entity.attach("sprite", new Sprite(geometry, material)) - return entity -} \ No newline at end of file diff --git a/demos/particle.js b/demos/particle.js deleted file mode 100644 index aa3188f7..00000000 --- a/demos/particle.js +++ /dev/null @@ -1,17 +0,0 @@ -import { - Sprite, - ParticleSystemSprite, - Vector, - Entity -} from "/src/index.js" - -export function particle(manager) { - manager.clear() - let renderer = manager.getSystem("renderer") - - let entity = Entity.Default(innerWidth/2,innerHeight/2 -200) - let sprite = new ParticleSystemSprite(10,1000) - entity.attach("sprite",sprite) - - manager.add(entity) -} \ No newline at end of file diff --git a/demos/pathfollower.js b/demos/pathfollower.js index e55c4af3..577bb140 100644 --- a/demos/pathfollower.js +++ b/demos/pathfollower.js @@ -12,7 +12,7 @@ import { WanderBehaviour, Path, Vector -} from "/src/index.js" +} from "/dist/chaos.module.js" export function pathfollower(manager) { diff --git a/demos/pyramid.js b/demos/pyramid.js index 35d91356..2713b8b0 100644 --- a/demos/pyramid.js +++ b/demos/pyramid.js @@ -1,4 +1,4 @@ -import { Box, BodySprite, Entity, Vector } from "/src/index.js" +import { Box, BodySprite, Entity, Vector } from "/dist/chaos.module.js" export function pyramid(manager) { stackpyramid(200, 100, 50, 50, 3, 5, manager) diff --git a/demos/random.js b/demos/random.js index 7423e4a3..615417c5 100644 --- a/demos/random.js +++ b/demos/random.js @@ -6,7 +6,7 @@ import { Entity, Box, Ball -} from "/src/index.js" +} from "/dist/chaos.module.js" export function random(manager) { let world = manager.getSystem("world") diff --git a/demos/stacking.js b/demos/stacking.js index 730069bd..aee9e9f6 100644 --- a/demos/stacking.js +++ b/demos/stacking.js @@ -2,7 +2,7 @@ import { BodySprite, Box, Entity -} from "/src/index.js" +} from "/dist/chaos.module.js" export function stacking(manager) { diff --git a/dist/chaos.module.d.ts b/dist/chaos.module.d.ts index bf0c5729..5403ba94 100644 --- a/dist/chaos.module.d.ts +++ b/dist/chaos.module.d.ts @@ -1,2394 +1,1077 @@ -export type Traverser = (node: Node) => boolean; export type Bounds = { - max: Vector_like; - min: Vector_like; + max: Vector_like; + min: Vector_like; }; export type CollisionPair = { - a: Body; - b: Body; + a: Body; + b: Body; }; export type Manifold = { - bodyA: Body; - bodyB: Body; - contactData: ContactManifold; - stmp: number; - impulse: number; - persistent: boolean; - ca1: Vector; - ca2: Vector; - restitution: number; - staticFriction: number; - kineticFriction: number; - velA: Vector; - velB: Vector; - rotA: number; - rotB: number; + bodyA: Body; + bodyB: Body; + contactData: ContactManifold; + stmp: number; + impulse: number; + persistent: boolean; + ca1: Vector; + ca2: Vector; + restitution: number; + staticFriction: number; + kineticFriction: number; + velA: Vector; + velB: Vector; + rotA: number; + rotB: number; }; export type ContactManifold = { - lastOverlap: number; - overlap: number; - done: boolean; - axis: Vector; - verticesA: Vector[]; - verticesB: Vector[]; - vertShapeA: Shape; - vertShapeB: Shape; - contactNo: number; - indexA: number; - indexB: number; + lastOverlap: number; + overlap: number; + done: boolean; + axis: Vector; + verticesA: Vector[]; + verticesB: Vector[]; + vertShapeA: Shape; + vertShapeB: Shape; + contactNo: number; + indexA: number; + indexB: number; }; export type Vector_like = { - x: number; - y: number; + x: number; + y: number; }; export class Agent implements Component { - position: Vector; - velocity: Vector; - acceleration: Vector; - orientation: Angle; - rotation: Angle; - maxSpeed: number; - maxTurnRate: number; - private behaviours; - init(entity: Entity): void; - entity: Entity; - add(behaviour: Behaviour): void; - remove(behaviour: Behaviour): void; - update(inv_dt: number): void; - draw(ctx: CanvasRenderingContext2D): void; + position: Vector; + velocity: Vector; + acceleration: Vector; + orientation: Angle; + rotation: Angle; + maxSpeed: number; + maxTurnRate: number; + private behaviours; + init(entity: Entity): void; + entity: Entity; + add(behaviour: Behaviour): void; + remove(behaviour: Behaviour): void; + update(inv_dt: number): void; + Entity: any; + draw(renderer: Renderer): void; } export class AgentManager { - objects: Agent[]; - init(manager: Manager): void; - update(dt: number): void; + objects: Agent[]; + init(manager: Manager): void; + update(dt: number): void; } export class AgentSprite extends Sprite { - constructor(); - private agent; - init(entity: Entity): void; - render(ctx: CanvasRenderingContext2D): void; + private agent; + init(entity: Entity): void; + draw(renderer: Renderer): void; + render(renderer: Renderer): void; } export class Angle { - constructor(deg?: number); - private _deg; - private _rad; - get CHOAS_CLASSNAME(): string; - get CHAOS_OBJ_TYPE(): string; - set degree(arg: number); - get degree(): number; - set radian(arg: number); - get radian(): number; - copy(angle: Angle): void; - fromJSON(obj: any): void; - toJson(): { - deg: number; - type: string | number; - }; + static fromJSON(obj: any): Angle; + constructor(deg ? : number); + private _deg; + private _rad; + get CHOAS_CLASSNAME(): any; + get CHAOS_OBJ_TYPE(): string; + set degree(arg: number); + get degree(): number; + set radian(arg: number); + get radian(): number; + copy(angle: Angle): void; } export class ArriveBehaviour extends Behaviour { - constructor(target: Vector); - radius: number; - target: Vector; + constructor(target: Vector); + radius: number; + target: Vector; } export class AudioHandler { - private ctx; - private sfx; - private _backname; - private _background; - private playing; - private toplay; - private _mute; - private masterGainNode; - baseUrl: string; - canPlay: boolean; - load(src: string): void; - loadFromLoader(loader: Loader): void; - playBackgroundMusic(name: string): void; - playEffect(name: string, offset?: number, duration?: number): void; - createSfx(name: string): Sfx; - pauseAll(): void; - mute(): void; - unmute(): void; - remove(sfx: Sfx): void; + private ctx; + private sfx; + private _backname; + private _background; + playing: any[]; + toplay: {}; + baseUrl: string; + private _mute; + private masterGainNode; + canPlay: boolean; + load(src: string): void; + loadFromLoader(loader: Loader): void; + playBackgroundMusic(name: string): void; + playEffect(name: string, offset ? : number, duration ? : number): void; + createSfx(name: string): Sfx; + pauseAll(): void; + mute(): void; + unmute(): void; + remove(sfx: Sfx): void; } export class Ball extends Body { - constructor(radius: number); + constructor(radius: number); } -export class BasicMaterial implements Material { - fill: string; - stroke: string; - wireframe: boolean; - render(ctx: CanvasRenderingContext2D, dt: number, path: Path2D): void; +export class BasicMaterial { + fill: string; + lineWidth: number; + stroke: string; + wireframe: boolean; + render(ctx: any): void; } export class Behaviour { - position: Vector; - velocity: Vector; - maxSpeed: number; - maxForce: number; - active: boolean; - init(agent: Agent): void; - calc(target: Vector, inv_dt: number): void; - draw(renderer: Renderer): void; + position: Vector; + velocity: Vector; + maxSpeed: number; + maxForce: number; + active: boolean; + init(agent: Agent): void; + calc(target: Vector, inv_dt: number): void; + draw(renderer: Renderer): void; } export class Body implements Component { - static STATIC: number; - static KINEMATIC: number; - static DYNAMIC: number; - constructor(...shapes: Shape[]); - id: number; - private _position; - private _velocity; - private _acceleration; - private _orientation; - private _rotation; - private _mass; - private _inertia; - private _type; - private _localanchors; - private anchors; - lastPosition: Vector; - inv_mass: number; - inv_inertia: number; - restitution: number; - staticFriction: number; - kineticFriction: number; - boundPadding: number; - index: number; - mask: { - layer: number; - group: number; - }; - entity: Entity | null; - bounds: BoundingBox | BoundingCircle | null; - shapes: Shape[]; - client: any | null; - allowSleep: boolean; - sleeping: boolean; - aabbDetectionOnly: boolean; - collisionResponse: boolean; - autoUpdateBound: boolean; - set type(arg: number); - get type(): number; - set mass(arg: number); - get mass(): number; - set inertia(arg: number); - get inertia(): number; - get physicsType(): number; - get CHOAS_CLASSNAME(): string; - get CHAOS_OBJ_TYPE(): string; - set acceleration(arg: Vector); - get acceleration(): Vector; - set velocity(arg: Vector); - get velocity(): Vector; - set rotation(arg: Angle); - get rotation(): Angle; - set angle(arg: number); - get angle(): number; - set density(arg: number); - get density(): number; - set position(arg: Vector); - get position(): Vector; - set orientation(arg: Angle); - get orientation(): Angle; - set angularVelocity(arg: number); - get angularVelocity(): number; - setAnchor(v: Vector): number; - getAnchor(index: number): Vector; - getLocalAnchor(index: number, target?: Vector): Vector; - applyForce(force: Vector, arm?: Vector): void; - init(entity: Entity | null, composited?: boolean): void; - update(): void; - toJson(): { - id: number; - position: any; - velocity: any; - acceleration: any; - orientation: { - deg: number; - type: string | number; - }; - rotation: { - deg: number; - type: string | number; - }; - shapes: any[]; - anchors: any[]; - collisionResponse: boolean; - allowSleep: boolean; - type: string; - phyType: number; - mass: number; - inertia: number; - autoUpdateBound: boolean; - boundPadding: number; - aabbDetectionOnly: boolean; - mask: { - layer: number; - group: number; - }; - }; - fromJson(obj: any): void; + static STATIC: number; + static KINEMATIC: number; + static DYNAMIC: number; + constructor(...shapes: Shape[]); + id: number; + private _position; + private _velocity; + private _acceleration; + private _orientation; + private _rotation; + private _mass; + private _inertia; + private _type; + private _localanchors; + private anchors; + lastPosition: Vector; + inv_mass: number; + inv_inertia: number; + restitution: number; + staticFriction: number; + kineticFriction: number; + boundPadding: number; + index: number; + mask: { + layer: number; + group: number; + }; + entity: Entity | null; + bounds: BoundingBox | BoundingCircle | null; + shapes: Shape[]; + client: any | null; + allowSleep: boolean; + sleeping: boolean; + aabbDetectionOnly: boolean; + collisionResponse: boolean; + autoUpdateBound: boolean; + set type(arg: number); + get type(): number; + set mass(arg: number); + get mass(): number; + set inertia(arg: number); + get inertia(): number; + get physicsType(): number; + get CHOAS_CLASSNAME(): any; + get CHAOS_OBJ_TYPE(): string; + set acceleration(arg: Vector); + get acceleration(): Vector; + set velocity(arg: Vector); + get velocity(): Vector; + set rotation(arg: Angle); + get rotation(): Angle; + set angle(arg: number); + get angle(): number; + set density(arg: number); + get density(): number; + set position(arg: Vector); + get position(): Vector; + set orientation(arg: Angle); + get orientation(): Angle; + set angularVelocity(arg: number); + get angularVelocity(): number; + setAnchor(v: Vector): number; + getAnchor(index: number): Vector; + getLocalAnchor(index: number, target ? : Vector): Vector; + applyForce(force: Vector, arm ? : Vector): void; + init(entity: Entity | null, composited ? : boolean): void; + update(): void; } export class BodySprite extends Sprite { - constructor(options?: {}); - private body; - drawVelocity: boolean; - drawBounds: boolean; - render(ctx: CanvasRenderingContext2D, dt: number): void; - private _drawVelocity; - private _drawBound; - private _drawShapes; - init(parent: Entity): void; -} -export class Bound extends Component implements Component { - bounds: BoundingBox | BoundingCircle; - entity: any; - toJson(): { - bounds: { - posX: number; - posY: number; - minX: number; - minY: number; - maxX: number; - maxY: number; - } | { - posX: number; - posY: number; - r: number; - }; - }; - fromJson(obj: any): void; + constructor(options ? : {}); + private body; + drawVelocity: boolean; + drawBounds: boolean; + private _drawVelocity; + private _drawBound; + private _drawShapes; + init(parent: Entity): void; } export class BoundingBox extends Component { - static union(bound1: BoundingBox, bound2: BoundingBox, target: BoundingBox): BoundingBox; - constructor(minX?: number, minY?: number, maxX?: number, maxY?: number); - pos: Vector_like; - max: Vector_like; - min: Vector_like; - intersects(bound: BoundingCircle | BoundingBox): boolean; - calculateBounds(body: Body, padding?: number): void; - update(pos: Vector): void; - clone(): BoundingBox; - copy(bounds: BoundingBox): void; - toJson(): { - posX: number; - posY: number; - minX: number; - minY: number; - maxX: number; - maxY: number; - }; - fromJson(obj: any): void; + static union(bound1: BoundingBox, bound2: BoundingBox, target: BoundingBox): BoundingBox; + constructor(minX ? : number, minY ? : number, maxX ? : number, maxY ? : number); + pos: Vector_like; + max: Vector_like; + min: Vector_like; + intersects(bound: BoundingBox): boolean; + calculateBounds(body: Body, padding ? : number): void; + update(pos: Vector): void; + clone(): BoundingBox; + copy(bounds: BoundingBox): void; } export class BoundingCircle { - constructor(r?: number); - r: number; - pos: Vector_like; - intersects(bound: BoundingCircle | BoundingBox): boolean; - calculateBounds(body: Body, padding?: number): void; - update(pos: Vector_like): void; - toJson(): { - posX: number; - posY: number; - r: number; - }; - fromJson(obj: any): void; + constructor(r ? : number); + r: number; + pos: Vector_like; + intersects(bound: BoundingBox): boolean; + calculateBounds(body: Body, padding ? : number): void; + update(pos: any): void; } export class Box extends Body { - constructor(w: number, h: number); + constructor(w: number, h: number); } export class BufferGeometry { - constructor(vertices: Vector[]); - readonly vertices: Vector[]; - drawable: Path2D | WebGLVertexArrayObject; - init(ctx: CanvasRenderingContext2D): void; -} -export class CamController { - constructor(camera: Camera); - readonly offset: Vector; - transform: Transform; - targetPosition: any; - targetOrientation: Angle; - follow(position: Vector, orientation?: Angle): void; - followEntity(entity: Entity): void; - setOffset(x: number, y: number): void; - init(): void; - update(): void; -} -export class Camera { - readonly transform: Transform; - set position(arg: Vector); - get position(): Vector; - update(): void; + constructor(vertices: any); + vertices: any; + render(renderer: any): void; } export class Circle extends Shape { - static calcInertia(mass: number, radius: number): number; - constructor(radius: number, offset: Vector, offsetAngle: number); - radius: number; - vertices: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }[]; - type: number; - get position(): { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - toJson(): { - radius: number; - offset: Vector; - offAngle: number; - shapeType: number; - type: string; - }; - fromJson(obj: any): Circle; + static calcInertia(mass: number, radius: number): number; + constructor(radius: number, offset: Vector, offsetAngle: number); + radius: number; + type: number; + get position(): Vector; + getNormals(shape: Shape, target ? : Vector[]): Vector[]; } export class CircleGeometry { - constructor(radius: number); - radius: number; - init(ctx: CanvasRenderingContext2D): void; - _drawable: Path2D; - render(ctx: CanvasRenderingContext2D): void; + constructor(radius: any); + radius: any; + render(renderer: any): void; } export class Clock { - private lastcall; - dt: number; - update(accumulate: number): number; - delta: number; + private lastcall; + dt: number; + update(accumulate: number): number; + delta: number; } export class Component { - static fromJson(): void; - static toJson(): void; - entity: Entity | null; - destroy(): void; - get CHOAS_CLASSNAME(): string; - get CHAOS_OBJ_TYPE(): string; - init(entity: Entity): void; - update(dt: number): void; - get(n: string): any; - requires(...names: string[]): void; - query(bound: CircleBounding | BoxBounding, target?: Entity): Entity[]; + entity: Entity | null; } export class Composite { - entity: Entity | null; - bodies: Body[]; - constraints: Constraint[]; - get physicsType(): number; - init(entity: Entity | null): void; - add(object: Constraint | Body): number; - update(): void; - set acceleration(arg: Vector); - get acceleration(): Vector; - set velocity(arg: Vector); - get velocity(): Vector; - set angle(arg: number); - get angle(): number; - set mass(arg: number); - get mass(): number; - set density(arg: number); - get density(): number; - set position(arg: Vector); - get position(): Vector; - set orientation(arg: number); - get orientation(): number; - set angularVelocity(arg: number); - get angularVelocity(): number; + entity: Entity | null; + bodies: Body[]; + constraints: Constraint[]; + get physicsType(): number; + init(entity: Entity | null): void; + add(object: Constraint | Body): number; + update(): void; + set acceleration(arg: Vector); + get acceleration(): Vector; + set velocity(arg: Vector); + get velocity(): Vector; + set angle(arg: void); + get angle(): void; + set mass(arg: number); + get mass(): number; + set density(arg: number); + get density(): number; + set position(arg: Vector); + get position(): Vector; + set orientation(arg: any); + set angularVelocity(arg: number); + get angularVelocity(): number; } export class Constraint { - constructor(body1: Body, body2: Body, localA: Vector, localB: Vector); - body1: Body; - body2: Body; - localA: any; - localB: any; - stiffness: number; - dampening: number; - get physicsType(): number; - get CHOAS_CLASSNAME(): string; - get CHAOS_OBJ_TYPE(): string; - protected behavior(body1: Body, body2: Body, dt: number): void; - update(dt: number): void; - toJson(): { - body1: number; - body2: number; - localA: any; - stiffness: number; - dampening: number; - type: string; - }; - fromJson(obj: any, world: any): Constraint; + constructor(body1: Body, body2: Body, localA: Vector, localB: Vector); + body1: Body; + body2: Body; + localA: Vector; + localB: Vector; + stiffness: number; + dampening: number; + get physicsType(): number; + get CHOAS_CLASSNAME(): any; + get CHAOS_OBJ_TYPE(): string; + protected behavior(body1: Body, body2: Body, dt: number): void; + update(dt: number): void; } export namespace Cookies { - export function set(n: string, v: string, maxAge?: number): void; - export function get(n: string): string; - function _delete(n: string): void; - export { _delete as delete }; - export function clear(): void; + export function set(n: string, v: string, maxAge ? : number): void; + export function get(n: string): string; + + function _delete(n: string): void; + export { _delete as delete }; + export function clear(): void; } export namespace DEVICE { - let audio: boolean; - let canvas: boolean; - let webgl: boolean; + let audio: boolean; + let canvas: boolean; + let webgl: boolean; } export class DOMEventHandler { - private handlers; - private _evHandlers; - add(e: string, h: Function): number; - remove(e: string, h: Function): void; - disposeEvent(e: string): void; - clear(): void; - init(): void; + private handlers; + private _evHandlers; + add(e: string, h: Function): number; + remove(e: string, h: Function): void; + disposeEvent(e: string): void; + clear(): void; + init(): void; +} +export class DebugMesh extends Sprite { + constructor(manager: any); + manager: any; + count: number; + now: number; + lastPerf: {}; + drawBounds: boolean; } export class DistanceConstraint extends Constraint { - fixed: boolean; - maxDistance: number; -} -export namespace Easing { - namespace Linear { - function In(x: any): any; - function Out(x: any): any; - function InOut(x: any): any; - } - namespace Quadratic { - export function In_1(x: any): number; - export { In_1 as In }; - export function Out_1(x: any): number; - export { Out_1 as Out }; - export function InOut_1(x: any): number; - export { InOut_1 as InOut }; - } - namespace Cubic { - export function In_2(x: any): number; - export { In_2 as In }; - export function Out_2(x: any): number; - export { Out_2 as Out }; - export function InOut_2(x: any): number; - export { InOut_2 as InOut }; - } - namespace Quartic { - export function In_3(x: any): number; - export { In_3 as In }; - export function Out_3(x: any): number; - export { Out_3 as Out }; - export function InOut_3(x: any): number; - export { InOut_3 as InOut }; - } - namespace Quintic { - export function In_4(x: any): number; - export { In_4 as In }; - export function Out_4(x: any): number; - export { Out_4 as Out }; - export function InOut_4(x: any): number; - export { InOut_4 as InOut }; - } - namespace Sinusoidal { - export function In_5(x: any): number; - export { In_5 as In }; - export function Out_5(x: any): number; - export { Out_5 as Out }; - export function InOut_5(x: any): number; - export { InOut_5 as InOut }; - } - namespace Exponential { - export function In_6(x: any): number; - export { In_6 as In }; - export function Out_6(x: any): number; - export { Out_6 as Out }; - export function InOut_6(x: any): number; - export { InOut_6 as InOut }; - } - namespace Circular { - export function In_7(x: any): number; - export { In_7 as In }; - export function Out_7(x: any): number; - export { Out_7 as Out }; - export function InOut_7(x: any): number; - export { InOut_7 as InOut }; - } - namespace Elastic { - export function In_8(x: any): number; - export { In_8 as In }; - export function Out_8(x: any): number; - export { Out_8 as Out }; - export function InOut_8(x: any): number; - export { InOut_8 as InOut }; - } - namespace Back { - export function In_9(x: any): number; - export { In_9 as In }; - export function Out_9(x: any): number; - export { Out_9 as Out }; - export function InOut_9(x: any): number; - export { InOut_9 as InOut }; - } - namespace Bounce { - export function In_10(x: any): number; - export { In_10 as In }; - export function Out_10(x: any): number; - export { Out_10 as Out }; - export function InOut_10(x: any): number; - export { InOut_10 as InOut }; - } - function generatePow(power: any): { - In: (x: any) => number; - Out: (x: any) => number; - InOut: (x: any) => number; - }; + fixed: boolean; + dampen: number; + maxDistance: number; } export class Entity { - static Default(x: number, y: number, a: number): Entity; - private _components; - private _handlers; - private _tags; - private _global; - active: boolean; - get CHAOS_OBJ_TYPE(): string; - get CHAOS_CLASSNAME(): any; - destroy(): void; - removeSelf(): void; - removeComponents(): void; - get manager(): Manager; - attach(n: string, c: Component): this; - remove(n: string): this; - register(n: string, h: Function): void; - unregister(n: string): void; - getHandler(n: string): Function | undefined; - get(n: string): Component | undefined; - has(n: string): boolean; - addTag(n: string): void; - removeTag(n: string): void; - hasTag(n: string): boolean; - init(global: Manager): void; - query(bound: Bounds, target?: Entity[]): Entity[]; - fromJSON(obj: {}, compList: Map): this; - toJson(): { - deg: number; - type: string; - }; -} -declare namespace Err$1 { - export function warn(message: string): void; - function _throw(message: string): never; - export { _throw as throw }; - export function error(message: string): void; - export function log(message: string): void; - export function warnOnce(message: string): void; - export function assert(test: boolean, errfunc: Function, message: string): boolean; + static Default(x: any, y: any, a: any): Entity; + private _components; + private _handlers; + private _tags; + private _global; + active: boolean; + get CHAOS_OBJ_TYPE(): string; + get CHAOS_CLASSNAME(): any; + destroy(): void; + removeSelf(): void; + removeComponents(): void; + get manager(): Manager; + attach(n: string, c: Component): this; + remove(n: string): this; + register(n: string, h: Function): void; + unregister(n: string): void; + getHandler(n: string): Function | undefined; + get(n: string): Component | undefined; + has(n: string): boolean; + addTag(n: string): void; + removeTag(n: string): void; + hasTag(n: string): boolean; + init(global: Manager): void; + query(bound: Bounds, target ? : Entity[]): Entity[]; +} +export namespace Err { + export function warn(message: string): void; + + function _throw(message: string): never; + export { _throw as throw }; + export function error(message: string): void; + export function log(message: string): void; + export function warnOnce(message: string): void; + export function assert(test: boolean, errfunc: Function, message: string): boolean; } export class EvadeBehaviour extends Behaviour { - constructor(pursuer: Vector); - radius: number; - pursuer: Vector; + constructor(pursuer: Vector); + radius: number; + pursuer: Vector; } export class EventDispatcher { - private handlers; - trigger(n: string, data: any): void; - init(): void; - add(name: string, handler: Function): void; + private handlers; + trigger(n: string, data: any): void; + init(): void; + add(name: string, handler: Function): void; } export type Events = string; export namespace Events { - let COLLISION: string; - let PRECOLLISION: string; - let PREUPDATE: string; - let POSTUPDATE: string; - let UPDATE: string; - let INITIALIZE: string; - let ADD: string; - let REMOVE: string; - let PAUSE: string; - let PLAY: string; + let COLLISION: string; + let PRECOLLISION: string; + let PREUPDATE: string; + let POSTUPDATE: string; + let UPDATE: string; + let INITIALIZE: string; + let ADD: string; + let REMOVE: string; + let PAUSE: string; + let PLAY: string; } export class Flock { - neighbours: Agent[]; - init(agent: Agent): void; - calc(target: Vector, inv_dt: number): void; + neighbours: any[]; + init(): void; + calc(target: Vector): void; } export class Geometry { - constructor(vertices: Vector[]); - vertices: Vector[]; - normals: Vector[]; - _dynNormals: Vector[]; - get CHOAS_CLASSNAME(): string; - get CHAOS_OBJ_TYPE(): string; - getNormals(rad: number, target: Vector[]): Vector[]; - private calcFaceNormals; - transform(vertices: Vector[], pos: Vector, rad: any, n: number): void; - toJson(): { - vertices: any[]; - }; - fromJson(obj: any): void; -} -export class Group extends Sprite { - constructor(sprites?: Sprite[]); - private _children; - get CHOAS_CLASSNAME(): string; - get CHAOS_OBJ_TYPE(): string; - add(sprite: Sprite | Group): void; - remove(sprite: Sprite | Group, recursive?: boolean, index?: number): boolean; - render(ctx: CanvasRenderingContext2D, dt: number): void; + constructor(vertices: any); + vertices: any; + normals: any[]; + _dynNormals: any[]; + get CHOAS_CLASSNAME(): any; + get CHAOS_OBJ_TYPE(): string; + getNormals(rad: any, target: any): any; + calcFaceNormals(): any[]; + transform(vertices: any, pos: any, rad: any, n: any): void; +} +export class Grid extends Broadphase { + constructor(bounds: any, divX: any, divY: any); + bins: any[]; + bounds: any; + divX: any; + divY: any; + _hash(x: any, y: any): number[]; + private _insert; + private _remove; + private _update; + _naiveCheck(arr: any, ids: any, target: any): void; +} +export class HeightMap extends Body { + constructor(step: any, heights: any); +} +export class ImageSprite extends Sprite { + constructor(img: HTMLImageElement, frames: number, actions: number); + _index: number; + _maxFrame: number; + _frame: number; + _accumulator: number; + _dt: number; + frameRate: number; + _maxFrames: any; + width: number; + height: number; + frameWidth: number; + frameHeight: number; + img: HTMLImageElement; + setMaxFrames(action: number, max: number): void; + setAction(index: any): void; } export class Input { - constructor(eventHandler: DOMEventHandler); - DOMEventHandler: DOMEventHandler; - mouse: Mouse; - touch: Touch; - keyboard: Keyboard; - update(): void; - dispose(): void; -} -export namespace Interpolation { - export function Linear_1(p0: any, p1: any, t: any): any; - export { Linear_1 as Linear }; - export function Bernstein(n: any, i: any): any; - export function Factorial(n: any): number; - export function CatmullRom(p0: any, p1: any, p2: any, p3: any, t: any): any; + constructor(eventHandler: DOMEventHandler); + DOMEventHandler: DOMEventHandler; + mouse: Mouse; + touch: Touch; + keyboard: Keyboard; + update(): void; + dispose(): void; } export class Keyboard { - constructor(eh: DOMEventHandler); - keys: { - [x: string]: boolean; - }; - private normalize; - init(eh: DOMEventHandler): void; - private _onDown; - private _onUp; + constructor(eh: DOMEventHandler); + keys: { + [x: string]: boolean; + }; + private normalize; + init(eh: DOMEventHandler): void; + _onDown: (e: any) => void; + _onUp: (e: any) => void; + ondown(e: any): void; + onup(e: any): void; +} +export class Layer { + constructor(img: any); + speed: number; + img: any; + draw(ctx: any, x: any, y: any): void; + update(ctx: any, dt: any): void; } export class Line extends Shape { - constructor(length: number, offset: Vector, offsetAngle: any); - length: number; + constructor(length: any, offset: any, offsetAngle: any); + length: any; } export class Loader { - constructor(manager: any); - _toload: any[]; - imgs: {}; - sfx: {}; - json: {}; - _progressBytes: number; - _totalBytes: number; - _filesErr: number; - _filesLoaded: number; - _totalFileNo: number; - onfinish: any; - _handlers: { - onload: (xhr: any, e: any) => void; - onheadload: (e: any) => void; - onerror: (e: any) => void; - }; - _getName(url: any): any; - _getType(url: any): "audio" | "image" | "json"; - loadAll(files?: {}): void; + constructor(manager: any); + _toload: any[]; + imgs: {}; + sfx: {}; + json: {}; + _progressBytes: number; + _totalBytes: number; + _filesErr: number; + _filesLoaded: number; + _totalFileNo: number; + onfinish: any; + _handlers: { + onload: (xhr: any, e: any) => void; + onheadload: (e: any) => void; + onerror: (e: any) => void; + }; + _getName(url: any): any; + _getType(url: any): "audio" | "image" | "json"; + loadAll(files ? : {}): void; } export class Manager { - static DefaultSystem(name: string): System; - constructor(options?: { - autoPlay?: boolean; - files?: any; - physics?: boolean; - renderer?: boolean; - input?: boolean; - }); - private _rafID; - private _classes; - private _componentLists; - private _systems; - private _coreSystems; - private _initialized; - playing: boolean; - private _systemsMap; - private _compMap; - clock: Clock; - private objects; - private _accumulator; - frameRate: number; - perf: { - lastTimestamp: number; - total: number; - }; - readonly loader: Loader; - readonly events: EventDispatcher; - private _update; - init(): void; - add(object: Entity): void; - addComponent(n: string, c: Component): void; - removeComponent(n: string, c: Component): void; - remove(object: Entity): void; - clear(): void; - private RAF; - play(): void; - pause(): void; - private initSystems; - private update; - registerClass(obj: Function, override?: boolean): void; - registerSystem(n: string, sys: System, cn?: string): void; - getSystem(n: string): System; - unregisterSystem(n: string): void; - setComponentList(n: string, arr?: Component[]): void; - getComponentList(n: string): Component[]; - getEntityByComponents(comps: Array): Entity; - getEntitiesByComponents(comps: Array, entities?: Entity[], target?: Entity[]): Entity[]; - getEntityByTags(tags: Array): Entity; - getEntitiesByTags(tags: string[], entities?: Entity[], target?: Entity[]): Entity[]; - private infertype; - private clone; - query(bound: BoundingCircle | BoundingBpx): Body[]; + static DefaultSystem(name: string): System; + constructor(options ? : { + autoPlay ? : boolean; + files ? : any; + physics ? : boolean; + renderer ? : boolean; + input ? : boolean; + }); + private _rafID; + private _classes; + private _componentLists; + private _systems; + private _coreSystems; + private _initialized; + playing: boolean; + private _systemsMap; + private _compMap; + clock: Clock; + private objects; + private _accumulator; + frameRate: number; + perf: { + lastTimestamp: number; + total: number; + }; + readonly loader: Loader; + readonly events: EventDispatcher; + private _update; + init(): void; + add(object: Entity): void; + addComponent(n: string, c: Component): void; + removeComponent(n: string, c: Component): void; + remove(object: Entity): void; + clear(): void; + private RAF; + play(): void; + pause(): void; + private initSystems; + private update; + registerClass(obj: Function, override ? : boolean): void; + registerSystem(n: string, sys: System, cn ? : string): void; + getSystem(n: string): System; + unregisterSystem(n: string): any; + setComponentList(n: string, arr ? : Component[]): void; + getComponentList(n: string): Component[]; + getEntityByComponents(comps: Array < string > ): Entity; + getEntitiesByComponents(comps: Array < string > , entities ? : Entity[], target ? : any[]): Entity[]; + getEntityByTags(tags: Array < string > ): Entity; + getEntitiesByTags(tags: string[], entities ? : Entity[], target ? : any[]): Entity[]; + private infertype; + clone(obj: any): Entity; } export class Material { - render(ctx: CanvasRenderingContext2D, dt: number, path?: Path2D): void; + render(): void; } export class Matrix2 { - constructor(a?: number, b?: number, c?: number, d?: number, e?: number, f?: number); - a: number; - b: number; - c: number; - d: number; - e: number; - f: number; - setFromTransform(x: number, y: number, scaleX: number, scaleY: number, rotation: number): this; - prepend(m: Matrix2): this; - append(m: Matrix2): this; - identity(): this; - rotate(radians: number): this; - translate(x: number, y: number): this; - scale(x: number, y: number): this; - transform(v: Vector): Vector; - invert(): this; - copy(m: Matrix2): this; - clone(): Matrix2; - equals(matrix: Matrix2): boolean; + constructor(a ? : number, b ? : number, c ? : number, d ? : number, e ? : number, f ? : number); + a: number; + b: number; + c: number; + d: number; + e: number; + f: number; + setFromTransform(x: number, y: number, scaleX: number, scaleY: number, rotation: number): this; + prepend(m: Matrix2): this; + append(m: Matrix2): this; + identity(): this; + rotate(radians: number): this; + translate(x: number, y: number): this; + scale(x: number, y: number): this; + transform(v: Vector): Vector; + invert(): this; + copy(m: Matrix2): this; + clone(): Matrix2; + equals(matrix: Matrix2): boolean; } export class Mouse { - constructor(eh: DOMEventHandler); - clickCount: number; - dragging: boolean; - dragLastPosition: Vector_like; - delta: Vector_like; - position: Vector_like; - lastPosition: Vector_like; - leftbutton: boolean; - rightbutton: boolean; - inDragBox(pos: Vector_like): boolean; - init(eh: DOMEventHandler): void; - private _onClick; - private _onMove; - private _onDown; - private _onUp; - private _onWheel; - private _onContextMenu; - update(): void; + constructor(eh: DOMEventHandler); + clickCount: number; + dragging: boolean; + dragLastPosition: Vector_like; + delta: Vector_like; + position: Vector_like; + lastPosition: Vector_like; + leftbutton: boolean; + rightbutton: boolean; + inDragBox(pos: Vector): boolean; + init(eh: any): void; + _onClick: (e: any) => void; + _onMove: (e: any) => void; + _onDown: (e: any) => void; + _onUp: (e: any) => void; + _onWheel: (e: any) => void; + _onContextMenu: (e: any) => void; + onmove(e: any): void; + onclick(e: any): void; + ondown(e: any): void; + onup(e: any): void; + onwheel(e: any): void; + oncontextmenu(e: any): void; + update(): void; } export class Movable extends Component implements Component { - constructor(x: number, y: number, a: number); - entity: any; - velocity: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - rotation: Angle; - acceleration: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - toJson(): { - velocity: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - rotation: { - deg: number; - type: string | number; - }; - acceleration: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - }; - fromJson(obj: any): void; + constructor(x: any, y: any, a: any); + entity: any; + velocity: Vector; + rotation: Angle; + acceleration: Vector; } export class NaiveBroadphase extends Broadphase { - constructor(world: World); - private bodies; + constructor(world: any); + private bodies; } export namespace Overlaps { - function AABBColliding(a: BoundingBox, b: BoundingBox): boolean; - function boundSpheresColliding(a: BoundingCircle, b: BoundingCircle): boolean; - function AABBvsSphere(a: BoundingBox, b: BoundingCircle): boolean; + function AABBColliding(a: BoundingBox, b: BoundingBox): boolean; + + function boundSpheresColliding(a: BoundingCircle, b: BoundingCircle): boolean; + + function AABBvsSphere(a: BoundingBox, b: BoundingCircle): boolean; +} +export class ParallaxBackground { + constructor(...layers: any[]); + layers: any[]; + update(ctx: any, dt: any): void; } export class Particle { - constructor(pos: Vector, radius: number, lifespan?: number); - readonly position: Vector; - readonly velocity: Vector; - active: boolean; - radius: number; - color: { - r: number; - b: number; - g: number; - a: number; - }; - private _life; - readonly lifespan: number; - draw(ctx: CanvasRenderingContext2D): void; - update(ctx: CanvasRenderingContext2D, dt: number): void; -} -export class ParticleSystemSprite extends Sprite { - constructor(initial?: number, max?: number, increment?: number); - private _particles; + constructor(pos: Vector, radius: number, lifespan ? : number); + position: Vector; + active: boolean; + velocity: Vector; + radius: number; + color: { + r: number; + g: number; + b: number; + a: number; + }; + lifespan: number; + _life: number; + draw(ctx: any): void; + update(ctx: any, dt: any): void; +} +let System$1: { + new(initial ? : number, max ? : number, increment ? : number): { initial: number; frameIncrease: number; max: number; - protected initParticles(n: number): void; - protected create(): Particle; - init(entity: Entity): void; - protected behavior(p: Particle, dt: number): void; - render(ctx: CanvasRenderingContext2D, dt: number): void; -} + initParticles(n: any): void; + create(): Particle; + init(entity: any): void; + behavior(p: any): void; + render(ctx: any, dt: any): void; + _position: Vector; + _orientation: Angle; + scale: Vector; + geometry: any; + material: any; + parent: any; + angle: number; + position: Vector; + orientation: Angle; + draw(render: any): void; + entity: any; + update(): void; + }; +}; export class Path { - private _points; - private _index; - speed: number; - tolerance: number; - private _lerp_t; - private _lerpdist; - private _way; - private _finished; - private _lerpedPoint; - loop: boolean; - add(point: Vector): this; - clear(): this; - advance(): boolean; - update(lerpdist?: number): { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - current(): any[]; - point(): { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - get path(): any[]; - draw(ctx: CanvasRenderingContext2D): void; + _points: any[]; + _index: number; + speed: number; + tolerance: number; + _lerp_t: number; + _lerpdist: number; + _way: number[]; + _finished: boolean; + _lerpedPoint: Vector; + loop: boolean; + add(point: any): this; + clear(): this; + advance(): boolean; + update(lerpdist ? : number): Vector; + current(): any[]; + point(): Vector; + get path(): any[]; + draw(renderer: any): void; } export class PathFollowing extends Behaviour { - constructor(path: Path); - path: Path; - calc(target: Vector, inv_dt: number): Vector; - clear(): void; - add(point: Vector): void; - set loop(arg: boolean); - get loop(): boolean; - setPath(path: Path): void; - draw(ctx: any): void; + constructor(path: Path); + path: Path; + calc(target: Vector, inv_dt: number): Vector; + clear(): void; + add(point: Vector): void; + set loop(arg: boolean); + get loop(): boolean; + setPath(path: Path): void; + draw(renderer: any): void; } export class Pursuit { - init(): void; - calc(target: Vector): void; -} -declare class Tree extends Broadphase { - constructor(bounds: Bounds, maxdepth?: number); - _root: Node; - maxDepth: number; - bounds: Bounds; - _insert(client: any): void; - _remove(client: any): boolean; - remove(obj: Body): boolean; - traverse(func: Function): any[]; - draw(ctx: CanvasRenderingContext2D): void; - recalculateBounds(bounds: any): void; + init(): void; + calc(target: Vector): void; +} +class Tree extends Broadphase { + constructor(bounds: Bounds, maxdepth ? : number); + _root: Node; + maxDepth: number; + bounds: Bounds; + _insert(client: any): void; + _remove(client: any): boolean; + remove(obj: Body): boolean; + traverse(func: (node: Node) => any): any[]; + draw(ctx: CanvasRenderingContext2D): void; + recalculateBounds(bounds: any): void; } export class Rectangle extends Shape { - static calcInertia(mass: number, width: number, height: number): number; - constructor(width: number, height: number, offset: Vector, offsetAngle: number); - height: number; - width: number; + static calcInertia(mass: number, width: number, height: number): number; + constructor(width: number, height: number, offset: Vector, offsetAngle: number); + height: number; + width: number; } export class Renderer { - constructor(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext); - _rafID: number; - private _accumulator; - objects: Sprite[]; - perf: { - lastTimestamp: number; - total: number; - }; - private domElement; - ctx: CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext; - camera: Camera; - clock: Clock; - init(manager: Manager): void; - clear(): void; - update(dt: number): void; - protected RAF(): void; - play(): void; - pause(): void; - bindTo(selector: string, focus?: true): void; - add(sprite: Sprite | Group): void; - remove(sprite: Sprite): void; - requestFullScreen(): void; - setViewport(w: number, h: number): void; - set width(arg: number); - get width(): number; - set height(arg: number); - get height(): number; + constructor(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext); + _rafID: number; + private _accumulator; + objects: Sprite[]; + perf: { + lastTimestamp: number; + total: number; + }; + private domElement; + ctx: CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext; + camera: Camera; + clock: Clock; + init(manager: Manager): void; + clear(): void; + update(dt: number): void; + protected RAF(): void; + play(): void; + pause(): void; + bindTo(selector: string, focus ? : true): void; + add(sprite: any): void; + remove(sprite: Sprite): void; + requestFullScreen(): void; + setViewport(w: number, h: number): void; + set width(arg: number); + get width(): number; + set height(arg: number); + get height(): number; } export class Renderer2D extends Renderer { - constructor(canvas?: HTMLCanvasElement); - frameRate: number; - renderLast: any[]; - private _update; - addUI(sprite: Sprite): void; + constructor(canvas ? : HTMLCanvasElement); + frameRate: number; + renderLast: any[]; + push(): void; + pop(): void; + reset(): void; + translate(x: any, y: any): void; + scale(x: any, y: any): void; + rotate(rad: any): void; + line(x1: any, y1: any, x2: any, y2: any): void; + rect(x: any, y: any, w: any, h: any): void; + circle(x: any, y: any, r: any): void; + vertices(vertices: any, close ? : boolean): void; + arc(x: any, y: any, r: any, start: any, end: any): void; + fillText(text: any, x: any, y: any): void; + fill(color: string, fillRule: any): void; + stroke(color ? : string, width ? : number): void; + begin(): void; + close(): void; + clip(): void; + drawImage(img: any, x: any, y: any, w ? : any, h ? : any, ix ? : number, iy ? : number): void; + update(dt: any): void; + _update: (accumulate: any) => void; + addUI(mesh: any): void; } export class SeekBehaviour extends Behaviour { - constructor(target: Vector); - radius: number; - target: Vector; + constructor(target: any); + radius: number; + target: any; } export namespace Session { - function set(k: string, v: any): void; - function get(k: string): any; - function clear(): void; + function set(k: string, v: any): void; + + function get(k: string): any; + + function clear(): void; } export class Sfx { - constructor(handler: AudioHandler, buffer: AudioBuffer); - private _soundBuffer; - private _source; - private _onended; - private _destination; - private _playingOffset; - offset: number; - loop: boolean; - private delay; - duration: number; - handler: AudioHandler; - ctx: AudioContext; - finished: boolean; - id: number; - set onended(arg: any); - play(): void; - resume(): void; - _startTime: number; - pause(): void; - disconnect(): void; - connect(node: AudioNode): void; + constructor(handler: AudioHandler, buffer: AudioBuffer); + private _soundBuffer; + private _source; + private _onended; + private _destination; + private _playingOffset; + offset: number; + loop: boolean; + private delay; + duration: number; + handler: AudioHandler; + ctx: AudioContext; + finished: boolean; + id: number; + set onended(arg: any); + play(): void; + resume(): void; + _startTime: number; + pause(): void; + disconnect(): void; + connect(node: AudioNode): void; } export class Shape { - static calcInertia(): number; - static CIRCLE: number; - static POLYGON: number; - constructor(vertices: Vector[], offset?: Vector, offsetAngle?: number); - readonly type: number; - offAngle: number; - offPosition: Vector; - vertices: Vector[]; - geometry: Geometry; - get CHOAS_CLASSNAME(): string; - get CHAOS_OBJ_TYPE(): string; - get area(): number; - getNormals(shape: Shape, target?: Vector[]): Vector[]; - update(position: Vector, angle: number, scale: number): void; - angle: number; - getVertices(axis: Vector, target: Vector[]): Vector[]; - toJson(): void; - fromJson(obj: any): void; + static calcInertia(): number; + static CIRCLE: number; + static POLYGON: number; + constructor(vertices: Vector[], offset ? : Vector, offsetAngle ? : number); + readonly type: number; + offAngle: number; + offPosition: Vector; + vertices: Vector[]; + geometry: Geometry; + get CHOAS_CLASSNAME(): any; + get CHAOS_OBJ_TYPE(): string; + get area(): number; + getNormals(body: any, target ? : any): Vector[]; + update(position: Vector, angle: number, scale: number): void; + angle: number; + getVertices(axis: Vector, target: any): Vector[]; } export class SpringConstraint extends Constraint { - localA: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - localB: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - fixed: boolean; - maxDistance: number; + fixed: boolean; + dampen: number; + maxDistance: number; } export class Sprite implements Component { - constructor(geometry: BufferGeometry, material: Material); - private _position; - private _orientation; - private _scale; - private geometry; - private material; - parent: Group | null; - set angle(arg: number); - get angle(): number; - set position(arg: Vector); - get position(): Vector; - set orientation(arg: Angle); - get orientation(): Angle; - render(ctx: any, dt: any): void; - init(entity: Entity): this; - entity: Entity; - toJson(): { - pos: any; - angle: any; - geometry: any; - material: any; - parent: any; - }; - fromJson(obj: any, renderer: any): void; -} -export class SpriteMaterial implements Material { - constructor(img: HTMLImageElement, frames?: number, actions?: number); - img: HTMLImageElement; - private _index; - private _maxFrame; - private _frame; - private _accumulator; - frameRate: number; - private _maxFrames; - width: number; - height: number; - private frameWidth; - private frameHeight; - setup(frames: number, actions: number): void; - setMaxFrames(action: number, max: number): void; - setAction(index: number): void; - render(ctx: CanvasRenderingContext2D, dt: number): void; -} -export class StaticImageMaterial implements Material { - constructor(img: new (width?: number, height?: number) => HTMLImageElement); - readonly image: new (width?: number, height?: number) => HTMLImageElement; - width: number; - height: number; - render(ctx: CanvasRenderingContext2D): void; + constructor(geometry: any, material: any); + private _position; + private _orientation; + scale: Vector; + private geometry; + material: any; + parent: any; + set angle(arg: number); + get angle(): number; + set position(arg: Vector); + get position(): Vector; + set orientation(arg: Angle); + get orientation(): Angle; + draw(render: any): void; + render(render: any, dt: any): void; + init(entity: any): void; + entity: any; + update(): void; +} +export class StaticImageSprite extends Sprite { + constructor(img: HTMLImageElement); + img: HTMLImageElement; + width: number; + height: number; + frameWidth: number; + frameHeight: number; + draw(renderer: any): void; + _accumulator: number; + _frame: number; } export namespace Storage { - function set(k: string, v: any): void; - function get(k: string): any; - function clear(): void; -} -export class System { + function set(k: string, v: any): void; + + function get(k: string): any; + + function clear(): void; } +export class System {} export class Touch { - constructor(eh: DOMEventHandler); - touches: TouchEvent[]; - clickCount: number; - inDragBox(pos: Vector_like): boolean; - init(eh: DOMEventHandler): void; - private _onMove; - private _onDown; - private _onUp; - update(): void; + constructor(eh: any); + clickCount: number; + touches: any[]; + inDragBox(pos: any): boolean; + init(eh: DOMEventHandler): void; + _onMove: (e: any) => void; + _onDown: (e: any) => void; + _onUp: (e: any) => void; + onmove(e: any): void; + onclick(e: any): void; + ondown(e: any): void; + onup(e: any): void; + onwheel(e: any): void; + update(): void; } export class Transform implements Component { - constructor(x: number, y: number, a: number); - entity: any; - position: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - orientation: Angle; - init(): void; - toJson(): { - position: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): any; - addScalar(n: number): any; - sub(v: any): any; - subScalar(n: number): any; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): any; - divide(n: number): any; - normalize(): any; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): any; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): any; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): any; - reverse(): any; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): any; - toJson(): any; - fromJspn(obj: any): void; - }; - orientation: { - deg: number; - type: string | number; - }; - }; - fromJson(obj: any): void; + constructor(x: any, y: any, a: any); + entity: any; + position: Vector; + orientation: Angle; + init(): void; } export class Triangle extends Shape { - constructor(length1: number, length2: number, angle: number, offset: Vector, offsetAngle: number); -} -declare namespace Utils$1 { - function appendArr(arr1: T[], arr2: T[]): void; - function clearArr(arr: T[]): void; - function popArr(arr: T[], number: number): void; - function removeElement(arr: T[], index: number): T; - function generateID(): number; - function inheritComponent(component: Function, overrideInit?: boolean, overrideUpdate?: boolean): void; - function inheritSystem(system: Function): void; -} -declare let Vector$1: { - new (x: number, y: number): { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }; - getAbsDegBtwn(v1: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }, v2: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): number; - getAbsRadBtwn(v1: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }, v2: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): number; - getRadBtwn(v1: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }, v2: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): number; - getDegBtwn(v1: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }, v2: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): number; - fromRad(radian: number, target?: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }; - fromDeg(degree: number, target?: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }; - random(target?: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }; - lerp(v1: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }, v2: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }, t: number, target?: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }; - toDeg(v: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): number; - toRad(v: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }): number; - readonly ZERO: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; - }; -}; + constructor(length1: number, length2: number, angle: number, offset: Vector, offsetAngle: number); +} +export namespace Utils { + function appendArr(arr1: T[], arr2: T[]): void; + + function clearArr(arr: T[]): void; + + function popArr(arr: T[], number: number): void; + + function removeElement(arr: T[], index: number): T; + + function generateID(): number; + + function inheritComponent(component: any, overrideInit ? : boolean, overrideUpdate ? : boolean): void; + + function inheritSystem(system: any): void; +} +export class Vector { + static getAbsDegBtwn(v1: Vector, v2: Vector): number; + static getAbsRadBtwn(v1: Vector, v2: Vector): number; + static getRadBtwn(v1: Vector, v2: Vector): number; + static getDegBtwn(v1: Vector, v2: Vector): number; + static fromRad(radian: number, target ? : Vector): Vector; + static fromDeg(degree: number, target ? : Vector): Vector; + static random(target: Vector): Vector; + static lerp(v1: Vector, v2: Vector, t: number, target ? : Vector): Vector; + static toDeg(v: Vector): number; + static toRad(v: Vector): number; + static ZERO: Vector; + constructor(x: number, y: number); + x: number; + y: number; + get CHOAS_CLASSNAME(): any; + get CHAOS_OBJ_TYPE(): string; + magnitude(): number; + setMagnitude(length: number): void; + magnitudeSquared(): number; + distanceTo(v: Vector): number; + distanceToSquared(v: Vector): number; + add(v: Vector): this; + addScalar(n: number): this; + sub(v: Vector): this; + subScalar(n: number): this; + dot(v: Vector): number; + cross(v: Vector): number; + multiply(n: number): this; + divide(n: number): this; + normalize(): this; + equals(v: Vector): boolean; + equalsZero(): boolean; + normal(l ? : number, target ? : Vector): Vector; + normalFast(target ? : Vector): Vector; + rotate(rad: number): this; + toArray(target ? : number[], offset ? : number): number[]; + clone(): Vector; + copy(v: Vector): this; + set(x: number, y: number): this; + draw(ctx: CanvasRenderingContext2D, x ? : number, y ? : number, color ? : string, scale ? : number): this; + reverse(): this; + reflect(normal: number, target ? : Vector): Vector; + clamp(min ? : number, max ? : number): this; +} export class WanderBehaviour extends Behaviour { - _theta: number; - dtheta: number; - _radius: number; + _theta: number; + dtheta: number; + _radius: number; } export class WebGLRenderer extends Renderer { - constructor(); + constructor(); } export class WebGPURenderer extends Renderer { - constructor(); + constructor(); } export class World { - private count; - protected records: Map; - private objects; - private fixedConstraits; - private constraints; - linearDamping: number; - angularDamping: number; - velocitySolverIterations: number; - CLMDs: Manifold[]; - contactList: CollisionPair[]; - gravitationalAcceleration: Vector; - fixedFrameRate: number; - perf: { - lastTimestamp: number; - total: number; - }; - broadphase: Broadphase; - set gravity(arg: Vector); - get gravity(): Vector; - private narrowPhase; - broadPhase(): void; - private collisionDetection; - private collisionResponse; - private intergrate; - private applyGravity; - private updateConstraints; - private updateBodies; - update(delta: number): void; - init(manager: Manager): void; - add(object: Body | Composite | Constraint): void; - addBody(body: Body): void; - remove(object: Body | Composite | Constraint): void; - removeBody(body: Body): Body; - addConstraint(constraint: Constraint): void; - removeContraint(constraint: Constraint): Constraint; - addComposite(composite: Composite): void; - removeComposite(composite: Composite): void; - query(bound: Bounds, target?: Array): Body[]; -} -export function arc(ctx: CanvasRenderingContext2D, x: number, y: number, r: number, start: number, end: number): void; -export function circle(ctx: CanvasRenderingContext2D, x: number, y: number, r: number): void; + private count; + protected records: Map < number, Manifold > ; + private objects; + private fixedConstraits; + private constraints; + linearDamping: number; + angularDamping: number; + velocitySolverIterations: number; + CLMDs: Manifold[]; + contactList: CollisionPair[]; + gravitationalAcceleration: Vector; + fixedFrameRate: number; + perf: { + lastTimestamp: number; + total: number; + }; + broadphase: Broadphase; + set gravity(arg: Vector); + get gravity(): Vector; + private narrowPhase; + broadPhase(): void; + private collisionDetection; + private collisionResponse; + private intergrate; + private applyGravity; + private updateConstraints; + private updateBodies; + update(delta: number): void; + init(manager: Manager): void; + add(object: Body | Composite | Constraint): void; + addBody(body: Body): void; + remove(object: Body | Composite | Constraint): void; + removeBody(body: Body): Body; + addConstraint(constraint: Constraint): void; + removeContraint(constraint: Constraint): Constraint; + addComposite(composite: Composite): void; + removeComposite(composite: Composite): void; + query(bound: Bounds, target ? : Array < Body > ): Body[]; +} export function clamp(value: number, min: number, max: number): number; export function defaultCollisionHandler(clmds: CollisionPair[]): void; export function defaultPrecollisionHandler(clmds: Manifold[]): void; export function degToRad(deg: number): number; -export function drawImage(ctx: CanvasRenderingContext2D, img: HTMLImageElement, x: number, y: number, w?: number, h?: number, ix?: number, iy?: number): void; -export function exp(x: number, e?: number): number; -export function fill(ctx: CanvasRenderingContext2D, color?: string, fillRule?: string): void; -export function fillText(ctx: CanvasRenderingContext2D, text: string, x: number, y: number): void; +export function exp(x: number, e ? : number): number; export function lerp(a: number, b: number, t: number): number; -export function line(ctx: CanvasRenderingContext2D, x1: number, y1: number, x2: number, y2: number): void; export function map(v: number, x1: number, y1: number, x2: number, y2: number): number; export function naturalizePair(a: number, b: number): number; export function radToDeg(rad: number): number; -export function rand(min?: number, max?: number): number; -export function rect(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number): void; -export function round(number: number, precision?: number): number; +export function rand(min ? : number, max ? : number): number; +export function round(number: number, precision ? : number): number; export function sq(x: number): number; export function sqrt(x: number): number; -export function stroke(ctx: CanvasRenderingContext2D, color?: string, width?: number): void; -export function vertices(ctx: CanvasRenderingContext2D, vertices: Vector[], close?: boolean): void; -export function wrapAngle(x: any): any; -declare class Node { - constructor(bounds: { - max: Vector_like; - min: Vector_like; - }); - children: Node[]; - objects: Body[]; - root: Node; - parent: Node; - hasObjects: boolean; - index: number; - global: Tree; - dims: Vector_like; - depth: number; - bounds: { - max: Vector_like; - min: Vector_like; - }; - add(node: Node): void; - clear(): void; - split(depth?: number): void; - draw(ctx: CanvasRenderingContext2D): void; - isLeafNode(): boolean; - childrenHaveObj(): boolean; - intersects(bounds: Bounds): boolean; - contains(bounds: Bounds): boolean; - query(bounds: Bounds, target?: Body[]): Body[]; - insertObject(obj: Body): boolean; - isInNode(position: Vector_like): boolean; - isRootNode(): boolean; - updateObject(obj: Body): boolean; - removeObject(obj: Body): boolean; - traverse(func: Traverser, target: T[]): T[]; - getCollisionPairs(target: CollisionPair[], stack: CollisionPair[]): void; -} -declare class Broadphase { - canCollide(a: Body, b: Body): boolean; - insert(obj: Body): void; - remove(obj: Body): void; - draw(ctx: any): void; - update(bodies: Body[]): void; - getCollisionPairs(target: CollisionPair[]): CollisionPair[]; - query(bounds: Bounds, target: Body[]): Body[]; -} -declare let r: { - x: number; - y: number; - readonly CHOAS_CLASSNAME: string; - readonly CHAOS_OBJ_TYPE: string; - magnitude(): number; - setMagnitude(length: number): void; - magnitudeSquared(): number; - distanceTo(v: any): number; - distanceToSquared(v: any): number; - add(v: any): this; - addScalar(n: number): this; - sub(v: any): this; - subScalar(n: number): this; - dot(v: any): number; - cross(v: any): number; - multiply(n: number): this; - divide(n: number): this; - normalize(): this; - equals(v: any): boolean; - equalsZero(): boolean; - normal(l?: number, target?: any): any; - normalFast(target?: any): any; - rotate(rad: number): this; - toArray(target?: number[], offset?: number): number[]; - clone(): any; - copy(v: any): any; - set(x: number, y: number): this; - draw(ctx: CanvasRenderingContext2D, x?: number, y?: number, color?: string, scale?: number): this; - reverse(): this; - reflect(normal: number, target?: any): any; - clamp(min?: number, max?: number): this; - toJson(): any; - fromJspn(obj: any): void; -}; -export { Err$1 as Err, Matrix2 as Matrix, Tree as QuadTreeBroadphase, Utils$1 as Utils, Vector$1 as Vector }; +class Broadphase { + canCollide(a: Body, b: Body): boolean; + insert(obj: Body): void; + remove(obj: Body): void; + draw(ctx: any): void; + update(bodies: Body[]): void; + getCollisionPairs(target: CollisionPair[]): CollisionPair[]; + query(bounds: Bounds, target: Body[]): Body[]; +} +class Node { + constructor(bounds: { + max: Vector_like; + min: Vector_like; + }); + children: Node[]; + objects: Body[]; + root: Node; + parent: Node; + hasObjects: boolean; + index: number; + global: Tree; + dims: Vector_like; + depth: number; + bounds: { + max: Vector_like; + min: Vector_like; + }; + add(node: Node): void; + clear(): void; + split(depth ? : number): void; + draw(ctx: CanvasRenderingContext2D): void; + isLeafNode(): boolean; + childrenHaveObj(): boolean; + intersects(bounds: Bounds): boolean; + contains(bounds: Bounds): boolean; + query(bounds: Bounds, target ? : Body[]): Body[]; + insertObject(obj: Body): boolean; + isInNode(position: Vector_like): boolean; + isRootNode(): boolean; + updateObject(obj: Body): boolean; + removeObject(obj: Body): boolean; + traverse < T_1 > (func: (node: Node) => boolean, target: T_1[]): T_1[]; + getCollisionPairs(target: CollisionPairs[], stack: CollisionPairs[]): void; +} +class Camera { + constructor(renderer: any, position: any); + _position: Vector; + transformMatrix: Matrix2; + target: any; + lerpFactor: number; + renderer: any; + offset: Vector; + _actualPosition: Vector; + orientation: Angle; + set position(arg: Vector); + get position(): Vector; + get transform(): Vector; + update(): void; + clear(ctx: any): void; + dispose(): void; + follow(position: any): void; +} +export { Matrix2 as Matrix, System$1 as ParticleSystemSprite, Tree as QuadTreeBroadphase }; \ No newline at end of file diff --git a/dist/chaos.module.js b/dist/chaos.module.js index 052000b3..bec55662 100644 --- a/dist/chaos.module.js +++ b/dist/chaos.module.js @@ -80,7 +80,7 @@ let mess = []; /** * A set of functions to streamline logging of items to the console */ -const Err$1 = {}; +const Err = {}; /** * Logs out a warning to the console. @@ -88,7 +88,7 @@ const Err$1 = {}; * @memberof Err * @param {string} message */ -Err$1.warn = function(message) { +Err.warn = function(message) { console.warn(marker + message); }; @@ -98,7 +98,7 @@ Err$1.warn = function(message) { * @memberof Err * @param {string} message */ -Err$1.throw = function(message) { +Err.throw = function(message) { throw new Error(marker + message) }; @@ -108,7 +108,7 @@ Err$1.throw = function(message) { * @memberof Err * @param {string} message */ -Err$1.error = function(message) { +Err.error = function(message) { console.error(marker + message); }; @@ -118,7 +118,7 @@ Err$1.error = function(message) { * @memberof Err * @param {string} message */ -Err$1.log = function(message) { +Err.log = function(message) { console.log(marker + message); }; /** @@ -127,10 +127,10 @@ Err$1.log = function(message) { * @memberof Err * @param {string} message */ -Err$1.warnOnce = function(message) { +Err.warnOnce = function(message) { if (mess.includes(message)) return mess.push(message); - Err$1.warn(message); + Err.warn(message); }; /** * Logs out a message,warning or error to the console according to the supplied log function. @@ -140,7 +140,7 @@ Err$1.warnOnce = function(message) { * @param {string} message * @param {Function} errfunc */ -Err$1.assert = function(test, errfunc, message) { +Err.assert = function(test, errfunc, message) { if (!test) errfunc(message); return test }; @@ -150,18 +150,17 @@ Err$1.assert = function(test, errfunc, message) { * * @module Utils */ -const Utils$1 = {}; +const Utils = {}; let tmpID = 0; /** * Appends the second array to the first. * * @memberof Utils - * @template T - * @param {T[]} arr1 - * @param {T[]} arr2 + * @param {any[]} arr1 + * @param {any[]} arr1 */ -Utils$1.appendArr = function appendArr(arr1, arr2) { +Utils.appendArr = function(arr1, arr2) { for (var i = 0; i < arr2.length; i++) { arr1.push(arr2[i]); } @@ -170,10 +169,9 @@ Utils$1.appendArr = function appendArr(arr1, arr2) { * Clears an array * * @memberof Utils - * @template T - * @param {T[]} arr + * @param {any[]} arr */ -Utils$1.clearArr = function(arr) { +Utils.clearArr = function(arr) { for (var i = arr.length; i > 0; i--) { arr.pop(); } @@ -182,11 +180,10 @@ Utils$1.clearArr = function(arr) { * Removes a number of items at the end of an array * * @memberof Utils - * @template T - * @param {T[]} arr + * @param {any[]} arr * @param {number} number */ -Utils$1.popArr = function(arr, number) { +Utils.popArr = function(arr, number) { let length = arr.length; for (var i = length; i > length - number; i--) { arr.pop(); @@ -196,11 +193,10 @@ Utils$1.popArr = function(arr, number) { * Removes an element by its index from an array * * @memberof Utils - * @template T - * @param {T[]} arr + * @param {any[]} arr * @param {number} index */ -Utils$1.removeElement = function(arr, index) { +Utils.removeElement = function(arr, index) { if (index == -1) return null if (arr.length - 1 == index) return arr.pop() @@ -213,7 +209,7 @@ Utils$1.removeElement = function(arr, index) { * * @memberof Utils */ -Utils$1.generateID = function() { +Utils.generateID = function() { return (tmpID += 1) }; @@ -221,11 +217,11 @@ Utils$1.generateID = function() { * Mixes the functions required by a component into a class. * * @memberof Utils - * @param {Function} component the class/constructor function to add methods to. + * @param {Object} component the class to add methods to. * @param {boolean} [overrideInit=true] * @param {boolean} [overrideUpdate=true] */ -Utils$1.inheritComponent = function(component, overrideInit = true, overrideUpdate = true) { +Utils.inheritComponent = function(component, overrideInit = true, overrideUpdate = true) { if (component == void 0 || typeof component !== "function") return let proto = component.prototype; @@ -253,7 +249,7 @@ Utils$1.inheritComponent = function(component, overrideInit = true, overrideUpda } if (!proto.update && overrideUpdate) { proto.update = function() { - Err$1.warnOnce("Please override the update function in the component " + proto.constructor.name); + Err.warnOnce("Please override the update function in the component " + proto.constructor.name); }; } @@ -263,18 +259,12 @@ Utils$1.inheritComponent = function(component, overrideInit = true, overrideUpda proto.requires = function(...names) { for (var i = 0; i < names.length; i++) if (!this.entity.has(names[i])) - Err$1.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); + Err.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); }; proto.query = function(bound, target = []) { return this.entity.query(bound, target) }; - if (!proto.toJson) { - //console.log(proto); - proto.toJson = function() { - throw "Error, implement .toJson() in the class " + this.CHOAS_CLASSNAME - }; - } Object.defineProperty(proto, "CHOAS_CLASSNAME", { get: function() { return this.constructor.name.toLowerCase() @@ -290,23 +280,18 @@ Utils$1.inheritComponent = function(component, overrideInit = true, overrideUpda configurable: false }); }; -/** - * Mixes the functions required by a system into a class. - * - * @memberof Utils - * @param {Function} system the class constructor function to add methods to. - */ -Utils$1.inheritSystem = function(system) { + +Utils.inheritSystem = function(system) { if (system == void 0 || typeof system !== "function") return let proto = system.prototype; if (!proto.init) { proto.init = function() { - Err$1.warnOnce("Please override the init method in the system " + proto.constructor.name); + Err.warnOnce("Please override the init method in the system " + proto.constructor.name); }; } if (!proto.update) { proto.update = function() { - Err$1.warnOnce("Please override the update method in the system " + proto.constructor.name); + Err.warnOnce("Please override the update method in the system " + proto.constructor.name); }; } @@ -319,7 +304,7 @@ Utils$1.inheritSystem = function(system) { if (!proto.remove) { proto.remove = function(component) { let index = this.objects.indexOf(component); - Utils$1.removeElement(this.objects, index); + Utils.removeElement(this.objects, index); }; } }; @@ -365,7 +350,7 @@ class Clock { * A helper class. * Since there are no interfaces in JavaScript, * you might have to extend this to create a component, but there is another solution. - * Use instead Utils.inheritComponent() if you have your own hierarchy of classes. + * Use instead Utils.inheritComponent if you have your own hierarchy of classes. * In typescript,this would be an interface. * * @interface @@ -374,74 +359,16 @@ class Clock { class Component { /** * @type Entity | null - */ - entity = null - - destroy() { - this.entity = null; - } - /** - * @type string - */ - get CHOAS_CLASSNAME() { - return this.constructor.name.toLowerCase() - } - /** - * @type string - */ - get CHAOS_OBJ_TYPE() { - return "component" - } - /** - - * @param {Entity} entity - */ - init(entity) { - this.entity = entity; - } - /** - * @param {number} dt - */ - update(dt) { - Err.warnOnce("Please override the update function in the component " + proto.constructor.name); - - } - /** - * @param {string} n - */ - get(n) { - return this.entity.getComponent(n); - } - /** - * @param {...string} names - */ - requires(...names) { - for (var i = 0; i < names.length; i++) - if (!this.entity.has(names[i])) - Err.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); - } - /** - * @param {CircleBounding | BoxBounding} bound - * @param {Entity} [target=[]] - */ - query(bound, target = []) { - return this.entity.query(bound, target) - } - static fromJson() { - throw "Implement static method fromJson() in your component " + this.CHOAS_CLASSNAME - } - static toJson() { - throw "Implement static method toJson() in your component " + this.CHOAS_CLASSNAME - } + entity = null } -Utils$1.inheritComponent(Component); +Utils.inheritComponent(Component); /** * Destroys the component. * * @function * @name Component#destroy - */ +*/ /** * Initializes a component. * @@ -510,8 +437,9 @@ class BoundingBox extends Component { /** * * Checks to see if this intersects with another bounding box - * @param {BoundingCircle | BoundingBox} bound the bound to check intersection with - * @returns boolean + * @param { BoundingBox} bound the bound to check intersection with + * + * @param { BoundingCircle | BoundingBox } bound the bound to check intersection with **/ intersects(bound) { if (bound.r) @@ -522,7 +450,7 @@ class BoundingBox extends Component { * Calculates the bounds of the body * * @param {Body} body Body to calculate max and min from - * @param {Number} padding increases the size of the bounds + * @@param {Number} padding increases the size of the bounds */ calculateBounds(body, padding = 0) { let minX = Number.MAX_SAFE_INTEGER, @@ -587,7 +515,7 @@ class BoundingBox extends Component { * Deep copies a bounding box to a new one. * * @returns BoundingBox - */ + */ clone() { return new BoundingBox(this.min.x, this.min.y, this.max.x, this.max.y) } @@ -595,7 +523,7 @@ class BoundingBox extends Component { * Deep copies another bounding box. * * @param {BoundingBox} bounds - */ + */ copy(bounds) { this.pos.x = bounds.pos.x; this.pos.y = bounds.pos.y; @@ -604,24 +532,6 @@ class BoundingBox extends Component { this.max.x = bounds.max.x; this.max.y = bounds.max.y; } - toJson() { - return { - posX: this.pos.x, - posY: this.pos.y, - minX: this.min.x, - minY: this.min.y, - maxX: this.max.x, - maxY: this.max.y, - } - } - fromJson(obj) { - this.pos.x = obj.posX; - this.pos.y = obj.posY; - this.min.x = obj.minX; - this.min.y = obj.minY; - this.max.x = obj.maxX; - this.max.y = obj.maxY; - } /** * Combines two bounds to create a new one that covers the previous two. * @@ -665,6 +575,8 @@ class BoundingCircle { /** * * Checks to see if this intersects with another bounding box + * @param { BoundingBox} bound the bound to check intersection with + * * @param { BoundingCircle | BoundingBox } bound the bound to check intersection with **/ intersects(bound) { @@ -705,8 +617,6 @@ class BoundingCircle { } /** * Translates this bound to the given position. - * - * @param {Vector_like} pos */ update(pos) { //let dx = pos.x - this.pos.x @@ -715,18 +625,6 @@ class BoundingCircle { this.pos.x = pos.x; this.pos.y = pos.y; } - toJson(){ - return { - posX:this.pos.x, - posY:this.pos.y, - r:this.r - } - } - fromJson(obj){ - this.pos.x = obj.posX; - this.pos.y = obj.posY; - this.r = obj.r; - } } const RHI = Math.PI / 180, @@ -867,7 +765,7 @@ let TWO_PI = Math.PI * 2; * @author Wayne Mwashuma * @license MIT */ -let Vector$1 = class Vector { +class Vector { /** * @param {number} x the x coordinate of the vector * @param {number} y the y coordinate of the vector @@ -876,15 +774,9 @@ let Vector$1 = class Vector { this.x = x || 0; this.y = y || 0; } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "vector" } @@ -988,7 +880,7 @@ let Vector$1 = class Vector { /** * Calculates the cross product of two vectors. * - * @param {Vector} v + * @param {Vector} vproduct * @returns {number} */ cross(v) { @@ -1070,7 +962,7 @@ let Vector$1 = class Vector { /** * Rotates this vector by a given angle in radians. * - * @param {number} rad Angle in radians + * @param {Vector} Angle in radians * @returns {this} */ rotate(rad) { @@ -1166,10 +1058,10 @@ let Vector$1 = class Vector { * Returns a vector of this reflected on a sirface perpendicular to the normal. * * @param {number} normal the unit vector perpendicular to reflection surface - * @param {Vector} [target] * @return {Vector} */ - reflect(normal, target = new Vector()) { + reflect(normal, target) { + target = target || new Vector(); return target.copy(normal).multiply(this.dot(normal) * 2).sub(this) } /** @@ -1191,14 +1083,6 @@ let Vector$1 = class Vector { return this } -toJson(){ - return this -} -fromJspn(obj){ - this.x = obj.x; - this.y = obj.y; -} - [Symbol.iterator] = function*() { yield this.x; yield this.y; @@ -1255,7 +1139,7 @@ fromJspn(obj){ * given angle starting from the positive x axis. * * @param {number} radian angle in radians from 0 to `Math.PI * 2` - * @param {Vector} [target] Vector to store results in. + * @param {Vector} target Vector to store results in. * @returns {Vector} */ static fromRad(radian, target = new Vector()) { @@ -1266,7 +1150,7 @@ fromJspn(obj){ * given angle from the positive x axis * * @param {number} degree angle in radians from `0°` to `360°` - * @param {Vector} [target] Vector to store results in. + * @param {Vector} target Vector to store results in. * @returns {Vector} */ static fromDeg(degree, target) { @@ -1275,7 +1159,6 @@ fromJspn(obj){ /** * Generates a new unit Vector in a random direction * - * @param {Vector} [target] * @returns {Vector} */ static random(target) { @@ -1286,11 +1169,11 @@ fromJspn(obj){ * @param {Vector} v1 the vector to lerp from * @param {Vector} v2 the vector to lerp from * @param {number} t a value from 0 to 1 to scale the new Vector between v1 and v2 - * @param {Vector} [target] the vector to store results into + * @param {Vector} target the vector to store results into * * @returns {Vector} */ - static lerp(v1, v2, t, target = new Vector()) { + static lerp(v1, v2, t, target) { target = target || new Vector(); return target.copy(v1).set( (v2.x - v1.x) * t + v1.x, @@ -1322,13 +1205,11 @@ fromJspn(obj){ /** * A vector whose x and y values will remain 0. * - * @static - * @readonly * @type {Vector} */ static ZERO = Object.freeze(new Vector()) -}; +} /** * Wrapper class since JavaScript doesn't support references to numbers explicitly. @@ -1352,20 +1233,13 @@ class Angle { /** * @param {number} [deg=0] Orientation in degrees. */ - //TODO - Change this to radians instead constructor(deg = 0) { this._deg = deg || 0; - this._rad = deg * Math.PI / 180 || 0; + this._rad = deg * Math.PI / 2 || 0; } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "angle" } @@ -1397,21 +1271,9 @@ class Angle { copy(angle) { this.degree = angle.degree; } - - fromJSON(obj) { - this.degree = obj.deg; - } - /** - * @returns {{ - deg: number, - type:string | number - }} - */ - toJson() { - return { - deg: this._deg, - type: this.CHAOS_OBJ_TYPE - } + + static fromJSON(obj) { + return new Angle(obj._deg) } } @@ -1630,312 +1492,25 @@ class Matrix2 { } } -function wrapAngle(x) { - let a = x; - while (a > Math.PI * 2) { - a = a - Math.PI * 2; - } - while (a < 0) { - a = a + Math.PI * 2; - } - return a -} - -const Easing = { - Linear: { - In: function(x) { - return x; - }, - Out: function(x) { - return x; - }, - InOut: function(x) { - return x; - }, - }, - Quadratic: { - In: function(x) { - return x * x; - }, - Out: function(x) { - return x * (2 - x); - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return 0.5 * x * x; - } - return -0.5 * (--x * (x - 2) - 1); - }, - }, - Cubic: { - In: function(x) { - return x * x * x; - }, - Out: function(x) { - return --x * x * x + 1; - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return 0.5 * x * x * x; - } - return 0.5 * ((x -= 2) * x * x + 2); - }, - }, - Quartic: { - In: function(x) { - return x * x * x * x; - }, - Out: function(x) { - return 1 - --x * x * x * x; - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return 0.5 * x * x * x * x; - } - return -0.5 * ((x -= 2) * x * x * x - 2); - }, - }, - Quintic: { - In: function(x) { - return x * x * x * x * x; - }, - Out: function(x) { - return --x * x * x * x * x + 1; - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return 0.5 * x * x * x * x * x; - } - return 0.5 * ((x -= 2) * x * x * x * x + 2); - }, - }, - Sinusoidal: { - In: function(x) { - return 1 - Math.sin(((1.0 - x) * Math.PI) / 2); - }, - Out: function(x) { - return Math.sin((x * Math.PI) / 2); - }, - InOut: function(x) { - return 0.5 * (1 - Math.sin(Math.PI * (0.5 - x))); - }, - }, - Exponential: { - In: function(x) { - return x === 0 ? 0 : Math.pow(1024, x - 1); - }, - Out: function(x) { - return x === 1 ? 1 : 1 - Math.pow(2, -10 * x); - }, - InOut: function(x) { - if (x === 0) { - return 0; - } - if (x === 1) { - return 1; - } - if ((x *= 2) < 1) { - return 0.5 * Math.pow(1024, x - 1); - } - return 0.5 * (-Math.pow(2, -10 * (x - 1)) + 2); - }, - }, - Circular: { - In: function(x) { - return 1 - Math.sqrt(1 - x * x); - }, - Out: function(x) { - return Math.sqrt(1 - --x * x); - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return -0.5 * (Math.sqrt(1 - x * x) - 1); - } - return 0.5 * (Math.sqrt(1 - (x -= 2) * x) + 1); - }, - }, - Elastic: { - In: function(x) { - if (x === 0) { - return 0; - } - if (x === 1) { - return 1; - } - return -Math.pow(2, 10 * (x - 1)) * Math.sin((x - 1.1) * 5 * Math.PI); - }, - Out: function(x) { - if (x === 0) { - return 0; - } - if (x === 1) { - return 1; - } - return Math.pow(2, -10 * x) * Math.sin((x - 0.1) * 5 * Math.PI) + 1; - }, - InOut: function(x) { - if (x === 0) { - return 0; - } - if (x === 1) { - return 1; - } - x *= 2; - if (x < 1) { - return -0.5 * Math.pow(2, 10 * (x - 1)) * Math.sin((x - 1.1) * 5 * Math.PI); - } - return 0.5 * Math.pow(2, -10 * (x - 1)) * Math.sin((x - 1.1) * 5 * Math.PI) + 1; - }, - }, - Back: { - In: function(x) { - var s = 1.70158; - return x === 1 ? 1 : x * x * ((s + 1) * x - s); - }, - Out: function(x) { - var s = 1.70158; - return x === 0 ? 0 : --x * x * ((s + 1) * x + s) + 1; - }, - InOut: function(x) { - var s = 1.70158 * 1.525; - if ((x *= 2) < 1) { - return 0.5 * (x * x * ((s + 1) * x - s)); - } - return 0.5 * ((x -= 2) * x * ((s + 1) * x + s) + 2); - }, - }, - Bounce: { - In: function(x) { - return 1 - Easing.Bounce.Out(1 - x); - }, - Out: function(x) { - if (x < 1 / 2.75) { - return 7.5625 * x * x; - } - else if (x < 2 / 2.75) { - return 7.5625 * (x -= 1.5 / 2.75) * x + 0.75; - } - else if (x < 2.5 / 2.75) { - return 7.5625 * (x -= 2.25 / 2.75) * x + 0.9375; - } - else { - return 7.5625 * (x -= 2.625 / 2.75) * x + 0.984375; - } - }, - InOut: function(x) { - if (x < 0.5) { - return Easing.Bounce.In(x * 2) * 0.5; - } - return Easing.Bounce.Out(x * 2 - 1) * 0.5 + 0.5; - }, - }, - generatePow: function(power) { - if (power === void 0) { power = 4; } - power = power < Number.EPSILON ? Number.EPSILON : power; - power = power > 10000 ? 10000 : power; - return { - In: function(x) { - return Math.pow(x, power); - }, - Out: function(x) { - return 1 - Math.pow((1 - x), power); - }, - InOut: function(x) { - if (x < 0.5) { - return Math.pow((x * 2), power) / 2; - } - return (1 - Math.pow((2 - x * 2), power)) / 2 + 0.5; - }, - }; - }, -}; - -const Interpolation = { - Linear: function(p0, p1, t) { - return (p1 - p0) * t + p0 - }, - Bernstein: function(n, i) { - const fc = Interpolation.Utils.Factorial; - - return fc(n) / fc(i) / fc(n - i) - }, - Factorial: (function() { - const a = [1]; - - return function(n) { - let s = 1; - - if (a[n]) { - return a[n] - } - - for (let i = n; i > 1; i--) { - s *= i; - } - - a[n] = s; - return s - } - })(), - - CatmullRom: function(p0, p1, p2, p3, t) { - const v0 = (p2 - p0) * 0.5; - const v1 = (p3 - p1) * 0.5; - const t2 = t * t; - const t3 = t * t2; - - return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1 - }, -}; - class Geometry { - /** - * @type Vector[] - */ - vertices = null - /** - * @type Vector[] - */ - normals = null - /** - * @type Vector[] - */ - _dynNormals = null - /** - * @param {Vector[]} vertices - */ constructor(vertices) { this.vertices = vertices; this.normals = this.calcFaceNormals(); - this._dynNormals = this.normals.map(e => e.clone()); + this._dynNormals = this.normals.map(e=>e.clone()); } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "geometry" } - /** - * @param {number} rad - * @param {Vector[]} target - */ - getNormals(rad, target) { + getNormals(rad,target) { target = target || []; for (var i = 0; i < this.normals.length; i++) { target.push(this._dynNormals[i].copy(this.normals[i]).rotate(rad)); } return target } - /** - * @private - * @returns Vector[] - */ calcFaceNormals() { const axes = [], { vertices } = this; @@ -1954,13 +1529,7 @@ class Geometry { } return axes } - /** - * @param {number} n - * @param {Vector[]} vertices - * @param {Vector} pos - * @patam {number} rad - */ - transform(vertices, pos, rad, n) { + transform(vertices,pos, rad, n) { for (let i = 0; i < this.vertices.length; i++) { let vertex = vertices[i]; vertex.copy(this.vertices[i]); @@ -1969,17 +1538,6 @@ class Geometry { vertex.add(pos); } } - toJson(){ - let obj = { - vertices:this.vertices.map((v)=>v.toJson()) - }; - return obj - } - fromJson(obj){ - this.vertices = obj.vertices.map(v=>new Vector().fromJson(v)); - this.normals = this.calcFaceNormals(); - this._dynNormals = this.normals.map(e => e.clone()); - } } /**@enum {number}*/ @@ -2022,7 +1580,7 @@ const Settings = { type:BodyType.DYNAMIC }; -let tmp1$c = new Vector$1(); +let tmp1$d = new Vector(); /** * This class makes a body tangible @@ -2052,13 +1610,13 @@ class Shape { * The vertices describing the shape. * * @type Vector[] - */ + */ vertices = null /** * Keeps the original normals and vertices of this shape * * @type Geometry - */ + */ geometry = null /** @@ -2066,39 +1624,34 @@ class Shape { * @param {Vector} [offset=vector] offset position relative to parent body * @param {number} [offsetAngle=0] offset angle relative to parent body. */ - constructor(vertices, offset = new Vector$1(), offsetAngle = 0) { + constructor(vertices, offset = new Vector(), offsetAngle = 0) { this.offPosition = offset; this.offAngle = offsetAngle * Math.PI / 180; this.vertices = vertices.map(v => v.clone()); this.geometry = new Geometry(vertices); } - /** - * @type string - */ + get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "shape" } /** * The area occupied by a shape. * @type number - */ - get area() { + */ + get area(){ return 0 } /** * Returns the normals of the faces when rotated. * - * @param {Shape} shape - * @param {Vector[]} [target=[]] An array where results are stored. - * @returns {Vector[]} + * @param {} body + * @param {} [target=[]] An array where results are stored. + * @returns {Array} */ - getNormals(shape, target) { + getNormals(body, target) { return this.geometry.getNormals(this.angle, target) } /** @@ -2110,17 +1663,17 @@ class Shape { */ update(position, angle, scale) { this.angle = this.offAngle + angle; - this.geometry.transform(this.vertices, tmp1$c.copy(position).add(this.offPosition), this.angle, 1 , position); + this.geometry.transform(this.vertices, tmp1$d.copy(position).add(this.offPosition), this.angle, 1 , position); } /** * Returns the world coordinates of the vertices. * * @param {Vector} axis - * @param {Vector[]} target + * @param {Vector[]}} target * @returns {Vector[]} */ - getVertices(axis, target) { + getVertices(axis,target) { return this.vertices } @@ -2133,45 +1686,21 @@ class Shape { static calcInertia() { throw new Error("Implement in the children classes") } - toJson(){ - ({ - type:this.CHAOS_OBJ_TYPE, - geometry:this.geometry.toJson(), - shapwType:this.type, - offset:this.offPosition.toJson(), - offAngle:this.offAngle - }); - } - fromJson(obj){ - this.offAngle = obj.offAngle; - this.offPosition = obj.offset; - this.geometry.fromJson(obj.geometry); - this.vertices = this.geometry.vertices.map(v=>v.clone()); - } static CIRCLE = 0 static POLYGON = 1 } class Line extends Shape { - /** - * @type number - */ - length = 0 - /** - * @param {number} length - * @param {Vector} offset - * @param {number} pffsetAngle - */ constructor(length,offset,offsetAngle) { - let start = new Vector$1(1).multiply(length / 2), - end = new Vector$1(1).multiply(-length / 2); + let start = new Vector(1).multiply(length / 2), + end = new Vector(1).multiply(-length / 2); super([start, end],offset,offsetAngle); this.length = length; } } -let _vec1 = new Vector$1(); -let _vec2 = new Vector$1(); +let _vec1 = new Vector(); +let _vec2 = new Vector(); /** * A circular shape. @@ -2191,7 +1720,7 @@ class Circle extends Shape { //the first vertex is position super([], offset, offsetAngle); - this.vertices = [new Vector$1(), new Vector$1(), new Vector$1()]; + this.vertices = [new Vector(), new Vector(), new Vector()]; this.radius = radius; this.type = Shape.CIRCLE; } @@ -2210,11 +1739,11 @@ class Circle extends Shape { * @inheritdoc * * @param {Vector} axis - * @param {Vector[]} out + * @param {Vector[]}} target * @returns {Vector[]} */ - getVertices(axis, out) { - let target = out || []; + getVertices(axis, target) { + target = target || []; let v1 = _vec1.copy(axis).multiply(-this.radius).add(this.position); let v2 = _vec2.copy(axis).multiply(this.radius).add(this.position); target[0] = v1.clone(); @@ -2255,23 +1784,6 @@ class Circle extends Shape { get area() { return Math.PI * this.radius * this.radius } - toJson() { - let obj = { - radius: this.radius, - offset: this.offPosition, - offAngle: this.offAngle, - shapeType: this.type, - type: this.CHAOS_OBJ_TYPE - }; - return obj - } - fromJson(obj) { - return new Circle( - obj.radius, - new Vector$1().fromJson(obj.offset), - obj.offAngle - ) - } } class Rectangle extends Shape { @@ -2290,10 +1802,10 @@ class Rectangle extends Shape { * @param {number} offsetAngle Angular offset from the body center. */ constructor(width, height, offset, offsetAngle) { - let v1 = new Vector$1(-width / 2, -height / 2); - let v2 = new Vector$1(-width / 2, height / 2); - let v3 = new Vector$1(width / 2, height / 2); - let v4 = new Vector$1(width / 2, -height / 2); + let v1 = new Vector(-width / 2, -height / 2); + let v2 = new Vector(-width / 2, height / 2); + let v3 = new Vector(width / 2, height / 2); + let v4 = new Vector(width / 2, -height / 2); super([v1, v2, v3, v4], offset, offsetAngle); this.height = height; this.width = width; @@ -2314,8 +1826,8 @@ class Rectangle extends Shape { } -let tmp1$b = new Vector$1(), - tmp2$9 = new Vector$1(); +let tmp1$c = new Vector(), + tmp2$9 = new Vector(); /** * A triangular shape. @@ -2332,18 +1844,18 @@ class Triangle extends Shape { * */ constructor(length1, length2, angle, offset, offsetAngle) { - let l1 = tmp1$b.set(1, 0).multiply(length1); - let l2 = Vector$1.fromDeg(angle, tmp2$9).multiply(length2); + let l1 = tmp1$c.set(1, 0).multiply(length1); + let l2 = Vector.fromDeg(angle, tmp2$9).multiply(length2); super([ - new Vector$1( + new Vector( -l1.x / 2, -l2.y / 2 ), - new Vector$1( + new Vector( l1.x / 2, -l2.y / 2 ), - new Vector$1( + new Vector( l2.x / 2, l2.y / 2 ) @@ -2362,28 +1874,28 @@ class Body { * * @type number */ - id = Utils$1.generateID() + id = Utils.generateID() /** * World space coordinates of a body * * @private * @type Vector */ - _position = new Vector$1() + _position = new Vector() /** * velocity of a body.Speed in pixels per second. * * @private * @type Vector */ - _velocity = new Vector$1() + _velocity = new Vector() /** * acceleration of a body in pixels per second squared. * * @private * @type Vector */ - _acceleration = new Vector$1() + _acceleration = new Vector() /** * World space orientation of a body * @@ -2439,7 +1951,7 @@ class Body { * * @type Vector */ - lastPosition = new Vector$1() + lastPosition = new Vector() /** * Inverse mass of the body. * @@ -2595,15 +2107,9 @@ class Body { get physicsType() { return ObjType.BODY } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "body" } @@ -2735,7 +2241,7 @@ class Body { * @returns {number} */ setAnchor(v) { - this.anchors.push(new Vector$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); + this.anchors.push(new Vector(v.x, v.y).rotate(this.orientation.radian).add(this.position)); return this._localanchors.push(v) - 1 } /** @@ -2755,7 +2261,7 @@ class Body { * @param {Vector} [target=Vector] Vector to store results in. * @returns {Vector} */ - getLocalAnchor(index, target = new Vector$1()) { + getLocalAnchor(index, target = new Vector()) { return target.copy(this._localanchors[index]).rotate(this.orientation.radian) } /** @@ -2765,7 +2271,7 @@ class Body { * @param {Vector} force The force to be applied. * @param {Vector} [arm=Vector] The collision arm. */ - applyForce(force, arm = Vector$1.ZERO) { + applyForce(force, arm = Vector.ZERO) { this.acceleration.add(force.multiply(this.inv_mass)); this.rotation.degree += arm.cross(force) * this.inv_inertia; } @@ -2806,68 +2312,13 @@ class Body { this.shapes[i].update(this.position, this._orientation.radian); } for (var i = 0; i < this.anchors.length; i++) { - this.anchors[i].copy(this._localanchors[i]).rotate(this.orientation.radian); //.add(this.position) + this.anchors[i].copy(this._localanchors[i]).rotate(this.orientation.radian);//.add(this.position) } if (this.autoUpdateBound) this.bounds.calculateBounds(this, this.boundPadding); this.bounds.update(this.position); //this.angle = this.angle > 360 ? this.angle - 360 : this.angle < 0 ? 360 + this.angle : this.angle } - toJson() { - let obj = { - id:this.id, - position: this.position.toJson(), - velocity: this.velocity.toJson(), - acceleration: this.acceleration.toJson(), - orientation: this.orientation.toJson(), - rotation: this.rotation.toJson(), - shapes: [], - anchors:[], - collisionResponse: this.collisionResponse, - allowSleep: this.allowSleep, - type: this.CHAOS_OBJ_TYPE, - phyType: this.type, - mass: this.mass, - inertia:this.inertia, - autoUpdateBound:this.autoUpdateBound, - boundPadding:this.boundPadding, - aabbDetectionOnly:this.aabbDetectionOnly, - mask:this.mask - }; - this.anchors.forEach((a)=>{ - obj.anchors.push(a); - }); - this.shapes.forEach((a) => { - obj.shapes.push(a.toJson()); - }); - return obj - } - //TODO - Add way to add shapes to body - fromJson(obj){ - let shapes = []; - obj.shapes.forEach((shape)=>{ - shapes.push(Shape.fromJson(shape)); - }); - let body = this; - body.shapes = shapes; - body.acceleration = obj.acceleration; - body.velocity = obj.velocity; - body.position = pbj.position; - body.rotation = obj.rotation; - body.orientation = obj.orientation; - body.mass = obj.mass; - body.inertia = obj.inertia; - body.type = obj.phyType; - body.allowSleep = obj.allowSleep; - body.aabbDetectionOnly = obj.aabbDetectionOnly; - body.collisionResponse = obj.collisionResponse; - body.autoUpdateBound = obj.autoUpdateBound; - body.id = obj.id; - body.mask = obj.mask; - obj.anchors.forEach((v)=>{ - body.setAnchor(new Vector$1().fromJson(v)); - }); - } /** *Body type that dictates a body cannot move nor respond to collisions. * @@ -2886,10 +2337,27 @@ class Body { * * @static * @type number - */ + */ static DYNAMIC = ObjType.DYNAMIC } -Utils$1.inheritComponent(Body, false, false); +Utils.inheritComponent(Body, false, false); + +class HeightMap extends Body { + constructor(step, heights) { + let l = [], + j = []; + for (let i = 0; i < heights.length; i++) { + l.push(new Vector(step * i, heights[i])); + } + for (let i = 1; i < l.length; i++) { + let line = new Line(l[i - 1], l[i]); + j.push(line); + } + super(new Vector(), ...j); + this.mass = 0; + this.mask.layer = 0; + } +} /** * A body with a circle shape on it. @@ -3012,7 +2480,7 @@ class Composite { * @type Vector */ get acceleration() { - let acceleration = new Vector$1(); + let acceleration = new Vector(); for (var i = 0; i < this.bodies.length; i++) { acceleration.copy(this.bodies[i].acceleration); } @@ -3029,7 +2497,7 @@ class Composite { * @type Vector */ get velocity() { - let velocity = new Vector$1(); + let velocity = new Vector(); for (var i = 0; i < this.bodies.length; i++) { velocity.add(this.bodies[i].velocity); @@ -3041,28 +2509,27 @@ class Composite { this.bodies[i].velocity.copy(x); } } - /** - * Orientation of a body in degrees. - * - * @type number - */ - get angle() { - let angle = 0; + /** + * Orientation of a body in degrees. + * + * @type number + */ + set angle(angle) { for (var i = 0; i < this.bodies.length; i++) { - angle += this.bodies[i].angle; + this.bodies[i].angle = x; } } - set angle(angle) { + get angle() { + let angle = 0; for (var i = 0; i < this.bodies.length; i++) { - this.bodies[i].angle = x; + angle += this.bodies[i].angle; } } - - /** - * Mass of a body. - * - * @type number - */ + /** + * Mass of a body. + * + * @type number + */ set mass(x) { for (var i = 0; i < this.bodies.length; i++) { this.bodies[i].mass = x; @@ -3075,11 +2542,11 @@ class Composite { } return mass } - /** - * Density of a body. - * - * @type number - */ + /** + * Density of a body. + * + * @type number + */ set density(x) { for (var i = 0; i < this.bodies.length; i++) { this.bodies[i].density = x; @@ -3098,7 +2565,7 @@ class Composite { * @type Vector */ get position() { - let position = new Vector$1(); + let position = new Vector(); for (var i = 0; i < this.shapes.length; i++) { position.add(this.bodies[i].position); } @@ -3120,24 +2587,17 @@ class Composite { this.bodies[i].orientation.copy(r); } } - get orientation() { - let ang = 0; - for (var i = 0; i < this.bodies.length; i++) { - ang += this.bodies[i].orientation; - } - return ang / this.bodies.length - } - /** - * Angular velocity of a body. - * - * @type number - */ + /** + * Angular velocity of a body. + * + * @type number + */ get angularVelocity() { let ang = 0; for (var i = 0; i < this.bodies.length; i++) { ang += this.bodies[i].angularVelocity; } - return ang / this.bodies.length + return ang } set angularVelocity(x) { for (var i = 0; i < this.bodies.length; i++) { @@ -3145,7 +2605,7 @@ class Composite { } } } -Utils$1.inheritComponent(Composite); +Utils.inheritComponent(Composite); /** * Base class for constructing different types of constraints. @@ -3164,8 +2624,8 @@ class Constraint { constructor(body1, body2, localA, localB) { this.body1 = body1; this.body2 = body2; - this.localA = localA || new Vector$1(); - this.localB = localB || new Vector$1(); + this.localA = localA || new Vector(); + this.localB = localB || new Vector(); this.stiffness = 50; this.dampening = 0.03; } @@ -3178,15 +2638,9 @@ class Constraint { get physicsType() { return ObjType.CONSTRAINT } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "constraint" } @@ -3198,7 +2652,7 @@ class Constraint { * @param {Body} body2 * @param {number} dt */ - behavior(body1, body2, dt) { + behavior(body1, body2,dt) { body2.position.copy(body1.position); } /** @@ -3207,40 +2661,15 @@ class Constraint { * @param {number} dt */ update(dt) { - this.behavior(this.body1, this.body2, dt); - } - toJson() { - return { - body1: this.body1.id, - body2: this.body2.id, - localA: this.localA.toJson(), - localA: this.localB.toJson(), - stiffness: this.stiffness, - dampening: this.dampening, - type:this.CHAOS_OBJ_TYPE - } - } - fromJson(obj, world) { - let bod1 = world.getById(obj.body1); - let bod2 = world.getById(obj.body2); - - let constraint = new Constraint( - bod1, - bod2, - new Vector$1().fromJson(obj.localA), - new Vector$1().fromJson(obj.localB) - ); - constraint.stiffness = obj.stiffness; - constraint.dampening = obj.dampening; - return constraint + this.behavior(this.body1, this.body2,dt); } } -let tmp1$a = new Vector$1(), - tmp2$8 = new Vector$1(), - tmp3$5 = new Vector$1(), - tmp4$4 = new Vector$1(), - tmp5$3 = new Vector$1(); +let tmp1$b = new Vector(), + tmp2$8 = new Vector(), + tmp3$5 = new Vector(), + tmp4$4 = new Vector(), + tmp5$3 = new Vector(); /** * This constraint is stronger than a spring in the sense that it will not oscilate as such as a spring constraint. @@ -3255,7 +2684,7 @@ class DistanceConstraint extends Constraint { constructor(body1, body2, localA, localB) { super(body1, body2,localA,localB); this.fixed = !body1.mass || !body2.mass; - this.dampening = 1; + this.dampen = 1; this.maxDistance = 1; this.stiffness = 1; } @@ -3267,7 +2696,7 @@ class DistanceConstraint extends Constraint { * @param {number} dt */ behavior(body1, body2,dt) { - let arm1 = tmp1$a.copy(this.localA), + let arm1 = tmp1$b.copy(this.localA), arm2 = tmp2$8.copy(this.localB), pos1 = tmp3$5.copy(body1.position).add(arm1), pos2 = tmp4$4.copy(body2.position).add(arm2), @@ -3278,7 +2707,7 @@ class DistanceConstraint extends Constraint { return } let difference = (magnitude - this.maxDistance) / magnitude, - force = dist.multiply(difference * this.stiffness * this.dampening), + force = dist.multiply(difference * this.stiffness * this.dampen), massTotal = body1.inv_mass + body2.inv_mass; body1.inv_inertia + body2.inv_inertia; tmp4$4.copy(force); @@ -3295,12 +2724,12 @@ class DistanceConstraint extends Constraint { } } -let tmp1$9 = new Vector$1(), - tmp2$7 = new Vector$1(), - tmp3$4 = new Vector$1(), - tmp4$3 = new Vector$1(), - tmp5$2 = new Vector$1(), - zero = new Vector$1(); +let tmp1$a = new Vector(), + tmp2$7 = new Vector(), + tmp3$4 = new Vector(), + tmp4$3 = new Vector(), + tmp5$2 = new Vector(), + zero = new Vector(); /** * A constraint that acts like a spring between two bodies */ @@ -3313,10 +2742,10 @@ class SpringConstraint extends Constraint { */ constructor(body1, body2, localA, localB) { super(body1, body2); - this.localA = new Vector$1().copy(localA || zero); - this.localB = new Vector$1().copy(localB || zero); + this.localA = new Vector().copy(localA || zero); + this.localB = new Vector().copy(localB || zero); this.fixed = !body1.mass || !body2.mass; - this.dampening = 1; + this.dampen = 1; this.maxDistance = 100; this.stiffness = 1; } @@ -3328,7 +2757,7 @@ class SpringConstraint extends Constraint { * @param {number} dt */ behavior(body1, body2, dt) { - let arm1 = tmp1$9.copy(this.localA), + let arm1 = tmp1$a.copy(this.localA), arm2 = tmp2$7.copy(this.localB), pos1 = tmp3$4.copy(body1.position).add(arm1), pos2 = tmp4$3.copy(body2.position).add(arm2), @@ -3339,7 +2768,7 @@ class SpringConstraint extends Constraint { return } let difference = (magnitude - this.maxDistance) / magnitude, - force = dist.multiply(difference * this.stiffness * this.dampeninging), + force = dist.multiply(difference * this.stiffness * this.dampen), massTotal = body1.inv_mass + body2.inv_mass, inertiaTotal = body1.inv_inertia + body2.inv_inertia; force.divide(massTotal + inertiaTotal); @@ -3351,9 +2780,9 @@ class SpringConstraint extends Constraint { } } -let position = new Vector$1(); -let acceleration = new Vector$1(); -let velocity = new Vector$1(); +let position = new Vector(); +let acceleration = new Vector(); +let velocity = new Vector(); /** * Verlet intergration. @@ -3376,11 +2805,11 @@ class VerletSolver { } } -let tmp1$8 = new Vector$1(), - tmp2$6 = new Vector$1(), - tmp3$3 = new Vector$1(), - tmp4$2 = new Vector$1(), - tmp5$1 = new Vector$1(); +let tmp1$9 = new Vector(), + tmp2$6 = new Vector(), + tmp3$3 = new Vector(), + tmp4$2 = new Vector(), + tmp5$1 = new Vector(); /** * Solves for impulse along collision tangent for a given body pair. @@ -3391,7 +2820,7 @@ const FrictionSolver = { let { bodyA: a, bodyB: b, ca1, ca2, restitution, impulse } = manifold; let { axis } = manifold.contactData; if (impulse <= 0) return - let a$va = tmp1$8.set(ca1.y * -a.rotation._rad, ca1.x * a.rotation._rad); + let a$va = tmp1$9.set(ca1.y * -a.rotation._rad, ca1.x * a.rotation._rad); let a$vb = tmp2$6.set(ca2.y * -b.rotation._rad, ca2.x * b.rotation._rad); let va = tmp3$3.copy(a.velocity).add(a$va); let vb = tmp4$2.copy(b.velocity).add(a$vb); @@ -3456,8 +2885,8 @@ const ContactSolver = { } }; -const tmp1$7 = new Vector$1(), - tmp2$5 = new Vector$1(); +const tmp1$8 = new Vector(), + tmp2$5 = new Vector(); let dampen = Settings.posDampen; /** @@ -3471,18 +2900,18 @@ const PenetrationSolver = { const dampened = overlap * dampen; const a = dampened / (bodyA.inv_mass + bodyB.inv_mass + sq(ca1.cross(axis)) * bodyA.inv_inertia + sq(ca2.cross(axis)) * bodyB.inv_inertia); let jp = tmp2$5.copy(axis).multiply(a); - bodyA.velocity.add(tmp1$7.copy(jp).multiply(bodyA.inv_mass * inv_dt)); - bodyB.velocity.add(tmp1$7.copy(jp).multiply(-bodyB.inv_mass * inv_dt)); + bodyA.velocity.add(tmp1$8.copy(jp).multiply(bodyA.inv_mass * inv_dt)); + bodyB.velocity.add(tmp1$8.copy(jp).multiply(-bodyB.inv_mass * inv_dt)); bodyA.rotation.radian += ca1.cross(jp) * bodyA.inv_inertia * inv_dt; bodyB.rotation.radian += ca2.cross(jp) * -bodyB.inv_inertia * inv_dt; manifold.contactData.lastOverlap = overlap; } }; -let tmp1$6 = new Vector$1(), - tmp2$4 = new Vector$1(), - tmp3$2 = new Vector$1(), - tmp4$1 = new Vector$1(); +let tmp1$7 = new Vector(), + tmp2$4 = new Vector(), + tmp3$2 = new Vector(), + tmp4$1 = new Vector(); /** * Solves for the collision normal impulse of a given body pair. @@ -3491,7 +2920,7 @@ const ImpulseSolver = { solve(manifold) { let { bodyA, bodyB, ca1, ca2, restitution } = manifold; let { axis } = manifold.contactData; - let a$va = tmp1$6.set(ca1.y * -bodyA.rotation.radian, ca1.x * bodyA.rotation.radian); + let a$va = tmp1$7.set(ca1.y * -bodyA.rotation.radian, ca1.x * bodyA.rotation.radian); let a$vb = tmp2$4.set(ca2.y * -bodyB.rotation.radian, ca2.x * bodyB.rotation.radian); let va = tmp3$2.copy(bodyA.velocity).add(a$va); let vb = tmp4$1.copy(bodyB.velocity).add(a$vb); @@ -3524,11 +2953,11 @@ const ImpulseSolver = { }; const _arr = [], - tmp1$5 = { + tmp1$6 = { overlap: 0, verticesA: null, verticesB: null, - axis: new Vector$1(), + axis: new Vector(), vertex: null, shape: null }, @@ -3542,9 +2971,9 @@ const _arr = [], max: 0, indexN: 0 }, - tmp4 = new Vector$1(), - tmp5 = new Vector$1(), - tmp6 = new Vector$1(); + tmp4 = new Vector(), + tmp5 = new Vector(), + tmp6 = new Vector(); /** * Used for narrowphase collision detection and contact info generation. @@ -3621,7 +3050,7 @@ const SAT = { shapesCollided(shape1, shape2, target) { let arr = _arr, boundary; - Utils$1.clearArr(arr); + Utils.clearArr(arr); shape1.getNormals(shape2, arr); boundary = arr.length; shape2.getNormals(shape1, arr); @@ -3636,7 +3065,7 @@ const SAT = { * @param {number} iu */ projectShapesToAxes(shapeA, shapeB, axes, manifold, iu) { - let temp = tmp1$5; + let temp = tmp1$6; temp.vertex = null; temp.body = null; temp.overlap = Infinity; @@ -3738,7 +3167,7 @@ const SAT = { } if (point < min) { min = point; - Utils$1.clearArr(nearVertices); + Utils.clearArr(nearVertices); nearVertices.push(vertices[i]); i = -1; } @@ -3868,16 +3297,13 @@ class NaiveBroadphase extends Broadphase { * @type Body[] */ bodies = null - /** - * @param {World} world - */ constructor(world) { super(); this.bodies = world.objects; } /** * @inheritdoc - * @param {Bounds} bound Region to check in. + * @param {Bounds} bounds Region to check in. * @param {Body[]} target Empty array to store results. * @returns {Body[]} */ @@ -3892,7 +3318,7 @@ class NaiveBroadphase extends Broadphase { } /** * @inheritdoc - * @param {CollisionPair[]} target Empty array to store results. + * @param {array} target Empty array to store results. * @returns {CollisionPair[]} */ getCollisionPairs(target) { @@ -3920,54 +3346,30 @@ class NaiveBroadphase extends Broadphase { } -class Client { +let Client$1 = class Client { constructor(body) { this.body = body; this.bounds = body.bounds.clone(); this.node = null; } -} +}; class Node { - /**@type Node[]*/ - children = [] - /**@type Body[]*/ - objects = [] - /**@type Node*/ - root = null - /**@type Node*/ - parent = null - /**@type boolean*/ - hasObjects = false - /**@type number*/ - index = -1 - /**@type Tree*/ - global = null - /**@type Vector_like*/ - dims = null - /**@type number*/ - depth = -1 - /**@type {{ - max:Vector_like, - min:Vector_like - }}*/ - bounds = null - /** - * @param {{ - max:Vector_like, - min:Vector_like - }} bounds - */ constructor(bounds) { + this.children = []; + this.objects = []; + this.parent = null; + this.global = null; + this.index = -1; + this.root = null; this.bounds = bounds; + this.hasObjects = false; + this.depth = -1; this.dims = { x: this.bounds.max.x - this.bounds.min.x, y: this.bounds.max.y - this.bounds.min.y }; } - /** - * @param {Node} node - */ add(node) { node.index = this.children.length; this.children.push(node); @@ -3984,9 +3386,6 @@ class Node { node.global = null; } } - /** - * @param {number} depth - */ split(depth = 1) { let w = this.dims.x / 2; let h = this.dims.y / 2; @@ -4037,9 +3436,6 @@ class Node { if (depth <= 1) return this.children.forEach(e => e.split(depth - 1)); } - /** - * @param {CanvasRenderingContext2D} ctx - */ draw(ctx) { ctx.beginPath(); ctx.strokeStyle = "blue"; @@ -4047,15 +3443,9 @@ class Node { ctx.stroke(); ctx.closePath(); } - /** - * @return boolean - */ isLeafNode() { return this.children.length == 0 } - /** - * @return boolean - */ childrenHaveObj() { return this.children.length > 0 || ( this.children[0].hasObjects || @@ -4064,19 +3454,11 @@ class Node { this.children[3].hasObjects ) } - /** - * @param {Bounds} bounds - * @return boolean - */ intersects(bounds) { if (bounds.r) return Overlaps.AABBvsSphere(this.bounds, bounds) return Overlaps.AABBColliding(this.bounds, bounds) } - /** - * @param {Bounds} bounds - * @return boolean - */ contains(bounds) { return ( bounds.max.x < this.bounds.max.x && @@ -4085,13 +3467,7 @@ class Node { bounds.min.y > this.bounds.min.y ) } - /** - * @inheritdoc - * @param {Bounds} bounds - * @param {Body[]} [target] - * @returns boolean - */ - query(bounds, target = []) { + query(bounds, target) { if (!this.intersects(bounds)) return target if (!this.isLeafNode()) { @@ -4106,10 +3482,6 @@ class Node { } return target } - /** - * @param {Body} obj - * @returns boolean - */ insertObject(obj) { if (!this.contains(obj.bounds)) return false @@ -4130,10 +3502,6 @@ class Node { } return false } - /** - * @param {Vector_like} position - * @returns boolean - */ isInNode(position) { if ( position.x > this.bounds.min.x && @@ -4147,24 +3515,17 @@ class Node { isRootNode() { return !this.parent } - /** - * @param {Body} obj - */ updateObject(obj) { this.removeObject(obj); this.global.insert(obj); return true } - /** - * @param {Body} obj - * @returns boolean - */ removeObject(obj) { if (!this.isInNode(obj.lastPosition)) return false let t = this.objects.indexOf(obj); if (t !== -1) { - Utils$1.removeElement(this.objects, t); + Utils.removeElement(this.objects, t); if ( this.objects.length == 0 && this.childrenHaveObj() @@ -4186,12 +3547,6 @@ class Node { } return false } - /** - * @template T - * @param {Traverser} func - * @param {T[]} target - * @returns [] - */ traverse(func, target) { if (!this.isLeafNode()) { for (var i = 0; i < 4; i++) { @@ -4205,18 +3560,14 @@ class Node { return target } } - /** - * @param {CollisionPair[]} target - * @param {CollisionPair[]} stack - */ getCollisionPairs(target, stack) { if (!this.hasObjects) return if (!this.isLeafNode()) { - Utils$1.appendArr(stack, this.objects); + Utils.appendArr(stack, this.objects); for (var i = 0; i < 4; i++) { this.children[i].getCollisionPairs(target, stack); } - Utils$1.popArr(stack, this.objects.length); + Utils.popArr(stack, this.objects.length); } let length = stack.length, obLength = this.objects.length, @@ -4299,7 +3650,7 @@ class Tree extends Broadphase { insert(obj) { let client = body.client; if (client == null) { - client = body.client = new Client(body); + client = body.client = new Client$1(body); } this._insert(client); } @@ -4338,7 +3689,7 @@ class Tree extends Broadphase { /** * A depth first search of the quadtree that applies the given function to its nodes. * - * @param {Function} func The function that checks every node unless it returns true. + * @param {function} func The function that checks every node unless it returns true. * */ traverse(func) { @@ -4346,7 +3697,6 @@ class Tree extends Broadphase { } /** * @inheritdoc - * @param {CanvasRenderingContext2D} ctx */ draw(ctx) { this._root.traverse(e => { @@ -4387,11 +3737,162 @@ class Tree extends Broadphase { } } +let floor = Math.floor; +class Client { + constructor(body) { + this.body = body; + this.bounds = body.bounds.clone(); + } +} + /** - * @callback Traverser - * @param {Node} node - * @returns {boolean} -*/ + * This is a bounded broadphase that is used to speed up collision testing on dense number of objects over a small area. + * + * @extends Broadphase + */ +class Grid extends Broadphase { + bins = [] + bounds = null + constructor(bounds, divX, divY) { + super(); + this.bounds = bounds; + this.divX = divX; + this.divY = divY; + for (let i = 0; i < divX; i++) { + let Xbin = []; + for (let j = 0; j < divY; j++) { + Xbin.push([]); + } + this.bins.push(Xbin); + } + } + _hash(x, y) { + let key = [0, 0], + minX = this.bounds.min.x, + minY = this.bounds.min.y, + width = this.bounds.max.x - this.bounds.min.x, + height = this.bounds.max.y - this.bounds.min.y; + + key[0] = floor( + ((x - minX) / width) * this.divX); + key[1] = floor(((y - minY) / height) * this.divY); + return key + } + /** + * @inheritdoc + * @private + * @param {Client} client + */ + _insert(client) { + client.bounds.copy(client.body.bounds); + let [x1, y1] = this._hash(client.bounds.min.x, client.bounds.min.y); + let [x2, y2] = this._hash(client.bounds.max.x, client.bounds.max.y); + + + if (x1 > this.divX - 1 || x1 < 0) return + if (y1 > this.divY - 1 || y1 < 0) return + if (x2 > this.divX - 1 || x2 < 0) return + if (y2 > this.divY - 1 || y2 < 0) return + + for (let i = x1; i <= x2; i++) { + for (var j = y1; j <= y2; j++) { + this.bins[i][j].push(client); + } + } + } + /** + * @inheritdoc + * @param {Body} body + */ + insert(body) { + let client = body.client; + if (client == null) { + client = body.client = new Client(body); + } + this._insert(client); + } + /** + * @inheritdoc + * @private + * @param {Client} client + */ + _remove(client) { + let [x1, y1] = this._hash(client.bounds.max.x, client.bounds.max.y); + let [x2, y2] = this._hash(client.bounds.max.x, client.bounds.max.y); + + if (x1 > this.divX - 1 || x1 < 0) return + if (y1 > this.divY - 1 || y1 < 0) return + if (x2 > this.divX - 1. || x2 < 0) return + if (y2 > this.divY - 1. || y2 < 0) return + + for (let i = x1; i <= x2; i++) { + for (let j = y1; j <= y2; j++) { + let index = this.bins[i][j].indexOf(client); + Utils.removeElement(this.bins[i][j], index); + } + } + } + /** + * @inheritdoc + * @param {Body} body + */ + remove(body) { + if (body.client === null) return + this._remove(body.client); + } + /** + * @inheritdoc + * @private + * @param {Body} body + */ + _update(body) { + this._remove(body.client); + this._insert(body.client); + } + /** + * @inheritdoc + * @param {Body[]} bodies + */ + update(bodies) { + for (var i = 0; i < bodies.length; i++) { + this._update(bodies[i]); + } + } + _naiveCheck(arr, ids, target) { + for (var j = 0; j < arr.length; j++) { + for (var k = j + 1; k < arr.length; k++) { + let a = arr[j]; + let b = arr[k]; + let id = naturalizePair(a.id, b.id); + + if (ids.has(id)) continue + if (!this.canCollide(a, b)) continue + if (!a.bounds.intersects(b.bounds)) + continue + ids.add(id); + target.push({ + a, + b + }); + } + } + } + /** + * @inheritdoc + * @param {CollisionPair[]} target Empty array to store results. + * @returns {CollisionPair[]} + */ + getCollisionPairs(target) { + //When bodies are in more than one bin,there is a possibility that they might show up in more than one collision,this remedies that. + let ids = new Set(); + for (let i = 0; i < divX; i++) { + for (let j = 0; j < divY; j++) { + this._naiveCheck(this.bins[i][j], ids, target); + } + } + return target + } +} /** * Class responsible for updating bodies,constraints and composites. @@ -4414,14 +3915,14 @@ class World { /** * A list of bodies. * - * @type Body[] + * @type Array * @private */ objects = [] /** * A list of constraints fixed to a static object. * - * @type Constraint[] + * @type Array * @private */ fixedConstraits = [] @@ -4454,7 +3955,7 @@ class World { /** * The collision manifolds that have passed narrowphase and verified to be colliding. * - * @type Manifold[] + * @type Array */ CLMDs = [] /** @@ -4469,7 +3970,7 @@ class World { * * @type Vector */ - gravitationalAcceleration = new Vector$1(0, 0) + gravitationalAcceleration = new Vector(0, 0) /** * Time in seconds that a single frame takes.This has more precedence than the first parameter of World.update(),set to this to zero if you want to use the latter as the delta time. * @@ -4532,7 +4033,7 @@ class World { lastOverlap: 0, overlap: -Infinity, done: false, - axis: new Vector$1(), + axis: new Vector(), verticesA: [], verticesB: [], vertShapeA: null, @@ -4545,13 +4046,13 @@ class World { stmp: -1, impulse: 0, persistent: false, - ca1: new Vector$1(), - ca2: new Vector$1(), + ca1: new Vector(), + ca2: new Vector(), restitution: 0, staticFriction: 0, kineticFriction: 0, - velA: new Vector$1(), - velB: new Vector$1(), + velA: new Vector(), + velB: new Vector(), rotA: 0, rotB: 0 }); @@ -4562,13 +4063,13 @@ class World { SAT.shapesInBodyCollided(a, b, collisionData); if (collisionData.overlap < 0 || !collisionData.done) continue if (collisionData.contactNo == 2) { - Vector$1.lerp( + Vector.lerp( collisionData.verticesA[0], collisionData.verticesA[1], 0.5, manifold.ca1 ).sub(a.position); - Vector$1.lerp( + Vector.lerp( collisionData.verticesB[0], collisionData.verticesB[1], 0.5, @@ -4702,7 +4203,7 @@ class World { /** * * - * @param {Number} delta the time passed between the last call and this call. + * @param {Number} dt the time passed between the last call and this call. */ update(delta) { this.perf.lastTimestamp = performance.now(); @@ -4777,7 +4278,7 @@ class World { */ removeBody(body) { this.broadphase.remove(body); - if (Utils$1.removeElement(this.objects, body.index)) { + if (Utils.removeElement(this.objects, body.index)) { if (body.index === this.objects.length) return this.objects[body.index].index = body.index; @@ -4806,7 +4307,7 @@ class World { removeContraint(constraint) { let arr = constraint.fixed ? this.fixedConstraits : this.constraints; let temp = arr.pop(); - if(constraint.index == arr.length) return constraint + if (constraint.index == arr.length) return constraint arr[constraint.index] = temp; temp.index = constraint.index; constraint.index = -1; @@ -4852,54 +4353,49 @@ class World { } } -/** - * Holds transformation info of an entity - * - * @implements Component - */ -class Transform { - entity = null - /** - * @param {number} x - * @param {number} y - * @param {number} a - * @returns - */ - constructor(x,y,a){ - this.position = new Vector$1(x,y); - this.orientation = new Angle(a); - } - init(){} - toJson(){ - return { - position: this.position.toJson(), - orientation:this.orientation.toJson() - } - } - fromJson(obj){ - this.position.fromJson(obj.position); - this.orientation.fromJson(obj.orientation); - } -} - class Camera { - /** - * @readonly - * @type Transform - */ - transform = new Transform() - - constructor() { } - /** - * @type Vector - */ + _position = new Vector() + constructor(renderer, position) { + this.transformMatrix = new Matrix2(); + this.target = null; + this.lerpFactor = 0.5; + this.renderer = renderer; + this.offset = new Vector(); + this._position = new Vector(); + this._actualPosition = new Vector(); + this.position.set(position?.x || 0, position?.y || 0); + this.orientation = new Angle(); + } get position() { - return this.transform.position + return this._actualPosition } set position(x) { - this.transform.position.copy(x); + this._actualPosition.copy(x); + } + get transform() { + return this.position + } + update() { + if (this.target) + Vector.lerp( + this._position, + this.target, + this.lerpFactor, + this._position + ); + this._actualPosition + .copy(this._position) + .add(this.offset); + } + clear(ctx) { + ctx.setTransform(); + } + dispose() { + this.renderer = null; + } + follow(position) { + this.target = position; } - update() {} } /** @@ -4911,10 +4407,6 @@ class Camera { * @see WebGPURenderer */ class Renderer { - /** - * @type number - */ - _rafID = 0 /** * Used to throttle the frame rate. * @@ -4943,9 +4435,6 @@ class Renderer { domElement = null /**@type {CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext}*/ ctx = null - /** - * @type {Camera} - */ camera = null /** * @param {CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext} context @@ -4973,9 +4462,7 @@ class Renderer { throw "Override Renderer.clear()" } /** - * Updates the objects within the renderer. - * - * @param {number} dt + * Updates the objects within the renderer */ update(dt) { throw "Override Renderer.update()" @@ -5016,7 +4503,7 @@ class Renderer { /** * Adds a mesh to the renderer. * - * @param {Sprite | Group} sprite + * @param {Sprite} Sprite */ add(sprite) { this.objects.push(sprite); @@ -5076,8 +4563,10 @@ class Renderer { * Renders images and paths to the 2D context of a canvas. * * @extends Renderer - */ +*/ class Renderer2D extends Renderer { + _fill = "black" + _stroke = "black" frameRate = 1 / 60 renderLast = [] /** @@ -5085,49 +4574,136 @@ class Renderer2D extends Renderer { */ constructor(canvas) { canvas = canvas || document.createElement("canvas"); - super(canvas, canvas.getContext("2d")); + super(canvas,canvas.getContext("2d")); + + } + push() { + this.ctx.save(); + } + pop() { + this.ctx.restore(); } - /** - * @inheritdoc - * - * @param {Sprite | Group} sprite - */ - add(sprite) { - super.add(sprite); - sprite.geometry?.init(this.ctx); + reset() { + this.ctx.setTransform(); + } + translate(x, y) { + this.ctx.translate(x, y); + } + scale(x, y) { + this.ctx.scale(x, y); + } + rotate(rad) { + this.ctx.rotate(rad); + } + line(x1, y1, x2, y2) { + this.ctx.moveTo( + x1 - this.camera.position.x, + y1 - this.camera.position.y + ); + this.ctx.lineTo( + x2 - this.camera.position.x, + y2 - this.camera.position.y + ); + } + rect(x, y, w, h) { + this.ctx.rect( + x - this.camera.position.x, + y - this.camera.position.y, + w, + h + ); + } + circle(x, y, r) { + this.ctx.arc( + x - this.camera.position.x, + y - this.camera.position.y, + r, 0, Math.PI * 2 + ); + } + vertices(vertices, close = true) { + if (vertices.length < 2) return; + this.ctx.moveTo( + vertices[0].x - this.camera.position.x, + vertices[0].y - this.camera.position.y); + for (var i = 1; i < vertices.length; i++) { + this.ctx.lineTo( + vertices[i].x - this.camera.position.x, + vertices[i].y - this.camera.position.y + ); + } + if (close) + this.ctx.lineTo( + vertices[0].x - this.camera.position.x, + vertices[0].y - this.camera.position.y + ); + } + arc(x, y, r, start, end) { + this.ctx.arc( + x - this.camera.position.x, + y - this.camera.position.y, + r, start, end + ); + } + fillText(text, x, y) { + this.ctx.fillText(text, + x - this.camera.position.x, + y - this.camera.position.y + ); + } + fill(color = "black", fillRule) { + this.ctx.fillStyle = color; + this.ctx.fill(fillRule); + } + stroke(color = "black", width = 1) { + this.ctx.strokeStyle = color; + this.ctx.lineWidth = width; + this.ctx.stroke(); + } + begin() { + this.ctx.beginPath(); + } + close() { + this.ctx.closePath(); + } + clip() { + this.ctx.clip(); + } + drawImage( + img, + x, + y, + w = img.width, + h = img.height, + ix = 0, + iy = 0 + ) { + this.ctx.drawImage(img, w * ix, h * iy, w, h, + x - this.camera.position.y, + y - this.camera.position.y, + w, h); } clear() { - this.ctx.setTransform(); + this.reset(); let h = this.height, w = this.width; this.ctx.clearRect(0, 0, w, h); } - /** - * @param {number} dt - */ update(dt) { - this.camera.update(); + this.camera.update(dt); this.perf.lastTimestamp = performance.now(); this.clear(); if (this.background != void 0) this.background.update(this, dt); - this.ctx.save(); - this.ctx.translate(this.camera.transform.position.x,-this.camera.transform.position.y); - this.ctx.rotate(this.camera.transform.orientation.radian); for (var i = 0; i < this.objects.length; i++) { - this.objects[i].render(this.ctx, dt); + this.objects[i].render(this, dt); } - this.ctx.restore(); for (var i = 0; i < this.renderLast.length; i++) { this.renderLast[i].update(this, dt, this.camera.transform); } this.perf.total = performance.now() - this.perf.lastTimestamp; } - /** - * @private - */ - _update = (accumulate) => { + _update = (accumulate)=> { let dt = this.clock.update(accumulate); if (this._accumulator < this.frameRate) { this._accumulator += dt; @@ -5138,11 +4714,9 @@ class Renderer2D extends Renderer { this.RAF(); this._accumulator = 0; } - /** - * @param {Sprite} sprite - */ - addUI(sprite) { - this.renderLast.push(sprite); + + addUI(mesh) { + this.renderLast.push(mesh); } requestFullScreen() { this.domElement.parentElement.requestFullscreen(); @@ -5179,516 +4753,82 @@ class WebGLRenderer extends Renderer{ * Extend it to create your custom behaviour. * * @implements Component - * TODO - ADD id property to this class and Group class. */ class Sprite { /** * @private */ - _position = null - /** - * @private - */ - _orientation = null + _position = new Vector() /** * @private */ - _scale = null + _orientation = new Angle() + scale = new Vector(1, 1) /** * @private */ geometry = null - /** - * @private - */ material = null - /** - * @type Group | null - */ parent = null - /** - * @param {BufferGeometry} geometry - * @param {Material} material - */ constructor(geometry, material) { this.geometry = geometry; this.material = material; } - /** - * Angle in degrees - * - * @type number - */ get angle() { return this._orientation.radian * 180 / Math.PI } set angle(x) { this._orientation.degree = x; } - /** - * World space position. - * - * @type Vector - */ get position() { return this._position } set position(x) { this._position.copy(x); } - /** - * Orientation of the sprite - * - * @type Angle - */ get orientation() { return this._orientation } set orientation(x) { this._orientation.copy(x); } - render(ctx, dt) { - ctx.save(); - ctx.beginPath(); - ctx.translate(...this._position); - ctx.rotate(this._orientation.radian); - ctx.scale(...this._scale); - this.material?.render(ctx,dt,this.geometry?.drawable); - ctx.closePath(); - ctx.restore(); - } - /** - * @param {Entity} entity - */ - init(entity) { - if(!entity){ - this._position = new Vector$1(); - this._orientation = new Angle(); - this._scale = new Vector$1(1,1); - return - } - this.entity = entity; - this.requires("transform"); - let transform = entity.get("transform"); - this._position = transform.position; - this._orientation = transform.orientation; - //TODO - Correct this later - this._scale = new Vector$1(1,1); - return this - } - toJson(){ - let obj = { - pos:this._position.toJson(), - angle:this._orientation.toJson(), - geometry:this.geometry?.toJson(), - material:this.material?.toJson(), - parent:this.parent?.id - }; - return obj - } - fromJson(obj,renderer){ - this.geometry?.fromJson(obj.geometry); - this.material?.fromJson(obj.material); - this.position.fromJson(obj.pos); - this._orientation.fromJson(obj.angle); - this.parent = renderer.getById(obj.parent); - } -} -Utils$1.inheritComponent(Sprite); - -/** - * @param {CanvasRenderingContext2D} ctx - * @param {number} x1 - * @param {number} y1 - * @param {number} x2 - * @param {number} y2 - */ -function line(ctx, x1, y1, x2, y2) { - ctx.moveTo(x1, y1); - ctx.lineTo(x2, y2); -} -/** - * @param {CanvasRenderingContext2D} ctx - * @param {number} x - * @param {number} y - * @param {number} w - * @param {number} h - */ -function rect(ctx, x, y, w, h) { - ctx.rect(x, y, w, h); -} -/** - * @param {CanvasRenderingContext2D} ctx - * @param {number} x - * @param {number} y - * @param {number} r - */ -function circle(ctx, x, y, r) { - ctx.arc(x, y, r, 0, Math.PI * 2); -} -/** - * @param {CanvasRenderingContext2D} ctx - * @param {Vector[]} vertices - * @param {boolean} [close=true] - */ -function vertices(ctx, vertices, close = true) { - if (vertices.length < 2) return; - ctx.moveTo(vertices[0].x, vertices[0].y); - for (var i = 1; i < vertices.length; i++) { - ctx.lineTo(vertices[i].x, vertices[i].y); - } - if (close) - ctx.lineTo(vertices[0].x, vertices[0].y); -} -/** - * @param {CanvasRenderingContext2D} ctx - * @param {number} x - * @param {number} y - * @param {number} r - * @param {number} start - * @param {number} end - */ -function arc(ctx, x, y, r, start, end) { - ctx.arc(x, y, r, start, end); -} -/** - * @param {CanvasRenderingContext2D} ctx - * @param {string} text - * @param {number} x - * @param {number} y - */ -function fillText(ctx, text, x, y) { - ctx.fillText(text, x, y); -} -/** - * @param {CanvasRenderingContext2D} ctx - * @param {string} [color="black"] - * @param {string} [fillRule] - */ -function fill(ctx, color = "black", fillRule) { - ctx.fillStyle = color; - ctx.fill(fillRule); -} -/** - * @param {CanvasRenderingContext2D} ctx - * @param { string } [color = "black"] - * @param {number} [width=1] - */ -function stroke(ctx, color = "black", width = 1) { - ctx.strokeStyle = color; - ctx.lineWidth = width; - ctx.stroke(); -} -/** - * @param {CanvasRenderingContext2D} ctx - * @param {HTMLImageElement} img - * @param {number} x - * @param {number} y - * @param { number } [w = img#width] - * @param { number } [h=img#height] - * @param { number } [ix = 0] - * @param { number } [iy = 0] - */ -function drawImage( - ctx, - img, - x, - y, - w = img.width, - h = img.height, - ix = 0, - iy = 0 -) { - ctx.drawImage(img, w * ix, h * iy, w, h, - x, - y, - w, h); -} - -class BufferGeometry { - /** - * @readonly - * @type Vector[] - */ - vertices = null - /** - * @package - * @type Path2D | WebGLVertexArrayObject - */ - drawable = null - /** - * @param {Vector[]} vertices - */ - constructor(vertices) { - this.vertices = vertices || []; - } - /** - * @package - * @param {CanvasRenderingContext2D} ctx - */ - init(ctx) { - let path = this.drawable = new Path2D(); - vertices(path, this.vertices, true); - } -} - -class CircleGeometry { - /** - * @param {number} radius - */ - constructor(radius) { - this.radius = radius; - } - /** - * @param {CanvasRenderingContext2D} ctx - */ - init(ctx) { - this._drawable = new Path2D(); - circle(path, this.vertices, true); - } - /** - * @param {CanvasRenderingContext2D} ctx - */ - render(ctx) { - circle(ctx, 0, 0, this.radius); - } -} - -/** - * @interface -*/ -class Material{ - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - * @param {Path2D} [path] - */ - render(ctx,dt,path){ - throw "Override this method in derived class" - } -} - -/** - * - * @implements Material -*/ -class BasicMaterial { - /** - * - * @type string - * @default "white" - */ - fill = "white" - /** - * - * @type string - * @default "black" - */ - stroke = "black" - /** - * - * @type boolean - * @default false - */ - wireframe = false - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - * @param {Path2D} path - */ - render(ctx,dt, path) { - if (!this.wireframe) { - ctx.fillStyle = this.fill; - ctx.fill(path); - } - ctx.strokeStyle = this.stroke; - ctx.stroke(path); - } -} - -/** - * - * @implements Material - */ -class StaticImageMaterial { - /** - * @readonly - * @type Image - */ - image = null - /** - * - * @type number - */ - width = 100 - /** - * - * @type number - */ - height = 100 - /** - * @param {Image} img - */ - constructor(img) { - //TODO - Find a way to load images synchronously. - this.image = img; - } - /** - * @param {CanvasRenderingContext2D} ctx - */ - render(ctx) { - ctx.drawImage(this.image, -this.width / 2, -this.height / 2, this.width, this.height); - } -} - -/** - * - * @implements Material - */ -class SpriteMaterial { - /** - * @type HTMLImageElement - */ - img = null - /** - * The index of the current action. - * - * @private - * @type number - */ - _index = 0 - /** - * The current action's max frame index. - * - * @private - * @type number - */ - _maxFrame = 0 - /** - * The current frame of an action. - * - * @private - * @type number - */ - _frame = 0 - /** - * Used with ImageSprite#frameRate to throttle the fps of the sprite. - * - * @private - * @type number - */ - _accumulator = 0 - /** - * The maximum frames for each given action. - * - * @type number - */ - frameRate = 1 / 60 - /** - * The current action. - * - * @private - * @type number[] - */ - _maxFrames = null - /** - * The width of the sprite. - * - * @type number - */ - width = 0 - /** - * The height of the sprite.. - * - * @type number - */ - height = 0 - /** - * The width of a frame. - * - * @private - * @type number - */ - frameWidth = 0 - /** - * The height of a frame.. - * - * @private - * @type number - */ - frameHeight = 0 - /** - * @param {HTMLImageElement} img Image to draw - * @param {number} [frames] Number of cutouts in the sprite in the X axis of the image. - * @param {number} [actions] Number of cutouts in the sprite in the Y axis of the image. - */ - constructor(img, frames = 1, actions = 1) { - this.img = img; - this.setup(frames, actions); - } - /** - * - * @param {number} frames - * @param {number} actions - */ - setup(frames, actions) { - this._maxFrame = frames - 1; - this.width = this.img.width; - this.height = this.img.height; - this.frameWidth = this.img.width / (frames || 1); - this.frameHeight = this.img.height / actions; - } - /** - * Sets max number of frames for a given action - * - * @param {number} action - * @param {number} max - */ - setMaxFrames(action, max) { - this._maxFrames = max; - } - /** - * Sets a given action to be rendered - * - * @param {number} index - */ - setAction(index) { - this._maxFrame = (this._maxFrames[index] || 0); - this._index = index; - this._frame = 0; - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ - render(ctx, dt) { - drawImage( - ctx, - this.img, - -this.frameWidth / 2, - -this.frameHeight / 2, - this.frameWidth, - this.frameHeight, - this._frame, - this._index - ); - this._accumulator += dt; - if (this._accumulator < this.frameRate) return - this._accumulator = 0; - this._frame += 1; - if (this._frame >= this._maxFrame) - this._frame = 0; - } + /** + * Override this function. + * The canvas is already transformed to the position and rotation of the sprite. + * + */ + draw(render) { + this.geometry.render(render); + this.material.render(render); + } + render(render, dt) { + render.begin(); + render.translate(...this._position); + render.rotate(this._orientation.radian); + render.scale(...this.scale); + this.draw(render, dt); + render.close(); + render.reset(); + } + init(entity) { + this.entity = entity; + this.requires("transform"); + let transform = entity.get("transform"); + this._position = transform.position; + this._orientation = transform.orientation; + } + + + update() {} } +Utils.inheritComponent(Sprite); -let r = new Vector$1(); -let material$1 = new BasicMaterial(); -material$1.wireframe = true; /** * This draws a body from the physics System. * * @augments Sprite */ +let r = new Vector(); class BodySprite extends Sprite { /** * @private @@ -5717,92 +4857,87 @@ class BodySprite extends Sprite { this.drawVelocity = options.drawVelocity || false; this.drawBounds = options.drawBounds || false; } - /** - * @inheritdoc - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ - render(ctx, dt) { + render(renderer, dt) { if (this.body.physicsType == ObjType.COMPOSITE) { for (var i = 0; i < this.body.bodies.length; i++) { - this._drawShapes(this.body.bodies[i], ctx); + this._drawShapes(this.body.bodies[i], renderer); } } else { - this._drawShapes(this.body, ctx); + this._drawShapes(this.body, renderer); } if (this.drawVelocity == true) - this._drawVelocity(this.body, ctx); + this._drawVelocity(this.body, renderer); if (this.drawBounds == true) - this._drawBound(this.body, ctx); + this._drawBound(this.body, renderer); } /** * @private * @param {Body} body - * @param {CanvasRenderingContext2D} renderer + * @param {Renderer} renderer */ _drawVelocity(body, ctx) { - ctx.beginPath(); - line( - ctx, + ctx.begin(); + ctx.line( body.position.x, body.position.y, body.position.x + body.velocity.x, body.position.y + body.velocity.y ); - stroke(ctx, "cyan"); - ctx.closePath(); + ctx.stroke("cyan"); + ctx.close(); } /** * @private * @param {Body} body - * @param {CanvasRenderingContext2D} renderer + * @param {Renderer} renderer */ - _drawBound(body, ctx) { - ctx.beginPath(); + _drawBound(body, renderer) { + renderer.begin(); if (body.bounds.r) { - circle(ctx, ...body.position, body.bounds.r); + //renderer.circle(body.bounds.pos.x,body.bounds.pos.y, body.bounds.r) + + renderer.circle(...body.position, body.bounds.r); } else { - rect( - ctx, + renderer.rect( body.bounds.min.x, body.bounds.min.y, body.bounds.max.x - this.body.bounds.min.x, body.bounds.max.y - this.body.bounds.min.y ); } - stroke(ctx,"red"); - ctx.closePath(); + renderer.stroke("red"); + renderer.close(); + } /** * @private * @param {Body} body - * @param {CanvasRenderingContext2D} renderer + * @param {Renderer} renderer */ - _drawShapes(body, ctx) { - ctx.beginPath(); + _drawShapes(body, renderer) { + renderer.begin(); for (var i = 0; i < body.shapes.length; i++) { let shape = body.shapes[i]; - if (shape.type === Shape.CIRCLE) { - circle( - ctx, + if (shape.type == Shape.CIRCLE) { + renderer.circle( shape.position.x, shape.position.y, shape.radius); - Vector$1.fromRad(shape.angle, r).multiply(shape.radius); - line(ctx,...shape.position, + Vector.fromRad(shape.angle, r).multiply(shape.radius); + renderer.line(...shape.position, shape.position.x + r.x, shape.position.y + r.y); } else { - vertices(ctx,shape.vertices, true); + renderer.vertices(shape.vertices, true); } } - stroke(ctx); - ctx.closePath(); + renderer.stroke(); + renderer.close(); } /** - * @inheritdoc + * @package * @param {Entity} parent */ init(parent) { @@ -5811,18 +4946,11 @@ class BodySprite extends Sprite { } } -let geometry = new BufferGeometry([ - new Vector$1(-10, -10), - new Vector$1(-10, 10), - new Vector$1(20, 0) - ]); -let material = new BasicMaterial(); -material.fill = "purple"; -/** - * Used for debugging agents. - * - * @augments Sprite - */ +let path = [ + new Vector(-10, -10), + new Vector(-10, 10), + new Vector(20, 0) + ]; class AgentSprite extends Sprite { /** * @@ -5830,12 +4958,8 @@ class AgentSprite extends Sprite { * @type Agent */ agent = null - constructor() { - super(geometry,material); - } /** - * @inheritdoc - * @param {Entity} entity + * @param {Entity} entity */ init(entity) { super.init(entity); @@ -5843,58 +4967,217 @@ class AgentSprite extends Sprite { this.agent = entity.get("agent"); } /** - * @param {CanvasRenderingContext2D} ctx + * @param {Renderer} renderer + */ + draw(renderer) { + renderer.vertices(path, true); + renderer.fill("purple"); + renderer.stroke("black"); + } + /** + * @param {Renderer} renderer */ - render(ctx) { - this.agent.draw(ctx); - super.render(ctx); + render(renderer) { + this.agent.draw(renderer); + super.render(renderer); + } +} + +class DebugMesh extends Sprite { + constructor(manager) { + super(); + this.manager = manager; + this.count = 25; + this.now = 0; + this.lastPerf = {}; + this.drawBounds = false; + } + render(ctx, dt) { + this.now++; + let renderer = this.manager.getSystem("renderer"); + let world = this.manager.getSystem("world"); + let phy = world?.perf?.total, + rend = renderer?.perf?.total, + framerate = 1 / dt; + + if (this.now > this.count) { + this.lastPerf.rate = round(framerate, 2); + this.lastPerf.actual = round(1 / (rend + phy) * 1000, 2); + this.lastPerf.phy = round(phy, 2); + this.lastPerf.ren = round(rend, 2); + this.lastPerf.tot = round(this.manager.perf.total, 2); + this.now = 0; + } + ctx.begin(); + ctx.translate( renderer.width - 80, 80); + ctx.fill("cyan"); + ctx.fillText(this.lastPerf.actual + "afps", 0, -20); + ctx.fillText("render: " + this.lastPerf.ren + "ms", 0, 0); + ctx.fillText("physics: " + this.lastPerf.phy + "ms", 0, 10); + ctx.fillText("total: " + this.lastPerf.tot + "ms", 0, 20); + ctx.fillText(`bodies: ${world?.objects?.length}`, 0, 30); + + if (this.lastPerf.rate > 59) + ctx.fill("cyan"); + else if (this.lastPerf.rate > 29) + ctx.fill("orange"); + else if (this.lastPerf.rate <= 29) + ctx.fill("red"); + + ctx.fillText(this.lastPerf.rate + "fps", 0, -30); + ctx.close(); + ctx.translate( -renderer.width + 80, -80); } } /** - * Its a fricking particle! + * Renders an image-sprite frame by frame. + * The frames of the image should have equal width and height in respect to each other. + * + * @augments Sprite */ -class Particle { +class ImageSprite extends Sprite { + _index = 0 + _maxFrame = 0 + _frame = 0 + _accumulator = 0 + _dt = 0 + frameRate = 1 / 60 + _maxFrames = null + width = 0 + height = 0 + frameWidth = 0 + frameHeight = 0 /** - * @readonly - * @type Vector + * @param {HTMLImageElement} img Image to draw + * @param {number} frames Maximum number of cutouts in the sprite in the X axis of the image. + * @param {number} actions Maximum number of cutouts in the sprite in the Y axis of the image. */ - position = null + constructor(img, frames, actions) { + super(); + this.img = img; + this._maxFrame = (frames || 1) - 1; + img.onload = () => { + this.width = img.width; + this.height = img.height; + this.frameWidth = img.width / (frames || 1); + this.frameHeight = img.height / (actions || 1); + }; + this.width = 0; + this.height = 0; + this.frameWidth = 0; + this.frameHeight = 0; + } /** - * @readonly - * @type Vector + * Sets max number of frames for a given action + * + * @param {number} action + * @paran {number} max */ - velocity = null + setMaxFrames(action, max) { + this._maxFrames = max; + } /** - * @type boolean + * Sets a given action to be rendered + * + * @param {number} action + * @paran {number} max */ - active = true + setAction(index) { + this._maxFrame = this._maxFrames[index]; + this._index = index; + this._frame = 0; + } /** - * @type number + * @inheritdoc */ - radius = 0 + draw(renderer) { + renderer.drawImage( + this.img, + -this.frameWidth / 2, + -this.frameHeight / 2, + this.frameWidth, + this.frameHeight, + this._frame, + this._index + ); + } /** - * @type {{r:number,b:number,g:number,a:number}} + * @inheritdoc */ - color = null + render(renderer, dt) { + super.update(renderer, dt); + this._accumulator += dt; + if (this._accumulator < this._frameRate) return + this._accumulator = 0; + this._frame += 1; + if (this._frame > this._maxFrame) + this._frame = 0; + } +} + +/** + * Renders a single image with no frames. + * + * @augments Sprite +*/ +class StaticImageSprite extends Sprite { /** - * @private - * @type number - */ - _life = 0 + * @param {HTMLImageElement} img Image to draw + */ + constructor(img) { + super(); + this.img = img; + img.onload = () => { + this.width = img.width; + this.height = img.height; + }; + this.width = 0; + this.height = 0; + this.frameWidth = 0; + this.frameHeight = 0; + } /** - * @readonly - * @type number + * @param {Renderer} ctx */ - lifespan = 0 + draw(renderer) { + renderer.drawImage( + this.img, + -this.frameWidth / 2, + -this.frameHeight / 2, + this.frameWidth, + this.frameHeight, + this._frame, + this._index + ); + } + render(renderer, dt) { + super.update(renderer, dt); + this._accumulator += dt; + if (this._accumulator < this._frameRate) return + this._accumulator = 0; + this._frame += 1; + if (this._frame > this._maxFrame) + this._frame = 0; + + } +} + +let tmp1$5 = new Vector(); + +/** + * Its a fricking particle! +*/ +class Particle { /** * @param {Vector} pos * @param {number} radius * @param {number} [lifespan=5] In seconds - */ + */ constructor(pos, radius, lifespan = 5) { this.position = pos; - this.velocity = new Vector$1(); + this.active = true; + this.velocity = new Vector(); this.radius = radius; this.color = { r: 100, @@ -5907,24 +5190,19 @@ class Particle { } /** * Renders a particle. - * - * @param {CanvasRenderingContext2D} ctx - */ + */ draw(ctx) { - ctx.beginPath(); - circle(ctx, ...this.position, this.radius); - fill(ctx, `rgba(${this.color.r},${this.color.g},${this.color.b},${this.color.a})`); - ctx.closePath(); + ctx.begin(); + ctx.circle(...this.position, this.radius); + ctx.fill(`rgba(${this.color.r},${this.color.g},${this.color.b},${this.color.a})`); + ctx.close(); } /** * Updates a particle's lifetime - * @inheritdoc - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ + */ update(ctx, dt) { this._life += dt; - this.position.add(this.velocity); + this.position.add(tmp1$5.copy(this.velocity).multiply(dt)); this.active = this._life < this.lifespan; } } @@ -5933,30 +5211,10 @@ class Particle { * This creates a particle system * @augments Sprite */ -class ParticleSystemSprite extends Sprite { - /** - * @private - */ - _particles = [] - /** - * @type number - * @default 1 - */ - initial = 0 - /** - * @type number - * @default 1 - */ - frameIncrease = 0 - /** - * @type number - * @default 1 - */ - max = 0 +let System$1 = class System extends Sprite { /** * @param {number} [initial=1] Number of particles to start with. * @param {number} [max=100] Maximum number of particles. - * param {number} [increment=5] Maximum number of particles. */ constructor(initial = 1, max = 100, increment = 5) { super(); @@ -5967,11 +5225,10 @@ class ParticleSystemSprite extends Sprite { /** * @protected - * @param {number} n */ initParticles(n) { for (var i = 0; i < n; i++) { - this._particles.push(this.create()); + this.add(this.create()); } } @@ -5982,14 +5239,13 @@ class ParticleSystemSprite extends Sprite { */ create() { return new Particle( - new Vector$1(...this.position), + new Vector(...this.position), rand(1, 10), rand(1, 6) ) } /** * @inheritdoc - * @param {Entity} entity */ init(entity) { super.init(entity); @@ -5997,160 +5253,94 @@ class ParticleSystemSprite extends Sprite { } /** * @protected - * @param {Particle} p - * @param {number} dt */ - behavior(p,dt) { + behavior(p) { p.velocity.set( - p.velocity.x + rand(-1, 1)*dt, - p.velocity.y + rand(0, 0.3)*dt + p.velocity.x + rand(-1, 1), + p.velocity.y + rand(0, 0.3) ); } /** * @inheritdoc - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ + */ render(ctx, dt) { - for (let i = this._particles.length - 1; i > 0; i--) { - let p = this._particles[i]; + for (let i = this._children.length - 1; i > 0; i--) { + let p = this._children[i]; p.update(ctx, dt); - this.behavior(p,dt); + this.behavior(p); p.draw(ctx, dt); if (!p.active) { - this._particles.splice(i, 1); + this.remove(i); } } - if (this._particles.length < this.max) { + if (this._children.length < this.max) { this.initParticles(this.frameIncrease); } } -} +}; -/** - * Used for grouping similar. - * - * @augments Sprite - */ -class Group extends Sprite { - /** - * @private - * @type Sprite[] - */ - _children = null - /** - * @private - * @type Group - */ - parent = null - /** - * @param {Sprite[]} sprites - */ - constructor(sprites = []) { - super(); - this._children = sprites; +class Layer{ + speed = 1 + constructor(img){ + this.img = img; } - /** - * @type string - */ - get CHOAS_CLASSNAME() { - return this.constructor.name.toLowerCase() + draw(ctx,x,y){ + ctx.drawImage(this.img,x,y); } - /** - * @type string - */ - get CHAOS_OBJ_TYPE() { - return "group" + update(ctx,dt){ + } +} - /** - * Adds another sprite to this one - * - * @param {Sprite | Group} sprite - */ - add(sprite) { - this._children.push(sprite); - sprite.parent = this; +class ParallaxBackground { + constructor(...layers) { + this.layers =layers || []; } - /** - * Removes another sprite to this one - * - * @param {Sprite | Group} sprite - * @param {boolean} [recursive=false] - * @param {number} [index] - */ - remove(sprite, recursive = false, index) { - let inx = index ?? this._children.indexOf(sprite); - if (inx !== -1) { - this._children[inx].parent = null; - Utils.removeElement(this._children, inx); - return true - } - if (!recursive) return false - for (var i = 0; i < this._children.length; i++) { - if (this._children.CHAOS_OBJ_TYPE == "group") { - let t = this._children[i].remove(sprite, recursive, index); - if (t) return true - } - } - return false + update(ctx,dt){ + this.layers.forEach(layer=>{ + layer.draw(ctx,dt); + }); } - /** - * @inheritdoc - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ - render(ctx, dt) { - for (var i = 0; i < this._children.length; i++) { - this._children[i].render(ctx, dt); - } +} + +class BufferGeometry{ + constructor(vertices){ + this.vertices = vertices || []; + } + render(renderer){ + renderer.vertices(this.vertices,true); } } -class CamController { - /** - * @readonly - * @type Vector - */ - offset = new Vector$1() - /** - * @param {Camera} camera - */ - constructor(camera) { - this.transform = camera.transform; - this.offset = new Vector$1(); - this.targetPosition = null; - this.targetOrientation = null; +class CircleGeometry{ + constructor(radius){ + this.radius = radius; } - /** - * @param {Vector} position - * @param {Angle} orientation - */ - follow(position, orientation = null) { - this.targetOrientation = orientation; - this.targetPosition = position; + render(renderer){ + renderer.circle(0,0,this.radius); } - /** - * @param {Entity} entity - */ - followEntity(entity) { - if (!entity.has("transform")) return - let target = entity.get("transform"); - this.follow(target.position, target.orientation); +} + +class Material{ + constructor(){ } - /** - * @param {number} x - * @param {number} y - */ - setOffset(x, y) { - this.offset.set(x, y); + render(){ + } - init() {} - update() { - if (this.targetPosition) - this.transform.position.copy(this.targetPosition.clone().sub(this.offset)); - if (this.targetOrientation) - this.transform.orientation.copy(this.targetOrientation); +} + +class BasicMaterial{ + constructor(){ + this.fill = "red"; + this.lineWidth = 1; + this.stroke = "green"; + this.wireframe = true; + } + render(ctx){ + if(!this.wireframe){ + ctx.fill(this.fill); + } + ctx.stroke(this.stroke,this.lineWidth); } } @@ -6197,7 +5387,7 @@ const DEVICE = { */ supportedAudio: [], /** - * A list of image extensions this device supports. + * A list of audio extensions this device supports. * * @type array */ @@ -6374,7 +5564,7 @@ class Loader { } else if (type === "json") { that.json[name] = JSON.parse(xhr.response); } else { - return Err$1.warn(`The file in url ${xhr.responseURL} is not loaded into the loader because its extension name is not supported.`) + return Err.warn(`The file in url ${xhr.responseURL} is not loaded into the loader because its extension name is not supported.`) } that._filesLoaded += 1; @@ -6395,7 +5585,7 @@ class Loader { }, onerror: function(e) { that._filesErr += 1; - Err$1.warn(`The file ${e.responseURL} could not be loaded as the file might not exist in current url`); + Err.warn(`The file ${e.responseURL} could not be loaded as the file might not exist in current url`); if (that._filesLoaded + that._filesErr === that._totalFileNo && that.onfinish) that.onfinish(); } }; @@ -6594,12 +5784,12 @@ function defaultCollisionHandler(clmds) { a = clmds[i].bodyA.entity.getHandler("collision"); b = clmds[i].bodyB.entity.getHandler("collision"); - if (a) a( + if (a) a.call( clmds[i].bodyA.entity, clmds[i].bodyB.entity, clmds[i] ); - if (b) b( + if (b) b.call( clmds[i].bodyB.entity, clmds[i].bodyA.entity, clmds[i] @@ -6618,12 +5808,12 @@ function defaultPrecollisionHandler(clmds) { a = clmds[i].a.entity.getHandler("precollision"); b = clmds[i].b.entity.getHandler("precollision"); - if (a) a( + if (a) a.call( clmds[i].a.entity, clmds[i].b.entity, clmds[i] ); - if (b) b( + if (b) b.call( clmds[i].b.entity, clmds[i].a.entity, clmds[i] @@ -6660,6 +5850,7 @@ class Keyboard { */ constructor(eh) { this.keys = {}; + this.activeKeys = []; this.init(eh); } /** @@ -6685,20 +5876,18 @@ class Keyboard { eh.add('keydown',this._onDown); eh.add('keyup',this._onUp); } - /** - * @private - */ _onDown = e => { let key = this.normalize(e.code); this.keys[key] = true; this.activeKeys.push(key); + this.ondown(e); } - /** - * @private - */ _onUp = e =>{ this.keys[this.normalize(e.code)] = false; + this.onup(e); } + ondown(e) {} + onup(e) {} } /** @@ -6736,14 +5925,6 @@ class Mouse { * @type Vector_like */ position = { x: 0, y: 0 } - /** - - * Position of the mouse in last frame. - - * - * @type Vector_like - */ - lastPosition = { x: 0, y: 0 } /** * If the left mouse button is pressed or not. * @@ -6760,13 +5941,19 @@ class Mouse { * @param {DOMEventHandler} eh */ constructor(eh) { + this.dragging = false; + this.dragLastPosition = {}; + this.delta = { x: 0, y: 0 }; + this.position = { x: 0, y: 0 }; + this.lastPosition = { x: 0, y: 0 }; + this.init(eh); } /** * Checks to see if the vector provided is * within a dragbox if mouse is being dragged with a right or left button down * - * @param {Vector_like} pos an object containing x and y coordinates to be checked + * @param {Vector} pos an object containing x and y coordinates to be checked * @returns {Boolean} * */ @@ -6782,7 +5969,6 @@ class Mouse { /** * Initializes the mouse by appending to the DOM * - * @param {DOMEventHandler} eh */ init(eh) { eh.add('click', this._onClick); @@ -6792,15 +5978,10 @@ class Mouse { eh.add('mousemove', this._onMove); eh.add("contextmenu", this._onContextMenu); } - /** - * @private - */ _onClick = (e) => { ++this.clickCount; + this.onclick(e); } - /** - * @private - */ _onMove = (e) => { this.position.x = e.clientX; @@ -6816,10 +5997,8 @@ class Mouse { this.dragLastPosition.x = e.clientX; this.dragLastPosition.y = e.clientY; } + this.onmove(e); } - /** - * @private - */ _onDown = (e) => { switch (e.button) { @@ -6831,10 +6010,8 @@ class Mouse { this.rightbutton = true; break; } + this.ondown(e); } - /** - * @private - */ _onUp = (e) => { switch (e.button) { case 0: @@ -6844,21 +6021,26 @@ class Mouse { this.rightbutton = false; break; } + this.onup(e); } - /** - * @private - */ _onWheel = (e) => { + this.onwheel(e); } - /** - * @private - */ _onContextMenu = (e) => { e.preventDefault(); + this.oncontextmenu(e); } + + onmove(e) {} + onclick(e) {} + ondown(e) {} + onup(e) {} + onwheel(e) {} + oncontextmenu(e) {} + /** * Updates the mouse internals. - */ + */ update() { this.lastPosition = { ...this.position }; } @@ -6870,25 +6052,14 @@ class Mouse { * Realized i need to massively change this to make it work well. */ class Touch { - /** - * @type TouchEvent[] - */ - touches = [] - /** - * @type number - */ - clickCount = 0 - /** - * @param {DOMEventHandler} eh - */ constructor(eh) { + this.clickCount = 0; + this.touches = []; this.init(eh); } /** * Checks to see if the position is within the dragbox of the first two touches. * Not yet fully implemented - * - * @param {Vector_like} pos */ inDragBox(pos) { if (pos.x > this.dragLastPosition.x && pos.x < this.dragLastPosition.x + this.position.x && @@ -6907,24 +6078,23 @@ class Touch { eh.add('touchend', this._onUp); eh.add('touchmove', this._onMove); } - /** - * @private - */ _onMove = (e) => { e.preventDefault(); + this.onmove(e); } - /** - * @private - */ _onDown = (e) => { this.touches = e.touches; + this.ondown(e); } - /** - * @private - */ _onUp = (e) => { this.touches = e.touches; + this.onup(e); } + onmove(e) {} + onclick(e) {} + ondown(e) {} + onup(e) {} + onwheel(e) {} update() {} } @@ -7086,7 +6256,7 @@ class Manager { * @ignore. * This is an artifact of me debugging this. * TODO - Should implement a better soluton - */ + */ perf = { lastTimestamp: 0, total: 0 @@ -7096,12 +6266,12 @@ class Manager { * * @readonly * @type Loader - */ + */ loader = new Loader() /** * @readonly * @type EventDispatcher - */ + */ events = new EventDispatcher() /** * @private @@ -7177,7 +6347,7 @@ class Manager { */ add(object) { if (object.manager) { - Err$1.warn(`The entity with id ${object.id} has already been added to a manager.It will be ignored and not added to the manager`, object); + Err.warn(`The entity with id ${object.id} has already been added to a manager.It will be ignored and not added to the manager`, object); return } this.objects.push(object); @@ -7225,7 +6395,7 @@ class Manager { return } if (n in this._componentLists) - Utils$1.removeElement(this._componentLists[n], this._componentLists[n].indexOf(c)); + Utils.removeElement(this._componentLists[n], this._componentLists[n].indexOf(c)); } /** * Removes an entity from the manager. @@ -7237,7 +6407,7 @@ class Manager { remove(object) { let index = this.objects.indexOf(object); object.removeComponents(); - Utils$1.removeElement(this.objects, index); + Utils.removeElement(this.objects, index); this.events.trigger("remove", object); } @@ -7330,7 +6500,7 @@ class Manager { */ registerClass(obj, override = false) { let n = obj.name.toLowerCase(); - if (n in this._classes && !override) return Err$1.warn(`The class \`${obj.name}\` is already registered.Set the second parameter of \`Manager.registerClass()\` to true if you wish to override the set class`) + if (n in this._classes && !override) return Err.warn(`The class \`${obj.name}\` is already registered.Set the second parameter of \`Manager.registerClass()\` to true if you wish to override the set class`) this._classes[n] = obj; } /** @@ -7378,8 +6548,7 @@ class Manager { /** * Removes a system from the manager. * - * @param {string} n The name of the system - * @returns {void} + * @param {string} n The name of the system. * */ unregisterSystem(n) { @@ -7410,9 +6579,11 @@ class Manager { * Finds the first entity with all the components and returns it. * * @param {Array} comps An array containing the component names to be searched + * @param {Entity[]} [entities = Manager#objects] The array of entities to search in.Defaults to the manager's entity list + * * @returns {Entity} */ - getEntityByComponents(comps) { + getEntityByComponents(comps, entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < comps.length; j++) { if (!entities[i].has(comps[j])) continue @@ -7425,7 +6596,6 @@ class Manager { * * @param {Array} comps An array containing the component names to be searched * @param {Entity[]} [entities = Manager#objects] The array of entities to search in.Defaults to the manager's entity list - * @param {Entity[]} [target] * * @returns {Entity[]} */ @@ -7442,9 +6612,11 @@ class Manager { * Finds the first entity with all the tag and returns it. * * @param {Array} tags An array containing the tags to be searched + * @param {Entity[]} [entities = Manager#objects] The array of entities to search in.Defaults to the manager's entity list + * * @returns {Entity} */ - getEntityByTags(tags) { + getEntityByTags(tags, entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < tags.length; j++) { if (!entities[i].hasTag(tags[j])) continue @@ -7457,7 +6629,7 @@ class Manager { * * @param {string[]} tags An array containing the tags to be searched * @param {Entity[]} [entities = Manager#objects] The array of entities to search in. Defaults to the manager's entity list - * @param {Entity[]} target + * * @returns {Entity[]} */ getEntitiesByTags(tags, entities = this.objects, target = []) { @@ -7478,7 +6650,7 @@ class Manager { if (n) { if (n in this._classes) return new this._classes[n]() - Err$1.throw(`Class \`${n}\` is not registered in the manager thus cannot be used in cloning.Use \`Manager.registerClass\` to register it into this manager.`); + Err.throw(`Class \`${n}\` is not registered in the manager thus cannot be used in cloning.Use \`Manager.registerClass\` to register it into this manager.`); } return obj instanceof Array ? [] : {} } @@ -7486,7 +6658,6 @@ class Manager { * Deep copies an entity * * @deprecated - * @private * @returns {Entity} */ clone(obj) { @@ -7522,18 +6693,10 @@ class Manager { remove(comp) { let list = manager.getComponentList(n), index = list.indexOf(comp); - Utils$1.removeElement(list, index); + Utils.removeElement(list, index); } } } - /** - * @param {BoundingCircle | BoundingBpx } bound - * @returns Entity[] - */ - query(bound) { - ///TODO - What will happen if there is no world? ...Yes,it will crash. - return this._coreSystems.world.query(bound) - } } /** @@ -7543,7 +6706,7 @@ class Manager { */ class System{} -Utils$1.inheritSystem(System); +Utils.inheritSystem(System); /** * @@ -7574,33 +6737,29 @@ Utils$1.inheritSystem(System); * Component to hold requirements for an entity to move. * * @implements Component - */ +*/ class Movable extends Component { entity = null - /** * - * @param {number} x - * @param {number} y - * @param {number} a - * @returns {Entity} - */ constructor(x, y, a) { super(); - this.velocity = new Vector$1(x, y); + this.velocity = new Vector(x,y); this.rotation = new Angle(a); - this.acceleration = new Vector$1(); - } - toJson() { - return { - velocity: this.velocity.toJson(), - rotation: this.rotation.toJson(), - acceleration: this.acceleration.toJson() - } + this.acceleration = new Vector(); } - fromJson(obj) { - this.velocity.fromJson(obj.velocity); - this.rotation.fromJson(obj.rptatjon); - this.acceleration.fromJson(obj.acceleration); +} + +/** + * Holds transformation info of an entity + * + * @implements Component +*/ +class Transform { + entity = null + constructor(x,y,a){ + this.position = new Vector(x,y); + this.orientation = new Angle(a); } + init(){} } /** @@ -7616,14 +6775,6 @@ class Bound extends Component { */ bounds = new BoundingBox() entity = null - toJson(){ - return { - bounds:this.bounds.toJson() - } - } - fromJson(obj){ - this.bpunds.fromJson(obj.bounds); - } } /** @@ -7725,6 +6876,9 @@ class Entity { * @returns {this} */ attach(n, c) { + if(c == void 0){ + console.log(true); + } this._components[n] = c; if (this.manager) { c.init(this); @@ -7831,9 +6985,6 @@ class Entity { /** * A helper function to create a new Entity with transform,movable and bounds components. * - * @param {number} x - * @param {number} y - * @param {number} a * @returns {Entity} */ static Default(x, y, a) { @@ -7852,43 +7003,6 @@ class Entity { query(bound, target = []) { return this._global.query(bound, target) } - /** - * Todo - type serialization docs correctly - * @param {{}} obj - * @param {Map} compList - */ - fromJSON(obj, compList) { - let entity = this; - - obj.tags.forEach((a) => { - entity.addTag(a); - }); - for (var key in obj.comps) { - let c =new compList[key]().fromJSON(obj.comps[key]); - entity.attach(key, c); - } - return entity - } - /** - * @returns {{ - deg: number, - type:string - }} - */ - toJson() { - let obj = { - comps: {}, - tags: [] - }; - for (var key in this._components) { - obj.comps[key] = this._components[key].toJson(); - } - this._tags.forEach((a) => { - obj.tags.push(a); - }); - obj.type = this.CHAOS_OBJ_TYPE; - return obj - } } /** @@ -8044,16 +7158,19 @@ class AudioHandler { /** * List of playing sounds * - * @private - * @type Sfx[] + * @deprecated */ playing = [] /** * What to play after loading the audiobuffers. * - * @private + * @ignore */ toplay = {} + /** + * @ignore + */ + baseUrl = "" /** * Volume to resume playing when unmuted. * @@ -8066,17 +7183,13 @@ class AudioHandler { * * @private * @type AudioNode - */ + */ masterGainNode = null /** - * @type string - */ - baseUrl = "" - /** - * If the manager can play a sound. + * If the manager can play a sound. + * * @type boolean - */ - canPlay = false + */ constructor() { this.masterGainNode = this.ctx.createGain(); this.masterGainNode.connect(this.ctx.destination); @@ -8161,13 +7274,13 @@ class AudioHandler { this.playing.push(s); s.play(); } - + /** * Creates and returns an SFX. * * @param {string} name * @rerurns Sfx - */ + */ createSfx(name) { ///throw error if name is not in this. return new Sfx(this, this.sfx[name]) @@ -8203,7 +7316,7 @@ class AudioHandler { let id = this.playing.indexOf(sfx); if (id == -1) return sfx.disconnect(); - Utils$1.removeElement(this.playing, id); + Utils.removeElement(this.playing, id); } } @@ -8253,7 +7366,7 @@ class BehaviourManager { /** * Accumulated force from behaviours to apply to agent */ - _accumulated = new Vector$1() + _accumulated = new Vector() /** * Adds a behavior to the manager * @@ -8269,7 +7382,7 @@ class BehaviourManager { * @param {Behaviour} behaviour */ remove(behaviour) { - Utils$1.removeElement(this._behaviours, this._behaviours.indexOf(behaviour)); + Utils.removeElement(this._behaviours, this._behaviours.indexOf(behaviour)); } /** * Boots up the behavoiurs of the agent that contains it. @@ -8288,23 +7401,22 @@ class BehaviourManager { * @param {number} inv_dt */ update(inv_dt) { - let result = new Vector$1(); + let result = new Vector(); this._accumulated.set(0, 0); for (let i = 0; i < this._behaviours.length; i++) { this._behaviours[i].calc(result, inv_dt); this._accumulated.add(result); } this._agent.acceleration.add(this._accumulated); - this._agent.orientation.radian = Vector$1.toRad(this._agent.velocity); + this._agent.orientation.radian = Vector.toRad(this._agent.velocity); } /** * Removes all behaviours from a manager. */ clear() { - Utils$1.clearArr(this._behaviours); + Utils.clearArr(this._behaviours); } /** - * @ignore * Used for visually debugging items. */ draw(renderer) { @@ -8404,14 +7516,15 @@ class Agent { update(inv_dt) { this.behaviours.update(inv_dt); } + Entity /** - * @param {CanvasRenderingContext2D} ctx + * @param {Renderer} renderer */ - draw(ctx) { - this.behaviours.draw(ctx); + draw(renderer) { + this.behaviours.draw(renderer); } } -Utils$1.inheritComponent(Agent); +Utils.inheritComponent(Agent); /** * Base class for implementing customized behaviours. @@ -8472,7 +7585,7 @@ class Behaviour { draw(renderer) {} } -let tmp1$4 = new Vector$1(); +let tmp1$4 = new Vector(); /** * Creates a behaviour to evade a certain position. * @@ -8519,8 +7632,8 @@ class EvadeBehaviour extends Behaviour { } } -let tmp1$3 = new Vector$1(), - tmp2$2 = new Vector$1(); +let tmp1$3 = new Vector(), + tmp2$2 = new Vector(); /** * Creates a behaviour that is used to make an agent wander in an organic manner. @@ -8566,12 +7679,12 @@ class WanderBehaviour extends Behaviour { this._theta += rand(-this.dtheta, +this.dtheta); let forward = tmp1$3.copy(this.velocity); if (forward.equalsZero()) - Vector$1.random(forward); + Vector.random(forward); let radius = this._radius * 0.8; forward.setMagnitude(this._radius); //ctx.arc(...tmp2.copy(this.position).add(forward), radius, 0, Math.PI * 2) //ctx.stroke() - Vector$1.fromDeg(this._theta + Vector$1.toDeg(this.velocity), tmp2$2).multiply(radius); + Vector.fromDeg(this._theta + Vector.toDeg(this.velocity), tmp2$2).multiply(radius); forward.add(tmp2$2); //forward.draw(ctx,...this.position) forward.setMagnitude(this.maxSpeed); @@ -8612,33 +7725,31 @@ class Pursuit { * not complete. * * @augments Behaviour - */ -class Flock { - /** - * @type Agent[] - */ - neighbours = [] - constructor() {} - /** - * @inheritdoc - * @param {Agent} agent - * - */ - init(agent) { - +*/ +class Flock{ + constructor(){ + this.neighbours = []; } - /** - * @inheritdoc - * @param {Vector} target - * @param {number} inv_dt - * @returns Vector the first parameter - */ - calc(target,inv_dt) { - + /** + * @inheritdoc + * @param {Agent} agent + * + */ + init(){ + + } + /** + * @inheritdoc + * @param {Vector} target + * @param {number} inv_dt + * @returns Vector the first parameter + */ + calc(target){ + } } -let tmp1$2 = new Vector$1(); +let tmp1$2 = new Vector(); /** * Creates a behaviour to seek out a target and move towards it. @@ -8653,13 +7764,6 @@ class SeekBehaviour extends Behaviour { * @type number */ radius = 100 - /** - * @type Vector - */ - target = null - /** - * @param {Vector} target - */ constructor(target) { super(); this.target = target; @@ -8688,8 +7792,8 @@ class SeekBehaviour extends Behaviour { } } -let tmp1$1 = new Vector$1(), - tmp2$1 = new Vector$1(); +let tmp1$1 = new Vector(), + tmp2$1 = new Vector(); /** * This provides a seek behaviour which slows down when the agent approaches a target. @@ -8744,24 +7848,24 @@ class ArriveBehaviour extends Behaviour { } } -const tmp1 = new Vector$1(); -const tmp2 = new Vector$1(); -const tmp3 = new Vector$1(); +const tmp1 = new Vector(); +const tmp2 = new Vector(); +const tmp3 = new Vector(); /** * Creates a behaviour that follows a certain path. * * @augments Behaviour - */ +*/ class PathFollowing extends Behaviour { /** * The path taken by a pathfollowing behaviour. * * @type Path - */ + */ path = null /** * @param {Path} path - */ + */ constructor(path) { super(); this.path = path; @@ -8796,7 +7900,7 @@ class PathFollowing extends Behaviour { } /** * Removes all points on the path. - */ + */ clear() { this.path.clear(); } @@ -8812,7 +7916,7 @@ class PathFollowing extends Behaviour { * Adds a point into the path. * * @param {Vector} point - */ + */ add(point) { this.path.add(point); } @@ -8820,7 +7924,7 @@ class PathFollowing extends Behaviour { * If the agent should start at the beginning after reaching the ent of the path. * * @type boolean - */ + */ set loop(x) { this.path.loop = x; } @@ -8831,80 +7935,41 @@ class PathFollowing extends Behaviour { * Sets a new path to follow. * * @param {Path} path - */ + */ setPath(path) { this.path = path; } - draw(ctx) { - ctx.beginPath(); - circle(ctx, ...this.path.point(), 4); - fill(ctx, "blue"); - ctx.closePath(); - ctx.beginPath(); - circle(ctx, ...this.path.point(), this.path.tolerance); - stroke(ctx, "blue"); - ctx.closePath(); - this.path.draw(ctx); + draw(renderer) { + renderer.begin(); + renderer.circle(...this.path.point(), 4); + renderer.fill("blue"); + renderer.close(); + renderer.begin(); + renderer.circle(...this.path.point(), this.path.tolerance); + renderer.stroke("blue"); + renderer.close(); + this.path.draw(renderer); } } -let tmp = new Vector$1(); +let tmp = new Vector(); class Path { - /** - * @private - * type Vector[] - */ _points = [] - /** - * @private - * type number - */ _index = 0 - /** - * type number - */ speed = 20 - /** - * type number - */ - tolerance = 20 - /** - * @private - * type number - */ + tolerance= 20 _lerp_t = 0 - /** - * @private - * type number - */ _lerpdist = 0 - /** - * @private - * type number[] - */ _way = [0, 1] - /** - * @private - * type boolean - */ _finished = false - /** - * @private - * type Vector - */ - _lerpedPoint = new Vector$1() - /** - * type boolean - */ + _lerpedPoint = new Vector() loop = false - /** - * @param {Vector} point - */ add(point) { this._points.push(point); return this } + clear() { this._points.length = 0; this._way[0] = 0; @@ -8914,9 +7979,6 @@ class Path { return this } - /** - * private - */ advance() { if (this._points.length < 2) return false if (this._way[1] == this._points.length - 1 && @@ -8935,10 +7997,6 @@ class Path { this._lerp_t = 0; return true } - /** - * - * @param {number} lerpdist - */ update(lerpdist = this._lerpdist) { if (this._finished) return this._lerpedPoint let dist = tmp.copy(this._points[this._way[0]]).sub(this._points[this._way[1]]).magnitude(); @@ -8947,7 +8005,7 @@ class Path { if (!this.advance()) this._finished = true; } this._lerp_t = clamp(this._lerp_t, 0, 1); - Vector$1.lerp( + Vector.lerp( this._points[this._way[0]], this._points[this._way[1]], this._lerp_t, @@ -8961,20 +8019,17 @@ class Path { this._points[this._way[1]] ] } - point() { + point(){ return this._lerpedPoint } - get path() { + get path(){ return this._points } - /** - * @param {CanvasRenderingContext2D} ctx - */ - draw(ctx) { - ctx.beginPath(); - vertices(ctx, this._points, this.loop); - stroke(ctx, "lightgreen"); - ctx.closePath(); + draw(renderer){ + renderer.begin(); + renderer.vertices(this._points,this.loop); + renderer.stroke("lightgreen"); + renderer.close(); } } @@ -9094,51 +8149,4 @@ const Storage = { } }; -export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, Ball, BasicMaterial, Behaviour, Body, BodySprite, Bound, BoundingBox, BoundingCircle, Box, BufferGeometry, CamController, Camera, Circle, CircleGeometry, Clock, Component, Composite, Constraint, Cookies, DEVICE, DOMEventHandler, DistanceConstraint, Easing, Entity, Err$1 as Err, EvadeBehaviour, EventDispatcher, Events, Flock, Geometry, Group, Input, Interpolation, Keyboard, Line, Loader, Manager, Material, Matrix2 as Matrix, Matrix2, Mouse, Movable, NaiveBroadphase, Overlaps, Particle, ParticleSystemSprite, Path, PathFollowing, Pursuit, Tree as QuadTreeBroadphase, Rectangle, Renderer, Renderer2D, SeekBehaviour, Session, Sfx, Shape, SpringConstraint, Sprite, SpriteMaterial, StaticImageMaterial, Storage, System, Touch, Transform, Triangle, Utils$1 as Utils, Vector$1 as Vector, WanderBehaviour, WebGLRenderer, WebGPURenderer, World, arc, circle, clamp, defaultCollisionHandler, defaultPrecollisionHandler, degToRad, drawImage, exp, fill, fillText, lerp, line, map, naturalizePair, radToDeg, rand, rect, round, sq, sqrt, stroke, vertices, wrapAngle }; -/** - * @typedef Bounds - * @property {Vector_like} max - * @property {Vector_like} min - *//** - * @typedef CollisionPair - * @property {Body} a - * @property {Body} b -*/ - -/** - * @typedef Manifold - * @property {Body} bodyA - * @property {Body} bodyB - * @property {ContactManifold} contactData - * @property {number} stmp - * @property {number} impulse - * @property {boolean} persistent - * @property {Vector} ca1 - * @property {Vector} ca2 - * @property {number} restitution - * @property {number} staticFriction - * @property {number} kineticFriction - * @property {Vector} velA - * @property {Vector} velB - * @property {number} rotA - * @property {number} rotB - */ - -/** - * @typedef ContactManifold - * @property {number} lastOverlap - * @property {number} overlap=-Infinity - * @property {boolean} done=false - * @property {Vector} axis - * @property {Vector[]} verticesA - * @property {Vector[]} verticesB - * @property {Shape} vertShapeA - * @property {Shape} vertShapeB - * @property {number} contactNo - * @property {number} indexA - * @property {number} indexB - *//** - * @typedef Vector_like - * @property {number} x - * @property {number} y - */ \ No newline at end of file +export { Agent, AgentManager, AgentSprite, Angle, ArriveBehaviour, AudioHandler, Ball, BasicMaterial, Behaviour, Body, BodySprite, BoundingBox, BoundingCircle, Box, BufferGeometry, Circle, CircleGeometry, Clock, Component, Composite, Constraint, Cookies, DEVICE, DOMEventHandler, DebugMesh, DistanceConstraint, Entity, Err, EvadeBehaviour, EventDispatcher, Events, Flock, Geometry, Grid, HeightMap, ImageSprite, Input, Keyboard, Layer, Line, Loader, Manager, Material, Matrix2 as Matrix, Matrix2, Mouse, Movable, NaiveBroadphase, Overlaps, ParallaxBackground, Particle, System$1 as ParticleSystemSprite, Path, PathFollowing, Pursuit, Tree as QuadTreeBroadphase, Rectangle, Renderer, Renderer2D, SeekBehaviour, Session, Sfx, Shape, SpringConstraint, Sprite, StaticImageSprite, Storage, System, Touch, Transform, Triangle, Utils, Vector, WanderBehaviour, WebGLRenderer, WebGPURenderer, World, clamp, defaultCollisionHandler, defaultPrecollisionHandler, degToRad, exp, lerp, map, naturalizePair, radToDeg, rand, round, sq, sqrt }; diff --git a/dist/chaos.umd.js b/dist/chaos.umd.js index 9eb019a1..be95a69c 100644 --- a/dist/chaos.umd.js +++ b/dist/chaos.umd.js @@ -86,7 +86,7 @@ SOFTWARE. /** * A set of functions to streamline logging of items to the console */ - const Err$1 = {}; + const Err = {}; /** * Logs out a warning to the console. @@ -94,7 +94,7 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.warn = function(message) { + Err.warn = function(message) { console.warn(marker + message); }; @@ -104,7 +104,7 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.throw = function(message) { + Err.throw = function(message) { throw new Error(marker + message) }; @@ -114,7 +114,7 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.error = function(message) { + Err.error = function(message) { console.error(marker + message); }; @@ -124,7 +124,7 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.log = function(message) { + Err.log = function(message) { console.log(marker + message); }; /** @@ -133,10 +133,10 @@ SOFTWARE. * @memberof Err * @param {string} message */ - Err$1.warnOnce = function(message) { + Err.warnOnce = function(message) { if (mess.includes(message)) return mess.push(message); - Err$1.warn(message); + Err.warn(message); }; /** * Logs out a message,warning or error to the console according to the supplied log function. @@ -146,7 +146,7 @@ SOFTWARE. * @param {string} message * @param {Function} errfunc */ - Err$1.assert = function(test, errfunc, message) { + Err.assert = function(test, errfunc, message) { if (!test) errfunc(message); return test }; @@ -156,18 +156,17 @@ SOFTWARE. * * @module Utils */ - const Utils$1 = {}; + const Utils = {}; let tmpID = 0; /** * Appends the second array to the first. * * @memberof Utils - * @template T - * @param {T[]} arr1 - * @param {T[]} arr2 + * @param {any[]} arr1 + * @param {any[]} arr1 */ - Utils$1.appendArr = function appendArr(arr1, arr2) { + Utils.appendArr = function(arr1, arr2) { for (var i = 0; i < arr2.length; i++) { arr1.push(arr2[i]); } @@ -176,10 +175,9 @@ SOFTWARE. * Clears an array * * @memberof Utils - * @template T - * @param {T[]} arr + * @param {any[]} arr */ - Utils$1.clearArr = function(arr) { + Utils.clearArr = function(arr) { for (var i = arr.length; i > 0; i--) { arr.pop(); } @@ -188,11 +186,10 @@ SOFTWARE. * Removes a number of items at the end of an array * * @memberof Utils - * @template T - * @param {T[]} arr + * @param {any[]} arr * @param {number} number */ - Utils$1.popArr = function(arr, number) { + Utils.popArr = function(arr, number) { let length = arr.length; for (var i = length; i > length - number; i--) { arr.pop(); @@ -202,11 +199,10 @@ SOFTWARE. * Removes an element by its index from an array * * @memberof Utils - * @template T - * @param {T[]} arr + * @param {any[]} arr * @param {number} index */ - Utils$1.removeElement = function(arr, index) { + Utils.removeElement = function(arr, index) { if (index == -1) return null if (arr.length - 1 == index) return arr.pop() @@ -219,7 +215,7 @@ SOFTWARE. * * @memberof Utils */ - Utils$1.generateID = function() { + Utils.generateID = function() { return (tmpID += 1) }; @@ -227,11 +223,11 @@ SOFTWARE. * Mixes the functions required by a component into a class. * * @memberof Utils - * @param {Function} component the class/constructor function to add methods to. + * @param {Object} component the class to add methods to. * @param {boolean} [overrideInit=true] * @param {boolean} [overrideUpdate=true] */ - Utils$1.inheritComponent = function(component, overrideInit = true, overrideUpdate = true) { + Utils.inheritComponent = function(component, overrideInit = true, overrideUpdate = true) { if (component == void 0 || typeof component !== "function") return let proto = component.prototype; @@ -259,7 +255,7 @@ SOFTWARE. } if (!proto.update && overrideUpdate) { proto.update = function() { - Err$1.warnOnce("Please override the update function in the component " + proto.constructor.name); + Err.warnOnce("Please override the update function in the component " + proto.constructor.name); }; } @@ -269,18 +265,12 @@ SOFTWARE. proto.requires = function(...names) { for (var i = 0; i < names.length; i++) if (!this.entity.has(names[i])) - Err$1.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); + Err.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); }; proto.query = function(bound, target = []) { return this.entity.query(bound, target) }; - if (!proto.toJson) { - //console.log(proto); - proto.toJson = function() { - throw "Error, implement .toJson() in the class " + this.CHOAS_CLASSNAME - }; - } Object.defineProperty(proto, "CHOAS_CLASSNAME", { get: function() { return this.constructor.name.toLowerCase() @@ -296,23 +286,18 @@ SOFTWARE. configurable: false }); }; - /** - * Mixes the functions required by a system into a class. - * - * @memberof Utils - * @param {Function} system the class constructor function to add methods to. - */ - Utils$1.inheritSystem = function(system) { + + Utils.inheritSystem = function(system) { if (system == void 0 || typeof system !== "function") return let proto = system.prototype; if (!proto.init) { proto.init = function() { - Err$1.warnOnce("Please override the init method in the system " + proto.constructor.name); + Err.warnOnce("Please override the init method in the system " + proto.constructor.name); }; } if (!proto.update) { proto.update = function() { - Err$1.warnOnce("Please override the update method in the system " + proto.constructor.name); + Err.warnOnce("Please override the update method in the system " + proto.constructor.name); }; } @@ -325,7 +310,7 @@ SOFTWARE. if (!proto.remove) { proto.remove = function(component) { let index = this.objects.indexOf(component); - Utils$1.removeElement(this.objects, index); + Utils.removeElement(this.objects, index); }; } }; @@ -371,7 +356,7 @@ SOFTWARE. * A helper class. * Since there are no interfaces in JavaScript, * you might have to extend this to create a component, but there is another solution. - * Use instead Utils.inheritComponent() if you have your own hierarchy of classes. + * Use instead Utils.inheritComponent if you have your own hierarchy of classes. * In typescript,this would be an interface. * * @interface @@ -380,74 +365,16 @@ SOFTWARE. class Component { /** * @type Entity | null - */ - entity = null - - destroy() { - this.entity = null; - } - /** - * @type string - */ - get CHOAS_CLASSNAME() { - return this.constructor.name.toLowerCase() - } - /** - * @type string - */ - get CHAOS_OBJ_TYPE() { - return "component" - } - /** - - * @param {Entity} entity - */ - init(entity) { - this.entity = entity; - } - /** - * @param {number} dt - */ - update(dt) { - Err.warnOnce("Please override the update function in the component " + proto.constructor.name); - - } - /** - * @param {string} n - */ - get(n) { - return this.entity.getComponent(n); - } - /** - * @param {...string} names - */ - requires(...names) { - for (var i = 0; i < names.length; i++) - if (!this.entity.has(names[i])) - Err.throw(`The component \`${this.CHOAS_CLASSNAME}\` requires another component \`${names[i]}\` but cannot find it in the Entity with id ${this.entity.id}`); - } - /** - * @param {CircleBounding | BoxBounding} bound - * @param {Entity} [target=[]] - */ - query(bound, target = []) { - return this.entity.query(bound, target) - } - static fromJson() { - throw "Implement static method fromJson() in your component " + this.CHOAS_CLASSNAME - } - static toJson() { - throw "Implement static method toJson() in your component " + this.CHOAS_CLASSNAME - } + entity = null } - Utils$1.inheritComponent(Component); + Utils.inheritComponent(Component); /** * Destroys the component. * * @function * @name Component#destroy - */ + */ /** * Initializes a component. * @@ -516,8 +443,9 @@ SOFTWARE. /** * * Checks to see if this intersects with another bounding box - * @param {BoundingCircle | BoundingBox} bound the bound to check intersection with - * @returns boolean + * @param { BoundingBox} bound the bound to check intersection with + * + * @param { BoundingCircle | BoundingBox } bound the bound to check intersection with **/ intersects(bound) { if (bound.r) @@ -528,7 +456,7 @@ SOFTWARE. * Calculates the bounds of the body * * @param {Body} body Body to calculate max and min from - * @param {Number} padding increases the size of the bounds + * @@param {Number} padding increases the size of the bounds */ calculateBounds(body, padding = 0) { let minX = Number.MAX_SAFE_INTEGER, @@ -593,7 +521,7 @@ SOFTWARE. * Deep copies a bounding box to a new one. * * @returns BoundingBox - */ + */ clone() { return new BoundingBox(this.min.x, this.min.y, this.max.x, this.max.y) } @@ -601,7 +529,7 @@ SOFTWARE. * Deep copies another bounding box. * * @param {BoundingBox} bounds - */ + */ copy(bounds) { this.pos.x = bounds.pos.x; this.pos.y = bounds.pos.y; @@ -610,24 +538,6 @@ SOFTWARE. this.max.x = bounds.max.x; this.max.y = bounds.max.y; } - toJson() { - return { - posX: this.pos.x, - posY: this.pos.y, - minX: this.min.x, - minY: this.min.y, - maxX: this.max.x, - maxY: this.max.y, - } - } - fromJson(obj) { - this.pos.x = obj.posX; - this.pos.y = obj.posY; - this.min.x = obj.minX; - this.min.y = obj.minY; - this.max.x = obj.maxX; - this.max.y = obj.maxY; - } /** * Combines two bounds to create a new one that covers the previous two. * @@ -671,6 +581,8 @@ SOFTWARE. /** * * Checks to see if this intersects with another bounding box + * @param { BoundingBox} bound the bound to check intersection with + * * @param { BoundingCircle | BoundingBox } bound the bound to check intersection with **/ intersects(bound) { @@ -711,8 +623,6 @@ SOFTWARE. } /** * Translates this bound to the given position. - * - * @param {Vector_like} pos */ update(pos) { //let dx = pos.x - this.pos.x @@ -721,18 +631,6 @@ SOFTWARE. this.pos.x = pos.x; this.pos.y = pos.y; } - toJson(){ - return { - posX:this.pos.x, - posY:this.pos.y, - r:this.r - } - } - fromJson(obj){ - this.pos.x = obj.posX; - this.pos.y = obj.posY; - this.r = obj.r; - } } const RHI = Math.PI / 180, @@ -873,7 +771,7 @@ SOFTWARE. * @author Wayne Mwashuma * @license MIT */ - let Vector$1 = class Vector { + class Vector { /** * @param {number} x the x coordinate of the vector * @param {number} y the y coordinate of the vector @@ -882,15 +780,9 @@ SOFTWARE. this.x = x || 0; this.y = y || 0; } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "vector" } @@ -994,7 +886,7 @@ SOFTWARE. /** * Calculates the cross product of two vectors. * - * @param {Vector} v + * @param {Vector} vproduct * @returns {number} */ cross(v) { @@ -1076,7 +968,7 @@ SOFTWARE. /** * Rotates this vector by a given angle in radians. * - * @param {number} rad Angle in radians + * @param {Vector} Angle in radians * @returns {this} */ rotate(rad) { @@ -1172,10 +1064,10 @@ SOFTWARE. * Returns a vector of this reflected on a sirface perpendicular to the normal. * * @param {number} normal the unit vector perpendicular to reflection surface - * @param {Vector} [target] * @return {Vector} */ - reflect(normal, target = new Vector()) { + reflect(normal, target) { + target = target || new Vector(); return target.copy(normal).multiply(this.dot(normal) * 2).sub(this) } /** @@ -1197,14 +1089,6 @@ SOFTWARE. return this } - toJson(){ - return this - } - fromJspn(obj){ - this.x = obj.x; - this.y = obj.y; - } - [Symbol.iterator] = function*() { yield this.x; yield this.y; @@ -1261,7 +1145,7 @@ SOFTWARE. * given angle starting from the positive x axis. * * @param {number} radian angle in radians from 0 to `Math.PI * 2` - * @param {Vector} [target] Vector to store results in. + * @param {Vector} target Vector to store results in. * @returns {Vector} */ static fromRad(radian, target = new Vector()) { @@ -1272,7 +1156,7 @@ SOFTWARE. * given angle from the positive x axis * * @param {number} degree angle in radians from `0°` to `360°` - * @param {Vector} [target] Vector to store results in. + * @param {Vector} target Vector to store results in. * @returns {Vector} */ static fromDeg(degree, target) { @@ -1281,7 +1165,6 @@ SOFTWARE. /** * Generates a new unit Vector in a random direction * - * @param {Vector} [target] * @returns {Vector} */ static random(target) { @@ -1292,11 +1175,11 @@ SOFTWARE. * @param {Vector} v1 the vector to lerp from * @param {Vector} v2 the vector to lerp from * @param {number} t a value from 0 to 1 to scale the new Vector between v1 and v2 - * @param {Vector} [target] the vector to store results into + * @param {Vector} target the vector to store results into * * @returns {Vector} */ - static lerp(v1, v2, t, target = new Vector()) { + static lerp(v1, v2, t, target) { target = target || new Vector(); return target.copy(v1).set( (v2.x - v1.x) * t + v1.x, @@ -1328,13 +1211,11 @@ SOFTWARE. /** * A vector whose x and y values will remain 0. * - * @static - * @readonly * @type {Vector} */ static ZERO = Object.freeze(new Vector()) - }; + } /** * Wrapper class since JavaScript doesn't support references to numbers explicitly. @@ -1358,20 +1239,13 @@ SOFTWARE. /** * @param {number} [deg=0] Orientation in degrees. */ - //TODO - Change this to radians instead constructor(deg = 0) { this._deg = deg || 0; - this._rad = deg * Math.PI / 180 || 0; + this._rad = deg * Math.PI / 2 || 0; } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "angle" } @@ -1403,21 +1277,9 @@ SOFTWARE. copy(angle) { this.degree = angle.degree; } - - fromJSON(obj) { - this.degree = obj.deg; - } - /** - * @returns {{ - deg: number, - type:string | number - }} - */ - toJson() { - return { - deg: this._deg, - type: this.CHAOS_OBJ_TYPE - } + + static fromJSON(obj) { + return new Angle(obj._deg) } } @@ -1636,312 +1498,25 @@ SOFTWARE. } } - function wrapAngle(x) { - let a = x; - while (a > Math.PI * 2) { - a = a - Math.PI * 2; - } - while (a < 0) { - a = a + Math.PI * 2; - } - return a - } - - const Easing = { - Linear: { - In: function(x) { - return x; - }, - Out: function(x) { - return x; - }, - InOut: function(x) { - return x; - }, - }, - Quadratic: { - In: function(x) { - return x * x; - }, - Out: function(x) { - return x * (2 - x); - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return 0.5 * x * x; - } - return -0.5 * (--x * (x - 2) - 1); - }, - }, - Cubic: { - In: function(x) { - return x * x * x; - }, - Out: function(x) { - return --x * x * x + 1; - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return 0.5 * x * x * x; - } - return 0.5 * ((x -= 2) * x * x + 2); - }, - }, - Quartic: { - In: function(x) { - return x * x * x * x; - }, - Out: function(x) { - return 1 - --x * x * x * x; - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return 0.5 * x * x * x * x; - } - return -0.5 * ((x -= 2) * x * x * x - 2); - }, - }, - Quintic: { - In: function(x) { - return x * x * x * x * x; - }, - Out: function(x) { - return --x * x * x * x * x + 1; - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return 0.5 * x * x * x * x * x; - } - return 0.5 * ((x -= 2) * x * x * x * x + 2); - }, - }, - Sinusoidal: { - In: function(x) { - return 1 - Math.sin(((1.0 - x) * Math.PI) / 2); - }, - Out: function(x) { - return Math.sin((x * Math.PI) / 2); - }, - InOut: function(x) { - return 0.5 * (1 - Math.sin(Math.PI * (0.5 - x))); - }, - }, - Exponential: { - In: function(x) { - return x === 0 ? 0 : Math.pow(1024, x - 1); - }, - Out: function(x) { - return x === 1 ? 1 : 1 - Math.pow(2, -10 * x); - }, - InOut: function(x) { - if (x === 0) { - return 0; - } - if (x === 1) { - return 1; - } - if ((x *= 2) < 1) { - return 0.5 * Math.pow(1024, x - 1); - } - return 0.5 * (-Math.pow(2, -10 * (x - 1)) + 2); - }, - }, - Circular: { - In: function(x) { - return 1 - Math.sqrt(1 - x * x); - }, - Out: function(x) { - return Math.sqrt(1 - --x * x); - }, - InOut: function(x) { - if ((x *= 2) < 1) { - return -0.5 * (Math.sqrt(1 - x * x) - 1); - } - return 0.5 * (Math.sqrt(1 - (x -= 2) * x) + 1); - }, - }, - Elastic: { - In: function(x) { - if (x === 0) { - return 0; - } - if (x === 1) { - return 1; - } - return -Math.pow(2, 10 * (x - 1)) * Math.sin((x - 1.1) * 5 * Math.PI); - }, - Out: function(x) { - if (x === 0) { - return 0; - } - if (x === 1) { - return 1; - } - return Math.pow(2, -10 * x) * Math.sin((x - 0.1) * 5 * Math.PI) + 1; - }, - InOut: function(x) { - if (x === 0) { - return 0; - } - if (x === 1) { - return 1; - } - x *= 2; - if (x < 1) { - return -0.5 * Math.pow(2, 10 * (x - 1)) * Math.sin((x - 1.1) * 5 * Math.PI); - } - return 0.5 * Math.pow(2, -10 * (x - 1)) * Math.sin((x - 1.1) * 5 * Math.PI) + 1; - }, - }, - Back: { - In: function(x) { - var s = 1.70158; - return x === 1 ? 1 : x * x * ((s + 1) * x - s); - }, - Out: function(x) { - var s = 1.70158; - return x === 0 ? 0 : --x * x * ((s + 1) * x + s) + 1; - }, - InOut: function(x) { - var s = 1.70158 * 1.525; - if ((x *= 2) < 1) { - return 0.5 * (x * x * ((s + 1) * x - s)); - } - return 0.5 * ((x -= 2) * x * ((s + 1) * x + s) + 2); - }, - }, - Bounce: { - In: function(x) { - return 1 - Easing.Bounce.Out(1 - x); - }, - Out: function(x) { - if (x < 1 / 2.75) { - return 7.5625 * x * x; - } - else if (x < 2 / 2.75) { - return 7.5625 * (x -= 1.5 / 2.75) * x + 0.75; - } - else if (x < 2.5 / 2.75) { - return 7.5625 * (x -= 2.25 / 2.75) * x + 0.9375; - } - else { - return 7.5625 * (x -= 2.625 / 2.75) * x + 0.984375; - } - }, - InOut: function(x) { - if (x < 0.5) { - return Easing.Bounce.In(x * 2) * 0.5; - } - return Easing.Bounce.Out(x * 2 - 1) * 0.5 + 0.5; - }, - }, - generatePow: function(power) { - if (power === void 0) { power = 4; } - power = power < Number.EPSILON ? Number.EPSILON : power; - power = power > 10000 ? 10000 : power; - return { - In: function(x) { - return Math.pow(x, power); - }, - Out: function(x) { - return 1 - Math.pow((1 - x), power); - }, - InOut: function(x) { - if (x < 0.5) { - return Math.pow((x * 2), power) / 2; - } - return (1 - Math.pow((2 - x * 2), power)) / 2 + 0.5; - }, - }; - }, - }; - - const Interpolation = { - Linear: function(p0, p1, t) { - return (p1 - p0) * t + p0 - }, - Bernstein: function(n, i) { - const fc = Interpolation.Utils.Factorial; - - return fc(n) / fc(i) / fc(n - i) - }, - Factorial: (function() { - const a = [1]; - - return function(n) { - let s = 1; - - if (a[n]) { - return a[n] - } - - for (let i = n; i > 1; i--) { - s *= i; - } - - a[n] = s; - return s - } - })(), - - CatmullRom: function(p0, p1, p2, p3, t) { - const v0 = (p2 - p0) * 0.5; - const v1 = (p3 - p1) * 0.5; - const t2 = t * t; - const t3 = t * t2; - - return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1 - }, - }; - class Geometry { - /** - * @type Vector[] - */ - vertices = null - /** - * @type Vector[] - */ - normals = null - /** - * @type Vector[] - */ - _dynNormals = null - /** - * @param {Vector[]} vertices - */ constructor(vertices) { this.vertices = vertices; this.normals = this.calcFaceNormals(); - this._dynNormals = this.normals.map(e => e.clone()); + this._dynNormals = this.normals.map(e=>e.clone()); } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "geometry" } - /** - * @param {number} rad - * @param {Vector[]} target - */ - getNormals(rad, target) { + getNormals(rad,target) { target = target || []; for (var i = 0; i < this.normals.length; i++) { target.push(this._dynNormals[i].copy(this.normals[i]).rotate(rad)); } return target } - /** - * @private - * @returns Vector[] - */ calcFaceNormals() { const axes = [], { vertices } = this; @@ -1960,13 +1535,7 @@ SOFTWARE. } return axes } - /** - * @param {number} n - * @param {Vector[]} vertices - * @param {Vector} pos - * @patam {number} rad - */ - transform(vertices, pos, rad, n) { + transform(vertices,pos, rad, n) { for (let i = 0; i < this.vertices.length; i++) { let vertex = vertices[i]; vertex.copy(this.vertices[i]); @@ -1975,17 +1544,6 @@ SOFTWARE. vertex.add(pos); } } - toJson(){ - let obj = { - vertices:this.vertices.map((v)=>v.toJson()) - }; - return obj - } - fromJson(obj){ - this.vertices = obj.vertices.map(v=>new Vector().fromJson(v)); - this.normals = this.calcFaceNormals(); - this._dynNormals = this.normals.map(e => e.clone()); - } } /**@enum {number}*/ @@ -2028,7 +1586,7 @@ SOFTWARE. type:BodyType.DYNAMIC }; - let tmp1$c = new Vector$1(); + let tmp1$d = new Vector(); /** * This class makes a body tangible @@ -2058,13 +1616,13 @@ SOFTWARE. * The vertices describing the shape. * * @type Vector[] - */ + */ vertices = null /** * Keeps the original normals and vertices of this shape * * @type Geometry - */ + */ geometry = null /** @@ -2072,39 +1630,34 @@ SOFTWARE. * @param {Vector} [offset=vector] offset position relative to parent body * @param {number} [offsetAngle=0] offset angle relative to parent body. */ - constructor(vertices, offset = new Vector$1(), offsetAngle = 0) { + constructor(vertices, offset = new Vector(), offsetAngle = 0) { this.offPosition = offset; this.offAngle = offsetAngle * Math.PI / 180; this.vertices = vertices.map(v => v.clone()); this.geometry = new Geometry(vertices); } - /** - * @type string - */ + get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "shape" } /** * The area occupied by a shape. * @type number - */ - get area() { + */ + get area(){ return 0 } /** * Returns the normals of the faces when rotated. * - * @param {Shape} shape - * @param {Vector[]} [target=[]] An array where results are stored. - * @returns {Vector[]} + * @param {} body + * @param {} [target=[]] An array where results are stored. + * @returns {Array} */ - getNormals(shape, target) { + getNormals(body, target) { return this.geometry.getNormals(this.angle, target) } /** @@ -2116,17 +1669,17 @@ SOFTWARE. */ update(position, angle, scale) { this.angle = this.offAngle + angle; - this.geometry.transform(this.vertices, tmp1$c.copy(position).add(this.offPosition), this.angle, 1 , position); + this.geometry.transform(this.vertices, tmp1$d.copy(position).add(this.offPosition), this.angle, 1 , position); } /** * Returns the world coordinates of the vertices. * * @param {Vector} axis - * @param {Vector[]} target + * @param {Vector[]}} target * @returns {Vector[]} */ - getVertices(axis, target) { + getVertices(axis,target) { return this.vertices } @@ -2139,45 +1692,21 @@ SOFTWARE. static calcInertia() { throw new Error("Implement in the children classes") } - toJson(){ - ({ - type:this.CHAOS_OBJ_TYPE, - geometry:this.geometry.toJson(), - shapwType:this.type, - offset:this.offPosition.toJson(), - offAngle:this.offAngle - }); - } - fromJson(obj){ - this.offAngle = obj.offAngle; - this.offPosition = obj.offset; - this.geometry.fromJson(obj.geometry); - this.vertices = this.geometry.vertices.map(v=>v.clone()); - } static CIRCLE = 0 static POLYGON = 1 } class Line extends Shape { - /** - * @type number - */ - length = 0 - /** - * @param {number} length - * @param {Vector} offset - * @param {number} pffsetAngle - */ constructor(length,offset,offsetAngle) { - let start = new Vector$1(1).multiply(length / 2), - end = new Vector$1(1).multiply(-length / 2); + let start = new Vector(1).multiply(length / 2), + end = new Vector(1).multiply(-length / 2); super([start, end],offset,offsetAngle); this.length = length; } } - let _vec1 = new Vector$1(); - let _vec2 = new Vector$1(); + let _vec1 = new Vector(); + let _vec2 = new Vector(); /** * A circular shape. @@ -2197,7 +1726,7 @@ SOFTWARE. //the first vertex is position super([], offset, offsetAngle); - this.vertices = [new Vector$1(), new Vector$1(), new Vector$1()]; + this.vertices = [new Vector(), new Vector(), new Vector()]; this.radius = radius; this.type = Shape.CIRCLE; } @@ -2216,11 +1745,11 @@ SOFTWARE. * @inheritdoc * * @param {Vector} axis - * @param {Vector[]} out + * @param {Vector[]}} target * @returns {Vector[]} */ - getVertices(axis, out) { - let target = out || []; + getVertices(axis, target) { + target = target || []; let v1 = _vec1.copy(axis).multiply(-this.radius).add(this.position); let v2 = _vec2.copy(axis).multiply(this.radius).add(this.position); target[0] = v1.clone(); @@ -2261,23 +1790,6 @@ SOFTWARE. get area() { return Math.PI * this.radius * this.radius } - toJson() { - let obj = { - radius: this.radius, - offset: this.offPosition, - offAngle: this.offAngle, - shapeType: this.type, - type: this.CHAOS_OBJ_TYPE - }; - return obj - } - fromJson(obj) { - return new Circle( - obj.radius, - new Vector$1().fromJson(obj.offset), - obj.offAngle - ) - } } class Rectangle extends Shape { @@ -2296,10 +1808,10 @@ SOFTWARE. * @param {number} offsetAngle Angular offset from the body center. */ constructor(width, height, offset, offsetAngle) { - let v1 = new Vector$1(-width / 2, -height / 2); - let v2 = new Vector$1(-width / 2, height / 2); - let v3 = new Vector$1(width / 2, height / 2); - let v4 = new Vector$1(width / 2, -height / 2); + let v1 = new Vector(-width / 2, -height / 2); + let v2 = new Vector(-width / 2, height / 2); + let v3 = new Vector(width / 2, height / 2); + let v4 = new Vector(width / 2, -height / 2); super([v1, v2, v3, v4], offset, offsetAngle); this.height = height; this.width = width; @@ -2320,8 +1832,8 @@ SOFTWARE. } - let tmp1$b = new Vector$1(), - tmp2$9 = new Vector$1(); + let tmp1$c = new Vector(), + tmp2$9 = new Vector(); /** * A triangular shape. @@ -2338,18 +1850,18 @@ SOFTWARE. * */ constructor(length1, length2, angle, offset, offsetAngle) { - let l1 = tmp1$b.set(1, 0).multiply(length1); - let l2 = Vector$1.fromDeg(angle, tmp2$9).multiply(length2); + let l1 = tmp1$c.set(1, 0).multiply(length1); + let l2 = Vector.fromDeg(angle, tmp2$9).multiply(length2); super([ - new Vector$1( + new Vector( -l1.x / 2, -l2.y / 2 ), - new Vector$1( + new Vector( l1.x / 2, -l2.y / 2 ), - new Vector$1( + new Vector( l2.x / 2, l2.y / 2 ) @@ -2368,28 +1880,28 @@ SOFTWARE. * * @type number */ - id = Utils$1.generateID() + id = Utils.generateID() /** * World space coordinates of a body * * @private * @type Vector */ - _position = new Vector$1() + _position = new Vector() /** * velocity of a body.Speed in pixels per second. * * @private * @type Vector */ - _velocity = new Vector$1() + _velocity = new Vector() /** * acceleration of a body in pixels per second squared. * * @private * @type Vector */ - _acceleration = new Vector$1() + _acceleration = new Vector() /** * World space orientation of a body * @@ -2445,7 +1957,7 @@ SOFTWARE. * * @type Vector */ - lastPosition = new Vector$1() + lastPosition = new Vector() /** * Inverse mass of the body. * @@ -2601,15 +2113,9 @@ SOFTWARE. get physicsType() { return ObjType.BODY } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "body" } @@ -2741,7 +2247,7 @@ SOFTWARE. * @returns {number} */ setAnchor(v) { - this.anchors.push(new Vector$1(v.x, v.y).rotate(this.orientation.radian).add(this.position)); + this.anchors.push(new Vector(v.x, v.y).rotate(this.orientation.radian).add(this.position)); return this._localanchors.push(v) - 1 } /** @@ -2761,7 +2267,7 @@ SOFTWARE. * @param {Vector} [target=Vector] Vector to store results in. * @returns {Vector} */ - getLocalAnchor(index, target = new Vector$1()) { + getLocalAnchor(index, target = new Vector()) { return target.copy(this._localanchors[index]).rotate(this.orientation.radian) } /** @@ -2771,7 +2277,7 @@ SOFTWARE. * @param {Vector} force The force to be applied. * @param {Vector} [arm=Vector] The collision arm. */ - applyForce(force, arm = Vector$1.ZERO) { + applyForce(force, arm = Vector.ZERO) { this.acceleration.add(force.multiply(this.inv_mass)); this.rotation.degree += arm.cross(force) * this.inv_inertia; } @@ -2812,68 +2318,13 @@ SOFTWARE. this.shapes[i].update(this.position, this._orientation.radian); } for (var i = 0; i < this.anchors.length; i++) { - this.anchors[i].copy(this._localanchors[i]).rotate(this.orientation.radian); //.add(this.position) + this.anchors[i].copy(this._localanchors[i]).rotate(this.orientation.radian);//.add(this.position) } if (this.autoUpdateBound) this.bounds.calculateBounds(this, this.boundPadding); this.bounds.update(this.position); //this.angle = this.angle > 360 ? this.angle - 360 : this.angle < 0 ? 360 + this.angle : this.angle } - toJson() { - let obj = { - id:this.id, - position: this.position.toJson(), - velocity: this.velocity.toJson(), - acceleration: this.acceleration.toJson(), - orientation: this.orientation.toJson(), - rotation: this.rotation.toJson(), - shapes: [], - anchors:[], - collisionResponse: this.collisionResponse, - allowSleep: this.allowSleep, - type: this.CHAOS_OBJ_TYPE, - phyType: this.type, - mass: this.mass, - inertia:this.inertia, - autoUpdateBound:this.autoUpdateBound, - boundPadding:this.boundPadding, - aabbDetectionOnly:this.aabbDetectionOnly, - mask:this.mask - }; - this.anchors.forEach((a)=>{ - obj.anchors.push(a); - }); - this.shapes.forEach((a) => { - obj.shapes.push(a.toJson()); - }); - return obj - } - //TODO - Add way to add shapes to body - fromJson(obj){ - let shapes = []; - obj.shapes.forEach((shape)=>{ - shapes.push(Shape.fromJson(shape)); - }); - let body = this; - body.shapes = shapes; - body.acceleration = obj.acceleration; - body.velocity = obj.velocity; - body.position = pbj.position; - body.rotation = obj.rotation; - body.orientation = obj.orientation; - body.mass = obj.mass; - body.inertia = obj.inertia; - body.type = obj.phyType; - body.allowSleep = obj.allowSleep; - body.aabbDetectionOnly = obj.aabbDetectionOnly; - body.collisionResponse = obj.collisionResponse; - body.autoUpdateBound = obj.autoUpdateBound; - body.id = obj.id; - body.mask = obj.mask; - obj.anchors.forEach((v)=>{ - body.setAnchor(new Vector$1().fromJson(v)); - }); - } /** *Body type that dictates a body cannot move nor respond to collisions. * @@ -2892,10 +2343,27 @@ SOFTWARE. * * @static * @type number - */ + */ static DYNAMIC = ObjType.DYNAMIC } - Utils$1.inheritComponent(Body, false, false); + Utils.inheritComponent(Body, false, false); + + class HeightMap extends Body { + constructor(step, heights) { + let l = [], + j = []; + for (let i = 0; i < heights.length; i++) { + l.push(new Vector(step * i, heights[i])); + } + for (let i = 1; i < l.length; i++) { + let line = new Line(l[i - 1], l[i]); + j.push(line); + } + super(new Vector(), ...j); + this.mass = 0; + this.mask.layer = 0; + } + } /** * A body with a circle shape on it. @@ -3018,7 +2486,7 @@ SOFTWARE. * @type Vector */ get acceleration() { - let acceleration = new Vector$1(); + let acceleration = new Vector(); for (var i = 0; i < this.bodies.length; i++) { acceleration.copy(this.bodies[i].acceleration); } @@ -3035,7 +2503,7 @@ SOFTWARE. * @type Vector */ get velocity() { - let velocity = new Vector$1(); + let velocity = new Vector(); for (var i = 0; i < this.bodies.length; i++) { velocity.add(this.bodies[i].velocity); @@ -3047,28 +2515,27 @@ SOFTWARE. this.bodies[i].velocity.copy(x); } } - /** - * Orientation of a body in degrees. - * - * @type number - */ - get angle() { - let angle = 0; + /** + * Orientation of a body in degrees. + * + * @type number + */ + set angle(angle) { for (var i = 0; i < this.bodies.length; i++) { - angle += this.bodies[i].angle; + this.bodies[i].angle = x; } } - set angle(angle) { + get angle() { + let angle = 0; for (var i = 0; i < this.bodies.length; i++) { - this.bodies[i].angle = x; + angle += this.bodies[i].angle; } } - - /** - * Mass of a body. - * - * @type number - */ + /** + * Mass of a body. + * + * @type number + */ set mass(x) { for (var i = 0; i < this.bodies.length; i++) { this.bodies[i].mass = x; @@ -3081,11 +2548,11 @@ SOFTWARE. } return mass } - /** - * Density of a body. - * - * @type number - */ + /** + * Density of a body. + * + * @type number + */ set density(x) { for (var i = 0; i < this.bodies.length; i++) { this.bodies[i].density = x; @@ -3104,7 +2571,7 @@ SOFTWARE. * @type Vector */ get position() { - let position = new Vector$1(); + let position = new Vector(); for (var i = 0; i < this.shapes.length; i++) { position.add(this.bodies[i].position); } @@ -3126,24 +2593,17 @@ SOFTWARE. this.bodies[i].orientation.copy(r); } } - get orientation() { - let ang = 0; - for (var i = 0; i < this.bodies.length; i++) { - ang += this.bodies[i].orientation; - } - return ang / this.bodies.length - } - /** - * Angular velocity of a body. - * - * @type number - */ + /** + * Angular velocity of a body. + * + * @type number + */ get angularVelocity() { let ang = 0; for (var i = 0; i < this.bodies.length; i++) { ang += this.bodies[i].angularVelocity; } - return ang / this.bodies.length + return ang } set angularVelocity(x) { for (var i = 0; i < this.bodies.length; i++) { @@ -3151,7 +2611,7 @@ SOFTWARE. } } } - Utils$1.inheritComponent(Composite); + Utils.inheritComponent(Composite); /** * Base class for constructing different types of constraints. @@ -3170,8 +2630,8 @@ SOFTWARE. constructor(body1, body2, localA, localB) { this.body1 = body1; this.body2 = body2; - this.localA = localA || new Vector$1(); - this.localB = localB || new Vector$1(); + this.localA = localA || new Vector(); + this.localB = localB || new Vector(); this.stiffness = 50; this.dampening = 0.03; } @@ -3184,15 +2644,9 @@ SOFTWARE. get physicsType() { return ObjType.CONSTRAINT } - /** - * @type string - */ get CHOAS_CLASSNAME() { return this.constructor.name.toLowerCase() } - /** - * @type string - */ get CHAOS_OBJ_TYPE() { return "constraint" } @@ -3204,7 +2658,7 @@ SOFTWARE. * @param {Body} body2 * @param {number} dt */ - behavior(body1, body2, dt) { + behavior(body1, body2,dt) { body2.position.copy(body1.position); } /** @@ -3213,40 +2667,15 @@ SOFTWARE. * @param {number} dt */ update(dt) { - this.behavior(this.body1, this.body2, dt); - } - toJson() { - return { - body1: this.body1.id, - body2: this.body2.id, - localA: this.localA.toJson(), - localA: this.localB.toJson(), - stiffness: this.stiffness, - dampening: this.dampening, - type:this.CHAOS_OBJ_TYPE - } - } - fromJson(obj, world) { - let bod1 = world.getById(obj.body1); - let bod2 = world.getById(obj.body2); - - let constraint = new Constraint( - bod1, - bod2, - new Vector$1().fromJson(obj.localA), - new Vector$1().fromJson(obj.localB) - ); - constraint.stiffness = obj.stiffness; - constraint.dampening = obj.dampening; - return constraint + this.behavior(this.body1, this.body2,dt); } } - let tmp1$a = new Vector$1(), - tmp2$8 = new Vector$1(), - tmp3$5 = new Vector$1(), - tmp4$4 = new Vector$1(), - tmp5$3 = new Vector$1(); + let tmp1$b = new Vector(), + tmp2$8 = new Vector(), + tmp3$5 = new Vector(), + tmp4$4 = new Vector(), + tmp5$3 = new Vector(); /** * This constraint is stronger than a spring in the sense that it will not oscilate as such as a spring constraint. @@ -3261,7 +2690,7 @@ SOFTWARE. constructor(body1, body2, localA, localB) { super(body1, body2,localA,localB); this.fixed = !body1.mass || !body2.mass; - this.dampening = 1; + this.dampen = 1; this.maxDistance = 1; this.stiffness = 1; } @@ -3273,7 +2702,7 @@ SOFTWARE. * @param {number} dt */ behavior(body1, body2,dt) { - let arm1 = tmp1$a.copy(this.localA), + let arm1 = tmp1$b.copy(this.localA), arm2 = tmp2$8.copy(this.localB), pos1 = tmp3$5.copy(body1.position).add(arm1), pos2 = tmp4$4.copy(body2.position).add(arm2), @@ -3284,7 +2713,7 @@ SOFTWARE. return } let difference = (magnitude - this.maxDistance) / magnitude, - force = dist.multiply(difference * this.stiffness * this.dampening), + force = dist.multiply(difference * this.stiffness * this.dampen), massTotal = body1.inv_mass + body2.inv_mass; body1.inv_inertia + body2.inv_inertia; tmp4$4.copy(force); @@ -3301,12 +2730,12 @@ SOFTWARE. } } - let tmp1$9 = new Vector$1(), - tmp2$7 = new Vector$1(), - tmp3$4 = new Vector$1(), - tmp4$3 = new Vector$1(), - tmp5$2 = new Vector$1(), - zero = new Vector$1(); + let tmp1$a = new Vector(), + tmp2$7 = new Vector(), + tmp3$4 = new Vector(), + tmp4$3 = new Vector(), + tmp5$2 = new Vector(), + zero = new Vector(); /** * A constraint that acts like a spring between two bodies */ @@ -3319,10 +2748,10 @@ SOFTWARE. */ constructor(body1, body2, localA, localB) { super(body1, body2); - this.localA = new Vector$1().copy(localA || zero); - this.localB = new Vector$1().copy(localB || zero); + this.localA = new Vector().copy(localA || zero); + this.localB = new Vector().copy(localB || zero); this.fixed = !body1.mass || !body2.mass; - this.dampening = 1; + this.dampen = 1; this.maxDistance = 100; this.stiffness = 1; } @@ -3334,7 +2763,7 @@ SOFTWARE. * @param {number} dt */ behavior(body1, body2, dt) { - let arm1 = tmp1$9.copy(this.localA), + let arm1 = tmp1$a.copy(this.localA), arm2 = tmp2$7.copy(this.localB), pos1 = tmp3$4.copy(body1.position).add(arm1), pos2 = tmp4$3.copy(body2.position).add(arm2), @@ -3345,7 +2774,7 @@ SOFTWARE. return } let difference = (magnitude - this.maxDistance) / magnitude, - force = dist.multiply(difference * this.stiffness * this.dampeninging), + force = dist.multiply(difference * this.stiffness * this.dampen), massTotal = body1.inv_mass + body2.inv_mass, inertiaTotal = body1.inv_inertia + body2.inv_inertia; force.divide(massTotal + inertiaTotal); @@ -3357,9 +2786,9 @@ SOFTWARE. } } - let position = new Vector$1(); - let acceleration = new Vector$1(); - let velocity = new Vector$1(); + let position = new Vector(); + let acceleration = new Vector(); + let velocity = new Vector(); /** * Verlet intergration. @@ -3382,11 +2811,11 @@ SOFTWARE. } } - let tmp1$8 = new Vector$1(), - tmp2$6 = new Vector$1(), - tmp3$3 = new Vector$1(), - tmp4$2 = new Vector$1(), - tmp5$1 = new Vector$1(); + let tmp1$9 = new Vector(), + tmp2$6 = new Vector(), + tmp3$3 = new Vector(), + tmp4$2 = new Vector(), + tmp5$1 = new Vector(); /** * Solves for impulse along collision tangent for a given body pair. @@ -3397,7 +2826,7 @@ SOFTWARE. let { bodyA: a, bodyB: b, ca1, ca2, restitution, impulse } = manifold; let { axis } = manifold.contactData; if (impulse <= 0) return - let a$va = tmp1$8.set(ca1.y * -a.rotation._rad, ca1.x * a.rotation._rad); + let a$va = tmp1$9.set(ca1.y * -a.rotation._rad, ca1.x * a.rotation._rad); let a$vb = tmp2$6.set(ca2.y * -b.rotation._rad, ca2.x * b.rotation._rad); let va = tmp3$3.copy(a.velocity).add(a$va); let vb = tmp4$2.copy(b.velocity).add(a$vb); @@ -3462,8 +2891,8 @@ SOFTWARE. } }; - const tmp1$7 = new Vector$1(), - tmp2$5 = new Vector$1(); + const tmp1$8 = new Vector(), + tmp2$5 = new Vector(); let dampen = Settings.posDampen; /** @@ -3477,18 +2906,18 @@ SOFTWARE. const dampened = overlap * dampen; const a = dampened / (bodyA.inv_mass + bodyB.inv_mass + sq(ca1.cross(axis)) * bodyA.inv_inertia + sq(ca2.cross(axis)) * bodyB.inv_inertia); let jp = tmp2$5.copy(axis).multiply(a); - bodyA.velocity.add(tmp1$7.copy(jp).multiply(bodyA.inv_mass * inv_dt)); - bodyB.velocity.add(tmp1$7.copy(jp).multiply(-bodyB.inv_mass * inv_dt)); + bodyA.velocity.add(tmp1$8.copy(jp).multiply(bodyA.inv_mass * inv_dt)); + bodyB.velocity.add(tmp1$8.copy(jp).multiply(-bodyB.inv_mass * inv_dt)); bodyA.rotation.radian += ca1.cross(jp) * bodyA.inv_inertia * inv_dt; bodyB.rotation.radian += ca2.cross(jp) * -bodyB.inv_inertia * inv_dt; manifold.contactData.lastOverlap = overlap; } }; - let tmp1$6 = new Vector$1(), - tmp2$4 = new Vector$1(), - tmp3$2 = new Vector$1(), - tmp4$1 = new Vector$1(); + let tmp1$7 = new Vector(), + tmp2$4 = new Vector(), + tmp3$2 = new Vector(), + tmp4$1 = new Vector(); /** * Solves for the collision normal impulse of a given body pair. @@ -3497,7 +2926,7 @@ SOFTWARE. solve(manifold) { let { bodyA, bodyB, ca1, ca2, restitution } = manifold; let { axis } = manifold.contactData; - let a$va = tmp1$6.set(ca1.y * -bodyA.rotation.radian, ca1.x * bodyA.rotation.radian); + let a$va = tmp1$7.set(ca1.y * -bodyA.rotation.radian, ca1.x * bodyA.rotation.radian); let a$vb = tmp2$4.set(ca2.y * -bodyB.rotation.radian, ca2.x * bodyB.rotation.radian); let va = tmp3$2.copy(bodyA.velocity).add(a$va); let vb = tmp4$1.copy(bodyB.velocity).add(a$vb); @@ -3530,11 +2959,11 @@ SOFTWARE. }; const _arr = [], - tmp1$5 = { + tmp1$6 = { overlap: 0, verticesA: null, verticesB: null, - axis: new Vector$1(), + axis: new Vector(), vertex: null, shape: null }, @@ -3548,9 +2977,9 @@ SOFTWARE. max: 0, indexN: 0 }, - tmp4 = new Vector$1(), - tmp5 = new Vector$1(), - tmp6 = new Vector$1(); + tmp4 = new Vector(), + tmp5 = new Vector(), + tmp6 = new Vector(); /** * Used for narrowphase collision detection and contact info generation. @@ -3627,7 +3056,7 @@ SOFTWARE. shapesCollided(shape1, shape2, target) { let arr = _arr, boundary; - Utils$1.clearArr(arr); + Utils.clearArr(arr); shape1.getNormals(shape2, arr); boundary = arr.length; shape2.getNormals(shape1, arr); @@ -3642,7 +3071,7 @@ SOFTWARE. * @param {number} iu */ projectShapesToAxes(shapeA, shapeB, axes, manifold, iu) { - let temp = tmp1$5; + let temp = tmp1$6; temp.vertex = null; temp.body = null; temp.overlap = Infinity; @@ -3744,7 +3173,7 @@ SOFTWARE. } if (point < min) { min = point; - Utils$1.clearArr(nearVertices); + Utils.clearArr(nearVertices); nearVertices.push(vertices[i]); i = -1; } @@ -3874,16 +3303,13 @@ SOFTWARE. * @type Body[] */ bodies = null - /** - * @param {World} world - */ constructor(world) { super(); this.bodies = world.objects; } /** * @inheritdoc - * @param {Bounds} bound Region to check in. + * @param {Bounds} bounds Region to check in. * @param {Body[]} target Empty array to store results. * @returns {Body[]} */ @@ -3898,7 +3324,7 @@ SOFTWARE. } /** * @inheritdoc - * @param {CollisionPair[]} target Empty array to store results. + * @param {array} target Empty array to store results. * @returns {CollisionPair[]} */ getCollisionPairs(target) { @@ -3926,54 +3352,30 @@ SOFTWARE. } - class Client { + let Client$1 = class Client { constructor(body) { this.body = body; this.bounds = body.bounds.clone(); this.node = null; } - } + }; class Node { - /**@type Node[]*/ - children = [] - /**@type Body[]*/ - objects = [] - /**@type Node*/ - root = null - /**@type Node*/ - parent = null - /**@type boolean*/ - hasObjects = false - /**@type number*/ - index = -1 - /**@type Tree*/ - global = null - /**@type Vector_like*/ - dims = null - /**@type number*/ - depth = -1 - /**@type {{ - max:Vector_like, - min:Vector_like - }}*/ - bounds = null - /** - * @param {{ - max:Vector_like, - min:Vector_like - }} bounds - */ constructor(bounds) { + this.children = []; + this.objects = []; + this.parent = null; + this.global = null; + this.index = -1; + this.root = null; this.bounds = bounds; + this.hasObjects = false; + this.depth = -1; this.dims = { x: this.bounds.max.x - this.bounds.min.x, y: this.bounds.max.y - this.bounds.min.y }; } - /** - * @param {Node} node - */ add(node) { node.index = this.children.length; this.children.push(node); @@ -3990,9 +3392,6 @@ SOFTWARE. node.global = null; } } - /** - * @param {number} depth - */ split(depth = 1) { let w = this.dims.x / 2; let h = this.dims.y / 2; @@ -4043,9 +3442,6 @@ SOFTWARE. if (depth <= 1) return this.children.forEach(e => e.split(depth - 1)); } - /** - * @param {CanvasRenderingContext2D} ctx - */ draw(ctx) { ctx.beginPath(); ctx.strokeStyle = "blue"; @@ -4053,15 +3449,9 @@ SOFTWARE. ctx.stroke(); ctx.closePath(); } - /** - * @return boolean - */ isLeafNode() { return this.children.length == 0 } - /** - * @return boolean - */ childrenHaveObj() { return this.children.length > 0 || ( this.children[0].hasObjects || @@ -4070,19 +3460,11 @@ SOFTWARE. this.children[3].hasObjects ) } - /** - * @param {Bounds} bounds - * @return boolean - */ intersects(bounds) { if (bounds.r) return Overlaps.AABBvsSphere(this.bounds, bounds) return Overlaps.AABBColliding(this.bounds, bounds) } - /** - * @param {Bounds} bounds - * @return boolean - */ contains(bounds) { return ( bounds.max.x < this.bounds.max.x && @@ -4091,13 +3473,7 @@ SOFTWARE. bounds.min.y > this.bounds.min.y ) } - /** - * @inheritdoc - * @param {Bounds} bounds - * @param {Body[]} [target] - * @returns boolean - */ - query(bounds, target = []) { + query(bounds, target) { if (!this.intersects(bounds)) return target if (!this.isLeafNode()) { @@ -4112,10 +3488,6 @@ SOFTWARE. } return target } - /** - * @param {Body} obj - * @returns boolean - */ insertObject(obj) { if (!this.contains(obj.bounds)) return false @@ -4136,10 +3508,6 @@ SOFTWARE. } return false } - /** - * @param {Vector_like} position - * @returns boolean - */ isInNode(position) { if ( position.x > this.bounds.min.x && @@ -4153,24 +3521,17 @@ SOFTWARE. isRootNode() { return !this.parent } - /** - * @param {Body} obj - */ updateObject(obj) { this.removeObject(obj); this.global.insert(obj); return true } - /** - * @param {Body} obj - * @returns boolean - */ removeObject(obj) { if (!this.isInNode(obj.lastPosition)) return false let t = this.objects.indexOf(obj); if (t !== -1) { - Utils$1.removeElement(this.objects, t); + Utils.removeElement(this.objects, t); if ( this.objects.length == 0 && this.childrenHaveObj() @@ -4192,12 +3553,6 @@ SOFTWARE. } return false } - /** - * @template T - * @param {Traverser} func - * @param {T[]} target - * @returns [] - */ traverse(func, target) { if (!this.isLeafNode()) { for (var i = 0; i < 4; i++) { @@ -4211,18 +3566,14 @@ SOFTWARE. return target } } - /** - * @param {CollisionPair[]} target - * @param {CollisionPair[]} stack - */ getCollisionPairs(target, stack) { if (!this.hasObjects) return if (!this.isLeafNode()) { - Utils$1.appendArr(stack, this.objects); + Utils.appendArr(stack, this.objects); for (var i = 0; i < 4; i++) { this.children[i].getCollisionPairs(target, stack); } - Utils$1.popArr(stack, this.objects.length); + Utils.popArr(stack, this.objects.length); } let length = stack.length, obLength = this.objects.length, @@ -4305,7 +3656,7 @@ SOFTWARE. insert(obj) { let client = body.client; if (client == null) { - client = body.client = new Client(body); + client = body.client = new Client$1(body); } this._insert(client); } @@ -4344,7 +3695,7 @@ SOFTWARE. /** * A depth first search of the quadtree that applies the given function to its nodes. * - * @param {Function} func The function that checks every node unless it returns true. + * @param {function} func The function that checks every node unless it returns true. * */ traverse(func) { @@ -4352,7 +3703,6 @@ SOFTWARE. } /** * @inheritdoc - * @param {CanvasRenderingContext2D} ctx */ draw(ctx) { this._root.traverse(e => { @@ -4393,11 +3743,162 @@ SOFTWARE. } } + let floor = Math.floor; + class Client { + constructor(body) { + this.body = body; + this.bounds = body.bounds.clone(); + } + } + /** - * @callback Traverser - * @param {Node} node - * @returns {boolean} - */ + * This is a bounded broadphase that is used to speed up collision testing on dense number of objects over a small area. + * + * @extends Broadphase + */ + class Grid extends Broadphase { + bins = [] + bounds = null + constructor(bounds, divX, divY) { + super(); + this.bounds = bounds; + this.divX = divX; + this.divY = divY; + for (let i = 0; i < divX; i++) { + let Xbin = []; + for (let j = 0; j < divY; j++) { + Xbin.push([]); + } + this.bins.push(Xbin); + } + } + _hash(x, y) { + let key = [0, 0], + minX = this.bounds.min.x, + minY = this.bounds.min.y, + width = this.bounds.max.x - this.bounds.min.x, + height = this.bounds.max.y - this.bounds.min.y; + + key[0] = floor( + ((x - minX) / width) * this.divX); + key[1] = floor(((y - minY) / height) * this.divY); + return key + } + /** + * @inheritdoc + * @private + * @param {Client} client + */ + _insert(client) { + client.bounds.copy(client.body.bounds); + let [x1, y1] = this._hash(client.bounds.min.x, client.bounds.min.y); + let [x2, y2] = this._hash(client.bounds.max.x, client.bounds.max.y); + + + if (x1 > this.divX - 1 || x1 < 0) return + if (y1 > this.divY - 1 || y1 < 0) return + if (x2 > this.divX - 1 || x2 < 0) return + if (y2 > this.divY - 1 || y2 < 0) return + + for (let i = x1; i <= x2; i++) { + for (var j = y1; j <= y2; j++) { + this.bins[i][j].push(client); + } + } + } + /** + * @inheritdoc + * @param {Body} body + */ + insert(body) { + let client = body.client; + if (client == null) { + client = body.client = new Client(body); + } + this._insert(client); + } + /** + * @inheritdoc + * @private + * @param {Client} client + */ + _remove(client) { + let [x1, y1] = this._hash(client.bounds.max.x, client.bounds.max.y); + let [x2, y2] = this._hash(client.bounds.max.x, client.bounds.max.y); + + if (x1 > this.divX - 1 || x1 < 0) return + if (y1 > this.divY - 1 || y1 < 0) return + if (x2 > this.divX - 1. || x2 < 0) return + if (y2 > this.divY - 1. || y2 < 0) return + + for (let i = x1; i <= x2; i++) { + for (let j = y1; j <= y2; j++) { + let index = this.bins[i][j].indexOf(client); + Utils.removeElement(this.bins[i][j], index); + } + } + } + /** + * @inheritdoc + * @param {Body} body + */ + remove(body) { + if (body.client === null) return + this._remove(body.client); + } + /** + * @inheritdoc + * @private + * @param {Body} body + */ + _update(body) { + this._remove(body.client); + this._insert(body.client); + } + /** + * @inheritdoc + * @param {Body[]} bodies + */ + update(bodies) { + for (var i = 0; i < bodies.length; i++) { + this._update(bodies[i]); + } + } + _naiveCheck(arr, ids, target) { + for (var j = 0; j < arr.length; j++) { + for (var k = j + 1; k < arr.length; k++) { + let a = arr[j]; + let b = arr[k]; + let id = naturalizePair(a.id, b.id); + + if (ids.has(id)) continue + if (!this.canCollide(a, b)) continue + if (!a.bounds.intersects(b.bounds)) + continue + ids.add(id); + target.push({ + a, + b + }); + } + } + } + /** + * @inheritdoc + * @param {CollisionPair[]} target Empty array to store results. + * @returns {CollisionPair[]} + */ + getCollisionPairs(target) { + //When bodies are in more than one bin,there is a possibility that they might show up in more than one collision,this remedies that. + let ids = new Set(); + for (let i = 0; i < divX; i++) { + for (let j = 0; j < divY; j++) { + this._naiveCheck(this.bins[i][j], ids, target); + } + } + return target + } + } /** * Class responsible for updating bodies,constraints and composites. @@ -4420,14 +3921,14 @@ SOFTWARE. /** * A list of bodies. * - * @type Body[] + * @type Array * @private */ objects = [] /** * A list of constraints fixed to a static object. * - * @type Constraint[] + * @type Array * @private */ fixedConstraits = [] @@ -4460,7 +3961,7 @@ SOFTWARE. /** * The collision manifolds that have passed narrowphase and verified to be colliding. * - * @type Manifold[] + * @type Array */ CLMDs = [] /** @@ -4475,7 +3976,7 @@ SOFTWARE. * * @type Vector */ - gravitationalAcceleration = new Vector$1(0, 0) + gravitationalAcceleration = new Vector(0, 0) /** * Time in seconds that a single frame takes.This has more precedence than the first parameter of World.update(),set to this to zero if you want to use the latter as the delta time. * @@ -4538,7 +4039,7 @@ SOFTWARE. lastOverlap: 0, overlap: -Infinity, done: false, - axis: new Vector$1(), + axis: new Vector(), verticesA: [], verticesB: [], vertShapeA: null, @@ -4551,13 +4052,13 @@ SOFTWARE. stmp: -1, impulse: 0, persistent: false, - ca1: new Vector$1(), - ca2: new Vector$1(), + ca1: new Vector(), + ca2: new Vector(), restitution: 0, staticFriction: 0, kineticFriction: 0, - velA: new Vector$1(), - velB: new Vector$1(), + velA: new Vector(), + velB: new Vector(), rotA: 0, rotB: 0 }); @@ -4568,13 +4069,13 @@ SOFTWARE. SAT.shapesInBodyCollided(a, b, collisionData); if (collisionData.overlap < 0 || !collisionData.done) continue if (collisionData.contactNo == 2) { - Vector$1.lerp( + Vector.lerp( collisionData.verticesA[0], collisionData.verticesA[1], 0.5, manifold.ca1 ).sub(a.position); - Vector$1.lerp( + Vector.lerp( collisionData.verticesB[0], collisionData.verticesB[1], 0.5, @@ -4708,7 +4209,7 @@ SOFTWARE. /** * * - * @param {Number} delta the time passed between the last call and this call. + * @param {Number} dt the time passed between the last call and this call. */ update(delta) { this.perf.lastTimestamp = performance.now(); @@ -4783,7 +4284,7 @@ SOFTWARE. */ removeBody(body) { this.broadphase.remove(body); - if (Utils$1.removeElement(this.objects, body.index)) { + if (Utils.removeElement(this.objects, body.index)) { if (body.index === this.objects.length) return this.objects[body.index].index = body.index; @@ -4812,7 +4313,7 @@ SOFTWARE. removeContraint(constraint) { let arr = constraint.fixed ? this.fixedConstraits : this.constraints; let temp = arr.pop(); - if(constraint.index == arr.length) return constraint + if (constraint.index == arr.length) return constraint arr[constraint.index] = temp; temp.index = constraint.index; constraint.index = -1; @@ -4858,54 +4359,49 @@ SOFTWARE. } } - /** - * Holds transformation info of an entity - * - * @implements Component - */ - class Transform { - entity = null - /** - * @param {number} x - * @param {number} y - * @param {number} a - * @returns - */ - constructor(x,y,a){ - this.position = new Vector$1(x,y); - this.orientation = new Angle(a); - } - init(){} - toJson(){ - return { - position: this.position.toJson(), - orientation:this.orientation.toJson() - } - } - fromJson(obj){ - this.position.fromJson(obj.position); - this.orientation.fromJson(obj.orientation); - } - } - class Camera { - /** - * @readonly - * @type Transform - */ - transform = new Transform() - - constructor() { } - /** - * @type Vector - */ + _position = new Vector() + constructor(renderer, position) { + this.transformMatrix = new Matrix2(); + this.target = null; + this.lerpFactor = 0.5; + this.renderer = renderer; + this.offset = new Vector(); + this._position = new Vector(); + this._actualPosition = new Vector(); + this.position.set(position?.x || 0, position?.y || 0); + this.orientation = new Angle(); + } get position() { - return this.transform.position + return this._actualPosition } set position(x) { - this.transform.position.copy(x); + this._actualPosition.copy(x); + } + get transform() { + return this.position + } + update() { + if (this.target) + Vector.lerp( + this._position, + this.target, + this.lerpFactor, + this._position + ); + this._actualPosition + .copy(this._position) + .add(this.offset); + } + clear(ctx) { + ctx.setTransform(); + } + dispose() { + this.renderer = null; + } + follow(position) { + this.target = position; } - update() {} } /** @@ -4917,10 +4413,6 @@ SOFTWARE. * @see WebGPURenderer */ class Renderer { - /** - * @type number - */ - _rafID = 0 /** * Used to throttle the frame rate. * @@ -4949,9 +4441,6 @@ SOFTWARE. domElement = null /**@type {CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext}*/ ctx = null - /** - * @type {Camera} - */ camera = null /** * @param {CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext} context @@ -4979,9 +4468,7 @@ SOFTWARE. throw "Override Renderer.clear()" } /** - * Updates the objects within the renderer. - * - * @param {number} dt + * Updates the objects within the renderer */ update(dt) { throw "Override Renderer.update()" @@ -5022,7 +4509,7 @@ SOFTWARE. /** * Adds a mesh to the renderer. * - * @param {Sprite | Group} sprite + * @param {Sprite} Sprite */ add(sprite) { this.objects.push(sprite); @@ -5082,8 +4569,10 @@ SOFTWARE. * Renders images and paths to the 2D context of a canvas. * * @extends Renderer - */ + */ class Renderer2D extends Renderer { + _fill = "black" + _stroke = "black" frameRate = 1 / 60 renderLast = [] /** @@ -5091,49 +4580,136 @@ SOFTWARE. */ constructor(canvas) { canvas = canvas || document.createElement("canvas"); - super(canvas, canvas.getContext("2d")); + super(canvas,canvas.getContext("2d")); + + } + push() { + this.ctx.save(); + } + pop() { + this.ctx.restore(); } - /** - * @inheritdoc - * - * @param {Sprite | Group} sprite - */ - add(sprite) { - super.add(sprite); - sprite.geometry?.init(this.ctx); + reset() { + this.ctx.setTransform(); + } + translate(x, y) { + this.ctx.translate(x, y); + } + scale(x, y) { + this.ctx.scale(x, y); + } + rotate(rad) { + this.ctx.rotate(rad); + } + line(x1, y1, x2, y2) { + this.ctx.moveTo( + x1 - this.camera.position.x, + y1 - this.camera.position.y + ); + this.ctx.lineTo( + x2 - this.camera.position.x, + y2 - this.camera.position.y + ); + } + rect(x, y, w, h) { + this.ctx.rect( + x - this.camera.position.x, + y - this.camera.position.y, + w, + h + ); + } + circle(x, y, r) { + this.ctx.arc( + x - this.camera.position.x, + y - this.camera.position.y, + r, 0, Math.PI * 2 + ); + } + vertices(vertices, close = true) { + if (vertices.length < 2) return; + this.ctx.moveTo( + vertices[0].x - this.camera.position.x, + vertices[0].y - this.camera.position.y); + for (var i = 1; i < vertices.length; i++) { + this.ctx.lineTo( + vertices[i].x - this.camera.position.x, + vertices[i].y - this.camera.position.y + ); + } + if (close) + this.ctx.lineTo( + vertices[0].x - this.camera.position.x, + vertices[0].y - this.camera.position.y + ); + } + arc(x, y, r, start, end) { + this.ctx.arc( + x - this.camera.position.x, + y - this.camera.position.y, + r, start, end + ); + } + fillText(text, x, y) { + this.ctx.fillText(text, + x - this.camera.position.x, + y - this.camera.position.y + ); + } + fill(color = "black", fillRule) { + this.ctx.fillStyle = color; + this.ctx.fill(fillRule); + } + stroke(color = "black", width = 1) { + this.ctx.strokeStyle = color; + this.ctx.lineWidth = width; + this.ctx.stroke(); + } + begin() { + this.ctx.beginPath(); + } + close() { + this.ctx.closePath(); + } + clip() { + this.ctx.clip(); + } + drawImage( + img, + x, + y, + w = img.width, + h = img.height, + ix = 0, + iy = 0 + ) { + this.ctx.drawImage(img, w * ix, h * iy, w, h, + x - this.camera.position.y, + y - this.camera.position.y, + w, h); } clear() { - this.ctx.setTransform(); + this.reset(); let h = this.height, w = this.width; this.ctx.clearRect(0, 0, w, h); } - /** - * @param {number} dt - */ update(dt) { - this.camera.update(); + this.camera.update(dt); this.perf.lastTimestamp = performance.now(); this.clear(); if (this.background != void 0) this.background.update(this, dt); - this.ctx.save(); - this.ctx.translate(this.camera.transform.position.x,-this.camera.transform.position.y); - this.ctx.rotate(this.camera.transform.orientation.radian); for (var i = 0; i < this.objects.length; i++) { - this.objects[i].render(this.ctx, dt); + this.objects[i].render(this, dt); } - this.ctx.restore(); for (var i = 0; i < this.renderLast.length; i++) { this.renderLast[i].update(this, dt, this.camera.transform); } this.perf.total = performance.now() - this.perf.lastTimestamp; } - /** - * @private - */ - _update = (accumulate) => { + _update = (accumulate)=> { let dt = this.clock.update(accumulate); if (this._accumulator < this.frameRate) { this._accumulator += dt; @@ -5144,11 +4720,9 @@ SOFTWARE. this.RAF(); this._accumulator = 0; } - /** - * @param {Sprite} sprite - */ - addUI(sprite) { - this.renderLast.push(sprite); + + addUI(mesh) { + this.renderLast.push(mesh); } requestFullScreen() { this.domElement.parentElement.requestFullscreen(); @@ -5185,516 +4759,82 @@ SOFTWARE. * Extend it to create your custom behaviour. * * @implements Component - * TODO - ADD id property to this class and Group class. */ class Sprite { /** * @private */ - _position = null - /** - * @private - */ - _orientation = null + _position = new Vector() /** * @private */ - _scale = null + _orientation = new Angle() + scale = new Vector(1, 1) /** * @private */ geometry = null - /** - * @private - */ material = null - /** - * @type Group | null - */ parent = null - /** - * @param {BufferGeometry} geometry - * @param {Material} material - */ constructor(geometry, material) { this.geometry = geometry; this.material = material; } - /** - * Angle in degrees - * - * @type number - */ get angle() { return this._orientation.radian * 180 / Math.PI } set angle(x) { this._orientation.degree = x; } - /** - * World space position. - * - * @type Vector - */ get position() { return this._position } set position(x) { this._position.copy(x); } - /** - * Orientation of the sprite - * - * @type Angle - */ - get orientation() { - return this._orientation - } - set orientation(x) { - this._orientation.copy(x); - } - render(ctx, dt) { - ctx.save(); - ctx.beginPath(); - ctx.translate(...this._position); - ctx.rotate(this._orientation.radian); - ctx.scale(...this._scale); - this.material?.render(ctx,dt,this.geometry?.drawable); - ctx.closePath(); - ctx.restore(); - } - /** - * @param {Entity} entity - */ - init(entity) { - if(!entity){ - this._position = new Vector$1(); - this._orientation = new Angle(); - this._scale = new Vector$1(1,1); - return - } - this.entity = entity; - this.requires("transform"); - let transform = entity.get("transform"); - this._position = transform.position; - this._orientation = transform.orientation; - //TODO - Correct this later - this._scale = new Vector$1(1,1); - return this - } - toJson(){ - let obj = { - pos:this._position.toJson(), - angle:this._orientation.toJson(), - geometry:this.geometry?.toJson(), - material:this.material?.toJson(), - parent:this.parent?.id - }; - return obj - } - fromJson(obj,renderer){ - this.geometry?.fromJson(obj.geometry); - this.material?.fromJson(obj.material); - this.position.fromJson(obj.pos); - this._orientation.fromJson(obj.angle); - this.parent = renderer.getById(obj.parent); - } - } - Utils$1.inheritComponent(Sprite); - - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} x1 - * @param {number} y1 - * @param {number} x2 - * @param {number} y2 - */ - function line(ctx, x1, y1, x2, y2) { - ctx.moveTo(x1, y1); - ctx.lineTo(x2, y2); - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} x - * @param {number} y - * @param {number} w - * @param {number} h - */ - function rect(ctx, x, y, w, h) { - ctx.rect(x, y, w, h); - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} x - * @param {number} y - * @param {number} r - */ - function circle(ctx, x, y, r) { - ctx.arc(x, y, r, 0, Math.PI * 2); - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param {Vector[]} vertices - * @param {boolean} [close=true] - */ - function vertices(ctx, vertices, close = true) { - if (vertices.length < 2) return; - ctx.moveTo(vertices[0].x, vertices[0].y); - for (var i = 1; i < vertices.length; i++) { - ctx.lineTo(vertices[i].x, vertices[i].y); - } - if (close) - ctx.lineTo(vertices[0].x, vertices[0].y); - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} x - * @param {number} y - * @param {number} r - * @param {number} start - * @param {number} end - */ - function arc(ctx, x, y, r, start, end) { - ctx.arc(x, y, r, start, end); - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param {string} text - * @param {number} x - * @param {number} y - */ - function fillText(ctx, text, x, y) { - ctx.fillText(text, x, y); - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param {string} [color="black"] - * @param {string} [fillRule] - */ - function fill(ctx, color = "black", fillRule) { - ctx.fillStyle = color; - ctx.fill(fillRule); - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param { string } [color = "black"] - * @param {number} [width=1] - */ - function stroke(ctx, color = "black", width = 1) { - ctx.strokeStyle = color; - ctx.lineWidth = width; - ctx.stroke(); - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param {HTMLImageElement} img - * @param {number} x - * @param {number} y - * @param { number } [w = img#width] - * @param { number } [h=img#height] - * @param { number } [ix = 0] - * @param { number } [iy = 0] - */ - function drawImage( - ctx, - img, - x, - y, - w = img.width, - h = img.height, - ix = 0, - iy = 0 - ) { - ctx.drawImage(img, w * ix, h * iy, w, h, - x, - y, - w, h); - } - - class BufferGeometry { - /** - * @readonly - * @type Vector[] - */ - vertices = null - /** - * @package - * @type Path2D | WebGLVertexArrayObject - */ - drawable = null - /** - * @param {Vector[]} vertices - */ - constructor(vertices) { - this.vertices = vertices || []; - } - /** - * @package - * @param {CanvasRenderingContext2D} ctx - */ - init(ctx) { - let path = this.drawable = new Path2D(); - vertices(path, this.vertices, true); - } - } - - class CircleGeometry { - /** - * @param {number} radius - */ - constructor(radius) { - this.radius = radius; - } - /** - * @param {CanvasRenderingContext2D} ctx - */ - init(ctx) { - this._drawable = new Path2D(); - circle(path, this.vertices, true); - } - /** - * @param {CanvasRenderingContext2D} ctx - */ - render(ctx) { - circle(ctx, 0, 0, this.radius); - } - } - - /** - * @interface - */ - class Material{ - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - * @param {Path2D} [path] - */ - render(ctx,dt,path){ - throw "Override this method in derived class" - } - } - - /** - * - * @implements Material - */ - class BasicMaterial { - /** - * - * @type string - * @default "white" - */ - fill = "white" - /** - * - * @type string - * @default "black" - */ - stroke = "black" - /** - * - * @type boolean - * @default false - */ - wireframe = false - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - * @param {Path2D} path - */ - render(ctx,dt, path) { - if (!this.wireframe) { - ctx.fillStyle = this.fill; - ctx.fill(path); - } - ctx.strokeStyle = this.stroke; - ctx.stroke(path); - } - } - - /** - * - * @implements Material - */ - class StaticImageMaterial { - /** - * @readonly - * @type Image - */ - image = null - /** - * - * @type number - */ - width = 100 - /** - * - * @type number - */ - height = 100 - /** - * @param {Image} img - */ - constructor(img) { - //TODO - Find a way to load images synchronously. - this.image = img; - } - /** - * @param {CanvasRenderingContext2D} ctx - */ - render(ctx) { - ctx.drawImage(this.image, -this.width / 2, -this.height / 2, this.width, this.height); - } - } - - /** - * - * @implements Material - */ - class SpriteMaterial { - /** - * @type HTMLImageElement - */ - img = null - /** - * The index of the current action. - * - * @private - * @type number - */ - _index = 0 - /** - * The current action's max frame index. - * - * @private - * @type number - */ - _maxFrame = 0 - /** - * The current frame of an action. - * - * @private - * @type number - */ - _frame = 0 - /** - * Used with ImageSprite#frameRate to throttle the fps of the sprite. - * - * @private - * @type number - */ - _accumulator = 0 - /** - * The maximum frames for each given action. - * - * @type number - */ - frameRate = 1 / 60 - /** - * The current action. - * - * @private - * @type number[] - */ - _maxFrames = null - /** - * The width of the sprite. - * - * @type number - */ - width = 0 - /** - * The height of the sprite.. - * - * @type number - */ - height = 0 - /** - * The width of a frame. - * - * @private - * @type number - */ - frameWidth = 0 - /** - * The height of a frame.. - * - * @private - * @type number - */ - frameHeight = 0 - /** - * @param {HTMLImageElement} img Image to draw - * @param {number} [frames] Number of cutouts in the sprite in the X axis of the image. - * @param {number} [actions] Number of cutouts in the sprite in the Y axis of the image. - */ - constructor(img, frames = 1, actions = 1) { - this.img = img; - this.setup(frames, actions); - } - /** - * - * @param {number} frames - * @param {number} actions - */ - setup(frames, actions) { - this._maxFrame = frames - 1; - this.width = this.img.width; - this.height = this.img.height; - this.frameWidth = this.img.width / (frames || 1); - this.frameHeight = this.img.height / actions; - } - /** - * Sets max number of frames for a given action - * - * @param {number} action - * @param {number} max - */ - setMaxFrames(action, max) { - this._maxFrames = max; - } - /** - * Sets a given action to be rendered - * - * @param {number} index - */ - setAction(index) { - this._maxFrame = (this._maxFrames[index] || 0); - this._index = index; - this._frame = 0; - } - /** - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ - render(ctx, dt) { - drawImage( - ctx, - this.img, - -this.frameWidth / 2, - -this.frameHeight / 2, - this.frameWidth, - this.frameHeight, - this._frame, - this._index - ); - this._accumulator += dt; - if (this._accumulator < this.frameRate) return - this._accumulator = 0; - this._frame += 1; - if (this._frame >= this._maxFrame) - this._frame = 0; + get orientation() { + return this._orientation + } + set orientation(x) { + this._orientation.copy(x); + } + /** + * Override this function. + * The canvas is already transformed to the position and rotation of the sprite. + * + */ + draw(render) { + this.geometry.render(render); + this.material.render(render); + } + render(render, dt) { + render.begin(); + render.translate(...this._position); + render.rotate(this._orientation.radian); + render.scale(...this.scale); + this.draw(render, dt); + render.close(); + render.reset(); + } + init(entity) { + this.entity = entity; + this.requires("transform"); + let transform = entity.get("transform"); + this._position = transform.position; + this._orientation = transform.orientation; } + + + update() {} } + Utils.inheritComponent(Sprite); - let r = new Vector$1(); - let material$1 = new BasicMaterial(); - material$1.wireframe = true; /** * This draws a body from the physics System. * * @augments Sprite */ + let r = new Vector(); class BodySprite extends Sprite { /** * @private @@ -5723,92 +4863,87 @@ SOFTWARE. this.drawVelocity = options.drawVelocity || false; this.drawBounds = options.drawBounds || false; } - /** - * @inheritdoc - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ - render(ctx, dt) { + render(renderer, dt) { if (this.body.physicsType == ObjType.COMPOSITE) { for (var i = 0; i < this.body.bodies.length; i++) { - this._drawShapes(this.body.bodies[i], ctx); + this._drawShapes(this.body.bodies[i], renderer); } } else { - this._drawShapes(this.body, ctx); + this._drawShapes(this.body, renderer); } if (this.drawVelocity == true) - this._drawVelocity(this.body, ctx); + this._drawVelocity(this.body, renderer); if (this.drawBounds == true) - this._drawBound(this.body, ctx); + this._drawBound(this.body, renderer); } /** * @private * @param {Body} body - * @param {CanvasRenderingContext2D} renderer + * @param {Renderer} renderer */ _drawVelocity(body, ctx) { - ctx.beginPath(); - line( - ctx, + ctx.begin(); + ctx.line( body.position.x, body.position.y, body.position.x + body.velocity.x, body.position.y + body.velocity.y ); - stroke(ctx, "cyan"); - ctx.closePath(); + ctx.stroke("cyan"); + ctx.close(); } /** * @private * @param {Body} body - * @param {CanvasRenderingContext2D} renderer + * @param {Renderer} renderer */ - _drawBound(body, ctx) { - ctx.beginPath(); + _drawBound(body, renderer) { + renderer.begin(); if (body.bounds.r) { - circle(ctx, ...body.position, body.bounds.r); + //renderer.circle(body.bounds.pos.x,body.bounds.pos.y, body.bounds.r) + + renderer.circle(...body.position, body.bounds.r); } else { - rect( - ctx, + renderer.rect( body.bounds.min.x, body.bounds.min.y, body.bounds.max.x - this.body.bounds.min.x, body.bounds.max.y - this.body.bounds.min.y ); } - stroke(ctx,"red"); - ctx.closePath(); + renderer.stroke("red"); + renderer.close(); + } /** * @private * @param {Body} body - * @param {CanvasRenderingContext2D} renderer + * @param {Renderer} renderer */ - _drawShapes(body, ctx) { - ctx.beginPath(); + _drawShapes(body, renderer) { + renderer.begin(); for (var i = 0; i < body.shapes.length; i++) { let shape = body.shapes[i]; - if (shape.type === Shape.CIRCLE) { - circle( - ctx, + if (shape.type == Shape.CIRCLE) { + renderer.circle( shape.position.x, shape.position.y, shape.radius); - Vector$1.fromRad(shape.angle, r).multiply(shape.radius); - line(ctx,...shape.position, + Vector.fromRad(shape.angle, r).multiply(shape.radius); + renderer.line(...shape.position, shape.position.x + r.x, shape.position.y + r.y); } else { - vertices(ctx,shape.vertices, true); + renderer.vertices(shape.vertices, true); } } - stroke(ctx); - ctx.closePath(); + renderer.stroke(); + renderer.close(); } /** - * @inheritdoc + * @package * @param {Entity} parent */ init(parent) { @@ -5817,18 +4952,11 @@ SOFTWARE. } } - let geometry = new BufferGeometry([ - new Vector$1(-10, -10), - new Vector$1(-10, 10), - new Vector$1(20, 0) - ]); - let material = new BasicMaterial(); - material.fill = "purple"; - /** - * Used for debugging agents. - * - * @augments Sprite - */ + let path = [ + new Vector(-10, -10), + new Vector(-10, 10), + new Vector(20, 0) + ]; class AgentSprite extends Sprite { /** * @@ -5836,12 +4964,8 @@ SOFTWARE. * @type Agent */ agent = null - constructor() { - super(geometry,material); - } /** - * @inheritdoc - * @param {Entity} entity + * @param {Entity} entity */ init(entity) { super.init(entity); @@ -5849,58 +4973,217 @@ SOFTWARE. this.agent = entity.get("agent"); } /** - * @param {CanvasRenderingContext2D} ctx + * @param {Renderer} renderer + */ + draw(renderer) { + renderer.vertices(path, true); + renderer.fill("purple"); + renderer.stroke("black"); + } + /** + * @param {Renderer} renderer */ - render(ctx) { - this.agent.draw(ctx); - super.render(ctx); + render(renderer) { + this.agent.draw(renderer); + super.render(renderer); + } + } + + class DebugMesh extends Sprite { + constructor(manager) { + super(); + this.manager = manager; + this.count = 25; + this.now = 0; + this.lastPerf = {}; + this.drawBounds = false; + } + render(ctx, dt) { + this.now++; + let renderer = this.manager.getSystem("renderer"); + let world = this.manager.getSystem("world"); + let phy = world?.perf?.total, + rend = renderer?.perf?.total, + framerate = 1 / dt; + + if (this.now > this.count) { + this.lastPerf.rate = round(framerate, 2); + this.lastPerf.actual = round(1 / (rend + phy) * 1000, 2); + this.lastPerf.phy = round(phy, 2); + this.lastPerf.ren = round(rend, 2); + this.lastPerf.tot = round(this.manager.perf.total, 2); + this.now = 0; + } + ctx.begin(); + ctx.translate( renderer.width - 80, 80); + ctx.fill("cyan"); + ctx.fillText(this.lastPerf.actual + "afps", 0, -20); + ctx.fillText("render: " + this.lastPerf.ren + "ms", 0, 0); + ctx.fillText("physics: " + this.lastPerf.phy + "ms", 0, 10); + ctx.fillText("total: " + this.lastPerf.tot + "ms", 0, 20); + ctx.fillText(`bodies: ${world?.objects?.length}`, 0, 30); + + if (this.lastPerf.rate > 59) + ctx.fill("cyan"); + else if (this.lastPerf.rate > 29) + ctx.fill("orange"); + else if (this.lastPerf.rate <= 29) + ctx.fill("red"); + + ctx.fillText(this.lastPerf.rate + "fps", 0, -30); + ctx.close(); + ctx.translate( -renderer.width + 80, -80); } } /** - * Its a fricking particle! + * Renders an image-sprite frame by frame. + * The frames of the image should have equal width and height in respect to each other. + * + * @augments Sprite */ - class Particle { + class ImageSprite extends Sprite { + _index = 0 + _maxFrame = 0 + _frame = 0 + _accumulator = 0 + _dt = 0 + frameRate = 1 / 60 + _maxFrames = null + width = 0 + height = 0 + frameWidth = 0 + frameHeight = 0 /** - * @readonly - * @type Vector + * @param {HTMLImageElement} img Image to draw + * @param {number} frames Maximum number of cutouts in the sprite in the X axis of the image. + * @param {number} actions Maximum number of cutouts in the sprite in the Y axis of the image. */ - position = null + constructor(img, frames, actions) { + super(); + this.img = img; + this._maxFrame = (frames || 1) - 1; + img.onload = () => { + this.width = img.width; + this.height = img.height; + this.frameWidth = img.width / (frames || 1); + this.frameHeight = img.height / (actions || 1); + }; + this.width = 0; + this.height = 0; + this.frameWidth = 0; + this.frameHeight = 0; + } /** - * @readonly - * @type Vector + * Sets max number of frames for a given action + * + * @param {number} action + * @paran {number} max */ - velocity = null + setMaxFrames(action, max) { + this._maxFrames = max; + } /** - * @type boolean + * Sets a given action to be rendered + * + * @param {number} action + * @paran {number} max */ - active = true + setAction(index) { + this._maxFrame = this._maxFrames[index]; + this._index = index; + this._frame = 0; + } /** - * @type number + * @inheritdoc */ - radius = 0 + draw(renderer) { + renderer.drawImage( + this.img, + -this.frameWidth / 2, + -this.frameHeight / 2, + this.frameWidth, + this.frameHeight, + this._frame, + this._index + ); + } /** - * @type {{r:number,b:number,g:number,a:number}} + * @inheritdoc */ - color = null + render(renderer, dt) { + super.update(renderer, dt); + this._accumulator += dt; + if (this._accumulator < this._frameRate) return + this._accumulator = 0; + this._frame += 1; + if (this._frame > this._maxFrame) + this._frame = 0; + } + } + + /** + * Renders a single image with no frames. + * + * @augments Sprite + */ + class StaticImageSprite extends Sprite { /** - * @private - * @type number - */ - _life = 0 + * @param {HTMLImageElement} img Image to draw + */ + constructor(img) { + super(); + this.img = img; + img.onload = () => { + this.width = img.width; + this.height = img.height; + }; + this.width = 0; + this.height = 0; + this.frameWidth = 0; + this.frameHeight = 0; + } /** - * @readonly - * @type number + * @param {Renderer} ctx */ - lifespan = 0 + draw(renderer) { + renderer.drawImage( + this.img, + -this.frameWidth / 2, + -this.frameHeight / 2, + this.frameWidth, + this.frameHeight, + this._frame, + this._index + ); + } + render(renderer, dt) { + super.update(renderer, dt); + this._accumulator += dt; + if (this._accumulator < this._frameRate) return + this._accumulator = 0; + this._frame += 1; + if (this._frame > this._maxFrame) + this._frame = 0; + + } + } + + let tmp1$5 = new Vector(); + + /** + * Its a fricking particle! + */ + class Particle { /** * @param {Vector} pos * @param {number} radius * @param {number} [lifespan=5] In seconds - */ + */ constructor(pos, radius, lifespan = 5) { this.position = pos; - this.velocity = new Vector$1(); + this.active = true; + this.velocity = new Vector(); this.radius = radius; this.color = { r: 100, @@ -5913,24 +5196,19 @@ SOFTWARE. } /** * Renders a particle. - * - * @param {CanvasRenderingContext2D} ctx - */ + */ draw(ctx) { - ctx.beginPath(); - circle(ctx, ...this.position, this.radius); - fill(ctx, `rgba(${this.color.r},${this.color.g},${this.color.b},${this.color.a})`); - ctx.closePath(); + ctx.begin(); + ctx.circle(...this.position, this.radius); + ctx.fill(`rgba(${this.color.r},${this.color.g},${this.color.b},${this.color.a})`); + ctx.close(); } /** * Updates a particle's lifetime - * @inheritdoc - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ + */ update(ctx, dt) { this._life += dt; - this.position.add(this.velocity); + this.position.add(tmp1$5.copy(this.velocity).multiply(dt)); this.active = this._life < this.lifespan; } } @@ -5939,30 +5217,10 @@ SOFTWARE. * This creates a particle system * @augments Sprite */ - class ParticleSystemSprite extends Sprite { - /** - * @private - */ - _particles = [] - /** - * @type number - * @default 1 - */ - initial = 0 - /** - * @type number - * @default 1 - */ - frameIncrease = 0 - /** - * @type number - * @default 1 - */ - max = 0 + let System$1 = class System extends Sprite { /** * @param {number} [initial=1] Number of particles to start with. * @param {number} [max=100] Maximum number of particles. - * param {number} [increment=5] Maximum number of particles. */ constructor(initial = 1, max = 100, increment = 5) { super(); @@ -5973,11 +5231,10 @@ SOFTWARE. /** * @protected - * @param {number} n */ initParticles(n) { for (var i = 0; i < n; i++) { - this._particles.push(this.create()); + this.add(this.create()); } } @@ -5988,14 +5245,13 @@ SOFTWARE. */ create() { return new Particle( - new Vector$1(...this.position), + new Vector(...this.position), rand(1, 10), rand(1, 6) ) } /** * @inheritdoc - * @param {Entity} entity */ init(entity) { super.init(entity); @@ -6003,160 +5259,94 @@ SOFTWARE. } /** * @protected - * @param {Particle} p - * @param {number} dt */ - behavior(p,dt) { + behavior(p) { p.velocity.set( - p.velocity.x + rand(-1, 1)*dt, - p.velocity.y + rand(0, 0.3)*dt + p.velocity.x + rand(-1, 1), + p.velocity.y + rand(0, 0.3) ); } /** * @inheritdoc - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ + */ render(ctx, dt) { - for (let i = this._particles.length - 1; i > 0; i--) { - let p = this._particles[i]; + for (let i = this._children.length - 1; i > 0; i--) { + let p = this._children[i]; p.update(ctx, dt); - this.behavior(p,dt); + this.behavior(p); p.draw(ctx, dt); if (!p.active) { - this._particles.splice(i, 1); + this.remove(i); } } - if (this._particles.length < this.max) { + if (this._children.length < this.max) { this.initParticles(this.frameIncrease); } } - } + }; - /** - * Used for grouping similar. - * - * @augments Sprite - */ - class Group extends Sprite { - /** - * @private - * @type Sprite[] - */ - _children = null - /** - * @private - * @type Group - */ - parent = null - /** - * @param {Sprite[]} sprites - */ - constructor(sprites = []) { - super(); - this._children = sprites; + class Layer{ + speed = 1 + constructor(img){ + this.img = img; } - /** - * @type string - */ - get CHOAS_CLASSNAME() { - return this.constructor.name.toLowerCase() + draw(ctx,x,y){ + ctx.drawImage(this.img,x,y); } - /** - * @type string - */ - get CHAOS_OBJ_TYPE() { - return "group" + update(ctx,dt){ + } + } - /** - * Adds another sprite to this one - * - * @param {Sprite | Group} sprite - */ - add(sprite) { - this._children.push(sprite); - sprite.parent = this; + class ParallaxBackground { + constructor(...layers) { + this.layers =layers || []; } - /** - * Removes another sprite to this one - * - * @param {Sprite | Group} sprite - * @param {boolean} [recursive=false] - * @param {number} [index] - */ - remove(sprite, recursive = false, index) { - let inx = index ?? this._children.indexOf(sprite); - if (inx !== -1) { - this._children[inx].parent = null; - Utils.removeElement(this._children, inx); - return true - } - if (!recursive) return false - for (var i = 0; i < this._children.length; i++) { - if (this._children.CHAOS_OBJ_TYPE == "group") { - let t = this._children[i].remove(sprite, recursive, index); - if (t) return true - } - } - return false + update(ctx,dt){ + this.layers.forEach(layer=>{ + layer.draw(ctx,dt); + }); } - /** - * @inheritdoc - * @param {CanvasRenderingContext2D} ctx - * @param {number} dt - */ - render(ctx, dt) { - for (var i = 0; i < this._children.length; i++) { - this._children[i].render(ctx, dt); - } + } + + class BufferGeometry{ + constructor(vertices){ + this.vertices = vertices || []; + } + render(renderer){ + renderer.vertices(this.vertices,true); } } - class CamController { - /** - * @readonly - * @type Vector - */ - offset = new Vector$1() - /** - * @param {Camera} camera - */ - constructor(camera) { - this.transform = camera.transform; - this.offset = new Vector$1(); - this.targetPosition = null; - this.targetOrientation = null; + class CircleGeometry{ + constructor(radius){ + this.radius = radius; } - /** - * @param {Vector} position - * @param {Angle} orientation - */ - follow(position, orientation = null) { - this.targetOrientation = orientation; - this.targetPosition = position; + render(renderer){ + renderer.circle(0,0,this.radius); + } + } + + class Material{ + constructor(){ } - /** - * @param {Entity} entity - */ - followEntity(entity) { - if (!entity.has("transform")) return - let target = entity.get("transform"); - this.follow(target.position, target.orientation); + render(){ + } - /** - * @param {number} x - * @param {number} y - */ - setOffset(x, y) { - this.offset.set(x, y); + } + + class BasicMaterial{ + constructor(){ + this.fill = "red"; + this.lineWidth = 1; + this.stroke = "green"; + this.wireframe = true; } - init() {} - update() { - if (this.targetPosition) - this.transform.position.copy(this.targetPosition.clone().sub(this.offset)); - if (this.targetOrientation) - this.transform.orientation.copy(this.targetOrientation); + render(ctx){ + if(!this.wireframe){ + ctx.fill(this.fill); + } + ctx.stroke(this.stroke,this.lineWidth); } } @@ -6203,7 +5393,7 @@ SOFTWARE. */ supportedAudio: [], /** - * A list of image extensions this device supports. + * A list of audio extensions this device supports. * * @type array */ @@ -6380,7 +5570,7 @@ SOFTWARE. } else if (type === "json") { that.json[name] = JSON.parse(xhr.response); } else { - return Err$1.warn(`The file in url ${xhr.responseURL} is not loaded into the loader because its extension name is not supported.`) + return Err.warn(`The file in url ${xhr.responseURL} is not loaded into the loader because its extension name is not supported.`) } that._filesLoaded += 1; @@ -6401,7 +5591,7 @@ SOFTWARE. }, onerror: function(e) { that._filesErr += 1; - Err$1.warn(`The file ${e.responseURL} could not be loaded as the file might not exist in current url`); + Err.warn(`The file ${e.responseURL} could not be loaded as the file might not exist in current url`); if (that._filesLoaded + that._filesErr === that._totalFileNo && that.onfinish) that.onfinish(); } }; @@ -6600,12 +5790,12 @@ SOFTWARE. a = clmds[i].bodyA.entity.getHandler("collision"); b = clmds[i].bodyB.entity.getHandler("collision"); - if (a) a( + if (a) a.call( clmds[i].bodyA.entity, clmds[i].bodyB.entity, clmds[i] ); - if (b) b( + if (b) b.call( clmds[i].bodyB.entity, clmds[i].bodyA.entity, clmds[i] @@ -6624,12 +5814,12 @@ SOFTWARE. a = clmds[i].a.entity.getHandler("precollision"); b = clmds[i].b.entity.getHandler("precollision"); - if (a) a( + if (a) a.call( clmds[i].a.entity, clmds[i].b.entity, clmds[i] ); - if (b) b( + if (b) b.call( clmds[i].b.entity, clmds[i].a.entity, clmds[i] @@ -6666,6 +5856,7 @@ SOFTWARE. */ constructor(eh) { this.keys = {}; + this.activeKeys = []; this.init(eh); } /** @@ -6691,20 +5882,18 @@ SOFTWARE. eh.add('keydown',this._onDown); eh.add('keyup',this._onUp); } - /** - * @private - */ _onDown = e => { let key = this.normalize(e.code); this.keys[key] = true; this.activeKeys.push(key); + this.ondown(e); } - /** - * @private - */ _onUp = e =>{ this.keys[this.normalize(e.code)] = false; + this.onup(e); } + ondown(e) {} + onup(e) {} } /** @@ -6742,14 +5931,6 @@ SOFTWARE. * @type Vector_like */ position = { x: 0, y: 0 } - /** - - * Position of the mouse in last frame. - - * - * @type Vector_like - */ - lastPosition = { x: 0, y: 0 } /** * If the left mouse button is pressed or not. * @@ -6766,13 +5947,19 @@ SOFTWARE. * @param {DOMEventHandler} eh */ constructor(eh) { + this.dragging = false; + this.dragLastPosition = {}; + this.delta = { x: 0, y: 0 }; + this.position = { x: 0, y: 0 }; + this.lastPosition = { x: 0, y: 0 }; + this.init(eh); } /** * Checks to see if the vector provided is * within a dragbox if mouse is being dragged with a right or left button down * - * @param {Vector_like} pos an object containing x and y coordinates to be checked + * @param {Vector} pos an object containing x and y coordinates to be checked * @returns {Boolean} * */ @@ -6788,7 +5975,6 @@ SOFTWARE. /** * Initializes the mouse by appending to the DOM * - * @param {DOMEventHandler} eh */ init(eh) { eh.add('click', this._onClick); @@ -6798,15 +5984,10 @@ SOFTWARE. eh.add('mousemove', this._onMove); eh.add("contextmenu", this._onContextMenu); } - /** - * @private - */ _onClick = (e) => { ++this.clickCount; + this.onclick(e); } - /** - * @private - */ _onMove = (e) => { this.position.x = e.clientX; @@ -6822,10 +6003,8 @@ SOFTWARE. this.dragLastPosition.x = e.clientX; this.dragLastPosition.y = e.clientY; } + this.onmove(e); } - /** - * @private - */ _onDown = (e) => { switch (e.button) { @@ -6837,10 +6016,8 @@ SOFTWARE. this.rightbutton = true; break; } + this.ondown(e); } - /** - * @private - */ _onUp = (e) => { switch (e.button) { case 0: @@ -6850,21 +6027,26 @@ SOFTWARE. this.rightbutton = false; break; } + this.onup(e); } - /** - * @private - */ _onWheel = (e) => { + this.onwheel(e); } - /** - * @private - */ _onContextMenu = (e) => { e.preventDefault(); + this.oncontextmenu(e); } + + onmove(e) {} + onclick(e) {} + ondown(e) {} + onup(e) {} + onwheel(e) {} + oncontextmenu(e) {} + /** * Updates the mouse internals. - */ + */ update() { this.lastPosition = { ...this.position }; } @@ -6876,25 +6058,14 @@ SOFTWARE. * Realized i need to massively change this to make it work well. */ class Touch { - /** - * @type TouchEvent[] - */ - touches = [] - /** - * @type number - */ - clickCount = 0 - /** - * @param {DOMEventHandler} eh - */ constructor(eh) { + this.clickCount = 0; + this.touches = []; this.init(eh); } /** * Checks to see if the position is within the dragbox of the first two touches. * Not yet fully implemented - * - * @param {Vector_like} pos */ inDragBox(pos) { if (pos.x > this.dragLastPosition.x && pos.x < this.dragLastPosition.x + this.position.x && @@ -6913,24 +6084,23 @@ SOFTWARE. eh.add('touchend', this._onUp); eh.add('touchmove', this._onMove); } - /** - * @private - */ _onMove = (e) => { e.preventDefault(); + this.onmove(e); } - /** - * @private - */ _onDown = (e) => { this.touches = e.touches; + this.ondown(e); } - /** - * @private - */ _onUp = (e) => { this.touches = e.touches; + this.onup(e); } + onmove(e) {} + onclick(e) {} + ondown(e) {} + onup(e) {} + onwheel(e) {} update() {} } @@ -7092,7 +6262,7 @@ SOFTWARE. * @ignore. * This is an artifact of me debugging this. * TODO - Should implement a better soluton - */ + */ perf = { lastTimestamp: 0, total: 0 @@ -7102,12 +6272,12 @@ SOFTWARE. * * @readonly * @type Loader - */ + */ loader = new Loader() /** * @readonly * @type EventDispatcher - */ + */ events = new EventDispatcher() /** * @private @@ -7183,7 +6353,7 @@ SOFTWARE. */ add(object) { if (object.manager) { - Err$1.warn(`The entity with id ${object.id} has already been added to a manager.It will be ignored and not added to the manager`, object); + Err.warn(`The entity with id ${object.id} has already been added to a manager.It will be ignored and not added to the manager`, object); return } this.objects.push(object); @@ -7231,7 +6401,7 @@ SOFTWARE. return } if (n in this._componentLists) - Utils$1.removeElement(this._componentLists[n], this._componentLists[n].indexOf(c)); + Utils.removeElement(this._componentLists[n], this._componentLists[n].indexOf(c)); } /** * Removes an entity from the manager. @@ -7243,7 +6413,7 @@ SOFTWARE. remove(object) { let index = this.objects.indexOf(object); object.removeComponents(); - Utils$1.removeElement(this.objects, index); + Utils.removeElement(this.objects, index); this.events.trigger("remove", object); } @@ -7336,7 +6506,7 @@ SOFTWARE. */ registerClass(obj, override = false) { let n = obj.name.toLowerCase(); - if (n in this._classes && !override) return Err$1.warn(`The class \`${obj.name}\` is already registered.Set the second parameter of \`Manager.registerClass()\` to true if you wish to override the set class`) + if (n in this._classes && !override) return Err.warn(`The class \`${obj.name}\` is already registered.Set the second parameter of \`Manager.registerClass()\` to true if you wish to override the set class`) this._classes[n] = obj; } /** @@ -7384,8 +6554,7 @@ SOFTWARE. /** * Removes a system from the manager. * - * @param {string} n The name of the system - * @returns {void} + * @param {string} n The name of the system. * */ unregisterSystem(n) { @@ -7416,9 +6585,11 @@ SOFTWARE. * Finds the first entity with all the components and returns it. * * @param {Array} comps An array containing the component names to be searched + * @param {Entity[]} [entities = Manager#objects] The array of entities to search in.Defaults to the manager's entity list + * * @returns {Entity} */ - getEntityByComponents(comps) { + getEntityByComponents(comps, entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < comps.length; j++) { if (!entities[i].has(comps[j])) continue @@ -7431,7 +6602,6 @@ SOFTWARE. * * @param {Array} comps An array containing the component names to be searched * @param {Entity[]} [entities = Manager#objects] The array of entities to search in.Defaults to the manager's entity list - * @param {Entity[]} [target] * * @returns {Entity[]} */ @@ -7448,9 +6618,11 @@ SOFTWARE. * Finds the first entity with all the tag and returns it. * * @param {Array} tags An array containing the tags to be searched + * @param {Entity[]} [entities = Manager#objects] The array of entities to search in.Defaults to the manager's entity list + * * @returns {Entity} */ - getEntityByTags(tags) { + getEntityByTags(tags, entities = this.objects) { for (let i = 0; i < entities.length; i++) { for (let j = 0; j < tags.length; j++) { if (!entities[i].hasTag(tags[j])) continue @@ -7463,7 +6635,7 @@ SOFTWARE. * * @param {string[]} tags An array containing the tags to be searched * @param {Entity[]} [entities = Manager#objects] The array of entities to search in. Defaults to the manager's entity list - * @param {Entity[]} target + * * @returns {Entity[]} */ getEntitiesByTags(tags, entities = this.objects, target = []) { @@ -7484,7 +6656,7 @@ SOFTWARE. if (n) { if (n in this._classes) return new this._classes[n]() - Err$1.throw(`Class \`${n}\` is not registered in the manager thus cannot be used in cloning.Use \`Manager.registerClass\` to register it into this manager.`); + Err.throw(`Class \`${n}\` is not registered in the manager thus cannot be used in cloning.Use \`Manager.registerClass\` to register it into this manager.`); } return obj instanceof Array ? [] : {} } @@ -7492,7 +6664,6 @@ SOFTWARE. * Deep copies an entity * * @deprecated - * @private * @returns {Entity} */ clone(obj) { @@ -7528,18 +6699,10 @@ SOFTWARE. remove(comp) { let list = manager.getComponentList(n), index = list.indexOf(comp); - Utils$1.removeElement(list, index); + Utils.removeElement(list, index); } } } - /** - * @param {BoundingCircle | BoundingBpx } bound - * @returns Entity[] - */ - query(bound) { - ///TODO - What will happen if there is no world? ...Yes,it will crash. - return this._coreSystems.world.query(bound) - } } /** @@ -7549,7 +6712,7 @@ SOFTWARE. */ class System{} - Utils$1.inheritSystem(System); + Utils.inheritSystem(System); /** * @@ -7580,33 +6743,29 @@ SOFTWARE. * Component to hold requirements for an entity to move. * * @implements Component - */ + */ class Movable extends Component { entity = null - /** * - * @param {number} x - * @param {number} y - * @param {number} a - * @returns {Entity} - */ constructor(x, y, a) { super(); - this.velocity = new Vector$1(x, y); + this.velocity = new Vector(x,y); this.rotation = new Angle(a); - this.acceleration = new Vector$1(); - } - toJson() { - return { - velocity: this.velocity.toJson(), - rotation: this.rotation.toJson(), - acceleration: this.acceleration.toJson() - } + this.acceleration = new Vector(); } - fromJson(obj) { - this.velocity.fromJson(obj.velocity); - this.rotation.fromJson(obj.rptatjon); - this.acceleration.fromJson(obj.acceleration); + } + + /** + * Holds transformation info of an entity + * + * @implements Component + */ + class Transform { + entity = null + constructor(x,y,a){ + this.position = new Vector(x,y); + this.orientation = new Angle(a); } + init(){} } /** @@ -7622,14 +6781,6 @@ SOFTWARE. */ bounds = new BoundingBox() entity = null - toJson(){ - return { - bounds:this.bounds.toJson() - } - } - fromJson(obj){ - this.bpunds.fromJson(obj.bounds); - } } /** @@ -7731,6 +6882,9 @@ SOFTWARE. * @returns {this} */ attach(n, c) { + if(c == void 0){ + console.log(true); + } this._components[n] = c; if (this.manager) { c.init(this); @@ -7837,9 +6991,6 @@ SOFTWARE. /** * A helper function to create a new Entity with transform,movable and bounds components. * - * @param {number} x - * @param {number} y - * @param {number} a * @returns {Entity} */ static Default(x, y, a) { @@ -7858,43 +7009,6 @@ SOFTWARE. query(bound, target = []) { return this._global.query(bound, target) } - /** - * Todo - type serialization docs correctly - * @param {{}} obj - * @param {Map} compList - */ - fromJSON(obj, compList) { - let entity = this; - - obj.tags.forEach((a) => { - entity.addTag(a); - }); - for (var key in obj.comps) { - let c =new compList[key]().fromJSON(obj.comps[key]); - entity.attach(key, c); - } - return entity - } - /** - * @returns {{ - deg: number, - type:string - }} - */ - toJson() { - let obj = { - comps: {}, - tags: [] - }; - for (var key in this._components) { - obj.comps[key] = this._components[key].toJson(); - } - this._tags.forEach((a) => { - obj.tags.push(a); - }); - obj.type = this.CHAOS_OBJ_TYPE; - return obj - } } /** @@ -8050,16 +7164,19 @@ SOFTWARE. /** * List of playing sounds * - * @private - * @type Sfx[] + * @deprecated */ playing = [] /** * What to play after loading the audiobuffers. * - * @private + * @ignore */ toplay = {} + /** + * @ignore + */ + baseUrl = "" /** * Volume to resume playing when unmuted. * @@ -8072,17 +7189,13 @@ SOFTWARE. * * @private * @type AudioNode - */ + */ masterGainNode = null /** - * @type string - */ - baseUrl = "" - /** - * If the manager can play a sound. + * If the manager can play a sound. + * * @type boolean - */ - canPlay = false + */ constructor() { this.masterGainNode = this.ctx.createGain(); this.masterGainNode.connect(this.ctx.destination); @@ -8167,13 +7280,13 @@ SOFTWARE. this.playing.push(s); s.play(); } - + /** * Creates and returns an SFX. * * @param {string} name * @rerurns Sfx - */ + */ createSfx(name) { ///throw error if name is not in this. return new Sfx(this, this.sfx[name]) @@ -8209,7 +7322,7 @@ SOFTWARE. let id = this.playing.indexOf(sfx); if (id == -1) return sfx.disconnect(); - Utils$1.removeElement(this.playing, id); + Utils.removeElement(this.playing, id); } } @@ -8259,7 +7372,7 @@ SOFTWARE. /** * Accumulated force from behaviours to apply to agent */ - _accumulated = new Vector$1() + _accumulated = new Vector() /** * Adds a behavior to the manager * @@ -8275,7 +7388,7 @@ SOFTWARE. * @param {Behaviour} behaviour */ remove(behaviour) { - Utils$1.removeElement(this._behaviours, this._behaviours.indexOf(behaviour)); + Utils.removeElement(this._behaviours, this._behaviours.indexOf(behaviour)); } /** * Boots up the behavoiurs of the agent that contains it. @@ -8294,23 +7407,22 @@ SOFTWARE. * @param {number} inv_dt */ update(inv_dt) { - let result = new Vector$1(); + let result = new Vector(); this._accumulated.set(0, 0); for (let i = 0; i < this._behaviours.length; i++) { this._behaviours[i].calc(result, inv_dt); this._accumulated.add(result); } this._agent.acceleration.add(this._accumulated); - this._agent.orientation.radian = Vector$1.toRad(this._agent.velocity); + this._agent.orientation.radian = Vector.toRad(this._agent.velocity); } /** * Removes all behaviours from a manager. */ clear() { - Utils$1.clearArr(this._behaviours); + Utils.clearArr(this._behaviours); } /** - * @ignore * Used for visually debugging items. */ draw(renderer) { @@ -8410,14 +7522,15 @@ SOFTWARE. update(inv_dt) { this.behaviours.update(inv_dt); } + Entity /** - * @param {CanvasRenderingContext2D} ctx + * @param {Renderer} renderer */ - draw(ctx) { - this.behaviours.draw(ctx); + draw(renderer) { + this.behaviours.draw(renderer); } } - Utils$1.inheritComponent(Agent); + Utils.inheritComponent(Agent); /** * Base class for implementing customized behaviours. @@ -8478,7 +7591,7 @@ SOFTWARE. draw(renderer) {} } - let tmp1$4 = new Vector$1(); + let tmp1$4 = new Vector(); /** * Creates a behaviour to evade a certain position. * @@ -8525,8 +7638,8 @@ SOFTWARE. } } - let tmp1$3 = new Vector$1(), - tmp2$2 = new Vector$1(); + let tmp1$3 = new Vector(), + tmp2$2 = new Vector(); /** * Creates a behaviour that is used to make an agent wander in an organic manner. @@ -8572,12 +7685,12 @@ SOFTWARE. this._theta += rand(-this.dtheta, +this.dtheta); let forward = tmp1$3.copy(this.velocity); if (forward.equalsZero()) - Vector$1.random(forward); + Vector.random(forward); let radius = this._radius * 0.8; forward.setMagnitude(this._radius); //ctx.arc(...tmp2.copy(this.position).add(forward), radius, 0, Math.PI * 2) //ctx.stroke() - Vector$1.fromDeg(this._theta + Vector$1.toDeg(this.velocity), tmp2$2).multiply(radius); + Vector.fromDeg(this._theta + Vector.toDeg(this.velocity), tmp2$2).multiply(radius); forward.add(tmp2$2); //forward.draw(ctx,...this.position) forward.setMagnitude(this.maxSpeed); @@ -8618,33 +7731,31 @@ SOFTWARE. * not complete. * * @augments Behaviour - */ - class Flock { - /** - * @type Agent[] - */ - neighbours = [] - constructor() {} - /** - * @inheritdoc - * @param {Agent} agent - * - */ - init(agent) { - + */ + class Flock{ + constructor(){ + this.neighbours = []; } - /** - * @inheritdoc - * @param {Vector} target - * @param {number} inv_dt - * @returns Vector the first parameter - */ - calc(target,inv_dt) { - + /** + * @inheritdoc + * @param {Agent} agent + * + */ + init(){ + + } + /** + * @inheritdoc + * @param {Vector} target + * @param {number} inv_dt + * @returns Vector the first parameter + */ + calc(target){ + } } - let tmp1$2 = new Vector$1(); + let tmp1$2 = new Vector(); /** * Creates a behaviour to seek out a target and move towards it. @@ -8659,13 +7770,6 @@ SOFTWARE. * @type number */ radius = 100 - /** - * @type Vector - */ - target = null - /** - * @param {Vector} target - */ constructor(target) { super(); this.target = target; @@ -8694,8 +7798,8 @@ SOFTWARE. } } - let tmp1$1 = new Vector$1(), - tmp2$1 = new Vector$1(); + let tmp1$1 = new Vector(), + tmp2$1 = new Vector(); /** * This provides a seek behaviour which slows down when the agent approaches a target. @@ -8750,24 +7854,24 @@ SOFTWARE. } } - const tmp1 = new Vector$1(); - const tmp2 = new Vector$1(); - const tmp3 = new Vector$1(); + const tmp1 = new Vector(); + const tmp2 = new Vector(); + const tmp3 = new Vector(); /** * Creates a behaviour that follows a certain path. * * @augments Behaviour - */ + */ class PathFollowing extends Behaviour { /** * The path taken by a pathfollowing behaviour. * * @type Path - */ + */ path = null /** * @param {Path} path - */ + */ constructor(path) { super(); this.path = path; @@ -8802,7 +7906,7 @@ SOFTWARE. } /** * Removes all points on the path. - */ + */ clear() { this.path.clear(); } @@ -8818,7 +7922,7 @@ SOFTWARE. * Adds a point into the path. * * @param {Vector} point - */ + */ add(point) { this.path.add(point); } @@ -8826,7 +7930,7 @@ SOFTWARE. * If the agent should start at the beginning after reaching the ent of the path. * * @type boolean - */ + */ set loop(x) { this.path.loop = x; } @@ -8837,80 +7941,41 @@ SOFTWARE. * Sets a new path to follow. * * @param {Path} path - */ + */ setPath(path) { this.path = path; } - draw(ctx) { - ctx.beginPath(); - circle(ctx, ...this.path.point(), 4); - fill(ctx, "blue"); - ctx.closePath(); - ctx.beginPath(); - circle(ctx, ...this.path.point(), this.path.tolerance); - stroke(ctx, "blue"); - ctx.closePath(); - this.path.draw(ctx); + draw(renderer) { + renderer.begin(); + renderer.circle(...this.path.point(), 4); + renderer.fill("blue"); + renderer.close(); + renderer.begin(); + renderer.circle(...this.path.point(), this.path.tolerance); + renderer.stroke("blue"); + renderer.close(); + this.path.draw(renderer); } } - let tmp = new Vector$1(); + let tmp = new Vector(); class Path { - /** - * @private - * type Vector[] - */ _points = [] - /** - * @private - * type number - */ _index = 0 - /** - * type number - */ speed = 20 - /** - * type number - */ - tolerance = 20 - /** - * @private - * type number - */ + tolerance= 20 _lerp_t = 0 - /** - * @private - * type number - */ _lerpdist = 0 - /** - * @private - * type number[] - */ _way = [0, 1] - /** - * @private - * type boolean - */ _finished = false - /** - * @private - * type Vector - */ - _lerpedPoint = new Vector$1() - /** - * type boolean - */ + _lerpedPoint = new Vector() loop = false - /** - * @param {Vector} point - */ add(point) { this._points.push(point); return this } + clear() { this._points.length = 0; this._way[0] = 0; @@ -8920,9 +7985,6 @@ SOFTWARE. return this } - /** - * private - */ advance() { if (this._points.length < 2) return false if (this._way[1] == this._points.length - 1 && @@ -8941,10 +8003,6 @@ SOFTWARE. this._lerp_t = 0; return true } - /** - * - * @param {number} lerpdist - */ update(lerpdist = this._lerpdist) { if (this._finished) return this._lerpedPoint let dist = tmp.copy(this._points[this._way[0]]).sub(this._points[this._way[1]]).magnitude(); @@ -8953,7 +8011,7 @@ SOFTWARE. if (!this.advance()) this._finished = true; } this._lerp_t = clamp(this._lerp_t, 0, 1); - Vector$1.lerp( + Vector.lerp( this._points[this._way[0]], this._points[this._way[1]], this._lerp_t, @@ -8967,20 +8025,17 @@ SOFTWARE. this._points[this._way[1]] ] } - point() { + point(){ return this._lerpedPoint } - get path() { + get path(){ return this._points } - /** - * @param {CanvasRenderingContext2D} ctx - */ - draw(ctx) { - ctx.beginPath(); - vertices(ctx, this._points, this.loop); - stroke(ctx, "lightgreen"); - ctx.closePath(); + draw(renderer){ + renderer.begin(); + renderer.vertices(this._points,this.loop); + renderer.stroke("lightgreen"); + renderer.close(); } } @@ -9111,13 +8166,10 @@ SOFTWARE. exports.Behaviour = Behaviour; exports.Body = Body; exports.BodySprite = BodySprite; - exports.Bound = Bound; exports.BoundingBox = BoundingBox; exports.BoundingCircle = BoundingCircle; exports.Box = Box; exports.BufferGeometry = BufferGeometry; - exports.CamController = CamController; - exports.Camera = Camera; exports.Circle = Circle; exports.CircleGeometry = CircleGeometry; exports.Clock = Clock; @@ -9127,19 +8179,21 @@ SOFTWARE. exports.Cookies = Cookies; exports.DEVICE = DEVICE; exports.DOMEventHandler = DOMEventHandler; + exports.DebugMesh = DebugMesh; exports.DistanceConstraint = DistanceConstraint; - exports.Easing = Easing; exports.Entity = Entity; - exports.Err = Err$1; + exports.Err = Err; exports.EvadeBehaviour = EvadeBehaviour; exports.EventDispatcher = EventDispatcher; exports.Events = Events; exports.Flock = Flock; exports.Geometry = Geometry; - exports.Group = Group; + exports.Grid = Grid; + exports.HeightMap = HeightMap; + exports.ImageSprite = ImageSprite; exports.Input = Input; - exports.Interpolation = Interpolation; exports.Keyboard = Keyboard; + exports.Layer = Layer; exports.Line = Line; exports.Loader = Loader; exports.Manager = Manager; @@ -9150,8 +8204,9 @@ SOFTWARE. exports.Movable = Movable; exports.NaiveBroadphase = NaiveBroadphase; exports.Overlaps = Overlaps; + exports.ParallaxBackground = ParallaxBackground; exports.Particle = Particle; - exports.ParticleSystemSprite = ParticleSystemSprite; + exports.ParticleSystemSprite = System$1; exports.Path = Path; exports.PathFollowing = PathFollowing; exports.Pursuit = Pursuit; @@ -9165,88 +8220,30 @@ SOFTWARE. exports.Shape = Shape; exports.SpringConstraint = SpringConstraint; exports.Sprite = Sprite; - exports.SpriteMaterial = SpriteMaterial; - exports.StaticImageMaterial = StaticImageMaterial; + exports.StaticImageSprite = StaticImageSprite; exports.Storage = Storage; exports.System = System; exports.Touch = Touch; exports.Transform = Transform; exports.Triangle = Triangle; - exports.Utils = Utils$1; - exports.Vector = Vector$1; + exports.Utils = Utils; + exports.Vector = Vector; exports.WanderBehaviour = WanderBehaviour; exports.WebGLRenderer = WebGLRenderer; exports.WebGPURenderer = WebGPURenderer; exports.World = World; - exports.arc = arc; - exports.circle = circle; exports.clamp = clamp; exports.defaultCollisionHandler = defaultCollisionHandler; exports.defaultPrecollisionHandler = defaultPrecollisionHandler; exports.degToRad = degToRad; - exports.drawImage = drawImage; exports.exp = exp; - exports.fill = fill; - exports.fillText = fillText; exports.lerp = lerp; - exports.line = line; exports.map = map; exports.naturalizePair = naturalizePair; exports.radToDeg = radToDeg; exports.rand = rand; - exports.rect = rect; exports.round = round; exports.sq = sq; exports.sqrt = sqrt; - exports.stroke = stroke; - exports.vertices = vertices; - exports.wrapAngle = wrapAngle; })); -/** - * @typedef Bounds - * @property {Vector_like} max - * @property {Vector_like} min - *//** - * @typedef CollisionPair - * @property {Body} a - * @property {Body} b -*/ - -/** - * @typedef Manifold - * @property {Body} bodyA - * @property {Body} bodyB - * @property {ContactManifold} contactData - * @property {number} stmp - * @property {number} impulse - * @property {boolean} persistent - * @property {Vector} ca1 - * @property {Vector} ca2 - * @property {number} restitution - * @property {number} staticFriction - * @property {number} kineticFriction - * @property {Vector} velA - * @property {Vector} velB - * @property {number} rotA - * @property {number} rotB - */ - -/** - * @typedef ContactManifold - * @property {number} lastOverlap - * @property {number} overlap=-Infinity - * @property {boolean} done=false - * @property {Vector} axis - * @property {Vector[]} verticesA - * @property {Vector[]} verticesB - * @property {Shape} vertShapeA - * @property {Shape} vertShapeB - * @property {number} contactNo - * @property {number} indexA - * @property {number} indexB - *//** - * @typedef Vector_like - * @property {number} x - * @property {number} y - */ \ No newline at end of file diff --git a/docs/AI_agent.js.html b/docs/AI_agent.js.html index eeafc287..2851f0a7 100644 --- a/docs/AI_agent.js.html +++ b/docs/AI_agent.js.html @@ -121,11 +121,12 @@

Source: AI/agent.js

update(inv_dt) { this.behaviours.update(inv_dt) } + Entity /** - * @param {CanvasRenderingContext2D} ctx + * @param {Renderer} renderer */ - draw(ctx) { - this.behaviours.draw(ctx) + draw(renderer) { + this.behaviours.draw(renderer) } } Utils.inheritComponent(Agent) @@ -141,13 +142,13 @@

Source: AI/agent.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviourManager.js.html b/docs/AI_behaviourManager.js.html index e79f65ab..493de08b 100644 --- a/docs/AI_behaviourManager.js.html +++ b/docs/AI_behaviourManager.js.html @@ -95,7 +95,6 @@

Source: AI/behaviourManager.js

Utils.clearArr(this._behaviours) } /** - * @ignore * Used for visually debugging items. */ draw(renderer) { @@ -114,13 +113,13 @@

Source: AI/behaviourManager.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_arrive.js.html b/docs/AI_behaviours_arrive.js.html index c48aae2b..996ca81c 100644 --- a/docs/AI_behaviours_arrive.js.html +++ b/docs/AI_behaviours_arrive.js.html @@ -97,13 +97,13 @@

Source: AI/behaviours/arrive.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_behaviour.js.html b/docs/AI_behaviours_behaviour.js.html index 7502d998..8cea9704 100644 --- a/docs/AI_behaviours_behaviour.js.html +++ b/docs/AI_behaviours_behaviour.js.html @@ -96,13 +96,13 @@

Source: AI/behaviours/behaviour.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_evade.js.html b/docs/AI_behaviours_evade.js.html index 507f5993..1cb0f37a 100644 --- a/docs/AI_behaviours_evade.js.html +++ b/docs/AI_behaviours_evade.js.html @@ -89,13 +89,13 @@

Source: AI/behaviours/evade.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_flocking.js.html b/docs/AI_behaviours_flocking.js.html index 6da251cf..ee3cbb44 100644 --- a/docs/AI_behaviours_flocking.js.html +++ b/docs/AI_behaviours_flocking.js.html @@ -26,7 +26,7 @@

Source: AI/behaviours/flocking.js

-
import { Behaviour } from "./behaviour.js"
+            
import {Behaviour} from "./behaviour.js"
 import { Vector } from "../../math/index.js"
 
 
@@ -34,33 +34,31 @@ 

Source: AI/behaviours/flocking.js

* not complete. * * @augments Behaviour - */ -class Flock { - /** - * @type Agent[] - */ - neighbours = [] - constructor() {} - /** - * @inheritdoc - * @param {Agent} agent - * - */ - init(agent) { - +*/ +class Flock{ + constructor(){ + this.neighbours = [] } - /** - * @inheritdoc - * @param {Vector} target - * @param {number} inv_dt - * @returns Vector the first parameter - */ - calc(target,inv_dt) { - + /** + * @inheritdoc + * @param {Agent} agent + * + */ + init(){ + + } + /** + * @inheritdoc + * @param {Vector} target + * @param {number} inv_dt + * @returns Vector the first parameter + */ + calc(target){ + } } -export { +export{ Flock }
@@ -72,13 +70,13 @@

Source: AI/behaviours/flocking.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_path.js.html b/docs/AI_behaviours_path.js.html index 8f161012..6247648d 100644 --- a/docs/AI_behaviours_path.js.html +++ b/docs/AI_behaviours_path.js.html @@ -28,7 +28,7 @@

Source: AI/behaviours/path.js

import { Behaviour } from "./behaviour.js"
 import { Vector, clamp, map } from "../../math/index.js"
-import { circle, fill, stroke } from "../../render/index.js"
+
 const tmp1 = new Vector()
 const tmp2 = new Vector()
 const tmp3 = new Vector()
@@ -36,17 +36,17 @@ 

Source: AI/behaviours/path.js

* Creates a behaviour that follows a certain path. * * @augments Behaviour - */ +*/ export class PathFollowing extends Behaviour { /** * The path taken by a pathfollowing behaviour. * * @type Path - */ + */ path = null /** * @param {Path} path - */ + */ constructor(path) { super() this.path = path @@ -81,7 +81,7 @@

Source: AI/behaviours/path.js

} /** * Removes all points on the path. - */ + */ clear() { this.path.clear() } @@ -97,7 +97,7 @@

Source: AI/behaviours/path.js

* Adds a point into the path. * * @param {Vector} point - */ + */ add(point) { this.path.add(point) } @@ -105,7 +105,7 @@

Source: AI/behaviours/path.js

* If the agent should start at the beginning after reaching the ent of the path. * * @type boolean - */ + */ set loop(x) { this.path.loop = x } @@ -116,20 +116,20 @@

Source: AI/behaviours/path.js

* Sets a new path to follow. * * @param {Path} path - */ + */ setPath(path) { this.path = path } - draw(ctx) { - ctx.beginPath() - circle(ctx, ...this.path.point(), 4) - fill(ctx, "blue") - ctx.closePath() - ctx.beginPath() - circle(ctx, ...this.path.point(), this.path.tolerance) - stroke(ctx, "blue") - ctx.closePath() - this.path.draw(ctx) + draw(renderer) { + renderer.begin() + renderer.circle(...this.path.point(), 4) + renderer.fill("blue") + renderer.close() + renderer.begin() + renderer.circle(...this.path.point(), this.path.tolerance) + renderer.stroke("blue") + renderer.close() + this.path.draw(renderer) } }
@@ -141,13 +141,13 @@

Source: AI/behaviours/path.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_pursuit.js.html b/docs/AI_behaviours_pursuit.js.html index 367cf8ff..73e6ef2a 100644 --- a/docs/AI_behaviours_pursuit.js.html +++ b/docs/AI_behaviours_pursuit.js.html @@ -69,13 +69,13 @@

Source: AI/behaviours/pursuit.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_seek.js.html b/docs/AI_behaviours_seek.js.html index 5cfef242..6579d446 100644 --- a/docs/AI_behaviours_seek.js.html +++ b/docs/AI_behaviours_seek.js.html @@ -45,13 +45,6 @@

Source: AI/behaviours/seek.js

* @type number */ radius = 100 - /** - * @type Vector - */ - target = null - /** - * @param {Vector} target - */ constructor(target) { super() this.target = target @@ -92,13 +85,13 @@

Source: AI/behaviours/seek.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_behaviours_wandering.js.html b/docs/AI_behaviours_wandering.js.html index d624b696..dd856070 100644 --- a/docs/AI_behaviours_wandering.js.html +++ b/docs/AI_behaviours_wandering.js.html @@ -103,13 +103,13 @@

Source: AI/behaviours/wandering.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_manager.js.html b/docs/AI_manager.js.html index 7dd82882..afdd1822 100644 --- a/docs/AI_manager.js.html +++ b/docs/AI_manager.js.html @@ -65,13 +65,13 @@

Source: AI/manager.js


- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AI_paths_path.js.html b/docs/AI_paths_path.js.html deleted file mode 100644 index 19d141d2..00000000 --- a/docs/AI_paths_path.js.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - JSDoc: Source: AI/paths/path.js - - - - - - - - - - -
- -

Source: AI/paths/path.js

- - - - - - -
-
-
import { Vector, clamp } from "../../math/index.js"
-import { vertices, fill, stroke } from "../../render/index.js"
-
-let tmp = new Vector()
-export class Path {
-  /**
-   * @private
-   * type Vector[]
-   */
-  _points = []
-  /**
-   * @private
-   * type number 
-   */
-  _index = 0
-  /**
-   * type number 
-   */
-  speed = 20
-  /**
-   * type number 
-   */
-  tolerance = 20
-  /**
-   * @private
-   * type number 
-   */
-  _lerp_t = 0
-  /**
-   * @private
-   * type number 
-   */
-  _lerpdist = 0
-  /**
-   * @private
-   * type number[]
-   */
-  _way = [0, 1]
-  /**
-   * @private
-   * type boolean 
-   */
-  _finished = false
-  /**
-   * @private
-   * type Vector 
-   */
-  _lerpedPoint = new Vector()
-  /**
-   * type boolean 
-   */
-  loop = false
-  /**
-   * @param {Vector} point
-   */
-  add(point) {
-    this._points.push(point)
-
-    return this
-  }
-  clear() {
-    this._points.length = 0
-    this._way[0] = 0
-    this._way[1] = 0
-    this._lerp_t = 0
-    this._finished = false
-
-    return this
-  }
-  /**
-   * private
-   */
-  advance() {
-    if (this._points.length < 2) return false
-    if (this._way[1] == this._points.length - 1 &&
-      !this.loop) return false
-    if (
-      this._way[1] == this._points.length - 1 &&
-      this.loop
-    ) {
-      this._way[0] = this._points.length - 1
-      this._way[1] = 0
-      this._lerp_t = 0
-      return true
-    }
-    this._way[0] = this._way[1]
-    this._way[1] += 1
-    this._lerp_t = 0
-    return true
-  }
-  /**
-   * 
-   * @param {number} lerpdist
-   */
-  update(lerpdist = this._lerpdist) {
-    if (this._finished) return this._lerpedPoint
-    let dist = tmp.copy(this._points[this._way[0]]).sub(this._points[this._way[1]]).magnitude()
-    let current = lerpdist / dist
-    this._lerp_t = (this.speed + lerpdist) / dist
-    if (this._lerp_t > 1 && (dist - lerpdist) < this.tolerance) {
-      if (!this.advance()) this._finished = true
-    }
-    this._lerp_t = clamp(this._lerp_t, 0, 1)
-    Vector.lerp(
-      this._points[this._way[0]],
-      this._points[this._way[1]],
-      this._lerp_t,
-      this._lerpedPoint
-    )
-    return this._lerpedPoint
-  }
-  current() {
-    return [
-      this._points[this._way[0]],
-      this._points[this._way[1]]
-      ]
-  }
-  point() {
-    return this._lerpedPoint
-  }
-  get path() {
-    return this._points
-  }
-  /**
-   * @param {CanvasRenderingContext2D} ctx
-   */
-  draw(ctx) {
-    ctx.beginPath()
-    vertices(ctx, this._points, this.loop)
-    stroke(ctx, "lightgreen")
-    ctx.closePath()
-  }
-}
-
-
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - diff --git a/docs/Agent.html b/docs/Agent.html index 3d50c29f..de50fae8 100644 --- a/docs/Agent.html +++ b/docs/Agent.html @@ -870,7 +870,7 @@
Parameters:
-

draw(ctx)

+

draw(renderer)

@@ -910,13 +910,13 @@
Parameters:
- ctx + renderer -CanvasRenderingContext2D +Renderer @@ -967,7 +967,7 @@
Parameters:
Source:
@@ -1111,7 +1111,7 @@
Parameters:
Source:
@@ -1392,7 +1392,7 @@
Parameters:
Source:
@@ -1438,13 +1438,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AgentManager.html b/docs/AgentManager.html index 93b6159e..c821d30f 100644 --- a/docs/AgentManager.html +++ b/docs/AgentManager.html @@ -509,13 +509,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AgentSprite.html b/docs/AgentSprite.html deleted file mode 100644 index fbdffa7c..00000000 --- a/docs/AgentSprite.html +++ /dev/null @@ -1,774 +0,0 @@ - - - - - JSDoc: Class: AgentSprite - - - - - - - - - - -
- -

Class: AgentSprite

- - - - - - -
- -
- -

AgentSprite()

- -
Used for debugging agents.
- - -
- -
-
- - - - -

Constructor

- - - -

new AgentSprite()

- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - -

Extends

- - - - - - - - - - - - -

Classes

- -
-
AgentSprite
-
-
- - - - - - - - - -

Members

- - - -

angle :number

- - - - -
- Angle in degrees -
- - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

orientation :Angle

- - - - -
- Orientation of the sprite -
- - - -
Type:
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

parent :Group|null

- - - - - - -
Type:
-
    -
  • - -Group -| - -null - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

position :Vector

- - - - -
- World space position. -
- - - -
Type:
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - -

init(entity)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
entity - - -Entity - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

render(ctx)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
ctx - - -CanvasRenderingContext2D - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/Angle.html b/docs/Angle.html index 12595b1a..48cd1642 100644 --- a/docs/Angle.html +++ b/docs/Angle.html @@ -213,142 +213,6 @@

Members

-

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

degree

@@ -393,7 +257,7 @@

degreeSource:
@@ -455,7 +319,7 @@

radianSource:
@@ -584,91 +448,7 @@
Parameters:
Source:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

toJson()

- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
@@ -693,12 +473,6 @@

toJsonReturns:

- - - - - @@ -720,13 +494,13 @@
Returns:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/ArriveBehaviour.html b/docs/ArriveBehaviour.html index f37c1348..f5ef4493 100644 --- a/docs/ArriveBehaviour.html +++ b/docs/ArriveBehaviour.html @@ -1129,13 +1129,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/AudioHandler.html b/docs/AudioHandler.html index 61d4e010..09bfd0da 100644 --- a/docs/AudioHandler.html +++ b/docs/AudioHandler.html @@ -52,6 +52,10 @@

new Audio +
+ If the manager can play a sound. +
+ @@ -143,95 +147,17 @@

Members

-

baseUrl :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

canPlay :boolean

+

playing

- If the manager can play a sound. + List of playing sounds
-
Type:
-
    -
  • - -boolean - - -
  • -
- @@ -253,6 +179,8 @@
Type:
+
Deprecated:
  • Yes
+ @@ -265,7 +193,7 @@
Type:
Source:
@@ -394,7 +322,7 @@
Parameters:
Source:
@@ -531,7 +459,7 @@
Parameters:
Source:
@@ -668,7 +596,7 @@
Parameters:
Source:
@@ -756,7 +684,7 @@

muteSource:
@@ -844,7 +772,7 @@

pauseAllSource:
@@ -981,7 +909,7 @@
Parameters:
Source:
@@ -1212,7 +1140,7 @@
Parameters:
Source:
@@ -1349,7 +1277,7 @@
Parameters:
Source:
@@ -1437,7 +1365,7 @@

unmuteSource:
@@ -1483,13 +1411,13 @@

unmute
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/Ball.html b/docs/Ball.html index 1ebf8b4c..4d8f95cb 100644 --- a/docs/Ball.html +++ b/docs/Ball.html @@ -203,166 +203,6 @@

Members

-

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

DYNAMIC :number

@@ -422,7 +262,7 @@
Type:
Source:
@@ -499,7 +339,7 @@
Type:
Source:
@@ -576,7 +416,7 @@
Type:
Source:
@@ -735,7 +575,7 @@
Type:
Source:
@@ -894,7 +734,7 @@
Type:
Source:
@@ -971,7 +811,7 @@
Type:
Source:
@@ -1457,7 +1297,7 @@
Type:
Source:
@@ -1780,7 +1620,7 @@
Type:
Source:
@@ -2254,7 +2094,7 @@
Type:
Source:
@@ -2331,7 +2171,7 @@
Type:
Source:
@@ -2485,7 +2325,7 @@
Type:
Source:
@@ -2644,7 +2484,7 @@
Type:
Source:
@@ -3033,7 +2873,7 @@
Type:
Source:
@@ -3222,7 +3062,7 @@
Parameters:
Source:
@@ -3365,7 +3205,7 @@
Parameters:
Source:
@@ -3580,7 +3420,7 @@
Parameters:
Source:
@@ -3805,7 +3645,7 @@
Parameters:
Source:
@@ -3947,7 +3787,7 @@
Parameters:
Source:
@@ -4065,7 +3905,7 @@

updateSource:
@@ -4111,13 +3951,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/BasicMaterial.html b/docs/BasicMaterial.html deleted file mode 100644 index a255b4aa..00000000 --- a/docs/BasicMaterial.html +++ /dev/null @@ -1,586 +0,0 @@ - - - - - JSDoc: Class: BasicMaterial - - - - - - - - - - -
- -

Class: BasicMaterial

- - - - - - -
- -
- -

BasicMaterial()

- - -
- -
-
- - - - - - -

new BasicMaterial()

- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -

Members

- - - -

fill :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
Default Value:
-
    -
  • "white"
  • -
- - - -
Source:
-
- - - - - - - -
- - - - - - - - -

stroke :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
Default Value:
-
    -
  • "black"
  • -
- - - -
Source:
-
- - - - - - - -
- - - - - - - - -

wireframe :boolean

- - - - - - -
Type:
-
    -
  • - -boolean - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
Default Value:
-
    -
  • false
  • -
- - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - -

render(ctx, dt, path)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
ctx - - -CanvasRenderingContext2D - - - -
dt - - -number - - - -
path - - -Path2D - - - -
- - - - - - -
- - - - - - - - - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/Behaviour.html b/docs/Behaviour.html index df94b49c..50f3f70e 100644 --- a/docs/Behaviour.html +++ b/docs/Behaviour.html @@ -957,13 +957,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/BehaviourManager.html b/docs/BehaviourManager.html index 9d35ad37..f0673dd1 100644 --- a/docs/BehaviourManager.html +++ b/docs/BehaviourManager.html @@ -506,6 +506,94 @@

cleardraw()

+ + + + + + +
+ Used for visually debugging items. +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + @@ -933,13 +1021,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/Body.html b/docs/Body.html index fdaa6233..dfdec965 100644 --- a/docs/Body.html +++ b/docs/Body.html @@ -211,156 +211,6 @@

Members

-

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

DYNAMIC :number

@@ -415,7 +265,7 @@
Type:
Source:
@@ -487,7 +337,7 @@
Type:
Source:
@@ -559,7 +409,7 @@
Type:
Source:
@@ -708,7 +558,7 @@
Type:
Source:
@@ -857,7 +707,7 @@
Type:
Source:
@@ -929,7 +779,7 @@
Type:
Source:
@@ -1385,7 +1235,7 @@
Type:
Source:
@@ -1688,7 +1538,7 @@
Type:
Source:
@@ -2132,7 +1982,7 @@
Type:
Source:
@@ -2204,7 +2054,7 @@
Type:
Source:
@@ -2348,7 +2198,7 @@
Type:
Source:
@@ -2497,7 +2347,7 @@
Type:
Source:
@@ -2861,7 +2711,7 @@
Type:
Source:
@@ -3045,7 +2895,7 @@
Parameters:
Source:
@@ -3183,7 +3033,7 @@
Parameters:
Source:
@@ -3393,7 +3243,7 @@
Parameters:
Source:
@@ -3613,7 +3463,7 @@
Parameters:
Source:
@@ -3750,7 +3600,7 @@
Parameters:
Source:
@@ -3863,7 +3713,7 @@

updateSource:
@@ -3909,13 +3759,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/BodySprite.html b/docs/BodySprite.html index 413cb661..610568b1 100644 --- a/docs/BodySprite.html +++ b/docs/BodySprite.html @@ -30,8 +30,6 @@

Class: BodySprite

BodySprite(optionsopt)

-
This draws a body from the physics System.
- @@ -41,8 +39,6 @@

BodySprite< -

Constructor

-

new BodySprite(optionsopt)

@@ -270,7 +266,7 @@
Properties
Source:
@@ -304,17 +300,6 @@
Properties
-

Extends

- - - - - - - - @@ -331,83 +316,6 @@

Members

-

angle :number

- - - - -
- Angle in degrees -
- - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

drawBounds :boolean

@@ -462,7 +370,7 @@
Type:
Source:
@@ -534,237 +442,7 @@
Type:
Source:
- - - - - - - -

- - - - - - - - -

orientation :Angle

- - - - -
- Orientation of the sprite -
- - - -
Type:
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

parent :Group|null

- - - - - - -
Type:
-
    -
  • - -Group -| - -null - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

position :Vector

- - - - -
- World space position. -
- - - -
Type:
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
@@ -792,7 +470,7 @@

Methods

-

init(entity)

+

(package) init(parent)

@@ -832,7 +510,7 @@
Parameters:
- entity + parent @@ -866,167 +544,6 @@
Parameters:
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

render(ctx, dt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
ctx - - -CanvasRenderingContext2D - - - -
dt - - -number - - - -
- - - - - - -
- - - - - @@ -1050,7 +567,7 @@
Parameters:
Source:
@@ -1096,13 +613,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/Bound.html b/docs/Bound.html index 7f1f3a71..b8e9dd17 100644 --- a/docs/Bound.html +++ b/docs/Bound.html @@ -319,13 +319,13 @@
Type:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/BoundingBox.html b/docs/BoundingBox.html index 2b14a552..e84603f3 100644 --- a/docs/BoundingBox.html +++ b/docs/BoundingBox.html @@ -558,7 +558,7 @@

Methods

-

calculateBounds(body, padding)

+

calculateBounds(body)

@@ -592,8 +592,6 @@
Parameters:
- Default - Description @@ -619,44 +617,11 @@
Parameters:
- - - - Body to calculate max and min from - - - - padding - - - - - -Number - - - - - - - - - - - 0 - - - - - increases the size of the bounds - - - @@ -694,7 +659,7 @@
Parameters:
Source:
@@ -782,7 +747,7 @@

cloneSource:
@@ -929,7 +894,7 @@
Parameters:
Source:
@@ -965,7 +930,7 @@
Parameters:
-

intersects(bound)

+

intersects(bound, bound)

@@ -1015,6 +980,29 @@
Parameters:
+BoundingBox + + + + + + + + + + the bound to check intersection with + + + + + + + bound + + + + + BoundingCircle | @@ -1069,7 +1057,7 @@
Parameters:
Source:
@@ -1094,16 +1082,6 @@
Parameters:
-
Returns:
- - -
- boolean -
- - - - @@ -1216,7 +1194,7 @@
Parameters:
Source:
@@ -1399,7 +1377,7 @@
Parameters:
Source:
@@ -1455,13 +1433,13 @@
Returns:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/BoundingCircle.html b/docs/BoundingCircle.html index 66571b3f..d8fd6dbe 100644 --- a/docs/BoundingCircle.html +++ b/docs/BoundingCircle.html @@ -466,7 +466,7 @@
Parameters:
Source:
@@ -502,7 +502,7 @@
Parameters:
-

intersects(bound)

+

intersects(bound, bound)

@@ -552,6 +552,29 @@
Parameters:
+BoundingBox + + + + + + + + + + the bound to check intersection with + + + + + + + bound + + + + + BoundingCircle | @@ -606,7 +629,7 @@
Parameters:
Source:
@@ -642,7 +665,7 @@
Parameters:
-

update(pos)

+

update()

@@ -661,55 +684,6 @@

updateParameters:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
pos - - -Vector_like - - - -
- - @@ -789,13 +763,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/Box.html b/docs/Box.html index 6fec7333..62a5d341 100644 --- a/docs/Box.html +++ b/docs/Box.html @@ -226,166 +226,6 @@

Members

-

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - -
Implements:
-
- - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

DYNAMIC :number

@@ -445,7 +285,7 @@
Type:
Source:
@@ -522,7 +362,7 @@
Type:
Source:
@@ -599,7 +439,7 @@
Type:
Source:
@@ -758,7 +598,7 @@
Type:
Source:
@@ -917,7 +757,7 @@
Type:
Source:
@@ -994,7 +834,7 @@
Type:
Source:
@@ -1480,7 +1320,7 @@
Type:
Source:
@@ -1803,7 +1643,7 @@
Type:
Source:
@@ -2277,7 +2117,7 @@
Type:
Source:
@@ -2354,7 +2194,7 @@
Type:
Source:
@@ -2508,7 +2348,7 @@
Type:
Source:
@@ -2667,7 +2507,7 @@
Type:
Source:
@@ -3056,7 +2896,7 @@
Type:
Source:
@@ -3245,7 +3085,7 @@
Parameters:
Source:
@@ -3388,7 +3228,7 @@
Parameters:
Source:
@@ -3603,7 +3443,7 @@
Parameters:
Source:
@@ -3828,7 +3668,7 @@
Parameters:
Source:
@@ -3970,7 +3810,7 @@
Parameters:
Source:
@@ -4088,7 +3928,7 @@

updateSource:
@@ -4134,13 +3974,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/Broadphase.html b/docs/Broadphase.html index 71edb98d..96b6ec52 100644 --- a/docs/Broadphase.html +++ b/docs/Broadphase.html @@ -1162,13 +1162,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/BufferGeometry_BufferGeometry.html b/docs/BufferGeometry_BufferGeometry.html deleted file mode 100644 index 544251db..00000000 --- a/docs/BufferGeometry_BufferGeometry.html +++ /dev/null @@ -1,215 +0,0 @@ - - - - - JSDoc: Class: BufferGeometry - - - - - - - - - - -
- -

Class: BufferGeometry

- - - - - - -
- -
- -

BufferGeometry(vertices)

- - -
- -
-
- - - - - - -

new BufferGeometry(vertices)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
vertices - - -Array.<Vector> - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/CamController_CamController.html b/docs/CamController_CamController.html deleted file mode 100644 index 1ffaf1b3..00000000 --- a/docs/CamController_CamController.html +++ /dev/null @@ -1,215 +0,0 @@ - - - - - JSDoc: Class: CamController - - - - - - - - - - -
- -

Class: CamController

- - - - - - -
- -
- -

CamController(camera)

- - -
- -
-
- - - - - - -

new CamController(camera)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
camera - - -Camera - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/Circle.html b/docs/Circle.html index 6fd4b019..6b3b50f2 100644 --- a/docs/Circle.html +++ b/docs/Circle.html @@ -249,152 +249,6 @@

Members

-

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

area :number

@@ -454,7 +308,7 @@
Type:
Source:
@@ -472,7 +326,7 @@
Type:
-

geometry :Geometry

+

geometry :Geometry

@@ -487,7 +341,7 @@
Type:

- - - - - - - - - - - - - - - - - - - - - - - - - - -

update(dt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
dt - - -number - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
@@ -1578,13 +707,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/Composite.html b/docs/Composite.html index 2d15c8d5..e2d70e7a 100644 --- a/docs/Composite.html +++ b/docs/Composite.html @@ -341,7 +341,7 @@
Type:
Source:
@@ -557,7 +557,7 @@
Type:
Source:
@@ -704,7 +704,7 @@
Type:
Source:
@@ -776,7 +776,7 @@
Type:
Source:
@@ -920,7 +920,7 @@
Type:
Source:
@@ -1417,13 +1417,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/Constraint.html b/docs/Constraint.html index a3727ddc..caed3f5b 100644 --- a/docs/Constraint.html +++ b/docs/Constraint.html @@ -270,142 +270,6 @@

Members

-

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

(package) physicsType :number

@@ -635,7 +499,7 @@
Parameters:
Source:
@@ -772,7 +636,7 @@
Parameters:
Source:
@@ -818,13 +682,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/DOMEventHandler.html b/docs/DOMEventHandler.html index 4b94d70e..0e616b3f 100644 --- a/docs/DOMEventHandler.html +++ b/docs/DOMEventHandler.html @@ -727,13 +727,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/DistanceConstraint.html b/docs/DistanceConstraint.html index 07221970..5a5319de 100644 --- a/docs/DistanceConstraint.html +++ b/docs/DistanceConstraint.html @@ -456,13 +456,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/Entity.html b/docs/Entity.html index 24b69231..dff2b5d5 100644 --- a/docs/Entity.html +++ b/docs/Entity.html @@ -684,166 +684,6 @@

destroyfromJSON(obj, compList)

- - - - - - -
- Todo - type serialization docs correctly -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
obj - - -Object - - - -
compList - - -Map.<string, function()> - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - @@ -1770,7 +1610,7 @@
Parameters:
Source:
@@ -2429,108 +2269,6 @@
Parameters:
- - - - - - -

toJson() → {Object}

- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Object - - -
-
- - - - - - - @@ -2674,7 +2412,7 @@
Parameters:
-

(static) Default(x, y, a) → {Entity}

+

(static) Default() → {Entity}

@@ -2693,101 +2431,6 @@

(static) Defa -

Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
x - - -number - - - -
y - - -number - - - -
a - - -number - - - -
- - @@ -2821,7 +2464,7 @@
Parameters:
Source:
@@ -2885,13 +2528,13 @@
Returns:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/EulerSolver.html b/docs/EulerSolver.html index d3404416..e55d5cf2 100644 --- a/docs/EulerSolver.html +++ b/docs/EulerSolver.html @@ -316,13 +316,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/EvadeBehaviour.html b/docs/EvadeBehaviour.html index dda2230a..875bf7f4 100644 --- a/docs/EvadeBehaviour.html +++ b/docs/EvadeBehaviour.html @@ -1129,13 +1129,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time)
diff --git a/docs/EventDispatcher.html b/docs/EventDispatcher.html index fa2a187a..10b4f914 100644 --- a/docs/EventDispatcher.html +++ b/docs/EventDispatcher.html @@ -568,13 +568,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Flock.html b/docs/Flock.html index 76530fc8..66415208 100644 --- a/docs/Flock.html +++ b/docs/Flock.html @@ -375,74 +375,6 @@
Type:
-

neighbours :Array.<Agent>

- - - - - - -
Type:
-
    -
  • - -Array.<Agent> - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

position :Vector

@@ -1076,13 +1008,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Geometry.html b/docs/Geometry.html deleted file mode 100644 index e24f95fb..00000000 --- a/docs/Geometry.html +++ /dev/null @@ -1,898 +0,0 @@ - - - - - JSDoc: Class: Geometry - - - - - - - - - - -
- -

Class: Geometry

- - - - - - -
- -
- -

Geometry(vertices)

- - -
- -
-
- - - - - - -

new Geometry(vertices)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
vertices - - -Array.<Vector> - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -

Members

- - - -

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

_dynNormals :Array.<Vector>

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

normals :Array.<Vector>

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

vertices :Array.<Vector>

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - -

getNormals(rad, target)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
rad - - -number - - - -
target - - -Array.<Vector> - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

transform(n, vertices, pos)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
n - - -number - - - -
vertices - - -Array.<Vector> - - - -
pos - - -Vector - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/Grid.html b/docs/Grid.html index 87b5eba0..8e0b30f2 100644 --- a/docs/Grid.html +++ b/docs/Grid.html @@ -1197,13 +1197,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Group.html b/docs/Group.html deleted file mode 100644 index 4dbaa580..00000000 --- a/docs/Group.html +++ /dev/null @@ -1,1278 +0,0 @@ - - - - - JSDoc: Class: Group - - - - - - - - - - -
- -

Class: Group

- - - - - - -
- -
- -

Group(sprites)

- -
Used for grouping similar.
- - -
- -
-
- - - - -

Constructor

- - - -

new Group(sprites)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
sprites - - -Array.<Sprite> - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - -

Extends

- - - - - - - - - - - - -

Classes

- -
-
Group
-
-
- - - - - - - - - -

Members

- - - -

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

angle :number

- - - - -
- Angle in degrees -
- - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

orientation :Angle

- - - - -
- Orientation of the sprite -
- - - -
Type:
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

position :Vector

- - - - -
- World space position. -
- - - -
Type:
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - -

add(sprite)

- - - - - - -
- Adds another sprite to this one -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
sprite - - -Sprite -| - -Group - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

init(entity)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
entity - - -Entity - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

remove(sprite, recursiveopt, indexopt)

- - - - - - -
- Removes another sprite to this one -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDefaultDescription
sprite - - -Sprite -| - -Group - - - - - - - - - - - -
recursive - - -boolean - - - - - - <optional>
- - - - - -
- - false - -
index - - -number - - - - - - <optional>
- - - - - -
- -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

render(ctx, dt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
ctx - - -CanvasRenderingContext2D - - - -
dt - - -number - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/Input.html b/docs/Input.html index 99ba28bf..4a0b3969 100644 --- a/docs/Input.html +++ b/docs/Input.html @@ -664,13 +664,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Keyboard.html b/docs/Keyboard.html index 60d0cea0..672bd5aa 100644 --- a/docs/Keyboard.html +++ b/docs/Keyboard.html @@ -375,7 +375,7 @@
Parameters:
Source:
@@ -421,13 +421,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Line.html b/docs/Line.html deleted file mode 100644 index f9dd2f95..00000000 --- a/docs/Line.html +++ /dev/null @@ -1,333 +0,0 @@ - - - - - JSDoc: Class: Line - - - - - - - - - - -
- -

Class: Line

- - - - - - -
- -
- -

Line(length, offset, pffsetAngle)

- - -
- -
-
- - - - - - -

new Line(length, offset, pffsetAngle)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
length - - -number - - - -
offset - - -Vector - - - -
pffsetAngle - - -number - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -

Members

- - - -

length :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/Manager.html b/docs/Manager.html index 4a0a21ec..769f1659 100644 --- a/docs/Manager.html +++ b/docs/Manager.html @@ -1242,6 +1242,114 @@

clearclone() → {Entity}

+ + + + + + +
+ Deep copies an entity +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
Deprecated:
  • Yes
+ + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Entity + + +
+
+ + + + + + + @@ -1349,7 +1457,7 @@
Parameters:
Source:
@@ -1407,7 +1515,7 @@
Returns:
-

getEntitiesByComponents(comps, entitiesopt, targetopt) → {Array.<Entity>}

+

getEntitiesByComponents(comps, entitiesopt) → {Array.<Entity>}

@@ -1526,43 +1634,6 @@
Parameters:
- - - - target - - - - - -Array.<Entity> - - - - - - - - - <optional>
- - - - - - - - - - - - - - - - - - @@ -1654,7 +1725,7 @@
Returns:
-

getEntitiesByTags(tags, entitiesopt, target) → {Array.<Entity>}

+

getEntitiesByTags(tags, entitiesopt) → {Array.<Entity>}

@@ -1773,41 +1844,6 @@
Parameters:
- - - - target - - - - - -Array.<Entity> - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1845,7 +1881,7 @@
Parameters:
Source:
@@ -1899,7 +1935,7 @@
Returns:
-

getEntityByComponents(comps) → {Entity}

+

getEntityByComponents(comps, entitiesopt) → {Entity}

@@ -1931,8 +1967,12 @@
Parameters:
Type + Attributes + + Default + Description @@ -1956,13 +1996,64 @@
Parameters:
+ + + + + + + + + + + + An array containing the component names to be searched + + + + entities + + + + + +Array.<Entity> + + + + + + + + + <optional>
+ + + + + + + + + + + + Manager#objects + + + + + The array of entities to search in.Defaults to the manager's entity list + + + @@ -2000,7 +2091,7 @@
Parameters:
Source:
@@ -2054,7 +2145,7 @@
Returns:
-

getEntityByTags(tags) → {Entity}

+

getEntityByTags(tags, entitiesopt) → {Entity}

@@ -2086,8 +2177,12 @@
Parameters:
Type + Attributes + + Default + Description @@ -2111,13 +2206,64 @@
Parameters:
+ + + + + + + + + + + + An array containing the tags to be searched + + + + entities + + + + + +Array.<Entity> + + + + + + + + + <optional>
+ + + + + + + + + + + + Manager#objects + + + + + The array of entities to search in.Defaults to the manager's entity list + + + @@ -2155,7 +2301,7 @@
Parameters:
Source:
@@ -2624,152 +2770,6 @@

playquery(bound)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bound - - -BoundingCircle -| - -BoundingBpx - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- Entity[] -
- - - - - - - - - @@ -3634,7 +3634,7 @@
Parameters:
Source:
@@ -3670,7 +3670,7 @@
Parameters:
-

unregisterSystem(n) → {void}

+

unregisterSystem(n)

@@ -3730,7 +3730,7 @@
Parameters:
- The name of the system + The name of the system. @@ -3771,7 +3771,7 @@
Parameters:
Source:
@@ -3796,24 +3796,6 @@
Parameters:
-
Returns:
- - - - -
-
- Type -
-
- -void - - -
-
- - @@ -3926,7 +3908,7 @@
Parameters:
Source:
@@ -3990,13 +3972,13 @@
Returns:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Material.html b/docs/Material.html deleted file mode 100644 index 1fe3e60e..00000000 --- a/docs/Material.html +++ /dev/null @@ -1,341 +0,0 @@ - - - - - JSDoc: Interface: Material - - - - - - - - - - -
- -

Interface: Material

- - - - - - -
- -
- -

Material

- - -
- -
-
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - -
- - - - - - - - - - - - - - - - -

Methods

- - - - - - - -

render(ctx, dt, pathopt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
ctx - - -CanvasRenderingContext2D - - - - - - - - - -
dt - - -number - - - - - - - - - -
path - - -Path2D - - - - - - <optional>
- - - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/Matrix2.html b/docs/Matrix2.html index c09a6043..bd9b6d07 100644 --- a/docs/Matrix2.html +++ b/docs/Matrix2.html @@ -2181,13 +2181,13 @@
Returns:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Mouse.html b/docs/Mouse.html index 8e0701e3..c497cf31 100644 --- a/docs/Mouse.html +++ b/docs/Mouse.html @@ -480,78 +480,6 @@
Type:
-

lastPosition :Vector_like

- - - - -
- Position of the mouse in last frame. -
- - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

leftbutton :boolean

@@ -606,7 +534,7 @@
Type:
Source:
@@ -750,7 +678,7 @@
Type:
Source:
@@ -828,7 +756,7 @@
Parameters:
-Vector_like +Vector @@ -879,7 +807,7 @@
Parameters:
Source:
@@ -933,7 +861,7 @@
Returns:
-

init(eh)

+

init()

@@ -952,55 +880,6 @@

init - - - - Name - - - Type - - - - - - Description - - - - - - - - - eh - - - - - -DOMEventHandler - - - - - - - - - - - - - - - - - @@ -1034,7 +913,7 @@
Parameters:
Source:
@@ -1122,7 +1001,7 @@

updateSource:
@@ -1168,13 +1047,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Movable.html b/docs/Movable.html index b8b6a731..04db1c75 100644 --- a/docs/Movable.html +++ b/docs/Movable.html @@ -28,7 +28,7 @@

Class: Movable

-

Movable(x, y, a) → {Entity}

+

Movable()

Component to hold requirements for an entity to move.
@@ -45,7 +45,7 @@

Constructor

-

new Movable(x, y, a) → {Entity}

+

new Movable()

@@ -60,101 +60,6 @@

new MovableParameters:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
x - - -number - - - -
y - - -number - - - -
a - - -number - - - -
- - @@ -220,24 +125,6 @@
Parameters:
-
Returns:
- - - - -
-
- Type -
-
- -Entity - - -
-
- - @@ -357,13 +244,13 @@
Type:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/NaiveBroadphase.html b/docs/NaiveBroadphase.html index dbb849ac..7c6c08de 100644 --- a/docs/NaiveBroadphase.html +++ b/docs/NaiveBroadphase.html @@ -28,7 +28,7 @@

Class: NaiveBroadphase

-

NaiveBroadphase(world)

+

NaiveBroadphase()

Most basic broadphase.Should be used when number of bodies are few(i.e less than 100)
@@ -45,7 +45,7 @@

Constructor

-

new NaiveBroadphase(world)

+

new NaiveBroadphase()

@@ -60,55 +60,6 @@

new Na -

Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
world - - -World - - - -
- - @@ -244,7 +195,7 @@
Parameters:
-Array.<CollisionPair> +array @@ -295,7 +246,7 @@
Parameters:
Source:
@@ -349,7 +300,7 @@
Returns:
-

query(bound, target) → {Array.<Body>}

+

query(bounds, target) → {Array.<Body>}

@@ -389,7 +340,7 @@
Parameters:
- bound + bounds @@ -469,7 +420,7 @@
Parameters:
Source:
@@ -533,13 +484,13 @@
Returns:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Node.html b/docs/Node.html deleted file mode 100644 index deec8995..00000000 --- a/docs/Node.html +++ /dev/null @@ -1,2854 +0,0 @@ - - - - - JSDoc: Class: Node - - - - - - - - - - -
- -

Class: Node

- - - - - - -
- -
- -

Node(bounds)

- - -
- -
-
- - - - - - -

new Node(bounds)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bounds - - -Object - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -

Members

- - - -

bounds :Object

- - - - - - -
Type:
-
    -
  • - -Object - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

children :Array.<Node>

- - - - - - -
Type:
-
    -
  • - -Array.<Node> - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

depth :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

dims :Vector_like

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

global :Tree

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

hasObjects :boolean

- - - - - - -
Type:
-
    -
  • - -boolean - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

index :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

objects :Array.<Body>

- - - - - - -
Type:
-
    -
  • - -Array.<Body> - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

parent :Node

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

root :Node

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - -

add(node)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
node - - -Node - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

childrenHaveObj()

- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- boolean -
- - - - - - - - - - - - - - - -

contains(bounds)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bounds - - -Bounds - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- boolean -
- - - - - - - - - - - - - - - -

draw(ctx)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
ctx - - -CanvasRenderingContext2D - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

getCollisionPairs(target, stack)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
target - - -Array.<CollisionPair> - - - -
stack - - -Array.<CollisionPair> - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

insertObject(obj)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
obj - - -Body - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- boolean -
- - - - - - - - - - - - - - - -

intersects(bounds)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
bounds - - -Bounds - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- boolean -
- - - - - - - - - - - - - - - -

isInNode(position)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
position - - -Vector_like - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- boolean -
- - - - - - - - - - - - - - - -

isLeafNode()

- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- boolean -
- - - - - - - - - - - - - - - -

query(bounds, targetopt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
bounds - - -Bounds - - - - - - - - - -
target - - -Array.<Body> - - - - - - <optional>
- - - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- boolean -
- - - - - - - - - - - - - - - -

removeObject(obj)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
obj - - -Body - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- boolean -
- - - - - - - - - - - - - - - -

split(depth)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
depth - - -number - - - - - - 1 - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

traverse(func, target)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
func - - -Traverser - - - -
target - - -Array.<T> - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - -
- [] -
- - - - - - - - - - - - - - - -

updateObject(obj)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
obj - - -Body - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/Particle.html b/docs/Particle.html index 6d08a642..8e65f8f6 100644 --- a/docs/Particle.html +++ b/docs/Particle.html @@ -232,7 +232,7 @@
Parameters:
Source:
@@ -278,418 +278,6 @@
Parameters:
-

Members

- - - -

active :boolean

- - - - - - -
Type:
-
    -
  • - -boolean - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

color :Object

- - - - - - -
Type:
-
    -
  • - -Object - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

(readonly) lifespan :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

(readonly) position :Vector

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

radius :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

(readonly) velocity :Vector

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

Methods

@@ -700,7 +288,7 @@

Methods

-

draw(ctx)

+

draw()

@@ -719,55 +307,6 @@

draw - - - - Name - - - Type - - - - - - Description - - - - - - - - - ctx - - - - - -CanvasRenderingContext2D - - - - - - - - - - - - - - - - - @@ -801,7 +340,7 @@
Parameters:
Source:
@@ -837,7 +376,7 @@
Parameters:
-

update(ctx, dt)

+

update()

@@ -856,78 +395,6 @@

updateParameters:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
ctx - - -CanvasRenderingContext2D - - - -
dt - - -number - - - -
- - @@ -961,7 +428,7 @@
Parameters:
Source:
@@ -1007,13 +474,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/ParticleSystemSprite.html b/docs/ParticleSystemSprite.html deleted file mode 100644 index 904e99fd..00000000 --- a/docs/ParticleSystemSprite.html +++ /dev/null @@ -1,1495 +0,0 @@ - - - - - JSDoc: Class: ParticleSystemSprite - - - - - - - - - - -
- -

Class: ParticleSystemSprite

- - - - - - -
- -
- -

ParticleSystemSprite(initialopt, maxopt)

- -
This creates a particle system
- - -
- -
-
- - - - -

Constructor

- - - -

new ParticleSystemSprite(initialopt, maxopt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDefaultDescription
initial - - -number - - - - - - <optional>
- - - - - -
- - 1 - - Number of particles to start with.
max - - -number - - - - - - <optional>
- - - - - -
- - 100 - - Maximum number of particles. -param {number} [increment=5] Maximum number of particles.
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- - -

Extends

- - - - - - - - - - - - - - - - - - - - -

Members

- - - -

angle :number

- - - - -
- Angle in degrees -
- - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

frameIncrease :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
Default Value:
-
    -
  • 1
  • -
- - - -
Source:
-
- - - - - - - -
- - - - - - - - -

initial :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
Default Value:
-
    -
  • 1
  • -
- - - -
Source:
-
- - - - - - - -
- - - - - - - - -

max :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
Default Value:
-
    -
  • 1
  • -
- - - -
Source:
-
- - - - - - - -
- - - - - - - - -

orientation :Angle

- - - - -
- Orientation of the sprite -
- - - -
Type:
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

parent :Group|null

- - - - - - -
Type:
-
    -
  • - -Group -| - -null - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

position :Vector

- - - - -
- World space position. -
- - - -
Type:
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - -

Methods

- - - - - - - -

(protected) behavior(p, dt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
p - - -Particle - - - -
dt - - -number - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

(protected) create()

- - - - - - -
- override this to return an object created from your own class extending the particle class -
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

init(entity)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
entity - - -Entity - - - -
- - - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

(protected) initParticles(n)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
n - - -number - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -

render(ctx, dt)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
ctx - - -CanvasRenderingContext2D - - - -
dt - - -number - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - -
- -
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) -
- - - - - \ No newline at end of file diff --git a/docs/PathFollowing.html b/docs/PathFollowing.html index 392b4185..a2d1bcfa 100644 --- a/docs/PathFollowing.html +++ b/docs/PathFollowing.html @@ -91,7 +91,7 @@
Parameters:
-Path +Path @@ -503,7 +503,7 @@
Type:
-

path :Path

+

path :Path

@@ -518,7 +518,7 @@
Type:

- - - - - - - - - - - - - - - - - - - - - - - - - - -

addUI(sprite)

- - - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
sprite - - -Sprite - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
@@ -1267,7 +985,7 @@
Parameters:
Source:
@@ -1360,7 +1078,7 @@

clearSource:
@@ -1502,7 +1220,7 @@
Parameters:
Source:
@@ -1595,7 +1313,7 @@

pauseSource:
@@ -1688,7 +1406,7 @@

playSource:
@@ -1830,7 +1548,7 @@
Parameters:
Source:
@@ -1923,7 +1641,7 @@

requ
Source:
@@ -2088,7 +1806,7 @@

Parameters:
Source:
@@ -2124,68 +1842,23 @@
Parameters:
-

update(dt)

- - +

update()

- - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - +
+ Updates the objects within the renderer +
- - - - - - - -
NameTypeDescription
dt - - -number - -
@@ -2226,7 +1899,7 @@
Parameters:
Source:
@@ -2272,13 +1945,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/RungeKuttaSolver.html b/docs/RungeKuttaSolver.html index b3095a14..5d66effd 100644 --- a/docs/RungeKuttaSolver.html +++ b/docs/RungeKuttaSolver.html @@ -316,13 +316,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/SeekBehaviour.html b/docs/SeekBehaviour.html index c2fa9f36..9e650b53 100644 --- a/docs/SeekBehaviour.html +++ b/docs/SeekBehaviour.html @@ -28,7 +28,7 @@

Class: SeekBehaviour

-

SeekBehaviour(target)

+

SeekBehaviour()

Creates a behaviour to seek out a target and move towards it.
@@ -45,7 +45,7 @@

Constructor

-

new SeekBehaviour(target)

+

new SeekBehaviour()

@@ -60,55 +60,6 @@

new Seek -

Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
target - - -Vector - - - -
- - @@ -574,74 +525,6 @@
Type:
-

target :Vector

- - - - - - -
Type:
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

velocity :Vector

@@ -1198,13 +1081,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Sfx.html b/docs/Sfx.html index e7d56f5c..f71026c8 100644 --- a/docs/Sfx.html +++ b/docs/Sfx.html @@ -1002,13 +1002,13 @@

resume
- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Shape.html b/docs/Shape.html index 166ba4ed..d4f3b778 100644 --- a/docs/Shape.html +++ b/docs/Shape.html @@ -287,142 +287,6 @@

Members

-

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

area :number

@@ -477,7 +341,7 @@
Type:
Source:
@@ -495,7 +359,7 @@
Type:
-

geometry :Geometry

+

geometry :Geometry

@@ -510,7 +374,7 @@
Type:

+ + + + + + + + + + + + + + + + + + + + + + + + + + +

(protected) initParticles()

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
@@ -504,6 +957,90 @@
Parameters:
+ + + + + + +

render()

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + @@ -587,6 +1124,11 @@
Parameters:
+
Overrides:
+
+ @@ -653,13 +1195,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Touch.html b/docs/Touch.html index a423bbd1..17af4d53 100644 --- a/docs/Touch.html +++ b/docs/Touch.html @@ -28,7 +28,7 @@

Class: Touch

-

Touch(eh)

+

Touch()

Handles the touch input of an application from a smartphone,tablet or PCs with touchscreens. Realized i need to massively change this to make it work well.
@@ -45,7 +45,7 @@

Constructor

-

new Touch(eh)

+

new Touch()

@@ -60,55 +60,6 @@

new TouchParameters:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
eh - - -DOMEventHandler - - - -
- - @@ -188,146 +139,6 @@
Parameters:
-

Members

- - - -

clickCount :number

- - - - - - -
Type:
-
    -
  • - -number - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

touches :Array.<TouchEvent>

- - - - - - -
Type:
-
    -
  • - -Array.<TouchEvent> - - -
  • -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

Methods

@@ -338,7 +149,7 @@

Methods

-

inDragBox(pos)

+

inDragBox()

@@ -357,55 +168,6 @@

inDragBoxParameters:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
pos - - -Vector_like - - - -
- - @@ -439,7 +201,7 @@
Parameters:
Source:
@@ -576,7 +338,7 @@
Parameters:
Source:
@@ -622,13 +384,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Transform.html b/docs/Transform.html index 293b3704..cb49442c 100644 --- a/docs/Transform.html +++ b/docs/Transform.html @@ -28,7 +28,7 @@

Class: Transform

-

Transform(x, y, a)

+

Transform()

Holds transformation info of an entity
@@ -45,7 +45,7 @@

Constructor

-

new Transform(x, y, a)

+

new Transform()

@@ -60,101 +60,6 @@

new Transfor -

Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
x - - -number - - - -
y - - -number - - - -
a - - -number - - - -
- - @@ -220,12 +125,6 @@
Parameters:
-
Returns:
- - - - - @@ -447,7 +346,7 @@
Parameters:
Source:
@@ -493,13 +392,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Tree.html b/docs/Tree.html index 68e86291..f7ea724b 100644 --- a/docs/Tree.html +++ b/docs/Tree.html @@ -1006,7 +1006,7 @@
Parameters:
Source:
@@ -1285,7 +1285,7 @@
Parameters:
Source:
@@ -1646,7 +1646,7 @@
Parameters:
Source:
@@ -2558,7 +2558,7 @@
Parameters:
Source:
@@ -2837,7 +2837,7 @@
Parameters:
Source:
@@ -3025,13 +3025,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time)
diff --git a/docs/Triangle.html b/docs/Triangle.html index 95fba3ce..26a595b8 100644 --- a/docs/Triangle.html +++ b/docs/Triangle.html @@ -295,152 +295,6 @@

Members

-

CHAOS_OBJ_TYPE :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - -

CHOAS_CLASSNAME :string

- - - - - - -
Type:
-
    -
  • - -string - - -
  • -
- - - - - -
- - - - - - - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - -

area :number

@@ -500,7 +354,7 @@
Type:
Source:
@@ -518,7 +372,7 @@
Type:
-

geometry :Geometry

+

geometry :Geometry

@@ -533,7 +387,7 @@
Type:
@@ -105,6 +105,142 @@

Members

+

CHAOS_OBJ_TYPE :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

CHOAS_CLASSNAME :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +

entity :Entity|null

@@ -238,7 +374,7 @@

destroySource:
@@ -274,17 +410,13 @@

destroyinit(entity)

+

get(n)

-
- Initializes a component. -
- @@ -318,13 +450,13 @@
Parameters:
- entity + n -Entity +string @@ -375,7 +507,7 @@
Parameters:
Source:
@@ -411,7 +543,7 @@
Parameters:
-

requires()

+

init(entity)

@@ -419,7 +551,7 @@

requires - Gets a component in the entity containing this entity. + Initializes a component. @@ -455,13 +587,13 @@
Parameters:
- ...names + entity -string +Entity @@ -512,7 +644,7 @@
Parameters:
Source:
@@ -535,16 +667,21 @@
Parameters:
-
Throws:
+ + + + + + + -
- - Qhen a named component isnt in the parent entity -
+ +

init(entity)

+ @@ -554,22 +691,756 @@
Throws:
+ + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
entity + + +Entity + + + +
+ + + + + + +
-

update(dt)

+ + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

query(bound, targetopt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
bound + + +CircleBounding +| + +BoxBounding + + + + + + + + + + + +
target + + +Entity + + + + + + <optional>
+ + + + + +
+ + [] + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

requires()

+ + + + + + +
+ Gets a component in the entity containing this entity. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
...names + + +string + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Throws:
+ + + +
+ + Qhen a named component isnt in the parent entity + +
+ + + + + + + + + + + + + + + + +

requires(…names)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
names + + +string + + + + + + + + + + <repeatable>
+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

update(dt)

+ + + + + + +
+ Updates a component.Called by the system which manages its type. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dt + + +number + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

update(dt)

+ + + -
- Updates a component.Called by the system which manages its type. -
@@ -661,7 +1532,7 @@
Parameters:
Source:
@@ -707,13 +1578,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Composite.html b/docs/Composite.html index e2d70e7a..2d15c8d5 100644 --- a/docs/Composite.html +++ b/docs/Composite.html @@ -341,7 +341,7 @@
Type:
Source:
@@ -557,7 +557,7 @@
Type:
Source:
@@ -704,7 +704,7 @@
Type:
Source:
@@ -776,7 +776,7 @@
Type:
Source:
@@ -920,7 +920,7 @@
Type:
Source:
@@ -1417,13 +1417,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Constraint.html b/docs/Constraint.html index caed3f5b..a3727ddc 100644 --- a/docs/Constraint.html +++ b/docs/Constraint.html @@ -270,6 +270,142 @@

Members

+

CHAOS_OBJ_TYPE :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

CHOAS_CLASSNAME :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +

(package) physicsType :number

@@ -499,7 +635,7 @@
Parameters:
Source:
@@ -636,7 +772,7 @@
Parameters:
Source:
@@ -682,13 +818,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/DOMEventHandler.html b/docs/DOMEventHandler.html index 0e616b3f..4b94d70e 100644 --- a/docs/DOMEventHandler.html +++ b/docs/DOMEventHandler.html @@ -727,13 +727,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/DistanceConstraint.html b/docs/DistanceConstraint.html index 5a5319de..07221970 100644 --- a/docs/DistanceConstraint.html +++ b/docs/DistanceConstraint.html @@ -456,13 +456,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Entity.html b/docs/Entity.html index dff2b5d5..24b69231 100644 --- a/docs/Entity.html +++ b/docs/Entity.html @@ -684,6 +684,166 @@

destroyfromJSON(obj, compList)

+ + + + + + +
+ Todo - type serialization docs correctly +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + +
compList + + +Map.<string, function()> + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + @@ -1610,7 +1770,7 @@
Parameters:
Source:
@@ -2269,6 +2429,108 @@
Parameters:
+ + + + + + +

toJson() → {Object}

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Object + + +
+
+ + + + + + + @@ -2412,7 +2674,7 @@
Parameters:
-

(static) Default() → {Entity}

+

(static) Default(x, y, a) → {Entity}

@@ -2431,6 +2693,101 @@

(static) Defa +

Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +number + + + +
y + + +number + + + +
a + + +number + + + +
+ + @@ -2464,7 +2821,7 @@

(static) Defa
Source:
@@ -2528,13 +2885,13 @@

Returns:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/EulerSolver.html b/docs/EulerSolver.html index e55d5cf2..d3404416 100644 --- a/docs/EulerSolver.html +++ b/docs/EulerSolver.html @@ -316,13 +316,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/EvadeBehaviour.html b/docs/EvadeBehaviour.html index 875bf7f4..dda2230a 100644 --- a/docs/EvadeBehaviour.html +++ b/docs/EvadeBehaviour.html @@ -1129,13 +1129,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:23 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/EventDispatcher.html b/docs/EventDispatcher.html index 10b4f914..fa2a187a 100644 --- a/docs/EventDispatcher.html +++ b/docs/EventDispatcher.html @@ -568,13 +568,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Flock.html b/docs/Flock.html index 66415208..76530fc8 100644 --- a/docs/Flock.html +++ b/docs/Flock.html @@ -375,6 +375,74 @@
Type:
+

neighbours :Array.<Agent>

+ + + + + + +
Type:
+
    +
  • + +Array.<Agent> + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +

position :Vector

@@ -1008,13 +1076,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Geometry.html b/docs/Geometry.html new file mode 100644 index 00000000..e24f95fb --- /dev/null +++ b/docs/Geometry.html @@ -0,0 +1,898 @@ + + + + + JSDoc: Class: Geometry + + + + + + + + + + +
+ +

Class: Geometry

+ + + + + + +
+ +
+ +

Geometry(vertices)

+ + +
+ +
+
+ + + + + + +

new Geometry(vertices)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
vertices + + +Array.<Vector> + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

CHAOS_OBJ_TYPE :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

CHOAS_CLASSNAME :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

_dynNormals :Array.<Vector>

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

normals :Array.<Vector>

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

vertices :Array.<Vector>

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

getNormals(rad, target)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rad + + +number + + + +
target + + +Array.<Vector> + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

transform(n, vertices, pos)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + +
vertices + + +Array.<Vector> + + + +
pos + + +Vector + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) +
+ + + + + \ No newline at end of file diff --git a/docs/Grid.html b/docs/Grid.html index 8e0b30f2..87b5eba0 100644 --- a/docs/Grid.html +++ b/docs/Grid.html @@ -1197,13 +1197,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Group.html b/docs/Group.html new file mode 100644 index 00000000..4dbaa580 --- /dev/null +++ b/docs/Group.html @@ -0,0 +1,1278 @@ + + + + + JSDoc: Class: Group + + + + + + + + + + +
+ +

Class: Group

+ + + + + + +
+ +
+ +

Group(sprites)

+ +
Used for grouping similar.
+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new Group(sprites)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
sprites + + +Array.<Sprite> + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + +

Classes

+ +
+
Group
+
+
+ + + + + + + + + +

Members

+ + + +

CHAOS_OBJ_TYPE :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

CHOAS_CLASSNAME :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

angle :number

+ + + + +
+ Angle in degrees +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

orientation :Angle

+ + + + +
+ Orientation of the sprite +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

position :Vector

+ + + + +
+ World space position. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

add(sprite)

+ + + + + + +
+ Adds another sprite to this one +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
sprite + + +Sprite +| + +Group + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

init(entity)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
entity + + +Entity + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

remove(sprite, recursiveopt, indexopt)

+ + + + + + +
+ Removes another sprite to this one +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
sprite + + +Sprite +| + +Group + + + + + + + + + + + +
recursive + + +boolean + + + + + + <optional>
+ + + + + +
+ + false + +
index + + +number + + + + + + <optional>
+ + + + + +
+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

render(ctx, dt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ctx + + +CanvasRenderingContext2D + + + +
dt + + +number + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) +
+ + + + + \ No newline at end of file diff --git a/docs/Input.html b/docs/Input.html index 4a0b3969..99ba28bf 100644 --- a/docs/Input.html +++ b/docs/Input.html @@ -664,13 +664,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Keyboard.html b/docs/Keyboard.html index 672bd5aa..60d0cea0 100644 --- a/docs/Keyboard.html +++ b/docs/Keyboard.html @@ -375,7 +375,7 @@
Parameters:
Source:
@@ -421,13 +421,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Line.html b/docs/Line.html new file mode 100644 index 00000000..f9dd2f95 --- /dev/null +++ b/docs/Line.html @@ -0,0 +1,333 @@ + + + + + JSDoc: Class: Line + + + + + + + + + + +
+ +

Class: Line

+ + + + + + +
+ +
+ +

Line(length, offset, pffsetAngle)

+ + +
+ +
+
+ + + + + + +

new Line(length, offset, pffsetAngle)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
length + + +number + + + +
offset + + +Vector + + + +
pffsetAngle + + +number + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

length :number

+ + + + + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) +
+ + + + + \ No newline at end of file diff --git a/docs/Manager.html b/docs/Manager.html index 769f1659..4a0a21ec 100644 --- a/docs/Manager.html +++ b/docs/Manager.html @@ -1242,114 +1242,6 @@

clearclone() → {Entity}

- - - - - - -
- Deep copies an entity -
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
Deprecated:
  • Yes
- - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Entity - - -
-
- - - - - - - @@ -1457,7 +1349,7 @@
Parameters:
Source:
@@ -1515,7 +1407,7 @@
Returns:
-

getEntitiesByComponents(comps, entitiesopt) → {Array.<Entity>}

+

getEntitiesByComponents(comps, entitiesopt, targetopt) → {Array.<Entity>}

@@ -1634,6 +1526,43 @@
Parameters:
+ + + + target + + + + + +Array.<Entity> + + + + + + + + + <optional>
+ + + + + + + + + + + + + + + + + + @@ -1725,7 +1654,7 @@
Returns:
-

getEntitiesByTags(tags, entitiesopt) → {Array.<Entity>}

+

getEntitiesByTags(tags, entitiesopt, target) → {Array.<Entity>}

@@ -1844,6 +1773,41 @@
Parameters:
+ + + + target + + + + + +Array.<Entity> + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1881,7 +1845,7 @@
Parameters:
Source:
@@ -1935,7 +1899,7 @@
Returns:
-

getEntityByComponents(comps, entitiesopt) → {Entity}

+

getEntityByComponents(comps) → {Entity}

@@ -1967,12 +1931,8 @@
Parameters:
Type - Attributes - - Default - Description @@ -1996,64 +1956,13 @@
Parameters:
- - - - - - - - - - - - An array containing the component names to be searched - - - - entities - - - - - -Array.<Entity> - - - - - - - - - <optional>
- - - - - - - - - - - - Manager#objects - - - - - The array of entities to search in.Defaults to the manager's entity list - - - @@ -2091,7 +2000,7 @@
Parameters:
Source:
@@ -2145,7 +2054,7 @@
Returns:
-

getEntityByTags(tags, entitiesopt) → {Entity}

+

getEntityByTags(tags) → {Entity}

@@ -2177,12 +2086,8 @@
Parameters:
Type - Attributes - - Default - Description @@ -2206,64 +2111,13 @@
Parameters:
- - - - - - - - - - - - An array containing the tags to be searched - - - - entities - - - - - -Array.<Entity> - - - - - - - - - <optional>
- - - - - - - - - - - - Manager#objects - - - - - The array of entities to search in.Defaults to the manager's entity list - - - @@ -2301,7 +2155,7 @@
Parameters:
Source:
@@ -2770,6 +2624,152 @@

playquery(bound)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bound + + +BoundingCircle +| + +BoundingBpx + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ Entity[] +
+ + + + + + + + + @@ -3634,7 +3634,7 @@
Parameters:
Source:
@@ -3670,7 +3670,7 @@
Parameters:
-

unregisterSystem(n)

+

unregisterSystem(n) → {void}

@@ -3730,7 +3730,7 @@
Parameters:
- The name of the system. + The name of the system @@ -3771,7 +3771,7 @@
Parameters:
Source:
@@ -3796,6 +3796,24 @@
Parameters:
+
Returns:
+ + + + +
+
+ Type +
+
+ +void + + +
+
+ + @@ -3908,7 +3926,7 @@
Parameters:
Source:
@@ -3972,13 +3990,13 @@
Returns:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Material.html b/docs/Material.html new file mode 100644 index 00000000..1fe3e60e --- /dev/null +++ b/docs/Material.html @@ -0,0 +1,341 @@ + + + + + JSDoc: Interface: Material + + + + + + + + + + +
+ +

Interface: Material

+ + + + + + +
+ +
+ +

Material

+ + +
+ +
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + +

Methods

+ + + + + + + +

render(ctx, dt, pathopt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
ctx + + +CanvasRenderingContext2D + + + + + + + + + +
dt + + +number + + + + + + + + + +
path + + +Path2D + + + + + + <optional>
+ + + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) +
+ + + + + \ No newline at end of file diff --git a/docs/Matrix2.html b/docs/Matrix2.html index bd9b6d07..c09a6043 100644 --- a/docs/Matrix2.html +++ b/docs/Matrix2.html @@ -2181,13 +2181,13 @@
Returns:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Mouse.html b/docs/Mouse.html index c497cf31..8e0701e3 100644 --- a/docs/Mouse.html +++ b/docs/Mouse.html @@ -480,6 +480,78 @@
Type:
+

lastPosition :Vector_like

+ + + + +
+ Position of the mouse in last frame. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +

leftbutton :boolean

@@ -534,7 +606,7 @@
Type:
Source:
@@ -678,7 +750,7 @@
Type:
Source:
@@ -756,7 +828,7 @@
Parameters:
-Vector +Vector_like @@ -807,7 +879,7 @@
Parameters:
Source:
@@ -861,7 +933,7 @@
Returns:
-

init()

+

init(eh)

@@ -880,6 +952,55 @@

init + + + + Name + + + Type + + + + + + Description + + + + + + + + + eh + + + + + +DOMEventHandler + + + + + + + + + + + + + + + + + @@ -913,7 +1034,7 @@

initSource:
@@ -1001,7 +1122,7 @@

updateSource:
@@ -1047,13 +1168,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Movable.html b/docs/Movable.html index 04db1c75..b8b6a731 100644 --- a/docs/Movable.html +++ b/docs/Movable.html @@ -28,7 +28,7 @@

Class: Movable

-

Movable()

+

Movable(x, y, a) → {Entity}

Component to hold requirements for an entity to move.
@@ -45,7 +45,7 @@

Constructor

-

new Movable()

+

new Movable(x, y, a) → {Entity}

@@ -60,6 +60,101 @@

new MovableParameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +number + + + +
y + + +number + + + +
a + + +number + + + +
+ + @@ -125,6 +220,24 @@

new MovableReturns:

+ + + + +
+
+ Type +
+
+ +Entity + + +
+
+ + @@ -244,13 +357,13 @@
Type:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/NaiveBroadphase.html b/docs/NaiveBroadphase.html index 7c6c08de..dbb849ac 100644 --- a/docs/NaiveBroadphase.html +++ b/docs/NaiveBroadphase.html @@ -28,7 +28,7 @@

Class: NaiveBroadphase

-

NaiveBroadphase()

+

NaiveBroadphase(world)

Most basic broadphase.Should be used when number of bodies are few(i.e less than 100)
@@ -45,7 +45,7 @@

Constructor

-

new NaiveBroadphase()

+

new NaiveBroadphase(world)

@@ -60,6 +60,55 @@

new Na +

Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
world + + +World + + + +
+ + @@ -195,7 +244,7 @@
Parameters:
-array +Array.<CollisionPair> @@ -246,7 +295,7 @@
Parameters:
Source:
@@ -300,7 +349,7 @@
Returns:
-

query(bounds, target) → {Array.<Body>}

+

query(bound, target) → {Array.<Body>}

@@ -340,7 +389,7 @@
Parameters:
- bounds + bound @@ -420,7 +469,7 @@
Parameters:
Source:
@@ -484,13 +533,13 @@
Returns:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Node.html b/docs/Node.html new file mode 100644 index 00000000..deec8995 --- /dev/null +++ b/docs/Node.html @@ -0,0 +1,2854 @@ + + + + + JSDoc: Class: Node + + + + + + + + + + +
+ +

Class: Node

+ + + + + + +
+ +
+ +

Node(bounds)

+ + +
+ +
+
+ + + + + + +

new Node(bounds)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bounds + + +Object + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

bounds :Object

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

children :Array.<Node>

+ + + + + + +
Type:
+
    +
  • + +Array.<Node> + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

depth :number

+ + + + + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

dims :Vector_like

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

global :Tree

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

hasObjects :boolean

+ + + + + + +
Type:
+
    +
  • + +boolean + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

index :number

+ + + + + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

objects :Array.<Body>

+ + + + + + +
Type:
+
    +
  • + +Array.<Body> + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

parent :Node

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

root :Node

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

add(node)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
node + + +Node + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

childrenHaveObj()

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ boolean +
+ + + + + + + + + + + + + + + +

contains(bounds)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bounds + + +Bounds + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ boolean +
+ + + + + + + + + + + + + + + +

draw(ctx)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ctx + + +CanvasRenderingContext2D + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

getCollisionPairs(target, stack)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
target + + +Array.<CollisionPair> + + + +
stack + + +Array.<CollisionPair> + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

insertObject(obj)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Body + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ boolean +
+ + + + + + + + + + + + + + + +

intersects(bounds)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
bounds + + +Bounds + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ boolean +
+ + + + + + + + + + + + + + + +

isInNode(position)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
position + + +Vector_like + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ boolean +
+ + + + + + + + + + + + + + + +

isLeafNode()

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ boolean +
+ + + + + + + + + + + + + + + +

query(bounds, targetopt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
bounds + + +Bounds + + + + + + + + + +
target + + +Array.<Body> + + + + + + <optional>
+ + + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ boolean +
+ + + + + + + + + + + + + + + +

removeObject(obj)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Body + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ boolean +
+ + + + + + + + + + + + + + + +

split(depth)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
depth + + +number + + + + + + 1 + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

traverse(func, target)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
func + + +Traverser + + + +
target + + +Array.<T> + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ [] +
+ + + + + + + + + + + + + + + +

updateObject(obj)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Body + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) +
+ + + + + \ No newline at end of file diff --git a/docs/Particle.html b/docs/Particle.html index 8e65f8f6..6d08a642 100644 --- a/docs/Particle.html +++ b/docs/Particle.html @@ -232,7 +232,7 @@
Parameters:
Source:
@@ -278,6 +278,418 @@
Parameters:
+

Members

+ + + +

active :boolean

+ + + + + + +
Type:
+
    +
  • + +boolean + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

color :Object

+ + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(readonly) lifespan :number

+ + + + + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(readonly) position :Vector

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

radius :number

+ + + + + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

(readonly) velocity :Vector

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +

Methods

@@ -288,7 +700,7 @@

Methods

-

draw()

+

draw(ctx)

@@ -307,6 +719,55 @@

draw + + + + Name + + + Type + + + + + + Description + + + + + + + + + ctx + + + + + +CanvasRenderingContext2D + + + + + + + + + + + + + + + + + @@ -340,7 +801,7 @@

drawSource:
@@ -376,7 +837,7 @@

drawupdate()

+

update(ctx, dt)

@@ -395,6 +856,78 @@

updateParameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ctx + + +CanvasRenderingContext2D + + + +
dt + + +number + + + +
+ + @@ -428,7 +961,7 @@

updateSource:
@@ -474,13 +1007,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/ParticleSystemSprite.html b/docs/ParticleSystemSprite.html new file mode 100644 index 00000000..904e99fd --- /dev/null +++ b/docs/ParticleSystemSprite.html @@ -0,0 +1,1495 @@ + + + + + JSDoc: Class: ParticleSystemSprite + + + + + + + + + + +
+ +

Class: ParticleSystemSprite

+ + + + + + +
+ +
+ +

ParticleSystemSprite(initialopt, maxopt)

+ +
This creates a particle system
+ + +
+ +
+
+ + + + +

Constructor

+ + + +

new ParticleSystemSprite(initialopt, maxopt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
initial + + +number + + + + + + <optional>
+ + + + + +
+ + 1 + + Number of particles to start with.
max + + +number + + + + + + <optional>
+ + + + + +
+ + 100 + + Maximum number of particles. +param {number} [increment=5] Maximum number of particles.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Members

+ + + +

angle :number

+ + + + +
+ Angle in degrees +
+ + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

frameIncrease :number

+ + + + + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 1
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

initial :number

+ + + + + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 1
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

max :number

+ + + + + + +
Type:
+
    +
  • + +number + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Default Value:
+
    +
  • 1
  • +
+ + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

orientation :Angle

+ + + + +
+ Orientation of the sprite +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

parent :Group|null

+ + + + + + +
Type:
+
    +
  • + +Group +| + +null + + +
  • +
+ + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

position :Vector

+ + + + +
+ World space position. +
+ + + +
Type:
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

(protected) behavior(p, dt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
p + + +Particle + + + +
dt + + +number + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

(protected) create()

+ + + + + + +
+ override this to return an object created from your own class extending the particle class +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

init(entity)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
entity + + +Entity + + + +
+ + + + + + +
+ + + + + + + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

(protected) initParticles(n)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

render(ctx, dt)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ctx + + +CanvasRenderingContext2D + + + +
dt + + +number + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time) +
+ + + + + \ No newline at end of file diff --git a/docs/PathFollowing.html b/docs/PathFollowing.html index a2d1bcfa..392b4185 100644 --- a/docs/PathFollowing.html +++ b/docs/PathFollowing.html @@ -91,7 +91,7 @@
Parameters:
-Path +Path @@ -503,7 +503,7 @@
Type:
-

path :Path

+

path :Path

@@ -518,7 +518,7 @@
Type:

+ + + + + + + + + + + + + + + + + + + + + + + + + + +

addUI(sprite)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
sprite + + +Sprite + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
@@ -985,7 +1267,7 @@
Parameters:
Source:
@@ -1078,7 +1360,7 @@

clearSource:
@@ -1220,7 +1502,7 @@
Parameters:
Source:
@@ -1313,7 +1595,7 @@

pauseSource:
@@ -1406,7 +1688,7 @@

playSource:
@@ -1548,7 +1830,7 @@
Parameters:
Source:
@@ -1641,7 +1923,7 @@

requ
Source:
@@ -1806,7 +2088,7 @@

Parameters:
Source:
@@ -1842,16 +2124,13 @@
Parameters:
-

update()

+

update(dt)

-
- Updates the objects within the renderer -
@@ -1860,6 +2139,54 @@

updateParameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
dt + + +number + + + +
+ @@ -1899,7 +2226,7 @@

updateSource:
@@ -1945,13 +2272,13 @@

update
- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/RungeKuttaSolver.html b/docs/RungeKuttaSolver.html index 5d66effd..b3095a14 100644 --- a/docs/RungeKuttaSolver.html +++ b/docs/RungeKuttaSolver.html @@ -316,13 +316,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/SeekBehaviour.html b/docs/SeekBehaviour.html index 9e650b53..c2fa9f36 100644 --- a/docs/SeekBehaviour.html +++ b/docs/SeekBehaviour.html @@ -28,7 +28,7 @@

Class: SeekBehaviour

-

SeekBehaviour()

+

SeekBehaviour(target)

Creates a behaviour to seek out a target and move towards it.
@@ -45,7 +45,7 @@

Constructor

-

new SeekBehaviour()

+

new SeekBehaviour(target)

@@ -60,6 +60,55 @@

new Seek +

Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
target + + +Vector + + + +
+ + @@ -525,6 +574,74 @@
Type:
+

target :Vector

+ + + + + + +
Type:
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +

velocity :Vector

@@ -1081,13 +1198,13 @@
Parameters:

- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Sfx.html b/docs/Sfx.html index f71026c8..e7d56f5c 100644 --- a/docs/Sfx.html +++ b/docs/Sfx.html @@ -1002,13 +1002,13 @@

resume
- Documentation generated by JSDoc 4.0.2 on Fri Jul 07 2023 15:03:24 GMT+0300 (East Africa Time) + Documentation generated by JSDoc 4.0.2 on Sun Sep 10 2023 16:39:39 GMT+0300 (East Africa Time)
diff --git a/docs/Shape.html b/docs/Shape.html index d4f3b778..166ba4ed 100644 --- a/docs/Shape.html +++ b/docs/Shape.html @@ -287,6 +287,142 @@

Members

+

CHAOS_OBJ_TYPE :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

CHOAS_CLASSNAME :string

+ + + + + + +
Type:
+
    +
  • + +string + + +
  • +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +

area :number

@@ -341,7 +477,7 @@
Type:
Source:
@@ -359,7 +495,7 @@
Type:
-

geometry :Geometry

+

geometry :Geometry

@@ -374,7 +510,7 @@
Type: