Skip to content

Commit

Permalink
Netcode comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rameshvarun committed Apr 6, 2023
1 parent c8ec5b2 commit ffea049
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion netplayjs-client/src/netcode/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { JsonObject, JsonValue } from "type-fest";
import * as autoserialize from "../serialization/autoserialize";

/**
* NetplayState is the interface between the netcode
* and the actual game mechanics. It describes to the
* netcode how to simulate the game forward and how to
* save / restore the game for rewinds.
*/
export abstract class NetplayState<TInput extends NetplayInput<TInput>> {
/**
* This function describes how a state ticks forward given
* the player inputs. It's used by netcodes to simulate the
* game forward, sometimes with predicted inputs
* and sometimes with actual inputs.
*/
abstract tick(playerInputs: Map<NetplayPlayer, TInput>): void;

/**
Expand All @@ -19,9 +31,16 @@ export abstract class NetplayState<TInput extends NetplayInput<TInput>> {
}
}

/**
* NetplayJS games are synchronized by sending inputs across the network.
* The NetplayInput class describes, abstractly, what each netcode implementation
*/
export abstract class NetplayInput<TInput extends NetplayInput<TInput>> {
/**
* By default, the prediction is to just use the same value.
* For predictive netcodes like rollback, we need to be able
* to speculatively predict the next input from the current
* input. By default, though, the prediction is just the same value as
* the previous frame.
*/
predictNext(): TInput {
// @ts-ignore
Expand All @@ -43,6 +62,9 @@ export abstract class NetplayInput<TInput extends NetplayInput<TInput>> {
}
}

/**
* A NetplayPlayer object represents one player in a game.
*/
export class NetplayPlayer {
id: number;
isLocal: boolean;
Expand Down

0 comments on commit ffea049

Please sign in to comment.