• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Martomate / Hexacraft / 4212765122

pending completion
4212765122

push

github

Martin Jakobsson
Moved block specs from json files to code

51 of 51 new or added lines in 9 files covered. (100.0%)

1609 of 4743 relevant lines covered (33.92%)

0.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.21
/src/main/scala/com/martomate/hexacraft/world/loader/ChunkLoadingPrioritizerSimple.scala
1
package com.martomate.hexacraft.world.loader
2

3
import com.martomate.hexacraft.util.CylinderSize
4
import com.martomate.hexacraft.world.coord.CoordUtils
5
import com.martomate.hexacraft.world.coord.integer.ChunkRelWorld
6

7
import scala.collection.mutable
8

9
class ChunkLoadingPrioritizerSimple(
10
    origin: PosAndDir,
11
    distSqFunc: (PosAndDir, ChunkRelWorld) => Double,
12
    maxDist: Double
13
)(implicit cylSize: CylinderSize)
14
    extends ChunkLoadingPrioritizer {
15

1✔
16
  private val chunksLoaded: mutable.Set[ChunkRelWorld] = new mutable.HashSet
1✔
17
  private val chunksLoadingEdge: mutable.Set[ChunkRelWorld] = new mutable.HashSet
18

19
  private val maxDistSqInBlocks: Double = (maxDist * 16) * (maxDist * 16)
20

1✔
21
  override def +=(chunk: ChunkRelWorld): Unit = {
1✔
22
    chunksLoaded += chunk
1✔
23
    chunksLoadingEdge += chunk
1✔
24
    removeNonEdgeNeighbors(chunk)
25
  }
26

1✔
27
  private def removeNonEdgeNeighbors(chunk: ChunkRelWorld): Unit = {
1✔
28
    chunk.neighbors.foreach(neigh => removeIfNotEdge(neigh))
29
  }
30

1✔
31
  private def removeIfNotEdge(chunk: ChunkRelWorld): Unit = {
1✔
32
    if (chunk.neighbors.forall(neigh => chunksLoaded(neigh))) chunksLoadingEdge -= chunk
33
  }
34

1✔
35
  override def -=(chunk: ChunkRelWorld): Unit = {
1✔
36
    chunksLoaded -= chunk
1✔
37
    chunksLoadingEdge -= chunk
1✔
38
    addNewEdgeNeighbors(chunk)
39
  }
40

1✔
41
  private def addNewEdgeNeighbors(chunk: ChunkRelWorld): Unit = {
×
42
    chunk.neighbors.foreach(n => if (chunksLoaded(n)) chunksLoadingEdge += n)
43
  }
44

×
45
  override def tick(): Unit = ()
46

1✔
47
  override def nextAddableChunk: Option[ChunkRelWorld] = {
1✔
48
    if (chunksLoadingEdge.isEmpty) {
1✔
49
      val coords = CoordUtils.approximateChunkCoords(origin.pos)
×
50
      if (!chunksLoaded(coords)) Some(coords) else None
1✔
51
    } else {
1✔
52
      chunksLoadingEdge.iterator
1✔
53
        .map(
1✔
54
          _.neighbors.find(coords => !chunksLoaded(coords) && distSqFunc(origin, coords) <= maxDistSqInBlocks)
55
        )
1✔
56
        .find(_.isDefined)
57
        .flatten
58
    }
59
  }
60

1✔
61
  override def nextRemovableChunk: Option[ChunkRelWorld] =
1✔
62
    chunksLoadingEdge.find(coords => distSqFunc(origin, coords) > maxDistSqInBlocks)
63

×
64
  override def unload(): Unit = ()
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc