Need help optimise simple tiles that consume a lot

Hello, am building my editor and I build maps base on a 2D grid that are for the moment something like 150 X 150. The data itself ain’t that big, they are simple tiles that just need to be accessible or not, but the visual is quite heavy.

My frame drop as low as 5 frames/sec right now, even with the processor and ram not really been use. And the more a zoom out, the lower the frame rate get, at a point where it’s usually just unusable.

What I don’t understand is that usually the engine has no problem whit huge amount of spaces. I have done some test and I can basically import as many low poly item as I want and it runs fine, but for some reason this ain’t working. Here is the code:

public class MeCaseVisual extends Node
{

	 private Geometry body ;
	 private Geometry frame ; 
	 MECaseEtat etat ;
	 Vector2Int pos ; 
	 
	 public static final float size = MEWholeSettings.caseSize ; 
	 public static final float thick = MapUtils.thick ;
	 public static final float lineThick = 3f ; 
	 
	 public static final Box box = new Box(size, thick, size);
	 public static final Box selectBox = new Box(size/2, thick, size/2);
	 public static final Grid grid = new Grid(2,2,size * 2) ;
    
	 
	 public Geometry selectGeom ;
	 public boolean isSelect ;
	
	 public boolean asLayout ;
	 public Spatial layoutSpat ; 
	
	 public MeCaseVisual(MECaseConcept tileConcept)
	 {
		pos = tileConcept.pos ;
		etat = tileConcept.etat ;
		
        body = new Geometry("Box", box);  // create cube geometry from the shape
        frame = new Geometry("trace",grid) ;
        frame.setMaterial(MEMaterial.frameForBasic);
        grid.setLineWidth(lineThick);
        
		 
        body.setQueueBucket(Bucket.Transparent);
        body.setUserData("Case", tileConcept.makePosCode());
      
        body.setShadowMode(ShadowMode.Off);
        frame.setShadowMode(ShadowMode.Off);
  
      //  geom2.setCullHint(CullHint.Inherit);
      //  geom.setCullHint(CullHint.Inherit);
        
		frame.move(-size,
				thick + 0.3f,
				-size) ;

		
		body.setQueueBucket(Bucket.Transparent);
		frame.setQueueBucket(Bucket.Inherit);
		
		
		this.setLocalTranslation(
				pos.x*size*2 + MEWholeSettings.decalX,
				thick  * (tileConcept.etat.hauteur),
				pos.y*size*2 + MEWholeSettings.decalY) ; 
	    this.attachChild(body);
	    this.attachChild(frame) ;
		 
        setGlass() ;
        buildSelect() ;      
     }

I was thinking about creating the object direcly in blender and then import it, but i fell like am missing something important here.

So you’re creating one box per tile? Thats bad. Make one mesh.

Well, every box have an individual height, and i was thinking about giving them a individual shape so they can fit the ground they are on. I don’t think i could do that whit only one mesh :confused:

Sure you can, Minecraft can too… But if you don’t know how to do it at least batch your boxes… That will still leave you with lots of wasted vertices (namely the ones below the surface) but you’ll at least not have ten thousands of objects.

It doesn’t sound like you understand what a mesh is. But for now you can just do what normen said and batch them. Have a look at http://wiki.jmonkeyengine.org/doku.php/jme3:intermediate:optimization

I fixed your code blocks for you. People still insist on trying to use the indent approach (I guess because it’s what the button does) but it’s horribly broken and it’s better to use the three back ticks approach. I wish we could fix the button to use the better way.

2 Likes

I have test the solution you gave me and it work, but I then lose the transpanrency on my tile. What should be done now?

After some more testing it seem like even my more powerfull computer il not able to run it at more then 30 frame secondes.

But i don’t underthand why. its only lines and cubes. Is it the tranparent filter?

It. Is. The. Number. Of. Objects.

2 Likes

So your telling me that the only solution I have to make a large grid is to build it as one large mesh build whit the coordinates of pairs of triangles and to calculate every interaction whit those triangles instead of simply declare every pair as object and then refers too those objects?

Its really the only valid options? Cause that seem like a lots of work for a simple interactive grid.

Yes. This doesn’t have anything to do with the engine btw. thats just how it is with 3D game graphics.

O well don’t get me wrong, I ain’t blaming anyone this just seem way more complicated than it have too. But alright, I got do just that, I’ll post the results when it’s done.

Imagine it like your usual calculator:
It takes you more time to enter the expression than it takes the calculator to do the calculation.

This is basically the same with GPUs. Telling them to start drawing takes more time then drawing itself, so, the bigger the buffer, the faster the same triangle count will be

Note: As always there’s a sweet spot. The Engine removes backsided Triangles and far away ones (the latter only in theory/LOD), so too big objects wont work either

In our analogy that would be if you run a programm which calculates more additional stuff that you don’t really use/cant even see

1 Like

Note: not necessarily one large mesh. But definitely large meshes. For example, you might have one mesh per layer. Or you might have one mesh for one tileset and one mesh for another tileset. Or you might have a separate mesh for the transparent tiles.

Edit: by the way, 150x150 tiles seems like a lot of tiles to fit on screen at once. How big are they?

They aint all display at once, only like 7575 max are display at the same time. For the moment the map is 165 per 110 and each tile is a 4 per 4. But this is only for the editor, i won’t display that map for the user. Also that size is just for testing, the goal is too maybie go up too something like 500500

For the moment the only valid solution i found was to get the thick as low as possible, because doing everything by mesh would be just too much work. But am still on it and testing stuff.

Well, you shouldn’t bother to render tiles that aren’t on the screen really. Generate what you render on screen from the world tiles, sure… but only what you need. When the player moves from one tile to another then regenerate the screen layer meshes.

It’s actually not that complicated and I guarantee you this is similar to what every other tile-based game will be doing.

Well, after reading the whole thread (:stuck_out_tongue: lazy me):
Such a Minecraft-Style-Game simply shifts the artistic power to the coding power. Even though the game looks bad, it’s incredibly hard.

First of all: (I think this one’s a normen quote) “A Box world is not made out of boxes”

Grab yourself two dices and lay them on each other. Now you have two intersecting faces of which one would be drawn but is invisible to the user. Remove that.

Now think of an atleast 3x3x3 Dice Array. The inner die isn’t drawn at all (or it shouldn’t be), except when using transparency, which is fun again.

So my advice is: Create 8x8 Tiles, perform such an intersection analysis on all blocks like: if me.blockAbove() removePlane(0);
For this, you could simply extend Mesh and “Simulate” a Box by simply having 6 Planes with a different rotation.

Ideally you use the same algorithm again when you stitch tiles together

Note aswell: You shouldn’t really extend Node/Spatial/Geometry. You could use an “TileControl” on Nodes or have some Array with Tiles which have a Link to the Node but generally you should split Logic and Graphics.

When you did this, you could use the BatchNode to batch all the boxes of a tile together, with the problem that you need to recalculate everything once you remove a Block out of a tile (Note: You need to anyway, since the hidden faces will change)

So this will be a simple way to have a way better performance with next to no problems in implementing.

Oh… is this a Minecraft clone?

That’s a whole different ball of wax.

Pretty sure it don’t, i have not touch the faceCull and the default mode should already do that, no? And its not a minecraft close, its a tactical, so i use the grid to show the world in editing and help in the player combat mode.

Dark :
This is a lot too digest, i kinda knew a little bit about that but not deeply enouf it seem. I’ll take my time and come back after a full underthanding of all of this x)

My fault. I read “Minecraft” in the title but this was a comparison by normen.
However since it seems an editor for a 2D-Grid with each grid having a different height? it’s barely comparable in it’s style.
(With the exception that it doesn’t have to be really playable, only semi-performant)

Edit: Simon, just give the dice idea a try in the real world. Then try to compile a Box clone by using 6 planes (each number on a side of the dice). When you have that, you only need to remove the right plane on time :slight_smile:

Edit2: And if not, simply create bigger tiles (like 8 to 16 world units) and simply make each tile one batched node.