MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / Transient

Class Transient

src/main/java/field/graphics/Scene.java:541–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

539 }
540
541 static public class Transient implements Perform {
542 int[] passes;
543 Consumer<Integer> call;
544 LinkedHashSet<GraphicsContext> allContexts = new LinkedHashSet<>(GraphicsContext.allGraphicsContexts);
545 boolean onceOnly = false;
546
547 public Transient(Perform p) {
548 this.passes = p.getPasses();
549 this.call = (x) -> p.perform(x);
550 }
551
552 public Transient(Runnable p, int... passes) {
553 this.passes = passes;
554 this.call = (x) -> p.run();
555 }
556
557 public Transient(Consumer<Integer> m, int... passes) {
558 this.passes = passes;
559 this.call = (x) -> m.accept(x);
560 }
561
562 /**
563 * by default this transient will wait until it has run once in all contexts. Set this to change make this transient execute only once in the first context that happens to execute it
564 */
565 public Transient setOnceOnly() {
566 onceOnly = true;
567 return this;
568 }
569
570 /**
571 * by default this transient will wait until it has run once in all contexts. Use this method to limit this to just some of the graphics contexts
572 */
573 public Transient setAllContexts(Collection<GraphicsContext> c) {
574 allContexts.clear();
575 allContexts.addAll(c);
576 return this;
577 }
578
579 /**
580 * by default this transient will wait until it has run once in all contexts. Use this method to limit this to just some of the graphics contexts where object 'o' has state stored
581 */
582 public Transient setAllContextsFor(Object o) {
583 allContexts.clear();
584 GraphicsContext.allGraphicsContexts.stream().filter(x -> x.context.containsKey(o)).forEach(x -> allContexts.add(x));
585 return this;
586 }
587
588 @Override
589 public boolean perform(int pass) {
590// System.out.println(" perform for transient ?? "+this);
591 if (allContexts.remove(GraphicsContext.getContext())) call.accept(pass);
592
593 return !onceOnly && allContexts.size() > 0;
594 }
595
596 @Override
597 public int[] getPasses() {
598 return passes;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected