OpenMiner/include/world/Chunk.hpp

96 lines
2.4 KiB
C++
Raw Normal View History

2014-12-18 07:02:48 +01:00
/*
* =====================================================================================
*
* Filename: Chunk.hpp
*
2018-06-05 01:24:54 +02:00
* Description:
2014-12-18 07:02:48 +01:00
*
* Created: 15/12/2014 17:31:17
*
* Author: Quentin Bazin, <quent42340@gmail.com>
2014-12-18 07:02:48 +01:00
*
* =====================================================================================
*/
#ifndef CHUNK_HPP_
#define CHUNK_HPP_
2014-12-21 15:25:58 +01:00
#include <map>
2015-02-06 01:44:16 +01:00
#include <memory>
2014-12-18 07:02:48 +01:00
#include <vector>
2015-02-06 01:44:16 +01:00
#include "Block.hpp"
#include "NonCopyable.hpp"
2014-12-18 07:02:48 +01:00
#include "Shader.hpp"
2014-12-20 01:46:31 +01:00
#include "Texture.hpp"
2014-12-18 07:02:48 +01:00
#include "VertexBuffer.hpp"
class Chunk : public NonCopyable {
2014-12-18 07:02:48 +01:00
public:
2015-02-06 01:44:16 +01:00
Chunk(s32 x, s32 y, s32 z, Texture &texture);
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
void update();
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
void draw(Shader &shader);
2018-06-05 01:24:54 +02:00
void addBlock(u32 id);
2015-02-06 01:44:16 +01:00
Block *getBlock(s8 x, s8 y, s8 z);
2018-06-05 01:24:54 +02:00
2014-12-21 22:21:54 +01:00
u32 getCoordID(u8 x, u8 y, u8 z, u8 i, u8 j, u8 coordinate);
2018-06-05 01:24:54 +02:00
2014-12-21 22:21:54 +01:00
u32 getVertexID(u8 x, u8 y, u8 z, u8 i, u8 j, u8 coordinate);
u32 getTexCoordID(u8 x, u8 y, u8 z, u8 i, u8 j, u8 coordinate);
2018-06-05 01:24:54 +02:00
2014-12-21 22:21:54 +01:00
bool vertexExists(u8 x, u8 y, u8 z, u8 i, u8 j);
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
s32 x() const { return m_x; }
s32 y() const { return m_y; }
s32 z() const { return m_z; }
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
Chunk *left() const { return m_surroundingChunks[0]; }
Chunk *right() const { return m_surroundingChunks[1]; }
Chunk *front() const { return m_surroundingChunks[2]; }
Chunk *back() const { return m_surroundingChunks[3]; }
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
static const u8 width = 16;
static const u8 height = 32;
static const u8 depth = 16;
2018-06-05 01:24:54 +02:00
2018-06-05 01:47:15 +02:00
void setLeft(Chunk *left) { m_surroundingChunks[0] = left; }
2014-12-18 07:02:48 +01:00
void setRight(Chunk *right) { m_surroundingChunks[1] = right; }
void setFront(Chunk *front) { m_surroundingChunks[2] = front; }
2018-06-05 01:47:15 +02:00
void setBack(Chunk *back) { m_surroundingChunks[3] = back; }
2018-06-05 01:24:54 +02:00
bool isGenerated() const { return m_isGenerated; }
bool isInitialized() const { return m_isInitialized; }
void setChanged(bool isChanged) { m_isChanged = isChanged; }
void setGenerated(bool isGenerated) { m_isGenerated = isGenerated; }
void setInitialized(bool isInitialized) { m_isInitialized = isInitialized; }
2014-12-18 07:02:48 +01:00
private:
s32 m_x;
s32 m_y;
s32 m_z;
2018-06-05 01:24:54 +02:00
2014-12-20 01:46:31 +01:00
Texture m_texture;
2018-06-05 01:24:54 +02:00
2015-02-06 01:44:16 +01:00
std::vector<std::unique_ptr<Block>> m_data;
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
std::vector<float> m_vertices;
std::vector<float> m_normals;
std::vector<float> m_texCoords;
2018-06-05 01:24:54 +02:00
2014-12-21 22:21:54 +01:00
std::map<u32, u32> m_verticesID;
std::map<u32, u32> m_extendedFaces;
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
VertexBuffer m_vbo;
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
Chunk *m_surroundingChunks[4];
2018-06-05 01:24:54 +02:00
bool m_isChanged;
bool m_isInitialized;
bool m_isGenerated;
2014-12-18 07:02:48 +01:00
};
#endif // CHUNK_HPP_