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 support for indexed properties in api-generator #312

Merged
merged 2 commits into from
May 10, 2022

Conversation

silentorb
Copy link
Contributor

@silentorb silentorb commented Mar 16, 2022

Some of Godot's property getter/setters have an additional index parameter, specified with the index field of the property metadata.

For those properties the api-generator within godot-kotlin-jvm is not including the index arguments in the generated property code, causing the setters for indexed properties to throw exceptions.

The indexed getters seem to be working without the extra index property. I'm not sure how that is.

This PR adds code to api-generator's Property::generate so that the generated code includes the indexed arguments for properties that need them.

For example, the code generated for SpatialMaterial::albedoTexture (which has a hard-coded index of 0) looks like this after the PR:

  public open var albedoTexture: Texture?
    get() {
      TransferContext.writeArguments(JVM_INT to 0)
      TransferContext.callMethod(rawPtr,
          ENGINEMETHOD_ENGINECLASS_SPATIALMATERIAL_GET_ALBEDO_TEXTURE, OBJECT)
      return TransferContext.readReturnValue(OBJECT, true) as Texture?
    }
    set(`value`) {
      TransferContext.writeArguments(JVM_INT to 0, OBJECT to value)
      TransferContext.callMethod(rawPtr,
          ENGINEMETHOD_ENGINECLASS_SPATIALMATERIAL_SET_ALBEDO_TEXTURE, NIL)
    }

Where before those two writeArguments lines were:

TransferContext.writeArguments()

and

TransferContext.writeArguments(OBJECT to value)

Even though only the setters were throwing exceptions, I also added the index parameter to the getter because that seems like the more accurate call. I haven't been able to verify yet but maybe there is some additional code on the C++ side that is filling in the gaps for the indexed getter calls?

My understanding is that godot-kotlin-jvm is using Long instead of Int for interop, though in this case using Long for the indexed properties was failing while using Int is working. I'm guessing maybe that's because the index parameter is not a formally exposed element of the Godot API and is instead a lower-level implementation detail.

For the current version of the API this PR affects 32 generated files. I left the generated files out of the PR to keep the PR minimal but can add them if needed.

I've tested some of the indexed property cases and everything I have tested is working. I have not comprehensively tested every property affected by this PR.

@silentorb silentorb changed the title Add support for indexed properties in api-generator Add support for indexed property setters in api-generator Mar 16, 2022
@piiertho
Copy link
Member

Hello ! That’s a good catch ! Thanks a lot !
What error did you have with Long ? This should work with it, JVM_INT is here only for convenience, it will send a long in buffer.
Can you please push modified classes ?

@silentorb silentorb changed the title Add support for indexed property setters in api-generator Add support for indexed properties in api-generator Mar 17, 2022
@silentorb
Copy link
Contributor Author

silentorb commented Mar 17, 2022

@piiertho The generated code changes are now included.

The error I had been running into with Long was with the buffer writing where code was expecting a Long but receiving an Int. At the time I had though there must be some lower level API expecting an Int, but on further inspection the mismatch was with my own added code, which was using Int literals when it should have been using Long literals.

I updated my changes to consistently use Longs and that is working now.

After further testing, it turns out that I must have mixed up which builds I was testing when I thought the indexed getters were originally working, and after more testing can now confirm that the indexing problem does also apply to the getters so the changes in this PR are needed for both getters and setters.

For the record, here's a link to the code that is generating the code that is raising the error this PR is addressing: https://github.com/godotengine/godot/blob/3.4.2-stable/core/make_binders.py#L48-L53.

As a side note, when I peruse the affected properties, it looks like mostly less common Godot properties use this indexing mechanism. I've been using Godot Kotlin JVM for over six months and only recently ran into this issue.

@piiertho
Copy link
Member

Build errors on windows are not from your side. I asked on an existing godot issue why this is happening: godotengine/godot#58595

Linux check is error we have because gpg key is repo private :/

Anyway, everything looks good to me.

piiertho
piiertho previously approved these changes Mar 19, 2022
chippmann
chippmann previously approved these changes Apr 10, 2022
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.

Thx a lot for the fix!

@piiertho
Copy link
Member

piiertho commented Apr 11, 2022

@silentorb can you rebase branch on master ?

CedNaru
CedNaru previously approved these changes Apr 11, 2022
@silentorb silentorb dismissed stale reviews from CedNaru, chippmann, and piiertho via 2b1bd44 April 24, 2022 17:39
@silentorb silentorb force-pushed the enhancement/indexed-properties branch from ad10b72 to 2b1bd44 Compare April 24, 2022 17:39
@silentorb
Copy link
Contributor Author

@piiertho: The PR is rebased with the latest build changes.

@piiertho piiertho merged commit a21b048 into utopia-rise:master May 10, 2022
@piiertho
Copy link
Member

piiertho commented May 10, 2022

Thx for contribution !

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.

4 participants