Share one server instance between two client instances!

This commit is contained in:
Tangent Wantwight 2020-05-02 21:20:54 -04:00
parent c8589828c7
commit a8b5dea37a
5 changed files with 15 additions and 9 deletions

View file

@ -1,10 +1,10 @@
Open:
- Multiplayer loopback server
- Insecured websocket server implementation
- Cloneable RNG that goes in state (use MurmurHash3 finalizer in counter mode?)
- remove all random() calls
Done:
- Multiplayer loopback server
- Refactor input generics to distinct local/full types
- Refactor input messages for more than one player
- Rework State implementation for easier cloning/deserialization

View file

@ -3,7 +3,7 @@ import subscribe from "callbag-subscribe";
import { KeyControl, KeyName } from "../Applet/Keyboard";
import { DrawSet } from "../Applet/Render";
import { Location, Polygon, PolygonComponent, RenderBounds } from "../Ecs/Components";
import { Location, PolygonComponent, RenderBounds } from "../Ecs/Components";
import { Create } from "../Ecs/Data";
import { RunRenderBounds } from "../Ecs/Renderers";
import { LockstepClient } from "../Net/LockstepClient";
@ -15,13 +15,11 @@ export class Main extends LockstepClient<KeyName[], KeyName[][], Data> {
buttons = new Buttons();
constructor(canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl) {
constructor(canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl, server: LoopbackServer<KeyName[], Data>) {
super(new Engine());
keys.setHandler(this.buttons);
const server = new LoopbackServer<KeyName[], Data>();
this.connect(server.socket);
server.resetState({});
pipe(
this.renderFrames,

View file

@ -4,7 +4,8 @@
<title></title>
<link rel="stylesheet" href="./index.scss" />
</head><body>
<canvas id="GameCanvas" width="500" height="400"></canvas>
<canvas id="RenderTest" width="500" height="400"></canvas>
<canvas class="GameCanvas" width="500" height="400"></canvas>
<canvas class="GameCanvas" width="500" height="400"></canvas>
<!--<canvas id="RenderTest" width="500" height="400"></canvas>-->
<script src="./index.ts"></script>
</body></html>

View file

@ -12,7 +12,7 @@ body {
line-height: $line-height;
display: flex;
flex-flow: column;
flex-flow: row wrap;
align-items: center;
justify-content: center;
}

View file

@ -1,6 +1,9 @@
import { Select } from "./Applet/Init";
import { KeyName } from "./Applet/Keyboard";
import { Data } from "./Ecs/Components";
import { BindTests } from "./Ecs/test";
import { Main } from "./Game/Main";
import { LoopbackServer } from "./Net/LoopbackServer";
/* // Hot Module Reloading stub, if that's viable
* declare const module: any;
@ -13,6 +16,10 @@ import { Main } from "./Game/Main";
* }
*/
Select("#GameCanvas").forEachCanvas((c, cx, keys) => new Main(c, cx, keys));
const server = new LoopbackServer<KeyName[], Data>();
Select(".GameCanvas").forEachCanvas((c, cx, keys) => new Main(c, cx, keys, server));
server.resetState({});
BindTests();