Skip to content

Commit

Permalink
fix: this time it should work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Prozi committed Nov 1, 2024
1 parent 6520be6 commit dc5e0c2
Show file tree
Hide file tree
Showing 24 changed files with 5,226 additions and 5,443 deletions.
3 changes: 0 additions & 3 deletions clean-dist-types.sh

This file was deleted.

10 changes: 10 additions & 0 deletions clean-dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Find and clean up TypeScript files in the 'dist' directory
find dist -name '*.*' | while read -r file; do
if [ -f "$file" ]; then
# Replace four spaces with two spaces
sed -i 's/ / /g' "$file"
echo "Cleaned $file"
fi
done
87 changes: 37 additions & 50 deletions dist/base-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,69 +15,63 @@ const polygon_1 = require("./bodies/polygon");
*/
class BaseSystem extends model_1.RBush {
/**
* create point at position with options and add to system
*/
* create point at position with options and add to system
*/
createPoint(position, options, Class) {
const PointClass = Class || point_1.Point;
const point = new PointClass(position, options);
this.insert(point);
return point;
}

/**
* create line at position with options and add to system
*/
* create line at position with options and add to system
*/
createLine(start, end, options, Class) {
const LineClass = Class || line_1.Line;
const line = new LineClass(start, end, options);
this.insert(line);
return line;
}

/**
* create circle at position with options and add to system
*/
* create circle at position with options and add to system
*/
createCircle(position, radius, options, Class) {
const CircleClass = Class || circle_1.Circle;
const circle = new CircleClass(position, radius, options);
this.insert(circle);
return circle;
}

/**
* create box at position with options and add to system
*/
* create box at position with options and add to system
*/
createBox(position, width, height, options, Class) {
const BoxClass = Class || box_1.Box;
const box = new BoxClass(position, width, height, options);
this.insert(box);
return box;
}

/**
* create ellipse at position with options and add to system
*/
* create ellipse at position with options and add to system
*/
createEllipse(position, radiusX, radiusY = radiusX, step, options, Class) {
const EllipseClass = Class || ellipse_1.Ellipse;
const ellipse = new EllipseClass(position, radiusX, radiusY, step, options);
this.insert(ellipse);
return ellipse;
}

/**
* create polygon at position with options and add to system
*/
* create polygon at position with options and add to system
*/
createPolygon(position, points, options, Class) {
const PolygonClass = Class || polygon_1.Polygon;
const polygon = new PolygonClass(position, points, options);
this.insert(polygon);
return polygon;
}

/**
* re-insert body into collision tree and update its bbox
* every body can be part of only one system
*/
* re-insert body into collision tree and update its bbox
* every body can be part of only one system
*/
insert(body) {
body.bbox = body.getAABBAsBBox();
if (body.system) {
Expand All @@ -96,68 +90,61 @@ class BaseSystem extends model_1.RBush {
// reinsert bounding box to collision tree
return super.insert(body);
}

/**
* updates body in collision tree
*/
* updates body in collision tree
*/
updateBody(body) {
body.updateBody();
}

/**
* update all bodies aabb
*/
* update all bodies aabb
*/
update() {
(0, optimized_1.forEach)(this.all(), body => {
(0, optimized_1.forEach)(this.all(), (body) => {
this.updateBody(body);
});
}

/**
* draw exact bodies colliders outline
*/
* draw exact bodies colliders outline
*/
draw(context) {
(0, optimized_1.forEach)(this.all(), body => {
(0, optimized_1.forEach)(this.all(), (body) => {
body.draw(context);
});
}

/**
* draw bounding boxes hierarchy outline
*/
* draw bounding boxes hierarchy outline
*/
drawBVH(context, isTrigger = true) {
const drawChildren = body => {
const drawChildren = (body) => {
(0, utils_1.drawBVH)(context, body, isTrigger);
if (body.children) {
(0, optimized_1.forEach)(body.children, drawChildren);
}
};
(0, optimized_1.forEach)(this.data.children, drawChildren);
}

/**
* remove body aabb from collision tree
*/
* remove body aabb from collision tree
*/
remove(body, equals) {
body.system = undefined;
return super.remove(body, equals);
}

/**
* get object potential colliders
* @deprecated because it's slower to use than checkOne() or checkAll()
*/
* get object potential colliders
* @deprecated because it's slower to use than checkOne() or checkAll()
*/
getPotentials(body) {
// filter here is required as collides with self
return (0, optimized_1.filter)(this.search(body), candidate => candidate !== body);
return (0, optimized_1.filter)(this.search(body), (candidate) => candidate !== body);
}

/**
* used to find body deep inside data with finder function returning boolean found or not
*
* @param traverseFunction
* @param tree
*/
* used to find body deep inside data with finder function returning boolean found or not
*
* @param traverseFunction
* @param tree
*/
traverse(traverseFunction, { children } = this.data) {
return children === null || children === void 0 ? void 0 : children.find((body, index) => {
if (!body) {
Expand Down
8 changes: 4 additions & 4 deletions dist/benchmarks/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stressBenchmark = exports.insertionBenchmark = void 0;
const insertion_bench_1 = require("./insertion.bench");
Object.defineProperty(exports, "insertionBenchmark", { enumerable: true, get: function() { return insertion_bench_1.insertionBenchmark; } });
const stress_bench_1 = require("./stress.bench");
Object.defineProperty(exports, "stressBenchmark", { enumerable: true, get: function() { return stress_bench_1.stressBenchmark; } });
var insertion_bench_1 = require("./insertion.bench");
Object.defineProperty(exports, "insertionBenchmark", { enumerable: true, get: function () { return insertion_bench_1.insertionBenchmark; } });
var stress_bench_1 = require("./stress.bench");
Object.defineProperty(exports, "stressBenchmark", { enumerable: true, get: function () { return stress_bench_1.stressBenchmark; } });
88 changes: 44 additions & 44 deletions dist/benchmarks/insertion.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,58 +44,58 @@ const insertionBenchmark = () => {
}
benchmark
.add("non overlapping circles", () => {
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(nonoverlappingBodies[ndx]);
}
})
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(nonoverlappingBodies[ndx]);
}
})
.add("overlapping circles", () => {
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(overlappingBodies[ndx]);
}
})
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(overlappingBodies[ndx]);
}
})
.add("non-overlapping triangles", () => {
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(nonoverlappingTriangles[ndx]);
}
})
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(nonoverlappingTriangles[ndx]);
}
})
.add("overlapping triangles", () => {
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(overlappingTriangles[ndx]);
}
})
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(overlappingTriangles[ndx]);
}
})
.add("non-overlapping quad", () => {
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(nonoverlappingRectangles[ndx]);
}
})
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(nonoverlappingRectangles[ndx]);
}
})
.add("overlapping quad", () => {
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(overlappingRectangles[ndx]);
}
});
const uut = new system_js_1.System(BODY_COUNT);
for (let ndx = 0; ndx < BODY_COUNT; ndx++) {
uut.insert(overlappingRectangles[ndx]);
}
});
benchmark
.run()
.then(() => {
console.table(benchmark.tasks.map(({ name, result }) => {
let _a, _b, _c, _d, _e;
return ({
"Task Name": name,
"Average Time (s)": parseFloat(((_a = result === null || result === void 0 ? void 0 : result.mean) !== null && _a !== void 0 ? _a : 0).toFixed(3)),
"Standard Deviation (s)": parseFloat(((_b = result === null || result === void 0 ? void 0 : result.sd) !== null && _b !== void 0 ? _b : 0).toFixed(3)),
hz: parseFloat(((_c = result === null || result === void 0 ? void 0 : result.hz) !== null && _c !== void 0 ? _c : 0).toFixed(3)),
"p99 (s)": parseFloat(((_d = result === null || result === void 0 ? void 0 : result.p99) !== null && _d !== void 0 ? _d : 0).toFixed(3)),
"p995 (s)": parseFloat(((_e = result === null || result === void 0 ? void 0 : result.p995) !== null && _e !== void 0 ? _e : 0).toFixed(3)),
});
}));
})
console.table(benchmark.tasks.map(({ name, result }) => {
var _a, _b, _c, _d, _e;
return ({
"Task Name": name,
"Average Time (s)": parseFloat(((_a = result === null || result === void 0 ? void 0 : result.mean) !== null && _a !== void 0 ? _a : 0).toFixed(3)),
"Standard Deviation (s)": parseFloat(((_b = result === null || result === void 0 ? void 0 : result.sd) !== null && _b !== void 0 ? _b : 0).toFixed(3)),
hz: parseFloat(((_c = result === null || result === void 0 ? void 0 : result.hz) !== null && _c !== void 0 ? _c : 0).toFixed(3)),
"p99 (s)": parseFloat(((_d = result === null || result === void 0 ? void 0 : result.p99) !== null && _d !== void 0 ? _d : 0).toFixed(3)),
"p995 (s)": parseFloat(((_e = result === null || result === void 0 ? void 0 : result.p995) !== null && _e !== void 0 ? _e : 0).toFixed(3)),
});
}));
})
.catch(err => {
console.warn(err.message || err);
});
console.warn(err.message || err);
});
};
exports.insertionBenchmark = insertionBenchmark;
26 changes: 13 additions & 13 deletions dist/benchmarks/stress.bench.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
"use strict";
const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) {k2 = k;}
let desc = Object.getOwnPropertyDescriptor(m, k);
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) {k2 = k;}
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
const __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
const __importStar = (this && this.__importStar) || function(mod) {
if (mod && mod.__esModule) {return mod;}
const result = {};
if (mod != null) {for (const k in mod) {if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) {__createBinding(result, mod, k);}}}
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
const __awaiter = (this && this.__awaiter) || function(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function(resolve) { resolve(value); }); }
return new (P || (P = Promise))(function(resolve, reject) {
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
Expand All @@ -49,7 +49,7 @@ const stressBenchmark = () => __awaiter(void 0, void 0, void 0, function* () {
stressTest.physics.clear();
},
});
const recursiveAddTest = items => {
const recursiveAddTest = (items) => {
benchmark.add(`stress test, items=${items}`, () => {
stressTest.update();
}, { items });
Expand Down
Loading

0 comments on commit dc5e0c2

Please sign in to comment.