OSDN Git Service

Change asset cache.
authorKazuhiko Kobayashi <chototsu_moushinp@yahoo.co.jp>
Sat, 19 Jan 2013 15:54:33 +0000 (00:54 +0900)
committerkobayasi <kobayasi@pscnet.co.jp>
Sat, 6 Jul 2013 01:37:51 +0000 (10:37 +0900)
engine/src/desktop/com/jme3/asset/DesktopAssetManager.java
engine/src/desktop/com/jme3/asset/SoftRefCache.java [new file with mode: 0644]

index 7cbd7a8..a0c486b 100644 (file)
@@ -58,7 +58,7 @@ public class DesktopAssetManager implements AssetManager {
 \r
     private static final Logger logger = Logger.getLogger(AssetManager.class.getName());\r
 \r
-    private final AssetCache cache = new AssetCache();\r
+    private final SoftRefCache cache = new SoftRefCache();\r
     private final ImplHandler handler = new ImplHandler(this);\r
 \r
     private AssetEventListener eventListener = null;\r
@@ -208,17 +208,17 @@ public class DesktopAssetManager implements AssetManager {
         AssetKey smartKey = null;\r
         Object o = null;\r
         if (key.shouldCache()){\r
-            if (key.useSmartCache()){\r
-                SmartAssetInfo smartInfo = cache.getFromSmartCache(key);\r
-                if (smartInfo != null){\r
-                    smartKey = smartInfo.smartKey.get();\r
-                    if (smartKey != null){\r
-                        o = smartInfo.asset;\r
-                    }\r
-                }\r
-            }else{\r
+//            if (key.useSmartCache()){\r
+//                SmartAssetInfo smartInfo = cache.getFromSmartCache(key);\r
+//                if (smartInfo != null){\r
+//                    smartKey = smartInfo.smartKey.get();\r
+//                    if (smartKey != null){\r
+//                        o = smartInfo.asset;\r
+//                    }\r
+//                }\r
+//            }else{\r
                 o = cache.getFromCache(key);\r
-            }\r
+//            }\r
         }\r
         if (o == null){\r
             AssetLoader loader = handler.aquireLoader(key);\r
diff --git a/engine/src/desktop/com/jme3/asset/SoftRefCache.java b/engine/src/desktop/com/jme3/asset/SoftRefCache.java
new file mode 100644 (file)
index 0000000..67f0928
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.jme3.asset;
+
+import java.lang.ref.SoftReference;
+import java.util.HashMap;
+
+/**
+ *
+ * @author kobayasi
+ */
+public class SoftRefCache {
+    private final HashMap<AssetKey, SoftReference> cache = new HashMap<AssetKey, SoftReference>();
+    public void addToCache(AssetKey key, Object obj) {
+        cache.put(key, new SoftReference(obj));
+    }
+
+    public void deleteAllAssets() {
+        cache.clear();
+    }
+
+    public boolean deleteFromCache(AssetKey key) {
+        return cache.remove(key) != null;
+    }
+
+    public Object getFromCache(AssetKey key) {
+        SoftReference ref = cache.get(key);
+        if (ref != null) {
+            return ref.get();
+        }
+        return null;
+    }
+
+//    public AssetCache.SmartAssetInfo getFromSmartCache(AssetKey key) {
+//        SoftReference ref = cache.get(key);
+//        if (ref != null) {
+//            return ref.get();
+//        }
+//        return null;
+//    }
+    
+}