Im storing a 2d array of bytes in progmem because its pretty huge (4kb) If i want to read from this 2d array can someone give me an example of how to do this?
I understand I need pgm_read_byte(address) But im not sure what the address would be?
(storing the array in progmem because the rest of the game isnt likely to take up too much space and because I want more detail to my map than the bit array i used before)
(Strictly speaking arrayWidth and arrayHeight should be size_t, but size_t is 16 bits on the Arduboy, so using uint8_t should produce less code. Iām not completely sure though, Iāve never actually tested - itās possible that it doesnāt make a difference because itās constexpr or because it has to get promoted anyway.)
Oh that easy? Nice one. Just as an aside question, say I have converted a bitmap image into an array, this array was produced by going left to right along each ārowā of pixels on the image and assigned them a byte (so a 2x2 pixel image might look like {0, 0, 0, 0}) If i want to convert this to a 2d array I should just be able to do arrayofbytes[2,2] right?
Thanks for the useful advice, I know I could squeeze more data into each byte but Im doubting if i NEED to for this particular application. If I did I would probably just draw the map in bits using the function i used in my roguelike wip and then modify what it displays based on when on the array a tile is drawn, would squeeze the map well below 1kb but im being lazy for reasons of getting more done.
Depending on how big your game gets you might have to eventually.
That progmem runs out really quickly.
If you do end up packing your bits and using your map code, make sure to replace your #defines with constexpr variables.
Also, try using MapStorage = unsigned char; instead of #define MAP_STORAGE unsigned char.
Macros are evil and should be avoided whenever possible.