Split out UpdateFrequency
This commit is contained in:
@@ -10,89 +10,82 @@
|
||||
#include "Base/ICloseable.hpp"
|
||||
#include "Math/Math.hpp"
|
||||
#include "Drawable.hpp"
|
||||
#include "UpdateFrequency.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace openVulkanoCpp
|
||||
namespace openVulkanoCpp::Scene
|
||||
{
|
||||
namespace Scene
|
||||
class Scene;
|
||||
|
||||
class Node : public virtual IInitable, public virtual ICloseable
|
||||
{
|
||||
class Scene;
|
||||
friend Scene;
|
||||
|
||||
enum class UpdateFrequency
|
||||
public:
|
||||
Math::Matrix4f localMat, worldMat;
|
||||
bool enabled = true;
|
||||
Node* parent = nullptr;
|
||||
Scene* scene = nullptr;
|
||||
std::vector<Node*> children;
|
||||
std::vector<Drawable*> drawables;
|
||||
UpdateFrequency matrixUpdateFrequency = UpdateFrequency::Never;
|
||||
ICloseable* renderNode = nullptr;
|
||||
|
||||
public:
|
||||
Node();
|
||||
|
||||
~Node() override;
|
||||
|
||||
void Init() override;
|
||||
|
||||
void Close() override;
|
||||
|
||||
void AddChild(Node* node);
|
||||
|
||||
inline void AddChild(Drawable* drawable) { AddDrawable(drawable); }
|
||||
|
||||
void RemoveChild(Node* node);
|
||||
|
||||
inline void RemoveChild(Drawable* drawable) { RemoveDrawable(drawable); }
|
||||
|
||||
void AddDrawable(Drawable* drawable);
|
||||
|
||||
void RemoveDrawable(Drawable* drawable);
|
||||
|
||||
void SetMatrix(const Math::Matrix4f& mat);
|
||||
|
||||
[[nodiscard]] Math::Matrix3f GetRotationMatrix() const { return static_cast<const Math::Matrix3f>(localMat); }
|
||||
|
||||
[[nodiscard]] const Math::Matrix4f& GetMatrix() const { return localMat; }
|
||||
|
||||
[[nodiscard]] const Math::Matrix4f& GetWorldMatrix() const { return worldMat; }
|
||||
|
||||
[[nodiscard]] bool IsEnabled() const { return enabled; }
|
||||
|
||||
void Enable() { enabled = true; }
|
||||
|
||||
void Disable() { enabled = false; }
|
||||
|
||||
[[nodiscard]] Node* GetParent() const { return parent; }
|
||||
|
||||
[[nodiscard]] Scene* GetScene() const { return scene; }
|
||||
|
||||
[[nodiscard]] bool IsRoot() const { return scene && parent == this; }
|
||||
|
||||
[[nodiscard]] UpdateFrequency GetUpdateFrequency() const { return matrixUpdateFrequency; }
|
||||
|
||||
void SetUpdateFrequency(UpdateFrequency frequency)
|
||||
{
|
||||
Always, Sometimes, Never
|
||||
};
|
||||
|
||||
class Node : public virtual IInitable, public virtual ICloseable
|
||||
{
|
||||
friend Scene;
|
||||
if (!children.empty()) throw std::runtime_error("The update must not be changed for nodes with children.");
|
||||
this->matrixUpdateFrequency = frequency;
|
||||
}
|
||||
|
||||
public:
|
||||
Math::Matrix4f localMat, worldMat;
|
||||
bool enabled = true;
|
||||
Node* parent = nullptr;
|
||||
Scene* scene = nullptr;
|
||||
std::vector<Node*> children;
|
||||
std::vector<Drawable*> drawables;
|
||||
UpdateFrequency matrixUpdateFrequency = UpdateFrequency::Never;
|
||||
ICloseable* renderNode = nullptr;
|
||||
protected:
|
||||
virtual void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat);
|
||||
|
||||
public:
|
||||
Node();
|
||||
private:
|
||||
void SetParent(Node* parent);
|
||||
|
||||
~Node() override;
|
||||
|
||||
void Init() override;
|
||||
|
||||
void Close() override;
|
||||
|
||||
void AddChild(Node* node);
|
||||
|
||||
inline void AddChild(Drawable* drawable) { AddDrawable(drawable); }
|
||||
|
||||
void RemoveChild(Node* node);
|
||||
|
||||
inline void RemoveChild(Drawable* drawable) { RemoveDrawable(drawable); }
|
||||
|
||||
void AddDrawable(Drawable* drawable);
|
||||
|
||||
void RemoveDrawable(Drawable* drawable);
|
||||
|
||||
void SetMatrix(const Math::Matrix4f& mat);
|
||||
|
||||
[[nodiscard]] Math::Matrix3f GetRotationMatrix() const { return static_cast<const Math::Matrix3f>(localMat); }
|
||||
|
||||
[[nodiscard]] const Math::Matrix4f& GetMatrix() const { return localMat; }
|
||||
|
||||
[[nodiscard]] const Math::Matrix4f& GetWorldMatrix() const { return worldMat; }
|
||||
|
||||
[[nodiscard]] bool IsEnabled() const { return enabled; }
|
||||
|
||||
void Enable() { enabled = true; }
|
||||
|
||||
void Disable() { enabled = false; }
|
||||
|
||||
[[nodiscard]] Node* GetParent() const { return parent; }
|
||||
|
||||
[[nodiscard]] Scene* GetScene() const { return scene; }
|
||||
|
||||
[[nodiscard]] bool IsRoot() const { return scene && parent == this; }
|
||||
|
||||
[[nodiscard]] UpdateFrequency GetUpdateFrequency() const { return matrixUpdateFrequency; }
|
||||
|
||||
void SetUpdateFrequency(UpdateFrequency frequency)
|
||||
{
|
||||
if (!children.empty()) throw std::runtime_error("The update must not be changed for nodes with children.");
|
||||
this->matrixUpdateFrequency = frequency;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat);
|
||||
|
||||
private:
|
||||
void SetParent(Node* parent);
|
||||
|
||||
void SetScene(Scene* scene);
|
||||
};
|
||||
}
|
||||
void SetScene(Scene* scene);
|
||||
};
|
||||
}
|
||||
|
||||
15
openVulkanoCpp/Scene/UpdateFrequency.hpp
Normal file
15
openVulkanoCpp/Scene/UpdateFrequency.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace openVulkanoCpp::Scene
|
||||
{
|
||||
enum class UpdateFrequency : uint8_t
|
||||
{
|
||||
Always, Sometimes, Never
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user