Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (521)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
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  
  Storing level data  (Read 1760 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2013-04-04 14:27:43 »

Hello, anybody knows a good way of storing level data? I mean, I have for example a 2d map made of squares and its dimensions are 1k by 1k. So it makes 1 million squares. Any ideas for storing such things?

PS

Minecraft has like even larger map, and it is 3d. So it makes it 50 if not more times larger. How does minecraft store such things?!
Offline StrideColossus
« Reply #1 - Posted 2013-04-04 14:45:22 »

Hello, anybody knows a good way of storing level data? I mean, I have for example a 2d map made of squares and its dimensions are 1k by 1k. So it makes 1 million squares. Any ideas for storing such things?

Really depends on what each square in your level map represents.  For example, if it's just (say) the colour of that tile then you could easily represent that as a simple in-memory 2D array for a a few 10s of Mb.  If however you're talking about height-map data, references to textures, objects within the world, etc. then that approach will obviously break down very quickly.

Quote
Minecraft has like even larger map, and it is 3d. So it makes it 50 if not more times larger. How does minecraft store such things?!

All games that have large maps use pagination.

The 'world' is segmented into tiles (or chunks of the map) and only those in view reside in memory.  As the character avatar or camera or whatever moves around the map, chunks are loaded into memory and added to the view, chunks that are no longer needed are discarded (usually on a background thread with suitable caching).  What data is in each tile and the granularity of the tiles is really down to the individual application / game.

I've used this approach to represent very large 3D world maps with each tile containing the actual terrain height-map with additional information such as cosmetic objects (trees models, rocks, etc), lighting, ambient colours, AI spawn/routing data, yada yada.
Offline ReBirth
« Reply #2 - Posted 2013-04-05 02:13:49 »

Make sure you know how much things that appear on world (grass tile, tree tile, count it) and map it to binary. It is faster and easy. In the end, you have one big number to draw whole world.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Oskuro

JGO Knight


Medals: 40
Exp: 6 years


Coding in Style


« Reply #3 - Posted 2013-04-05 13:33:56 »

To simplify the concept of pagination, as explained above by StrideColossus, think of it as having two places to store your information:

  • Hard Drive
  • System Memory

Stuff stored in memory you can use "right now", while stuff in the hard drive needs to be loaded into memory first. Kind of like having books on your desk or stored in a cabinet.

The point is to find an strategy to decide what stuff is kept on memory and what stuff is stored for later, being aware that bringing stuff back from storage is sloooooow.

Offline trollwarrior1
« Reply #4 - Posted 2013-04-05 17:13:14 »

How much space would an array of 1 million integers take in RAM?
Offline Longor1996
« Reply #5 - Posted 2013-04-05 18:33:38 »

1 Million Integers?

1 Integer = 4 Bytes
1 Million Integers = 4 Million Bytes

4 Million divided by 1024 = 3906,25 Kilobyte
3906,25 Kilobyte divided by 1024 = 3,814697265625 Megabyte

Correct me if im wrong.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline ReBirth
« Reply #6 - Posted 2013-04-06 14:11:14 »

1 Million Integers?

1 Integer = 4 Bytes
1 Million Integers = 4 Million Bytes

4 Million divided by 1024 = 3906,25 Kilobyte
3906,25 Kilobyte divided by 1024 = 3,814697265625 Megabyte

Correct me if im wrong.

- Longor1996
That's right, but to answer that question I think we need to count the address/pointer space too or it'll just be raw data sitting there. It may be very small but still.

Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #7 - Posted 2013-04-07 22:39:21 »

That's right, but to answer that question I think we need to count the address/pointer space too or it'll just be raw data sitting there. It may be very small but still.
Primitives can't have references, so the size is just 4 bytes per int. You would however need an array object too so you'd need those 4 000 000 bytes plus, uh, 12 bytes for the array object, so yeah. 4 000 012 bytes. That's assuming you use a single array (int[1000 * 1000]), not an array of arrays (int[1000][1000]).

Myomyomyo.
Offline ReBirth
« Reply #8 - Posted 2013-04-08 01:32:09 »

My mistake
Quote
1 Million Integers?

Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #9 - Posted 2013-04-08 09:15:11 »

I think that would be 8 bytes + 4 bytes for the int primitive data per Integer instance (assuming they aren't being cached), so 12 bytes per Integer. The Integer[] array needs 12 bytes for the object header+length and then length*4 bytes for the references to the Integer instances (hmm, on 64-bit VMs the reference would be 8 bytes I think?).
Array: 12 + 4 000 000
Data: 12 000 000

Total: 16 000 012 bytes.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 202



« Reply #10 - Posted 2013-04-08 15:26:42 »

(hmm, on 64-bit VMs the reference would be 8 bytes I think?).

Not with CompressedOops, which is on by default for 64 bit VMs.   There's also structure alignment though, so every object's size is effectively rounded up to a multiple of 8 bytes.
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.

xFryIx (58 views)
2014-11-13 12:34:49

digdugdiggy (37 views)
2014-11-12 21:11:50

digdugdiggy (30 views)
2014-11-12 21:10:15

digdugdiggy (26 views)
2014-11-12 21:09:33

kovacsa (48 views)
2014-11-07 19:57:14

TehJavaDev (51 views)
2014-11-03 22:04:50

BurntPizza (51 views)
2014-11-03 18:54:52

moogie (66 views)
2014-11-03 06:22:04

CopyableCougar4 (65 views)
2014-11-01 23:36:41

DarkCart (151 views)
2014-11-01 14:51:03
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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