This commit is contained in:
Isuru Samarathunga
2025-09-11 11:13:47 +05:30
parent 2856bfac6c
commit 33513ba94e
18 changed files with 245 additions and 33 deletions

View File

@ -4,8 +4,8 @@ namespace ia::iae::game
{
TiledMap::TiledMap(IN Engine *engine) : m_engine(engine)
{
m_musicEmitter = AddComponent<SoundEmitterComponent>();
m_atlasRenderer = AddComponent<AtlasRendererComponent>();
//m_musicEmitter = AddComponent<SoundEmitterComponent>();
//m_atlasRenderer = AddComponent<AtlasRendererComponent>();
}
VOID TiledMap::OnAdded(IN Scene *scene)

View File

@ -22,6 +22,6 @@ namespace ia::iae::game
private:
Engine *CONST m_engine;
RefPtr<SpriteRendererComponent> m_spriteRenderer;
SpriteRendererComponent* m_spriteRenderer;
};
} // namespace ia::iae::game

View File

@ -22,6 +22,6 @@ namespace ia::iae::game
private:
Engine *CONST m_engine;
RefPtr<SpriteRendererComponent> m_spriteRenderer;
SpriteRendererComponent* m_spriteRenderer;
};
} // namespace ia::iae::game

View File

@ -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})

View File

@ -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)

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -0,0 +1,22 @@
#include <IAEngine/Components/TextureRenderer.hpp>
#include <IAEngine/Nodes/Node.hpp>
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

View File

@ -1,9 +1,9 @@
#include <IAEngine/Audio.hpp>
#include <IAEngine/IAEngine.hpp>
#include <IAEngine/Input.hpp>
#include <IAEngine/Physics/Physics.hpp>
#include <IAEngine/Random.hpp>
#include <IAEngine/Time.hpp>
#include <IAEngine/Physics/Physics.hpp>
#include <SDL3/SDL.h>
@ -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<VOID()> 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);
}

View File

@ -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> node)
{
m_children.pushBack(node);
}
VOID Node::AddComponent(IN RefPtr<IComponent> component)
{
m_components.pushBack(IA_MOVE(component));

View File

@ -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> 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

View File

@ -26,6 +26,8 @@ namespace ia::iae
public:
struct TileGrid
{
iam::Vec3f Position{};
INT32 TileWidth{};
INT32 TileHeight{};
INT32 TileCountX{};

View File

@ -17,6 +17,7 @@
#pragma once
#include <IAEngine/Components/SpriteRenderer.hpp>
#include <IAEngine/Time.hpp>
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<RefPtr<SpriteRendererComponent>> &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<RefPtr<SpriteRendererComponent>> &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<RefPtr<SpriteRendererComponent>> m_sprites{};
};
} // namespace ia::iae

View File

@ -50,6 +50,27 @@ namespace ia::iae
VOID SetActiveAnimation(IN Handle animation);
public:
Vector<Animation> &Animations()
{
return m_animations;
}
CONST Vector<Animation> &Animations() CONST
{
return m_animations;
}
BOOL& IsFlippedV()
{
return m_isFlippedV;
}
BOOL& IsFlippedH()
{
return m_isFlippedH;
}
public:
VOID Draw();
VOID Update();

View File

@ -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 <https://www.gnu.org/licenses/>.
#pragma once
#include <IAEngine/Components/Component.hpp>
#include <IAEngine/Texture.hpp>
namespace ia::iae
{
class TextureRendererComponent : public IComponent
{
public:
TextureRendererComponent(IN Node *node);
RefPtr<iae::Texture> &Texture()
{
return m_texture;
}
iam::Vec3f &Position()
{
return m_position;
}
public:
VOID Draw();
VOID Update();
private:
iam::Vec3f m_position;
RefPtr<iae::Texture> m_texture;
};
} // namespace ia::iae

View File

@ -27,6 +27,14 @@ namespace ia::iae
class Engine
{
struct DebugUIWindow
{
PCCHAR Title{""};
iam::Vec2f Position{};
iam::Vec2f Size{};
std::function<VOID()> 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<VOID()> contentDrawCallback);
template<typename _class_type>
_class_type* RegisterResourceManager();
@ -68,6 +78,7 @@ namespace ia::iae
RefPtr<Scene> m_activeScene{};
CONST RefPtr<EngineContext> m_context;
RefPtr<ResourceManager> m_resourceManager;
Vector<DebugUIWindow> m_debugUIWindows;
};
template<typename _class_type>

View File

@ -36,8 +36,13 @@ namespace ia::iae
VIRTUAL VOID Disable();
public:
VOID AddChild(IN RefPtr<Node> node);
template<typename _component_type>
RefPtr<_component_type> AddComponent();
_component_type* AddComponent();
template<typename _component_type>
_component_type* GetComponent();
CONST Vector<RefPtr<IComponent>>& GetComponents() CONST
{
@ -58,10 +63,22 @@ namespace ia::iae
};
template<typename _component_type>
RefPtr<_component_type> Node::AddComponent()
_component_type* Node::AddComponent()
{
const auto c = MakeRefPtr<_component_type>(this);
AddComponent(c);
return c;
return c.get();
}
template<typename _component_type>
_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