mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
lightmap: reduce memory allocations
This commit is contained in:
parent
9cb58126c7
commit
b85c9e475f
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
* Copyright (C) 2020-2025 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -16,7 +16,6 @@ package de.bixilon.minosoft.gui.rendering.light.updater
|
||||
import de.bixilon.kotlinglm.vec3.Vec3
|
||||
import de.bixilon.minosoft.gui.rendering.light.LightmapBuffer
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import java.util.*
|
||||
|
||||
object FullbrightLightUpdater : LightmapUpdater {
|
||||
|
||||
@ -25,7 +24,6 @@ object FullbrightLightUpdater : LightmapUpdater {
|
||||
return
|
||||
}
|
||||
|
||||
val random = Random(10000L)
|
||||
for (sky in 0 until ProtocolDefinition.LIGHT_LEVELS) {
|
||||
for (block in 0 until ProtocolDefinition.LIGHT_LEVELS) {
|
||||
buffer[sky, block] = Vec3(1.0f)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2024 Moritz Zwerger
|
||||
* Copyright (C) 2020-2025 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -26,7 +26,7 @@ import de.bixilon.minosoft.data.world.weather.WorldWeather
|
||||
import de.bixilon.minosoft.gui.rendering.light.LightmapBuffer
|
||||
import de.bixilon.minosoft.gui.rendering.light.updater.LightmapUpdater
|
||||
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.clamp
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.clampAssign
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.modify
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.interpolateLinear
|
||||
import de.bixilon.minosoft.protocol.network.session.play.PlaySession
|
||||
@ -91,9 +91,10 @@ class NormalLightmapUpdater(
|
||||
val gamma = profile.gamma
|
||||
val nightVision = getNightVisionStrength(millis)
|
||||
|
||||
var color = Vec3()
|
||||
for (sky in 0 until ProtocolDefinition.LIGHT_LEVELS) {
|
||||
for (block in 0 until ProtocolDefinition.LIGHT_LEVELS) {
|
||||
var color = combine(skyColors[sky], blockColors[block])
|
||||
combine(skyColors[sky], blockColors[block], color)
|
||||
color = tweak(color, gamma, dimension.effects.brighten, nightVision)
|
||||
buffer[sky, block] = color
|
||||
}
|
||||
@ -165,10 +166,10 @@ class NormalLightmapUpdater(
|
||||
}
|
||||
|
||||
|
||||
private fun combine(sky: Vec3, block: Vec3): Vec3 {
|
||||
val color = sky + block
|
||||
private fun combine(sky: Vec3, block: Vec3, output: Vec3) {
|
||||
Vec3.plus(output, sky, block.x, block.y, block.z)
|
||||
|
||||
return color.clamp()
|
||||
output.clampAssign()
|
||||
}
|
||||
|
||||
private fun tweak(
|
||||
@ -200,7 +201,7 @@ class NormalLightmapUpdater(
|
||||
}
|
||||
|
||||
private fun applyBrighten(color: Vec3, brighten: Vec3): Vec3 {
|
||||
return interpolateLinear(0.25f, color, brighten).clamp()
|
||||
return interpolateLinear(0.25f, color, brighten).apply { clampAssign() }
|
||||
}
|
||||
|
||||
private fun applyGamma(color: Vec3, gamma: Float): Vec3 {
|
||||
@ -225,8 +226,8 @@ class NormalLightmapUpdater(
|
||||
return this * (1.0f - value) + value
|
||||
}
|
||||
|
||||
private fun Vec3.clamp(): Vec3 {
|
||||
return clamp(0.0f, 1.0f)
|
||||
private fun Vec3.clampAssign() {
|
||||
this.clampAssign(0.0f, 1.0f)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
@ -101,6 +101,8 @@ class ParticleRenderer(
|
||||
profile::maxAmount.observe(this, true) { maxAmount = minOf(it, MAXIMUM_AMOUNT) }
|
||||
profile::enabled.observe(this, true) { enabled = it }
|
||||
|
||||
// TODO: unload particles when renderer is paused
|
||||
|
||||
session.events.listen<CameraMatrixChangeEvent> { matrixUpdate = true }
|
||||
|
||||
mesh.load()
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.particle
|
||||
|
||||
import de.bixilon.kutil.concurrent.schedule.RepeatedTask
|
||||
import de.bixilon.kutil.exception.ExceptionUtil.ignoreAll
|
||||
import de.bixilon.kutil.time.TimeUtil.millis
|
||||
import de.bixilon.minosoft.data.world.chunk.ChunkUtil.isInViewDistance
|
||||
@ -24,7 +23,6 @@ import de.bixilon.minosoft.protocol.network.session.play.PlaySessionStates
|
||||
class ParticleTicker(val renderer: ParticleRenderer) {
|
||||
private val particles = renderer.particles
|
||||
private val context = renderer.context
|
||||
private var task: RepeatedTask? = null
|
||||
|
||||
|
||||
private fun canTick(): Boolean {
|
||||
@ -69,8 +67,7 @@ class ParticleTicker(val renderer: ParticleRenderer) {
|
||||
if (collect) {
|
||||
particle.addVertex(renderer.mesh, renderer.translucentMesh, time)
|
||||
}
|
||||
if (index % 1000 == 0) {
|
||||
// check periodically if time is exceeded
|
||||
if (index % 1000 == 0) { // don't spam the os with time calls
|
||||
time = millis()
|
||||
if (time - start > MAX_TICK_TIME) {
|
||||
break
|
||||
|
@ -169,6 +169,11 @@ object VecUtil {
|
||||
z = horizontal(positionHash shr 8)).clamp(-maxModelOffset, maxModelOffset)
|
||||
}
|
||||
|
||||
fun Vec3.clampAssign(min: Float, max: Float) {
|
||||
this.x = x.clamp(min, max)
|
||||
this.y = y.clamp(min, max)
|
||||
this.z = z.clamp(min, max)
|
||||
}
|
||||
fun Vec3.clamp(min: Float, max: Float): Vec3 {
|
||||
return Vec3(
|
||||
x = x.clamp(min, max),
|
||||
|
Loading…
x
Reference in New Issue
Block a user