Skip to content

Commit

Permalink
Added component registrar guis
Browse files Browse the repository at this point in the history
  • Loading branch information
denis authored and denis committed Nov 10, 2024
1 parent c3e3e4c commit 003f76e
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 66 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.8.0)
project(Prisma-client VERSION 0.1.0)
add_subdirectory(engine)
set(CMAKE_CXX_STANDARD 17)
add_executable(Prisma-client "main.cpp" "UserEngine/include/UserEngine.h" "UserEngine/src/UserEngine.cpp" "GUI/include/ImGuiStyle.h" "GUI/include/Postprocess/Effects.h" "GUI/src/Postprocess/Effects.cpp" "GUI/include/LightInfo.h" "GUI/src/LightInfo.cpp" "GUI/include/TextureInfo.h" "GUI/src/TextureInfo.cpp" "GUI/include/PixelCapture.h" "GUI/src/PixelCapture.cpp" "UserEngine/include/PlayerController.h" "UserEngine/src/PlayerController.cpp" "GUI/include/SettingsTab.h" "GUI/src/SettingsTab.cpp" "GUI/include/PlotFPS.h" "GUI/src/PlotFPS.cpp" "UserEngine/include/ParticleController.h" "UserEngine/src/ParticleController.cpp" "GUI/include/NodeViewer.h" "GUI/src/NodeViewer.cpp" "UserEngine/Components/include/GrassRenderer.h" "UserEngine/Components/src/GrassRenderer.cpp" "GUI/include/MeshCreator.h" "GUI/src/MeshCreator.cpp" "GUI/include/AddingMenu.h" "GUI/src/AddingMenu.cpp")
add_executable(Prisma-client "main.cpp" "UserEngine/include/UserEngine.h" "UserEngine/src/UserEngine.cpp" "GUI/include/ImGuiStyle.h" "GUI/include/Postprocess/Effects.h" "GUI/src/Postprocess/Effects.cpp" "GUI/include/LightInfo.h" "GUI/src/LightInfo.cpp" "GUI/include/TextureInfo.h" "GUI/src/TextureInfo.cpp" "GUI/include/PixelCapture.h" "GUI/src/PixelCapture.cpp" "UserEngine/include/PlayerController.h" "UserEngine/src/PlayerController.cpp" "GUI/include/SettingsTab.h" "GUI/src/SettingsTab.cpp" "GUI/include/PlotFPS.h" "GUI/src/PlotFPS.cpp" "UserEngine/include/ParticleController.h" "UserEngine/src/ParticleController.cpp" "GUI/include/NodeViewer.h" "GUI/src/NodeViewer.cpp" "UserEngine/Components/include/GrassRenderer.h" "UserEngine/Components/src/GrassRenderer.cpp" "GUI/include/MeshCreator.h" "GUI/src/MeshCreator.cpp" "GUI/include/AddingMenu.h" "GUI/src/AddingMenu.cpp" "GUI/include/RegisterComponent.h" "GUI/include/RegisterCreator.h" "GUI/src/RegisterCreator.cpp")
find_package(glm CONFIG REQUIRED)

target_link_libraries(Prisma-client PRIVATE PrismaEngineDll glm::glm)
1 change: 1 addition & 0 deletions Engine/include/Components/CloudComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ namespace Prisma

void setVariables();

private:
const int m_downscale = 4;

std::function<void()> m_startButton;
Expand Down
2 changes: 2 additions & 0 deletions Engine/include/Components/PhysicsMeshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace Prisma
void colliderDispatcher();
BodyCreationSettings getBodySettings();
void addSoftBody();

private:
std::shared_ptr<BodyID> m_physicsId = nullptr;
Body* m_physicsSoftId = nullptr;

Expand Down
2 changes: 2 additions & 0 deletions Engine/src/Components/CloudComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ Prisma::CloudComponent::CloudComponent() : Component{}
name("Cloud");
}


void Prisma::CloudComponent::ui()
{
Prisma::Component::ui();
std::vector<ComponentType> components;

components.push_back(std::make_tuple(TYPES::FLOAT, "CoverageScale", &m_cloudSSBO.coverageScale));
Expand Down
2 changes: 2 additions & 0 deletions Engine/src/Components/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ uint64_t Prisma::Component::uuid()

Prisma::Component::Component()
{
name("BaseComponent");
m_uuid = uuidComponent;
uuidComponent = uuidComponent + 1;
sceneComponents[m_uuid] = this;
}


Prisma::Component::~Component()
{
//destroy();
Expand Down
2 changes: 2 additions & 0 deletions Engine/src/Components/CullingComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

Prisma::CullingComponent::CullingComponent()
{
name("Culling");
}

void Prisma::CullingComponent::ui()
{
Prisma::Component::ui();
}

void Prisma::CullingComponent::update()
Expand Down
52 changes: 34 additions & 18 deletions Engine/src/Components/MaterialComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,45 @@ const std::vector<Prisma::Texture>& Prisma::MaterialComponent::diffuse() const

void Prisma::MaterialComponent::ui()
{
Prisma::Component::ui();

auto getLast = [](std::string s)
{
size_t found = s.find_last_of('/');
return found != std::string::npos ? s.substr(found + 1) : s;
};
m_diffuseName = std::make_shared<std::string>(getLast(m_diffuse[0].name()));
m_normalName = std::make_shared<std::string>(getLast(m_normal[0].name()));
m_metalness_roughnessName = std::make_shared<std::string>(getLast(m_roughness_metalness[0].name()));
m_specularName = std::make_shared<std::string>(getLast(m_specular[0].name()));
m_ambientOcclusionName = std::make_shared<std::string>(getLast(m_ambientOcclusion[0].name()));

m_componentTypeDiffuse = std::make_tuple(TYPES::STRING, "Diffuse", m_diffuseName.get());
m_componentTypeNormal = std::make_tuple(TYPES::STRING, "Normal", m_normalName.get());
m_componentTypeMetalnessRoughness = std::make_tuple(TYPES::STRING, "Metalness-Roughness",
m_metalness_roughnessName.get());
m_componentTypeSpecular = std::make_tuple(TYPES::STRING, "Specular", m_specularName.get());
m_componentTypeAmbientOcclusion = std::make_tuple(TYPES::STRING, "Diffuse", m_ambientOcclusionName.get());

addGlobal(m_componentTypeDiffuse);
addGlobal(m_componentTypeNormal);
addGlobal(m_componentTypeMetalnessRoughness);
addGlobal(m_componentTypeSpecular);
addGlobal(m_componentTypeAmbientOcclusion);
if (m_diffuse.size() > 0)
{
m_diffuseName = std::make_shared<std::string>(getLast(m_diffuse[0].name()));
m_componentTypeDiffuse = std::make_tuple(TYPES::STRING, "Diffuse", m_diffuseName.get());
addGlobal(m_componentTypeDiffuse);
}
if (m_normal.size() > 0)
{
m_normalName = std::make_shared<std::string>(getLast(m_normal[0].name()));
m_componentTypeNormal = std::make_tuple(TYPES::STRING, "Normal", m_normalName.get());
addGlobal(m_componentTypeNormal);
}
if (m_roughness_metalness.size() > 0)
{
m_metalness_roughnessName = std::make_shared<std::string>(getLast(m_roughness_metalness[0].name()));
m_componentTypeMetalnessRoughness = std::make_tuple(TYPES::STRING, "Metalness-Roughness",
m_metalness_roughnessName.get());
addGlobal(m_componentTypeMetalnessRoughness);
}
if (m_specular.size() > 0)
{
m_specularName = std::make_shared<std::string>(getLast(m_specular[0].name()));
m_componentTypeSpecular = std::make_tuple(TYPES::STRING, "Specular", m_specularName.get());
addGlobal(m_componentTypeSpecular);
}
if (m_ambientOcclusion.size() > 0)
{
m_ambientOcclusionName = std::make_shared<std::string>(getLast(m_ambientOcclusion[0].name()));
m_componentTypeAmbientOcclusion = std::make_tuple(TYPES::STRING, "Diffuse", m_ambientOcclusionName.get());
addGlobal(m_componentTypeAmbientOcclusion);
}


m_id = materialId;
materialId++;
Expand Down
2 changes: 2 additions & 0 deletions Engine/src/Components/PhysicsMeshComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

void Prisma::PhysicsMeshComponent::ui()
{
Prisma::Component::ui();

ComponentType componentType;
m_status.currentitem = static_cast<int>(m_collisionData.collider);
m_status.items.push_back("BOX COLLIDER");
Expand Down
2 changes: 2 additions & 0 deletions GUI/include/ImGuiDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../../Engine/include/GlobalData/InstanceData.h"
#include "../../Engine/include/Helpers/TimeCounter.h"
#include "AddingMenu.h"
#include "RegisterCreator.h"


namespace Prisma
Expand Down Expand Up @@ -99,5 +100,6 @@ namespace Prisma
TimeCounter m_timeCounterEngine;

Prisma::ImGuiAddingMenu m_addingMenu;
Prisma::RegisterData m_registerData;
};
}
2 changes: 2 additions & 0 deletions GUI/include/NodeViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace Prisma
std::shared_ptr<Texture> m_scaleTexture;
std::shared_ptr<Texture> m_eyeOpen;
std::shared_ptr<Texture> m_eyeClose;
int m_componentSelect = 0;
std::vector<const char*> m_components;

ImGuizmo::OPERATION mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
ImGuizmo::MODE mCurrentGizmoMode = ImGuizmo::WORLD;
Expand Down
53 changes: 53 additions & 0 deletions GUI/include/RegisterComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once
#include <map>
#include <memory>
#include <functional>
#include <string>
#include "../../Engine/include/Components/Component.h"

namespace Prisma
{
class Factory
{
public:
using Creator = std::function<std::shared_ptr<Prisma::Component>()>;

// Method to register a class type with a name
static void registerClass(const std::string& className, Creator creator)
{
getRegistry()[className] = creator;
}

// Method to create an instance of a class by name
static std::shared_ptr<Prisma::Component> createInstance(const std::string& className)
{
auto it = getRegistry().find(className);
if (it != getRegistry().end())
{
return it->second();
}
return nullptr; // Return null if class name not found
}

// Registry storing class name to creator function mappings
static std::unordered_map<std::string, Creator>& getRegistry()
{
static std::unordered_map<std::string, Creator> registry;
return registry;
}
};

// Helper template to register classes
template <typename T>
class Registrar
{
public:
explicit Registrar(const std::string& className)
{
Factory::registerClass(className, []() -> std::shared_ptr<Prisma::Component>
{
return std::make_shared<T>();
});
}
};
}
14 changes: 14 additions & 0 deletions GUI/include/RegisterCreator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "RegisterComponent.h"
#include "../../Engine/include/Components/PhysicsMeshComponent.h"
#include "../../Engine/include/Components/CloudComponent.h"
#include "../../Engine/include/Components/CullingComponent.h"

namespace Prisma
{
class RegisterData
{
public:
void init();
};
}
1 change: 1 addition & 0 deletions GUI/src/ImguiDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Prisma::ImguiDebug::ImguiDebug() : m_lastFrameTime{glfwGetTime()}, m_fps{60.0f}
m_pauseButton->loadTexture({"../../../GUI/icons/pause.png", false, false, false});

NodeViewer::getInstance();
m_registerData.init();

initStatus();
}
Expand Down
Loading

0 comments on commit 003f76e

Please sign in to comment.