Skip to content

Commit

Permalink
Added groups
Browse files Browse the repository at this point in the history
  • Loading branch information
denis authored and denis committed Nov 10, 2024
1 parent 6bdeb55 commit 6d405fc
Show file tree
Hide file tree
Showing 34 changed files with 338 additions and 183 deletions.
61 changes: 53 additions & 8 deletions Engine/include/GlobalData/GlobalData.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,57 @@ namespace Prisma::LightType

namespace Prisma
{
extern std::shared_ptr<Scene> currentGlobalScene;
extern std::shared_ptr<FBO> fboTarget;
extern std::unordered_map<uint64_t, Component*> sceneComponents;
extern std::unordered_map<uint64_t, std::shared_ptr<Node>> sceneNodes;
extern glm::mat4 currentProjection;
extern Texture defaultBlack;
extern Texture defaultWhite;
extern Texture defaultNormal;
class GlobalData : public InstanceData<GlobalData>
{
public:
// Getter and Setter for m_currentGlobalScene
std::shared_ptr<Scene> currentGlobalScene() const;

void currentGlobalScene(const std::shared_ptr<Scene>& currentGlobalScene);

// Getter and Setter for m_fboTarget
std::shared_ptr<FBO> fboTarget() const;

void fboTarget(const std::shared_ptr<FBO>& fboTarget);

// Getter and Setter for m_sceneComponents
std::unordered_map<uint64_t, Component*>& sceneComponents();

void sceneComponents(const std::unordered_map<uint64_t, Component*>& sceneComponents);

// Getter and Setter for m_sceneNodes
std::unordered_map<uint64_t, std::shared_ptr<Node>>& sceneNodes();

void sceneNodes(const std::unordered_map<uint64_t, std::shared_ptr<Node>>& sceneNodes);

// Getter and Setter for m_currentProjection
glm::mat4 currentProjection();

void currentProjection(const glm::mat4& currentProjection);

// Getter and Setter for m_defaultBlack
Texture& defaultBlack();

void defaultBlack(const Texture& defaultBlack);

// Getter and Setter for m_defaultWhite
Texture& defaultWhite();

void defaultWhite(const Texture& defaultWhite);

// Getter and Setter for m_defaultNormal
Texture& defaultNormal();

void defaultNormal(const Texture& defaultNormal);

private:
std::shared_ptr<Scene> m_currentGlobalScene;
std::shared_ptr<FBO> m_fboTarget;
std::unordered_map<uint64_t, Component*> m_sceneComponents;
std::unordered_map<uint64_t, std::shared_ptr<Node>> m_sceneNodes;
glm::mat4 m_currentProjection;
Texture m_defaultBlack;
Texture m_defaultWhite;
Texture m_defaultNormal;
};
}
22 changes: 14 additions & 8 deletions Engine/include/Physics/PhysicsData.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ namespace Prisma
void OnContactAdded(const Body& inBody1, const Body& inBody2, const ContactManifold& inManifold,
ContactSettings& ioSettings) override
{
auto physicsComponent = dynamic_cast<PhysicsMeshComponent*>(sceneComponents[inBody1.GetUserData()]);
auto physicsComponent = dynamic_cast<PhysicsMeshComponent*>(Prisma::GlobalData::getInstance().
sceneComponents()[inBody1.GetUserData()]);
if (physicsComponent && physicsComponent->onCollisionEnter())
{
auto addComponent = physicsComponent->onCollisionEnter();
addComponent(inBody2);
}
auto physicsComponent2 = dynamic_cast<PhysicsMeshComponent*>(sceneComponents[inBody2.GetUserData()]);
auto physicsComponent2 = dynamic_cast<PhysicsMeshComponent*>(Prisma::GlobalData::getInstance().
sceneComponents()[inBody2.GetUserData()]);
if (physicsComponent2 && physicsComponent2->onCollisionEnter())
{
auto addComponent = physicsComponent2->onCollisionEnter();
Expand All @@ -161,13 +163,15 @@ namespace Prisma
void OnContactPersisted(const Body& inBody1, const Body& inBody2, const ContactManifold& inManifold,
ContactSettings& ioSettings) override
{
auto physicsComponent = dynamic_cast<PhysicsMeshComponent*>(sceneComponents[inBody1.GetUserData()]);
auto physicsComponent = dynamic_cast<PhysicsMeshComponent*>(Prisma::GlobalData::getInstance().
sceneComponents()[inBody1.GetUserData()]);
if (physicsComponent && physicsComponent->onCollisionStay())
{
auto stayComponent = physicsComponent->onCollisionStay();
stayComponent(inBody2);
}
auto physicsComponent2 = dynamic_cast<PhysicsMeshComponent*>(sceneComponents[inBody2.GetUserData()]);
auto physicsComponent2 = dynamic_cast<PhysicsMeshComponent*>(Prisma::GlobalData::getInstance().
sceneComponents()[inBody2.GetUserData()]);
if (physicsComponent2 && physicsComponent2->onCollisionStay())
{
auto stayComponent = physicsComponent2->onCollisionStay();
Expand All @@ -177,16 +181,18 @@ namespace Prisma

void OnContactRemoved(const SubShapeIDPair& inSubShapePair) override
{
auto physicsComponent = dynamic_cast<PhysicsMeshComponent*>(sceneComponents[Physics::getInstance().
physicsSystem().GetBodyInterfaceNoLock().GetUserData(inSubShapePair.GetBody1ID())]);
auto physicsComponent = dynamic_cast<PhysicsMeshComponent*>(Prisma::GlobalData::getInstance().
sceneComponents()[Physics::getInstance().
physicsSystem().GetBodyInterfaceNoLock().GetUserData(inSubShapePair.GetBody1ID())]);
if (physicsComponent && physicsComponent->onCollisionExit())
{
auto removeComponent = physicsComponent->onCollisionExit();
removeComponent(inSubShapePair.GetBody2ID());
}

auto physicsComponent2 = dynamic_cast<PhysicsMeshComponent*>(sceneComponents[Physics::getInstance().
physicsSystem().GetBodyInterfaceNoLock().GetUserData(inSubShapePair.GetBody2ID())]);
auto physicsComponent2 = dynamic_cast<PhysicsMeshComponent*>(Prisma::GlobalData::getInstance().
sceneComponents()[Physics::getInstance().
physicsSystem().GetBodyInterfaceNoLock().GetUserData(inSubShapePair.GetBody2ID())]);
if (physicsComponent2 && physicsComponent2->onCollisionExit())
{
auto removeComponent2 = physicsComponent2->onCollisionExit();
Expand Down
20 changes: 10 additions & 10 deletions Engine/include/SceneData/SceneExporterLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultBlack);
textures.push_back(Prisma::GlobalData::getInstance().defaultBlack());
}
else
{
Expand All @@ -362,7 +362,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultNormal);
textures.push_back(Prisma::GlobalData::getInstance().defaultNormal());
}
else
{
Expand All @@ -378,7 +378,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultBlack);
textures.push_back(Prisma::GlobalData::getInstance().defaultBlack());
}
else
{
Expand All @@ -394,7 +394,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultWhite);
textures.push_back(Prisma::GlobalData::getInstance().defaultWhite());
}
else
{
Expand All @@ -410,7 +410,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultWhite);
textures.push_back(Prisma::GlobalData::getInstance().defaultWhite());
}
else
{
Expand Down Expand Up @@ -502,7 +502,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultBlack);
textures.push_back(Prisma::GlobalData::getInstance().defaultBlack());
}
else
{
Expand All @@ -518,7 +518,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultNormal);
textures.push_back(Prisma::GlobalData::getInstance().defaultNormal());
}
else
{
Expand All @@ -534,7 +534,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultBlack);
textures.push_back(Prisma::GlobalData::getInstance().defaultBlack());
}
else
{
Expand All @@ -550,7 +550,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultBlack);
textures.push_back(Prisma::GlobalData::getInstance().defaultBlack());
}
else
{
Expand All @@ -566,7 +566,7 @@ namespace Prisma
Texture texture;
if (t.second == "NO_TEXTURE")
{
textures.push_back(defaultBlack);
textures.push_back(Prisma::GlobalData::getInstance().defaultBlack());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Engine/include/SceneObjects/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace Prisma
parent->addChild(newInstance);
parent->parent(light->parent()->parent());
newInstance->parent(parent);
currentGlobalScene->root->addChild(parent);
Prisma::GlobalData::getInstance().currentGlobalScene()->root->addChild(parent);
}
}

Expand Down
14 changes: 9 additions & 5 deletions Engine/src/Components/CloudComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,12 @@ void Prisma::CloudComponent::generateWeather()

void Prisma::CloudComponent::setVariables()
{
m_cloudShader->setVec3(m_camPos, currentGlobalScene->camera->position());
if (currentGlobalScene->dirLights.size() > 0)
m_cloudShader->setVec3(m_camPos, Prisma::GlobalData::getInstance().currentGlobalScene()->camera->position());
if (Prisma::GlobalData::getInstance().currentGlobalScene()->dirLights.size() > 0)
{
m_cloudShader->setVec3(m_lightPos, normalize(
currentGlobalScene->dirLights[0]->parent()->finalMatrix() * currentGlobalScene->
Prisma::GlobalData::getInstance().currentGlobalScene()->dirLights[0]->parent()->
finalMatrix() * Prisma::GlobalData::getInstance().currentGlobalScene()->
dirLights[0]->type().direction));
}
// Calculate elapsed time since the first render call
Expand All @@ -322,6 +323,9 @@ void Prisma::CloudComponent::setVariables()
m_cloudShader->setInt64(m_worlPos, m_worley);

// Setting the uniforms
m_cloudShader->setMat4(m_invViewPos, glm::inverse(currentGlobalScene->camera->matrix())); // Inverse View matrix
m_cloudShader->setMat4(m_invProjPos, glm::inverse(currentProjection)); // Inverse Projection matrix
m_cloudShader->setMat4(m_invViewPos,
glm::inverse(Prisma::GlobalData::getInstance().currentGlobalScene()->camera->matrix()));
// Inverse View matrix
m_cloudShader->setMat4(m_invProjPos, glm::inverse(Prisma::GlobalData::getInstance().currentProjection()));
// Inverse Projection matrix
}
4 changes: 2 additions & 2 deletions Engine/src/Components/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void Prisma::Component::onParent(Node* parent)
void Prisma::Component::destroy()
{
m_parent = nullptr;
sceneComponents.erase(m_uuid);
Prisma::GlobalData::getInstance().sceneComponents().erase(m_uuid);
}

void Prisma::Component::parent(Node* parent)
Expand Down Expand Up @@ -94,7 +94,7 @@ Prisma::Component::Component()
name("BaseComponent");
m_uuid = uuidComponent;
uuidComponent = uuidComponent + 1;
sceneComponents[m_uuid] = this;
Prisma::GlobalData::getInstance().sceneComponents()[m_uuid] = this;
}


Expand Down
2 changes: 1 addition & 1 deletion Engine/src/Components/CullingComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ void Prisma::CullingComponent::start()
Component::start();
m_shader = std::make_shared<Shader>("../../../Engine/Shaders/CullingPipeline/compute.glsl");
m_ssbo = std::make_shared<SSBO>(17);
m_ssbo->resize(sizeof(glm::mat4) * currentGlobalScene->meshes.size());
m_ssbo->resize(sizeof(glm::mat4) * Prisma::GlobalData::getInstance().currentGlobalScene()->meshes.size());
}
85 changes: 76 additions & 9 deletions Engine/src/GlobalData/GlobalData.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,81 @@
#include "../../include/GlobalData/GlobalData.h"

std::shared_ptr<Prisma::Scene> Prisma::GlobalData::currentGlobalScene() const
{
return m_currentGlobalScene;
}

void Prisma::GlobalData::currentGlobalScene(const std::shared_ptr<Scene>& currentGlobalScene)
{
m_currentGlobalScene = currentGlobalScene;
}

std::shared_ptr<Prisma::FBO> Prisma::GlobalData::fboTarget() const
{
return m_fboTarget;
}

void Prisma::GlobalData::fboTarget(const std::shared_ptr<FBO>& fboTarget)
{
m_fboTarget = fboTarget;
}

std::unordered_map<uint64_t, Prisma::Component*>& Prisma::GlobalData::sceneComponents()
{
return m_sceneComponents;
}

void Prisma::GlobalData::sceneComponents(const std::unordered_map<uint64_t, Component*>& sceneComponents)
{
m_sceneComponents = sceneComponents;
}

std::unordered_map<uint64_t, std::shared_ptr<Prisma::Node>>& Prisma::GlobalData::sceneNodes()
{
return m_sceneNodes;
}

void Prisma::GlobalData::sceneNodes(const std::unordered_map<uint64_t, std::shared_ptr<Node>>& sceneNodes)
{
m_sceneNodes = sceneNodes;
}

glm::mat4 Prisma::GlobalData::currentProjection()
{
return m_currentProjection;
}

void Prisma::GlobalData::currentProjection(const glm::mat4& currentProjection)
{
m_currentProjection = currentProjection;
}

Prisma::Texture& Prisma::GlobalData::defaultBlack()
{
return m_defaultBlack;
}

void Prisma::GlobalData::defaultBlack(const Texture& defaultBlack)
{
m_defaultBlack = defaultBlack;
}

Prisma::Texture& Prisma::GlobalData::defaultWhite()
{
return m_defaultWhite;
}

void Prisma::GlobalData::defaultWhite(const Texture& defaultWhite)
{
m_defaultWhite = defaultWhite;
}

Prisma::Texture& Prisma::GlobalData::defaultNormal()
{
return m_defaultNormal;
}

namespace Prisma
void Prisma::GlobalData::defaultNormal(const Texture& defaultNormal)
{
std::shared_ptr<Scene> currentGlobalScene = nullptr;
glm::mat4 currentProjection = glm::mat4(1.0f);
std::unordered_map<uint64_t, std::shared_ptr<Node>> sceneNodes;
Texture defaultBlack;
Texture defaultWhite;
Texture defaultNormal;
std::shared_ptr<FBO> fboTarget = nullptr;
std::unordered_map<uint64_t, Component*> sceneComponents;
m_defaultNormal = defaultNormal;
}
6 changes: 3 additions & 3 deletions Engine/src/GlobalData/PrismaFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ Prisma::PrismaFunc::PrismaFunc()

privatePrisma = std::make_shared<PrivatePrisma>();

defaultBlack.loadTexture({DIR_DEFAULT_BLACK});
defaultWhite.loadTexture({DIR_DEFAULT_WHITE});
defaultNormal.loadTexture({DIR_DEFAULT_NORMAL});
Prisma::GlobalData::getInstance().defaultBlack().loadTexture({DIR_DEFAULT_BLACK});
Prisma::GlobalData::getInstance().defaultWhite().loadTexture({DIR_DEFAULT_WHITE});
Prisma::GlobalData::getInstance().defaultNormal().loadTexture({DIR_DEFAULT_NORMAL});
}

void Prisma::PrismaFunc::swapBuffers()
Expand Down
2 changes: 1 addition & 1 deletion Engine/src/Handlers/AnimationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

void Prisma::AnimationHandler::fill()
{
for (auto mesh : currentGlobalScene->animateMeshes)
for (auto mesh : Prisma::GlobalData::getInstance().currentGlobalScene()->animateMeshes)
{
if (mesh->animator())
{
Expand Down
Loading

0 comments on commit 6d405fc

Please sign in to comment.