88 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package electrosphere.renderer.assetmanager;
 | |
| 
 | |
| import electrosphere.renderer.Model;
 | |
| import electrosphere.renderer.texture.Texture;
 | |
| import electrosphere.util.ModelLoader;
 | |
| import java.util.HashMap;
 | |
| import java.util.LinkedList;
 | |
| import java.util.List;
 | |
| import java.util.UUID;
 | |
| import java.util.concurrent.ConcurrentHashMap;
 | |
| import java.util.concurrent.CopyOnWriteArrayList;
 | |
| 
 | |
| /**
 | |
|  *
 | |
|  * @author amaterasu
 | |
|  */
 | |
| public class AssetManager {
 | |
|     
 | |
|     ConcurrentHashMap<String,Model> modelsLoadedIntoMemory = new ConcurrentHashMap();
 | |
|     CopyOnWriteArrayList<String> modelsInQueue = new CopyOnWriteArrayList();
 | |
|     
 | |
|     ConcurrentHashMap<String,Texture> texturesLoadedIntoMemory = new ConcurrentHashMap();
 | |
|     CopyOnWriteArrayList<String> texturesInQueue = new CopyOnWriteArrayList();
 | |
|     
 | |
|     public void loadAssetsInQueue(){
 | |
|         for(String currentPath : modelsInQueue){
 | |
|             modelsInQueue.remove(currentPath);
 | |
|             modelsLoadedIntoMemory.put(currentPath, ModelLoader.load_Model_From_File(currentPath));
 | |
|         }
 | |
|         for(String currentPath : texturesInQueue){
 | |
|             texturesInQueue.remove(currentPath);
 | |
|             texturesLoadedIntoMemory.put(currentPath, new Texture(currentPath));
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     public void addModelPathToQueue(String path){
 | |
|         if(!modelsInQueue.contains(path) && !modelsLoadedIntoMemory.containsKey(path)){
 | |
|             modelsInQueue.add(path);
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     public Model fetchModel(String path){
 | |
|         Model rVal = null;
 | |
|         if(modelsLoadedIntoMemory.containsKey(path)){
 | |
|             rVal = modelsLoadedIntoMemory.get(path);
 | |
|         }
 | |
|         return rVal;
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|     Registers a (presumably generated in code) model with the asset manager
 | |
|     @returns a random string that represents the model in the asset manager
 | |
|     */
 | |
|     public String registerModel(Model m){
 | |
|         String rVal;
 | |
|         UUID newUUID = UUID.randomUUID();
 | |
|         rVal = newUUID.toString();
 | |
|         modelsLoadedIntoMemory.put(rVal,m);
 | |
|         return rVal;
 | |
|     }
 | |
|     
 | |
|     public void registerModelToSpecificString(Model m, String s){
 | |
|         modelsLoadedIntoMemory.put(s,m);
 | |
|     }
 | |
|     
 | |
|     public void addTexturePathtoQueue(String path){
 | |
|         if(!texturesInQueue.contains(path) && !texturesLoadedIntoMemory.containsKey(path)){
 | |
|             texturesInQueue.add(path);
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     public Texture fetchTexture(String path){
 | |
|         Texture rVal = null;
 | |
|         if(texturesLoadedIntoMemory.containsKey(path)){
 | |
|             rVal = texturesLoadedIntoMemory.get(path);
 | |
|         }
 | |
|         return rVal;
 | |
|     }
 | |
|     
 | |
|     public String registerTexture(Texture t){
 | |
|         String rVal;
 | |
|         UUID newUUID = UUID.randomUUID();
 | |
|         rVal = newUUID.toString();
 | |
|         texturesLoadedIntoMemory.put(rVal,t);
 | |
|         return rVal;
 | |
|     }
 | |
| }
 |