Skip to content
Snippets Groups Projects
Commit fbf7443b authored by Le-Bao-Tin.Ha's avatar Le-Bao-Tin.Ha
Browse files

add comments

parent 31192603
No related branches found
No related tags found
4 merge requests!8Modele,!7Modele,!6Modele,!5Modele Version 1
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
#define INSAGAME_MAP_H #define INSAGAME_MAP_H
typedef struct { typedef struct {
char *path; char *path; //path of image bmp of map
int width; int width;
int height; int height;
int **functional; int **functional; //2D functional matrix
} MAP; } MAP;
int initmap(MAP *map,char *path); int initmap(MAP *map,char *path); //allocate the map's name and call the maptomatrix
int **maptomatrix(MAP *map); int **maptomatrix(MAP *map); //get matrix'length and width => create a functional matrix from the bmp matrix
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
int initmap(MAP *map,char *path){ int initmap(MAP *map,char *path){
int lenpath = strlen(path); int lenpath = strlen(path); //get the path lenght
map->path = (char *)malloc((lenpath)*sizeof(char)); map->path = (char *)malloc((lenpath)*sizeof(char)); //allocate the path
strcpy(map->path,path); strcpy(map->path,path); //copy the path given to map's path
map->functional = maptomatrix(map); map->functional = maptomatrix(map); //fill the map's functional matrix
return 0; return 0;
} }
...@@ -65,8 +65,10 @@ int **maptomatrix(MAP *map){ ...@@ -65,8 +65,10 @@ int **maptomatrix(MAP *map){
fread(&hResolution,sizeof(hResolution),1,bin); fread(&hResolution,sizeof(hResolution),1,bin);
fread(&vResolution,sizeof(vResolution),1,bin); fread(&vResolution,sizeof(vResolution),1,bin);
fread(&nbUsedColours,sizeof(nbUsedColours),1,bin); fread(&nbUsedColours,sizeof(nbUsedColours),1,bin);
fread(&nbImportantColours,sizeof(nbImportantColours),1,bin); fread(&nbImportantColours,sizeof(nbImportantColours),1,bin);
//allocating a 2D matrix
cmalloc = image_width; cmalloc = image_width;
rmalloc = image_height; rmalloc = image_height;
fonc = (int **)malloc(rmalloc * sizeof(int *)); fonc = (int **)malloc(rmalloc * sizeof(int *));
...@@ -74,6 +76,9 @@ int **maptomatrix(MAP *map){ ...@@ -74,6 +76,9 @@ int **maptomatrix(MAP *map){
{ {
fonc[i] = (int *)malloc(cmalloc*sizeof(int)); fonc[i] = (int *)malloc(cmalloc*sizeof(int));
} }
//get map height and width //get map height and width
map->height = image_height; map->height = image_height;
map->width = image_width; map->width = image_width;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment