Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
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  
  Infinite 2D world  (Read 11169 times)
0 Members and 1 Guest are viewing this topic.
Offline Doubstract
« Posted 2014-03-01 10:00:35 »

I want to know how to avoid "Java heap space" error in big 2D worlds. If i have more than 1000 chunks i get java heap space error. I tried to save chunks and delete them from game (keep data about them in computer hard drive). but when i need to load them my FPS drops to 1 for few seconds.
Offline LiquidNitrogen
« Reply #1 - Posted 2014-03-01 10:03:35 »

perhaps you need to load a portion of a chunk each frame, rather than loading the whole chunk in one go? then the game play will still continue
Offline Doubstract
« Reply #2 - Posted 2014-03-01 10:22:49 »

I will try it, if there is no way. Thanks!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Gef
« Reply #3 - Posted 2014-03-01 10:35:54 »

If the problem is too much chuncks to load, you can differ loading by using a chuncks list that keeps all new chuncks and treat that list in your game loop by just loading X chuncks every Y (milli)seconds.
On the other hand, if the problem is too much datas to load in one chunck, as LiquidNitrogen said, you problaby need to load portion of a chunck every Y (milli)seconds.
Perharps also, the chunck file format could be a bit modified to speed up loading...

Offline lcass
« Reply #4 - Posted 2014-03-01 19:47:02 »

THere are ways to increase heap space, you could increase it then allocate an area of the memory for a cache style usage, then use a seperate thread to handle it instead of your game thread, you wont need millisecond accuracy when doing this.
Offline Drenius
« Reply #5 - Posted 2014-03-01 19:57:23 »

Since you are saying it has to be an infinite world you need to drop chunks anyways.
What does one of your chunks contain and why the hell do you need to load 1000 of them?
Offline Drenius
« Reply #6 - Posted 2014-03-01 20:28:11 »

@SwordsMiner: Note that a chunk must not be a grid of blocks but can also be a container of some objects.
so @Doubstract: What are your chunks?
Offline Doubstract
« Reply #7 - Posted 2014-03-02 21:13:29 »

I have chunks with 256 blocks (16x16), one block size is 8 pixels. And each block have tons of info about that block.
Offline Drenius
« Reply #8 - Posted 2014-03-02 21:22:04 »

Which kind of game?
Offline Doubstract
« Reply #9 - Posted 2014-03-03 12:03:24 »

Its something like a terraria or starbound
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grunnt

JGO Kernel

Medals: 143
Projects: 8
Exp: 5 years

Complex != complicated

« Reply #10 - Posted 2014-03-03 12:50:22 »

I have chunks with 256 blocks (16x16), one block size is 8 pixels. And each block have tons of info about that block.

You will always run into limits with regards to memory and/or file I/O when processing lots of data. You have several options:
- Reduce size required per block (would both decrease memory usage and delays when reading & writing chunks)
- Speed up file I/O (for example using Kryo), or by writing your own fast chunk save/load routines.
- Increase available memory (e.g. using the JVMs -Xmx<size> parameter)

I'd personally also try to optimize things in this order, especially if youre having 'tons' of data per block.

Offline Varkas
« Reply #11 - Posted 2014-03-03 14:57:30 »

... and sometimes one must recognize that the plan was too big for the current computers.

An infinite 2D world is possible if you can keep changes local to the players vinvinity. There is one active area where the player is, and 8 surrounding areas where the player might go to next.

You need these 9 areas in memory.

If the player changes from the middle area to one of the 8 surrounding areas, you drop the three "far" areas from memory and load up the 3 new neighbor areas. You can do the loading in paralell to the game, so the IO won#t block the game.

Choose the areas big enough that the loading is done before the player can traverse an area and it should be fine.

if (error) throw new Brick(); // Blog (german):
Offline 04hockey

Senior Devvie

Medals: 6
Projects: 3
Exp: 6 years

Founder of Fanger Games.

« Reply #12 - Posted 2014-04-17 00:48:31 »

What I do for my game is I have an array that stores objects that are currently loaded, and each time the update loop goes through I check to see the players movement to see if I have to load/unload any more objects.
Pages: [1]
  ignore  |  Print  

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

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

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

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

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

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

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

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

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

nelsongames (4305 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 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‑
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!