Skip to content

Commit

Permalink
Revert "Revert "TEST""
Browse files Browse the repository at this point in the history
This reverts commit b365ed9.
  • Loading branch information
jacklehamster committed Feb 29, 2024
1 parent b365ed9 commit b85a886
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
Binary file modified bun.lockb
Binary file not shown.
43 changes: 28 additions & 15 deletions example/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46312,7 +46312,7 @@ class B2 {
return this.#w?.goal ?? this.valueOf();
}
}
var z4 = function(D3, J = Y) {
var z4 = function(D3, J = _3) {
R3(D3, (K2, Q3) => D3.informUpdate(Q3, J));
};

Expand Down Expand Up @@ -46463,7 +46463,8 @@ class H2 extends X2 {
#D;
#J = new Map;
#K = new O3;
#Q = new $2({ informUpdate: this.informUpdate.bind(this), addElem: this.#R.bind(this), removeElem: this.#V.bind(this) });
#Q = new $2({ informUpdate: this.informUpdate.bind(this), addElem: this.#V.bind(this), removeElem: this.#W.bind(this) });
#R = false;
constructor({ onChange: D3 } = {}) {
super();
this.#D = new B3({ onChange: D3 });
Expand All @@ -46472,6 +46473,8 @@ class H2 extends X2 {
return this.#D.length;
}
at(D3) {
if (!this.#R)
return;
const J = this.#D.at(D3);
return J?.elems.at(J.index);
}
Expand All @@ -46490,15 +46493,23 @@ class H2 extends X2 {
this.#K.recycle(D3);
}), this.#D.clear();
}
activate() {
if (!this.#R)
this.#R = true, this.updateFully();
}
deactivate() {
if (this.#R)
this.#R = false, this.updateFully();
}
updateFully(D3) {
for (let [J, K2] of this.#J)
R3(J, (Q3, V22) => K2.onUpdate(V22, D3));
}
#R(D3, J) {
#V(D3, J) {
const K2 = this.#D.addElem(this.#K.create(D3, J));
return this.informUpdate(K2), K2;
}
#V(D3) {
#W(D3) {
const J = this.#D.removeElem(D3);
if (J)
this.#K.recycle(J), this.informUpdate(D3);
Expand All @@ -46518,7 +46529,7 @@ class O3 extends W2 {
}
}

class _3 {
class Y {
i;
f;
warningLimit = 50000;
Expand Down Expand Up @@ -46556,7 +46567,7 @@ class _3 {
console.warn("ObjectPool already created", this.#D.size + this.#J.length, "in", this.constructor.name);
}
}
var Y = -1;
var _3 = -1;

class UpdateRegistry extends X2 {
applyUpdate;
Expand Down Expand Up @@ -47842,7 +47853,7 @@ class b2 extends I {
}
var U = [3, 3, 3];

class h2 {
class E3 {
cellTags = new R4("");
cellTrack;
cellPool = new Q3;
Expand Down Expand Up @@ -47904,7 +47915,7 @@ class G4 {
}
}

class E3 {
class h2 {
minX;
maxX;
minY;
Expand Down Expand Up @@ -47949,7 +47960,7 @@ class M2 {
this.#H.recycle(Y2);
}
activate() {
this.#w.addChangeListener(this.#K), this.#m.pos[0] = Number.NaN, this.#m.pos[1] = Number.NaN, this.#m.pos[2] = Number.NaN, this.#J(this.#w);
this.#m.pos[0] = Number.NaN, this.#m.pos[1] = Number.NaN, this.#m.pos[2] = Number.NaN, this.#w.addChangeListener(this.#K), this.#J(this.#w);
}
deactivate() {
this.#w.removeChangeListener(this.#K);
Expand Down Expand Up @@ -48055,13 +48066,12 @@ var updateBodyRecord = function(record, accumulator, id, elems) {
};

class BodyModel {
transform;
sprites = new H2;
colliders = new H2;
#bodies = new H2;
#spritesPerId = {};
#collidersPerId = {};
constructor({ sprites, colliders, bodies, transform } = {}) {
constructor({ sprites, colliders, bodies } = {}) {
this.#bodies.addUpdateListener({
onUpdate: (bodyId) => {
const body = this.#bodies.at(bodyId);
Expand All @@ -48078,7 +48088,6 @@ class BodyModel {
if (bodies) {
this.#bodies.add(bodies);
}
this.transform = transform ?? d.IDENTITY;
}
addSprites(sprites) {
this.sprites.add(sprites);
Expand Down Expand Up @@ -48203,6 +48212,7 @@ class DemoGame extends AuxiliaryHolder {
constructor({ engine, motor, ui, keyboard, controls }) {
super();
const mediaAccumulator = new H2;
this.addAuxiliary(mediaAccumulator);
this.addAuxiliary(new MediaUpdater({ engine, motor, medias: mediaAccumulator }));
const mediaItems = new ItemsGroup([{
id: Assets.DOBUKI,
Expand Down Expand Up @@ -48412,6 +48422,7 @@ class DemoGame extends AuxiliaryHolder {
}
});
const animationAccumulator = new H2;
this.addAuxiliary(animationAccumulator);
this.addAuxiliary(new AnimationUpdater({ engine, motor, animations: animationAccumulator }));
const animationItems = new ItemsGroup([{
id: Anims.STILL,
Expand All @@ -48435,6 +48446,7 @@ class DemoGame extends AuxiliaryHolder {
const spritesAccumulator = new H2({
onChange: (value) => engine.setMaxSpriteCount(value)
});
this.addAuxiliary(spritesAccumulator);
this.addAuxiliary({
deactivate() {
engine.setMaxSpriteCount(0);
Expand All @@ -48452,6 +48464,7 @@ class DemoGame extends AuxiliaryHolder {
const exitCell = N3(0, 0, 0, CELLSIZE);
const exitPosition = exitCell.worldPosition;
const worldColliders = new H2;
this.addAuxiliary(worldColliders);
const heroBox = {
top: 1,
bottom: -1,
Expand Down Expand Up @@ -48580,7 +48593,7 @@ class DemoGame extends AuxiliaryHolder {
const spritesMap = new Map;
const collidersMap = new Map;
cellTrackers.add(P({
trackCell: function(cell) {
trackCell: (cell) => {
const rng2 = import_seedrandom.alea(cell.tag);
const sprites = arrayPool.create();
const cellPos = cell.pos;
Expand Down Expand Up @@ -48649,7 +48662,7 @@ class DemoGame extends AuxiliaryHolder {
}
});
}
}, new E3({ yRange: [0, 0] })));
}, new h2({ yRange: [0, 0] })));
}
worldColliders.add([
...blockPositions.map((blockPosition) => new CollisionDetector({
Expand Down Expand Up @@ -48746,7 +48759,7 @@ class DemoGame extends AuxiliaryHolder {
heroSprites.setAnimationId(animId);
shadowHeroSprites.setAnimationId(animId);
}));
const surroundingTracker = new h2({ cellTrack: cellTrackers }, {
const surroundingTracker = new E3({ cellTrack: cellTrackers }, {
cellLimit: 200,
range: [7, 3, 7],
cellSize: CELLSIZE
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
"typescript": "^5.2.2"
},
"dependencies": {
"cell-tracker": "^1.0.20",
"cell-tracker": "^1.0.22",
"gl-texture-manager": "^1.0.14",
"list-accumulator": "^1.0.9",
"list-accumulator": "^1.0.11",
"seedrandom": "^3.0.5",
"uuid": "^9.0.1"
},
Expand Down
6 changes: 5 additions & 1 deletion src/demo/DemoGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class DemoGame extends AuxiliaryHolder {
// * Each media is a texture that can be shown on a sprite.
// * You can show videos, images, or you can have instructions to draw on a canvas.
const mediaAccumulator = new Accumulator<Media>();
this.addAuxiliary(mediaAccumulator);
this.addAuxiliary(new MediaUpdater({ engine, motor, medias: mediaAccumulator }));
const mediaItems = new ItemsGroup<Media>([{
id: Assets.DOBUKI,
Expand Down Expand Up @@ -316,6 +317,7 @@ export class DemoGame extends AuxiliaryHolder {
});

const animationAccumulator = new Accumulator<Animation>();
this.addAuxiliary(animationAccumulator);
this.addAuxiliary(new AnimationUpdater({ engine, motor, animations: animationAccumulator }));
const animationItems = new ItemsGroup<Animation>([{
id: Anims.STILL,
Expand All @@ -340,6 +342,7 @@ export class DemoGame extends AuxiliaryHolder {
const spritesAccumulator = new Accumulator<Sprite>({
onChange: (value) => engine.setMaxSpriteCount(value),
});
this.addAuxiliary(spritesAccumulator);
this.addAuxiliary({
deactivate() {
engine.setMaxSpriteCount(0);
Expand All @@ -359,6 +362,7 @@ export class DemoGame extends AuxiliaryHolder {
const exitPosition = exitCell.worldPosition;

const worldColliders = new Accumulator<ICollisionDetector>();
this.addAuxiliary(worldColliders);

const heroBox = {
top: 1,
Expand Down Expand Up @@ -518,7 +522,7 @@ export class DemoGame extends AuxiliaryHolder {
const spritesMap = new Map<Tag, Sprite[]>();
const collidersMap = new Map<Tag, ICollisionDetector[]>();
cellTrackers.add(filter({
trackCell: function (cell: Cell): boolean {
trackCell: (cell: Cell): boolean => {
const rng = alea(cell.tag);
const sprites: Sprite[] = arrayPool.create();
const cellPos = cell.pos;
Expand Down
5 changes: 1 addition & 4 deletions src/world/sprite/body/BodyModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ interface Props {
sprites: IPotentiallyUpdatableList<Sprite>;
colliders: IPotentiallyUpdatableList<ICollisionDetector>;
bodies: IPotentiallyUpdatableList<IBodyModel>;
transform: IMatrix;
}

export class BodyModel implements IBodyModel {
readonly transform: IMatrix;
readonly sprites = new Accumulator<Sprite>();
readonly colliders = new Accumulator<ICollisionDetector>();
readonly #bodies = new Accumulator<IBodyModel>();
readonly #spritesPerId: Record<IdType, IPotentiallyUpdatableList<Sprite>> = {};
readonly #collidersPerId: Record<IdType, IPotentiallyUpdatableList<ICollisionDetector>> = {};

constructor({ sprites, colliders, bodies, transform }: Partial<Props> = {}) {
constructor({ sprites, colliders, bodies }: Partial<Props> = {}) {
this.#bodies.addUpdateListener({
onUpdate: (bodyId: IdType): void => {
const body = this.#bodies.at(bodyId);
Expand All @@ -36,7 +34,6 @@ export class BodyModel implements IBodyModel {
if (bodies) {
this.#bodies.add(bodies);
}
this.transform = transform ?? Matrix.IDENTITY;
}

addSprites(sprites: IPotentiallyUpdatableList<Sprite>): void {
Expand Down
1 change: 0 additions & 1 deletion src/world/sprite/body/IBodyModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ import { ICollisionDetector, IMatrix } from "dok-matrix";
export interface IBodyModel {
readonly sprites: IUpdatableList<Sprite>;
readonly colliders: IUpdatableList<ICollisionDetector>;
readonly transform: IMatrix;
}

0 comments on commit b85a886

Please sign in to comment.