Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  Isometric tiles and heights...can I modify?  (Read 1779 times)
0 Members and 1 Guest are viewing this topic.
Offline CS

Innocent Bystander





« Posted 2013-06-29 20:39:45 »

I have an isometric 2D Engine that has capability of generating different heights.



It runs at 20~30 FPS with grid layers, 55~60 FPS without grid layers.
And I started to think about improving it's performance much higher(though I have enough fps for smooth scrolling).

The way it generates the world is by dividing entire world by chunks(The engine itself can generate maximum map size of 2048x2048).
I have single tile vertices saved in vbo, and when it is time to render a tile, I map out the buffer and change the vertex location based on its height, flip the buffer, then ummap it.

But now I'm thinking about putting a single chunk into vbo, then render it.
However, if I put single chunk(which contains vertices for tiles) into vbo, it will be impossible to unmap the buffer, pin-point the tile, then change it's height value.

So my question is, is there a way to "store all tiles in one chunk, into one vbo, then modify individual tile as it needs"?
Offline GNecro1
« Reply #1 - Posted 2013-07-31 10:08:34 »

1  
2  
3  
4  
5  
6  
7  
8  
Tile[][] tile = new Tile[xMax][yMax][zMax];
for (int x = 0; x < tile.lenght; x++){
   for (int y = 0; y < tile[0].lenght; y++){
      for (int z = 0; z < tile[0][0].lenght; z++){
         vbo.add(tile[x][y][z]);
      }
   }
}


Maybe Huh? :/  Huh

Java freak! Cheesy
Offline quew8

JGO Coder


Medals: 31



« Reply #2 - Posted 2013-07-31 15:22:45 »

For this example, I am going to assume that each vertex comprises of 3 floats (x, y, z) and you store them in the vbo in row major order.

This means that for the tile at position X, Z (relative to the chunk it is in) the four vertices begin at offsets:
     ( ( Z * CHUNK_WIDTH ) + X ) * 3
     ( ( ( Z + 1 ) * CHUNK_WIDTH ) + X ) * 3
     ( ( ( Z + 1 ) * CHUNK_WIDTH ) + ( X + 1 ) ) * 3
     ( ( Z * CHUNK_WIDTH ) + ( X + 1 ) ) * 3

which we must not forget to times by 4 to get the byte offset.

So the following method will update the height of a specific tile. (I don't know if you LWJGL or what but that is the format I'll give it in)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
static FloatBuffer fb = BufferUtils.createFloatBuffer(4); //We will reuse the buffer since this is about efficiency.

public static updateTile(int bufferId, int x, int z, int newHeight) {
    glBindBuffer(GL_ARRAY_BUFFER, bufferId);
   
    fb.flip();
    int offset1 = ( ( ( ( z * CHUNK_WIDTH ) + x ) * 3 ) + 1 ) * 4; //+1 since we will start updating at the y coord
    fb.put(newHeight);
    fb.put(z);
    fb.put(x + 1);
    fb.put(newHeight);
    fb.flip();
    glBufferSubData(GL_ARRAY_BUFFER, offset1, fb);

    fb.flip();
    int offset2 = ( ( ( ( ( z + 1) * CHUNK_WIDTH ) + x ) * 3 ) + 1 ) * 4;
    fb.put(newHeight);
    fb.put(z + 1);
    fb.put(x + 1);
    fb.put(newHeight);
    fb.flip();
    glBufferSubData(GL_ARRAY_BUFFER, offset2, fb);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
}


In this example I updated it with 2 calls to glBufferSubData. That meant that I was needlessly updating 2 other values, but I suspect that it would still be quicker than 4 calls, but you can try it out to your hearts content.

I'm sure there are probably some other optimizations (perhaps caching buffer offsets or working them out more efficiently), but I shall leave that up to you.

I have made some assumptions about your system, but you're a smart guy, I'm sure you'll figure out anything I got wrong. Saying that I didn't comment much so feel free to ask about the code.

Here's hoping I got that all right (would be a miracle)
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.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!