Jump to content
  • Advertisement
Sign in to follow this  
always_learning

help with casts

This topic is 3711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am getting the following error: "--------------------Configuration: test - Win32 Debug-------------------- Compiling... main.cpp C:\test\main.cpp(190) : error C2664: 'LoadMap' : cannot convert parameter 2 from 'int [12][18]' to 'int *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe. Here is line 190:
LoadMap(map_id, g_levels[k].map);
So how do I get it to compile? Also, here is the map array:
int map[WORLDSIZE_Y][WORLDSIZE_X];
I see that I have an int* and an array int[][] so how do I get this to compile?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by fpsgamer
LoadMap should have the following signature:

LoadMap(int id, int map[][WORLDSIZE_X]);


Ok now it compiles but it immeddiately crashes

Here's load map for reference:

void LoadMap(const char* name, int destination[][WORLDSIZE_X])
{
FILE* map_data = fopen(name, "r");

if (!map_data)
{
WriteToLogFile("Error: Unable to open map file.");
}

for (int m = 0; m < WORLDSIZE_X; m++)
{
for (int n = 0; n < WORLDSIZE_Y; n++)
{
fscanf(map_data, "%d", &destination[n * WORLDSIZE_X + m]);
}
}

fclose(map_data);
}

Share this post


Link to post
Share on other sites
Change this:

fscanf(map_data, "%d", &destination[n * WORLDSIZE_X + m]);

to this:

fscanf(map_data, "%d", &destination[n][m]);

Share this post


Link to post
Share on other sites
Hmmm

I noticed that it renders 25 of the blue tiles and there's 25 of them in the actual map00.txt file

so it's detecting them but putting them in the wrong place in the array
how though?

I'm fairly sure that my DrawTiles function is working properly, here it is for reference though:

void DrawTiles()
{
// used to retrieve current tile
int current_tile;

// so we will know where to draw the tile
SDL_Rect src, dest;

// each tile is 32x32
src.w = 32;
src.h = 32;

for (int i = 0; i < WORLDSIZE_X; i++)
{
for (int j = 0; j < WORLDSIZE_Y; j++)
{
// retrive current tile
current_tile = g_levels[g_current_level].map[j];

// determine where to render it onscreen
src.x = current_tile * 32;
src.y = 0;
dest.x = OFFSET_X + i*32;
dest.y = OFFSET_Y + j*32;

// draw tile
SDL_BlitSurface(g_tileset,&src,g_screen,&dest);
}
}
}

Share this post


Link to post
Share on other sites
You have it transposed; as in, you've mixed up your rows for columns, when you are loading your map.

Change:

for (int m = 0; m < WORLDSIZE_X; m++) // for each column
{
for (int n = 0; n < WORLDSIZE_Y; n++) // for each row in column
{
fscanf(map_data, "%d", &destination[n][m]);
}
}



to:


for (int n = 0; n < WORLDSIZE_Y; n++) // for each row...
{
for (int m = 0; m < WORLDSIZE_X; m++) // for each column in row...
{
fscanf(map_data, "%d", &destination[n][m]);
}
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!