I have a struct:
typedef struct Image {
byte height;
byte width;
byte data[];
} Image;
and I create 2 images:
static const __flash Image GRID = {
.width = 16,
.height = 8,
.data = {
0x10, 0x10, 0x28, 0x28, 0x44, 0x44, 0x82, 0x82, ...
}
};
static const __flash Image HOUSE1 = {
.width = 24,
.height = 24,
.data = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ...
}
};
Then I create an array of pointers to the images:
static const __flash Image *IMAGES[] = {
&GRID,
&HOUSE1,
};
I can draw an image using my draw_image() function:
void main(void)
{
draw_image(IMAGES[0], 16, 16);
}
I have a map:
typedef struct Map {
word cols;
word rows;
byte tiles[];
} Map;
static const __flash Map level_1 = {
.cols = 16,
.rows = 8,
.tiles = {
0,0,1,0,...
the .tiles field is a list of indexes into the IMAGES array. I'm doing it this way because my engine doesn't know what images are available without being told:
void draw_map(const Map __memx *map, const Image __memx *tileset[]);
{
...
draw_image(tileset[map->tiles[index]], x, y);
...
}
called thusly:
void main(void)
{
draw_map(&level_1, &IMAGES[0]);
}
The compiler does not like this and gives me incompatible pointer type warnings. The map is not drawn:
note: expected
‘const __memx Image ** {aka const __memx struct Image **}’
but argument is of type
‘const __flash Image ** {aka const __flash struct Image **}’
I did try removing the [] from the draw_map() declaration:
void draw_map(const Map __memx *map, const __memx Image *tileset);
but that gave me an error in calling the draw_image() call:
error: incompatible type for argument 1 of ‘draw_image’
draw_image(tileset[0], c*8+(64 - r*8), r*8);
^
tile-engine.c:63:6: note: expected
‘const __memx Image * {aka const __memx struct Image *}’ but argument is of type
‘Image {aka const __memx struct Image}’
Where am I going wrong?
void draw_image(const Image __memx *image, int x, int y)
{
byte rows = image->height>>3;
byte cols = image->width>>3;
for(byte r=0 ; r<rows ; r++)
{
for(byte c=0 ; c<cols ; c++)
{
draw_tile(&image->data[(r*cols+c)*8], &image->data[(r*cols+c)*8], x+(c*8), y+(r*8));
}
}
}
draw_mapparameters with__memx?Maptypedef, very similar toImagereallydraw_image?