NpcInfo

An implementation of the npc info packet. This class is responsible for bringing together all the bits of the npc info protocol, including copying all the pre-built buffers that were made beforehand.

Functions

Link copied to clipboard

Synchronizes the last coordinate of the local player with the current coordinate set previously in this cycle. This is simply to help make removal of all NPCs in high resolution more efficient, as we can avoid distance checks against every NPC, and only do so against the player's last coordinate.

Link copied to clipboard
fun backingBuffer(): ByteBuf

Returns the backing byte buffer holding all the computed information.

Link copied to clipboard
fun compute()

Computes the high resolution and low resolution bitcodes for this given player, additionally marks down which NPCs need to furthermore send their extended info updates.

Link copied to clipboard
open override fun onAlloc(index: Int, oldSchoolClientType: OldSchoolClientType)

Invoked whenever a previously pooled object is re-allocated. This function will be responsible for restoring state to be equivalent to newly instantiated object.

Link copied to clipboard
open override fun onDealloc()

Invoked whenever a pooled object is no longer in use. This function is primarily used to clear out any sensitive information or potential memory leaks regarding byte buffers. This function should not fully reset objects, particularly primitives, as there is a chance a given pooled object never gets re-utilized and the garbage collector ends up picking it up. In such cases, it is more beneficial to do the resetting of properties during the onAlloc, to ensure no work is 'wasted'.

Link copied to clipboard

This function allocates a new clean world details object, as on reconnect, all existing npc info state is lost. This function should be called on the old npc info object whenever a reconnect occurs.

Link copied to clipboard

Resets the view distance back to a default value of 15 tile radius.

Link copied to clipboard

Sets the view distance, meaning how far the player can see NPCs.

Link copied to clipboard
fun toNpcInfoPacket(): OutgoingGameMessage

Turns this npc info structure into a respective npc info packet, depending on the current known view distance.

Link copied to clipboard
fun updateBuildArea(buildArea: BuildArea)

Updates the build area for this NPC info. This will ensure that no NPCs outside of this box will be added to high resolution view.

Link copied to clipboard
fun updateCoord(level: Int, x: Int, z: Int)

Updates the coordinate of the local player, as this is necessary to know how far NPCs nearby are to the player, which allows us to remove NPCs that have gone too far out, and add NPCs that are within certain distance.