temportalflux / TemportalEngine

GNU General Public License v3.0
4 stars 1 forks source link

Chunks, Coordinates, & Collisions #21

Open temportalflux opened 4 years ago

temportalflux commented 4 years ago

Chunks

Chunks are cubes which contain TDimension^3 references to blocks and handle collisions between entities and their contents. A chunk can be defined by 1 constexpr size which is used for the width, height, and length dimensions. The number of block ids it contains is equivalent to TDimension^3 and are stored as raw ids. Each id is keyed by a Vector3UInt indicating its position within the chunk. It is possible for a chunk to have many blocks which have null or empty ids. Each chunk has a Vector3UInt coordinate within the world.

Coordinates

Because each chunk has a Vector3UInt position and a set of Vector3UInt positions within it, an entities position can be defined as its Vector3UInt chunk coordinate, its Vector3UInt block coordinate (relative to the chunk coordinate) and its Vector3/Vector<f32, 3> offset coordinate (relative to the block coordinate).

Collisions

Each chunk is responsible for running collision checks against entities.

Chunk-Spectrum

An entity is definitely not colliding with a chunk if n + 1 > c where n is a dimension of the entity's current chunk coordinate and c is the same dimension of a given chunk's coordinate. (An entity could be colliding with a chunk if it is in an adjacent chunk but on its boundary).

Broad Block-Spectrum

Assuming each chunk has a sequential fixed-sized list (i.e. an array with no empty values) which represents the block coordinates which are non-empty, an entity is definitely not colliding with a given block if n + 1 > c where nn is the largest dimension of the entity's bounding box and c is any dimension of the block's coordinate within the chunk.

Narrow Block-Spectrum

For an blocks which could be colliding from the Broad Block-Spectrum, those that actually do collide will need to run their own specific collision checks. In most cases, an entity is definitely not colliding with a block if general cube collision fails against the entity's bounds. This can use the rectangular prism collision check against the block's general coordinates. This should be the default case.