11-11-2013, 04:32 AM
I'm not exactly sure on how to solve this problem. Getting the player position by name sounds horribly inefficient, but storing a pointer can lead to dangling pointers...
One solution I know is using smart pointers, but usage of smart pointers seem to indicate bad software architecture.
Storing an entity ID, and using that to look up a player position should already be a lot faster, you could also use a (hash)map and it should be fast enough.
But that's all referencing the player indirectly.
Another solution could be to hook into some kind of callback that notifies you when an object is removed, so you can check whether it's the player you're pointing to and clear the reference.
I don't know the perfect solution to this, maybe xoft knows something that is more suitable.
One solution I know is using smart pointers, but usage of smart pointers seem to indicate bad software architecture.
Storing an entity ID, and using that to look up a player position should already be a lot faster, you could also use a (hash)map and it should be fast enough.
But that's all referencing the player indirectly.
Another solution could be to hook into some kind of callback that notifies you when an object is removed, so you can check whether it's the player you're pointing to and clear the reference.
I don't know the perfect solution to this, maybe xoft knows something that is more suitable.