1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
void CMap::LoadListsOfVisibleCubes(FILE *filepointer)
{
fscanf(filepointer, "Visible cubes filename\n");
//let us read the number of characters of the file to load
unsigned int nbchar;
fscanf(filepointer, "%d\n", &nbchar);
char *path;
try
{
path = new char[nbchar];
}
catch(exception &exc)
{
Erreur( "Allocation error, map.cpp" );
}
fscanf(filepointer, "%s\n\n", path);
//now let us load the file
FILE *filepointer2;
if ((filepointer2=fopen(path, "r"))==NULL)
Erreur("Error loading the visible cubes file, map.cpp");
//displaying what is happening
printf("\n\nLoading the visible cubes list ...\n");
printf(" allocating memory for 'visible_cubes'\n");
system("pause");
visible_cubes = new(std::nothrow) CList<int>* [n*p*h];
if (visible_cubes == NULL)
Erreur("Error allocating memory, 'visible_cubes', map.cpp");
system("pause");
for (int i=0; i<n*p*h; i++)
{
try
{
visible_cubes[i] = new CList<int>;
}
catch(exception &exc)
{
Erreur( "Allocation error, map.cpp" );
}
//reading the coordinates of the current position
int id;
fscanf(filepointer2, "id cube : %d, ", &id);
unsigned int coordx, coordy, coordz;
fscanf(filepointer2, "coordinates : %d %d %d\n", &coordx, &coordy, &coordz);
fscanf(filepointer2, "Visible cubes' indices : ");
//reading the indices of the visible cubes;
int visible_cubes_index;
fscanf(filepointer2, "%d ", &visible_cubes_index);
while(visible_cubes_index != -1)
{
visible_cubes[i]->AjouterDebut(visible_cubes_index);
fscanf(filepointer2, "%d ", &visible_cubes_index);
} //end while
fscanf(filepointer2, "\n\n");
} //end (int i=0; i<n*p*h; i++)
fclose(filepointer2);
if (path != NULL)
delete[] path;
printf("\nVisible cubes lists loaded.\n\n");
} |
Partager