Skip to content

Commit

Permalink
Some work to prepare for continuous cell spawner
Browse files Browse the repository at this point in the history
  • Loading branch information
Zang3th committed Oct 18, 2023
1 parent 43c0799 commit a7b8ed9
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 257 deletions.
52 changes: 33 additions & 19 deletions Apps/CellSim/CellSimApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ namespace CS
_sceneRenderer = Engine::RenderManager::AddSceneRenderer();
_sceneRenderer->SetModelShader("ModelShader");
_shadowRenderer = Engine::RenderManager::AddShadowRenderer(8192, glm::ortho(-60.0f, 60.0f, -60.0f, 60.0f, 105.0f, 228.0f), "ShadowCreateShader");
_cellRenderer = Engine::RenderManager::AddCellRenderer(1.0f, "CellShader", glm::vec3(482.0f, 2.0f, 482.0f));
_spriteRenderer = Engine::RenderManager::AddSpriteRenderer();

//Create cell manager and add cell renderer
_cellManager = Engine::MakeScope<Engine::CellManager>();
_cellManager->AddCellRenderer(1.0f, "CellShader", glm::vec3(482.0f, 2.0f, 482.0f));

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

Expand Down Expand Up @@ -88,6 +91,24 @@ namespace CS
);
}

void CellSimApp::HandleCellSpawn()
{
if(Engine::CellSimParams::selectedCellAmount == 1)
{
_cellManager->SpawnCell
(
Engine::CellSimParams::selectedCellType,
glm::u32vec3(Engine::CellSimParams::selectedCellCoords[0],
Engine::CellSimParams::selectedCellCoords[1],
Engine::CellSimParams::selectedCellCoords[2])
);
}
else if(Engine::CellSimParams::createSpawner)
{
//ToDo: Implement
}
}

// ----- Public -----

CellSimApp::CellSimApp()
Expand Down Expand Up @@ -129,44 +150,32 @@ namespace CS
}

{
//ToDo: Add profiling
Engine::PROFILE_SCOPE("Manage cells");

//Check for cell spawn
if(Engine::CellSimParams::spawnNewCell)
{
if(Engine::CellSimParams::selectedCellAmount == 1)
{
_cellRenderer->SpawnCell
(
Engine::CellSimParams::selectedCellType,
glm::u32vec3(Engine::CellSimParams::selectedCellCoords[0],
Engine::CellSimParams::selectedCellCoords[1],
Engine::CellSimParams::selectedCellCoords[2])
);
}

HandleCellSpawn();
Engine::CellSimParams::spawnNewCell = false;
}

//Check for cell delete
if(Engine::CellSimParams::deleteAllCells)
{
_cellRenderer->DeleteAllCells();
_cellManager->DeleteAllCells();
Engine::CellSimParams::deleteAllCells = false;
}

Engine::CellSimParams::cellsAlive = _cellRenderer->GetAliveCellAmount();

//Check if we need to do physics (every 10ms)
if(Engine::CellSimParams::cellsAlive > 0 && _timeElapsed >= 0.01)
{
_cellRenderer->CalculateCellPhysics();
_cellManager->CalculateCellPhysics();
_timeElapsed = 0;
}

if(Engine::CellSimParams::printDebug)
{
_cellRenderer->PrintDebug();
_cellManager->PrintDebug();
Engine::CellSimParams::printDebug = false;
}
}
Expand All @@ -189,14 +198,19 @@ namespace CS
Engine::PROFILE_SCOPE("Render scene");

Engine::RenderManager::RenderScene();
Engine::RenderManager::RenderCells();

if(Engine::WindowParams::debugSprites)
{
Engine::RenderManager::RenderSprites();
}
}

{
Engine::PROFILE_SCOPE("Render cells");

Engine::RenderManager::RenderCells();
}

{
Engine::PROFILE_SCOPE("Render UI");

Expand Down
13 changes: 7 additions & 6 deletions Apps/CellSim/CellSimApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ namespace CS
class CellSimApp final : public Engine::App
{
private:
double _timeElapsed = 0.0;
Engine::SceneRenderer* _sceneRenderer = nullptr;
Engine::CellRenderer* _cellRenderer = nullptr;
Engine::ShadowRenderer* _shadowRenderer = nullptr;
Engine::SpriteRenderer* _spriteRenderer = nullptr;
Engine::Scope<CellSimInterface> _interface;
double _timeElapsed = 0.0;
Engine::SceneRenderer* _sceneRenderer = nullptr;
Engine::ShadowRenderer* _shadowRenderer = nullptr;
Engine::SpriteRenderer* _spriteRenderer = nullptr;
Engine::Scope<Engine::CellManager> _cellManager;
Engine::Scope<CellSimInterface> _interface;

void LoadResources() final;
Engine::uint32 InitModules() final;
void AddObjects();
void AddSprites();
void HandleCellSpawn();

public:
CellSimApp();
Expand Down
196 changes: 103 additions & 93 deletions Apps/CellSim/CellSimInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,143 +70,149 @@ namespace CS
ImGui::PlotVar("", (float)Engine::Window::GetDeltaTime() * 1000.0f, 0.0f, 30.0f);

// --- Render stats
ImGui::NewLine();
ImGui::Separator();
ImGui::Text("Draw calls: %d", Engine::RenderStatistics::drawCalls);
ImGui::Text("Drawn vertices: %d", Engine::RenderStatistics::drawnVertices);
ImGui::Separator();

ImGui::NewLine();
ImGui::Separator();
ImGui::Text("Model passes: %d", Engine::RenderStatistics::modelPasses);
ImGui::Text("Sprite passes: %d", Engine::RenderStatistics::spritePasses);
ImGui::Text("Cell passes: %d", Engine::RenderStatistics::cellPasses);
ImGui::Separator();

// --- Camera stats
ImGui::NewLine();
ImGui::Separator();
ImGui::Text("Camera-Position: ( %.1f, %.1f, %.1f )", Engine::Camera3D::GetPosition().x, Engine::Camera3D::GetPosition().y, Engine::Camera3D::GetPosition().z);
ImGui::Text("Camera-Front: ( %.1f, %.1f, %.1f )", Engine::Camera3D::GetFront().x, Engine::Camera3D::GetFront().y, Engine::Camera3D::GetFront().z);
ImGui::Text("Camera-Yaw, Pitch: ( %.2f, %.2f )", Engine::Camera3D::GetYaw(), Engine::Camera3D::GetPitch());
ImGui::Separator();

// --- Profiling/Timing-Results
ImGui::NewLine();
ImGui::Separator();
for(auto const& entry : Engine::Profiler::_results)
{
ImGui::Text("%.3fms - %s", entry.second, entry.first);
}
ImGui::Separator();
}

// --- Cell spawn menu
// --- Cell management
{
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 10));

// --- Titlebar
ImGui::NewLine();
ImGui::Separator();
CenterText("Cell management panel");
CenterText("Cell management");
ImGui::Separator();

// --- General information
ImGui::Text("Frame dimensions: (%d, %d, %d)",
Engine::CellSimParams::CELL_FRAME_SIZE,
Engine::CellSimParams::CELL_FRAME_SIZE,
Engine::CellSimParams::CELL_FRAME_SIZE);
ImGui::Text("Cells alive: %d", Engine::CellSimParams::cellsAlive);
ImGui::Separator();

// --- Cell selection menu
std::string cellTypeString = std::string("Selected cell type: ") + Engine::CellTypeStrings[Engine::CellSimParams::selectedCellType];
if(ImGui::BeginMenu(cellTypeString.c_str()))
{
if(ImGui::MenuItem("None"))
{
Engine::CellSimParams::selectedCellType = Engine::CellType::None;
}

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

if(ImGui::MenuItem("Lava"))
{
Engine::CellSimParams::selectedCellType = Engine::CellType::Lava;
}

ImGui::EndMenu();

Engine::CameraController3D::DeFocusWindow(Engine::Window::GetWindow());
}

// --- Cell spawn coordinate input
float width = ImGui::CalcItemWidth();
ImGui::PushItemWidth(width / 1.5f);

ImGui::Text("X Coordinate:\t");
ImGui::SameLine();
Input_u32("##1", &Engine::CellSimParams::selectedCellCoords[0], 1, 10, ImGuiInputTextFlags_CharsDecimal);
ImGui::Text("Y Coordinate:\t");
ImGui::SameLine();
Input_u32("##2", &Engine::CellSimParams::selectedCellCoords[1], 1, 10, ImGuiInputTextFlags_CharsDecimal);
ImGui::Text("Z Coordinate:\t");
ImGui::SameLine();
Input_u32("##3", &Engine::CellSimParams::selectedCellCoords[2], 1, 10, ImGuiInputTextFlags_CharsDecimal);

ImGui::PopItemWidth();
CheckCellBoundaries();

// --- Cell spawn amount
ImGui::Text("Amount:\t");
ImGui::SameLine();
RadioButton_u32("1", &Engine::CellSimParams::selectedCellAmount, 1);
ImGui::SameLine();
ImGui::Text("\t");
ImGui::SameLine();
RadioButton_u32("9", &Engine::CellSimParams::selectedCellAmount, 9);
ImGui::SameLine();
ImGui::Text("\t");
ImGui::SameLine();
RadioButton_u32("25", &Engine::CellSimParams::selectedCellAmount, 25);
ImGui::SameLine();
ImGui::Text("\t");
ImGui::SameLine();
RadioButton_u32("49", &Engine::CellSimParams::selectedCellAmount, 49);

// --- Spawn button
ImGui::Text("\t\t");
ImGui::SameLine();
if(ImGui::Button("Spawn"))
{
Engine::CellSimParams::spawnNewCell = true;
}
ImGui::SameLine();
ImGui::Text("Cells alive: %d", Engine::CellSimParams::cellsAlive);

// --- Delete all cells
ImGui::Text("\t\t");
ImGui::SameLine();
if(ImGui::Button("Delete all"))
{
Engine::CellSimParams::deleteAllCells = true;
}
ImGui::Separator();

// --- Print debug information
ImGui::Text("\t\t");
ImGui::SameLine();
if(ImGui::Button("Print cell debug information"))
// --- Cell management tabs
if(ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
{
Engine::CellSimParams::printDebug = true;
}
ImGui::Separator();

//ToDo: Add "generate stone ground" Button
// --- Cell spawn menu
if(ImGui::BeginTabItem("Spawn"))
{
// --- Cell selection menu
std::string cellTypeString = std::string("Selected cell type: ") + Engine::CellTypeStrings[Engine::CellSimParams::selectedCellType];
if(ImGui::BeginMenu(cellTypeString.c_str()))
{
if(ImGui::MenuItem("Water"))
{
Engine::CellSimParams::selectedCellType = Engine::CellType::Water;
}

if(ImGui::MenuItem("Lava"))
{
Engine::CellSimParams::selectedCellType = Engine::CellType::Lava;
}

ImGui::EndMenu();

Engine::CameraController3D::DeFocusWindow(Engine::Window::GetWindow());
}

// --- Cell spawn coordinate input
float width = ImGui::CalcItemWidth();
ImGui::PushItemWidth(width / 1.5f);

ImGui::Text("X Coordinate:\t");
ImGui::SameLine();
Input_u32("##Input1", &Engine::CellSimParams::selectedCellCoords[0], 1, 10, ImGuiInputTextFlags_CharsDecimal);
ImGui::Text("Y Coordinate:\t");
ImGui::SameLine();
Input_u32("##Input2", &Engine::CellSimParams::selectedCellCoords[1], 1, 10, ImGuiInputTextFlags_CharsDecimal);
ImGui::Text("Z Coordinate:\t");
ImGui::SameLine();
Input_u32("##Input3", &Engine::CellSimParams::selectedCellCoords[2], 1, 10, ImGuiInputTextFlags_CharsDecimal);

ImGui::PopItemWidth();
CheckCellBoundaries();

// --- Checkbox to create a continuous spawner
ImGui::Checkbox("Continuous spawner", &Engine::CellSimParams::createSpawner);

// --- If a spawner should be created reset cell amount selection value
if(Engine::CellSimParams::createSpawner)
{
Engine::CellSimParams::selectedCellAmount = 0;
}
// --- Else allow manual cell amount selection for single spawns
else
{
ImGui::Text("Amount:\t");
ImGui::SameLine();
RadioButton_u32("1", &Engine::CellSimParams::selectedCellAmount, 1);
ImGui::SameLine();
ImGui::Text("\t");
ImGui::SameLine();
RadioButton_u32("9", &Engine::CellSimParams::selectedCellAmount, 9);
ImGui::SameLine();
ImGui::Text("\t");
ImGui::SameLine();
RadioButton_u32("25", &Engine::CellSimParams::selectedCellAmount, 25);
ImGui::SameLine();
ImGui::Text("\t");
ImGui::SameLine();
RadioButton_u32("49", &Engine::CellSimParams::selectedCellAmount, 49);
}

// --- Spawn button
ImGui::Text("\t\t\t\t\t");
ImGui::SameLine();
if(ImGui::Button("Spawn"))
{
Engine::CellSimParams::spawnNewCell = true;
}
ImGui::SameLine();

ImGui::EndTabItem();
}

ImGui::PopStyleVar();
// --- Debug menu
if(ImGui::BeginTabItem("Debug"))
{
// --- Print debug information
ImGui::Text("\t\t");
ImGui::SameLine();
if(ImGui::Button("Print cell debug information"))
{
Engine::CellSimParams::printDebug = true;
}
ImGui::Separator();

ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}
}
ImGui::End();
Expand Down Expand Up @@ -245,12 +251,16 @@ namespace CS
// --- Menu bar
AddMenuBar();

// --- Add more space between all items
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 10));

// --- Overlay/Sidebar
if(_showOverlay)
{
AddSideBar();
}

ImGui::PopStyleVar();
ImGui::PopStyleVar();
}
}
Loading

0 comments on commit a7b8ed9

Please sign in to comment.