Text Optimisations!
Nothing exciting! Just writing a to-do list... Pretty boring, feel free to skip!
Text is currently drawn character-by-character, each frame. So multiple paragraphs of text can be surprisingly expensive... We can fix this in a couple ways.
Only draw text that is confirmed visible on screen.
If all of the text in an instance is stationary... We can basically take a screenshot of how it looks completely drawn, and use that instead of typing out each character one at a time again.
Let's talk about point 2 using more technical language.
We'll check if a block of text is unmoving (no shaking or wiggley text), if it is... Then we create a surface and draw all the text to that once. All the text belonging to this block, that is.
Then, we keep the surface in a variable and whenever the text attempts to draw it just uses the surface image instead.
Some people might try saving the surface as a sprite. I don't think that's a bad idea. But as far as I understand, sprites use up more memory than a surface alone.
The downsides to using surfaces are that they are 'volatile'. Which means under certain circumstances they can be suddenly erased. But I consider this a good thing... One of these cases is when you alt+tab away to a different window. The surface will automatically clear and free up some memory, if you're not looking at the game window there wont be text. Simple enough!
At worst, there'll be a minor lag-spike when alt+tabbing back to the game window. Orrrrr... We have a terrible memory leak. That's definitely possible but only if I mess up.
Staying vigilant, then!














