object oriented – Resource management classes in C++ game

This is a part of simple sfml C++ game, but I think neither the library nor the language is that much crucial here. I am mainly worried about the design.

I have a class template ResourceHolder<Key, Resource> to hold one type of Resource such as texture or sound, inside a map. A key is usually an enum but can be anything.

I also have a class ResourceManager that keeps all available ResourceHolders in one place.

A simplified class diagram:

enter image description here

I am providing the full code for those classes:

ResourceHolder.h:

template <typename Key, typename Resource>
class ResourceHolder {
public:
    explicit ResourceHolder(std::string resourcesDir = "../resources/")
            : resourcesDir{std::move(resourcesDir)}
    {}

    template <typename... Args>
    void insert(const Key& key, Args&&... args) {
        auto resPtr = std::make_unique<Resource>();
        if (!resPtr->loadFromFile(resourcesDir + std::forward<Args>(args)...)) {
            msgErrorLoading(std::forward<Args>(args)...);
            ///* todo: should I e.g. "throw ErrorLoadingResource" here? */
        }
        resources.emplace(key, std::move(resPtr));
    }

    Resource& get(const Key& key) const {
        if (auto resource = resources.find(key); resource != std::end(resources)) {
            return *(resource->second);
        } throw std::invalid_argument{"No such resource id."};
    }

    void erase(const Key& key) noexcept {
        if (auto found = resources.find(key); found != std::end(resources)) {
            resources.erase(key);
        }
    }

    void eraseAll() {
        resources.clear();
    }

private:
    std::string resourcesDir;
    std::unordered_map<Key, std::unique_ptr<Resource>> resources;

public:
    template <typename... Args>
    ResourceHolder& operator+=(const ResourceInserter<Key, Args...>& inserter) {
        insert(std::move(inserter.key), std::move(std::get<Args>(inserter.args)...));
        return *this;
    }

    inline const Resource& operator()(const Key& key) const {
        return get(std::move(key));
    }

    inline Resource& operator()(const Key& key) {
        return get(std::move(key));
    }

    auto& getResources() const {
        return resources;
    }

    auto& getResourcesDir() const {
        return resourcesDir;
    }

    void setResourcesDir(std::string newPath) {
        resourcesDir = std::move(newPath);
    }

private:
    template <typename... Args>
    void msgErrorLoading(const Args... args) {
         std::cerr << "Failed loading resource: { Type: "" << typeid(Resource).name()<< "", File name: "";
        (std::cerr << ... << args) << "" }" << std::endl;
    }
};

ResourceManager.h:

class ResourceManager {
public:
    ResourceManager();

private:
    ResourceHolder<res::Texture, sf::Texture> textures;
    ResourceHolder<res::Sound, sf::SoundBuffer> sounds{"../resources/sound/"};

    void loadTextures();
    void loadSounds();

public:
    auto& getTextures() {
        return textures;
    }

    auto& getSounds() {
        return sounds;
    }
};

ResourceManager.cpp:

ResourceManager::ResourceManager() {
    loadTextures();
    loadSounds();
}

void ResourceManager::loadTextures() {
    textures.insert(res::Texture::Wizard, "wizard.png");
    textures.insert(res::Texture::Gray,   "gray.png");
    textures.insert(res::Texture::Orange, "orange.png");
}

void ResourceManager::loadSounds() {
    sounds += ResourceInserter(res::Sound::Bullet, "boing.wav");
    sounds += ResourceInserter(res::Sound::Bing,   "boing_long.wav");
    sounds += ResourceInserter(res::Sound::Poof,   "poof.wav");
}

ResourceInserter.h:

/** Operator += must take one argument
 *  This is a proxy class for operator+=
 *  You can use operator+= instead of insert() as an alternative insertion method
 */

template <typename Key, typename... Args>
class ResourceInserter {
public:
    explicit ResourceInserter(Key&& key, Args&&... args)
            : key{std::forward<Key>(key)}
            , args{std::forward<Args>(args)...}
    {}

    Key key;
    std::tuple<Args...> args;
};

template <typename T, typename... Args>
ResourceInserter(T&&, Args&&... args) -> ResourceInserter<T, Args...>;

Resources.h

namespace res {
    enum class Texture {
        Gray,
        Orange,
        Wizard
    };

    enum class Sound {
        Bullet,
        Poof,
        Bing
    };
}

Some basic usage (inside parent/caller/owner class):

auto wizardTexture = textures.get(res::Texture::Wizard);
auto bulletSound   = sounds(res::Sound::Bullet);

I am not asking for a deep-throughout review as I imagine it’d take too much off of your time.


I have few questions, answering any of them would be absolutely helpful.

  1. Whatever you think of that looks smelly or problematic, please do let me know.
  2. What’s wrong with my design from OOP/design patterns point of view? (I am especially worried about the part where I am inserting all the resources inside ResourceManager.cpp)
  3. What’s wrong with my code from C++ point of view? (I am especially interested in parts where I attempted using move semantics/perfect forwarding e.g. insert method or operator+=)
  4. Is there something confusing related to naming identifiers?

The reason why I am using enums as keys is that it works as a sort of connection interface for both insertion and then retrieval of the resource. If I insert a resource of key Enum_Type::Enum_Item, then I can also retrieve it using the same key.

I’d rather not hardcode the insertion process inside ResourceManager.cpp, and preferably keep it in a separate file, but the fact that I am using Enum as a key is kind of an obstacle here for me. Not sure how to fix it.


Thanks a lot!

Server Management & Web Hosting Support ( Help Desk & Live Chat Support )


Get your own SUPPORT TEAM who works with you with TOTAL responsibility in a professional way!

We just want YOUR clients to be happy with the SERVICES

For which we GIVE the best!

The WEB HOSTING SUPPORT PLANS suits for ANY SIZE of Web Hosting Companies.

SERVICES OFFERED BY US:

– 24/7 Support Coverage

– 24/7 Server Management

– Unlimited Ticket Support

– Unlimited Live Chat Support

– Datacenter Communication

– 24/7 Skype Support [For Your Management & Support Team]

SUPPORT PLANS:
https://www.supportfacility.com/hostingsupportservices

– DEDICATED REMOTE STAFF

– SEMI DEDICATED REMOTE STAFF

– PER SERVER PLAN

– 24/7 LIVE CHAT SUPPORT

– SERVER MANAGEMENT

And much more….

Kindly schedule a one to one meeting and we can discuss further. Discussions can be done in ANY timezone on Skype.

Get in touch with us today!

https://www.supportfacility.com/portal/contact.php

Proactive Server Management Service – FREE DirectAdmin or Clientexec or Blesta

Are you getting DOS attacks? Is your server slow? Are you getting a lot of spam? Are your sites getting injected with malware? Is your server being used for attack? Do you want to decrease the load on your server? How about having 100% server up time and making your clients smile? Or simply put, do you want your server to perform well?

Look no further. We have the right solutions for your problems.

Why do you need to secure your server with JoneSolutions? Simply because you want the above-mentioned problems solved and you want your server to perform well, and thus provide better up time and security for your clients. If you secure your server with JS, you will have happy clients and you can enjoy focusing on your business and enjoy spending time with your loved ones knowing your server is in good hands.

Security is the number one priority a server owner should have. If you do not secure your server properly, you will experience more down time, slow running server sites, hacked web sites and spam. And the worst problem is, if your server is being used to attack other servers.

With our solutions, we will keep hackers away from your server and block those unnecessary bots connecting to your server. You will experience 100% up time, amazing server performance and best of all, a secured server.

And we are not yet done. What is the use of the secured server if it is not optimised properly?

Our optimisation is based on your server specifications setup and the kind of sites you are running. With lesser load due to our security setup, we can even do more by optimising services running on your server including Apache, PHP, MariaDB, etc. I bet you would agree that security and speed, complementing each other, is a good combination. SECURITY AND SPEED are what Jonesolutions is expert of and these are what we offer to you.

Our technical staff has 16+ years of experience in managing servers. We are currently managing 400+ servers from the USA, Italy and other countries.

Start protecting and optimising your server by signing up now.

For more informations, visit 101% Secured With JoneSolutions .

45$ Per Month, Billed Quarterly –> Click Here To Sign Up

Requirements:

1.) You must have cPanel or DirectAdmin.

2.) Operating System (OS) Supported: All RedHat, CentOS and CloudLinux Products

Promo: For a limited time, we offer free DirectAdmin ( Standard ) or Clientexec or Blesta with our server management service.

Are you getting a better price from other providers? Show it to us and we will try to beat it.

If you have any questions about our server management/features, please email us at sales@jonesolutions.com or chat with us live. .

Server Management FAQ

——————————————————————

********** Special Offers 4 Someone Special Like You ****************

———————————————————————–

Some Testimonials About Our Services:

https://www.webhostingtalk.com/showt…9#post10191859
https://www.webhostingtalk.com/showt…3#post10182883
https://www.webhostingtalk.com/showt…0#post10182800
https://jonesolutions.com/testimonial-view/cecio/
http://www.webhostingtalk.com/showpo…6&postcount=12
http://www.webhostingtalk.com/showpo…7&postcount=13
http://www.webhostingtalk.com/showpo…05&postcount=1
http://www.webhostingtalk.com/showpo…07&postcount=3
http://www.webhostingtalk.com/showpo…49&postcount=5
http://www.webhostingtalk.com/showpo…53&postcount=6
http://www.webhostingtalk.com/showpo…5&postcount=16
http://www.webhostingtalk.com/showpo…79&postcount=4
http://www.webhostingtalk.com/showpo…42&postcount=8
http://www.webhostingtalk.com/showpo…0&postcount=35
http://xenforo.com/community/threads…9/#post-200451
http://www.webhostingtalk.com/showpo…75&postcount=1
http://www.webhostingtalk.com/showpo…0&postcount=15
http://www.webhostingtalk.com/showpo…4&postcount=22
http://www.webhostingtalk.com/showpo…4&postcount=11
http://www.webhostingtalk.com/showpo…4&postcount=11
http://www.webhostingtalk.com/showpo…6&postcount=15
http://www.webhostingtalk.com/showpo…63&postcount=7
http://www.webhostingtalk.com/showpo…74&postcount=6
http://www.webhostingtalk.com/showpo…97&postcount=1
http://www.webhostingtalk.com/showpo…60&postcount=1
http://www.webhostingtalk.com/showpo…4&postcount=15
http://www.vbulletin.org/forum/showp…7&postcount=12
http://www.webhostingtalk.com/showpost.php?p=4496870
http://www.webhostingtalk.com/showpost.php?p=4495732
http://www.webhostingtalk.com/showpo…82&postcount=4
http://www.webhostingtalk.com/showpo…71&postcount=7
http://www.webhostingtalk.com/showpo…31&postcount=3
http://www.webhostingtalk.com/showpo…7&postcount=21
http://www.webhostingtalk.com/showpo…8&postcount=10
http://webhostingtalk.com/showpost.p…04&postcount=2
http://www.webhostingtalk.com/showpo…45&postcount=2
http://www.webhostingtalk.com/showpo…66&postcount=3
http://www.webhostingtalk.com/showpo…66&postcount=4
http://webhostingtalk.com/showpost.p…29&postcount=1
http://webhostingtalk.com/showpost.p…91&postcount=5

————————————————————–

Looking for Linux Reseller Hosting? Visit https://jonesolutions.com/premium-ssd-linux-reseller/
Looking for cPanel Fully Managed KVM VPS? Visit https://jonesolutions.com/fully-managed-kvm-vps/
Looking for cPanel Fully Managed Cloud KVM VPS? Visit https://jonesolutions.com/fully-managed-cloud-ssd-vps/
Looking for cPanel Fully Managed Dedicated Servers? Visit https://jonesolutions.com/fully-mana…cated-servers/
Looking for Acronis Backup Service? Visit https://jonesolutions.com/acronis-backup-cloud/
Looking for Cloudlinux License? Visit https://jonesolutions.com/cloudlinux-license/
Looking for KernelCare License? Visit https://jonesolutions.com/kernelcare-license/

Thanks,

net

mysql – Product Inventory Management System

I’ve been reading inventory management system tutorials for a while but still don’t understand.
Let’s assume we are in charge of developing a typical crud API to serve a variety of products.
At first, we just have 10 different products, so we can make a model for each one. But the more successful the application, the more product models we will have to add. So it becomes tedious to make a unique model for each product. Therefore, I decide to use the flexibility of MongoDB documents and let the products not have a strict scheme.
But it also has its own challenge, like validating an incoming product to make sure it has at least the minimum required fields since we don’t have a scheme against which to validate the incoming product.

What recommendations can I apply in a scenario like this?

regex – Why are tagged expressions not found in SQL Server Management Studio?

I understand from my reading that curly brackets denote tagged expression in a “find” in SQL Server Management Studio (SSMS) with “use regular expressions” toggled on. And that backslash n is a placeholder for that matched text in replace. Even before I get to the replace I cannot get the find to work. For instance with this text …

this that

… and this find …

{(a-z)*}

… I get “the following specified text was not found”. If I remove the curly brackets the find gets a hit on each of those two words as expected. What am I doing wrong? This is SSMS v18.5.

wordpress.com – Is there any management free wordpress hosting/website builder?

There are plenty of providers offering “managed” WordPress – but usually this just means that they install WordPress for you, and you have to deal with the rest, technical maintenance etc.

https://wordpress.com seems like they offer this

I also found https://10web.io/ – but they write that from time to time you need to login to the ftp and delete the .maintenance file, exactly the kind of stuff I want to get rid off.

It’s basically impossible to know from the website’s description if it is really hassle-free, without trying it out. Did you make any stellar experiences with any service?

release management – Tracking stories and code to be released after its tested and out of the sprint

We will finish a sprint with stories tested and “Done” and thereby closed in Jira. They often sit in a branch somewhere until someone remembers we have code waiting to be pushed live. Or worse, we go to push something live and someone will pipe up with “oh that also includes xyz change…”, or even worse we push one change not realising it includes another one. Usually, it works, because it’s tested, but kinda scary we don’t often know exactly what going live without doing a thorough code review of all merge requests and diffs across multiple services/components.

Often we can’t push things live immediately as there are dependencies, related work in progress, marketing or any number of other reasons. I know feature flags are a good solution but we’re not currently planning to implement.

How do you track issues and related code that is Done, but not yet released in a methodical manner so you can see the code changes involved and the issues involved across any environment at any time?

color management – Windows 10 v1909 Loads Laptop Monitor’s ICC Profile For External Monitor

I have a brand new Sager NP6855 Windows 10 Pro v1909 laptop with an Intel i7-9750H CPU that has integrated Intel UHD 630 Graphics. An external Viewsoinic 1920 x 1080 monitor is connected via HDMI to the laptop. I have been doing color management for over 8 years and I understand the topic very well. I use Windows 10’s control panel Color Management app to assign ICC profiles to the laptop’s monitor and to the external monitor. I make these ICC profile assignments with the laptop video in the Extend display setting. I can see both ICC profiles, they are assigned to the correct displays, and everything works as expected.

As soon as I change the video display setting to either “Second screen only” or “PC screen only” Windows 10 thinks that the external monitor is Display #1 and assigns the Display #1 ICC profile to the external monitor. The problem is that Display #1 is the laptop monitor, not the external monitor. When I launch Settings> System> Display and click on “Identify,” the external monitor is identified as Display #2, which is correct. However, when I launch the control panel Color Management app and click “Identify monitors” the external monitor is identified as Display #1. I believe that because the control panel Color Management app reports the external monitor as Display #1 that that’s the reason that the laptop monitor’s ICC profile is being assigned to the external monitor, which is Display #2. This prevents me from using the correct ICC profile on the external monitor, which is where I do 99% of my work.

Has anyone seen this problem? If so, what did you do to fix it? I’ve read that Microsoft released KB4505903 to fix some of these issues prior to the release of v1909. According to articles I’ve read, the fixes offered by KB4505903 are supposed to be present in v1909, therefore I haven’t downloaded and applied KB4505903. Is there a Microsoft fix for this problem or maybe a third party app that takes ICC profile management completely away from Windows 10 (which I would be THRILLED to use!).

Thanks In Advance For Your Help!

SDLC for a registry management system?

I need to choose an SLDC for a registry management system. I decided to opt for the waterfall model. Is it a good choice?

My main reason for choosing this model is that the specifications are clearly defined.

Thank you

power management – MacOs PreventUserIdleDisplaySleep is 1 without any assertion and the computer does not turn off the screen

I noticed that the Apple display of my connected MBP was on. After digging a bit, I found that the display assertion was activated but no process called for it. How is it possible?

$ pmset -g assertions | egrep '(PreventUserIdleSystemSleep|PreventUserIdleDisplaySleep)'
   PreventUserIdleDisplaySleep    1
   PreventUserIdleSystemSleep     0