Resource Cache Questions

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Resource Cache Question

      Hiya,

      I'm trying to get my head around the resource cache presented in the book, and I had a question I was hoping someone could answer...

      The resource cache seems to be great at loading and cahing primitive resources like bitmaps, mesh files, etc. My design has resources like ITexture and IMesh, though, that internally hold DirectX objects, not the bitmap or X files they are stored as. I'm not sure if the resource cache is meant for caching objects like this.

      As an example, say a list of dynamic objects are created. Each one has a pointer to the IMesh object that represents it, amongst other things. That mesh object loads from an X file in the resource cache. Then the cache sits around doing... what? To be honest, it seems like a bit of an unnecessary intermediate stage for loading from an archive file.

      I don't know if I'm trying to use the cache for something it's not designed for. Is it for caching game objects and the like, or just resources that will be used to create those objects while they are being loaded, or what?

      I really hope that was clear enough, but any help would be very much appreciated :)

      The post was edited 1 time, last by beebs1 ().

    • I interpret the resource cache as a tool for creating objects that would otherwise require hard drive access. In other words, the resource cache should seek to make hard drive assets available in memory to whatever needs it.

      So, I do it like this (essentially):

      Hard drive asset, maybe some textures or something
      |
      v
      Resource cache, which keeps it in memory as long as it's needed, and knows where to look to load it up again
      |
      v
      Game object, references the textures we loaded into the cache

      That way, the object doesn't have to worry about whether the assets are in memory in order to use them, because the cache ensures that whenever an object wants to use an asset, it's in memory. It also ensures that you don't waste precious memory on extraneous hard drive assets.

      It's very useful (and necessary) in free-roam games, or games with long levels like Halo. Platformers, fighting games, etc. probably don't even need any caching, in the true sense of the word. However, it is still nice to abstract game assets into a resource in memory to save individual objects the effort and potential problems associated with loading from the hard drive.
    • Thanks - so it sits between the game and the hard disk. Heh, I was thinking it was for something different... :rolleyes:

      If the game objects reference DirectX objects though, how would the cache handle that? At the moment it only handles the actual texture files that are used to create the DX objects. Would I need to modify it for this?

      Also, does that mean the game object needs to call ReosurceCache::Get() every time it needs to do something with a resource, to make sure it is loaded?

      Thanks a lot for your help :)
    • I haven't looked at it in a while - I'd have the object ask the ResourceCache for the texture/model/script whatever rather than having the ResourceCache hold onto the object itself. That way the object is controlled by the game engine and its resources are controlled by the ResourceCache.
      "Your job is not to die for your country. Your job is to make some other poor sod die for his."