-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Basic ECS architecture for the entity system
- Loading branch information
Showing
8 changed files
with
152 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
game/src/main/scala/hexacraft/world/entity/components.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package hexacraft.world.entity | ||
|
||
import hexacraft.world.{CylinderSize, HexBox} | ||
import hexacraft.world.coord.CylCoords | ||
|
||
import com.martomate.nbt.Nbt | ||
import org.joml.{Matrix4f, Vector3d} | ||
|
||
trait EntityComponent | ||
|
||
class TransformComponent(var position: CylCoords, var rotation: Vector3d = new Vector3d) extends EntityComponent: | ||
def transform: Matrix4f = new Matrix4f() | ||
.translate(position.toVector3f) | ||
.rotateZ(rotation.z.toFloat) | ||
.rotateX(rotation.x.toFloat) | ||
.rotateY(rotation.y.toFloat) | ||
|
||
object TransformComponent: | ||
def fromNBT(tag: Nbt.MapTag)(using CylinderSize): TransformComponent = | ||
val pos = tag | ||
.getMap("pos") | ||
.map(t => CylCoords(t.setVector(new Vector3d))) | ||
.getOrElse(CylCoords(0, 0, 0)) | ||
|
||
val rot = new Vector3d | ||
tag.getMap("rotation").foreach(_.setVector(rot)) | ||
|
||
TransformComponent(pos, rot) | ||
|
||
class VelocityComponent(var velocity: Vector3d = new Vector3d) extends EntityComponent | ||
|
||
object VelocityComponent: | ||
def fromNBT(tag: Nbt.MapTag)(using CylinderSize): VelocityComponent = | ||
val vel = new Vector3d | ||
tag.getMap("velocity").foreach(_.setVector(vel)) | ||
|
||
VelocityComponent(vel) | ||
|
||
class ModelComponent(val model: EntityModel) extends EntityComponent | ||
|
||
class AiComponent(val ai: EntityAI) extends EntityComponent | ||
|
||
object AiComponent: | ||
def fromNBT(tag: Nbt.MapTag)(using CylinderSize): AiComponent = | ||
val ai: EntityAI = | ||
tag.getMap("ai") match | ||
case Some(t) => SimpleWalkAI.fromNBT(t) | ||
case None => SimpleWalkAI.create | ||
AiComponent(ai) | ||
|
||
class BoundsComponent(val bounds: HexBox) extends EntityComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.