-
-
Notifications
You must be signed in to change notification settings - Fork 97
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 a built-in UUIDv4 function #1654
Comments
I too have started to use UUIDs in my projects in places where I'll synchronize objects with multiple clients and think there is a need for UUIDs in game development and that they should be added to Godot. So which implementation are you proposing? The PR has a UUID v1 (somewhat) based on timestamp while your example script implements v4 according to RFC-4122. I think v4 should be used. |
It is the UUIDv4 implementation Im talking about. |
I agree uuidv4 should be implemented. I'd probably just call the function |
I use uuid4 in godot in a single-player game to generate identifiers for player-created levels so they can be shared without needing a centralized id-giver. 👍 for this |
Can you edit the PR then to provide an implementation analogous to the GDScript? |
I agree, it would be simpler to call it |
It is done the same way, without collision. |
Yes, but timestamp plus a rand is not v4. See the RFC for a reference:
|
So you want something like that? uint8_t bytes[16] = {
// time low
(uint8_t)(Math::rand() & 0xff),
(uint8_t)(Math::rand() & 0xff),
(uint8_t)(Math::rand() & 0xff),
(uint8_t)(Math::rand() & 0xff),
// time mid
(uint8_t)(Math::rand() & 0xff),
(uint8_t)(Math::rand() & 0xff),
// time high
(uint8_t)(Math::rand() & 0xff),
(uint8_t)(Math::rand() & 0xff),
// clock seq hi
(uint8_t)((Math::rand() & 0x0f) | 0x40),
// clock seq low
(uint8_t)(Math::rand() & 0xff),
// node
(uint8_t)((Math::rand() & 0x3f) | 0x80),
(uint8_t)(Math::rand() & 0xff),
(uint8_t)(Math::rand() & 0xff),
(uint8_t)(Math::rand() & 0xff),
(uint8_t)(Math::rand() & 0xff),
(uint8_t)(Math::rand() & 0xff)
}; |
That looks like a uuidV4 implementation. If you want sequential UUIDs based on timestamp you can add them as a V1 implementation that includes the |
Yukitty@godot-addon-crypto_uuid_v4 So instead, here's an implementation that provides UUID refrence objects with an |
Ok now I feel like someone is watching me work. I have stumbled upon Really like your implementation and I'll probably just use your addon. Regarding the immutability aspect I think you can prevent outside access to |
Forceful no-op setters are not the GDScript way. 😜 My actual issue is, wanting to make sure that every That would make simple object comparisons super easy, since you could just do |
GDScript has a known bug for this as well godotengine/godot#41319, so I try to avoid using getter without a setter in GDScript. |
Random implementations could be in theory added in |
I don't want to flood the godot-proposals repository. And since this proposal doesn't seem to get implemented anytime soon, I'd rather close it to give more visibility to other proposals who might be implemented. |
If anyone is interested I have a custom build where I use a global singleton Rand class (similar to what Xrayez proposes) with a lot more random functions including uuidv4 called like this |
Describe the project you are working on:
City Game Studio
Describe the problem or limitation you are having in your project:
I don't have any problem, but a uuidv4 function would be great since Im using it extensively.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Having a uuidv4 builtin function within the engine itself improved the performances and removed most of the stuttering.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
godotengine/godot#42408
If this enhancement will not be used often, can it be worked around with a few lines of script?:
https://github.com/binogure-studio/godot-uuid
Is there a reason why this should be core and not an add-on in the asset library?:
I have worked on many games before (solo and with a small team of 50 people), and all of them needed a uuidv4 generator. So, if it is widely used it should be part of the engine itself.
The text was updated successfully, but these errors were encountered: