Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (236)
games submitted by our members
Games in WIP (865)
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  
  [LibGdx] Massive fps drop when loading more than 1 texture.  (Read 3017 times)
0 Members and 1 Guest are viewing this topic.
Offline huchevsky

Junior Devvie


Medals: 3



« Posted 2014-09-16 17:38:21 »

Hello, JGO!
I have created world. World size is 250 * 250 tiles and tile information is stored in 2D object array.
At first i was generating randomly 2 tiles - dirt and empty tile. There was no problems and had like 60fps without culling.
After that i created another tile(stone) and then it started to lag(~5fps). If i generate 250x250 with only dirt tile/stone tile then fps is normal.

Writing this up i remembered that it might lag, because there is 2 different Tile objects now, but why would it lag?

If you need any code, say it. And if you don't understand me, i will try to tell this differently.
Offline lcass
« Reply #1 - Posted 2014-09-16 18:04:34 »

Tile and rendering code would be good.
Offline huchevsky

Junior Devvie


Medals: 3



« Reply #2 - Posted 2014-09-16 18:17:58 »


Tile rendering.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
/**
    * Checks every tile -> Gets tile id -> Draws correct texture.
    * If Tile is empty, ignore it.
    * @param batch
    */

   public void drawTiles(SpriteBatch batch) {
      for(int x = 0; x < WORLD_X; x++) {
         for(int y = 0; y < WORLD_Y; y++) {
            if(getTileId(x, y) != 0) {
               batch.draw(Tiles.getTile(getTileId(x, y)).getTileImg(), 16 * x, 16 * y);
            }
         }
      }
   }



Generating world
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
//Contains map information
   private Tile[][] map = new Tile[WORLD_X][WORLD_Y];
   
   /**
    * Generates new map
    */

   public TerrainGenerator() {
      for(int x = 0; x < WORLD_X; x++) {
         for(int y = 0; y < WORLD_Y; y++) {
            map[x][y] = new Tile(Misc.random(0, 2));
         }
      }
    }


Tile class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
public class Tile {
   
   private int id;
   private int durability;
   
   public Tile(int tileId) {
      this.id = tileId;
      this.durability = Tiles.getTile(tileId).getDurability();
   }
   
   public int getId() {
      return this.id;
   }
   
   public int setId(int tileId) {
      return this.id = tileId;
   }
   
   
   public int getDurability() {
      return this.durability;
   }
}


Contains tile information.

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  
public enum Tiles {
   
   EMPTY(0, null, -1),
   DIRT(1, new Texture("tiles/sand.png"), 5),
   ROCK(2, new Texture("tiles/rock.png"), 2);
   
   //Tile id
   private int id;
   //Tile image
   private Texture tileImg;
   //Tile durability
   private int durability;
   
   Tiles(int id, Texture tileImg, int durability) {
      this.id = id;
      this.tileImg = tileImg;
      this.durability = durability;
   }
   
   /**
    * Returns Specified Tile data.
    * @param tileId
    * @return
    */

   public static Tiles getTile(int tileId) {
      for(Tiles t : Tiles.values()) {
         if(t.getId() == tileId) {
            return t;
         }
      }
      return null;
   }
   
   /**
    * Returns Tile id
    * @return
    */

   public int getId() {
      return id;
   }
   
   /**
    * Returns Tiles image
    * @return
    */

   public Texture getTileImg() {
      return tileImg;
   }
   
   public int getDurability() {
      return durability;
   }

}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lcass
« Reply #3 - Posted 2014-09-16 19:38:24 »

mind if I see the batch code?
Offline huchevsky

Junior Devvie


Medals: 3



« Reply #4 - Posted 2014-09-16 19:43:33 »

mind if I see the batch code?

Sorry, you want to see SpriteBatch.java or what?
I think it's not batching problem. It might be something with tile creating or anything else.
Offline pitbuller
« Reply #5 - Posted 2014-09-16 19:44:37 »

You can only batch sprites that use same texture. Look the amount of drawcalls spriteBatch do per frame and you see that this is the problem.
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #6 - Posted 2014-09-16 19:57:51 »

You can only batch sprites that use same texture. Look the amount of drawcalls spriteBatch do per frame and you see that this is the problem.

Solution to this BTW is TextureAtlas.
Offline huchevsky

Junior Devvie


Medals: 3



« Reply #7 - Posted 2014-09-16 21:10:33 »

Thanks, fixed. You can close this. Smiley
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #8 - Posted 2014-09-16 21:11:15 »

Just edit and put [Solved] in the title.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (185 views)
2019-09-04 15:33:17

hadezbladez (4864 views)
2018-11-16 13:46:03

hadezbladez (1785 views)
2018-11-16 13:41:33

hadezbladez (5136 views)
2018-11-16 13:35:35

hadezbladez (1016 views)
2018-11-16 13:32:03

EgonOlsen (4367 views)
2018-06-10 19:43:48

EgonOlsen (5215 views)
2018-06-10 19:43:44

EgonOlsen (2946 views)
2018-06-10 19:43:20

DesertCoockie (3867 views)
2018-05-13 18:23:11

nelsongames (4293 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!