From 1afc4a3f31bb8d58c29c6e76dc47bd088a75f34f Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Tue, 16 Aug 2016 23:20:00 +0200 Subject: [PATCH] don't create and destroy bitmap on every PrintConsole call --- src/internal.c | 4 ++-- src/libsuperderpy.c | 1 + src/libsuperderpy.h | 1 + src/utils.c | 6 ++---- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/internal.c b/src/internal.c index 1a54511..b5b873a 100644 --- a/src/internal.c +++ b/src/internal.c @@ -108,8 +108,6 @@ SYMBOL_INTERNAL void DrawConsole(struct Game *game) { } SYMBOL_INTERNAL void Console_Load(struct Game *game) { - game->_priv.font_console = NULL; - game->_priv.console = NULL; game->_priv.font_console = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"),al_get_display_height(game->display)*0.025,0 ); if (al_get_display_height(game->display)*0.025 >= 16) { game->_priv.font_bsod = al_load_ttf_font(GetDataFilePath(game, "fonts/PerfectDOSVGA437.ttf"),16 * ((al_get_display_height(game->display) > 1080) ? 2 : 1) ,0 ); @@ -117,6 +115,7 @@ SYMBOL_INTERNAL void Console_Load(struct Game *game) { game->_priv.font_bsod = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"), al_get_display_height(game->display)*0.025,0 ); } game->_priv.console = al_create_bitmap((al_get_display_width(game->display) / 320) * 320, al_get_font_line_height(game->_priv.font_console)*5); + game->_priv.console_tmp = al_create_bitmap((al_get_display_width(game->display) / 320) * 320, al_get_font_line_height(game->_priv.font_console)*5); al_set_target_bitmap(game->_priv.console); al_clear_to_color(al_map_rgba(0,0,0,80)); al_set_target_bitmap(al_get_backbuffer(game->display)); @@ -125,6 +124,7 @@ SYMBOL_INTERNAL void Console_Load(struct Game *game) { SYMBOL_INTERNAL void Console_Unload(struct Game *game) { al_destroy_font(game->_priv.font_console); al_destroy_bitmap(game->_priv.console); + al_destroy_bitmap(game->_priv.console_tmp); } SYMBOL_INTERNAL void GamestateProgress(struct Game *game) { diff --git a/src/libsuperderpy.c b/src/libsuperderpy.c index 745f0f1..9a8a1dc 100644 --- a/src/libsuperderpy.c +++ b/src/libsuperderpy.c @@ -65,6 +65,7 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char* game->_priv.font_bsod = NULL; game->_priv.console = NULL; + game->_priv.console_tmp = NULL; game->_priv.garbage = NULL; diff --git a/src/libsuperderpy.h b/src/libsuperderpy.h index 2de6e93..491ab92 100644 --- a/src/libsuperderpy.h +++ b/src/libsuperderpy.h @@ -79,6 +79,7 @@ struct Game { ALLEGRO_FONT *font_console; /*!< Font used in game console. */ ALLEGRO_FONT *font_bsod; /*!< Font used in Blue Screens of Derp. */ ALLEGRO_BITMAP *console; /*!< Bitmap with game console. */ + ALLEGRO_BITMAP *console_tmp; /*!< Bitmap used for drawing game console. */ ALLEGRO_EVENT_QUEUE *event_queue; /*!< Main event queue. */ ALLEGRO_TIMER *timer; /*!< Main LPS (logic) timer. */ bool showconsole; /*!< If true, game console is rendered on screen. */ diff --git a/src/utils.c b/src/utils.c index 295cd4c..88829d3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -266,16 +266,14 @@ SYMBOL_EXPORT void PrintConsole(struct Game *game, char* format, ...) { if (game->config.debug) { printf("%s\n", text); fflush(stdout); } if (!game->_priv.console) return; if ((!game->config.debug) && (!game->_priv.showconsole)) return; - ALLEGRO_BITMAP *con = al_create_bitmap(al_get_bitmap_width(game->_priv.console), al_get_bitmap_height(game->_priv.console)); - al_set_target_bitmap(con); + al_set_target_bitmap(game->_priv.console_tmp); al_clear_to_color(al_map_rgba(0,0,0,80)); al_draw_bitmap_region(game->_priv.console, 0, (int)(al_get_bitmap_height(game->_priv.console)*0.2), al_get_bitmap_width(game->_priv.console), (int)(al_get_bitmap_height(game->_priv.console)*0.8), 0, 0, 0); al_draw_text(game->_priv.font_console, al_map_rgb(255,255,255), (int)(game->viewport.width*0.005), (int)(al_get_bitmap_height(game->_priv.console)*0.81), ALLEGRO_ALIGN_LEFT, text); al_set_target_bitmap(game->_priv.console); al_clear_to_color(al_map_rgba(0,0,0,0)); - al_draw_bitmap(con, 0, 0, 0); + al_draw_bitmap(game->_priv.console_tmp, 0, 0, 0); al_set_target_bitmap(al_get_backbuffer(game->display)); - al_destroy_bitmap(con); } SYMBOL_EXPORT void SetupViewport(struct Game *game) {