The principle class of the Field Graphics "Scene List" structure. A Scene is a list of Perform instances that can run at various passes of their choosing. Passes are ordered numerically and created on demand. By convention geometry is drawn on pass 0. For example a texture Perform might set
| 31 | * reexpressing the semantics of OpenGL's decaying state-machine just right. |
| 32 | */ |
| 33 | public class Scene extends Box implements fieldlinker.AsMap { |
| 34 | |
| 35 | static public Dict.Prop<LinkedHashMapAndArrayList<Perform>> passes = new Dict.Prop<LinkedHashMapAndArrayList<Perform>>("passes").toCanon(); |
| 36 | static public Method supplier_get; |
| 37 | static private Object[] nothing = {}; |
| 38 | |
| 39 | static { |
| 40 | try { |
| 41 | supplier_get = Supplier.class.getDeclaredMethod("get"); |
| 42 | } catch (NoSuchMethodException e) { |
| 43 | e.printStackTrace(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public TreeMap<Integer, Set<Consumer<Integer>>> internalScene = new TreeMap<>(); |
| 48 | protected Set<String> knownNonProperties; |
| 49 | Map<String, Consumer<Integer>> tagged = new LinkedHashMap<>(); |
| 50 | List<Throwable> exceptions = new ArrayList<Throwable>(); |
| 51 | UniformBundle defaultBundle = null; |
| 52 | |
| 53 | /** |
| 54 | * utility, takes a consumer and returns a version that runs only once every "count" iterations |
| 55 | */ |
| 56 | |
| 57 | static public <T> Consumer<T> strobe(Consumer<T> c, int count) { |
| 58 | return new Consumer<T>() { |
| 59 | int tick = 0; |
| 60 | |
| 61 | @Override |
| 62 | public void accept(T t) { |
| 63 | if (tick++ % count == 0) c.accept(t); |
| 64 | } |
| 65 | }; |
| 66 | } |
| 67 | |
| 68 | static public Perform perform(int pass, Supplier<Boolean> action) { |
| 69 | return new Perform() { |
| 70 | @Override |
| 71 | public boolean perform(int pass) { |
| 72 | return action.get(); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int[] getPasses() { |
| 77 | return new int[pass]; |
| 78 | } |
| 79 | }; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * A (int pass, Consumer<Integer>) tuple can be effectively cast as a Perform. The int says what pass the consumer should be run for, and the consumer is called for that pass |
| 84 | */ |
| 85 | public boolean attach(int pass, Consumer<Integer> p) { |
| 86 | Set<Consumer<Integer>> c = internalScene.get(pass); |
| 87 | if (c == null) internalScene.put(pass, c = new LinkedHashSet<Consumer<Integer>>()); |
| 88 | return c.add(p); |
| 89 | } |
| 90 |