update voronoi for weak hardware
This commit is contained in:
parent
bfd068410c
commit
09711466ac
5 changed files with 47 additions and 14 deletions
|
@ -31,18 +31,11 @@
|
||||||
<p>{{game.name}}</p>
|
<p>{{game.name}}</p>
|
||||||
<p>Turns: {{game.turns}}</p>
|
<p>Turns: {{game.turns}}</p>
|
||||||
</div>
|
</div>
|
||||||
{# {% else %}
|
|
||||||
<div class="option">
|
|
||||||
No options available
|
|
||||||
</div> #}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
|
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
|
||||||
<script>
|
|
||||||
console.log(window);
|
|
||||||
</script>
|
|
||||||
<script src="frontend/bootstrap.js"></script>
|
<script src="frontend/bootstrap.js"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Game } from "planetwars";
|
import { Game } from "planetwars";
|
||||||
import { memory } from "planetwars/planetwars_bg";
|
import { memory } from "planetwars/planetwars_bg";
|
||||||
import { Resizer, resizeCanvasToDisplaySize, FPSCounter, url_to_mesh, Mesh } from "./webgl/util";
|
import { Resizer, resizeCanvasToDisplaySize, FPSCounter, url_to_mesh, Mesh } from "./webgl/util";
|
||||||
import { Shader, Uniform4f, Uniform2fv, Uniform3fv, Uniform1i, Uniform1f, Uniform2f, ShaderFactory, Uniform3f, UniformMatrix3fv } from './webgl/shader';
|
import { Shader, Uniform4f, Uniform2fv, Uniform3fv, Uniform1i, Uniform1f, Uniform2f, ShaderFactory, Uniform3f, UniformMatrix3fv, UniformBool } from './webgl/shader';
|
||||||
import { Renderer } from "./webgl/renderer";
|
import { Renderer } from "./webgl/renderer";
|
||||||
import { VertexBuffer, IndexBuffer } from "./webgl/buffer";
|
import { VertexBuffer, IndexBuffer } from "./webgl/buffer";
|
||||||
import { VertexBufferLayout, VertexArray } from "./webgl/vertexBufferLayout";
|
import { VertexBufferLayout, VertexArray } from "./webgl/vertexBufferLayout";
|
||||||
|
@ -79,6 +79,8 @@ class GameInstance {
|
||||||
renderer: Renderer;
|
renderer: Renderer;
|
||||||
planet_count: number;
|
planet_count: number;
|
||||||
|
|
||||||
|
vor_counter = 3;
|
||||||
|
use_vor = true;
|
||||||
playing = true; // 0 is paused, 1 is playing but not rerendered, 2 is playing and rerendered
|
playing = true; // 0 is paused, 1 is playing but not rerendered, 2 is playing and rerendered
|
||||||
time_stopped_delta = 0;
|
time_stopped_delta = 0;
|
||||||
last_time = 0;
|
last_time = 0;
|
||||||
|
@ -223,6 +225,16 @@ class GameInstance {
|
||||||
render(time: number) {
|
render(time: number) {
|
||||||
COUNTER.frame(time);
|
COUNTER.frame(time);
|
||||||
|
|
||||||
|
if (COUNTER.delta(time) < 30) {
|
||||||
|
this.vor_counter = Math.min(3, this.vor_counter + 1);
|
||||||
|
} else {
|
||||||
|
this.vor_counter = Math.max(-3, this.vor_counter - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.vor_counter < -2) {
|
||||||
|
this.use_vor = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.playing) {
|
if (!this.playing) {
|
||||||
this.last_time = time;
|
this.last_time = time;
|
||||||
|
|
||||||
|
@ -244,11 +256,13 @@ class GameInstance {
|
||||||
|
|
||||||
this.vor_shader.uniform(GL, "u_viewbox", new Uniform4f(this.resizer.get_viewbox()));
|
this.vor_shader.uniform(GL, "u_viewbox", new Uniform4f(this.resizer.get_viewbox()));
|
||||||
this.vor_shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION));
|
this.vor_shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION));
|
||||||
|
this.vor_shader.uniform(GL, "u_vor", new UniformBool(this.use_vor));
|
||||||
|
|
||||||
this.shader.uniform(GL, "u_time", new Uniform1f((time - this.last_time) / ms_per_frame));
|
this.shader.uniform(GL, "u_time", new Uniform1f((time - this.last_time) / ms_per_frame));
|
||||||
this.shader.uniform(GL, "u_mouse", new Uniform2f(this.resizer.get_mouse_pos()));
|
this.shader.uniform(GL, "u_mouse", new Uniform2f(this.resizer.get_mouse_pos()));
|
||||||
this.shader.uniform(GL, "u_viewbox", new Uniform4f(this.resizer.get_viewbox()));
|
this.shader.uniform(GL, "u_viewbox", new Uniform4f(this.resizer.get_viewbox()));
|
||||||
this.shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION));
|
this.shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION));
|
||||||
|
this.shader.uniform(GL, "u_vor", new UniformBool(true));
|
||||||
|
|
||||||
this.renderer.render(GL);
|
this.renderer.render(GL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,14 @@ uniform vec3 u_planet_colours[$PLANETS * 2];
|
||||||
|
|
||||||
uniform float u_step_interval;
|
uniform float u_step_interval;
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
|
uniform bool u_vor;
|
||||||
|
|
||||||
varying vec2 v_pos;
|
varying vec2 v_pos;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 color = vec3(0.2);
|
vec3 color = vec3(0.2);
|
||||||
|
|
||||||
|
if (u_vor) {
|
||||||
float dis = 1000000.0;
|
float dis = 1000000.0;
|
||||||
|
|
||||||
for(int i = 0; i < $PLANETS; i++) {
|
for(int i = 0; i < $PLANETS; i++) {
|
||||||
|
@ -21,6 +24,7 @@ void main() {
|
||||||
color = u_planet_colours[2 * i];
|
color = u_planet_colours[2 * i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gl_FragColor = vec4(color, 0.2);
|
gl_FragColor = vec4(color, 0.2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,3 +312,14 @@ export class UniformMatrix3fv implements Uniform {
|
||||||
gl.uniformMatrix3fv(location, false, this.data);
|
gl.uniformMatrix3fv(location, false, this.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class UniformBool implements Uniform {
|
||||||
|
data: boolean;
|
||||||
|
constructor(data: boolean) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
setUniform(gl: WebGLRenderingContext, location: WebGLUniformLocation) {
|
||||||
|
gl.uniform1i(location, this.data ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -35,19 +35,30 @@ export function resizeCanvasToDisplaySize(
|
||||||
export class FPSCounter {
|
export class FPSCounter {
|
||||||
last: number;
|
last: number;
|
||||||
count: number;
|
count: number;
|
||||||
|
_delta: number;
|
||||||
|
_prev: number
|
||||||
constructor() {
|
constructor() {
|
||||||
this.last = 0;
|
this.last = 0;
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
|
this._delta = 0;
|
||||||
|
this._prev = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame(now: number) {
|
frame(now: number) {
|
||||||
this.count += 1;
|
this.count += 1;
|
||||||
|
this._delta = now - this._prev;
|
||||||
|
this._prev = now;
|
||||||
|
|
||||||
if (now - this.last > 1000) {
|
if (now - this.last > 1000) {
|
||||||
this.last = now;
|
this.last = now;
|
||||||
console.log(this.count + " fps");
|
console.log(this.count + " fps");
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delta(now: number): number {
|
||||||
|
return this._delta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Resizer {
|
export class Resizer {
|
||||||
|
|
Loading…
Reference in a new issue