ressources are not reloadable, ressource interface deleted

This commit is contained in:
arthur.jamet
2021-05-28 12:41:21 +02:00
parent 590545243d
commit b92b35f191
17 changed files with 123 additions and 364 deletions
-17
View File
@@ -13,11 +13,6 @@ RAY::Image::Image(const std::string &filename):
{
}
RAY::Image::Image()
{
}
RAY::Image::Image(RAY::Texture &texture):
_image(GetTextureData(texture))
{
@@ -29,24 +24,12 @@ RAY::Image::~Image()
UnloadImage(_image);
}
bool RAY::Image::load(const std::string &filename)
{
this->_image = LoadImage(filename.c_str());
return true;
}
bool RAY::Image::exportTo(const std::string &outputPath)
{
ExportImage(_image, outputPath.c_str());
return true;
}
bool RAY::Image::unload()
{
UnloadImage(_image);
return true;
}
RAY::Image::operator ::Image() const
{
return _image;
+3 -15
View File
@@ -11,16 +11,14 @@
#include <raylib.h>
#include <string>
#include "Texture.hpp"
#include "IRessource.hpp"
namespace RAY
{
namespace Drawables {
class ADrawable2D;
}
class IRessource;
//! @brief Object representation of a framebuffer
class Image: public IRessource {
class Image {
public:
//! @brief Create an image, loading a file
//! @param filename: path to file to load
@@ -31,28 +29,18 @@ namespace RAY
Image(Texture &texture);
//! @brief A default copy constructor
Image(const Image &image) = default;
//! @brief A default constructor, no ressources loaded
Image();
Image(const Image &image) = delete;
//! @brief An image is assignable
Image &operator=(const Image &image) = default;
Image &operator=(const Image &image) = delete;
//! @brief Image destructor, will unload ressources
~Image();
//! @brief load ressources from file
//! @param filename: path of input
bool load(const std::string &filename) override;
//! @brief export to file
//! @param outputPath: path of output
bool exportTo(const std::string &outputPath);
//! @brief unload ressources
bool unload() override;
//! @brief draw drawable
void draw(Drawables::ADrawable2D &);
+26 -25
View File
@@ -7,35 +7,36 @@
#include "Drawables/Texture.hpp"
RAY::Texture::Texture(const std::string &filename):
_texture(LoadTexture(filename.c_str()))
{
}
namespace RAY {
RAY::Texture::Texture(const Image &image):
_texture(LoadTextureFromImage(image))
{
Texture::Texture(const std::string &filename):
_texture(LoadTexture(filename.c_str())),
_resourcePath(filename)
{
}
}
Texture::Texture(const Texture &texture):
_texture(LoadTexture(texture._resourcePath.c_str())),
_resourcePath(texture._resourcePath)
{
}
RAY::Texture::~Texture()
{
UnloadTexture(this->_texture);
}
bool RAY::Texture::load(const std::string &filename)
{
this->_texture = LoadTexture(filename.c_str());
return true;
}
Texture &Texture::operator=(const Texture &other)
{
UnloadTexture(this->_texture);
this->_resourcePath = other._resourcePath;
this->_texture = LoadTexture(this->_resourcePath.c_str());
return *this;
}
bool RAY::Texture::unload()
{
UnloadTexture(this->_texture);
return true;
}
Texture::~Texture()
{
UnloadTexture(this->_texture);
}
RAY::Texture::operator ::Texture() const
{
return this->_texture;
Texture::operator ::Texture() const
{
return this->_texture;
}
}
+6 -16
View File
@@ -10,42 +10,32 @@
#include <raylib.h>
#include <string>
#include "IRessource.hpp"
namespace RAY
{
//! @brief Object representation of a texture
class Texture: public IRessource {
class Texture {
public:
//! @brief Create an texture, loading a file
//! @param filename: path to file to load
Texture(const std::string &filename);
//! @brief Create an texture, from an image
//! @param image: reference to image to create texture from
Texture(const Image &image);
//! @brief A texture is not copy constructable
Texture(const Texture &) = delete;
Texture(const Texture &);
//! @brief An image is assignable
Texture &operator=(const Texture &) = delete;
Texture &operator=(const Texture &);
//! @brief Texture destructor, will unload ressources
~Texture() override;
//! @brief load ressources from file
//! @param filename: path of input
bool load(const std::string &filename) override;
//! @brief unload ressources
bool unload() override;
~Texture();
protected:
private:
//! @brief Texture, really, that's just it...
::Texture _texture;
std::string _resourcePath;
INTERNAL:
//! @return libray Texture struct
operator ::Texture() const;