Created
April 7, 2023 16:59
-
-
Save ultraviolet-jordan/1e15f70869be850486b9877636b42f0a 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
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