utopia-rise / godot-kotlin-jvm

Godot Kotlin JVM Module
MIT License
636 stars 44 forks source link

Investigate `native_structures` in `api.json` #309

Open chippmann opened 2 years ago

chippmann commented 2 years ago

The new api.json from the GDExtensions includes a block native_structures which we do not yet understand for what it's for. We can't just ignore those types in there as they are used as parameters/return types in other methods in the api.

We need to investicate (and document) for what these thypes are, and how we should handle/treat them.

This is required to finish the work in https://github.com/utopia-rise/godot-kotlin-jvm/issues/307

CedNaru commented 2 years ago

Native structures are former low level internal structures used by Godot. For the sake of having extensions able to override some servers or other lower level features, some structures have been exposed to the API. They are considered to be different from the regular API because they are used as pointer parameters in different Godot methods so only languages with direct memory management can use them.

Those structures are supposed to be small but in huge number ( thousand at once), we can't simply implement them as regular Kotlin classes, it would kill the memory and the GC. The only hope we have to use them and to use the future value classes but before that I don't think it's realistic to try anything with them. Short term solution imo is to simply ignore methods using native structures in the API generation process.

CedNaru commented 2 years ago

Initial PR made by Reduz regarding that. I haven't check the recent change to them https://github.com/godotengine/godot/pull/52036

The reference implementation in that PR is the AudioBuffer structure. It allows an extension to create it own sound player by implementating the method void AudioStreamPlayback::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) In that case it's a pointer to an array of AudioFrame, a very classic C like way to send data. You literally have one instance of the structure for each sound data (it means thousands per second)

piiertho commented 2 years ago

Thanks for explaination. I was wondering how I would treat these pointers regarding buffer etc, but we'll delay them waiting for value classes.

@chippmann should we keep this issue opened in order to keep in mind for the time value class are here ?

chippmann commented 1 year ago

Yeah I'd keep that open for now