diff --git a/Application/Block.h b/Application/Block.h new file mode 100644 index 0000000..6a2ead9 --- /dev/null +++ b/Application/Block.h @@ -0,0 +1,6 @@ +#ifndef BLOCK_H +#define BLOCK_H + +#include + +#endif diff --git a/Application/Chunk.cpp b/Application/Chunk.cpp new file mode 100644 index 0000000..4b690b1 --- /dev/null +++ b/Application/Chunk.cpp @@ -0,0 +1,29 @@ +#include +#include + +Chunk::Chunk(Scop::Scene& world, Scop::Vec2ui offset) : m_data(CHUNK_VOLUME), m_offset(offset), m_position(std::move(offset) * Scop::Vec2ui{ CHUNK_SIZE }) +{ +} + +void Chunk::GenerateChunk() +{ + std::fill(m_data.begin(), m_data.end(), 0); + + for(std::uint32_t x = 0; x < CHUNK_SIZE.x; x++) + { + for(std::uint32_t z = 0; z < CHUNK_SIZE.z; z++) + { + std::uint32_t pos_x = m_position.x + x; + std::uint32_t pos_z = m_position.y + z; + + for(std::uint32_t y = 0; y < CHUNK_SIZE.y; y++) + { + std::uint32_t index = (z * CHUNK_SIZE.x * CHUNK_SIZE.y) + (y * CHUNK_SIZE.x) + x; + + // Implement noise here + + m_data[index] = y < 10 ? 1 : 0; + } + } + } +} diff --git a/Application/Chunk.h b/Application/Chunk.h new file mode 100644 index 0000000..52a0a59 --- /dev/null +++ b/Application/Chunk.h @@ -0,0 +1,27 @@ +#ifndef CHUNK_H +#define CHUNK_H + +#include +#include +#include + +constexpr Scop::Vec3ui CHUNK_SIZE = Scop::Vec3ui{ 16, 256, 16 }; +constexpr std::uint32_t CHUNK_VOLUME = CHUNK_SIZE.x * CHUNK_SIZE.y * CHUNK_SIZE.z; + +class Chunk +{ + public: + Chunk(Scop::Scene& world, Scop::Vec2ui offset); + + void GenerateChunk(); + + ~Chunk() = default; + + private: + std::vector m_data; + Scop::Vec2ui m_offset; // In chunks + Scop::Vec2ui m_position; // In blocks + Scop::NonOwningPtr p_actor = nullptr; +}; + +#endif diff --git a/Application/ScriptSubRoutines.cpp b/Application/ScriptSubRoutines.cpp deleted file mode 100644 index 7e0793c..0000000 --- a/Application/ScriptSubRoutines.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include - -constexpr const float SPEED = 40.0f; - -void WireframeHandler(Scop::NonOwningPtr scene, Scop::Inputs& inputs) -{ - static bool key_pressed_last_frame = false; - if(inputs.IsKeyPressed(SDL_SCANCODE_F)) - key_pressed_last_frame = true; - else if(key_pressed_last_frame) - { - scene->GetForwardData().wireframe = !scene->GetForwardData().wireframe; - Scop::RenderCore::Get().WaitDeviceIdle(); - scene->GetPipeline().Destroy(); - key_pressed_last_frame = false; - } - static Scop::Vec3f rotations{ 0.0f, 0.0f, 0.0f }; -} - -void MovementHandler(Scop::NonOwningPtr actor, Scop::Inputs& inputs, float delta) -{ - static Scop::Vec3f position{ 0.0f, 0.0f, 0.0f }; - if(inputs.IsKeyPressed(SDL_SCANCODE_I)) - position.x += SPEED * delta; - if(inputs.IsKeyPressed(SDL_SCANCODE_K)) - position.x -= SPEED * delta; - if(inputs.IsKeyPressed(SDL_SCANCODE_L)) - position.z += SPEED * delta; - if(inputs.IsKeyPressed(SDL_SCANCODE_J)) - position.z -= SPEED * delta; - if(inputs.IsKeyPressed(SDL_SCANCODE_U)) - position.y += SPEED * delta; - if(inputs.IsKeyPressed(SDL_SCANCODE_O)) - position.y -= SPEED * delta; - actor->SetPosition(position); -} - -void ColorsTransitionHandler(Scop::NonOwningPtr actor, Scop::Inputs& inputs, float delta, Scop::MaterialData& data) -{ - static bool colors_transition = false; - static bool colors_key_pressed_last_frame = false; - static std::uint8_t colors_transition_way = 0; - if(inputs.IsKeyPressed(SDL_SCANCODE_C) && !colors_transition) - colors_key_pressed_last_frame = true; - else if(colors_key_pressed_last_frame) - { - colors_key_pressed_last_frame = false; - colors_transition = true; - colors_transition_way = (data.dissolve_black_white_colors_factor >= 0.5f); - } - if(colors_transition) - { - if(colors_transition_way == 1) - { - data.dissolve_black_white_colors_factor -= 1.0f * delta; - colors_transition = (data.dissolve_black_white_colors_factor > 0.0f); - } - else - { - data.dissolve_black_white_colors_factor += 1.0f * delta; - colors_transition = (data.dissolve_black_white_colors_factor < 1.0f); - } - } - - static bool normals_transition = false; - static bool normals_key_pressed_last_frame = false; - static std::uint8_t normals_transition_way = 0; - if(inputs.IsKeyPressed(SDL_SCANCODE_N) && !normals_transition) - normals_key_pressed_last_frame = true; - else if(normals_key_pressed_last_frame) - { - normals_key_pressed_last_frame = false; - normals_transition = true; - normals_transition_way = (data.dissolve_normals_colors_factor >= 0.5f); - } - if(normals_transition) - { - if(normals_transition_way == 1) - { - data.dissolve_normals_colors_factor -= 1.0f * delta; - normals_transition = (data.dissolve_normals_colors_factor > 0.0f); - } - else - { - data.dissolve_normals_colors_factor += 1.0f * delta; - normals_transition = (data.dissolve_normals_colors_factor < 1.0f); - } - } -} - -void TextureTransitionHandler(Scop::NonOwningPtr actor, Scop::Inputs& inputs, float delta, Scop::MaterialData& data) -{ - static bool texture_transition = false; - static bool key_pressed_last_frame = false; - static std::uint8_t transition_way = 0; - - if(inputs.IsKeyPressed(SDL_SCANCODE_T) && !texture_transition) - key_pressed_last_frame = true; - else if(key_pressed_last_frame) - { - texture_transition = true; - key_pressed_last_frame = false; - transition_way = (data.dissolve_texture_factor >= 0.5f); - } - if(texture_transition) - { - if(transition_way == 1) - { - data.dissolve_texture_factor -= 1.0f * delta; - texture_transition = (data.dissolve_texture_factor > 0.0f); - } - else - { - data.dissolve_texture_factor += 1.0f * delta; - texture_transition = (data.dissolve_texture_factor < 1.0f); - } - } -} diff --git a/Application/ScriptSubRoutines.h b/Application/ScriptSubRoutines.h deleted file mode 100644 index 465055c..0000000 --- a/Application/ScriptSubRoutines.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __SCRIPT_SUB_ROUTINES__ -#define __SCRIPT_SUB_ROUTINES__ - -#include -#include - -void WireframeHandler(Scop::NonOwningPtr scene, Scop::Inputs& inputs); -void MovementHandler(Scop::NonOwningPtr actor, Scop::Inputs& inputs, float delta); -void ColorsTransitionHandler(Scop::NonOwningPtr actor, Scop::Inputs& inputs, float delta, Scop::MaterialData& data); -void TextureTransitionHandler(Scop::NonOwningPtr actor, Scop::Inputs& inputs, float delta, Scop::MaterialData& data); - -#endif diff --git a/Application/Utils.h b/Application/Utils.h new file mode 100644 index 0000000..229e214 --- /dev/null +++ b/Application/Utils.h @@ -0,0 +1,20 @@ +#ifndef UTILS_H +#define UTILS_H + +#include +#include +#include + +inline std::filesystem::path GetExecutablePath() +{ + char result[PATH_MAX]; + ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); + return std::string(result, (count > 0) ? count : 0); +} + +inline std::filesystem::path GetResourcesPath() +{ + return GetExecutablePath().parent_path().parent_path() / "Resources"; +} + +#endif diff --git a/Application/World.cpp b/Application/World.cpp new file mode 100644 index 0000000..07225c4 --- /dev/null +++ b/Application/World.cpp @@ -0,0 +1,18 @@ +#include + +#include +#include + +World::World(Scop::Scene& scene) : m_scene(scene), m_narrator(scene.CreateNarrator()) +{ + Scop::Vec2ui32 map_size; + Scop::MaterialTextures material_params; + material_params.albedo = std::make_shared(Scop::LoadBMPFile(GetResourcesPath() / "prototype.bmp", map_size), map_size.x, map_size.y); + p_block_material = std::make_shared(material_params); + + auto narrator_update = [](Scop::NonOwningPtr scene, Scop::Inputs& input, float delta) + { + }; + + m_narrator.AttachScript(std::make_shared(std::function{}, narrator_update, std::function{})); +} diff --git a/Application/World.h b/Application/World.h new file mode 100644 index 0000000..d5efc8c --- /dev/null +++ b/Application/World.h @@ -0,0 +1,28 @@ +#ifndef WORLD_H +#define WORLD_H + +#include + +#include + +#include + +class World +{ + public: + World(Scop::Scene& scene); + + [[nodiscard]] inline Scop::Scene& GetScene() noexcept { return m_scene; } + + ~World() = default; + + private: + static inline constexpr std::size_t CHUNKS_SIZE = 16; + + std::vector> m_chunks; + std::shared_ptr p_block_material; + Scop::Narrator& m_narrator; + Scop::Scene& m_scene; +}; + +#endif diff --git a/Application/main.cpp b/Application/main.cpp index 410ce36..5f159ad 100644 --- a/Application/main.cpp +++ b/Application/main.cpp @@ -1,27 +1,9 @@ #include #include -#include #include - -#include -#include -#include -#include -#include -#include - -std::filesystem::path GetExecutablePath() -{ - char result[PATH_MAX]; - ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); - return std::string(result, (count > 0) ? count : 0); -} - -std::filesystem::path GetResourcesPath() -{ - return GetExecutablePath().parent_path().parent_path() / "Resources"; -} +#include +#include int main(int ac, char** av) { @@ -37,6 +19,16 @@ int main(int ac, char** av) Scop::Vec2ui32 skybox_size; main_scene.AddSkybox(std::make_shared(Scop::LoadBMPFile(GetResourcesPath() / "skybox.bmp", skybox_size), skybox_size.x, skybox_size.y)); + World world(main_scene); + + Scop::Actor& object = main_scene.CreateActor(Scop::CreateCube()); + + Scop::Vec2ui32 map_size; + Scop::MaterialTextures material_params; + material_params.albedo = std::make_shared(Scop::LoadBMPFile(GetResourcesPath() / "prototype.bmp", map_size), map_size.x, map_size.y); + std::shared_ptr material = std::make_shared(material_params); + object.GetModelRef().SetMaterial(material, 0); + engine.RegisterMainScene(splash_scene.get()); engine.Run(); return 0; diff --git a/Resources/prototype.bmp b/Resources/prototype.bmp new file mode 100644 index 0000000..160be7b Binary files /dev/null and b/Resources/prototype.bmp differ diff --git a/ScopEngine/Runtime/Includes/Core/NativeScript.h b/ScopEngine/Runtime/Includes/Core/NativeScript.h index 8efee6c..c661e4a 100644 --- a/ScopEngine/Runtime/Includes/Core/NativeScript.h +++ b/ScopEngine/Runtime/Includes/Core/NativeScript.h @@ -44,6 +44,25 @@ namespace Scop std::function, NonOwningPtr, class Inputs&, float)> f_on_update; std::function)> f_on_quit; }; + + class NativeNarratorScript : public NarratorScript + { + public: + NativeNarratorScript(std::function on_init, std::function, class Inputs&, float)> on_update, std::function 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 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 f_on_init; + std::function, class Inputs&, float)> f_on_update; + std::function f_on_quit; + }; } #endif diff --git a/ScopEngine/Runtime/Includes/Core/Script.h b/ScopEngine/Runtime/Includes/Core/Script.h index 6d15f08..18a8d7c 100644 --- a/ScopEngine/Runtime/Includes/Core/Script.h +++ b/ScopEngine/Runtime/Includes/Core/Script.h @@ -28,6 +28,18 @@ namespace Scop virtual ~SpriteScript() = default; }; + + class NarratorScript + { + public: + NarratorScript() = default; + + virtual void OnInit() = 0; + virtual void OnUpdate(NonOwningPtr scene, class Inputs& input, float delta) = 0; + virtual void OnQuit() = 0; + + virtual ~NarratorScript() = default; + }; } #endif diff --git a/ScopEngine/Runtime/Includes/Graphics/Actor.h b/ScopEngine/Runtime/Includes/Graphics/Actor.h index 4a5b484..f619042 100644 --- a/ScopEngine/Runtime/Includes/Graphics/Actor.h +++ b/ScopEngine/Runtime/Includes/Graphics/Actor.h @@ -1,5 +1,5 @@ -#ifndef __SCOP_RENDERER_ACTOR__ -#define __SCOP_RENDERER_ACTOR__ +#ifndef __SCOP_GRAPHICS_ACTOR__ +#define __SCOP_GRAPHICS_ACTOR__ #include #include @@ -11,12 +11,13 @@ namespace Scop { class Actor { + friend Scene; + public: Actor(); Actor(Model model); inline void AttachScript(std::shared_ptr script) { p_script = script; } - void Update(NonOwningPtr 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 scene, class Inputs& input, float timestep); + private: Model m_model; Quatf m_orientation = Quatf::Identity(); diff --git a/ScopEngine/Runtime/Includes/Graphics/Narrator.h b/ScopEngine/Runtime/Includes/Graphics/Narrator.h new file mode 100644 index 0000000..9693d36 --- /dev/null +++ b/ScopEngine/Runtime/Includes/Graphics/Narrator.h @@ -0,0 +1,38 @@ +#ifndef __SCOP_GRAPHICS_NARRATOR__ +#define __SCOP_GRAPHICS_NARRATOR__ + +#include +#include +#include +#include +#include + +namespace Scop +{ + class Narrator + { + friend Scene; + + public: + Narrator() = default; + inline void AttachScript(std::shared_ptr script) { p_script = script; } + inline ~Narrator() + { + if(p_script) + p_script->OnQuit(); + } + + private: + inline void Update(NonOwningPtr scene, class Inputs& input, float timestep) + { + if(p_script) + p_script->OnUpdate(scene, input, timestep); + } + + private: + std::shared_ptr p_script; + }; +} + +#endif + diff --git a/ScopEngine/Runtime/Includes/Graphics/Scene.h b/ScopEngine/Runtime/Includes/Graphics/Scene.h index 36c3e6a..dd42d78 100644 --- a/ScopEngine/Runtime/Includes/Graphics/Scene.h +++ b/ScopEngine/Runtime/Includes/Graphics/Scene.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -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) noexcept; Sprite& CreateSprite(std::string_view name, std::shared_ptr texture); @@ -82,6 +86,7 @@ namespace Scop std::shared_ptr p_skybox; std::vector> m_actors; std::vector> m_sprites; + std::vector> m_narrators; std::vector m_scene_children; std::string m_name; NonOwningPtr p_parent; diff --git a/ScopEngine/Runtime/Includes/Maths/Enums.h b/ScopEngine/Runtime/Includes/Maths/Enums.h index df12fbd..f560453 100644 --- a/ScopEngine/Runtime/Includes/Maths/Enums.h +++ b/ScopEngine/Runtime/Includes/Maths/Enums.h @@ -1,5 +1,5 @@ -#ifndef __SCOPE_MATHS_ENUMS__ -#define __SCOPE_MATHS_ENUMS__ +#ifndef __SCOP_MATHS_ENUMS__ +#define __SCOP_MATHS_ENUMS__ #include diff --git a/ScopEngine/Runtime/Includes/ScopGraphics.h b/ScopEngine/Runtime/Includes/ScopGraphics.h index 105539e..42ea7a0 100644 --- a/ScopEngine/Runtime/Includes/ScopGraphics.h +++ b/ScopEngine/Runtime/Includes/ScopGraphics.h @@ -11,5 +11,6 @@ #include #include #include +#include #endif diff --git a/ScopEngine/Runtime/Sources/Graphics/Scene.cpp b/ScopEngine/Runtime/Sources/Graphics/Scene.cpp index c5fa6af..9b02cec 100644 --- a/ScopEngine/Runtime/Sources/Graphics/Scene.cpp +++ b/ScopEngine/Runtime/Sources/Graphics/Scene.cpp @@ -35,6 +35,20 @@ namespace Scop return *actor; } + Narrator& Scene::CreateNarrator() noexcept + { + std::shared_ptr narrator = std::make_shared(); + m_narrators.push_back(narrator); + return *narrator; + } + + Narrator& Scene::CreateNarrator(std::string_view name) + { + std::shared_ptr narrator = std::make_shared(); + m_narrators.push_back(narrator); + return *narrator; + } + Sprite& Scene::CreateSprite(std::shared_ptr texture) noexcept { std::shared_ptr sprite = std::make_shared(texture); @@ -92,6 +106,7 @@ namespace Scop m_forward.matrices_set->Update(i); } m_forward.albedo_set = std::make_shared(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();