From 5ec8a86b0294b8cbe7769b2623002e0728859fba Mon Sep 17 00:00:00 2001 From: PolishPigeon Date: Sat, 22 Jan 2022 11:37:35 +0100 Subject: [PATCH] feat: Divided resource.cpp file into resource.hpp and resource.inl --- SFMLEngine/makingAGameTick/app | Bin 77704 -> 77704 bytes SFMLEngine/makingAGameTick/game.cpp | 2 +- SFMLEngine/makingAGameTick/game.o | Bin 127632 -> 127632 bytes SFMLEngine/makingAGameTick/resources.hpp | 27 ++++++++++++++++++ .../{resources.cpp => resources.inl} | 24 ++-------------- 5 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 SFMLEngine/makingAGameTick/resources.hpp rename SFMLEngine/makingAGameTick/{resources.cpp => resources.inl} (66%) diff --git a/SFMLEngine/makingAGameTick/app b/SFMLEngine/makingAGameTick/app index f17f686a19ab0bf4ae022b344323f1b5102a4ad7..db3781e0534d3409b2628da92329679371ff0f3e 100755 GIT binary patch delta 58 zcmV-A0LA}^-vo%?1h9Am6ji^*tf8oAlJ6d|KGF!7t(}e9*0YQQ{x$&)vx_=50Ra@V Q!aJxm18Ht-vu$u2zcrg0SpWb4 delta 58 zcmV-A0LA}^-vo%?1h9Am6qik&)VeSq;^5KexgN;8^!5xr; #include #include "constants.hpp" -#include "resources.cpp" +#include "resources.hpp" #include "basic.cpp" diff --git a/SFMLEngine/makingAGameTick/game.o b/SFMLEngine/makingAGameTick/game.o index 624a22ec9080da0de50d0ce72626956812c2d43e..5fc86b3f4425e853f470c839ba90c371b4359cfd 100644 GIT binary patch delta 40 ycmV+@0N4MJd#2sQx$6qC^iAG0S4a|#1#Zft{{6t|re0rTB6Qx69K delta 40 ycmV+@0N4MJ+!AG0S4a|#1vaBzd26t|re0rTBA0}m?z diff --git a/SFMLEngine/makingAGameTick/resources.hpp b/SFMLEngine/makingAGameTick/resources.hpp new file mode 100644 index 0000000..bfbbf0e --- /dev/null +++ b/SFMLEngine/makingAGameTick/resources.hpp @@ -0,0 +1,27 @@ +#ifndef RESOURCES_HPP +#define RESOURCES_HPP + +#include +// Mostly Chapter 2 +// Handles resource management +namespace Textures // This gives us a scope for the enumerators which allows us to write Textures::Airplane instead of just Airplane to avoid name collisions in the global scope +{ + enum ID { Landscape, Airplane, Missile }; +} + +class TextureHolder +{ + public: + void load(Textures::ID id, const std::string& filename); + sf::Texture& get(Textures::ID id); + const sf::Texture& get(Textures::ID id) const; + private: + std::map< Textures::ID, std::unique_ptr > mTextureMap; + // unique_ptr are class templates that act like pointers, this allows us to work with heavyweight objects without copying them all the time, or we can store classes that are non-cpyable like sf::Shader +}; + + + +#include "resources.inl" + +#endif // RESOURCES_HPP diff --git a/SFMLEngine/makingAGameTick/resources.cpp b/SFMLEngine/makingAGameTick/resources.inl similarity index 66% rename from SFMLEngine/makingAGameTick/resources.cpp rename to SFMLEngine/makingAGameTick/resources.inl index 6ca9833..f773553 100644 --- a/SFMLEngine/makingAGameTick/resources.cpp +++ b/SFMLEngine/makingAGameTick/resources.inl @@ -1,24 +1,6 @@ -#ifndef RESOURCES_CPP -#define RESOURCES_CPP +#ifndef RESOURCES_INL +#define RESOURCES_INL -#include -// Mostly Chapter 2 -// Handles resource management -namespace Textures // This gives us a scope for the enumerators which allows us to write Textures::Airplane instead of just Airplane to avoid name collisions in the global scope -{ - enum ID { Landscape, Airplane, Missile }; -} - -class TextureHolder -{ - public: - void load(Textures::ID id, const std::string& filename); - sf::Texture& get(Textures::ID id); - const sf::Texture& get(Textures::ID id) const; - private: - std::map< Textures::ID, std::unique_ptr > mTextureMap; - // unique_ptr are class templates that act like pointers, this allows us to work with heavyweight objects without copying them all the time, or we can store classes that are non-cpyable like sf::Shader -}; void TextureHolder::load(Textures::ID id, const std::string& filename) // Function to load a resource, it takes one parameter for filename and one for identifier @@ -45,4 +27,4 @@ const sf::Texture& TextureHolder::get(Textures::ID id) const // we need to be ab return *found -> second; // We have to access the second member of the pointer, then we deference it and get a texture } -#endif //RESOUIRCES_CPP +#endif // RESOURCES_INL