SFML community forums

Help => Graphics => Topic started by: The Terminator on August 13, 2012, 01:47:48 pm

Title: Are resource managers really necessary?
Post by: The Terminator on August 13, 2012, 01:47:48 pm
I've written a resource manager, and I think honestly it's more pain than just using the plain old methods for the individual objects like textures, soundbuffers, etc. Do you guys think that a resource manager is worth it for a smallish game (under 20000) lines? If so, could you explain why?
Title: Re: Are resource managers really necessary?
Post by: eXpl0it3r on August 13, 2012, 01:58:19 pm
It completly depends on the game and the code design and not on the line of codes.
If you're able to integrate the resource manager good enough into your code design then it would make a lot of sense, because everything resource related would then get handled by it.
Another reason for a resource manager is if you're using diffrent resources multiple times, so your manager will detect that he's already loaded that reasource and only direct you to the loaded one instead of slowly filling up your memory.

Now for games that run in states where at the beginning one loads all the resources and they get removed as soon as one leaves the state, it won't make much sense to have such a manager, since he'd then only function as resource loading wrapper and can be quite annoying to handle since everything is centralized.
For smaller games/code designs that allows it, it's completly okay to have the resources as member variable of the state it's used int.
Title: Re: Are resource managers really necessary?
Post by: Mark on December 27, 2013, 08:57:54 pm
Well, this is quite an old topic... But I got one very related argument against the resource managers for graphics resources too. Besides complicating the code, doesn't they upload multiple textures? And as I know, switching between textures while drawing is a very costly operation.

Wouldn't it be perfect for game to have a single texture with all the graphics the game needs on it to simplify the code and maximize performance?
Title: AW: Are resource managers really necessary?
Post by: eXpl0it3r on December 27, 2013, 09:14:16 pm
Well there's always a texture size limit, it's especially low on older hardware. ;)

Plus if the game is a bit bigger, you might not want to load all the images at once, but only when it's needed, e.g. if have 20 bosses in your game, you don't want to load all 10 "animated" images of all the 20 bosses, but you'd probably load one animated boss when sgarting the boss level.
Title: Re: Are resource managers really necessary?
Post by: Nexus on December 27, 2013, 09:16:49 pm
Well, this is quite an old topic...
Yes. Generally, prefer to open a new thread and link to the old one.

Besides complicating the code
The idea is to simplify the code. Of course you have to implement resource managers once, but if you've designed them well, the client code that uses the resources will often be simpler.

doesn't they upload multiple textures?
I don't see how this is related to resource managers. If you allocate multiple textures, yes, otherwise, no. This is the same if you directly create the sf::Texture objects and load them.

Wouldn't it be perfect for game to have a single texture with all the graphics the game needs on it to simplify the code and maximize performance?
Code will be more complicated, because you have to determine the texture rect. Furthermore, there is a size limit for textures, so you can't pack infinitely many sprites into one.
Title: Re: Are resource managers really necessary?
Post by: Mark on December 27, 2013, 09:21:56 pm
Thanks. I got the point.