Change message type enum to serde-friendly strings; remove unused Ping message
This commit is contained in:
parent
a22ca95d3d
commit
ca5bf65e9d
1 changed files with 4 additions and 11 deletions
|
@ -10,27 +10,22 @@ export const enum MessageTypes {
|
|||
/**
|
||||
* Reserved, likely for transient messages that wouldn't make sense appearing in a replay
|
||||
*/
|
||||
META = 0,
|
||||
META = "m",
|
||||
/**
|
||||
* 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 = "s",
|
||||
/**
|
||||
* 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 = "i",
|
||||
/**
|
||||
* 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,
|
||||
/**
|
||||
* For liveness checks / latency estimate. Echos a cookie.
|
||||
* May be refactored into one of the above messages.
|
||||
*/
|
||||
PING = 4
|
||||
GET_STATE = "g",
|
||||
}
|
||||
|
||||
export type Packet<TypeId, Payload> = { t: TypeId } & Payload;
|
||||
|
@ -39,14 +34,12 @@ export type ClientMessage<LocalInput, State> =
|
|||
| Packet<MessageTypes.SET_STATE, { s: Partial<State> }>
|
||||
| Packet<MessageTypes.INPUT, { i: LocalInput }>
|
||||
| Packet<MessageTypes.GET_STATE, { c: number, s: State }>
|
||||
| Packet<MessageTypes.PING, { z: number }>
|
||||
;
|
||||
|
||||
export type ServerMessage<GlobalInput, State> =
|
||||
| Packet<MessageTypes.SET_STATE, { u: number, s: Partial<State> }>
|
||||
| Packet<MessageTypes.INPUT, { i: GlobalInput }>
|
||||
| Packet<MessageTypes.GET_STATE, { c: number }>
|
||||
| Packet<MessageTypes.PING, { z: number }>
|
||||
;
|
||||
|
||||
export type Server<LocalInput, GlobalInput, State> = Callbag<ClientMessage<LocalInput, State>, ServerMessage<GlobalInput, State>>;
|
||||
|
|
Loading…
Reference in a new issue