mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 01:56:41 +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.
		
			
				
	
	
		
			40 lines
		
	
	
	
		
			644 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
	
		
			644 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "nifcache.hpp"
 | |
| 
 | |
| namespace Nif
 | |
| {
 | |
| 
 | |
| Cache* Cache::sThis = 0;
 | |
| 
 | |
| Cache& Cache::getInstance()
 | |
| {
 | |
|     assert (sThis);
 | |
|     return *sThis;
 | |
| }
 | |
| 
 | |
| Cache* Cache::getInstancePtr()
 | |
| {
 | |
|     return sThis;
 | |
| }
 | |
| 
 | |
| Cache::Cache()
 | |
| {
 | |
|     assert (!sThis);
 | |
|     sThis = this;
 | |
| }
 | |
| 
 | |
| NIFFilePtr Cache::load(const std::string &filename)
 | |
| {
 | |
|     // TODO: normalize file path to make sure we're not loading the same file twice
 | |
| 
 | |
|     LoadedMap::iterator it = mLoadedMap.find(filename);
 | |
|     if (it != mLoadedMap.end())
 | |
|         return it->second;
 | |
|     else
 | |
|     {
 | |
|         NIFFilePtr file(new Nif::NIFFile(filename));
 | |
|         mLoadedMap[filename] = file;
 | |
|         return file;
 | |
|     }
 | |
| }
 | |
| 
 | |
| }
 |