Splitting Assets from Code: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
m (Clarified the use of buffer)
(Corrected a factual mistake regarding global variable initialization.)
 
Line 96: Line 96:
The idea is, before you start rendering the level, you load any textures you need into your global cache (which can be any size you want, not just 4096 bytes). Then, when the data isn't needed anymore, you mark that part of the buffer as "empty" and you can overwrite it with new data.
The idea is, before you start rendering the level, you load any textures you need into your global cache (which can be any size you want, not just 4096 bytes). Then, when the data isn't needed anymore, you mark that part of the buffer as "empty" and you can overwrite it with new data.


You're probably wondering: "Hold on, this global buffer variable is part of the code... Won't it be subject to the exact same 1MB restriction we had before?". The answer is yes, however this method ensures that only the data you need is loaded at a time in the 1MB code segment (as opposed to everything being there). The alternative would be:
You're probably wondering: "Hold on, this global buffer variable is part of the code... Won't it be subject to the exact same 1MB restriction we had before?". The answer is no, because initialized global variables are not loaded from ROM (as they're dynamically "created" when your code loads). The downside to this method is that you might not always have full control over where the data is initialized to in memory. The alternative would be:


== Having a buffer somewhere in RAM ==
== Having a buffer somewhere in RAM ==