Tilemaps are cool things, but as implied by the topic, you run into problems when you have many possible sprites that could be displayed. Just for fun, I was toying with a spritesheet with a full size of 384x176, or about 8 separate 128x64 xLIBC tilemap AppVars. Because xLIBC can only "cache" a maximum of two tilemap spritesheets at a time, having locality becomes extremely important. This locality can be exploited in one of several ways:
1) Pack together sprites that will be most likely to be displayed together on the same spritesheets, and pair spritesheets as needed so that the two can be frequently loaded at the same time.
2) Make multiple passes over the tilemap, displaying only tiles using sprites from the two currently-cached spritesheets in the current pass.
3) Allow new spritesheets to be swapped in, but be intelligent about which one you trash.
For this experiment, I chose to simply use LRU caching, and not bother with any temporal locality tricks:
Code:
As you can see, L1 is used to track which of six tilemap AppVars are loaded into buffers 0 and 1, and wipe out whichever was used less recently based on what the O variable was in the last iteration. I did see a significant reduction in rendering time compared with caching a new spritesheet on every single sprite draw, but the screenshots below still take about 20-30 seconds each to render.
Comments or questions? Suggestions about how I could do this better?
1) Pack together sprites that will be most likely to be displayed together on the same spritesheets, and pair spritesheets as needed so that the two can be frequently loaded at the same time.
2) Make multiple passes over the tilemap, displaying only tiles using sprites from the two currently-cached spritesheets in the current pass.
3) Allow new spritesheets to be swapped in, but be intelligent about which one you trash.
For this experiment, I chose to simply use LRU caching, and not bother with any temporal locality tricks:
Code:
real(0,1,1
real(0,3,4,0
{~1,~1->L1
1->G
For(X,0,9
For(A,0,6
randInt(1,6
If max(Ans=L1
Then
Ans=L1(2->O
Else
Ans->V
1-O->O
"MCSPRT"+sub("123456",V,1
real(5,0,O
V->L1(1+O
End
128O+2randInt(0,3)+16randInt(0,7
real(4,0,16X,16A,2,2,0,0,248,0,0,Ans,Ans+1,Ans+8,Ans+9
End:End
real(9
Pause
Comments or questions? Suggestions about how I could do this better?