Skip to content

Commit

Permalink
feat: renderer custimization
Browse files Browse the repository at this point in the history
  • Loading branch information
load1n9 committed Feb 11, 2022
1 parent 3d94142 commit 5f2e832
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 105 deletions.
10 changes: 10 additions & 0 deletions assets/system/icons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


# color palette
- #DD901C
- #DD791C
- #F6D7BA
- #CFBEAE
- #9E8F81
- #564E46
- #302B27
1 change: 0 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export {
MSX,
// Particle,
// ParticleSystem,
// PhysicsRectangle,
PICO8,
// Point,
// Polygon,
Expand Down
57 changes: 0 additions & 57 deletions src/entities/physics/Rectangle.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/entities/physics/mod.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/entities/physics/types.ts

This file was deleted.

27 changes: 21 additions & 6 deletions src/renderers/webgl/2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class WebGLRenderer2D {
private gl: WebGL2RenderingContext;
private location: ProgramInfo2d;
private buffers: Map<string, EntityBuffers>;

private backgroundColor: Array<number> = [0.0, 0.0, 0.0, 1.0];
constructor(private canvas: Canvas) {
const gl = canvas.getContext("webgl");
if (!gl) throw new Error(`Could not request device!`);
Expand Down Expand Up @@ -56,13 +56,21 @@ export class WebGLRenderer2D {
for (const child of entity.children) {
this._start(child);
}
} else if (entity instanceof Image || entity instanceof AtlasSprite || entity instanceof Sprite) {
} else if (
entity instanceof Image || entity instanceof AtlasSprite ||
entity instanceof Sprite
) {
this.setupImage(entity);
}
}

public render(entities: Entity[]): void {
this.gl.clearColor(1.0, 1.0, 1.0, 1.0);
this.gl.clearColor(
this.backgroundColor[0],
this.backgroundColor[1],
this.backgroundColor[2],
this.backgroundColor[3],
);
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
this.gl.viewport(0, 0, this.canvas.width, this.canvas.height);

Expand All @@ -82,7 +90,10 @@ export class WebGLRenderer2D {
for (const child of entity.children) {
this._render(child);
}
} else if (entity instanceof Image || entity instanceof AtlasSprite || entity instanceof Sprite) {
} else if (
entity instanceof Image || entity instanceof AtlasSprite ||
entity instanceof Sprite
) {
this.renderImage(entity);
}
}
Expand Down Expand Up @@ -121,7 +132,9 @@ export class WebGLRenderer2D {
}

private setupImage(entity: Image | AtlasSprite): void {
const { x, y, width, height } = entity instanceof Image? { x: 0, y: 0, width: entity.width, height: entity.height } : entity.frame;
const { x, y, width, height } = entity instanceof Image
? { x: 0, y: 0, width: entity.width, height: entity.height }
: entity.frame;
const data = [
x,
y,
Expand Down Expand Up @@ -161,7 +174,9 @@ export class WebGLRenderer2D {
this.gl.uniform1f(this.location.usage, 1);
this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4);
}

public setBackground(color: RGBA): void {
this.backgroundColor = this.colorNorm(color);
}
private colorNorm(rgba: RGBA): Array<number> {
return rgba.map((c) => c / 255);
}
Expand Down
25 changes: 0 additions & 25 deletions src/scenes/PhysicsScene.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/scenes/mod.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { Scene } from "./Scene.ts";
// export { PhysicsScene } from "./PhysicsScene.ts";
export { Scene } from "./Scene.ts";

0 comments on commit 5f2e832

Please sign in to comment.