1 /*
  2   Copyright (c) 2008 Seneca College
  3   Licenced under the MIT License (http://www.c3dl.org/index.php/mit-license/)
  4 */
  5 
  6 /**
  7 	@private
  8 	@class ColladaQueue is a queueing system to load collada files.  There
  9 	seems to be issues when two or more files are attempted to be loaded
 10 	in script.  Albeit, if the second model is loaded once the first has
 11 	been completely loaded, then they are both loaded properly.  Therefore
 12 	this class was created for taking care of such serial loading.
 13 */
 14 c3dl.ColladaQueue = 
 15 {
 16 
 17 	queue : [],
 18 	firstTime : true,
 19 
 20 	/**
 21 		@private
 22 		Are there any more files to load?
 23 
 24 		@returns {boolean} true if there are no more files to load, false otherwise.
 25 	*/
 26 	isEmpty : function()
 27 	{
 28 		return (c3dl.ColladaQueue.queue.length == 0 ? true: false);
 29 	},
 30 
 31 	/**
 32 		@private
 33 		Add a file to load at the end of the list
 34 
 35 		@param {Collada} colladaInstance
 36 	*/
 37 	pushBack : function(colladaInstance)
 38 	{
 39 		c3dl.ColladaQueue.queue.push(colladaInstance);
 40 
 41 		// every time scene sees that a file is loaded, it
 42 		// will popFront(), which in turn will load the next
 43 		// file, but for the first file loaded,  we have to
 44 		// do it manually.
 45 		if(c3dl.ColladaQueue.firstTime)
 46 		{
 47 			c3dl.ColladaQueue.firstTime = false;
 48 			c3dl.ColladaManager.loadFile(c3dl.ColladaQueue.queue[0].path);
 49 		}
 50 	},
 51 
 52 	/**
 53 		@private	
 54 		Remove the first element from the queue. Do this if the first
 55 		element has finished loading.
 56 	*/
 57 	popFront : function()
 58 	{
 59 		c3dl.ColladaQueue.queue.shift();
 60 
 61 		// if there are more files to load, load them.
 62 		if(c3dl.ColladaQueue.isEmpty() == false)
 63 		{
 64 			c3dl.ColladaManager.loadFile(c3dl.ColladaQueue.queue[0].path);
 65 		}
 66 
 67 		// if all the models were done, but the user didn't give us	
 68 		// their main functions, we don't want the gif spinning there
 69 		// forever, so turn it off.	
 70 		else if( c3dl.ColladaQueue.isEmpty() == true && c3dl.mainCallBacks.length == 0)
 71 		{
 72 			c3dl.removeProgressBars();
 73 		}
 74 
 75 		// otherwise we loaded all the models, we can start rendering.
 76 		else if(c3dl.ColladaQueue.isEmpty() == true && c3dl.mainCallBacks.length != 0)
 77 		{
 78 			c3dl.removeProgressBars();
 79 		
 80 			for (var i=0; i < c3dl.mainCallBacks.length; i++)
 81 			{
 82 				var func = c3dl.mainCallBacks[i].f;
 83 				var tag = c3dl.mainCallBacks[i].t;
 84 				func(tag);
 85 			}
 86 		}
 87 	},
 88 
 89 	/**
 90 		@private	
 91 		Get the first element from the queue.
 92 
 93 		@returns {Collada}
 94 	*/
 95 	getFront : function()
 96 	{
 97 		return c3dl.ColladaQueue.queue[0];
 98 	}
 99 };
100