Update list of message types from thinking
This commit is contained in:
parent
01349724a9
commit
4667c4b567
2 changed files with 9 additions and 5 deletions
|
@ -6,17 +6,21 @@ import map from "callbag-map";
|
||||||
import { INPUT_FREQUENCY, LockstepProcessor, LockstepState } from "../Ecs/Lockstep";
|
import { INPUT_FREQUENCY, LockstepProcessor, LockstepState } from "../Ecs/Lockstep";
|
||||||
|
|
||||||
export const enum MessageTypes {
|
export const enum MessageTypes {
|
||||||
RESET = 0,
|
META = 0,
|
||||||
INPUT = 1,
|
SET_STATE = 1,
|
||||||
|
INPUT = 2,
|
||||||
|
GET_STATE = 3,
|
||||||
|
PING = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Packet<TypeId, Payload> = { t: TypeId } & Payload;
|
export type Packet<TypeId, Payload> = { t: TypeId } & Payload;
|
||||||
|
|
||||||
export type ClientMessage<Input, State> =
|
export type ClientMessage<Input, State> =
|
||||||
|
| Packet<MessageTypes.SET_STATE, { s: Partial<State> }>
|
||||||
| Packet<MessageTypes.INPUT, { i: Input }>;
|
| Packet<MessageTypes.INPUT, { i: Input }>;
|
||||||
|
|
||||||
export type ServerMessage<Input, State> =
|
export type ServerMessage<Input, State> =
|
||||||
| Packet<MessageTypes.RESET, { s: Partial<State> }>
|
| Packet<MessageTypes.SET_STATE, { s: Partial<State> }>
|
||||||
| Packet<MessageTypes.INPUT, { i: Input }>;
|
| Packet<MessageTypes.INPUT, { i: Input }>;
|
||||||
|
|
||||||
export type Server<Input, State> = Callbag<ClientMessage<Input, State>, ServerMessage<Input, State>>;
|
export type Server<Input, State> = Callbag<ClientMessage<Input, State>, ServerMessage<Input, State>>;
|
||||||
|
@ -62,7 +66,7 @@ export abstract class LockstepClient<Input, State> {
|
||||||
// server message
|
// server message
|
||||||
const message = data as ServerMessage<Input, State>;
|
const message = data as ServerMessage<Input, State>;
|
||||||
switch (message.t) {
|
switch (message.t) {
|
||||||
case MessageTypes.RESET:
|
case MessageTypes.SET_STATE:
|
||||||
const resetState = this.initState(message.s);
|
const resetState = this.initState(message.s);
|
||||||
this.state = new LockstepState(resetState, this.engine);
|
this.state = new LockstepState(resetState, this.engine);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -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: {}});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue