Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant code in components by using inheritence instead of adding an abstraction layer #284

Open
adriengivry opened this issue Dec 7, 2023 · 0 comments
Labels
Feature New feature to the engine Refactoring Something that needs a refactoring

Comments

@adriengivry
Copy link
Owner

adriengivry commented Dec 7, 2023

Problem this feature should fix
Components usually holds entities (i.e. CCamera holds an instance of Camera, CTransform holds an instance of FTransform, CAudioSource holds an instance of AudioSource, etc...). This adds a lot of redundant code like:

// [...]

void OvCore::ECS::Components::CTransform::SetParent(CTransform& p_parent)
{
    m_transform.SetParent(p_parent.GetFTransform());
}

bool OvCore::ECS::Components::CTransform::RemoveParent()
{
    return m_transform.RemoveParent();
}

bool OvCore::ECS::Components::CTransform::HasParent() const
{
    return m_transform.HasParent();
}

void OvCore::ECS::Components::CTransform::SetLocalPosition(OvMaths::FVector3 p_newPosition)
{
    m_transform.SetLocalPosition(p_newPosition);
}

void OvCore::ECS::Components::CTransform::SetLocalRotation(OvMaths::FQuaternion p_newRotation)
{
    m_transform.SetLocalRotation(p_newRotation);
}

// [...]

Expected solution
We could get rid of all these indirections by directly inheriting components from their respective entities:
CTransform

class CTransform : public AComponent {}
// would become
class CTransform : public AComponent, public OvMaths::FTransform {}

CCamera

class CCamera : public AComponent {}
// would become
class CCamera : public AComponent, public OvRendering::Entities::Camera {}

And so on for other components...

This would completely remove the need to handle internally/externally managed transforms in entities, and would greatly simplify the base entities too.

Instead of needing to have OvRendering::Entities::Entity defined this way:

struct Entity
{
    OvTools::Utils::ReferenceOrValue<OvMaths::FTransform> transform;
};

We could have it defined this way instead:

struct Entity
{
    OvMaths::FTransform transform;
}

Same for AudioSource in OvAudio:

OvMaths::FTransform* const m_transform;
const bool m_internalTransform;
// would become
OvMaths::FTransform transform;
@adriengivry adriengivry added Feature New feature to the engine Refactoring Something that needs a refactoring labels Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature to the engine Refactoring Something that needs a refactoring
Projects
None yet
Development

No branches or pull requests

1 participant