diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/Config.h | 2 | ||||
-rw-r--r-- | src/crepe/api/LoopManager.h | 7 | ||||
-rw-r--r-- | src/crepe/api/LoopTimer.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/Sprite.cpp | 12 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 5 | ||||
-rw-r--r-- | src/crepe/api/Texture.cpp | 23 | ||||
-rw-r--r-- | src/crepe/api/Texture.h | 15 |
7 files changed, 29 insertions, 38 deletions
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index 6472270..73c9a4e 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -26,7 +26,7 @@ struct Config final { * * Only messages with equal or higher priority than this value will be logged. */ - Log::Level level = Log::Level::INFO; + Log::Level level = Log::Level::TRACE; /** * \brief Colored log output * diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h index d8910a0..8a30602 100644 --- a/src/crepe/api/LoopManager.h +++ b/src/crepe/api/LoopManager.h @@ -8,6 +8,7 @@ #include "../system/System.h" #include "LoopTimer.h" +#include "manager/ResourceManager.h" namespace crepe { @@ -96,8 +97,10 @@ private: //! Scene manager instance SceneManager scene_manager{mediator}; - //! SDL context \todo no more singletons! - SDLContext & sdl_context = SDLContext::get_instance(); + SDLContext sdl_context {mediator}; + + ResourceManager res_man {mediator}; + //! Loop timer \todo no more singletons! LoopTimer & loop_timer = LoopTimer::get_instance(); diff --git a/src/crepe/api/LoopTimer.cpp b/src/crepe/api/LoopTimer.cpp index 15a0e3a..40fc94e 100644 --- a/src/crepe/api/LoopTimer.cpp +++ b/src/crepe/api/LoopTimer.cpp @@ -1,6 +1,5 @@ #include <chrono> -#include "../facade/SDLContext.h" #include "../util/Log.h" #include "LoopTimer.h" @@ -67,7 +66,7 @@ void LoopTimer::enforce_frame_rate() { = std::chrono::duration_cast<std::chrono::milliseconds>(this->frame_target_time - frame_duration); if (delay_time.count() > 0) { - SDLContext::get_instance().delay(delay_time.count()); + //SDLContext::get_instance().delay(delay_time.count()); } } diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index cc0e20a..bae5ad9 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -2,25 +2,25 @@ #include <utility> #include "../util/Log.h" +#include "api/Asset.h" #include "Component.h" #include "Sprite.h" -#include "Texture.h" #include "types.h" using namespace std; using namespace crepe; -Sprite::Sprite(game_object_id_t id, Texture & texture, const Sprite::Data & data) +Sprite::Sprite(game_object_id_t id, const Asset & texture, const Sprite::Data & data) : Component(id), - texture(std::move(texture)), + source(texture), data(data) { dbg_trace(); - this->mask.w = this->texture.get_size().x; - this->mask.h = this->texture.get_size().y; - this->aspect_ratio = static_cast<double>(this->mask.w) / this->mask.h; + //this->mask.w = this->texture.get_size().x; + //this->mask.h = this->texture.get_size().y; + //this->aspect_ratio = static_cast<double>(this->mask.w) / this->mask.h; } Sprite::~Sprite() { dbg_trace(); } diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index dbf41e4..ec120c0 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -4,6 +4,7 @@ #include "Color.h" #include "Texture.h" +#include "api/Asset.h" #include "types.h" namespace crepe { @@ -74,11 +75,11 @@ public: * \param texture asset of the image * \param ctx all the sprite data */ - Sprite(game_object_id_t id, Texture & texture, const Data & data); + Sprite(game_object_id_t id, const Asset & texture, const Data & data); ~Sprite(); //! Texture used for the sprite - const Texture texture; + const Asset source; Data data; diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index 2b56271..9d8e02d 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -1,16 +1,16 @@ -#include "../facade/SDLContext.h" #include "../util/Log.h" #include "Asset.h" +#include "Resource.h" #include "Texture.h" #include "types.h" +#include <utility> using namespace crepe; using namespace std; -Texture::Texture(const Asset & src) { +Texture::Texture(const Asset & src) : Resource(src) { dbg_trace(); - this->load(src); } Texture::~Texture() { @@ -18,21 +18,12 @@ Texture::~Texture() { this->texture.reset(); } -Texture::Texture(Texture && other) noexcept : texture(std::move(other.texture)) {} - -Texture & Texture::operator=(Texture && other) noexcept { - if (this != &other) { - texture = std::move(other.texture); - } - return *this; -} - -void Texture::load(const Asset & res) { - SDLContext & ctx = SDLContext::get_instance(); - this->texture = ctx.texture_from_path(res.get_path()); +void Texture::load(std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> texture) { + this->texture = std::move(texture); + this->loaded = true; } ivec2 Texture::get_size() const { if (this->texture == nullptr) return {}; - return SDLContext::get_instance().get_size(*this); + return {}; } diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h index 1817910..f9c7919 100644 --- a/src/crepe/api/Texture.h +++ b/src/crepe/api/Texture.h @@ -8,6 +8,7 @@ #include <memory> #include "Asset.h" +#include "Resource.h" #include "types.h" namespace crepe { @@ -22,7 +23,7 @@ class Animator; * The Texture class is responsible for loading an image from a source and providing access to * its dimensions. Textures can be used for rendering. */ -class Texture { +class Texture : public Resource { public: /** @@ -35,12 +36,6 @@ public: * \brief Destroys the Texture instance, freeing associated resources. */ ~Texture(); - // FIXME: this constructor shouldn't be necessary because this class doesn't manage memory - - Texture(Texture && other) noexcept; - Texture & operator=(Texture && other) noexcept; - Texture(const Texture &) = delete; - Texture & operator=(const Texture &) = delete; /** * \brief Gets the width and height of the texture. @@ -53,12 +48,14 @@ private: * \brief Loads the texture from an Asset resource. * \param res Unique pointer to an Asset resource to load the texture from. */ - void load(const Asset & res); - + void load(std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> texture); + private: //! The texture of the class from the library std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> texture; + bool loaded = false; + //! Grants SDLContext access to private members. friend class SDLContext; |