element: rename maxSize to prefMaxSize, remove RenderWindow::setRenderStatus

This commit is contained in:
Bixilon 2021-08-31 15:25:39 +02:00
parent f25ec89bde
commit 8bf7246bb7
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 46 additions and 37 deletions

View File

@ -128,21 +128,26 @@ open class TextComponent(
for (chatFormattingCode in formatting) {
when (chatFormattingCode) {
PreChatFormattingCodes.OBFUSCATED -> {
// ToDo: potential memory leak: Stop timeline, when TextComponent isn't shown anymore
// ToDo: potential memory/performance leak: Stop timeline, when TextComponent isn't shown anymore
val obfuscatedTimeline = if (Minosoft.config.config.chat.obfuscated) {
Timeline(KeyFrame(Duration.millis(50.0), {
val chars = text.text.toCharArray()
for (i in chars.indices) {
chars[i] = Util.getRandomChar(ProtocolDefinition.OBFUSCATED_CHARS)
}
text.text = String(chars)
}))
Timeline(
KeyFrame(Duration.millis(50.0), {
val chars = text.text.toCharArray()
for (i in chars.indices) {
chars[i] = Util.getRandomChar(ProtocolDefinition.OBFUSCATED_CHARS)
}
text.text = String(chars)
}),
)
} else {
Timeline(KeyFrame(Duration.millis(500.0), {
text.isVisible = false
}), KeyFrame(Duration.millis(1000.0), {
text.isVisible = true
}))
Timeline(
KeyFrame(Duration.millis(500.0), {
text.isVisible = false
}),
KeyFrame(Duration.millis(1000.0), {
text.isVisible = true
}),
)
}
obfuscatedTimeline.cycleCount = Animation.INDEFINITE

View File

@ -63,6 +63,17 @@ class RenderWindow(
private val latch = CountUpAndDownLatch(1)
private var renderingState = RenderingStates.RUNNING
set(value) {
if (field == value) {
return
}
if (field == RenderingStates.PAUSED) {
queue.clear()
}
val previousState = field
field = value
connection.fireEvent(RenderingStateChangeEvent(connection, previousState, value))
}
private val screenshotTaker = ScreenshotTaker(this)
@ -168,11 +179,11 @@ class RenderWindow(
Log.log(LogMessageType.RENDERING_LOADING) { "Registering window callbacks (${stopwatch.labTime()})..." }
connection.registerEvent(CallbackEventInvoker.of<WindowFocusChangeEvent> {
setRenderStatus(it.focused.decide(RenderingStates.RUNNING, RenderingStates.SLOW))
renderingState = it.focused.decide(RenderingStates.RUNNING, RenderingStates.SLOW)
})
connection.registerEvent(CallbackEventInvoker.of<WindowIconifyChangeEvent> {
setRenderStatus(it.iconified.decide(RenderingStates.PAUSED, RenderingStates.RUNNING))
renderingState = it.iconified.decide(RenderingStates.PAUSED, RenderingStates.RUNNING)
})
@ -221,11 +232,16 @@ class RenderWindow(
if (connection.wasConnected || closed) {
break
}
if (renderingState == RenderingStates.PAUSED) {
window.title = "Minosoft | Paused"
}
while (renderingState == RenderingStates.PAUSED) {
Thread.sleep(100L)
window.pollEvents()
continue
}
renderStats.startFrame()
renderSystem.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER)
@ -269,9 +285,9 @@ class RenderWindow(
queue.timeWork(RenderConstants.MAXIMUM_QUEUE_TIME_PER_FRAME)
when (renderingState) {
RenderingStates.SLOW -> Thread.sleep(100L)
RenderingStates.RUNNING, RenderingStates.PAUSED -> {
}
RenderingStates.SLOW -> Thread.sleep(100L)
RenderingStates.STOPPED -> window.close()
}
renderStats.endFrame()
@ -288,18 +304,6 @@ class RenderWindow(
connection.disconnect()
}
private fun setRenderStatus(renderingStatus: RenderingStates) {
if (renderingStatus == this.renderingState) {
return
}
if (this.renderingState == RenderingStates.PAUSED) {
queue.clear()
}
val previousState = this.renderingState
this.renderingState = renderingStatus
connection.fireEvent(RenderingStateChangeEvent(connection, previousState, renderingState))
}
fun registerRenderer(rendererBuilder: RendererBuilder<*>) {
val renderer = rendererBuilder.build(connection, this)
rendererMap[rendererBuilder.RESOURCE_LOCATION] = renderer

View File

@ -33,7 +33,7 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
*/
fun wrap(): Boolean {
val yAdd = Font.CHAR_HEIGHT + Font.VERTICAL_SPACING
if (size.y + yAdd > element.maxSize.y) {
if (size.y + yAdd > element.prefMaxSize.y) {
return true
}
offset.x = initialOffset.x
@ -47,7 +47,7 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
* @return If the text can't fit into the layout anymore
*/
fun add(x: Int): Boolean {
if (offset.x - initialOffset.x + x > element.maxSize.x) {
if (offset.x - initialOffset.x + x > element.prefMaxSize.x) {
if (wrap()) {
return true
}
@ -90,7 +90,7 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
val width = charData.calculateWidth(text)
if (offset.x == initialOffset.x && offset.x - initialOffset.x + width > element.maxSize.x) {
if (offset.x == initialOffset.x && offset.x - initialOffset.x + width > element.prefMaxSize.x) {
return
}
consumer?.let { charData.render(offset, z, text, it) }

View File

@ -21,20 +21,20 @@ abstract class Element {
open var prepared: Boolean = false
open var minSize: Vec2i = Vec2i(10, 10)
open var maxSize: Vec2i = Vec2i(50, 50)
open var prefMaxSize: Vec2i = Vec2i(50, 50)
open var size: Vec2i = Vec2i()
open val realMaxSize: Vec2i
open val maxSize: Vec2i
get() {
val ret = Vec2i()
parent?.let {
ret.x = maxSize.x
ret.y = maxSize.y
ret.x = prefMaxSize.x
ret.y = prefMaxSize.y
}
val maxSize = maxSize
val maxSize = prefMaxSize
if (maxSize.x < ret.x) {
ret.x = maxSize.x