godot.core.Constructors.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of godot-library-debug Show documentation
Show all versions of godot-library-debug Show documentation
Contains godot api as kotlin classes and jvm cpp interaction code.
@file:Suppress("UNCHECKED_CAST", "unused")
package godot.core
import godot.core.memory.TransferContext
import godot.tools.common.constants.Constraints
import godot.util.VoidPtr
import godot.util.threadLocal
abstract class KtConstructor(
vararg argsTypes: Pair
) {
val parameterCount: Int = argsTypes.size
val parameterTypes: Array = argsTypes.map { it.first }.toTypedArray()
val parameterNullables: Array = argsTypes.map { it.second }.toTypedArray()
abstract operator fun invoke(): T
fun construct(rawPtr: VoidPtr, instanceId: Long) = KtObject.instantiateWith(rawPtr, instanceId) {
TransferContext.readArguments(parameterTypes, parameterNullables, paramsArray)
val instance = invoke()
resetParamsArray()
instance
}
companion object {
val paramsArray by threadLocal { arrayOfNulls(Constraints.MAX_CONSTRUCTOR_ARG_COUNT) }
fun resetParamsArray() {
paramsArray.fill(null)
}
}
}
class KtConstructor0(
private val constructor: () -> T
) : KtConstructor() {
override fun invoke(): T {
return constructor()
}
}
class KtConstructor1(
private val constructor: (P0) -> T,
p0Type: Pair
) : KtConstructor(p0Type) {
override fun invoke(): T {
return constructor(
paramsArray[0] as P0
)
}
}
class KtConstructor2(
private val constructor: (P0, P1) -> T,
p0Type: Pair,
p1Type: Pair
) : KtConstructor(p0Type, p1Type) {
override fun invoke(): T {
return constructor(
paramsArray[0] as P0,
paramsArray[1] as P1
)
}
}
class KtConstructor3(
private val constructor: (P0, P1, P2) -> T,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair
) : KtConstructor(p0Type, p1Type, p2Type) {
override fun invoke(): T {
return constructor(
paramsArray[0] as P0,
paramsArray[1] as P1,
paramsArray[2] as P2
)
}
}
class KtConstructor4(
private val constructor: (P0, P1, P2, P3) -> T,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair
) : KtConstructor(p0Type, p1Type, p2Type, p3Type) {
override fun invoke(): T {
return constructor(
paramsArray[0] as P0,
paramsArray[1] as P1,
paramsArray[2] as P2,
paramsArray[3] as P3
)
}
}
class KtConstructor5(
private val constructor: (P0, P1, P2, P3, P4) -> T,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair
) : KtConstructor(p0Type, p1Type, p2Type, p3Type, p4Type) {
override fun invoke(): T {
return constructor(
paramsArray[0] as P0,
paramsArray[1] as P1,
paramsArray[2] as P2,
paramsArray[3] as P3,
paramsArray[4] as P4
)
}
}
class KtConstructor6(
private val constructor: (P0, P1, P2, P3, P4, P5) -> T,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
) : KtConstructor(p0Type, p1Type, p2Type, p3Type, p4Type, p5Type) {
override fun invoke(): T {
return constructor(
paramsArray[0] as P0,
paramsArray[1] as P1,
paramsArray[2] as P2,
paramsArray[3] as P3,
paramsArray[4] as P4,
paramsArray[5] as P5,
)
}
}
class KtConstructor7(
private val constructor: (P0, P1, P2, P3, P4, P5, P6) -> T,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
) : KtConstructor(p0Type, p1Type, p2Type, p3Type, p4Type, p5Type, p6Type) {
override fun invoke(): T {
return constructor(
paramsArray[0] as P0,
paramsArray[1] as P1,
paramsArray[2] as P2,
paramsArray[3] as P3,
paramsArray[4] as P4,
paramsArray[5] as P5,
paramsArray[6] as P6,
)
}
}
class KtConstructor8(
private val constructor: (P0, P1, P2, P3, P4, P5, P6, P7) -> T,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
) : KtConstructor(p0Type, p1Type, p2Type, p3Type, p4Type, p5Type, p6Type, p7Type) {
override fun invoke(): T {
return constructor(
paramsArray[0] as P0,
paramsArray[1] as P1,
paramsArray[2] as P2,
paramsArray[3] as P3,
paramsArray[4] as P4,
paramsArray[5] as P5,
paramsArray[6] as P6,
paramsArray[7] as P7,
)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy