Skip to content

Commit 52892f6

Browse files
CedNarupiiertho
andauthored
Add coroutines await() to signals (#660)
* feat: Implement KotlinCallableCustom to enable lambda callables * Add godot-coroutine-library to project * Align Signal and Callable packages on other core types. --------- Co-authored-by: Pierre-Thomas Meisels <meisels27@yahoo.fr>
1 parent 359d785 commit 52892f6

File tree

318 files changed

+1735
-883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

318 files changed

+1735
-883
lines changed

.clang-tidy

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,cppcoreguidelines-pro-type-member-init,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-nullptr,readability-braces-around-statements,readability-redundant-member-init'
3+
WarningsAsErrors: ''
4+
HeaderFilterRegex: ''
5+
AnalyzeTemporaryDtors: false
6+
FormatStyle: none
7+
CheckOptions:
8+
- key: cert-dcl16-c.NewSuffixes
9+
value: 'L;LL;LU;LLU'
10+
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
11+
value: '0'
12+
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
13+
value: '1'
14+
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
15+
value: '1'
16+
- key: cppcoreguidelines-pro-type-member-init.IgnoreArrays
17+
value: '1'
18+
- key: cppcoreguidelines-pro-type-member-init.UseAssignment
19+
value: '1'
20+
- key: google-readability-function-size.StatementThreshold
21+
value: '800'
22+
- key: google-readability-namespace-comments.ShortNamespaceLines
23+
value: '10'
24+
- key: google-readability-namespace-comments.SpacesBeforeComments
25+
value: '2'
26+
- key: modernize-loop-convert.MaxCopySize
27+
value: '16'
28+
- key: modernize-loop-convert.MinConfidence
29+
value: reasonable
30+
- key: modernize-loop-convert.NamingStyle
31+
value: CamelCase
32+
- key: modernize-pass-by-value.IncludeStyle
33+
value: llvm
34+
- key: modernize-replace-auto-ptr.IncludeStyle
35+
value: llvm
36+
- key: modernize-use-bool-literals.IgnoreMacros
37+
value: '0'
38+
- key: modernize-use-default-member-init.IgnoreMacros
39+
value: '0'
40+
- key: modernize-use-default-member-init.UseAssignment
41+
value: '1'
42+
- key: modernize-use-nullptr.NullMacros
43+
value: 'NULL'
44+
- key: readability-braces-around-statements.ShortStatementLines
45+
value: '0'
46+
...
47+

.github/workflows/deploy_jvm.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ jobs:
7777
run: |
7878
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-library:publish publish -Prelease
7979
80+
- name: Publish godot-coroutine-library debug
81+
shell: sh
82+
run: |
83+
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-coroutine-library:publish publish -Pdebug
84+
85+
- name: Publish godot-coroutine-library release
86+
shell: sh
87+
run: |
88+
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-coroutine-library:publish publish -Prelease
89+
8090
- name: Publish godot-plugins-common
8191
shell: sh
8292
run: |

docs/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ nav:
7070
- Signals: user-guide/signals.md
7171
- Functions: user-guide/functions.md
7272
- Exporting: user-guide/exporting.md
73+
- Coroutines: user-guide/coroutines.md
7374
- Debugging: user-guide/debugging.md
7475
- Consuming libraries: user-guide/consuming-libraries.md
7576
- Versioning: user-guide/versioning.md
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Using Kotlin coroutines in Godot
2+
3+
Coroutines are an opt-in feature that require an additional import in Kotlin.
4+
We follow the same logic and keep them separated from the main library.
5+
6+
To use it, you need to add the following to your build.gradle:
7+
8+
```kotlin
9+
godot {
10+
enableGodotCoroutines.set(true)
11+
}
12+
```
13+
14+
It will automatically import our coroutine library and `kotlinx.coroutine` as a dependency.
15+
That library adds a Godot specific coroutine scope and extensions to signals.
16+
To use them, you simply need to write the following:
17+
18+
```kotlin
19+
fun myMethod() = godotCoroutine {
20+
doSomething()
21+
mySignal.await() // the current coroutine will suspend until that signal is emitted.
22+
doSomething2()
23+
}
24+
```

harness/tests/Spatial.tscn

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
[ext_resource type="Script" path="res://scripts/godot/tests/Invocation.gdj" id="1"]
44

5-
[sub_resource type="NavigationMesh" id="NavigationMesh_prd4u"]
5+
[sub_resource type="NavigationMesh" id="NavigationMesh_1ex3u"]
66

7-
[sub_resource type="NavigationMesh" id="NavigationMesh_tuyoa"]
7+
[sub_resource type="NavigationMesh" id="NavigationMesh_q3pqa"]
88

9-
[sub_resource type="NavigationMesh" id="NavigationMesh_bh4po"]
9+
[sub_resource type="NavigationMesh" id="NavigationMesh_hn8kg"]
1010

11-
[sub_resource type="NavigationMesh" id="NavigationMesh_bdc7j"]
11+
[sub_resource type="NavigationMesh" id="NavigationMesh_87cay"]
1212

13-
[sub_resource type="NavigationMesh" id="NavigationMesh_abcao"]
13+
[sub_resource type="NavigationMesh" id="NavigationMesh_b12lh"]
1414

1515
[node name="Spatial" type="Node3D" node_paths=PackedStringArray("button")]
1616
script = ExtResource("1")
1717
button = NodePath("CanvasLayer/Button")
18-
resource_test = SubResource("NavigationMesh_prd4u")
18+
resource_test = SubResource("NavigationMesh_1ex3u")
1919
jvm_id = 319061373
20-
nav_meshes = Array[NavigationMesh]([SubResource("NavigationMesh_tuyoa")])
21-
nullable_array = Array[NavigationMesh]([SubResource("NavigationMesh_bh4po"), null])
20+
nav_meshes = Array[NavigationMesh]([SubResource("NavigationMesh_q3pqa")])
21+
nullable_array = Array[NavigationMesh]([SubResource("NavigationMesh_hn8kg"), null])
2222
nav_meshes_dictionary = {
23-
"AwesomeNavmesh": SubResource("NavigationMesh_bdc7j")
23+
"AwesomeNavmesh": SubResource("NavigationMesh_87cay")
2424
}
2525
nullable_dictionary = {
26-
"notnull": SubResource("NavigationMesh_abcao"),
26+
"notnull": SubResource("NavigationMesh_b12lh"),
2727
"null": null
2828
}
2929

harness/tests/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import org.jetbrains.kotlin.konan.target.HostManager
2-
import java.io.OutputStream
32

43
plugins {
54
// no need to apply kotlin jvm plugin. Our plugin already applies the correct version for you
@@ -14,6 +13,7 @@ repositories {
1413
godot {
1514
registrationFileBaseDir.set(projectDir.resolve("scripts").also { it.mkdirs() })
1615
isRegistrationFileHierarchyEnabled.set(true)
16+
enableGodotCoroutines.set(true)
1717

1818
//uncomment to test android
1919
// isAndroidExportEnabled.set(true)

harness/tests/scripts/CoreTypePropertyChecks.gdj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ signals = [
1616
]
1717
properties = [
1818
exported_normal_core_type,
19-
normal_core_type,
20-
normal_non_null_core_type
19+
normal_core_type
2120
]
2221
functions = [
2322

harness/tests/scripts/godot/tests/Invocation.gdj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,5 @@ functions = [
166166
set_vector3_in_packed_array,
167167
resize_vector3_packed_array,
168168
is_sent_xr_same_instance_as_jvm_singleton,
169-
nullable_string_is_null,
170-
nullable_return_type,
171169
create_variant_array_of_user_type
172-
]
170+
]

harness/tests/scripts/godot/tests/JavaTestClass.gdj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ properties = [
2525
exported_string,
2626
exported_byte,
2727
exported_button,
28-
signal_emitted
28+
signal_emitted,
29+
variant_array,
30+
dictionary
2931
]
3032
functions = [
3133
greeting,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// THIS FILE IS GENERATED! DO NOT EDIT OR DELETE IT. EDIT OR DELETE THE ASSOCIATED SOURCE CODE FILE INSTEAD
2+
// 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.
3+
4+
registeredName = CoroutineTest
5+
fqName = godot.tests.coroutine.CoroutineTest
6+
relativeSourcePath = src/main/kotlin/godot/tests/coroutine/CoroutineTest.kt
7+
baseType = Object
8+
supertypes = [
9+
godot.Object,
10+
godot.core.KtObject,
11+
kotlin.Any
12+
]
13+
signals = [
14+
signal_without_parameter,
15+
signal_with_parameters,
16+
signal_with_many_parameters
17+
]
18+
properties = [
19+
step
20+
]
21+
functions = [
22+
start_coroutine_without_parameter,
23+
start_coroutine_with_parameters,
24+
start_coroutine_with_many_parameters
25+
]

0 commit comments

Comments
 (0)