*******************************************************************************/
package org.simantics.scenegraph.profile.common;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.simantics.scenegraph.g2d.G2DSceneGraph;
import org.simantics.scenegraph.profile.EvaluationContext;
import org.simantics.scenegraph.profile.ProfileEntry;
+import org.simantics.scenegraph.profile.Style;
import org.simantics.scenegraph.profile.impl.DebugPolicy;
import org.simantics.scenegraph.profile.impl.ProfileActivationListener;
import org.simantics.scenegraph.profile.request.RuntimeProfileActiveEntries;
+import org.simantics.utils.datastructures.Pair;
import org.simantics.utils.datastructures.disposable.IDisposable;
import org.simantics.utils.threads.IThreadWorkQueue;
import org.simantics.utils.threads.ThreadUtils;
private final Runnable notification;
private final G2DSceneGraph sceneGraph;
- private boolean dirty = true;
- private boolean disposed = false;
+ private volatile boolean dirty = true;
+ private volatile boolean disposed = false;
+ private List<Pair<Style, Object>> updates = new ArrayList<>();
+ private boolean updateAll;
+
private ProfileActivationListener activationListener;
private Map<String, Object> constants = new HashMap<String, Object>();
}
@Override
- public void update() {
+ public void update(Style style, Object item) {
if (DebugPolicy.DEBUG_PROFILE_OBSERVER_UPDATE)
System.out.println("Profile observer marked dirty.");
+
+ updates.add(new Pair<>(style, item));
+ //updateAll = true;
dirty = true;
}
+ public void update() {
+ updateAll = true;
+ dirty = true;
+ }
+
private void perform() {
dirty = false;
if (DebugPolicy.DEBUG_PROFILE_OBSERVER_UPDATE)
// Variables.init(e, ProfileObserver.this);
// }
- for(ProfileEntry e : entries) {
- if (DebugPolicy.DEBUG_PROFILE_OBSERVER_PERFORM)
- System.out.println("Apply profile entry: " + e);
- e.apply(ProfileObserver.this);
+
+ long t0 = System.nanoTime();
+
+ if (updateAll) {
+ for(ProfileEntry e : entries) {
+ if (DebugPolicy.DEBUG_PROFILE_OBSERVER_PERFORM)
+ System.out.println("Apply profile entry: " + e);
+ e.apply(ProfileObserver.this);
+ }
+ updateAll = false;
+ updates.clear();
+ } else {
+ List<Pair<Style, Object>> updatesCopy = new ArrayList<>(updates);
+ updates.clear();
+ for (Pair<Style, Object> update : updatesCopy) {
+ Style style = update.first;
+ Object item = update.second;
+
+ style.apply2(item, ProfileObserver.this);
+ }
}
+
+ long t1 = System.nanoTime();
+ System.out.println((t1-t0) / 1e6);
+
if(dirty) {
sceneGraph.setPending(ProfileObserver.this);
// System.err.println("setPending, dirty=true");