Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D map in 3D optimizations  (Read 1616 times)
0 Members and 1 Guest are viewing this topic.
Offline 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.
Offline 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.
Offline 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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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 Tongue
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (25 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (58 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!