Engine Single Instance Mode

This commit is contained in:
Isuru Samarathunga
2025-09-13 22:02:35 +05:30
parent 594180c5d3
commit c6a8a8a76c
22 changed files with 123 additions and 523 deletions

View File

@ -2,9 +2,6 @@
set(IAESandbox_Sources set(IAESandbox_Sources
imp/cpp/Main.cpp imp/cpp/Main.cpp
imp/cpp/Game.cpp imp/cpp/Game.cpp
imp/cpp/Map.cpp
imp/cpp/Ground.cpp
imp/cpp/Player.cpp
) )
add_executable(IAESandbox ${IAESandbox_Sources}) add_executable(IAESandbox ${IAESandbox_Sources})

View File

@ -1,8 +1,5 @@
#include <Game.hpp> #include <Game.hpp>
#include <Player.hpp>
#include <Ground.hpp>
#include <IAEngine/ResourceManager.hpp>
#include <IAEngine/Rendering/Camera.hpp> #include <IAEngine/Rendering/Camera.hpp>
#include <IACore/File.hpp> #include <IACore/File.hpp>
@ -11,33 +8,24 @@ namespace ia::iae::game
{ {
RefPtr<iae::Scene> scene; RefPtr<iae::Scene> scene;
ResourceManager* g_resourceManager{}; Texture g_tex;
RefPtr<Texture> g_tex;
VOID Game::Initialize() VOID Game::Initialize()
{ {
g_resourceManager = m_engine->RegisterResourceManager<ResourceManager>(); scene = Engine::CreateScene();
Engine::ChangeScene(scene);
scene = m_engine->CreateScene();
m_engine->ChangeScene(scene);
iae::Renderer::AddDebugUIWindow("Debug Window", {100, 100}, {100, 200}, [](){});
const auto d = File::ReadToVector("Graphics/1.jpg"); const auto d = File::ReadToVector("Graphics/1.jpg");
g_tex = g_resourceManager->CreateTexture(d.data(), d.size()); g_tex = Engine::CreateTexture(d.data(), d.size());
} }
VOID Game::Terminate() VOID Game::Terminate()
{ {
g_tex.reset();
} }
VOID Game::Update() VOID Game::Update()
{ {
g_tex->Draw({200.0f, 150.0f, 0.0f}, {1.0f, 1.0f, 1.0f}, 0.0f, false, false, {1.0f, 1.0f, 1.0f, 1.0f}); g_tex.Draw({200.0f, 150.0f, 0.0f}, {1.0f, 1.0f, 1.0f}, 0.0f, false, false, {1.0f, 1.0f, 1.0f, 1.0f});
iae::Renderer::GetCamera()->Position().x += 0.1f; iae::Renderer::GetCamera()->Position().x += 0.1f;
} }
} }

View File

@ -1,49 +0,0 @@
#include <Ground.hpp>
#include <IAEngine/Physics/Physics.hpp>
#include <IACore/File.hpp>
namespace ia::iae::game
{
extern ResourceManager* g_resourceManager;
Handle m_id2;
Ground::Ground(IN Engine *engine) : m_engine(engine)
{
m_spriteRenderer = AddComponent<SpriteRendererComponent>();
}
VOID Ground::OnAdded(IN Scene *scene)
{
Node::OnAdded(scene);
iae::SpriteRendererComponent::AnimationKeyFrame keyFrame{};
const auto d = File::ReadToVector("Graphics/red.png");
keyFrame.Texture = g_resourceManager->CreateTexture(d.data(), d.size());
keyFrame.Scale = {3.0f, 0.25f, 1.0f};
m_spriteRenderer->AddAnimation({.ShouldLoop = true, .Keys = {keyFrame}});
m_spriteRenderer->BakeAnimations();
//m_id2 = Physics::CreateStaticBody({GetPosition().X + 300, GetPosition().Y + 25});
//Physics::AddBoxCollider(m_id2, {600.0f, 50.0f});
}
VOID Ground::OnRemoved()
{
Node::OnRemoved();
}
VOID Ground::Draw()
{
Node::Draw();
}
VOID Ground::Update()
{
Node::Update();
}
} // namespace ia::iae::game

View File

@ -1,20 +1,18 @@
#include <Game.hpp> #include <Game.hpp>
ia::iae::Engine g_engine;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
g_engine.Initialize({.GameName = "IAE Sandbox", .WindowWidth = 800, .WindowHeight = 600}); ia::iae::Engine::Initialize({.GameName = "IAE Sandbox", .WindowWidth = 800, .WindowHeight = 600});
const auto game = new ia::iae::game::Game(&g_engine); const auto game = new ia::iae::game::Game();
game->Initialize(); game->Initialize();
while (!g_engine.ShouldClose()) while (!ia::iae::Engine::ShouldClose())
{ {
g_engine.BeginFrame(); ia::iae::Engine::BeginFrame();
game->Update(); game->Update();
g_engine.EndFrame(); ia::iae::Engine::EndFrame();
} }
game->Terminate(); game->Terminate();
delete game; delete game;
g_engine.Terminate(); ia::iae::Engine::Terminate();
return 0; return 0;
} }

View File

@ -1,30 +0,0 @@
#include <Map.hpp>
namespace ia::iae::game
{
TiledMap::TiledMap(IN Engine *engine) : m_engine(engine)
{
//m_musicEmitter = AddComponent<SoundEmitterComponent>();
//m_atlasRenderer = AddComponent<AtlasRendererComponent>();
}
VOID TiledMap::OnAdded(IN Scene *scene)
{
Node::OnAdded(scene);
}
VOID TiledMap::OnRemoved()
{
Node::OnRemoved();
}
VOID TiledMap::Draw()
{
Node::Draw();
}
VOID TiledMap::Update()
{
Node::Update();
}
} // namespace ia::iae::game

View File

@ -1,51 +0,0 @@
#include <Player.hpp>
#include <IAEngine/Physics/Physics.hpp>
#include <IAEngine/Input.hpp>
#include <IACore/File.hpp>
namespace ia::iae::game
{
extern ResourceManager* g_resourceManager;
Handle m_id;
Player::Player(IN Engine *engine) : m_engine(engine)
{
m_spriteRenderer = AddComponent<SpriteRendererComponent>();
}
VOID Player::OnAdded(IN Scene *scene)
{
Node::OnAdded(scene);
iae::SpriteRendererComponent::AnimationKeyFrame keyFrame{};
const auto d = File::ReadToVector("Graphics/green.png");
keyFrame.Texture = g_resourceManager->CreateTexture(d.data(), d.size());
keyFrame.Scale = {0.2f, 0.2f, 1.0f};
m_spriteRenderer->AddAnimation({.ShouldLoop = true, .Keys = {keyFrame}});
m_spriteRenderer->BakeAnimations();
//m_id = Physics::CreateDynamicBody({GetPosition().X + 20, GetPosition().Y + 20});
//Physics::AddBoxCollider(m_id, {40.0f, 40.0f});
}
VOID Player::OnRemoved()
{
Node::OnRemoved();
}
VOID Player::Draw()
{
Node::Draw();
}
VOID Player::Update()
{
Node::Update();
SetLocalPosition(Physics::GetBodyPosition(m_id) - glm::vec3{20.0f, 20.0f, 0.0f});
}
} // namespace ia::iae::game

View File

@ -7,13 +7,8 @@ namespace ia::iae::game
class Game class Game
{ {
public: public:
Game(IN Engine* engine): m_engine(engine) {}
VOID Initialize(); VOID Initialize();
VOID Terminate(); VOID Terminate();
VOID Update(); VOID Update();
private:
Engine* CONST m_engine;
}; };
} }

View File

@ -1,27 +0,0 @@
#pragma once
#include <IAEngine/Components/SoundEmitter.hpp>
#include <IAEngine/Components/SpriteRenderer.hpp>
#include <IAEngine/IAEngine.hpp>
namespace ia::iae::game
{
class Ground : public Node
{
public:
Ground(IN Engine *engine);
VIRTUAL VOID OnAdded(IN Scene *scene) OVERRIDE;
VIRTUAL VOID OnRemoved() OVERRIDE;
VIRTUAL VOID Draw() OVERRIDE;
VIRTUAL VOID Update() OVERRIDE;
private:
INT32 m_speed{};
UINT8 m_direction{};
private:
Engine *CONST m_engine;
SpriteRendererComponent* m_spriteRenderer;
};
} // namespace ia::iae::game

View File

@ -1,24 +0,0 @@
#pragma once
#include <IAEngine/Components/SoundEmitter.hpp>
#include <IAEngine/Components/AtlasRenderer.hpp>
#include <IAEngine/IAEngine.hpp>
namespace ia::iae::game
{
class TiledMap : public Node
{
public:
TiledMap(IN Engine* engine);
VIRTUAL VOID OnAdded(IN Scene *scene) OVERRIDE;
VIRTUAL VOID OnRemoved() OVERRIDE;
VIRTUAL VOID Draw() OVERRIDE;
VIRTUAL VOID Update() OVERRIDE;
private:
Engine* CONST m_engine;
RefPtr<SoundEmitterComponent> m_musicEmitter;
RefPtr<AtlasRendererComponent> m_atlasRenderer;
};
}

View File

@ -1,27 +0,0 @@
#pragma once
#include <IAEngine/Components/SoundEmitter.hpp>
#include <IAEngine/Components/SpriteRenderer.hpp>
#include <IAEngine/IAEngine.hpp>
namespace ia::iae::game
{
class Player : public Node
{
public:
Player(IN Engine *engine);
VIRTUAL VOID OnAdded(IN Scene *scene) OVERRIDE;
VIRTUAL VOID OnRemoved() OVERRIDE;
VIRTUAL VOID Draw() OVERRIDE;
VIRTUAL VOID Update() OVERRIDE;
private:
INT32 m_speed{};
UINT8 m_direction{};
private:
Engine *CONST m_engine;
SpriteRendererComponent* m_spriteRenderer;
};
} // namespace ia::iae::game

View File

@ -8,8 +8,6 @@ set(IAEngine_Sources
imp/cpp/Random.cpp imp/cpp/Random.cpp
imp/cpp/Texture.cpp imp/cpp/Texture.cpp
imp/cpp/ResourceManager.cpp
imp/cpp/Rendering/Camera.cpp imp/cpp/Rendering/Camera.cpp
imp/cpp/Rendering/Renderer.cpp imp/cpp/Rendering/Renderer.cpp
imp/cpp/Rendering/GPUBuffer.cpp imp/cpp/Rendering/GPUBuffer.cpp

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <IAEngine/Rendering/GPUTexture.hpp>
#include <IAEngine/Audio.hpp> #include <IAEngine/Audio.hpp>
#include <IAEngine/IAEngine.hpp> #include <IAEngine/IAEngine.hpp>
#include <IAEngine/Input.hpp> #include <IAEngine/Input.hpp>
@ -23,31 +25,24 @@
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <imgui.h>
#include <backends/imgui_impl_sdl3.h> #include <backends/imgui_impl_sdl3.h>
#include <imgui.h>
namespace ia::iae #define STB_IMAGE_IMPLEMENTATION
{ #include <stb_image.h>
struct EngineContext
{
SDL_Window *Window{};
SDL_Event Event{};
BOOL ShouldClose{false};
};
} // namespace ia::iae
namespace ia::iae namespace ia::iae
{ {
CONSTEXPR FLOAT32 GAME_UPDATE_INTERVAL = 1000.0f / 60.0f; CONSTEXPR FLOAT32 GAME_UPDATE_INTERVAL = 1000.0f / 60.0f;
Engine::Engine() : m_context(MakeRefPtr<EngineContext>()) SDL_Event g_event{};
{ FLOAT32 g_updateTimer{};
} BOOL g_shouldClose{false};
SDL_Window *g_windowHandle{};
Vector<RefPtr<GPUTexture>> g_gpuTextureRefs;
RefPtr<Scene> g_activeScene;
Engine::~Engine()
{
}
BOOL Engine::Initialize(IN CONST InitConfig &config) BOOL Engine::Initialize(IN CONST InitConfig &config)
{ {
@ -59,16 +54,17 @@ namespace ia::iae
return false; return false;
} }
if (!(m_context->Window = SDL_CreateWindow(config.GameName.c_str(), config.WindowWidth, config.WindowHeight, SDL_WINDOW_RESIZABLE))) if (!(g_windowHandle = SDL_CreateWindow(config.GameName.c_str(), config.WindowWidth, config.WindowHeight,
SDL_WINDOW_RESIZABLE)))
{ {
IAE_LOG_ERROR("Couldn't create SDL3 window: ", SDL_GetError()); IAE_LOG_ERROR("Couldn't create SDL3 window: ", SDL_GetError());
return false; return false;
} }
SDL_SetWindowResizable(m_context->Window, false); SDL_SetWindowResizable(g_windowHandle, false);
Time::Initialize(); Time::Initialize();
if (!Renderer::Initialize(this)) if (!Renderer::Initialize())
return false; return false;
Random::Initialize(); Random::Initialize();
@ -84,29 +80,30 @@ namespace ia::iae
{ {
IAE_LOG_INFO("Shutting down IAEngine"); IAE_LOG_INFO("Shutting down IAEngine");
m_resourceManager.reset(); for (auto &t : g_gpuTextureRefs)
t.reset();
Physics::Terminate();
Audio::Terminate();
Renderer::Terminate(); Renderer::Terminate();
Audio::Terminate();
Physics::Terminate();
SDL_DestroyWindow(m_context->Window); SDL_DestroyWindow(g_windowHandle);
SDL_Quit(); SDL_Quit();
} }
VOID Engine::BeginFrame() VOID Engine::BeginFrame()
{ {
SDL_PollEvent(&m_context->Event); SDL_PollEvent(&g_event);
if (m_context->Event.type == SDL_EVENT_QUIT) if (g_event.type == SDL_EVENT_QUIT)
m_context->ShouldClose = true; g_shouldClose = true;
ProcessEvents(); ProcessEvents();
m_updateTimer += Time::GetFrameDeltaTime(); g_updateTimer += Time::GetFrameDeltaTime();
if (m_updateTimer >= GAME_UPDATE_INTERVAL) if (g_updateTimer >= GAME_UPDATE_INTERVAL)
{ {
UpdateGame(); UpdateGame();
while (m_updateTimer >= GAME_UPDATE_INTERVAL) while (g_updateTimer >= GAME_UPDATE_INTERVAL)
m_updateTimer -= GAME_UPDATE_INTERVAL; g_updateTimer -= GAME_UPDATE_INTERVAL;
} }
Renderer::BeginFrame(); Renderer::BeginFrame();
RenderGame(); RenderGame();
@ -120,41 +117,72 @@ namespace ia::iae
BOOL Engine::ShouldClose() BOOL Engine::ShouldClose()
{ {
return m_context->ShouldClose; return g_shouldClose;
} }
VOID Engine::ProcessEvents() VOID Engine::ProcessEvents()
{ {
ImGui_ImplSDL3_ProcessEvent(&m_context->Event); ImGui_ImplSDL3_ProcessEvent(&g_event);
Input::OnEvent(&m_context->Event); Input::OnEvent(&g_event);
} }
VOID Engine::UpdateGame() VOID Engine::UpdateGame()
{ {
Physics::Update(); Physics::Update();
if B_LIKELY (m_activeScene) if B_LIKELY (g_activeScene)
m_activeScene->Update(); g_activeScene->Update();
} }
VOID Engine::RenderGame() VOID Engine::RenderGame()
{ {
if B_LIKELY (m_activeScene) if B_LIKELY (g_activeScene)
m_activeScene->Draw(); g_activeScene->Draw();
} }
VOID Engine::ChangeScene(IN RefPtr<Scene> scene) VOID Engine::ChangeScene(IN RefPtr<Scene> scene)
{ {
m_activeScene = scene; g_activeScene = scene;
} }
} // namespace ia::iae
RefPtr<Scene> Engine::CreateScene()
{ namespace ia::iae
return MakeRefPtr<Scene>(this); {
} RefPtr<Scene> Engine::CreateScene()
{
PVOID Engine::GetWindowHandle() CONST return MakeRefPtr<Scene>();
{ }
return m_context->Window;
Texture Engine::CreateTexture(IN CONST Vector<UINT8> &encodedData)
{
return CreateTexture(encodedData.data(), encodedData.size());
}
Texture Engine::CreateTexture(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
{
INT32 w, h, nrChannels;
const auto pixels = stbi_load_from_memory(encodedData, encodedDataSize, &w, &h, &nrChannels, STBI_rgb_alpha);
if (!pixels)
THROW_INVALID_DATA("Failed to decode the provided image data");
const auto result = CreateTexture((PCUINT8) pixels, w, h);
STBI_FREE(pixels);
return result;
}
Texture Engine::CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
{
const auto t = GPUTexture::Create(rgbaData, width, height);
g_gpuTextureRefs.pushBack(t);
return Texture(t->GetHandle(), width, height);
}
Sound Engine::CreateSound(IN PCUINT8 audioData, IN SIZE_T audioDataSize)
{
return Audio::CreateSound(audioData, audioDataSize);
}
Sound Engine::CreateSound(IN CONST Vector<UINT8> &audioData)
{
return CreateSound(audioData.data(), audioData.size());
} }
} // namespace ia::iae } // namespace ia::iae

View File

@ -36,49 +36,13 @@ namespace ia::iae
VOID Node::Draw() VOID Node::Draw()
{ {
BOOL drew = false;
for (auto &n : m_children) for (auto &n : m_children)
{
if (((INT32) n->GetPosition().z) >= 0)
continue;
n->Draw(); n->Draw();
}
if(((INT32) GetPosition().z) < 0)
{
for (auto &c : m_components) for (auto &c : m_components)
c->Draw(); 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() VOID Node::Update()
{ {
for (auto &c : m_components) for (auto &c : m_components)

View File

@ -29,11 +29,12 @@
namespace ia::iae namespace ia::iae
{ {
EXTERN SDL_Window *g_windowHandle;
INT32 Renderer::s_width{}; INT32 Renderer::s_width{};
INT32 Renderer::s_height{}; INT32 Renderer::s_height{};
Vector<Renderer::DebugUIWindow> Renderer::s_debugUIWindows; Vector<Renderer::DebugUIWindow> Renderer::s_debugUIWindows;
SDL_Window *g_windowHandle{};
SDL_GPUDevice *g_gpuDevice{}; SDL_GPUDevice *g_gpuDevice{};
// Render State // Render State
@ -53,12 +54,11 @@ namespace ia::iae
glm::mat4 matView{1.0f}; glm::mat4 matView{1.0f};
glm::mat4 matModel{1.0f}; glm::mat4 matModel{1.0f};
BOOL Renderer::Initialize(IN Engine *engine) BOOL Renderer::Initialize()
{ {
g_windowHandle = (SDL_Window *) engine->GetWindowHandle();
SDL_GetWindowSizeInPixels(g_windowHandle, &s_width, &s_height); SDL_GetWindowSizeInPixels(g_windowHandle, &s_width, &s_height);
if (!(g_gpuDevice = SDL_CreateGPUDevice(SDL_GPU_SHADERFORMAT_SPIRV, engine->IsDebugMode, nullptr))) if (!(g_gpuDevice = SDL_CreateGPUDevice(SDL_GPU_SHADERFORMAT_SPIRV, Engine::IsDebugMode, nullptr)))
{ {
IAE_LOG_ERROR("Couldn't create SDL3 GPU Device: ", SDL_GetError()); IAE_LOG_ERROR("Couldn't create SDL3 GPU Device: ", SDL_GetError());
return false; return false;

View File

@ -1,60 +0,0 @@
// 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/>.
#include <IAEngine/IAEngine.hpp>
#include <IAEngine/Rendering/GPUTexture.hpp>
#include <IAEngine/ResourceManager.hpp>
#include <SDL3/SDL.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
namespace ia::iae
{
ResourceManager::ResourceManager(IN Engine *engine) : m_engine(engine)
{
}
ResourceManager::~ResourceManager()
{
for(auto& t: m_textures)
t.reset();
}
RefPtr<Texture> ResourceManager::CreateTexture(IN CONST Span<CONST UINT8> &encodedData)
{
return CreateTexture(encodedData.data(), encodedData.size());
}
RefPtr<Texture> ResourceManager::CreateTexture(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
{
INT32 w, h, nrChannels;
const auto pixels = stbi_load_from_memory(encodedData, encodedDataSize, &w, &h, &nrChannels, STBI_rgb_alpha);
if (!pixels)
THROW_INVALID_DATA("Failed to decode the provided image data");
const auto result = CreateTexture((PCUINT8) pixels, w, h);
STBI_FREE(pixels);
return result;
}
RefPtr<Texture> ResourceManager::CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
{
const auto t = GPUTexture::Create(rgbaData, width, height);
m_textures.pushBack(t);
return MakeRefPtr<Texture>(t->GetHandle(), width, height);
}
} // namespace ia::iae

View File

@ -18,41 +18,12 @@
namespace ia::iae namespace ia::iae
{ {
Scene::Scene(IN Engine *engine) : m_engine(engine)
{
}
Scene::~Scene()
{
}
VOID Scene::Draw() VOID Scene::Draw()
{ {
for (auto &n : m_nodes) for (auto &n : m_nodes)
{
if (((INT32) n->GetPosition().z) >= 0)
continue;
n->Draw(); 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() VOID Scene::Update()
{ {
for (auto &n : m_nodes) for (auto &n : m_nodes)

View File

@ -17,13 +17,17 @@
#include <IAEngine/IAEngine.hpp> #include <IAEngine/IAEngine.hpp>
#include <IAEngine/Texture.hpp> #include <IAEngine/Texture.hpp>
#include <IAEngine/Rendering/Renderer.hpp>
#include <IAEngine/Rendering/Mesh/Quad.hpp> #include <IAEngine/Rendering/Mesh/Quad.hpp>
#include <IAEngine/Rendering/Renderer.hpp>
namespace ia::iae namespace ia::iae
{ {
Texture::Texture(IN Handle handle,IN INT32 width, IN INT32 height): Texture::Texture()
m_handle(handle), m_size({(FLOAT32)width, (FLOAT32)height, 1.0f}) {
}
Texture::Texture(IN Handle handle, IN INT32 width, IN INT32 height)
: m_handle(handle), m_size({(FLOAT32) width, (FLOAT32) height, 1.0f})
{ {
} }

View File

@ -16,16 +16,13 @@
#pragma once #pragma once
#include <IAEngine/Nodes/Node.hpp> #include <IAEngine/Audio.hpp>
#include <IAEngine/Texture.hpp> #include <IAEngine/Texture.hpp>
#include <IAEngine/Rendering/Renderer.hpp>
#include <IAEngine/ResourceManager.hpp>
#include <IAEngine/Scene.hpp> #include <IAEngine/Scene.hpp>
#include <IAEngine/Rendering/Renderer.hpp>
namespace ia::iae namespace ia::iae
{ {
struct EngineContext;
class Engine class Engine
{ {
public: public:
@ -43,41 +40,28 @@ namespace ia::iae
#endif #endif
public: public:
Engine(); STATIC BOOL Initialize(IN CONST InitConfig &config);
~Engine(); STATIC VOID Terminate();
BOOL Initialize(IN CONST InitConfig &config); STATIC VOID BeginFrame();
VOID Terminate(); STATIC VOID EndFrame();
STATIC BOOL ShouldClose();
VOID BeginFrame(); STATIC VOID ChangeScene(IN RefPtr<Scene> scene);
VOID EndFrame();
BOOL ShouldClose();
template<typename _class_type> _class_type *RegisterResourceManager();
public: public:
RefPtr<Scene> CreateScene(); STATIC RefPtr<Scene> CreateScene();
VOID ChangeScene(IN RefPtr<Scene> scene); STATIC Texture CreateTexture(IN CONST Vector<UINT8> &encodedData);
STATIC Texture CreateTexture(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
STATIC Texture CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
public: STATIC Sound CreateSound(IN CONST Vector<UINT8> &audioData);
PVOID GetWindowHandle() CONST; STATIC Sound CreateSound(IN PCUINT8 audioData, IN SIZE_T audioDataSize);
private: private:
VOID ProcessEvents(); STATIC VOID ProcessEvents();
VOID UpdateGame(); STATIC VOID UpdateGame();
VOID RenderGame(); STATIC VOID RenderGame();
private:
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 } // namespace ia::iae

View File

@ -20,7 +20,6 @@
namespace ia::iae namespace ia::iae
{ {
class Engine;
class Camera2D; class Camera2D;
class Renderer class Renderer
@ -34,7 +33,7 @@ namespace ia::iae
}; };
public: public:
STATIC BOOL Initialize(IN Engine *engine); STATIC BOOL Initialize();
STATIC VOID Terminate(); STATIC VOID Terminate();
public: public:

View File

@ -1,53 +0,0 @@
// 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/Audio.hpp>
#include <IAEngine/Texture.hpp>
namespace ia::iae
{
class Engine;
class ResourceManager
{
public:
ResourceManager(IN Engine *engine);
~ResourceManager();
RefPtr<Texture> CreateTexture(IN CONST Span<CONST UINT8> &encodedData);
RefPtr<Texture> CreateTexture(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
RefPtr<Texture> CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
public:
Sound CreateSound(IN PCUINT8 audioData, IN SIZE_T audioDataSize)
{
return Audio::CreateSound(audioData, audioDataSize);
}
Sound CreateSound(IN CONST Vector<UINT8> &audioData)
{
return CreateSound(audioData.data(), audioData.size());
}
protected:
Engine *CONST m_engine;
Vector<RefPtr<class GPUTexture>> m_textures;
friend class Engine;
};
} // namespace ia::iae

View File

@ -20,14 +20,9 @@
namespace ia::iae namespace ia::iae
{ {
class Engine;
class Scene class Scene
{ {
public: public:
Scene(IN Engine* engine);
~Scene();
VOID Draw(); VOID Draw();
VOID Update(); VOID Update();
@ -42,7 +37,6 @@ namespace ia::iae
} }
private: private:
Engine* CONST m_engine;
Vector<RefPtr<Node>> m_nodes; Vector<RefPtr<Node>> m_nodes;
}; };
} // namespace ia::iae } // namespace ia::iae

View File

@ -24,6 +24,7 @@ namespace ia::iae
{ {
public: public:
Texture(IN Handle handle, IN INT32 width, IN INT32 height); Texture(IN Handle handle, IN INT32 width, IN INT32 height);
Texture();
~Texture(); ~Texture();
public: public:
@ -42,7 +43,7 @@ namespace ia::iae
} }
private: private:
CONST Handle m_handle{}; Handle m_handle{INVALID_HANDLE};
CONST glm::vec3 m_size; glm::vec3 m_size{};
}; };
} // namespace ia::iae } // namespace ia::iae