SFML community forums

Help => General => Topic started by: marktilbrook on August 21, 2017, 10:27:57 pm

Title: Help with SFML Book
Post by: marktilbrook on August 21, 2017, 10:27:57 pm
Hi all,

I am following the SFML Game Development book, however, my C++ knowledge is still average, therefore, I am finding it difficult understanding the ResourceManager part of the section, i was wondering, is it possible to build games without a resource manager and what is the best way to just add sprites and textures. Below is the resourceManager thing im talking about, i just want to try continue with the book by avoiding this but im not sure if thats possible



template <typename Resource, typename Identifier>
class ResourceHolder
{
        public:
                void                                            load(Identifier id, const std::string& filename);

                template <typename Parameter>
                void                                            load(Identifier id, const std::string& filename, const Parameter& secondParam);

                Resource&                                       get(Identifier id);
                const Resource&                         get(Identifier id) const;


        private:
                void                                            insertResource(Identifier id, std::unique_ptr<Resource> resource);


        private:
                std::map<Identifier, std::unique_ptr<Resource>> mResourceMap;
};
 
Title: Re: Help with SFML Book
Post by: eXpl0it3r on August 22, 2017, 01:26:05 pm
A resource holder isn't mandatory to write anything with SFML (otherwise it would be included in SFML), however it's highly recommended you use something like that, as managing the construction and lifetime of resources should happen centralized and require following certain rules to not invalidate references.

Maybe try re-reading that chapter and look at some examples. If you continue in the book you also might start to understand how to use it at some point.