Add basic tiled rendering

This commit is contained in:
schmelczerandras 2020-07-27 22:53:17 +02:00
parent 854e5a55a1
commit edffd22c2e
26 changed files with 350 additions and 167 deletions

View file

@ -1,5 +1,5 @@
import { vec2 } from 'gl-matrix';
import { BeforeDrawCommand } from '../../commands/types/before-draw';
import { BeforeRenderCommand } from '../../commands/types/before-render';
import { CursorMoveCommand } from '../../commands/types/cursor-move-command';
import { MoveToCommand } from '../../commands/types/move-to';
import { ZoomCommand } from '../../commands/types/zoom';
@ -13,7 +13,7 @@ export class Camera extends GameObject {
constructor(private light: CircleLight) {
super();
this.addCommandExecutor(BeforeDrawCommand, this.draw.bind(this));
this.addCommandExecutor(BeforeRenderCommand, this.draw.bind(this));
this.addCommandExecutor(MoveToCommand, this.moveTo.bind(this));
this.addCommandExecutor(
CursorMoveCommand,
@ -22,10 +22,10 @@ export class Camera extends GameObject {
this.addCommandExecutor(ZoomCommand, this.zoom.bind(this));
}
private draw(c: BeforeDrawCommand) {
c.drawer.setCameraPosition(this.position);
c.drawer.setCursorPosition(this.cursorPosition);
this._boundingBoxSize = c.drawer.setInViewArea(this.inViewArea);
private draw(c: BeforeRenderCommand) {
c.renderer.setCameraPosition(this.position);
c.renderer.setCursorPosition(this.cursorPosition);
this._boundingBoxSize = c.renderer.setInViewArea(this.inViewArea);
}
private moveTo(c: MoveToCommand) {

View file

@ -1,7 +1,7 @@
import { vec2, vec3 } from 'gl-matrix';
import { DrawCommand } from '../../commands/types/draw';
import { RenderCommand } from '../../commands/types/draw';
import { MoveToCommand } from '../../commands/types/move-to';
import { Circle } from '../../math/circle';
import { Circle } from '../../drawing/primitives/circle';
import { GameObject } from '../game-object';
const range = 2000;
@ -18,13 +18,13 @@ export class CircleLight extends GameObject {
this.boundingCircle = new Circle(center, range);
this.addCommandExecutor(DrawCommand, this.draw.bind(this));
this.addCommandExecutor(RenderCommand, this.draw.bind(this));
this.addCommandExecutor(MoveToCommand, this.moveTo.bind(this));
}
private draw(c: DrawCommand) {
if (c.drawer.isPositionOnScreen(this.center)) {
c.drawer.appendToUniformList('lights', {
private draw(c: RenderCommand) {
if (c.renderer.isPositionOnScreen(this.center)) {
c.renderer.appendToUniformList('lights', {
center: this.center,
radius: this.radius,
value: this.value,

View file

@ -1,11 +1,11 @@
import { RenderCommand } from '../../commands/types/draw';
import { GameObject } from '../game-object';
import { DrawCommand } from '../../commands/types/draw';
export class InfoText extends GameObject {
constructor() {
super();
this.addCommandExecutor(DrawCommand, this.draw.bind(this));
this.addCommandExecutor(RenderCommand, this.draw.bind(this));
}
private static records: Map<string, string> = new Map();
@ -14,9 +14,9 @@ export class InfoText extends GameObject {
InfoText.records.set(key, value);
}
private draw(e: DrawCommand) {
private draw(e: RenderCommand) {
let text = '';
InfoText.records.forEach((v, k) => (text += `${k}\n\t${v}\n`));
e.drawer.drawInfoText(text);
e.renderer.drawInfoText(text);
}
}

View file

@ -1,36 +1,20 @@
import { vec2 } from 'gl-matrix';
import { DrawCommand } from '../../commands/types/draw';
import { Circle } from '../../math/circle';
import { RenderCommand } from '../../commands/types/draw';
import { TunnelShape } from '../../drawing/primitives/tunnel-shape';
import { GameObject } from '../game-object';
export interface Line {}
export class Tunnel extends GameObject {
private boundingCircle: Circle;
private tangent: vec2;
private primitive: TunnelShape;
constructor(
private from: vec2,
private to: vec2,
private radiusFrom: number,
private radiusTo: number
) {
constructor(from: vec2, to: vec2, fromRadius: number, toRadius: number) {
super();
this.boundingCircle = new Circle(
vec2.fromValues(from.x / 2 + to.x / 2, from.y / 2 + to.y / 2),
radiusFrom + radiusTo + vec2.distance(from, to)
);
this.tangent = vec2.subtract(vec2.create(), to, from);
this.addCommandExecutor(DrawCommand, this.draw.bind(this));
this.primitive = new TunnelShape(from, to, fromRadius, toRadius);
this.addCommandExecutor(RenderCommand, this.draw.bind(this));
}
private draw(c: DrawCommand) {
if (c.drawer.isOnScreen(this.boundingCircle)) {
c.drawer.appendToUniformList('lines', this.from, this.tangent);
c.drawer.appendToUniformList('radii', this.radiusFrom, this.radiusTo);
}
private draw(c: RenderCommand) {
c.renderer.drawPrimitive(this.primitive);
}
}