diff --git a/src/Resources.cpp b/src/Resources.cpp index 29e0976..f820938 100644 --- a/src/Resources.cpp +++ b/src/Resources.cpp @@ -6,12 +6,6 @@ #include -Resources::Resources() -{ - for (const auto& [resourceType, path] : resourcePaths_) - bitmaps_[resourceType] = ::al_load_bitmap(path.c_str()); -} - Resources::~Resources() { for (const auto& [_, bitmap] : bitmaps_) @@ -20,6 +14,9 @@ Resources::~Resources() ALLEGRO_BITMAP* Resources::getBitmap(ResourceType resourceType) const { + if (bitmaps_.empty()) + for (const auto& [resType, path] : resourcePaths_) + bitmaps_[resType] = ::al_load_bitmap(path.c_str()); return bitmaps_.at(resourceType); } diff --git a/src/Resources.h b/src/Resources.h index 61862fc..4f8ecf5 100644 --- a/src/Resources.h +++ b/src/Resources.h @@ -11,14 +11,14 @@ struct ALLEGRO_BITMAP; class Resources { public: - Resources(); + Resources() = default; ~Resources(); Resources& operator=(const Resources& other) = delete; Resources(const Resources& other) = delete; - Resources& operator=(Resources&& other) = default; - Resources(Resources&& other) = default; + Resources& operator=(Resources&& other) = delete; + Resources(Resources&& other) = delete; ALLEGRO_BITMAP* getBitmap(ResourceType resourceType) const; @@ -50,5 +50,5 @@ class Resources {ResourceType::ENEMY_TANK_TIER_3, "image/board/tank_tier3_enemy.tga"}, {ResourceType::ENEMY_TANK_TIER_4, "image/board/tank_tier4_enemy.tga"}}; - std::unordered_map bitmaps_; + mutable std::unordered_map bitmaps_; }; diff --git a/src/Screen.cpp b/src/Screen.cpp index 3d9d81b..8834807 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -37,7 +37,6 @@ bool Screen::init() ::al_set_window_title(::al_get_current_display(), "TankBle"); - resources_ = {}; font_ = ::al_create_builtin_font(); return true;