示例#1
0
	public SpriteBatch( GraphicsContext graphics, int maxSpriteCount )
	{
		int maxVertexCount = maxSpriteCount * 4 ;
		int maxIndexCount = maxSpriteCount * 6 ;

		graphicsContext = graphics ;
		#if !RESIZE_VERTEX_BUFFER
		vertexBuffer = new VertexBuffer( maxVertexCount, maxIndexCount, vertexFormats ) ;
		spriteCapacity = maxSpriteCount ;
		#endif // RESIZE_VERTEX_BUFFER
		vertexData = new Vertex[ maxVertexCount ] ;
		indexData = new ushort[ maxIndexCount ] ;

		spriteList = new Sprite[ maxSpriteCount ] ;
		sortedList = new Sprite[ maxSpriteCount ] ;

		#if ENABLE_SIN_TABLE
		if ( sinTable == null ) {
			sinTable = new float[ 4096 ] ;
			for ( int i = 0 ; i < 4096 ; i ++ ) {
				sinTable[ i ] = FMath.Sin( i * ( FMath.PI / 2048.0f ) ) ;
			}
		}
		#endif // ENABLE_SIN_TABLE
	}
示例#2
0
	public void RemoveSprite( Sprite sprite )
	{
		RemoveFromSpriteList( sprite ) ;
		RemoveFromSortedList( sprite ) ;
		sprite.batch = null ;
		vertexCount -= 4 ;
		indexCount -= 6 ;
	}
示例#3
0
	public void AddSprite( Sprite sprite )
	{
		AddToSpriteList( sprite ) ;
		AddToSortedList( sprite ) ;
		sprite.batch = this ;
		vertexCount += 4 ;
		indexCount += 6 ;
	}
示例#4
0
 public void SetSpriteCount( int count )
 {
     count = Math.Min( Math.Max( count, 1 ), sprites.Length ) ;
     if ( count > spriteCount ) {
     for ( int i = spriteCount ; i < count ; i ++ ) {
         sprites[ i ] = new Sprite( batch, material, 0 ) ;
         InitSprite( sprites[ i ] ) ;
     }
     } else {
     for ( int i = count ; i < spriteCount ; i ++ ) {
         batch.RemoveSprite( sprites[ i ] ) ;
     }
     }
     spriteCount = count ;
 }
示例#5
0
        public void InitSprite( Sprite s )
        {
            s.Position.X = 0;
            s.Position.Y = 0;
            s.Direction.X = 0;
            s.Direction.Y = 0;
            s.Size = new Vector2( spriteSize, spriteSize ) ;
            s.Center = new Vector2( 0.5f, 0.5f ) ;
            s.UVOffset = new Vector2( 0.25f, 0.25f ) ;
            s.UVSize = new Vector2( 0.25f, 0.25f ) ;
            s.Color = new Rgba( 255, 255, 255, 255 ) ;

            s.UpdateAll() ;
        }
示例#6
0
	internal int FindSortedList( Sprite sprite )
	{
		int lower = -1 ;
		int upper = sortedCount ;
		while ( lower + 1 < upper ) {
			int middle = ( lower + upper ) / 2 ;
			if ( sortedList[ middle ].sortKey > sprite.sortKey ) {
				upper = middle ;
			} else {
				lower = middle ;
			}
		}
		return lower ;
	}
示例#7
0
	internal void RemoveFromSortedList( Sprite sprite )
	{
		int index = FindSortedList( sprite ) ;
		if ( sortedList[ index ] == sprite ) {
			sortedList[ index ] = sprite.sortNext ;
			if ( sprite.sortNext == sprite ) {
				int count = ( -- sortedCount ) - index ;
				if ( count > 0 ) Array.Copy( sortedList, index + 1, sortedList, index, count ) ;
			}
		}
		sprite.sortPrev.sortNext = sprite.sortNext ;
		sprite.sortNext.sortPrev = sprite.sortPrev ;
		needUpdateIndexData = true ;
	}
示例#8
0
	internal void AddToSortedList( Sprite sprite )
	{
		int index = FindSortedList( sprite ) ;
		if ( index >= 0 && sortedList[ index ].sortKey == sprite.sortKey ) {
			var head = sortedList[ index ] ;
			var tail = head.sortPrev ;
			head.sortPrev = sprite ;
			tail.sortNext = sprite ;
			sprite.sortPrev = tail ;
			sprite.sortNext = head ;
		} else {
			int count = ( sortedCount ++ ) - ( ++ index ) ;
			if ( count > 0 ) Array.Copy( sortedList, index, sortedList, index + 1, count ) ;
			sortedList[ index ] = sprite ;
			sprite.sortPrev = sprite ;
			sprite.sortNext = sprite ;
		}
		sprite.indexID = -1 ;
		needUpdateIndexData = true ;
	}
示例#9
0
	internal void RemoveFromSpriteList( Sprite sprite )
	{
		var tail = spriteList[ -- spriteCount ] ;
		if ( sprite != tail ) {
			spriteList[ sprite.spriteID ] = tail ;
			for ( int i = 0 ; i < 4 ; i ++ ) {
				vertexData[ sprite.vertexID + i ] = vertexData[ tail.vertexID + i ] ;
			}
			tail.spriteID = sprite.spriteID ;
			tail.vertexID = sprite.vertexID ;
		}
		needUpdateVertexData = true ;
	}
示例#10
0
	//  Subroutines

	internal void AddToSpriteList( Sprite sprite )
	{
		sprite.spriteID = spriteCount ;
		sprite.vertexID = vertexCount ;
		spriteList[ spriteCount ++ ] = sprite ;
		needUpdateVertexData = true ;
	}