Optimization de performance du renderer!
This commit is contained in:
@@ -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<67>)
|
||||
cosinus = .99984769515; // cos(1 degr<67>)
|
||||
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,24 +321,25 @@ 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<75>es dans la frame, et ne pas avoir <20> refaire l'array <20> 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);
|
||||
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);
|
||||
}
|
||||
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();
|
||||
glBlendColor(0.f, 0.f, 0.f, renderManifest[index].y);
|
||||
ChunkAt(chx, 1, chy)->Render();
|
||||
world.ApplyTranslation(-chx, 0, -chy);
|
||||
}
|
||||
shader.Disable();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user