From 636ec2a9a5095660fb7bdf88247a86b2c7a6453a Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Wed, 26 Aug 2015 16:35:48 -0300 Subject: [PATCH] moved global translation to rl_image --- src/rl_image.c | 24 ++++++++++++++++++++++-- src/rl_image.h | 3 +++ src/rl_sprite.c | 19 +++++-------------- src/rl_sprite.h | 2 -- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/rl_image.c b/src/rl_image.c index c2a8385..425f88b 100644 --- a/src/rl_image.c +++ b/src/rl_image.c @@ -2,10 +2,21 @@ #include #include -#include - #include +static int tslt_x, tslt_y; + +void rl_image_init( void ) +{ + tslt_x = tslt_y = 0; +} + +void rl_image_translate( int x, int y ) +{ + tslt_x = x; + tslt_y = y; +} + const rl_image_t* rl_image_create( const rl_imagedata_t* imagedata, int check_transp, uint16_t transparent ) { size_t size; @@ -44,6 +55,9 @@ const rl_image_t* rl_image_create( const rl_imagedata_t* imagedata, int check_tr void rl_image_blit_nobg( const rl_image_t* image, int x, int y ) { + x += tslt_x; + y += tslt_y; + int x0 = 0; int y0 = 0; int x1 = image->width; @@ -174,6 +188,9 @@ void rl_image_blit_nobg( const rl_image_t* image, int x, int y ) uint16_t* rl_image_blit( const rl_image_t* image, int x, int y, uint16_t* bg_ ) { + x += tslt_x; + y += tslt_y; + int x0 = 0; int y0 = 0; int x1 = image->width; @@ -315,6 +332,9 @@ uint16_t* rl_image_blit( const rl_image_t* image, int x, int y, uint16_t* bg_ ) void rl_image_unblit( const rl_image_t* image, int x, int y, const uint16_t* bg_ ) { + x += tslt_x; + y += tslt_y; + int x0 = 0; int y0 = 0; int x1 = image->width; diff --git a/src/rl_image.h b/src/rl_image.h index 1d6865c..dc458c9 100644 --- a/src/rl_image.h +++ b/src/rl_image.h @@ -31,6 +31,9 @@ typedef struct } rl_image_t; +void rl_image_init( void ); +void rl_image_translate( int x, int y ); + /* Creates an image from a rl_imagedata_t. */ const rl_image_t* rl_image_create( const rl_imagedata_t* imagedata, int check_transp, uint16_t transparent ); /* Destroys an image. */ diff --git a/src/rl_sprite.c b/src/rl_sprite.c index 23e25e4..ebf2c7b 100644 --- a/src/rl_sprite.c +++ b/src/rl_sprite.c @@ -30,8 +30,6 @@ static item_t* free_list; static spt_t sprites[ RL_MAX_SPRITES + 1 ]; static int num_sprites, num_visible; -static int x0, y0; - static uint16_t saved_backgrnd[ RL_BG_SAVE_SIZE ]; static uint16_t* saved_ptr; @@ -46,7 +44,6 @@ void rl_sprite_init( void ) free_list = items; num_sprites = num_visible = 0; - x0 = y0 = 0; } rl_sprite_t* rl_sprite_create( void ) @@ -67,12 +64,6 @@ rl_sprite_t* rl_sprite_create( void ) return NULL; } -void rl_sprites_translate( int x, int y ) -{ - x0 = x; - y0 = y; -} - static int compare( const void* e1, const void* e2 ) { const spt_t* s1 = (const spt_t*)e1; @@ -105,7 +96,7 @@ void rl_sprites_blit_nobg( void ) qsort( (void*)sprites, num_sprites, sizeof( spt_t ), compare ); - item_t guard = { 0 }; + item_t guard = { { { { { 0 } } } } }; /* Ugh */ guard.sprite.flags = RL_SPRITE_UNUSED; sprites[ num_sprites ].item = &guard; @@ -117,7 +108,7 @@ void rl_sprites_blit_nobg( void ) { do { - rl_image_blit_nobg( sptptr->item->sprite.image, x0 + sptptr->item->sprite.x, y0 + sptptr->item->sprite.y ); + rl_image_blit_nobg( sptptr->item->sprite.image, sptptr->item->sprite.x, sptptr->item->sprite.y ); sptptr++; } while ( sptptr->item->sprite.flags == 0 ); @@ -174,7 +165,7 @@ void rl_sprites_blit( void ) qsort( (void*)sprites, num_sprites, sizeof( spt_t ), compare ); - item_t guard = { 0 }; + item_t guard = { { { { { 0 } } } } }; /* Ugh */ guard.sprite.flags = RL_SPRITE_UNUSED; sprites[ num_sprites ].item = &guard; @@ -188,7 +179,7 @@ void rl_sprites_blit( void ) do { sptptr->item->bg = saved_ptr; - saved_ptr = rl_image_blit( sptptr->item->sprite.image, x0 + sptptr->item->sprite.x, y0 + sptptr->item->sprite.y, saved_ptr ); + saved_ptr = rl_image_blit( sptptr->item->sprite.image, sptptr->item->sprite.x, sptptr->item->sprite.y, saved_ptr ); sptptr++; } while ( sptptr->item->sprite.flags == 0 ); @@ -236,7 +227,7 @@ void rl_sprites_unblit( void ) { do { - rl_image_unblit( sptptr->item->sprite.image, x0 + sptptr->item->sprite.x, y0 + sptptr->item->sprite.y, sptptr->item->bg ); + rl_image_unblit( sptptr->item->sprite.image, sptptr->item->sprite.x, sptptr->item->sprite.y, sptptr->item->bg ); sptptr--; } while ( sptptr >= sprites ); diff --git a/src/rl_sprite.h b/src/rl_sprite.h index 492462c..52c0198 100644 --- a/src/rl_sprite.h +++ b/src/rl_sprite.h @@ -36,8 +36,6 @@ void rl_sprite_init( void ); rl_sprite_t* rl_sprite_create( void ); #define rl_sprite_destroy( sprite ) do { ( sprite )->flags |= RL_SPRITE_UNUSED; } while ( 0 ) -void rl_sprites_translate( int x0, int y0 ); - void rl_sprites_blit_nobg( void ); void rl_sprites_blit( void );