Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 2527 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...

Online 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 SwordsMiner

JGO Coder


Medals: 3
Projects: 2
Exp: 1 year


The one and only.


« Reply #6 - Posted 2014-03-01 20:20:00 »

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?

If your taking the minecraft approach thats fine, but still, 1000 chunks of probably 8x8, 16x16, 32x32 blocks or similar data? With the 2D game I am making I could achieve infinite chunks with only 16 ever having to be loaded at a single time.

If I made you laugh, helped you at all, or did something cool, I only ask that you smash that appreciate button with your nose.
Offline Drenius
« Reply #7 - 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 #8 - 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 #9 - Posted 2014-03-02 21:22:04 »

Which kind of game?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Doubstract
« Reply #10 - Posted 2014-03-03 12:03:24 »

Its something like a terraria or starbound
Offline Grunnt

JGO Wizard


Medals: 68
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #11 - 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 #12 - 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): http://gedankenweber.wordpress.com
Offline 04hockey

Junior Member


Medals: 2
Projects: 1
Exp: 2 years


Founder of Fanger Games.


« Reply #13 - 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  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (19 views)
2014-09-19 03:14:18

Dwinin (34 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (84 views)
2014-09-10 06:39:09

Tekkerue (42 views)
2014-09-09 02:24:56

mitcheeb (64 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (39 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59: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!