Quote:
Quote:
First of all the way he's doing it will cause the terrain to draw itself sideways, and the tiles will be spaced out far too much!
Could you explain this, if possible in different words?
I think it's pretty obvious that "64" stands for the tile size in my example, and I don't get what you mean with "the terrain to draw itself sideways".

Joozey stated in his first post that he was working with 8x8 tiles, so I naturally assumed that your example would use that size. Also, you were using the "y" variable to reference the tilemap column and the "x" variable to reference the tilemap row, and then you were drawing the tilemap with draw_quad with the "x" parameter as the column and the "y" parameter of the row! Basically, you confused the variables halfway through, which would cause the data to be drawn sideways. I've done it before lots of times.

Quote:
Quote:
Also you should put the "y" for loop before the "x" for loop to get better caching performance.

What kind of difference is that supposed to make?

2D arrays in C are stored in memory with each row of data stored in linear succession. Therefore if you put the for loop for "x" before "y" then you will start referencing row 1, column 1, and with each cycle you will go down one row until you reach column 2. This actually throws the CPU off, because it anticipates you to access the columns in succession, not the rows.

Basically the tilemap might visually look like this:

1, 2, 3, 4,
5, 6, 7, 8,
A, B, C, D

But it is stored in memory like this:

1, 2, 3, 4, 5, 6, 7, 8, A, B, C, D,

And if you access them the way you were doing, they are referenced in this order:

1, 5, A, 2, 6, B, 3, 7, C, 4, 8, D

Which completely throws off the CPU!

Last edited by Redeemer; 07/25/11 19:51.

Eats commas for breakfast.

Play Barony: Cursed Edition!