Client Replicator
Disconnect
Section titled “Disconnect”type Disconnect = () -> ()Methods
Section titled “Methods”client:init()
Section titled “client:init()”Initializes the client replicator. World can be provided here if it wasn’t provided when creating the replicator.
type Client = { init: (self: Client, world: jecs.World?) -> ()}Arguments
Section titled “Arguments”- world: The world to use for the replicators. Can also be provided when initing the replicator.
client:destroy()
Section titled “client:destroy()”Destroys the client replicator. This will disconnect jecs hooks and connections.
type Client = { destroy: (self: Client) -> ()}client:apply_updates()
Section titled “client:apply_updates()”Applies the updates from the server.
type Client = { apply_updates: (self: Client, buf: buffer, variants: {{any}}) -> ()}Arguments
Section titled “Arguments”- buf: The buffer containing the updates.
- variants: The variants table containing non-serialized values.
client:apply_unreliable()
Section titled “client:apply_unreliable()”Applies the unreliable values from the server.
type Client = { apply_unreliable: (self: Client, buf: buffer, variants: {{any}}) -> ()}Arguments
Section titled “Arguments”- buf: The buffer containing the updates.
- variants: The variants table containing non-serialized values.
client:apply_full()
Section titled “client:apply_full()”Applies the full state of the world from the server.
type Client = { apply_full: (self: Client, buf: buffer, variants: {{any}}) -> ()}Arguments
Section titled “Arguments”- buf: The buffer containing the updates.
- variants: The variants table containing non-serialized values.
client:hook()
Section titled “client:hook()”Hooks to a networking process. The arguments depend on the action type
type Client = { hook: (self: Client, action: "changed", pair: Pair, callback: (entity: Entity, id: Id, value: any) -> ()) -> Disconnect, hook: (self: Client, action: "removed", pair: Pair, callback: (entity: Entity, id: Id) -> ()) -> Disconnect, hook: (self: Client, action: "deleted", entity: Entity, callback: (entity: Entity) -> ()) -> Disconnect,}Arguments
Section titled “Arguments”- action: The action to hook to.
- …: Hook arguments.
Returns
Section titled “Returns”- disconnect: A function that disconnects the hook when called.
client:override()
Section titled “client:override()”Special hook that overrides the networking process entirely, allowing you to customize or abort actions.
The usage is identical to client:hook().
type Client = { override: (self: Client, action: "changed", pair: Pair, callback: (entity: Entity, id: Id, value: any) -> ()) -> Disconnect, override: (self: Client, action: "removed", pair: Pair, callback: (entity: Entity, id: Id) -> ()) -> Disconnect, override: (self: Client, action: "deleted", entity: Entity, callback: (entity: Entity) -> ()) -> Disconnect,}client:added()
Section titled “client:added()”Hook that gets called when replecs creates a new entity,
this is called right after the entity is created so it will be empty.
Use client:after_replication() to wait for any useful info from it.
This hook is not called if the entity was created with a custom id.
type Client = { added: (self: Client, callback: (entity: Entity) -> ()) -> Disconnect,}Arguments
Section titled “Arguments”- callback: Function that gets called when the entity is created.
Returns
Section titled “Returns”- disconnect: A function that disconnects the hook when called.
client:get_server_entity()
Section titled “client:get_server_entity()”Gets the equivalent server entity for a client entity.
type Client = { get_server_entity: (self: Client, client_entity: Entity) -> number?}Arguments
Section titled “Arguments”- entity: The client entity.
Returns
Section titled “Returns”- server_entity: The server entity, This is typed a number to avoid using this in the client.
client:get_client_entity()
Section titled “client:get_client_entity()”Gets the equivalent client entity from a server entity.
type Client = { get_client_entity: (self: Client, server_entity: number) -> Entity?}Arguments
Section titled “Arguments”- server_entity: The server entity.
Returns
Section titled “Returns”- entity: The client entity.
client:register_entity()
Section titled “client:register_entity()”Binds a client entity to a server id. This would modify what get_server_entity and get_client_entity return.
type Client = { register_entity: (self: Client, entity: Entity, server_entity: number) -> ()}Arguments
Section titled “Arguments”- entity: The client entity to bind.
- server_entity: The server entity to bind.
client:unregister_entity()
Section titled “client:unregister_entity()”Unbinds a client entity from a server id. This would also cause replecs to recreate a client entity for the server entity, and can possibly be used for force replecs to re-run custom ids.
type Client = { unregister_entity: (self: Client, entity: Entity) -> ()}Arguments
Section titled “Arguments”- entity: The client entity to unbind.
client:enconde_component()
Section titled “client:enconde_component()”Encodes a component for sending through the network. This returns a number between 1 to 255.
type Client = { encode_component: (self: Client, component: Entity) -> number}Arguments
Section titled “Arguments”- component: The component to encode.
Returns
Section titled “Returns”- number: The encoded component.
client:decode_component()
Section titled “client:decode_component()”Decodes a component from a number.
type Client = { decode_component: (self: Client, encoded: number) -> Entity}Arguments
Section titled “Arguments”- number: The number to decode, This is number from
encode_component.
Returns
Section titled “Returns”- component: The decoded component.
client:register_custom_id()
Section titled “client:register_custom_id()”Registers a custom id handler. Custom ids can only be used if they are registered.
type Client = { register_custom_id: (self: Client, custom_id: CustomId) -> ()}client:generate_handshake()
Section titled “client:generate_handshake()”Generates a handshake info. This can be used to verify that the server and client are setup correctly.
Relevant for components with shared,serdes and custom_ids,
as a mistmatch in these between server and client would cause hard to debug issues.
type Client = { generate_handshake: (self: Client) -> HandshakeInfo}Returns
Section titled “Returns”- handshake: The handshake info. This can be passed to
server:verify_handshake()
client:verify_handshake()
Section titled “client:verify_handshake()”Verifies a handshake info from server:generate_handshake().
type Client = { verify_handshake: (self: Client, handshake: HandshakeInfo) -> (success: boolean, err: string?)}Arguments
Section titled “Arguments”- handshake: The handshake info to verify.
Returns
Section titled “Returns”- success: Whether the handshake info is valid.
- err: The error message if the handshake was not successful.