Skip to content

Commit

Permalink
Refactor: Moved client specific code to client module
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed Jul 12, 2024
1 parent a81a00f commit 242b8aa
Show file tree
Hide file tree
Showing 68 changed files with 25 additions and 40 deletions.
12 changes: 3 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ lazy val system = project

lazy val game = project
.in(file("game"))
.dependsOn(common, nbt, window, audio, fs, gpu, system)
.dependsOn(common, nbt, window, fs)
.settings(commonSettings*)
.settings(
libraryDependencies ++= LwjglSystem ++ Seq(Joml, ZeroMQ) ++ Seq(MUnit, Mockito)
)

lazy val client = project
.in(file("client"))
.dependsOn(common, game)
.dependsOn(game, audio, gpu)
.settings(commonSettings*)
.settings(
libraryDependencies ++= Seq(Joml, ZeroMQ) :+ MUnit
)

lazy val server = project
.in(file("server"))
.dependsOn(common, game % "compile->compile;test->test")
.dependsOn(game % "compile->compile;test->test")
.settings(commonSettings*)
.settings(
libraryDependencies ++= Seq(Joml, ZeroMQ) :+ MUnit
Expand All @@ -103,15 +103,9 @@ lazy val server = project
lazy val main = project
.in(file("main"))
.dependsOn(
common,
game % "compile->compile;test->test",
client % "compile->compile;test->test",
server,
nbt,
window,
audio,
fs,
gpu,
system
)
.settings(commonSettings*)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package hexacraft.client

import hexacraft.client.render.BlockRenderer
import hexacraft.gui.comp.GUITransformation
import hexacraft.renderer.*
import hexacraft.shaders.GuiBlockShader
import hexacraft.world.CameraProjection
import hexacraft.world.block.Block
import hexacraft.world.render.BlockRenderer

import org.joml.{Matrix4f, Vector2f}

Expand Down
8 changes: 5 additions & 3 deletions client/src/main/scala/hexacraft/client/WorldRenderer.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package hexacraft.client

import hexacraft.client.ClientWorld.WorldTickResult
import hexacraft.client.render.*
import hexacraft.infra.gpu.OpenGL
import hexacraft.renderer.{GpuState, TextureArray, VAO}
import hexacraft.renderer.{GpuState, TextureArray, TextureSingle, VAO}
import hexacraft.shaders.*
import hexacraft.util.TickableTimer
import hexacraft.world.{BlocksInWorld, Camera, CylinderSize}
import hexacraft.world.block.BlockState
import hexacraft.world.chunk.Chunk
import hexacraft.world.coord.{BlockRelWorld, ChunkRelWorld}
import hexacraft.world.entity.{Entity, EntityModel}
import hexacraft.world.render.*

import org.joml.{Vector2ic, Vector3f}
import org.lwjgl.BufferUtils
Expand Down Expand Up @@ -321,12 +321,14 @@ class WorldRenderer(

entityDataList ++= EntityRenderDataFactory.getEntityRenderData(players, side, world)

for (texture, partLists) <- entityDataList.groupBy(_._1.texture) do {
for (textureName, partLists) <- entityDataList.groupBy(_._1.textureName) do {
val data = partLists.flatMap(_._2)

entityRenderers(side).setInstanceData(data.size): buf =>
data.foreach(_.fill(buf))

val texture = TextureSingle.getTexture("textures/entities/" + textureName)

texture.bind()
sh.setTextureSize(texture.width)
entityRenderers(side).render()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.util.{DenseKeyedSegmentStack, Segment, SegmentSet}
import hexacraft.world.coord.ChunkRelWorld
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.infra.gpu.OpenGL
import hexacraft.renderer.{GpuState, InstancedRenderer, VAO}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.shaders.BlockShader.BlockVertexData
import hexacraft.shaders.BlockShader
import hexacraft.shaders.BlockShader.BlockVertexData
import hexacraft.world.{BlocksInWorld, ChunkCache, CylinderSize}
import hexacraft.world.block.{Block, BlockState}
import hexacraft.world.chunk.LocalBlockState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.world.{BlocksInWorld, CylinderSize}
import hexacraft.world.chunk.LocalBlockState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.util.UniquePQ
import hexacraft.world.{Camera, CylinderSize, PosAndDir}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.shaders.EntityShader
import hexacraft.world.{BlocksInWorld, ChunkCache, CylinderSize}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.infra.gpu.OpenGL
import hexacraft.renderer.{FrameBuffer, TextureSingle}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.infra.gpu.OpenGL
import hexacraft.renderer.{GpuState, Renderer, VAO, VBO}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.world.CylinderSize
import hexacraft.world.coord.ChunkRelWorld
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hexacraft.world.render
package hexacraft.client.render

import hexacraft.util.Segment

Expand Down
3 changes: 1 addition & 2 deletions game/src/main/scala/hexacraft/world/entity/models.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package hexacraft.world.entity

import hexacraft.renderer.TextureSingle
import hexacraft.world.HexBox
import hexacraft.world.coord.CylCoords

import org.joml.{Matrix4f, Vector3f}

trait EntityModel {
def parts: Seq[EntityPart]
def texture: TextureSingle
def textureName: String
def tick(walking: Boolean): Unit
}

Expand Down
5 changes: 0 additions & 5 deletions game/src/main/scala/hexacraft/world/entity/player.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package hexacraft.world.entity

import hexacraft.renderer.TextureSingle
import hexacraft.world.{CylinderSize, HexBox}
import hexacraft.world.coord.BlockCoords

Expand All @@ -23,10 +22,6 @@ class PlayerEntityModel(
override def tick(walking: Boolean): Unit = {
animation.tick(walking)
}

override def texture: TextureSingle = {
TextureSingle.getTexture("textures/entities/" + textureName)
}
}

class PlayerAnimation(model: PlayerEntityModel) {
Expand Down
7 changes: 1 addition & 6 deletions game/src/main/scala/hexacraft/world/entity/sheep.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package hexacraft.world.entity

import hexacraft.renderer.TextureSingle
import hexacraft.world.{BlocksInWorld, CollisionDetector, CylinderSize, HexBox}
import hexacraft.world.{CylinderSize, HexBox}
import hexacraft.world.coord.BlockCoords

import org.joml.Vector3f
Expand All @@ -22,10 +21,6 @@ class SheepEntityModel(
override def tick(walking: Boolean): Unit = {
animation.tick(walking)
}

override def texture: TextureSingle = {
TextureSingle.getTexture("textures/entities/" + textureName)
}
}

class SheepAnimation(model: SheepEntityModel) {
Expand Down
6 changes: 3 additions & 3 deletions main/src/test/scala/hexacraft/RootArchTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RootArchTest extends FunSuite {
import ArchUnitHelpers.*

private val allClasses = new ClassFileImporter()
.importPackages("hexacraft..")
.importPackages("hexacraft..", "com.martomate..")
.ignoreScalaTests()
.ignoreMTests()

Expand All @@ -22,7 +22,7 @@ class RootArchTest extends FunSuite {
}

test("Nbt library should only be used in Nbt module") {
Packages("com.flowpowered.nbt..").assertOnlyUsedIn() // not used in any package, only in nbt module
Packages("com.flowpowered.nbt..").assertOnlyUsedIn("com.martomate.nbt")
}

test("Glfw library should only be used in Glfw wrapper") {
Expand Down Expand Up @@ -125,7 +125,7 @@ class RootArchTest extends FunSuite {
.where(Shaders, _.mayOnlyAccessLayers(Infra, Renderer, World, LWJGL, JOML))
.where(Text, _.mayOnlyAccessLayers(Infra, Renderer, Shaders, JOML))
.where(Util, _.mayOnlyAccessLayers(JOML, Nbt))
.where(World, _.mayOnlyAccessLayers(Math, Infra, Renderer, Shaders, Physics, Util, JOML, LWJGL, Nbt))
.where(World, _.mayOnlyAccessLayers(Infra, Math, Physics, Util, JOML, Nbt))
.check(allClasses)
}

Expand Down

0 comments on commit 242b8aa

Please sign in to comment.