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:
|
Open:
|
||||||
- Multiplayer loopback server
|
|
||||||
- Insecured websocket server implementation
|
- Insecured websocket server implementation
|
||||||
- Cloneable RNG that goes in state (use MurmurHash3 finalizer in counter mode?)
|
- Cloneable RNG that goes in state (use MurmurHash3 finalizer in counter mode?)
|
||||||
- remove all random() calls
|
- remove all random() calls
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
|
- Multiplayer loopback server
|
||||||
- Refactor input generics to distinct local/full types
|
- Refactor input generics to distinct local/full types
|
||||||
- Refactor input messages for more than one player
|
- Refactor input messages for more than one player
|
||||||
- Rework State implementation for easier cloning/deserialization
|
- Rework State implementation for easier cloning/deserialization
|
||||||
|
|
|
@ -3,7 +3,7 @@ import subscribe from "callbag-subscribe";
|
||||||
|
|
||||||
import { KeyControl, KeyName } from "../Applet/Keyboard";
|
import { KeyControl, KeyName } from "../Applet/Keyboard";
|
||||||
import { DrawSet } from "../Applet/Render";
|
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 { Create } from "../Ecs/Data";
|
||||||
import { RunRenderBounds } from "../Ecs/Renderers";
|
import { RunRenderBounds } from "../Ecs/Renderers";
|
||||||
import { LockstepClient } from "../Net/LockstepClient";
|
import { LockstepClient } from "../Net/LockstepClient";
|
||||||
|
@ -15,13 +15,11 @@ export class Main extends LockstepClient<KeyName[], KeyName[][], Data> {
|
||||||
|
|
||||||
buttons = new Buttons();
|
buttons = new Buttons();
|
||||||
|
|
||||||
constructor(canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl) {
|
constructor(canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl, server: LoopbackServer<KeyName[], Data>) {
|
||||||
super(new Engine());
|
super(new Engine());
|
||||||
keys.setHandler(this.buttons);
|
keys.setHandler(this.buttons);
|
||||||
|
|
||||||
const server = new LoopbackServer<KeyName[], Data>();
|
|
||||||
this.connect(server.socket);
|
this.connect(server.socket);
|
||||||
server.resetState({});
|
|
||||||
|
|
||||||
pipe(
|
pipe(
|
||||||
this.renderFrames,
|
this.renderFrames,
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
<title></title>
|
<title></title>
|
||||||
<link rel="stylesheet" href="./index.scss" />
|
<link rel="stylesheet" href="./index.scss" />
|
||||||
</head><body>
|
</head><body>
|
||||||
<canvas id="GameCanvas" width="500" height="400"></canvas>
|
<canvas class="GameCanvas" width="500" height="400"></canvas>
|
||||||
<canvas id="RenderTest" 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>
|
<script src="./index.ts"></script>
|
||||||
</body></html>
|
</body></html>
|
||||||
|
|
|
@ -12,7 +12,7 @@ body {
|
||||||
line-height: $line-height;
|
line-height: $line-height;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column;
|
flex-flow: row wrap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { Select } from "./Applet/Init";
|
import { Select } from "./Applet/Init";
|
||||||
|
import { KeyName } from "./Applet/Keyboard";
|
||||||
|
import { Data } from "./Ecs/Components";
|
||||||
import { BindTests } from "./Ecs/test";
|
import { BindTests } from "./Ecs/test";
|
||||||
import { Main } from "./Game/Main";
|
import { Main } from "./Game/Main";
|
||||||
|
import { LoopbackServer } from "./Net/LoopbackServer";
|
||||||
|
|
||||||
/* // Hot Module Reloading stub, if that's viable
|
/* // Hot Module Reloading stub, if that's viable
|
||||||
* declare const module: any;
|
* 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();
|
BindTests();
|
||||||
|
|
Loading…
Reference in a new issue