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

UUIDCollisionResolver #227

Open
NukeBird opened this issue Mar 28, 2019 · 2 comments
Open

UUIDCollisionResolver #227

NukeBird opened this issue Mar 28, 2019 · 2 comments

Comments

@NukeBird
Copy link

NukeBird commented Mar 28, 2019

I'm trying to integrate cereal serialization library with entityx

Also I have read #117, #14 and #25

I got four basic ideas:

  1. We should use custom UUID component instead of Entity id
  2. For serialization we should check manually if entity has specific components (and, well, iterate through all of them)
  3. (because of 2) We should manually decide what components should be registered and how components should be serialized/deserialized
  4. To iterate over all alive entities we must use entities_for_debugging(). It marked "not very fast, so should only be used for debugging", but well I don't see any other alternatives for serialization

My big question is: how elegantly implement UUIDCollisionResolver? I mean, UUIDGenerator automatically attaches UUID component for every new Entity, and when we try to deserialize some entities from external file here is high probability that UUIDs of that entities are already taken

Also, some components can store UUID in themselves, so UUID must be replaced with a correct one too

To be more specific, lets say we have such components:

struct UUID
{
    //UUID(...) {...}

    uint32_t value;
};

struct TreeNode
{
    //TreeNode(...) {...}

    std::string name;
};

struct Transform
{
    //Transform(...) {...}

    glm::vec3 position;
    glm::vec3 scale;
    glm::vec3 rotation;

    bool is_dirty;
    glm::mat4 cache;

    UUID parent;
    std::list<UUID> childs; 
};
@NukeBird
Copy link
Author

NukeBird commented Mar 28, 2019

I have such idea:

  1. Create an DeserializationStarted and DeserializationEnded events
  2. When DeserializationStarted emits, UUIDGenerator will stop automatically attach new UUIDs + all new entities will be stored in temporal buffer
  3. When DeserializationEnded emits, temporal buffer should be merged with "global id buffer" with collision resolving step (we can use std::map which will map UUID to the "corrected UUID" (they are the same if here is no collisions))

@NukeBird
Copy link
Author

NukeBird commented Mar 28, 2019

But, well, I think here must be another way to do exactly same thing

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

No branches or pull requests

1 participant