aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2019-05-27 15:07:57 +0200
committerJulien Gouesse <[email protected]>2019-05-27 15:07:57 +0200
commitde5b31c49742e57b8be3af51d37a6213a26ac002 (patch)
tree4ec6203ff6dbc56e9464f13748bf5b25670bce39
parentc9294898d899661a0273d02073fe377190e0c2c6 (diff)
Replaces Guava's Multimap by Java Map in ardor3d-animation (issue #13)
-rw-r--r--ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/blendtree/SimpleAnimationApplier.java42
1 files changed, 35 insertions, 7 deletions
diff --git a/ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/blendtree/SimpleAnimationApplier.java b/ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/blendtree/SimpleAnimationApplier.java
index 5772568..4fe4769 100644
--- a/ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/blendtree/SimpleAnimationApplier.java
+++ b/ardor3d-animation/src/main/java/com/ardor3d/extension/animation/skeletal/blendtree/SimpleAnimationApplier.java
@@ -10,6 +10,9 @@
package com.ardor3d.extension.animation.skeletal.blendtree;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
@@ -22,15 +25,13 @@ import com.ardor3d.extension.animation.skeletal.clip.TriggerCallback;
import com.ardor3d.extension.animation.skeletal.clip.TriggerData;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.Spatial;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
/**
* Very simple applier. Just applies joint transform data, calls any callbacks and updates the pose's global transforms.
*/
public class SimpleAnimationApplier implements AnimationApplier {
- private final Multimap<String, TriggerCallback> _triggerCallbacks = ArrayListMultimap.create(0, 0);
+ private final Map<String, List<TriggerCallback>> _triggerCallbacks = new HashMap<>();
private final Map<String, Spatial> _spatialCache = new WeakHashMap<>();
@@ -92,8 +93,11 @@ public class SimpleAnimationApplier implements AnimationApplier {
try {
// pull callback(s) for the current trigger key, if exists, and call.
for (final String curTrig : trigger.getCurrentTriggers()) {
- for (final TriggerCallback cb : _triggerCallbacks.get(curTrig)) {
- cb.doTrigger(applyToPose, manager);
+ final List<TriggerCallback> curTrigCallbackList = _triggerCallbacks.get(curTrig);
+ if (curTrigCallbackList != null) {
+ for (final TriggerCallback cb : curTrigCallbackList) {
+ cb.doTrigger(applyToPose, manager);
+ }
}
}
} finally {
@@ -113,11 +117,35 @@ public class SimpleAnimationApplier implements AnimationApplier {
@Override
public void addTriggerCallback(final String key, final TriggerCallback callback) {
- _triggerCallbacks.put(key, callback);
+ _triggerCallbacks.compute(key, (final String realKey, final List<TriggerCallback> oldValue) -> {
+ final List<TriggerCallback> newValue;
+ if (oldValue == null) {
+ newValue = new ArrayList<>();
+ } else {
+ newValue = oldValue;
+ }
+ newValue.add(callback);
+ return newValue;
+ });
}
@Override
public boolean removeTriggerCallback(final String key, final TriggerCallback callback) {
- return _triggerCallbacks.remove(key, callback);
+ final boolean[] result = new boolean[] { false };
+ _triggerCallbacks.compute(key, (final String realKey, final List<TriggerCallback> oldValue) -> {
+ final List<TriggerCallback> newValue;
+ if (oldValue == null) {
+ newValue = null;
+ } else {
+ result[0] = oldValue.remove(callback);
+ if (result[0] && oldValue.isEmpty()) {
+ newValue = null;
+ } else {
+ newValue = oldValue;
+ }
+ }
+ return newValue;
+ });
+ return result[0];
}
}