Open zach2good opened 2 weeks ago
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;
}
Does this mean we'll move all entities out of Zone->ZoneEntities? Unknown.
Creation/lookup/removal of these tokens needs to be constant time. It needs to proliferate into Lua
Partially related to: https://github.com/LandSandBoat/server/issues/5065
I affirm:
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.
TODO: A global (per process) tracker of entities.
TODO: Lookup mechanism.
TODO: On entity destruction, look up your own lookup entry and invalidate it.