Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  If and if and if and if... [ + real-time generation of textures in LWJGL]  (Read 2936 times)
0 Members and 1 Guest are viewing this topic.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Posted 2012-08-28 14:01:04 »

Hey! Is there any way to make the code smaller for things like this? :

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  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
if((x > 0 && x < mapWidth - 1) && (y > 0 && y < mapHeight - 1)) {
   if(map[x][y + 1] != map[x][y]) { dd = true; ddID = map[x][y + 1]; }
   if(map[x - 1][y + 1] != map[x][y]) { dl = true; dlID = map[x - 1][y + 1]; }
   if(map[x - 1][y] != map[x][y]) { ll = true; llID = map[x - 1][y]; }
   if(map[x - 1][y - 1] != map[x][y]) { ul = true; ulID = map[x - 1][y - 1]; }
   if(map[x][y - 1] != map[x][y]) { uu = true; uuID = map[x][y - 1]; }
   if(map[x + 1][y - 1] != map[x][y]) { ur = true; urID = map[x + 1][y - 1]; }
   if(map[x + 1][y] != map[x][y]) { rr = true; rrID = map[x + 1][y]; }
   if(map[x + 1][y + 1] != map[x][y]) { dr = true; drID = map[x + 1][y + 1]; }
} else {
   if(x == 0 && y == 0) {
      if(map[x][y + 1] != map[x][y]) { dd = true; ddID = map[x][y + 1]; }
      if(map[mapWidth - 1][y + 1] != map[x][y]) { dl = true; dlID = map[mapWidth - 1][y + 1]; }
      if(map[mapWidth - 1][y] != map[x][y]) { ll = true; llID = map[mapWidth - 1][y]; }
      if(map[mapWidth - 1][mapHeight - 1] != map[x][y]) { ul = true; ulID = map[mapWidth - 1][mapHeight - 1]; }
      if(map[x][mapHeight - 1] != map[x][y]) { uu = true; uuID = map[x][mapHeight - 1]; }
      if(map[x + 1][mapHeight - 1] != map[x][y]) { ur = true; urID = map[x + 1][mapHeight - 1]; }
      if(map[x + 1][y] != map[x][y]) { rr = true; rrID = map[x + 1][y]; }
      if(map[x + 1][y + 1] != map[x][y]) { dr = true; drID = map[x + 1][y + 1]; }
   } else if(x == mapWidth - 1 && y == 0) {
      if(map[x][y + 1] != map[x][y]) { dd = true; ddID = map[x][y + 1]; }
      if(map[x - 1][y + 1] != map[x][y]) { dl = true; dlID = map[x - 1][y + 1]; }
      if(map[x - 1][y] != map[x][y]) { ll = true; llID = map[x - 1][y]; }
      if(map[x - 1][mapHeight - 1] != map[x][y]) { ul = true; ulID = map[x - 1][mapHeight - 1]; }
      if(map[x][mapHeight - 1] != map[x][y]) { uu = true; uuID = map[x][mapHeight - 1]; }
      if(map[0][mapHeight - 1] != map[x][y]) { ur = true; urID = map[0][mapHeight - 1]; }
      if(map[0][y] != map[x][y]) { rr = true; rrID = map[0][y]; }
      if(map[0][y + 1] != map[x][y]) { dr = true; drID = map[0][y + 1]; }
   } else if(x == mapWidth - 1 && y == mapHeight - 1) {
      if(map[x][0] != map[x][y]) { dd = true; ddID = map[x][0]; }
      if(map[x - 1][0] != map[x][y]) { dl = true; dlID = map[x - 1][0]; }
      if(map[x - 1][y] != map[x][y]) { ll = true; llID = map[x - 1][y]; }
      if(map[x - 1][y - 1] != map[x][y]) { ul = true; ulID = map[x - 1][y - 1]; }
      if(map[x][y - 1] != map[x][y]) { uu = true; uuID = map[x][y - 1]; }
      if(map[0][y - 1] != map[x][y]) { ur = true; urID = map[0][y - 1]; }
      if(map[0][y] != map[x][y]) { rr = true; rrID = map[0][y]; }
      if(map[0][0] != map[x][y]) { dr = true; drID = map[0][0]; }
   } else if(x == 0 && y == mapHeight - 1) {
      if(map[x][0] != map[x][y]) { dd = true; ddID = map[x][0]; }
      if(map[mapWidth - 1][0] != map[x][y]) { dl = true; dlID = map[mapWidth - 1][0]; }
      if(map[mapWidth - 1][y] != map[x][y]) { ll = true; llID = map[mapWidth - 1][y]; }
      if(map[mapWidth - 1][y - 1] != map[x][y]) { ul = true; ulID = map[mapWidth - 1][y - 1]; }
      if(map[x][y - 1] != map[x][y]) { uu = true; uuID = map[x][y - 1]; }
      if(map[x + 1][y - 1] != map[x][y]) { ur = true; urID = map[x + 1][y - 1]; }
      if(map[x + 1][y] != map[x][y]) { rr = true; rrID = map[x + 1][y]; }
      if(map[x + 1][0] != map[x][y]) { dr = true; drID = map[x + 1][0]; }
   } else if(x == 0) {
      if(map[x][y + 1] != map[x][y]) { dd = true; ddID = map[x][y + 1]; }
      if(map[mapWidth - 1][y + 1] != map[x][y]) { dl = true; dlID = map[mapWidth - 1][y + 1]; }
      if(map[mapWidth - 1][y] != map[x][y]) { ll = true; llID = map[mapWidth - 1][y]; }
      if(map[mapWidth - 1][y - 1] != map[x][y]) { ul = true; ulID = map[mapWidth - 1][y - 1]; }
      if(map[x][y - 1] != map[x][y]) { uu = true; uuID = map[x][y - 1]; }
      if(map[x + 1][y - 1] != map[x][y]) { ur = true; urID = map[x + 1][y - 1]; }
      if(map[x + 1][y] != map[x][y]) { rr = true; rrID = map[x + 1][y]; }
      if(map[x + 1][y + 1] != map[x][y]) { dr = true; drID = map[x + 1][y + 1]; }
   } else if(x == mapWidth - 1) {
      if(map[x][y + 1] != map[x][y]) { dd = true; ddID = map[x][y + 1]; }
      if(map[x - 1][y + 1] != map[x][y]) { dl = true; dlID = map[x - 1][y + 1]; }
      if(map[x - 1][y] != map[x][y]) { ll = true; llID = map[x - 1][y]; }
      if(map[x - 1][y - 1] != map[x][y]) { ul = true; ulID = map[x - 1][y - 1]; }
      if(map[x][y - 1] != map[x][y]) { uu = true; uuID = map[x][y - 1]; }
      if(map[0][y - 1] != map[x][y]) { ur = true; urID = map[0][y - 1]; }
      if(map[0][y] != map[x][y]) { rr = true; rrID = map[0][y]; }
      if(map[0][y + 1] != map[x][y]) { dr = true; drID = map[0][y + 1]; }
   } else if(y == 0) {
      if(map[x][y + 1] != map[x][y]) { dd = true; ddID = map[x][y + 1]; }
      if(map[x - 1][y + 1] != map[x][y]) { dl = true; dlID = map[x - 1][y + 1]; }
      if(map[x - 1][y] != map[x][y]) { ll = true; llID = map[x - 1][y]; }
      if(map[x - 1][mapHeight - 1] != map[x][y]) { ul = true; ulID = map[x - 1][mapHeight - 1]; }
      if(map[x][mapHeight - 1] != map[x][y]) { uu = true; uuID = map[x][mapHeight - 1]; }
      if(map[x + 1][mapHeight - 1] != map[x][y]) { ur = true; urID = map[x + 1][mapHeight - 1]; }
      if(map[x + 1][y] != map[x][y]) { rr = true; rrID = map[x + 1][y]; }
      if(map[x + 1][y + 1] != map[x][y]) { dr = true; drID = map[x + 1][y + 1]; }
   } else if(y == mapHeight - 1) {
      if(map[x][0] != map[x][y]) { dd = true; ddID = map[x][0]; }
      if(map[x - 1][0] != map[x][y]) { dl = true; dlID = map[x - 1][0]; }
      if(map[x - 1][y] != map[x][y]) { ll = true; llID = map[x - 1][y]; }
      if(map[x - 1][y - 1] != map[x][y]) { ul = true; ulID = map[x - 1][y - 1]; }
      if(map[x][y - 1] != map[x][y]) { uu = true; uuID = map[x][y - 1]; }
      if(map[x + 1][y - 1] != map[x][y]) { ur = true; urID = map[x + 1][y - 1]; }
      if(map[x + 1][y] != map[x][y]) { rr = true; rrID = map[x + 1][y]; }
      if(map[x + 1][0] != map[x][y]) { dr = true; drID = map[x + 1][0]; }
   }
}


[tl;dr]
I am trying to see for every tile on the map who are it's neighbours. I use this later to update every tile's image.

Is there any way to make this code smaller?

Getting a project done is by far the most hard thing in game development.
Offline ReBirth
« Reply #1 - Posted 2012-08-28 14:13:24 »

It's same as minesweeper, and I have made it before. Calculate the indexes first then limit to within array's length.
1  
2  
3  
4  
5  
int xi, yi;
xi = x - 1; yi = y - 1; if ((xi >= 0 && xi < map.length) && (yi >= 0 && yi < map[0].length)){ }
xi = x - 1; yi = y; if ((xi >= 0 && xi < map.length) && (yi >= 0 && yi < map[0].length)){ }
...
xi = x + 1; yi = y + 1; if ((xi >= 0 && xi < map.length) && (yi >= 0 && yi < map[0].length)){ }

That should work on every tile, even if it's on side or corner.

Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #2 - Posted 2012-08-28 14:16:07 »

This is how i did before, but now i want to check tor the "neighbours" from the other side if the tile is on the edge.

Getting a project done is by far the most hard thing in game development.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-08-28 14:28:34 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
int xi, yi;
xi = x - 1; yi = y - 1; normalize(xi, yi); //do the work
...
xi = x + 1; yi = y + 1; normalize(xi, yi); //do the work

//meanwhile

void normalize(int xi, int yi){
if (xi >= map.length) xi = 0; else if (xi < 0) xi = map.length - 1;
if (yi >= map[0].length) yi = 0; else if (yi < 0) yi = map[0].length - 1;
}

Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #4 - Posted 2012-08-28 14:29:09 »

I'd do something like that:

1  
2  
3  
4  
5  
6  
7  
 
xNext = x+1;
xPrev = x-1;


if (x == mapWidth - 1) xNext=0;
if (x == 0) xPrev = mapWidth - 1;


Then do the ifs just once using the x, xNext and xPrev which have been determined for each scenario.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2012-08-28 15:08:10 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
int xi, yi;
xi = x - 1; yi = y - 1; normalize(xi, yi); //do the work
...
xi = x + 1; yi = y + 1; normalize(xi, yi); //do the work

//meanwhile

void normalize(int xi, int yi){
if (xi >= map.length) xi = 0; else if (xi < 0) xi = map.length - 1;
if (yi >= map[0].length) yi = 0; else if (yi < 0) yi = map[0].length - 1;
}

That code seems to expect pass-by-reference behaviour, which Java doesn't have.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ReBirth
« Reply #6 - Posted 2012-08-28 15:17:06 »

@Riven
LoL really? I must missed it with C++ or what. Then since it's only primitive type how about this
1  
2  
3  
4  
5  
6  
7  
8  
int xi, yi;
xi = x - 1; yi = y - 1; xi = normalizeX(xi); yi = normalizeY(yi); //do the work with xi and yi

//meanwhile

int normalizeX(int par){
if (par >= map.length) return 0; else if (par < 0) return map.length - 1;
}

Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #7 - Posted 2012-08-28 15:17:59 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
int xi, yi;
xi = x - 1; yi = y - 1; normalize(xi, yi); //do the work
...
xi = x + 1; yi = y + 1; normalize(xi, yi); //do the work

//meanwhile

void normalize(int xi, int yi){
if (xi >= map.length) xi = 0; else if (xi < 0) xi = map.length - 1;
if (yi >= map[0].length) yi = 0; else if (yi < 0) yi = map[0].length - 1;
}


This worked, but i made xi and yi global variables.

EDIT: Ok, maybe i should provide everything in this method.

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  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
public void updateTileImage() {
   int mapWidth = map.length, mapHeight = map[0].length;

   for(int y = 0; y < mapHeight; y++) {
      for(int x = 0; x < mapWidth; x++) {
         boolean dd, dl, ll, ul, uu, ur, rr, dr;
         dd = dl = ll = ul = uu = ur = rr = dr = false;
         int ddID, dlID, llID, ulID, uuID, urID, rrID, drID;
         ddID = dlID = llID = ulID = uuID = urID = rrID = drID = 0;

         if(map[x][y] != WaterTile.id) {
            xi = x; yi = y + 1; normalize(xi, yi);
            if(map[xi][yi] != map[x][y]) { dd = true; ddID = map[xi][yi]; }
            xi = x - 1; yi = y + 1; normalize(xi, yi);
            if(map[xi][yi] != map[x][y]) { dl = true; dlID = map[xi][yi]; }
            xi = x - 1; yi = y; normalize(xi, yi);
            if(map[xi][yi] != map[x][y]) { ll = true; llID = map[xi][yi]; }
            xi = x - 1; yi = y - 1; normalize(xi, yi);
            if(map[xi][yi] != map[x][y]) { ul = true; ulID = map[xi][yi]; }
            xi = x; yi = y - 1; normalize(xi, yi);
            if(map[xi][yi] != map[x][y]) { uu = true; uuID = map[xi][yi]; }
            xi = x + 1; yi = y - 1; normalize(xi, yi);
            if(map[xi][yi] != map[x][y]) { ur = true; urID = map[xi][yi]; }
            xi = x + 1; yi = y; normalize(xi, yi);
            if(map[xi][yi] != map[x][y]) { rr = true; rrID = map[xi][yi]; }
            xi = x + 1; yi = y + 1; normalize(xi, yi);
            if(map[xi][yi] != map[x][y]) { dr = true; drID = map[xi][yi]; }
         }

         Tile currentTile = levelTiles[x][y];

         if(dd && ll && uu && rr) currentTile.update(Tile.getTile(ddID), ImageEditor.C4, ImageEditor.D4_ALL);

         else if(dd && ll && uu) currentTile.update(Tile.getTile(ddID), ImageEditor.C3, ImageEditor.D3_UPLEFTDOWN);
         else if(ll && uu && rr) currentTile.update(Tile.getTile(llID), ImageEditor.C3, ImageEditor.D3_RIGHTUPLEFT);
         else if(uu && rr && dd) currentTile.update(Tile.getTile(uuID), ImageEditor.C3, ImageEditor.D3_DOWNRIGHTUP);
         else if(rr && dd && ll) currentTile.update(Tile.getTile(rrID), ImageEditor.C3, ImageEditor.D3_LEFTDOWNRIGHT);

         else if(uu && dd) currentTile.update(Tile.getTile(ddID), ImageEditor.C2_DIRECTION, ImageEditor.D2_UPDOWN);
         else if(ll && rr) currentTile.update(Tile.getTile(llID), ImageEditor.C2_DIRECTION, ImageEditor.D2_LEFTRIGHT);

         else if(dd && ll) currentTile.update(Tile.getTile(ddID), ImageEditor.C2_CORNER, ImageEditor.D2_DOWNLEFT);
         else if(ll && uu) currentTile.update(Tile.getTile(llID), ImageEditor.C2_CORNER, ImageEditor.D2_LEFTUP);
         else if(uu && rr) currentTile.update(Tile.getTile(uuID), ImageEditor.C2_CORNER, ImageEditor.D2_UPRIGHT);
         else if(rr && dd) currentTile.update(Tile.getTile(rrID), ImageEditor.C2_CORNER, ImageEditor.D2_RIGHTDOWN);

         else if(dd) currentTile.update(Tile.getTile(ddID), ImageEditor.C1_DIRECTION, ImageEditor.D1_DOWN);
         else if(ll) currentTile.update(Tile.getTile(llID), ImageEditor.C1_DIRECTION, ImageEditor.D1_LEFT);
         else if(uu) currentTile.update(Tile.getTile(uuID), ImageEditor.C1_DIRECTION, ImageEditor.D1_UP);
         else if(rr) currentTile.update(Tile.getTile(rrID), ImageEditor.C1_DIRECTION, ImageEditor.D1_RIGHT);

         else if(dl) currentTile.update(Tile.getTile(dlID), ImageEditor.C1_OUT, ImageEditor.D1_ODL);
         else if(ul) currentTile.update(Tile.getTile(ulID), ImageEditor.C1_OUT, ImageEditor.D1_OUL);
         else if(ur) currentTile.update(Tile.getTile(urID), ImageEditor.C1_OUT, ImageEditor.D1_OUR);
         else if(dr) currentTile.update(Tile.getTile(drID), ImageEditor.C1_OUT, ImageEditor.D1_ODR);
      }
   }
}


Getting a project done is by far the most hard thing in game development.
Offline ReBirth
« Reply #8 - Posted 2012-08-29 12:26:42 »

another code to simplied? Shocked

Offline Roquen
« Reply #9 - Posted 2012-08-29 12:31:39 »

Err...forget booleans and build integers out of bits.  For example that last huge cascaded if-else construct becomes a single line.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Reply #10 - Posted 2012-08-29 13:19:50 »

You should rather explain what you're trying to accomplish to get proper solutions, rather than posting some unreadable code and ask for it to be "simplified".

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline DrZoidberg

Senior Member


Medals: 15



« Reply #11 - Posted 2012-08-29 16:30:44 »

That code is way too long.
try this

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
ArrayList<Tile> neighbours = new ArrayList<Tile>();

for(int dy = -1; dy <= 1; dy++) {
    for(int dx = -1; dx <= 1; dx++) {
        if(dx == 0 && dy == 0) continue;
        int nx = x+dx, ny = y+dy;
        if(nx >= 0 && nx < mapWidth &&
           ny >= 0 && ny < mapHeight) {
               neighbours.add(map[nx][ny]);
        }
    }
}
Offline GabrielBailey74
« Reply #12 - Posted 2012-08-29 16:33:03 »

That's sexy if it works DrZoidberg.
Big ass code optimization.

Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #13 - Posted 2012-08-29 20:15:02 »

Err...forget booleans and build integers out of bits.  For example that last huge cascaded if-else construct becomes a single line.

Can you give me an example, please?

Getting a project done is by far the most hard thing in game development.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #14 - Posted 2012-08-29 20:28:15 »

You should rather explain what you're trying to accomplish to get proper solutions, rather than posting some unreadable code and ask for it to be "simplified".

After i am loading a map from the server, i want to connect the tiles one to other... Here is a pic of what i want to achive... or i already achived, but it takes 4+ sceonds to do...


Getting a project done is by far the most hard thing in game development.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #15 - Posted 2012-08-29 21:05:00 »

Ok, now I realized that the 4+ seconds aren't from this code.. This topic may get a new way now.

I am using LWJGL. The connections you saw above are made in this "ImageEditor" class. What it does is to take the two connecting tiles images (BufferedImage) and a mask for the "connection case", then it transforms the resulting BufferedImage into a Texture and sends to respective tile this Texture's ID. The problem is that there are 19 connection cases and *currently* 5 types of tile (Grass, Dirt, Sand, Water, Tree). This "connection" stage happens only once in game, when client receive the map from server. Is there any way to make this process last shorter, or I am trying to achieve something that when i will have 20+ tiles will last even one minute ?

Getting a project done is by far the most hard thing in game development.
Offline davedes
« Reply #16 - Posted 2012-08-29 21:23:00 »

I don't see why you don't create the map with the rounded edges, e.g. in Tiled or whatever tool you are using to design the maps.

Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #17 - Posted 2012-08-29 21:27:35 »

Because i am generating the map random using Perlin Noise.

Getting a project done is by far the most hard thing in game development.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #18 - Posted 2012-08-30 11:33:04 »

Ok, how i reduced the textures made in a 256x256 map from 7000+ to (number of tile types ^ 2 * number of cases of connections) was to make a 3D int array where i store the textureID for each case. i don't know if this is the best approach, but it works very good. The time reduced from 4+ seconds to ~150 ms.

Getting a project done is by far the most hard thing in game development.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #19 - Posted 2012-08-30 13:28:00 »

Here is the last version of the update method. If anyone could suggest me anything that will make it easier, please post.

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  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
import com.minier.level.tile.Tile;
import com.minier.level.tile.WaterTile;
import com.minier.util.ResourceEditor;

public void updateTileImage(int x, int y) {
   Tile currentTile = levelTiles[x][y];
   Tile[] neighbours = new Tile[9];

   if(currentTile.getTileID() != WaterTile.id) {
      int currentNeighbour = 0;
      for(int dy = -1; dy <= 1; dy++) {
         for(int dx = -1; dx <= 1; dx++) {
            if(dx == 0 && dy == 0) { currentNeighbour++; continue; }
            int nx = x + dx, ny = y + dy;
            if(levelTiles[normalizeX(nx)][normalizeY(ny)].getTileID() != currentTile.getTileID())
               neighbours[currentNeighbour] = levelTiles[normalizeX(nx)][normalizeY(ny)];
            currentNeighbour++;
         }
      }
   }

   boolean dd = neighbours[7] != null, dl = neighbours[6] != null, ll = neighbours[3] != null, ul = neighbours[0] != null,
         uu = neighbours[1] != null, ur = neighbours[2] != null, rr = neighbours[5] != null, dr = neighbours[8] != null;

   if(dd && ll && uu && rr) currentTile.update(neighbours[7], ResourceEditor.C4, ResourceEditor.D4_ALL);

   else if(dd && ll && uu) currentTile.update(neighbours[7], ResourceEditor.C3, ResourceEditor.D3_UPLEFTDOWN);
   else if(ll && uu && rr) currentTile.update(neighbours[3], ResourceEditor.C3, ResourceEditor.D3_RIGHTUPLEFT);
   else if(uu && rr && dd) currentTile.update(neighbours[1], ResourceEditor.C3, ResourceEditor.D3_DOWNRIGHTUP);
   else if(rr && dd && ll) currentTile.update(neighbours[5], ResourceEditor.C3, ResourceEditor.D3_LEFTDOWNRIGHT);

   else if(uu && dd) currentTile.update(neighbours[1], ResourceEditor.C2_DIRECTION, ResourceEditor.D2_UPDOWN);
   else if(ll && rr) currentTile.update(neighbours[3], ResourceEditor.C2_DIRECTION, ResourceEditor.D2_LEFTRIGHT);

   else if(dd && ll) currentTile.update(neighbours[7], ResourceEditor.C2_CORNER, ResourceEditor.D2_DOWNLEFT);
   else if(ll && uu) currentTile.update(neighbours[3], ResourceEditor.C2_CORNER, ResourceEditor.D2_LEFTUP);
   else if(uu && rr) currentTile.update(neighbours[1], ResourceEditor.C2_CORNER, ResourceEditor.D2_UPRIGHT);
   else if(rr && dd) currentTile.update(neighbours[5], ResourceEditor.C2_CORNER, ResourceEditor.D2_RIGHTDOWN);

   else if(dd) currentTile.update(neighbours[7], ResourceEditor.C1_DIRECTION, ResourceEditor.D1_DOWN);
   else if(ll) currentTile.update(neighbours[3], ResourceEditor.C1_DIRECTION, ResourceEditor.D1_LEFT);
   else if(uu) currentTile.update(neighbours[1], ResourceEditor.C1_DIRECTION, ResourceEditor.D1_UP);
   else if(rr) currentTile.update(neighbours[5], ResourceEditor.C1_DIRECTION, ResourceEditor.D1_RIGHT);

   else if(dl) currentTile.update(neighbours[6], ResourceEditor.C1_OUT, ResourceEditor.D1_ODL);
   else if(ul) currentTile.update(neighbours[0], ResourceEditor.C1_OUT, ResourceEditor.D1_OUL);
   else if(ur) currentTile.update(neighbours[2], ResourceEditor.C1_OUT, ResourceEditor.D1_OUR);
   else if(dr) currentTile.update(neighbours[8], ResourceEditor.C1_OUT, ResourceEditor.D1_ODR);
}

Getting a project done is by far the most hard thing in game development.
Offline theagentd
« Reply #20 - Posted 2012-08-31 15:17:20 »

Just use bitwise transitions, for example like this:
http://www.gamedev.net/page/resources/_/technical/game-programming/tilemap-based-game-techniques-handling-terrai-r934

Also, store your tiles in a single texture. Texture binds are very expensive, and you can't afford doing them for every tile.

Myomyomyo.
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.

Dwinin (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (27 views)
2014-09-07 01:11:22

Longarmx (27 views)
2014-09-07 01:10:19

mitcheeb (35 views)
2014-09-04 23:08:59
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!