11 ms·
Show HN: Minecraft clone in 2500 lines of C - even supports multiplayer online
- tuananh 13y agohas anyone test this? how's the performance?
- chandesho 13y agoJust tried it and the peformance is fast, it loads in seconds and looks really good. My friends are already installing it and we are trying get the multiplayer working. http://i.imgur.com/Mzjxhpp.png http://i.imgur.com/Mzjxhpp.png
- ngoldbaum 13y agoSilky smooth. Easy to build too, so long as you have cmake.
- TimCinel 13y agoBuilds easily on OS X using provided instructions. Loads quickly. Renders at least 30fps, probably more.
- malkia 13y agoWorks pretty good on croutonized Acer C710 Chromebook under debian/sid chroot.
- 10098 13y agoThis is amazing. Good job!
- angersock 13y agoCMake Error at CMakeLists.txt:20 (find_package): By not providing "FindGLEW.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "GLEW", but CMake did not find one. Could not find a package configuration file provided by "GLEW" with any of the following names: GLEWConfig.cmake glew-config.cmake Add the installation prefix of "GLEW" to CMAKE_PREFIX_PATH or set "GLEW_DIR" to a directory containing one of the above files. If "GLEW" provides a separate development package or SDK, be sure it has been installed. -- Configuring incomplete, errors occurred! ~ :( (Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux)
- sown 13y agoOn ubuntu 13, I had to sudo apt-get install cmake libglew-dev xorg-dev The readme mentions this, too: sudo apt-get build-dep glfw
- angersock 13y agoRight, did all that. ;) The last step yields: Reading package lists... Done Building dependency tree Reading state information... Done E: You must put some 'source' URIs in your sources.list Debian (#!) over here. EDIT: Even after updating my /etc/apt/sources.list, and having the build-dep step run without error, I still get that original message. :(
- shmerl 13y agoIt builds and runs fine on current Debian testing.
- xmrsilentx 13y agoTry compiling cmake yourself from the latest source at: http://www.cmake.org/cmake/resources/software.html http://www.cmake.org/cmake/resources/software.html I was having the same issue on Ubuntu until I uninstalled cmake and compiled from source.
- krakensden 13y ago
- deleted 13y ago[deleted]
- Taylorious 13y agoThis looks awesome. The code is very clean and well laid out. I am disappointed that there are literally no comments in the source code though. Hopefully he will add comments, because a lot of what he is doing is not super obvious, at least not to me.
- fyolnish 13y agoAre you a C programmer?
- sown 13y agoI think everything up until main.c:909 is setup. The while look at 909 is an event loop of sorts. Between that and line 1024 is receiving the network code, IIRC. There is some GL code after that to render GL, it looks like.
- fleitz 13y agoLearn to read code instead of comments. It's super straight forward C.
- eru 13y agoWhat the code is doing is clear. The why (and especially the `why not') could benefit from some commentary.
- DigitalJack 13y agoI wish more programmers understood this concept. Yes, we can read the code for the what, which is why we don't need you to tell us you are adding 2 to X. Why is a different matter altogether, and that is where a comment can shine light on the scenario.
- eru 13y agoThanks for elaborating on my thought. The `why not' is often as important (or even more important!) then the `why'. By `why not' I mean, briefly explain what other alternative approaches there were, and why you chose the trade-offs you went for, instead of some other set.
- simcop2387 13y agoIt would appear that placing block 15 (the clouds) can cause some problems. If you disconnect while in a player created cloud it causes you to fall through the ground permanently.
- DanielRibeiro 13y agoCool. From the same author of Minecraft clone with Python: https://github.com/fogleman/Minecraft https://github.com/fogleman/Minecraft The python version uses only 894 lines of code: https://github.com/fogleman/Minecraft/blob/master/main.py https://github.com/fogleman/Minecraft/blob/master/main.py
- tmikaeld 13y agoOne starts to think - what if minecraft was made in C from the start? Would it perform better?
- simfoo 13y agoYes, dramatically.
- 10098 13y agoDifficult to say. Writing in C doesn't magically make code run faster, and it's entirely possible to get abysmal performance compared to a better implementation in a high-level language. That being said, it probably wouldn't be too difficult to make something better in terms of performance than minecraft, because its perceived perf sucks now as far as I can tell from running it on my machine: sometimes rendering lags, I regularly see mobs "suspended" in the air while the terrain renders (and yes, this happens within "old" chunks too, so I can't say that terrain is being generated or something like that), and I'm not even on weak hardware, it's a gaming laptop that runs modern AAA titles smoothly. Not sure what the source of these problems is, maybe my drivers, maybe mojang screwed up. I didn't notice these things happening on earlier versions which I ran on a fairly weak linux machine with a crappy intel graphics chip.
- tmikaeld 13y agoI bought Minecraft very early, and the more "features" that they added the worse the performance got. Adding shaders and better lighting as they are doing now, will make my gaming computer go to a crawl completely. Though it's quite known that opengl performance on java is lacking and it does not seem to have any easy fixing.
- coldtea 13y ago>Difficult to say. Writing in C doesn't magically make code run faster, and it's entirely possible to get abysmal performance compared to a better implementation in a high-level language. That's the theory, but in practice, the kind of programmer that is competent enough to pull it off in C, is also the kind of programmer that will give it better performance than the one writing it in some not very game-suitable higher level language (say Python or Java).
- ryandrake 13y agoNot to be a party pooper, but there doesn't seem to be much in the way of error checking, null pointer checking, etc. e.g. Apparently library calls like calloc() and fopen() never fail. I guess if your goal is "few lines of code" it's understandable to leave that stuff out. If your brain has the tendency to automatically go into "code review" mode, I recommend against browsing the source :)
- papaf 13y agoWhat should you do if calloc fails? Any solution I can think of requires an architecture that does not belong in a game.
- EpicEng 13y agoWell, you probably shouldn't just throw up your hands and knowingly invoke UB for starters.
- papaf 13y agoCalloc returns NULL on error - the program dies on access. I am not trying to win an argument here. I am genuinely interested in finding a good strategy to deal with memory allocation errors.
- eru 13y agoYou could either try to free memory elsewhere, or die with a nice error message.
- geocar 13y agoNonsense. The application running out of memory isn't the responsibility of the application. If this is a job for anyone, it's a job for the operating system, however malloc() fails infrequently enough that it hasn't yet been worth it. Or does your minecraft implementation in C pre-allocate memory for its nice error message at startup, resorting to direct I/O operations against video ports if that allocation fails?
- qznc 13y agoThe minetest project could use a contributor with shader experience. ;) http://minetest.net/ http://minetest.net/
- coolsunglasses 13y agoWhat is minetest trying to do better than Minecraft?
- qznc 13y agoBetter performance, especially on cheaper machines through use of C++ Easy extensibility via Lua scripting, no need for Java disassembly Free Software
- coolsunglasses 13y agoCool. I really like the idea. I wonder how a Haskell version would compare in performance. I've wanted a leaner and simpler multiplayer Minecraft for some time.
- clarry 13y agoDuring an early stage of development, I ran minetest on OpenBSD on a netbook with Atom N450. It ran smoothly with a low-ish view distance. Last I checked, Minecraft was nonfree and depended on some binaries plus did an OS check, so running it on OpenBSD would've been a nonstarter. I'm sure performance on N450 would've been miserable too; if it could run at all with just 1G of RAM.
- qznc 13y agoThe out-of-box experience is pretty minimalistic. You want to install some plugins to get some wildlife.
- rocky1138 13y agoShameless plug: my gameplay video of the latest version of Minetest. https://www.youtube.com/watch?v=ss9kAQCAzVc https://www.youtube.com/watch?v=ss9kAQCAzVc
- gravedave 13y agoMy make also fails due to Glew. Can anyone provide some premade binaries?
- delian66 13y agoHere you go: http://www.pozdravi.net/tmp/craft.2013_12_10.binary.ubuntu.13.04.tar.gz http://www.pozdravi.net/tmp/craft.2013_12_10.binary.ubuntu.1...
- Todd 13y agoLooks like it's under the MIT License.
- Yuioup 13y agoKinda getting sick of Minecraft. All those clones and remakes. Plus I don't understand my Notch is so highly praised. On the one hand he claims to be an indie dev champion but turns around and makes lucrative exclusive deals with Microsoft. If he really cared he wouldn't choose his wallet over his principles. Sorry but that is how I feel.
- Nickoladze 13y agoWeren't those deals done after Notch stopped working on Minecraft?
- driverdan 13y agoWhat exclusive deals? MC is still available for any OS that will run Java. That doesn't seem very exclusive. Mojang recently said they're going to release on PS4 too.
- simplemath 13y agoDon't hate, congratulate
- aktau 13y agoI think an easy visual upgrade to get rid of the jaggies would be to (optionally) turn on MSAA (multi sample anti-aliasing). It doesn't drop the lo-fi look IMHO but still looks ways better. MSAA is real easy to enable, create your window with a MS buffer: /* I'm not entirely sure if this is the right call for GLFW * I normally use SDL, you can usually go up to 16 with the * samples */ glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); Enable multisamplimg before drawing anything: glEnable(GL_MULTISAMPLE); Thanks for the source, I'll have a read through!
- ohwp 13y agoSome days ago there were comments about Notch being a bad programmer. And when I see posts like this I think that's unfair. 2500 lines of C doesn't mean a thing. I could do it in 1 line when I removed all line breaks. Did the programmer created the concept, interaction design, graphic design? No, Notch did. So maybe Notch does write bad code but I think being a programmer is more than just writing code. In the end Notch got the job done and people are enjoying the result. But yeah! great to see another Minecraft clone. It's always nice when people share there knowledge!
- paraboul 13y agoThat's not the point. Thing like this can inspires wannabe game developers. Reading through large source code can be very discouraging for someone that want to start programming. Things like this show that with a little bit of Math and few libraries you can bootstrap a little universe.
- swah 13y agoI saw this livestream and I bet everyone though he was a great programmer. Even though he was writing code similar to what he was already writing: http://www.youtube.com/watch?v=yM0MYoEU2-k http://www.youtube.com/watch?v=yM0MYoEU2-k Really, who are we comparing him against?
- kd0amg 13y agoI don't think I can get a good idea as to the quality of his code from this video.
- swah 13y agoHmm, but if you found out later that Quake's codebase was ugly, would you think less of John Carmack? I love beautiful code, but its an ideal to be achieved... It can't be as important as the product itself.
- exadeci 13y agoHe didn't created the concept but took the ideas from Dwarf Fortress and he says it :) http://notch.tumblr.com/post/227922045/the-origins-of-minecraft http://notch.tumblr.com/post/227922045/the-origins-of-minecr... But still minecraft makes a 2012 macbookpro overheat like no other game, I get 80°C while Minecraft alternative clients/servers barely make it to 70°
- jackweirdy 13y agoOops https://github.com/fogleman/Craft/issues/15 https://github.com/fogleman/Craft/issues/15
- frik 13y agogreedy notch
- guidopallemans 13y agothat's the first thing he does on github?
- bitwize 13y agoThis is badass. Recently I'm discovering how little C it takes to create a decent game with OpenGL. Well-written, straightforward C is a phenomenally powerful language.
- xmrsilentx 13y agoAgreed. Minecraft definitely isn't as smooth as this.
- aktau 13y agoSame here, had the same idea and started a small toy engine which I work on from time to time: https://github.com/warfare/prototype https://github.com/warfare/prototype
- xmrsilentx 13y agoCompiles and works amazingly well on Porteus.
- jburgueno 13y agoclient.c: 145 struct sockaddr_in address; ... memset(&address, 0, sizeof(address)); Can someone explain me why you need to set memory of sockaddr_in to 0 ? (Even if &address haven't been touched).
- deleted 13y ago[deleted]
- anywherenotes 13y agoit's a local variable, and local variables do not get initialized in C.
- jburgueno 13y agoBut the initialization of the variable is right after the memset: address.sin_family = AF_INET; address.sin_addr.s_addr = ((struct in_addr *)(host->h_addr_list[0]))->s_addr; address.sin_port = htons(port); Why is it useful the put 0 before setting those values?
- oh_teh_meows 13y agoIt's good practice in general. There might be other fields that were not explicitly set, or the struct may expand in future versions, or you have union fields/bitfields (e.g. you explicitly set the low order bits of some union field to some value, thinking the high order bits are all zeroes, but because you neglected to zero them out first, they're filled with garbage bits. when you read the union field as a whole you'll get incorrect values).
- jburgueno 13y agoThanks for the explanation!
- davexunit 13y agoTime to plug Minetest. The core is written in C++ and a Lua API is exposed for extensions. https://github.com/minetest/minetest https://github.com/minetest/minetest
- outworlder 13y agoJust because it has blocks and you can break them, does not make it a 'minecraft clone'. Like we do not think a rich text editor to be a replacement for Microsoft Word. Let's see a redstone implementation in survival mode :)
- m3mnoch 13y agonot to be a parade-rainer (because this is really cool!), but it's not really a 'clone'. it's really just a cube rendering engine with a handful of textures and a barebones python socket server. in my very humble opinion, a minecraft clone would have (at least stubbed out): - ui. if you've never made a game, you'd be amazed at the amount of code ui takes up. even ugly ui. good lord. - mobs. while you can data-drive a lots of your mobs, something like minecraft still has vast swaths of business logic to drive interactions with everything from creepers to mating wolves to the ender dragon. - crafting. again, you can get a long way with data-driving your crafting system, but you've still got to build in all the mechanics that control your crafted items behavior among all the other various items in the game. and none of that counts any of the polish that publishing a game requires. as a guy who's shipped games, it's really (even more so than traditional enterprise software) a case of the last 20% of the work takes 80% of the time allotted to the entire project. in my experience, that's where "indie devs" fall down. they solve the hard, interesting problems (look! i've got an environment rendering! boom! the combat code works!), but then lose interest and chase other shiny things when it comes to the rote, painful tasks (wait... i've got to data-bind the hud? and handle socket disconnects without crashing? and the camera behavior? the animation has to blend? what about handling a network timeout on the dynamically loaded textures? you want to deliver "news and updates" to the client? from what server? and you want a cms with that? oh, and write the checkbox code for options screen? and qa insists we can apply and skip the first 30 levels so they can test 31 without playing the entire game? but, but, but... look! the environment loads on my machine! what kind of video card do you have?) anyway. sorry about the rant. this really is super-cool. just more of render-plumbing and not really a clone.
- frik 13y agoI found a similar project that fits also your definition of "clone". The guy coded it in C++ and created a cross platform framework with render path for OpenGL and DirectX. He even compiled it to JavaScript and WebGL via Emscripten. And it has some initial multiplayer support and he also wrote his own GUI framework. Interesting read: http://sea-of-memes.com/ http://sea-of-memes.com/
- erichocean 13y agoSomeone should hook up LuaJIT. :)