mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-24 14:06:17 +01:00
feat: Divided resource.cpp file into resource.hpp and resource.inl
This commit is contained in:
parent
5f457e91e0
commit
f83141988f
Binary file not shown.
@ -4,7 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
#include "resources.cpp"
|
#include "resources.hpp"
|
||||||
#include "basic.cpp"
|
#include "basic.cpp"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
27
SFMLEngine/makingAGameTick/resources.hpp
Normal file
27
SFMLEngine/makingAGameTick/resources.hpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef RESOURCES_HPP
|
||||||
|
#define RESOURCES_HPP
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
// 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<sf::Texture> > 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
|
||||||
@ -1,24 +1,6 @@
|
|||||||
#ifndef RESOURCES_CPP
|
#ifndef RESOURCES_INL
|
||||||
#define RESOURCES_CPP
|
#define RESOURCES_INL
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
// 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<sf::Texture> > 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)
|
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
|
// 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
|
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
|
||||||
Loading…
Reference in New Issue
Block a user