Blog 5: More Rendering
3/28/2023
Welcome back to the Integration Hell development blog.
Last week, I left off with two problems. I addressed both and solved them this week. Here were my solutions.
Game lag when rendering a frame due to loading/unloading textures for every tile. This was a relatively easy fix. Rather than give each tile a new copy of the texture, which loads from disk, I loaded one copy of the texture at the start of the program. Then when choosing what tile texture to render, the pointer to the texture gets updated to the texture that the tile needs. Doing it this way greatly increased performance during rendering.
Tiles not rendering in the correct spot. This was a much trickier thing to fix. All of the original code for rendering tiles that I made for last week's blog has been replaced. There were many bugs trying to get the tiles to retain their correct texture when the player moved around. Also, while the tile 'snapping' back to its assigned spot worked, it did not work in the context of the game. After a couple of rewrites to the tile rendering I did eventually find a solution. When the game renders the tiles, the first thing it does is grab the sector data in a 3x3 sector grid centered on the player. Then, the location of the player's icon on the screen is calculated. For each tile, it calculates how far away it is from the player in both the x and y direction in number of tiles. The tile then finds the tile it corresponds to in the sector. If the tile is not located in the same sector as the player, then it uses one of the neighboring sectors to get the correct tile information. For now this is a fixed number of sectors, so only resolutions up to 4K will be supported. Once the tile has been found, the texture pointer is updated to show the correct texture when rendered.
Fixing the second issue described above took much more time than I anticipated, so that is all I have done for this week. Thanks for reading and I hope to see you next week.
The Checklist:
Tasks:
✔️ Render a tile from memory
✔️ Render a sector from memory
✔️ Render the game world
𐄂 Create more assets to use
𐄂 Create better file organization for the game
𐄂 Create a menu system
𐄂 Create animations
𐄂 Give the game an icon