-
Notifications
You must be signed in to change notification settings - Fork 8
Tick Mode
Tick mode is a system to enable synchronization of commands across all Clients in a ClientManager. When tick mode is enabled, all commands sent to the Client
objects in tick mode will be queued and sent on the next tick. The ClientManager
will tick on a regular (configurable) basis. By default, ticks happen 60 times per second. This can be increased or decreased to change the fidelity of your Client
's data consumption.
Tick mode is best used for controlling the flow of data for games that require users to be totally in sync. It will rate-limit the amount of data being sent over the wire, as well as help prevent saturation of commands by grouping together all commands sent to the Client
object, where the consuming client program can then filter to pick the latest, most important command if need be (for example, updating a players position - only the latest position matters).
var ClientManager = require('patchwire').ClientManager;
var Server = require('patchwire').Server;
const ONE_SECOND = 1000
const THIRTY_TIMES_PER_SECOND = ONE_SECOND / 30;
var tickCount = 0;
// Set up the game manager
var gameManager = new ClientManager();
gameManager.setTickMode(true);
gameManager.setTickRate(THIRTY_TIMES_PER_SECOND);
gameManager.startTicking();
var server = new Server(3001, function(client) {
gameManager.addClient(client);
});
gameManager.on('tick', function() {
tickCount++;
console.info('Ticked: ' + tickCount);
});