Skip to content

Commit

Permalink
more renderer code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffomatic committed Dec 21, 2020
1 parent 8fd3e03 commit 657259c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ClientMessage, ClientMessageType } from '~/network/ClientMessage'
import { IServerConnection } from '~/network/ServerConnection'
import { ServerMessage, ServerMessageType } from '~/network/ServerMessage'
import { ParticleEmitter } from '~/particles/ParticleEmitter'
import { Primitive2d, Renderable2d, TextAlign } from '~/renderer/interfaces'
import { Primitive2d, Renderable2d, TextAlign } from '~/renderer/Renderer2d'
import { Renderer3d } from '~/renderer/Renderer3d'
import { simulate } from '~/simulate'
import * as systems from '~/systems'
Expand Down
10 changes: 0 additions & 10 deletions src/components/IRenderable.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/entities/EntityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,6 @@ export class EntityManager {
this.predictedDeletes = new SortedSet()
}

// public getRenderables(aabb: [vec2, vec2]): Renderable[] {
// const renderables: Renderable[] = []
// for (const id of this.queryByWorldPos(aabb)) {
// const r = this.renderables.get(id)
// if (!r) {
// continue
// }

// // an as-cast is required here to call member variables. Eventually, we
// // should transform this object into a plain-old-data structure instead
// // of a class.
// renderables.push(...(r as IRenderable).getRenderables(this, id))
// }
// return renderables
// }

public getPlayerId(playerNumber: number): EntityId | undefined {
for (const [id, n] of this.playerNumbers) {
if (n === playerNumber) {
Expand Down
2 changes: 1 addition & 1 deletion src/particles/ParticleEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { vec2 } from 'gl-matrix'
import { sample } from 'lodash'

import { Primitive2d, Renderable2d } from '~/renderer/interfaces'
import { Primitive2d, Renderable2d } from '~/renderer/Renderer2d'
import { lerp, radialTranslate2 } from '~/util/math'

interface Particle {
Expand Down
57 changes: 56 additions & 1 deletion src/renderer/Renderer2d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,63 @@
import { mat2d, vec2 } from 'gl-matrix'

import { Primitive2d, Renderable2d, TextAlign } from '~/renderer/interfaces'
import { transformCircle } from '~/util/math'

export enum Primitive2d {
PATH = 0,
RECT = 1,
CIRCLE = 2,
LINE = 3,
TEXT = 4,
}

export interface Path {
primitive: Primitive2d.PATH
fillStyle: string
mwTransform: mat2d
path: Array<vec2> // modelspace coordinates
}

export interface Rect {
primitive: Primitive2d.RECT
fillStyle?: string
strokeStyle?: string
pos: vec2 // worldspace coordinates
dimensions: vec2
}

export interface Circle {
primitive: Primitive2d.CIRCLE
fillStyle: string
pos: vec2 // worldspace coordinates
radius: number
}

export interface Line {
primitive: Primitive2d.LINE
style: string
from: vec2
to: vec2
width: number
}

export enum TextAlign {
Min,
Center,
Max,
}

export interface Text {
primitive: Primitive2d.TEXT
style: string
font: string
pos: vec2
text: string
hAlign: TextAlign
vAlign: TextAlign
}

export type Renderable2d = Path | Rect | Circle | Line | Text

export class Renderer2d {
private ctx: CanvasRenderingContext2D
private transform: mat2d
Expand Down
57 changes: 0 additions & 57 deletions src/renderer/interfaces.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/tools/map/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import * as entities from '~/entities'
import { Keyboard } from '~/input/Keyboard'
import { Mouse, MouseButton } from '~/input/Mouse'
import { Map } from '~/map/interfaces'
import { Primitive2d } from '~/renderer/interfaces'
import { Renderer2d } from '~/renderer/Renderer2d'
import { Primitive2d, Renderer2d } from '~/renderer/Renderer2d'
import * as terrain from '~/terrain'
import * as math from '~/util/math'

Expand Down

0 comments on commit 657259c

Please sign in to comment.