mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 08:26:42 +00:00 
			
		
		
		
	- Remove broken cache locking mechanism This was supposed to unload NIFFiles after a cell transition completes, but it was never working due to a mistake on the line if (--sLockLevel), should have been if (--sLockLevel == 0). Repairing this would increase load times (NIF files would have to be reloaded more frequently), so just removed it for now. - Decouple cache from NIFFile (now a new nifcache component) - Add API for future background loading - Provide a reliable way (SharedPtr) to hold on to loaded NIFFiles. This will be useful to avoid deep copies of keyframe and text key data, which is currently a performance bottleneck.
		
			
				
	
	
		
			48 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #ifndef OPENMW_COMPONENTS_NIFCACHE_H
 | |
| #define OPENMW_COMPONENTS_NIFCACHE_H
 | |
| 
 | |
| #include <components/nif/niffile.hpp>
 | |
| 
 | |
| #include <boost/shared_ptr.hpp>
 | |
| 
 | |
| namespace Nif
 | |
| {
 | |
| 
 | |
|     typedef boost::shared_ptr<Nif::NIFFile> NIFFilePtr;
 | |
| 
 | |
|     /// @brief A basic resource manager for NIF files
 | |
|     class Cache
 | |
|     {
 | |
|     public:
 | |
|         Cache();
 | |
| 
 | |
|         /// Queue this file for background loading. A worker thread will start loading the file.
 | |
|         /// To get the loaded NIFFilePtr, use the load method, which will wait until the worker thread is finished
 | |
|         /// and then return the loaded file.
 | |
|         //void loadInBackground (const std::string& file);
 | |
| 
 | |
|         /// Read and parse the given file. May retrieve from cache if this file has been used previously.
 | |
|         /// @note If the file is currently loading in the background, this function will block until
 | |
|         ///       the background loading finishes, then return the background loaded file.
 | |
|         /// @note Returns a SharedPtr to the file and the file will stay loaded as long as the user holds on to this pointer.
 | |
|         ///       When all external SharedPtrs to a file are released, the cache may decide to unload the file.
 | |
|         NIFFilePtr load (const std::string& filename);
 | |
| 
 | |
|         /// Return instance of this class.
 | |
|         static Cache& getInstance();
 | |
|         static Cache* getInstancePtr();
 | |
| 
 | |
|     private:
 | |
|         static Cache* sThis;
 | |
| 
 | |
|         Cache(const Cache&);
 | |
|         Cache& operator =(const Cache&);
 | |
| 
 | |
|         typedef std::map<std::string, NIFFilePtr> LoadedMap;
 | |
| 
 | |
|         LoadedMap mLoadedMap;
 | |
|     };
 | |
| 
 | |
| }
 | |
| 
 | |
| #endif
 |