Hey all again, not sure if this would get to anyone...but anyhow...
ive tried various things making the variables either private, public or protected. I tried the debugging and i can only see everything from the main function, of which I see all the weird values popping up. However, what i did notice was a pattern.
1. each chunk (there are 100 of them) had an array of 100, and each chunk would follow like -24, 60, 80, etc for each one
2. the members would ALWAYS be the same. However, when ever i made the members either private, public or protected, those values changed.
Im not entirely sure if its a scope issue. Because i can get the member printing the correct things from inside the function that changed it.
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
|
void defineMap::loadChunk(int x, int y, const char* filePath)
{
//this will determine which chunk to load into!
int whichChunk;
//Check the various chunks in the map to see whether they are in use
for (int i = 0; i < (maxLoad * maxLoad); i++)
{
if (map[i].inuse == false)
{
whichChunk = i;
break;
}
}
//Set the chunks x and y so we know where to put it!
map[whichChunk].x = x;
map[whichChunk].y = y;
//for the while loop!!
int i = 0;
int j = 0;
char tempChar;
//Create file stream and read the file
FILE* mapFile;
mapFile = fopen(filePath, "r");
//Actually read the file
while ((tempChar = fgetc(mapFile)) != EOF)
{
tempChar = fgetc(mapFile);
if (tempChar == '\n')
{
j++;
i = 0;
}
else if (tempChar != -1)
{
map[whichChunk].map[i][j] = tempChar;
printf("CHAR: %c and %c\n", tempChar, map[whichChunk].map[i][j]);
i++;
}
}
fclose(mapFile);
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
Output:
etc...CHAR: G and G
CHAR: D and D
CHAR: C and C
CHAR: A and A
CHAR: D and D
CHAR: C and C
CHAR: E and E
CHAR: C and C
CHAR: G and G
CHAR: C and C
CHAR: E and E
CHAR: A and A
CHAR: B and B
CHAR: G and G
CHAR: F and F
CHAR: A and A
CHAR: B and B
CHAR: G and G...etc
|
As it is seen, this is working fine
however... this is where the error occurs
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
|
//Drawing map function to go through the chunk and put them on the screen according to the textures
void defineMap::drawMap(SDL_Surface* screen)
{
//SDL_Rect for drawing a pixel!
SDL_Rect tempRect;
tempRect.w = 1;
tempRect.h = 1;
//this for is for the map
for (int i = 0; i < (maxLoad * maxLoad); i++)
{
if (map[i].inuse == 1)
{
//for loops to go through the chunks x and y
for (int j = 0; j < chunkSize; j++)
{
for (int k = 0; k < chunkSize; k++)
{
//Put the correct x and y's to place in the correct position
tempRect.x = j + (map[i].x * chunkSize);
tempRect.y = k + (map[i].y * chunkSize);
printf("STOOF: %i\n", map[i].x);
for (int a = 0; a < chunkSize; a++)
{
for (int b = 0; b < chunkSize; b++)
{
printf("CHUNK:%i COORD: %i and %i PIXEL: %i, X: %i Y: %i OTHER: %i\n", i, a, b, map[i].map[a][b], map[i].x, map[i].y, strlen(map[i].map[a]));
}
}
//Read the map and draw the pixel arcording to the
//x and y's values and textures (note: offset is for ASCII because A = 65 which then = 0 for map)
SDL_FillRect(screen, &tempRect, defineMap::textures.at(defineMap::map[i].map[j][k] - offset).decimalColour.at(randomInt(0, defineMap::textures.at(defineMap::map[i].map[j][k] - offset).decimalColour.size())));
printf("after\n");
}
}
}
}
}
|
The long printf statement within the a and b for loop prints this...
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
|
Output:
CHUNK:34 COORD: 0 and 0 PIXEL: -96, X: -1072365560 Y: 0 OTHER: 2
CHUNK:34 COORD: 0 and 1 PIXEL: 7, X: -1072365560 Y: 0 OTHER: 2
CHUNK:34 COORD: 0 and 2 PIXEL: 0, X: -1072365560 Y: 0 OTHER: 2
CHUNK:34 COORD: 0 and 3 PIXEL: 0, X: -1072365560 Y: 0 OTHER: 2
CHUNK:34 COORD: 0 and 4 PIXEL: 2, X: -1072365560 Y: 0 OTHER: 2
CHUNK:34 COORD: 0 and 5 PIXEL: 0, X: -1072365560 Y: 0 OTHER: 2
CHUNK:34 COORD: 0 and 6 PIXEL: 0, X: -1072365560 Y: 0 OTHER: 2
CHUNK:34 COORD: 0 and 7 PIXEL: 0, X: -1072365560 Y: 0 OTHER: 2
CHUNK:34 COORD: 0 and 8 PIXEL: 32, X: -1072365560 Y: 0 OTHER: 2
CHUNK:34 COORD: 0 and 9 PIXEL: -31, X: -1072365560 Y: 0 OTHER: 2
//...
CHUNK:92 COORD: 0 and 0 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 0 and 1 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 0 and 2 PIXEL: 83, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 0 and 3 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 0 and 4 PIXEL: -8, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 0 and 5 PIXEL: -65, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 0 and 6 PIXEL: 85, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 0 and 7 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 0 and 8 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 0 and 9 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 1 and 0 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 1 and 1 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 1 and 2 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
CHUNK:92 COORD: 1 and 3 PIXEL: 0, X: 2004273965 Y: 0 OTHER: 0
|
Thanks all for your efforts towards this, ive literally spent hours glued to the screen and pulling my hair out!
many thanks super stinger!