diff --git a/.github/workflows/deploy_jvm.yml b/.github/workflows/deploy_jvm.yml index 20b33da734..c5cc1046a4 100644 --- a/.github/workflows/deploy_jvm.yml +++ b/.github/workflows/deploy_jvm.yml @@ -102,6 +102,16 @@ jobs: run: | modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-api-library:publish -Prelease + - name: Publish godot-bootstrap-library debug + shell: sh + run: | + modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-bootstrap-library:publish -Pdebug + + - name: Publish godot-bootstrap-library release + shell: sh + run: | + modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-bootstrap-library:publish -Prelease + - name: Publish godot-extension-library debug shell: sh run: | diff --git a/harness/tests/scripts/godot/tests/inheritance/InterfaceChild.gdj b/harness/tests/scripts/godot/tests/inheritance/InterfaceChild.gdj new file mode 100644 index 0000000000..fd1ebeff93 --- /dev/null +++ b/harness/tests/scripts/godot/tests/inheritance/InterfaceChild.gdj @@ -0,0 +1,23 @@ +// THIS FILE IS GENERATED! DO NOT EDIT OR DELETE IT. EDIT OR DELETE THE ASSOCIATED SOURCE CODE FILE INSTEAD +// Note: You can however freely move this file inside your godot project if you want. Keep in mind however, that if you rename the originating source code file, this file will be deleted and regenerated as a new file instead of being updated! Other modifications to the source file however, will result in this file being updated. + +registeredName = InterfaceChild +fqName = godot.tests.inheritance.InterfaceChild +baseType = Node +supertypes = [ + godot.api.Node, + godot.api.Object, + godot.core.KtObject, + godot.tests.inheritance.TestInterface, + godot.common.interop.NativeWrapper, + godot.common.interop.NativePointer +] +signals = [ + +] +properties = [ + +] +functions = [ + do_thing +] \ No newline at end of file diff --git a/harness/tests/settings.gradle.kts b/harness/tests/settings.gradle.kts index 9c35285b76..662d3e4dbd 100644 --- a/harness/tests/settings.gradle.kts +++ b/harness/tests/settings.gradle.kts @@ -8,12 +8,14 @@ includeBuild("../../kt/api-generator") { includeBuild("../../kt") { dependencySubstitution { substitute(module("com.utopia-rise:godot-gradle-plugin")).using(project(":godot-gradle-plugin")) - substitute(module("com.utopia-rise:godot-internal-library-debug")).using(project(":godot-core-library")) - substitute(module("com.utopia-rise:godot-internal-library-release")).using(project(":godot-core-library")) + substitute(module("com.utopia-rise:godot-internal-library-debug")).using(project(":godot-internal-library")) + substitute(module("com.utopia-rise:godot-internal-library-release")).using(project(":godot-internal-library")) substitute(module("com.utopia-rise:godot-core-library-debug")).using(project(":godot-core-library")) substitute(module("com.utopia-rise:godot-core-library-release")).using(project(":godot-core-library")) substitute(module("com.utopia-rise:godot-api-library-debug")).using(project(":godot-api-library")) substitute(module("com.utopia-rise:godot-api-library-release")).using(project(":godot-api-library")) + substitute(module("com.utopia-rise:godot-bootstrap-library-debug")).using(project(":godot-bootstrap-library")) + substitute(module("com.utopia-rise:godot-bootstrap-library-release")).using(project(":godot-bootstrap-library")) substitute(module("com.utopia-rise:godot-extension-library-debug")).using(project(":godot-extension-library")) substitute(module("com.utopia-rise:godot-extension-library-release")).using(project(":godot-extension-library")) substitute(module("com.utopia-rise:godot-coroutine-library-debug")).using(project(":godot-coroutine-library")) diff --git a/harness/tests/src/main/kotlin/godot/tests/args/FunctionArgSizeTest.kt b/harness/tests/src/main/kotlin/godot/tests/args/FunctionArgSizeTest.kt index b692b2eff9..f59b0cd051 100644 --- a/harness/tests/src/main/kotlin/godot/tests/args/FunctionArgSizeTest.kt +++ b/harness/tests/src/main/kotlin/godot/tests/args/FunctionArgSizeTest.kt @@ -1,10 +1,8 @@ package godot.tests.args import godot.api.Node -import godot.api.Resource import godot.annotation.RegisterClass import godot.annotation.RegisterFunction -import godot.core.Dictionary import godot.core.VariantArray import godot.core.variantArrayOf diff --git a/harness/tests/src/main/kotlin/godot/tests/coretypes/StringTest.kt b/harness/tests/src/main/kotlin/godot/tests/coretypes/StringTest.kt index 0fa46b3bbf..84a05ab0cc 100644 --- a/harness/tests/src/main/kotlin/godot/tests/coretypes/StringTest.kt +++ b/harness/tests/src/main/kotlin/godot/tests/coretypes/StringTest.kt @@ -3,7 +3,6 @@ package godot.tests.coretypes import godot.api.Node import godot.annotation.RegisterClass import godot.annotation.RegisterFunction -import godot.core.StringName import godot.core.asStringName import godot.core.Vector2 diff --git a/harness/tests/src/main/kotlin/godot/tests/inheritance/InterfaceChild.kt b/harness/tests/src/main/kotlin/godot/tests/inheritance/InterfaceChild.kt new file mode 100644 index 0000000000..a496c15cce --- /dev/null +++ b/harness/tests/src/main/kotlin/godot/tests/inheritance/InterfaceChild.kt @@ -0,0 +1,13 @@ +package godot.tests.inheritance + +import godot.annotation.RegisterClass +import godot.annotation.RegisterFunction +import godot.api.Node + +@RegisterClass +class InterfaceChild : Node(), TestInterface { + @RegisterFunction + override fun doThing() { + + } +} \ No newline at end of file diff --git a/harness/tests/src/main/kotlin/godot/tests/inheritance/TestInterface.kt b/harness/tests/src/main/kotlin/godot/tests/inheritance/TestInterface.kt new file mode 100644 index 0000000000..121b8cd257 --- /dev/null +++ b/harness/tests/src/main/kotlin/godot/tests/inheritance/TestInterface.kt @@ -0,0 +1,8 @@ +package godot.tests.inheritance + +import godot.annotation.RegisterFunction + +interface TestInterface { + @RegisterFunction + fun doThing() +} \ No newline at end of file diff --git a/harness/tests/src/main/kotlin/godot/tests/static/CallStaticTest.kt b/harness/tests/src/main/kotlin/godot/tests/static/CallStaticTest.kt index 7d9a2d00ce..3535a69baf 100644 --- a/harness/tests/src/main/kotlin/godot/tests/static/CallStaticTest.kt +++ b/harness/tests/src/main/kotlin/godot/tests/static/CallStaticTest.kt @@ -5,7 +5,6 @@ import godot.api.Node import godot.api.ProjectSettings import godot.annotation.RegisterClass import godot.annotation.RegisterFunction -import godot.core.Color @RegisterClass class CallStaticTest: Node() { diff --git a/harness/tests/src/main/kotlin/godot/tests/subpackage/OtherScript.kt b/harness/tests/src/main/kotlin/godot/tests/subpackage/OtherScript.kt index 5590b1a5ed..5e4b6aaf91 100644 --- a/harness/tests/src/main/kotlin/godot/tests/subpackage/OtherScript.kt +++ b/harness/tests/src/main/kotlin/godot/tests/subpackage/OtherScript.kt @@ -1,7 +1,6 @@ package godot.tests.subpackage import godot.api.Node -import godot.api.Node3D import godot.annotation.RegisterClass import godot.annotation.RegisterFunction diff --git a/kt/entry-generation/godot-class-graph-symbol-processor/build.gradle.kts b/kt/entry-generation/godot-class-graph-symbol-processor/build.gradle.kts index 3152b97bd9..df10de8e17 100644 --- a/kt/entry-generation/godot-class-graph-symbol-processor/build.gradle.kts +++ b/kt/entry-generation/godot-class-graph-symbol-processor/build.gradle.kts @@ -12,7 +12,7 @@ kotlin { dependencies { implementation("com.utopia-rise:tools-common:$fullGodotKotlinJvmVersion") - implementation(project(":godot-core-library")) + implementation(project(":godot-bootstrap-library")) implementation(project(":godot-entry-generator")) implementation(libs.classGraph) diff --git a/kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/ClassExtentions.kt b/kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/ClassExtentions.kt index d9307ce488..6761779fda 100644 --- a/kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/ClassExtentions.kt +++ b/kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/ClassExtentions.kt @@ -78,11 +78,15 @@ private fun ClassInfo.shouldBeRegistered( registeredFunctions: List, registeredProperties: List, registeredSignals: List -) = hasAnnotation(RegisterClass::class.java) || isAbstractAndContainsRegisteredMembers( - registeredFunctions, - registeredProperties, - registeredSignals -) || isAbstractAndInheritsGodotObject +) = !isInterface && ( + hasAnnotation(RegisterClass::class.java) || + isAbstractAndContainsRegisteredMembers( + registeredFunctions, + registeredProperties, + registeredSignals + ) || + isAbstractAndInheritsGodotObject + ) private fun ClassInfo.isAbstractAndContainsRegisteredMembers( registeredFunctions: List, diff --git a/kt/entry-generation/godot-entry-generator/build.gradle.kts b/kt/entry-generation/godot-entry-generator/build.gradle.kts index 0fb9c3c3b6..71d47d14dc 100644 --- a/kt/entry-generation/godot-entry-generator/build.gradle.kts +++ b/kt/entry-generation/godot-entry-generator/build.gradle.kts @@ -12,7 +12,7 @@ kotlin { dependencies { implementation("com.utopia-rise:tools-common:$fullGodotKotlinJvmVersion") - implementation(project(":godot-core-library")) + implementation(project(":godot-bootstrap-library")) implementation(libs.kotlinPoet) } diff --git a/kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/filebuilder/ClassRegistrarFileBuilder.kt b/kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/filebuilder/ClassRegistrarFileBuilder.kt index 4b5f185b1d..5c17cdae09 100644 --- a/kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/filebuilder/ClassRegistrarFileBuilder.kt +++ b/kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/filebuilder/ClassRegistrarFileBuilder.kt @@ -122,7 +122,7 @@ class ClassRegistrarFileBuilder( .writeTo(bufferedWriter) } - return "%T().register(registry)" to arrayOf( + return "%T().register(this)" to arrayOf( ClassName( godotEntryBasePackage, "${registeredClass.registeredName}Registrar" diff --git a/kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/filebuilder/MainEntryFileBuilder.kt b/kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/filebuilder/MainEntryFileBuilder.kt index 4065cb4398..5e4cb24a8d 100644 --- a/kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/filebuilder/MainEntryFileBuilder.kt +++ b/kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/filebuilder/MainEntryFileBuilder.kt @@ -23,20 +23,12 @@ import kotlin.reflect.KClass class MainEntryFileBuilder { private val initFunctionSpec = FunSpec .builder("init") - .receiver(ClassName("$godotRegistrationPackage.${GodotKotlinJvmTypes.entry}", GodotKotlinJvmTypes.context)) + .receiver(ClassName(godotRegistrationPackage, GodotKotlinJvmTypes.classRegistry)) .addModifiers(KModifier.OVERRIDE) - private val initEngineTypesFunSpec = FunSpec - .builder("initEngineTypes") - .receiver(ClassName("$godotRegistrationPackage.${GodotKotlinJvmTypes.entry}", GodotKotlinJvmTypes.context)) - .addModifiers(KModifier.OVERRIDE) - .addStatement("%M()", MemberName(godotPackage, "registerVariantMapping")) - .addStatement("%M()", MemberName(godotPackage, "registerEngineTypes")) - .addStatement("%M()", MemberName(godotPackage, "registerEngineTypeMethods")) - private val registerUserTypesVariantMappingsFunSpec = FunSpec .builder("getRegisteredClasses") - .receiver(ClassName("$godotRegistrationPackage.${GodotKotlinJvmTypes.entry}", GodotKotlinJvmTypes.context)) + .receiver(ClassName(godotRegistrationPackage, GodotKotlinJvmTypes.classRegistry)) .addModifiers(KModifier.OVERRIDE) .returns( List::class @@ -65,7 +57,6 @@ class MainEntryFileBuilder { .classBuilder(ClassName("$godotEntryBasePackage.$randomPackageForEntryFile", GodotKotlinJvmTypes.entry)) .superclass(ClassName(godotRegistrationPackage, GodotKotlinJvmTypes.entry)) .addFunction(initFunctionSpec.build()) - .addFunction(initEngineTypesFunSpec.build()) .addFunction(registerUserTypesVariantMappingsFunSpec.build()) .addProperty(classRegistrarCountPropertySpec.build()) .addProperty(projectNamePropertySpec.build()) diff --git a/kt/godot-library/godot-bootstrap-library/build.gradle.kts b/kt/godot-library/godot-bootstrap-library/build.gradle.kts new file mode 100644 index 0000000000..9a1fae786a --- /dev/null +++ b/kt/godot-library/godot-bootstrap-library/build.gradle.kts @@ -0,0 +1,54 @@ +import versioninfo.fullGodotKotlinJvmVersion + +plugins { + alias(libs.plugins.kotlin.jvm) + id("com.utopia-rise.godot-publish") + id("com.utopia-rise.versioninfo") + alias(libs.plugins.kotlinPreProcessors) +} + +val isRelease = project.hasProperty("release") + +kotlinDefinitions { + definitionsObjectName.set("GodotJvmBuildConfig") + define("DEBUG", !isRelease) +} + +kotlin { + jvmToolchain(libs.versions.toolchain.jvm.get().toInt()) +} + +dependencies { + api("com.utopia-rise:common:${fullGodotKotlinJvmVersion}") + api(project(":godot-api-library")) + implementation(project(":godot-internal-library")) +} + +tasks { + compileKotlin { + dependsOn(":godot-library:generateAPI") + } + + // here so the sourcesJar task has an explicit dependency on the generateApi task. Needed since gradle 8 + withType { + dependsOn(":godot-library:generateAPI") + } +} + +val targetSuffix = if (isRelease) "release" else "debug" + +publishing { + publications { + @Suppress("UNUSED_VARIABLE", "unused") + val godotBootstrapLibraryPublication by registering(MavenPublication::class) { + pom { + name.set("${project.name}-$targetSuffix") + description.set("Contains code needed to bootstrap godot kotlin.") + } + artifactId = "godot-bootstrap-library-$targetSuffix" + description = "Contains code needed to bootstrap godot kotlin." + + from(components["java"]) + } + } +} diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/Export.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/Export.kt similarity index 93% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/Export.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/Export.kt index 5097a38b5a..bea2a7c9b7 100644 --- a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/Export.kt +++ b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/Export.kt @@ -1,6 +1,5 @@ package godot.annotation - /** * Mark a registered property as exported and thus visible in the inspector. * @@ -10,4 +9,4 @@ package godot.annotation */ @Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD) @Retention(AnnotationRetention.RUNTIME) -annotation class Export +annotation class Export \ No newline at end of file diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisterClass.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisterClass.kt similarity index 88% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisterClass.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisterClass.kt index 85221ca4e7..30f6040f3e 100644 --- a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisterClass.kt +++ b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisterClass.kt @@ -7,4 +7,4 @@ package godot.annotation */ @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) -annotation class RegisterClass(val className: String = "") +annotation class RegisterClass(val className: String = "") \ No newline at end of file diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisterFunction.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisterFunction.kt similarity index 100% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisterFunction.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisterFunction.kt diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisterProperty.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisterProperty.kt similarity index 100% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisterProperty.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisterProperty.kt diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisterSignal.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisterSignal.kt similarity index 100% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisterSignal.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisterSignal.kt diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisteredClassMetadata.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisteredClassMetadata.kt similarity index 99% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisteredClassMetadata.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisteredClassMetadata.kt index e394bfe349..c20ea5351f 100644 --- a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/RegisteredClassMetadata.kt +++ b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/RegisteredClassMetadata.kt @@ -13,4 +13,4 @@ annotation class RegisteredClassMetadata( val properties: String, val functions: String, val isRegistrationFileHierarchyEnabled: Boolean -) +) \ No newline at end of file diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/Rpc.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/Rpc.kt similarity index 100% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/Rpc.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/Rpc.kt diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/Tool.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/Tool.kt similarity index 90% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/Tool.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/Tool.kt index a75895e1b4..f9b676cce9 100644 --- a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/Tool.kt +++ b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/Tool.kt @@ -1,6 +1,5 @@ package godot.annotation - /** * Mark a class as tool class. * @@ -8,4 +7,4 @@ package godot.annotation */ @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) -annotation class Tool +annotation class Tool \ No newline at end of file diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/propertyHintAnnotations.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/propertyHintAnnotations.kt similarity index 100% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/annotation/propertyHintAnnotations.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/annotation/propertyHintAnnotations.kt diff --git a/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/registration/Entry.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/registration/Entry.kt new file mode 100644 index 0000000000..050d4fde59 --- /dev/null +++ b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/registration/Entry.kt @@ -0,0 +1,11 @@ +package godot.registration + +import kotlin.reflect.KClass + +abstract class Entry { + abstract fun ClassRegistry.init() + abstract fun ClassRegistry.getRegisteredClasses(): List> + + abstract val classRegistrarCount: Int + abstract val projectName: String +} diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/registration/Range.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/registration/Range.kt similarity index 100% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/registration/Range.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/registration/Range.kt diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/registration/Registration.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/registration/Registration.kt similarity index 99% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/registration/Registration.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/registration/Registration.kt index 21775d90ea..da5fd52bfc 100644 --- a/kt/godot-library/godot-core-library/src/main/kotlin/godot/registration/Registration.kt +++ b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/registration/Registration.kt @@ -35,7 +35,6 @@ import godot.internal.reflection.TypeManager import godot.core.VariantParser import godot.core.toVariantArray import godot.core.variantArrayOf -import godot.common.constants.Constraints import godot.core.VariantCaster import godot.core.enumFromGodotOrdinal import godot.core.godotOrdinal diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/runtime/Bootstrap.kt b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/runtime/Bootstrap.kt similarity index 82% rename from kt/godot-library/godot-core-library/src/main/kotlin/godot/runtime/Bootstrap.kt rename to kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/runtime/Bootstrap.kt index 2b45cdbbf7..1e9c0837fe 100644 --- a/kt/godot-library/godot-core-library/src/main/kotlin/godot/runtime/Bootstrap.kt +++ b/kt/godot-library/godot-bootstrap-library/src/main/kotlin/godot/runtime/Bootstrap.kt @@ -6,15 +6,15 @@ import godot.core.VariantParser import godot.core.variantMapper import godot.internal.logging.JVMLogging import godot.internal.reflection.TypeManager +import godot.registerEngineTypeMethods +import godot.registerEngineTypes +import godot.registerVariantMapping import godot.registration.ClassRegistry import godot.registration.Entry -import java.util.* - +import java.util.ServiceLoader internal class Bootstrap { private lateinit var serviceLoader: ServiceLoader - private var engineTypeInitialized = false - fun initJar(loader: ClassLoader) { serviceLoader = ServiceLoader.load(Entry::class.java, loader) @@ -38,6 +38,16 @@ internal class Bootstrap { serviceLoader.reload() } + fun initializeEngineTypes() { + registerVariantMapping() + registerEngineTypes() + registerEngineTypeMethods() + + registerManagedEngineTypes( + TypeManager.engineTypeNames.toTypedArray(), + TypeManager.engineSingletonsNames.toTypedArray() + ) + } private fun initializeUsingEntry() { val entryIterator = serviceLoader.iterator() @@ -56,7 +66,7 @@ internal class Bootstrap { val mainEntry = entries.maxBy { entry -> entry.classRegistrarCount } val classRegistries = mutableListOf() - var mainContext: Entry.Context? = null + var mainRegistry: ClassRegistry? = null entries.forEach { entry -> val isMainEntry = entry == mainEntry @@ -66,24 +76,15 @@ internal class Bootstrap { ) classRegistries.add(registry) - val context = Entry.Context(registry) with(entry) { if (isMainEntry) { - mainContext = context - if(!engineTypeInitialized) { - context.initEngineTypes() - engineTypeInitialized = true - } - registerManagedEngineTypes( - TypeManager.engineTypeNames.toTypedArray(), - TypeManager.engineSingletonsNames.toTypedArray() - ) + mainRegistry = registry } - for (clazz in context.getRegisteredClasses()) { + for (clazz in registry.getRegisteredClasses()) { variantMapper[clazz] = VariantParser.OBJECT } - context.init() + registry.init() } } @@ -99,12 +100,12 @@ internal class Bootstrap { fun forceJvmInitializationOfScripts() { // Ugly but it will have to wait for when you rework Registration and Bootstrap // Has to run after all classes are initialized in case a static block needs a Godot type - if (mainContext == null) { + if (mainRegistry == null) { return } with(mainEntry) { - mainContext.getRegisteredClasses().forEach { clazz -> + mainRegistry.getRegisteredClasses().forEach { clazz -> // Force init of the class so any static block runs. Class.forName(clazz.java.name, true, clazz.java.classLoader) } @@ -130,4 +131,4 @@ internal class Bootstrap { engineTypesNames: Array, engineSingletonNames: Array ) -} +} \ No newline at end of file diff --git a/kt/godot-library/godot-core-library/src/main/kotlin/godot/registration/Entry.kt b/kt/godot-library/godot-core-library/src/main/kotlin/godot/registration/Entry.kt deleted file mode 100644 index 755783a89e..0000000000 --- a/kt/godot-library/godot-core-library/src/main/kotlin/godot/registration/Entry.kt +++ /dev/null @@ -1,13 +0,0 @@ -package godot.registration - -import kotlin.reflect.KClass - -abstract class Entry { - class Context(val registry: ClassRegistry) - abstract fun Context.init() - abstract fun Context.initEngineTypes() - abstract fun Context.getRegisteredClasses(): List> - - abstract val classRegistrarCount: Int - abstract val projectName: String -} diff --git a/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/projectExt/projectExtensions.kt b/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/projectExt/projectExtensions.kt index df03354813..3804837896 100644 --- a/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/projectExt/projectExtensions.kt +++ b/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/projectExt/projectExtensions.kt @@ -35,6 +35,9 @@ val Project.godotCoreArtifactName: String val Project.godotApiArtifactName: String get() = "godot-api-library-${if (isRelease) "release" else "debug"}" +val Project.godotBootstrapArtifactName: String + get() = "godot-bootstrap-library-${if (isRelease) "release" else "debug"}" + val Project.godotExtensionArtifactName: String get() = "godot-extension-library-${if (isRelease) "release" else "debug"}" diff --git a/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/projectExt/setupConfigurationsAndCompilations.kt b/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/projectExt/setupConfigurationsAndCompilations.kt index c777a7c38d..27ea70bff5 100644 --- a/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/projectExt/setupConfigurationsAndCompilations.kt +++ b/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/projectExt/setupConfigurationsAndCompilations.kt @@ -22,6 +22,7 @@ fun Project.setupConfigurationsAndCompilations() { compileOnly("com.utopia-rise:godot-build-props:${GodotBuildProperties.assembledGodotKotlinJvmVersion}") compileOnly("com.utopia-rise:$godotCoreArtifactName:${GodotBuildProperties.assembledGodotKotlinJvmVersion}") compileOnly("com.utopia-rise:$godotApiArtifactName:${GodotBuildProperties.assembledGodotKotlinJvmVersion}") + compileOnly("com.utopia-rise:$godotBootstrapArtifactName:${GodotBuildProperties.assembledGodotKotlinJvmVersion}") compileOnly("com.utopia-rise:$godotExtensionArtifactName:${GodotBuildProperties.assembledGodotKotlinJvmVersion}") compileOnly("com.utopia-rise:godot-class-graph-symbol-processor:${GodotBuildProperties.assembledGodotKotlinJvmVersion}") @@ -39,6 +40,7 @@ fun Project.setupConfigurationsAndCompilations() { add(dependencies.create("com.utopia-rise:$godotInternalArtifactName:${GodotBuildProperties.assembledGodotKotlinJvmVersion}")) add(dependencies.create("com.utopia-rise:$godotCoreArtifactName:${GodotBuildProperties.assembledGodotKotlinJvmVersion}")) add(dependencies.create("com.utopia-rise:$godotApiArtifactName:${GodotBuildProperties.assembledGodotKotlinJvmVersion}")) + add(dependencies.create("com.utopia-rise:$godotBootstrapArtifactName:${GodotBuildProperties.assembledGodotKotlinJvmVersion}")) add(dependencies.create("com.utopia-rise:$godotExtensionArtifactName:${GodotBuildProperties.assembledGodotKotlinJvmVersion}")) // add reflection explicitly so it's usable in exported projects as well. See: GH-571 add(dependencies.create("org.jetbrains.kotlin:kotlin-reflect:${GodotBuildProperties.supportedKotlinVersion}")) diff --git a/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/tasks/packageMainJar.kt b/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/tasks/packageMainJar.kt index 1270041a73..120d40e56f 100644 --- a/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/tasks/packageMainJar.kt +++ b/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/tasks/packageMainJar.kt @@ -2,6 +2,7 @@ package godot.gradle.tasks import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import godot.gradle.projectExt.godotApiArtifactName +import godot.gradle.projectExt.godotBootstrapArtifactName import godot.gradle.projectExt.godotCoreArtifactName import godot.gradle.projectExt.godotExtensionArtifactName import org.gradle.api.Project @@ -30,6 +31,7 @@ fun Project.packageMainJarTask( dependencyFilter.exclude(dependencyFilter.dependency("org.jetbrains.kotlin:kotlin-stdlib.*")) dependencyFilter.exclude(dependencyFilter.dependency("com.utopia-rise:$godotCoreArtifactName:.*")) dependencyFilter.exclude(dependencyFilter.dependency("com.utopia-rise:$godotApiArtifactName:.*")) + dependencyFilter.exclude(dependencyFilter.dependency("com.utopia-rise:$godotBootstrapArtifactName:.*")) dependencyFilter.exclude(dependencyFilter.dependency("com.utopia-rise:$godotExtensionArtifactName:.*")) } } diff --git a/kt/settings.gradle.kts b/kt/settings.gradle.kts index 8205ad380e..1874f02d45 100644 --- a/kt/settings.gradle.kts +++ b/kt/settings.gradle.kts @@ -47,6 +47,7 @@ subdir("godot-library") { include("godot-internal-library") include("godot-core-library") include("godot-api-library") + include("godot-bootstrap-library") include("godot-extension-library") include("godot-coroutine-library") } diff --git a/kt/tools-common/src/main/kotlin/godot/tools/common/constants/Classes.kt b/kt/tools-common/src/main/kotlin/godot/tools/common/constants/Classes.kt index 1d0f204fc6..299dc5c219 100644 --- a/kt/tools-common/src/main/kotlin/godot/tools/common/constants/Classes.kt +++ b/kt/tools-common/src/main/kotlin/godot/tools/common/constants/Classes.kt @@ -43,7 +43,6 @@ object GodotKotlinJvmTypes { const val classRegistry = "ClassRegistry" const val classRegistrar = "ClassRegistrar" const val entry = "Entry" - const val context = "Context" const val naturalT = "NaturalT" const val realT = "RealT" diff --git a/src/gd_kotlin.cpp b/src/gd_kotlin.cpp index 04911726dc..81e47eb1f7 100644 --- a/src/gd_kotlin.cpp +++ b/src/gd_kotlin.cpp @@ -352,6 +352,12 @@ void GDKotlin::finalize_core_library() { callable_middleman = nullptr; } +bool GDKotlin::initialize_engine_types() const { + jni::Env env = jni::Jvm::current_env(); + bootstrap->initialize_engine_types(env); + return true; +} + void GDKotlin::unload_boostrap() { jni::Env env {jni::Jvm::current_env()}; Bootstrap::finalize(env, bootstrap_class_loader); @@ -382,6 +388,7 @@ void GDKotlin::initialize_up_to(State target_state) { #endif SET_LOADING_STATE(load_bootstrap(), BOOTSTRAP_LOADED, target_state) SET_LOADING_STATE(initialize_core_library(), CORE_LIBRARY_INITIALIZED, target_state) + SET_LOADING_STATE(initialize_engine_types(), ENGINE_TYPES_INITIALIZED, target_state) SET_LOADING_STATE(load_user_code(), JVM_SCRIPTS_INITIALIZED, target_state) } diff --git a/src/gd_kotlin.h b/src/gd_kotlin.h index f31b87f867..f1322c4e49 100644 --- a/src/gd_kotlin.h +++ b/src/gd_kotlin.h @@ -23,7 +23,8 @@ class GDKotlin { JVM_STARTED = 2,// Or retrieved in the case of Android BOOTSTRAP_LOADED = 3, CORE_LIBRARY_INITIALIZED = 4, - JVM_SCRIPTS_INITIALIZED = 5, + ENGINE_TYPES_INITIALIZED = 5, + JVM_SCRIPTS_INITIALIZED = 6, }; private: @@ -61,6 +62,8 @@ class GDKotlin { bool initialize_core_library(); void finalize_core_library(); + bool initialize_engine_types() const; + bool load_user_code(); void unload_user_code(); diff --git a/src/jvm_wrapper/bootstrap.cpp b/src/jvm_wrapper/bootstrap.cpp index 3153a14d65..a570634044 100644 --- a/src/jvm_wrapper/bootstrap.cpp +++ b/src/jvm_wrapper/bootstrap.cpp @@ -45,6 +45,10 @@ void Bootstrap::register_engine_type(JNIEnv* p_env, jobject p_this, jobjectArray Bootstrap::Bootstrap(jni::Env& p_env, jni::JObject p_wrapped) : JvmInstanceWrapper(p_env, p_wrapped) {} +void Bootstrap::initialize_engine_types(jni::Env& p_env) { + wrapped.call_void_method(p_env, INITIALIZE_ENGINE_TYPES); +} + void Bootstrap::init_jar(jni::Env& p_env, const jni::JObject& p_class_loader) { jvalue args[1] = {jni::to_jni_arg(p_class_loader)}; wrapped.call_void_method(p_env, INIT_JAR, args); diff --git a/src/jvm_wrapper/bootstrap.h b/src/jvm_wrapper/bootstrap.h index d3653ecd22..06ca67f633 100644 --- a/src/jvm_wrapper/bootstrap.h +++ b/src/jvm_wrapper/bootstrap.h @@ -7,12 +7,14 @@ JVM_INSTANCE_WRAPPER(Bootstrap, "godot.runtime.Bootstrap") { JVM_CLASS(Bootstrap) // clang-format off + JNI_VOID_METHOD(INITIALIZE_ENGINE_TYPES) JNI_VOID_METHOD(INIT_JAR) JNI_VOID_METHOD(INIT_NATIVE_IMAGE) JNI_VOID_METHOD(FINISH) JNI_OBJECT_METHOD(GET_VERSION) INIT_JNI_BINDINGS( + INIT_JNI_METHOD(INITIALIZE_ENGINE_TYPES, "initializeEngineTypes", "()V") INIT_JNI_METHOD(INIT_JAR, "initJar", "(Ljava/lang/ClassLoader;)V") INIT_JNI_METHOD(INIT_NATIVE_IMAGE, "initNativeImage", "()V") INIT_JNI_METHOD(GET_VERSION, "getVersion", "()Ljava/lang/String;") @@ -33,6 +35,7 @@ JVM_INSTANCE_WRAPPER(Bootstrap, "godot.runtime.Bootstrap") { Bootstrap(jni::Env& p_env, jni::JObject p_wrapped); ~Bootstrap() = default; + void initialize_engine_types(jni::Env& p_env); void init_jar(jni::Env& p_env, const jni::JObject& p_class_loader); void init_native_image(jni::Env& p_env); String get_version(jni::Env& p_env);