how frag-x works
- a server is started
- it initializes a simulation which can be accessed globally
- it starts a thread called
listener
which waits for new players to join
- this thread spawns new threads called
client_listener
for each connected player which has access to the simulations input_messages
(a thread safe queue)
- it starts a thread called
server_messager
which has access to the simulations output_messages
, which is also a thread safe queue
- a client is launched
- it makes a connection to the server
- the
listener
thread adds a player to the server simulation and starts a client_listener
thread
- the client starts receiving snapshots of the game simulation and is able to draw the player on the screen
- you are interacting with the game using input devices and the game state is changing
- the client samples these input devices and sends it over as a
PlayerStateMessage
- the server's client listener thread gets a
PlayerStateMessage
and adds it the Simulation
's input_messages
- the simulation is ticking at a rate defined by
SERVER_TICK_RATE_HZ
, the way we perform a tick in general is by calling a method that we define called step
- for example, at the top level of the server there is something that calls the global simulations
step
method
- this method in turn will call step functions of the objects that are involved in the simulation, these objects are all children of
SimulationObject
- after the
step
function is done, the server will have consumed the information that you provided from your keyboard and mouse, and determined what the game should now look like, it then adds a GameStateMessage
to output_messages
- a
GameStateMessage
is just enough information to draw the player on the client
- the
server_messager
thread has been waiting for something to appear in output_messages
, and so now it can get
from that queue and sends it across the network back to the player
- the client stores this message as a
simulation_state
, and it is drawn to the screen at a rate of FPS
until a new simulation_state
appears