This commit is contained in:
Isuru Samarathunga
2025-10-22 10:52:24 +05:30
parent e40b1f120b
commit 4e41048352
6 changed files with 51 additions and 33 deletions

View File

@ -83,6 +83,7 @@ namespace ia::iae
FontManager::Initialize();
UI::Initialize();
Physics::Initialize();
SceneManager::Initialize();
Game_OnInitialize();
@ -93,6 +94,7 @@ namespace ia::iae
{
Game_OnTerminate();
SceneManager::Terminate();
Physics::Terminate();
UI::Terminate();
FontManager::Terminate();

View File

@ -488,4 +488,9 @@ namespace ia::iae
Renderer::s_activeSceneDesignViewport = value;
Renderer::UpdateSceneScalingFactor();
}
Vec2 Engine::GetSceneDesignViewport()
{
return Renderer::s_activeSceneDesignViewport;
}
} // namespace ia::iae

View File

@ -44,27 +44,32 @@ namespace ia::iae
namespace ia::iae
{
SceneManager::SceneManager(
IN std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String> &)> getCustomNode,
IN std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> getResource)
: m_customNodeGetter(getCustomNode), m_resourceGetter(getResource)
{
Map<String, Scene *> SceneManager::s_scenes;
std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String> &)> SceneManager::s_customNodeGetter;
std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> SceneManager::s_resourceGetter;
VOID SceneManager::Initialize(){}
VOID SceneManager::Terminate(){
for (const auto &t : s_scenes)
delete t->Value;
}
SceneManager::~SceneManager()
VOID SceneManager::Setup(
IN std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String> &)> getCustomNode,
IN std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> getResource)
{
for (const auto &t : m_scenes)
delete t->Value;
s_customNodeGetter = getCustomNode;
s_resourceGetter = getResource;
}
VOID SceneManager::SwitchTo(IN CONST String &name)
{
Engine::ChangeActiveScene(m_scenes[name]);
Engine::ChangeActiveScene(s_scenes[name]);
}
Scene *SceneManager::GetScene(IN CONST String &name)
{
return m_scenes[name];
return s_scenes[name];
}
VOID SceneManager::AddScene(IN Scene *scene, IN CONST String &name, IN CONST String &xml)
@ -84,13 +89,13 @@ namespace ia::iae
{
if (!strcmp(t.name(), "Image"))
{
resources[t.attribute("name").as_string()] = m_resourceGetter(
resources[t.attribute("name").as_string()] = s_resourceGetter(
ResourceType::IMAGE, t.attribute("path").as_string(), t.attribute("index").as_llong());
}
else if (!strcmp(t.name(), "Audio"))
{
resources[t.attribute("name").as_string()] =
m_resourceGetter(ResourceType::SOUND, t.attribute("path").as_string(), 0);
s_resourceGetter(ResourceType::SOUND, t.attribute("path").as_string(), 0);
}
}
}
@ -104,17 +109,17 @@ namespace ia::iae
scene->Extent() = Vec2{t.attribute("width").as_float(), t.attribute("height").as_float()};
t = propRoot.child("DesignViewport");
if(t)
if (t)
scene->DesignViewport() = Vec2{t.attribute("width").as_float(), t.attribute("height").as_float()};
else
scene->DesignViewport() = Vec2{};
scene->EnableOnScreenGamePad() = false;
t = propRoot.child("GamePad");
if(t)
if (t)
{
const auto t2 = t.attribute("enableOnScreen");
if(t2 && t2.as_bool())
if (t2 && t2.as_bool())
scene->EnableOnScreenGamePad() = true;
}
}
@ -136,7 +141,7 @@ namespace ia::iae
}
else
{
const auto node = m_customNodeGetter(t.name(), String(t.attribute("id").as_string()).split(';'));
const auto node = s_customNodeGetter(t.name(), String(t.attribute("id").as_string()).split(';'));
scene->AddNode(node);
n = node.get();
}
@ -165,11 +170,11 @@ namespace ia::iae
});
scene->UIMarkup() = html;
}
else {
else
{
}
}
m_scenes[name] = scene;
s_scenes[name] = scene;
}
} // namespace ia::iae

View File

@ -24,9 +24,9 @@
#include <IAEngine/Components/CameraComponent.hpp>
#include <IAEngine/Components/SoundEmitterComponent.hpp>
#include <IAEngine/Scene.hpp>
#include <IAEngine/UI.hpp>
#include <IAEngine/Utils.hpp>
#include <IAEngine/SceneManager.hpp>
namespace ia::iae
{
@ -54,6 +54,7 @@ namespace ia::iae
STATIC VOID DrawQuad(IN Vec2 position, IN Handle texture, IN Vec2 scale, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex);
STATIC VOID DrawCircle(IN Vec2 position, IN Handle texture, IN FLOAT32 radius, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex);
STATIC VOID DrawText(IN CONST String& text, IN Vec2 position, IN FLOAT32 scale, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex);
STATIC Vec2 GetSceneDesignViewport();
STATIC VOID SetSceneDesignViewport(IN Vec2 value);
// Renderer State Functions

View File

@ -23,28 +23,33 @@ namespace ia::iae
class SceneManager
{
public:
SceneManager(IN std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String>&)> getCustomNode,
STATIC VOID Setup(IN std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String> &)> getCustomNode,
IN std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> getResource);
~SceneManager();
VOID SwitchTo(IN CONST String &name);
STATIC VOID SwitchTo(IN CONST String &name);
Scene *GetScene(IN CONST String &name);
STATIC Scene *GetScene(IN CONST String &name);
public:
template<typename SceneType> SceneType* AddScene(IN CONST String &name, IN CONST String &xml)
template<typename SceneType> STATIC SceneType *AddScene(IN CONST String &name, IN CONST String &xml)
{
const auto t = (Scene*)new SceneType();
const auto t = (Scene *) new SceneType();
AddScene(t, name, xml);
return (SceneType*)t;
return (SceneType *) t;
}
private:
VOID AddScene(IN Scene *scene, IN CONST String &name, IN CONST String &xml);
STATIC VOID AddScene(IN Scene *scene, IN CONST String &name, IN CONST String &xml);
private:
Map<String, Scene *> m_scenes;
std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String>&)> m_customNodeGetter;
std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> m_resourceGetter;
STATIC Map<String, Scene *> s_scenes;
STATIC std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String> &)> s_customNodeGetter;
STATIC std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> s_resourceGetter;
private:
STATIC VOID Initialize();
STATIC VOID Terminate();
friend class __Internal_Engine;
};
} // namespace ia::iae

2
Vendor/IACore vendored