Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Resource Manager

This is an archived page!
This page is very old and the content is not up to date.
Not everything (if any) which is written here will be in the final game!

Resources are Objects, that can be loaded from a harddrive, and then used from memory. Because the loading process is quite Resource-dependable, the loading of each resource (e.g Texture, 3d-model etc.) should be made as little as possible.

For this Orxonox provides a Shared Resource System for these time-consuming processes.

  1. Resources that are loaded (like a Texture) always have a Data-type (like TextureData) where the data is stored.
  2. The Resources have a counted pointer to these Data, so if you copy one Texture to another one, only the pointer will be copied, and the reference-count of the pointer will be automatically increased
  3. To Finaly load a Resource from disc, and keep a constant version of the Data in check, the Resource functionality is finally used: for the Resource Texture the coresponding Resourcerer is ResourceTexture. Resources do:
    • locate Files on the disc in a Directoy of your joice
    • store a copy of a ResourceData with a Key-Name.

In the following document ResourceTexture is only assumed as an Example. This also works with ResourceMD2, ResourceOBJ, ResourceSoundBuffer and so on.

Usage Example

  • Share a Resource (assumes texutre has some data assigned to it):
    #include "texture.h"
    ...
     Texture copy = texture;
    

Here you can see, that copy has _NO_ pointer type, so we can copy one Texture to another one, and both textures share the same data.

  • Load a Texture from the disc with ResourceTexture
    #include "texture.h"
    #include "resource_texture.h"
    
    ...
      Texture storeTex = ResourceTexture("orxonox.png", GL_TEXTURE_2D);
    

As you can see Texture is loaded over ResourceTexture, the data loaded in Resource Texture is assigned as easy from Texture to storeTex as from any other Texture (since ResourceTexture isA Texture :) ).

Behind the scenes

ResourceTexture is a Handler that is derived from Texture and Resource.

  • The Texture part sais, how to load a Texture from a disc.
  • The Resource part sais, where the Resource can be found, and to check if the Resource was already loaded
Last modified 7 years ago Last modified on Apr 15, 2017, 3:03:03 PM