1 registered members (AndrewAMD),
1,213
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How to: tiles in 3dgs
#378685
07/25/11 17:38
07/25/11 17:38
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
OP
Expert
|
OP
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
Hey, Though I just as well place it here. I'm running against problems with 3dgs when trying to show 80*60 little bitmap tiles on the screen. I want to make a little game like diggers/minecraft/dwarffortress in 2D; dig blocks and search for treasures. So I made a tileset with 8x8 tiles, and using some noise functions to create a 60*80 tiles geological landscape. I first tried to use panels for each tile, but that soon proved to be very fps-inefficient. Then I used one panel and 80*60 windows on it. That worked significantly better, but 14 fps is not all that great. Using BMP instead of TGA saved me another 3 fps, but what else could I do to improve the framerate to at least 30? Should I approach this way differently? Any ideas? Thanks, Joozey
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: How to: tiles in 3dgs
[Re: Joozey]
#378687
07/25/11 18:05
07/25/11 18:05
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Use an array (or a bitmap, doesn't matter) and use draw_quad to draw bmaps on the specific positions, that works pretty well. You can declare a BMAP array and draw the bitmaps f.i. as follows, should be self-explanatory:
BMAP* bmap_tile[MAX_TILES];
for(i = 0; i < SIZE_X; i++) {
for(j = 0; j < SIZE_Y; j++) {
if(array[i][j] > 0) draw_quad(bmap_tile[array[i][j]-1],vector(i*64,j*64,0),NULL,NULL,NULL,NULL,100,0);
}
}
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: How to: tiles in 3dgs
[Re: Superku]
#378689
07/25/11 18:31
07/25/11 18:31
|
Joined: Apr 2008
Posts: 2,488
ratchet
Expert
|
Expert
Joined: Apr 2008
Posts: 2,488
|
For any 2D, polygons are better , a method used in other engones for 2D like Unity also ! What will be your new ideas in this game ? Caus making exactly same ideas gameplays, feels a litlle useles, or can be good to learn !
Last edited by ratchet; 07/25/11 18:31.
|
|
|
Re: How to: tiles in 3dgs
[Re: Superku]
#378690
07/25/11 18:34
07/25/11 18:34
|
Joined: Dec 2008
Posts: 1,660 North America
Redeemer
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,660
North America
|
Superku has the right idea but there are a few improvements that could be made. 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!
BMAP* bmap_tile[MAX_TILES];
int x, y;
for(y=0; y<SIZE_Y; y++) {
for(x=0; x<SIZE_X; x++) {
if(tilemap[y][x]) draw_quad(bmap_tile[tilemap[y][x]],vector(x<<3,y<<3,0),NULL,NULL,NULL,NULL,100,0);
}
}
I like to keep as a general rule of thumb that whenever possible, use bit shifts to perform multiplication instead of straight multiplication. This is possible whenever you are multiplying a variable by a number that is a power of 2. Also you should put the "y" for loop before the "x" for loop to get better caching performance.
|
|
|
Re: How to: tiles in 3dgs
[Re: Redeemer]
#378691
07/25/11 18:42
07/25/11 18:42
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
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". Of course there are more things to consider, f.i. you only draw the part of the array that is potentially visible (in a scrolling game). 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?
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: How to: tiles in 3dgs
[Re: Superku]
#378695
07/25/11 19:23
07/25/11 19:23
|
Joined: Dec 2002
Posts: 616 Austria
Stromausfall
User
|
User
Joined: Dec 2002
Posts: 616
Austria
|
i had a similar problem and used a shader, it worked pretty neat - but i don't really have a clue whether this is a 'good' approach or not (my knowledge about shaders is actually non existent)...the method i used is the following(roughly) :
- create an entity with a skin of the size your landscape needs to have, for example : 80 * 60 pixels - then use pixel_to_bmap to write a pixel with a color , for example (255, 0, 0) ! this pixel represents a tile ! and (255, 0, 0) is the type of the tile ! - then you only need a shader that reads the pixel value (thus for example 255, 0, 0) and then paints a bmap that represents the tile (like the one you now use as panel element) at the position where the pixel with the value is read...
Last edited by Stromausfall; 07/25/11 19:26.
|
|
|
Re: How to: tiles in 3dgs
[Re: Stromausfall]
#378698
07/25/11 19:49
07/25/11 19:49
|
Joined: Dec 2008
Posts: 1,660 North America
Redeemer
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,660
North America
|
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. 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.
|
|
|
Re: How to: tiles in 3dgs
[Re: Redeemer]
#378700
07/25/11 20:18
07/25/11 20:18
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
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. I did not confuse them, you've just assumed that the first index variable indicates a row. I know that it's against the convention (of matrix notation) and now I know how those arrays are saved internally, thanks to you, but it doesn't matter, my approach works fine as well. I've done it before.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
|