[Sandy] [sandy commit] r973 - Integrate changeset 968 from AS3 trunk into 3.1 haxe branch. This patch will be merged int...

codesite-noreply at google.com codesite-noreply at google.com
Sat Mar 14 02:20:40 PST 2009


Author: cyanescent
Date: Sat Mar 14 03:18:46 2009
New Revision: 973

Modified:
    trunk/sandy/haxe/branches/3.1/src/sandy/core/Renderer.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/core/Scene3D.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/core/data/Polygon.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/core/light/Light3D.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Camera3D.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Node.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Shape3D.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/events/SandyEvent.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/materials/Appearance.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/materials/BitmapMaterial.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/materials/Material.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/materials/MovieMaterial.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/materials/VideoMaterial.hx
    trunk/sandy/haxe/branches/3.1/src/sandy/view/Frustum.hx

Log:
Integrate changeset 968 from AS3 trunk into 3.1 haxe branch. This patch  
will be merged into haxe trunk soon. Some inlining in SandyEvent.

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/core/Renderer.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/core/Renderer.hx	(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/core/Renderer.hx	Sat Mar 14  
03:18:46 2009
@@ -13,6 +13,7 @@
  import sandy.core.scenegraph.Sprite2D;
  import sandy.view.CullingState;
  import sandy.view.Frustum;
+import sandy.materials.Appearance;	

  import sandy.HaxeTypes;

@@ -285,8 +286,8 @@
  						// --
  						l_nPolyFlags |= l_nFlags;
  						// --
-						if( l_oShape.useSingleContainer == false | 
| !l_oShape.enableBackFaceCulling )
-							m_aRenderingList[m_nRenderingListCount++] = l_oFace;
+						if ( l_oShape.useSingleContainer == false )
+						    m_aRenderingList[m_nRenderingListCount++] = l_oFace;
  					}
  				}
  				// --

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/core/Scene3D.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/core/Scene3D.hx	(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/core/Scene3D.hx	Sat Mar 14  
03:18:46 2009
@@ -236,6 +236,8 @@
  		dispatchEvent(new SandyEvent(SandyEvent.LIGHT_ADDED));
  		return l;
  	}
+		
+	private function _onLightUpdate(pEvt:SandyEvent):Void {}

  	/**
  	* Enable this property to perfectly clip your 3D scene to the viewport's  
dimensions with a 2D clipping

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/core/data/Polygon.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/core/data/Polygon.hx	(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/core/data/Polygon.hx	Sat Mar 14  
03:18:46 2009
@@ -461,8 +461,8 @@
  		}
  		else
  		{
-			cvertices = vertices.slice(0,vertices.length);
-			caUVCoord = aUVCoord.slice(0,aUVCoord.length);
+			cvertices = vertices.concat([]);
+			caUVCoord = aUVCoord.concat([]);
  			// --
  			isClipped = p_oFrustum.clipFrustum( cvertices, caUVCoord );
  		}
@@ -476,7 +476,7 @@
  	*/
  	public function clipFrontPlane( p_oFrustum:Frustum ):Array<Vertex>
  	{
-		cvertices = vertices.slice(0,vertices.length);
+		cvertices = vertices.concat([]);
  		// If line
  		if( vertices.length < 3 )
  		{
@@ -484,7 +484,7 @@
  		}
  		else
  		{
-			caUVCoord = aUVCoord.slice(0,aUVCoord.length);
+			caUVCoord = aUVCoord.concat([]);
  			isClipped = p_oFrustum.clipFrontPlane( cvertices, caUVCoord );
  		}
  		return cvertices;
@@ -508,14 +508,8 @@
  	{
  		// --
  		var lCont:Sprite = (p_oContainer != null)?p_oContainer:m_oContainer;
-		if( visible )
-		{
-			m_oAppearance.frontMaterial.renderPolygon( scene, this, lCont );
-		}
-		else
-		{
-			m_oAppearance.backMaterial.renderPolygon( scene, this, lCont );
-		}
+		if( material != null )
+			material.renderPolygon( scene, this, lCont );
  	}

  	/**
@@ -525,6 +519,7 @@
  	public var material(__getMaterial,__setMaterial) : Material;
  	private function __getMaterial():Material
  	{
+		if( m_oAppearance == null ) return null;
  		return ( visible ) ? m_oAppearance.frontMaterial :  
m_oAppearance.backMaterial;
  	}
  	private function __setMaterial(v:Material) : Material
@@ -764,25 +759,38 @@
  	}
  	private function __setAppearance( p_oApp:Appearance ):Appearance
  	{
-		if( m_oAppearance != null )
+		if( p_oApp == m_oAppearance ) return null;
+		// --
+		if( m_oAppearance != null && p_oApp != null)
  		{
-			m_oAppearance.frontMaterial.unlink( this );
-			if( m_oAppearance.backMaterial != m_oAppearance.frontMaterial )
+			if( p_oApp.frontMaterial != m_oAppearance.frontMaterial )
+			{
+				m_oAppearance.frontMaterial.unlink( this );
+				p_oApp.frontMaterial.init( this );
+			}
+			if( m_oAppearance.frontMaterial != m_oAppearance.backMaterial &&  
p_oApp.backMaterial != m_oAppearance.backMaterial )
  			{
  				m_oAppearance.backMaterial.unlink( this );
  			}
-			m_oAppearance = null;
+			if( p_oApp.frontMaterial != p_oApp.backMaterial	&&  
p_oApp.backMaterial != m_oAppearance.backMaterial )
+			{
+				p_oApp.backMaterial.init( this );
+			}
+			m_oAppearance = p_oApp;
  		}
-		// --
-		if( p_oApp != null )
+		else if( p_oApp != null )
  		{
  			m_oAppearance = p_oApp;
-			// --
  			m_oAppearance.frontMaterial.init( this );
-			if( m_oAppearance.backMaterial != m_oAppearance.frontMaterial )
-			{
+			if( m_oAppearance.backMaterial != m_oAppearance.frontMaterial )
  				m_oAppearance.backMaterial.init( this );
-			}
+		}
+		else if( m_oAppearance != null )
+		{
+			m_oAppearance.frontMaterial.unlink( this );
+			if( m_oAppearance.backMaterial != m_oAppearance.frontMaterial )
+				m_oAppearance.backMaterial.unlink( this );
+			m_oAppearance = null;
  		}
  		return p_oApp;
  	}
@@ -790,7 +798,6 @@
  	private function _finishMaterial( pEvt:SandyEvent ):Void
  	{
  		if( m_oAppearance == null ) return;
-		//if( !visible ) return;
  		// --
  		m_oAppearance.frontMaterial.finish( m_oScene );
  		if( m_oAppearance.backMaterial != m_oAppearance.frontMaterial )
@@ -802,7 +809,7 @@
  	private function _beginMaterial( pEvt:SandyEvent ):Void
  	{
  		if( m_oAppearance == null ) return;
-		//if( !visible ) return;
+
  		// --
  		m_oAppearance.frontMaterial.begin( m_oScene );
  		if( m_oAppearance.backMaterial != m_oAppearance.frontMaterial )
@@ -832,9 +839,12 @@
  		// --
  		enableEvents = false;
  		enableInteractivity = false;
-		if( appearance.backMaterial != null ) appearance.backMaterial.unlink(  
this );
-		if( appearance.frontMaterial != null ) appearance.frontMaterial.unlink(  
this );
-		appearance = null;
+		if( appearance != null )
+		{
+			if( appearance.backMaterial != null ) appearance.backMaterial.unlink(  
this );
+			if( appearance.frontMaterial != null ) appearance.frontMaterial.unlink(  
this );
+			appearance = null;
+		}
  		if( m_oContainer.parent != null ) m_oContainer.parent.removeChild(  
m_oContainer );
  		m_oContainer = null;
  		// --

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/core/light/Light3D.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/core/light/Light3D.hx	(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/core/light/Light3D.hx	Sat Mar  
14 03:18:46 2009
@@ -30,6 +30,12 @@
  	public static inline var MAX_POWER:Float = 150;

  	/**
+	 * Public property which stores the modification of that light instance  
in case it changed.
+	 * It is useful for the cache system
+	 */
+	public var changed:Bool;
+
+	/**
  	 * Creates a new light source.
  	 *
  	 * @param p_oD		The direction of the emitted light.
@@ -55,6 +61,7 @@
  	{
  		_power =  NumberUtil.constrain(p_nPow, 0, Light3D.MAX_POWER);
  		_nPower = _power / Light3D.MAX_POWER;
+		changed = true;
  		dispatchEvent(new SandyEvent(SandyEvent.LIGHT_UPDATED));
  	}

@@ -101,6 +108,7 @@
  	{
  		_dir.x = x; _dir.y = y; _dir.z = z;
  		_dir.normalize();
+		changed = true;
  		dispatchEvent(new SandyEvent(SandyEvent.LIGHT_UPDATED));
  	}

@@ -115,6 +123,7 @@
  	{
  		_dir = pDir;
  		_dir.normalize();
+		changed = true;
  		dispatchEvent(new SandyEvent(SandyEvent.LIGHT_UPDATED));
  	}

@@ -164,6 +173,7 @@
  	private function __setColor(p_nColor:Int):Int
  	{
  		_color = p_nColor;
+		changed = true;

  		// we don't send LIGHT_UPDATED to aVoid recalculating light maps  
needlessly
  		// some event still has to be sent though, just in case...

Modified:  
trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Camera3D.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Camera3D.hx	 
(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Camera3D.hx	Sat  
Mar 14 03:18:46 2009
@@ -188,7 +188,6 @@
  	/**
  		* Updates the state of the camera transformation.
  		*
-		* @param p_oScene			The current scene
  		* @param p_oModelMatrix The matrix which represents the parent model  
matrix. Basically it stores the rotation/translation/scale of all the nodes  
above the current one.
  		* @param p_bChanged	A boolean value which specify if the state has  
changed since the previous rendering. If false, we save some matrix  
multiplication process.
  		*/
@@ -326,4 +325,4 @@
  	private var mp14:Float;private var mp24:Float;private var  
mp34:Float;private var mp44:Float;
  	private var	m_nOffx:Int;private var m_nOffy:Int;

-}
\ No newline at end of file
+}

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Node.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Node.hx	 
(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Node.hx	Sat Mar  
14 03:18:46 2009
@@ -224,6 +224,20 @@
  		return p_bUseSingleContainer;
  	}

+	/**
+	 * Apply clipping to all the children of that node
+	 * @param p_bUseClipping if true, the clipping will be used on that  
object and all its children if any
+	 */
+	private function __setEnableClipping( p_bUseClipping:Bool ):Bool
+	{
+		for ( l_oNode in children )
+		{
+			cast( l_oNode, Shape3D ).enableClipping = p_bUseClipping;
+		}
+		changed = true;
+		return p_bUseClipping;
+	}
+		
  	private function __getEnableBackFaceCulling( ):Bool
  	{
  		return false;

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Shape3D.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Shape3D.hx	 
(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/core/scenegraph/Shape3D.hx	Sat  
Mar 14 03:18:46 2009
@@ -74,7 +74,17 @@
  	*
  	* <p>Specify if this object polygons should be clipped against the camera  
frustum planes.</p>
  	*/
-	public var enableClipping:Bool;
+	public var enableClipping(__getEnableClipping,__setEnableClipping):Bool;
+	private function __getEnableClipping():Bool
+	{
+		return m_bClipping;
+	}
+
+	override private function __setEnableClipping( p_bClippingValue:Bool  
):Bool
+	{
+		m_bClipping = p_bClippingValue;
+		return p_bClippingValue;
+	}

  	/**
  	* Should forced depth be enable for this object?.
@@ -313,7 +323,8 @@
  	*/
  	public function display( ?p_oContainer:Sprite  ):Void
  	{
-		if (m_bNotConvex) {
+		if (m_bNotConvex)
+		{
  		// sort only if convex flag is not set
  #if flash
  		untyped aVisiblePolygons.sortOn( "m_nDepth", Array.NUMERIC |  
Array.DESCENDING );
@@ -791,6 +802,7 @@
  	private var m_bEv:Bool; // The event system state (enable or not)
  	private var m_oGeomCenter:Point3D;
  	private var m_bBackFaceCulling:Bool;
+	private var m_bClipping:Bool;

  	//@private
  	public var m_bWasOver:Bool;

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/events/SandyEvent.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/events/SandyEvent.hx	(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/events/SandyEvent.hx	Sat Mar 14  
03:18:46 2009
@@ -22,7 +22,7 @@
  	*
  	* @see sandy.core.Scene3D
  	*/
-	public static var LIGHT_ADDED:String = "lightAdded";
+	public static inline var LIGHT_ADDED:String = "lightAdded";

  	/**
  	* Defines the value of the <code>type</code> property of a  
<code>lightUpdated</code> event object.
@@ -31,7 +31,7 @@
  	*
  	* @see sandy.core.light.Light3D
  	*/
-	public static var LIGHT_UPDATED:String = "lightUpdated";
+	public static inline var LIGHT_UPDATED:String = "lightUpdated";

  	/**
  	* Defines the value of the <code>type</code> property of a  
<code>lightColorChanged</code> event object.
@@ -40,7 +40,7 @@
  	*
  	* @see sandy.core.light.Light3D
  	*/
-	public static var LIGHT_COLOR_CHANGED:String = "lightColorChanged";
+	public static inline var LIGHT_COLOR_CHANGED:String = "lightColorChanged";

  	/**
  	* Defines the value of the <code>type</code> property of a  
<code>scene_render</code> event object.
@@ -49,7 +49,7 @@
  	*
  	* @see sandy.core.Scene3D
  	*/
-	public static var SCENE_RENDER:String = "scene_render";
+	public static inline var SCENE_RENDER:String = "scene_render";

  	/**
  	* Defines the value of the <code>type</code> property of a  
<code>scene_render_finish</code> event object.
@@ -58,7 +58,7 @@
  	*
  	* @see sandy.core.Scene3D
  	*/
-	public static var SCENE_RENDER_FINISH:String = "scene_render_finish";
+	public static inline var SCENE_RENDER_FINISH:String  
= "scene_render_finish";

      /**
       * Indicates the scene has been culled.
@@ -67,7 +67,7 @@
       *
       * @see sandy.core.Scene3D
       */
-	public static var SCENE_CULL:String = "scene_cull";
+	public static inline var SCENE_CULL:String = "scene_cull";

      /**
       * Indicates the scene has been updated.
@@ -76,7 +76,7 @@
       *
       * @see sandy.core.Scene3D
       */
-	public static var SCENE_UPDATE:String = "scene_update";
+	public static inline var SCENE_UPDATE:String = "scene_update";

      /**
       * Indicates the display list has been rendered.
@@ -85,7 +85,7 @@
       *
       * @see sandy.core.Scene3D
       */
-	public static var SCENE_RENDER_DISPLAYLIST:String  
= "scene_render_display_list";
+	public static inline var SCENE_RENDER_DISPLAYLIST:String  
= "scene_render_display_list";

  	/**
  	* Defines the value of the <code>type</code> property of a  
<code>containerCreated</code> event object.
@@ -95,7 +95,7 @@
  	*
  	* @see sandy.core.World3D
  	*/
-	public static var CONTAINER_CREATED:String = "containerCreated";
+	public static inline var CONTAINER_CREATED:String = "containerCreated";

  	/**
  	* Defines the value of the <code>type</code> property of a  
<code>queueComplete</code> event object.
@@ -105,7 +105,7 @@
  	*
  	* @see sandy.util.LoaderQueue
  	*/
-	public static var QUEUE_COMPLETE:String = "queueComplete";
+	public static inline var QUEUE_COMPLETE:String = "queueComplete";

  	/**
  	* Defines the value of the <code>type</code> property of a  
<code>queueLoaderError</code> event object.
@@ -115,7 +115,7 @@
  	*
  	* @see sandy.util.LoaderQueue
  	*/
-	public static var QUEUE_LOADER_ERROR:String = "queueLoaderError";
+	public static inline var QUEUE_LOADER_ERROR:String = "queueLoaderError";

   	/**
  	 * Constructor.

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/materials/Appearance.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/materials/Appearance.hx	 
(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/materials/Appearance.hx	Sat Mar  
14 03:18:46 2009
@@ -3,6 +3,7 @@

  import sandy.core.Scene3D;
  import sandy.materials.Material;
+import sandy.core.data.Polygon;

  import sandy.HaxeTypes;

@@ -77,7 +78,18 @@
  	*/
  	private function __setFrontMaterial( p_oMat:Material ):Material
  	{
+		if( m_oFrontMaterial == p_oMat ) return null;
+		// --
+		var l_aUnLinked:haxe.FastList<Polygon> = new haxe.FastList<Polygon>();
+		if( m_oFrontMaterial != null )
+			l_aUnLinked = m_oFrontMaterial.unlinkAll();
+		// --
  		m_oFrontMaterial = p_oMat;
+		// --
+		for ( l_oPoly in l_aUnLinked )
+		{
+			m_oFrontMaterial.init(l_oPoly);
+		}
  		if( m_oBackMaterial == null )
  		{
  			m_oBackMaterial = p_oMat;

Modified:  
trunk/sandy/haxe/branches/3.1/src/sandy/materials/BitmapMaterial.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/materials/BitmapMaterial.hx	 
(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/materials/BitmapMaterial.hx	Sat  
Mar 14 03:18:46 2009
@@ -167,7 +167,6 @@
  		}
  		// --
  		super.renderPolygon( p_oScene, p_oPolygon, p_mcContainer );
-		//if( attributes != null )  attributes.draw( graphics, polygon, this,  
p_oScene ) ;
  		// --
  		l_points = null;
  		l_uv = null;
@@ -379,12 +378,14 @@
  		m_nWidth = m_oTexture.width;
  		m_nInvHeight = 1/m_nHeight;
  		m_nInvWidth = 1/m_nWidth;
+
  		// -- We reinitialize the precomputed matrix
  		if( l_bReWrap && m_oPolygonMatrixMap != null )
  		{
  			for( l_sID in m_oPolygonMatrixMap.keys() )
  			{
  				var l_oPoly:Polygon = Polygon.POLYGON_MAP.get( l_sID );
+				unlink( l_oPoly );
  				init( l_oPoly );
  			}
  		}
@@ -407,6 +408,7 @@
  		for( l_sID in m_oPolygonMatrixMap.keys() )
  		{
  			var l_oPoly:Polygon = Polygon.POLYGON_MAP.get( l_sID );
+			unlink( l_oPoly );
  			init( l_oPoly );
  		}
  	}
@@ -474,10 +476,23 @@
  		return p_nValue;
  	}

+	override public function dispose():Void
+	{
+		super.dispose();
+		if( m_oTexture != null ) m_oTexture.dispose();
+		m_oTexture = null;
+		if( m_oTextureClone != null ) m_oTextureClone.dispose();
+		m_oTextureClone = null;
+		m_oPolygonMatrixMap = null;
+	}
+		
  	public override function unlink( p_oPolygon:Polygon ):Void
  	{
-		if( m_oPolygonMatrixMap.exists(p_oPolygon.id) )
-			m_oPolygonMatrixMap.remove(p_oPolygon.id);
+		if( m_oPolygonMatrixMap != null )
+		{
+			if( m_oPolygonMatrixMap.exists(p_oPolygon.id) )
+				m_oPolygonMatrixMap.remove(p_oPolygon.id);
+		}
  		// --
  		super.unlink( p_oPolygon );
  	}

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/materials/Material.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/materials/Material.hx	(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/materials/Material.hx	Sat Mar  
14 03:18:46 2009
@@ -46,6 +46,12 @@
  	public var lightingEnable:Bool;

  	/**
+	 * Specifies if the material can automatically be disposed when unused
+	 * Default value is to true
+	 */
+	public var autoDipose:Bool;
+		
+	/**
  	* Creates a material.
  	*
  	* <p>This constructor is never called directly - but by sub class  
constructors.</p>
@@ -63,6 +69,36 @@
  		attributes = (p_oAttr == null) ? new MaterialAttributes() : p_oAttr;
  		m_bModified = true;
  		m_oType = MaterialType.NONE;
+		m_nRefCounting = 0;
+		m_oPolygonMap = new IntHash<Int>();
+		autoDipose = true;
+	}
+		
+	private var m_oPolygonMap:IntHash<Int>;
+	private var m_nRefCounting:Int;
+		
+	/**
+	 * Method to call when you want to release the resources of that material  
(filters, attributes and lreferences to polygons)
+	 */
+	public function dispose():Void
+	{
+		var l_oApp:Appearance;
+		var l_oPoly:Polygon;
+		for( l_sLabel in m_oPolygonMap )
+		{
+			l_oPoly = Polygon.POLYGON_MAP.get(l_sLabel);
+			unlink(l_oPoly);
+			l_oApp = l_oPoly.appearance;
+			if( l_oApp.frontMaterial == this )
+				l_oApp.frontMaterial = null;//Shape3D.DEFAULT_MATERIAL;
+			else if( l_oApp.backMaterial == this )
+				l_oApp.backMaterial = null;//Shape3D.DEFAULT_MATERIAL;
+		
+			m_oPolygonMap.remove(l_sLabel);
+		}
+		attributes = null;
+		_filters = null;
+		//m_oPolygonMap = null;
  	}

  	/**
@@ -145,8 +181,17 @@
  	*/
  	public function init( p_oPolygon:Polygon ):Void
  	{
-		if( attributes != null )
-			attributes.init( p_oPolygon );
+		if( !m_oPolygonMap.exists(p_oPolygon.id) )
+		{
+			m_oPolygonMap.set(p_oPolygon.id, 1);
+			m_nRefCounting ++;
+			if( attributes != null )
+				attributes.init( p_oPolygon );
+		}
+		else
+		{
+			m_oPolygonMap.set(p_oPolygon.id, m_oPolygonMap.get(p_oPolygon.id) + 1);
+		}
  	}

  	/**
@@ -156,9 +201,45 @@
  	*/
  	public function unlink( p_oPolygon:Polygon ):Void
  	{
-		if( attributes != null )
-			attributes.unlink( p_oPolygon );
+			if( !m_oPolygonMap.exists(p_oPolygon.id) )
+			{
+				m_oPolygonMap.set( p_oPolygon.id, m_oPolygonMap.get(p_oPolygon.id) - 1  
);
+				if( m_oPolygonMap.get(p_oPolygon.id) == 0 )
+				{
+					m_oPolygonMap.remove(p_oPolygon.id);
+					m_nRefCounting --;
+					if( attributes != null )
+						attributes.unlink( p_oPolygon );
+				}
+			}
+			//
+			if( autoDipose && m_nRefCounting <= 0 )
+			{
+				dispose();
+			}
+	}
+		
+	/**
+	 * Unlink all the non used polygons
+	 */
+	public function unlinkAll():haxe.FastList<Polygon>
+	{
+		var l_aUnlinked:haxe.FastList<Polygon> = new haxe.FastList<Polygon>();
+		var l_oApp:Appearance;
+		var l_oPoly:Polygon;
+		for( l_sLabel in m_oPolygonMap )
+		{
+			l_oPoly = Polygon.POLYGON_MAP.get( l_sLabel );
+			l_oApp = l_oPoly.appearance;
+			if( l_oApp.frontMaterial == this || l_oApp.backMaterial == this )
+			{
+				unlink(l_oPoly);
+				l_aUnlinked.add( l_oPoly );
+			}
+		}
+		return l_aUnlinked;
  	}
+		

  	/**
  	* The material type of this material.
@@ -243,6 +324,7 @@
  	private var _filters:Array<BitmapFilter>;
  	private var _id:Float;
  	private static var _ID_:Float = 0;
-	private static var create:Bool;
+	
+	//private static var create:Bool;
  }


Modified: trunk/sandy/haxe/branches/3.1/src/sandy/materials/MovieMaterial.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/materials/MovieMaterial.hx	 
(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/materials/MovieMaterial.hx	Sat  
Mar 14 03:18:46 2009
@@ -113,6 +113,14 @@
  		//h = null;
  	}

+	override public function dispose():Void
+	{
+		super.dispose();
+		stop();
+		m_oTimer = null;
+		m_oMovie = null;
+	}
+
  	/**
  	 * Renders this material on the face it dresses.
  	 *

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/materials/VideoMaterial.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/materials/VideoMaterial.hx	 
(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/materials/VideoMaterial.hx	Sat  
Mar 14 03:18:46 2009
@@ -70,6 +70,15 @@
  		start();
  	}

+	override public function dispose():Void
+	{
+		super.dispose();
+		stop();
+		m_oAlpha = null;
+		m_oTimer = null;
+		m_oVideo = null;
+	}
+
  	/**
  	* @private
  	*/

Modified: trunk/sandy/haxe/branches/3.1/src/sandy/view/Frustum.hx
==============================================================================
--- trunk/sandy/haxe/branches/3.1/src/sandy/view/Frustum.hx	(original)
+++ trunk/sandy/haxe/branches/3.1/src/sandy/view/Frustum.hx	Sat Mar 14  
03:18:46 2009
@@ -156,10 +156,11 @@
  	public function polygonInFrustum( p_oPoly:Polygon ):Int
  	{
  		var l_nIn:Int = 0, l_nOut:Int = 0, l_nDist:Float;
+	        var l_aVertices:Array<Vertex> = p_oPoly.vertices;
  		// --
  		for ( plane in aPlanes )
  		{
-			for ( l_oVertex in p_oPoly.vertices )
+			for ( l_oVertex in l_aVertices )
  			{
  				l_nDist = plane.a * l_oVertex.wx + plane.b * l_oVertex.wy + plane.c *  
l_oVertex.wz + plane.d;
  				// is the corner outside or inside
@@ -275,16 +276,33 @@
  	*/
  	public function clipFrustum( p_aCvert: Array<Vertex>,  
p_aUVCoords:Array<UVCoord> ):Bool
  	{
-		if( p_aCvert.length <= 2 ) return true;
+		if( p_aCvert.length <= 2 )
+		{
+			return true;
+		}
  		var l_bResult:Bool, l_bClipped:Bool;
  		l_bResult = clipPolygon( aPlanes[NEAR], p_aCvert, p_aUVCoords ); // near
+		if ( p_aCvert.length <= 2 )
+			return true;
+				
  		l_bClipped = clipPolygon( aPlanes[LEFT], p_aCvert, p_aUVCoords ); // left
+		if ( p_aCvert.length <= 2 )
+			return true;
  		l_bResult = l_bResult || l_bClipped;
+			
  		l_bClipped = clipPolygon( aPlanes[RIGHT], p_aCvert, p_aUVCoords ); //  
right
+		if ( p_aCvert.length <= 2 )
+			return true;
  		l_bResult  = l_bResult || l_bClipped;
+			
  		l_bClipped = clipPolygon( aPlanes[BOTTOM], p_aCvert, p_aUVCoords ); //  
top
+	        if ( p_aCvert.length <= 2 )
+			return true;
  		l_bResult = l_bResult || l_bClipped;
+	
  		l_bClipped = clipPolygon( aPlanes[TOP], p_aCvert, p_aUVCoords ); //  
bottom
+		if ( p_aCvert.length <= 2 )
+			return true;
  		l_bResult = l_bResult || l_bClipped;

  		return l_bResult;
@@ -367,11 +385,12 @@
  	* @param p_aCvert	Vertices of the polygon
  	* @param p_aUVCoords	UV coordiantes of the polygon
  	*/
+	private static inline var aDist:Array<Vertex> = [];
  	public function clipPolygon( p_oPlane:Plane, p_aCvert:Array<Vertex>,  
p_aUVCoords:Array<UVCoord> ):Bool
  	{
-		var allin:Bool = true, allout:Bool = true;
-		var v:Vertex;
-		var i:Int, l:Int = p_aCvert.length, lDist:Float;
+		var allin:Bool = true, allout:Bool = true, v:Vertex,
+			i:Int, l:Int = p_aCvert.length, lDist:Float,
+			a:Float = p_oPlane.a, b:Float = p_oPlane.b, c:Float = p_oPlane.c,  
d:Float = p_oPlane.d;
  		// -- If no points, we return null
  		#if flash10
  		untyped aDist.length = 0;
@@ -381,7 +400,7 @@
  		// -- otherwise we compute the distances to frustum plane
  		for ( v in p_aCvert )
  		{
-			lDist = p_oPlane.a * v.wx + p_oPlane.b * v.wy + p_oPlane.c * v.wz +  
p_oPlane.d;
+			lDist = a * v.wx + b * v.wy + c * v.wz + d;
  			if (lDist < 0) allin = false;
  			if (lDist >= 0) allout = false;
  			aDist.push( lDist );
@@ -404,8 +423,7 @@
  		var l_oUV1:UVCoord = l_aTmpUv[0], l_oUV2:UVCoord = null,  
l_oUVTmp:UVCoord = null;
  		var v1:Vertex = tmp[0], v2:Vertex = null,  t:Vertex = null;
  		//
-		var d:Float, dist2:Float, dist1:Float = aDist[0];
-		var clipped:Bool = false, inside:Bool = (dist1 >= 0);
+		var dist2:Float, dist1:Float = aDist[0], clipped:Bool = false,  
inside:Bool = (dist1 >= 0);
  		var curv:Float = 0;
  		for (i in 1...(l+1))
  		{
@@ -429,8 +447,8 @@
  				t.wy = (v1.wy+(v2.wy-v1.wy)*d);
  				t.wz = (v1.wz+(v2.wz-v1.wz)*d);
  				//
-				p_aCvert.push( t );
-				p_aCvert.push( v2 );
+				p_aCvert[p_aCvert.length] = ( t );
+				p_aCvert[p_aCvert.length] = ( v2 );
  				//
  				l_oUVTmp = new UVCoord();
  				l_oUVTmp.u = (l_oUV1.u+(l_oUV2.u-l_oUV1.u)*d);



More information about the Sandy mailing list