An Overview of Torque Multiplayer

This article expands upon topics discussed in Important Concepts. We recommend you read that article first.


Torque’s networking model is famous and has been optimized for highly performant multiplayer games. Right out of the box, any Torque game can be a multiplayer game! Almost all of the details for setting up a multiplayer game are handled for you already. With stock Torque 3D, you can easily make a game that can act as a host for other players, connect to a hosted game, or run in ‘Dedicated Server’ mode.

Joining a game

When a player first joins a multiplayer game, there is a complex loading and staged synchronization process that occurs between his client and the game server. The client is told what the current map is, and how many players are on it. The server sends down all the datablocks to the client, which then loads the map definition and, if necessary, performs any lighting tasks that need to take place. Once all this is done, the client notifies the server that it is ready to join the game. The server then spawns the player, and tells the client that it now has control of an object (player, car, starship, etc.) in the game.

Server Authoritative model

From here on in, the client is doing a combination of telling the server what it would like to do, and making educated guesses about what is going on in the game. Ultimately, the server is the final authority on what is allowed and what in fact is occurring in the game. If a client ‘guesses’ wrong, it will make corrections when it receives updated information about the game state from the server. This is called a ‘server authoritative’ networking model.

Example:
When a player presses a key to move forward, his client will tell the server that he would like to move forward. The client assumes that the server won’t have any issues with that, so it immediately begins to display that forward movement on screen. In the meantime, the server receives the move request, determines where the player moved to, and tells all the connected clients (i.e. all the players in the game) where the player now is. All clients get this information and update the scene accordingly. The original client who requested the move will make any corrections between its original guess and what the server is telling the client it actually did.

Doing the math...
All this happens an average of 33 times per second or faster, across multiple network connections, and is repeated millions of times during a game session. Torque uses numerous methods to account for errors, internet lag times, and to make good client side predictions. It is an extremely complex system of algorithms and works quite well. All the source code for this is included with your purchase of Torque 3D, but any modifications should be done with extreme care.

Map Changing

Map changing happens when the conditions of a map/level are met and a game is over. This could happen in response to a game time limit being met, a score limit being met, or any other event defined by the developer. When this event takes place, the server notifies all the clients that the map is switching. It then loads up a new map, and tells the clients to reconnect. At this point, all the map loading stages occur on the clients as if they were connecting from scratch.

Server Connections

An important consideration in Torque multiplayer is that every running instance of a Torque map/mission/level needs its own server instance. The server instance can be a dedicated server instance, or it can be a player who is hosting a map while playing at the same time. A server instance cannot run multiple maps, or different sets of players playing the same map. However, it is possible to run multiple server instances on the same physical machine, if they are running on different ports. Stock Torque 3D does not ship with a way to automatically start new server instances; this is an advanced function which requires interaction with the operating system. An advanced programmer (with at least some networking expertise) should be able to modify Torque 3D’s source to accomplish this if desired.