Share one server instance between two client instances!
This commit is contained in:
parent
c8589828c7
commit
a8b5dea37a
5 changed files with 15 additions and 9 deletions
2
plan.txt
2
plan.txt
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -12,7 +12,7 @@ body {
|
|||
line-height: $line-height;
|
||||
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
flex-flow: row wrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue