LastOliveGames / becsy

A multithreaded Entity Component System (ECS) for TypeScript and JavaScript, inspired by ECSY and bitecs.
MIT License
202 stars 17 forks source link

Is there an API to see if Becsy is currently running in accessRecentlyDeletedData mode? #23

Closed dxinteractive closed 1 year ago

dxinteractive commented 1 year ago

If not, I think this could be useful.

Reason: Sometimes I have a function (foo()) that does useful things to entities, in situations where accessRecentlyDeletedData(false) and also when accessRecentlyDeletedData(true). While accessing recently deleted data mode is on, I want to avoid calling entity.remove() on a recently deleted entity, because it's deleted already and an error is thrown in dev mode if I were to try. But I can't see a Becsy-API way of asking if accessRecentlyDeletedData is true or not, to make that check possible.

Alternatives:

Open to any thoughts!

dxinteractive commented 1 year ago

Just experimenting, it seems likely that the more accurate check is to look if the specific entity is entity.alive before removing.

pkaminski commented 1 year ago

Correct, checking entity.alive is the right thing to do in this case. It checks the same flag that causes entity.delete() to throw, and it's documented to return the same value where accessRecentlyDeletedData is true or not.

dxinteractive commented 1 year ago

Makes sense, thanks!