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
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.
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.
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 this player info object. 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.