Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
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  
  Adding chunks to world for large maps?  (Read 5526 times)
0 Members and 1 Guest are viewing this topic.
Offline GNecro1
« Posted 2015-02-17 13:07:19 »

I really don't know how do i implement large maps(over worlds), but i split it into smaller maps, like chunks, and update them only... If you know any tutorial or something, please don't hesitate to share! Thanks in advance!

Java freak! Cheesy
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 288
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #1 - Posted 2015-02-17 13:37:17 »

Sounds like a job for some kind of tree structure.

Top node is the whole world. Break that up into several child nodes: North, South, East, and West for example.

Break each of those child nodes into further nodes.

When you update a node, first check if it needs to be updated, and if so, tell its children to update recursively until you reach a leaf node that needs to be updated.

See also: http://en.wikipedia.org/wiki/Quadtree

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline GNecro1
« Reply #2 - Posted 2015-02-17 20:52:06 »

How would i do this for infinite terrain?

Java freak! Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2015-02-17 21:35:54 »

Not a single player will appreciate infinite terrain.

Make the world big enough and use a tree structure.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline GNecro1
« Reply #4 - Posted 2015-02-17 21:39:37 »

I dont realy know what that means.... a tree structure?

Java freak! Cheesy
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2015-02-17 21:43:53 »

Click KevinWorkman's link.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline Ed_RockStarGuy
« Reply #6 - Posted 2015-02-18 01:05:07 »

https://github.com/4H1Z1/Horizon/blob/master/src/com/horizon/game/map/MapData.java
This is how i used to save infinite maps, it breaks the land into 16X16 chunks, its just the basics, no map saving, no nonsense, but don't copy it and expect it to work, try and learn from it Smiley

*Update*

Well semi infinite xD but it also has a good example of how to add in world generation too
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 288
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #7 - Posted 2015-02-18 13:50:01 »

I dont realy know what that means.... a tree structure?

If you don't know what a tree structure is, then you probably shouldn't be worrying about creating infinite terrain.

I'm not trying to discourage you, but you really might want to take a step back and start with something smaller- you'll be more likely to succeed by taking smaller steps instead of trying to bite off more than you should be chewing.

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline Edd

Senior Newbie


Medals: 1
Exp: 2 years



« Reply #8 - Posted 2015-02-18 23:45:54 »

Since you already have split your map into chunks, saving and loading only nearest chunks shouldn't be that hard to achieve in order to save resources. What I would do is check the closest chunks around the player and test N, NE, E, SE, S, SW, W and NW cases:

This would work for a fixed size map. Also you would have to do some out of bounds checking. As for saving, I would try serializing the unneeded chunks and deserialize the new ones.

Thought for infinite map you should really look into some kind of structure. Or you could store them in an 1D ArrayList<Chunk> this way you could expand it as much as you need, just a wild thought.
Offline Ed_RockStarGuy
« Reply #9 - Posted 2015-02-19 01:05:21 »

Since you already have split your map into chunks, saving and loading only nearest chunks shouldn't be that hard to achieve in order to save resources. What I would do is check the closest chunks around the player and test N, NE, E, SE, S, SW, W and NW cases:

This would work for a fixed size map. Also you would have to do some out of bounds checking. As for saving, I would try serializing the unneeded chunks and deserialize the new ones.

Thought for infinite map you should really look into some kind of structure. Or you could store them in an 1D ArrayList<Chunk> this way you could expand it as much as you need, just a wild thought.

Unless your like me and asign a priority to each chunk based on what is on it and over time depsawn the chunks that are 3+ chunks away from the player
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 383
Projects: 11
Exp: 4 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #10 - Posted 2015-02-19 04:57:10 »



I've tried several methods of chunk loading in my voxel engine and found this approach to be the best. It allows you to have minimal allocations and you don't have to worry too much about data becoming invalid because that's part of the design. If you're happy with a fixed-size view of the world then this is the way to go.

Offline GNecro1
« Reply #11 - Posted 2015-02-21 12:03:40 »

Well i made something that is working BUT i load all of the chunks and if i have a lot my ram usage goes over 1 Gb.... and i dont want that

my world class

https://github.com/GNecro1/RPG/blob/master/src/net/world/World.java

and my Chunk class

https://github.com/GNecro1/RPG/blob/master/src/net/world/Chunk.java

I was thinking to just have an a 2D array of 3x3 chunks and as the player moves i make the previus chunk = new chunk.... and i don't really know how.....

Java freak! Cheesy
Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

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

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

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

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

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

nelsongames (5500 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

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