Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  How to work with a big world? EXTENSIVE QUESTIONS  (Read 1810 times)
0 Members and 1 Guest are viewing this topic.
Offline neuronich

Junior Member


Medals: 5



« Posted 2012-03-06 20:49:06 »

I'm using LIBgdx. My game seems to be pretty intensive in the future. Actually I'm interested how to not overload my system?
1. I'm wondering how many sprites can be drawn simultaneously on the screen? (For a normal computer. I'm having about 15000 right now)
-Should I care about cheking whether I see a sprite on the screen?
2. How many objects should I have in my game?
-Imagine I have a tiled map.
             -Can I have a separate object for every tile? (Now I'm making a list of objects. I have about 15000, but need more for bigger world)
             -Or should I better have some arrays, where every array stands for a certain property of my object?

For Example, let's take Minecraft. There's a huge world. Millions of blocks. The world lives all the time around you. Especially when there's a lot of players.
-How does he draw them?
-How does he update the world?
-How can I make the chunk System?

P.S. Can Eclipse check how much that or that action takes? I understand I can put System.nanoTime(); but in NetBeans there's a special tool for it.
Offline evilfrenchguy

Junior Member


Medals: 3



« Reply #1 - Posted 2012-03-06 22:08:48 »

I believe Notch/Markus/Mr. Perrson uses lwjgl for his rendering.

For "chunks" and how the world is stored, picture the whole world as 2d array of chunk objects. I imagine an initial 1000 x 1000 x 300 (w, h, d guess) chunk is generated with his algorithm for spawn, then an additional chunk is generated for each adjascent chunk surrounding the spawn chunk. Basically, always keep chunks around the player so they can see on the horizon.

Whenever the player would be about to move to an edge chunk (no more chunks in that direction PAST the one you're about to enter), generate border chunks for THAT chunk.

Any chunks you've already had generated that aren't in your "box" of chunks around you are probably written to a file and dumped from temp memory until you backtrack to those areas again.

I've never seen Minecraft's code, but that's how I would do it.
Offline Geemili

Senior Member


Medals: 9
Projects: 1
Exp: 2 years


No Games Finished


« Reply #2 - Posted 2012-03-06 22:25:43 »

I am no expert, but right now I have a game where there are chunks. Each chunk has its own 2d array of blocks, and the chunks are loaded depending on where the player is. I save the chunks in a text file, in the format:
1  
chunk.x.y


It works pretty well for me. Updating them is very easy. When you load a chunk, you put it into an ArrayList, and make a max amount of loaded chunks. If you reach that max amount, you check to see which chunk you can remove, save it, and remove it from the ArrayList. The only problem I have is with optimization...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pixelprime

Junior Member


Medals: 3



« Reply #3 - Posted 2012-03-07 00:08:40 »

I've never seen Minecraft's code, but that's how I would do it.

This behaviour is actually quite easy to see if you install any admin mods that allow you to fly faster than the recommended speed.

Since chunk loading is handled on its own thread, the effect in-game is minmal and mostly unintrusive. However, if you pick a direction and fly very quickly - you'll eventually start seeing chunks loading on-screen. The division between the chunk areas in this instance is very easy to see.

I may be wrong, but I believe the chunk size in Minecraft is 64x64x256 (1,048,576 blocks). Obviously there are easy ways of graphing this data to be more accessible and quicker to load (since they aren't 1.04 million unique blocks), but generally speaking that's still a vast array of data to store - so it should give the OP some idea of the clout possible with modern CPU / rendering techniques.

I do get the impression, however, that the OP needs to be a little more familiar with zoning and other techniques for improving CPU load and render performance. I would never subject a game to 15,000 simultaneous object updates - or in fact 15,000 renderable objects in one pass. You should be using techniquies such as view culling, and zoning out areas where updates shouldn't be happening (as mentioned by another poster).

This is the best place to ask such questions though, just don't be afraid to try out some of these things and make mistakes along the way - that's how we all learn Smiley
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #4 - Posted 2012-03-07 00:23:43 »

I may be wrong, but I believe the chunk size in Minecraft is 64x64x256
You're wrong. Wink

Chunks are 16x16x128, but are stored in region files which contain 32x32 chunks each.

Except it just changed, so now chunks are 16x16x16, and there may be up to 16 chunks in each vertical collumn (so the max height is now 256). Which means I have to re-write my map renderer again.

More info on the wiki, if you want: http://www.minecraftwiki.net/wiki/Anvil

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline pixelprime

Junior Member


Medals: 3



« Reply #5 - Posted 2012-03-07 11:03:19 »

Chunks are 16x16x128, but are stored in region files which contain 32x32 chunks each.
Except it just changed, so now chunks are 16x16x16, and there may be up to 16 chunks in each vertical collumn (so the max height is now 256).

I stand corrected! So, the layout is essentially divided into 4 chunk columns (in each region file), and up to 16 chunk slices in each column of 16x16 within that 32 x 32 region. Thinking logically, that's a better organisational method, since it'd be trivial to view-test the bounding area of a chunk for rendering rather than based on the player's position. So really, unless you're looking into an enormous quarry, you're actually not seeing a whole lot of chunks at runtime.

Anyway, this is veering off the OPs question now, and delving into the intricacies of data management in everyone's favourite brick builder!
Offline neuronich

Junior Member


Medals: 5



« Reply #6 - Posted 2012-03-08 18:13:37 »

Could you advice culling and zoning tutorials.

Don't think I'm lazy. I tried to Google it. Mostly I found 3D connected topics.

My question is not so about chunks and Minecraft. But about OO programming. Don't millions of objects slow up the project? Is it better than having an array or List?
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #7 - Posted 2012-03-08 18:56:19 »

My question is not so about chunks and Minecraft. But about OO programming. Don't millions of objects slow up the project? Is it better than having an array or List?

The idea is *not* to have millions of objects. You split your world up into manageable chunks somehow (like a regular grid minecraft uses) then load and unload only the chunks near the player so you're only acting on a small portion of your huge world. Loading and unloading should be done on a separate thread so you don't jam up your main update/drawing thread.

For culling you might want to start with googling quad trees.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!