Optimization de performance du renderer!
This commit is contained in:
parent
a75b1c97cb
commit
a3c0dee1f2
@ -35,7 +35,7 @@ void Engine::Init() {
|
||||
m_skybox.Init(0.00013f);
|
||||
|
||||
// Objet de musique!
|
||||
m_audio.ToggleMusicState();
|
||||
//m_audio.ToggleMusicState();
|
||||
|
||||
// Init Chunks
|
||||
m_world.GetChunks().Reset(nullptr);
|
||||
@ -52,9 +52,9 @@ void Engine::LoadResource() {
|
||||
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 texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
|
||||
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
|
||||
TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal.png");
|
||||
TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal1.png");
|
||||
|
||||
if (!m_textureAtlas.Generate(512, false)) {
|
||||
std::cout << " Unable to generate texture atlas ..." << std::endl;
|
||||
|
@ -47,7 +47,7 @@ private:
|
||||
TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
|
||||
|
||||
World m_world = World();
|
||||
Perlin m_perlin = Perlin(4,32.f,7.f,12345);
|
||||
Perlin m_perlin = Perlin(8,45.f,7.f,12345);
|
||||
|
||||
Texture m_textureSkybox;
|
||||
Texture m_textureFont;
|
||||
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -148,8 +148,8 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) {
|
||||
float xnoiz, ynoiz;
|
||||
xnoiz = (double)(x + (chx / CHUNK_SIZE_X + m_center[0]) * CHUNK_SIZE_X) / (double)INT16_MAX;
|
||||
ynoiz = (double)(z + (chy / CHUNK_SIZE_Z + m_center[1]) * CHUNK_SIZE_Z) / (double)INT16_MAX;
|
||||
float height = (perlin.Get(xnoiz, ynoiz)) * 10.f;
|
||||
for (int y = 0; y <= (int)height; ++y)
|
||||
float height = (perlin.Get(xnoiz, ynoiz)) * 20.f + 5.f;
|
||||
for (int y = 0; y <= (int)height % CHUNK_SIZE_Y; ++y)
|
||||
chunk->SetBlock(x, y, z, BTYPE_METAL, this);
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) {
|
||||
float xnoiz, ynoiz;
|
||||
xnoiz = (double)(x + (chx / CHUNK_SIZE_X + m_center[0]) * CHUNK_SIZE_X) / (double)INT16_MAX;
|
||||
ynoiz = (double)(z + (chy / CHUNK_SIZE_Z + m_center[1]) * CHUNK_SIZE_Z) / (double)INT16_MAX;
|
||||
float height = (perlin.Get(xnoiz, ynoiz) + 16.f);
|
||||
float height = perlin.Get(xnoiz, ynoiz) * 5.f + 16.f;
|
||||
for (int y = 0; y <= (int)height % CHUNK_SIZE_Y; ++y) {
|
||||
if (chunk->GetBlock(x, y, z) == BTYPE_AIR)
|
||||
chunk->SetBlock(x, y, z, BTYPE_GRASS, this);
|
||||
@ -272,14 +272,14 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran
|
||||
direct.Normalize();
|
||||
pos.y = 1;
|
||||
|
||||
static Vector3i renderManifest[VIEW_DISTANCE * 4];
|
||||
static Vector3f renderManifest[VIEW_DISTANCE * 4];
|
||||
|
||||
for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) {
|
||||
// Configuration du radar.
|
||||
float sinus, cosinus;
|
||||
int echantillons;
|
||||
|
||||
if (dist > VIEW_DISTANCE * .375f) {
|
||||
if (dist > VIEW_DISTANCE * .625f) {
|
||||
sinus = .01745240643; // sin(1 degré)
|
||||
cosinus = .99984769515; // cos(1 degré)
|
||||
echantillons = 90;
|
||||
@ -289,7 +289,7 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran
|
||||
cosinus = .99965732497;
|
||||
echantillons = 60;
|
||||
}
|
||||
else if (dist > VIEW_DISTANCE * .625f) {
|
||||
else if (dist > VIEW_DISTANCE * .375f) {
|
||||
sinus = .0348994967;
|
||||
cosinus = .99939082701;
|
||||
echantillons = 45;
|
||||
@ -313,7 +313,7 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran
|
||||
angle.Normalize();
|
||||
|
||||
cursor = pos - direct * CHUNK_SIZE_X * 2 + angle * dist;
|
||||
if (cursor.y >= 128.f || cursor.y >= 0.f) cursor.y = 1;
|
||||
if (cursor.y >= 128.f || cursor.y >= 0.f) cursor.y = CHUNK_SIZE_Y / 2.f;
|
||||
|
||||
bool valide = true;
|
||||
|
||||
@ -321,23 +321,24 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran
|
||||
int chx, chy;
|
||||
ChunkAt(cursor)->GetPosition(chx, chy);
|
||||
for (int index = 0; index < rendercount; ++index) // Permet de vérifier seulement contre celles ajoutées dans la frame, et ne pas avoir à refaire l'array à chaque frame.
|
||||
if (renderManifest[index] == Vector3i(chx, 0, chy)) {
|
||||
if (renderManifest[index].x == chx && renderManifest[index].z == chy) {
|
||||
valide = false;
|
||||
++badhitcount;
|
||||
}
|
||||
|
||||
if (valide) {
|
||||
world.ApplyTranslation((chx - m_center[0]) * CHUNK_SIZE_X, 0, (chy - m_center[1]) * CHUNK_SIZE_Z);
|
||||
float ray = (pos - cursor).Length();
|
||||
if (valide) renderManifest[rendercount++] = Vector3f(chx, (VIEW_DISTANCE - ray * 2 + 128) / (float)VIEW_DISTANCE, chy);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < rendercount; ++index) {
|
||||
int chx = (renderManifest[index].x - m_center[0]) * CHUNK_SIZE_X, chy = (renderManifest[index].z - m_center[1]) * CHUNK_SIZE_Z;
|
||||
|
||||
world.ApplyTranslation(chx, 0, chy);
|
||||
world.Use();
|
||||
float dist = (pos - cursor).Length();
|
||||
float blend = ((float)VIEW_DISTANCE - dist * 2.f + 128.f) / (float)VIEW_DISTANCE;
|
||||
glBlendColor(0.f, 0.f, 0.f, blend);
|
||||
ChunkAt(cursor)->Render();
|
||||
world.ApplyTranslation(-(chx - m_center[0]) * CHUNK_SIZE_X, 0, -(chy - m_center[1]) * CHUNK_SIZE_Z);
|
||||
renderManifest[++rendercount] = Vector3i(chx, 0, chy);
|
||||
}
|
||||
}
|
||||
}
|
||||
glBlendColor(0.f, 0.f, 0.f, renderManifest[index].y);
|
||||
ChunkAt(chx, 1, chy)->Render();
|
||||
world.ApplyTranslation(-chx, 0, -chy);
|
||||
}
|
||||
shader.Disable();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user