From 163efc05e89bc24e4fe8d6f763557a5f778e7293 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Sat, 3 Mar 2012 21:23:25 +0100 Subject: [PATCH] little cleanup --- TODO | 1 - src/about.c | 2 +- src/main.c | 22 ++++------------------ src/main.h | 2 +- src/map.c | 6 +++--- src/menu.c | 10 +++++----- 6 files changed, 14 insertions(+), 29 deletions(-) diff --git a/TODO b/TODO index 490f700..4024dfe 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -- check if every gamestate is stable on every platform - moar documentation - rewrite music handling into mixers - control settings diff --git a/src/about.c b/src/about.c index f0357d7..4226fd4 100644 --- a/src/about.c +++ b/src/about.c @@ -116,7 +116,7 @@ void About_Preload(struct Game *game) { game->about.letter_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)); al_set_target_bitmap(game->about.letter_bitmap); - ScaleBitmap(game->about.letter, al_get_display_width(game->display), al_get_display_height(game->display), 0.75); + ScaleBitmap(game->about.letter, al_get_display_width(game->display), al_get_display_height(game->display)); al_destroy_bitmap(game->about.letter); al_set_target_bitmap(game->about.fade_bitmap); diff --git a/src/main.c b/src/main.c index cb681c5..10ae4fe 100644 --- a/src/main.c +++ b/src/main.c @@ -147,7 +147,7 @@ void DrawGameState(struct Game *game) { } } -void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height, float val) { +void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height) { if ((al_get_bitmap_width(source)==width) && (al_get_bitmap_height(source)==height)) { al_draw_bitmap(source, 0, 0, 0); return; @@ -156,6 +156,8 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height, float val) { al_lock_bitmap(al_get_target_bitmap(), ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); al_lock_bitmap(source, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); + //linear filtering code written by SiegeLord + ALLEGRO_COLOR interpolate(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2, float frac) { return al_map_rgba_f(c1.r + frac * (c2.r - c1.r), c1.g + frac * (c2.g - c1.g), @@ -181,22 +183,6 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height, float val) { al_put_pixel(x, y, result); } - /* - float pixy = ((float)y / height) * al_get_bitmap_height(source); - for (x = 0; x < width; x++) { - float pixx = ((float)x / width) * al_get_bitmap_width(source); - ALLEGRO_COLOR a = al_get_pixel(source, pixx-val, pixy-val); - ALLEGRO_COLOR b = al_get_pixel(source, pixx+val, pixy-val); - ALLEGRO_COLOR c = al_get_pixel(source, pixx-val, pixy+val); - ALLEGRO_COLOR d = al_get_pixel(source, pixx+val, pixy+val); - ALLEGRO_COLOR result = al_map_rgba_f( - (a.r+b.r+c.r+d.r) / 4, - (a.g+b.b+c.g+d.g) / 4, - (a.b+b.g+c.b+d.b) / 4, - (a.a+b.a+c.a+d.a) / 4 - ); - al_put_pixel(x, y, result); - }*/ } al_unlock_bitmap(al_get_target_bitmap()); al_unlock_bitmap(source); @@ -216,7 +202,7 @@ ALLEGRO_BITMAP* LoadFromCache(struct Game *game, char* filename, int width, int source = al_load_bitmap( origfn ); al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR); - ScaleBitmap(source, width, height, 0.35); + ScaleBitmap(source, width, height); al_save_bitmap(cachefn, target); PrintConsole(game, "Cache bitmap %s generated.", filename); } diff --git a/src/main.h b/src/main.h index e3a7c74..08c6ebb 100644 --- a/src/main.h +++ b/src/main.h @@ -177,7 +177,7 @@ void PrintConsole(struct Game *game, char* format, ...); /*! \brief Draws console bitmap on screen. */ void DrawConsole(struct Game *game); -void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height, float val); +void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height); ALLEGRO_BITMAP* LoadFromCache(struct Game *game, char* filename, int width, int height); float tps(struct Game *game, float t); diff --git a/src/map.c b/src/map.c index 94e1e83..a4066cf 100644 --- a/src/map.c +++ b/src/map.c @@ -112,13 +112,13 @@ void Map_Preload(struct Game *game) { ALLEGRO_BITMAP *scaled =LoadFromCache(game, "table.png", al_get_display_width(game->display), al_get_display_height(game->display)); al_set_target_bitmap(game->map.map); al_draw_bitmap(scaled, 0, 0 ,0); - //ScaleBitmap(game->map.background, al_get_display_width(game->display), al_get_display_height(game->display), 0.5); + //ScaleBitmap(game->map.background, al_get_display_width(game->display), al_get_display_height(game->display)); al_set_target_bitmap(scaled); - ScaleBitmap(game->map.map_bg, al_get_display_width(game->display), al_get_display_height(game->display), 0.5); + ScaleBitmap(game->map.map_bg, al_get_display_width(game->display), al_get_display_height(game->display)); al_set_target_bitmap(game->map.map); al_draw_bitmap(scaled, 0, 0 ,0); al_set_target_bitmap(scaled); - ScaleBitmap(game->map.highlight, al_get_display_width(game->display), al_get_display_height(game->display), 0.5); + ScaleBitmap(game->map.highlight, al_get_display_width(game->display), al_get_display_height(game->display)); al_set_target_bitmap(game->map.map); al_draw_bitmap(scaled, 0, 0 ,0); al_destroy_bitmap(scaled); diff --git a/src/menu.c b/src/menu.c index b818f74..dbca801 100644 --- a/src/menu.c +++ b/src/menu.c @@ -112,7 +112,7 @@ void Menu_Preload(struct Game *game) { game->menu.menu_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)*0.45); al_set_target_bitmap(game->menu.menu_bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); - ScaleBitmap(game->menu.image, al_get_display_width(game->display), al_get_display_height(game->display)*0.45, 0.75); + ScaleBitmap(game->menu.image, al_get_display_width(game->display), al_get_display_height(game->display)*0.45); //al_draw_scaled_bitmap(game->menu.image,0, 0, al_get_bitmap_width(game->menu.image), al_get_bitmap_height(game->menu.image), 0, 0, al_get_display_width(game->display), al_get_display_height(game->display),0); al_destroy_bitmap(game->menu.image); @@ -120,21 +120,21 @@ void Menu_Preload(struct Game *game) { game->menu.cloud_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.25); al_set_target_bitmap(game->menu.cloud_bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); - ScaleBitmap(game->menu.cloud, al_get_bitmap_width(game->menu.cloud_bitmap), al_get_bitmap_height(game->menu.cloud_bitmap), 0.75); + ScaleBitmap(game->menu.cloud, al_get_bitmap_width(game->menu.cloud_bitmap), al_get_bitmap_height(game->menu.cloud_bitmap)); //al_draw_scaled_bitmap(game->menu.cloud,0, 0, al_get_bitmap_width(game->menu.cloud), al_get_bitmap_height(game->menu.cloud), 0, 0, al_get_bitmap_width(game->menu.cloud_bitmap), al_get_bitmap_height(game->menu.cloud_bitmap),0); al_destroy_bitmap(game->menu.cloud); game->menu.cloud2_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.2, al_get_display_height(game->display)*0.1); al_set_target_bitmap(game->menu.cloud2_bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); - ScaleBitmap(game->menu.cloud2, al_get_bitmap_width(game->menu.cloud2_bitmap), al_get_bitmap_height(game->menu.cloud2_bitmap), 0.75); + ScaleBitmap(game->menu.cloud2, al_get_bitmap_width(game->menu.cloud2_bitmap), al_get_bitmap_height(game->menu.cloud2_bitmap)); //al_draw_scaled_bitmap(game->menu.cloud2,0, 0, al_get_bitmap_width(game->menu.cloud2), al_get_bitmap_height(game->menu.cloud2), 0, 0, al_get_bitmap_width(game->menu.cloud2_bitmap), al_get_bitmap_height(game->menu.cloud2_bitmap),0); al_destroy_bitmap(game->menu.cloud2); game->menu.pinkcloud_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.33125, al_get_display_height(game->display)); //*0.8122); game->menu.pinkcloud_scaled = al_create_bitmap(al_get_bitmap_width(game->menu.pinkcloud_bitmap), al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.8122); al_set_target_bitmap(game->menu.pinkcloud_scaled); - ScaleBitmap(game->menu.pinkcloud, al_get_bitmap_width(game->menu.pinkcloud_scaled), al_get_bitmap_height(game->menu.pinkcloud_scaled), 0.75); + ScaleBitmap(game->menu.pinkcloud, al_get_bitmap_width(game->menu.pinkcloud_scaled), al_get_bitmap_height(game->menu.pinkcloud_scaled)); //al_draw_scaled_bitmap(game->menu.pinkcloud,0, 0, al_get_bitmap_width(game->menu.pinkcloud), al_get_bitmap_height(game->menu.pinkcloud), 0, 0, al_get_bitmap_width(game->menu.pinkcloud_scaled), al_get_bitmap_height(game->menu.pinkcloud_scaled),0); al_destroy_bitmap(game->menu.pinkcloud); @@ -149,7 +149,7 @@ void Menu_Preload(struct Game *game) { game->menu.mountain_bitmap = al_create_bitmap(al_get_display_width(game->display)*0.055, al_get_display_height(game->display)/9); al_set_target_bitmap(game->menu.mountain_bitmap); al_clear_to_color(al_map_rgba(0,0,0,0)); - ScaleBitmap(game->menu.mountain, al_get_bitmap_width(game->menu.mountain_bitmap), al_get_bitmap_height(game->menu.mountain_bitmap), 0.75); + ScaleBitmap(game->menu.mountain, al_get_bitmap_width(game->menu.mountain_bitmap), al_get_bitmap_height(game->menu.mountain_bitmap)); //al_draw_scaled_bitmap(game->menu.mountain,0, 0, al_get_bitmap_width(game->menu.mountain), al_get_bitmap_height(game->menu.mountain), 0, 0, al_get_bitmap_width(game->menu.mountain_bitmap), al_get_bitmap_height(game->menu.mountain_bitmap),0); al_destroy_bitmap(game->menu.mountain);