Skip to content

Commit

Permalink
use getters for private vars
Browse files Browse the repository at this point in the history
  • Loading branch information
azeem committed Mar 25, 2018
1 parent 8c61f44 commit 039f3ce
Show file tree
Hide file tree
Showing 36 changed files with 351 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -3,5 +3,5 @@ node_modules
*.iml
dist
.tmp
.doc
doc
coverage
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -12,7 +12,7 @@
"func-test": "karma start",
"unit-test": "cross-env TARGET=cjs mocha-webpack \"./test/unit/**/*.ts\"",
"lint": "tslint -c tslint.json \"src/**/*.ts\" \"test/**/*.ts\"",
"clean": "shx rm -rf ./dist ./coverage"
"clean": "shx rm -rf ./doc ./dist ./coverage"
},
"repository": {
"type": "git",
Expand Down
12 changes: 10 additions & 2 deletions src/Container.ts
Expand Up @@ -41,7 +41,7 @@ export default abstract class Container extends Component implements IContainer
const components = [];
if (this.opts.components) {
for (const opts of this.opts.components) {
const componentClass = this.main.componentRegistry.getComponentClass(opts.type);
const componentClass = this.main.getComponentRegistry().getComponentClass(opts.type);
const component = new componentClass(this.main, this, opts);
components.push(component);
}
Expand Down Expand Up @@ -78,7 +78,7 @@ export default abstract class Container extends Component implements IContainer
component = componentOpts;
component.setParent(this);
} else {
const componentClass = this.main.componentRegistry.getComponentClass(componentOpts.type);
const componentClass = this.main.getComponentRegistry().getComponentClass(componentOpts.type);
component = new componentClass(this.main, this, componentOpts);
}
this.components.splice(pos, 0, component);
Expand Down Expand Up @@ -156,4 +156,12 @@ export default abstract class Container extends Component implements IContainer
}
return opts;
}

/**
* sets the frambuffer manager for this container
* @param fm the frambuffermanager
*/
protected setFBM(fm: FrameBufferManager) {
this.fm = fm;
}
}
79 changes: 61 additions & 18 deletions src/EffectList.ts
Expand Up @@ -6,6 +6,9 @@ import IMain from "./IMain";
import { BlendModes } from "./utils";
import FrameBufferManager from "./webgl/FrameBufferManager";

/**
* BlendModes supported by Effectlist
*/
export enum ELBlendModes {
REPLACE = 1,
MAXIMUM,
Expand All @@ -20,15 +23,49 @@ export enum ELBlendModes {
IGNORE,
}

/**
* Options for EffectList
*/
export interface IEffectListOpts {
/**
* EEL code to control the effectlist.
*
* Following varaibles are available:
*
* + `beat`: 0 or 1 to indicate a beat for the current frame
* + `enabled`: set this to 0 or 1 to disable or enable the effectlist
* + `clear`: set this to 0 or 1 to clear the frame
*/
code: {
/**
* EEL that will be run on init
*/
init: string,
/**
* EEL that will be run per frame
*/
perFrame: string,
};
/**
* The output blend mode. Default: "REPLACE"
*/
output: string;
/**
* The input blend mode. Default: "IGNORE"
*/
input: string;
/**
* Enable clearing each frame. Default: false
*/
clearFrame: boolean;
/**
* If set, the this effectlist is enabled only on a beat. Default: false
*/
enableOnBeat: boolean;
/**
* When enableOnBeat, this determines the number of beats
* counted before the Effectlist is enabled. Default: 1
*/
enableOnBeatFor: number;
}

Expand All @@ -40,8 +77,12 @@ interface IELCodeInstance extends CodeInstance {
perFrame: () => void;
}

// Effectlist is a container that renders components to a separate buffer. and blends
// it in with the parent buffer. Its also used as the root component in Webvs.Main
/**
* Effectlist is a container that renders components to a separate buffer. And blends
* it in with the parent buffer.
*
* An implicit Effeclist is also created by [[Main]] as a root component.
*/
export default class EffectList extends Container {
public static componentName = "EffectList";
public static componentTag = "";
Expand Down Expand Up @@ -76,7 +117,9 @@ export default class EffectList extends Container {

public init() {
super.init();
this.fm = new FrameBufferManager(this.main.rctx, this.main.copier, this.parent ? true : false);
const fm = new FrameBufferManager(
this.main.getRctx(), this.main.getCopier(), this.parent ? true : false);
this.setFBM(fm);
this.updateCode();
this.updateBlendMode(this.opts.input, "input");
this.updateBlendMode(this.opts.output, "output");
Expand All @@ -89,7 +132,7 @@ export default class EffectList extends Container {
const opts = this.opts;

if (opts.enableOnBeat) {
if (this.main.analyser.beat) {
if (this.main.getAnalyser().isBeat()) {
this.frameCounter = opts.enableOnBeatFor;
} else if (this.frameCounter > 0) {
this.frameCounter--;
Expand All @@ -101,7 +144,7 @@ export default class EffectList extends Container {
}
}

this.code.beat = this.main.analyser.beat ? 1 : 0;
this.code.beat = this.main.getAnalyser().isBeat() ? 1 : 0;
this.code.enabled = 1;
this.code.clear = opts.clearFrame ? 1 : 0;
if (!this.inited) {
Expand All @@ -114,20 +157,20 @@ export default class EffectList extends Container {
}

// set rendertarget to internal framebuffer
this.fm.setRenderTarget();
this.getFBM().setRenderTarget();

// clear frame
if (opts.clearFrame || this.first || this.code.clear) {
const gl = this.main.rctx.gl;
const gl = this.main.getRctx().getGl();
gl.clearColor(0, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
this.first = false;
}

// blend input texture onto internal texture
if (this.input !== ELBlendModes.IGNORE) {
const inputTexture = this.parent.fm.getCurrentTexture();
this.main.copier.run(this.fm, { srcTexture: inputTexture }, this.input as number);
const inputTexture = this.parent.getFBM().getCurrentTexture();
this.main.getCopier().run(this.getFBM(), { srcTexture: inputTexture }, this.input as number);
}

// render all the components
Expand All @@ -139,27 +182,27 @@ export default class EffectList extends Container {
}

// switch to old framebuffer
this.fm.restoreRenderTarget();
this.getFBM().restoreRenderTarget();

// blend current texture to the output framebuffer
if (this.output !== ELBlendModes.IGNORE) {
if (this.parent) {
this.main.copier.run(
this.parent.fm,
{ srcTexture: this.fm.getCurrentTexture() },
this.main.getCopier().run(
this.parent.getFBM(),
{ srcTexture: this.getFBM().getCurrentTexture() },
this.output as number,
);
} else {
this.main.copier.run(null, { srcTexture: this.fm.getCurrentTexture() });
this.main.getCopier().run(null, { srcTexture: this.getFBM().getCurrentTexture() });
}
}
}

public destroy() {
super.destroy();
if (this.fm) {
if (this.getFBM()) {
// destroy the framebuffer manager
this.fm.destroy();
this.getFBM().destroy();
}
}

Expand All @@ -178,7 +221,7 @@ export default class EffectList extends Container {
}

private handleResize() {
this.fm.resize();
this.code.updateDimVars(this.main.rctx.gl);
this.getFBM().resize();
this.code.updateDimVars(this.main.getRctx().getGl());
}
}
48 changes: 40 additions & 8 deletions src/IMain.ts
Expand Up @@ -6,13 +6,45 @@ import CopyProgram from "./webgl/CopyProgram";
import FrameBufferManager from "./webgl/FrameBufferManager";
import RenderingContext from "./webgl/RenderingContext";

/**
* Interface for [[Main]] like objects. This is
* used by Components to refer to main, avoiding circular references
*/
export default interface IMain extends Model {
rctx: RenderingContext;
rsrcMan: ResourceManager;
copier: CopyProgram;
analyser: AnalyserAdapter;
componentRegistry: ComponentRegistry;
tempBuffers: FrameBufferManager;
registerBank: {[key: string]: number};
bootTime: number;
/**
* Returns the rendering context for webgl rendering
*/
getRctx(): RenderingContext;
/**
* Returns the Resource Manager that manages media resources
*/
getRsrcMan(): ResourceManager;
/**
* Returns A shader program that can be used to copy frames
*/
getCopier(): CopyProgram;
/**
* Returns the analyser instance that's used to get music data
* for the visualization
*/
getAnalyser(): AnalyserAdapter;
/**
* Returns a registry of [[Component]] classes that will be used
* to create preset effects
*/
getComponentRegistry(): ComponentRegistry;
/**
* Returns a FrameBufferManager for global temporary buffers, that can
* be shared between components.
*/
getTempFBM(): FrameBufferManager;
/**
* Returns register bank, a map of shared register values available
* in EEL code in components.
*/
getRegisterBank(): {[key: string]: number};
/**
* Returns the timestamp at which this instance was constructed
*/
getBootTime(): number;
}

0 comments on commit 039f3ce

Please sign in to comment.