Created
April 7, 2023 16:56
-
-
Save ultraviolet-jordan/255c9c44b53292cd4864225e6ed5f845 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
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 -> | |
if (block == null) return@fold size | |
when (block) { | |
is LowDefinitionRenderBlock -> size + block.bytes.size | |
is HighDefinitionRenderBlock -> size + block.builder.size(block.renderType) | |
else -> throw AssertionError("Block is not in correct instance.") | |
} | |
}.let { if (mask > 0xFF) it + 2 else it + 1 } | |
fun RSByteBuffer.writeMask(mask: Int) { | |
if (mask > 0xff) writeShortLittleEndian(mask) else writeByte(mask) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment