Skip to content

Vekteur/clonecraft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CloneCraft

An implementation of a simple voxel game inspired by Minecraft. It is written in C++ 17 and uses OpenGL 3.3 and SFML 2.6. The game is written with efficiency and simplicity in mind.

Screenshot

Controls

  • WASD, space and left shift to move
  • Left-click to destroy a block
  • Right-click to place a block
  • Middle-click to pick a block
  • Left control to sprint
  • Mouse wheel to zoom
  • T to teleport
  • E to create an explosion
  • Alt + E to create a huge explosition
  • B to use the brush tool
  • Alt + B to use the huge brush tool
  • G to change gamemode

Implementation details

World

The world consists of chunks of 32x32 blocks that are loaded and unloaded as the player moves. These chunks are divided in sections with an height of 32 blocks and are unlimited in height. The loading of the chunks is made in other threads. A new thread is also created when a set of sections is updated.

Terrain generation

The terrain consists of multiple octaves of perlin noise. Biomes are generated using noises representing temperature and altitude. A smooth interpolation allows to make smooth transitions between biomes. The structures are generated by dividing the world horizontally in small areas and randomly selecting a potential position in an area.

Mesh creation

Meshes are generated in each section to represent blocks, water, and lava. A mesh consists of potentially visible faces of a block. Aligned blocks with the same texture are merged in a same face.

Rendering

Blocks and water are rendered using shaders. The textures of the blocks are stored in an OpenGL texture array. The fog and water effects are implemented in the shaders. The water reflection is simulated by rendering the world symetrically on the other side of the water and drawing it on the water position. Movements in the water are created with a DuDv map. Frustum culling allows to render only visible chunks .

Collisions

Collisions are detected using the Swept AABB algorithm. This algorithm makes it impossible for the player to pass through an obstacle. Between two frames, all of the blocks that the player potentially collides with are checked in a specific order. After a collision, the velocity on the axis of collision is set to 0. The process is repeated 3 times, so that the remaining velocity on each axis is used.

Target block

The block the player is pointing at is found by computing exactly each block in the line of sight of the player, never skipping over a block.

Installation

1. Install Dependencies

  • Ubuntu/Debian: sudo apt install cmake build-essential libsfml-dev libglm-dev libgl-dev
  • Fedora: sudo dnf install cmake gcc-c++ SFML-devel glm-devel mesa-libGL-devel
  • Arch Linux: sudo pacman -S cmake base-devel sfml glm mesa
  • Windows: (using vcpkg): vcpkg install sfml glm && vcpkg integrate install

2. Build the Project

Run the following commands in the repository root directory:

cmake . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j 12

Then run ./build/clonecraft on Linux or build\clonecraft.exe on Windows.

Build Options

  • Use -DVIEW_DISTANCE=... (default 32) to change the view distance.
  • Use -DLOADING_WORKERS_COUNT=... (default 4) to change the number of worker threads used to load chunks.

About

Simple Minecraft clone using C++ 17, OpenGL 3.3 and SFML 2.6

Topics

Resources

License

Stars

35 stars

Watchers

2 watching

Forks

Packages

 
 
 

Contributors

Languages