Removed scaling algorithm customization

We're going to be using NN scaling for the map, and that's already handled automatically
by SDL (and in the future, OGL). We don't need these settings for surface SCALED_TO_ZOOM
and SCALED_TO_HEX scaling. In any case, if we want to scale a surface to zoom or hex, it
will almost certainly be for map rendering (such scaling methods don't make sense in the
UI, for example), so just defaulting to NN is simplest.

This change drops the option to use Linear or xBRZ scaling for map zooming. This was already
the practical case due to me converting map rendering to use textures. NN was used for all
zoom levels, and it's fast and looks good.
This commit is contained in:
Charles Dang 2018-06-25 16:37:27 +11:00
parent ff4b308d2c
commit 15bf3bb256
13 changed files with 5 additions and 465 deletions

View file

@ -34,6 +34,8 @@
* Fix --userdata-dir deprecation warning being printed when starting wesnoth without arguments
when -DPREFERENCES_DIR="..." was defined at compile time.
* Make wmllint recognize `[load_resource]` (issue #4538).
* Removed map scaling algorithm customization. Nearest-neighbor scaling will now
always be used.
## Version 1.15.2
### AI:

View file

@ -139,12 +139,6 @@
default=yes
[/advanced_preference]
[advanced_preference]
field=advanced_graphic_options
name= _ "Graphics scaling options"
type=custom
[/advanced_preference]
[advanced_preference]
field=orb_color
name= _ "Customize orb colors"

View file

@ -1,195 +0,0 @@
#textdomain wesnoth-lib
#define _GUI_COLUMN_LABEL LABEL TOOLTIP
[row]
grow_factor=0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = {LABEL}
tooltip = {TOOLTIP}
[/label]
[/column]
[/row]
#enddef
#define _GUI_SCALE_OPTION ID LABEL TOOLTIP
[row]
grow_factor=0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[toggle_button]
id = "scale_"+{ID}
definition = "radio"
label = {LABEL}
tooltip = {TOOLTIP}
[/toggle_button]
[/column]
[/row]
#enddef
#define _GUI_SCALE_ALGO_OPTIONS CASE
{_GUI_SCALE_OPTION ({CASE}+"_nn") _"Nearest Neighbor" _"Nearest Neighbor scaling (fastest)"}
{_GUI_SCALE_OPTION ({CASE}+"_xbrzlin") _"xBRZ + linear" _"xBRZ followed by Bilinear interpolation"}
{_GUI_SCALE_OPTION ({CASE}+"_xbrznn") _"xBRZ + NN" _"xBRZ followed by Nearest Neighbor (recommended)"}
{_GUI_SCALE_OPTION ({CASE}+"_linear") _"Linear" _"Bilinear interpolation scaling"}
#enddef
#define _GUI_SCALE_CHOICE CASE LABEL TOOLTIP
[grid]
{_GUI_COLUMN_LABEL {LABEL} {TOOLTIP}}
{_GUI_SCALE_ALGO_OPTIONS {CASE}}
[/grid]
#enddef
[window]
id = "advanced_graphics_options"
description = "Advanced options to control what image processing algorithms are used."
[resolution]
definition = "default"
#click_dismiss = true
maximum_width = 800
automatic_placement = true
vertical_placement = "center"
horizontal_placement = "center"
[linked_group]
id = "algorithm"
fixed_width = true
[/linked_group]
[tooltip]
id = "tooltip"
[/tooltip]
[helptip]
id = "tooltip"
[/helptip]
[grid]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Advanced Graphics Options"
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Images will be scaled using the following algorithms:"
wrap = true
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
[grid]
[row]
grow_factor = 0
[column]
horizontal_grow = true
vertical_grow = true
border = "top"
border_size = 5
{_GUI_SCALE_CHOICE zoom _"Scaled to zoom" _"All units, haloes, border hexes"}
[/column]
[column]
horizontal_grow = true
vertical_grow = true
border = "top"
border_size = 5
{_GUI_SCALE_CHOICE hex _"Scaled to hex" _"Everything else"}
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
grow_factor = 0
[column]
horizontal_alignment = "right"
[grid]
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "ok"
definition = "default"
label = _ "OK"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "cancel"
definition = "default"
label = _ "Cancel"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View file

@ -1498,13 +1498,6 @@
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Gui\Dialogs\Addon\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\advanced_graphics_options.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\attack_predictions.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Gui\Dialogs\</ObjectFileName>
@ -3745,7 +3738,6 @@
<ClInclude Include="..\..\src\gui\dialogs\addon\install_dependencies.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\addon\manager.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\addon\uninstall_list.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\advanced_graphics_options.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\attack_predictions.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\campaign_difficulty.hpp" />
<ClInclude Include="..\..\src\gui\dialogs\campaign_selection.hpp" />

View file

@ -527,9 +527,6 @@
<ClCompile Include="..\..\src\gui\widgets\window.cpp">
<Filter>Gui\Widgets</Filter>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\advanced_graphics_options.cpp">
<Filter>Gui\Dialogs</Filter>
</ClCompile>
<ClCompile Include="..\..\src\gui\dialogs\attack_predictions.cpp">
<Filter>Gui\Dialogs</Filter>
</ClCompile>
@ -1951,9 +1948,6 @@
<ClInclude Include="..\..\src\gui\widgets\window_private.hpp">
<Filter>Gui\Widgets</Filter>
</ClInclude>
<ClInclude Include="..\..\src\gui\dialogs\advanced_graphics_options.hpp">
<Filter>Gui\Dialogs</Filter>
</ClInclude>
<ClInclude Include="..\..\src\gui\dialogs\attack_predictions.hpp">
<Filter>Gui\Dialogs</Filter>
</ClInclude>

View file

@ -166,7 +166,6 @@ gui/dialogs/addon/connect.cpp
gui/dialogs/addon/install_dependencies.cpp
gui/dialogs/addon/manager.cpp
gui/dialogs/addon/uninstall_list.cpp
gui/dialogs/advanced_graphics_options.cpp
gui/dialogs/attack_predictions.cpp
gui/dialogs/campaign_difficulty.cpp
gui/dialogs/campaign_selection.cpp

View file

@ -1,107 +0,0 @@
/*
Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/advanced_graphics_options.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/window.hpp"
#include "picture.hpp"
#include "utils/functional.hpp"
#include "gettext.hpp"
namespace gui2
{
namespace dialogs
{
REGISTER_DIALOG(advanced_graphics_options)
const std::vector<std::string> advanced_graphics_options::scale_cases {"zoom", "hex"};
advanced_graphics_options::advanced_graphics_options()
: groups_()
{
}
void advanced_graphics_options::pre_show(window& window)
{
for(const std::string& i : scale_cases) {
setup_scale_case(i, window);
}
}
advanced_graphics_options::SCALING_ALGORITHM advanced_graphics_options::get_scale_pref(const std::string& pref_id)
{
SCALING_ALGORITHM algo = preferences::default_scaling_algorithm;
try {
algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
} catch(const bad_enum_cast&) {
preferences::set(pref_id, algo.to_string());
}
// algo is now synced with preference, and default value set if something went wrong
return algo;
}
void advanced_graphics_options::setup_scale_case(const std::string& case_id, window& window)
{
const std::string pref_id = "scale_" + case_id;
group<SCALING_ALGORITHM>& group = groups_[case_id];
for(std::size_t x = 0; x < SCALING_ALGORITHM::count; ++x) {
SCALING_ALGORITHM scale = SCALING_ALGORITHM::from_int(x);
// The widget ids in advanced_graphics_options.cfg must match the enum string values for this to work.
toggle_button* button = find_widget<toggle_button>(&window, pref_id + "_" + scale.to_string(), false, true);
VALIDATE(button, _("No matching widget found for scaling option") + " " + scale.to_string());
group.add_member(button, scale);
}
group.set_member_states(get_scale_pref(pref_id));
}
void advanced_graphics_options::update_scale_case(const std::string& case_id)
{
const std::string pref_id = "scale_" + case_id;
SCALING_ALGORITHM new_val = groups_[case_id].get_active_member_value();
if(new_val != get_scale_pref(pref_id)) {
image::flush_cache();
}
preferences::set(pref_id, new_val.to_string());
}
void advanced_graphics_options::post_show(window& /*window*/)
{
if(get_retval() == retval::OK) {
for(const std::string& i : scale_cases) {
update_scale_case(i);
}
image::update_from_preferences();
}
}
} // namespace dialogs
} // namespace gui2

View file

@ -1,63 +0,0 @@
/*
Copyright (C) 2012 - 2018 by Chris Beck <render787@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "gui/dialogs/modal_dialog.hpp"
#include "gui/widgets/group.hpp"
#include "preferences/general.hpp"
namespace gui2
{
namespace dialogs
{
class advanced_graphics_options : public modal_dialog
{
public:
/** Constructor. */
advanced_graphics_options();
/**
* The display function.
*
* See @ref modal_dialog for more information.
*/
DEFINE_SIMPLE_DISPLAY_WRAPPER(advanced_graphics_options)
// These names must match the infixes of the widget ids in advanced_graphics_options.cfg
static const std::vector<std::string> scale_cases;
private:
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;
/** Inherited from modal_dialog. */
virtual void pre_show(window& window) override;
/** Inherited from modal_dialog. */
virtual void post_show(window& window) override;
void setup_scale_case(const std::string&, window&);
void update_scale_case(const std::string&);
using SCALING_ALGORITHM = preferences::SCALING_ALGORITHM;
SCALING_ALGORITHM get_scale_pref(const std::string& pref_id);
std::map<std::string, group<SCALING_ALGORITHM>> groups_;
};
} // namespace dialogs
} // end namespace gui2

View file

@ -32,7 +32,6 @@
#include "video.hpp"
// Sub-dialog includes
#include "gui/dialogs/advanced_graphics_options.hpp"
#include "gui/dialogs/game_cache_options.hpp"
#include "gui/dialogs/hotkey_bind.hpp"
#include "gui/dialogs/log_settings.hpp"
@ -990,9 +989,7 @@ void preferences_dialog::on_advanced_prefs_list_select(listbox& list)
const std::string& selected_field = adv_preferences_cfg_[selected_row]["field"].str();
if(selected_type == ADVANCED_PREF_TYPE::SPECIAL) {
if(selected_field == "advanced_graphic_options") {
gui2::dialogs::advanced_graphics_options::display();
} else if(selected_field == "logging") {
if(selected_field == "logging") {
gui2::dialogs::log_settings::display();
} else if(selected_field == "orb_color") {
gui2::dialogs::select_orb_colors::display();

View file

@ -186,12 +186,6 @@ std::vector<std::string> team_colors;
unsigned int zoom = tile_size;
unsigned int cached_zoom = 0;
/** Algorithm choices */
// typedef std::function<surface(const surface &, int, int)> scaling_function;
typedef surface (*scaling_function)(const surface&, int, int);
scaling_function scale_to_zoom_func;
scaling_function scale_to_hex_func;
const std::string data_uri_prefix = "data:";
struct parsed_data_URI{
explicit parsed_data_URI(utils::string_view data_URI);
@ -745,42 +739,6 @@ void set_zoom(unsigned int amount)
}
}
// F should be a scaling algorithm without "integral" zoom limitations
template<scaling_function F>
static surface scale_xbrz_helper(const surface& res, int w, int h)
{
int best_integer_zoom = std::min(w / res->w, h / res->h);
int legal_zoom = utils::clamp(best_integer_zoom, 1, 5);
return F(scale_surface_xbrz(res, legal_zoom), w, h);
}
using SCALING_ALGORITHM = preferences::SCALING_ALGORITHM;
static scaling_function select_algorithm(SCALING_ALGORITHM algo)
{
switch(algo.v) {
case SCALING_ALGORITHM::LINEAR: {
scaling_function result = &scale_surface;
return result;
}
case SCALING_ALGORITHM::NEAREST_NEIGHBOR: {
scaling_function result = &scale_surface_nn;
return result;
}
case SCALING_ALGORITHM::XBRZ_LIN: {
scaling_function result = &scale_xbrz_helper<scale_surface>;
return result;
}
case SCALING_ALGORITHM::XBRZ_NN: {
scaling_function result = &scale_xbrz_helper<scale_surface_nn>;
return result;
}
default:
assert(false && "I don't know how to implement this scaling algorithm");
throw 42;
}
}
static surface get_hexed(const locator& i_locator)
{
surface image(get_image(i_locator, UNSCALED));
@ -797,7 +755,7 @@ static surface get_scaled_to_hex(const locator& i_locator)
// return scale_surface(img, zoom, zoom);
if(img) {
return scale_to_hex_func(img, zoom, zoom);
return scale_surface_nn(img, zoom, zoom);
}
return surface(nullptr);
@ -818,7 +776,7 @@ static surface get_scaled_to_zoom(const locator& i_locator)
surface res(get_image(i_locator, UNSCALED));
// For some reason haloes seems to have invalid images, protect against crashing
if(res) {
return scale_to_zoom_func(res, ((res->w * zoom) / tile_size), ((res->h * zoom) / tile_size));
return scale_surface_nn(res, ((res->w * zoom) / tile_size), ((res->h * zoom) / tile_size));
}
return surface(nullptr);
@ -1178,25 +1136,4 @@ save_result save_image(const surface& surf, const std::string& filename)
return save_result::unsupported_format;
}
bool update_from_preferences()
{
SCALING_ALGORITHM algo = preferences::default_scaling_algorithm;
try {
algo = SCALING_ALGORITHM::string_to_enum(preferences::get("scale_hex"));
} catch(const bad_enum_cast&) {
}
scale_to_hex_func = select_algorithm(algo);
algo = preferences::default_scaling_algorithm;
try {
algo = SCALING_ALGORITHM::string_to_enum(preferences::get("scale_zoom"));
} catch(const bad_enum_cast&) {
}
scale_to_zoom_func = select_algorithm(algo);
return true;
}
} // end namespace image

View file

@ -214,9 +214,6 @@ namespace image {
void precache_file_existence(const std::string& subdir = "");
bool precached_file_exists(const std::string& file);
/// initialize any private data, e.g. algorithm choices from preferences
bool update_from_preferences();
enum class save_result {success, unsupported_format, save_failed, no_image};
save_result save_image(const locator& i_locator, const std::string& outfile);

View file

@ -34,7 +34,6 @@
#include "gui/dialogs/addon/connect.hpp"
#include "gui/dialogs/addon/install_dependencies.hpp"
#include "gui/dialogs/addon/manager.hpp"
#include "gui/dialogs/advanced_graphics_options.hpp"
#include "gui/dialogs/attack_predictions.hpp"
#include "gui/dialogs/campaign_difficulty.hpp"
#include "gui/dialogs/campaign_selection.hpp"
@ -422,7 +421,6 @@ BOOST_AUTO_TEST_CASE(test_gui2)
/* The modal_dialog classes. */
test<addon_connect>();
//test<addon_manager>();
test<advanced_graphics_options>();
//test<attack_predictions>();
test<campaign_difficulty>();
test<campaign_selection>();

View file

@ -741,11 +741,6 @@ static int do_gameloop(const std::vector<std::string>& args)
return 1;
}
res = image::update_from_preferences();
if(res == false) {
std::cerr << "could not initialize image preferences\n";
return 1;
}
check_fpu();
const cursor::manager cursor_manager;