Skip to content

Commit

Permalink
Initialized all the cells (61x61x61). Fixed a bug where back face cul…
Browse files Browse the repository at this point in the history
…ling wasn't applied
  • Loading branch information
Zang3th committed Sep 28, 2023
1 parent 51b928c commit a4493d0
Show file tree
Hide file tree
Showing 28 changed files with 282 additions and 185 deletions.
41 changes: 35 additions & 6 deletions Apps/CellSim/src/CellSimApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,34 @@ namespace CS
LoadResources();

//Create application specific renderers
_sceneRenderer = Engine::RenderManager::AddScene(_nearPlane, _farPlane, _lightPos, _lightCol);
Engine::RenderManager::AddCells
_sceneRenderer = Engine::RenderManager::AddSceneRenderer(_nearPlane, _farPlane, _lightPos, _lightCol);
Engine::RenderManager::AddCellRenderer
(
1.0f,
_nearPlane,
_farPlane,
"CellShader",
glm::vec3(512.0f, 0.0f, 512.0f)
glm::vec3(482.0f, 2.0f, 482.0f)
);
_shadowRenderer = Engine::RenderManager::AddShadows
_shadowRenderer = Engine::RenderManager::AddShadowRenderer
(
8192,
_lightPos,
_lightTarget,
glm::ortho(-60.0f, 60.0f, -60.0f, 60.0f, 109.0f, 228.0f),
glm::ortho(-60.0f, 60.0f, -60.0f, 60.0f, 105.0f, 228.0f),
"ShadowCreateShader"
);
_spriteRenderer = Engine::RenderManager::AddSprites();
_spriteRenderer = Engine::RenderManager::AddSpriteRenderer();

//Set default shaders for the scene
_sceneRenderer->SetModelShader("ModelShader");

//Create UI
_interface = Engine::MakeScope<CellSimInterface>();

//Create cell manager
_cellManager = Engine::MakeScope<Engine::CellManager>();

return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -136,6 +139,32 @@ namespace CS
}
}

{
//ToDo: Add profiling

Engine::AppSettings::cellsAlive = _cellManager->GetAliveCellAmount();

if(Engine::AppSettings::spawnNewCell)
{
_cellManager->SpawnCell
(
Engine::AppSettings::selectedCellType,
Engine::AppSettings::selectedCellAmount,
glm::vec3(Engine::AppSettings::selectedCellCoords[0],
Engine::AppSettings::selectedCellCoords[1],
Engine::AppSettings::selectedCellCoords[2])
);

Engine::AppSettings::spawnNewCell = false;
}

if(Engine::AppSettings::cellsAlive > 0)
{
_cellManager->CalculateCellPhysics();
_cellManager->UpdateCellRenderer();
}
}

{
Engine::PROFILE_SCOPE("Prepare frame");

Expand Down
9 changes: 5 additions & 4 deletions Apps/CellSim/src/CellSimApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ namespace CS
const glm::vec3 _lightCol = glm::vec3(1.0f, 1.0f, 1.0f);
const glm::vec3 _camStartPos = glm::vec3(350.0f, 125.0f, 415.0f);

Engine::SceneRenderer* _sceneRenderer = nullptr;
Engine::ShadowRenderer* _shadowRenderer = nullptr;
Engine::SpriteRenderer* _spriteRenderer = nullptr;
Engine::Scope<CellSimInterface> _interface;
Engine::SceneRenderer* _sceneRenderer = nullptr;
Engine::ShadowRenderer* _shadowRenderer = nullptr;
Engine::SpriteRenderer* _spriteRenderer = nullptr;
Engine::Scope<CellSimInterface> _interface;
Engine::Scope<Engine::CellManager> _cellManager;

void LoadResources() final;
Engine::uint32 InitModules() final;
Expand Down
12 changes: 6 additions & 6 deletions Apps/CellSim/src/CellSimInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ namespace CS
// --- Render stats
ImGui::NewLine();
ImGui::Separator();
ImGui::Text("DrawCalls: %d", Engine::AppSettings::renderStats.drawCalls);
ImGui::Text("DrawnVertices: %d", Engine::AppSettings::renderStats.drawnVertices);
ImGui::Text("Draw calls: %d", Engine::AppSettings::renderStats.drawCalls);
ImGui::Text("Drawn vertices: %d", Engine::AppSettings::renderStats.drawnVertices);
ImGui::Separator();

ImGui::NewLine();
Expand Down Expand Up @@ -126,17 +126,17 @@ namespace CS
{
if(ImGui::MenuItem("None"))
{
Engine::AppSettings::selectedCellType = Engine::CellTypes::None;
Engine::AppSettings::selectedCellType = Engine::CellType::None;
}

if(ImGui::MenuItem("Water"))
{
Engine::AppSettings::selectedCellType = Engine::CellTypes::Water;
Engine::AppSettings::selectedCellType = Engine::CellType::Water;
}

if(ImGui::MenuItem("Magma"))
{
Engine::AppSettings::selectedCellType = Engine::CellTypes::Magma;
Engine::AppSettings::selectedCellType = Engine::CellType::Magma;
}

ImGui::EndMenu();
Expand Down Expand Up @@ -182,7 +182,7 @@ namespace CS
CenterCursor("Spawn");
if (ImGui::Button("Spawn"))
{
//ToDo: Implement cell spawn logic
Engine::AppSettings::spawnNewCell = true;
}
ImGui::Separator();

Expand Down
10 changes: 5 additions & 5 deletions Apps/GreenWorld/src/GreenWorldApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ namespace GW
LoadResources();

//Create application specific renderers
_sceneRenderer = Engine::RenderManager::AddScene(_nearPlane, _farPlane, _lightPos, _lightCol);
_shadowRenderer = Engine::RenderManager::AddShadows
_sceneRenderer = Engine::RenderManager::AddSceneRenderer(_nearPlane, _farPlane, _lightPos, _lightCol);
_shadowRenderer = Engine::RenderManager::AddShadowRenderer
(
8192,
_lightPos,
_lightTarget,
glm::ortho(-90.0f, 90.0f, -90.0f, 90.0f, 110.0f, 210.0f),
"ShadowCreateShader"
);
_spriteRenderer = Engine::RenderManager::AddSprites();
_waterRenderer = Engine::RenderManager::AddWater();
Engine::RenderManager::AddParticles
_spriteRenderer = Engine::RenderManager::AddSpriteRenderer();
_waterRenderer = Engine::RenderManager::AddWaterRenderer();
Engine::RenderManager::AddParticleRenderer
(
200,
5.0f,
Expand Down
14 changes: 7 additions & 7 deletions Apps/GreenWorld/src/GreenWorldInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ namespace GW
//Render stats
ImGui::NewLine();
ImGui::Separator();
ImGui::Text("DrawCalls: %d", Engine::AppSettings::renderStats.drawCalls);
ImGui::Text("DrawnVertices: %d", Engine::AppSettings::renderStats.drawnVertices);
ImGui::Text("Draw calls: %d", Engine::AppSettings::renderStats.drawCalls);
ImGui::Text("Drawn vertices: %d", Engine::AppSettings::renderStats.drawnVertices);
ImGui::Separator();

ImGui::NewLine();
ImGui::Separator();
ImGui::Text("Model passes: %d", Engine::AppSettings::renderStats.modelPasses);
ImGui::Text("Terrain passes: %d", Engine::AppSettings::renderStats.terrainPasses);
ImGui::Text("Water passes: %d", Engine::AppSettings::renderStats.waterPasses);
ImGui::Text("Model passes: %d", Engine::AppSettings::renderStats.modelPasses);
ImGui::Text("Terrain passes: %d", Engine::AppSettings::renderStats.terrainPasses);
ImGui::Text("Water passes: %d", Engine::AppSettings::renderStats.waterPasses);
ImGui::Text("Particle passes: %d", Engine::AppSettings::renderStats.particlePasses);
ImGui::Text("Sprite passes: %d", Engine::AppSettings::renderStats.spritePasses);
ImGui::Text("Cubemap passes: %d", Engine::AppSettings::renderStats.cubemapPasses);
ImGui::Text("Sprite passes: %d", Engine::AppSettings::renderStats.spritePasses);
ImGui::Text("Cubemap passes: %d", Engine::AppSettings::renderStats.cubemapPasses);
ImGui::Separator();

//Camera stats
Expand Down
10 changes: 10 additions & 0 deletions Engine/Core/GLRenderSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ namespace Engine
GLCall(glEnable(distance));
}

void GLRenderSettings::EnableCulling()
{
GLCall(glEnable(GL_CULL_FACE));
}

void GLRenderSettings::DisableMultisample()
{
GLCall(glDisable(GL_MULTISAMPLE));
Expand All @@ -63,6 +68,11 @@ namespace Engine
GLCall(glDisable(distance));
}

void GLRenderSettings::DisableCulling()
{
GLCall(glDisable(GL_CULL_FACE));
}

void GLRenderSettings::SetViewport(uint32 width, uint32 height)
{
GLCall(glViewport(0, 0, width, height));
Expand Down
2 changes: 2 additions & 0 deletions Engine/Core/GLRenderSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ namespace Engine
static void EnableBlending();
static void EnableWireframe();
static void EnableClipDistance(GLushort distance);
static void EnableCulling();

static void DisableMultisample();
static void DisableDepthtest();
static void DisableBlending();
static void DisableWireframe();
static void DisableClipDistance(GLushort distance);
static void DisableCulling();

static void SetViewport(uint32 width, uint32 height);
static void SetDepthFunc(GLushort func);
Expand Down
8 changes: 5 additions & 3 deletions Engine/Core/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace Engine
};

// --- Read in of cell types via X-Macro
enum CellTypes
enum CellType
{
# define X(a) a,
# include "CellTypes.def"
Expand Down Expand Up @@ -91,12 +91,14 @@ namespace Engine
inline static constexpr float GRAVITY = -20.0f;

// --- CellSim
inline static constexpr uint32 CELL_FRAME_SIZE = 64;
inline static constexpr uint32 CELL_FRAME_SIZE = 61;
inline static constexpr uint32 MAX_CELL_AMOUNT = CELL_FRAME_SIZE * CELL_FRAME_SIZE * CELL_FRAME_SIZE;
inline static bool resetCamera = false;
inline static CellTypes selectedCellType = None;
inline static CellType selectedCellType = None;
inline static int32 selectedCellCoords[3] = {0, 0, 0};
inline static int32 selectedCellAmount = 0;
inline static uint32 cellsAlive = 0;
inline static bool spawnNewCell = false;

AppSettings() = delete;
};
Expand Down
50 changes: 50 additions & 0 deletions Engine/Core/VerticeData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

namespace Engine
{
inline static const float CUBE_VERTICES[] =
{
// Back face
-1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
// Front face
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
// Left face
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
// Right face
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
// Bottom face
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
// Top face
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f
};
}
8 changes: 4 additions & 4 deletions Engine/Debug/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ namespace Engine
void Logger::Info(const std::string& action, const std::string& obj, const std::string& params)
{
LOG(INFO) << " | " << FileManager::PadString(action, 8)
<< " | " << FileManager::PadString(obj, 14)
<< " | " << FileManager::PadString(obj, 12)
<< " | " << params;
}

void Logger::Warn(const std::string& action, const std::string&obj, const std::string& params)
{
LOG(WARNING) << "| " << FileManager::PadString(action, 8)
<< " | " << FileManager::PadString(obj, 14)
<< " | " << FileManager::PadString(obj, 12)
<< " | " << params;
}

void Logger::Error(const std::string& action, const std::string& obj, const std::string& params)
{
LOG(ERROR) << "| " << FileManager::PadString(action, 8)
<< " | " << FileManager::PadString(obj, 14)
<< " | " << FileManager::PadString(obj, 12)
<< " | " << params;
}

void Logger::Trace(const std::string& action, const std::string& obj, const std::string& params)
{
LOG(TRACE) << "| " << FileManager::PadString(action, 8)
<< " | " << FileManager::PadString(obj, 14)
<< " | " << FileManager::PadString(obj, 12)
<< " | " << params;
}
}
13 changes: 10 additions & 3 deletions Engine/Engine.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
#pragma once

// ----- Engine core -----
#include "Logger.hpp"
#include "Window.hpp"
#include "ResourceManager.hpp"
#include "Types.hpp"
#include "Profiler.hpp"
#include "RenderManager.hpp"
#include "App.hpp"
#include "Audio.hpp"
#include "App.hpp"

// ----- Resources and renderables -----
#include "ResourceManager.hpp"
#include "RenderManager.hpp"
#include "CellManager.hpp"

// ----- Camera -----
#include "Camera3D.hpp"
#include "CameraController3D.hpp"

// ----- UI -----
#include "Interface.hpp"

// ----- Rendering -----
#include "SceneRenderer.hpp"
#include "ShadowRenderer.hpp"
#include "SpriteRenderer.hpp"
Expand Down
Loading

0 comments on commit a4493d0

Please sign in to comment.