Jump to content

  • Log In with Google      Sign In   
  • Create Account


return shared_ptr or Handle ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Tispe   Members   -  Reputation: 978

Like
0Likes
Like

Posted 20 April 2014 - 01:40 PM

Hi

 

I am refactoring and the Asset Manager has a std::map of all the game resources. But I can't quite think of how I should encapsulate things.

 

An entity manager can for example use the asset manager and call GetResource...(ID) and use it. But should GetResource() return a HANDLE with a shared_ptr inside it, or can I just return the shared_ptr?

 

It seems if I use handles I just put another layer on the cake but it does not do anything.

 

Any tips?

struct GameAssets
{
	std::vector<std::shared_ptr<Mesh> > Meshes;
	std::vector<std::shared_ptr<Texture> > Textures;
	std::vector<std::shared_ptr<Animation> > AnimationTracks;
	std::vector<std::shared_ptr<Skeleton> > Skeletons;
};

struct HandleAssets
{
	std::shared_ptr<GameAssets> Assets;
};

class AssetManager
{
public:
	AssetManager();
	~AssetManager();

	HandleAssets GetResourceByHandle(DWORD ID);
	std::shared_ptr<GameAssets> GetResourceBysptr(DWORD ID);

private:
	std::map<DWORD, HandleAssets > AllAssetsByHandle;
	std::map<DWORD, std::shared_ptr<GameAssets> > AllAssetsBysptr;
};


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 12212

Like
3Likes
Like

Posted 20 April 2014 - 01:49 PM

I am about to head out so I can only give a short answer, but you are correct that the extra layer on the cake is needless.
Just return a shared pointer and be alert as to how to and not to use them (as in passing them as references, not copies, to functions, etc.)


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS