diff options
author | Julien Gouesse <[email protected]> | 2019-05-28 12:15:22 +0200 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2019-05-28 12:15:22 +0200 |
commit | 291e8c46a6d1155dd21d11fde127820a70013d8a (patch) | |
tree | e4b88d2e5fb252587fb6a7ff8ee9c710df5079d9 /ardor3d-core | |
parent | f019b6dd39a173576488a98cd05a7adbb85b9832 (diff) |
Replaces Guava's Multimap by Java Map in DisplayListDelegate (issue #13)
Diffstat (limited to 'ardor3d-core')
-rw-r--r-- | ardor3d-core/src/main/java/com/ardor3d/util/scenegraph/DisplayListDelegate.java | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/ardor3d-core/src/main/java/com/ardor3d/util/scenegraph/DisplayListDelegate.java b/ardor3d-core/src/main/java/com/ardor3d/util/scenegraph/DisplayListDelegate.java index 64f569b..2ab7fa7 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/util/scenegraph/DisplayListDelegate.java +++ b/ardor3d-core/src/main/java/com/ardor3d/util/scenegraph/DisplayListDelegate.java @@ -11,6 +11,9 @@ package com.ardor3d.util.scenegraph; import java.lang.ref.ReferenceQueue; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -22,8 +25,6 @@ import com.ardor3d.renderer.RendererCallable; import com.ardor3d.scenegraph.Spatial; import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.SimpleContextIdReference; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; public class DisplayListDelegate implements RenderDelegate { @@ -66,7 +67,7 @@ public class DisplayListDelegate implements RenderDelegate { } public static void cleanAllDisplayLists(final Renderer deleter) { - final Multimap<Object, Integer> idMap = ArrayListMultimap.create(); + final Map<Object, List<Integer>> idMap = new HashMap<>(); // gather up expired Display Lists... these don't exist in our cache gatherGCdIds(idMap); @@ -74,7 +75,16 @@ public class DisplayListDelegate implements RenderDelegate { // Walk through the cached items and delete those too. for (final DisplayListDelegate buf : _identityCache.keySet()) { // Add id to map - idMap.put(buf._id.getGlContext(), buf._id.getId()); + idMap.compute(buf._id.getGlContext(), (final Object currentKey, final List<Integer> oldValue) -> { + final List<Integer> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(Integer.valueOf(buf._id.getId())); + return newValue; + }); } handleDisplayListDelete(deleter, idMap); @@ -82,7 +92,7 @@ public class DisplayListDelegate implements RenderDelegate { public static void cleanExpiredDisplayLists(final Renderer deleter) { // gather up expired display lists... - final Multimap<Object, Integer> idMap = gatherGCdIds(null); + final Map<Object, List<Integer>> idMap = gatherGCdIds(null); if (idMap != null) { // send to be deleted on next render. @@ -91,38 +101,51 @@ public class DisplayListDelegate implements RenderDelegate { } @SuppressWarnings("unchecked") - private static Multimap<Object, Integer> gatherGCdIds(Multimap<Object, Integer> store) { + private static Map<Object, List<Integer>> gatherGCdIds(Map<Object, List<Integer>> store) { // Pull all expired display lists from ref queue and add to an id multimap. SimpleContextIdReference<DisplayListDelegate> ref; while ((ref = (SimpleContextIdReference<DisplayListDelegate>) _refQueue.poll()) != null) { if (store == null) { // lazy init - store = ArrayListMultimap.create(); + store = new HashMap<>(); } - store.put(ref.getGlContext(), ref.getId()); + final SimpleContextIdReference<DisplayListDelegate> currentRef = ref; + store.compute(ref.getGlContext(), (final Object currentKey, final List<Integer> oldValue) -> { + final List<Integer> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(Integer.valueOf(currentRef.getId())); + return newValue; + }); ref.clear(); } return store; } - private static void handleDisplayListDelete(final Renderer deleter, final Multimap<Object, Integer> idMap) { + private static void handleDisplayListDelete(final Renderer deleter, final Map<Object, List<Integer>> idMap) { Object currentGLRef = null; // Grab the current context, if any. if (deleter != null && ContextManager.getCurrentContext() != null) { currentGLRef = ContextManager.getCurrentContext().getGlContextRep(); } // For each affected context... - for (final Object glref : idMap.keySet()) { + for (final Map.Entry<Object, List<Integer>> idMapEntry : idMap.entrySet()) { + final Object glref = idMapEntry.getKey(); // If we have a deleter and the context is current, immediately delete - if (deleter != null && glref.equals(currentGLRef)) { - deleter.deleteDisplayLists(idMap.get(glref)); + if (deleter != null && glref.equals(currentGLRef) && idMapEntry.getValue() != null) { + deleter.deleteDisplayLists(idMapEntry.getValue()); } // Otherwise, add a delete request to that context's render task queue. else { - GameTaskQueueManager.getManager(ContextManager.getContextForRef(glref)).render( - new RendererCallable<Void>() { + GameTaskQueueManager.getManager(ContextManager.getContextForRef(glref)) + .render(new RendererCallable<Void>() { @Override public Void call() throws Exception { - getRenderer().deleteDisplayLists(idMap.get(glref)); + if (idMapEntry.getValue() != null) { + getRenderer().deleteDisplayLists(idMapEntry.getValue()); + } return null; } }); |