Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  Not sure how to handle chunking  (Read 640 times)
0 Members and 1 Guest are viewing this topic.
Offline tommohawkaction
« Posted 2017-07-27 16:09:04 »

Hello
I am currently working in Libgdx and making a 3D top down game
I have made 1 chunk, however I am not sure how to handle multiple chunks

I want the system to work like this, I have 9 meshes (top left, top,top right,etc etc) I only want 9 chunks in the game at one given time, every time the player moves out of the chunk range it will generate and allocate a new chunk and deallocate a not visible chunk meaning It will only need 9 meshes (9 draw calls)

I am just not sure how to handle this... can someone explain the ways for me, there is no up or down its just like a 2D game I am only using X and Z

This is the world code
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  
package com.hawk.green.world;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.utils.Disposable;
import com.hawk.green.Art;

public class World implements Disposable {

   static final short MAX_CHUNKS = 9;
   
   private Mesh[] chunkMeshes = new Mesh[MAX_CHUNKS];
   private Chunk[] chunks = new Chunk[MAX_CHUNKS];

   private Camera camera;
   private ShaderProgram shader;
   
   

   public World(Camera camera) {
      this.camera = camera;
      shader = Art.getInstance().getShaderProgram();
     
      for(int i = 0;i < MAX_CHUNKS;++i){
         chunkMeshes[i] = ChunkMeshBuilder.createEmptyChunkMesh();
      }
   }

   public void render() {
      shader.begin();
      shader.setUniformMatrix("u_projTrans", camera.combined);
      for(int i = 0;i < MAX_CHUNKS;++i)
      chunkMeshes[i].render(Art.getInstance().getShaderProgram(), GL20.GL_TRIANGLES);
      shader.end();
   }

   @Override
   public void dispose() {
      for(int i = 0;i < MAX_CHUNKS;++i)
      chunkMeshes[i].dispose();

   }

}


This is my chunk code
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  
public class Chunk {

   public final static int CHUNK_SIZE = 32;
   public final static int WORLD_HEIGHT = 2;

   private short[][][] blocks = new short[CHUNK_SIZE][WORLD_HEIGHT][CHUNK_SIZE];
   
   private Vector2 position;

   public Chunk(float x,float z) {
      position = new Vector2(x, z);
   }

   void reset() {
      for (int x = 0; x < CHUNK_SIZE; ++x) {
         for (int y = 0; y < WORLD_HEIGHT; ++y) {
            for (int z = 0; z < CHUNK_SIZE; ++z) {
               blocks[x][y][z] = 0;
            }
         }

      }
   }
   
   public Vector2 getPosition() {
      return position;
   }

}
Offline tommohawkaction
« Reply #1 - Posted 2017-07-29 11:44:28 »

Can someone at least give me some hints, I'm kinda going for a huge map but not sure how to handle the data

So far I have 9 chunks rendering (9 meshes) I don't want to add anymore meshes I want to recreate them when i move around

https://ibb.co/ky2t5Q
Offline dime26

JGO Ninja


Medals: 60
Projects: 7
Exp: 12 years


Should traffic wardens be armed?


« Reply #2 - Posted 2017-07-30 01:49:49 »

If you are generating the whole map at once you can hold the chunk data in a file / database etc, using the players position you work out which chunks currently need loading / disposing.

You currently have 9 chunks loaded so which ever one the player moves to next its already loaded, when a player moves into one of those chunks you need to load the chunks that are not yet loaded (its neighbours). If you decide to randomly generate chunks then you would generate and save them rather than just loading them.

Will you be generating the full world before the player starts?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tommohawkaction
« Reply #3 - Posted 2017-07-30 15:13:32 »

I kinda wanted to handle a large map, but I have kinda sorted it using a smaller map but im using 81 chunks (meshes) but obviously not rendering them all at once

I wanted to see if i could make a unlimited world as i have no idea, sample code would be great
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (21 views)
2017-11-21 16:21:00

xxMrPHDxx (14 views)
2017-11-21 16:14:31

xxMrPHDxx (16 views)
2017-11-21 16:10:57

Ecumene (114 views)
2017-09-30 02:57:34

theagentd (150 views)
2017-09-26 18:23:31

cybrmynd (260 views)
2017-08-02 12:28:51

cybrmynd (250 views)
2017-08-02 12:19:43

cybrmynd (247 views)
2017-08-02 12:18:09

Sralse (260 views)
2017-07-25 17:13:48

Archive (881 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!