diff --git a/Src/IAESandbox/imp/cpp/Map.cpp b/Src/IAESandbox/imp/cpp/Map.cpp index c4c3b36..824e868 100644 --- a/Src/IAESandbox/imp/cpp/Map.cpp +++ b/Src/IAESandbox/imp/cpp/Map.cpp @@ -4,8 +4,8 @@ namespace ia::iae::game { TiledMap::TiledMap(IN Engine *engine) : m_engine(engine) { - m_musicEmitter = AddComponent(); - m_atlasRenderer = AddComponent(); + //m_musicEmitter = AddComponent(); + //m_atlasRenderer = AddComponent(); } VOID TiledMap::OnAdded(IN Scene *scene) diff --git a/Src/IAESandbox/imp/hpp/Ground.hpp b/Src/IAESandbox/imp/hpp/Ground.hpp index e23423d..ab550fb 100644 --- a/Src/IAESandbox/imp/hpp/Ground.hpp +++ b/Src/IAESandbox/imp/hpp/Ground.hpp @@ -22,6 +22,6 @@ namespace ia::iae::game private: Engine *CONST m_engine; - RefPtr m_spriteRenderer; + SpriteRendererComponent* m_spriteRenderer; }; } // namespace ia::iae::game \ No newline at end of file diff --git a/Src/IAESandbox/imp/hpp/Player.hpp b/Src/IAESandbox/imp/hpp/Player.hpp index 4312b66..e916d9b 100644 --- a/Src/IAESandbox/imp/hpp/Player.hpp +++ b/Src/IAESandbox/imp/hpp/Player.hpp @@ -22,6 +22,6 @@ namespace ia::iae::game private: Engine *CONST m_engine; - RefPtr m_spriteRenderer; + SpriteRendererComponent* m_spriteRenderer; }; } // namespace ia::iae::game \ No newline at end of file diff --git a/Src/IAEngine/CMakeLists.txt b/Src/IAEngine/CMakeLists.txt index 4d80b83..3c4b45d 100644 --- a/Src/IAEngine/CMakeLists.txt +++ b/Src/IAEngine/CMakeLists.txt @@ -22,6 +22,7 @@ set(IAEngine_Sources imp/cpp/Components/SoundEmitter.cpp imp/cpp/Components/ParticleEmitter.cpp imp/cpp/Components/PhysicsBody.cpp + imp/cpp/Components/TextureRenderer.cpp ) add_library(IAEngine STATIC ${IAEngine_Sources}) diff --git a/Src/IAEngine/imp/cpp/Audio.cpp b/Src/IAEngine/imp/cpp/Audio.cpp index e82e9d5..542ba31 100644 --- a/Src/IAEngine/imp/cpp/Audio.cpp +++ b/Src/IAEngine/imp/cpp/Audio.cpp @@ -77,7 +77,7 @@ namespace ia::iae VOID Audio::ClearTrack(IN INT64 trackHandle) { - //MIX_StopTrack(g_tracks[trackHandle], 0); + MIX_StopTrack(g_tracks[trackHandle], 0); } VOID Audio::PauseTrack(IN INT64 trackHandle) diff --git a/Src/IAEngine/imp/cpp/Components/AtlasRenderer.cpp b/Src/IAEngine/imp/cpp/Components/AtlasRenderer.cpp index fa3e3f8..b67331d 100644 --- a/Src/IAEngine/imp/cpp/Components/AtlasRenderer.cpp +++ b/Src/IAEngine/imp/cpp/Components/AtlasRenderer.cpp @@ -40,7 +40,7 @@ namespace ia::iae { const auto t = m_tileGrid.m_tileTextures[x + (y * m_tileGrid.TileCountX)]; if (t != INVALID_HANDLE) - m_textures[t]->Draw(p, {1.0f, 1.0f, 1.0f}, 0.0f, false, false, {1.0f, 1.0f, 1.0f, 1.0f}); + m_textures[t]->Draw(p + m_tileGrid.Position, {1.0f, 1.0f, 1.0f}, 0.0f, false, false, {1.0f, 1.0f, 1.0f, 1.0f}); p.X += m_tileGrid.TileWidth; } p.X = m_node->GetPosition().X; diff --git a/Src/IAEngine/imp/cpp/Components/ParticleEmitter.cpp b/Src/IAEngine/imp/cpp/Components/ParticleEmitter.cpp index b015187..d91d517 100644 --- a/Src/IAEngine/imp/cpp/Components/ParticleEmitter.cpp +++ b/Src/IAEngine/imp/cpp/Components/ParticleEmitter.cpp @@ -16,13 +16,26 @@ namespace ia::iae VOID ParticleEmitterComponent::Draw() { - for(auto& s: m_sprites) + if (!m_isEmitting) + return; + + for (auto &s : m_sprites) s->Draw(); } VOID ParticleEmitterComponent::Update() { - for(auto& s: m_sprites) + if (!m_isEmitting) + return; + + for (auto &s : m_sprites) s->Update(); + + m_timeline += Time::GetFrameDeltaTime(); + if (m_timeline >= m_lifeTime.GetValue()) + { + m_timeline = 0; + m_isEmitting = false; + } } } // namespace ia::iae \ No newline at end of file diff --git a/Src/IAEngine/imp/cpp/Components/SpriteRenderer.cpp b/Src/IAEngine/imp/cpp/Components/SpriteRenderer.cpp index a8a1902..f9be886 100644 --- a/Src/IAEngine/imp/cpp/Components/SpriteRenderer.cpp +++ b/Src/IAEngine/imp/cpp/Components/SpriteRenderer.cpp @@ -14,7 +14,8 @@ namespace ia::iae Handle SpriteRendererComponent::AddAnimation(IN CONST Animation &animation) { - IA_RELEASE_ASSERT(!animation.Keys.empty()); + if(animation.Keys.empty()) + return INVALID_HANDLE; m_animations.pushBack(animation); return m_animations.size() - 1; } @@ -51,6 +52,7 @@ namespace ia::iae VOID SpriteRendererComponent::Draw() { const auto &animFrame = m_currentAnimationState; + if(!animFrame.Texture) return; animFrame.Texture->Draw( m_node->GetPosition() + animFrame.Position, m_node->GetScale() * animFrame.Scale, m_node->GetRotation().Z + animFrame.Rotation.Z, m_isFlippedH, m_isFlippedV, animFrame.ColorOverlay); diff --git a/Src/IAEngine/imp/cpp/Components/TextureRenderer.cpp b/Src/IAEngine/imp/cpp/Components/TextureRenderer.cpp new file mode 100644 index 0000000..35c5cf4 --- /dev/null +++ b/Src/IAEngine/imp/cpp/Components/TextureRenderer.cpp @@ -0,0 +1,22 @@ +#include + +#include + +namespace ia::iae +{ + TextureRendererComponent::TextureRendererComponent(IN Node *node) : IComponent(node) + { + } + + VOID TextureRendererComponent::Update() + { + + } + + VOID TextureRendererComponent::Draw() + { + m_texture->Draw( + m_node->GetPosition() + m_position, m_node->GetScale(), + m_node->GetRotation().Z, false, false, iam::Vec4f{1.0f, 1.0f, 1.0f, 1.0f}); + } +} // namespace ia::iae \ No newline at end of file diff --git a/Src/IAEngine/imp/cpp/IAEngine.cpp b/Src/IAEngine/imp/cpp/IAEngine.cpp index 1119621..e78528f 100644 --- a/Src/IAEngine/imp/cpp/IAEngine.cpp +++ b/Src/IAEngine/imp/cpp/IAEngine.cpp @@ -1,9 +1,9 @@ #include #include #include +#include #include #include -#include #include @@ -132,6 +132,12 @@ namespace ia::iae Time::NextFrame(); } + VOID Engine::AddDebugUIWindow(IN PCCHAR title, IN CONST iam::Vec2f &position, IN CONST iam::Vec2f &size, + IN std::function contentDrawCallback) + { + m_debugUIWindows.pushBack(DebugUIWindow{title, position, size, contentDrawCallback}); + } + BOOL Engine::ShouldClose() { return m_context->ShouldClose; @@ -139,10 +145,18 @@ namespace ia::iae VOID Engine::RenderDebugUI() { + for (const auto &w : m_debugUIWindows) { + ImGui::Begin(w.Title); + ImGui::SetWindowPos({w.Position.X, w.Position.Y}); + ImGui::SetWindowSize({w.Size.X, w.Size.Y}); + w.ContentDrawCallback(); + ImGui::End(); + } } VOID Engine::ProcessEvents() { + ImGui_ImplSDL3_ProcessEvent(&m_context->Event); Input::OnEvent(&m_context->Event); } diff --git a/Src/IAEngine/imp/cpp/Nodes/Node.cpp b/Src/IAEngine/imp/cpp/Nodes/Node.cpp index e08eb0c..844eca4 100644 --- a/Src/IAEngine/imp/cpp/Nodes/Node.cpp +++ b/Src/IAEngine/imp/cpp/Nodes/Node.cpp @@ -20,11 +20,47 @@ namespace ia::iae VOID Node::Draw() { - for (auto &c : m_components) - c->Draw(); + BOOL drew = false; + for (auto &n : m_children) + { + if (((INT32) n->GetPosition().Z) >= 0) + continue; + n->Draw(); + } - for (auto &c : m_children) - c->Draw(); + if(((INT32) GetPosition().Z) < 0) + { + for (auto &c : m_components) + c->Draw(); + } + + for (INT32 i = 0; i < 8; i++) // [IATODO] + { + for (auto &n : m_children) + { + if (((INT32) n->GetPosition().Z) != i) + continue; + n->Draw(); + } + if (((INT32) GetPosition().Z) == i) + { + for (auto &c : m_components) + c->Draw(); + } + } + + for (auto &n : m_children) + { + if (((INT32) n->GetPosition().Z) < 8) + continue; + n->Draw(); + } + + if(((INT32) GetPosition().Z) > 8) + { + for (auto &c : m_components) + c->Draw(); + } } VOID Node::Update() @@ -50,6 +86,11 @@ namespace ia::iae c->Disable(); } + VOID Node::AddChild(IN RefPtr node) + { + m_children.pushBack(node); + } + VOID Node::AddComponent(IN RefPtr component) { m_components.pushBack(IA_MOVE(component)); diff --git a/Src/IAEngine/imp/cpp/Scene.cpp b/Src/IAEngine/imp/cpp/Scene.cpp index d9b1973..8fbfb29 100644 --- a/Src/IAEngine/imp/cpp/Scene.cpp +++ b/Src/IAEngine/imp/cpp/Scene.cpp @@ -13,7 +13,28 @@ namespace ia::iae VOID Scene::Draw() { for (auto &n : m_nodes) + { + if (((INT32) n->GetPosition().Z) >= 0) + continue; n->Draw(); + } + + for (INT32 i = 0; i < 8; i++) // [IATODO] + { + for (auto &n : m_nodes) + { + if (((INT32) n->GetPosition().Z) != i) + continue; + n->Draw(); + } + } + + for (auto &n : m_nodes) + { + if (((INT32) n->GetPosition().Z) < 8) + continue; + n->Draw(); + } } VOID Scene::Update() @@ -31,10 +52,10 @@ namespace ia::iae VOID Scene::RemoveNode(IN RefPtr node) { const auto it = m_nodes.find(node); - if(it != m_nodes.end()) + if (it != m_nodes.end()) { m_nodes.erase(it); node->OnRemoved(); - } + } } } // namespace ia::iae \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Components/AtlasRenderer.hpp b/Src/IAEngine/inc/IAEngine/Components/AtlasRenderer.hpp index 1be85bf..56507d6 100644 --- a/Src/IAEngine/inc/IAEngine/Components/AtlasRenderer.hpp +++ b/Src/IAEngine/inc/IAEngine/Components/AtlasRenderer.hpp @@ -26,6 +26,8 @@ namespace ia::iae public: struct TileGrid { + iam::Vec3f Position{}; + INT32 TileWidth{}; INT32 TileHeight{}; INT32 TileCountX{}; diff --git a/Src/IAEngine/inc/IAEngine/Components/ParticleEmitter.hpp b/Src/IAEngine/inc/IAEngine/Components/ParticleEmitter.hpp index 378ad13..38f8c63 100644 --- a/Src/IAEngine/inc/IAEngine/Components/ParticleEmitter.hpp +++ b/Src/IAEngine/inc/IAEngine/Components/ParticleEmitter.hpp @@ -17,6 +17,7 @@ #pragma once #include +#include namespace ia::iae { @@ -28,29 +29,24 @@ namespace ia::iae VOID AddAnimation(IN SpriteRendererComponent::Animation anim); public: - CONST INT32 &LifeTime() CONST + TimePeriod &LifeTime() { return m_lifeTime; } - CONST INT32 &CreationFrequency() CONST + TimePeriod &CreationDelay() { - return m_creationFrequency; + return m_creationDelay; } - CONST Vector> &Sprites() CONST + INT32 &InstanceLimit() { - return m_sprites; + return m_instanceLimit; } - INT32 &LifeTime() + INT32 &TimeLimit() { - return m_lifeTime; - } - - INT32 &CreationFrequency() - { - return m_creationFrequency; + return m_timeLimit; } Vector> &Sprites() @@ -63,8 +59,12 @@ namespace ia::iae VOID Update(); private: - INT32 m_lifeTime{}; - INT32 m_creationFrequency{}; + BOOL m_isEmitting{true}; + FLOAT32 m_timeline{}; + INT32 m_timeLimit{}; + INT32 m_instanceLimit{}; + TimePeriod m_lifeTime{}; + TimePeriod m_creationDelay{}; Vector> m_sprites{}; }; } // namespace ia::iae \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Components/SpriteRenderer.hpp b/Src/IAEngine/inc/IAEngine/Components/SpriteRenderer.hpp index 35b4e84..075a0da 100644 --- a/Src/IAEngine/inc/IAEngine/Components/SpriteRenderer.hpp +++ b/Src/IAEngine/inc/IAEngine/Components/SpriteRenderer.hpp @@ -50,6 +50,27 @@ namespace ia::iae VOID SetActiveAnimation(IN Handle animation); + public: + Vector &Animations() + { + return m_animations; + } + + CONST Vector &Animations() CONST + { + return m_animations; + } + + BOOL& IsFlippedV() + { + return m_isFlippedV; + } + + BOOL& IsFlippedH() + { + return m_isFlippedH; + } + public: VOID Draw(); VOID Update(); diff --git a/Src/IAEngine/inc/IAEngine/Components/TextureRenderer.hpp b/Src/IAEngine/inc/IAEngine/Components/TextureRenderer.hpp new file mode 100644 index 0000000..320087a --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Components/TextureRenderer.hpp @@ -0,0 +1,47 @@ +// IAEngine: 2D Game Engine by IA +// Copyright (C) 2025 IAS (ias@iasoft.dev) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#pragma once + +#include +#include + +namespace ia::iae +{ + class TextureRendererComponent : public IComponent + { + public: + TextureRendererComponent(IN Node *node); + + RefPtr &Texture() + { + return m_texture; + } + + iam::Vec3f &Position() + { + return m_position; + } + + public: + VOID Draw(); + VOID Update(); + + private: + iam::Vec3f m_position; + RefPtr m_texture; + }; +} // namespace ia::iae \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/IAEngine.hpp b/Src/IAEngine/inc/IAEngine/IAEngine.hpp index ca37e96..225e865 100644 --- a/Src/IAEngine/inc/IAEngine/IAEngine.hpp +++ b/Src/IAEngine/inc/IAEngine/IAEngine.hpp @@ -27,6 +27,14 @@ namespace ia::iae class Engine { + struct DebugUIWindow + { + PCCHAR Title{""}; + iam::Vec2f Position{}; + iam::Vec2f Size{}; + std::function ContentDrawCallback{}; + }; + public: struct InitConfig { @@ -46,6 +54,8 @@ namespace ia::iae VOID EndFrame(); BOOL ShouldClose(); + VOID AddDebugUIWindow(IN PCCHAR title, IN CONST iam::Vec2f &position, IN CONST iam::Vec2f &size, IN std::function contentDrawCallback); + template _class_type* RegisterResourceManager(); @@ -68,6 +78,7 @@ namespace ia::iae RefPtr m_activeScene{}; CONST RefPtr m_context; RefPtr m_resourceManager; + Vector m_debugUIWindows; }; template diff --git a/Src/IAEngine/inc/IAEngine/Nodes/Node.hpp b/Src/IAEngine/inc/IAEngine/Nodes/Node.hpp index b4008d4..785d54c 100644 --- a/Src/IAEngine/inc/IAEngine/Nodes/Node.hpp +++ b/Src/IAEngine/inc/IAEngine/Nodes/Node.hpp @@ -36,8 +36,13 @@ namespace ia::iae VIRTUAL VOID Disable(); public: + VOID AddChild(IN RefPtr node); + template - RefPtr<_component_type> AddComponent(); + _component_type* AddComponent(); + + template + _component_type* GetComponent(); CONST Vector>& GetComponents() CONST { @@ -58,10 +63,22 @@ namespace ia::iae }; template - RefPtr<_component_type> Node::AddComponent() + _component_type* Node::AddComponent() { const auto c = MakeRefPtr<_component_type>(this); AddComponent(c); - return c; + return c.get(); + } + + template + _component_type* Node::GetComponent() + { + for(auto& c: m_components) + { + _component_type* comp = dynamic_cast<_component_type*>(c.get()); + if(comp) + return comp; + } + return nullptr; } } // namespace ia::iae \ No newline at end of file