Skip to content
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

Add coroutines await() to signals #660

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Conversation

CedNaru
Copy link
Member

@CedNaru CedNaru commented Aug 15, 2024

  • Add a new godot.couroutine module.
  • The Gradle plugin can now optionnally include it (and implicitly kotlinx.coroutines)
  • Add a Godot specific scope for coroutines
  • Add an await() functions to all signals that will suspend the coroutines until the signal is emitted.
  • await() can return the signal's arguments, directly (when 1), as a tuple (when 2 and 3), and as list (4+)

I also changed the package of Signal and Callable (I needed them for the await implementation so I took the opportunity).
So far everything has been in the same godot.core package except for those 2. Maybe it's an error and we should split everything into smaller packages but right now I wanted to focus on more consistency.
Note that the await() functions are in the godot.coroutines package as it's not considered the same library.

@CedNaru CedNaru changed the title Add godot-coroutine-library to project Add coroutines await() to signals Aug 15, 2024
@CedNaru CedNaru changed the base branch from master to feature/kotlin-lambda-callable August 15, 2024 11:01
@piiertho piiertho force-pushed the feature/kotlin-lambda-callable branch 2 times, most recently from 5a448ec to 4f5785c Compare August 21, 2024 06:07
Base automatically changed from feature/kotlin-lambda-callable to master August 21, 2024 10:14
@CedNaru CedNaru force-pushed the feature/godot-coroutine branch 3 times, most recently from 6cc3d6e to 5db9b2a Compare September 13, 2024 23:39
@CedNaru CedNaru force-pushed the feature/godot-coroutine branch 2 times, most recently from 018d284 to 587e9f3 Compare September 14, 2024 11:56
@CedNaru CedNaru marked this pull request as ready for review September 14, 2024 18:07
Copy link
Contributor

@chippmann chippmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check that none of the IDE checks are requiring the signals to be in the signal package?

Comment on lines +35 to +44
tasks {
compileKotlin {
dependsOn(":godot-library:generateAPI")
}

// here so the sourcesJar task has an explicit dependency on the generateApi task. Needed since gradle 8
withType<Jar> {
dependsOn(":godot-library:generateAPI")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block should not be needed as you depend on the godot-library project which itself defines these dependency constraints.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to remove it but it doesn't want to build without that.

I get the following error:

What went wrong:
A problem was found with the configuration of task ':kt:godot-coroutine-library:sourcesJar' (type 'Jar').

  • Gradle detected a problem with the following location: 'D:\Godot\Module\kotlin\modules\kotlin_jvm\kt\godot-coroutine-library\src\main\kotlin'.

    Reason: Task ':kt:godot-coroutine-library:sourcesJar' uses this output of task ':kt:godot-library:generateAPI' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:

    1. Declare task ':kt:godot-library:generateAPI' as an input of ':kt:godot-coroutine-library:sourcesJar'.
    2. Declare an explicit dependency on ':kt:godot-library:generateAPI' from ':kt:godot-coroutine-library:sourcesJar' using Task#dependsOn.
    3. Declare an explicit dependency on ':kt:godot-library:generateAPI' from ':kt:godot-coroutine-library:sourcesJar' using Task#mustRunAfter.

Comment on lines +24 to 45
override fun apply(target: Project) = with(target) {
checkKotlinVersionCompatibility()

val extension = target.extensions.create("godot", GodotExtension::class.java).also {
it.configureExtensionDefaults(target)
val extension = extensions.create("godot", GodotExtension::class.java).also {
it.configureExtensionDefaults(this)
}

target.configureThirdPartyPlugins()
target.setupConfigurationsAndCompilations()
target.setupTasks()
configureThirdPartyPlugins()
setupConfigurationsAndCompilations()
setupTasks()

// registers the tooling model builder, so it can be used by the ide plugin
target.afterEvaluate {
afterEvaluate {
if (godotJvmExtension.enableGodotCoroutines.get()) {
dependencies.add(
"implementation",
dependencies.create("com.utopia-rise:${godotCoroutineLibraryArtifactName}:${GodotBuildProperties.assembledGodotKotlinJvmVersion}")
)
}
registry.register(
PropertiesModelBuilder(
isFqNameRegistrationEnabled = extension.isFqNameRegistrationEnabled.get(),
Copy link
Contributor

@chippmann chippmann Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave the explicit target be. There were some scoping issues IIRC before and i would not like to introduce such issues again

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But as i cannot remember them, you can also leave it be like that. I do not have a strong opinion here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have any problem running it. It just felt normal switching the receiver when almost all calls use "target"

@CedNaru CedNaru linked an issue Sep 18, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a coroutine context for Godot and its signals.
3 participants