Tile Chunk Position
Hello there reader. I think despite starting late again today I managed to be productive.
While struggling during my train rides with fixing the tile map rendering and other issues.
I decided for myself I should just clean up the tile map stuff and fix everything at once.
But that is not something you can do during a one hour train ride.
Which always happens to be interrupted by train switching.
So when I refused to do it on Saturday I left this task for the Monday.
Working the whole afternoon on this task it took 2 hours to have all compile errors sorted.
That means at first the code didn’t work obviously.
I just changed some names and removed the chunk_position
struct.
This struct was really not necessary anymore.
It became clearer and clearer how unnecessary some stuff had become.
As cleaning it up this way and only using tile_map_position
from now on made everything way easier to understand.
Now there is a concept of a tile_map_position
which can tell you in which chunk a particular thing lives.
And what the offset is from relative to that chunks origin.
The origin of a chunk is always the bottom left corner.
So that the tiles within a chunk line up perfectly with the tiles it contains.
As well as it becoming easier to tell on which tile an entity is standing.
Since tiles are just 1 by 1 world units (meters), you can simply just truncate the position and tada!
As a result of this, everything is back in working state. Tiles are getting rendered again. Entities are correctly placed in the world and can still use tile offsets. The only other thing I had to fix is that entities are now all unpacked from a chunk. Instead of checking if they are in the simulation region bounds. Otherwise some entities won’t be unpacked, but their block they reside in will get deleted. Though this check is actually not needed anymore, since the entities now already are constrained. Before the whole entities and tiles system change, all entities just sat in one big array. Now they are stored inside a chunk and therefore are naturally limited when loaded into a simulation region.
Very happy I did this big change. Entities should be easier to store now. The game is running faster as it does not need to clear some memory anymore. There basically is just one concept of position now instead of multiple. The only thing left to do now is fix the collision. As it has taken a beating. But it’s also godly unreadable.
Collision
That means the next task is to clean up the collision code.
So that it will be easier to debug.
As well as easier to improve.
There is probably a lot of nonsense going on in there.
Maybe even some code that is doing the same work twice or something.
I’ve already seen that the entity to entity collision is basically never happening.
So hopefully that will solidify the foundation some more.
Although it does make me diverge more and more from my schedule.
Which I am not too happy about.
That means I will try to do the collision clean up in at most two weeks.
And don’t think I can even afford more time to be honest.