Skip to content

Commit

Permalink
Refactor: Fixed most compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed Apr 8, 2024
1 parent 9bb3247 commit 794c670
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hexacraft.math.noise
import java.util.Random

class NoiseGenerator3D(random: Random, val numOctaves: Int, val scale: Double) {
private[this] val noiseGens = Seq.fill(numOctaves)(PerlinNoise3D(random))
private val noiseGens = Seq.fill(numOctaves)(PerlinNoise3D(random))

def genNoise(x: Double, y: Double, z: Double): Double = {
var amp = 1d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hexacraft.math.noise
import java.util.Random

class NoiseGenerator4D(random: Random, val numOctaves: Int, val scale: Double) {
private[this] val noiseGens = Seq.fill(numOctaves)(PerlinNoise4D(random))
private val noiseGens = Seq.fill(numOctaves)(PerlinNoise4D(random))

def genNoise(x: Double, y: Double, z: Double, w: Double): Double = {
var amp = 1d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.Random

// Improved Perlin Noise: http://mrl.nyu.edu/~perlin/noise/
class PerlinNoise3D(random: Random) { // Apparently SimplexNoise exists in joml
private[this] val perm = {
private val perm = {
val arr = (0 until 256).toArray
shuffleArray(arr, random)
arr ++ arr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PerlinNoise4D(random: Random) { // Apparently SimplexNoise exists in joml
)
// format: on

private[this] val perm = {
private val perm = {
val arr = (0 until 256).toArray
shuffleArray(arr, random)
arr ++ arr
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/hexacraft/util/SmartArray.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hexacraft.util
import scala.collection.mutable

class SmartArray[@specialized(Byte) T](size: Int, default: T, builder: Int => Array[T]) extends mutable.IndexedSeq[T] {
private var arr: Array[T] = _
private var arr: Array[T] = null.asInstanceOf[Array[T]]

def apply(idx: Int): T = {
if arr != null then {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/hexacraft/util/UniquePQ.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class UniquePQ[S](func: S => Double, ord: Ordering[Double]) { // PQ with fast lo
}
pq.clear()
val seq = buffer.toSeq
pq.enqueue(seq: _*)
pq.enqueue(seq*)
buffer.foreach(set += _._2)
}
}
6 changes: 3 additions & 3 deletions game/src/main/scala/hexacraft/game/net.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class GameClient(serverIp: String, serverPort: Int) {
private var _shouldLogout = false
def shouldLogout: Boolean = _shouldLogout

private var monitoringThread: Thread = _
private var monitoringThread: Thread = null.asInstanceOf[Thread]

def runMonitoring(): Unit = {
if monitoringThread != null then {
Expand Down Expand Up @@ -157,7 +157,7 @@ class GameClient(serverIp: String, serverPort: Int) {
}

class GameServer(worldProvider: WorldProvider, game: GameScene) {
private var serverThread: Thread = _
private var serverThread: Thread = null.asInstanceOf[Thread]

def run(): Unit = {
if serverThread != null then {
Expand Down Expand Up @@ -239,7 +239,7 @@ class GameServer(worldProvider: WorldProvider, game: GameScene) {
}

class NetworkHandler(val isHosting: Boolean, isOnline: Boolean, val worldProvider: WorldProvider, client: GameClient) {
private var server: GameServer = _
private var server: GameServer = null.asInstanceOf[GameServer]

def runServer(game: GameScene): Unit = if isOnline then {
server = GameServer(worldProvider, game)
Expand Down
4 changes: 2 additions & 2 deletions game/src/main/scala/hexacraft/gui/comp/ScrollPane.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class ScrollPane(
private var xOffset: Float = 0
private var yOffset: Float = 0

private val components: ArrayBuffer[Component with Boundable] = ArrayBuffer.empty
private val components: ArrayBuffer[Component & Boundable] = ArrayBuffer.empty

def addComponent(comp: Component with Boundable): Unit = components.append(comp)
def addComponent(comp: Component & Boundable): Unit = components.append(comp)

override def render(transformation: GUITransformation)(using context: RenderContext): Unit = {
Component.drawRect(
Expand Down
82 changes: 50 additions & 32 deletions game/src/main/scala/hexacraft/main/MainWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class MainWindow(
private val mouse: GameMouse = new GameMouse
private val keyboard: GameKeyboard = new GameKeyboard.GlfwKeyboard(window)

private var scene: Scene = _
private var nextScene: Scene = _
private var scene: Option[Scene] = None
private var nextScene: Option[Scene] = None

override def setCursorMode(cursorMode: CursorMode): Unit = {
window.setCursorMode(cursorMode)
Expand All @@ -64,9 +64,9 @@ class MainWindow(
val delta = ((currentTime - prevTime) * 1e-9 * 60).toInt
val realPrevTime = currentTime

if nextScene != null then {
setScene(nextScene)
nextScene = null
if nextScene.isDefined then {
setScene(nextScene.get)
nextScene = None
}

for _ <- 0 until delta do {
Expand Down Expand Up @@ -125,43 +125,57 @@ class MainWindow(
}
}

scene.handleEvent(Event.KeyEvent(key, scancode, action, mods))
if scene.isDefined then {
scene.get.handleEvent(Event.KeyEvent(key, scancode, action, mods))
}

case CallbackEvent.CharTyped(_, character) =>
scene.handleEvent(Event.CharEvent(character))
if scene.isDefined then {
scene.get.handleEvent(Event.CharEvent(character))
}

case CallbackEvent.MouseClicked(_, button, action, mods) =>
val normalizedMousePos = mouse.currentPos.heightNormalizedPos(windowSize.logicalSize)
val mousePos = (normalizedMousePos.x, normalizedMousePos.y)
scene.handleEvent(Event.MouseClickEvent(button, action, mods, mousePos))
if scene.isDefined then {
scene.get.handleEvent(Event.MouseClickEvent(button, action, mods, mousePos))
}

case CallbackEvent.MouseScrolled(_, xOff, yOff) =>
val normalizedMousePos = mouse.currentPos.heightNormalizedPos(windowSize.logicalSize)
val mousePos = (normalizedMousePos.x, normalizedMousePos.y)
scene.handleEvent(Event.ScrollEvent(xOff.toFloat, yOff.toFloat, mousePos))
if scene.isDefined then {
scene.get.handleEvent(Event.ScrollEvent(xOff.toFloat, yOff.toFloat, mousePos))
}

case CallbackEvent.WindowResized(_, w, h) =>
if w > 0 && h > 0
then {
if w != _windowSize.logicalSize.x || h != _windowSize.logicalSize.y
then {
scene.windowResized(w, h)
if scene.isDefined then {
scene.get.windowResized(w, h)
}
}

_windowSize = WindowSize(Vector2i(w, h), _windowSize.physicalSize)
resetMousePos()
}

case CallbackEvent.WindowFocusChanged(_, focused) =>
scene.windowFocusChanged(focused)
if scene.isDefined then {
scene.get.windowFocusChanged(focused)
}

case CallbackEvent.FrameBufferResized(_, w, h) =>
if w > 0 && h > 0
then {
if w != _windowSize.physicalSize.x || h != _windowSize.physicalSize.y
then {
OpenGL.glViewport(0, 0, w, h)
scene.frameBufferResized(w, h)
if scene.isDefined then {
scene.get.frameBufferResized(w, h)
}
}

_windowSize = WindowSize(_windowSize.logicalSize, Vector2i(w, h))
Expand All @@ -179,39 +193,43 @@ class MainWindow(
}

private def render(): Unit = {
scene.render(GUITransformation(0, 0))(using
RenderContext(
this._windowSize.logicalAspectRatio,
this._windowSize.physicalSize,
mouse.currentPos.heightNormalizedPos(this.windowSize.logicalSize)
if scene.isDefined then {
scene.get.render(GUITransformation(0, 0))(using
RenderContext(
this._windowSize.logicalAspectRatio,
this._windowSize.physicalSize,
mouse.currentPos.heightNormalizedPos(this.windowSize.logicalSize)
)
)
)
}
VAO.unbindVAO()
}

private def tick(): Unit = {
val (cx, cy) = window.cursorPosition
mouse.moveTo(cx, _windowSize.logicalSize.y - cy)

scene.tick(
TickContext(
windowSize = _windowSize,
currentMousePosition = mouse.currentPos,
previousMousePosition = mouse.previousPos
if scene.isDefined then {
scene.get.tick(
TickContext(
windowSize = _windowSize,
currentMousePosition = mouse.currentPos,
previousMousePosition = mouse.previousPos
)
)
)
}
}

private def setScene(newScene: Scene): Unit = {
if scene != null then {
scene.unload()
if scene.isDefined then {
scene.get.unload()
}
scene = newScene
scene = Some(newScene)
}

private def makeSceneRouter(): MainRouter = {
MainRouter(saveFolder, multiplayerEnabled, fs, this, keyboard, audioSystem):
case MainRouter.Event.SceneChanged(newScene) => nextScene = newScene
case MainRouter.Event.SceneChanged(newScene) => nextScene = Some(newScene)
case MainRouter.Event.QuitRequested => tryQuit()
}

Expand Down Expand Up @@ -297,11 +315,11 @@ class MainWindow(
}

private def destroy(): Unit = {
if scene != null then {
scene.unload()
if scene.isDefined then {
scene.get.unload()
}
if nextScene != null then {
nextScene.unload()
if nextScene.isDefined then {
nextScene.get.unload()
}

Resource.freeAllResources()
Expand Down
4 changes: 2 additions & 2 deletions game/src/main/scala/hexacraft/renderer/shader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.io.IOException
import scala.collection.mutable

object Shader {
private var activeShader: Shader = _
private var activeShader: Shader = null.asInstanceOf[Shader]

private val matrixBuffer = BufferUtils.createFloatBuffer(16)

Expand All @@ -36,7 +36,7 @@ class Shader private (config: ShaderConfig) extends Resource {
shaderID = new ShaderBuilder()
.setDefines(config.defines)
.loadAll(config.fileNames)
.bindAttribs(config.inputs: _*)
.bindAttribs(config.inputs*)
.attachAll()
.linkAndFinish()

Expand Down
4 changes: 2 additions & 2 deletions game/src/main/scala/hexacraft/renderer/texture.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import javax.imageio.ImageIO
object TextureSingle {
private val textures = collection.mutable.Map.empty[String, TextureSingle]

private var boundTexture: TextureSingle = _
private var boundTexture: TextureSingle = null.asInstanceOf[TextureSingle]

def unbind(): Unit = {
TextureSingle.boundTexture = null
Expand Down Expand Up @@ -94,7 +94,7 @@ class TextureSingle(val name: String) extends Resource {
object TextureArray {
private val textures = collection.mutable.Map.empty[String, TextureArray]

private var boundTextureArray: TextureArray = _
private var boundTextureArray: TextureArray = null.asInstanceOf[TextureArray]

def unbind(): Unit = {
TextureArray.boundTextureArray = null
Expand Down
4 changes: 2 additions & 2 deletions game/src/main/scala/hexacraft/renderer/vao.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.nio.ByteBuffer
import scala.collection.mutable.ArrayBuffer

object VAO {
private var boundVAO: VAO = _
private var boundVAO: VAO = null.asInstanceOf[VAO]

def unbindVAO(): Unit = {
boundVAO = null
Expand Down Expand Up @@ -92,7 +92,7 @@ class VAO(val id: OpenGL.VertexArrayId, val maxCount: Int, val vbos: Seq[VBO]) e
}

object VBO {
private var boundVBO: VBO = _
private var boundVBO: VBO = null.asInstanceOf[VBO]

def copy(from: VBO, to: VBO, fromOffset: Int, toOffset: Int, length: Int): Unit = {
import OpenGL.VertexBufferTarget.*
Expand Down
2 changes: 1 addition & 1 deletion game/src/main/scala/hexacraft/text/Text.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Text(
val centered: Boolean,
val hasShadow: Boolean
) {
private var textMeshVao: VAO = _
private var textMeshVao: VAO = null.asInstanceOf[VAO]
private var _vertexCount: Int = 0
private val _color: Vector3f = new Vector3f(0f, 0f, 0f)
private val _shadowColor: Vector3f = new Vector3f(0f, 0f, 0f)
Expand Down
2 changes: 1 addition & 1 deletion game/src/main/scala/hexacraft/world/ChunkCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.collection.mutable
class ChunkCache(world: BlocksInWorld) {
private val cache: mutable.LongMap[Chunk] = mutable.LongMap.empty
private var lastChunkCoords: Option[ChunkRelWorld] = None
private var lastChunk: Chunk = _
private var lastChunk: Chunk = null.asInstanceOf[Chunk]

def clearCache(): Unit = {
cache.clear()
Expand Down
12 changes: 5 additions & 7 deletions game/src/main/scala/hexacraft/world/camera.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hexacraft.world

import hexacraft.math.MathUtils
import hexacraft.world.coord.{BlockCoords, BlockRelWorld, CoordUtils, CylCoords}
import hexacraft.world.coord.{BlockRelWorld, CoordUtils, CylCoords}

import org.joml.{Matrix4f, Vector3d, Vector3f, Vector3fc}

Expand All @@ -10,8 +10,7 @@ class Camera(val proj: CameraProjection)(using worldSize: CylinderSize) {
def position: Vector3d = view.position
def rotation: Vector3f = view.rotation

var blockCoords: BlockRelWorld = _
var placeInBlock: BlockCoords.Offset = _
var blockCoords: BlockRelWorld = BlockRelWorld(0)

updateViewMatrix()
updateProjMatrix()
Expand Down Expand Up @@ -58,7 +57,6 @@ class Camera(val proj: CameraProjection)(using worldSize: CylinderSize) {
def updateCoords(): Unit = {
val temp = CoordUtils.getEnclosingBlock(CylCoords(position).toBlockCoords)
blockCoords = temp._1
placeInBlock = temp._2
}
}

Expand All @@ -74,9 +72,9 @@ class CameraProjection(var fov: Float, var aspect: Float, val near: Float, val f
}

object CameraView {
val unitX: Vector3fc = new Vector3f(1, 0, 0)
val unitY: Vector3fc = new Vector3f(0, 1, 0)
val unitZ: Vector3fc = new Vector3f(0, 0, 1)
private val unitX: Vector3fc = new Vector3f(1, 0, 0)
private val unitY: Vector3fc = new Vector3f(0, 1, 0)
private val unitZ: Vector3fc = new Vector3f(0, 0, 1)
}

class CameraView {
Expand Down
2 changes: 1 addition & 1 deletion game/src/main/scala/hexacraft/world/loader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object ChunkLoadingPrioritizer {
class ChunkLoadingPrioritizer(maxDist: Double)(using CylinderSize) {
private var origin: PosAndDir = PosAndDir(CylCoords(0, 0, 0))
private val edge = new ChunkLoadingEdge
edge.trackEvents(this.onChunkEdgeEvent _)
edge.trackEvents(e => this.onChunkEdgeEvent(e))

private val furthestFirst: Ordering[ChunkRelWorld] = Ordering.by(c => distSq(origin, c))
private val closestFirst: Ordering[ChunkRelWorld] = Ordering.by(c => -distSq(origin, c))
Expand Down
4 changes: 2 additions & 2 deletions game/src/test/scala/hexacraft/ArchUnitHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ object ArchUnitHelpers {
}

def layer(name: String, packageIdentifiers: String*): LayeredArchitecture = {
arch.layer(name).definedBy(packageIdentifiers: _*)
arch.layer(name).definedBy(packageIdentifiers*)
}

def optionalLayer(name: String, packageIdentifiers: String*): LayeredArchitecture = {
arch.optionalLayer(name).definedBy(packageIdentifiers: _*)
arch.optionalLayer(name).definedBy(packageIdentifiers*)
}

def where(name: String, check: LayerDependencyCheck): LayeredArchitecture = {
Expand Down
Loading

0 comments on commit 794c670

Please sign in to comment.