fill out more planned message types

This commit is contained in:
Tangent Wantwight 2020-04-04 22:17:50 -04:00
parent 04f947e7a4
commit 39018635cd

View file

@ -7,10 +7,29 @@ import pipe from "callbag-pipe";
import { INPUT_FREQUENCY, LockstepProcessor, LockstepState } from "../Ecs/Lockstep"; import { INPUT_FREQUENCY, LockstepProcessor, LockstepState } from "../Ecs/Lockstep";
export const enum MessageTypes { export const enum MessageTypes {
/**
* Reserved, likely for transient messages that wouldn't make sense appearing in a replay
*/
META = 0, META = 0,
/**
* From server: initialize client state / load new level, plus informing client of their "controller number"
* From client: (op only) force a new game state, likely loading a level
*/
SET_STATE = 1, SET_STATE = 1,
/**
* From server: array of canonical inputs for a frame
* From client: input for their controller for the next frame (TBD: strategy for handling late inputs)
*/
INPUT = 2, INPUT = 2,
/**
* From server: issue request for the current game state, with a cookie to identify the response
* From client: serialized game state, with the cookie of the request
*/
GET_STATE = 3, GET_STATE = 3,
/**
* For liveness checks / latency estimate. Echos a cookie.
* May be refactored into one of the above messages.
*/
PING = 4 PING = 4
} }
@ -18,11 +37,17 @@ 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.SET_STATE, { s: Partial<State> }>
| Packet<MessageTypes.INPUT, { i: Input }>; | Packet<MessageTypes.INPUT, { i: Input }>
| Packet<MessageTypes.GET_STATE, { c: number, s: State }>
| Packet<MessageTypes.PING, { z: number }>
;
export type ServerMessage<Input, State> = export type ServerMessage<Input, State> =
| Packet<MessageTypes.SET_STATE, { s: Partial<State> }> | Packet<MessageTypes.SET_STATE, { s: Partial<State> }>
| Packet<MessageTypes.INPUT, { i: Input }>; | Packet<MessageTypes.INPUT, { i: Input }>
| Packet<MessageTypes.GET_STATE, { c: number }>
| Packet<MessageTypes.PING, { z: number }>
;
export type Server<Input, State> = Callbag<ClientMessage<Input, State>, ServerMessage<Input, State>>; export type Server<Input, State> = Callbag<ClientMessage<Input, State>, ServerMessage<Input, State>>;