Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 2D map in 3D optimizations  (Read 3454 times) 0 Members and 1 Guest are viewing this topic.
led

Senior Newbie

:)

 « Posted 2004-04-08 14:18:33 »

Hi all, I can see a lot of new game based on 2D map (ie: all the rts new games). Anyway, though they might use terrain, I was wondering about ways to optimize without terrain.

So if some has some link to some optimized algorythm of a (x,y) map. Sure I thought of showing only some tiles depending on where the camera was, but still, there must be other ways.

thanks a lot.
Planner1

Senior Newbie

 « Reply #1 - Posted 2004-04-08 14:55:50 »

This is a very general question and so I'm sorry if my response too is general. Any space partitioning algorithm that works for 3D should have an equivalent in 2D. For example, you could use a quadtree to partition your map into smaller and smaller subsections and then display visible one's based on view. If you're using Xith, some of this stuff should be taken care of for you.
led

Senior Newbie

:)

 « Reply #2 - Posted 2004-04-08 17:10:16 »

Ok, let me explain this with an example (oh and by the way the "zone" partitionning is a good idea!)

What I want to do is a terrain like my subdivided with tiles. Let's define what a tile is:

A tile is a square subdivided into small triangle making little square. So, a tile has about 10x10 small pane into it. So, that's about 200 polys (triangle). I can modify the poly coords to make terrain effects in it. A tile is also as large as a character in the screen, so it is not big like a terrain.

Now, let's define map:

A map is made of tiles aligned to each other (with the height of each tiles) Making the map like a Warcraft 3 map. A map can have 64x64, 128x128, 100x50, etc. tiles. Though, I'm just showing what the camera is seeing, let's say the camera is pointing the character like warcraft. So, I just want to show maybe 16x16 tiles.

Well, now that's where the problem lies. The basic way to do this is surely a 2D array, containing the tiles informations.

tile
• [y]

and then getting the character position in the map, x and y, and limiting the vue to x + 8, x - 8, y + 8, y - 8.

now you can loop with 2 for loops like this:

for ( int y = charY - 8; y < charY + 8; y++ )
for ( int x = charX - 8; x < charX + 8; x++ )
if (we're not outside the array && the tile isn't null )
enable( tile
• [y] );

ok, it can be a bit long, I thought of another way that is making an array with one dimension like this:

tile[x * y]

// getting the top left 16x16 square depending on the character position
topleftSquare = ( mapSizeX * charY ) + charX;

// getting the bottom left 16x16 square depending on the character position
bottomleftSquare = ( mapSizeX * charY ) + charX;

for ( int i = topleftSquare; i < bottomleftSquare; i++ )
enable( tile )

I don't know if it's really faster, but anyway.

Another way could be making different BranchGroup, called zone. And when I'm approching of one zone, I enable it. While this solution can be the fastest (perhaps) It can be a problem if I'm in a 40x40 tiles zone and I load up a 40x40 zone.

Or, I could load the map, and divid it into small 16x16 tile not caring of what the map is made of (a "room" could be cut in a half) but the user will not see this, since 16x16 is as large as the screen view.

Any thought is welcome, I'm a bit lost in all this
EvgeniyS

Junior Newbie

Java games rock!

 « Reply #3 - Posted 2004-04-08 21:03:45 »

Hi
if u have relatively small map i think it doesnt matter how u find visible area. I mean ur way is good for small map - when u can store it in array. If u work with something really complex and large u just cant afford to store all tiles in array , so u have to use quadtree or BSP tree - as sad above. BSP tree  have better algorithm for finding visible area. but again - for 64x64 it really doesnt matter.
BTW 2dimention array and 1dimension array is same in binary representation , so it doesnt matter  what exactly u use
Pages: [1]
 ignore  |  Print

 ivj94 (583 views) 2018-03-24 14:47:39 ivj94 (47 views) 2018-03-24 14:46:31 ivj94 (374 views) 2018-03-24 14:43:53 Solater (61 views) 2018-03-17 05:04:08 nelsongames (108 views) 2018-03-05 17:56:34 Gornova (150 views) 2018-03-02 22:15:33 buddyBro (693 views) 2018-02-28 16:59:18 buddyBro (91 views) 2018-02-28 16:45:17 xxMrPHDxx (493 views) 2017-12-31 17:17:51 xxMrPHDxx (732 views) 2017-12-31 17:15:51
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org