From 3e3457bd8106ce9853c9c86a0a6be4c73bf2abcc Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Sun, 3 May 2020 20:57:34 -0400 Subject: [PATCH] Eliminate some use of CAP_FOO and ISFOO outside of the preprocessor. The old code worked, but it's strange to use these macros as if they were C++ `bool` variables at runtime. --- config.cpp | 74 +++++++++++++++++++++++--------------------------- rug.cpp | 4 ++- savemem.cpp | 3 +- screenshot.cpp | 12 ++++++-- 4 files changed, 48 insertions(+), 45 deletions(-) diff --git a/config.cpp b/config.cpp index 820d462c..2d3b9a72 100644 --- a/config.cpp +++ b/config.cpp @@ -1269,36 +1269,34 @@ EX void configureOther() { // dialog::addBoolItem_action(XLAT("forget faraway cells"), memory_saving_mode, 'y'); - #if CAP_AUDIO - if(CAP_AUDIO) { - dialog::addSelItem(XLAT("background music volume"), its(musicvolume), 'b'); - dialog::add_action([] { - dialog::editNumber(musicvolume, 0, 128, 10, 60, XLAT("background music volume"), ""); - dialog::reaction = [] () { - #if CAP_SDLAUDIO - Mix_VolumeMusic(musicvolume); - #endif - #if ISANDROID - settingsChanged = true; - #endif - }; - dialog::bound_low(0); - dialog::bound_up(MIX_MAX_VOLUME); - }); +#if CAP_AUDIO + dialog::addSelItem(XLAT("background music volume"), its(musicvolume), 'b'); + dialog::add_action([] { + dialog::editNumber(musicvolume, 0, 128, 10, 60, XLAT("background music volume"), ""); + dialog::reaction = [] () { +#if CAP_SDLAUDIO + Mix_VolumeMusic(musicvolume); +#endif +#if ISANDROID + settingsChanged = true; +#endif + }; + dialog::bound_low(0); + dialog::bound_up(MIX_MAX_VOLUME); + }); - dialog::addSelItem(XLAT("sound effects volume"), its(effvolume), 'e'); - dialog::add_action([] { - dialog::editNumber(effvolume, 0, 128, 10, 60, XLAT("sound effects volume"), ""); - dialog::reaction = [] () { - #if ISANDROID - settingsChanged = true; - #endif - }; - dialog::bound_low(0); - dialog::bound_up(MIX_MAX_VOLUME); - }); - } - #endif + dialog::addSelItem(XLAT("sound effects volume"), its(effvolume), 'e'); + dialog::add_action([] { + dialog::editNumber(effvolume, 0, 128, 10, 60, XLAT("sound effects volume"), ""); + dialog::reaction = [] () { +#if ISANDROID + settingsChanged = true; +#endif + }; + dialog::bound_low(0); + dialog::bound_up(MIX_MAX_VOLUME); + }); +#endif menuitem_sightrange('r'); @@ -1317,12 +1315,10 @@ EX void configureInterface() { gamescreen(3); dialog::init(XLAT("interface")); - #if CAP_TRANS - if(CAP_TRANS) { - dialog::addSelItem(XLAT("language"), XLAT("EN"), 'l'); - dialog::add_action_push(selectLanguageScreen); - } - #endif +#if CAP_TRANS + dialog::addSelItem(XLAT("language"), XLAT("EN"), 'l'); + dialog::add_action_push(selectLanguageScreen); +#endif dialog::addSelItem(XLAT("player character"), numplayers() > 1 ? "" : csname(vid.cs), 'g'); dialog::add_action_push(showCustomizeChar); @@ -2312,11 +2308,9 @@ EX void showSettings() { dialog::addItem(XLAT("colors & aura"), 'c'); dialog::add_action_push(show_color_dialog); -#if CAP_SHMUP - if(CAP_SHMUP && !ISMOBILE) { - dialog::addSelItem(XLAT("keyboard & joysticks"), "", 'k'); - dialog::add_action(multi::configure); - } +#if CAP_SHMUP && !ISMOBILE + dialog::addSelItem(XLAT("keyboard & joysticks"), "", 'k'); + dialog::add_action(multi::configure); #endif dialog::addSelItem(XLAT("mouse & touchscreen"), "", 'm'); diff --git a/rug.cpp b/rug.cpp index af3c1457..11b504e9 100644 --- a/rug.cpp +++ b/rug.cpp @@ -1624,8 +1624,10 @@ EX void show() { else if(uni == 'n' && !rug::rugged) pushScreen(rug_geometry_choice); #endif - else if(uni == 'g' && !rug::rugged && CAP_SDL) +#if CAP_SDL + else if(uni == 'g' && !rug::rugged) rendernogl = !rendernogl; +#endif else if(uni == 's') { texturesize *= 2; if(texturesize == 8192) texturesize = 64; diff --git a/savemem.cpp b/savemem.cpp index 29e9fe7e..7bf9e74c 100644 --- a/savemem.cpp +++ b/savemem.cpp @@ -285,7 +285,7 @@ EX void show_memory_menu() { } EX bool protect_memory() { - if(!CAP_MEMORY_RESERVE) return false; +#if CAP_MEMORY_RESERVE apply_memory_reserve(); if(reserve_limit && reserve_count < reserve_limit && !ignored_memory_warning) { pushScreen(show_memory_menu); @@ -295,6 +295,7 @@ EX bool protect_memory() { pushScreen(show_memory_menu); return true; } +#endif return false; } diff --git a/screenshot.cpp b/screenshot.cpp index a18a9f46..28055049 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -358,13 +358,14 @@ EX always_false in; /** 0 = no/unknown/disabled texture, 1 = rug, 2 = gradient, 3 = floor texture */ EX int texture_type(dqi_poly& p) { if(!p.tinf) return 0; - if(!CAP_PNG) return 0; +#if CAP_PNG if(!textures) return 0; if(p.tinf == &rug::tinf) return 1; #if MAXMDIM >= 4 if(p.tinf->texture_id == (int) floor_textures->renderedTexture) return (p.tinf->tvertices[0][0] == 0) ? 2 : 3; #endif +#endif return 0; } @@ -1730,8 +1731,13 @@ startanim perspective { "projection distance", no_init, [] { }}; startanim rug { "Hypersian Rug", [] { - if(!CAP_RUG) { pick(); return; } - rug::init(), rug::rugged = false; }, [] { +#if CAP_RUG + rug::init(); + rug::rugged = false; +#else + pick(); +#endif + }, [] { dynamicval b(rug::rugged, true); rug::physics(); dynamicval t(rug::rugView, cspin(1, 2, ticks / 3000.) * rug::rugView);