From 79b7e235ab98513a0c760e63b9634b5811c5851d Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Thu, 2 Nov 2023 10:39:50 -0500 Subject: [PATCH] Commit prog. --- CMakeLists.txt | 4 ++++ src/dawn/asset/Asset.cpp | 6 +----- src/dawn/asset/Asset.hpp | 6 ++---- src/dawn/asset/AssetManager.hpp | 2 +- src/dawn/asset/assets/AudioAsset.cpp | 4 ++-- src/dawn/asset/assets/AudioAsset.hpp | 2 +- src/dawn/asset/assets/LanguageAsset.cpp | 4 ++-- src/dawn/asset/assets/LanguageAsset.hpp | 2 +- src/dawn/asset/assets/TextureAsset.cpp | 4 ++-- src/dawn/asset/assets/TextureAsset.hpp | 3 +-- src/dawn/asset/assets/TrueTypeAsset.cpp | 4 ++-- src/dawn/asset/assets/TrueTypeAsset.hpp | 2 +- 12 files changed, 20 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 430ac5ae..5160acb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,10 @@ project(Dawn # Setup tests add_executable(dawntests) target_link_libraries(dawntests PRIVATE Catch2::Catch2WithMain) +target_compile_definitions(dawntests + PUBLIC + DAWN_ASSET_LOCATION="${DAWN_ROOT_DIR}/test/data" +) # Add tools add_subdirectory(tools) diff --git a/src/dawn/asset/Asset.cpp b/src/dawn/asset/Asset.cpp index 9c782888..057c5de0 100644 --- a/src/dawn/asset/Asset.cpp +++ b/src/dawn/asset/Asset.cpp @@ -7,12 +7,8 @@ using namespace Dawn; -Asset::Asset(AssetManager *assetManager, std::string name) { +Asset::Asset(const std::string name) : name(name) { assertTrue(name.size() > 0, "Asset::Asset: Name cannot be empty"); - assertNotNull(assetManager, "Asset::Asset: AssetManager cannot be null"); - - this->assetManager = assetManager; - this->name = name; } Asset::~Asset() { diff --git a/src/dawn/asset/Asset.hpp b/src/dawn/asset/Asset.hpp index d1ba0a09..064e4a0d 100644 --- a/src/dawn/asset/Asset.hpp +++ b/src/dawn/asset/Asset.hpp @@ -11,8 +11,7 @@ namespace Dawn { class Asset { public: - AssetManager *assetManager; - std::string name; + const std::string name; bool_t loaded = false; Event<> eventLoaded; StateEvent<> event2Loaded; @@ -20,10 +19,9 @@ namespace Dawn { /** * Create an abstract Asset object. * - * @param assetManager Asset manager that this asset belongs to. * @param name Name of the asset. */ - Asset(AssetManager *assetManager, std::string name); + Asset(const std::string name); /** * Virtual function that will be called by the asset manager on a diff --git a/src/dawn/asset/AssetManager.hpp b/src/dawn/asset/AssetManager.hpp index 351c0858..bfc0520e 100644 --- a/src/dawn/asset/AssetManager.hpp +++ b/src/dawn/asset/AssetManager.hpp @@ -80,7 +80,7 @@ namespace Dawn { if(existing != this->assets.end()) { return (T*)existing->second; } - auto asset = new T(this, name); + auto asset = new T(name); this->assets[name] = asset; return asset; } diff --git a/src/dawn/asset/assets/AudioAsset.cpp b/src/dawn/asset/assets/AudioAsset.cpp index 65fa8eac..0b70187d 100644 --- a/src/dawn/asset/assets/AudioAsset.cpp +++ b/src/dawn/asset/assets/AudioAsset.cpp @@ -7,8 +7,8 @@ using namespace Dawn; -AudioAsset::AudioAsset(AssetManager *man, std::string name) : - Asset(man, name), +AudioAsset::AudioAsset(const std::string name) : + Asset(name), loader(name + ".audio") { diff --git a/src/dawn/asset/assets/AudioAsset.hpp b/src/dawn/asset/assets/AudioAsset.hpp index def7628d..be7be535 100644 --- a/src/dawn/asset/assets/AudioAsset.hpp +++ b/src/dawn/asset/assets/AudioAsset.hpp @@ -35,7 +35,7 @@ namespace Dawn { size_t frameSize; public: - AudioAsset(AssetManager *man, std::string name); + AudioAsset(const std::string name); void updateSync() override; void updateAsync() override; diff --git a/src/dawn/asset/assets/LanguageAsset.cpp b/src/dawn/asset/assets/LanguageAsset.cpp index 1981762f..ef52495a 100644 --- a/src/dawn/asset/assets/LanguageAsset.cpp +++ b/src/dawn/asset/assets/LanguageAsset.cpp @@ -7,8 +7,8 @@ using namespace Dawn; -LanguageAsset::LanguageAsset(AssetManager *man, std::string name) : - Asset(man, name), +LanguageAsset::LanguageAsset(const std::string name) : + Asset(name), loader(name + ".language") { diff --git a/src/dawn/asset/assets/LanguageAsset.hpp b/src/dawn/asset/assets/LanguageAsset.hpp index 854ed315..9d7db881 100644 --- a/src/dawn/asset/assets/LanguageAsset.hpp +++ b/src/dawn/asset/assets/LanguageAsset.hpp @@ -28,7 +28,7 @@ namespace Dawn { uint8_t buffer[1024]; public: - LanguageAsset(AssetManager *man, std::string name); + LanguageAsset(const std::string name); void updateSync() override; void updateAsync() override; std::string getValue(std::string key); diff --git a/src/dawn/asset/assets/TextureAsset.cpp b/src/dawn/asset/assets/TextureAsset.cpp index b7a612e2..e399e795 100644 --- a/src/dawn/asset/assets/TextureAsset.cpp +++ b/src/dawn/asset/assets/TextureAsset.cpp @@ -8,8 +8,8 @@ using namespace Dawn; -TextureAsset::TextureAsset(AssetManager *assetManager, std::string name) : - Asset(assetManager, name), +TextureAsset::TextureAsset(const std::string name) : + Asset(name), loader(name + ".texture"), texture() { diff --git a/src/dawn/asset/assets/TextureAsset.hpp b/src/dawn/asset/assets/TextureAsset.hpp index cd1e9e19..3a54d50f 100644 --- a/src/dawn/asset/assets/TextureAsset.hpp +++ b/src/dawn/asset/assets/TextureAsset.hpp @@ -50,10 +50,9 @@ namespace Dawn { * Constructs a texture asset loader. You should instead use the parent * asset managers' abstracted load method * - * @param assetManager Asset manager this asset belongs to. * @param name File name asset to load, omitting the extension. */ - TextureAsset(AssetManager *assetManager, std::string name); + TextureAsset(const std::string name); void updateSync() override; void updateAsync() override; diff --git a/src/dawn/asset/assets/TrueTypeAsset.cpp b/src/dawn/asset/assets/TrueTypeAsset.cpp index 757b23df..190bda7d 100644 --- a/src/dawn/asset/assets/TrueTypeAsset.cpp +++ b/src/dawn/asset/assets/TrueTypeAsset.cpp @@ -9,8 +9,8 @@ using namespace Dawn; -TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) : - Asset(assMan, name), +TrueTypeAsset::TrueTypeAsset(const std::string name) : + Asset(name), loader(name + ".truetype") { this->locks.onLockRemoved = [&](usagelockid_t id){ diff --git a/src/dawn/asset/assets/TrueTypeAsset.hpp b/src/dawn/asset/assets/TrueTypeAsset.hpp index 75f4fc50..f909e5ee 100644 --- a/src/dawn/asset/assets/TrueTypeAsset.hpp +++ b/src/dawn/asset/assets/TrueTypeAsset.hpp @@ -44,7 +44,7 @@ namespace Dawn { std::map> locksByTexture; public: - TrueTypeAsset(AssetManager *assMan, std::string name); + TrueTypeAsset(const std::string name); void updateSync() override; void updateAsync() override;