mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-11 22:53:35 +00:00
working on chunk generation
This commit is contained in:
@@ -44,6 +44,25 @@ namespace Scop
|
||||
std::function<void(NonOwningPtr<class Scene>, NonOwningPtr<class Sprite>, class Inputs&, float)> f_on_update;
|
||||
std::function<void(NonOwningPtr<class Sprite>)> f_on_quit;
|
||||
};
|
||||
|
||||
class NativeNarratorScript : public NarratorScript
|
||||
{
|
||||
public:
|
||||
NativeNarratorScript(std::function<void()> on_init, std::function<void(NonOwningPtr<class Scene>, class Inputs&, float)> on_update, std::function<void()> on_quit)
|
||||
: f_on_init(std::move(on_init)), f_on_update(std::move(on_update)), f_on_quit(std::move(on_quit))
|
||||
{}
|
||||
|
||||
inline void OnInit() override { if(f_on_init) f_on_init(); }
|
||||
inline void OnUpdate(NonOwningPtr<class Scene> scene, class Inputs& input, float delta) override { if(f_on_update) f_on_update(scene, input, delta); }
|
||||
inline void OnQuit() override { if(f_on_quit) f_on_quit(); }
|
||||
|
||||
~NativeNarratorScript() = default;
|
||||
|
||||
private:
|
||||
std::function<void()> f_on_init;
|
||||
std::function<void(NonOwningPtr<class Scene>, class Inputs&, float)> f_on_update;
|
||||
std::function<void()> f_on_quit;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,18 @@ namespace Scop
|
||||
|
||||
virtual ~SpriteScript() = default;
|
||||
};
|
||||
|
||||
class NarratorScript
|
||||
{
|
||||
public:
|
||||
NarratorScript() = default;
|
||||
|
||||
virtual void OnInit() = 0;
|
||||
virtual void OnUpdate(NonOwningPtr<class Scene> scene, class Inputs& input, float delta) = 0;
|
||||
virtual void OnQuit() = 0;
|
||||
|
||||
virtual ~NarratorScript() = default;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __SCOP_RENDERER_ACTOR__
|
||||
#define __SCOP_RENDERER_ACTOR__
|
||||
#ifndef __SCOP_GRAPHICS_ACTOR__
|
||||
#define __SCOP_GRAPHICS_ACTOR__
|
||||
|
||||
#include <Maths/Vec3.h>
|
||||
#include <Maths/Vec4.h>
|
||||
@@ -11,12 +11,13 @@ namespace Scop
|
||||
{
|
||||
class Actor
|
||||
{
|
||||
friend Scene;
|
||||
|
||||
public:
|
||||
Actor();
|
||||
Actor(Model model);
|
||||
|
||||
inline void AttachScript(std::shared_ptr<ActorScript> script) { p_script = script; }
|
||||
void Update(NonOwningPtr<class Scene> scene, class Inputs& input, float timestep);
|
||||
|
||||
inline void SetColor(Vec4f color) noexcept { m_color = color; }
|
||||
inline void SetPosition(Vec3f position) noexcept { m_position = position; }
|
||||
@@ -32,6 +33,9 @@ namespace Scop
|
||||
|
||||
~Actor();
|
||||
|
||||
public:
|
||||
void Update(NonOwningPtr<class Scene> scene, class Inputs& input, float timestep);
|
||||
|
||||
private:
|
||||
Model m_model;
|
||||
Quatf m_orientation = Quatf::Identity();
|
||||
|
||||
38
ScopEngine/Runtime/Includes/Graphics/Narrator.h
git.filemode.normal_file
38
ScopEngine/Runtime/Includes/Graphics/Narrator.h
git.filemode.normal_file
@@ -0,0 +1,38 @@
|
||||
#ifndef __SCOP_GRAPHICS_NARRATOR__
|
||||
#define __SCOP_GRAPHICS_NARRATOR__
|
||||
|
||||
#include <Maths/Vec3.h>
|
||||
#include <Maths/Vec4.h>
|
||||
#include <Maths/Quaternions.h>
|
||||
#include <Core/Script.h>
|
||||
#include <Graphics/Model.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
class Narrator
|
||||
{
|
||||
friend Scene;
|
||||
|
||||
public:
|
||||
Narrator() = default;
|
||||
inline void AttachScript(std::shared_ptr<NarratorScript> script) { p_script = script; }
|
||||
inline ~Narrator()
|
||||
{
|
||||
if(p_script)
|
||||
p_script->OnQuit();
|
||||
}
|
||||
|
||||
private:
|
||||
inline void Update(NonOwningPtr<class Scene> scene, class Inputs& input, float timestep)
|
||||
{
|
||||
if(p_script)
|
||||
p_script->OnUpdate(scene, input, timestep);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<NarratorScript> p_script;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <Utils/NonOwningPtr.h>
|
||||
|
||||
#include <Graphics/Actor.h>
|
||||
#include <Graphics/Narrator.h>
|
||||
#include <Graphics/Sprite.h>
|
||||
#include <Renderer/Buffer.h>
|
||||
#include <Renderer/Descriptor.h>
|
||||
@@ -47,6 +48,9 @@ namespace Scop
|
||||
Actor& CreateActor(Model model) noexcept;
|
||||
Actor& CreateActor(std::string_view name, Model model);
|
||||
|
||||
Narrator& CreateNarrator() noexcept;
|
||||
Narrator& CreateNarrator(std::string_view name);
|
||||
|
||||
Sprite& CreateSprite(std::shared_ptr<Texture> texture) noexcept;
|
||||
Sprite& CreateSprite(std::string_view name, std::shared_ptr<Texture> texture);
|
||||
|
||||
@@ -82,6 +86,7 @@ namespace Scop
|
||||
std::shared_ptr<CubeTexture> p_skybox;
|
||||
std::vector<std::shared_ptr<Actor>> m_actors;
|
||||
std::vector<std::shared_ptr<Sprite>> m_sprites;
|
||||
std::vector<std::shared_ptr<Narrator>> m_narrators;
|
||||
std::vector<Scene> m_scene_children;
|
||||
std::string m_name;
|
||||
NonOwningPtr<Scene> p_parent;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __SCOPE_MATHS_ENUMS__
|
||||
#define __SCOPE_MATHS_ENUMS__
|
||||
#ifndef __SCOP_MATHS_ENUMS__
|
||||
#define __SCOP_MATHS_ENUMS__
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
@@ -11,5 +11,6 @@
|
||||
#include <Graphics/Cameras/FirstPerson3D.h>
|
||||
#include <Graphics/Loaders/OBJ.h>
|
||||
#include <Graphics/Loaders/BMP.h>
|
||||
#include <Graphics/Narrator.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,6 +35,20 @@ namespace Scop
|
||||
return *actor;
|
||||
}
|
||||
|
||||
Narrator& Scene::CreateNarrator() noexcept
|
||||
{
|
||||
std::shared_ptr<Narrator> narrator = std::make_shared<Narrator>();
|
||||
m_narrators.push_back(narrator);
|
||||
return *narrator;
|
||||
}
|
||||
|
||||
Narrator& Scene::CreateNarrator(std::string_view name)
|
||||
{
|
||||
std::shared_ptr<Narrator> narrator = std::make_shared<Narrator>();
|
||||
m_narrators.push_back(narrator);
|
||||
return *narrator;
|
||||
}
|
||||
|
||||
Sprite& Scene::CreateSprite(std::shared_ptr<Texture> texture) noexcept
|
||||
{
|
||||
std::shared_ptr<Sprite> sprite = std::make_shared<Sprite>(texture);
|
||||
@@ -92,6 +106,7 @@ namespace Scop
|
||||
m_forward.matrices_set->Update(i);
|
||||
}
|
||||
m_forward.albedo_set = std::make_shared<DescriptorSet>(m_descriptor.fragment_shader->GetShaderLayout().set_layouts[0].second, m_descriptor.fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment);
|
||||
|
||||
for(auto& child : m_scene_children)
|
||||
child.Init(renderer);
|
||||
}
|
||||
@@ -100,6 +115,8 @@ namespace Scop
|
||||
{
|
||||
for(auto actor : m_actors)
|
||||
actor->Update(this, input, timestep);
|
||||
for(auto narrator : m_narrators)
|
||||
narrator->Update(this, input, timestep);
|
||||
for(auto sprite : m_sprites)
|
||||
sprite->Update(this, input, timestep);
|
||||
if(m_descriptor.camera)
|
||||
@@ -112,6 +129,7 @@ namespace Scop
|
||||
p_skybox.reset();
|
||||
m_depth.Destroy();
|
||||
m_actors.clear();
|
||||
m_narrators.clear();
|
||||
m_sprites.clear();
|
||||
m_pipeline.Destroy();
|
||||
m_descriptor.fragment_shader.reset();
|
||||
|
||||
Reference in New Issue
Block a user