Skip to content

Commit

Permalink
Improves physics. #6
Browse files Browse the repository at this point in the history
- Fixes types
- Fixes bugs
- Changes warnings
- Improves the plugin interface
- Improves comments
- Improves tests
  • Loading branch information
tomaspietravallo committed Dec 23, 2021
1 parent b7a015f commit a04a4fc
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 76 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ npm i
- [x] Add a `Pool` class, which will create a pool of dynamically instanced objects
- [x] Integrate the changes & fixes made during the \*\*\*\*\*\*\*\*\*\* project (currently under development)
- [ ] Multipeer support (?) -- may be pushed back to v4 or 5. **[See](https://github.com/tomaspietravallo/sparkar-volts/commit/47bc2f6384be41ee5c6f1d8d65d3f31fb1db4a61)**
- [ ] Improve experience
- [x] Improve experience

> Multipeer features might get developed locally, or using some sort of obfuscation (?) that only allows people with access to the API to develop...
# v4.0.0 plans

- [ ] Use rollup.js to add a minified version of VOLTS
- [ ] Improve support for Plugins
- [ ] Add support for Async onLoad/frameUpdate functions. Quite a large change, beware unintended side effects
- Open a PR/issue & add/request features!

Expand Down
2 changes: 1 addition & 1 deletion coverage/badge-branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion coverage/badge-functions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion coverage/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion coverage/badge-statements.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion coverage/badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions coverage/coverage-summary.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{"total": {"lines":{"total":678,"covered":634,"skipped":0,"pct":93.51},"statements":{"total":783,"covered":714,"skipped":0,"pct":91.19},"functions":{"total":183,"covered":170,"skipped":0,"pct":92.9},"branches":{"total":441,"covered":326,"skipped":0,"pct":73.92}}
,"/Users/tomaspietravallo/Documents/GitHub/sparkar-volts/volts.ts": {"lines":{"total":678,"covered":634,"skipped":0,"pct":93.51},"functions":{"total":183,"covered":170,"skipped":0,"pct":92.9},"statements":{"total":783,"covered":714,"skipped":0,"pct":91.19},"branches":{"total":441,"covered":326,"skipped":0,"pct":73.92}}
{"total": {"lines":{"total":696,"covered":668,"skipped":0,"pct":95.98},"statements":{"total":797,"covered":749,"skipped":0,"pct":93.98},"functions":{"total":186,"covered":179,"skipped":0,"pct":96.24},"branches":{"total":443,"covered":342,"skipped":0,"pct":77.2}}
,"/Users/tomaspietravallo/Documents/GitHub/sparkar-volts/volts.ts": {"lines":{"total":696,"covered":668,"skipped":0,"pct":95.98},"functions":{"total":186,"covered":179,"skipped":0,"pct":96.24},"statements":{"total":797,"covered":749,"skipped":0,"pct":93.98},"branches":{"total":443,"covered":342,"skipped":0,"pct":77.2}}
}
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
collectCoverageFrom: ['volts.ts'],

// The directory where Jest should output its coverage files
coverageDirectory: './coverage',
Expand Down
6 changes: 3 additions & 3 deletions tests/__mocks__/Reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ class NDVectorSignal {
this._ops.push(['mul', args]);
return this;
}
sub(...args: number[]){
sub(...args: number[]) {
this._ops.push(['sub', args]);
return this
return this;
}
// super basic, lacks a lot
public pinLastValue(): Vector | number {
Expand Down Expand Up @@ -277,7 +277,7 @@ export class Quaternion extends NDVectorSignal {
return new ScalarSignal(this._vector.values[3]);
}
get eulerAngles(): Object {
return {x: 0};
return { x: 0 };
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/__mocks__/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class SceneObjectBase {
};
this.boundingBox = {
max: Reactive.vector(0, 0, 0),
min: Reactive.vector(0, 0, 0)
}
min: Reactive.vector(0, 0, 0),
};
this.identifier = 'a-unique-identifier';
this.hidden = Reactive.boolSignal(false);
}
Expand Down
40 changes: 28 additions & 12 deletions tests/object3d.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('constructor', () => {

describe('fetch reactive values', () => {
test('from scene obj', async () => {
const Instance = World.getInstance({mode: 'DEV'});
const Instance = World.getInstance({ mode: 'DEV' });
const sceneObj: SceneObjectBase = await Scene.root.findFirst('a-scene-obj');
const obj = new Object3D(sceneObj);
obj.body.transform.position = Reactive.vector(1, 2, 3);
Expand All @@ -20,20 +20,11 @@ describe('fetch reactive values', () => {
await expect(obj.fetchLastPosition()).resolves.not.toThrow();
await expect(obj.fetchLastRotation()).resolves.not.toThrow();
await expect(obj.fetchSize()).resolves.not.toThrow();

await expect(obj.stayInPlace()).resolves.not.toThrow();

expect(obj.pos.values).toEqual([1, 2, 3]);
expect(obj.rot.values).toEqual([1,2,3,4]);
Instance.stop();
});
test('stayInPlace', async () => {
const Instance = World.getInstance({mode: 'DEV'});
const sceneObj: SceneObjectBase = await Scene.root.findFirst('a-scene-obj');
const obj = new Object3D(sceneObj);

expect(obj.pos.values).toEqual([0, 0, 0]);
expect(obj.rot.values).toEqual([1, 0, 0, 0]);
expect(obj.rot.values).toEqual([1, 2, 3, 4]);
Instance.stop();
});
test('update', async () => {
Expand All @@ -48,3 +39,28 @@ describe('fetch reactive values', () => {
expect(obj.rot.values).toEqual([1, 0, 0, 0]);
});
});

describe('utils', () => {
test('lookAtOther', async () => {
const sceneObjOne: SceneObjectBase = await Scene.root.findFirst('a-scene-obj');
const sceneObjTwo: SceneObjectBase = await Scene.root.findFirst('a-scene-obj');
const first = new Object3D(sceneObjOne);
const second = new Object3D(sceneObjTwo);

expect(() => first.lookAtOther(second)).not.toThrow();
});
test('lookAtHeading', async () => {
const sceneObjOne: SceneObjectBase = await Scene.root.findFirst('a-scene-obj');
const obj = new Object3D(sceneObjOne);
obj.vel = new Vector(0, 0, 1);

expect(() => obj.lookAtHeading()).not.toThrow();
expect(obj.rot.values).toEqual([1, 0, 0, 0]);
});
test('makeRigidBody', async () => {
const sceneObjOne: SceneObjectBase = await Scene.root.findFirst('a-scene-obj');
const obj = new Object3D(sceneObjOne);

expect(() => obj.makeRigidBody()).toThrow();
});
});
31 changes: 31 additions & 0 deletions tests/quaternion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ describe('quaternion utils', () => {
expect(A.values).toEqual([0, 0, 0, 1]);
expect(B.values).toEqual([0, 0, 1, 0]);
});
test('toString', () => {
const Q = new Quaternion(1, 0, 0, 0);
expect(Q.toString(0)).toEqual('Quaternion: [1,0,0,0]');
});
test('toArray', () => {
const Q = new Quaternion(1, 0, 0, 0);
expect(Q.toArray()).toEqual([1, 0, 0, 0]);
});
test('toEulerArray', () => {
const Q = new Quaternion(1, 0, 0, 0);
expect(Q.toEulerArray()).toEqual([0, 0, 0]);
});
test('setSignalComponents', () => {
const Q = new Quaternion(1, 0, 0, 0);
expect(() => Q.setSignalComponents()).not.toThrow();
});
test('disposeSignalResources', () => {
const Q = new Quaternion(1, 0, 0, 0);
expect(() => Q.disposeSignalResources()).not.toThrow();
});
});

describe('operations', () => {
Expand All @@ -89,6 +109,13 @@ describe('operations', () => {
Q.add(Q);
expect(Q.normalized.values).toEqual([1, 0, 0, 0]);
});
test('lookAtOptimized', () => {
// already tested on "quaternion construction"
const nonOp = Quaternion.lookAt(new Vector(0, 0, 0), new Vector(0, 0, -1));
const op = Quaternion.lookAtOptimized(new Vector(0, 0, -1).values);
const match = nonOp.values.every((v, i) => Math.abs(v - op.values[i]) < 0.001);
expect(match).toEqual(true);
});
});

describe('accessors', () => {
Expand All @@ -113,4 +140,8 @@ describe('accessors', () => {
Q1234.z *= 2;
expect(Q1234.z).toEqual(8);
});
test('signal', () => {
expect(Q1234.signal).toBeTruthy();
expect(Q1234.signal.w).toBeTruthy();
});
});
13 changes: 13 additions & 0 deletions tests/vector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ describe('vector utils', () => {
expect(Vector.fromSignal(Scalar).values).toEqual([1]);
expect(Vector.fromSignal(Vec4Signal).values).toEqual([1, 2, 3, 4]);
});
test('setSignalComponents', () => {
const Q = new Vector(0, 0, 0);
expect(() => Q.setSignalComponents()).not.toThrow();
});
test('disposeSignalResources', () => {
const Q = new Vector(0, 0, 0);
expect(() => Q.disposeSignalResources()).not.toThrow();
});
test('screenToWorld', async () => {
privates.clearVoltsWorld();

Expand Down Expand Up @@ -238,4 +246,9 @@ describe('accessors', () => {
expect((fourD.w += 1)).toEqual(5);
expect(fourD.w).toEqual(5);
});
test('signal', () => {
expect(threeD.signal).toBeTruthy();
expect(threeD.signal.z).toBeTruthy();
expect(() => threeD.w).toThrow();
});
});
Loading

0 comments on commit a04a4fc

Please sign in to comment.