Handmade Hero » Forums » Code » Day 066 - multiple sword entities
Tim Green
3 posts
#10109 Day 066 - multiple sword entities
2 years ago

Hey folks, I started this series fairly recently, coded along up to day 66, watched (at work, just playing in the background, half paying attention) up to 85 or so. Great stuff!

Anyways, in day 66 there's this problem where the sword's shadow shows up super dark, because the sword entity is getting added multiple times into the sim region. The fix was to check the region's hash table for an entity's index before adding it, so that it would only get added one time.

However, while I was debugging that part, I noticed something else that ends up hidden by this fix. At least for me, the reason why the sword was added multiple times, was because it was inserted multiple times into the spatial partition (world_entity_block). Stepping through BeginSim, I could see some blocks half full with just the sword entity!

When the sword disappears, MakeEntityNonSpatial will set the NonSpatial flag, set invalid position, and then at the end of the frame in EndSim, ChangeEntityLocation will have no OldP (because everything has already been cleared) and no NewP (because it's nonspatial). So the sword can't get removed from its old cell.

Does this get addressed in a later episode? If so, I'll just leave it as-is on my own working copy. But if it's going to linger, I may fix it myself. Just don't want to go through that effort, end up with large differences that I have to reconcile while following along, only to end up with it going away anyways :)

Sorry if this has already come up, didn't find anything in the forum about it.