From 3081e69536a44cfa052cd48b8f002a447b049f9b Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 29 Oct 2016 23:16:15 +0000 Subject: [PATCH] Pass grs_main_bitmap to gr_init_bitmap_alloc --- common/2d/bitmap.cpp | 2 +- common/include/fwd-gr.h | 2 +- common/include/gr.h | 12 ++++++++++++ common/include/pcx.h | 2 +- similar/2d/pcx.cpp | 6 +++--- similar/main/automap.cpp | 5 +---- similar/main/credits.cpp | 3 +-- similar/main/gameseq.cpp | 3 +-- similar/main/kmatrix.cpp | 3 +-- similar/main/titles.cpp | 8 ++------ 10 files changed, 24 insertions(+), 22 deletions(-) diff --git a/common/2d/bitmap.cpp b/common/2d/bitmap.cpp index f648f8eff..2f00fde23 100644 --- a/common/2d/bitmap.cpp +++ b/common/2d/bitmap.cpp @@ -83,7 +83,7 @@ void gr_init_bitmap(grs_bitmap &bm, const bm_mode mode, const uint16_t x, const gr_set_bitmap_data(bm, data); } -void gr_init_bitmap_alloc(grs_bitmap &bm, const bm_mode mode, const uint16_t x, const uint16_t y, const uint16_t w, const uint16_t h, const uint16_t bytesperline) +void gr_init_bitmap_alloc(grs_main_bitmap &bm, const bm_mode mode, const uint16_t x, const uint16_t y, const uint16_t w, const uint16_t h, const uint16_t bytesperline) { unsigned char *d; MALLOC(d, unsigned char, MAX_BMP_SIZE(w, h)); diff --git a/common/include/fwd-gr.h b/common/include/fwd-gr.h index 978b20b76..9beabd00c 100644 --- a/common/include/fwd-gr.h +++ b/common/include/fwd-gr.h @@ -146,7 +146,7 @@ void gr_clear_canvas(color_t color); void gr_init_bitmap(grs_bitmap &bm, bm_mode mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline, const uint8_t* data); void gr_init_sub_bitmap (grs_bitmap &bm, grs_bitmap &bmParent, uint16_t x, uint16_t y, uint16_t w, uint16_t h); -void gr_init_bitmap_alloc(grs_bitmap &bm, bm_mode mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline); +void gr_init_bitmap_alloc(grs_main_bitmap &bm, bm_mode mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline); void gr_free_bitmap_data(grs_bitmap &bm); // Allocate a bitmap and its pixel data buffer. diff --git a/common/include/gr.h b/common/include/gr.h index dfe7d2bba..dbaddc2bc 100644 --- a/common/include/gr.h +++ b/common/include/gr.h @@ -34,6 +34,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "fmtcheck.h" #include "pack.h" #include "compiler-array.h" +#include "compiler-exchange.h" struct grs_point { @@ -199,6 +200,17 @@ public: grs_main_bitmap() = default; grs_main_bitmap(const grs_main_bitmap &) = delete; grs_main_bitmap &operator=(const grs_main_bitmap &) = delete; + grs_main_bitmap(grs_main_bitmap &&r) : + grs_bitmap(std::move(static_cast(r))) + { + r.bm_data = nullptr; + } + grs_main_bitmap &operator=(grs_main_bitmap &&r) + { + grs_bitmap::operator=(std::move(static_cast(r))); + bm_data = exchange(r.bm_data, nullptr); + return *this; + } ~grs_main_bitmap() { reset(); diff --git a/common/include/pcx.h b/common/include/pcx.h index 23158353e..17653626d 100644 --- a/common/include/pcx.h +++ b/common/include/pcx.h @@ -55,7 +55,7 @@ namespace dcx { // then bmp->bm_data is allocated and the w,h are filled. // If palette==NULL the palette isn't read in. Returns error code. -int pcx_read_bitmap(const char * filename, grs_bitmap &bmp, palette_array_t &palette); +int pcx_read_bitmap(const char * filename, grs_main_bitmap &bmp, palette_array_t &palette); // Writes the bitmap bmp to filename, using palette. Returns error code. diff --git a/similar/2d/pcx.cpp b/similar/2d/pcx.cpp index c98c8461f..6b5f5a3de 100644 --- a/similar/2d/pcx.cpp +++ b/similar/2d/pcx.cpp @@ -194,9 +194,9 @@ struct PCX_PHYSFS_file RAIIPHYSFS_File PCXfile; }; -static int pcx_read_bitmap_file(struct PCX_PHYSFS_file *const pcxphysfs, grs_bitmap &bmp, bm_mode bitmap_type, palette_array_t &palette); +static int pcx_read_bitmap_file(struct PCX_PHYSFS_file *const pcxphysfs, grs_main_bitmap &bmp, bm_mode bitmap_type, palette_array_t &palette); -int pcx_read_bitmap(const char *const filename, grs_bitmap &bmp, palette_array_t &palette) +int pcx_read_bitmap(const char *const filename, grs_main_bitmap &bmp, palette_array_t &palette) { int result; PCX_PHYSFS_file pcxphysfs{PHYSFSX_openReadBuffered(filename)}; @@ -211,7 +211,7 @@ static int PCX_PHYSFS_read(struct PCX_PHYSFS_file *pcxphysfs, ubyte *data, unsig return PHYSFS_read(pcxphysfs->PCXfile, data, size, sizeof(*data)); } -static int pcx_read_bitmap_file(struct PCX_PHYSFS_file *const pcxphysfs, grs_bitmap &bmp, const bm_mode bitmap_type, palette_array_t &palette) +static int pcx_read_bitmap_file(struct PCX_PHYSFS_file *const pcxphysfs, grs_main_bitmap &bmp, const bm_mode bitmap_type, palette_array_t &palette) { PCXHeader header; int i, row, col, count, xsize, ysize; diff --git a/similar/main/automap.cpp b/similar/main/automap.cpp index 44ba97c00..34df7b96e 100644 --- a/similar/main/automap.cpp +++ b/similar/main/automap.cpp @@ -141,7 +141,7 @@ struct automap : ignore_window_pointer_t // Screen canvas variables grs_canvas automap_view; - grs_bitmap automap_background; + grs_main_bitmap automap_background; // Rendering variables fix zoom; @@ -965,9 +965,6 @@ static window_event_result automap_handler(window *wind,const d_event &event, au ConsoleObject->mtype.phys_info.flags |= am->old_wiggle; // Restore wiggle event_toggle_focus(0); key_toggle_repeat(1); -#if DXX_USE_OGL - gr_free_bitmap_data(am->automap_background); -#endif std::default_delete()(am); window_set_visible(Game_wind, 1); Automap_active = 0; diff --git a/similar/main/credits.cpp b/similar/main/credits.cpp index 4d2f1c9e9..1b9846305 100644 --- a/similar/main/credits.cpp +++ b/similar/main/credits.cpp @@ -88,7 +88,7 @@ struct credits : ignore_window_pointer_t int extra_inc; int done; int row; - grs_bitmap backdrop; + grs_main_bitmap backdrop; }; } @@ -213,7 +213,6 @@ static window_event_result credits_handler(window *, const d_event &event, credi break; case EVENT_WINDOW_CLOSE: - gr_free_bitmap_data(cr->backdrop); songs_set_volume(GameCfg.MusicVolume); songs_play_song( SONG_TITLE, 1 ); std::default_delete()(cr); diff --git a/similar/main/gameseq.cpp b/similar/main/gameseq.cpp index bce9a0c32..e806177d9 100644 --- a/similar/main/gameseq.cpp +++ b/similar/main/gameseq.cpp @@ -1045,7 +1045,7 @@ static int draw_endlevel_background(newmenu *,const d_event &event, grs_bitmap * static void do_screen_message(const char *msg) __attribute_nonnull(); static void do_screen_message(const char *msg) { - grs_bitmap background; + grs_main_bitmap background; if (Game_mode & GM_MULTI) return; @@ -1058,7 +1058,6 @@ static void do_screen_message(const char *msg) nm_item_menu(TXT_OK), }}; newmenu_do( NULL, msg, nm_message_items, draw_endlevel_background, static_cast(&background)); - gr_free_bitmap_data(background); } #if defined(DXX_BUILD_DESCENT_II) diff --git a/similar/main/kmatrix.cpp b/similar/main/kmatrix.cpp index 951b94498..5eb5a26de 100644 --- a/similar/main/kmatrix.cpp +++ b/similar/main/kmatrix.cpp @@ -175,7 +175,7 @@ namespace { struct kmatrix_screen : ignore_window_pointer_t { - grs_bitmap background; + grs_main_bitmap background; int network; fix64 end_time; int playing; @@ -415,6 +415,5 @@ kmatrix_result kmatrix_view(int network) while (window_exists(wind)) event_process(); - gr_free_bitmap_data(km.background); return (km.aborted ? kmatrix_result::abort : kmatrix_result::proceed); } diff --git a/similar/main/titles.cpp b/similar/main/titles.cpp index 4c3fe9979..9e9127d41 100644 --- a/similar/main/titles.cpp +++ b/similar/main/titles.cpp @@ -102,7 +102,7 @@ namespace { struct title_screen : ignore_window_pointer_t { - grs_bitmap title_bm; + grs_main_bitmap title_bm; fix64 timer; int allow_keys; }; @@ -145,7 +145,6 @@ static window_event_result title_handler(window *, const d_event &event, title_s break; case EVENT_WINDOW_CLOSE: - gr_free_bitmap_data(ts->title_bm); break; default: @@ -183,7 +182,6 @@ static void show_title_screen(const char * filename, int allow_keys, int from_ho const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, title_handler, ts.get()); if (!wind) { - gr_free_bitmap_data(ts->title_bm); return; } @@ -469,7 +467,7 @@ struct briefing : ignore_window_pointer_t short level_num; short cur_screen; std::unique_ptr screen; - grs_bitmap background; + grs_main_bitmap background; char background_name[PATH_MAX]; #if defined(DXX_BUILD_DESCENT_II) int got_z; @@ -1339,8 +1337,6 @@ static void free_briefing_screen(briefing *br) #endif if (EMULATING_D1) br->screen.reset(); - if (br->background.bm_data != NULL) - gr_free_bitmap_data(br->background); } }