Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
This fixes my build and should also fix the Travis builds.
  • Loading branch information
CelticMinstrel committed Apr 4, 2016
1 parent 4f23676 commit 1bdce5b
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 31 deletions.
11 changes: 4 additions & 7 deletions src/game_launcher.cpp
Expand Up @@ -883,14 +883,11 @@ bool game_launcher::play_multiplayer()
start_wesnothd();
} catch(game::mp_server_error&)
{
std::string path = preferences::show_wesnothd_server_search(video());

if (!path.empty())
{
preferences::set_mp_server_program_name(path);
preferences::show_wesnothd_server_search(video());

try {
start_wesnothd();
}
else
} catch(game::mp_server_error&)
{
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/campaign_selection.cpp
Expand Up @@ -37,6 +37,7 @@
#include "serialization/string_utils.hpp"

#include "utils/functional.hpp"
#include "video.hpp"

namespace gui2
{
Expand Down
3 changes: 3 additions & 0 deletions src/gui/dialogs/editor/custom_tod.cpp
Expand Up @@ -320,9 +320,12 @@ void tcustom_tod::pre_show(twindow& window)
delete_button,
std::bind(&tcustom_tod::do_delete_tod, this, std::ref(window)));

// FIXME: This doesn't work (it does nothing at all)
/*
tbutton& save_button = find_widget<tbutton>(&window, "save", false);
connect_signal_mouse_left_click(
save_button, std::bind(&tcustom_tod::do_save_schedule, this));
*/

connect_signal_notify_modified(
*(lawful_bonus_field_->widget()),
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/game_cache_options.cpp
Expand Up @@ -32,6 +32,7 @@
#include "utils/functional.hpp"

#include "gettext.hpp"
#include "video.hpp"

namespace gui2
{
Expand Down
6 changes: 2 additions & 4 deletions src/gui/dialogs/game_load.cpp
Expand Up @@ -200,7 +200,7 @@ void tgame_load::list_item_clicked(twindow& window)
display_savegame(window);
}

bool tgame_load::filter_text_changed(ttext_* textbox, const std::string& text)
void tgame_load::filter_text_changed(ttext_* textbox, const std::string& text)
{
twindow& window = *textbox->get_window();

Expand All @@ -209,7 +209,7 @@ bool tgame_load::filter_text_changed(ttext_* textbox, const std::string& text)
const std::vector<std::string> words = utils::split(text, ' ');

if(words == last_words_)
return false;
return;
last_words_ = words;

std::vector<bool> show_items(list.get_item_count(), true);
Expand Down Expand Up @@ -243,8 +243,6 @@ bool tgame_load::filter_text_changed(ttext_* textbox, const std::string& text)
}

list.set_row_shown(show_items);

return false;
}

void tgame_load::post_show(twindow& window)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/game_load.hpp
Expand Up @@ -62,7 +62,7 @@ class tgame_load : public tdialog
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;

bool filter_text_changed(ttext_* textbox, const std::string& text);
void filter_text_changed(ttext_* textbox, const std::string& text);
void list_item_clicked(twindow& window);
void delete_button_callback(twindow& window);

Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogs/multiplayer/mp_connect.cpp
Expand Up @@ -28,6 +28,7 @@
#include "gui/widgets/settings.hpp"

#include "utils/functional.hpp"
#include "video.hpp"

namespace gui2
{
Expand Down
10 changes: 5 additions & 5 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -603,7 +603,7 @@ void tpreferences::initialize_members(twindow& window)
/* SELECT THEME */
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "choose_theme", false),
std::bind(&show_theme_dialog,
bind_void(&show_theme_dialog,
std::ref(window.video())));


Expand All @@ -614,22 +614,22 @@ void tpreferences::initialize_members(twindow& window)
/* SOUND FX */
setup_toggle_slider_pair("sound_toggle_sfx", "sound_volume_sfx",
sound_on(), sound_volume(),
set_sound, set_sound_volume, window);
bind_void(set_sound, _1), set_sound_volume, window);

/* MUSIC */
setup_toggle_slider_pair("sound_toggle_music", "sound_volume_music",
music_on(), music_volume(),
set_music, set_music_volume, window);
bind_void(set_music, _1), set_music_volume, window);

/* TURN BELL */
setup_toggle_slider_pair("sound_toggle_bell", "sound_volume_bell",
turn_bell(), bell_volume(),
set_turn_bell, set_bell_volume, window);
bind_void(set_turn_bell, _1), set_bell_volume, window);

/* UI FX */
setup_toggle_slider_pair("sound_toggle_uisfx", "sound_volume_uisfx",
UI_sound_on(), UI_volume(),
set_UI_sound, set_UI_volume, window);
bind_void(set_UI_sound, _1), set_UI_volume, window);


//
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dialogs/screenshot_notification.cpp
Expand Up @@ -96,12 +96,12 @@ void tscreenshot_notification::pre_show(twindow& window)

tbutton& open_b = find_widget<tbutton>(&window, "open", false);
connect_signal_mouse_left_click(
open_b, std::bind(&desktop::open_object, std::ref(path_)));
open_b, bind_void(&desktop::open_object, std::ref(path_)));

tbutton& bdir_b = find_widget<tbutton>(&window, "browse_dir", false);
connect_signal_mouse_left_click(
bdir_b,
std::bind(&desktop::open_object,
bind_void(&desktop::open_object,
std::ref(screenshots_dir_path_)));
}
}
6 changes: 2 additions & 4 deletions src/gui/dialogs/unit_create.cpp
Expand Up @@ -226,7 +226,7 @@ void tunit_create::list_item_clicked(twindow& window)
.set_displayed_type(units_[selected_row]);
}

bool tunit_create::filter_text_changed(ttext_* textbox, const std::string& text)
void tunit_create::filter_text_changed(ttext_* textbox, const std::string& text)
{
twindow& window = *textbox->get_window();

Expand All @@ -235,7 +235,7 @@ bool tunit_create::filter_text_changed(ttext_* textbox, const std::string& text)
const std::vector<std::string> words = utils::split(text, ' ');

if(words == last_words_)
return false;
return;
last_words_ = words;

std::vector<bool> show_items(list.get_item_count(), true);
Expand Down Expand Up @@ -269,8 +269,6 @@ bool tunit_create::filter_text_changed(ttext_* textbox, const std::string& text)
}

list.set_row_shown(show_items);

return false;
}

void tunit_create::gender_toggle_callback(twindow&)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/unit_create.hpp
Expand Up @@ -78,7 +78,7 @@ class tunit_create : public tdialog

/** Callbacks */
void list_item_clicked(twindow& window);
bool filter_text_changed(ttext_* textbox, const std::string& text);
void filter_text_changed(ttext_* textbox, const std::string& text);
void gender_toggle_callback(twindow& window);

tgroup<unit_race::GENDER> gender_toggle;
Expand Down
6 changes: 3 additions & 3 deletions src/hotkey/command_executor.cpp
Expand Up @@ -58,7 +58,7 @@ void make_screenshot(const std::string& name, CVideo& video, const TFunc& func)
const std::string ext = ".bmp";
#endif
filename = filesystem::get_next_filename(filename, ext);
const bool res = func(filename);
const bool res = func(filename, video);
if (res) {
gui2::tscreenshot_notification::display(filename, video);
} else {
Expand Down Expand Up @@ -553,7 +553,7 @@ void execute_command(const hotkey_command& command, command_executor* executor,
executor->get_video().set_fullscreen(!preferences::fullscreen());
break;
case HOTKEY_SCREENSHOT:
make_screenshot(_("Screenshot"), executor->get_video(), std::bind(&::screenshot, _1, std::ref(executor->get_video())));
make_screenshot(_("Screenshot"), executor->get_video(), &::screenshot);
break;
case HOTKEY_ANIMATE_MAP:
preferences::set_animate_map(!preferences::animate_map());
Expand Down Expand Up @@ -689,6 +689,6 @@ void command_executor_default::zoom_default()
}
void command_executor_default::map_screenshot()
{
make_screenshot(_("Map-Screenshot"), get_video(), std::bind(&display::screenshot, &get_display(), _1, true));
make_screenshot(_("Map-Screenshot"), get_video(), boost::bind(&display::screenshot, &get_display(), _1, true));
}
}
2 changes: 1 addition & 1 deletion src/preferences_display.cpp
Expand Up @@ -150,7 +150,7 @@ bool show_theme_dialog(CVideo& video)
return false;
}

std::string show_wesnothd_server_search(CVideo& video)
void show_wesnothd_server_search(CVideo& video)
{
// Showing file_chooser so user can search the wesnothd
std::string old_path = preferences::get_mp_server_program_name();
Expand Down
2 changes: 1 addition & 1 deletion src/preferences_display.hpp
Expand Up @@ -39,7 +39,7 @@ namespace preferences {
void set_idle_anim(bool ison);
void set_idle_anim_rate(int rate);

std::string show_wesnothd_server_search(CVideo&);
void show_wesnothd_server_search(CVideo&);
void show_preferences_dialog(CVideo& disp, const config& game_cfg,
const DIALOG_OPEN_TO initial_view = VIEW_DEFAULT);
bool show_theme_dialog(CVideo& disp);
Expand Down
2 changes: 1 addition & 1 deletion src/tod_manager.cpp
Expand Up @@ -91,7 +91,7 @@ void tod_manager::resolve_random(random_new::rng& r)
//comma-separated string of integers >= 1 referring to the times_ array indices
std::vector<int> output;
boost::copy( utils::split(random_tod_.str())
| boost::adaptors::transformed(std::bind(lexical_cast_default<int, std::string>, _1 , 0))
| boost::adaptors::transformed(boost::bind(lexical_cast_default<int, std::string>, _1 , 0))
| boost::adaptors::filtered(greater<int>(0))
, std::back_inserter(output) );

Expand Down
106 changes: 105 additions & 1 deletion src/utils/functional.hpp
Expand Up @@ -18,8 +18,112 @@
#ifndef INCL_FUNCTIONAL_HPP_
#define INCL_FUNCTIONAL_HPP_

#include "global.hpp"
#include <functional>
#include <boost/bind.hpp> // Because std::bind is just not flexible enough

using namespace std::placeholders;
// We'd like to just say "using namespace std::placeholders", but unfortunately
// that clashes with Boost.Bind's placeholders in some cases (even if bind.hpp is not included).
// Instead, we specialize std::is_placeholder for the Boost placeholders,
// so that Boost placeholders can be passed to std::bind.

template<int N>
struct std::is_placeholder<boost::arg<N>> : public std::integral_constant<int, N> {};

namespace detail {
template<typename Ret, typename... T>
struct apply {
using result_type = void;
apply(std::function<Ret(T...)> fcn) : fcn(fcn) {}
void operator()(T... params) {
fcn(std::forward<T>(params)...);
}
private:
std::function<Ret(T...)> fcn;
};

template<typename Ret, typename... T>
apply<Ret, T...> make_apply(std::function<Ret(T...)> fcn) {
return apply<Ret, T...>(fcn);
}

template<typename F>
struct function_base {
using type = typename function_base<decltype(&F::operator())>::type;
};

template<typename Ret, typename... P>
struct function_base<Ret(P...)> {
using type = Ret(P...);
};

template<typename Ret, typename... P>
struct function_base<Ret(*)(P...)> {
using type = Ret(P...);
};

template<typename Ret, typename Class, typename... P>
struct function_base<Ret(Class::*)(P...)> {
using type = Ret(Class,P...);
};

template<typename Ret, typename Class, typename... P>
struct function_base<Ret(Class::*)(P...)const> {
using type = Ret(const Class,P...);
};

template<typename Ret, typename Class, typename... P>
struct function_base<Ret(Class::*)(P...)volatile > {
using type = Ret(volatile Class,P...);
};

template<typename Ret, typename Class, typename... P>
struct function_base<Ret(Class::*)(P...)const volatile> {
using type = Ret(const volatile Class,P...);
};

template<typename Ret, typename... P>
struct function_base<std::function<Ret(P...)>> {
using type = Ret(P...);
};
}

template<typename F, typename... P>
auto bind_void(F fcn, P... bindings)
#ifndef HAVE_CXX14
-> decltype(boost::bind(
detail::make_apply(std::function<typename detail::function_base<F>::type>(fcn)), bindings...)
)
#endif
{
using T = typename detail::function_base<F>::type;
return boost::bind(detail::make_apply(std::function<T>(fcn)), bindings...);
}

template<typename F, typename... P>
auto bind_void_exact(F fcn, P... bindings)
#ifndef HAVE_CXX14
-> decltype(
boost::bind(detail::make_apply(std::function<typename detail::function_base<F>::type>(fcn)), bindings...)
)
#endif
{
using T = typename detail::function_base<F>::type;
return std::bind(detail::make_apply(std::function<T>(fcn)), bindings...);
}

/* A note on why std::bind is not flexible enough:
1. The functions produced do not silently consume extra parameters passed to them.
This is not a bad thing per se, but some of Wesnoth's code relied on it.
It's useful behaviour, as well.
2. A function that returns a value cannot be bound in a function type that returns void.
This is also relied upon in several places.
If behaviour #1 is needed, we need to use boost::bind. For behaviour #2, this won't work;
instead, the bind_void function is provided. (This also provides behaviour #1.
To get #2 without #1, use bind_void_exact.)
*/

#endif

0 comments on commit 1bdce5b

Please sign in to comment.