r/Minecraft • u/Asmageddon • Jun 06 '11
Few technical ideas for minecraft from a programmer.
1) Level saving:
Use octrees for saving level data. This should greatly reduce disk usage. Could also be used for storing data in memory, but that could lead to a drop in performance(hopefully not very severe one)
Allow for more than 256 block types - BZip(and GZip, dunno which one is used) uses huffman coding, so it won't take much more space if there can be 264 block types than it would with 256. You can use huffman for storing them in memory as well, so RAM isn't an issue
2) Rendering:
Chunks are 16x16x16. Why not raise render range, but load and render 8x8x8 approximations of chunks instead? And then 4x4x4. This could be used to significaly raise view distance without significant performance drop. Octree-based level format would be again very helpful.
AGAIN. If you use octrees, you can improve performance, since a single octree node can mean at most 6 quads instead of 24/96/384/1536. You probably "fuse" them anyway, but I believe this would still be superior.
3) Level data:
Use control bits for controlling size of tile variables - by adding 2 bits that switch between 0/4/8/16 you could save 2bits on blocks with no data and be able to have 256 variations of cloth or 65536 different values for some new redstone-powered block. And if you add 4 control bits, you could - if needed - have enough per-block storage to make custom paintings, TV's and chests with small worlds inside. (own plane of existence, anyone?)
This could be used for scripted redstone processor blocks. hint hint hint
4) Unlimited height maps.
NOTE: I cannot guarantee that it will be possible with these ideas, but I believe they will be highly useful when/if you decide to implement them.
- Lightning
Solution A: store a 16x16 lightmap per chunk indicating sunlight level in bottom layer of the chunk, so whole chunks don't have to be loaded. Every time sunlight is propagated to lower chunk, darken it for z<0 and brighten for z>0, so floating islands/bottomless pits won't pose a problem Solution B: Store heights at which level of sunlight changes and to what value as a list. Would have additional advantage of allowing sunlight-creating blocks(Artificial sky in caverns? Why not!)
- Chunk loading in case of falling.
I'll repeat this again: If you use octrees for terrain data, this won't be as serious problem as it is otherwise, but: If you don't store all level data as octrees: Store only chunks deep below in compressed format(but still in memory), so they don't occupy much RAM and can still be loaded very quick into proper map data. (this could also be used to lessen disk I/O when moving normally...)
- Objects - simple, don't process stuff too far from player
5) Level generation
- Abstract it.
Instead of having built-in level generator - make it simply put the level together based on heightmap, cave and debris maps supplied by separate modules. Allow loading building/dungeon/etc. data from supplied bitmaps. This should ease modding a lot and provide a good base for any potential future abandoned buildings/towns/etc.
Other programmers feel free to contribute your ideas or comment on these ones.
258
u/xNotch Minecraft Creator Jun 06 '11
I get suggestions like this every now and then, and while I appreciate the effort, most of your suggestions won't work.
The biggest issue is that you suggest I change how data is loaded in memory. Right now accessing or modifying a block is a straight array lookup, which is O(1). You can't get faster than that, so almost all other forms of storing the data in memory would result in a dramatically slower game.
Specifically, reading from an octree is O(log n), and writing to it is O(godknowswhat) since any block change can cause the entire tree to rebuild. The reason BSP (another space partitioning scheme with O(log n) read time) is/was popular in the past is that a read was O(n) without it, and the level data was never modified while playing the game.
17
u/Asmageddon Jun 06 '11
Oh, and I can provide example implementations of these ideas in Python or C++ if any of them are unclear.
31
u/[deleted] Jun 06 '11
And slows down chunk load/save operations, especially when you need to load and decompress a lot of surrounding data to get at what you're trying to load. McRegion works really well as a trade-off on size vs performance.
Aren't they 16x16x128? Irrelevant anyway, as what you're talking about is inflating the amount of data being loaded / decompressed / processed to render the surrounding area, which is already a problem.
I have no idea why you think this is a good idea. You'd be pulling a lot of control of game mechanics out of the game itself, which would be a bizarre design move at best.
Currently this already happens at around 300m, if I recall correctly. Decreasing that breaks a lot of current game mechanics. For example, mob spawning towers, water propagation after a change in state (via some kind of redstone action), redstone circuits themselves.
Usually easier said than done. There are a lot of improvements that can be made when you remove abstraction from the equation, and you might find chunk generation quite a bit slower / more CPU intensive if you try to make it truly extensible.
8
u/gr3yhill Jun 06 '11
I think everyone who plays MC and has some programming experience gets a number of ideas like this eventually. I recommend you implement a toy version of minecraft yourself and see how it pans out :-)
6
u/Hacksaures Jun 06 '11
Actually, chunks are 16x16x128
11
u/idrumgood Jun 06 '11
Did someone just learn about octrees in class this week?
4
u/00bet Jun 06 '11
shamless self promotion, check out my block game: http://www.youtube.com/watch?v=jMbJ4lGGkBs&t=1m10s http://www.youtube.com/watch?v=20KPUZTJzGU
.... In my game, instead of using an octree, what I do is I use wrapping and page into a single toroidal texture. I'm still implementing this, but the idea is to use RLE compression for pages that is away from the camera (cam is center page) and decompress when near the camera. I'm hoping that this will shave some memory off and will let me extent the view distance further out (current view distance is 352 blocks). I haven't done any hard calculation although I guess I should. Apart from saving memory this way, the other thing I'm doing is avoiding storing light values and avoiding per vertex interpolation and instead sample on the GPU. The latter allows me to decimate the mesh. In practice I'm betting on I can decimate quite a few faces. My earlier tests show that this is indeed the case. Plus decimation also helps with reducing data on the physics side.
For out of memory storage I will be using B-tree.
As for those other points you listed, I will have to think about it.
2
u/desimusxvii Jun 06 '11
Since chunks are actually 16x16x128 (which is a complete vertical column), a quadtree would make much more sense than an octree. But as Notch said he's already using arrays..
3
u/cored Jun 06 '11
This would kill monster farms and large scale redstone projects.
8
u/Xalem2 Jun 06 '11
Octrees only save space if large blocks are consistently all the same material. if a typical chunk could be represented by several 64x64x64 blocks(or nodes) of air, and several 32x32x32 nodes of smooth stone, and the other stuff could be described as 8x8x8x nodesof dirt, and there were few, very few 1x1x1 nodes in the map. Then maybe, just maybe one might save some space. The trouble is, most minecraft chunks have lots of irregularities, a single block of dirt reaching into a 32x32x32 pocket of air means that, the representation of that 32x32x32 block has to be broken down into 8 nodes of 16x16x16, and one of those has to be broken down into 8x8x8, then 4x4x4, then 2x2x2, then 1x1x1. So, what was one node, becomes 1+8+8+8+8+8=41 nodes.
So, 41 nodes is less than a 32x32x32 array containing mostly air.
Well, lets make an assumption. At every level, half the nodes need to be split. Given the nature of Minecraft maps, it sounds intuitive, but feel free to do some experiments. So, for a 128x128x128 block, half the 64x64x64 nodes (not likely, but let's pretend) is 8 8 nodes (size 64) divided by 2 then times by 8 = 32 32 nodes (size 32) divided by 2 then times by 8 = 128 128 (size 16) times by 4 (using that math degree) = 512 512 (size 8) *4=2048 2048(size 4) *4=8192 8192(size 2)*4= (break out calculator) 32768 32768 1x1x1 nodes, plus all the other nodes in the list is somewhere in the order of 44000 nodes. It can vary. in a much more disorganized chunk, replace the *4 above by a different number, and the number of nodes grows exponentially.
A far simpler way of compressing the existing chunks 16x16x128 is to have a few simple codes in the stream of layer by layer data. The codes can mark when an entire 16x16 layer is air, or the entire layer is smooth stone or or entirely water. Simple, clean and effective.
2
u/kcfcl Jun 06 '11
I'm afraid I won't be able to help here, but I'm curious about octrees. Do you know some good links about that, or game programming in general ?
13
u/WhatTheFuck Jun 06 '11
You can always count on /r/minecraft to upvote shit they don't understand.
1
u/maskull Jun 06 '11
My programmer's suggestion would be for a more resilient world file format. Server crashes have a nasty tendency to corrupt the world. Take a page from the land of traditional databases and do some transaction logging so that failed writes aren't (as much of) a problem.
9
u/GTB3NW Jun 06 '11
Great ideas, constructive criticism is always better. Could you direct me to some useful information on octrees please? :)
1
u/Asmageddon Jun 06 '11
Actually, i have idea for a structure even better than octrees(at least in terms of size): Every node has 4 control bits - does it split on x/y/z axis and if it holds data. Data is block type(+properties), and the node contains 0/2/4/8 sub-nodes. If there is no data, it is propagated from parent node or set to 0 in case root node has no data.
1
u/yatima2975 Jun 06 '11
Chunks are 16x16x128, first off. It has been ages since my 'Computational Geometry' course, but I think the way the chunks are stored, with a file/folder name based on x and z kinda-sorta converts them into a quadtree already, depending on the filesystem implementation.
As for the level data, that seems to be reinventing the Unicode wheel again. It makes for non-uniform block access: to find what is at a given spot you need to look at the control bits coming before it.
I don't really have a solution handy, but how about something like this: if the block id is 255, look in some kind of table (separately stored in the chunk file) for the rest of the data? That way, you don't have to change the current layout, just a field to the save file. A mapping between x/y/z in chunk coordinates to a type word and an offset would work here, I guess, since you won't have a chunk full of custom paintings or compressed redstone processors.
Your light map idea seems pretty reasonable, at least for storage and transmission over the net.
Disclaimer: I wrote a mod for 1.3 (yeah, yeah, should update now that the next update is far away) that raised the height limit to 512/1024/2048 (which is unlimited enough for me and my poor computer at the moment). It also allowed for raising and shrinking chunks by steps of 16, and that was basically all I could do before completely rewriting the engine; I'm no big OpenGL whiz so I can't comment on how the renderer would have to change.
If you want to give it a whack, why not try out the Minecraft Coder Pack?
5
u/netcrusher88 Jun 06 '11
Hello. I'm the Doctor.
2
u/inmatarian Jun 06 '11 edited Jun 06 '11
Question, when Mojang opens up the source code, can you audit the code and make these suggestions again? I'd like to see if you can show where these little tweaks would go, or if it would require tons and tons of rewriting to do it.
Edit: who put r and f next to each other?
1
u/longshot Jun 06 '11
I've had that rendering idea for a while, but haven't done anything in the java/gaming realm.
1
u/[deleted] Jun 06 '11
I don't know how minecraft internally works, but I will appreciate if someone could help me a little. I have a few questions (don't downvote me if they're too basic, I haven't player so much multiplayer games).
Are multiplayer games "persistent"? What I mean, redstone circuits breaks if they're not completely loaded in single player, does that happen also in multiplayer? Or the server "has consciousness" and take care of everything? For example, in a very very long minecart track. Will an empty minecart continue it way all the circuit, or it will stop as soon as is not in "visible" range of any player? I think, the ideal solution is to take care of everything (the minecart will not stop), but that's will take more server resources. If that's accomplished, single player games should run on a local server.
1
u/Not_Edward_Bernays Jun 07 '11
I don't think disk usage is a problem and I doubt octrees would be practical to improve that. I do think octrees could be applied usefully to a Minecraft-like game but don't know exactly how. Maybe if you were doing some type of 3d raycasting it would make rendering more practical.
Overall I think he has some interesting ideas. Its about 100x easier to come up with ideas though than to code them.
To me this is a really obnoxious post though. It almost sounds like he thinks he could code it better. If he is such a great programmer and knows better than Notch, then I hope he will make his own Minecraft-like game with unlimited height and worlds inside of chests.
I say, prove it, otherwise, shut up.
1
u/SN4T14 Jun 06 '11
A chunk is 16s16x128.
-1
u/[deleted] Jun 06 '11
I totaly octree
-2
u/Darkersun Jun 07 '11
You should program it in Python.
-3
u/rocketsocks Jun 07 '11
Step 1: Write your own (obviously technically superior) minecraft clone game.
Step 2a: If said clone game is very successful than then bask in your success and hope that minecraft will take some inspiration from your technical innovations.
Step 2b: If said clone game is not a success, then maybe consider keeping your "helpful" technical advice to yourself instead of broadcasting it to the world.