Created
April 7, 2023 16:57
-
-
Save ultraviolet-jordan/f3fb9e2885edbfaa969a26650c84b3fe to your computer and use it in GitHub Desktop.
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. | |
lowDefinitionUpdates[actor.index] = actor.renderer.lowDefinitionRenderBlocks.buildLowDefinitionUpdates() | |
} | |
override fun clear() { | |
lowDefinitionUpdates.fill(null) | |
highDefinitionUpdates.fill(null) | |
} | |
private fun Array<HighDefinitionRenderBlock<*>?>.buildHighDefinitionUpdates(player: Player): ByteArray { | |
val mask = calculateMask(0x40) | |
val size = calculateSize(mask) | |
return RSByteBuffer(ByteBuffer.allocate(size)).also { | |
it.writeMask(mask) | |
for (block in this) { | |
if (block == null) continue | |
val start = it.position() | |
block.builder.build(it, block.renderType) | |
val end = it.position() | |
player.renderer.setLowDefinitionRenderingBlock(block, it.array().sliceArray(start until end)) | |
} | |
}.array() | |
} | |
private fun Array<LowDefinitionRenderBlock<*>?>.buildLowDefinitionUpdates(): ByteArray { | |
val mask = calculateMask(0x40) | |
val size = calculateSize(mask) | |
return RSByteBuffer(ByteBuffer.allocate(size)).also { | |
it.writeMask(mask) | |
for (block in this) { | |
if (block == null) continue | |
it.writeBytes(block.bytes) | |
} | |
}.array() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment