Skip to main content
Skip to main content

PlayerNetworkComponent

PlayerNetworkComponent

Description

A base, abstract class that defines a set of functions for a networking component for the player.

Functions

debugDraw

Description

Displays the debug information.

Definition

debugDraw(float x, float y, float textSize)

Arguments

floatxThe x position on the screen to begin drawing the values.
floatyThe y position on the screen to begin drawing the values.
floattextSizeThe height of the text.

Return Values

floatyThe y position on the screen after the entire debug info was drawn.

Code

function PlayerNetworkComponent:debugDraw(x, y, textSize)
return y
end

new

Description

Creates an instance of the abstract PlayerNetworkComponent class. Only use this when deriving another class from it.

Definition

new(Player player, table custom_mt)

Arguments

PlayerplayerThe player who owns this component.
tablecustom_mtThe required metatable used to derive this class.

Return Values

tableinstanceThe created instance.

Code

function PlayerNetworkComponent.new(player, custom_mt)

-- Create the instance with the given metatable.
local self = setmetatable( { } , custom_mt)

-- The player who owns this component.
self.player = player

-- Return the created instance.
return self
end

readUpdateStream

Description

Reads the data from the incoming network stream and handles the state.

Definition

readUpdateStream(integer streamId, Connection connection, integer timestamp)

Arguments

integerstreamIdThe id of the stream from which to read.
ConnectionconnectionThe connection between the server and the target client.
integertimestampThe current timestamp for synchronisation purposes.

Code

function PlayerNetworkComponent:readUpdateStream(streamId, connection, timestamp)

end

update

Description

Updates the player based on the network state every frame.

Definition

update(float dt)

Arguments

floatdtdelta time in ms

Code

function PlayerNetworkComponent:update(dt)
end

updateTick

Description

Runs every tick and handles preparing the state.

Definition

updateTick(float dt)

Arguments

floatdtDelta time in ms.

Code

function PlayerNetworkComponent:updateTick(dt)
end

writeUpdateStream

Description

Writes the state into the outgoing network stream.

Definition

writeUpdateStream(integer streamId, Connection connection, integer dirtyMask)

Arguments

integerstreamIdThe id of the stream into which to write.
ConnectionconnectionThe connection between the server and the target client.
integerdirtyMaskThe current dirty mask.

Code

function PlayerNetworkComponent:writeUpdateStream(streamId, connection, dirtyMask)

end