Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Help with SFML Book  (Read 1053 times)

0 Members and 1 Guest are viewing this topic.

marktilbrook

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Help with SFML Book
« 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;
};
 
« Last Edit: August 21, 2017, 11:25:42 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Help with SFML Book
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/