diff --git a/.clang-format b/.clang-format index 5dcdeb6..66b3b81 100644 --- a/.clang-format +++ b/.clang-format @@ -1,6 +1,7 @@ --- BasedOnStyle: Microsoft IndentWidth: 4 +SortIncludes: false --- Language: Cpp FixNamespaceComments: true diff --git a/Src/IAEngine/CMakeLists.txt b/Src/IAEngine/CMakeLists.txt index 86e2970..eb9bb66 100644 --- a/Src/IAEngine/CMakeLists.txt +++ b/Src/IAEngine/CMakeLists.txt @@ -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" ) diff --git a/Src/IAEngine/imp/cpp/AssetManager.cpp b/Src/IAEngine/imp/cpp/Asset/AssetManager.cpp similarity index 68% rename from Src/IAEngine/imp/cpp/AssetManager.cpp rename to Src/IAEngine/imp/cpp/Asset/AssetManager.cpp index 5e8ea5e..f5f2ad1 100644 --- a/Src/IAEngine/imp/cpp/AssetManager.cpp +++ b/Src/IAEngine/imp/cpp/Asset/AssetManager.cpp @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include +#include #include - #include #define STB_IMAGE_IMPLEMENTATION @@ -29,9 +28,13 @@ namespace ia::iae { + String AssetManager::s_assetDirectory; + Vector AssetManager::s_assets; + Map 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 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("Plugin_OnInitialize"); - t->OnTerminate = lib.GetFunction("Plugin_OnTerminate"); - t->OnDebugDraw = lib.GetFunction("Plugin_OnDebugDraw"); - t->OnFixedUpdate = lib.GetFunction("Plugin_OnFixedUpdate"); - t->OnUpdate = lib.GetFunction("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> &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 &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 diff --git a/Src/IAEngine/imp/cpp/GameData.cpp b/Src/IAEngine/imp/cpp/GameData.cpp index 2aa1ff3..336d822 100644 --- a/Src/IAEngine/imp/cpp/GameData.cpp +++ b/Src/IAEngine/imp/cpp/GameData.cpp @@ -16,7 +16,6 @@ #include #include -#include #include @@ -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(r.attribute("name").as_string())); + scene->GetHandle()->AddReferencedResources(AssetManager::GetAssetByName(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(cellNode.attribute("tileSheet").as_string()); + cell.TileSheet = AssetManager::GetAssetByName(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(); diff --git a/Src/IAEngine/imp/cpp/IAEngine.cpp b/Src/IAEngine/imp/cpp/IAEngine.cpp index dd35ec3..1f72e18 100644 --- a/Src/IAEngine/imp/cpp/IAEngine.cpp +++ b/Src/IAEngine/imp/cpp/IAEngine.cpp @@ -35,9 +35,6 @@ namespace ia::iae Vector 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 diff --git a/Src/IAEngine/imp/hpp/GameData.hpp b/Src/IAEngine/imp/hpp/GameData.hpp index 1318f76..b48c756 100644 --- a/Src/IAEngine/imp/hpp/GameData.hpp +++ b/Src/IAEngine/imp/hpp/GameData.hpp @@ -16,7 +16,7 @@ #pragma once -#include +#include namespace ia::iae { diff --git a/Src/IAEngine/inc/IAEngine/Asset/AssetManager.hpp b/Src/IAEngine/inc/IAEngine/Asset/AssetManager.hpp new file mode 100644 index 0000000..980654e --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/AssetManager.hpp @@ -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 . + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ia::iae +{ + class AssetManager final + { + public: + STATIC VOID SetAssetDirectory(IN CONST String &path); + + STATIC String ReadTextAsset(IN CONST String &path); + STATIC Vector 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 &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 + requires std::is_base_of::value + STATIC AssetType *GetAssetByName(IN CONST String &name); + + public: + STATIC Vector Inflate(IN PCUINT8 data, IN SIZE_T dataSize); + STATIC Vector Deflate(IN PCUINT8 data, IN SIZE_T dataSize); + + public: + STATIC CONST String &GetAssetDirectory() + { + return s_assetDirectory; + } + + protected: + STATIC String s_assetDirectory; + STATIC Vector s_assets; + STATIC Map s_assetNames; + + protected: + STATIC IAsset *GetAssetByName(IN CONST String &name); + + private: + STATIC VOID Initialize(); + STATIC VOID Terminate(); + + friend class IAEngine; + }; + + template + requires std::is_base_of::value + AssetType *AssetManager::GetAssetByName(IN CONST String &name) + { + return (AssetType *) GetAssetByName(name); + } +} // namespace ia::iae \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Asset/IAsset.hpp b/Src/IAEngine/inc/IAEngine/Asset/IAsset.hpp new file mode 100644 index 0000000..e730afd --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/IAsset.hpp @@ -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 . + +#pragma once + +#include + +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; + }; +} \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Asset/Package.hpp b/Src/IAEngine/inc/IAEngine/Asset/Package.hpp new file mode 100644 index 0000000..08fe38f --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/Package.hpp @@ -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 . + +#pragma once + +#include +#include + +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::const_iterator ListAssets()); + PURE_VIRTUAL(RefPtr GetAssetData(IN Handle refHandle)); + + protected: + friend class AssetManager; + }; + +} // namespace ia::iae diff --git a/Src/IAEngine/inc/IAEngine/Asset/Plugin.hpp b/Src/IAEngine/inc/IAEngine/Asset/Plugin.hpp new file mode 100644 index 0000000..58c32e8 --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/Plugin.hpp @@ -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 . + +#pragma once + +#include + +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 \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Asset/Scene.hpp b/Src/IAEngine/inc/IAEngine/Asset/Scene.hpp new file mode 100644 index 0000000..a2bda1e --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/Scene.hpp @@ -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 . + +#pragma once + +#include +#include + +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 \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Asset/Sound.hpp b/Src/IAEngine/inc/IAEngine/Asset/Sound.hpp new file mode 100644 index 0000000..7c6dc26 --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/Sound.hpp @@ -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 . + +#pragma once + +#include + +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 \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Asset/Sprite.hpp b/Src/IAEngine/inc/IAEngine/Asset/Sprite.hpp new file mode 100644 index 0000000..6bc9d7f --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/Sprite.hpp @@ -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 . + +#pragma once + +#include + +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; + }; +} \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Asset/SpriteSheet.hpp b/Src/IAEngine/inc/IAEngine/Asset/SpriteSheet.hpp new file mode 100644 index 0000000..20e90bd --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/SpriteSheet.hpp @@ -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 . + +#pragma once + +#include + +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 &&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 m_animations; + + friend class AssetManager; + }; +} // namespace ia::iae \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Asset/Texture.hpp b/Src/IAEngine/inc/IAEngine/Asset/Texture.hpp new file mode 100644 index 0000000..144a0a7 --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/Texture.hpp @@ -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 . + +#pragma once + +#include + +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 \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/Asset/TileSheet.hpp b/Src/IAEngine/inc/IAEngine/Asset/TileSheet.hpp new file mode 100644 index 0000000..1859a3b --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Asset/TileSheet.hpp @@ -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 . + +#pragma once + +#include + +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 \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/AssetManager.hpp b/Src/IAEngine/inc/IAEngine/AssetManager.hpp deleted file mode 100644 index a40b4ac..0000000 --- a/Src/IAEngine/inc/IAEngine/AssetManager.hpp +++ /dev/null @@ -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 . - -#pragma once - -#include - -#include - -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 &GetFrameCounts() CONST; - - protected: - Vector 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::const_iterator ListAssets()); - PURE_VIRTUAL(RefPtr GetAssetData(IN Handle refHandle)); - }; - - class AssetManager - { - public: - VIRTUAL VOID SetAssetDirectory(IN CONST String &path); - - String ReadTextAsset(IN CONST String &path); - Vector 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> &animations); - VIRTUAL Asset_SpriteSheet *CreateSpriteSheet(IN CONST String &path, IN INT32 spriteWidth, IN INT32 spriteHeight, - IN CONST Vector &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 - requires std::is_base_of::value - AssetType *GetAssetByName(IN CONST String &name); - - public: - STATIC Vector Inflate(IN PCUINT8 data, IN SIZE_T dataSize); - STATIC Vector Deflate(IN PCUINT8 data, IN SIZE_T dataSize); - - public: - CONST String &GetAssetDirectory() CONST - { - return m_assetDirectory; - } - - protected: - String m_assetDirectory; - Vector m_assets; - Map m_assetNames; - - protected: - VIRTUAL IAsset *GetAssetByName(IN CONST String &name); - - private: - VOID Initialize(); - VOID Terminate(); - - friend class IAEngine; - }; - - template - requires std::is_base_of::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 &Asset_SpriteSheet::GetFrameCounts() CONST - { - return m_frameCounts; - } -} // namespace ia::iae \ No newline at end of file diff --git a/Src/IAEngine/inc/IAEngine/IAEngine.hpp b/Src/IAEngine/inc/IAEngine/IAEngine.hpp index 0025d3e..f375ad5 100644 --- a/Src/IAEngine/inc/IAEngine/IAEngine.hpp +++ b/Src/IAEngine/inc/IAEngine/IAEngine.hpp @@ -16,7 +16,7 @@ #pragma once -#include +#include 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);