PlayerInfo

An implementation of the player info packet. This class is responsible for tracking and building the packets each cycle. This class utilizes ReferencePooledObject, meaning instances of it will be pooled and re-used as needed, as the data stored within them is relatively memory-heavy.

Parameters

protocol

the repository of all the PlayerInfo objects, as well as a source global information about everyone in the game. As the packet is responsible for tracking everyone in the game, we need to provide access to this.

localIndex

the index of this local player. The index corresponds to the player's slot in the world. The index will not change throughout the lifespan of a player, but can change within allocations in the reference pool.

allocator

the ByteBuf allocator responsible for allocating the primary buffer the is written out to the pipeline, as well as any intermediate buffers used by extended info blocks. The allocator should ideally be pooled, as we acquire a new instance with each cycle. This is because there isn't necessarily a guarantee that Netty threads have fully written the information out to the network by the time the next cycle comes along and starts writing into this buffer. A direct implementation is also preferred, as this avoids unnecessary copying from and to the heap.

oldSchoolClientType

the client on which the player is logging into. This is utilized to determine what encoders to use for extended info blocks.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun allocateWorld(worldId: Int)

Allocates a new player info tracking object for the respective worldId, keeping track of everyone that's within this new world entity.

Link copied to clipboard

Appends the high resolution indices to the provided collection. This can be used to determine which players the player is currently seeing in the client.

Link copied to clipboard
fun clearEntities(worldId: Int)

Clears all the entities for the provided worldId. This function is only intended to be used together with the net.rsprot.protocol.game.outgoing.worldentity.ClearEntities packet. This packet should only be called before PlayerInfoProtocol.update has been called, otherwise problems may arise.

Link copied to clipboard
fun destroyWorld(worldId: Int)

Destroys player info tracking for the specified worldId. This is intended to be used when one of the world entities leaves the render distance.

Link copied to clipboard

Gets the high resolution indices in a new arraylist of integers. The list is initialized to an initial capacity equal to the high resolution player index count.

Link copied to clipboard
fun handleAbsolutePlayerPositions(byteBuf: ByteBuf)

Handles initializing absolute player positions.

Link copied to clipboard
open override fun isDestroyed(): Boolean

Whether this reference pooled object is destroyed. A destroyed object will not be returned back to the pool and instead will be left off for the garbage collector to clean up in due time. This condition is only hit when there was some error thrown during the processing of a given info object. In order to mitigate potential future problems that might continue to stem from re-using this object, we discard it altogether.

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

Resets all the primitive properties of this class which can be lazy-reset. We utilize lazy resetting here as there's no guarantee that a given PlayerInfo object will ever be re-used. Due to the nature of soft references, it is possible for the garbage collector to collect it when it truly needs it. In order to reduce processing time, we skip resetting these properties on de-allocation.

Link copied to clipboard
open override fun onDealloc()

Clears any references to temporary buffers on de-allocation, as we don't want these to stick around for extended periods of time. Any primitive properties will remain untouched.

Link copied to clipboard

Resets any existing state. Cached state should be re-assigned from the server as a result of this.

Link copied to clipboard
fun setHighPriority(otherPlayerAvatar: PlayerAvatar)

Sets the otherPlayerAvatar as high priority for us specifically. This means that when our local player count gets to >= 250 players, we will still keep that player rendered even if they are no longer within the range that we can still see to. It does not, however, extend past the preferred view range.

Link copied to clipboard
fun setNormalPriority(otherPlayerAvatar: PlayerAvatar)

Sets the otherPlayerAvatar back down to normal priority level, meaning they will not get preferential treatment in relation to everyone else at high populations, as described in setHighPriority.

Link copied to clipboard

Turns the player info object into a wrapped packet. This is necessary because the encoder itself is only triggered in Netty, and it is possible that the buffer has already been replaced with a new variant before it gets to that stage.

Link copied to clipboard
fun updateBuildArea(worldId: Int, buildArea: BuildArea)
fun updateBuildArea(worldId: Int, zoneX: Int, zoneZ: Int, widthInZones: Int = BuildArea.DEFAULT_BUILD_AREA_SIZE, heightInZones: Int = BuildArea.DEFAULT_BUILD_AREA_SIZE)

Updates the build area of a given world to the specified one. This will ensure that no players 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 current known coordinate of the given Avatar. This function must be called on each avatar before player info is computed.

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

Updates the render coordinate for the provided world id. This coordinate is what will be used to perform distance checks between the player and everyone else.