This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PlayerAppearanceBlockBuilder : RenderBlockBuilder<Appearance>( | |
index = 1, | |
mask = 0x4 | |
) { | |
private val builders = arrayOf( | |
HeadBuilder(), | |
BackBuilder(), | |
NeckBuilder(), | |
MainHandBuilder(), | |
TorsoBuilder(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
class PlayerUpdateBlocks( | |
val highDefinitionUpdates: Array<ByteArray?> = arrayOfNulls<ByteArray?>(World.MAX_PLAYERS), | |
val lowDefinitionUpdates: Array<ByteArray?> = arrayOfNulls<ByteArray?>(World.MAX_PLAYERS) | |
) : UpdateBlocks<Player>() { | |
override fun buildPendingUpdatesBlocks(actor: Player) { | |
if (actor.renderer.hasHighDefinitionUpdate()) { | |
highDefinitionUpdates[actor.index] = actor.renderer.highDefinitionRenderBlocks.buildHighDefinitionUpdates(actor) | |
} | |
// Low definitions are always built here for persisted blocks from previous game cycles. i.e Appearance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class UpdateBlocks<A : Actor> { | |
abstract fun buildPendingUpdatesBlocks(actor: A) | |
abstract fun clear() | |
fun Array<out RenderBlock<*>?>.calculateMask(comparator: Int): Int = fold(0) { mask, block -> | |
if (block == null) mask else mask or block.builder.mask | |
}.let { if (it > 0xFF) it or comparator else it } | |
fun Array<out RenderBlock<*>?>.calculateSize(mask: Int): Int = fold(0) { size, block -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
class PlayerInfoPacketBuilder @Inject constructor( | |
private val updateBlocks: PlayerUpdateBlocks | |
) : PacketBuilder<PlayerInfoPacket>( | |
opcode = 3, | |
size = -2 | |
) { | |
override fun build(packet: PlayerInfoPacket, buffer: RSByteBuffer) { | |
val players = packet.players | |
val viewport = packet.viewport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.nio.ByteBuffer | |
import kotlin.math.abs | |
fun main() { | |
val expectedInt = 420 | |
val buffer = ByteBuffer.allocate(3) | |
buffer.putAsVl64(expectedInt) | |
buffer.flip() | |
val readInt = buffer.getAsVl64() | |
println("Matches? ${expectedInt == readInt}") |
NewerOlder