Replies: 3 comments 2 replies
-
I tend to keep the contents of all callbacks as simple as possible. If it does something complex, you may inadvertely cause more and more callbacks and the whole program becomes hard to reason about, with many functions still hanging to be finished (that's why I don't trust standard OOP in certain domains) This job scheduling, can be as simple as |
Beta Was this translation helpful? Give feedback.
-
Actually, removing the component for which you received a notification is the only thing you can't do in a callback. You can sort pools, rmove other instances, create entities, create components, you can do literally everything but you can't remove that specific component. This is because it's also accessed and returned to the caller by the default pool. Though, with the upstream version of |
Beta Was this translation helpful? Give feedback.
-
Thanks both, interesting points! 👍 |
Beta Was this translation helpful? Give feedback.
-
Hi there,
Just had some thoughts on an issue that I've run into and wondering what people think.
The main issue is if I bind on_construct for a type then emplace it into the registry then during that callback I cannot remove the component.
Assuming
emplace
gets its origins from std::vector and the like, it wouldn't make sense for emplace to possibly have a side effect that removed the thing you were putting in. However since entt has callbacks involved there are some cases I can think of where it makes sense to remove the component that was just emplaced.Example 1.
A spawn order component.
In this example SpawnOrder is put into the registry and a callback generates a number of the given prefab at the location given. After which the data is no longer used but deleting it would cause emplace to fail.
Example 2.
A window.
This is example is supposed to be similar to the likes of Kubernetes where you can provide some data and then missing parts will be corrected later. So if I were to emplace with
L"Window", 800, 600, nullptr
then the bound on_construct could use the partial information to then create the window and assign thehwnd
member.However if for example a parameter was incorrect (e.g. -600 instead of 600) then we would not be able to create the hwnd and assign it. Depending on the application there are different responses to this. Most people I guess would just assert/crash but other systems may want to just log an error and then remove the component. But again that would cause a crash anyway due to the return type of emplace.
This could be solved I guess by something like a nullable/optional return type of emplace.
What are people's thoughts though?
There are plenty of workarounds so this isn't a blocker for me.
Thanks,
Alex
Beta Was this translation helpful? Give feedback.
All reactions