~ubuntu-branches/ubuntu/oneiric/nux/oneiric

« back to all changes in this revision

Viewing changes to NuxGraphics/GLResourceManager.h

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-06-22 17:16:16 UTC
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: james.westby@ubuntu.com-20110622171616-49405ntrtnxfcpjj
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
 
143
143
  protected:
144
144
    NResourceSet       *Set;
145
 
    bool                Cached;
 
145
    bool                _cached;
146
146
    unsigned int        NumRefs;
147
147
    NObjectType        *ResourceType;
148
148
 
191
191
    NObjectType *m_ResourceType;
192
192
  };
193
193
 
194
 
  template <class T, class D>
 
194
  template <typename T, typename U>
195
195
  class TGLResourceFactory : public NResourceFactory
196
196
  {
197
197
  public:
212
212
        @param  Resource        Resource to build and cache.
213
213
        @return The built resource.
214
214
    */
215
 
    virtual CachedResourceData *BuildResource (NResourceSet *ResourceManager, ResourceData *Resource)
 
215
    virtual CachedResourceData *BuildResource(NResourceSet *ResourceManager, ResourceData *Resource)
216
216
    {
217
 
      return new D (ResourceManager, (T *) Resource);
 
217
      return new U(ResourceManager, (T *)Resource);
218
218
    }
219
219
  };
220
220
 
277
277
      for (It = ResourceMap.begin(); It != ResourceMap.end(); It++)
278
278
      {
279
279
//         ObjectPtr< ResourceType >    CachedResource = (*It).second;
280
 
//         CachedResource->Cached = 0;
 
280
//         CachedResource->_cached = 0;
281
281
//         CachedResource.Release();
282
 
        (*It).second->Cached = 0;
 
282
        (*It).second->_cached = 0;
283
283
        (*It).second.Release();
284
284
      }
285
285
 
291
291
    {
292
292
      typedef std::map< IdType, ObjectPtr< ResourceType > >  MapType;
293
293
      ResourceMap.insert (typename MapType::value_type (Id, Resource) );
294
 
      Resource->Cached = 1;
 
294
      Resource->_cached = 1;
295
295
    }
296
296
 
297
297
    ObjectPtr<ResourceType> FindCachedResourceById (const IdType &Id)
305
305
      return ObjectPtr<ResourceType> (0);
306
306
    }
307
307
 
308
 
    void FlushResourceId (const IdType &Id)
 
308
    /*!
 
309
        Remove a cached resource from the cache. The cached resource may still have references to it.
 
310
        The resource internal flag "_cached" is set to false.
 
311
    */
 
312
    void FlushResourceId(const IdType &Id)
309
313
    {
310
 
      ObjectPtr< ResourceType > CachedResource (0);
311
 
 
312
 
      typedef std::map< IdType, ObjectPtr< ResourceType > >  MapType;
313
 
      typename MapType::iterator it = ResourceMap.find (Id);
314
 
 
315
 
      if (it != ResourceMap.end() )
 
314
      ObjectPtr<ResourceType>   CachedResource(0);
 
315
 
 
316
      typedef std::map<IdType, ObjectPtr<ResourceType> >  MapType;
 
317
      typename MapType::iterator it = ResourceMap.find(Id);
 
318
 
 
319
      if(it != ResourceMap.end())
316
320
        CachedResource = (*it).second;
317
321
 
318
 
      if (CachedResource.IsValid() )
 
322
      if(CachedResource.IsValid())
319
323
      {
320
 
        ResourceMap.erase (it);
321
 
        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.
 
324
        ResourceMap.erase(it);
 
325
        CachedResource->_cached = false;
322
326
      }
323
327
    }
324
328
 
334
338
        if (CachedResource == Resource)
335
339
        {
336
340
          ResourceMap.erase (it);
337
 
          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.
 
341
          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.
338
342
          return;
339
343
        }
340
344
      }
364
368
    bool         IsCachedResource (ResourceData *Source);
365
369
 
366
370
    virtual void InitializeResourceFactories();
367
 
    virtual void FreeResource (ResourceData *Resource)
368
 
    {
369
 
      FlushResourceId (Resource->GetResourceIndex() );
370
 
    }
 
371
//     virtual void FreeResource (ResourceData *Resource)
 
372
//     {
 
373
//       FlushResourceId(Resource->GetResourceIndex());
 
374
//     }
371
375
  };
372
376
 
373
377