Update list of message types from thinking

This commit is contained in:
Tangent Wantwight 2020-02-20 23:55:16 -05:00
parent 01349724a9
commit 4667c4b567
2 changed files with 9 additions and 5 deletions

View file

@ -6,17 +6,21 @@ import map from "callbag-map";
import { INPUT_FREQUENCY, LockstepProcessor, LockstepState } from "../Ecs/Lockstep";
export const enum MessageTypes {
RESET = 0,
INPUT = 1,
META = 0,
SET_STATE = 1,
INPUT = 2,
GET_STATE = 3,
PING = 4
}
export type Packet<TypeId, Payload> = { t: TypeId } & Payload;
export type ClientMessage<Input, State> =
| Packet<MessageTypes.SET_STATE, { s: Partial<State> }>
| Packet<MessageTypes.INPUT, { i: Input }>;
export type ServerMessage<Input, State> =
| Packet<MessageTypes.RESET, { s: Partial<State> }>
| Packet<MessageTypes.SET_STATE, { s: Partial<State> }>
| Packet<MessageTypes.INPUT, { i: Input }>;
export type Server<Input, State> = Callbag<ClientMessage<Input, State>, ServerMessage<Input, State>>;
@ -62,7 +66,7 @@ export abstract class LockstepClient<Input, State> {
// server message
const message = data as ServerMessage<Input, State>;
switch (message.t) {
case MessageTypes.RESET:
case MessageTypes.SET_STATE:
const resetState = this.initState(message.s);
this.state = new LockstepState(resetState, this.engine);
break;

View file

@ -20,5 +20,5 @@ export function Loopback<Input, State>(start: number, data?: Client<Input, State
}
}
});
sink(1, {t: MessageTypes.RESET, s: {}});
sink(1, {t: MessageTypes.SET_STATE, s: {}});
};