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}") |
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 RSByteBuffer( | |
private val buffer: ByteBuffer | |
) { | |
constructor(array: ByteArray) : this(ByteBuffer.wrap(array)) | |
private var accessBitsIndex = -1 | |
fun readByte(): Int { | |
checkAccessingBytes() | |
return buffer.get().toInt() |
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 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
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
class ActorRenderer( | |
val lowDefinitionRenderBlocks: Array<LowDefinitionRenderBlock<*>?> = arrayOfNulls(13), | |
val highDefinitionRenderBlocks: Array<HighDefinitionRenderBlock<*>?> = arrayOfNulls(13) | |
) { | |
fun <T : RenderType> update(type: T): T { | |
val block = type.toBlock() | |
highDefinitionRenderBlocks[block.index] = HighDefinitionRenderBlock(type, block) | |
return type | |
} |
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 Viewport( | |
val player: Player | |
) { | |
val nsnFlags = IntArray(MAX_PLAYERS) | |
val locations = IntArray(MAX_PLAYERS) | |
val highDefinitions = IntArray(MAX_PLAYERS) | |
val lowDefinitions = IntArray(MAX_PLAYERS) | |
val highDefinitionUpdates = ArrayList<Int>() | |
val lowDefinitionUpdates = ArrayList<Int>() | |
val players = arrayOfNulls<Player?>(MAX_PLAYERS) |
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
fun main() { | |
val buffer = ByteBuffer.allocate(100) | |
buffer.withBitAccess { | |
pBit(2, 3) | |
pBit(1, 0) | |
} | |
} | |
inline fun ByteBuffer.withBitAccess(function: ByteBuffer.() -> Unit) { | |
position(position() * 8) |
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
@JvmInline | |
value class MapSquareLandTile( | |
private val packed: Long | |
) { | |
constructor( | |
height: Int, | |
overlayId: Int, | |
overlayPath: Int, | |
overlayRotation: Int, | |
collision: Int, |
OlderNewer