Giter Site home page Giter Site logo

chunklands's Introduction

Chunklands

This page is designed for developers.

If you want to read more of the project, goals, etc. please have a look at chunklands.de.

Notice: Breaking change

Former Chunklands architecture (single-threaded) had performance issues. POC of executor-architecture was merged into master to see daily process on master.

Still the set of features is not fully implemented, but we decided to merge it now.

It will take some time to support all old features. Please also consider the documentation to be out-dated.

Technologies

C++ NodeJS N-API boost OpenGL clang

Installation

Requirements:

  • node.js 14+
  • clang-10+
  • cmake 3.0+ (for glfw)

Linux

make setup

MacOS

make setup

MacOS ships apple clang. It's likely to be incompatible, so another vendor-free clang version is needed.

brew install llvm

# add this to your .env file
cat .env
# CLANG_BIN=/usr/local/opt/llvm/bin/clang
# CLANG_TIDY_BIN=/usr/local/opt/llvm/bin/clang-tidy

Windows:

not supported, sorry

Development

Build / Run

Variant 1 - dev build, watch and run

  1. watch files and build dev
npm run dev
  1. start game
npm start

Variant 2 - dev build and run

build dev and run

npm run build:dev && npm start

Variant 3 - prod build and run

build prod and run

npm run build:prod && npm start

or simply:

npm run play

Other commands

Clean

remove /build directory

make clean

Links

Progress

Current status:

Current Result

chunklands's People

Contributors

daaitch avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

xrui94

chunklands's Issues

block-type registration (after #23)

implement minimal open-closed registrar for block-types:

  • require all js files from src/blocks e.g. src/blocks/dirt.js
  • each js file exports the block-definition (either data, or callbacks, let's see what's better)
  • block definition/data:
    • vertex data, normals
    • hidesNeighbor: boolean (if all neighbors on the 6 faces have it true, block doesn't need to be rendered)

chunkloading: limit per loop

  • only N chunks should be updated per loop
  • N can be a constant, or calculated as a time-window, e.g. start with 10, if loop is real-time, increase, if loop delays render, decrease amount

chunkloading priority

  • order chunks from near to far for updates
  • distance can be cheap chess/manhattan-distance (no euclidean distance).

optimization: don't render hidden blocks

small optimization:

  • only applies to the inside of a chunk not across chunk borders
  • just to reduce vertex count (currently 23m for render distance 2 = 5x5x5 chunks)

improve game loop, split into "render" and "update"

decouple update from render

  • update should be at fixed frequency
  • render can have unlimited frequency
  • investigate on key press events strange delay or event overflow. E.g. pressing "w" 2s makes player move 4s (sticky keys proper implemented, etc.?)

optimization: don't render hidden faces

  • we have opaque = true to not render hidden blocks
  • we need vertexData to have faces metadata (e.g. vertex index ranges define a face)
  • we need need more metadata for opaque, e.g.
enum Occlusion {
  OCCLUDES_TOP,
  OCCLUDES_RIGHT,
  ... ,
  OPAQUE = OCCLUDES_TOP | OCCLUDES_BOTTOM | ...
}

game metrics

  • render pipeline metrics => every shader
  • computation metrics => chunk generation, gl* calls for memory, e.g. glBufferData etc. (notice don't use wall clock time as GL is async, glQueryBegin(GL_TIME_ELAPSED, ...) ).

optimization: chunk prefetch

With #11 we improved internal chunk rendering, but chunks will render all surrounding faces. To get rid of that, we need to prefetch chunks around rendered chunks:

  • split Chunk::Prepare into sth. like PrepareModel with calculating block types and PrepareView for creating vertex buffer etc.
  • Chunk should hold information about whether model/view is prepared
  • introduce PREFETCH_DISTANCE
  • idea: make chunkloading need 3 game loop iterations to make chunks be ready for rendering
    1. PrepareModel
    2. PrepareView, only if adjacent chunks have prepared models
    3. Render
  • don't make any Prepare* call trigger other chunk Prepare* in order to prevent infinite recursion
  • small optimization: create Prepare* limits, so that not too many operations happen in one loop (implicit done with reverse Prepare order, that chunks are tested first for rendering, then model prepare)

Environment class

  • no direct exports of methods, but wrap in Environment class
  • initialize
  • loadProcs
  • terminate

chunkloading: profiling

  • some optimization done
  • chunk loading is smoother than ever, but still not smooth enough
  • we need profiling, where performance goes
  • check gl* calls, loops, etc. top -> down profiling

Render a simple scene (after #9)

  • render multiple chunks (a cube with 3x3x3 chunks)
  • generate chunk data from a simple world generator (some added sines waves set the ground)

dynamic chunkloading with render distance (after #10)

  • update fixed set of rendered chunks to dynamic range (chunk render distance)
  • mechanism to request a chunk (sync)
  • add chunk to scene (according to render distance)
  • remove chunk from scene (according to render distance)

chunkloading retain area

chunks should not immediately be unloaded if out of prefetch area

  • render distance < prefetch distance
  • prefetch distance <= retain distance

Render a chunk (no textures)

  • simple data structure (16x16x16)
  • block types (0 = AIR, 1 = GRASS/DIRT)
  • initialize with hard-coded data
  • create vb from data structure (use block geometry as reference data)
  • no hidden faces optimization

File loader for blocks (in JS):

From e.g. Blender we can export .obj files with Material Data. Investigate on how this could be useful for us or how do we create new blocks with uv data? Any format many 3D studios support which is easy for us to use?

add gravity, toggle flight mode

jumping will be part of another story. it would be possible to qnd implement it, but it doesn't make sense at the moment. we can fly and go around.

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.