Nerfage pour version Debug/MSVC

This commit is contained in:
MarcEricMartel 2021-12-06 09:45:51 -05:00
parent a3c0dee1f2
commit d01e8e9c62
20 changed files with 74 additions and 36 deletions

View File

@ -70,27 +70,27 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>ClangCL</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>ClangCL</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>ClangCL</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>ClangCL</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">

View File

@ -15,7 +15,18 @@
#define CHUNK_SIZE_X 16
#define CHUNK_SIZE_Y 128
#define CHUNK_SIZE_Z 16
#define MAX_SELECTION_DISTANCE 5
#ifdef _DEBUG
#define WORLD_SIZE_X 32
#define WORLD_SIZE_Y 32
#define FRAMES_RENDER_CHUNKS 4
#define FRAMES_UPDATE_CHUNKS 4
#define FRAMES_DELETE_CHUNKS 4
#define VIEW_DISTANCE 128
#else
#define WORLD_SIZE_X 128
#define WORLD_SIZE_Y 128
@ -24,7 +35,8 @@
#define FRAMES_DELETE_CHUNKS 2
#define VIEW_DISTANCE 512
#define MAX_SELECTION_DISTANCE 5
#endif
typedef uint8_t BlockType;
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST };

View File

@ -15,24 +15,26 @@ void Engine::Init() {
abort();
}
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glDisable(GL_FRAMEBUFFER_SRGB);
glClearColor(0.f, 0.f, 0.f, 1.f);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.0001f, 1000.0f);
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_CULL_FACE);
glDisable(GL_FRAMEBUFFER_SRGB);
glEnable(GL_BLEND);
glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); // , GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_SUBTRACT);// , GL_FUNC_ADD);
// Objet de skybox avec sa propre texture et son propre shader!
m_skybox.Init(0.00013f);
m_skybox.Init(0.2f);
// Objet de musique!
//m_audio.ToggleMusicState();
@ -54,7 +56,7 @@ void Engine::LoadResource() {
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.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 "metal1.png");
TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png");
if (!m_textureAtlas.Generate(512, false)) {
std::cout << " Unable to generate texture atlas ..." << std::endl;
@ -89,6 +91,7 @@ void Engine::DrawHud(float elapsedTime) {
// Setter le blend function , tout ce qui sera noir sera transparent
glColor4f(1.f, 1.f, 1.f, 1.f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBlendEquation(GL_FUNC_ADD);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
@ -135,7 +138,8 @@ void Engine::DrawHud(float elapsedTime) {
glTexCoord2f(0, 1);
glVertex2i(0, crossSize);
glEnd();
glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); // , GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_SUBTRACT);// , GL_FUNC_ADD);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
@ -174,7 +178,7 @@ void Engine::Render(float elapsedTime) {
Transformation all;
Transformation skybox;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Transformations initiales
glMatrixMode(GL_MODELVIEW);
@ -188,19 +192,23 @@ void Engine::Render(float elapsedTime) {
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation
// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
if (m_isSkybox) m_skybox.Render(skybox);
if (m_mouseL)
m_world.ChangeBlockAtCursor(BTYPE_DIRT, m_player, m_block);
else if (m_mouseR)
m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player, m_block);
glStencilFunc(GL_EQUAL, 1, 0x00);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
m_world.Update(m_renderCount, m_badHitCount, m_player, all, m_shader01, m_textureAtlas, m_perlin, m_blockinfo);
glStencilFunc(GL_GREATER, 1, 0xFF);
if (m_isSkybox) m_skybox.Render(skybox);
if (m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_STENCIL_TEST);
DrawHud(elapsedTime);
glEnable(GL_STENCIL_TEST);
if (m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 466 KiB

After

Width:  |  Height:  |  Size: 370 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 362 KiB

After

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 508 KiB

After

Width:  |  Height:  |  Size: 528 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 522 KiB

After

Width:  |  Height:  |  Size: 417 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 535 KiB

After

Width:  |  Height:  |  Size: 423 KiB

View File

@ -44,12 +44,14 @@ void Skybox::Init(float size){
void Skybox::Render(Transformation tran) const {
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
tran.Use();
m_texture.Bind();
m_shader.Use();
m_vertexBuffer.Render();
m_shader.Disable();
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
}
Texture& Skybox::GetTexture() { return m_texture; }

View File

@ -99,7 +99,6 @@ void World::CleanUpWorld(int& deleteframes, bool clear = false) {
m_tbDeleted.pop_back();
deleteframes = FRAMES_DELETE_CHUNKS;
}
std::cout << "Chunk Write Buffer: " << m_tbDeleted.size() << std::endl;
}
void World::GetScope(int& x, int& y) {
@ -124,7 +123,7 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) {
for (int index = 0; index < m_tbDeleted.size(); ++index) { // Vérifie l'existence d'un chunk dans le buffer de suppression avec sa position.
int x, y;
if (&m_tbDeleted.at(index)) {
if (m_tbDeleted.at(index)) {
m_tbDeleted.at(index)->GetPosition(x, y);
if (chx / CHUNK_SIZE_X + m_center[0] == x &&
chy / CHUNK_SIZE_Z + m_center[1] == y) {
@ -143,7 +142,7 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) {
GetChunks().Set(chx / CHUNK_SIZE_X, chy / CHUNK_SIZE_Z, new Chunk(chx / CHUNK_SIZE_X + m_center[0], chy / CHUNK_SIZE_Z + m_center[1]));
Chunk* chunk = GetChunks().Get(chx / CHUNK_SIZE_X, chy / CHUNK_SIZE_Z);
for (int x = 0; x < CHUNK_SIZE_X; ++x)
for (int x = 0; x < CHUNK_SIZE_X; ++x) // Montagnes
for (int z = 0; z < CHUNK_SIZE_Z; ++z) {
float xnoiz, ynoiz;
xnoiz = (double)(x + (chx / CHUNK_SIZE_X + m_center[0]) * CHUNK_SIZE_X) / (double)INT16_MAX;
@ -153,26 +152,44 @@ bool World::GenerateChunk(int chx, int chy, Perlin& perlin) {
chunk->SetBlock(x, y, z, BTYPE_METAL, this);
}
for (int x = 0; x < CHUNK_SIZE_X; ++x)
for (int x = 0; x < CHUNK_SIZE_X; ++x) // Collines
for (int z = 0; z < CHUNK_SIZE_Z; ++z) {
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) * 5.f + 16.f;
float height = perlin.Get(xnoiz, ynoiz) * 5.f + 24.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);
}
}
for (int x = 0; x < CHUNK_SIZE_X; ++x)
for (int x = 0; x < CHUNK_SIZE_X; ++x) // "Lacs"
for (int z = 0; z < CHUNK_SIZE_Z; ++z) {
for (int y = 0; y < 15; ++y) {
for (int y = 0; y < 12; ++y) {
if (chunk->GetBlock(x, y, z) == BTYPE_AIR)
chunk->SetBlock(x, y, z, BTYPE_ICE, this);
}
}
for (int x = 0; x < CHUNK_SIZE_X; ++x) // "Arbres"
for (int z = 0; z < CHUNK_SIZE_Z; ++z) {
float xnoiz, ynoiz;
xnoiz = (double)(z * CHUNK_SIZE_Y + (chx / CHUNK_SIZE_X + m_center[0]) * CHUNK_SIZE_X) / (double)INT16_MAX;
ynoiz = (double)(x * CHUNK_SIZE_Y + (chy / CHUNK_SIZE_Z + m_center[1]) * CHUNK_SIZE_Z) / (double)INT16_MAX;
bool tree = (int)(abs(perlin.Get(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true: false;
for (int y = 0; y < CHUNK_SIZE_Y - 10; ++y)
if (chunk->GetBlock(x, y, z) == BTYPE_AIR)
if (chunk->GetBlock(x, y - 1, z) == BTYPE_GRASS)
if (tree) {
for (int i = 0; i < (int)(abs(perlin.Get(xnoiz, ynoiz))) % 3 + 1; ++i)
chunk->SetBlock(x, y + i, z, BTYPE_DIRT, this);
break;
}
}
}
else {
input.seekg(0, std::ios_base::end);
@ -274,31 +291,28 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran
static Vector3f renderManifest[VIEW_DISTANCE * 4];
for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) {
//for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) {
for (int dist = 0; dist <= VIEW_DISTANCE; dist += CHUNK_SIZE_X) {
// Configuration du radar.
float sinus, cosinus;
int echantillons;
if (dist > VIEW_DISTANCE * .625f) {
sinus = .01745240643; // sin(1 degré)
cosinus = .99984769515; // cos(1 degré)
echantillons = 90;
}
else if (dist > VIEW_DISTANCE * .5f) {
else if (dist > VIEW_DISTANCE * .325f) {
sinus = .0261769483;
cosinus = .99965732497;
echantillons = 60;
}
else if (dist > VIEW_DISTANCE * .375f) {
else {
sinus = .0348994967;
cosinus = .99939082701;
echantillons = 45;
}
else {
sinus = .05233595624;
cosinus = .99862953475;
echantillons = 30;
}
angle.x = direct.z + direct.x;
angle.z = direct.z - direct.x;
@ -326,8 +340,7 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran
++badhitcount;
}
float ray = (pos - cursor).Length();
if (valide) renderManifest[rendercount++] = Vector3f(chx, (VIEW_DISTANCE - ray * 2 + 128) / (float)VIEW_DISTANCE, chy);
if (valide) renderManifest[rendercount++] = Vector3f(chx, (VIEW_DISTANCE - (pos - cursor).Length() * 2.f + 128) / (float)VIEW_DISTANCE, chy);
}
}
}
@ -336,7 +349,7 @@ void World::RenderWorld(int& rendercount, int& badhitcount, Player& player, Tran
world.ApplyTranslation(chx, 0, chy);
world.Use();
glBlendColor(0.f, 0.f, 0.f, renderManifest[index].y);
glBlendColor(renderManifest[index].y, renderManifest[index].y, renderManifest[index].y, 1.f);
ChunkAt(chx, 1, chy)->Render();
world.ApplyTranslation(-chx, 0, -chy);
}