safety of cMonster::m_Target
#1
cMonster::m_Target holds a raw entity pointer. Is this safe when entities Teleport, etc.?
Reply
Thanks given by:
#2
For teleports it should be save, but when the entity dies or is removed it's not.
Reply
Thanks given by:
#3
(01-19-2016, 12:38 AM)NiLSPACE Wrote: For teleports it should be save, but when the entity dies or is removed it's not.

What about teleports to other worlds? Do entities in different world tick in the same thread?
Reply
Thanks given by:
#4
They tick in different threads. Which is why I think that teleport should be done by destroying the old entity, and creating a new one, rather than transfering the entity.
Reply
Thanks given by:
#5
Not sure if that's possible with a cPlayer object, the client doesn't expect its EntityID to change.
Reply
Thanks given by:
#6
We could create a new entity with the same ID.
Reply
Thanks given by:
#7
That feels much more hackish than moving the entity to another world.
Reply
Thanks given by:
#8
(01-23-2016, 01:10 AM)xoft Wrote: That feels much more hackish than moving the entity to another world.

We'd need a safe way of telling everyone to let go of pointers to an entity when that entity teleports to avoid threading problems. Copying is one way, possibly the simplest way.
Reply
Thanks given by:
#9
Quite the opposite - you need to tell everyone to let go of the pointers when you delete the entity to replace it with a new one. When keeping the same entity for the new world, the pointers can be kept.
Reply
Thanks given by:
#10
(01-23-2016, 02:06 AM)xoft Wrote: Quite the opposite - you need to tell everyone to let go of the pointers when you delete the entity to replace it with a new one.

That problem is unrelated to world travel, it's a global thing - you need to have code which notifies others of your destruction anyways, regardless of anything discussed in this thread.

Quote:When keeping the same entity for the new world, the pointers can be kept.
They should never be kept. It is not thread safe to keep them.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)