Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How does MineCraft do this?

Author
Message
jeffhuys
19
Years of Service
User Offline
Joined: 24th May 2006
Location: No cheesy line here.
Posted: 14th Sep 2010 21:23 Edited at: 14th Sep 2010 21:24
Hi,

Recently I bought MineCraft and was amazed by the awesomeness of the game.
I got inspired, and thought "I could make this" (stupid thought) and fired up Dark Basic Pro.
Using very simple code, I made Dark Basic load a reference object and instance that 5000 times (again, stupid thought). Load time: 60 seconds. FPS: ~15... Not playable.

My question is, how does MineCraft render so much cubes without any slowdown? I mean, look at this! 92 fps with so many cubes!



(sorry for page stretch)

Is DBPro seriously this slow?
Anything that can be done about it?


Thanks,

Jeff

Attachments

Login to view attachments
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 14th Sep 2010 21:32
The problem might be the sheer volume of objects required, and DBPro struggles at handling so many. It might not be the polygon count that is the problem. For instance, if you used a 4x4x4 grid of cubes as 1 object, then used the limbs instead of individual objects, then it might update faster. Worth a shot at least.

Health, Ammo, and bacon and eggs!
bergice
17
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 14th Sep 2010 21:44
Probably the way dark basic renders the cubes, it doesnt handle as many objects.

9cdfb439c7876e703e307864c9167a15
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 14th Sep 2010 22:03
As you can see there, many rows of cubes can just be merged into a stretched 'cube', thus reducing polygons significantly. This with a decent culling algorithm, and a 3D engine that handles many objects efficiently, and you're good to go...
jeffhuys
19
Years of Service
User Offline
Joined: 24th May 2006
Location: No cheesy line here.
Posted: 14th Sep 2010 22:07
Minecraft is made in Java, and I heard Java is pretty easy. Is this a good idea to learn?

Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 14th Sep 2010 22:27
Quote: "As you can see there, many rows of cubes can just be merged into a stretched 'cube', thus reducing polygons significantly. "

that and Binary space partitioning.

Quote: "Is this a good idea to learn?"

yes .

jeffhuys
19
Years of Service
User Offline
Joined: 24th May 2006
Location: No cheesy line here.
Posted: 14th Sep 2010 22:55
But isn't it better to learn C++? Since it's faster, I'm sure.

Image All
19
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 15th Sep 2010 00:43
depends on what you need to do. java seems to have the corner on web-based apps, and c++ is c++. i don't know about either being actually faster than the other, and when it comes to games, the speed is really up to the engine you write.


Remember those old guys? They made epic renders, I think one of them was called DaVinci, and all they used was MS Paint. Sometimes it's just skill....
Eminent
14
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 15th Sep 2010 01:25
Nah. C++ is faster than Java.


KISTech
17
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 15th Sep 2010 01:50
Either way, both languages are similar enough you can learn one and the other should be easy enough to pick up.

Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 15th Sep 2010 01:51 Edited at: 15th Sep 2010 01:52
There are all sorts of things you can do to speed up rendering of lots of cubes. At any one time, only 3 faces on each cube can be visible. Also, you can combine hundreds of cubes into a single mesh, or in DX10 you can use hardware instancing to draw a single cube many times.

These are the benefits you get by using a lower level engine. The downside is that it is more work, and the work is much harder.

[b]
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 15th Sep 2010 03:53
C++ is all around a better language (err, in my opinion ). Java runs on a virtual machine... and in general interpreted languages are slower than compiled ones. Its an awesome language, and its easier to learn than c++, but the two things that annoy me is that there are no pointers, and there is no operator overloading.

I'd pick up the eclipse IDE and start programming java. Once you do that, you'll probably find transitioning to c++ much easier. Getting used to Object Oriented programming is a bit weird, and I really didn't understand what it was until after I made an application in that style. Theres a quote that I hear a lot talking about how Basic mutilates the mind beyond repair - and that's kinda true xD, it's a bit of a stretch to snap your mind to a different coding philosophy.

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 15th Sep 2010 08:40 Edited at: 15th Sep 2010 08:41
Quote: "Nah. C++ is faster than Java."


Yes, but the compiled version will only run on one type of instruction set, where java is interpreted and will run on any instruction set. I heard java bein about 80% the speed of C++.

But they are both incredibly fast compared to other languages (*cough* DBP *cough*)

EDIT : Neuro Fuzzy already mentioned that

TheComet

gbark
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 15th Sep 2010 22:40 Edited at: 15th Sep 2010 22:53
MineCraft is awesome, good to see a fellow player here.

Simply spawning thousands of objects in DBP without doing any other optimizations is definitely going to slow down your game. MineCraft has a rather good system for optimizing its objects, so that only the absolute necessary objects are drawn. You could definitely get something like this working in DBP, but it'll be more work than simply spawning objects and "forgetting" about them.

First of all, as mentioned above, MineCraft uses "chunks" to handle the rendering of large sections of the level. This helps because you can group many cubes together in bulk when performing certain checks. For example, instead of checking if all 128*128*64 cubes are in camera range, you can simply check 8*8*4 "chunks", and then if those are in view, you handle the smaller objects that are located in each chunk, etc. If you have truly massive levels you might even have some nested chunks! As mentioned earlier, you may want to look into how BSP trees work to help with this task.

As for rendering, DBP uses backface culling by default, but you also want to hide (or delete) objects that are impossible to see from any angle. In MineCraft, for example, blocks that are completely buried in the ground aren't ever drawn at all. Only as you delete blocks and dig down, do the faces of the behind blocks "appear". So rather than using whole cubes, I would work with individual faces, and always check the adjacent cell to see if it's solid or not before you decide to actually draw the face.

Also, (although this might be more of a challenge), you might look at consolidating large numbers of small faces into fewer polygons. For example, if you have a 10x10 wall, instead of drawing 100 faces on one side, your engine might automatically detect that and simply draw a single face that's scaled to fit the same area. Of course, this may also mess up your lighting when you have few vertices spread far apart (unless you're using a per-pixel lighting shader), so you should think about that before attempting this method.

Lastly, you can always set your draw distance smaller and use fog to hide it.

Good luck!
Hawkblood
15
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Sep 2010 15:51
Culling is the key! I don't know if DBP 'can' go any faster....
Check out 'culling' in the help. In C++/DX you can render the objects in order of near-to-far and that would cause any objects hidden by another to be skiped in the render pipe line. Also, you can tell DX to cull CW (clockwise), which is the default-- that will cause any pollys that are facing away from the camera to be ignored.

I can't see for myself in the DBP help 'cause I'm not at my home PC. Good luck!

The fastest code is the code never written.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Sep 2010 16:36
I think the only way to get the speed more on par with Minecraft, would be to create the chunks, plain by plain - so each chunk is it's own single limb object, covering 4x4x4 blocks

Look at the math...

A 4x4x4 block, native style would use 64 objects, so already using 'chunks' means far fewer objects to deal with. So an area of 128x128x64 would use 16384 objects instead of 1 million.

Moreover though, I'd only create the sides that are needed. A 4x4x4 block, native style would use 512 polygons - however it could be represented in far less, depending on what is within that chunk. I'd say most blocks that are visible would use less than 100 polygons.

One other factor with Minecraft - the texture is 1 big texture file, except it's tiny. I think the texture uses tiles of 10x10 pixels, so having all those polygons use the same texture probably saves a lot of render speed.

Personally, I would work out how to create chunks of blocks, because DBPro just wont cope if you use 'MAKE OBJECT CUBE' - it has to work (probably) like the way Minecraft does it, rendering only what is necessary. A lot of it will be calculated before the game starts, like a blocks visibility setting. You could use an extra map array, flag the very top blocks then flood fill - and any block that is not beside a filled block is invisible. That sort of stuff would be vital, but I'm sure DBPro could do a game like Minecraft, Blockland etc.

Health, Ammo, and bacon and eggs!
Sepnon
15
Years of Service
User Offline
Joined: 7th Feb 2010
Location: Brazil
Posted: 16th Sep 2010 20:01
Quote: "the two things that annoy me is that there are no pointers "


thats what i like the most

why not c#?
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 12th Oct 2010 01:52
I have a query: How would you save all this block/chunk data? cause a world the size of Minecraft, even a small portion of it could have millions of blocks.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
gbark
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 13th Oct 2010 17:57 Edited at: 13th Oct 2010 17:58
I don't know how MineCraft handles it, but I'd say that the most efficient (memory-wise, anyway) method would be to basically "regenerate" the level each time you load the game, and only save the modifications that the user made.

For example, when a level is generated, it's generally going to have several attributes. For example, one such attribute would be what general style of terrain the word is (ie, "mountainous", "flat", "forest", etc). Another important attribute is the random "seed" that the terrain was generated from.

If you save these attributes, you can essentially re-generate the exact same terrain every time you load the level. Then you just have to save the changes that the user makes (basically any blocks the user places or destroys himself), and apply those changes to the terrain each time you load the level.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 13th Oct 2010 18:32
I would imagine that method working, but with something like minecraft, that method will start to exceed the memory usually used to store all of the positions of the cubes the more you change.

A more efficient way would be to merge a huge group of cubes together to form just one cube, and then modify the UV data for that big cube so all of the different little cube images show up correctly on the big cube. You wouldn't notice any changes, and yet you would have saved about 10'000 cubes right there in just a few bytes of data.

TheComet

bergice
17
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 13th Oct 2010 20:43
If you strafe next to 2 cubes next to eachother you will see a small seam so i think all cubes are separate objects.

51fa1db0ec7c4af52d93a6f5d0e86bc5
thenerd
16
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 13th Oct 2010 21:51 Edited at: 13th Oct 2010 21:53
That's actually true, you can see a seam occasionally if you get in just the right spot. I'm pretty sure that all the cubes are separate objects, and he just has very good culling algorithms for hiding the cubes that are not visible. The other reason I suspect this besides the visible seam is easily shown by using a custom game client such as WOM: when you noclip beneath the surface, you cannot see all the caves, just the inside of one cube. If he had a system implemented that merged flat areas together for fewer polygons, you would be able to see farther, because those cubes would not exist under the surface where they would be totally hidden.

Quote: "I don't know how MineCraft handles it, but I'd say that the most efficient (memory-wise, anyway) method would be to basically "regenerate" the level each time you load the game, and only save the modifications that the user made."
That is sort of how Minecraft does it, there is indeed a seed variable. However, there is no set time where the game saves and loads a level. The engine saves the game about once every 5 seconds, and checks for any newly generated chunks and also any chunks modified by the player, and then only saves those sectors. The Minecraft save system actually is rather inefficient, notch is planning on rewriting it entirely because the levels can become huge sizes, and then eventually become corrupted.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 13th Oct 2010 22:47
Actually, if you replace the blocks textures with completely clear textures, you can see that there is no occlusion culling.

Not sure about cubes on the surface vs cubes underneath blocks tho...

thenerd
16
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 13th Oct 2010 23:59 Edited at: 14th Oct 2010 00:04
maybe it takes into account transparency? Otherwise, the glass, water, and lava blocks would have rendering holes behind them. I don't know, I really can't wait until notch releases the source code...

[EDIT] Nope. Apparently the transparent blocks are hard coded...

I'm pretty sure the engine is voxel-based, but I have no idea how it is that efficient without culling...

gbark
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 14th Oct 2010 05:38
As stated, while there is no backface culling (to my knowledge), the game does optimize rendering by not drawing faces that are adjacent to solid edges.

There used to be a glitch (I'm pretty sure it's been patched by now) where you could get the camera to move through a wall while in 3rd person view, and this behavior would become apparent. You could look down and see all the caves and paths at the very bottom of the map, because the solid dirt that should be between your view and those caves simply weren't drawn.

Basically, only as you destroy block and dig down to the adjacent faces "appear".

Login to post a reply

Server time is: 2025-06-04 18:11:12
Your offset time is: 2025-06-04 18:11:12