Skip to content

Instantly share code, notes, and snippets.

@ultraviolet-jordan
Created April 7, 2023 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ultraviolet-jordan/1e15f70869be850486b9877636b42f0a to your computer and use it in GitHub Desktop.
Save ultraviolet-jordan/1e15f70869be850486b9877636b42f0a to your computer and use it in GitHub Desktop.
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
}
fun setLowDefinitionRenderingBlock(highDefinitionRenderingBlock: HighDefinitionRenderBlock<*>, bytes: ByteArray) {
val lowDefinitionRenderingBlock = LowDefinitionRenderBlock(
renderType = highDefinitionRenderingBlock.renderType,
builder = highDefinitionRenderingBlock.builder,
bytes = bytes
)
lowDefinitionRenderBlocks[highDefinitionRenderingBlock.builder.index] = lowDefinitionRenderingBlock
}
fun hasHighDefinitionUpdate(): Boolean = highDefinitionRenderBlocks.any { it != null }
fun clearUpdates() {
// Clear out the pending high definition blocks.
highDefinitionRenderBlocks.fill(null)
// Clear out the pending low definition blocks.
for (index in lowDefinitionRenderBlocks.indices) {
val renderType = lowDefinitionRenderBlocks[index]?.renderType ?: continue
// Persist these render types.
if (renderType is Appearance || renderType is MovementSpeed || renderType is FaceAngle || renderType is FaceActor) continue
lowDefinitionRenderBlocks[index] = null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment