mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-11 14:43:34 +00:00
fixing UUID issue
This commit is contained in:
@@ -17,6 +17,7 @@ namespace Scop
|
|||||||
public:
|
public:
|
||||||
Actor();
|
Actor();
|
||||||
Actor(Model model);
|
Actor(Model model);
|
||||||
|
Actor(std::uint64_t uuid, Model model);
|
||||||
|
|
||||||
inline void AttachScript(std::shared_ptr<ActorScript> script) { p_script = script; }
|
inline void AttachScript(std::shared_ptr<ActorScript> script) { p_script = script; }
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ namespace Scop
|
|||||||
[[nodiscard]] inline const Quatf& GetOrientation() const noexcept { return m_orientation; }
|
[[nodiscard]] inline const Quatf& GetOrientation() const noexcept { return m_orientation; }
|
||||||
[[nodiscard]] inline const Model& GetModel() const noexcept { return m_model; }
|
[[nodiscard]] inline const Model& GetModel() const noexcept { return m_model; }
|
||||||
[[nodiscard]] inline Model& GetModelRef() noexcept { return m_model; }
|
[[nodiscard]] inline Model& GetModelRef() noexcept { return m_model; }
|
||||||
[[nodiscard]] inline std::uint32_t GetUUID() const noexcept { return m_uuid; }
|
[[nodiscard]] inline std::uint64_t GetUUID() const noexcept { return m_uuid; }
|
||||||
[[nodiscard]] inline bool IsVisible() const noexcept { return m_is_visible; }
|
[[nodiscard]] inline bool IsVisible() const noexcept { return m_is_visible; }
|
||||||
|
|
||||||
~Actor();
|
~Actor();
|
||||||
@@ -52,4 +53,16 @@ namespace Scop
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct hash<Scop::Actor>
|
||||||
|
{
|
||||||
|
std::size_t operator()(const Scop::Actor& a) const noexcept
|
||||||
|
{
|
||||||
|
return static_cast<std::size_t>(a.GetUUID());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ namespace Scop
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Narrator() : m_uuid(UUID()) {}
|
Narrator() : m_uuid(UUID()) {}
|
||||||
|
Narrator(std::uint64_t uuid) : m_uuid(uuid) {}
|
||||||
inline void AttachScript(std::shared_ptr<NarratorScript> script) { p_script = script; }
|
inline void AttachScript(std::shared_ptr<NarratorScript> script) { p_script = script; }
|
||||||
[[nodiscard]] inline std::uint32_t GetUUID() const noexcept { return m_uuid; }
|
[[nodiscard]] inline std::uint64_t GetUUID() const noexcept { return m_uuid; }
|
||||||
inline ~Narrator()
|
inline ~Narrator()
|
||||||
{
|
{
|
||||||
if(p_script)
|
if(p_script)
|
||||||
@@ -37,5 +38,16 @@ namespace Scop
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
namespace std
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct hash<Scop::Narrator>
|
||||||
|
{
|
||||||
|
std::size_t operator()(const Scop::Narrator& n) const noexcept
|
||||||
|
{
|
||||||
|
return static_cast<std::size_t>(n.GetUUID());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <Utils/NonOwningPtr.h>
|
#include <Utils/NonOwningPtr.h>
|
||||||
|
|
||||||
@@ -66,8 +67,8 @@ namespace Scop
|
|||||||
void SwitchToParent() const noexcept;
|
void SwitchToParent() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] inline ForwardData& GetForwardData() noexcept { return m_forward; }
|
[[nodiscard]] inline ForwardData& GetForwardData() noexcept { return m_forward; }
|
||||||
[[nodiscard]] inline const std::vector<Actor>& GetActors() const noexcept { return m_actors; }
|
[[nodiscard]] inline const std::map<std::uint64_t, Actor>& GetActors() const noexcept { return m_actors; }
|
||||||
[[nodiscard]] inline const std::vector<Sprite>& GetSprites() const noexcept { return m_sprites; }
|
[[nodiscard]] inline const std::map<std::uint64_t, Sprite>& GetSprites() const noexcept { return m_sprites; }
|
||||||
[[nodiscard]] inline const std::string& GetName() const noexcept { return m_name; }
|
[[nodiscard]] inline const std::string& GetName() const noexcept { return m_name; }
|
||||||
[[nodiscard]] inline GraphicPipeline& GetPipeline() noexcept { return m_pipeline; }
|
[[nodiscard]] inline GraphicPipeline& GetPipeline() noexcept { return m_pipeline; }
|
||||||
[[nodiscard]] inline std::shared_ptr<BaseCamera> GetCamera() const { return m_descriptor.camera; }
|
[[nodiscard]] inline std::shared_ptr<BaseCamera> GetCamera() const { return m_descriptor.camera; }
|
||||||
@@ -90,9 +91,9 @@ namespace Scop
|
|||||||
DepthImage m_depth;
|
DepthImage m_depth;
|
||||||
SceneDescriptor m_descriptor;
|
SceneDescriptor m_descriptor;
|
||||||
std::shared_ptr<CubeTexture> p_skybox;
|
std::shared_ptr<CubeTexture> p_skybox;
|
||||||
std::vector<Actor> m_actors;
|
std::map<std::uint64_t, Actor> m_actors;
|
||||||
std::vector<Sprite> m_sprites;
|
std::map<std::uint64_t, Sprite> m_sprites;
|
||||||
std::vector<Narrator> m_narrators;
|
std::map<std::uint64_t, Narrator> m_narrators;
|
||||||
std::vector<Scene> m_scene_children;
|
std::vector<Scene> m_scene_children;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
NonOwningPtr<Scene> p_parent;
|
NonOwningPtr<Scene> p_parent;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace Scop
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Sprite(std::shared_ptr<Texture> texture);
|
Sprite(std::shared_ptr<Texture> texture);
|
||||||
|
Sprite(std::uint64_t uuid, std::shared_ptr<Texture> texture);
|
||||||
|
|
||||||
inline void AttachScript(std::shared_ptr<SpriteScript> script) { p_script = script; }
|
inline void AttachScript(std::shared_ptr<SpriteScript> script) { p_script = script; }
|
||||||
void Update(NonOwningPtr<class Scene> scene, class Inputs& input, float timestep);
|
void Update(NonOwningPtr<class Scene> scene, class Inputs& input, float timestep);
|
||||||
@@ -31,7 +32,7 @@ namespace Scop
|
|||||||
[[nodiscard]] inline const Vec2f& GetScale() const noexcept { return m_scale; }
|
[[nodiscard]] inline const Vec2f& GetScale() const noexcept { return m_scale; }
|
||||||
[[nodiscard]] inline std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
|
[[nodiscard]] inline std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
|
||||||
[[nodiscard]] inline std::shared_ptr<Texture> GetTexture() const { return p_texture; }
|
[[nodiscard]] inline std::shared_ptr<Texture> GetTexture() const { return p_texture; }
|
||||||
[[nodiscard]] inline std::uint32_t GetUUID() const noexcept { return m_uuid; }
|
[[nodiscard]] inline std::uint64_t GetUUID() const noexcept { return m_uuid; }
|
||||||
|
|
||||||
~Sprite();
|
~Sprite();
|
||||||
|
|
||||||
@@ -62,4 +63,16 @@ namespace Scop
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct hash<Scop::Sprite>
|
||||||
|
{
|
||||||
|
std::size_t operator()(const Scop::Sprite& s) const noexcept
|
||||||
|
{
|
||||||
|
return static_cast<std::size_t>(s.GetUUID());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ namespace Scop
|
|||||||
p_script->OnInit(this);
|
p_script->OnInit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Actor::Actor(std::uint64_t uuid, Model model) : m_model(std::move(model)), m_uuid(uuid)
|
||||||
|
{
|
||||||
|
if(p_script)
|
||||||
|
p_script->OnInit(this);
|
||||||
|
}
|
||||||
|
|
||||||
void Actor::Update(NonOwningPtr<Scene> scene, Inputs& input, float delta)
|
void Actor::Update(NonOwningPtr<Scene> scene, Inputs& input, float delta)
|
||||||
{
|
{
|
||||||
if(p_script)
|
if(p_script)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include "Graphics/Narrator.h"
|
|
||||||
#include <Graphics/Scene.h>
|
#include <Graphics/Scene.h>
|
||||||
#include <Renderer/Renderer.h>
|
#include <Renderer/Renderer.h>
|
||||||
#include <Renderer/RenderCore.h>
|
#include <Renderer/RenderCore.h>
|
||||||
@@ -24,37 +23,43 @@ namespace Scop
|
|||||||
|
|
||||||
Actor& Scene::CreateActor(Model model) noexcept
|
Actor& Scene::CreateActor(Model model) noexcept
|
||||||
{
|
{
|
||||||
return m_actors.emplace_back(std::move(model));
|
UUID uuid = UUID();
|
||||||
|
return m_actors.try_emplace(uuid, uuid, std::move(model)).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Actor& Scene::CreateActor(std::string_view name, Model model)
|
Actor& Scene::CreateActor(std::string_view name, Model model)
|
||||||
{
|
{
|
||||||
return m_actors.emplace_back(std::move(model));
|
UUID uuid = UUID();
|
||||||
|
return m_actors.try_emplace(uuid, uuid, std::move(model)).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Narrator& Scene::CreateNarrator() noexcept
|
Narrator& Scene::CreateNarrator() noexcept
|
||||||
{
|
{
|
||||||
return m_narrators.emplace_back();
|
UUID uuid = UUID();
|
||||||
|
return m_narrators.try_emplace(uuid, uuid).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Narrator& Scene::CreateNarrator(std::string_view name)
|
Narrator& Scene::CreateNarrator(std::string_view name)
|
||||||
{
|
{
|
||||||
return m_narrators.emplace_back();
|
UUID uuid = UUID();
|
||||||
|
return m_narrators.try_emplace(uuid, uuid).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite& Scene::CreateSprite(std::shared_ptr<Texture> texture) noexcept
|
Sprite& Scene::CreateSprite(std::shared_ptr<Texture> texture) noexcept
|
||||||
{
|
{
|
||||||
return m_sprites.emplace_back(texture);
|
UUID uuid = UUID();
|
||||||
|
return m_sprites.try_emplace(uuid, uuid, texture).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite& Scene::CreateSprite(std::string_view name, std::shared_ptr<Texture> texture)
|
Sprite& Scene::CreateSprite(std::string_view name, std::shared_ptr<Texture> texture)
|
||||||
{
|
{
|
||||||
return m_sprites.emplace_back(texture);
|
UUID uuid = UUID();
|
||||||
|
return m_sprites.try_emplace(uuid, uuid, texture).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::RemoveActor(Actor& actor) noexcept
|
void Scene::RemoveActor(Actor& actor) noexcept
|
||||||
{
|
{
|
||||||
auto it = std::find_if(m_actors.begin(), m_actors.end(), [&actor](const Actor& lhs) { return actor.GetUUID() == lhs.GetUUID(); });
|
auto it = m_actors.find(actor.GetUUID());
|
||||||
if(it == m_actors.end())
|
if(it == m_actors.end())
|
||||||
{
|
{
|
||||||
Error("Actor not found");
|
Error("Actor not found");
|
||||||
@@ -65,7 +70,7 @@ namespace Scop
|
|||||||
|
|
||||||
void Scene::RemoveNarrator(Narrator& narrator) noexcept
|
void Scene::RemoveNarrator(Narrator& narrator) noexcept
|
||||||
{
|
{
|
||||||
auto it = std::find_if(m_narrators.begin(), m_narrators.end(), [&narrator](const Narrator& lhs) { return narrator.GetUUID() == lhs.GetUUID(); });
|
auto it = m_narrators.find(narrator.GetUUID());
|
||||||
if(it == m_narrators.end())
|
if(it == m_narrators.end())
|
||||||
{
|
{
|
||||||
Error("Narrator not found");
|
Error("Narrator not found");
|
||||||
@@ -76,7 +81,7 @@ namespace Scop
|
|||||||
|
|
||||||
void Scene::RemoveSprite(Sprite& sprite) noexcept
|
void Scene::RemoveSprite(Sprite& sprite) noexcept
|
||||||
{
|
{
|
||||||
auto it = std::find_if(m_sprites.begin(), m_sprites.end(), [&sprite](const Sprite& lhs) { return sprite.GetUUID() == lhs.GetUUID(); });
|
auto it = m_sprites.find(sprite.GetUUID());
|
||||||
if(it == m_sprites.end())
|
if(it == m_sprites.end())
|
||||||
{
|
{
|
||||||
Error("Sprite not found");
|
Error("Sprite not found");
|
||||||
@@ -135,11 +140,11 @@ namespace Scop
|
|||||||
|
|
||||||
void Scene::Update(Inputs& input, float timestep, float aspect)
|
void Scene::Update(Inputs& input, float timestep, float aspect)
|
||||||
{
|
{
|
||||||
for(auto actor : m_actors)
|
for(auto& [_, actor] : m_actors)
|
||||||
actor.Update(this, input, timestep);
|
actor.Update(this, input, timestep);
|
||||||
for(auto narrator : m_narrators)
|
for(auto& [_, narrator] : m_narrators)
|
||||||
narrator.Update(this, input, timestep);
|
narrator.Update(this, input, timestep);
|
||||||
for(auto sprite : m_sprites)
|
for(auto& [_, sprite] : m_sprites)
|
||||||
sprite.Update(this, input, timestep);
|
sprite.Update(this, input, timestep);
|
||||||
if(m_descriptor.camera)
|
if(m_descriptor.camera)
|
||||||
m_descriptor.camera->Update(input, aspect, timestep);
|
m_descriptor.camera->Update(input, aspect, timestep);
|
||||||
|
|||||||
@@ -17,6 +17,16 @@ namespace Scop
|
|||||||
p_script->OnInit(this);
|
p_script->OnInit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sprite::Sprite(std::uint64_t uuid, std::shared_ptr<Texture> texture)
|
||||||
|
{
|
||||||
|
Verify((bool)texture, "Sprite: invalid texture");
|
||||||
|
m_uuid = uuid;
|
||||||
|
p_mesh = CreateQuad(0, 0, texture->GetWidth(), texture->GetHeight());
|
||||||
|
p_texture = texture;
|
||||||
|
if(p_script)
|
||||||
|
p_script->OnInit(this);
|
||||||
|
}
|
||||||
|
|
||||||
void Sprite::Update(NonOwningPtr<Scene> scene, Inputs& input, float delta)
|
void Sprite::Update(NonOwningPtr<Scene> scene, Inputs& input, float delta)
|
||||||
{
|
{
|
||||||
if(p_script)
|
if(p_script)
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace Scop
|
|||||||
|
|
||||||
VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
|
VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
|
||||||
m_pipeline.BindPipeline(cmd, 0, {});
|
m_pipeline.BindPipeline(cmd, 0, {});
|
||||||
for(const auto& sprite : scene.GetSprites())
|
for(const auto& [_, sprite] : scene.GetSprites())
|
||||||
{
|
{
|
||||||
SpriteData sprite_data;
|
SpriteData sprite_data;
|
||||||
sprite_data.position = Vec2f{ static_cast<float>(sprite.GetPosition().x), static_cast<float>(sprite.GetPosition().y) };
|
sprite_data.position = Vec2f{ static_cast<float>(sprite.GetPosition().x), static_cast<float>(sprite.GetPosition().y) };
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Scop
|
|||||||
|
|
||||||
VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
|
VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
|
||||||
pipeline.BindPipeline(cmd, 0, {});
|
pipeline.BindPipeline(cmd, 0, {});
|
||||||
for(const auto& actor : scene.GetActors())
|
for(const auto& [_, actor] : scene.GetActors())
|
||||||
{
|
{
|
||||||
if(!actor.IsVisible())
|
if(!actor.IsVisible())
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user