diff --git a/lib/Ray/CMakeLists.txt b/lib/Ray/CMakeLists.txt index e9ffc25f..5bb12348 100644 --- a/lib/Ray/CMakeLists.txt +++ b/lib/Ray/CMakeLists.txt @@ -51,6 +51,7 @@ set(HEADERS sources/Drawables/3D/Ray.hpp sources/Drawables/3D/Sphere.hpp sources/Drawables/3D/Triangle.hpp + sources/Exceptions/RayError.hpp sources/Model/Model.hpp sources/Model/ModelAnimation.hpp sources/Model/ModelAnimations.hpp @@ -62,9 +63,6 @@ set(SRC sources/Color.cpp sources/Font.cpp sources/Window.cpp - sources/Model/Model.cpp - sources/Model/ModelAnimation.cpp - sources/Model/ModelAnimations.cpp sources/Audio/Music.cpp sources/Audio/Sound.cpp sources/Camera/Camera2D.cpp @@ -92,6 +90,10 @@ set(SRC sources/Drawables/ADrawable3D.cpp sources/Drawables/Image.cpp sources/Drawables/Texture.cpp + sources/Exceptions/RayError.cpp + sources/Model/Model.cpp + sources/Model/ModelAnimation.cpp + sources/Model/ModelAnimations.cpp sources/Vector/Vector2.cpp sources/Vector/Vector3.cpp ) diff --git a/lib/Ray/sources/Drawables/2D/Triangle.cpp b/lib/Ray/sources/Drawables/2D/Triangle.cpp index 35be178d..1857ec4e 100644 --- a/lib/Ray/sources/Drawables/2D/Triangle.cpp +++ b/lib/Ray/sources/Drawables/2D/Triangle.cpp @@ -6,7 +6,7 @@ */ #include "Drawables/2D/Triangle.hpp" -#include +#include "Exceptions/RayError.hpp" RAY::Drawables::Drawables2D::Triangle::Triangle(const Vector2 &positionA, const Vector2 &positionB, const Vector2 &positionC, const Color &color): ADrawable2D(positionA, color), _posB(positionB), _posC(positionC) @@ -54,6 +54,6 @@ void RAY::Drawables::Drawables2D::Triangle::drawOn(RAY::Window &) void RAY::Drawables::Drawables2D::Triangle::drawOn(RAY::Image &) { - throw std::exception(); + throw RAY::Exception::NotSupportedError("An triangle cannot be drawn on an image"); } diff --git a/lib/Ray/sources/Exceptions/RayError.cpp b/lib/Ray/sources/Exceptions/RayError.cpp new file mode 100644 index 00000000..bc2ba888 --- /dev/null +++ b/lib/Ray/sources/Exceptions/RayError.cpp @@ -0,0 +1,23 @@ +/* +** EPITECH PROJECT, 2021 +** Bomberman +** File description: +** RayError +*/ + +#include "RayError.hpp" + +RAY::Exception::RayError::RayError(const std::string &expectionMessage): + runtime_error(expectionMessage) +{ +} + +RAY::Exception::NotSupportedError::NotSupportedError(const std::string &expectionMessage): + RayError(expectionMessage) +{ +} + +RAY::Exception::NotCompatibleError::NotCompatibleError(const std::string &expectionMessage): + RayError(expectionMessage) +{ +} diff --git a/lib/Ray/sources/Exceptions/RayError.hpp b/lib/Ray/sources/Exceptions/RayError.hpp new file mode 100644 index 00000000..52068b22 --- /dev/null +++ b/lib/Ray/sources/Exceptions/RayError.hpp @@ -0,0 +1,63 @@ +/* +** EPITECH PROJECT, 2021 +** Bomberman +** File description: +** RayError +*/ + +#ifndef RAYERROR_HPP_ +#define RAYERROR_HPP_ + +#include + +namespace RAY::Exception { + //! @brief base exception class for RAY lib + class RayError: public std::runtime_error { + public: + //! @brief Create a new RAY exception + RayError(const std::string &what); + + //! @brief A default destructor + ~RayError() = default; + + //! @brief A RAY exception is copy constructable + RayError(const RayError &) = default; + + //! @brief A default assignment operator + RayError &operator=(const RayError &) = default; + }; + + //! @brief exception used when an incompatibility occurs + class NotCompatibleError: public RayError { + public: + //! @brief Create a new exception instance + NotCompatibleError(const std::string &what); + + //! @brief A default destructor + ~NotCompatibleError() = default; + + //! @brief An exception is copy constructable + NotCompatibleError(const NotCompatibleError &) = default; + + //! @brief A default assignment operator + NotCompatibleError &operator=(const NotCompatibleError &) = default; + }; + + //! @brief exception used when an non-supported operation is done + class NotSupportedError: public RayError { + public: + //! @brief Create a new exception instance + NotSupportedError(const std::string &what = "This operation is currently not supported"); + + //! @brief A default destructor + ~NotSupportedError() = default; + + //! @brief An exception is copy constructable + NotSupportedError(const NotSupportedError &) = default; + + //! @brief A default assignment operator + NotSupportedError &operator=(const NotSupportedError &) = default; + }; +} + +#endif /* !RAYERROR_HPP_ */ diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index 791d95b3..5ce18d71 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -6,6 +6,7 @@ */ #include "Model/Model.hpp" +#include "Exceptions/RayError.hpp" RAY::Model::Model(const std::string &filename): _model(LoadModel(filename.c_str())) @@ -49,7 +50,7 @@ bool RAY::Model::unloadKeepMeshes() bool RAY::Model::setAnimation(const RAY::ModelAnimation &animation) { if (!IsModelAnimationValid(this->_model, animation)) - return false; + throw RAY::Exception::NotCompatibleError("The animation is not compatible with the model"); UpdateModelAnimation(this->_model, animation, animation.getFrameCounter()); return true; } diff --git a/lib/Ray/sources/Model/Model.hpp b/lib/Ray/sources/Model/Model.hpp index c131d63c..9dc858ef 100644 --- a/lib/Ray/sources/Model/Model.hpp +++ b/lib/Ray/sources/Model/Model.hpp @@ -52,7 +52,6 @@ namespace RAY { bool unloadKeepMeshes(); //! @brief Update model animation pose - //! @return false if animation is not compatible bool setAnimation(const RAY::ModelAnimation &animation); //! @brief Sets a texture to the Nth material