This commit is contained in:
Isuru Samarathunga
2025-11-12 23:07:53 +05:30
parent 9d6f525b81
commit 9ff39d7245
18 changed files with 613 additions and 345 deletions

View File

@ -1,6 +1,7 @@
---
BasedOnStyle: Microsoft
IndentWidth: 4
SortIncludes: false
---
Language: Cpp
FixNamespaceComments: true

View File

@ -3,7 +3,8 @@ set(SRC_FILES
"imp/cpp/Scene.cpp"
"imp/cpp/GameData.cpp"
"imp/cpp/AssetManager.cpp"
"imp/cpp/Asset/AssetManager.cpp"
#"imp/cpp/EmbeddedResources.cpp"
)

View File

@ -14,10 +14,9 @@
// 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/AssetManager.hpp>
#include <IAEngine/Asset/AssetManager.hpp>
#include <IAEngine/IAEngine.hpp>
#include <SDL3/SDL_iostream.h>
#define STB_IMAGE_IMPLEMENTATION
@ -29,9 +28,13 @@
namespace ia::iae
{
String AssetManager::s_assetDirectory;
Vector<IAsset *> AssetManager::s_assets;
Map<String, IAsset *> AssetManager::s_assetNames;
Handle CreateTextureFromFile(IN PCCHAR path, IN INT32 tileWidth = -1, IN INT32 tileHeight = -1)
{
const auto data = IAEngine::GetAssetManager()->ReadBinaryAsset(path);
const auto data = AssetManager::ReadBinaryAsset(path);
INT32 w, h, n;
auto pixels = stbi_load_from_memory(data.data(), data.size(), &w, &h, &n, STBI_rgb_alpha);
@ -49,18 +52,18 @@ namespace ia::iae
VOID AssetManager::Terminate()
{
for (SIZE_T i = 0; i < m_assets.size(); i++)
DestroyAsset(m_assets[i]);
for (SIZE_T i = 0; i < s_assets.size(); i++)
DestroyAsset(s_assets[i]);
}
VOID AssetManager::SetAssetDirectory(IN CONST String &path)
{
m_assetDirectory = path;
s_assetDirectory = path;
}
String AssetManager::ReadTextAsset(IN CONST String &path)
{
const auto t = BuildString(m_assetDirectory, "/", path);
const auto t = BuildString(s_assetDirectory, "/", path);
SDL_IOStream *f = SDL_IOFromFile(t.c_str(), "r");
if (!f)
THROW_FILE_OPEN_READ(t);
@ -76,7 +79,7 @@ namespace ia::iae
Vector<UINT8> AssetManager::ReadBinaryAsset(IN CONST String &path)
{
const auto t = BuildString(m_assetDirectory, "/", path);
const auto t = BuildString(s_assetDirectory, "/", path);
SDL_IOStream *f = SDL_IOFromFile(t.c_str(), "rb");
if (!f)
THROW_FILE_OPEN_READ(t);
@ -89,64 +92,61 @@ namespace ia::iae
return result;
}
Asset_Plugin *AssetManager::LoadPlugin(IN CONST String &path)
Asset_Texture *AssetManager::LoadTexture(IN CONST String &path)
{
auto lib = DynamicLib::Load(BuildString(m_assetDirectory, "/Plugins"), path);
auto t = new Asset_Plugin();
t->OnInitialize = lib.GetFunction<VOID (*)()>("Plugin_OnInitialize");
t->OnTerminate = lib.GetFunction<VOID (*)()>("Plugin_OnTerminate");
t->OnDebugDraw = lib.GetFunction<VOID (*)()>("Plugin_OnDebugDraw");
t->OnFixedUpdate = lib.GetFunction<VOID (*)()>("Plugin_OnFixedUpdate");
t->OnUpdate = lib.GetFunction<VOID (*)(IN FLOAT32 deltaTime)>("Plugin_OnUpdate");
const auto t = new Asset_Sprite(CreateTextureFromFile(path.c_str()));
s_assets.pushBack(t);
return t;
}
Asset_Sprite *AssetManager::CreateSprite(IN CONST String &path)
Asset_Sprite *AssetManager::LoadSprite(IN CONST String &path)
{
const auto t = new Asset_Sprite();
t->m_texture = CreateTextureFromFile(path.c_str());
m_assets.pushBack(t);
const auto t = new Asset_Sprite(CreateTextureFromFile(path.c_str()));
s_assets.pushBack(t);
return t;
}
Asset_SpriteSheet *AssetManager::LoadSpriteSheet(IN CONST String &path)
{
// const auto t = new Asset_SpriteSheet();
// t->m_frameCounts = frameCounts;
// t->m_texture = CreateTextureFromFile(path.c_str(), spriteWidth, spriteHeight);
// s_assets.pushBack(t);
// return t;
return nullptr;
}
Asset_TileSheet *AssetManager::LoadTileSheet(IN CONST String &path)
{
return nullptr;
}
IAsset_Package *AssetManager::LoadPackage(IN CONST String &path)
{
return nullptr;
}
Asset_Texture *AssetManager::CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
{
return nullptr;
}
Asset_Sprite *AssetManager::CreateSprite(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
{
const auto t = new Asset_Sprite();
t->m_texture = RDC::CreateImage(rgbaData, width, height);
m_assets.pushBack(t);
return t;
}
Asset_SpriteSheet *AssetManager::CreateSpriteSheet(IN CONST Vector<Vector<Handle>> &animations)
{
THROW_NOT_IMPLEMENTED();
return nullptr;
}
Asset_SpriteSheet *AssetManager::CreateSpriteSheet(IN CONST String &path, IN INT32 spriteWidth,
Asset_SpriteSheet *AssetManager::CreateSpriteSheet(IN CONST Asset_Texture *texture, IN INT32 spriteWidth,
IN INT32 spriteHeight, IN CONST Vector<INT32> &frameCounts)
{
const auto t = new Asset_SpriteSheet();
t->m_frameCounts = frameCounts;
t->m_texture = CreateTextureFromFile(path.c_str(), spriteWidth, spriteHeight);
m_assets.pushBack(t);
return t;
return nullptr;
}
Asset_TileSheet *AssetManager::CreateTileSheet(IN CONST String &path, IN INT32 tileWidth, IN INT32 tileHeight)
Asset_TileSheet *AssetManager::CreateTileSheet(IN CONST Asset_Texture *texture, IN INT32 tileWidth,
IN INT32 tileHeight)
{
const auto t = new Asset_TileSheet();
t->m_texture = CreateTextureFromFile(path.c_str(), tileWidth, tileHeight);
m_assets.pushBack(t);
return t;
}
Asset_TileSheet *AssetManager::CreateTileSheet(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height,
IN INT32 tileWidth, IN INT32 tileHeight)
{
const auto t = new Asset_TileSheet();
t->m_texture = RDC::CreateImage(rgbaData, width, height, width / tileWidth, height / tileHeight);
m_assets.pushBack(t);
const auto t = new Asset_TileSheet(texture->m_handle, tileWidth, tileHeight);
s_assets.pushBack(t);
return t;
}
@ -155,30 +155,29 @@ namespace ia::iae
asset->Destroy();
delete asset;
for (auto &t : m_assets)
for (auto &t : s_assets)
if (t == asset)
t = nullptr;
for (auto &t : m_assetNames)
for (auto &t : s_assetNames)
if (t->Value == asset)
t->Value = nullptr;
}
IAsset *AssetManager::GetAssetByName(IN CONST String &name)
{
return m_assetNames[name];
return s_assetNames[name];
}
VOID AssetManager::AssignAssetName(IN IAsset *asset, IN CONST String &name)
{
m_assetNames[name] = asset;
s_assetNames[name] = asset;
}
Asset_Scene *AssetManager::CreateScene(IN IVec2 extent)
{
const auto t = new Asset_Scene();
t->m_scene.SetExtent(extent);
m_assets.pushBack(t);
const auto t = new Asset_Scene(new Scene(extent));
s_assets.pushBack(t);
return t;
}
} // namespace ia::iae
@ -193,6 +192,22 @@ namespace ia::iae
{
}
VOID Asset_Texture::Compile()
{
}
VOID Asset_Texture::Destroy()
{
}
VOID Asset_TileSheet::Compile()
{
}
VOID Asset_TileSheet::Destroy()
{
}
VOID Asset_Sprite::Compile()
{
}
@ -224,6 +239,14 @@ namespace ia::iae
VOID Asset_Plugin::Destroy()
{
}
VOID IAsset_Package::Compile()
{
}
VOID IAsset_Package::Destroy()
{
}
} // namespace ia::iae
#include <zlib.h>

View File

@ -16,7 +16,6 @@
#include <GameData.hpp>
#include <IAEngine/IAEngine.hpp>
#include <IAEngine/AssetManager.hpp>
#include <ConfigData/ConfigData.hpp>
@ -46,7 +45,7 @@ namespace ia::iae
BOOL GameData::LoadSceneData()
{
for (const auto &entry : std::filesystem::directory_iterator(BuildString(IAEngine::GetAssetManager()->GetAssetDirectory(), "/Scenes/").c_str()))
for (const auto &entry : std::filesystem::directory_iterator(BuildString(AssetManager::GetAssetDirectory(), "/Scenes/").c_str()))
{
const auto scene = ParseScene(entry.path().string().c_str());
if (!scene)
@ -60,7 +59,7 @@ namespace ia::iae
BOOL GameData::LoadAssetData()
{
auto xml = ConfigData::LoadFromFile(BuildString(IAEngine::GetAssetManager()->GetAssetDirectory(), "/Assets.xml"));
auto xml = ConfigData::LoadFromFile(BuildString(AssetManager::GetAssetDirectory(), "/Assets.xml"));
if (!xml)
return false;
@ -86,8 +85,8 @@ namespace ia::iae
}
else if (!strcmp(entry.name(), "TileSheet"))
{
IAEngine::GetAssetManager()->AssignAssetName(
IAEngine::GetAssetManager()->CreateTileSheet(entry.attribute("path").as_string(),
AssetManager::AssignAssetName(
AssetManager::CreateTileSheet(entry.attribute("path").as_string(),
entry.attribute("tileWidth").as_int(),
entry.attribute("tileHeight").as_int()),
entry.attribute("name").as_string());
@ -110,27 +109,27 @@ namespace ia::iae
return nullptr;
const auto extent = IVec2{extentNode.attribute("width").as_int(), extentNode.attribute("height").as_int()};
auto scene = IAEngine::GetAssetManager()->CreateScene(extent);
auto scene = AssetManager::CreateScene(extent);
for (const auto &child : xml->Children())
{
if (!strcmp(child.name(), "Assets"))
{
for (const auto &r : child.children())
scene->GetScene().AddReferencedResources(IAEngine::GetAssetManager()->GetAssetByName<IAsset>(r.attribute("name").as_string()));
scene->GetHandle()->AddReferencedResources(AssetManager::GetAssetByName<IAsset>(r.attribute("name").as_string()));
}
else if (!strcmp(child.name(), "Nodes"))
{
}
else if (!strcmp(child.name(), "Grid"))
{
ParseSceneGrid(&scene->GetScene(), &child);
ParseSceneGrid(scene->GetHandle(), &child);
}
else
THROW_INVALID_DATA();
}
IAEngine::GetAssetManager()->AssignAssetName(scene, xml->Name());
AssetManager::AssignAssetName(scene, xml->Name());
if (!g_entryScene)
g_entryScene = scene;
@ -156,7 +155,7 @@ namespace ia::iae
return;
auto& cell = scene->GetGridCell(tileCursorX, tileCursorY);
cell.TileSheet = IAEngine::GetAssetManager()->GetAssetByName<Asset_TileSheet>(cellNode.attribute("tileSheet").as_string());
cell.TileSheet = AssetManager::GetAssetByName<Asset_TileSheet>(cellNode.attribute("tileSheet").as_string());
cell.TileIndex.x = cellNode.attribute("tileX").as_int();
cell.TileIndex.y = cellNode.attribute("tileY").as_int();
cell.CollisionMask = cellNode.attribute("collisionMask").as_ullong();

View File

@ -35,9 +35,6 @@ namespace ia::iae
Vector<Asset_Plugin *> g_plugins;
AssetManager* g_assetManager{};
AssetManager* g_defaultAssetManager{};
BOOL g_isHeadlessMode = false;
INT32 Run(IN CONST String &name, IN CONST String &packageName, IN CONST String &developerName,
@ -118,20 +115,18 @@ namespace ia::iae
RDC::Initialize(IVec2{g_designViewport.x, g_designViewport.y}, g_windowHandle, g_isDebugMode);
g_defaultAssetManager = new AssetManager();
g_assetManager = g_defaultAssetManager;
g_assetManager->SetAssetDirectory(assetDirectory);
AssetManager::SetAssetDirectory(assetDirectory);
GameData::Initialize();
ChangeActiveScene(GameData::GetEntryScene()
? GameData::GetEntryScene()
: g_assetManager->CreateScene({g_designViewport.x, g_designViewport.y}));
: AssetManager::CreateScene({g_designViewport.x, g_designViewport.y}));
Game_OnInitialize();
for (auto &p : g_plugins)
p->OnInitialize();
//for (auto &p : g_plugins)
// p->OnInitialize();
}
VOID IAEngine::__InitializeHeadless(IN CONST String& assetDirectory)
@ -141,78 +136,74 @@ namespace ia::iae
if (!g_designViewport.x || !g_designViewport.y)
g_designViewport = {800, 600};
g_defaultAssetManager = new AssetManager();
g_assetManager = g_defaultAssetManager;
g_assetManager->SetAssetDirectory(assetDirectory);
AssetManager::SetAssetDirectory(assetDirectory);
GameData::Initialize();
ChangeActiveScene(GameData::GetEntryScene()
? GameData::GetEntryScene()
: g_assetManager->CreateScene({g_designViewport.x, g_designViewport.y}));
: AssetManager::CreateScene({g_designViewport.x, g_designViewport.y}));
Game_OnInitialize();
for (auto &p : g_plugins)
p->OnInitialize();
//for (auto &p : g_plugins)
// p->OnInitialize();
}
VOID IAEngine::__Terminate()
{
for (auto &p : g_plugins)
p->OnTerminate();
//for (auto &p : g_plugins)
// p->OnTerminate();
Game_OnTerminate();
GameData::Terminate();
delete g_defaultAssetManager;
RDC::Terminate();
}
VOID IAEngine::__RenderToWindow()
{
g_activeScene->GetScene().OnDraw();
g_activeScene->GetHandle()->OnDraw();
RDC::RenderToWindow();
g_activeScene->GetScene().OnDebugDraw();
g_activeScene->GetHandle()->OnDebugDraw();
Game_OnDebugDraw();
for (auto &p : g_plugins)
p->OnDebugDraw();
//for (auto &p : g_plugins)
// p->OnDebugDraw();
}
VOID IAEngine::__RenderToTexture(IN PVOID textureHandle)
{
g_activeScene->GetScene().OnDraw();
g_activeScene->GetHandle()->OnDraw();
RDC::RenderToTexture((SDL_GPUTexture *) textureHandle);
g_activeScene->GetScene().OnDebugDraw();
g_activeScene->GetHandle()->OnDebugDraw();
Game_OnDebugDraw();
for (auto &p : g_plugins)
p->OnDebugDraw();
//for (auto &p : g_plugins)
// p->OnDebugDraw();
}
VOID IAEngine::__Update()
{
FLOAT32 deltaTime = 0;
g_activeScene->GetScene().OnUpdate(deltaTime);
g_activeScene->GetHandle()->OnUpdate(deltaTime);
Game_OnUpdate(deltaTime);
for (auto &p : g_plugins)
p->OnUpdate(deltaTime);
//for (auto &p : g_plugins)
// p->OnUpdate(deltaTime);
}
VOID IAEngine::__FixedUpdate()
{
g_activeScene->GetScene().OnFixedUpdate();
g_activeScene->GetHandle()->OnFixedUpdate();
Game_OnFixedUpdate();
for (auto &p : g_plugins)
p->OnFixedUpdate();
//for (auto &p : g_plugins)
// p->OnFixedUpdate();
}
VOID IAEngine::__ProcessEvent(IN PVOID _event)
@ -224,16 +215,6 @@ namespace ia::iae
{
g_plugins.pushBack(plugin);
}
AssetManager* IAEngine::GetAssetManager()
{
return g_assetManager;
}
VOID IAEngine::SetAssetManager(IN AssetManager *instance)
{
g_assetManager = instance;
}
} // namespace ia::iae
namespace ia::iae
@ -241,21 +222,21 @@ namespace ia::iae
VOID IAEngine::DrawTile(IN Asset_TileSheet *tileSheet, IN INT32 tileIndexX, IN INT32 tileIndexY, IN Vec2 position,
IN Vec2 scale, IN FLOAT32 rotation, IN BOOL flipH, IN BOOL flipV, IN Vec2 uvOffset)
{
RDC::DrawSpriteTopLeft(tileSheet->GetTexture(), tileIndexX, tileIndexY, position, scale, rotation, flipH, flipV,
RDC::DrawSpriteTopLeft(tileSheet->GetHandle(), tileIndexX, tileIndexY, position, scale, rotation, flipH, flipV,
uvOffset);
}
VOID IAEngine::DrawSprite(IN Asset_Sprite *sprite, IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation,
IN BOOL flipH, IN BOOL flipV, IN Vec2 uvOffset)
{
RDC::DrawSpriteTopLeft(sprite->GetTexture(), 0, 0, position, scale, rotation, flipH, flipV, uvOffset);
RDC::DrawSpriteTopLeft(sprite->GetHandle(), 0, 0, position, scale, rotation, flipH, flipV, uvOffset);
}
VOID IAEngine::DrawSprite(IN Asset_SpriteSheet *spriteSheet, IN INT32 animationIndex, IN INT32 frameIndex,
IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation, IN BOOL flipH, IN BOOL flipV,
IN Vec2 uvOffset)
{
RDC::DrawSpriteTopLeft(spriteSheet->GetTexture(), frameIndex, animationIndex, position, scale, rotation, flipH,
RDC::DrawSpriteTopLeft(spriteSheet->GetHandle(), frameIndex, animationIndex, position, scale, rotation, flipH,
flipV, uvOffset);
}
} // namespace ia::iae

View File

@ -16,7 +16,7 @@
#pragma once
#include <IAEngine/AssetManager.hpp>
#include <IAEngine/Asset/AssetManager.hpp>
namespace ia::iae
{

View File

@ -0,0 +1,91 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Asset/Package.hpp>
#include <IAEngine/Asset/Plugin.hpp>
#include <IAEngine/Asset/Scene.hpp>
#include <IAEngine/Asset/Sound.hpp>
#include <IAEngine/Asset/Sprite.hpp>
#include <IAEngine/Asset/SpriteSheet.hpp>
#include <IAEngine/Asset/Texture.hpp>
#include <IAEngine/Asset/TileSheet.hpp>
namespace ia::iae
{
class AssetManager final
{
public:
STATIC VOID SetAssetDirectory(IN CONST String &path);
STATIC String ReadTextAsset(IN CONST String &path);
STATIC Vector<UINT8> ReadBinaryAsset(IN CONST String &path);
public:
STATIC Asset_Texture *LoadTexture(IN CONST String &path);
STATIC Asset_Sprite *LoadSprite(IN CONST String &path);
STATIC Asset_SpriteSheet *LoadSpriteSheet(IN CONST String &path);
STATIC Asset_TileSheet *LoadTileSheet(IN CONST String &path);
STATIC IAsset_Package *LoadPackage(IN CONST String &path);
STATIC Asset_Scene *CreateScene(IN IVec2 extent);
STATIC Asset_Texture *CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
STATIC Asset_Sprite *CreateSprite(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
STATIC Asset_SpriteSheet *CreateSpriteSheet(IN CONST Asset_Texture *texture, IN INT32 spriteWidth,
IN INT32 spriteHeight, IN CONST Vector<INT32> &frameCounts);
STATIC Asset_TileSheet *CreateTileSheet(IN CONST Asset_Texture *texture, IN INT32 tileWidth,
IN INT32 tileHeight);
STATIC VOID DestroyAsset(IN IAsset *asset);
STATIC VOID AssignAssetName(IN IAsset *asset, IN CONST String &name);
template<typename AssetType>
requires std::is_base_of<IAsset, AssetType>::value
STATIC AssetType *GetAssetByName(IN CONST String &name);
public:
STATIC Vector<UINT8> Inflate(IN PCUINT8 data, IN SIZE_T dataSize);
STATIC Vector<UINT8> Deflate(IN PCUINT8 data, IN SIZE_T dataSize);
public:
STATIC CONST String &GetAssetDirectory()
{
return s_assetDirectory;
}
protected:
STATIC String s_assetDirectory;
STATIC Vector<IAsset *> s_assets;
STATIC Map<String, IAsset *> s_assetNames;
protected:
STATIC IAsset *GetAssetByName(IN CONST String &name);
private:
STATIC VOID Initialize();
STATIC VOID Terminate();
friend class IAEngine;
};
template<typename AssetType>
requires std::is_base_of<IAsset, AssetType>::value
AssetType *AssetManager::GetAssetByName(IN CONST String &name)
{
return (AssetType *) GetAssetByName(name);
}
} // namespace ia::iae

View File

@ -0,0 +1,49 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Base.hpp>
namespace ia::iae
{
enum class EAssetType
{
INVALID,
TEXTURE,
SPRITE,
TILESHEET,
SPRITESHEET,
SOUND,
SCENE,
PLUGIN,
PACKAGE
};
class IAsset
{
public:
IAsset(IN EAssetType type);
VIRTUAL ~IAsset();
PURE_VIRTUAL(VOID Compile());
PURE_VIRTUAL(VOID Destroy());
protected:
CONST EAssetType m_type;
};
}

View File

@ -0,0 +1,49 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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 <IACore/StreamReader.hpp>
#include <IAEngine/Asset/IAsset.hpp>
namespace ia::iae
{
class IAsset_Package : public IAsset
{
public:
struct AssetRef
{
String Path;
Handle RefHandle{INVALID_HANDLE};
EAssetType Type{EAssetType::INVALID};
};
public:
IAsset_Package(IN Handle handle) : IAsset(EAssetType::PACKAGE)
{
}
VIRTUAL VOID Compile();
VIRTUAL VOID Destroy();
PURE_VIRTUAL(Vector<AssetRef>::const_iterator ListAssets());
PURE_VIRTUAL(RefPtr<IStreamReader> GetAssetData(IN Handle refHandle));
protected:
friend class AssetManager;
};
} // namespace ia::iae

View File

@ -0,0 +1,40 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Asset/IAsset.hpp>
namespace ia::iae
{
class Asset_Plugin : public IAsset
{
public:
Asset_Plugin(IN Handle handle) : IAsset(EAssetType::PLUGIN), m_handle(handle)
{
}
VIRTUAL VOID Compile();
VIRTUAL VOID Destroy();
INLINE Handle GetHandle();
protected:
CONST Handle m_handle;
friend class AssetManager;
};
} // namespace ia::iae

View File

@ -0,0 +1,46 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Asset/IAsset.hpp>
#include <IAEngine/Scene.hpp>
namespace ia::iae
{
class Asset_Scene : public IAsset
{
public:
Asset_Scene(IN Scene* handle) : IAsset(EAssetType::SCENE), m_handle(handle)
{
}
VIRTUAL VOID Compile();
VIRTUAL VOID Destroy();
INLINE Scene* GetHandle();
protected:
Scene* CONST m_handle;
friend class AssetManager;
};
INLINE Scene* Asset_Scene::GetHandle()
{
return m_handle;
}
} // namespace ia::iae

View File

@ -0,0 +1,45 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Asset/IAsset.hpp>
namespace ia::iae
{
class Asset_Sound : public IAsset
{
public:
Asset_Sound(IN Handle handle) : IAsset(EAssetType::SOUND), m_handle(handle)
{
}
VIRTUAL VOID Compile();
VIRTUAL VOID Destroy();
INLINE Handle GetHandle();
protected:
CONST Handle m_handle;
friend class AssetManager;
};
INLINE Handle Asset_Sound::GetHandle()
{
return m_handle;
}
} // namespace ia::iae

View File

@ -0,0 +1,36 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Asset/Texture.hpp>
namespace ia::iae
{
class Asset_Sprite : public Asset_Texture
{
public:
Asset_Sprite(IN Handle textureHandle) : Asset_Texture(textureHandle, EAssetType::SPRITE)
{
}
VIRTUAL VOID Compile();
VIRTUAL VOID Destroy();
protected:
friend class AssetManager;
};
}

View File

@ -0,0 +1,50 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Asset/Texture.hpp>
namespace ia::iae
{
class Asset_SpriteSheet : public Asset_Texture
{
public:
struct AnimationDesc
{
INT32 StartRow{};
INT32 FrameCount{};
};
public:
Asset_SpriteSheet(IN Handle textureHandle, IN INT32 frameWidth, IN INT32 frameHeight,
IN Map<String, AnimationDesc> &&animations)
: Asset_Texture(textureHandle, EAssetType::SPRITESHEET), m_frameWidth(frameWidth), m_frameHeight(frameHeight),
m_animations(IA_MOVE(animations))
{
}
VIRTUAL VOID Compile();
VIRTUAL VOID Destroy();
protected:
CONST INT32 m_frameWidth;
CONST INT32 m_frameHeight;
CONST Map<String, AnimationDesc> m_animations;
friend class AssetManager;
};
} // namespace ia::iae

View File

@ -0,0 +1,49 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Asset/IAsset.hpp>
namespace ia::iae
{
class Asset_Texture : public IAsset
{
public:
Asset_Texture(IN Handle handle) : IAsset(EAssetType::TEXTURE), m_handle(handle)
{
}
Asset_Texture(IN Handle handle, IN EAssetType type) : IAsset(type), m_handle(handle)
{
}
VIRTUAL VOID Compile();
VIRTUAL VOID Destroy();
INLINE Handle GetHandle();
protected:
CONST Handle m_handle;
friend class AssetManager;
};
INLINE Handle Asset_Texture::GetHandle()
{
return m_handle;
}
} // namespace ia::iae

View File

@ -0,0 +1,39 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Asset/Texture.hpp>
namespace ia::iae
{
class Asset_TileSheet : public Asset_Texture
{
public:
Asset_TileSheet(IN Handle textureHandle, IN INT32 tileWidth, IN INT32 tileHeight)
: Asset_Texture(textureHandle, EAssetType::TILESHEET), m_tileWidth(tileWidth), m_tileHeight(tileHeight)
{
}
VIRTUAL VOID Compile();
VIRTUAL VOID Destroy();
protected:
CONST INT32 m_tileWidth;
CONST INT32 m_tileHeight;
friend class AssetManager;
};
} // namespace ia::iae

View File

@ -1,228 +0,0 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Scene.hpp>
#include <IACore/StreamReader.hpp>
namespace ia::iae
{
enum class EAssetType
{
INVALID,
SCENE,
SOUND,
SPRITE,
TILESHEET,
SPRITESHEET,
PLUGIN,
PACKAGE
};
class IAsset
{
public:
IAsset(IN EAssetType type);
VIRTUAL ~IAsset();
PURE_VIRTUAL(VOID Compile());
PURE_VIRTUAL(VOID Destroy());
protected:
CONST EAssetType m_type;
};
class Asset_Sprite : public IAsset
{
public:
Asset_Sprite() : IAsset(EAssetType::SPRITE)
{
}
Asset_Sprite(IN EAssetType type) : IAsset(type)
{
}
VOID Compile();
VOID Destroy();
INLINE Handle GetTexture();
protected:
Handle m_texture;
friend class AssetManager;
};
class Asset_TileSheet : public Asset_Sprite
{
public:
Asset_TileSheet() : Asset_Sprite(EAssetType::TILESHEET)
{
}
};
class Asset_SpriteSheet : public Asset_Sprite
{
public:
Asset_SpriteSheet() : Asset_Sprite(EAssetType::SPRITESHEET)
{
}
VOID Compile();
VOID Destroy();
INLINE CONST Vector<INT32> &GetFrameCounts() CONST;
protected:
Vector<INT32> m_frameCounts;
friend class AssetManager;
};
class Asset_Scene : public IAsset
{
public:
Asset_Scene() : IAsset(EAssetType::SCENE)
{
}
VOID Compile();
VOID Destroy();
public:
INLINE Scene &GetScene();
protected:
Scene m_scene;
friend class AssetManager;
};
class Asset_Plugin : public IAsset
{
public:
Asset_Plugin() : IAsset(EAssetType::PLUGIN)
{
}
VOID Compile();
VOID Destroy();
public:
VOID (*OnInitialize)();
VOID (*OnTerminate)();
VOID (*OnDebugDraw)();
VOID (*OnFixedUpdate)();
VOID (*OnUpdate)(IN FLOAT32 deltaTime);
};
class IAsset_Package : public IAsset
{
public:
struct AssetRef
{
String Path;
Handle RefHandle{INVALID_HANDLE};
EAssetType Type{EAssetType::INVALID};
};
public:
PURE_VIRTUAL(Vector<AssetRef>::const_iterator ListAssets());
PURE_VIRTUAL(RefPtr<IStreamReader> GetAssetData(IN Handle refHandle));
};
class AssetManager
{
public:
VIRTUAL VOID SetAssetDirectory(IN CONST String &path);
String ReadTextAsset(IN CONST String &path);
Vector<UINT8> ReadBinaryAsset(IN CONST String &path);
public:
VIRTUAL Asset_Plugin *LoadPlugin(IN CONST String &path);
VIRTUAL Asset_Sprite *CreateSprite(IN CONST String &path);
VIRTUAL Asset_Sprite *CreateSprite(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
VIRTUAL Asset_SpriteSheet *CreateSpriteSheet(IN CONST Vector<Vector<Handle>> &animations);
VIRTUAL Asset_SpriteSheet *CreateSpriteSheet(IN CONST String &path, IN INT32 spriteWidth, IN INT32 spriteHeight,
IN CONST Vector<INT32> &frameCounts);
VIRTUAL Asset_TileSheet *CreateTileSheet(IN CONST String &path, IN INT32 tileWidth, IN INT32 tileHeight);
VIRTUAL Asset_TileSheet *CreateTileSheet(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height,
IN INT32 tileWidth, IN INT32 tileHeight);
VIRTUAL Asset_Scene *CreateScene(IN IVec2 extent);
VIRTUAL VOID DestroyAsset(IN IAsset *asset);
VIRTUAL VOID AssignAssetName(IN IAsset *asset, IN CONST String &name);
template<typename AssetType>
requires std::is_base_of<IAsset, AssetType>::value
AssetType *GetAssetByName(IN CONST String &name);
public:
STATIC Vector<UINT8> Inflate(IN PCUINT8 data, IN SIZE_T dataSize);
STATIC Vector<UINT8> Deflate(IN PCUINT8 data, IN SIZE_T dataSize);
public:
CONST String &GetAssetDirectory() CONST
{
return m_assetDirectory;
}
protected:
String m_assetDirectory;
Vector<IAsset *> m_assets;
Map<String, IAsset *> m_assetNames;
protected:
VIRTUAL IAsset *GetAssetByName(IN CONST String &name);
private:
VOID Initialize();
VOID Terminate();
friend class IAEngine;
};
template<typename AssetType>
requires std::is_base_of<IAsset, AssetType>::value
AssetType *AssetManager::GetAssetByName(IN CONST String &name)
{
return (AssetType *) GetAssetByName(name);
}
Handle Asset_Sprite::GetTexture()
{
return m_texture;
}
Scene &Asset_Scene::GetScene()
{
return m_scene;
}
CONST Vector<INT32> &Asset_SpriteSheet::GetFrameCounts() CONST
{
return m_frameCounts;
}
} // namespace ia::iae

View File

@ -16,7 +16,7 @@
#pragma once
#include <IAEngine/AssetManager.hpp>
#include <IAEngine/Asset/AssetManager.hpp>
namespace ia::iae
{
@ -25,9 +25,6 @@ namespace ia::iae
public:
STATIC VOID AddPlugin(IN Asset_Plugin *plugin);
STATIC AssetManager *GetAssetManager();
STATIC VOID SetAssetManager(IN AssetManager *instance);
public:
STATIC Asset_Scene *GetActiveScene();
STATIC VOID ChangeActiveScene(IN Asset_Scene *scene);