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
3 changes: 2 additions & 1 deletion .idea/kotlinc.xml

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

1 change: 1 addition & 0 deletions .idea/vcs.xml

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

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(":"))
}
}
12 changes: 12 additions & 0 deletions src/internal/client/kotlin/net/terramodulus/engine/AsdIntData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* SPDX-FileCopyrightText: 2026 TerraModulus Team and Contributors
* SPDX-License-Identifier: LGPL-3.0-only
*/

package net.terramodulus.engine

/**
* ASD Intermediate Data
*/
class AsdIntData {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2026 TerraModulus Team and Contributors
* SPDX-License-Identifier: LGPL-3.0-only
*/

package net.terramodulus.engine

import java.io.InputStream

/**
* Since for most parts, there is no definite metadata of lengths for all data,
* it is necessary to provide at least processing fragmentation from implementation.
*/
interface BaseAsdProcessor {
/**
* @param data ByteArrayInputStream backed by direct byte buffer
*/
fun process(data: InputStream)
}
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,8 +5,11 @@

package net.terramodulus.engine

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

@OptIn(ExperimentalUnsignedTypes::class)
sealed class ModelTransform(handles: ULongArray) {
Expand All @@ -15,19 +18,15 @@ sealed class ModelTransform(handles: ULongArray) {
}

@OptIn(ExperimentalUnsignedTypes::class)
class SmartScaling private constructor(vararg args: Int) :
ModelTransform(modelSmartScaling(args)) {

companion object {
fun none(w: Int, h: Int) = SmartScaling(w, h, 0)

fun x(w: Int, h: Int, ww: Int, hh: Int) = SmartScaling(w, h, 1, ww, hh)

fun y(w: Int, h: Int, ww: Int, hh: Int) = SmartScaling(w, h, 2, ww, hh)

fun both(w: Int, h: Int, ww: Int, hh: Int) = SmartScaling(w, h, 3, ww, hh)
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 FullScaling(w: Int, h: Int) : ModelTransform(modelFullScaling(intArrayOf(w, h)))
23 changes: 21 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,30 @@ 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)

private val listeners = HashSet<(UInt, UInt) -> Unit>()

fun addListener(listener: (UInt, UInt) -> Unit) = listeners.add(listener)
fun removeListener(listener: (UInt, UInt) -> Unit) = listeners.remove(listener)

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

fun show() = showWindow(windowHandle)

fun swap() = swapWindow(windowHandle)
Expand Down
Loading
Loading