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

Martomate / Hexacraft / 7351367576

28 Dec 2023 06:50PM UTC coverage: 51.185% (-0.1%) from 51.312%
7351367576

push

github

Martomate
Refactor: Made Chunk not know if it has been saved to file

9 of 12 new or added lines in 2 files covered. (75.0%)

110 existing lines in 32 files now uncovered.

2829 of 5527 relevant lines covered (51.19%)

0.51 hits per line

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

78.79
/game/src/main/scala/hexacraft/world/gen/tree/parts.scala
1
package hexacraft.world.gen.tree
2

3
import hexacraft.world.block.Block
4
import hexacraft.world.coord.{NeighborOffsets, Offset}
5

6
import scala.collection.mutable
7
import scala.util.Random
8

9
trait PartGenerator {
10
  protected type BlockSpec = (Offset, Block)
11

1✔
12
  final def generate(x: Int, y: Int, z: Int, block: Block): Seq[BlockSpec] =
1✔
13
    generate(Offset(x, y, z), block)
14

1✔
15
  final def generate(center: Offset, block: Block): Seq[BlockSpec] =
1✔
16
    generate().map(center + _ -> block)
17

18
  def generate(): Seq[Offset]
19
}
20

21
case class PillarGenerator(len: Int) extends PartGenerator {
1✔
22
  override def generate(): Seq[Offset] = {
1✔
23
    for (yy <- 0 until len) yield Offset(0, yy, 0)
24
  }
25
}
26

27
case class PlatformGenerator(r: Int) extends PartGenerator {
1✔
28
  override def generate(): Seq[Offset] = {
1✔
29
    for {
×
30
      dx <- -r to r
1✔
31
      dz <- -r to r
×
32
      if math.abs(dx + dz) <= r
33
    } yield Offset(dx, 0, dz)
34
  }
35
}
36

37
case class ImperfectPlatformGenerator(rand: Random, r: Int, imperfection: Float) extends PartGenerator {
×
38
  override def generate(): Seq[Offset] = {
×
39
    val offsets = PlatformGenerator(r).generate()
40

×
41
    offsets.filter(l => l.manhattanDistance < r || rand.nextFloat() > imperfection)
42
  }
43
}
44

45
/** A blob is randomly grown from the origin into a double cone with adjustable cone heights. The
46
  * double cone shape comes from the use of manhattan distances. This might be changed in the
47
  * future. With sufficient irregularity the effect can be greatly reduced.
48
  * @param numBlocks
49
  *   the total number of blocks the blob will consist of
50
  * @param irregularity
51
  *   how much random the growth speed should be a each simulation step
52
  * @param flatnessBottom
53
  *   how much flatter the bottom of the blob should be. 1.0 gives a spherical blob.
54
  * @param flatnessTop
55
  *   like `flatnessBottom` but for the top
56
  */
57
case class BlobGenerator(
58
    rand: Random,
59
    numBlocks: Int,
60
    irregularity: Float,
61
    flatnessBottom: Float,
62
    flatnessTop: Float
63
) extends PartGenerator {
1✔
64
  override def generate(): Seq[Offset] = {
1✔
65
    val seen = mutable.HashSet.empty[Offset]
1✔
UNCOV
66
    val result = mutable.HashSet.empty[Offset]
×
67
    val edge = mutable.PriorityQueue.empty[(Float, Offset)](Ordering.by(-_._1))
68
    var time = 0.0f
69

70
    val start = Offset(0, 0, 0)
1✔
71
    seen += start
1✔
72
    edge += time -> start
73

×
74
    for (_ <- 1 to numBlocks) {
1✔
75
      val top = edge.dequeue()
1✔
76
      time = top._1
1✔
77
      val here = top._2
1✔
78
      result += here
79

1✔
80
      for (off <- NeighborOffsets.all) {
1✔
81
        val pos = here + off
1✔
82
        if (!seen(pos)) {
1✔
83
          seen += pos
84

85
          val growthResistance =
1✔
86
            if (off.dy > 0) flatnessTop else if (off.dy < 0) flatnessBottom else 1.0f
1✔
87
          val newTime = time + (1.0f + (rand.nextFloat() * 2 - 1) * irregularity) * growthResistance
1✔
88
          edge += newTime -> pos
89
        }
90
      }
91
    }
1✔
92
    result.toSeq
93
  }
94
}
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