2021-09-24 10:15:43 -04:00
|
|
|
#ifndef CHUNK_H__
|
|
|
|
#define CHUNK_H__
|
2021-10-11 11:37:58 -04:00
|
|
|
#include "define.h"
|
|
|
|
#include "array3d.h"
|
2021-11-02 13:25:24 -04:00
|
|
|
#include "array2d.h"
|
2021-10-11 11:37:58 -04:00
|
|
|
#include "vertexbuffer.h"
|
2021-10-31 00:31:08 -04:00
|
|
|
#include "blockinfo.h"
|
2021-11-18 19:27:16 -05:00
|
|
|
|
|
|
|
class World;
|
2021-10-11 11:37:58 -04:00
|
|
|
|
|
|
|
class Chunk {
|
|
|
|
private:
|
|
|
|
Array3d<BlockType> m_blocks = Array3d<BlockType>(CHUNK_SIZE_X, CHUNK_SIZE_Y, CHUNK_SIZE_Z);
|
|
|
|
VertexBuffer m_vertexBuffer;
|
|
|
|
bool m_isDirty = true;
|
2021-11-26 11:59:02 -05:00
|
|
|
bool m_isModified = false;
|
2021-10-11 11:37:58 -04:00
|
|
|
|
2021-11-02 13:25:24 -04:00
|
|
|
int m_posX; // Position du chunk dans l'array constituant le monde.
|
|
|
|
int m_posY;
|
|
|
|
|
2021-12-13 23:24:12 -05:00
|
|
|
VertexBuffer::VertexData* m_vd;
|
|
|
|
int m_vcount;
|
|
|
|
|
2021-11-18 19:27:16 -05:00
|
|
|
void AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt, int x, int y, int z, float u, float v, float s, World* world);
|
2021-09-24 10:15:43 -04:00
|
|
|
|
|
|
|
public:
|
2021-11-02 13:25:24 -04:00
|
|
|
Chunk(int x, int y);
|
2021-10-11 11:37:58 -04:00
|
|
|
~Chunk();
|
|
|
|
|
2021-11-19 11:11:08 -05:00
|
|
|
void RemoveBlock(int x, int y, int z, World* world);
|
|
|
|
void SetBlock(int x, int y, int z, BlockType type, World* world);
|
2021-10-11 11:37:58 -04:00
|
|
|
BlockType GetBlock(int x, int y, int z);
|
2021-11-19 11:11:08 -05:00
|
|
|
void CheckNeighbors(int x, int z, World* world);
|
2021-11-30 19:55:11 -05:00
|
|
|
void GetPosition(int& x, int& y) const;
|
2021-09-24 10:15:43 -04:00
|
|
|
|
2021-12-13 23:24:12 -05:00
|
|
|
|
2021-11-18 19:27:16 -05:00
|
|
|
void Update(BlockInfo* blockinfo[BTYPE_LAST], World* world);
|
2021-12-13 23:24:12 -05:00
|
|
|
void FlushMeshToVBO();
|
2021-10-11 11:37:58 -04:00
|
|
|
|
|
|
|
void Render() const;
|
|
|
|
bool IsDirty() const;
|
2021-11-19 11:11:08 -05:00
|
|
|
void MakeDirty();
|
2021-11-26 11:59:02 -05:00
|
|
|
void MakeModified();
|
2021-09-24 10:15:43 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CHUNK_H__
|