Module crystalorb::client[][src]

Expand description

This module houses the structures that are specific to the management of a CrystalOrb game client.

The Client structure is what you create, store, and update, analogous to the Server structure. However, there isn’t much functionality you can directly access from a Client object. This is because most functionality depends on what stage the Client is at, with different functionality provided at different stages. To access other important and useful functionality to view and control your client, you can call Client::stage and Client::stage_mut which will return some stage structure containing the extra functionality.

For the majority of the time, you would probably want to use stage::Ready in order to perform the following useful operations:

  • Issuing commands that come from the player.
    use crystalorb::{Config, client::{Client, stage::StageMut}};
    use crystalorb_demo::{DemoWorld, DemoCommand, PlayerSide, PlayerCommand};
    use crystalorb_mock_network::MockNetwork;
    
    // Using a mock network as an example...
    let (_, (mut network, _)) =
        MockNetwork::new_mock_network::<DemoWorld>();
    
    let mut client = Client::<DemoWorld>::new(Config::new());
    
    // ...later on in your update loop, in response to a player input...
    
    if let StageMut::Ready(mut ready_client) = client.stage_mut() {
        let command = DemoCommand::new(PlayerSide::Left, PlayerCommand::Jump, true);
        ready_client.issue_command(command, &mut network);
    }
  • Getting the current display state to render on the screen.
    use crystalorb::{
        Config,
        client::{Client, stage::Stage},
        world::DisplayState,
    };
    use crystalorb_demo::{DemoWorld, DemoDisplayState};
    
    fn render(display_state: &DemoDisplayState) {
        // [Your game rendering code]
        println!("{:?}", display_state);
    }
    
    let client = Client::<DemoWorld>::new(Config::new());
    
    // ...later on in your update loop...
    
    if let Stage::Ready(ready_client) = client.stage() {
        render(ready_client.display_state().display_state());
    }

Modules

stage

The Client undergoes several stages of initialization before it is ready to accept commands and be displayed to the player’s screen. The enums in this module provides access to different functionality depending on what stage the Client is at:

Structs

ActiveClient

The internal CrystalOrb structure used to actively run the simulations, which is not constructed until the ClockSyncer is ready.

Client

This is the top-level structure of CrystalOrb for your game client, analogous to the Server for game servers. You create, store, and update this client instance to run your game on the client side.

Enums

FastforwardingHealth

Fastforwarding the server’s snapshot to the current timestamp can take multiple update cycles. During this time, different external situations can cause the fastfowarding process to abort in an unexpected way. This enum describes these possible situations.

ReconciliationStatus

The client needs to perform different behaviours at different times. For example, the client cannot reconcile with the server before receing a snapshot from the server. The client cannot blend the snapshot into the current world state until the snapshot state has been fastforwarded to the correct timestamp (since server snapshots are always behind the client’s state).