-
Notifications
You must be signed in to change notification settings - Fork 55
Add coroutines await() to signals #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
590edb1
feat: Implement KotlinCallableCustom to enable lambda callables
piiertho 6c753bb
Add godot-coroutine-library to project
CedNaru d8b34f0
Add basic test for Coroutine
CedNaru 92aa792
Add basic signal waiter
CedNaru ed24606
Fix rebase
CedNaru dd672db
Align Signal and Callable packages on other core types.
CedNaru 27a9e8a
Generate signal awaiters
CedNaru f82ec23
Fix test
CedNaru 21283d1
Fix JNI signatures
CedNaru 55c37ad
Fix test
CedNaru c50b837
Add coroutine tests
CedNaru 6317976
Fix test again
CedNaru 0012ba2
Improve test
CedNaru f017f4e
Add return type to await()
CedNaru 02b0833
Update CI
CedNaru 247e889
Add Doc
CedNaru 9c904a4
Replace await() return type with tuples
CedNaru dd9170a
Improve GodotCoroutine and tests
CedNaru 88c29ee
Improve generation
CedNaru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| --- | ||
| 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' | ||
| WarningsAsErrors: '' | ||
| HeaderFilterRegex: '' | ||
| AnalyzeTemporaryDtors: false | ||
| FormatStyle: none | ||
| CheckOptions: | ||
| - key: cert-dcl16-c.NewSuffixes | ||
| value: 'L;LL;LU;LLU' | ||
| - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField | ||
| value: '0' | ||
| - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors | ||
| value: '1' | ||
| - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic | ||
| value: '1' | ||
| - key: cppcoreguidelines-pro-type-member-init.IgnoreArrays | ||
| value: '1' | ||
| - key: cppcoreguidelines-pro-type-member-init.UseAssignment | ||
| value: '1' | ||
| - key: google-readability-function-size.StatementThreshold | ||
| value: '800' | ||
| - key: google-readability-namespace-comments.ShortNamespaceLines | ||
| value: '10' | ||
| - key: google-readability-namespace-comments.SpacesBeforeComments | ||
| value: '2' | ||
| - key: modernize-loop-convert.MaxCopySize | ||
| value: '16' | ||
| - key: modernize-loop-convert.MinConfidence | ||
| value: reasonable | ||
| - key: modernize-loop-convert.NamingStyle | ||
| value: CamelCase | ||
| - key: modernize-pass-by-value.IncludeStyle | ||
| value: llvm | ||
| - key: modernize-replace-auto-ptr.IncludeStyle | ||
| value: llvm | ||
| - key: modernize-use-bool-literals.IgnoreMacros | ||
| value: '0' | ||
| - key: modernize-use-default-member-init.IgnoreMacros | ||
| value: '0' | ||
| - key: modernize-use-default-member-init.UseAssignment | ||
| value: '1' | ||
| - key: modernize-use-nullptr.NullMacros | ||
| value: 'NULL' | ||
| - key: readability-braces-around-statements.ShortStatementLines | ||
| value: '0' | ||
| ... | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| ## Using Kotlin coroutines in Godot | ||
|
|
||
| Coroutines are an opt-in feature that require an additional import in Kotlin. | ||
| We follow the same logic and keep them separated from the main library. | ||
|
|
||
| To use it, you need to add the following to your build.gradle: | ||
|
|
||
| ```kotlin | ||
| godot { | ||
| enableGodotCoroutines.set(true) | ||
| } | ||
| ``` | ||
|
|
||
| It will automatically import our coroutine library and `kotlinx.coroutine` as a dependency. | ||
| That library adds a Godot specific coroutine scope and extensions to signals. | ||
| To use them, you simply need to write the following: | ||
|
|
||
| ```kotlin | ||
| fun myMethod() = godotCoroutine { | ||
| doSomething() | ||
| mySignal.await() // the current coroutine will suspend until that signal is emitted. | ||
| doSomething2() | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
harness/tests/scripts/godot/tests/coroutine/CoroutineTest.gdj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // 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 = CoroutineTest | ||
| fqName = godot.tests.coroutine.CoroutineTest | ||
| relativeSourcePath = src/main/kotlin/godot/tests/coroutine/CoroutineTest.kt | ||
| baseType = Object | ||
| supertypes = [ | ||
| godot.Object, | ||
| godot.core.KtObject, | ||
| kotlin.Any | ||
| ] | ||
| signals = [ | ||
| signal_without_parameter, | ||
| signal_with_parameters, | ||
| signal_with_many_parameters | ||
| ] | ||
| properties = [ | ||
| step | ||
| ] | ||
| functions = [ | ||
| start_coroutine_without_parameter, | ||
| start_coroutine_with_parameters, | ||
| start_coroutine_with_many_parameters | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
harness/tests/src/main/kotlin/godot/tests/coroutine/CoroutineTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package godot.tests.coroutine | ||
|
|
||
|
|
||
| import godot.annotation.RegisterClass | ||
| import godot.core.Dictionary | ||
| import godot.core.VariantArray | ||
| import godot.Object | ||
| import godot.annotation.RegisterFunction | ||
| import godot.annotation.RegisterProperty | ||
| import godot.annotation.RegisterSignal | ||
| import godot.core.Vector2 | ||
| import godot.core.signal | ||
| import godot.coroutines.GodotCoroutine | ||
| import godot.coroutines.await | ||
| import kotlinx.coroutines.CoroutineStart | ||
|
|
||
| @RegisterClass | ||
| class CoroutineTest : Object() { | ||
|
|
||
| @RegisterSignal | ||
| val signalWithoutParameter by signal() | ||
|
|
||
| @RegisterSignal | ||
| val signalWithOneParameter by signal<Int>("int") | ||
|
|
||
| @RegisterSignal | ||
| val signalWithManyParameters by signal<Int, Float, Vector2, String>("int", "float", "vector2", "string") | ||
|
|
||
| @RegisterProperty | ||
| var step: Int = 0 | ||
|
|
||
| @RegisterFunction | ||
| fun startCoroutineWithoutParameter() = GodotCoroutine { | ||
| step = 1 | ||
| signalWithoutParameter.await() | ||
| step = 2 | ||
| } | ||
|
|
||
| @RegisterFunction | ||
| fun startCoroutineWithOneParameter() = GodotCoroutine { | ||
| step = 3 | ||
| step = signalWithOneParameter.await() | ||
| } | ||
|
|
||
| @RegisterFunction | ||
| fun startCoroutineWithManyParameters() = GodotCoroutine { | ||
| step = 5 | ||
| val (int, _, _, _) = signalWithManyParameters.await() | ||
| step = int | ||
| } | ||
|
|
||
| @RegisterFunction | ||
| fun startCoroutineUndispatched() = GodotCoroutine(start = CoroutineStart.UNDISPATCHED) { | ||
| step = 7 | ||
| signalWithoutParameter.await() | ||
| step = 8 | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.