From 8a03d326f4ca8a0b20e4266ae2cfd5e118434f53 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 2 Dec 2022 15:00:31 +0700 Subject: [PATCH] Use hash table for chunk map --- .../kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt | 8 ++++++++ src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt index d22ac010..10ac53c5 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt @@ -117,9 +117,17 @@ class ChunkPos(val x: Int, val y: Int) : Comparable { return ChunkPos(x, y) } + fun toLong(): Long { + return toLong(x, y) + } + companion object { val ZERO = ChunkPos(0, 0) + fun toLong(x: Int, y: Int): Long { + return x.toLong() or (y.toLong() shl 32) + } + fun fromTilePosition(input: IStruct2i): ChunkPos { val (x, y) = input return ChunkPos(tileToChunkComponent(x), tileToChunkComponent(y)) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt index 8331a708..b0e6acf6 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList import it.unimi.dsi.fastutil.objects.Object2DoubleAVLTreeMap import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap import it.unimi.dsi.fastutil.objects.Object2ObjectFunction +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import ru.dbotthepony.kbox2d.api.ContactImpulse import ru.dbotthepony.kbox2d.api.IContactFilter import ru.dbotthepony.kbox2d.api.IContactListener @@ -129,11 +130,7 @@ abstract class World, ChunkType : Chunk cmp@{ a, b -> - return@cmp a.compareTo(b) - } - - //protected val chunkMap = HashMap() + protected val chunkMap = Object2ObjectOpenHashMap() /** * Является ли мир "сферическим"