diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj
index adbfa92..4de98aa 100644
--- a/SQCSim2021/SQCSim2021.vcxproj
+++ b/SQCSim2021/SQCSim2021.vcxproj
@@ -68,13 +68,13 @@
Application
true
Unicode
- v142
+ ClangCL
Application
true
Unicode
- v142
+ ClangCL
Application
diff --git a/SQCSim2021/chunk.cpp b/SQCSim2021/chunk.cpp
index 17884ae..606b97f 100644
--- a/SQCSim2021/chunk.cpp
+++ b/SQCSim2021/chunk.cpp
@@ -16,7 +16,7 @@ void Chunk::SetBlock(int x, int y, int z, BlockType type) {
BlockType Chunk::GetBlock(int x, int y, int z) { return m_blocks.Get(x, y, z); }
-void Chunk::Update(BlockInfo* blockinfo[BTYPE_LAST]) {
+void Chunk::Update(BlockInfo* blockinfo[BTYPE_LAST], World* world) {
float u, v, s;
// Update mesh
if (m_isDirty) {
@@ -28,10 +28,12 @@ void Chunk::Update(BlockInfo* blockinfo[BTYPE_LAST]) {
for (int y = 0; y < CHUNK_SIZE_Y; ++y) {
if (count > USHRT_MAX)
break;
+
BlockType bt = GetBlock(x, y, z);
+
if (bt != BTYPE_AIR) {
blockinfo[bt]->GetTexture(u, v, s);
- AddBlockToMesh(vd, count, bt, x, y, z, u, v, s);
+ AddBlockToMesh(vd, count, bt, x, y, z, u, v, s, world);
}
}
}
@@ -47,21 +49,9 @@ void Chunk::Update(BlockInfo* blockinfo[BTYPE_LAST]) {
}
void Chunk::AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt,
- int x, int y, int z, float u, float v, float s) {
-
- if (x == CHUNK_SIZE_X - 1 || GetBlock(x + 1, y, z) == BTYPE_AIR) { // x
- vd[count++] = VertexBuffer::VertexData(x + 1.f, y, z, .9f, .9f, .9f, u, v);
- vd[count++] = VertexBuffer::VertexData(x + 1.f, y + 1.f, z, .9f, .9f, .9f, u, v + s);
- vd[count++] = VertexBuffer::VertexData(x + 1.f, y + 1.f, z + 1.f, .9f, .9f, .9f, u + s, v + s);
- vd[count++] = VertexBuffer::VertexData(x + 1.f, y, z + 1.f, .9f, .9f, .9f, u + s, v);
- }
+ int x, int y, int z, float u, float v, float s, World* world) {
- if (x == 0 || GetBlock(x - 1, y, z) == BTYPE_AIR) { // -x
- vd[count++] = VertexBuffer::VertexData(x, y + 1.f, z + 1.f, .9f, .9f, .9f, u, v + s);
- vd[count++] = VertexBuffer::VertexData(x, y + 1.f, z, .9f, .9f, .9f, u + s, v + s);
- vd[count++] = VertexBuffer::VertexData(x, y, z, .9f, .9f, .9f, u + s, v);
- vd[count++] = VertexBuffer::VertexData(x, y, z + 1.f, .9f, .9f, .9f, u, v);
- }
+ int cx = x + m_posX * CHUNK_SIZE_X, cy = z + m_posY * CHUNK_SIZE_Z;
if (y == CHUNK_SIZE_Y - 1 || GetBlock(x, y + 1, z) == BTYPE_AIR) { // y
vd[count++] = VertexBuffer::VertexData(x, y + 1.f, z, .8f, .8f, .8f, u, v);
@@ -77,14 +67,28 @@ void Chunk::AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType b
vd[count++] = VertexBuffer::VertexData(x + 1.f, y, z + 1.f, .8f, .8f, .8f, u + s, v);
}
- if (z == CHUNK_SIZE_Z - 1 || GetBlock(x, y, z + 1) == BTYPE_AIR) { // z
+ if (cx == INT16_MAX - 1 || world->BlockAt(cx + 1, y, cy) == BTYPE_AIR) { // x
+ vd[count++] = VertexBuffer::VertexData(x + 1.f, y, z, .9f, .9f, .9f, u, v);
+ vd[count++] = VertexBuffer::VertexData(x + 1.f, y + 1.f, z, .9f, .9f, .9f, u, v + s);
+ vd[count++] = VertexBuffer::VertexData(x + 1.f, y + 1.f, z + 1.f, .9f, .9f, .9f, u + s, v + s);
+ vd[count++] = VertexBuffer::VertexData(x + 1.f, y, z + 1.f, .9f, .9f, .9f, u + s, v);
+ }
+
+ if (cx == 0 || world->BlockAt(cx - 1, y, cy) == BTYPE_AIR) { // -x
+ vd[count++] = VertexBuffer::VertexData(x, y + 1.f, z + 1.f, .9f, .9f, .9f, u, v + s);
+ vd[count++] = VertexBuffer::VertexData(x, y + 1.f, z, .9f, .9f, .9f, u + s, v + s);
+ vd[count++] = VertexBuffer::VertexData(x, y, z, .9f, .9f, .9f, u + s, v);
+ vd[count++] = VertexBuffer::VertexData(x, y, z + 1.f, .9f, .9f, .9f, u, v);
+ }
+
+ if (cy == INT16_MAX - 1 || world->BlockAt(cx, y, cy + 1) == BTYPE_AIR) { // z
vd[count++] = VertexBuffer::VertexData(x, y, z + 1.f, 1.f, 1.f, 1.f, u, v);
vd[count++] = VertexBuffer::VertexData(x + 1.f, y, z + 1.f, 1.f, 1.f, 1.f, u + s, v);
vd[count++] = VertexBuffer::VertexData(x + 1.f, y + 1.f, z + 1.f, 1.f, 1.f, 1.f, u + s, v + s);
vd[count++] = VertexBuffer::VertexData(x, y + 1.f, z + 1.f, 1.f, 1.f, 1.f, u, v + s);
}
- if (z == 0 || GetBlock(x, y, z - 1) == BTYPE_AIR) { // -z
+ if (cy == 0 || world->BlockAt(cx, y, cy - 1) == BTYPE_AIR) { // -z
vd[count++] = VertexBuffer::VertexData(x, y + 1.f, z, 1.f, 1.f, 1.f, u, v + s);
vd[count++] = VertexBuffer::VertexData(x + 1.f, y + 1.f, z, 1.f, 1.f, 1.f, u + s, v + s);
vd[count++] = VertexBuffer::VertexData(x + 1.f, y, z, 1.f, 1.f, 1.f, u + s, v);
diff --git a/SQCSim2021/chunk.h b/SQCSim2021/chunk.h
index 6b52fcc..62ea548 100644
--- a/SQCSim2021/chunk.h
+++ b/SQCSim2021/chunk.h
@@ -5,6 +5,9 @@
#include "array2d.h"
#include "vertexbuffer.h"
#include "blockinfo.h"
+#include "world.h"
+
+class World;
class Chunk {
private:
@@ -15,7 +18,7 @@ class Chunk {
int m_posX; // Position du chunk dans l'array constituant le monde.
int m_posY;
- void AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt, int x, int y, int z, float u, float v, float s);
+ 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);
@@ -25,7 +28,7 @@ class Chunk {
void SetBlock(int x, int y, int z, BlockType type);
BlockType GetBlock(int x, int y, int z);
- void Update(BlockInfo* blockinfo[BTYPE_LAST]);
+ void Update(BlockInfo* blockinfo[BTYPE_LAST], World* world);
void Render() const;
bool IsDirty() const;
diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h
index 106ea2b..7696862 100644
--- a/SQCSim2021/define.h
+++ b/SQCSim2021/define.h
@@ -12,7 +12,7 @@
#include
#endif
-#define VIEW_DISTANCE 64
+#define VIEW_DISTANCE 128
#define CHUNK_SIZE_X 16
#define CHUNK_SIZE_Y 128
#define CHUNK_SIZE_Z 16
diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp
index 1180f60..2d25f4c 100644
--- a/SQCSim2021/engine.cpp
+++ b/SQCSim2021/engine.cpp
@@ -30,7 +30,7 @@ void Engine::Init()
glEnable(GL_CULL_FACE);
// Light
- GLfloat light0Pos[4] = { 0.0f, CHUNK_SIZE_Y, 0.0f, 1.0f };
+ /*GLfloat light0Pos[4] = { 0.0f, CHUNK_SIZE_Y, 0.0f, 1.0f };
GLfloat light0Amb[4] = { 0.2f, 0.2f, 0.2f, 1.f };
GLfloat light0Diff[4] = { 1.f, 1.f, 1.f, 1.f };
GLfloat light0Spec[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
@@ -39,7 +39,7 @@ void Engine::Init()
glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);
glLightfv(GL_LIGHT0, GL_AMBIENT, light0Amb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0Diff);
- glLightfv(GL_LIGHT0, GL_SPECULAR, light0Spec);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, light0Spec);*/
// Objet de skybox avec sa propre texture et son propre shader!
m_skybox.Init(0.00013f);
@@ -248,7 +248,7 @@ void Engine::Render(float elapsedTime) {
all.ApplyTranslation(chx * CHUNK_SIZE_X, 0, chy * CHUNK_SIZE_Z);
all.Use();
if (m_world.GetChunks().Get(chx, chy)->IsDirty())
- m_world.GetChunks().Get(chx, chy)->Update(m_blockinfo);
+ m_world.GetChunks().Get(chx, chy)->Update(m_blockinfo, &m_world);
m_world.GetChunks().Get(chx, chy)->Render();
all.ApplyTranslation(-chx * CHUNK_SIZE_X, 0, -chy * CHUNK_SIZE_Z);
}
@@ -262,7 +262,7 @@ void Engine::Render(float elapsedTime) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- if (m_player.GetPosition().y < -10.f) m_player = Player(Vector3f(64, 34, 64)); // Respawn si le bonho- joueur tombe en bas du monde.
+ if (m_player.GetPosition().y < -10.f) m_player = Player(Vector3f(VIEW_DISTANCE * CHUNK_SIZE_X / 2, CHUNK_SIZE_Y / 2, VIEW_DISTANCE * CHUNK_SIZE_Z / 2)); // Respawn si le bonho- joueur tombe en bas du monde.
}
void Engine::KeyPressEvent(unsigned char key)
diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h
index 49c4d66..9693523 100644
--- a/SQCSim2021/engine.h
+++ b/SQCSim2021/engine.h
@@ -52,7 +52,7 @@ private:
Shader m_shader01;
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
- Player m_player = Player(Vector3f(64, 34, 64));
+ Player m_player = Player(Vector3f(VIEW_DISTANCE * CHUNK_SIZE_X / 2, CHUNK_SIZE_Y / 2, VIEW_DISTANCE * CHUNK_SIZE_Z / 2));
bool m_keyW = false;
bool m_keyA = false;
diff --git a/SQCSim2021/openglcontext.cpp b/SQCSim2021/openglcontext.cpp
index f0b3b52..cb78fb6 100644
--- a/SQCSim2021/openglcontext.cpp
+++ b/SQCSim2021/openglcontext.cpp
@@ -152,7 +152,7 @@ void OpenglContext::ShowCrossCursor() const
void OpenglContext::InitWindow(int width, int height)
{
- m_app.create((m_fullscreen ? sf::VideoMode::getFullscreenModes()[0] : sf::VideoMode(width, height, 32)), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize | sf::Style::Close), sf::ContextSettings(32, 8, 0));
+ m_app.create((m_fullscreen ? sf::VideoMode::getFullscreenModes()[0] : sf::VideoMode(width, height, 32)), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize | sf::Style::Close), sf::ContextSettings(32, 8, 8));
}
OpenglContext::MOUSE_BUTTON OpenglContext::ConvertMouseButton(sf::Mouse::Button button) const
diff --git a/SQCSim2021/world.h b/SQCSim2021/world.h
index ec0f70f..7c027ac 100644
--- a/SQCSim2021/world.h
+++ b/SQCSim2021/world.h
@@ -6,6 +6,8 @@
#include "vector3.h"
#include "transformation.h"
+class Chunk;
+
class World {
public:
World();