2022-11-10 19:47:39 +01:00
# ifndef CHUNK_H
# define CHUNK_H
# include <glm/glm.hpp>
# include <glm/gtc/matrix_transform.hpp>
# include <glm/gtc/type_ptr.hpp>
# include <array>
# include <bitset>
# include "block.hpp"
2022-11-20 19:14:11 +01:00
# include "spacefilling.hpp"
# include "intervalmap.hpp"
2023-02-12 12:18:30 +01:00
# include "shader.hpp"
2022-11-10 19:47:39 +01:00
# define CHUNK_SIZE 16
# define CHUNK_VOLUME (CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE)
# define CHUNK_MAX_INDEX (CHUNK_VOLUME - 1)
namespace Chunk
{
constexpr uint8_t CHUNK_STATE_GENERATED = 1 ;
constexpr uint8_t CHUNK_STATE_MESHED = 2 ;
constexpr uint8_t CHUNK_STATE_LOADED = 3 ;
constexpr uint8_t CHUNK_STATE_EMPTY = 4 ;
int coord3DTo1D ( int x , int y , int z ) ;
class Chunk
{
public :
Chunk ( glm : : vec3 pos = glm : : vec3 ( 0.0f ) ) ; // a default value for the argument satisfies the need for a default constructor when using the type in an unordered_map (i.e. in chunkmanager)
2022-11-11 20:36:39 +01:00
~ Chunk ( ) ;
2022-11-10 19:47:39 +01:00
public :
glm : : vec3 getPosition ( ) { return this - > position ; }
std : : bitset < 8 > getTotalState ( ) { return this - > state ; }
bool getState ( uint8_t n ) { return this - > state . test ( n ) ; }
void setState ( uint8_t nstate , bool value ) ;
void setBlock ( Block b , int x , int y , int z ) ;
2022-11-20 19:47:04 +01:00
void setBlocks ( int start , int end , Block b ) ;
2022-11-10 19:47:39 +01:00
Block getBlock ( int x , int y , int z ) ;
2022-11-20 19:14:11 +01:00
IntervalMap < Block > & getBlocks ( ) { return ( this - > blocks ) ; }
Block * getBlocksArray ( int * len ) { return ( this - > blocks . toArray ( len ) ) ; }
2022-11-10 19:47:39 +01:00
2023-02-12 14:36:59 +01:00
public :
GLuint VAO { 0 } , VBO { 0 } , EBO { 0 } , colorBuffer { 0 } , vIndex { 0 } ;
2022-11-10 19:47:39 +01:00
private :
glm : : vec3 position { } ;
2022-11-20 19:14:11 +01:00
IntervalMap < Block > blocks { } ;
2022-11-10 19:47:39 +01:00
std : : bitset < 8 > state { 0 } ;
} ;
} ;
# endif