TreeSet is faster than ObjectRBTreeSet for some reason
This commit is contained in:
parent
7a5a979169
commit
7ca0ba1ce5
@ -5,7 +5,6 @@ import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.github.benmanes.caffeine.cache.Scheduler
|
||||
import com.mojang.serialization.Codec
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap
|
||||
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList
|
||||
import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet
|
||||
@ -31,6 +30,7 @@ import ru.dbotthepony.mc.otm.worldgen.placement.EnhancedPlacement
|
||||
import java.io.DataOutputStream
|
||||
import java.time.Duration
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.math.sqrt
|
||||
|
||||
object EnhancedPlacedFeature : Feature<EnhancedPlacedFeature.Config>(
|
||||
@ -58,12 +58,12 @@ object EnhancedPlacedFeature : Feature<EnhancedPlacedFeature.Config>(
|
||||
val root: EnhancedPlacement,
|
||||
) : FeatureConfiguration {
|
||||
private class GeneratedChunk : EnhancedPlacementContext.Placer {
|
||||
private data class Placement(val context: EnhancedPlacementContext, val positions: ObjectRBTreeSet<PlacementPos>, val feature: EnhancedFeature.Configured<*, *>)
|
||||
private data class Placement(val context: EnhancedPlacementContext, val positions: TreeSet<PlacementPos>, val feature: EnhancedFeature.Configured<*, *>)
|
||||
private val placed = LinkedList<Placement>()
|
||||
|
||||
override fun place(context: EnhancedPlacementContext, positions: List<PlacementPos>, feature: EnhancedFeature.Configured<*, *>) {
|
||||
if (positions.isNotEmpty()) {
|
||||
placed.add(Placement(context, ObjectRBTreeSet<PlacementPos>().also { it.addAll(positions) }, feature))
|
||||
placed.add(Placement(context, TreeSet<PlacementPos>().also { it.addAll(positions) }, feature))
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,12 +72,12 @@ object EnhancedPlacedFeature : Feature<EnhancedPlacedFeature.Config>(
|
||||
val pos = ChunkPos(context.origin())
|
||||
|
||||
for ((eContext, positions, feature) in placed) {
|
||||
val itr = positions.iterator(PlacementPos(BlockPos(pos.minBlockX, Int.MIN_VALUE, pos.minBlockZ), emptyVariableMap))
|
||||
val itr = positions.tailSet(PlacementPos(BlockPos(pos.minBlockX, Int.MIN_VALUE, pos.minBlockZ), emptyVariableMap)).iterator()
|
||||
|
||||
if (!itr.hasNext())
|
||||
continue
|
||||
|
||||
val result = ObjectRBTreeSet<PlacementPos>()
|
||||
val result = TreeSet<PlacementPos>()
|
||||
|
||||
for (placementPos in itr) {
|
||||
if (SectionPos.blockToSectionCoord(placementPos.pos.x) != pos.x || SectionPos.blockToSectionCoord(placementPos.pos.z) != pos.z)
|
||||
@ -155,14 +155,21 @@ object EnhancedPlacedFeature : Feature<EnhancedPlacedFeature.Config>(
|
||||
// between threads which lookup cache while it is being populated on neighbouring chunks
|
||||
withIndex.shuffle(THREAD_LOCAL_RANDOM)
|
||||
|
||||
val instances = Int2ObjectRBTreeMap<GeneratedChunk>()
|
||||
data class P(val i: Int, val v: GeneratedChunk) : Comparable<P> {
|
||||
override fun compareTo(other: P): Int {
|
||||
return i.compareTo(other.i)
|
||||
}
|
||||
}
|
||||
|
||||
val instances = ArrayList<P>()
|
||||
instances.sort()
|
||||
|
||||
withIndex.forEach { (i, it) ->
|
||||
instances.put(i, cache.get(it) { evaluate(context, it) })
|
||||
instances.add(P(i, cache.get(it) { evaluate(context, it) }))
|
||||
}
|
||||
|
||||
var any = false
|
||||
instances.values.forEach { any = it.place(context) }
|
||||
instances.forEach { any = it.v.place(context) }
|
||||
return any
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package ru.dbotthepony.mc.otm.worldgen.placement
|
||||
|
||||
import com.mojang.serialization.MapCodec
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||
import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.util.RandomSource
|
||||
import net.minecraft.util.valueproviders.FloatProvider
|
||||
@ -14,6 +13,7 @@ import ru.dbotthepony.mc.otm.core.collect.Vec3iHashStrategy
|
||||
import ru.dbotthepony.mc.otm.registry.data.MPlacementModifiers
|
||||
import ru.dbotthepony.mc.otm.worldgen.EnhancedPlacementContext
|
||||
import ru.dbotthepony.mc.otm.worldgen.PlacementPos
|
||||
import java.util.*
|
||||
import java.util.stream.Stream
|
||||
|
||||
/**
|
||||
@ -61,9 +61,9 @@ data class EllipsoidPlacement(
|
||||
require(yLength.minValue >= 1f) { "Bad ellipsoid y minimal size: $yLength" }
|
||||
}
|
||||
|
||||
private fun evaluate(random: RandomSource, position: BlockPos): ObjectRBTreeSet<BlockPos> {
|
||||
private fun evaluate(random: RandomSource, position: BlockPos): Set<BlockPos> {
|
||||
val count = count.sample(random)
|
||||
val results = ObjectRBTreeSet<BlockPos>(Vec3iHashStrategy)
|
||||
val results = TreeSet<BlockPos>(Vec3iHashStrategy)
|
||||
|
||||
if (count <= 0)
|
||||
return results
|
||||
|
Loading…
Reference in New Issue
Block a user