Salut,
Je cherche à faire des maps de taille variable avec le TileMap Engine.
Après avoir alloué mon tableau dynamique, je l'assigne au membre "matrix" de la structure Plane du TileMap Engine. Le problème est que rien ne se passe....
Le code ressemble à ceci:
typedef struct _LEVELDESC
{
int nWidth;
int nHeight;
unsigned char** foreground;
} LEVELDESC, *PLEVELDESC;
l'allocation du membre foreground se fait comme suit:
if (!AllocateArray(&level->foreground, level->nHeight, level->nWidth))
...
et AllocateArray est comme suit:
BOOL AllocateArray(unsigned char*** newArray, int nHeight, int nWidth)
{
int i=0, j=0;
*newArray=(unsigned char**) malloc(nHeight*sizeof(unsigned char*));
// could not allocate rows
if (!(*newArray))
return FALSE;
// allocate columns
for(i = 0; i<nHeight; i++)
{
(*newArray)[i]=(unsigned char*) malloc(nWidth*sizeof(unsigned char));
// could not allocate columns
if (!(*newArray)[i])
{
// free allocated data
FreeArray(&(*newArray), i);
return FALSE;
}
for (j=0; j<nWidth; j++)
(*newArray)[i][j]=0;
}
return TRUE;
}
la fonction FreeArray:
void FreeArray(unsigned char*** array, int nHeight)
{
int i=0;
// already unallocated
if (!*array)
return;
// unallocate array
for(i=0; i<nHeight; i++)
free((*array)[i]);
free(*array);
*array=NULL;
}
ensuite, j'initialise la structure Plane comme suit:
plane.matrix=level.foreground; // level.forground est un unsigned char**
plane.sprites=g_ptrTiles;
plane.width=level.nWidth;
plane.big_vscreen=g_vScreen+LCD_SIZE*2;
Au debugger de tiemu, tout est bien initialisé comme il faut mais lorsque je dessine le plan via l'appel:
DrawPlane(0, 0, &plane, darkScreen, TM_GRPLC, TM_G8B);
ça fait n'importe quoi... pourtant, plane.matrix pointe bien sur le tableau...
Là, je sèche...
Quelqu'un peut m'aider???
D'avance, merci.
Fred.