Streaming map data from SD card test

A while back, I wrote a simple test for streaming a map from the SD card on the Gamebuino, and I have now converted it to run on the Pokitto. The Pokitto’s current SD library is based on petitFatFS, which causes some serious performance problems.

This test streams map data one row or column at a time on demand, as soon as the camera moves a single tile in any direction. This means that each time data must be loaded, the amount is small, but it also means data is read quite often. This was quite smooth for vertical scrolling, but caused severe lag when scrolling horizontally. This was because in order to load a column, I had to read one byte from the column, seek to the next row, and then read the next byte for the column.

I got rid of this lag by storing the map duplicated in two orderings in the file, row-ordered and column-ordered, and reading from the respective ordering depending on whether I am loading a row or a column. Unfortunately, when moving diagonally, I think seek time is still causing problems. I think that these performance issues might not appear with a faster SD library.

I’m not sure about loading larger chunks less often as an option, because I feel like it might cause less frequent but more noticeable lag.

I can share the source if anybody might find this useful, but right now the lag from moving diagonally makes it a bit impractical.

Please share. Then we can benchmark the speed of different solutions. I am also interested in seeing how you are trying to do it at the moment

Sure thing, here is the link to the source:
https://os.mbed.com/users/wuuff/code/sd_map_test/

I also forgot to mention that when I was figuring out how to use the Pokitto SD card API, I found that certain functions automatically initialize the Sd card, but others don’t. For example, fileOpen didn’t work by itself, so I ended up calling another function first. Checking now, I realize I probably should have just called pokInitSD first.

This also needs the map file itself to work, which needs to be named SDMAP.DAT. I use this json file as the map data:

And this python script converts the json into raw bytes:

I redirect the output of the script to a file like so:

$ python binarymapconverter.py large_test_map.json > SDMAP.DAT