From c5a7665ace904077ec35f9dae38dbf9df77cfb73 Mon Sep 17 00:00:00 2001 From: Martin Jakobsson Date: Thu, 11 Jul 2024 20:03:12 +0200 Subject: [PATCH] Add experimental scala linter --- build.sbt | 8 +++++--- common/src/main/scala/hexacraft/util/UniquePQ.scala | 2 +- common/src/main/scala/hexacraft/util/segments.scala | 10 +++++----- .../main/scala/hexacraft/world/gen/tree/parts.scala | 2 +- game/src/main/scala/hexacraft/world/loader.scala | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/build.sbt b/build.sbt index aa5a6ee8..ddb50a08 100644 --- a/build.sbt +++ b/build.sbt @@ -4,7 +4,7 @@ import scala.util.Properties.isMac ThisBuild / organization := "com.martomate" ThisBuild / version := "0.14" -ThisBuild / scalaVersion := "3.4.0" +ThisBuild / scalaVersion := "3.4.2" ThisBuild / publishArtifact := false ThisBuild / logBuffered := false ThisBuild / fork := true @@ -14,7 +14,8 @@ val commonSettings: scala.Seq[Def.Setting[?]] = Defaults.coreDefaultSettings ++ module.organization + "." + module.name + "-" + module.revision + "." + artifact.extension }, scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature"), - javacOptions ++= Seq("-release", "11") + javacOptions ++= Seq("-release", "11"), + libraryDependencies += "org.scala-lang" %% "scala2-library-tasty-experimental" % scalaVersion.value ) lazy val hexacraft = project @@ -99,5 +100,6 @@ lazy val game = project ), packJarNameConvention := "full", packGenerateMakefile := false, - packArchiveExcludes := Seq("VERSION", "bin/hexacraft-mac.bat") + packArchiveExcludes := Seq("VERSION", "bin/hexacraft-mac.bat"), + packExcludeJars := Seq(".*scala2-library-tasty.*\\.jar") ) diff --git a/common/src/main/scala/hexacraft/util/UniquePQ.scala b/common/src/main/scala/hexacraft/util/UniquePQ.scala index 355d7236..01ef8969 100644 --- a/common/src/main/scala/hexacraft/util/UniquePQ.scala +++ b/common/src/main/scala/hexacraft/util/UniquePQ.scala @@ -6,7 +6,7 @@ import scala.collection.mutable.ArrayBuffer class UniquePQ[S](func: S => Double, ord: Ordering[Double]) { // PQ with fast lookup and resorting private type DS = (Double, S) - private val pq: mutable.PriorityQueue[DS] = mutable.PriorityQueue.empty(ord.on(_._1)) + private val pq: mutable.PriorityQueue[DS] = mutable.PriorityQueue.empty(using ord.on(_._1)) private val set: mutable.Set[S] = mutable.HashSet.empty def enqueue(elem: S): Unit = { diff --git a/common/src/main/scala/hexacraft/util/segments.scala b/common/src/main/scala/hexacraft/util/segments.scala index 6fb63076..efa8e4a5 100644 --- a/common/src/main/scala/hexacraft/util/segments.scala +++ b/common/src/main/scala/hexacraft/util/segments.scala @@ -17,14 +17,14 @@ case class Segment(start: Int, length: Int) { class SegmentSet extends mutable.Iterable[Segment] { - private val segments: mutable.TreeSet[Segment] = mutable.TreeSet.empty { (s1, s2) => + private val segments: mutable.TreeSet[Segment] = mutable.TreeSet.empty(using { (s1, s2) => if (s1.overlaps(s2)) 0 else s1.start - s2.start - } - private val segmentsContain: mutable.TreeMap[Segment, Segment] = mutable.TreeMap.empty { (s1, s2) => + }) + private val segmentsContain: mutable.TreeMap[Segment, Segment] = mutable.TreeMap.empty(using { (s1, s2) => if (s2.contains(s1)) 0 else s1.start - s2.start - } + }) private var _totalLength = 0 protected def _add(seg: Segment): Unit = { @@ -121,7 +121,7 @@ class KeyedSegmentSet[T] extends SegmentSet { } } - private val invMap: mutable.TreeMap[Segment, T] = mutable.TreeMap.empty(invMapOrder) + private val invMap: mutable.TreeMap[Segment, T] = mutable.TreeMap.empty(using invMapOrder) private val segmentsPerKey: mutable.HashMap[T, Int] = mutable.HashMap.empty override protected def _add(seg: Segment): Unit = { diff --git a/game/src/main/scala/hexacraft/world/gen/tree/parts.scala b/game/src/main/scala/hexacraft/world/gen/tree/parts.scala index 1c572e2b..35393cb0 100644 --- a/game/src/main/scala/hexacraft/world/gen/tree/parts.scala +++ b/game/src/main/scala/hexacraft/world/gen/tree/parts.scala @@ -70,7 +70,7 @@ case class BlobGenerator( override def generate(): Seq[Offset] = { val seen = mutable.HashSet.empty[Offset] val result = mutable.HashSet.empty[Offset] - val edge = mutable.PriorityQueue.empty[(Float, Offset)](Ordering.by(-_._1)) + val edge = mutable.PriorityQueue.empty[(Float, Offset)](using Ordering.by(-_._1)) var time = 0.0f val start = Offset(0, 0, 0) diff --git a/game/src/main/scala/hexacraft/world/loader.scala b/game/src/main/scala/hexacraft/world/loader.scala index 8c17b3db..425b6988 100644 --- a/game/src/main/scala/hexacraft/world/loader.scala +++ b/game/src/main/scala/hexacraft/world/loader.scala @@ -18,8 +18,8 @@ class ChunkLoadingPrioritizer(maxDist: Double)(using CylinderSize) { private val furthestFirst: Ordering[ChunkRelWorld] = Ordering.by(c => distSq(origin, c)) private val closestFirst: Ordering[ChunkRelWorld] = Ordering.by(c => -distSq(origin, c)) - private val addableChunks: mutable.PriorityQueue[ChunkRelWorld] = mutable.PriorityQueue.empty(closestFirst) - private val removableChunks: mutable.PriorityQueue[ChunkRelWorld] = mutable.PriorityQueue.empty(furthestFirst) + private val addableChunks: mutable.PriorityQueue[ChunkRelWorld] = mutable.PriorityQueue.empty(using closestFirst) + private val removableChunks: mutable.PriorityQueue[ChunkRelWorld] = mutable.PriorityQueue.empty(using furthestFirst) private val maxDistSqInBlocks: Double = (maxDist * 16) * (maxDist * 16)