disable my brain
I ... escaped. Barely. It was tough, it was dumb, it was horrible.
I started working on a new game prototype, great! I made a thing move, put some collision in to get walls in the thing, it was great. I put bullets in and ... everything kinda collapsed.
This isn't the first thing I've made in my engine with bullets (you played super smash-hit rigid right?). But things have changed since then and the way I do things now basically came down to horrible ordering issues in memory, which meant that when bullets hit a wall and they get destroyed ... a bunch of other things iterating over lists care about the memory the bullet was using being affected. And it expresses this care with a seg fault.
When I want direction with something entity and component related I look at a few different popular things, one of which is Unity (n.b. I don't use it, so bear with me!). When you call
Destroy on an entity in Unity, it doesn't actually get destroyed. It gets 'Disabled', and told to be destroyed after the current update but before the next one (and before rendering).
I wondered how Unity does this whilst still efficiently iterating over everything: does it check if an entity is disabled before every instance of every component you update before moving on to the update? It sounds horrible and I didn't want to do it. I tried to find out if anyone knows how other systems deal with this kind of thing, but no luck.
I didn't have time (or energy) to benchmark anything, so ... I just did it. CPUs can handle it right, even with crazy branching? I hope so. I turned the high bit of the entity IDs into a "disabled" flag, have everything check for everything and called it a day. The world didn't explode and that's enough for now.