Merge branch 'develop' of github.com:AnonymusRaccoon/Bomberman into find_bg

# Conflicts:
#	CMakeLists.txt
#	lib/Ray/sources/Drawables/2D/Rectangle.hpp
#	lib/Ray/sources/Drawables/Texture.cpp
#	lib/Ray/sources/Drawables/Texture.hpp
#	sources/Runner/CreditScene.cpp
#	sources/Runner/GameScene.cpp
#	sources/Runner/Runner.cpp

still some issues with textures that are drawn behind
This commit is contained in:
Clément Le Bihan
2021-06-16 00:36:06 +02:00
70 changed files with 1085 additions and 233 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ namespace RAY::Drawables::Drawables2D
Rectangle &operator=(const Rectangle &) = default;
//! @brief A default destructor
virtual ~Rectangle() override = default;
~Rectangle() override = default;
//! @return the dimensions of the rectangle
const Vector2 &getDimensions(void);
+13 -1
View File
@@ -11,7 +11,11 @@
namespace RAY {
Cache<::Texture> Texture::_texturesCache(LoadTexture, UnloadTexture);
Cache<::Texture> Texture::_texturesCache(LoadTexture, UnloadTexture);
Texture::Texture()
: Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE, 0, 0)
{}
Texture::Texture(const std::string &filename, bool lonely, float scale, float rotation):
Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE, scale, rotation),
@@ -34,9 +38,15 @@ namespace RAY {
return *this;
this->_texture = this->_texturesCache.fetch(filename);
this->_resourcePath = filename;
this->_dimensions = Vector2(this->_texture->width, this->_texture->height);
return *this;
}
const std::string &Texture::getResourcePath() const
{
return this->_resourcePath;
}
Texture::operator ::Texture() const
{
return *this->_texture;
@@ -44,6 +54,8 @@ namespace RAY {
void Texture::drawOn(RAY::Window &)
{
if (!this->_texture)
return;
DrawTextureEx(*this, this->_position, this->_rotation, this->_scale, this->_color);
}
}
+8 -2
View File
@@ -21,7 +21,10 @@ namespace RAY
//! @brief Create an texture, loading a file
//! @param filename: path to file to load
//! @param lonely: should be set to true if the entity's loaded data must be independant from others
Texture(const std::string &filename, bool lonely = false, float scale = 1, float rotation = 0);
explicit Texture(const std::string &filename, bool lonely = false, float scale = 1, float rotation = 0);
//! @brief Create an empty texture
Texture();
//! @brief A texture is copy constructable
Texture(const Texture &) = default;
@@ -33,7 +36,7 @@ namespace RAY
Texture &operator=(const Texture &) = default;
//! @brief Texture destructor, will not unload ressources
~Texture() = default;
~Texture() override = default;
//! @brief draw texture on a window
void drawOn(RAY::Window &) override;
@@ -41,6 +44,9 @@ namespace RAY
//! @brief Load texture from file, lets one use one entity for multiple files
Texture &use(const std::string &filename);
//! @return path of loaded texture
const std::string &getResourcePath() const;
protected:
private:
//! @brief Texture, really, that's just it...
+5
View File
@@ -71,6 +71,11 @@ namespace RAY::Drawables::Drawables3D
return true;
}
Texture &Model::getTextureByMaterial(MaterialType materialType)
{
return this->_textureList[materialType];
}
Model::operator ::Model() const
{
return *this->_model;
+4
View File
@@ -95,6 +95,10 @@ namespace RAY::Drawables::Drawables3D {
//! @brief Draw model's wires on window
void drawWiresOn(RAY::Window &) override;
//! @param materialType type of material
//! @return texture
Texture &getTextureByMaterial(MaterialType materialType);
private:
//! @brief Raw data from raylib
std::shared_ptr<::Model> _model;
+2 -6
View File
@@ -5,9 +5,10 @@
** ModelAnimation
*/
#include <iostream>
#include "Model/ModelAnimation.hpp"
RAY::ModelAnimation::ModelAnimation(::ModelAnimation &animation):
RAY::ModelAnimation::ModelAnimation(::ModelAnimation animation):
_animation(animation), _frameCounter(0)
{
}
@@ -38,9 +39,4 @@ RAY::ModelAnimation &RAY::ModelAnimation::incrementFrameCounter()
RAY::ModelAnimation::operator ::ModelAnimation() const
{
return this->_animation;
}
RAY::ModelAnimation::operator ::ModelAnimation *()
{
return &this->_animation;
}
+2 -5
View File
@@ -17,7 +17,7 @@ namespace RAY {
public:
//! @brief A Model animation constructor
//! @param animationPtr an animation pointer, returned by the nimation-loading function
ModelAnimation(::ModelAnimation &animationPtr);
explicit ModelAnimation(::ModelAnimation animation);
//! @brief A default copy-constructor
ModelAnimation(const ModelAnimation &) = default;
@@ -41,13 +41,10 @@ namespace RAY {
~ModelAnimation() = default;
private:
::ModelAnimation &_animation;
::ModelAnimation _animation;
size_t _frameCounter;
INTERNAL:
//! @brief Castin Object to raw model animation pointer
operator ::ModelAnimation *();
//! @brief Castin Object to raw model animation pointer
operator ::ModelAnimation() const;
};
+2 -2
View File
@@ -19,7 +19,7 @@ namespace RAY {
public:
//! @brief A Model animation constructor
//! @param filePath Path to the file containing animations
ModelAnimations(const std::string &filePath);
explicit ModelAnimations(const std::string &filePath);
//! @brief default copy ctor
ModelAnimations(const ModelAnimations &) = default;
@@ -59,7 +59,7 @@ namespace RAY {
int _animationCount;
//! @brief The file where the animations were loaded (used to create a copy of this class)
const std::string _filePath;
std::string _filePath;
static Cache<::ModelAnimation> _animationsCache;
};
+27 -21
View File
@@ -73,24 +73,6 @@ namespace RAY {
template<>
class Cache<::ModelAnimation> {
public:
Cache(std::function<::ModelAnimation *(const char *, int *)> dataLoader, std::function<void(::ModelAnimation *, unsigned int)>dataUnloader):
_dataLoader(std::move(dataLoader)), _dataUnloader(std::move(dataUnloader))
{};
std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter)
{
if (this->_cache.find(path) != this->_cache.end())
return this->_cache[path];
::ModelAnimation *animations = this->_dataLoader(path.c_str(), counter);
unsigned int animCount = *counter;
this->_cache.emplace(path, std::shared_ptr<::ModelAnimation>(
animations, [this, animCount](::ModelAnimation *p) {
this->_dataUnloader(p, animCount);
}));
return this->_cache[path];
};
private:
//! @brief function to call to load data
std::function<::ModelAnimation *(const char *, int *)> _dataLoader;
@@ -98,10 +80,34 @@ namespace RAY {
//! @brief function to call when the ray data will be unloaded
std::function<void(::ModelAnimation *, unsigned int)> _dataUnloader;
//! @brief map storing shared ptr of caches
std::unordered_map<std::string, std::shared_ptr<::ModelAnimation>> _cache;
};
typedef struct {
std::shared_ptr<::ModelAnimation> animations;
int animationsCount;
} AnimationsHolder;
//! @brief map storing shared ptr of caches
std::unordered_map<std::string, AnimationsHolder> _cache;
public:
Cache(std::function<::ModelAnimation *(const char *, int *)> dataLoader, std::function<void(::ModelAnimation *, unsigned int)>dataUnloader):
_dataLoader(std::move(dataLoader)), _dataUnloader(std::move(dataUnloader))
{};
std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter)
{
if (this->_cache.find(path) != this->_cache.end()) {
*counter = this->_cache[path].animationsCount;
} else {
::ModelAnimation *animations = this->_dataLoader(path.c_str(), counter);
int animCount = *counter;
AnimationsHolder holder = {std::shared_ptr<::ModelAnimation>(
animations, [this, animCount](::ModelAnimation *p) {
this->_dataUnloader(p, animCount);
}),animCount};
this->_cache.emplace(path, holder);
}
return this->_cache[path].animations;
};
};
template<>
class Cache<::Shader>
{