Coder Social home page Coder Social logo

c_minecraft_clone's Introduction

C "Minecraft Clone"

a lake scene with clouds

For some value of "Minecraft Clone". Updated in late 2023!

This was a university project back in 2010/2011 which I really enjoyed -- build a minecraft-like world of cubes with OpenGL, including first person mouselook+wasd controls, digging, mobs, perlin-noise caves, clouds, and hills, a day/night system, and networked players. At the time I got to a place where, well... I think I passed.

Over the years I'd come back to it every once in a while and wince at the atrocious mess of code. I got it running a few times and noticed how slow and buggy and insane it was -- no textures, the lighting jumps all over, digging seemed completely non-operational, and it was so slow. I could start a server and a client, and the client would get the world from the server, but the two players wouldn't see each other in there. And the only time I ever saw the mobs (monster objects, which are supposed to wander around in the caves) was when I hit rendering issues allowing me to see through the world.

So I've recently (December 2023ish) picked this back up with a bit of a resolution to fix it and see where I can take it. I'd like to learn more about modern OpenGL, play with a networking sandbox from an interesting working start, and try to make this old turd shine.

To install / run

Windows

  • I have no idea how to make this work on windows. Sorry! It'd take something like: get the code, and then you'll likely want to use mingw-w64 or something, and write your own makefile pieces in makefile and src/makefile which point to an installed opengl library and include files, which may need to be some very old crazy versions, like 2.1. I'm not sure if more modern ones let you call old functions this project used.

OSX

  • get the code and run make osx. You may need to mess with the OpenGL Framework directory in src/makefile, but a compatible (read: ancient) OpenGL and GLUT should be installed already. You might need to install xcode's dev tools to run make/gcc etc, which is way outside the scope of this paragraph.
  • this project has been run in 2023 on an m1 laptop, under sonoma 14.1

Linux

  • get the code and run make ubuntu. You'll likely need to have opengl development libraries and other build tools installed, and might need to change where the libs/includes are pointed at. You might hit problems with opengl versions.
  • I haven't run this on linux in a decade, so it may be hairier than that.

Project State

Todos

  • refactor out most of the global state into passed context objects
  • possibly port to C++ for the sake of adding classes
  • try to make it run on other systems than my mac
  • "placing cubes"
  • further fill out network protocol
  • possibly an inventory / menu
  • timer-based cube removal to increase mincraft-feels
  • textures (maybe waiting for a move to modern opengl)
  • rewrite opengl code to use 3.3+-style shaders and functions, rather than the 2.1-style fixed function pipeline this project was originally built in
  • chunks for bigger maps? threading?

v0.05 - 2023-12-23

  • better network error handling (like server quits)
  • now handles clients other than the most recent client quitting/rejoining (right now if client 1 exits and rejoins while client 2+ exist, client 1 will be assigned client 2's id)
  • more sophisticated movement physics to reduce choppy motion feeling

v0.04 - 2023-12-18

  • enable networked players to see each other, with correct position and orientation over time
  • enable networked digs, including from client A -> server -> client B and back
  • sane-ify initialization order for the sake of networking (e.g. clients should request their identity from the server before initializing most of the world)
  • window titles now reflect client ids
  • some small orientation and networking bugfixes
  • allow random seed to be specified and also print the seed-in-use out
  • sped up network FPS by lowering the timeval set to wait for incoming data
  • also sped up general FPS by cutting steps for block highlighting in half
  • fixed up mobs, got them running around in caves, looking the right direction, and networked
  • fixed the lines rendering-mode; it had been broken by the block outline drawing which changed modes without considering whether to fall back to line or shaded mode

v0.03 - 2023-12-13

  • finally implemented digging properly, including a screenspace crosshair and mouselook-driven cube highlights so you can see what cube you're going to remove with confidence
  • restored working culling, improving framerate from 15ish fps up to 50-70ish
  • mitigated most lighting glitches which would occur while player simply stood still looked around
  • smaller lighting improvements: colour, levels, self-emission all moved to values I personally found more pleasing
  • increased player movement speed
  • fixed mouselook initialization issue where first motion would throw player angle to a random place
  • reformatted codebase with some AStyle rules to bring consistency to it

v0.02 - 2019ish

basically no changes; just got it running again and fixed a small bug or two.

v0.01 - 2011ish

At present, things compile and run and the worlds sync - players aren't quite there yet, clouds and the sun are kind of dodgy (the sun is sometimes synced), and mobs could be doing anything and I wouldn't know. But they look good by the numbers.

Committing because the worlds manage to transmit.

v0.00 - 2011ish

commits lost to time (I likely wasn't using git very actively while working on the project)

Notes (as of 2023)

Due to rampant horrors, the code in this project has been formatted using Artistic Style (https://astyle.sourceforge.net/astyle.html), specifically via the Sublime plugin. The extra options defined are:

"options_default": { "style": "1tbs", "indent": "spaces", "indent-spaces": 2, "unpad-paren": true, "pad-header": true, "squeeze-ws": true, "squeeze-lines": 2, "break-blocks": "default" }

As of December 2023, getting Artistic Style's sublime plugin to run on an m1 mac required this process: timonwong/SublimeAStyleFormatter#95 (comment)

And getting openGL to link on osx required finding the location of the linkable Frameworks with .xcrun --sdk macosx --show-sdk-path

Questions, etc

Find a path to my attention and I'd be very happy to chat about this project.

License

All code here, with the exception of Ken Perlin's noise-related code, which is vital to this project, is public domain. Use it in any way, with or without my permission. If you do use it, I'd love to hear about it! I make no claims of the usefulness or fitness of any code here for any purposes.

Ken Perlin's code is of questionable provenance... the website I found it on no longer responds to DNS entries, so ... choose your own adventure there.

a caves scene with rock and dirt

c_minecraft_clone's People

Contributors

wcarss avatar

Stargazers

hayden avatar ็‡Ž avatar Rory Harvey avatar  avatar Ben Sparks avatar  avatar  avatar Alex Rozgo avatar Xavier Belanche Alonso avatar

Watchers

James Cloos avatar

Forkers

galexcode

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.