meniku / NPBehave

Event Driven Behavior Trees for Unity 3D
MIT License
1.15k stars 195 forks source link

A question about the source code of Clock.cs and Blackborad.cs #37

Closed pan64271 closed 2 years ago

pan64271 commented 2 years ago

I have encountered a question while reading the source code. I'm not sure whether it's a bug or designed like that intentionally, so I just list it out here. If it's the latter case, I would be pleased if someone could tell me the intention behind it.

In methods AddObserver and RemoveObserver in Blackboard.cs, before add/remove a observer, it will check whether there is already a add/ remove request in addObservers/removeObservers. If so, this request will be ignored.

But in methods AddUpdateObserver and RemoveUpdateObserver in Clock.cs, before add/remove a observer, it does not check the same thing, which means that there could be two remove requests for the same observer.

So, what's the intention of this difference?

Thanks.

meniku commented 2 years ago

Hi @pan64271 it has been a while since I wrote the code, however in Clock.cs the observers are stored within a HashSet, so there shouldn't be need to check if they're existing already

pan64271 commented 2 years ago

Hi @pan64271 it has been a while since I wrote the code, however in Clock.cs the observers are stored within a HashSet, so there shouldn't be need to check if they're existing already

OK, I got your point. Thanks for your reply!