Handmade Hero»Forums»Code
Jay
18 posts
Why check bounds when adding simulation entities?
I have a question re day 66.

Can someone explain to me why we check if the position is within the bounds we pass in during the BeginSim call?

Since the entities are now spatially partitioned into chunks surely we can just get the min and max chunk and add all entities from those chunks? Why do we do the additional check? The only thing I can think of is the case where we might be partially on a chunk, so we only add the entities in that chunk that are actually in the bounds? But in that case, can't we just add the additional entities anyway? Wouldn't that be better than checking if all the entities in the sim region are contained in the bounds?
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Why check bounds when adding simulation entities?
Well, the reason it that we have some constraints on our bounds, because we need to ensure that entities in the bounds can move the maximum movement rate and not exit the collision bounds (the outer bounds). If we allowed entities that were not in the bounds to be in the simulation region simply because they were in a chunk that was in bounds, that entity could theoretically leave the collision region and miss a collision it should have had.

We could instead enlarge the outer collision bound by chunk side, so if we found that it was too onerous to do the extra checking, we could do that. But it doesn't seem like a great tradeoff, I should think.

- Casey