public class Overlay extends flash.display.MovieClip {
- private var registry:Registry;
+ private var registry:RegistryManager;
/*
* After doing some science, 50ms seems to be roughly the time it takes
private const REFRESH_RATE = 10;
public function Overlay() {
- this.registry = new Registry(REFRESH_RATE);
+ this.registry = new RegistryManager(REFRESH_RATE);
var confParser:ConfigParserRegistry = new ConfigParserRegistry("StreamInfo.txt");
var confParser2:ConfigParserRegistry = new ConfigParserRegistry("StreamInfo2.txt");
- this.registry.addSubRegistry(confParser);
- this.registry.addSubRegistry(confParser2);
+ this.registry.addRegistry(confParser);
+ this.registry.addRegistry(confParser2);
- //this.registry.addEventListener(confParser.getUpdateEventType(), this.updated);
+ this.registry.addEventListener(registry.getUpdateEventType(), this.updated);
}
private function updated(e:Event) {
trace("updated");
+ trace(this.registry.getLastUpdated());
//var cam:Object = this.conf.get('Cam');
//trace(cam.MusicBoxBase);
}
--- /dev/null
+package {
+ import flash.events.Event
+ import flash.utils.*
+ import flash.utils.getQualifiedClassName
+
+ public class RegistryManager extends PollableBaseRegistry {
+
+ // This object will keep track of which registry last updated which
+ // values. This way there is no need to copy across values. We just check
+ // who had it last and ask her for it.
+ private var valueMap:Object;
+ private var registries:Array;
+ private var numRegistriesPolled:int;
+ private var pollRate:int;
+
+ public function RegistryManager(pollRate:int) {
+ this.registries = [];
+ this.valueMap = {};
+ this.numRegistriesPolled = 0;
+ this.pollRate = pollRate;
+
+ super.whoAmI();
+
+ var test = super;
+ test.whoAmI();
+
+ // INCEPTION INTENSIFIES
+ //this.addRegistry(super);
+
+ //setInterval(this.poll, this.pollRate);
+ }
+
+ public function addRegistry(registry:IPollableRegistry, registryCallback:Function = null) {
+ this.registries.push(registry);
+ registry.addEventListener(registry.getUpdateEventType(), this.updated);
+ registry.addEventListener(registry.getCycleCompleteEventType(), this.cycleComplete);
+ }
+
+ public override function get(propChain:String):* {
+ trace('should not see this');
+ return (this.valueMap[propChain] && this.valueMap[propChain].get(propChain));
+ }
+
+ public override function getLastUpdated():Array {
+ var updatedValues = [];
+ for (var propChain in this.valueMap) {
+ trace(this.valueMap[propChain].whoAmI());
+ // HMMMM...
+ // if we are looking at ourselves AND we have updated values, OR we are looking at something else and it has updated values
+ if(this.valueMap[propChain].getLastUpdated().indexOf(propChain) >= 0)
+ updatedValues.push(propChain)
+ }
+
+ return updatedValues;
+ }
+
+ private function poll() {
+ // This acts as a lock. After all the registries are polled, it resets to 0
+ // so we know it's safe to poll again.
+ if(this.numRegistriesPolled === 0) {
+ for each(var registry:Object in this.registries) {
+ this.numRegistriesPolled++;
+ var fn:Function = registry.getPollableFunction();
+ fn();
+ }
+ }
+ }
+
+ // Fires when _any_ of our registries are updated
+ private function updated(e:PollEvent) {
+ var update = false;
+
+ for each(var propChain in e.pollTarget.getLastUpdated()) {
+ this.valueMap[propChain] = e.pollTarget;
+ update = true;
+ }
+
+ //for each(var propChain in e.pollTarget.getLastUpdated()) {
+ // update = true;
+ // this.valueMap[propChain] = e.pollTarget;
+ //}
+
+ update && this.dispatchEvent(new PollEvent(this.getUpdateEventType(), this));
+ }
+
+ private function cycleComplete(e:PollEvent) {
+ if(this.numRegistriesPolled == this.registries.length) {
+ this.numRegistriesPolled = 0;
+ }
+
+ }
+
+ public override function whoAmI() {
+ trace("regman");
+ }
+ }
+
+}