mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
some further memory improvements
Mainly when moving around
This commit is contained in:
parent
8035ca315d
commit
db7e1312d8
@ -155,10 +155,11 @@ class Frustum(
|
|||||||
|
|
||||||
fun containsChunkSection(chunkPosition: Vec2i, sectionHeight: Int, minPosition: Vec3i = CHUNK_NIN_POSITION, maxPosition: Vec3i = ProtocolDefinition.CHUNK_SECTION_SIZE): Boolean {
|
fun containsChunkSection(chunkPosition: Vec2i, sectionHeight: Int, minPosition: Vec3i = CHUNK_NIN_POSITION, maxPosition: Vec3i = ProtocolDefinition.CHUNK_SECTION_SIZE): Boolean {
|
||||||
val offset = camera.offset.offset
|
val offset = camera.offset.offset
|
||||||
val base = Vec3i.of(chunkPosition, sectionHeight) - offset
|
val base = Vec3i.of(chunkPosition, sectionHeight)
|
||||||
val min = base + minPosition
|
base -= offset
|
||||||
val max = base + maxPosition + 1
|
val min = Vec3(base.x.toFloat() + minPosition.x, base.y.toFloat() + minPosition.y, base.z.toFloat() + minPosition.z)
|
||||||
return containsRegion(Vec3(min), Vec3(max))
|
val max = Vec3(base.x + maxPosition.x + 1.0f, base.y + maxPosition.y + 1.0f, base.z + maxPosition.z + 1.0f)
|
||||||
|
return containsRegion(min, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun containsChunk(chunkPosition: Vec2i): Boolean {
|
fun containsChunk(chunkPosition: Vec2i): Boolean {
|
||||||
|
@ -15,9 +15,10 @@ package de.bixilon.minosoft.gui.rendering.stats
|
|||||||
|
|
||||||
import de.bixilon.kutil.avg.LongAverage
|
import de.bixilon.kutil.avg.LongAverage
|
||||||
import de.bixilon.kutil.time.TimeUtil
|
import de.bixilon.kutil.time.TimeUtil
|
||||||
|
import de.bixilon.kutil.time.TimeUtil.millis
|
||||||
|
|
||||||
class RenderStats : AbstractRenderStats {
|
class RenderStats : AbstractRenderStats {
|
||||||
override val avgFrameTime: LongAverage = LongAverage(1L * 1000000000L) // 1 second * SECOND_SCALE
|
override val avgFrameTime: LongAverage = LongAverage(1L * 1000000000L, Long.MAX_VALUE) // 1 second * SECOND_SCALE
|
||||||
override var totalFrames: Long = 0L
|
override var totalFrames: Long = 0L
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ class RenderStats : AbstractRenderStats {
|
|||||||
|
|
||||||
override var smoothAvgFPS: Double = 0.0
|
override var smoothAvgFPS: Double = 0.0
|
||||||
get() {
|
get() {
|
||||||
val time = TimeUtil.millis
|
val time = millis()
|
||||||
if (time - lastSmoothFPSCalculationTime > 100) {
|
if (time - lastSmoothFPSCalculationTime > 100) {
|
||||||
field = avgFPS
|
field = avgFPS
|
||||||
lastSmoothFPSCalculationTime = time
|
lastSmoothFPSCalculationTime = time
|
||||||
|
@ -21,7 +21,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTex
|
|||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
||||||
|
|
||||||
class SingleWorldMesh(context: RenderContext, initialCacheSize: Int, onDemand: Boolean = false) : Mesh(context, WorldMeshStruct, initialCacheSize = initialCacheSize, onDemand = onDemand) {
|
class SingleWorldMesh(context: RenderContext, initialCacheSize: Int, onDemand: Boolean = false) : Mesh(context, WorldMeshStruct, initialCacheSize = initialCacheSize, onDemand = onDemand), Comparable<SingleWorldMesh> {
|
||||||
var distance: Float = 0.0f // Used for sorting
|
var distance: Float = 0.0f // Used for sorting
|
||||||
|
|
||||||
fun addVertex(position: FloatArray, uv: Vec2, texture: AbstractTexture, tintColor: Int, light: Int) {
|
fun addVertex(position: FloatArray, uv: Vec2, texture: AbstractTexture, tintColor: Int, light: Int) {
|
||||||
@ -44,6 +44,12 @@ class SingleWorldMesh(context: RenderContext, initialCacheSize: Int, onDemand: B
|
|||||||
data.add(tintLight)
|
data.add(tintLight)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun compareTo(other: SingleWorldMesh): Int {
|
||||||
|
if (distance < other.distance) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
data class WorldMeshStruct(
|
data class WorldMeshStruct(
|
||||||
val position: Vec3,
|
val position: Vec3,
|
||||||
|
@ -39,7 +39,7 @@ class VisibleMeshes(val cameraPosition: Vec3 = Vec3.EMPTY, previous: VisibleMesh
|
|||||||
opaque += it
|
opaque += it
|
||||||
}
|
}
|
||||||
mesh.translucentMesh?.let {
|
mesh.translucentMesh?.let {
|
||||||
it.distance = distance
|
it.distance = -distance
|
||||||
translucent += it
|
translucent += it
|
||||||
}
|
}
|
||||||
mesh.transparentMesh?.let {
|
mesh.transparentMesh?.let {
|
||||||
@ -58,10 +58,10 @@ class VisibleMeshes(val cameraPosition: Vec3 = Vec3.EMPTY, previous: VisibleMesh
|
|||||||
|
|
||||||
fun sort() {
|
fun sort() {
|
||||||
val worker = UnconditionalWorker()
|
val worker = UnconditionalWorker()
|
||||||
worker += UnconditionalTask(ThreadPool.Priorities.HIGHER) { opaque.sortBy { it.distance } }
|
worker += UnconditionalTask(ThreadPool.Priorities.HIGHER) { opaque.sort() }
|
||||||
worker += UnconditionalTask(ThreadPool.Priorities.HIGHER) { translucent.sortBy { -it.distance } }
|
worker += UnconditionalTask(ThreadPool.Priorities.HIGHER) { translucent.sort() }
|
||||||
worker += UnconditionalTask(ThreadPool.Priorities.HIGHER) { transparent.sortBy { it.distance } }
|
worker += UnconditionalTask(ThreadPool.Priorities.HIGHER) { transparent.sort() }
|
||||||
worker += UnconditionalTask(ThreadPool.Priorities.HIGHER) { text.sortBy { it.distance } }
|
worker += UnconditionalTask(ThreadPool.Priorities.HIGHER) { text.sort() }
|
||||||
worker.work()
|
worker.work()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,8 +250,10 @@ class WorldVisibilityGraph(
|
|||||||
|
|
||||||
val section = chunk.sections.getOrNull(sectionIndex)?.blocks
|
val section = chunk.sections.getOrNull(sectionIndex)?.blocks
|
||||||
|
|
||||||
|
val nextPosition = Vec2i()
|
||||||
|
|
||||||
if (directionX <= 0 && (section?.occlusion?.isOccluded(inverted, Directions.WEST) != true) && chunkPosition.x > chunkMin.x) {
|
if (directionX <= 0 && (section?.occlusion?.isOccluded(inverted, Directions.WEST) != true) && chunkPosition.x > chunkMin.x) {
|
||||||
val nextPosition = chunkPosition + Directions.WEST
|
nextPosition.x = chunkPosition.x - 1; nextPosition.y = chunkPosition.y // + WEST
|
||||||
val nextChunk = chunk.neighbours[ChunkNeighbours.WEST]
|
val nextChunk = chunk.neighbours[ChunkNeighbours.WEST]
|
||||||
if (nextChunk != null) {
|
if (nextChunk != null) {
|
||||||
val nextVisibilities = getVisibility(nextPosition) ?: return
|
val nextVisibilities = getVisibility(nextPosition) ?: return
|
||||||
@ -263,7 +265,7 @@ class WorldVisibilityGraph(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (directionX >= 0 && (section?.occlusion?.isOccluded(inverted, Directions.EAST) != true) && chunkPosition.x < chunkMax.x) {
|
if (directionX >= 0 && (section?.occlusion?.isOccluded(inverted, Directions.EAST) != true) && chunkPosition.x < chunkMax.x) {
|
||||||
val nextPosition = chunkPosition + Directions.EAST
|
nextPosition.x = chunkPosition.x + 1; nextPosition.y = chunkPosition.y // + EAST
|
||||||
val nextChunk = chunk.neighbours[ChunkNeighbours.EAST]
|
val nextChunk = chunk.neighbours[ChunkNeighbours.EAST]
|
||||||
if (nextChunk != null) {
|
if (nextChunk != null) {
|
||||||
val nextVisibilities = getVisibility(nextPosition) ?: return
|
val nextVisibilities = getVisibility(nextPosition) ?: return
|
||||||
@ -288,7 +290,7 @@ class WorldVisibilityGraph(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (directionZ <= 0 && (section?.occlusion?.isOccluded(inverted, Directions.NORTH) != true) && chunkPosition.y > chunkMin.y) {
|
if (directionZ <= 0 && (section?.occlusion?.isOccluded(inverted, Directions.NORTH) != true) && chunkPosition.y > chunkMin.y) {
|
||||||
val nextPosition = chunkPosition + Directions.NORTH
|
nextPosition.x = chunkPosition.x; nextPosition.y = chunkPosition.y - 1 // + NORTH
|
||||||
val nextChunk = chunk.neighbours[ChunkNeighbours.NORTH]
|
val nextChunk = chunk.neighbours[ChunkNeighbours.NORTH]
|
||||||
if (nextChunk != null) {
|
if (nextChunk != null) {
|
||||||
val nextVisibilities = getVisibility(nextPosition) ?: return
|
val nextVisibilities = getVisibility(nextPosition) ?: return
|
||||||
@ -300,7 +302,7 @@ class WorldVisibilityGraph(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (directionZ >= 0 && (section?.occlusion?.isOccluded(inverted, Directions.SOUTH) != true) && chunkPosition.y < chunkMax.y) {
|
if (directionZ >= 0 && (section?.occlusion?.isOccluded(inverted, Directions.SOUTH) != true) && chunkPosition.y < chunkMax.y) {
|
||||||
val nextPosition = chunkPosition + Directions.SOUTH
|
nextPosition.x = chunkPosition.x; nextPosition.y = chunkPosition.y + 1 // + SOUTH
|
||||||
val nextChunk = chunk.neighbours[ChunkNeighbours.SOUTH]
|
val nextChunk = chunk.neighbours[ChunkNeighbours.SOUTH]
|
||||||
if (nextChunk != null) {
|
if (nextChunk != null) {
|
||||||
val nextVisibilities = getVisibility(nextPosition) ?: return
|
val nextVisibilities = getVisibility(nextPosition) ?: return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user