/** * Creates an emitter that uses {@code batch} to render its particles. When this emitter's * layer is added to the scene graph, it will connect itself to {@code paint} to drive the * particle animations, and when its layer is removed, it will disconnect from {@code paint}. * * @param batch the particle batch to use when rendering our particles. * @param paint the paint signal which will drive this emitter. * @param maxParticles the maximum number of active particles. * @param tile the texture to use when rendering particles. */ public Emitter (final ParticleBatch batch, final Signal<Clock> paint, final int maxParticles, final Tile tile) { this.layer = new Layer() { @Override protected void paintImpl (Surface surface) { QuadBatch obatch = surface.pushBatch(batch); _buffer.render(batch.prepare(tile, maxParticles), tile.width(), tile.height()); surface.popBatch(obatch); } }; _buffer = new ParticleBuffer(maxParticles); LayerUtil.bind(layer, paint, new Slot<Clock>() { public void onEmit (Clock clock) { paint(clock); } }); }
public Stock (SceneGame game) { super(game); add("Shader info:", true); add(_quadShader); add(_trisShader); add("Per second:", true); add("Frames:", _frames); add("Shader creates:", _shaderCreates); add("FB creates:", _fbCreates); add("Tex creates:", _texCreates); add("Per frame:", true); add("Shader binds:", _shaderBinds); add("FB binds:", _fbBinds); add("Tex binds:", _texBinds); add("Quads drawn:", _rQuads); add("Tris drawn:", _rTris); add("Shader flushes:", _shaderFlushes); // receive paint updates while our layer is connected LayerUtil.bind(layer, game.paint, new Slot<Clock>() { public void onEmit (Clock clock) { int now = clock.tick; if (now > _nextUpdate) { willUpdate(); update(); _nextUpdate = now + 1000; } } protected int _nextUpdate; }); }