Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: iCE³ - clone of Minecraft  (Read 59941 times)

0 Members and 1 Guest are viewing this topic.

Kalith

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
iCE³ - clone of Minecraft
« on: July 22, 2011, 02:44:39 am »
From time to time, I see a game that is inspiring enough for me to either try to re-code them my way or create a new game that is very similar. It recently happened with Minecraft, the fabulous game by Mojang AB (or you could say just Notch).

The concept is simple : you begin the game in a wild cubic world, with a few animals around, mountains, trees and the see. The only tool you have is your bare hands, with which you can destroy most cubes in the world to collect them, and eventually place them wherever you want.
What is the point of the game ? Well, soon enough, the night starts to fall, and monsters appear... At first you can't fight them (unless you're willing to die after earing a *pshhhhh...*), so your only option is to build yourself a house and wait for the sun to return. Then, all monsters will catch on fire and die in a matter of seconds, leaving you alone again in this wide world (~4 times the surface of Earth !).

Very early in the game, you can build some tools using your inventory, torches for example, or a crafting table, which allows you to create many new things (pickaxes, swords, ...). These will help you to discover some new areas of the game, by allowing you to dig fast in the stone, of traveling the seas with a boat.

On top of that, you can play this game on a multi-player server, to build and discover with your friends.

I really like the simplicity of the game, and the vast opportunities it offers.
So I wanted to give it a shot : could I program such a game myself ?

My first priority was performances : currently, I only have a very crappy laptop at my disposal, on which Minecraft runs smoothly only with the lowest graphics options. But it is written in Java, and some even say it is badly written in Java. So that leaves some room for improvements.
On top of that, you can run into memory problems if you're not careful : improving performances implies most of the time to cache calculations to avoid running them on every frame. If you cache too much, you end up using enormous amounts of memory... To give you an idea, Minecraft can display the world up to a distance of 256 blocks, that means roughly 70 000 000 blocks... Assuming 5 bytes per block (which is quite a low number), it sums up to at least 300MB of memory.
As for CPU/GPU performances, I have at least 30 frames per second with a view distance of 250 blocks and smooth lighting enabled (per vertex lighting and ambient occlusion), while Minecraft runs terribly slow with the same parameters (about twice slower).
But again, I'm missing many features of Minecraft, so maybe I've done some optimizations that I won't be able to keep in the future.

I've used SFML for input handling, window and opengl context creation, and 2D drawing for the GUI. I also plan to use it for networking and sound/music later.
zlib is used to compress and decompress the world files to decrease disk usage and bandwidth.
The rest is done using OpenGL directly (not a big deal actually).

Anyway, enough talking, here are the pretty screenshots :

(don't mind the 8FPS, I had to Alt+Tab to take a screen shot without the mouse on Ubuntu...)

Smooth lighting and normal lighting comparison (I erased the mouse with Gimp here... damn thing). Normal lighting is the raw result of light propagation per block. Lighting is done per cube face. With smooth lighting, each vertex takes the average light amount of the surrounding blocs and lighting is done per vertex instead. There is also an ambient occlusion effect, which is very simply implemented (~ number of occupied blocks around the vertex).


Basic procedural terrain generation.
All pictures were taken on my laptop with an integrated Intel chip, except the last one which was taken on my gaming rig that is ~2-3 years old (with GUI caching on).

What is done :
  • Basic procedural terrain generation
  • Multithreaded updating, loading, generating, saving of block chunks
  • Placing/removing blocs
  • Fully implemented lighting system with sun light (saved in the world file) and point lights
  • Ambient occlusion effect
  • Collision detection and response
  • 8 inventory quick slots
  • Inventory (no GUI yet)
  • Basic items from minecraft (all tools in all qualities)
  • Block solidity
Known issues :
  • Severe visibility bug since svn0032 (bad chunk update).
  • Imperfect collision detection code (it is possible to fall through the ground).
Current controls :
  • Escape : exit the game
  • W, S, A, D : move front/back left/right (editable in game)
  • Space : jump (editable in game)
  • Mouse left : dig
  • Mouse right : place selected block
  • Mouse wheel : change selected block
  • Shift : toggle mouse cursor
  • L : add a light
  • Shift+L : remove a light
  • F2 : toggle smooth lighting (enabled by default)
  • F3 : toggle shaders (enabled by default if supported)
  • F4 : toggle VBO rendering (enabled by default if supported)
  • F6 : toggle wireframe view
  • F7 : toggle day/night cycle (enabled by default)
You can download the sources and binaries (win32 and linux32) from the project's sourceforge page : [download], or using the following links (I may forget to update this post for every release, so don't hesitate to visite the sourceforge page). It is released under the GNU General Public License (GPL).
Although I'm much less used to distributing linux programs, it should work out of the box provided that you have the following packages installed :
  • libfreetype6 (libfreetype.so.6)
  • zlib1g (libz.so.1)
  • libgl1-mesa-glx (libGL.so.1)
  • libglu1-mesa (libGLU.so.1)
  • libglew1.5 (libGLEW.so.1.5)
Please tell me if the program requires a shared object that is not covered by this list. All other dependencies are linked as static libraries, except some very common ones like libc, libX11, ...

If you decide to compile the program yourself, I warn you : it may be a little difficult... I use several libraries written by myself for other projects, which depends among others on lua5.1 (to which I've made some modifications) and freetype2. I've also modified SFML a little ;). Latest Win32 builds also require boost::thread (until MinGW supports std::thread).
The project (and the utility libraries) needs to be compiled with GCC 4.4 at least (using C++0x). Project files for Code::Blocks are provided in each package.

You can download most dependencies from here : [download] (source only, not always updated to the last svn version), and the modified versions of Lua5.1 and SFML2.0 here : [zip], [7z] (again, source only).
Kal.

AngelHoof

  • Newbie
  • *
  • Posts: 27
    • View Profile
iCE³ - clone of Minecraft
« Reply #1 on: July 22, 2011, 01:06:08 pm »
Very interesting, and great work to you, good sir.

Zinlibs

  • Full Member
  • ***
  • Posts: 127
    • View Profile
iCE³ - clone of Minecraft
« Reply #2 on: July 22, 2011, 04:04:11 pm »
Oh my God ! I just dreamed to make a minecraft-clone too !
I'm gonna test It ! Congrats !
Zoost & Zoom libraries : An easy way to create and handle geometric objets, animate and use them for better graphics !

Kalith

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
iCE³ - clone of Minecraft
« Reply #3 on: July 22, 2011, 04:11:41 pm »
Compiling instructions are in readme.txt from the dependency archive.
Good luck :P
Kal.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
iCE³ - clone of Minecraft
« Reply #4 on: July 22, 2011, 05:38:04 pm »
Gah damn you, seems like pretty many want to make infiniminer/minecraft clones. Though I want to go more in the Dwarf fortress direction but have the FPS perspective of Minecraft. Also you confirmed everything I thought about Notch. I meet Jens(Back-end programmer at Mojang) on NGC and asked him about the performance and his answers were that Markus had prioritized functionality over performance. But if you got so much done in 10 days it feels like he should have been able to at least make something.

Anymway looks nice. Are you thinking about completing it or your just experimenting so you'll only work with it as long as it entertains you? Will you try and make something of your own or just copy Minecraft?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Kalith

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
iCE³ - clone of Minecraft
« Reply #5 on: July 22, 2011, 05:53:58 pm »
Well it only took me 10 days because I didn't have to invent anything except some algorithms. I know where I'm going, and it helps a lot.

I don't have any plans for now. As you say, I'm doing it because I enjoy it. If I ever make a truly playable version (that is, with random map generation, crafting, block drops and probably multiplayer), I won't stop here and I'll surely try to add new things ! Elevators, more entertaining enemies, etc.

If you're interested in this kind of project, there are far more advanced ones such as Minetest, which is also written in C++ and open source (but uses Irrlicht).
Kal.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
iCE³ - clone of Minecraft
« Reply #6 on: July 22, 2011, 06:31:00 pm »
I'm not interested in Minecraft directly it's more sand-box games overall. As I said I come from Dwarf Fortress which is a lot more story guided even if it's a sand-box game. So I'm actually not interested in any minecraft implementations.

Though if you want to discuss things then I wouldn't mind ^^
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Kalith

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
iCE³ - clone of Minecraft
« Reply #7 on: July 26, 2011, 05:50:54 pm »
I've released a new version, here is the changelog :
  • Implemented collisions with the world.
  • Implemented an optional VBO rendering. Should speed up rendering in all cases when available (can be enabled/disabled using the V key). It is automatically disabled at dawn and dusk, when the vertex cache is modified on every frame.
  • Created two render queues for blocks that are two sided (leaves and glass) and the others, so that face culling can be disabled for the former and enabled for the latter.
I've also tried to cross compile some Win32 binaries from Ubuntu using Wine and MinGW. I managed to build everything and run, but there are some very strange Z-buffer issues (seems to be caused by Wine, runs fine natively on Windows). Plus I had to disable VBO rendering, else the program wouldn't run (now fixed).
Anyway, here is the resulting binary (along with all the files needed to play), please tell me if it works better for you :
Kal.

Zinlibs

  • Full Member
  • ***
  • Posts: 127
    • View Profile
iCE³ - clone of Minecraft
« Reply #8 on: July 26, 2011, 09:33:05 pm »
On Windows 7, I don't have Z-buffer issues at all. :D
Zoost & Zoom libraries : An easy way to create and handle geometric objets, animate and use them for better graphics !

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
iCE³ - clone of Minecraft
« Reply #9 on: July 26, 2011, 09:49:00 pm »
Very nice :)

The Windows version works well so far. I think the default controls are quite strange (ZQSD, although WASD would be more meaningful). And the game crashes when I dig too deep ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kalith

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
iCE³ - clone of Minecraft
« Reply #10 on: July 26, 2011, 10:10:36 pm »
Great !

The crash when you dig too much is expected, and should vanish in the end. It happens because the unit you control gets out of the playable world, and ends up associated to a NULL block chunk. It can be fixed, but this crash should never appear in a full featured version with procedural generation of chunks, as there would always be a chunk to be in.

And about the controls, that's because I use a french keyboard layout, on which A/Q and W/Z are reversed...
I don't know if SFML has a way to figure out what the keyboard layout of the user is ? I could allow a simple switch in the configuration file, but that'd be much less pretty...

By the way, might I ask how performances are in full screen ?
You can switch to fullscreen by editing DefaultConfig.lua in the root directory, setting "Fullscreen" to true and modifying "ScreenWidth" and "ScreenHeight" to match your display's native resolution. That should disable the vertical synchronization and allow unlimited FPS count.
Kal.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
iCE³ - clone of Minecraft
« Reply #11 on: July 26, 2011, 10:47:50 pm »
Quote from: "Kalith"
By the way, might I ask how performances are in full screen ?
You can switch to fullscreen by editing DefaultConfig.lua in the root directory, setting "Fullscreen" to true and modifying "ScreenWidth" and "ScreenHeight" to match your display's native resolution. That should disable the vertical synchronization and allow unlimited FPS count.
Usually, I get 170-230 FPS. When looking at the clear sky, the framerate goes up to 370 FPS, during the day/night change it sinks to 70 FPS.

I used fullscreen mode with a resolution of 1680x1050.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kalith

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
iCE³ - clone of Minecraft
« Reply #12 on: July 26, 2011, 10:59:30 pm »
With VBOs disabled, performances should be strictly identical during day/night and transition periods. Have you pressed the V key (which toggles VBO rendering) ?
Kal.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
iCE³ - clone of Minecraft
« Reply #13 on: July 26, 2011, 11:17:54 pm »
Quote from: "Kalith"
Have you pressed the V key (which toggles VBO rendering) ?
No. When I press the V key, only the glass and tree leaf blocks are rendered, and as soon as a day/night transition ends, the game crashes.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kalith

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
iCE³ - clone of Minecraft
« Reply #14 on: July 27, 2011, 02:35:09 am »
Yes I think I've done something wrong with the Glew library when cross compiling... I'll try to fix this.

About the FPS drop, you're right : I see it too on my machine. And I think I've found the reason. I didn't think it'd matter so much though.

Each block has two lighting values, "sunlight" and "light". When rendered, and depending on the day time, the resulting lighting color of each face is calculated using these two values. Because they are clamped to the [0,255] range, I can make a "lighting array" that contains all possible final lighting of a block, indexed by the two lighting parameters "sunlight" and "light", to avoid recalculating them every time.
This lighting array is only updated on day/night transitions.
The same thing is done for ambient occlusion.

The actual calculation is not that expensive (it's a rather simple 256x256 double loop), but I've optimized it as much as I could, and now I don't have any FPS drop... it even runs better during day/night transitions :( For such a small optimization (a priori), I find it really hard to believe.
I've tried to understand why for an hour, profiling the rendering code, but I have absolutely no clue : rendering takes twice less time to execute when the lighting array is updated... Maybe a CPU/GPU synchronization thing ?

Anyway, I've updated the previous binaries, please tell me what is the result on your side.

Edit : I've fixed the VBO problem : wasn't calling glewInit. Strange it didn't matter on Linux though. Anyway, they are now enabled by default.
Kal.

 

anything