My resources are killing me

How are you guys handling your resources (textures, images, sound, models)?



What I would like is some kind of resource manager. Is this something others feel the need for as well? What features would you like too see in it?



Possible features:


  • Register paths in the resource manager for different kinds of assets: data/sounds, data/textures, etc. Then you specify only the filename of the asset when loading

  • Filename specified without the extension. This way you can compress one of your tgas to a png and change no code.

  • Assets uploaded to their respective hardware in the next update of the resource manager (load textures outside the GL thread)

  • Pluggable loaders that register the extensions they can load to the resource manager

  • Filename suffixes: background_1280x1024.tga, background_1024x768.tga ... You tell the manager that on images you want the suffix "1280x1024" and later on just load using "background". Same thing with music_22k.wav, music_44k.wav, etc...

  • ...



Looks like a lot to code though, doesn't it :P

Actually, I've got a very similar system in Galaxies Beyond and it's actually quite small.  It's based on GameSettings that determine the machine's performance and choose the quality of models and textures to load ("low", "medium", "high", and "ultra").  Since the usefulness of such a class is very specific to the game you are writing I would suggest simply writing one for your game explicitly.

true, should cost you an hour, probably 2 more for the advanced stuff

yeah…  you are probably right. Easier to procrastinate than just do it…  :slight_smile:

Oh I hear that!  :stuck_out_tongue:

darkfrog said:

Oh I hear that!  :P


and how many wheels have you reinvented??

Each of us has reinvented many wheels.



I think that about once a week I reinvent another wheel or try to make the round wheel square. :smiley:



I also use something similar to what DF did… but different.



I setup a StorageManager that contains a Map of BaseObjects (each object contains the Texure URL and width, height whatever I need)



I setup one thread for each portion I want to load.



E.g. I have a startup menu that loads first and is the smallest number to load.



I check to see if the threads have terminated… if not then I know they're not fully loaded.



The problem is to ensure that you're not calling a resource that's not been loaded.



As a matter of fact, I'm rewriting it now so it's a better implementation and actually uses the map that I've created to clone the objects.



I should point out that the way I did it before is not even close to what I wanted, but allowed me to put all of my resources together.  Now, I have to rewrite it b/c it wasn't what I wanted and doesn't handle cloning that well.  I'm implementing a SpatialPool to handle that.

Are you using the ObjectPool I created for jME?


drfugly said:

and how many wheels have you reinvented??


Quite a few, but when the world is driving on square pegs I feel I'm providing a service. ;)  What would the world be like without StandardGame, GameControls, GameConsole, ModelLoader, JGN, JavaRelational, jME-Networking, jME-Physics-Networking, GTGE-Networking, jCommon, LogicalNetwork.com, jSeamless, yet another space game, Roll-A-Rama, jHelper, jInstaller, MagicBeans, WebStartCreator, an e-mail server, a non-blocking web server, an object relational database server, and about 10,000 other projects?  :P

Besides, I sure have a fun time writing code, so if other people find it useful that's great, but I love what I do and use what I write, so I'm happy. :)
darkfrog said:

What would the world be like without StandardGame, GameControls, GameConsole, ModelLoader, JGN, JavaRelational, jME-Networking, jME-Physics-Networking, GTGE-Networking, jCommon, LogicalNetwork.com, jSeamless, yet another space game, Roll-A-Rama, jHelper, jInstaller, MagicBeans, WebStartCreator, an e-mail server, a non-blocking web server, an object relational database server, and about 10,000 other projects?  :P


Better?

The correct question was "Feeling better now after spitting that all out?"  :stuck_out_tongue:

Yes, quite. :)  I may not receive high acclaim for most (if not all) my projects, but so long as I can spew them forth in a rant every now and again in a single sentence I'm still a happy frog. :wink:

applauds 

clap-clap-clap 

Happy darkfrog:





Or:

The dude on top looks pretty scary and the Michigan J. Frog and I are all friends.



Can you believe on the first web site I ever created I think I had that exact animation TWICE on the main page…wow…brings back memories of a simpler time. :slight_smile:

Zombifying this thread…  I am currently working on something related to this topic for jME's core that can be used for Texture, Sound, Model and Shader loading instead of getting your hands dirty working directly with TextureManager and such.  Any suggestions on generally useful features are welcome.

are we talking about caching, resolving resources by names or both?

Mostly about resource resolution as many people have issues here. (Converted models and their textures for example.)  Caching could be part of it, if that makes sense, (eg, for things other than Textures which are already cached and managed by TextureManager.)

Sound move renanse.





On textures, i have many different scenes under the hood, so have some bespoke way to clear down nodes releasing the textures, but its not very reliable and only works if the texture is assigned to a spatial from a scene node.  The complete way to flush textures if im not wrong is to call TextureManager.doTextureCleanup(). This however will delete the cursor loaded, the FPS text and any JMEDesktop artefacts.



Would be nice to have a texture cache tree, or to be able to use a wrapper around TextureManager and have that wrapper as an instance so that it effects a scenegraph and its children but not its parent.





The ObjectPool sounds interesting, ill give it a look over.



Breifly touched on another thread is the fact that in some instances, the bytes are not required within the JME core after they have been sent to the GPU, any thoughts on a method signature in loading up textures etc and flagging that they are not required within the Core










Good ideas.  One more to add is that I'd like a side-effect of this to be a reduction in necessary parameters for creating Textures and other resources.  A simple, default settings Texture would then be loaded like:



resourceManager.addTextureDirectory("./mygameAssets/Textures/");

Texture t = resourceManager.findTexture("Dirt.jpg");

This is how my resource manager is used.



First of all:



ResourceManager rman = ResourceManager.getInstance();

TrackLoader trackLoader = new TrackLoader();
trackLoader.addPath("tracks/");
trackLoader.addSuffix(".txt");
rman.registerLoader(trackLoader);

TextureLoader texLoader = new TextureLoader();
texLoader.addPath("textures/");
texLoader.addSuffix(".tga");
texLoader.addSuffix(".png");
rman.registerLoader(texLoader);

FontLoader fontLoader = new FontLoader();
fontLoader.addPath("fonts/");
fontLoader.addSuffix(".fnt");
rman.registerLoader(fontLoader);



And then:


font = (Font)ResourceManager.getInstance().load("font", "arialtest", null);
sfx = (CompositeSFX)ResourceManager.getInstance().load("sfx", "argh", null);



Where "font" and "sfx" are the types, not the paths. The loaders define what types of resources they load.

Nothing advanced yet, but it's coming along nicely. I'll post the code if anyone wants to take a look at it.