Skip to content

Add PackedByteArray conversion to PackedVector2Array, PackedVector3Array, PackedVector4Array and PackedColorArray #76075

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 1 commit into from
Jun 12, 2025

Conversation

OsakiTsukiko
Copy link
Contributor

@OsakiTsukiko OsakiTsukiko commented Apr 15, 2023

adds to_vector2_array, to_vector3_array, and to_color_array methods on PackedByteArray to convert to the corresponding types, as prior you could only convert from said type to PackedByteArray (with to_byte_array)

@OsakiTsukiko OsakiTsukiko requested review from a team as code owners April 15, 2023 00:46
@Calinou Calinou added this to the 4.x milestone Apr 15, 2023
@OsakiTsukiko
Copy link
Contributor Author

I haven't done one for PackedStringArray as I think the to_byte_array method on PackedStringArray is broken (I'll look some more into it tomorrow)

@bitsawer
Copy link
Member

Note that for Vector2/3/4 the underlaying data type is not always a float, it's real_t which can be a 32-bit float or 64-bit double depending on Godot build settings. But it might be best to just use full class size. So instead of using sizeof(float) * 2 for Vector2, just use sizeof(Vector2) directly. You'll also have to update the documentation for this.

PackedStringArray also only stores the String objects themselves, which are basically just pointers to the actual text data. It doesn't actually store tightly packed text data or anything like that. So there is probably no point in adding that converter.

Also remember to squish your commits into a single commit, see PR Workflow.

@OsakiTsukiko
Copy link
Contributor Author

Note that for Vector2/3/4 the underlaying data type is not always a float, it's real_t which can be a 32-bit float or 64-bit double depending on Godot build settings. But it might be best to just use full class size. So instead of using sizeof(float) * 2 for Vector2, just use sizeof(Vector2) directly. You'll also have to update the documentation for this.

Oh, I wasn't sure if I could use sizeof on custom data types

PackedStringArray also only stores the String objects themselves, which are basically just pointers to the actual text data. It doesn't actually store tightly packed text data or anything like that. So there is probably no point in adding that converter.

Hmm, yea, I thought so. Is there any point to the to_byte_array method on the String? I do not see much use for a byte array of references, and it's quite unintuitive, especially for beginners (It doesn't really specify anywhere in the docs that it only stores references, but that it packs data tightly (in-built docs), and even worse on the online docs: Returns a PackedByteArray with each string encoded as bytes.)

Also remember to squish your commits into a single commit, see PR Workflow.

Oh, Sure!

@OsakiTsukiko OsakiTsukiko force-pushed the PackedByteArray branch 2 times, most recently from 49ad6a7 to 03736a5 Compare April 15, 2023 09:35
@kleonc
Copy link
Member

kleonc commented Apr 28, 2023

Duplicate/alternative: #65811.

@ghost
Copy link

ghost commented Aug 30, 2023

why isnt this approved already? friend is running this PR on his own custom compiled version with no problem, this is essential for compute shaders, and compute shaders are a very big thing

@Calinou
Copy link
Member

Calinou commented Aug 30, 2023

why isnt this approved already? friend is running this PR on his own custom compiled version with no problem, this is essential for compute shaders, and compute shaders are a very big thing

There is a related proposal, but it's not very focused on this particular feature. Not much consensus has been reached, and we don't know whether this PR or #65811 is better yet.

@AThousandShips AThousandShips changed the title add PackedByteArray conversion to PackedVector2Array, PackedVector3Array and PackedColorArray Add PackedByteArray conversion to PackedVector2Array, PackedVector3Array and PackedColorArray May 16, 2024
@OsakiTsukiko OsakiTsukiko changed the title Add PackedByteArray conversion to PackedVector2Array, PackedVector3Array and PackedColorArray Add PackedByteArray conversion to PackedVector2Array, PackedVector3Array, PackedVector4Array and PackedColorArray May 16, 2024
Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

Generally I think this looks great! I'll see if I can't find the time soon to provide some hints for the documentation as I think it needs some suggestions, but once I've given those I'll be approving this as I think it's both a good feature and looks good

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

Some ideas for improving the documentation, the details on the precision is available on the respective vector type page so should be sufficient to link there

@AThousandShips
Copy link
Member

Please squash your commits into one, see here

@OsakiTsukiko
Copy link
Contributor Author

ok, I hope I did it right 🥲

@AThousandShips
Copy link
Member

Looks great! Just one last detail, could you please update the title of the commit to match the PR to make it a bit clearer without low level details of the code, you do this with:

git commit --amend
git push --force

Thank you and this looks great!

@akien-mga akien-mga modified the milestones: 4.x, 4.4 May 21, 2024
@nvl-ez
Copy link

nvl-ez commented Jan 22, 2025

Will it be merged? Since it is essential for working with compute shaders.

@AThousandShips AThousandShips modified the milestones: 4.4, 4.5 Jan 22, 2025
@AThousandShips
Copy link
Member

It will hopefully be merged early in 4.5, we're in feature freeze now

@tjpalmer
Copy link

It will hopefully be merged early in 4.5, we're in feature freeze now

Looking forward to this merge for 4.5!

@akien-mga akien-mga merged commit 786bf74 into godotengine:master Jun 12, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@OsakiTsukiko
Copy link
Contributor Author

Thanks! And congrats for your first merged Godot contribution 🎉

Thank you!
Tho it's not my first 😅

@akien-mga
Copy link
Member

First with this GitHub identity / username at least according to GitHub and the git log :D

@OsakiTsukiko
Copy link
Contributor Author

First with this GitHub identity / username at least according to GitHub and the git log :D

I thought that was weird, so I looked a bit into it, and it doesn't show in the log because it's not on the master branch. (Tho tbf that was just a small fix, so this is my first actual contribution. I was just interested as to how you knew this was my first commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PackedByteArray: add to_vector2_array and to_vector3_array functions
8 participants