Start refactoring

This commit is contained in:
schmelczerandras 2020-07-29 22:33:46 +02:00
commit 9b47d56d8f
39 changed files with 423 additions and 234 deletions

View file

@ -18,11 +18,8 @@ A good-looking 2D adventure.
- rancher os - rancher os
- Frontend nginx disable logging - Frontend nginx disable logging
- procedural piano - procedural piano
- obfuscate function names
- lightweight object storage - lightweight object storage
- dockerswarm.rocks
- local dev env - local dev env
- CI pipeline: - CI pipeline:
- prettier script - prettier script
- tests? - tests?
- monitoring: https://dockerswarm.rocks/swarmpit/

View file

@ -5,7 +5,6 @@
<title>{title}</title> <title>{title}</title>
<meta name="theme-color" content="#b7455e" /> <meta name="theme-color" content="#b7455e" />
<meta name="viewport" content="initial-scale=1.0" /> <meta name="viewport" content="initial-scale=1.0" />
<style> <style>
html, html,
body { body {
@ -21,7 +20,7 @@
} }
h1 { h1 {
font-family: 'Roboto', 'Helvetica Neue', sans-serif; font-family: "Roboto", "Helvetica Neue", sans-serif;
font-weight: 100; font-weight: 100;
font-size: 3rem; font-size: 3rem;
color: white; color: white;

View file

@ -1,8 +1,12 @@
import { IRenderer } from '../../drawing/i-renderer';
import { Command } from '../command'; import { Command } from '../command';
import { IRenderer } from '../../drawing/rendering/i-renderer';
export class BeforeRenderCommand extends Command { export class BeforeRenderCommand extends Command {
public constructor(public readonly renderer?: IRenderer) { public constructor(public readonly renderer?: IRenderer) {
super(); super();
} }
public get type(): string {
return 'BeforeRenderCommand';
}
} }

View file

@ -5,4 +5,8 @@ export class CursorMoveCommand extends Command {
public constructor(public readonly position?: vec2) { public constructor(public readonly position?: vec2) {
super(); super();
} }
public get type(): string {
return 'CursorMoveCommand';
}
} }

View file

@ -1,8 +1,12 @@
import { IRenderer } from '../../drawing/i-renderer';
import { Command } from '../command'; import { Command } from '../command';
import { IRenderer } from '../../drawing/rendering/i-renderer';
export class RenderCommand extends Command { export class RenderCommand extends Command {
public constructor(public readonly renderer?: IRenderer) { public constructor(public readonly renderer?: IRenderer) {
super(); super();
} }
public get type(): string {
return 'RenderCommand';
}
} }

View file

@ -4,4 +4,8 @@ export class KeyDownCommand extends Command {
public constructor(public readonly key?: string) { public constructor(public readonly key?: string) {
super(); super();
} }
public get type(): string {
return 'KeyDownCommand';
}
} }

View file

@ -4,4 +4,8 @@ export class KeyUpCommand extends Command {
public constructor(public readonly key?: string) { public constructor(public readonly key?: string) {
super(); super();
} }
public get type(): string {
return 'KeyUpCommand';
}
} }

View file

@ -5,4 +5,8 @@ export class MoveToCommand extends Command {
public constructor(public readonly position?: vec2) { public constructor(public readonly position?: vec2) {
super(); super();
} }
public get type(): string {
return 'MoveToCommand';
}
} }

View file

@ -5,4 +5,8 @@ export class PrimaryActionCommand extends Command {
public constructor(public readonly position?: vec2) { public constructor(public readonly position?: vec2) {
super(); super();
} }
public get type(): string {
return 'PrimaryActionCommand';
}
} }

View file

@ -5,4 +5,8 @@ export class SecondaryActionCommand extends Command {
public constructor(public readonly position?: vec2) { public constructor(public readonly position?: vec2) {
super(); super();
} }
public get type(): string {
return 'SecondaryActionCommand';
}
} }

View file

@ -6,4 +6,8 @@ export class StepCommand extends Command {
) { ) {
super(); super();
} }
public get type(): string {
return 'StepCommand';
}
} }

View file

@ -5,4 +5,8 @@ export class SwipeCommand extends Command {
public constructor(public readonly delta?: vec2) { public constructor(public readonly delta?: vec2) {
super(); super();
} }
public get type(): string {
return 'SwipeCommand';
}
} }

View file

@ -4,4 +4,8 @@ export class ZoomCommand extends Command {
public constructor(public readonly factor?: number) { public constructor(public readonly factor?: number) {
super(); super();
} }
public get type(): string {
return 'ZoomCommand';
}
} }

View file

@ -1,22 +0,0 @@
import { vec2 } from 'gl-matrix';
import { Circle } from './primitives/circle';
import { IPrimitive } from './primitives/i-primitive';
export interface IRenderer {
startFrame(deltaTime: DOMHighResTimeStamp): void;
finishFrame(): void;
drawPrimitive(primitive: IPrimitive): void;
setCameraPosition(position: vec2): void;
setCursorPosition(position: vec2): void;
setInViewArea(size: number): vec2;
giveUniforms(uniforms: any): void;
appendToUniformList(listName: string, ...values: Array<any>): void;
screenUvToWorldCoordinate(mousePosition: vec2): vec2;
drawInfoText(text: string): void;
isOnScreen(boundingCircle: Circle): boolean;
isPositionOnScreen(position: vec2): boolean;
}

View file

@ -0,0 +1,35 @@
import { ILight } from './i-light';
import { vec2, vec3 } from 'gl-matrix';
export class CircleLight implements ILight {
public static uniformName = 'lights';
constructor(
public center: vec2,
public radius: number,
public color: vec3,
public lightness: number
) {}
serializeToUniforms(uniforms: any): void {
const listName = CircleLight.uniformName;
if (!uniforms.hasOwnProperty(listName)) {
uniforms[listName] = [];
}
uniforms[listName].push({
center: this.center,
radius: this.radius,
value: this.value,
});
}
get value(): vec3 {
return vec3.scale(
vec3.create(),
vec3.normalize(this.color, this.color),
this.lightness
);
}
}

View file

@ -0,0 +1,3 @@
export interface ILight {
serializeToUniforms(uniforms: any): void;
}

View file

@ -0,0 +1,30 @@
import { ILight } from './i-light';
import { vec2, vec3 } from 'gl-matrix';
export class PointLight implements ILight {
public static uniformName = 'lights';
constructor(
public center: vec2,
public color: vec3,
public lightness: number
) {}
serializeToUniforms(uniforms: any): void {
const listName = PointLight.uniformName;
if (!uniforms.hasOwnProperty(listName)) {
uniforms[listName] = [];
}
uniforms[listName].push({
center: this.center,
radius: 0,
value: this.value,
});
}
get value(): vec3 {
return vec3.scale(vec3.create(), this.color, this.lightness);
}
}

View file

@ -2,7 +2,11 @@ import { vec2 } from 'gl-matrix';
import { IPrimitive } from './i-primitive'; import { IPrimitive } from './i-primitive';
export class Circle implements IPrimitive { export class Circle implements IPrimitive {
public constructor(public center: vec2, public radius: number) {} public constructor(public center = vec2.create(), public radius = 0) {}
public serializeToUniforms(uniforms: any): void {
throw new Error('Method not implemented.');
}
public distance(target: vec2): number { public distance(target: vec2): number {
return vec2.distance(this.center, target) - this.radius; return vec2.distance(this.center, target) - this.radius;

View file

@ -1,6 +1,7 @@
import { vec2 } from 'gl-matrix'; import { vec2 } from 'gl-matrix';
export interface IPrimitive { export interface IPrimitive {
serializeToUniforms(uniforms: any): void;
distance(target: vec2): number; distance(target: vec2): number;
minimumDistance(target: vec2): number; minimumDistance(target: vec2): number;
} }

View file

@ -5,6 +5,9 @@ import { Circle } from './circle';
import { IPrimitive } from './i-primitive'; import { IPrimitive } from './i-primitive';
export class TunnelShape implements IPrimitive { export class TunnelShape implements IPrimitive {
public static uniformNameLines = 'lines';
public static uniformNameRadii = 'radii';
public readonly toFromDelta: vec2; public readonly toFromDelta: vec2;
private toFromDeltaLength: number; private toFromDeltaLength: number;
@ -25,6 +28,21 @@ export class TunnelShape implements IPrimitive {
); );
} }
serializeToUniforms(uniforms: any): void {
if (!uniforms.hasOwnProperty(TunnelShape.uniformNameLines)) {
uniforms[TunnelShape.uniformNameLines] = [];
}
if (!uniforms.hasOwnProperty(TunnelShape.uniformNameRadii)) {
uniforms[TunnelShape.uniformNameRadii] = [];
}
uniforms[TunnelShape.uniformNameLines].push(this.from);
uniforms[TunnelShape.uniformNameLines].push(this.toFromDelta);
uniforms[TunnelShape.uniformNameRadii].push(this.fromRadius);
uniforms[TunnelShape.uniformNameRadii].push(this.toRadius);
}
public distance(target: vec2): number { public distance(target: vec2): number {
const targetFromDelta = vec2.subtract(vec2.create(), target, this.from); const targetFromDelta = vec2.subtract(vec2.create(), target, this.from);
const h = clamp01( const h = clamp01(

Some files were not shown because too many files have changed in this diff Show more