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

🔨 EntityId tracking structure #6167

Open
3 tasks done
zach2good opened this issue Aug 25, 2024 · 7 comments
Open
3 tasks done

🔨 EntityId tracking structure #6167

zach2good opened this issue Aug 25, 2024 · 7 comments
Labels
enhancement New feature request

Comments

@zach2good
Copy link
Contributor

I affirm:

  • I understand that if I do not agree to the following points by completing the checkboxes my issue will be ignored.
  • I have read and understood the Contributing Guide and the Code of Conduct.
  • I have searched existing issues to see if the issue has already been opened, and I have checked the commit log to see if the issue has been resolved since my server was last updated.

Describe the feature

A recurring theme of the server is the caching/looking up of pointers to invalid/gone entities. As much as I like to harp on about the abuse of DEs, invalid pointers to Pets and Trusts are still possible, so it is a legitimate problem. We need a mechanism to safely hold references to entities that might no longer exist when you try to look them up.

struct EntityId
{
    u64 hash; // Incremental is enough here. A process will never be up long enough for this to overflow. If it does we've won the stability game.
    u16 zoneId;
    u16 index;
};

TODO: A global (per process) tracker of entities.

TODO: Lookup mechanism.

TODO: On entity destruction, look up your own lookup entry and invalidate it.

@zach2good zach2good added the enhancement New feature request label Aug 25, 2024
@zach2good
Copy link
Contributor Author

I'm not sure if it's even possible to stop people from taking references/pointers to objects. We wouldn't even want std::optional. We'd need:

auto entityToken = PEntity->getToken();

// later

if (auto PEntity = entityToken.resolve())
{
    // Successfully looked-up
}

// later

if (!entityToken.valid())
{
    // Log
    return;
}

@zach2good
Copy link
Contributor Author

Does this mean we'll move all entities out of Zone->ZoneEntities? Unknown.

@zach2good
Copy link
Contributor Author

Creation/lookup/removal of these tokens needs to be constant time. It needs to proliferate into Lua

@zach2good
Copy link
Contributor Author

Partially related to: #5065

@zach2good
Copy link
Contributor Author

A small place we could road-test this is PChar->PWideScanTarget. It's only used in 10 lines or so. I was thinking about whether or not we need a spawntime or creationtime stored, but the u64 incremental id serves the same purpose.

@zach2good
Copy link
Contributor Author

We also already have someone's attempt at this:

// TODO:it is possible to make this structure part of the class, instead of the current ID and Targid, but without the Clean method

struct EntityID_t
{
    void clean()
    {
        id     = 0;
        targid = 0;
    }

    uint32 id;
    uint16 targid;
};

@zach2good
Copy link
Contributor Author

Partially here: #6392

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

No branches or pull requests

1 participant