Monde de max de UINT_MAX * UINT_MAX
This commit is contained in:
parent
5dc05167de
commit
5f50f5f87e
@ -1,7 +1,7 @@
|
||||
#include "chunk.h"
|
||||
#include "world.h"
|
||||
|
||||
Chunk::Chunk(int x, int y) : m_posX(x), m_posY(y) {
|
||||
Chunk::Chunk(unsigned int x, unsigned int y) : m_posX(x), m_posY(y) {
|
||||
std::ostringstream pos; // Vérifie l'existence d'un fichier .chunk avec sa position.
|
||||
pos << CHUNK_PATH << x << '_' << y << ".chunk";
|
||||
std::ifstream input(pos.str(), std::fstream::binary);
|
||||
@ -13,8 +13,8 @@ Chunk::Chunk(int x, int y) : m_posX(x), m_posY(y) {
|
||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes
|
||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||
float xnoiz, ynoiz;
|
||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / (double)INT16_MAX;
|
||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / (double)INT16_MAX;
|
||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / (double)UINT16_MAX;
|
||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / (double)UINT16_MAX;
|
||||
float height = (perlin.Get(xnoiz, ynoiz)) * 20.f + 5.f;
|
||||
for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy)
|
||||
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
|
||||
@ -22,8 +22,8 @@ Chunk::Chunk(int x, int y) : m_posX(x), m_posY(y) {
|
||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines
|
||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||
float xnoiz, ynoiz;
|
||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / (double)INT16_MAX;
|
||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / (double)INT16_MAX;
|
||||
xnoiz = (double)(ix + x * CHUNK_SIZE_X) / (double)UINT16_MAX;
|
||||
ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / (double)UINT16_MAX;
|
||||
float height = perlin.Get(xnoiz, ynoiz) * 5.f + 24.f;
|
||||
for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) {
|
||||
if (GetBlock(ix, iy, iz) == BTYPE_AIR)
|
||||
@ -40,8 +40,8 @@ Chunk::Chunk(int x, int y) : m_posX(x), m_posY(y) {
|
||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres"
|
||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||
float xnoiz, ynoiz;
|
||||
xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / (double)INT16_MAX;
|
||||
ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / (double)INT16_MAX;
|
||||
xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / (double)UINT16_MAX;
|
||||
ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / (double)UINT16_MAX;
|
||||
bool tree = (int)(abs(perlin.Get(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false;
|
||||
|
||||
for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy)
|
||||
@ -102,8 +102,8 @@ void Chunk::SetBlock(int x, int y, int z, BlockType type, World* world) {
|
||||
|
||||
BlockType Chunk::GetBlock(int x, int y, int z) { return m_blocks.Get(x, y, z); }
|
||||
|
||||
void Chunk::CheckNeighbors(int x, int z, World* world) {
|
||||
int cx, cy;
|
||||
void Chunk::CheckNeighbors(unsigned int x, unsigned int z, World* world) {
|
||||
unsigned int cx, cy;
|
||||
|
||||
world->GetScope(cx, cy);
|
||||
|
||||
@ -122,7 +122,7 @@ void Chunk::CheckNeighbors(int x, int z, World* world) {
|
||||
world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)->MakeDirty();
|
||||
}
|
||||
|
||||
void Chunk::GetPosition(int& x, int& y) const { x = m_posX; y = m_posY; }
|
||||
void Chunk::GetPosition(unsigned int& x, unsigned int& y) const { x = m_posX; y = m_posY; }
|
||||
|
||||
void Chunk::FlushMeshToVBO() {
|
||||
m_vertexBuffer.SetMeshData(m_vd, m_vcount);
|
||||
@ -167,7 +167,7 @@ void Chunk::Update(BlockInfo* blockinfo[BTYPE_LAST], World* world) {
|
||||
void Chunk::AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt,
|
||||
int x, int y, int z, float u, float v, float s, World* world) {
|
||||
|
||||
int cex, cey;
|
||||
unsigned int cex, cey;
|
||||
|
||||
world->GetScope(cex, cey);
|
||||
|
||||
|
@ -15,8 +15,8 @@ class Chunk {
|
||||
bool m_isDirty = true;
|
||||
bool m_isModified = false;
|
||||
|
||||
int m_posX; // Position du chunk dans l'array constituant le monde.
|
||||
int m_posY;
|
||||
unsigned int m_posX; // Position du chunk dans l'array constituant le monde.
|
||||
unsigned int m_posY;
|
||||
|
||||
VertexBuffer::VertexData* m_vd;
|
||||
int m_vcount;
|
||||
@ -24,14 +24,14 @@ class Chunk {
|
||||
void AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt, int x, int y, int z, float u, float v, float s, World* world);
|
||||
|
||||
public:
|
||||
Chunk(int x, int y);
|
||||
Chunk(unsigned int x, unsigned int y);
|
||||
~Chunk();
|
||||
|
||||
void RemoveBlock(int x, int y, int z, World* world);
|
||||
void SetBlock(int x, int y, int z, BlockType type, World* world);
|
||||
BlockType GetBlock(int x, int y, int z);
|
||||
void CheckNeighbors(int x, int z, World* world);
|
||||
void GetPosition(int& x, int& y) const;
|
||||
void CheckNeighbors(unsigned int x, unsigned int z, World* world);
|
||||
void GetPosition(unsigned int& x, unsigned int& y) const;
|
||||
|
||||
|
||||
void Update(BlockInfo* blockinfo[BTYPE_LAST], World* world);
|
||||
|
@ -43,7 +43,7 @@ void Engine::Init() {
|
||||
m_skybox.Init(0.2f);
|
||||
|
||||
// Objet de musique!
|
||||
m_audio.ToggleMusicState();
|
||||
//m_audio.ToggleMusicState();
|
||||
|
||||
// Array pour les balles.
|
||||
for (int x = 0; x < MAX_BULLETS; ++x)
|
||||
|
@ -120,7 +120,7 @@ void World::CleanUpWorld(int& deleteframes, bool clear = false) {
|
||||
}
|
||||
}
|
||||
|
||||
void World::GetScope(int& x, int& y) {
|
||||
void World::GetScope(unsigned int& x, unsigned int& y) {
|
||||
x = m_center[0];
|
||||
y = m_center[1];
|
||||
}
|
||||
@ -136,7 +136,7 @@ void World::Update(int& rendercount, Bullet* bullets[MAX_BULLETS], Player& playe
|
||||
glStencilFunc(GL_GREATER, 1, 0xFF);
|
||||
}
|
||||
|
||||
void World::UpdateChunk(int& updates, int chx, int chy, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||
void World::UpdateChunk(int& updates, unsigned int chx, unsigned int chy, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||
if (updates == 0 && ChunkAt(chx, 1, chy) &&
|
||||
ChunkAt(chx, 1, chy)->IsDirty()) {
|
||||
ChunkAt(chx, 1, chy)->Update(blockinfo, this);
|
||||
@ -223,7 +223,7 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world,
|
||||
direct.Normalize();
|
||||
pos.y = 1;
|
||||
|
||||
static Vector3f renderManifest[VIEW_DISTANCE * 4]; // Nombre de Chunks maximal à être rendus.
|
||||
static Vector3<unsigned int> renderManifest[VIEW_DISTANCE * 4]; // Nombre de Chunks maximal à être rendus.
|
||||
|
||||
//for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) {
|
||||
for (int dist = 0; dist <= VIEW_DISTANCE; dist += CHUNK_SIZE_X) {
|
||||
@ -272,16 +272,19 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world,
|
||||
cursor = pos - direct * CHUNK_SIZE_X * 2 + angle * dist;
|
||||
if (cursor.y >= 128.f || cursor.y >= 0.f) cursor.y = CHUNK_SIZE_Y / 2.f;
|
||||
|
||||
bool valide = true;
|
||||
|
||||
if (ChunkAt(cursor)) {
|
||||
int chx, chy;
|
||||
bool valide = true;
|
||||
unsigned 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].x == chx && renderManifest[index].z == chy)
|
||||
valide = false;
|
||||
|
||||
if (valide) renderManifest[rendercount++] = Vector3f(chx, (VIEW_DISTANCE - (pos - cursor).Length() * 2.f + 128) / (float)VIEW_DISTANCE, chy);
|
||||
if (valide) renderManifest[rendercount++] = Vector3<unsigned int>(chx,
|
||||
(VIEW_DISTANCE - (pos - cursor).Length() * 2.f) < 0.f? 0:
|
||||
(VIEW_DISTANCE - (pos - cursor).Length() * 2.f) * 1000,
|
||||
chy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -290,7 +293,8 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world,
|
||||
|
||||
world.ApplyTranslation(chx, 0, chy);
|
||||
world.Use();
|
||||
glBlendColor(renderManifest[index].y, renderManifest[index].y, renderManifest[index].y, 1.f);
|
||||
float blcolor = renderManifest[index].y / (VIEW_DISTANCE * 1000.f);
|
||||
glBlendColor(blcolor, blcolor, blcolor, 1.f);
|
||||
ChunkAt(chx, 1, chy)->Render();
|
||||
world.ApplyTranslation(-chx, 0, -chy);
|
||||
}
|
||||
@ -326,7 +330,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
chy = cy + ty * CHUNK_SIZE_Z;
|
||||
if (chx < WORLD_SIZE_X * CHUNK_SIZE_X && chy < WORLD_SIZE_Y * CHUNK_SIZE_Z &&
|
||||
chx >= 0 && chy >= 0 && !ChunkAt(chx, 1, chy))
|
||||
genThList[threads++] = std::async(std::launch::async, [](int x, int y) { return new Chunk(x, y); }, chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]);
|
||||
genThList[threads++] = std::async(std::launch::async, [](unsigned int x, unsigned int y) { return new Chunk(x, y); }, chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]);
|
||||
if (threads == THREADS_GENERATE_CHUNKS) frameGenerate = FRAMES_RENDER_CHUNKS;
|
||||
}
|
||||
for (; ty <= side; ++ty) {
|
||||
@ -336,7 +340,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
chy = cy + ty * CHUNK_SIZE_Z;
|
||||
if (chx < WORLD_SIZE_X * CHUNK_SIZE_X && chy < WORLD_SIZE_Y * CHUNK_SIZE_Z &&
|
||||
chx >= 0 && chy >= 0 && !ChunkAt(chx, 1, chy))
|
||||
genThList[threads++] = std::async(std::launch::async, [](int x, int y) { return new Chunk(x, y); }, chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]);
|
||||
genThList[threads++] = std::async(std::launch::async, [](unsigned int x, unsigned int y) { return new Chunk(x, y); }, chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]);
|
||||
if (threads == THREADS_GENERATE_CHUNKS) frameGenerate = FRAMES_RENDER_CHUNKS;
|
||||
}
|
||||
for (; tx >= -side; --tx) {
|
||||
@ -346,7 +350,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
chy = cy + ty * CHUNK_SIZE_Z;
|
||||
if (chx < WORLD_SIZE_X * CHUNK_SIZE_X && chy < WORLD_SIZE_Y * CHUNK_SIZE_Z &&
|
||||
chx >= 0 && chy >= 0 && !ChunkAt(chx, 1, chy))
|
||||
genThList[threads++] = std::async(std::launch::async, [](int x, int y) { return new Chunk(x, y); }, chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]);
|
||||
genThList[threads++] = std::async(std::launch::async, [](unsigned int x, unsigned int y) { return new Chunk(x, y); }, chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]);
|
||||
if (threads == THREADS_GENERATE_CHUNKS) frameGenerate = FRAMES_RENDER_CHUNKS;
|
||||
}
|
||||
for (; ty >= -side; --ty) {
|
||||
@ -356,7 +360,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
chy = cy + ty * CHUNK_SIZE_Z;
|
||||
if (chx < WORLD_SIZE_X * CHUNK_SIZE_X && chy < WORLD_SIZE_Y * CHUNK_SIZE_Z &&
|
||||
chx >= 0 && chy >= 0 && !ChunkAt(chx, 1, chy))
|
||||
genThList[threads++] = std::async(std::launch::async, [](int x, int y) { return new Chunk(x, y); }, chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]);
|
||||
genThList[threads++] = std::async(std::launch::async, [](unsigned int x, unsigned int y) { return new Chunk(x, y); }, chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]);
|
||||
if (threads == THREADS_GENERATE_CHUNKS) frameGenerate = FRAMES_RENDER_CHUNKS;
|
||||
}
|
||||
if (frameGenerate)
|
||||
@ -369,7 +373,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
genThList[i].wait();
|
||||
|
||||
for (int i = 0; i < threads; ++i) {
|
||||
int x, y;
|
||||
unsigned int x, y;
|
||||
Chunk* chunk = genThList[i].get();
|
||||
chunk->GetPosition(x, y);
|
||||
m_chunks.Set(x - m_center[0], y - m_center[1], chunk);
|
||||
@ -386,8 +390,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
for (; tx <= side; ++tx) {
|
||||
if (frameUpdate)
|
||||
break;
|
||||
int chx = cx + tx * CHUNK_SIZE_X;
|
||||
int chy = cy + ty * CHUNK_SIZE_Z;
|
||||
unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z;
|
||||
if (ChunkAt(chx, 1, chy) &&
|
||||
ChunkAt(chx, 1, chy)->IsDirty()) {
|
||||
updateThList[threads++] =
|
||||
@ -400,8 +403,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
for (; ty <= side; ++ty) {
|
||||
if (frameUpdate)
|
||||
break;
|
||||
int chx = cx + tx * CHUNK_SIZE_X;
|
||||
int chy = cy + ty * CHUNK_SIZE_Z;
|
||||
unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z;
|
||||
if (ChunkAt(chx, 1, chy) &&
|
||||
ChunkAt(chx, 1, chy)->IsDirty()) {
|
||||
updateThList[threads++] =
|
||||
@ -414,8 +416,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
for (; tx >= -side; --tx) {
|
||||
if (frameUpdate)
|
||||
break;
|
||||
int chx = cx + tx * CHUNK_SIZE_X;
|
||||
int chy = cy + ty * CHUNK_SIZE_Z;
|
||||
unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z;
|
||||
if (ChunkAt(chx, 1, chy) &&
|
||||
ChunkAt(chx, 1, chy)->IsDirty()) {
|
||||
updateThList[threads++] =
|
||||
@ -428,8 +429,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
for (; ty >= -side; --ty) {
|
||||
if (frameUpdate)
|
||||
break;
|
||||
int chx = cx + tx * CHUNK_SIZE_X;
|
||||
int chy = cy + ty * CHUNK_SIZE_Z;
|
||||
unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z;
|
||||
if (ChunkAt(chx, 1, chy) &&
|
||||
ChunkAt(chx, 1, chy)->IsDirty()) {
|
||||
updateThList[threads++] =
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
|
||||
void Update(int& rendercount, Bullet* bullets[MAX_BULLETS], Player& player, Transformation& world, Shader& shader, TextureAtlas& atlas, Perlin& perlin, BlockInfo* blockinfo[BTYPE_LAST]);
|
||||
|
||||
void GetScope(int& x, int& y);
|
||||
void GetScope(unsigned int& x, unsigned int& y);
|
||||
|
||||
void ChangeBlockAtCursor(BlockType blockType, Player& player, bool& block);
|
||||
void ChangeBlockAtPosition(BlockType blockType, Vector3f pos);
|
||||
@ -45,9 +45,9 @@ private:
|
||||
Array2d<Chunk*> m_chunks = Array2d<Chunk*>(WORLD_SIZE_X, WORLD_SIZE_Y);
|
||||
std::vector<Chunk*> m_tbDeleted;
|
||||
|
||||
int m_center[2] = { INT16_MAX / 2 - WORLD_SIZE_X / 2, INT16_MAX / 2 - WORLD_SIZE_Y / 2 };
|
||||
unsigned int m_center[2] = { UINT16_MAX / 2 - WORLD_SIZE_X / 2, UINT16_MAX / 2 - WORLD_SIZE_Y / 2 };
|
||||
|
||||
void UpdateChunk(int& updates, int chx, int chy, BlockInfo* blockinfo[BTYPE_LAST]);
|
||||
void UpdateChunk(int& updates, unsigned int chx, unsigned int chy, BlockInfo* blockinfo[BTYPE_LAST]);
|
||||
void RenderWorld(int& rendercount, Player& player, Transformation& world, Shader& shader);
|
||||
void UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTYPE_LAST]);
|
||||
void TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]);
|
||||
|
Loading…
Reference in New Issue
Block a user