Optimization interne de chunk!
This commit is contained in:
@@ -47,16 +47,19 @@ void Engine::Init()
|
||||
// Objet de musique!
|
||||
m_audio.ToggleMusicState();
|
||||
|
||||
// Init testChunk
|
||||
for (int x = 0; x < CHUNK_SIZE_X; ++x) {
|
||||
for (int z = 0; z < CHUNK_SIZE_Z; ++z) {
|
||||
for (int y = 0; y < 32; ++y) {
|
||||
if (x % 2 == 0 && y % 2 == 0 && z % 2 == 0)
|
||||
m_testChunk.SetBlock(x, y, z, BTYPE_DIRT);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Init Chunks
|
||||
for (int x = 0; x < CHUNK_SIZE_X; ++x)
|
||||
for (int z = 0; z < CHUNK_SIZE_Z; ++z)
|
||||
for (int y = 0; y < 32; ++y)
|
||||
m_testChunk.SetBlock(x, y, z, BTYPE_DIRT);
|
||||
|
||||
for (int chx = 0; chx < VIEW_DISTANCE; ++chx)
|
||||
for (int chy = 0; chy < VIEW_DISTANCE; ++chy)
|
||||
m_chunks.Set(chx, chy, &m_testChunk);
|
||||
|
||||
//m_chunks.Set(0, 0, &m_testChunk);
|
||||
|
||||
// Gestion de souris.
|
||||
CenterMouse();
|
||||
HideCursor();
|
||||
}
|
||||
@@ -66,19 +69,28 @@ void Engine::DeInit() { }
|
||||
void Engine::LoadResource() {
|
||||
LoadTexture(m_textureFloor, TEXTURE_PATH "grass.png");
|
||||
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png");
|
||||
LoadTexture(m_textureCube1, TEXTURE_PATH "metal1.png");
|
||||
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp");
|
||||
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp");
|
||||
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
|
||||
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png");
|
||||
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
|
||||
TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal.png");
|
||||
|
||||
TextureAtlas::TextureIndex texCheckerIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "checker.png");
|
||||
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png");
|
||||
|
||||
if (!m_textureAtlas.Generate(128, false))
|
||||
{
|
||||
if (!m_textureAtlas.Generate(512, false)) {
|
||||
std::cout << " Unable to generate texture atlas ..." << std::endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
float u, v, s;
|
||||
m_textureAtlas.TextureIndexToCoord(texDirtIndex, u, v, s, s);
|
||||
m_blockinfo[BTYPE_DIRT] = new BlockInfo(BTYPE_DIRT, "Dirt", u, v, s, 1);
|
||||
m_textureAtlas.TextureIndexToCoord(texGrassIndex, u, v, s, s);
|
||||
m_blockinfo[BTYPE_GRASS] = new BlockInfo(BTYPE_GRASS, "Grass", u, v, s, 1);
|
||||
m_textureAtlas.TextureIndexToCoord(texMetalIndex, u, v, s, s);
|
||||
m_blockinfo[BTYPE_METAL] = new BlockInfo(BTYPE_METAL, "Metal", u, v, s, 1);
|
||||
m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s);
|
||||
m_blockinfo[BTYPE_ICE] = new BlockInfo(BTYPE_ICE, "Ice", u, v, s, 1);
|
||||
|
||||
std::cout << " Loading and compiling shaders ..." << std::endl;
|
||||
if (!m_shader01.Load(SHADER_PATH "shader01.vert", SHADER_PATH "shader01.frag", true)) {
|
||||
std::cout << " Failed to load shader " << std::endl;
|
||||
@@ -210,13 +222,18 @@ void Engine::Render(float elapsedTime) {
|
||||
glVertex3f(-100.f, -2.f, -100.f);
|
||||
glEnd();
|
||||
|
||||
// Chunk
|
||||
// Chunks
|
||||
m_textureAtlas.Bind();
|
||||
|
||||
if (m_testChunk.IsDirty())
|
||||
m_testChunk.Update();
|
||||
for (int chx = 0; chx < VIEW_DISTANCE; chx++)
|
||||
for (int chy = 0; chy < VIEW_DISTANCE; chy++) {
|
||||
all.ApplyTranslation(chx * CHUNK_SIZE_X, 0, chy * CHUNK_SIZE_Z);
|
||||
all.Use();
|
||||
if (m_chunks.Get(chx, chy)->IsDirty())
|
||||
m_chunks.Get(chx, chy)->Update(m_blockinfo);
|
||||
m_chunks.Get(chx, chy)->Render();
|
||||
all.ApplyTranslation(-(chx * CHUNK_SIZE_X), 0, -(chy * CHUNK_SIZE_Z));
|
||||
}
|
||||
|
||||
m_testChunk.Render();
|
||||
m_shader01.Disable();
|
||||
|
||||
if (m_wireframe)
|
||||
|
Reference in New Issue
Block a user