From 204ee6689881203c0c0da2073812a1415583c865 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Tue, 5 May 2015 14:22:11 -0300 Subject: [PATCH] added rl_sprites_render which renders sprites without saving the background --- src/rl_sprite.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ src/rl_sprite.h | 2 ++ 2 files changed, 54 insertions(+) diff --git a/src/rl_sprite.c b/src/rl_sprite.c index 2c1d6cd..2e5790c 100644 --- a/src/rl_sprite.c +++ b/src/rl_sprite.c @@ -64,6 +64,58 @@ static int compare( const void* e1, const void* e2 ) return c1 - c2; } +void rl_sprites_render( void ) +{ + spt_t* sptptr = sprites; + const spt_t* endptr = sprites + num_sprites; + + if ( sptptr < endptr ) + { + do + { + sptptr->sprite->flags &= ~RL_SPRITE_TEMP_INV; + sptptr->sprite->flags |= sptptr->sprite->image == NULL; + sptptr++; + } + while ( sptptr < endptr ); + } + + qsort( (void*)sprites, num_sprites, sizeof( spt_t ), compare ); + + rl_sprite_t guard; + guard.flags = RL_SPRITE_UNUSED; + sprites[ num_sprites ].sprite = &guard; /* guard */ + + sptptr = sprites; + + /* Iterate over active and visible sprites and blit them */ + /* flags & 0x0007U == 0 */ + if ( sptptr->sprite->flags == 0 ) + { + do + { + rl_image_blit_nobg( sptptr->sprite->image, x0 + sptptr->sprite->x, y0 + sptptr->sprite->y ); + sptptr++; + } + while ( sptptr->sprite->flags == 0 ); + } + + num_visible = sptptr - sprites; + + /* Jump over active but invisible sprites */ + /* flags & 0x0004U == 0x0000U */ + if ( ( sptptr->sprite->flags & RL_SPRITE_UNUSED ) == 0 ) + { + do + { + sptptr++; + } + while ( ( sptptr->sprite->flags & RL_SPRITE_UNUSED ) == 0 ); + } + + num_sprites = sptptr - sprites; +} + void rl_sprites_begin( void ) { spt_t* sptptr = sprites; diff --git a/src/rl_sprite.h b/src/rl_sprite.h index 76f8a54..d9ac87b 100644 --- a/src/rl_sprite.h +++ b/src/rl_sprite.h @@ -38,6 +38,8 @@ rl_sprite_t* rl_sprite_create( void ); void rl_sprites_translate( int x0, int y0 ); +void rl_sprites_render( void ); + void rl_sprites_begin( void ); void rl_sprites_end( void );