Systems Showcase

Debug

Using SDL_Log() got me through a lot of troubleshooting, but I found myself needing an automated solution for reporting information that changes each frame. Alt+Tabbing to the console wasn’t cutting it!

I created a pool of entities with UI Text Components. Each frame, they are cleared (t.text = ““), and then whenever a systems calls Debug::Display(myInfo), the Debug system sets pool[0].text = myInfo, and increments a counter. The next time, pool[1].text = newInfo, and so on. If there are ever any more Display() calls than entities in the pool, a new one is created and added to the pool.

The entities in the pool are never destroyed to prevent creating and destroying entities/components each frame, but this also means that a lot of the time there are empty text boxes just hanging out. I think that’s ok!

Another benefit of this is that I can pass different types into Display(), like Display(vector), or Display(float, 2) if I want to format to 2 decimal places for example. This makes it very easy to quickly get the information I want without having to fiddle with formatting.