mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-06-27 16:10:34 +08:00
Progress: Documentation
This commit is contained in:
@@ -4,7 +4,7 @@ A simple, lightweight, HTML multiplayer game server (and client) for Node.js
|
||||
## Features
|
||||
- Authoritative Game Server
|
||||
- Client Side / Input Prediciton
|
||||
- Client Side Smooting
|
||||
- Client Side Smoothing
|
||||
- Entity Interpolation
|
||||
- Server State History
|
||||
- Server and Client Messaging
|
||||
@@ -31,7 +31,7 @@ var server = garageServer.createGarageServer(sockets,
|
||||
```js
|
||||
server.start();
|
||||
```
|
||||
**3.** Inside physics loop, process inputs for players, process entites and update states. Note that state is an object literal effectively offering up any grab bag of properties that pertain to your game's state.
|
||||
**3.** Inside physics loop, process inputs for players, process entites and update states. Note that state is an object literal effectively offering up any grab bag of properties that are specific to your game's state.
|
||||
```js
|
||||
var players = server.getPlayers(),
|
||||
entities = server.getEntities();
|
||||
@@ -87,11 +87,11 @@ GarageServerIO.initializeGarageServer('http://insertmygameurlhere.com', {
|
||||
}
|
||||
};
|
||||
```
|
||||
**2.** Inside physics loop, capture and send input via GarageServer.IO.
|
||||
**2.** Inside physics loop, capture and send input via GarageServer.IO. Similar to state, input offers up any grab bag of properties specific to your game's input.
|
||||
```js
|
||||
GarageServerIO.addInput(myInput);
|
||||
```
|
||||
**3.** Inside render loop, extract player and entity states.
|
||||
**3.** Inside render loop, extract player and entity states - this will retrieve the current states based on your interpolation, prediction and smoothing settings. Players are effectively clients whereas entities are determined by players inputs and controlled by the server.
|
||||
```js
|
||||
var playerStates = GarageServerIO.getPlayerStates(),
|
||||
entityStates = GarageServerIO.getEntityStates();
|
||||
@@ -122,7 +122,7 @@ Configure the different options, events, callbacks that you would like to consum
|
||||
```js
|
||||
options.onPlayerConnect(callback)
|
||||
```
|
||||
Once the client has made a connection to the server, this event will fire.
|
||||
Invoked once the player has made a connection to the server.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
@@ -130,7 +130,7 @@ Function to be invoked upon event firing.
|
||||
```js
|
||||
options.onPlayerDisconnect(callback)
|
||||
```
|
||||
If client disconnects from the server, this event will fire.
|
||||
Invoked if a player disconnects from the server.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
@@ -138,7 +138,7 @@ Function to be invoked upon event firing.
|
||||
```js
|
||||
options.onPlayerReconnect(callback)
|
||||
```
|
||||
If client disconnects and reconnects to the server, this event will fire.
|
||||
Invoked if a player disconnects and then reconnects to the server.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
@@ -146,28 +146,28 @@ Function to be invoked upon event firing.
|
||||
```js
|
||||
options.onPlayerUpdate(callback(state))
|
||||
```
|
||||
Event fired each time `state` has been received to the client for a player.
|
||||
Invoked each time `state` has been received to the player for a player.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
`state` **object literal**
|
||||
Object containing all of the properties pertaining to a player for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
Object containing all of the properties specific to a player for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
|
||||
---
|
||||
```js
|
||||
options.onEntityUpdate(callback(state))
|
||||
```
|
||||
Event fired each time `state` has been received to the client for an entity.
|
||||
Invoked each time `state` has been received to the client for an entity.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
`state` **object literal**
|
||||
Object containing all of the properties pertaining to an entity for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
Object containing all of the properties specific to an entity for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
|
||||
---
|
||||
```js
|
||||
options.onPlayerRemove(callback(id))
|
||||
```
|
||||
Event fired when a player has been removed from GarageServer.IO.
|
||||
Invoked when a player has been removed from GarageServer.IO.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
@@ -178,7 +178,7 @@ Id of the player who has been removed from GarageServer.IO.
|
||||
```js
|
||||
options.onEntityRemove(callback(id))
|
||||
```
|
||||
Event fired when an entity has been removed from GarageServer.IO.
|
||||
Invoked when an entity has been removed from GarageServer.IO.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
@@ -189,29 +189,29 @@ Id of the entity who has been removed from GarageServer.IO.
|
||||
```js
|
||||
options.onEvent(callback(data))
|
||||
```
|
||||
Event fired for custom event calling.
|
||||
Invoked when a custom event is received. Custom events are merely funneled thru GarageServer.IO - acts simply as a transport to and from the server and client(s).
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
`data` **object literal**
|
||||
Object containing all of the properties pertaining to a custom event for your game - a, b, c, etc., whatever you want to add to it.
|
||||
Object containing all of the properties specific to a custom event for your game - a, b, c, etc., whatever you want to add to it.
|
||||
|
||||
---
|
||||
```js
|
||||
options.onWorldState(callback(state))
|
||||
```
|
||||
Event fired once world state has been received to the client from the server.
|
||||
Invoked once world state has been received to the client from the server.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
`state` **object literal**
|
||||
Object containing all of the properties pertaining to world state for your game - f, u, n, etc., whatever you want to add to it.
|
||||
Object containing all of the properties specific to world state for your game - height, width, start, etc., whatever you want to add to it.
|
||||
|
||||
---
|
||||
```js
|
||||
options.onPing(callback(pingDelay))
|
||||
```
|
||||
Event fired upon receiving ping delay on the client - determined by the 'pingInterval' option from the server.
|
||||
Invoked upon receiving a ping delay on the client - determined by the 'pingInterval' option from the server.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
@@ -220,11 +220,12 @@ The current ping in milliseconds.
|
||||
|
||||
---
|
||||
```js
|
||||
options.onUpdatePlayerPrediction(callback(state, inputs, deltaTime) : newState)
|
||||
options.onUpdatePlayerPrediction(callback(currentState, inputs, deltaTime) : newState)
|
||||
```
|
||||
If using client side prediction, this callback should return the new state based on the current state, inputs to be processed, and the delta time.
|
||||
**_Returns:_ object literal**
|
||||
|
||||
If using client side prediction, this callback should return the new state based on the current state, inputs to be processed, and the delta time.
|
||||
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
@@ -241,26 +242,27 @@ The amount, in milliseconds, between physics processing.
|
||||
```js
|
||||
options.onInterpolation(callback(previousState, targetState, amount) : newState)
|
||||
```
|
||||
If using interpolation, this callback should return the new state, based on the previous state, target state, and percent between.
|
||||
**_Returns:_ object literal**
|
||||
|
||||
If using interpolation, this callback should return the new state, based on the previous state, target state, and percent between frames.
|
||||
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
`previousState` **object literal**
|
||||
Object containing all of the properties pertaining to a player for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
Object containing all of the properties specific to a player for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
|
||||
`targetState` **object literal**
|
||||
Object containing all of the properties pertaining to a player for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
Object containing all of the properties specific to a player for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
|
||||
`amount` **number**
|
||||
The "rough" percentage between frames to be used in conjuction with interpolation - client side smoothing is considered during the calculation of this number.
|
||||
The "rough" percentage between frames to be used in conjuction with interpolation - the server `options.smoothing` is considered during the calculation of this number.
|
||||
|
||||
---
|
||||
```js
|
||||
options.onReady(callback)
|
||||
```
|
||||
Event fired once client has succesfully connected to the server and received the world state.
|
||||
Invoked once a client has succesfully connected to the server and received the world state.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
|
||||
@@ -276,7 +278,7 @@ Enables console logging of all the events occuring within the GarageServer.IO cl
|
||||
```js
|
||||
GarageServerIO.addInput(input)
|
||||
```
|
||||
Notify the server of client inputs. These will be used to determine state from the physics processing.
|
||||
Notify the server of client inputs. Inputs are transferred to the server and subsequently used to determine the new player state from the physics processing. The idea here is that this call is made during each pass of the physics loop on the client.
|
||||
`input` **object literal**
|
||||
This can be anything as it pertains to your game - 1, 'left', 'right', etc., whatever you want to make it.
|
||||
#### getPlayerStates
|
||||
@@ -284,31 +286,33 @@ This can be anything as it pertains to your game - 1, 'left', 'right', etc., wha
|
||||
```js
|
||||
GarageServerIO.getPlayerStates() : [, {id, state}]
|
||||
```
|
||||
Returns a list of current player states from the most recent broadcast depending on interpolation settings.
|
||||
**_Returns:_ array**
|
||||
|
||||
Returns a list of current player states from the most recent broadcast depending on interpolation settings.
|
||||
|
||||
`id` **string**
|
||||
The id of the player.
|
||||
`state` **object literal**
|
||||
Object containing all properties pertaining to an entity state in your game.
|
||||
Object containing all properties specific to player state in your game.
|
||||
#### getEntityStates
|
||||
---
|
||||
```js
|
||||
GarageServerIO.getEntityStates() : [, {id, state}]
|
||||
```
|
||||
Returns a list of current entity states from the most recent broadcast depending on interpolation settings.
|
||||
**_Returns:_ array**
|
||||
|
||||
Returns a list of current entity states from the most recent broadcast depending on interpolation settings.
|
||||
|
||||
`id` **string**
|
||||
The id of the entity.
|
||||
`state` **object literal**
|
||||
Object containing all properties pertaining to an entity state in your game.
|
||||
Object containing all properties specific to entity state in your game.
|
||||
#### getId
|
||||
---
|
||||
```js
|
||||
GarageServerIO.getId() : playerid
|
||||
```
|
||||
Gets the id of the client's player.
|
||||
Gets the id of the client. Recall, clients are effectively players.
|
||||
**_Returns:_ string**
|
||||
|
||||
`playerid` **string**
|
||||
@@ -318,9 +322,9 @@ Id of the client's player.
|
||||
```js
|
||||
GarageServerIO.sendServerEvent(data)
|
||||
```
|
||||
Send a custom event to the server.
|
||||
Send a custom event to the server. Use this to make custom calls to GarageServer.IO for your game.
|
||||
`data` **object literal**
|
||||
Object containing all properties pertaining to the custom event.
|
||||
Object containing all properties specific to the custom event.
|
||||
### Server
|
||||
|
||||
#### createGarageServer
|
||||
@@ -346,68 +350,68 @@ The amount, in milliseconds, that state is broadcasted to clients.
|
||||
options.logging
|
||||
```
|
||||
**boolean**
|
||||
Enable console logging of all the events occuring within the GarageServer.IO server.
|
||||
Enables console logging of all the events occuring within the GarageServer.IO server. Defaults to `false`.
|
||||
|
||||
---
|
||||
```js
|
||||
options.clientSidePrediction
|
||||
```
|
||||
**boolean**
|
||||
Enables client side prediction and callback on the client.
|
||||
Enables client side prediction and callback on the client. Defaults to `false`.
|
||||
|
||||
---
|
||||
```js
|
||||
options.interpolation
|
||||
```
|
||||
**boolean**
|
||||
Enables interpolation and callback on the client.
|
||||
Enables interpolation and callback on the client. Defaults to `false`.
|
||||
|
||||
---
|
||||
```js
|
||||
options.interpolationDelay
|
||||
```
|
||||
**number**
|
||||
The amount, in milliseconds, that state is rendered to the client behind actual server time.
|
||||
The amount, in milliseconds, that state is rendered to the client behind actual server time. Defaults to `100`.
|
||||
|
||||
---
|
||||
```js
|
||||
options.smoothingFactor
|
||||
```
|
||||
**number**
|
||||
|
||||
Defaults to `0.3`.
|
||||
---
|
||||
```js
|
||||
options.pingInterval
|
||||
```
|
||||
**number**
|
||||
The amount, in milliseconds, that a ping is made to the server to test for latency.
|
||||
The amount, in milliseconds, that a ping is made to the server to test for latency. Defaults to `2000`.
|
||||
|
||||
---
|
||||
```js
|
||||
options.maxUpdateBuffer
|
||||
```
|
||||
**number**
|
||||
The maximum amount of broadcasted state updates to store on the client for each player and entity.
|
||||
The maximum amount of broadcasted state updates to store on the client for each player and entity. Defaults to `120`.
|
||||
|
||||
---
|
||||
```js
|
||||
options.maxHistorySecondBuffer
|
||||
```
|
||||
**number**
|
||||
The amount, in milliseconds, that a ping is made to the server to test for latency.
|
||||
The amount, in milliseconds, that history is stored for a player and/or entity. Defaults to `1000`.
|
||||
|
||||
---
|
||||
```js
|
||||
options.worldState
|
||||
```
|
||||
**object literal**
|
||||
Object containing all of the properties pertaining to world state for your game - f, u, n, etc., whatever you want to add to it.
|
||||
Object containing all of the properties specific to world state for your game - f, u, n, etc., whatever you want to add to it.
|
||||
|
||||
---
|
||||
```js
|
||||
options.onPlayerConnect(callback(socket))
|
||||
```
|
||||
Event fired when a player connects to the server.
|
||||
Invoked when a player (client) connects to the server.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
`socket` **Socket**
|
||||
@@ -416,6 +420,7 @@ Function to be invoked upon event firing.
|
||||
```js
|
||||
options.onPlayerInput(callback(socket, input))
|
||||
```
|
||||
Invoked when a player (client) submits input to the server.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
`socket` **Socket**
|
||||
@@ -426,6 +431,7 @@ Function to be invoked upon event firing.
|
||||
```js
|
||||
options.onPlayerDisconnect(callback(socket))
|
||||
```
|
||||
Invoked when a player (client) disconnects from the server.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
`socket` **Socket**
|
||||
@@ -434,6 +440,7 @@ Function to be invoked upon event firing.
|
||||
```js
|
||||
options.onPing(callback(socket, data))
|
||||
```
|
||||
Invoked when a client pings the server.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
`socket` **Socket**
|
||||
@@ -445,10 +452,11 @@ The client start time when the ping was initiated.
|
||||
```js
|
||||
options.onEvent(callback(data))
|
||||
```
|
||||
Invoked when a client emits a custom event.
|
||||
`callback` **function**
|
||||
Function to be invoked upon event firing.
|
||||
`data` **object literal**
|
||||
Object containing all properties pertaining to the custom event.
|
||||
Object containing all properties specific to the custom event.
|
||||
#### start
|
||||
---
|
||||
```js
|
||||
@@ -468,6 +476,8 @@ GarageServerIO.getPlayers() : [, {id, state, [, inputs], [, {states, executionTi
|
||||
```
|
||||
**_Returns:_ array**
|
||||
|
||||
Returns a list of all players, their current states, inputs to be processed, and a list of their prior states and times limited by the server `options.maxHistorySecondBuffer`.
|
||||
|
||||
`id` **string**
|
||||
Id of the player.
|
||||
`state` **object literal**
|
||||
@@ -475,7 +485,7 @@ Current state of the player.
|
||||
`inputs` **array of object literals**
|
||||
List of all the inputs received for this player that need to be processed.
|
||||
`stateHistory` **array of object literals**
|
||||
List of all previous states up to `options.maxHistorySecondBuffer`.
|
||||
List of all previous states and their execution times up to `options.maxHistorySecondBuffer`.
|
||||
#### getEntities
|
||||
---
|
||||
```js
|
||||
@@ -483,35 +493,46 @@ GarageServerIO.getEntities() : [,{id, state, [, {state, executionTime }]}]
|
||||
```
|
||||
**_Returns:_ array**
|
||||
|
||||
Returns a list of all entities, their current states, and a list of their prior states and times limited by the server `options.maxHistorySecondBuffer`.
|
||||
|
||||
`id` **string**
|
||||
Id of the entity.
|
||||
`state` **object literal**
|
||||
Current state of the entity.
|
||||
`stateHistory` **array of object literals**
|
||||
List of all previous states up to `options.maxHistorySecondBuffer`.
|
||||
List of all previous states and their execution times up to `options.maxHistorySecondBuffer`.
|
||||
#### updatePlayerState
|
||||
---
|
||||
```js
|
||||
GarageServerIO.updatePlayerState(id, state)
|
||||
```
|
||||
|
||||
Notify GargeServer.IO of a new state with an id of the player to be updated. The idea here is that this call is made during each pass of the physics loop on the server.
|
||||
|
||||
`id` **string**
|
||||
Id of the player whose state should be updated.
|
||||
`state` **object literal**
|
||||
New state of the entity containing all of the properties pertaining to a player for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
New state of the entity containing all of the properties specific to a player for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
#### updateEntityState
|
||||
---
|
||||
```js
|
||||
GarageServerIO.updateEntityState(id, state)
|
||||
```
|
||||
|
||||
Notify GargeServer.IO of a new state with an id of the entity to be updated. The idea here is that this call is made during each pass of the physics loop on the server.
|
||||
|
||||
`id` **string**
|
||||
Id of the entity whose state should be updated.
|
||||
`state` **object literal**
|
||||
New state of the entity containing all of the properties pertaining to an entity for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
New state of the entity containing all of the properties specific to an entity for your game - x, y, z, time, etc., whatever you want to add to it.
|
||||
#### addEntity
|
||||
---
|
||||
```js
|
||||
GarageServerIO.addEntity(id)
|
||||
```
|
||||
|
||||
Notify GarageServer.IO that a new entity has been added to the game.
|
||||
|
||||
`id` **string**
|
||||
Id of the entity to be added.
|
||||
#### removeEntity
|
||||
@@ -519,6 +540,9 @@ Id of the entity to be added.
|
||||
```js
|
||||
GarageServerIO.removeEntity(id)
|
||||
```
|
||||
|
||||
Notify GarageServer.IO that an entity has been removed from the game.
|
||||
|
||||
`id` **string**
|
||||
Id of the entity to be removed.
|
||||
#### sendPlayerEvent
|
||||
@@ -526,19 +550,19 @@ Id of the entity to be removed.
|
||||
```js
|
||||
GarageServerIO.sendPlayerEvent(id, data)
|
||||
```
|
||||
Allows server to broadcast events to a specific player.
|
||||
Allows server to broadcast events to a specific player. Use this to make custom calls to a GarageServer.IO client for your game.
|
||||
`id` **string**
|
||||
Id of the player to receive event.
|
||||
`data` **object literal**
|
||||
Object containing all properties pertaining to the custom event.
|
||||
Object containing all properties specific to the custom event.
|
||||
#### sendPlayersEvent
|
||||
---
|
||||
```js
|
||||
GarageServerIO.sendPlayersEvent(data)
|
||||
```
|
||||
Allows server to broadcast events to a all players.
|
||||
Allows server to broadcast events to all players. Use this to make custom calls to GarageServer.IO clients for your game.
|
||||
`data` **object literal**
|
||||
Object containing all properties pertaining to the custom event.
|
||||
Object containing all properties specific to the custom event.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Reference in New Issue
Block a user