Player Info
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
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.
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.
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.
the client on which the player is logging into. This is utilized to determine what encoders to use for extended info blocks.
Functions
Allocates a new player info tracking object for the respective worldId, keeping track of everyone that's within this new world entity.
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.
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.
Destroys player info tracking for the specified worldId. This is intended to be used when one of the world entities leaves the render distance.
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.
Handles initializing absolute player positions.
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.
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.
Resets any existing state. Cached state should be re-assigned from the server as a result of this.
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.
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.
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.
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.
Updates the current known coordinate of the given Avatar. This function must be called on each avatar before player info is computed.
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.