Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "ferricia"]
path = ferricia
url = https://github.com/bitsusei/TerraModulus-Ferricia-Engine
[submodule "vector-math"]
path = vector-math
url = https://github.com/bitsusei/kotlin-vector-math
95 changes: 59 additions & 36 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,56 @@ plugins {
kotlin("jvm") version "2.3.21"
kotlin("plugin.serialization") version "2.1.20"
id("org.jetbrains.kotlinx.atomicfu") version "0.27.0"
id("io.github.arc-blroth.cargo-wrapper") version "1.0.0" apply false
// id("fr.stardustenterprises.rust.wrapper") version "3.2.4" apply false
application
}

allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
version = "0.0.1"

version = "0.0.1"
repositories {
mavenCentral()
}

project(":ferricia") {
// Candidates: fr.stardustenterprises.rust.wrapper
apply(plugin = "io.github.arc-blroth.cargo-wrapper")

repositories {
mavenCentral()
if (providers.gradleProperty("release").isPresent) configure<ai.arcblroth.cargo.CargoExtension> {
profile = "release" // use `-Prelease=true`
}
// somehow, .cargo extension is unusable
configure<ai.arcblroth.cargo.CargoExtension> {
outputs = mapOf("" to System.mapLibraryName("ferricia"))
}
configurations {
create("client") {
configure<ai.arcblroth.cargo.CargoExtension> {
arguments = listOf("-F", "client")
}
}
create("server") {
configure<ai.arcblroth.cargo.CargoExtension> {
arguments = listOf("-F", "server")
}
}
}
artifacts {
add("client", tasks.named("build"))
add("server", tasks.named("build"))
}
}

configure(listOf(project(":kernel"), project(":internal"))) {
configure(listOf(project("common"), project("client"), project("server"))) {
apply(plugin = "org.jetbrains.kotlin.jvm")

version = rootProject.version

repositories {
mavenCentral()
}

sourceSets.main {
kotlin.srcDir("kotlin")
resources.srcDir("resources")
Expand Down Expand Up @@ -61,6 +96,23 @@ project(":kernel") {
}
}

project(":kernel:client") {
dependencies {
implementation(project(":ferricia", "client"))
}
}
project(":kernel:server") {
dependencies {
implementation(project(":ferricia", "server"))
}
}

configure(listOf(project(":internal:common"), project(":kernel:common"))) {
dependencies {
api("com.cout970:kotlin-vector-math:0.1.0")
}
}

project(":kernel:common") {
dependencies {
api("org.jetbrains:annotations:26.1.0")
Expand Down Expand Up @@ -112,28 +164,6 @@ configure(listOf(project(":kernel:server"), project(":kernel:client"))) {
}
}

/** Build Ferricia Engine with Cargo */
tasks.register<Exec>("cargoBuildClient") {
onlyIf {
!gradle.taskGraph.hasTask(":kernel:server:jar")
}
workingDir = rootProject.file("ferricia")
commandLine("cargo", "build")
if (project.hasProperty("release")) args("--release") // use `-Prelease=true`
args("-F", "client")
}
tasks.register<Exec>("cargoBuildServer") {
onlyIf {
!gradle.taskGraph.hasTask(":kernel:client:jar")
}
workingDir = rootProject.file("ferricia")
commandLine("cargo", "build")
if (project.hasProperty("release")) args("--release") // use `-Prelease=true`
args("-F", "server")
}
project(":kernel:client").tasks.named("jar") { dependsOn(tasks.named("cargoBuildClient")) }
project(":kernel:server").tasks.named("jar") { dependsOn(tasks.named("cargoBuildServer")) }

tasks.register("buildClient") {
group = "build"
description = "Build client"
Expand All @@ -151,17 +181,13 @@ tasks.named("run") {
tasks.register("runClient") {
group = "application"
description = "Run client"
dependsOn("cargoBuildClient")
dependsOn(":kernel:client:run")
}
project(":kernel:client").tasks.named("run").get().mustRunAfter(tasks.named("cargoBuildClient"))
tasks.register("runServer") {
group = "application"
description = "Run server"
dependsOn("cargoBuildServer")
dependsOn(":kernel:server:run")
}
project(":kernel:server").tasks.named("run").get().mustRunAfter(tasks.named("cargoBuildServer"))

configure(listOf(project(":kernel:server"), project(":kernel:client"))) {
distributions {
Expand All @@ -170,15 +196,12 @@ configure(listOf(project(":kernel:server"), project(":kernel:client"))) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
into("lib") {
val dir = if (project.hasProperty("release")) "release" else "debug"
from("$rootDir/ferricia/target/$dir/${System.mapLibraryName("ferricia")}")
if (OperatingSystem.current().isWindows) from(
"$rootDir/ferricia/target/$dir/ferricia.dll",
"$rootDir/ferricia/target/$dir/oded.dll",
"$rootDir/ferricia/target/$dir/OpenAL32.dll",
"$rootDir/ferricia/target/$dir/SDL3.dll",
) else { // suppose UNIX
// other libs should be installed on user's end directly
from("$rootDir/ferricia/target/$dir/libferricia.so")
}
) // for UNIX, other libs should have been installed on user's end directly
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ferricia
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 3 additions & 3 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ rootProject.children.forEach {
it.projectDir = File(settingsDir, "src/${it.name}")
include("${it.name}:common", "${it.name}:client", "${it.name}:server")
}

include("ferricia") // this is Rust

includeBuild("vector-math") {
dependencySubstitution {
substitute(module("com.cout970:kotlin-vector-math")).using(project(":"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Canvas internal constructor(private val windowHandle: ULong) : Closeable {

fun setClearColor(r: Float, g: Float, b: Float, a: Float) = setCanvasClearColor(r, g, b, a)

fun resizeGLViewport() = if (camera3D == null) {
internal fun resizeGLViewport() = if (camera3D == null) {
Mui.resizeGLViewport(windowHandle, handle)
} else {
Mui.resizeGLViewportCamera(windowHandle, handle, camera3D!!.handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

package net.terramodulus.engine

data class Rgba(val r: Int, val g: Int, val b: Int, val a: Int) {
fun toArray() = intArrayOf(r, g, b, a)
}
import com.cout970.math.vec4.Vec4i

data class Vec3F(val x: Float, val y: Float, val z: Float) {
fun toArray() = floatArrayOf(x, y, z)
}
fun Vec4i.toArray() = intArrayOf(x, y, z, w)
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@

package net.terramodulus.engine

import com.cout970.math.vec2.MutVec2d
import com.cout970.math.vec2.Vec2d
import net.terramodulus.engine.ferricia.Mui.modelFullScaling
import net.terramodulus.engine.ferricia.Mui.modelGeneralTransform
import net.terramodulus.engine.ferricia.Mui.modelSmartScaling
import net.terramodulus.engine.ferricia.Mui.updateGeneralTransform
import kotlin.properties.Delegates

@OptIn(ExperimentalUnsignedTypes::class)
sealed class ModelTransform(handles: ULongArray) {
internal val handle: ULong = handles[0]
internal val wideHandle: ULong = handles[1]
}

@OptIn(ExperimentalUnsignedTypes::class)
class GeneralTransform(sx: Double, sy: Double, angle: Double, px: Double, py: Double) :
ModelTransform(modelGeneralTransform(doubleArrayOf(sx, sy, angle, px, py))) {
var scale: Vec2d by Delegates.observable(MutVec2d(sx, sy)) { _, _, new ->
updateGeneralTransform(handle, doubleArrayOf(new.x, new.y, angle, px, py))
}
var angle: Double by Delegates.observable(angle) { _, _, new ->
updateGeneralTransform(handle, doubleArrayOf(sx, sy, new, px, py))
}
var pos: Vec2d by Delegates.observable(MutVec2d(px, py)) { _, _, new ->
updateGeneralTransform(handle, doubleArrayOf(sx, sy, angle, new.x, new.y))
}
}

@OptIn(ExperimentalUnsignedTypes::class)
class SmartScaling private constructor(vararg args: Int) :
ModelTransform(modelSmartScaling(args)) {
Expand Down
17 changes: 15 additions & 2 deletions src/internal/client/kotlin/net/terramodulus/engine/Window.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ import java.io.Closeable
/**
* Manages the SDL window instance and the underlying GL context.
*/
class Window : Closeable {
class Window(
width: UInt,
height: UInt,
) : Closeable {
var width = width
private set
var height = height
private set
private val sdlHandle = initSdlHandle()
private val windowHandle = initWindowHandle(sdlHandle)
private val windowHandle = initWindowHandle(sdlHandle) // TODO pass dimensions
val canvas = Canvas(windowHandle)

fun sizeChanged(width: UInt, height: UInt) {
this.width = width
this.height = height
canvas.resizeGLViewport()
}

fun show() = showWindow(windowHandle)

fun swap() = swapWindow(windowHandle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,41 @@

package net.terramodulus.engine

import com.cout970.math.quaternion.Quatd
import com.cout970.math.vec3.Vec3d
import com.cout970.math.vec4.Vec4i
import net.terramodulus.engine.ferricia.Gwr.newMeshGeomCube
import net.terramodulus.engine.ferricia.Gwr.newMeshGeomSphere
import net.terramodulus.engine.ferricia.Gwr.updateWorldObjModel

sealed class WorldObjDrawable(internal val handle: ULong, private var pos: Vec3D, private var scale: Vec3D, private var rot: Quat) {
sealed class WorldObjDrawable(internal val handle: ULong, private var pos: Vec3d, private var scale: Vec3d, private var rot: Quatd) {
fun updateModel(px: Double, py: Double, pz: Double, sx: Double, sy: Double, sz: Double, w: Double, i: Double, j: Double, k: Double) =
updateWorldObjModel(handle, doubleArrayOf(px, py, pz, w, i, j, k, sx, sy, sz))
fun updateModel(pos: Vec3D, scale: Vec3D, rot: Quat) =
updateModel(pos.x, pos.y, pos.z, scale.x, scale.y, scale.z, rot.w, rot.i, rot.j, rot.k)
fun updateModel(pos: Vec3d, scale: Vec3d, rot: Quatd) =
updateModel(pos.x, pos.y, pos.z, scale.x, scale.y, scale.z, rot.w, rot.x, rot.y, rot.z)

init {
updateModel(pos, scale, rot)
}

fun setPos(value: Vec3D) {
fun setPos(value: Vec3d) {
pos = value
updateModel(pos, scale, rot)
}

fun setScale(value: Vec3D) {
fun setScale(value: Vec3d) {
scale = value
updateModel(pos, scale, rot)
}

fun setRot(value: Quat) {
fun setRot(value: Quatd) {
rot = value
updateModel(pos, scale, rot)
}
}

class SimpleMesh3dGeomCube(width: Float, rgba: Rgba, pos: Vec3D, scale: Vec3D, rot: Quat) :
class SimpleMesh3dGeomCube(width: Float, rgba: Vec4i, pos: Vec3d, scale: Vec3d, rot: Quatd) :
WorldObjDrawable(newMeshGeomCube(width, rgba.toArray()), pos, scale, rot)

class SimpleMesh3dGeomSphere(radius: Float, rgba: Rgba, pos: Vec3D, scale: Vec3D, rot: Quat) :
class SimpleMesh3dGeomSphere(radius: Float, rgba: Vec4i, pos: Vec3d, scale: Vec3d, rot: Quatd) :
WorldObjDrawable(newMeshGeomSphere(radius, rgba.toArray()), pos, scale, rot)
15 changes: 15 additions & 0 deletions src/internal/client/kotlin/net/terramodulus/engine/ferricia/Mui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package net.terramodulus.engine.ferricia

import net.terramodulus.engine.MuiEvent

@OptIn(ExperimentalUnsignedTypes::class)
internal object Mui {
/**
* @return SDL handle pointer
Expand Down Expand Up @@ -141,6 +142,20 @@ internal object Mui {
@JvmName("setGeomPos")
external fun setGeomPos(handle: ULong, data: FloatArray)

/**
* @param data `[sx, sy, angle, px, py]`; scaling, rotation, position
* @return GeneralTransform handle pointers
*/
@JvmName("modelGeneralTransform")
external fun modelGeneralTransform(data: DoubleArray): ULongArray

/**
* @param handle GeneralTransform thin pointer
* @param data `[sx, sy, angle, px, py]`; scaling, rotation, position
*/
@JvmName("updateGeneralTransform")
external fun updateGeneralTransform(handle: ULong, data: DoubleArray)

/**
* @param data `[w, h, param, w, h]`
* @return SmartScaling handle pointers
Expand Down
Loading
Loading