Corrections dans le générateur pour le MakeDirty au bout du monde

This commit is contained in:
MarcEricMartel 2021-12-14 17:16:14 -05:00
parent cdc926bb39
commit 2ec9170fe3

View File

@ -54,7 +54,8 @@ void World::TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]) {
if (ax - x >= 0) { if (ax - x >= 0) {
m_chunks.Set(ax - x, ay, m_chunks.Set(ax - x, ay,
m_chunks.Remove(ax, ay)); m_chunks.Remove(ax, ay));
if (ax == WORLD_SIZE_X - 1) m_chunks.Get(ax - x, ay)->MakeDirty(); if (ax == WORLD_SIZE_X - 1 && m_chunks.Get(ax - x, ay))
m_chunks.Get(ax - x, ay)->MakeDirty();
} }
else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay)); else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay));
} }
@ -64,7 +65,8 @@ void World::TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]) {
if (ax - x < WORLD_SIZE_X) { if (ax - x < WORLD_SIZE_X) {
m_chunks.Set(ax - x, ay, m_chunks.Set(ax - x, ay,
m_chunks.Remove(ax, ay)); m_chunks.Remove(ax, ay));
if (ax + x == 0) m_chunks.Get(ax + x, ay)->MakeDirty(); if (ax == 0 && m_chunks.Get(ax - x, ay))
m_chunks.Get(ax - x, ay)->MakeDirty();
} }
else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay)); else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay));
} }
@ -75,7 +77,8 @@ void World::TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]) {
if (ay - y >= 0) { if (ay - y >= 0) {
m_chunks.Set(ax, ay - y, m_chunks.Set(ax, ay - y,
m_chunks.Remove(ax, ay)); m_chunks.Remove(ax, ay));
if (ay == WORLD_SIZE_Y) m_chunks.Get(ax, ay - y)->MakeDirty(); if (ay == WORLD_SIZE_Y - 1 && m_chunks.Get(ax, ay - y))
m_chunks.Get(ax, ay - y)->MakeDirty();
} }
else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay)); else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay));
} }
@ -85,7 +88,8 @@ void World::TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]) {
if (ay - y < WORLD_SIZE_Y) { if (ay - y < WORLD_SIZE_Y) {
m_chunks.Set(ax, ay - y, m_chunks.Set(ax, ay - y,
m_chunks.Remove(ax, ay)); m_chunks.Remove(ax, ay));
if (ay - x == 0) m_chunks.Get(ax, ay - y)->MakeDirty(); if (ay == 0 && m_chunks.Get(ax, ay - y))
m_chunks.Get(ax, ay - y)->MakeDirty();
} }
else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay)); else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay));
} }
@ -133,7 +137,7 @@ void World::UpdateChunk(int& updates, int chx, int chy, BlockInfo* blockinfo[BTY
ChunkAt(chx, 1, chy)->Update(blockinfo, this); ChunkAt(chx, 1, chy)->Update(blockinfo, this);
updates = FRAMES_UPDATE_CHUNKS; updates = FRAMES_UPDATE_CHUNKS;
} }
} }
void World::ChangeBlockAtCursor(BlockType blockType, Player& player, bool& block) { void World::ChangeBlockAtCursor(BlockType blockType, Player& player, bool& block) {
@ -194,12 +198,12 @@ void World::ChangeBlockAtCursor(BlockType blockType, Player& player, bool& block
} }
void World::ChangeBlockAtPosition(BlockType blockType, Vector3f pos) { void World::ChangeBlockAtPosition(BlockType blockType, Vector3f pos) {
int bx = (int)pos.x % CHUNK_SIZE_X; int bx = (int)pos.x % CHUNK_SIZE_X;
int by = (int)pos.y % CHUNK_SIZE_Y; int by = (int)pos.y % CHUNK_SIZE_Y;
int bz = (int)pos.z % CHUNK_SIZE_Z; int bz = (int)pos.z % CHUNK_SIZE_Z;
ChunkAt(pos)->SetBlock(bx, by, bz, blockType, this); ChunkAt(pos)->SetBlock(bx, by, bz, blockType, this);
ChunkAt(pos)->MakeModified(); ChunkAt(pos)->MakeModified();
} }
void World::RenderWorld(int& rendercount, Player& player, Transformation& world, Shader& shader) { void World::RenderWorld(int& rendercount, Player& player, Transformation& world, Shader& shader) {
@ -232,7 +236,7 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world,
cosinus = .99993365506; // cos(2/3 degré) cosinus = .99993365506; // cos(2/3 degré)
echantillons = 120; echantillons = 120;
} }
else if (dist > VIEW_DISTANCE * .3f) { else if (dist > VIEW_DISTANCE * .3f) {
sinus = .01745240643; // sin(1 degré) sinus = .01745240643; // sin(1 degré)
cosinus = .99984769515; // cos(1 degré) cosinus = .99984769515; // cos(1 degré)
echantillons = 90; echantillons = 90;
@ -269,7 +273,7 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world,
int chx, chy; int chx, chy;
ChunkAt(cursor)->GetPosition(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. 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].x == chx && renderManifest[index].z == chy) if (renderManifest[index].x == chx && renderManifest[index].z == chy)
valide = false; valide = false;
if (valide) renderManifest[rendercount++] = Vector3f(chx, (VIEW_DISTANCE - (pos - cursor).Length() * 2.f + 128) / (float)VIEW_DISTANCE, chy); if (valide) renderManifest[rendercount++] = Vector3f(chx, (VIEW_DISTANCE - (pos - cursor).Length() * 2.f + 128) / (float)VIEW_DISTANCE, chy);
@ -357,11 +361,11 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
if (threads > 0) { if (threads > 0) {
for (int i = 0; i < threads; ++i) for (int i = 0; i < threads; ++i)
genThList[i].wait(); genThList[i].wait();
for (int i = 0; i < threads; ++i) { for (int i = 0; i < threads; ++i) {
int x, y; int x, y;
Chunk* chunk = genThList[i].get(); Chunk* chunk = genThList[i].get();
chunk->GetPosition(x,y); chunk->GetPosition(x, y);
m_chunks.Set(x - m_center[0], y - m_center[1], chunk); m_chunks.Set(x - m_center[0], y - m_center[1], chunk);
} }
} }
@ -378,7 +382,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
break; break;
int chx = cx + tx * CHUNK_SIZE_X; int chx = cx + tx * CHUNK_SIZE_X;
int chy = cy + ty * CHUNK_SIZE_Z; int chy = cy + ty * CHUNK_SIZE_Z;
if (ChunkAt(chx, 1, chy) && if (ChunkAt(chx, 1, chy) &&
ChunkAt(chx, 1, chy)->IsDirty()) { ChunkAt(chx, 1, chy)->IsDirty()) {
updateThList[threads++] = updateThList[threads++] =
std::async(std::launch::async, std::async(std::launch::async,
@ -386,13 +390,13 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this);
if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS;
} }
} }
for (; ty <= side; ++ty) { for (; ty <= side; ++ty) {
if (frameUpdate) if (frameUpdate)
break; break;
int chx = cx + tx * CHUNK_SIZE_X; int chx = cx + tx * CHUNK_SIZE_X;
int chy = cy + ty * CHUNK_SIZE_Z; int chy = cy + ty * CHUNK_SIZE_Z;
if (ChunkAt(chx, 1, chy) && if (ChunkAt(chx, 1, chy) &&
ChunkAt(chx, 1, chy)->IsDirty()) { ChunkAt(chx, 1, chy)->IsDirty()) {
updateThList[threads++] = updateThList[threads++] =
std::async(std::launch::async, std::async(std::launch::async,
@ -400,13 +404,13 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this);
if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS;
} }
} }
for (; tx >= -side; --tx) { for (; tx >= -side; --tx) {
if (frameUpdate) if (frameUpdate)
break; break;
int chx = cx + tx * CHUNK_SIZE_X; int chx = cx + tx * CHUNK_SIZE_X;
int chy = cy + ty * CHUNK_SIZE_Z; int chy = cy + ty * CHUNK_SIZE_Z;
if (ChunkAt(chx, 1, chy) && if (ChunkAt(chx, 1, chy) &&
ChunkAt(chx, 1, chy)->IsDirty()) { ChunkAt(chx, 1, chy)->IsDirty()) {
updateThList[threads++] = updateThList[threads++] =
std::async(std::launch::async, std::async(std::launch::async,
@ -414,13 +418,13 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this);
if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS;
} }
} }
for (; ty >= -side; --ty) { for (; ty >= -side; --ty) {
if (frameUpdate) if (frameUpdate)
break; break;
int chx = cx + tx * CHUNK_SIZE_X; int chx = cx + tx * CHUNK_SIZE_X;
int chy = cy + ty * CHUNK_SIZE_Z; int chy = cy + ty * CHUNK_SIZE_Z;
if (ChunkAt(chx, 1, chy) && if (ChunkAt(chx, 1, chy) &&
ChunkAt(chx, 1, chy)->IsDirty()) { ChunkAt(chx, 1, chy)->IsDirty()) {
updateThList[threads++] = updateThList[threads++] =
std::async(std::launch::async, std::async(std::launch::async,
@ -428,7 +432,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this);
if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS;
} }
} }
if (frameUpdate) if (frameUpdate)
break; break;
++side; ++side;