Sign in to follow this  

Asset Manager

This topic is 816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All,

I'm working on a game, and I've been agonizing how I'm going to implement my asset manager. I really want to do this the 'data driven' way. I have a folder filled with assets. Sprite animations, static assets, etc... These images are composited into one larger bitmap using a bin packing algorithm. This is my image atlas that I use to render to the screen.

Now I've been loading and using my assets by hard coding all of the asset loading into the code. For example:

 

 

String[] assetsRequired = {"grass1.png","grass2.png","grass3.png","cloud1.png","cloud2.png","cloud3.png","mountain1.png","mountain2.png",
"mountain3.png","0.png","1.png","2.png","3.png","4.png","5.png","6.png","7.png","8.png","9.png"};

 

And this is just getting the background set up.

 

I pass this array to the AssetManager to take care of the bin packing and setting up texture regions into a member of the AssetManager. Then I reference the texture region something like AssetManager.grass1 in my code.

 

So now I have all of these references to files and data members littered throughout my code which is a problem. I'm hoping that 'data driven' asset management can help me here but I can't seem to get a grip on how it should work. Either way I slice it, I can't see a way to get this done without hardcoding things like, "grass1.png" in my code.

 

Does anyone have any ideas on how I should be implementing this?

 

 

Share this post


Link to post
Share on other sites

This is great! I'm going to give this a shot, thanks! I was definitely missing the 'map' piece. I would have an xml file outlining all of the assets, then I would think about how I could load all the assets based on this xml file. Then I would think, well heck I'm still going to have to hardcode the asset names when I need to use them in the code. But the way you mention it I can just use a map file to mention these assets by name. Then load these config files and write my code so that it knows nothing about the specifics of the maps/assets.

 

Thank you!

Share this post


Link to post
Share on other sites

What I did was create sha hashes of each file name at compile time and build a header that held them. This was done by a perl script.

 

Then when I wanted to access a particular sprite or texture I would refer to it by id. This avoided an expensive string lookup in the hash map.

 

If you need an example of this let me know as I would be happy to share source.

Share this post


Link to post
Share on other sites

Ah that sounds interesting. I could use both of these methods together. Well, except how would the map loading routine know how to reference the hashed assets? All it has is the ID that is set up in the data before runtime... How do I get the performance boost of a hash map with the flexibility of data driven asset management?

Share this post


Link to post
Share on other sites
I would start with the approach as sketched by the Servant, and see how fast it is. If it is fast enough (which is likely unless you have a large map or need to load the map very often), just leave it at that.
One of the bigger pitfalls in programming is to optimize things that don't need to go faster.

Share this post


Link to post
Share on other sites

This topic is 816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this