OpenMiner/include/world/Chunk.hpp

91 lines
2.2 KiB
C++
Raw Normal View History

2014-12-18 07:02:48 +01:00
/*
* =====================================================================================
*
* Filename: Chunk.hpp
*
* Description:
*
* Version: 1.0
* Created: 15/12/2014 17:31:17
* Revision: none
* Compiler: gcc
*
* Author: Quentin BAZIN, <quent42340@gmail.com>
* Company:
*
* =====================================================================================
*/
#ifndef CHUNK_HPP_
#define CHUNK_HPP_
2014-12-21 15:25:58 +01:00
#include <map>
2014-12-18 07:02:48 +01:00
#include <vector>
#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:
Chunk(s32 x, s32 y, s32 z);
~Chunk();
void generate();
void update();
void draw(Shader &shader);
u8 getBlock(s8 x, s8 y, s8 z);
2014-12-21 17:02:09 +01:00
s32 getVertexID(u8 x, u8 y, u8 z, u8 i, u8 j, u8 coordinate);
s32 getTexCoordID(u8 x, u8 y, u8 z, u8 i, u8 j, u8 coordinate);
2014-12-21 15:25:58 +01:00
2014-12-18 07:02:48 +01:00
static float noise2d(float x, float y, int seed, int octaves, float persistence);
static float noise3d_abs(float x, float y, float z, int seed, int octaves, float persistence);
s32 x() const { return m_x; }
s32 y() const { return m_y; }
s32 z() const { return m_z; }
bool initialized() const { return m_initialized; }
void setInitialized(bool initialized) { m_initialized = initialized; }
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]; }
static const u8 width = 16;
static const u8 height = 32;
static const u8 depth = 16;
void setLeft(Chunk *left) { m_surroundingChunks[0] = left; }
void setRight(Chunk *right) { m_surroundingChunks[1] = right; }
void setFront(Chunk *front) { m_surroundingChunks[2] = front; }
void setBack(Chunk *back) { m_surroundingChunks[3] = back; }
private:
s32 m_x;
s32 m_y;
s32 m_z;
2014-12-20 01:46:31 +01:00
Texture m_texture;
2014-12-18 07:02:48 +01:00
std::vector<u8> m_data;
std::vector<float> m_vertices;
std::vector<float> m_normals;
std::vector<float> m_texCoords;
2014-12-21 15:25:58 +01:00
std::map<size_t, size_t> m_verticesID;
2014-12-18 07:02:48 +01:00
VertexBuffer m_vbo;
Chunk *m_surroundingChunks[4];
bool m_changed;
bool m_initialized;
};
#endif // CHUNK_HPP_