Hot Fixes

This commit is contained in:
Isuru Samarathunga
2025-09-08 19:55:35 +05:30
parent 74ab81e298
commit 3d87701727
12 changed files with 16 additions and 47 deletions

View File

@ -12,12 +12,6 @@ namespace ia::iae
{
}
Handle SpriteRendererComponent::AddTexture(IN RefPtr<Texture> texture)
{
m_textures.pushBack(texture);
return m_textures.size() - 1;
}
Handle SpriteRendererComponent::AddAnimation(IN CONST Animation &animation)
{
IA_RELEASE_ASSERT(!animation.Keys.empty());
@ -25,26 +19,6 @@ namespace ia::iae
return m_animations.size() - 1;
}
Handle SpriteRendererComponent::AddAnimation(IN initializer_list<INT32> frames, IN INT32 frameDuration,
IN BOOL shouldLoop)
{
Animation anim;
anim.ShouldLoop = shouldLoop;
for (const auto &idx : frames)
anim.Keys.pushBack(AnimationKeyFrame{.Duration = frameDuration, .TextureHandle = idx});
return AddAnimation(anim);
}
Handle SpriteRendererComponent::AddAnimation(IN INT32 startFrame, IN INT32 endFrame, IN INT32 frameDuration,
IN BOOL shouldLoop)
{
Animation anim;
anim.ShouldLoop = shouldLoop;
for (INT32 i = startFrame; i < endFrame; i++)
anim.Keys.pushBack(AnimationKeyFrame{.Duration = frameDuration, .TextureHandle = i});
return AddAnimation(anim);
}
VOID SpriteRendererComponent::BakeAnimations()
{
for (auto &anim : m_animations)
@ -55,14 +29,6 @@ namespace ia::iae
}
if (m_animations.size())
SetActiveAnimation(0);
else
SetActiveTexture(0);
}
VOID SpriteRendererComponent::SetActiveTexture(IN Handle texture)
{
IA_RELEASE_ASSERT((texture != INVALID_HANDLE) && (texture < m_textures.size()));
m_currentAnimationState.TextureHandle = texture;
}
VOID SpriteRendererComponent::SetActiveAnimation(IN Handle animation)
@ -85,9 +51,7 @@ namespace ia::iae
VOID SpriteRendererComponent::Draw()
{
const auto &animFrame = m_currentAnimationState;
if (animFrame.TextureHandle == INVALID_HANDLE)
return;
m_textures[animFrame.TextureHandle]->Draw(
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

@ -1,7 +1,7 @@
#include <IAEngine/Audio.hpp>
#include <IAEngine/IAEngine.hpp>
#include <IAEngine/Random.hpp>
#include <IAEngine/Input.hpp>
#include <IAEngine/Random.hpp>
#include <IAEngine/Time.hpp>
#include <SDL3/SDL.h>

View File

@ -32,7 +32,7 @@ namespace ia::iae
iam::Vec3f Scale{1.0f, 1.0f, 1.0f};
iam::Vec4f ColorOverlay{1.0f, 1.0f, 1.0f, 1.0f};
BOOL ShouldInterpolate{};
INT32 TextureHandle{INVALID_HANDLE};
RefPtr<Texture> Texture;
};
struct Animation
@ -44,14 +44,10 @@ namespace ia::iae
public:
SpriteRendererComponent(IN Node *node);
Handle AddTexture(IN RefPtr<Texture> texture);
Handle AddAnimation(IN CONST Animation &animation);
Handle AddAnimation(IN initializer_list<INT32> frames, IN INT32 frameDuration, IN BOOL shouldLoop);
Handle AddAnimation(IN INT32 startFrame, IN INT32 endFrame, IN INT32 frameDuration, IN BOOL shouldLoop);
VOID BakeAnimations();
VOID SetActiveTexture(IN Handle texture);
VOID SetActiveAnimation(IN Handle animation);
public:
@ -68,7 +64,6 @@ namespace ia::iae
Animation m_activeAnimation{};
Handle m_activeAnimationHandle{INVALID_HANDLE};
Vector<Animation> m_animations;
Vector<RefPtr<Texture>> m_textures;
AnimationKeyFrame m_currentAnimationState{};
AnimationKeyFrame m_nextAnimationKeyFrame{};
AnimationKeyFrame m_prevAnimationKeyFrame{};

View File

@ -19,6 +19,7 @@
#include <IAEngine/Nodes/Node.hpp>
#include <IAEngine/Scene.hpp>
#include <IAEngine/Texture.hpp>
#include <IAEngine/ResourceManager.hpp>
namespace ia::iae
{
@ -45,6 +46,9 @@ namespace ia::iae
VOID EndFrame();
BOOL ShouldClose();
template<typename _class_type>
_class_type* RegisterResourceManager();
public:
RefPtr<Scene> CreateScene();
@ -63,5 +67,13 @@ namespace ia::iae
FLOAT32 m_updateTimer{};
RefPtr<Scene> m_activeScene{};
CONST RefPtr<EngineContext> m_context;
RefPtr<ResourceManager> m_resourceManager;
};
template<typename _class_type>
_class_type* Engine::RegisterResourceManager()
{
m_resourceManager = MakeRefPtr<_class_type>(this);
return (_class_type*)m_resourceManager.get();
}
} // namespace ia::iae

View File

@ -44,9 +44,7 @@ namespace ia::iae
protected:
Engine *CONST m_engine;
private:
ResourceManager(IN Engine *engine);
friend class Engine;
};
} // namespace ia::iae