use of spacegraph.space2d.Surface in project narchy by automenta.
the class Ortho method updateMouse.
/**
* called each frame regardless of mouse activity
*/
Surface updateMouse(float sx, float sy, short[] buttonsDown) {
if (!updatingMouse.compareAndSet(false, true)) {
error(this, 1f, "update collision; skipped");
// skipped - this is BAD. maybe should be properly queued
return null;
}
try {
Surface touching = finger.touching;
Surface touchedNext = finger.on(surface, sx, sy, buttonsDown);
if (touchedNext != null && touchedNext != touching) {
debug(this, 1f, () -> "touch(" + touchedNext + ")");
}
return touchedNext;
} finally {
updatingMouse.set(false);
}
}
use of spacegraph.space2d.Surface in project narchy by automenta.
the class Container method onTouch.
@Override
public Surface onTouch(Finger finger, short[] buttons) {
if (!visible())
return null;
if (childrenCount() > 0) {
// Draw forward, propagate touch events backwards
if (finger == null) {
forEach(c -> c.onTouch(null, null));
return null;
} else {
// HACK
final Surface[] found = { null };
float fx = finger.pos.x;
float fy = finger.pos.y;
// iterate in reverse, so that the contents drawn last are tested first for interaction (sloppy z-ordering)
whileEachReverse(c -> {
if (!clipTouchBounds || (fx >= c.left() && fx <= c.right() && fy >= c.top() && fy <= c.bottom())) {
Surface s = c.onTouch(finger, buttons);
if (s != null) {
if (found[0] == null || found[0].bounds.cost() > s.bounds.cost())
// FIFO
found[0] = s;
}
}
// while null
return found[0] == null;
});
if ((found[0]) != null)
return found[0];
}
}
return tangible() ? this : null;
}
use of spacegraph.space2d.Surface in project narchy by automenta.
the class ExeCharts method metaGoalControls.
public static Surface metaGoalControls(NAR n) {
CheckBox auto = new CheckBox("Auto");
auto.set(false);
float[] want = n.emotion.want;
Gridding g = grid(// Stream.of(auto),
IntStream.range(0, want.length).mapToObj(w -> new FloatSlider(want[w], -1f, +1f) {
@Override
protected void paintWidget(GL2 gl, RectFloat2D bounds) {
if (auto.on()) {
value(want[w]);
}
}
}.text(MetaGoal.values()[w].name()).type(BaseSlider.Knob).on((s, v) -> {
if (!auto.on())
want[w] = v;
})).toArray(Surface[]::new));
return g;
}
use of spacegraph.space2d.Surface in project narchy by automenta.
the class ExeCharts method metaGoalChart.
private static Surface metaGoalChart(NAgent a) {
return new TreeChart<Cause>() {
final DurService on;
final FasterList<ItemVis<Cause>> cache = new FasterList();
final Function<Cause, TreeChart.ItemVis<Cause>> builder = ((i) -> {
short id = i.id;
ItemVis<Cause> item;
if (cache.capacity() - 1 < id)
cache.ensureCapacity(id + 16);
else {
item = cache.get(id);
if (item != null)
return item;
}
String str = i.toString();
if (str.startsWith("class nars."))
// skip default toString
str = str.substring("class nars.".length());
if (str.startsWith("class "))
// skip default toString
str = str.substring(5);
item = new CauseVis(i, str);
cache.set(id, item);
return item;
});
{
on = a.onFrame(() -> {
update(a.nar().causes, (c, i) -> {
float v = c.value();
float r, g, b;
if (v < 0) {
r = 0.75f * Math.max(0.1f, Math.min(1f, -v));
g = 0;
} else {
g = 0.75f * Math.max(0.1f, Math.min(1f, +v));
r = 0;
}
float t = Util.sum(((FloatFunction<Traffic>) (p -> Math.abs(p.last))), c.goal);
b = Math.max(r, g) / 2f * Util.unitize(t);
i.update(v, r, g, b);
// i.updateMomentum(
// //0.01f + Util.sqr(Util.tanhFast(v)+1),
// //Math.signum(v) *(1+Math.abs(v))*(t),
// //Math.signum(v) * t,
// v,
// 0.25f,
// r, g, b);
}, builder);
});
}
@Override
public void stop() {
super.stop();
on.off();
}
};
}
use of spacegraph.space2d.Surface in project narchy by automenta.
the class ExeCharts method runPanel.
public static Surface runPanel(NAR n) {
Label nameLabel;
LoopPanel control = new LoopPanel(n.loop);
Surface p = new Gridding(nameLabel = new Label(n.self().toString()), control);
return DurSurface.get(p, n, () -> {
control.update();
});
}
Aggregations