Back to index

nux  3.0.0
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends
nux::NResourceCache Class Reference

#include <GLResourceManager.h>

Inheritance diagram for nux::NResourceCache:
Inheritance graph
[legend]
Collaboration diagram for nux::NResourceCache:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 NResourceCache ()
ObjectPtr< CachedResourceDataGetCachedResource (ResourceData *Source)
bool IsCachedResource (ResourceData *Source)
virtual void InitializeResourceFactories ()
void Flush ()
void AddCachedResource (const int &Id, ObjectPtr< CachedResourceData > Resource)
ObjectPtr< CachedResourceDataFindCachedResourceById (const int &Id)
void FlushResourceId (const int &Id)
 Remove a cached resource from the cache.
virtual void FlushResource (CachedResourceData *Resource)
std::vector< NResourceFactory * > & GetResourceFactories (void)
std::vector< NResourceUpdater * > & GetResourceUpdaters (void)

Public Attributes

std::map< int, ObjectPtr
< CachedResourceData > > 
ResourceMap
std::vector< NResourceFactory * > ResourceFactories
std::vector< NResourceUpdater * > ResourceUpdaters

Protected Member Functions

virtual void FreeResource (ResourceData *Resource)

Protected Attributes

CachedResourceDataFirstResource

Friends

class CachedResourceData

Detailed Description

Definition at line 360 of file GLResourceManager.h.


Constructor & Destructor Documentation

Definition at line 363 of file GLResourceManager.h.

      :   TResourceCache<int, CachedResourceData>()
    {}

Member Function Documentation

void nux::TResourceCache< int , CachedResourceData >::AddCachedResource ( const int &  Id,
ObjectPtr< CachedResourceData Resource 
) [inline, inherited]

Definition at line 290 of file GLResourceManager.h.

    {
      typedef std::map< IdType, ObjectPtr< ResourceType > >  MapType;
      ResourceMap.insert(typename MapType::value_type(Id, Resource));
      Resource->_cached = 1;
    }

Here is the caller graph for this function:

ObjectPtr<CachedResourceData > nux::TResourceCache< int , CachedResourceData >::FindCachedResourceById ( const int &  Id) [inline, inherited]

Definition at line 297 of file GLResourceManager.h.

    {
      typedef std::map< IdType, ObjectPtr< ResourceType > >  MapType;
      typename MapType::iterator it = ResourceMap.find(Id);

      if (it != ResourceMap.end())
        return(*it).second;

      return ObjectPtr<ResourceType> (0);
    }

Here is the caller graph for this function:

void nux::TResourceCache< int , CachedResourceData >::Flush ( ) [inline, virtual, inherited]

Reimplemented from nux::NResourceSet.

Definition at line 272 of file GLResourceManager.h.

    {
      // See the language FAQ 35.18 at http://www.parashift.com/c++-faq-lite/templates.html  for why the "typename".
      typename std::map< IdType, ObjectPtr< ResourceType > >::iterator It;

      for (It = ResourceMap.begin(); It != ResourceMap.end(); It++)
      {
//         ObjectPtr< ResourceType >      CachedResource = (*It).second;
//         CachedResource->_cached = 0;
//         CachedResource.Release();
        (*It).second->_cached = 0;
        (*It).second.Release();
      }

      // Erases all elements from the map.
      ResourceMap.clear();
    }
virtual void nux::TResourceCache< int , CachedResourceData >::FlushResource ( CachedResourceData Resource) [inline, virtual, inherited]

Reimplemented from nux::NResourceSet.

Definition at line 329 of file GLResourceManager.h.

    {
      typedef std::map< IdType, ObjectPtr< ResourceType > >  MapType;
      typename MapType::iterator it;

      for (it = ResourceMap.begin(); it != ResourceMap.end(); it++)
      {
        ObjectPtr< ResourceType >  CachedResource = (*it).second;

        if (CachedResource == Resource)
        {
          ResourceMap.erase(it);
          CachedResource->_cached = 0; // Make sure that if the following line deletes the resource, it doesn't try to remove itself from the TDynamicMap we're iterating over.
          return;
        }
      }
    }
void nux::TResourceCache< int , CachedResourceData >::FlushResourceId ( const int &  Id) [inline, inherited]

Remove a cached resource from the cache.

The cached resource may still have references to it. The resource internal flag "_cached" is set to false.

Definition at line 312 of file GLResourceManager.h.

    {
      ObjectPtr<ResourceType>      CachedResource(0);

      typedef std::map<IdType, ObjectPtr<ResourceType> >  MapType;
      typename MapType::iterator it = ResourceMap.find(Id);

      if (it != ResourceMap.end())
        CachedResource = (*it).second;

      if (CachedResource.IsValid())
      {
        ResourceMap.erase(it);
        CachedResource->_cached = false;
      }
    }

Here is the call graph for this function:

virtual void nux::NResourceSet::FreeResource ( ResourceData Resource) [inline, protected, virtual, inherited]

Definition at line 95 of file GLResourceManager.h.

{}

Definition at line 148 of file GLResourceManager.cpp.

  {
    NUX_RETURN_VALUE_IF_NULL(Source, ObjectPtr<CachedResourceData>(0));
    
    // check to see if it already exists
    ObjectPtr<CachedResourceData> CachedResource = TResourceCache<int, CachedResourceData>::FindCachedResourceById(Source->GetResourceIndex());

    if (CachedResource.IsNull())
    {
      // iterate over the list of factory types
      for (unsigned int i = 0; i < GetResourceFactories().size(); ++i)
      {
        NResourceFactory *ResourceFactory = GetResourceFactories() [i];

        // check if the factory is valid for the source resource type
        if (ResourceFactory->BuildsThisResource(Source))
        {
          // cache the device resource
          CachedResourceData* ptr = ResourceFactory->BuildResource(this, Source);
          CachedResource = ObjectPtr<CachedResourceData> (ptr);
          ptr->UnReference();
          break;
        }
      }

      // make sure the result is valid
      if (CachedResource.IsNull())
      {
        nuxError("Cannot cache resource type %s", Source->Type().name );
      }
      else
      {
        // Get resource type
        CachedResource->ResourceType      = & (Source->Type());
        // add it to the pool of cached resources
        AddCachedResource(Source->GetResourceIndex(), CachedResource);
      }
    }

    return CachedResource;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector<NResourceFactory *>& nux::TResourceCache< int , CachedResourceData >::GetResourceFactories ( void  ) [inline, inherited]

Definition at line 350 of file GLResourceManager.h.

    {
      return(ResourceFactories);
    }

Here is the caller graph for this function:

std::vector<NResourceUpdater *>& nux::TResourceCache< int , CachedResourceData >::GetResourceUpdaters ( void  ) [inline, inherited]

Definition at line 354 of file GLResourceManager.h.

    {
      return(ResourceUpdaters);
    }

Implements nux::TResourceCache< int, CachedResourceData >.

Definition at line 111 of file GLResourceManager.cpp.

  {
    // Define the factory pair ResourceData - CachedResourceData
#define NUX_DEFINE_RESOURCE_FACTORY_PAIR(SourceTypeName, ResourceTypeName) \
    static TGLResourceFactory<SourceTypeName, ResourceTypeName> Factory##SourceTypeName(&SourceTypeName::StaticObjectType); \
    GetResourceFactories().push_back(&Factory##SourceTypeName);

    NUX_DEFINE_RESOURCE_FACTORY_PAIR(Texture2D, CachedTexture2D);
    NUX_DEFINE_RESOURCE_FACTORY_PAIR(TextureRectangle, CachedTextureRectangle);
    NUX_DEFINE_RESOURCE_FACTORY_PAIR(TextureCube, CachedTextureCube);
    NUX_DEFINE_RESOURCE_FACTORY_PAIR(TextureVolume, CachedTextureVolume);
    NUX_DEFINE_RESOURCE_FACTORY_PAIR(TextureFrameAnimation, CachedTextureFrameAnimation);
    NUX_DEFINE_RESOURCE_FACTORY_PAIR(VertexBuffer, CachedVertexBuffer);
    NUX_DEFINE_RESOURCE_FACTORY_PAIR(IndexBuffer, CachedIndexBuffer);
    NUX_DEFINE_RESOURCE_FACTORY_PAIR(VertexDeclaration, CachedVertexDeclaration);
    NUX_DEFINE_RESOURCE_FACTORY_PAIR(MeshBuffer, CachedMeshBuffer);

#undef NUX_DEFINE_RESOURCE_FACTORY_PAIR

    // Define the factory updater for and ResourceData
#define NUX_DEFINE_RESOURCE_UPDATER(SourceTypeName) \
    static NResourceUpdater Updater##SourceTypeName(&SourceTypeName::StaticObjectType); \
    GetResourceUpdaters().push_back(&Updater##SourceTypeName);

    NUX_DEFINE_RESOURCE_UPDATER(Texture2D);
    NUX_DEFINE_RESOURCE_UPDATER(TextureRectangle);
    NUX_DEFINE_RESOURCE_UPDATER(TextureCube);
    NUX_DEFINE_RESOURCE_UPDATER(TextureVolume);
    NUX_DEFINE_RESOURCE_UPDATER(TextureFrameAnimation);
    NUX_DEFINE_RESOURCE_UPDATER(VertexBuffer);
    NUX_DEFINE_RESOURCE_UPDATER(IndexBuffer);
    NUX_DEFINE_RESOURCE_UPDATER(VertexDeclaration);
    NUX_DEFINE_RESOURCE_UPDATER(MeshBuffer);

#undef NUX_DEFINE_RESOURCE_UPDATER
  }

Here is the caller graph for this function:

Definition at line 190 of file GLResourceManager.cpp.

  {
    ObjectPtr<CachedResourceData> CachedResource = TResourceCache< int, CachedResourceData >::FindCachedResourceById(Source->GetResourceIndex());
    return(CachedResource.IsValid());
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class CachedResourceData [friend, inherited]

Definition at line 100 of file GLResourceManager.h.


Member Data Documentation

Definition at line 86 of file GLResourceManager.h.

Definition at line 262 of file GLResourceManager.h.

Definition at line 259 of file GLResourceManager.h.

Definition at line 265 of file GLResourceManager.h.


The documentation for this class was generated from the following files: