package
{
	import com.kaltura.kdpfl.model.type.NotificationType;
	import com.kaltura.kdpfl.plugin.IPlugin;
	import com.kaltura.kdpfl.plugin.IPluginFactory;
	import com.kaltura.kdpfl.plugin.component.NielsenVideoCensusMediator;
	import com.yahoo.astra.fl.controls.AbstractButtonRow;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.events.TimerEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.utils.Dictionary;
	import flash.utils.Timer;

	import org.puremvc.as3.interfaces.IFacade;

	public dynamic class nielsenVideoCensusPluginCode extends Sprite implements IPlugin
	{
		private var _nielsenMediator:NielsenVideoCensusMediator;
		private var _customEvents	:	Array;
		public function set customEvents(val:String):void{
			_customEvents		= val.split(",");
		}

		public var requestMethod	: String	= "queryString";

		//ads (st,a for ads   or  st,c for content streams)
		public var c3	:	String;

		//cookie check (cc=1)
		public var cc	:	String;

		//Show name (encoded)
		public var cg	:	String;

		public var clientId: String;
		public var videoCensusId:String;
		//video title (encoded  dav0-encoded title)
		public var tl	:	String;
		public var lp	:	String;
		public var ls	: 	String;
		public var serverUrl:String;
		private var _facade:IFacade;
		private var _eventData:Object;
		private var _paramsMap:Object =	{videoCensusId:"C6",
													clientId:"CI",
													cg:"CG",
													tl:"TL",
													lp:"LP",
													ls:"LS",
													cc:"CC",
													rnd:"RND",
													c3:"C3"};

		public function nielsenVideoCensusPluginCode()
		{
			super();
		}

		public function initializePlugin(facade:IFacade):void {
			_facade				= facade;
			_nielsenMediator 	= new NielsenVideoCensusMediator(_customEvents);
			_nielsenMediator.eventDispatcher.addEventListener(NielsenVideoCensusMediator.DISPATCH_BEACON, onBeacon);
			//_nielsenMediator.eventDispatcher.addEventListener(NielsenVideoCensusMediator.AD_START, onAdStart);

			facade.registerMediator(_nielsenMediator);

		}

		/**
		 * Do nothing.
		 * No implementation required for this interface method on this plugin.
		 * @param styleName
		 * @param setSkinSize
		 */
		public function setSkin(styleName:String, setSkinSize:Boolean = false):void {}

		private var loader : URLLoader;

		private function onAdStart(e:Event):void{
			onBeacon();
		}

		private function onCuePoints(e:Event):void{_eventData			= _nielsenMediator.eventData;}

		private function createQueryString(url:String, key:String, val:String):String{
			url 	= url.concat(key,"=",val,"&");
			return url;
		}

		public function onBeacon(e:Event=null):void{
			var url	: String				= (serverUrl)?serverUrl+"cgi-bin/m":"http://secure-us.imrworldwide.com/cgi-bin/m";

			var vars : URLVariables	 		= new URLVariables();
			loader							= new URLLoader();
			url +=	"?";
			for(var s:String in this)
				if(s.indexOf("c") == 0 && s.length == 2){
					url		= createQueryString(url,s,this[s]);
				}

			//CC - Cookie check. Hard coded to cc=1
			url=createQueryString(url,_paramsMap.cc,"1");

			//TL -Video title. Should be prefixed by “dav0-“. Percent (%) encode the TL value after the “dav0-“ previx.
			//Encoding prevents restricted charactrs from impacting any processing scripts
			if(tl)url=createQueryString(url,_paramsMap.tl,"dav0-"+tl);

			//CG - Show name or category name TV networks required to use program name here
			//The entire cg value should be percent (%) encoded
			if(cg)url=createQueryString(url,_paramsMap.cg,cg);

			//CI -Client ID provider by Nielsen
			if(clientId)url=createQueryString(url,_paramsMap.clientId,clientId);

			//C6 -Video Census ID
			if(videoCensusId)url=createQueryString(url,_paramsMap.videoCensusId,videoCensusId);

			//RND - Random number. Must be dynamic per event. Do not use scientific notation
			url=createQueryString(url,_paramsMap.rnd,getRndNumber());

			//LP - Long play indicator
			//Four sub parameters:
			//1. Short form/long form override. The publisher can explicitly state the this is a short form or long form clip. If set to SF then parameters 2 and 4 will be ignored.
			//2. Current segment/chapter number. Set to 0 if not known
			//3. Length in seconds of this segment/chapter. Set to 0 if not known
			//4. Anticipated total number of segments/chapters for this episode. Set to 0 if not known

			// NOTE: total length can only be determined.  unable to determine length of segments with current KDP3 libraries
			if(lp)url=createQueryString(url,_paramsMap.lp,getLongPlayIndicator());

			if(c3)url=createQueryString(url,_paramsMap.c3,c3);

			//LS -Live stream indicator. One parameter:
			//1. Set to Y if this is a live stream
			//2. Set to N if this is a standard video on demand stream
			if(ls)url=createQueryString(url,_paramsMap.ls,getLiveStreamIndicator());

			//C3  - Ad indicator. If this parameter is omitted then the stream will be assumed to be content.
			//url = createQueryString(url,_paramsMap.c3,getAdIndicator());

			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
			loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			var request : URLRequest  		= new URLRequest(url);
			request.data				= vars;

			if(requestMethod	== "post")
				request.method				= URLRequestMethod.POST;

			loader.load(request);
		}

		private function getRndNumber():String{
			return String(Math.random()).split(".")[1];
		}

		//C3  - Ad indicator. If this parameter is omitted then the stream will be assumed to be content.
		private function getAdIndicator():String{
			return "";//("st,c":"st,a");
		}

		//LS -Live stream indicator. One parameter:
		//1. Set to Y if this is a live stream
		//2. Set to N if this is a standard video on demand stream
		private function getLiveStreamIndicator():String{
			return (_facade.retrieveProxy("mediaProxy")["vo"]["isLive"])?"Y":"N";
		}

		//LP - Long play indicator
		//Four sub parameters:
		//1. LF & SF Short form/long form override. The publisher can explicitly state this is a short form or long form clip. If set to SF then parameters 2 and 4 will be ignored.
		//2. LF Current segment/chapter number. Set to 0 if not known
		//3. LF & SF Length in seconds of this segment/chapter. Set to 0 if not known
		//4. LF Anticipated total number of segments/chapters for this episode. Set to 0 if not known
		//lp=LF,3,582,6
		private function getLongPlayIndicator():String{
			var value:String	= "";
			//get clip type
				value 	+=	lp.toUpperCase()+",";

				if(lp.toUpperCase() == "LF")
					value	+=  _nielsenMediator.eventData["segmentId"]+",";

				value	+=	_nielsenMediator.eventData["length"];

				if(lp.toUpperCase() == "LF")
					value	+=	","+_nielsenMediator.eventData["totalSegments"];

			return value;
		}

		private function decodeString():void{

		}

		private function onComplete(e:Event):void{
			loader.removeEventListener(Event.COMPLETE, onComplete);
			loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
			loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
		}

		private function onSecurityError(e:SecurityErrorEvent):void{
			trace("ERROR: NIELSEN Plugin - error sending beacon : "+e);
		}

		private function onIOError(e:IOErrorEvent):void{
			trace("ERROR: NIELSEN Plugin - error sending beacon : "+e);
		}
	}
}

package
{
	import com.kaltura.kdpfl.model.SequenceProxy;
	import com.kaltura.kdpfl.model.type.NotificationType;
	import com.kaltura.kdpfl.plugin.IPlugin;
	import com.kaltura.kdpfl.plugin.IPluginFactory;
	import com.kaltura.kdpfl.plugin.component.NielsenVideoCensusMediator;
	import com.yahoo.astra.fl.controls.AbstractButtonRow;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.events.TimerEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.utils.Dictionary;
	import flash.utils.Timer;

	import org.puremvc.as3.interfaces.IFacade;

	public dynamic class nielsenVideoCensusPluginCode extends Sprite implements IPlugin
	{
		private var _nielsenMediator:NielsenVideoCensusMediator;
		private var _customEvents	:	Array;
		public function set customEvents(val:String):void{
			_customEvents		= val.split(",");
		}

		public var requestMethod	: String	= "queryString";

		//ads (st,a for ads   or  st,c for content streams)
		public var c3	:	String;

		//cookie check (cc=1)
		public var cc	:	String;

		//Show name (encoded)
		public var cg	:	String;

		public var clientId: String;
		public var videoCensusId:String;
		//video title (encoded  dav0-encoded title)
		public var tl	:	String;
		public var lp	:	String;
		public var ls	: 	String;
		public var serverUrl:String;
		public var c10	: 	String;
		public var c11	: 	String;

		private var _facade:IFacade;
		private var _eventData:Object;
		private var _paramsMap:Object =	{videoCensusId:"C6",
													clientId:"CI",
													cg:"CG",
													tl:"TL",
													lp:"LP",
													ls:"LS",
													cc:"CC",
													rnd:"RND",
													c3:"C3",
													c10:"C10",
													c11:"C11"};

		private var _sequenceProxy:SequenceProxy;
		public function nielsenVideoCensusPluginCode()
		{
			super();
		}

		public function initializePlugin(facade:IFacade):void {
			_facade				= facade;
			_nielsenMediator 	= new NielsenVideoCensusMediator(_customEvents);
			_nielsenMediator.eventDispatcher.addEventListener(NielsenVideoCensusMediator.DISPATCH_BEACON, onBeacon);
			//_nielsenMediator.eventDispatcher.addEventListener(NielsenVideoCensusMediator.AD_START, onAdStart);

			facade.registerMediator(_nielsenMediator);
			_sequenceProxy = facade.retrieveProxy(SequenceProxy.NAME) as SequenceProxy;

		}

		/**
		 * Do nothing.
		 * No implementation required for this interface method on this plugin.
		 * @param styleName
		 * @param setSkinSize
		 */
		public function setSkin(styleName:String, setSkinSize:Boolean = false):void {}

		private var loader : URLLoader;

		private function onAdStart(e:Event):void{
			onBeacon();
		}

		private function onCuePoints(e:Event):void{_eventData			= _nielsenMediator.eventData;}

		private function createQueryString(url:String, key:String, val:String):String{
			url 	= url.concat(key,"=",val,"&");
			return url;
		}

		public function onBeacon(e:Event=null):void{
			var url	: String				= (serverUrl)?serverUrl+"cgi-bin/m":"http://secure-us.imrworldwide.com/cgi-bin/m";

			var vars : URLVariables	 		= new URLVariables();
			loader							= new URLLoader();
			url +=	"?";
			for(var s:String in this)
				if(s.indexOf("c") == 0 && s.length == 2){
					url		= createQueryString(url,s,this[s]);
				}

			//CC - Cookie check. Hard coded to cc=1
			url=createQueryString(url,_paramsMap.cc,"1");

			//TL -Video title. Should be prefixed by “dav0-“. Percent (%) encode the TL value after the “dav0-“ previx.
			//Encoding prevents restricted charactrs from impacting any processing scripts
			if(tl)
				url=createQueryString(url,_paramsMap.tl,"dav0-"+tl);

			//CG - Show name or category name TV networks required to use program name here
			//The entire cg value should be percent (%) encoded
			if(cg)
				url=createQueryString(url,_paramsMap.cg,cg);

			//CI -Client ID provider by Nielsen
			if(clientId)
				url=createQueryString(url,_paramsMap.clientId,clientId);

			//C6 -Video Census ID
			if(videoCensusId)
				url=createQueryString(url,_paramsMap.videoCensusId,videoCensusId);

			//RND - Random number. Must be dynamic per event. Do not use scientific notation
			url=createQueryString(url,_paramsMap.rnd,getRndNumber());

			//LP - Long play indicator
			//Four sub parameters:
			//1. Short form/long form override. The publisher can explicitly state the this is a short form or long form clip. If set to SF then parameters 2 and 4 will be ignored.
			//2. Current segment/chapter number. Set to 0 if not known
			//3. Length in seconds of this segment/chapter. Set to 0 if not known
			//4. Anticipated total number of segments/chapters for this episode. Set to 0 if not known

			// NOTE: total length can only be determined.  unable to determine length of segments with current KDP3 libraries
			if(lp)
				url=createQueryString(url,_paramsMap.lp,getLongPlayIndicator());

			if(c3)
				url=createQueryString(url,_paramsMap.c3,c3);

			//adid is sent only for ads. eidr is sent for both content and ads
			if(_sequenceProxy.vo.isInSequence && c10)
				url=createQueryString(url,_paramsMap.c10,c10);
			if(c11)
				url=createQueryString(url,_paramsMap.c11,c11);

			//LS -Live stream indicator. One parameter:
			//1. Set to Y if this is a live stream
			//2. Set to N if this is a standard video on demand stream
			if(ls)
				url=createQueryString(url,_paramsMap.ls,getLiveStreamIndicator());

			//C3  - Ad indicator. If this parameter is omitted then the stream will be assumed to be content.
			//url = createQueryString(url,_paramsMap.c3,getAdIndicator());

			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
			loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			var request : URLRequest  		= new URLRequest(url);
			request.data				= vars;

			if(requestMethod	== "post")
				request.method				= URLRequestMethod.POST;

			loader.load(request);
		}

		private function getRndNumber():String{
			return String(Math.random()).split(".")[1];
		}

		//C3  - Ad indicator. If this parameter is omitted then the stream will be assumed to be content.
		private function getAdIndicator():String{
			return "";//("st,c":"st,a");
		}

		//LS -Live stream indicator. One parameter:
		//1. Set to Y if this is a live stream
		//2. Set to N if this is a standard video on demand stream
		private function getLiveStreamIndicator():String{
			return (_facade.retrieveProxy("mediaProxy")["vo"]["isLive"])?"Y":"N";
		}

		//LP - Long play indicator
		//Four sub parameters:
		//1. LF & SF Short form/long form override. The publisher can explicitly state this is a short form or long form clip. If set to SF then parameters 2 and 4 will be ignored.
		//2. LF Current segment/chapter number. Set to 0 if not known
		//3. LF & SF Length in seconds of this segment/chapter. Set to 0 if not known
		//4. LF Anticipated total number of segments/chapters for this episode. Set to 0 if not known
		//lp=LF,3,582,6
		private function getLongPlayIndicator():String{
			var value:String	= "";
			//get clip type
				value 	+=	lp.toUpperCase()+",";

				if(lp.toUpperCase() == "LF")
					value	+=  _nielsenMediator.eventData["segmentId"]+",";

				value	+=	_nielsenMediator.eventData["length"];

				if(lp.toUpperCase() == "LF")
					value	+=	","+_nielsenMediator.eventData["totalSegments"];

			return value;
		}

		private function decodeString():void{

		}

		private function onComplete(e:Event):void{
			loader.removeEventListener(Event.COMPLETE, onComplete);
			loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
			loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
		}

		private function onSecurityError(e:SecurityErrorEvent):void{
			trace("ERROR: NIELSEN Plugin - error sending beacon : "+e);
		}

		private function onIOError(e:IOErrorEvent):void{
			trace("ERROR: NIELSEN Plugin - error sending beacon : "+e);
		}
	}
}

add c10 and c11 params

qnd: add c10 and c11 params

git-svn-id: 3f608e5a9a704dd448217c0a64c508e7f145cfa1@92059 6b8eccd3-e8c5-4e7d-8186-e12b5326b719


package aerys.minko.render.shader.compiler.graph.nodes.vertex
{
	import aerys.minko.render.shader.compiler.CRC32;
	import aerys.minko.render.shader.compiler.InstructionFlag;
	import aerys.minko.render.shader.compiler.graph.nodes.AbstractNode;
	import aerys.minko.render.shader.compiler.register.Components;

	import flash.utils.Dictionary;

	/**
	 * @private
	 * @author Romain Gilliotte
	 */
	public class Instruction extends AbstractNode
	{
		public static const MOV : uint = 0x00;
		public static const ADD : uint = 0x01;
		public static const SUB : uint = 0x02;
		public static const MUL : uint = 0x03;
		public static const DIV : uint = 0x04;
		public static const RCP : uint = 0x05;
		public static const MIN : uint = 0x06;
		public static const MAX : uint = 0x07;
		public static const FRC : uint = 0x08;
		public static const SQT : uint = 0x09;
		public static const RSQ : uint = 0x0a;
		public static const POW : uint = 0x0b;
		public static const LOG : uint = 0x0c;
		public static const EXP : uint = 0x0d;
		public static const NRM : uint = 0x0e;
		public static const SIN : uint = 0x0f;
		public static const COS : uint = 0x10;
		public static const CRS : uint = 0x11;
		public static const DP3 : uint = 0x12;
		public static const DP4 : uint = 0x13;
		public static const ABS : uint = 0x14;
		public static const NEG : uint = 0x15;
		public static const SAT : uint = 0x16;
		public static const M33 : uint = 0x17;
		public static const M44 : uint = 0x18;
		public static const M34 : uint = 0x19;
		public static const KIL	: uint = 0x27;
		public static const TEX : uint = 0x28;
		public static const SGE : uint = 0x29;
		public static const SLT : uint = 0x2a;
		public static const SEQ : uint = 0x2c;
		public static const SNE : uint = 0x2d;

		public static const MUL_MAT33 : uint = 0x100;
		public static const MUL_MAT44 : uint = 0x101;

		public static const NAME : Dictionary = new Dictionary();
		{
			NAME[MOV] = 'mov';		NAME[ADD] = 'add';		NAME[SUB] = 'sub';
			NAME[MUL] = 'mul';		NAME[DIV] = 'div';		NAME[RCP] = 'rcp';
			NAME[MIN] = 'min';		NAME[MAX] = 'max';		NAME[FRC] = 'frc';
			NAME[SQT] = 'sqt';		NAME[RSQ] = 'rsq';		NAME[POW] = 'pow';
			NAME[LOG] = 'log';		NAME[EXP] = 'exp';		NAME[NRM] = 'nrm';
			NAME[SIN] = 'sin';		NAME[COS] = 'cos';		NAME[CRS] = 'crs';
			NAME[DP3] = 'dp3';		NAME[DP4] = 'dp4';		NAME[ABS] = 'abs';
			NAME[NEG] = 'neg';		NAME[SAT] = 'sat';		NAME[M33] = 'm33';
			NAME[M44] = 'm44';		NAME[M34] = 'm34';		NAME[TEX] = 'tex';
			NAME[KIL] = 'kil';		NAME[SGE] = 'sge';		NAME[SLT] = 'slt';
			NAME[SEQ] = 'seq';		NAME[SNE] = 'sne';

			NAME[MUL_MAT33] = 'mulMat33';
			NAME[MUL_MAT44] = 'mulMat44';
		}

		private static const FLAGS : Dictionary = new Dictionary();
		{
			FLAGS[MOV] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE | InstructionFlag.LINEAR;
			FLAGS[ADD] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE | InstructionFlag.LINEAR;
			FLAGS[SUB] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.LINEAR;
			FLAGS[MUL] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE | InstructionFlag.LINEAR;
			FLAGS[DIV] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.LINEAR;
			FLAGS[RCP] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE | InstructionFlag.LINEAR;
			FLAGS[MIN] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE;
			FLAGS[MAX] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE;
			FLAGS[FRC] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[SQT] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[RSQ] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[POW] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE;
			FLAGS[LOG] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[EXP] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[NRM] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.SINGLE;
			FLAGS[SIN] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[COS] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[CRS] = InstructionFlag.AVAILABLE_ALL;
			FLAGS[DP3] = InstructionFlag.AVAILABLE_ALL;
			FLAGS[DP4] = InstructionFlag.AVAILABLE_ALL;
			FLAGS[ABS] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[NEG] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE | InstructionFlag.LINEAR;
			FLAGS[SAT] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[M33] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.SPECIAL_MATRIX | InstructionFlag.LINEAR;
			FLAGS[M44] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.SPECIAL_MATRIX | InstructionFlag.LINEAR;
			FLAGS[M34] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.SPECIAL_MATRIX | InstructionFlag.LINEAR;
			FLAGS[KIL] = InstructionFlag.AVAILABLE_FS | InstructionFlag.SINGLE;
			FLAGS[TEX] = InstructionFlag.AVAILABLE_FS;
			FLAGS[SGE] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE;
			FLAGS[SLT] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE;
			FLAGS[SEQ] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE;
			FLAGS[SNE] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE;

			FLAGS[MUL_MAT33] = InstructionFlag.AVAILABLE_CPU | InstructionFlag.ASSOCIATIVE;
			FLAGS[MUL_MAT44] = InstructionFlag.AVAILABLE_CPU | InstructionFlag.ASSOCIATIVE;
		}

		private var _id : uint;

		public function get id()			: uint		{ return _id;		}
		public function get name()			: String	{ return NAME[_id];	}

		public function get argument1()		: AbstractNode	{ return getArgumentAt(0);	}
		public function get argument2() 	: AbstractNode 	{ return getArgumentAt(1);	}
		public function get component1()	: uint			{ return getComponentAt(0);	}
		public function get component2()	: uint			{ return getComponentAt(1);	}

		public function set argument1(v : AbstractNode) : void { setArgumentAt(0, v);	}
		public function set argument2(v : AbstractNode) : void { setArgumentAt(1, v);	}
		public function set component1(v : uint) 		: void { setComponentAt(0, v);	}
		public function set component2(v : uint) 		: void { setComponentAt(1, v);	}

		public function get isAssociative() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.ASSOCIATIVE) != 0;
		}

		public function get isComponentWise() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.COMPONENT_WISE) != 0;
		}

		public function get isSingle() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.SINGLE) != 0;
		}

		public function get isLinear() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.LINEAR) != 0;
		}

		public function isCommutative() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.COMMUTATIVE) != 0;
		}

		public function Instruction(id			: uint,
									argument1	: AbstractNode,
									argument2	: AbstractNode = null)
		{
			_id = id;

			var component1 : uint = id == MUL_MAT33 || id == MUL_MAT44 ?
				Components.createContinuous(0, 0, 4, 4) :
				Components.createContinuous(0, 0, argument1.size, argument1.size)

			var arguments	: Vector.<AbstractNode>	= new <AbstractNode>[argument1];
			var components	: Vector.<uint>			= new <uint>[component1];

			if (!isSingle)
			{
				var component2 : uint;

				if ((FLAGS[id] & InstructionFlag.SPECIAL_MATRIX) != 0)
					component2	= Components.createContinuous(0, 0, 4, 4);
				else if (id != TEX && id != MUL_MAT33 && id != MUL_MAT44)
					component2	= Components.createContinuous(0, 0, argument2.size, argument2.size);

				arguments.push(argument2);
				components.push(component2);
			}

			arguments.fixed = components.fixed = true;

			super(arguments, components);
		}

		override protected function computeHash() : uint
		{
			// commutative operations invert the arguments when computing the hash if arg1.crc > arg2.crc
			// that way, mul(a, b).hash == mul(b, a).hash

			var hashLeft  : String = argument1.hash.toString(16) + '_' + component1.toString(16);

			if ((FLAGS[_id] & InstructionFlag.SINGLE) != 0)
				return CRC32.computeForString(hashLeft);

			else
			{
				var hashRight : String = argument2.hash.toString(16) + '_' + component2.toString(16);

				if ((FLAGS[_id] & InstructionFlag.COMMUTATIVE) != 0 && argument1.hash > argument2.hash)
					return CRC32.computeForString(hashRight + hashLeft);
				else
					return CRC32.computeForString(hashLeft + hashRight);
			}
		}

		override protected function computeSize() : uint
		{
			switch (_id)
			{
				case DP3: case DP4:	return 1;
				case M33: case M34: case NRM: case CRS: return 3;
				case TEX: case M44: return 4;

				default:
					var nodeSize : uint;
					nodeSize = Components.getMaxWriteOffset(component1)
								- Components.getMinWriteOffset(component1) + 1;

					if (nodeSize > 4)
						throw new Error();

					if (!isSingle)
						nodeSize = Math.max(nodeSize,
							Components.getMaxWriteOffset(component2)
							- Components.getMinWriteOffset(component2) + 1
						);

					if (nodeSize < 1)
						throw new Error();

					if (nodeSize > 4)
						throw new Error();

					return nodeSize;
			}
		}

		override public function toString() : String
		{
			return name;
		}

		override public function clone() : AbstractNode
		{
			var clone : Instruction;
			if (isSingle)
			{
				clone = new Instruction(_id, argument1);
				clone.component1 = component1;
			}
			else
			{
				clone = new Instruction(_id, argument1, argument2);
				clone.component1 = component1;
				clone.component2 = component2;
			}

			return clone;
		}

	}
}

package aerys.minko.render.shader.compiler.graph.nodes.vertex
{
	import aerys.minko.render.shader.compiler.CRC32;
	import aerys.minko.render.shader.compiler.InstructionFlag;
	import aerys.minko.render.shader.compiler.graph.nodes.AbstractNode;
	import aerys.minko.render.shader.compiler.register.Components;

	import flash.utils.Dictionary;

	/**
	 * @private
	 * @author Romain Gilliotte
	 */
	public class Instruction extends AbstractNode
	{
		public static const MOV : uint = 0x00;
		public static const ADD : uint = 0x01;
		public static const SUB : uint = 0x02;
		public static const MUL : uint = 0x03;
		public static const DIV : uint = 0x04;
		public static const RCP : uint = 0x05;
		public static const MIN : uint = 0x06;
		public static const MAX : uint = 0x07;
		public static const FRC : uint = 0x08;
		public static const SQT : uint = 0x09;
		public static const RSQ : uint = 0x0a;
		public static const POW : uint = 0x0b;
		public static const LOG : uint = 0x0c;
		public static const EXP : uint = 0x0d;
		public static const NRM : uint = 0x0e;
		public static const SIN : uint = 0x0f;
		public static const COS : uint = 0x10;
		public static const CRS : uint = 0x11;
		public static const DP3 : uint = 0x12;
		public static const DP4 : uint = 0x13;
		public static const ABS : uint = 0x14;
		public static const NEG : uint = 0x15;
		public static const SAT : uint = 0x16;
		public static const M33 : uint = 0x17;
		public static const M44 : uint = 0x18;
		public static const M34 : uint = 0x19;
		public static const KIL	: uint = 0x27;
		public static const TEX : uint = 0x28;
		public static const SGE : uint = 0x29;
		public static const SLT : uint = 0x2a;
		public static const SEQ : uint = 0x2c;
		public static const SNE : uint = 0x2d;

		public static const MUL_MAT33 : uint = 0x100;
		public static const MUL_MAT44 : uint = 0x101;

		public static const NAME : Dictionary = new Dictionary();
		{
			NAME[MOV] = 'mov';		NAME[ADD] = 'add';		NAME[SUB] = 'sub';
			NAME[MUL] = 'mul';		NAME[DIV] = 'div';		NAME[RCP] = 'rcp';
			NAME[MIN] = 'min';		NAME[MAX] = 'max';		NAME[FRC] = 'frc';
			NAME[SQT] = 'sqt';		NAME[RSQ] = 'rsq';		NAME[POW] = 'pow';
			NAME[LOG] = 'log';		NAME[EXP] = 'exp';		NAME[NRM] = 'nrm';
			NAME[SIN] = 'sin';		NAME[COS] = 'cos';		NAME[CRS] = 'crs';
			NAME[DP3] = 'dp3';		NAME[DP4] = 'dp4';		NAME[ABS] = 'abs';
			NAME[NEG] = 'neg';		NAME[SAT] = 'sat';		NAME[M33] = 'm33';
			NAME[M44] = 'm44';		NAME[M34] = 'm34';		NAME[TEX] = 'tex';
			NAME[KIL] = 'kil';		NAME[SGE] = 'sge';		NAME[SLT] = 'slt';
			NAME[SEQ] = 'seq';		NAME[SNE] = 'sne';

			NAME[MUL_MAT33] = 'mulMat33';
			NAME[MUL_MAT44] = 'mulMat44';
		}

		private static const FLAGS : Dictionary = new Dictionary();
		{
			FLAGS[MOV] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE | InstructionFlag.LINEAR;
			FLAGS[ADD] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE | InstructionFlag.LINEAR;
			FLAGS[SUB] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.LINEAR;
			FLAGS[MUL] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE | InstructionFlag.LINEAR;
			FLAGS[DIV] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.LINEAR;
			FLAGS[RCP] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE | InstructionFlag.LINEAR;
			FLAGS[MIN] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE;
			FLAGS[MAX] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE;
			FLAGS[FRC] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[SQT] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[RSQ] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[POW] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE;
			FLAGS[LOG] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[EXP] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[NRM] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.SINGLE;
			FLAGS[SIN] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[COS] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[CRS] = InstructionFlag.AVAILABLE_ALL;
			FLAGS[DP3] = InstructionFlag.AVAILABLE_ALL;
			FLAGS[DP4] = InstructionFlag.AVAILABLE_ALL;
			FLAGS[ABS] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[NEG] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE | InstructionFlag.LINEAR;
			FLAGS[SAT] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.SINGLE;
			FLAGS[M33] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.SPECIAL_MATRIX | InstructionFlag.LINEAR;
			FLAGS[M44] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.SPECIAL_MATRIX | InstructionFlag.LINEAR;
			FLAGS[M34] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.SPECIAL_MATRIX | InstructionFlag.LINEAR;
			FLAGS[KIL] = InstructionFlag.AVAILABLE_FS | InstructionFlag.SINGLE;
			FLAGS[TEX] = InstructionFlag.AVAILABLE_FS;
			FLAGS[SGE] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE;
			FLAGS[SLT] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE;
			FLAGS[SEQ] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE;
			FLAGS[SNE] = InstructionFlag.AVAILABLE_ALL | InstructionFlag.COMPONENT_WISE | InstructionFlag.COMMUTATIVE;

			FLAGS[MUL_MAT33] = InstructionFlag.AVAILABLE_CPU | InstructionFlag.ASSOCIATIVE;
			FLAGS[MUL_MAT44] = InstructionFlag.AVAILABLE_CPU | InstructionFlag.ASSOCIATIVE;
		}

		private var _id : uint;

		public function get id()			: uint		{ return _id;		}
		public function get name()			: String	{ return NAME[_id];	}

		public function get argument1()		: AbstractNode	{ return getArgumentAt(0);	}
		public function get argument2() 	: AbstractNode 	{ return getArgumentAt(1);	}
		public function get component1()	: uint			{ return getComponentAt(0);	}
		public function get component2()	: uint			{ return getComponentAt(1);	}

		public function set argument1(v : AbstractNode) : void { setArgumentAt(0, v);	}
		public function set argument2(v : AbstractNode) : void { setArgumentAt(1, v);	}
		public function set component1(v : uint) 		: void { setComponentAt(0, v);	}
		public function set component2(v : uint) 		: void { setComponentAt(1, v);	}

		public function get isAssociative() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.ASSOCIATIVE) != 0;
		}

		public function get isComponentWise() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.COMPONENT_WISE) != 0;
		}

		public function get isSingle() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.SINGLE) != 0;
		}

		public function get isLinear() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.LINEAR) != 0;
		}

		public function isCommutative() : Boolean
		{
			return (FLAGS[_id] & InstructionFlag.COMMUTATIVE) != 0;
		}

		public function Instruction(id			: uint,
									argument1	: AbstractNode,
									argument2	: AbstractNode = null)
		{
			_id = id;

			var component1 : uint = id == MUL_MAT33 || id == MUL_MAT44 ?
				Components.createContinuous(0, 0, 4, 4) :
				Components.createContinuous(0, 0, argument1.size, argument1.size)

			var arguments	: Vector.<AbstractNode>	= new <AbstractNode>[argument1];
			var components	: Vector.<uint>			= new <uint>[component1];

			if (!isSingle)
			{
				var component2 : uint;

				if ((FLAGS[id] & InstructionFlag.SPECIAL_MATRIX) != 0)
					component2	= Components.createContinuous(0, 0, 4, 4);
				else if (id != TEX && id != MUL_MAT33 && id != MUL_MAT44)
					component2	= Components.createContinuous(0, 0, argument2.size, argument2.size);

				arguments.push(argument2);
				components.push(component2);
			}

			arguments.fixed = components.fixed = true;

			super(arguments, components);
		}

		override protected function computeHash() : uint
		{
			// commutative operations invert the arguments when computing the hash if arg1.crc > arg2.crc
			// that way, mul(a, b).hash == mul(b, a).hash

			var hashLeft  : String = id.toFixed(16) + '_' + argument1.hash.toString(16)
				+ '_' + component1.toString(16);

			if ((FLAGS[_id] & InstructionFlag.SINGLE) != 0)
				return CRC32.computeForString(hashLeft);
			else
			{
				var hashRight : String = argument2.hash.toString(16) + '_' + component2.toString(16);

				if ((FLAGS[_id] & InstructionFlag.COMMUTATIVE) != 0 && argument1.hash > argument2.hash)
					return CRC32.computeForString(hashRight + hashLeft);
				else
					return CRC32.computeForString(hashLeft + hashRight);
			}
		}

		override protected function computeSize() : uint
		{
			switch (_id)
			{
				case DP3: case DP4:	return 1;
				case M33: case M34: case NRM: case CRS: return 3;
				case TEX: case M44: return 4;

				default:
					var nodeSize : uint;
					nodeSize = Components.getMaxWriteOffset(component1)
								- Components.getMinWriteOffset(component1) + 1;

					if (nodeSize > 4)
						throw new Error();

					if (!isSingle)
						nodeSize = Math.max(nodeSize,
							Components.getMaxWriteOffset(component2)
							- Components.getMinWriteOffset(component2) + 1
						);

					if (nodeSize < 1)
						throw new Error();

					if (nodeSize > 4)
						throw new Error();

					return nodeSize;
			}
		}

		override public function toString() : String
		{
			return name;
		}

		override public function clone() : AbstractNode
		{
			var clone : Instruction;
			if (isSingle)
			{
				clone = new Instruction(_id, argument1);
				clone.component1 = component1;
			}
			else
			{
				clone = new Instruction(_id, argument1, argument2);
				clone.component1 = component1;
				clone.component2 = component2;
			}

			return clone;
		}

	}
}

fix Instruction.computeHash() to prefix the string hash with the instruction id and avoid instructions with the same arguments being mixed up


package dolly {

import dolly.core.dolly_internal;
import dolly.core.errors.CloningError;
import dolly.core.metadata.MetadataName;

import org.as3commons.reflect.Accessor;
import org.as3commons.reflect.Field;
import org.as3commons.reflect.Type;
import org.as3commons.reflect.Variable;

use namespace dolly_internal;

public class Cloner {

	private static function isTypeCloneable(type:Type):Boolean {
		return type.hasMetadata(MetadataName.CLONEABLE);
	}

	private static function isVariableCloneable(variable:Variable, skipMetadataChecking:Boolean = true):Boolean {
		return !variable.isStatic && (skipMetadataChecking || variable.hasMetadata(MetadataName.CLONEABLE));
	}

	private static function isAccessorCloneable(accessor:Accessor, skipMetadataChecking:Boolean = true):Boolean {
		return !accessor.isStatic && accessor.isReadable() && accessor.isWriteable() &&
				(skipMetadataChecking || accessor.hasMetadata(MetadataName.CLONEABLE));
	}

	dolly_internal static function getWritableFieldsOfType(type:Type):Vector.<Field> {
		const result:Vector.<Field> = new Vector.<Field>();

		var variable:Variable;
		var accessor:Accessor;

		for each(variable in type.variables) {
			if (isVariableCloneable(variable)) {
				result.push(variable);
			}
		}
		for each(accessor in type.accessors) {
			if (isAccessorCloneable(accessor)) {
				result.push(accessor);
			}
		}

		return result;
	}

	dolly_internal static function findAllCloneableFieldsForType(type:Type):Vector.<Field> {
		const result:Vector.<Field> = getWritableFieldsOfType(type);

		const superclassNames:Array = type.extendsClasses;
		for each(var superclassName:String in superclassNames) {
			var superclassType:Type = Type.forName(superclassName);
			var superclassWritableFields:Vector.<Field> = getWritableFieldsOfType(superclassType);
			if (superclassWritableFields.length > 0) {
				result.concat(superclassWritableFields);
			}
		}

		return result;
	}

	public static function clone(source:*):* {
		const type:Type = Type.forInstance(source);

		if (!isTypeCloneable(type)) {
			throw new CloningError(
					CloningError.CLASS_IS_NOT_CLONEABLE_MESSAGE,
					CloningError.CLASS_IS_NOT_CLONEABLE_CODE
			);
		}

		const clone:* = new (type.clazz)();

		// Find all public writable fields in a hierarchy of a source object
		// and assign their values to a clone object.
		const fieldsToClone:Vector.<Field> = findAllCloneableFieldsForType(type);
		var name:String;
		for each(var field:Field in fieldsToClone) {
			name = field.name;
			clone[name] = source[name];
		}

		return clone;
	}
}
}

package dolly {

import dolly.core.dolly_internal;
import dolly.core.errors.CloningError;
import dolly.core.metadata.MetadataName;

import org.as3commons.reflect.Accessor;
import org.as3commons.reflect.AccessorAccess;
import org.as3commons.reflect.Field;
import org.as3commons.reflect.Type;

use namespace dolly_internal;

public class Cloner {

	private static function isTypeCloneable(type:Type):Boolean {
		return type.hasMetadata(MetadataName.CLONEABLE);
	}

	dolly_internal static function findAllWritableFieldsForType(type:Type):Vector.<Field> {
		const result:Vector.<Field> = new Vector.<Field>();

		for each(var field:Field in type.fields) {
			if (field.isStatic) {
				continue;
			}

			if (!(field is Accessor) || (field as Accessor).access == AccessorAccess.READ_WRITE) {
				result.push(field);
			}
		}

		return result;
	}

	public static function clone(source:*):* {
		const type:Type = Type.forInstance(source);

		if (!isTypeCloneable(type)) {
			throw new CloningError(
					CloningError.CLASS_IS_NOT_CLONEABLE_MESSAGE,
					CloningError.CLASS_IS_NOT_CLONEABLE_CODE
			);
		}

		const clone:* = new (type.clazz)();

		// Find all public writable fields in a hierarchy of a source object
		// and assign their values to a clone object.
		const fieldsToClone:Vector.<Field> = findAllWritableFieldsForType(type);
		var name:String;
		for each(var field:Field in fieldsToClone) {
			name = field.name;
			clone[name] = source[name];
		}

		return clone;
	}
}
}

Optimize cloning performance.

Optimize cloning performance.


////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

package mx.core
{

import mx.resources.ResourceManager;

[ResourceBundle("core")]

/**
 *  This class controls the backward-compatibility of the framework.
 *  With every new release, some aspects of the framework such as behaviors,
 *  styles, and default settings, are changed which can affect your application.
 *  By setting the compatibilityVersion property, the behavior can be changed
 *  to match previous releases.
 *  This is a 'global' flag; you cannot apply one version to one component or group of components
 *  and a different version to another component or group of components.
 *
 *  @langversion 3.0
 *  @playerversion Flash 9
 *  @playerversion AIR 1.1
 *  @productversion Flex 3
 */
public class FlexVersion
{
    include "../core/Version.as";

    //--------------------------------------------------------------------------
    //
    //  Class constants
    //
    //--------------------------------------------------------------------------

    /**
     *  The current released version of the Flex SDK, encoded as a uint.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const CURRENT_VERSION:uint = 0x04110000;

	/**
	 *  The compatibilityVersion value of Flex 4.11,
	 *  encoded numerically as a uint.
	 *  Code can compare this constant against
	 *  the compatibilityVersion
	 *  to implement version-specific behavior.
	 *
	 *  @langversion 3.0
	 *  @playerversion Flash 11
	 *  @playerversion AIR 3
	 *  @productversion Apache Flex 4.11
	 */
	public static const VERSION_4_11:uint = 0x04110000;

	/**
	 *  The compatibilityVersion value of Flex 4.10,
	 *  encoded numerically as a uint.
	 *  Code can compare this constant against
	 *  the compatibilityVersion
	 *  to implement version-specific behavior.
	 *
	 *  @langversion 3.0
	 *  @playerversion Flash 11
	 *  @playerversion AIR 3
	 *  @productversion Apache Flex 4.10
	 */
	public static const VERSION_4_10:uint = 0x04100000;

    /**
     *  The compatibilityVersion value of Flex 4.9,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 11
     *  @playerversion AIR 3
     *  @productversion Apache Flex 4.9
     */
    public static const VERSION_4_9:uint = 0x04090000;

    /**
     *  The compatibilityVersion value of Flex 4.8,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 11
     *  @playerversion AIR 3
     *  @productversion Apache Flex 4.8
     */
    public static const VERSION_4_8:uint = 0x04080000;

    /**
     *  The compatibilityVersion value of Flex 4.6,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 11
     *  @playerversion AIR 3
     *  @productversion Flex 4.6
     */
    public static const VERSION_4_6:uint = 0x04060000;

    /**
     *  The compatibilityVersion value of Flex 4.5,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_4_5:uint = 0x04050000;

    /**
     *  The compatibilityVersion value of Flex 4.0,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_4_0:uint = 0x04000000;

    /**
     *  The compatibilityVersion value of Flex 3.0,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_3_0:uint = 0x03000000;

    /**
     *  The compatibilityVersion value of Flex 2.0.1,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_2_0_1:uint = 0x02000001;

    /**
     *  The compatibilityVersion value of Flex 2.0,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_2_0:uint = 0x02000000;

    /**
     *  A String passed as a parameter
     *  to the compatibilityErrorFunction() method
     *  if the compatibility version has already been set.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_ALREADY_SET:String = "versionAlreadySet";
        // Also used as resource string, so be careful changing it.

    /**
     *  A String passed as a parameter
     *  to the compatibilityErrorFunction() method
     *  if the compatibility version has already been read.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_ALREADY_READ:String = "versionAlreadyRead";
        // Also used as resource string, so be careful changing it.

    //--------------------------------------------------------------------------
    //
    //  Class properties
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  compatibilityErrorFunction
    //----------------------------------

    /**
     *  @private
     *  Storage for the compatibilityErrorFunction property.
     */
    private static var _compatibilityErrorFunction:Function;

    /**
     *  A function that gets called when the compatibility version
     *  is set more than once, or set after it has been read.
     *  If this function is not set, the SDK throws an error.
     *  If set, File calls this function, but it is
     *  up to the developer to decide how to handle the call.
     *  This function will also be called if the function is set more than once.
     *  The function takes two parameters: the first is a uint
     *  which is the version that was attempted to be set; the second
     *  is a string that is the reason it failed, either
     *  VERSION_ALREADY_SET or VERSION_ALREADY_READ.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static function get compatibilityErrorFunction():Function
    {
        return _compatibilityErrorFunction;
    }

    /**
     *  @private
     */
    public static function set compatibilityErrorFunction(value:Function):void
    {
        _compatibilityErrorFunction = value;
    }

    //----------------------------------
    //  compatibilityVersion
    //----------------------------------

    /**
     *  @private
     *  Storage for the compatibilityVersion property.
     */
    private static var _compatibilityVersion:uint = CURRENT_VERSION;

    /**
     *  @private
     */
    private static var compatibilityVersionChanged:Boolean = false;

    /**
     *  @private
     */
    private static var compatibilityVersionRead:Boolean = false;

    /**
     *  The current version that the framework maintains compatibility for.
     *  This defaults to CURRENT_VERSION.
     *  It can be changed only once; changing it a second time
     *  results in a call to the compatibilityErrorFunction() method
     *  if it exists, or results in a runtime error.
     *  Changing it after the compatibilityVersion property has been read results in an error
     *  because code that is dependent on the version has already run.
     *  There are no notifications; the assumption is that this is set only once, and this it is set
     *  early enough that no code that depends on it has run yet.
     *
     *  @default FlexVersion.CURRENT_VERSION
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static function get compatibilityVersion():uint
    {
        compatibilityVersionRead = true;

        return _compatibilityVersion;
    }

    /**
     *  @private
     */
    public static function set compatibilityVersion(value:uint):void
    {
        if (value == _compatibilityVersion)
            return;

        var s:String;

        if (compatibilityVersionChanged)
        {
            if (compatibilityErrorFunction == null)
            {
                s = ResourceManager.getInstance().getString(
                    "core", VERSION_ALREADY_SET);
                throw new Error(s);
            }
            else
                compatibilityErrorFunction(value, VERSION_ALREADY_SET);
        }

        if (compatibilityVersionRead)
        {
            if (compatibilityErrorFunction == null)
            {
                s = ResourceManager.getInstance().getString(
                    "core", VERSION_ALREADY_READ);
                throw new Error(s);
            }
            else
                compatibilityErrorFunction(value, VERSION_ALREADY_READ);
        }

        _compatibilityVersion = value;
        compatibilityVersionChanged = true;
    }

    //----------------------------------
    //  compatibilityVersionString
    //----------------------------------

    /**
     *  The compatibility version, as a string of the form "X.X.X".
     *  This is a pass-through to the compatibilityVersion
     *  property, which converts the number to and from a more
     *  human-readable String version.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static function get compatibilityVersionString():String
    {
        var major:uint = (compatibilityVersion >> 24) & 0xFF;
        var minor:uint = (compatibilityVersion >> 16) & 0xFF;
        var update:uint = compatibilityVersion & 0xFFFF;

        return major.toString() + "." +
               minor.toString() + "." +
               update.toString();
    }

    /**
     *  @private
     */
    public static function set compatibilityVersionString(value:String):void
    {
        var pieces:Array = value.split(".");

        var major:uint = parseInt(pieces[0]);
        var minor:uint = parseInt(pieces[1]);
        var update:uint = parseInt(pieces[2]);

        compatibilityVersion = (major << 24) + (minor << 16) + update;
    }

    /**
     *  @private
     *  A back door for changing the compatibility version.
     *  This is provided for Flash Builder's Design View,
     *  which needs to be able to change compatibility mode.
     *  In general, we won't support late changes to compatibility,
     *  because the framework won't watch for changes.
     *  Design View will need to set this early during initialization.
     */
    mx_internal static function changeCompatibilityVersionString(
                                        value:String):void
    {
        var pieces:Array = value.split(".");

        var major:uint = parseInt(pieces[0]);
        var minor:uint = parseInt(pieces[1]);
        var update:uint = parseInt(pieces[2]);

        _compatibilityVersion = (major << 24) + (minor << 16) + update;
    }
}

}

////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

package mx.core
{

import mx.resources.ResourceManager;

[ResourceBundle("core")]

/**
 *  This class controls the backward-compatibility of the framework.
 *  With every new release, some aspects of the framework such as behaviors,
 *  styles, and default settings, are changed which can affect your application.
 *  By setting the compatibilityVersion property, the behavior can be changed
 *  to match previous releases.
 *  This is a 'global' flag; you cannot apply one version to one component or group of components
 *  and a different version to another component or group of components.
 *
 *  @langversion 3.0
 *  @playerversion Flash 9
 *  @playerversion AIR 1.1
 *  @productversion Flex 3
 */
public class FlexVersion
{
    include "../core/Version.as";

    //--------------------------------------------------------------------------
    //
    //  Class constants
    //
    //--------------------------------------------------------------------------

    /**
     *  The current released version of the Flex SDK, encoded as a uint.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const CURRENT_VERSION:uint = 0x040B0000;

	/**
	 *  The compatibilityVersion value of Flex 4.11,
	 *  encoded numerically as a uint.
	 *  Code can compare this constant against
	 *  the compatibilityVersion
	 *  to implement version-specific behavior.
	 *
	 *  @langversion 3.0
	 *  @playerversion Flash 11
	 *  @playerversion AIR 3
	 *  @productversion Apache Flex 4.11
	 */
	public static const VERSION_4_11:uint = 0x040B0000;

	/**
	 *  The compatibilityVersion value of Flex 4.10,
	 *  encoded numerically as a uint.
	 *  Code can compare this constant against
	 *  the compatibilityVersion
	 *  to implement version-specific behavior.
	 *
	 *  @langversion 3.0
	 *  @playerversion Flash 11
	 *  @playerversion AIR 3
	 *  @productversion Apache Flex 4.10
	 */
	public static const VERSION_4_10:uint = 0x040A0000;

    /**
     *  The compatibilityVersion value of Flex 4.9,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 11
     *  @playerversion AIR 3
     *  @productversion Apache Flex 4.9
     */
    public static const VERSION_4_9:uint = 0x04090000;

    /**
     *  The compatibilityVersion value of Flex 4.8,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 11
     *  @playerversion AIR 3
     *  @productversion Apache Flex 4.8
     */
    public static const VERSION_4_8:uint = 0x04080000;

    /**
     *  The compatibilityVersion value of Flex 4.6,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 11
     *  @playerversion AIR 3
     *  @productversion Flex 4.6
     */
    public static const VERSION_4_6:uint = 0x04060000;

    /**
     *  The compatibilityVersion value of Flex 4.5,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_4_5:uint = 0x04050000;

    /**
     *  The compatibilityVersion value of Flex 4.0,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_4_0:uint = 0x04000000;

    /**
     *  The compatibilityVersion value of Flex 3.0,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_3_0:uint = 0x03000000;

    /**
     *  The compatibilityVersion value of Flex 2.0.1,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_2_0_1:uint = 0x02000001;

    /**
     *  The compatibilityVersion value of Flex 2.0,
     *  encoded numerically as a uint.
     *  Code can compare this constant against
     *  the compatibilityVersion
     *  to implement version-specific behavior.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_2_0:uint = 0x02000000;

    /**
     *  A String passed as a parameter
     *  to the compatibilityErrorFunction() method
     *  if the compatibility version has already been set.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_ALREADY_SET:String = "versionAlreadySet";
        // Also used as resource string, so be careful changing it.

    /**
     *  A String passed as a parameter
     *  to the compatibilityErrorFunction() method
     *  if the compatibility version has already been read.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static const VERSION_ALREADY_READ:String = "versionAlreadyRead";
        // Also used as resource string, so be careful changing it.

    //--------------------------------------------------------------------------
    //
    //  Class properties
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  compatibilityErrorFunction
    //----------------------------------

    /**
     *  @private
     *  Storage for the compatibilityErrorFunction property.
     */
    private static var _compatibilityErrorFunction:Function;

    /**
     *  A function that gets called when the compatibility version
     *  is set more than once, or set after it has been read.
     *  If this function is not set, the SDK throws an error.
     *  If set, File calls this function, but it is
     *  up to the developer to decide how to handle the call.
     *  This function will also be called if the function is set more than once.
     *  The function takes two parameters: the first is a uint
     *  which is the version that was attempted to be set; the second
     *  is a string that is the reason it failed, either
     *  VERSION_ALREADY_SET or VERSION_ALREADY_READ.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static function get compatibilityErrorFunction():Function
    {
        return _compatibilityErrorFunction;
    }

    /**
     *  @private
     */
    public static function set compatibilityErrorFunction(value:Function):void
    {
        _compatibilityErrorFunction = value;
    }

    //----------------------------------
    //  compatibilityVersion
    //----------------------------------

    /**
     *  @private
     *  Storage for the compatibilityVersion property.
     */
    private static var _compatibilityVersion:uint = CURRENT_VERSION;

    /**
     *  @private
     */
    private static var compatibilityVersionChanged:Boolean = false;

    /**
     *  @private
     */
    private static var compatibilityVersionRead:Boolean = false;

    /**
     *  The current version that the framework maintains compatibility for.
     *  This defaults to CURRENT_VERSION.
     *  It can be changed only once; changing it a second time
     *  results in a call to the compatibilityErrorFunction() method
     *  if it exists, or results in a runtime error.
     *  Changing it after the compatibilityVersion property has been read results in an error
     *  because code that is dependent on the version has already run.
     *  There are no notifications; the assumption is that this is set only once, and this it is set
     *  early enough that no code that depends on it has run yet.
     *
     *  @default FlexVersion.CURRENT_VERSION
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static function get compatibilityVersion():uint
    {
        compatibilityVersionRead = true;

        return _compatibilityVersion;
    }

    /**
     *  @private
     */
    public static function set compatibilityVersion(value:uint):void
    {
        if (value == _compatibilityVersion)
            return;

        var s:String;

        if (compatibilityVersionChanged)
        {
            if (compatibilityErrorFunction == null)
            {
                s = ResourceManager.getInstance().getString(
                    "core", VERSION_ALREADY_SET);
                throw new Error(s);
            }
            else
                compatibilityErrorFunction(value, VERSION_ALREADY_SET);
        }

        if (compatibilityVersionRead)
        {
            if (compatibilityErrorFunction == null)
            {
                s = ResourceManager.getInstance().getString(
                    "core", VERSION_ALREADY_READ);
                throw new Error(s);
            }
            else
                compatibilityErrorFunction(value, VERSION_ALREADY_READ);
        }

        _compatibilityVersion = value;
        compatibilityVersionChanged = true;
    }

    //----------------------------------
    //  compatibilityVersionString
    //----------------------------------

    /**
     *  The compatibility version, as a string of the form "X.X.X".
     *  This is a pass-through to the compatibilityVersion
     *  property, which converts the number to and from a more
     *  human-readable String version.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public static function get compatibilityVersionString():String
    {
        var major:uint = (compatibilityVersion >> 24) & 0xFF;
        var minor:uint = (compatibilityVersion >> 16) & 0xFF;
        var update:uint = compatibilityVersion & 0xFFFF;

        return major.toString() + "." +
               minor.toString() + "." +
               update.toString();
    }

    /**
     *  @private
     */
    public static function set compatibilityVersionString(value:String):void
    {
        var pieces:Array = value.split(".");

        var major:uint = parseInt(pieces[0]);
        var minor:uint = parseInt(pieces[1]);
        var update:uint = parseInt(pieces[2]);

        compatibilityVersion = (major << 24) + (minor << 16) + update;
    }

    /**
     *  @private
     *  A back door for changing the compatibility version.
     *  This is provided for Flash Builder's Design View,
     *  which needs to be able to change compatibility mode.
     *  In general, we won't support late changes to compatibility,
     *  because the framework won't watch for changes.
     *  Design View will need to set this early during initialization.
     */
    mx_internal static function changeCompatibilityVersionString(
                                        value:String):void
    {
        var pieces:Array = value.split(".");

        var major:uint = parseInt(pieces[0]);
        var minor:uint = parseInt(pieces[1]);
        var update:uint = parseInt(pieces[2]);

        _compatibilityVersion = (major << 24) + (minor << 16) + update;
    }
}

}

Fix internal version numbers

Fix internal version numbers


package battlecode.client.viewer.render {
import battlecode.common.RobotType;

import mx.controls.Image;
    import mx.core.UIComponent;

    public class ExplosionAnimation extends UIComponent implements DrawObject {
        private var image:Image;
        private var robotType:String;
        private var round:int = 0;
        private var exploding:Boolean = false;

        public function ExplosionAnimation(robotType:String) {
            this.image = new Image();
            this.robotType = robotType;
            this.addChild(image);
        }

        public function explode():void {
            exploding = true;
        }

        public function draw(force:Boolean = false):void {
            if (!RenderConfiguration.showExplosions() || !exploding) {
                this.image.source = null;
                return;
            }

            // TODO big missile explosion animations?
            var w:Number = RenderConfiguration.getGridSize(); // * (robotType == RobotType.MISSILE ? 3 : 1);

            var imageSource:Class = getExplosionImage();
            this.image.source = new imageSource();
            this.image.width = w;
            this.image.height = w;
            this.image.x = -w / 2;
            this.image.y = -w / 2;
        }

        public function clone():DrawObject {
            var anim:ExplosionAnimation = new ExplosionAnimation(robotType);
            anim.round = round;
            anim.exploding = exploding;
            return anim;
        }

        public function getRound():uint {
            return round;
        }

        public function isExploding():Boolean {
            return exploding;
        }

        public function isAlive():Boolean {
            return round < 8 && exploding;
        }

        public function updateRound():void {
            if (exploding) round++;
        }

        private function getExplosionImage():Class {
            switch (round) {
                case 0:
                    return ImageAssets.EXPLODE_1;
                case 1:
                    return ImageAssets.EXPLODE_2;
                case 2:
                    return ImageAssets.EXPLODE_3;
                case 3:
                    return ImageAssets.EXPLODE_4;
                case 4:
                    return ImageAssets.EXPLODE_5;
                case 5:
                    return ImageAssets.EXPLODE_6;
                case 6:
                    return ImageAssets.EXPLODE_7;
                case 7:
                    return ImageAssets.EXPLODE_8;
                default:
                    return ImageAssets.EXPLODE_8;
            }
        }

    }

}

package battlecode.client.viewer.render {
import battlecode.common.RobotType;

import mx.controls.Image;
    import mx.core.UIComponent;

    public class ExplosionAnimation extends UIComponent implements DrawObject {
        private var image:Image;
        private var robotType:String;
        private var round:int = 0;
        private var exploding:Boolean = false;

        public function ExplosionAnimation(robotType:String) {
            this.image = new Image();
            this.robotType = robotType;
            this.addChild(image);
        }

        public function explode():void {
            exploding = true;
        }

        public function draw(force:Boolean = false):void {
            if (!RenderConfiguration.showExplosions() || !exploding) {
                this.image.source = null;
                return;
            }

            // TODO big missile explosion animations?
            var w:Number = RenderConfiguration.getGridSize(); // * (robotType == RobotType.MISSILE ? 3 : 1);

            var imageSource:Class = getExplosionImage();
            this.image.source = new imageSource();
            this.image.width = w;
            this.image.height = w;
            this.image.x = -w / 2;
            this.image.y = -w / 2;
        }

        public function clone():DrawObject {
            var anim:ExplosionAnimation = new ExplosionAnimation(robotType);
            anim.round = round;
            anim.exploding = exploding;
            return anim;
        }

        public function getRound():uint {
            return round;
        }

        public function isExploding():Boolean {
            return exploding;
        }

        public function isAlive():Boolean {
            return round < 8 && exploding;
        }

        public function updateRound():void {
            if (exploding) round++;
        }

        private function getExplosionImage():Class {
            if (round < 8) {
                return ImageAssets["EXPLODE_" + (round + 1)];
            } else {
                return ImageAssets.EXPLODE_8;
            }
        }

    }

}

simplify explision animations

simplify explision animations


package battlecode.client.viewer.render {

    import battlecode.client.viewer.MatchController;
    import battlecode.common.RobotType;
    import battlecode.common.Team;
    import battlecode.events.MatchEvent;
    import battlecode.serial.Match;

    import flash.filters.DropShadowFilter;

    import mx.containers.Canvas;
    import mx.containers.VBox;
    import mx.controls.Label;
import mx.controls.Spacer;
import mx.events.ResizeEvent;
    import mx.formatters.NumberFormatter;

    public class DrawHUD extends VBox {
        private var controller:MatchController;
        private var team:String;

        private var pointLabel:Label;
        private var hqBox:DrawHUDHQ;
        private var towerBoxes:Object; // id -> DrawHUDTower
        private var buildingLabel:Label;
        private var buildingBoxes:Array;
        private var unitLabel:Label;
        private var unitBoxes:Array;
        private var winMarkerCanvas:Canvas;

        private var lastRound:uint = 0;
        private var maxTowers:uint = 0;

        private var formatter:NumberFormatter;

        public function DrawHUD(controller:MatchController, team:String) {
            this.controller = controller;
            this.team = team;

            controller.addEventListener(MatchEvent.ROUND_CHANGE, onRoundChange);
            controller.addEventListener(MatchEvent.MATCH_CHANGE, onMatchChange);
            addEventListener(ResizeEvent.RESIZE, onResize);

            width = 180;
            percentHeight = 100;
            autoLayout = false;

            horizontalScrollPolicy = "off";
            verticalScrollPolicy = "off";

            pointLabel = new Label();
            pointLabel.width = width;
            pointLabel.height = 30;
            pointLabel.x = 0;
            pointLabel.y = 10;
            pointLabel.filters = [ new DropShadowFilter(3, 45, 0x333333, 1, 2, 2) ];
            pointLabel.setStyle("color", team == Team.A ? 0xFF6666 : 0x9999FF);
            pointLabel.setStyle("fontSize", 24);
            pointLabel.setStyle("fontWeight", "bold");
            pointLabel.setStyle("textAlign", "center");
            pointLabel.setStyle("fontFamily", "Courier New");

            winMarkerCanvas = new Canvas();
            winMarkerCanvas.width = width;
            winMarkerCanvas.height = 40;

            addChild(pointLabel);

            hqBox = new DrawHUDHQ();
            addChild(hqBox);

            buildingLabel = new Label();
            buildingLabel.width = width;
            buildingLabel.height = 30;
            buildingLabel.setStyle("color", 0xFFFFFF);
            buildingLabel.setStyle("fontSize", 18);
            buildingLabel.setStyle("textAlign", "center");
            buildingLabel.setStyle("fontFamily", "Courier New");
            buildingLabel.text = "Buildings";
            addChild(buildingLabel);

            unitLabel = new Label();
            unitLabel.width = width;
            unitLabel.height = 30;
            unitLabel.setStyle("color", 0xFFFFFF);
            unitLabel.setStyle("fontSize", 18);
            unitLabel.setStyle("textAlign", "center");
            unitLabel.setStyle("fontFamily", "Courier New");
            unitLabel.text = "Units";
            addChild(unitLabel);

            towerBoxes = {};

            buildingBoxes = new Array();
            for each (var building:String in RobotType.buildings()) {
                var buildingBox:DrawHUDUnit = new DrawHUDUnit(building, team);
                buildingBoxes.push(buildingBox);
                addChild(buildingBox);
            }

            unitBoxes = new Array();
            for each (var unit:String in RobotType.units()) {
                var unitBox:DrawHUDUnit = new DrawHUDUnit(unit, team);
                unitBoxes.push(unitBox);
                addChild(unitBox);
            }

            formatter = new NumberFormatter();
            formatter.rounding = "down";
            formatter.precision = 0;

            addChild(winMarkerCanvas);

            repositionWinMarkers();
            resizeHQBox();
            drawTowerBoxes();
            drawBuildingCounts();
            drawUnitCounts();
        }

        private function onRoundChange(e:MatchEvent):void {
            var points:Number = controller.currentState.getPoints(team);
            pointLabel.text = formatter.format(points);

            if (e.currentRound <= lastRound) {
                hqBox.removeRobot();
                drawWinMarkers();
            }
            lastRound = e.currentRound;

            var hq:DrawRobot = controller.currentState.getHQ(team);
            if (hq && hq.isAlive()) {
                hqBox.setRobot(hq);
                hq.draw();
            }

            var towers:Object = controller.currentState.getTowers(team);
            var towerCount:uint = 0;
            for each (var tower:DrawRobot in towers) {
                if (!towerBoxes[tower.getRobotID()]) {
                    towerBoxes[tower.getRobotID()] = new DrawHUDTower();
                    addChild(towerBoxes[tower.getRobotID()]);
                }
                towerBoxes[tower.getRobotID()].setRobot(tower);
                tower.draw();
                towerCount++;
            }
            maxTowers = Math.max(maxTowers, towerCount);
            drawTowerBoxes();

            for each (var buildingBox:DrawHUDUnit in buildingBoxes) {
                buildingBox.setCount(controller.currentState.getUnitCount(buildingBox.getType(), team));
            }
            drawBuildingCounts();

            for each (var unitBox:DrawHUDUnit in unitBoxes) {
                unitBox.setCount(controller.currentState.getUnitCount(unitBox.getType(), team));
            }
            drawUnitCounts();

            if (controller.currentRound == controller.match.getRounds()) {
                drawWinMarkers();
            }
        }

        private function onMatchChange(e:MatchEvent):void {
            pointLabel.text = "0";
            hqBox.removeRobot();

            // clear tower boxes
            for (var a:String in towerBoxes) {
                towerBoxes[a].removeRobot();
                if (towerBoxes[a].parent == this) {
                    removeChild(towerBoxes[a]);
                }
            }
            towerBoxes = {};
            maxTowers = 0;

            drawWinMarkers();
        }

        private function resizeHQBox():void {
            var boxSize:Number = Math.min(100, (height - 70 - pointLabel.height - winMarkerCanvas.height) - 20);
            hqBox.resize(boxSize);
            hqBox.x = (width - boxSize) / 2;
            hqBox.y = 50;
        }

        private function drawTowerBoxes():void {
            var top:Number = hqBox.height + hqBox.y + 10;
            var i:uint = 0;
            for (var a:String in towerBoxes) {
                var towerBox:DrawHUDTower = towerBoxes[a];
                towerBox.x = (width - towerBox.width * 3) / 2 + (i % 3) * towerBox.width;
                towerBox.y = ((towerBox.height + 10) * Math.floor(i / 3)) + top;
                i++;
            }
        }

        private function drawBuildingCounts():void {
            var towerBoxTop:Number = Math.ceil(maxTowers / 3.0) * (DrawHUDTower.HEIGHT + 10);
            var top:Number = hqBox.height + hqBox.y + towerBoxTop + 10;
            buildingLabel.y = top + 10;
            top = buildingLabel.height + buildingLabel.y + 5;
            var i:uint = 0;
            for each (var buildingBox:DrawHUDUnit in buildingBoxes) {
                buildingBox.x = (width - buildingBox.width * 3) / 2 + (i % 3) * buildingBox.width;
                buildingBox.y = ((buildingBox.height + 10) * Math.floor(i / 3)) + top;
                if (buildingBox.getCount() > 0) {
                    buildingBox.visible = true;
                    i++;
                } else {
                    buildingBox.visible = false;
                }
            }
        }

        private function drawUnitCounts():void {
            var topBuildingBox:DrawHUDUnit = buildingBoxes[buildingBoxes.length-1];
            for (var j:int = buildingBoxes.length - 1; j >= 0; j--) {
                topBuildingBox = buildingBoxes[j];
                if (topBuildingBox.visible) {
                    break;
                }
            }

            var top:Number = topBuildingBox.height + topBuildingBox.y + 10;
            unitLabel.y = top + 10;
            top = unitLabel.height + unitLabel.y + 5;
            var i:uint = 0;
            for each (var unitBox:DrawHUDUnit in unitBoxes) {
                unitBox.x = (width - unitBox.width * 3) / 2 + (i % 3) * unitBox.width;
                unitBox.y = ((unitBox.height + 10) * Math.floor(i / 3)) + top;
                if (unitBox.getCount() > 0) {
                    unitBox.visible = true;
                    i++;
                } else {
                    unitBox.visible = false;
                }
            }
        }

        private function drawWinMarkers():void {
            var matches:Vector.<Match> = controller.getMatches();
            winMarkerCanvas.graphics.clear();
            var i:uint, wins:uint = 0;
            var numMatches:int =
                    (controller.currentRound == controller.match.getRounds()) ?
                            controller.currentMatch :
                            controller.currentMatch - 1;
            for (i = 0; i <= numMatches; i++) {
                if (matches[i].getWinner() == team) {
                    var x:Number = (winMarkerCanvas.height - 5) / 2 + wins * winMarkerCanvas.height + 30;
                    var y:Number = (winMarkerCanvas.height - 5) / 2;
                    var r:Number = (winMarkerCanvas.height - 5) / 2;
                    winMarkerCanvas.graphics.lineStyle(2, 0x000000);
                    winMarkerCanvas.graphics.beginFill((team == Team.A) ? 0xFF6666 : 0x9999FF);
                    winMarkerCanvas.graphics.drawCircle(x, y, r);
                    winMarkerCanvas.graphics.endFill();
                    wins++;
                }
            }
        }

        private function repositionWinMarkers():void {
            winMarkerCanvas.y = height - winMarkerCanvas.height - 20;
        }

        private function onResize(e:ResizeEvent):void {
            repositionWinMarkers();
            resizeHQBox();
            drawTowerBoxes();
            drawBuildingCounts();
            drawUnitCounts();
        }

    }

}

package battlecode.client.viewer.render {

    import battlecode.client.viewer.MatchController;
    import battlecode.common.RobotType;
    import battlecode.common.Team;
    import battlecode.events.MatchEvent;
    import battlecode.serial.Match;

    import flash.filters.DropShadowFilter;

    import mx.containers.Canvas;
    import mx.containers.VBox;
    import mx.controls.Label;
import mx.controls.Spacer;
import mx.events.ResizeEvent;
    import mx.formatters.NumberFormatter;

    public class DrawHUD extends VBox {
        private var controller:MatchController;
        private var team:String;

        private var pointLabel:Label;
        private var hqBox:DrawHUDHQ;
        private var towerBoxes:Object; // id -> DrawHUDTower
        private var buildingLabel:Label;
        private var buildingBoxes:Array;
        private var unitLabel:Label;
        private var unitBoxes:Array;
        private var winMarkerCanvas:Canvas;

        private var lastRound:uint = 0;
        private var maxTowers:uint = 0;

        private var formatter:NumberFormatter;

        public function DrawHUD(controller:MatchController, team:String) {
            this.controller = controller;
            this.team = team;

            controller.addEventListener(MatchEvent.ROUND_CHANGE, onRoundChange);
            controller.addEventListener(MatchEvent.MATCH_CHANGE, onMatchChange);
            addEventListener(ResizeEvent.RESIZE, onResize);

            width = 180;
            percentHeight = 100;
            autoLayout = false;

            horizontalScrollPolicy = "off";
            verticalScrollPolicy = "off";

            pointLabel = new Label();
            pointLabel.width = width;
            pointLabel.height = 30;
            pointLabel.x = 0;
            pointLabel.y = 10;
            pointLabel.filters = [ new DropShadowFilter(3, 45, 0x333333, 1, 2, 2) ];
            pointLabel.setStyle("color", team == Team.A ? 0xFF6666 : 0x9999FF);
            pointLabel.setStyle("fontSize", 24);
            pointLabel.setStyle("fontWeight", "bold");
            pointLabel.setStyle("textAlign", "center");
            pointLabel.setStyle("fontFamily", "Courier New");

            winMarkerCanvas = new Canvas();
            winMarkerCanvas.width = width;
            winMarkerCanvas.height = 40;

            addChild(pointLabel);

            hqBox = new DrawHUDHQ();
            addChild(hqBox);

            buildingLabel = new Label();
            buildingLabel.width = width;
            buildingLabel.height = 30;
            buildingLabel.setStyle("color", 0xFFFFFF);
            buildingLabel.setStyle("fontSize", 18);
            buildingLabel.setStyle("textAlign", "center");
            buildingLabel.setStyle("fontFamily", "Courier New");
            buildingLabel.text = "Buildings";
            addChild(buildingLabel);

            unitLabel = new Label();
            unitLabel.width = width;
            unitLabel.height = 30;
            unitLabel.setStyle("color", 0xFFFFFF);
            unitLabel.setStyle("fontSize", 18);
            unitLabel.setStyle("textAlign", "center");
            unitLabel.setStyle("fontFamily", "Courier New");
            unitLabel.text = "Units";
            addChild(unitLabel);

            towerBoxes = {};

            buildingBoxes = new Array();
            for each (var building:String in RobotType.buildings()) {
                var buildingBox:DrawHUDUnit = new DrawHUDUnit(building, team);
                buildingBoxes.push(buildingBox);
                addChild(buildingBox);
            }

            unitBoxes = new Array();
            for each (var unit:String in RobotType.units()) {
                var unitBox:DrawHUDUnit = new DrawHUDUnit(unit, team);
                unitBoxes.push(unitBox);
                addChild(unitBox);
            }

            formatter = new NumberFormatter();
            formatter.rounding = "down";
            formatter.precision = 0;

            addChild(winMarkerCanvas);

            repositionWinMarkers();
            resizeHQBox();
            drawTowerBoxes();
            drawUnitCounts();
            drawBuildingCounts();
        }

        private function onRoundChange(e:MatchEvent):void {
            var points:Number = controller.currentState.getPoints(team);
            pointLabel.text = formatter.format(points);

            if (e.currentRound <= lastRound) {
                hqBox.removeRobot();
                drawWinMarkers();
            }
            lastRound = e.currentRound;

            var hq:DrawRobot = controller.currentState.getHQ(team);
            if (hq && hq.isAlive()) {
                hqBox.setRobot(hq);
                hq.draw();
            }

            var towers:Object = controller.currentState.getTowers(team);
            var towerCount:uint = 0;
            for each (var tower:DrawRobot in towers) {
                if (!towerBoxes[tower.getRobotID()]) {
                    towerBoxes[tower.getRobotID()] = new DrawHUDTower();
                    addChild(towerBoxes[tower.getRobotID()]);
                }
                towerBoxes[tower.getRobotID()].setRobot(tower);
                tower.draw();
                towerCount++;
            }
            maxTowers = Math.max(maxTowers, towerCount);
            drawTowerBoxes();

            for each (var unitBox:DrawHUDUnit in unitBoxes) {
                unitBox.setCount(controller.currentState.getUnitCount(unitBox.getType(), team));
            }

            for each (var buildingBox:DrawHUDUnit in buildingBoxes) {
                buildingBox.setCount(controller.currentState.getUnitCount(buildingBox.getType(), team));
            }

            drawUnitCounts();
            drawBuildingCounts();

            if (controller.currentRound == controller.match.getRounds()) {
                drawWinMarkers();
            }
        }

        private function onMatchChange(e:MatchEvent):void {
            pointLabel.text = "0";
            hqBox.removeRobot();

            // clear tower boxes
            for (var a:String in towerBoxes) {
                towerBoxes[a].removeRobot();
                if (towerBoxes[a].parent == this) {
                    removeChild(towerBoxes[a]);
                }
            }
            towerBoxes = {};
            maxTowers = 0;

            drawWinMarkers();
        }

        private function resizeHQBox():void {
            var boxSize:Number = Math.min(100, (height - 70 - pointLabel.height - winMarkerCanvas.height) - 20);
            hqBox.resize(boxSize);
            hqBox.x = (width - boxSize) / 2;
            hqBox.y = 50;
        }

        private function drawTowerBoxes():void {
            var top:Number = hqBox.height + hqBox.y + 10;
            var i:uint = 0;
            for (var a:String in towerBoxes) {
                var towerBox:DrawHUDTower = towerBoxes[a];
                towerBox.x = (width - towerBox.width * 3) / 2 + (i % 3) * towerBox.width;
                towerBox.y = ((towerBox.height + 10) * Math.floor(i / 3)) + top;
                i++;
            }
        }

        private function drawUnitCounts():void {
            var towerBoxTop:Number = Math.ceil(maxTowers / 3.0) * (DrawHUDTower.HEIGHT + 10);
            var top:Number = hqBox.height + hqBox.y + towerBoxTop + 10;
            unitLabel.y = top + 10;
            top = unitLabel.height + unitLabel.y + 5;
            var i:uint = 0;
            for each (var unitBox:DrawHUDUnit in unitBoxes) {
                unitBox.x = (width - unitBox.width * 3) / 2 + (i % 3) * unitBox.width;
                unitBox.y = ((unitBox.height + 10) * Math.floor(i / 3)) + top;
                if (unitBox.getCount() > 0) {
                    unitBox.visible = true;
                    i++;
                } else {
                    unitBox.visible = false;
                }
            }
        }

        private function drawBuildingCounts():void {
            var topUnitBox:DrawHUDUnit = unitBoxes[unitBoxes.length-1];
            for (var j:int = unitBoxes.length - 1; j >= 0; j--) {
                topUnitBox = unitBoxes[j];
                if (topUnitBox.visible) {
                    break;
                }
            }

            var top:Number = topUnitBox.height + topUnitBox.y + 10;
            buildingLabel.y = top + 10;
            top = buildingLabel.height + buildingLabel.y + 5;
            var i:uint = 0;
            for each (var buildingBox:DrawHUDUnit in buildingBoxes) {
                buildingBox.x = (width - buildingBox.width * 3) / 2 + (i % 3) * buildingBox.width;
                buildingBox.y = ((buildingBox.height + 10) * Math.floor(i / 3)) + top;
                if (buildingBox.getCount() > 0) {
                    buildingBox.visible = true;
                    i++;
                } else {
                    buildingBox.visible = false;
                }
            }
        }

        private function drawWinMarkers():void {
            var matches:Vector.<Match> = controller.getMatches();
            winMarkerCanvas.graphics.clear();
            var i:uint, wins:uint = 0;
            var numMatches:int =
                    (controller.currentRound == controller.match.getRounds()) ?
                            controller.currentMatch :
                            controller.currentMatch - 1;
            for (i = 0; i <= numMatches; i++) {
                if (matches[i].getWinner() == team) {
                    var x:Number = (winMarkerCanvas.height - 5) / 2 + wins * winMarkerCanvas.height + 30;
                    var y:Number = (winMarkerCanvas.height - 5) / 2;
                    var r:Number = (winMarkerCanvas.height - 5) / 2;
                    winMarkerCanvas.graphics.lineStyle(2, 0x000000);
                    winMarkerCanvas.graphics.beginFill((team == Team.A) ? 0xFF6666 : 0x9999FF);
                    winMarkerCanvas.graphics.drawCircle(x, y, r);
                    winMarkerCanvas.graphics.endFill();
                    wins++;
                }
            }
        }

        private function repositionWinMarkers():void {
            winMarkerCanvas.y = height - winMarkerCanvas.height - 20;
        }

        private function onResize(e:ResizeEvent):void {
            repositionWinMarkers();
            resizeHQBox();
            drawTowerBoxes();
            drawUnitCounts();
            drawBuildingCounts();
        }

    }

}

put unit count above building count

put unit count above building count