From 1c610e834fcf7be76bffb7a5d1c09306068b4deb Mon Sep 17 00:00:00 2001 From: "striker.sh" Date: Wed, 9 Dec 2020 22:08:53 +0100 Subject: [PATCH 1/7] replace boost::optional by std::optional --- CMakeLists.txt | 2 +- src/badguy/mriceblock.cpp | 2 +- src/badguy/snail.cpp | 4 +- src/control/controller.cpp | 4 +- src/control/controller.hpp | 4 +- src/control/joystick_config.cpp | 2 +- src/control/keyboard_config.cpp | 4 +- src/control/keyboard_manager.cpp | 2 +- src/control/keyboard_manager.hpp | 4 +- src/editor/editor.cpp | 4 +- src/editor/editor.hpp | 4 +- src/editor/object_option.cpp | 16 +++---- src/editor/object_option.hpp | 35 ++++++++-------- src/editor/object_settings.cpp | 42 +++++++++---------- src/editor/object_settings.hpp | 36 ++++++++-------- src/object/background.cpp | 2 +- src/object/bonus_block.cpp | 2 +- src/object/path_gameobject.cpp | 8 ++-- src/object/path_object.cpp | 4 +- src/object/textscroller.cpp | 4 +- src/sprite/sprite_data.cpp | 4 +- src/supertux/command_line_arguments.hpp | 56 ++++++++++++------------- src/supertux/game_manager.cpp | 2 +- src/supertux/game_manager.hpp | 4 +- src/supertux/gameconfig.cpp | 14 +++---- src/supertux/gameconfig.hpp | 4 +- src/supertux/levelset_screen.cpp | 2 +- src/supertux/levelset_screen.hpp | 6 +-- src/supertux/main.cpp | 12 +++--- src/supertux/menu/editor_menu.cpp | 2 +- src/supertux/savegame.cpp | 4 +- src/supertux/sector_parser.cpp | 4 +- src/supertux/tile_set_parser.cpp | 14 +++---- src/supertux/tile_set_parser.hpp | 4 +- src/trigger/sequence_trigger.cpp | 2 +- src/util/reader_mapping.cpp | 20 ++++----- src/util/reader_mapping.hpp | 18 ++++---- src/video/drawing_context.hpp | 2 +- src/video/gl/gl_texture.cpp | 2 +- src/video/gl/gl_texture.hpp | 4 +- src/video/null/null_painter.cpp | 2 +- src/video/null/null_painter.hpp | 4 +- src/video/sdl/sdl_painter.hpp | 4 +- src/video/sdl/sdl_screen_renderer.hpp | 2 +- src/video/sdl/sdl_texture_renderer.hpp | 2 +- src/video/surface.cpp | 8 ++-- src/video/surface.hpp | 6 +-- src/video/texture.hpp | 4 +- src/video/texture_manager.cpp | 6 +-- src/video/texture_manager.hpp | 6 +-- src/video/video_system.cpp | 6 +-- src/worldmap/worldmap_parser.cpp | 2 +- tests/object_option_test.cpp | 2 +- tests/reader_test.cpp | 4 +- 54 files changed, 212 insertions(+), 211 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cb83ed91f8..3ed3ace25ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ if(COMMAND cmake_policy) cmake_policy(SET CMP0023 NEW) endif(COMMAND cmake_policy) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index f677d62ec0c..f5cb47385af 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -181,7 +181,7 @@ MrIceBlock::collision_squished(GameObject& object) break; } } - BOOST_FALLTHROUGH; + [[fallthrough]]; case ICESTATE_NORMAL: { diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index b582cacaad6..0c8f308f141 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -216,7 +216,7 @@ Snail::collision_solid(const CollisionHit& hit) m_physic.set_velocity_x(-m_physic.get_velocity_x()); } } - BOOST_FALLTHROUGH; + [[fallthrough]]; case STATE_FLAT: case STATE_KICKED_DELAY: if (hit.top || hit.bottom) { @@ -298,7 +298,7 @@ Snail::collision_squished(GameObject& object) player->bounce(*this); break; } - BOOST_FALLTHROUGH; + [[fallthrough]]; case STATE_KICKED: squishcount++; if (squishcount >= MAX_SNAIL_SQUISHES) { diff --git a/src/control/controller.cpp b/src/control/controller.cpp index 7f1d7299cbe..bcedd41286e 100644 --- a/src/control/controller.cpp +++ b/src/control/controller.cpp @@ -55,7 +55,7 @@ std::string Control_to_string(Control control) return g_control_names[static_cast(control)]; } -boost::optional Control_from_string(const std::string& text) +std::optional Control_from_string(const std::string& text) { for(int i = 0; g_control_names[i] != nullptr; ++i) { if (text == g_control_names[i]) { @@ -63,7 +63,7 @@ boost::optional Control_from_string(const std::string& text) } } - return boost::none; + return std::nullopt; } Controller::Controller() diff --git a/src/control/controller.hpp b/src/control/controller.hpp index bb98c6e1d25..0b29833deb1 100644 --- a/src/control/controller.hpp +++ b/src/control/controller.hpp @@ -18,7 +18,7 @@ #define HEADER_SUPERTUX_CONTROL_CONTROLLER_HPP #include -#include +#include enum class Control { LEFT = 0, @@ -51,7 +51,7 @@ enum class Control { std::ostream& operator<<(std::ostream& os, Control control); std::string Control_to_string(Control control); -boost::optional Control_from_string(const std::string& text); +std::optional Control_from_string(const std::string& text); class Controller { diff --git a/src/control/joystick_config.cpp b/src/control/joystick_config.cpp index e2746ac2833..10a360a1180 100644 --- a/src/control/joystick_config.cpp +++ b/src/control/joystick_config.cpp @@ -173,7 +173,7 @@ JoystickConfig::read(const ReaderMapping& joystick_mapping) std::string control_text; map.get("control", control_text); - const boost::optional maybe_control = Control_from_string(control_text); + const std::optional maybe_control = Control_from_string(control_text); if (!maybe_control) { log_info << "Invalid control '" << control_text << "' in buttonmap" << std::endl; diff --git a/src/control/keyboard_config.cpp b/src/control/keyboard_config.cpp index 51eac5127db..a994ede156e 100644 --- a/src/control/keyboard_config.cpp +++ b/src/control/keyboard_config.cpp @@ -16,7 +16,7 @@ #include "control/keyboard_config.hpp" -#include +#include #include "util/log.hpp" #include "util/reader_mapping.hpp" @@ -92,7 +92,7 @@ KeyboardConfig::read(const ReaderMapping& keymap_mapping) std::string control_text; map.get("control", control_text); - const boost::optional maybe_control = Control_from_string(control_text); + const std::optional maybe_control = Control_from_string(control_text); if (maybe_control) { if (m_configurable_controls.count(*maybe_control)) { bind_key(static_cast(key), *maybe_control); diff --git a/src/control/keyboard_manager.cpp b/src/control/keyboard_manager.cpp index 16aac92422e..1194f0b5837 100644 --- a/src/control/keyboard_manager.cpp +++ b/src/control/keyboard_manager.cpp @@ -168,7 +168,7 @@ KeyboardManager::process_menu_key_event(const SDL_KeyboardEvent& event) } m_parent->reset(); MenuManager::instance().refresh(); - m_wait_for_key = boost::none; + m_wait_for_key = std::nullopt; return; } diff --git a/src/control/keyboard_manager.hpp b/src/control/keyboard_manager.hpp index 202e46e720a..064fba8c14f 100644 --- a/src/control/keyboard_manager.hpp +++ b/src/control/keyboard_manager.hpp @@ -18,7 +18,7 @@ #ifndef HEADER_SUPERTUX_CONTROL_KEYBOARD_MANAGER_HPP #define HEADER_SUPERTUX_CONTROL_KEYBOARD_MANAGER_HPP -#include +#include #include "control/controller.hpp" @@ -42,7 +42,7 @@ class KeyboardManager final private: InputManager* m_parent; KeyboardConfig& m_keyboard_config; - boost::optional m_wait_for_key; + std::optional m_wait_for_key; bool m_lock_text_input; private: diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp index 89cf04061c6..dfcd224ba87 100644 --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -288,7 +288,7 @@ Editor::get_level_directory() const } void -Editor::test_level(const boost::optional>& test_pos) +Editor::test_level(const std::optional>& test_pos) { Tile::draw_editor_images = false; @@ -648,7 +648,7 @@ Editor::event(const SDL_Event& ev) if (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_t && ev.key.keysym.mod & KMOD_CTRL) { - test_level(boost::none); + test_level(std::nullopt); } if (ev.type == SDL_KEYDOWN && diff --git a/src/editor/editor.hpp b/src/editor/editor.hpp index 4e5277b8c5b..4a316787317 100644 --- a/src/editor/editor.hpp +++ b/src/editor/editor.hpp @@ -153,7 +153,7 @@ class Editor final : public Screen, void reload_level(); void quit_editor(); void save_level(); - void test_level(const boost::optional>& test_pos); + void test_level(const std::optional>& test_pos); void update_keyboard(const Controller& controller); protected: @@ -172,7 +172,7 @@ class Editor final : public Screen, bool m_save_request; bool m_test_request; bool m_particle_editor_request; - boost::optional> m_test_pos; + std::optional> m_test_pos; std::unique_ptr m_savegame; std::string* m_particle_editor_filename; diff --git a/src/editor/object_option.cpp b/src/editor/object_option.cpp index 047fb52a01b..fce05b9161f 100644 --- a/src/editor/object_option.cpp +++ b/src/editor/object_option.cpp @@ -51,7 +51,7 @@ ObjectOption::~ObjectOption() } BoolObjectOption::BoolObjectOption(const std::string& text, bool* pointer, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) : ObjectOption(text, key, flags), m_pointer(pointer), @@ -84,7 +84,7 @@ BoolObjectOption::to_string() const } IntObjectOption::IntObjectOption(const std::string& text, int* pointer, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) : ObjectOption(text, key, flags), m_pointer(pointer), @@ -150,7 +150,7 @@ RectfObjectOption::add_to_menu(Menu& menu) const } FloatObjectOption::FloatObjectOption(const std::string& text, float* pointer, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) : ObjectOption(text, key, flags), m_pointer(pointer), @@ -183,7 +183,7 @@ FloatObjectOption::add_to_menu(Menu& menu) const } StringObjectOption::StringObjectOption(const std::string& text, std::string* pointer, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) : ObjectOption(text, key, flags), m_pointer(pointer), @@ -217,7 +217,7 @@ StringObjectOption::add_to_menu(Menu& menu) const StringSelectObjectOption::StringSelectObjectOption(const std::string& text, int* pointer, const std::vector& select, - boost::optional default_value, + std::optional default_value, const std::string& key, unsigned int flags) : ObjectOption(text, key, flags), m_pointer(pointer), @@ -262,7 +262,7 @@ StringSelectObjectOption::add_to_menu(Menu& menu) const EnumObjectOption::EnumObjectOption(const std::string& text, int* pointer, const std::vector& labels, const std::vector& symbols, - boost::optional default_value, + std::optional default_value, const std::string& key, unsigned int flags) : ObjectOption(text, key, flags), m_pointer(pointer), @@ -341,7 +341,7 @@ ScriptObjectOption::add_to_menu(Menu& menu) const } FileObjectOption::FileObjectOption(const std::string& text, std::string* pointer, - boost::optional default_value, + std::optional default_value, const std::string& key, std::vector filter, const std::string& basedir, @@ -383,7 +383,7 @@ FileObjectOption::add_to_menu(Menu& menu) const } ColorObjectOption::ColorObjectOption(const std::string& text, Color* pointer, const std::string& key, - boost::optional default_value, bool use_alpha, + std::optional default_value, bool use_alpha, unsigned int flags) : ObjectOption(text, key, flags), m_pointer(pointer), diff --git a/src/editor/object_option.hpp b/src/editor/object_option.hpp index 233592d400c..fa213276709 100644 --- a/src/editor/object_option.hpp +++ b/src/editor/object_option.hpp @@ -17,7 +17,8 @@ #ifndef HEADER_SUPERTUX_EDITOR_OBJECT_OPTION_HPP #define HEADER_SUPERTUX_EDITOR_OBJECT_OPTION_HPP -#include +#include +#include #include #include @@ -73,7 +74,7 @@ class BoolObjectOption : public ObjectOption { public: BoolObjectOption(const std::string& text, bool* pointer, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags); virtual void save(Writer& write) const override; @@ -82,7 +83,7 @@ class BoolObjectOption : public ObjectOption private: bool* const m_pointer; - const boost::optional m_default_value; + const std::optional m_default_value; private: BoolObjectOption(const BoolObjectOption&) = delete; @@ -93,7 +94,7 @@ class IntObjectOption : public ObjectOption { public: IntObjectOption(const std::string& text, int* pointer, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags); virtual void save(Writer& write) const override; @@ -102,7 +103,7 @@ class IntObjectOption : public ObjectOption private: int* const m_pointer; - const boost::optional m_default_value; + const std::optional m_default_value; private: IntObjectOption(const IntObjectOption&) = delete; @@ -133,7 +134,7 @@ class FloatObjectOption : public ObjectOption { public: FloatObjectOption(const std::string& text, float* pointer, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags); virtual void save(Writer& write) const override; @@ -142,7 +143,7 @@ class FloatObjectOption : public ObjectOption private: float* const m_pointer; - const boost::optional m_default_value; + const std::optional m_default_value; private: FloatObjectOption(const FloatObjectOption&) = delete; @@ -153,7 +154,7 @@ class StringObjectOption : public ObjectOption { public: StringObjectOption(const std::string& text, std::string* pointer, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags); virtual void save(Writer& write) const override; @@ -162,7 +163,7 @@ class StringObjectOption : public ObjectOption private: std::string* const m_pointer; - boost::optional m_default_value; + std::optional m_default_value; private: StringObjectOption(const StringObjectOption&) = delete; @@ -173,7 +174,7 @@ class StringSelectObjectOption : public ObjectOption { public: StringSelectObjectOption(const std::string& text, int* pointer, const std::vector& select, - boost::optional default_value, + std::optional default_value, const std::string& key, unsigned int flags); virtual void save(Writer& write) const override; @@ -183,7 +184,7 @@ class StringSelectObjectOption : public ObjectOption private: int* const m_pointer; const std::vector m_select; - const boost::optional m_default_value; + const std::optional m_default_value; private: StringSelectObjectOption(const StringSelectObjectOption&) = delete; @@ -196,7 +197,7 @@ class EnumObjectOption : public ObjectOption EnumObjectOption(const std::string& text, int* pointer, const std::vector& labels, const std::vector& symbols, - boost::optional default_value, + std::optional default_value, const std::string& key, unsigned int flags); virtual void save(Writer& write) const override; @@ -207,7 +208,7 @@ class EnumObjectOption : public ObjectOption int* const m_pointer; const std::vector m_labels; const std::vector m_symbols; - const boost::optional m_default_value; + const std::optional m_default_value; private: EnumObjectOption(const EnumObjectOption&) = delete; @@ -236,7 +237,7 @@ class FileObjectOption : public ObjectOption { public: FileObjectOption(const std::string& text, std::string* pointer, - boost::optional default_value, + std::optional default_value, const std::string& key, std::vector filter, const std::string& basedir, @@ -248,7 +249,7 @@ class FileObjectOption : public ObjectOption private: std::string* const m_pointer; - boost::optional m_default_value; + std::optional m_default_value; const std::vector m_filter; std::string m_basedir; @@ -261,7 +262,7 @@ class ColorObjectOption : public ObjectOption { public: ColorObjectOption(const std::string& text, Color* pointer, const std::string& key, - boost::optional default_value, bool use_alpha, + std::optional default_value, bool use_alpha, unsigned int flags); virtual void save(Writer& write) const override; @@ -270,7 +271,7 @@ class ColorObjectOption : public ObjectOption private: Color* const m_pointer; - const boost::optional m_default_value; + const std::optional m_default_value; bool m_use_alpha; private: diff --git a/src/editor/object_settings.cpp b/src/editor/object_settings.cpp index 6ec3525fd1b..91e53178d7f 100644 --- a/src/editor/object_settings.cpp +++ b/src/editor/object_settings.cpp @@ -44,7 +44,7 @@ ObjectSettings::add_badguy(const std::string& text, std::vector* va void ObjectSettings::add_color(const std::string& text, Color* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_option(std::make_unique(text, value_ptr, key, default_value, true, flags)); @@ -53,7 +53,7 @@ ObjectSettings::add_color(const std::string& text, Color* value_ptr, void ObjectSettings::add_rgba(const std::string& text, Color* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_option(std::make_unique(text, value_ptr, key, default_value, true, flags)); @@ -62,7 +62,7 @@ ObjectSettings::add_rgba(const std::string& text, Color* value_ptr, void ObjectSettings::add_rgb(const std::string& text, Color* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_option(std::make_unique(text, value_ptr, key, default_value, false, flags)); @@ -71,7 +71,7 @@ ObjectSettings::add_rgb(const std::string& text, Color* value_ptr, void ObjectSettings::add_bool(const std::string& text, bool* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_option(std::make_unique(text, value_ptr, key, default_value, flags)); @@ -80,7 +80,7 @@ ObjectSettings::add_bool(const std::string& text, bool* value_ptr, void ObjectSettings::add_float(const std::string& text, float* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_option(std::make_unique(text, value_ptr, key, default_value, flags)); @@ -89,7 +89,7 @@ ObjectSettings::add_float(const std::string& text, float* value_ptr, void ObjectSettings::add_int(const std::string& text, int* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_option(std::make_unique(text, value_ptr, key, default_value, flags)); @@ -105,37 +105,37 @@ ObjectSettings::add_rectf(const std::string& text, Rectf* value_ptr, void ObjectSettings::add_direction(const std::string& text, Direction* value_ptr, - boost::optional default_value, + std::optional default_value, const std::string& key, unsigned int flags) { add_enum(text, reinterpret_cast(value_ptr), {_("auto"), _("left"), _("right"), _("up"), _("down")}, {"auto", "left", "right", "up", "down"}, - default_value ? static_cast(*default_value) : boost::optional(), + default_value ? static_cast(*default_value) : std::optional(), key, flags); } void ObjectSettings::add_worldmap_direction(const std::string& text, worldmap::Direction* value_ptr, - boost::optional default_value, + std::optional default_value, const std::string& key, unsigned int flags) { add_enum(text, reinterpret_cast(value_ptr), {_("None"), _("West"), _("East"), _("North"), _("South")}, {"none", "west", "east", "north", "south"}, - default_value ? static_cast(*default_value) : boost::optional(), + default_value ? static_cast(*default_value) : std::optional(), key, flags); } void ObjectSettings::add_walk_mode(const std::string& text, WalkMode* value_ptr, - boost::optional default_value, + std::optional default_value, const std::string& key, unsigned int flags) { add_option(std::make_unique( text, reinterpret_cast(value_ptr), std::vector{_("One shot"), _("Ping-pong"), _("Circular"), _("Unordered")}, - boost::none, key, flags)); + std::nullopt, key, flags)); } void @@ -154,7 +154,7 @@ ObjectSettings::add_script(const std::string& text, std::string* value_ptr, void ObjectSettings::add_text(const std::string& text, std::string* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_option(std::make_unique(text, value_ptr, key, default_value, flags)); @@ -163,7 +163,7 @@ ObjectSettings::add_text(const std::string& text, std::string* value_ptr, void ObjectSettings::add_translatable_text(const std::string& text, std::string* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_option(std::make_unique(text, value_ptr, key, default_value, @@ -172,7 +172,7 @@ ObjectSettings::add_translatable_text(const std::string& text, std::string* valu void ObjectSettings::add_string_select(const std::string& text, int* value_ptr, const std::vector& select, - boost::optional default_value, + std::optional default_value, const std::string& key, unsigned int flags) { add_option(std::make_unique(text, value_ptr, select, default_value, key, flags)); @@ -182,7 +182,7 @@ void ObjectSettings::add_enum(const std::string& text, int* value_ptr, const std::vector& labels, const std::vector& symbols, - boost::optional default_value, + std::optional default_value, const std::string& key, unsigned int flags) { add_option(std::make_unique(text, value_ptr, labels, symbols, default_value, key, flags)); @@ -191,7 +191,7 @@ ObjectSettings::add_enum(const std::string& text, int* value_ptr, void ObjectSettings::add_file(const std::string& text, std::string* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, const std::vector& filter, const std::string& basedir, unsigned int flags) @@ -239,7 +239,7 @@ ObjectSettings::add_level(const std::string& text, std::string* value_ptr, const void ObjectSettings::add_sprite(const std::string& text, std::string* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_file(text, value_ptr, key, std::move(default_value), {".jpg", ".png", ".sprite"}, {}, flags); @@ -248,7 +248,7 @@ ObjectSettings::add_sprite(const std::string& text, std::string* value_ptr, void ObjectSettings::add_surface(const std::string& text, std::string* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_file(text, value_ptr, key, std::move(default_value), {".jpg", ".png", ".surface"}, {}, flags); @@ -257,7 +257,7 @@ ObjectSettings::add_surface(const std::string& text, std::string* value_ptr, void ObjectSettings::add_sound(const std::string& text, std::string* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_file(text, value_ptr, key, std::move(default_value), {".wav", ".ogg"}, {}, flags); @@ -266,7 +266,7 @@ ObjectSettings::add_sound(const std::string& text, std::string* value_ptr, void ObjectSettings::add_music(const std::string& text, std::string* value_ptr, const std::string& key, - boost::optional default_value, + std::optional default_value, unsigned int flags) { add_file(text, value_ptr, key, std::move(default_value), {".music"}, {}, flags); diff --git a/src/editor/object_settings.hpp b/src/editor/object_settings.hpp index 418c1fa427b..da65cf7655b 100644 --- a/src/editor/object_settings.hpp +++ b/src/editor/object_settings.hpp @@ -44,77 +44,77 @@ class ObjectSettings final void add_bool(const std::string& text, bool* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_float(const std::string& text, float* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_int(const std::string& text, int* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_rectf(const std::string& text, Rectf* value_ptr, const std::string& key = {}, unsigned int flags = 0); void add_worldmap_direction(const std::string& text, worldmap::Direction* value_ptr, - boost::optional default_value = {}, + std::optional default_value = {}, const std::string& key = {}, unsigned int flags = 0); void add_direction(const std::string& text, Direction* value_ptr, - boost::optional default_value = {}, + std::optional default_value = {}, const std::string& key = {}, unsigned int flags = 0); void add_walk_mode(const std::string& text, WalkMode* value_ptr, - boost::optional default_value = {}, + std::optional default_value = {}, const std::string& key = {}, unsigned int flags = 0); void add_badguy(const std::string& text, std::vector* value_ptr, const std::string& key = {}, unsigned int flags = 0); void add_color(const std::string& text, Color* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_rgba(const std::string& text, Color* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_rgb(const std::string& text, Color* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_remove(); void add_script(const std::string& text, std::string* value_ptr, const std::string& key = {}, unsigned int flags = 0); void add_text(const std::string& text, std::string* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_translatable_text(const std::string& text, std::string* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_string_select(const std::string& text, int* value_ptr, const std::vector& select, - boost::optional default_value = {}, + std::optional default_value = {}, const std::string& key = {}, unsigned int flags = 0); void add_enum(const std::string& text, int* value_ptr, const std::vector& labels, const std::vector& symbols, - boost::optional default_value = {}, + std::optional default_value = {}, const std::string& key = {}, unsigned int flags = 0); void add_sprite(const std::string& text, std::string* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_surface(const std::string& text, std::string* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_sound(const std::string& text, std::string* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_music(const std::string& text, std::string* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, unsigned int flags = 0); void add_worldmap(const std::string& text, std::string* value_ptr, const std::string& key = {}, @@ -129,7 +129,7 @@ class ObjectSettings final unsigned int flags = 0); void add_file(const std::string& text, std::string* value_ptr, const std::string& key = {}, - boost::optional default_value = {}, + std::optional default_value = {}, const std::vector& filter = {}, const std::string& basedir = {}, unsigned int flags = 0); diff --git a/src/object/background.cpp b/src/object/background.cpp index 7dbe736bbe4..efaf285f5a9 100644 --- a/src/object/background.cpp +++ b/src/object/background.cpp @@ -170,7 +170,7 @@ Background::get_settings() result.add_float(_("Scroll offset y"), &m_scroll_offset.y, "scroll-offset-y", 0.0f); result.add_float(_("Scroll speed x"), &m_scroll_speed.x, "scroll-speed-x", 0.0f); result.add_float(_("Scroll speed y"), &m_scroll_speed.y, "scroll-speed-y", 0.0f); - result.add_float(_("Parallax Speed x"), &m_parallax_speed.x, "speed", boost::none); + result.add_float(_("Parallax Speed x"), &m_parallax_speed.x, "speed", std::nullopt); result.add_float(_("Parallax Speed y"), &m_parallax_speed.y, "speed-y", m_parallax_speed.x); result.add_surface(_("Top image"), &m_imagefile_top, "image-top", std::string()); result.add_surface(_("Image"), &m_imagefile, "image"); diff --git a/src/object/bonus_block.cpp b/src/object/bonus_block.cpp index e35b5bab124..b0cdfdc2cd0 100644 --- a/src/object/bonus_block.cpp +++ b/src/object/bonus_block.cpp @@ -110,7 +110,7 @@ BonusBlock::BonusBlock(const ReaderMapping& mapping) : if (Editor::is_active()) { mapping.get("custom-contents", m_custom_sx); } else { - boost::optional content_collection; + std::optional content_collection; if (!mapping.get("custom-contents", content_collection)) { log_warning << "bonusblock is missing 'custom-contents' tag" << std::endl; diff --git a/src/object/path_gameobject.cpp b/src/object/path_gameobject.cpp index 17af8157b10..9784d8f7a2c 100644 --- a/src/object/path_gameobject.cpp +++ b/src/object/path_gameobject.cpp @@ -16,7 +16,7 @@ #include "object/path_gameobject.hpp" -#include +#include #include "object/path.hpp" #include "sprite/sprite.hpp" @@ -75,7 +75,7 @@ PathGameObject::PathGameObject(const ReaderMapping& mapping, bool backward_compa } else { - boost::optional path_mapping; + std::optional path_mapping; if (mapping.get("path", path_mapping)) { m_path->read(*path_mapping); @@ -110,7 +110,7 @@ PathGameObject::draw(DrawingContext& context) { if (m_style == PathStyle::SOLID) { - boost::optional previous_node; + std::optional previous_node; for (const auto& node : m_path->get_nodes()) { if (previous_node) @@ -144,7 +144,7 @@ PathGameObject::draw(DrawingContext& context) const Color node_color = Color::BLUE; const Color edge_color = Color::MAGENTA; - boost::optional previous_node; + std::optional previous_node; for (const auto& node : m_path->get_nodes()) { if (previous_node) diff --git a/src/object/path_object.cpp b/src/object/path_object.cpp index 02d420ef400..acf335560b9 100644 --- a/src/object/path_object.cpp +++ b/src/object/path_object.cpp @@ -16,7 +16,7 @@ #include "object/path_object.hpp" -#include +#include #include "object/path_gameobject.hpp" #include "supertux/d_scope.hpp" @@ -42,7 +42,7 @@ PathObject::init_path(const ReaderMapping& mapping, bool running_default) mapping.get("running", running); std::string path_ref; - boost::optional path_mapping; + std::optional path_mapping; if (mapping.get("path", path_mapping)) { auto& path_gameobject = d_gameobject_manager->add(*path_mapping, true); diff --git a/src/object/textscroller.cpp b/src/object/textscroller.cpp index 7216f6ab83d..f8a9675a8fd 100644 --- a/src/object/textscroller.cpp +++ b/src/object/textscroller.cpp @@ -17,7 +17,7 @@ #include "object/textscroller.hpp" -#include +#include #include #include "control/input_manager.hpp" @@ -111,7 +111,7 @@ TextScroller::parse_root(const ReaderObject& root) } else if (version == 2) { - boost::optional content_collection; + std::optional content_collection; if (!mapping.get("content", content_collection)) { throw std::runtime_error("File doesn't contain content"); } else { diff --git a/src/sprite/sprite_data.cpp b/src/sprite/sprite_data.cpp index c0f597f10e7..8b1346b8a58 100644 --- a/src/sprite/sprite_data.cpp +++ b/src/sprite/sprite_data.cpp @@ -78,7 +78,7 @@ SpriteData::parse_action(const ReaderMapping& mapping) case 4: action->hitbox_h = hitbox[3]; action->hitbox_w = hitbox[2]; - BOOST_FALLTHROUGH; + [[fallthrough]]; case 2: action->y_offset = hitbox[1]; action->x_offset = hitbox[0]; @@ -161,7 +161,7 @@ SpriteData::parse_action(const ReaderMapping& mapping) } } } else { // Load images - boost::optional surfaces_collection; + std::optional surfaces_collection; std::vector images; if (mapping.get("images", images)) { diff --git a/src/supertux/command_line_arguments.hpp b/src/supertux/command_line_arguments.hpp index 1f91d0e7804..1e35124978f 100644 --- a/src/supertux/command_line_arguments.hpp +++ b/src/supertux/command_line_arguments.hpp @@ -17,7 +17,7 @@ #ifndef HEADER_SUPERTUX_SUPERTUX_COMMAND_LINE_ARGUMENTS_HPP #define HEADER_SUPERTUX_SUPERTUX_COMMAND_LINE_ARGUMENTS_HPP -#include +#include #include #include "math/size.hpp" @@ -44,44 +44,44 @@ class CommandLineArguments final LogLevel m_log_level; public: - boost::optional datadir; - boost::optional userdir; + std::optional datadir; + std::optional userdir; - boost::optional fullscreen_size; - boost::optional fullscreen_refresh_rate; - boost::optional window_size; - boost::optional aspect_size; + std::optional fullscreen_size; + std::optional fullscreen_refresh_rate; + std::optional window_size; + std::optional aspect_size; - // boost::optional magnification; + // std::optional magnification; - boost::optional use_fullscreen; - boost::optional video; - // boost::optional try_vsync; - boost::optional show_fps; - boost::optional show_player_pos; - boost::optional sound_enabled; - boost::optional music_enabled; + std::optional use_fullscreen; + std::optional video; + // std::optional try_vsync; + std::optional show_fps; + std::optional show_player_pos; + std::optional sound_enabled; + std::optional music_enabled; - // boost::optional random_seed; + // std::optional random_seed; std::vector filenames; - boost::optional enable_script_debugger; - boost::optional start_demo; - boost::optional record_demo; - boost::optional tux_spawn_pos; - boost::optional sector; - boost::optional spawnpoint; + std::optional enable_script_debugger; + std::optional start_demo; + std::optional record_demo; + std::optional tux_spawn_pos; + std::optional sector; + std::optional spawnpoint; - boost::optional developer_mode; + std::optional developer_mode; - boost::optional christmas_mode; + std::optional christmas_mode; - boost::optional repository_url; + std::optional repository_url; - boost::optional editor; - boost::optional resave; + std::optional editor; + std::optional resave; - // boost::optional locale; + // std::optional locale; public: CommandLineArguments(); diff --git a/src/supertux/game_manager.cpp b/src/supertux/game_manager.cpp index ffff287c0aa..a145ac76c55 100644 --- a/src/supertux/game_manager.cpp +++ b/src/supertux/game_manager.cpp @@ -40,7 +40,7 @@ GameManager::GameManager() : void GameManager::start_level(const World& world, const std::string& level_filename, - const boost::optional>& start_pos) + const std::optional>& start_pos) { m_savegame = Savegame::from_file(world.get_savegame_filename()); diff --git a/src/supertux/game_manager.hpp b/src/supertux/game_manager.hpp index 415a5c10b93..9be381f48b7 100644 --- a/src/supertux/game_manager.hpp +++ b/src/supertux/game_manager.hpp @@ -17,7 +17,7 @@ #ifndef HEADER_SUPERTUX_SUPERTUX_GAME_MANAGER_HPP #define HEADER_SUPERTUX_SUPERTUX_GAME_MANAGER_HPP -#include +#include #include #include #include "math/vector.hpp" @@ -33,7 +33,7 @@ class GameManager final : public Currenton void start_worldmap(const World& world, const std::string& spawnpoint = "", const std::string& worldmap_filename = ""); void start_level(const World& world, const std::string& level_filename, - const boost::optional>& start_pos = boost::none); + const std::optional>& start_pos = std::nullopt); bool load_next_worldmap(); void set_next_worldmap(const std::string& worldmap, const std::string &spawnpoint); diff --git a/src/supertux/gameconfig.cpp b/src/supertux/gameconfig.cpp index 2e173e4381d..cc545d7cd2e 100644 --- a/src/supertux/gameconfig.cpp +++ b/src/supertux/gameconfig.cpp @@ -85,7 +85,7 @@ Config::load() config_mapping.get("confirmation_dialog", confirmation_dialog); config_mapping.get("pause_on_focusloss", pause_on_focusloss); - boost::optional config_integrations_mapping; + std::optional config_integrations_mapping; if (config_mapping.get("integrations", config_integrations_mapping)) { config_integrations_mapping->get("hide_editor_levelnames", hide_editor_levelnames); @@ -109,7 +109,7 @@ Config::load() config_mapping.get("random_seed", random_seed); config_mapping.get("repository_url", repository_url); - boost::optional config_video_mapping; + std::optional config_video_mapping; if (config_mapping.get("video", config_video_mapping)) { config_video_mapping->get("fullscreen", use_fullscreen); @@ -139,7 +139,7 @@ Config::load() config_video_mapping->get("magnification", magnification); } - boost::optional config_audio_mapping; + std::optional config_audio_mapping; if (config_mapping.get("audio", config_audio_mapping)) { config_audio_mapping->get("sound_enabled", sound_enabled); @@ -148,23 +148,23 @@ Config::load() config_audio_mapping->get("music_volume", music_volume); } - boost::optional config_control_mapping; + std::optional config_control_mapping; if (config_mapping.get("control", config_control_mapping)) { - boost::optional keymap_mapping; + std::optional keymap_mapping; if (config_control_mapping->get("keymap", keymap_mapping)) { keyboard_config.read(*keymap_mapping); } - boost::optional joystick_mapping; + std::optional joystick_mapping; if (config_control_mapping->get("joystick", joystick_mapping)) { joystick_config.read(*joystick_mapping); } } - boost::optional config_addons_mapping; + std::optional config_addons_mapping; if (config_mapping.get("addons", config_addons_mapping)) { for (auto const& addon_node : config_addons_mapping->get_objects()) diff --git a/src/supertux/gameconfig.hpp b/src/supertux/gameconfig.hpp index 04e26292860..79d38f093fa 100644 --- a/src/supertux/gameconfig.hpp +++ b/src/supertux/gameconfig.hpp @@ -27,7 +27,7 @@ #include #include -#include +#include class Config final { @@ -75,7 +75,7 @@ class Config final std::string record_demo; /** this variable is set if tux should spawn somewhere which isn't the "main" spawn point*/ - boost::optional tux_spawn_pos; + std::optional tux_spawn_pos; /** force SuperTux language to this locale, e.g. "de". A file "data/locale/xx.po" must exist for this to work. An empty string diff --git a/src/supertux/levelset_screen.cpp b/src/supertux/levelset_screen.cpp index 10c69b92dee..34c0194c190 100644 --- a/src/supertux/levelset_screen.cpp +++ b/src/supertux/levelset_screen.cpp @@ -29,7 +29,7 @@ LevelsetScreen::LevelsetScreen(const std::string& basedir, const std::string& level_filename, Savegame& savegame, - const boost::optional>& start_pos) : + const std::optional>& start_pos) : m_basedir(basedir), m_level_filename(level_filename), m_savegame(savegame), diff --git a/src/supertux/levelset_screen.hpp b/src/supertux/levelset_screen.hpp index a90ad64a916..ea87eaccd4c 100644 --- a/src/supertux/levelset_screen.hpp +++ b/src/supertux/levelset_screen.hpp @@ -17,7 +17,7 @@ #ifndef HEADER_SUPERTUX_SUPERTUX_LEVELSET_SCREEN_HPP #define HEADER_SUPERTUX_SUPERTUX_LEVELSET_SCREEN_HPP -#include +#include #include #include "math/vector.hpp" @@ -38,7 +38,7 @@ class LevelsetScreen final : public Screen, public: LevelsetScreen(const std::string& basedir, const std::string& level_filename, Savegame& savegame, - const boost::optional>& start_pos); + const std::optional>& start_pos); virtual void draw(Compositor& compositor) override; virtual void update(float dt_sec, const Controller& controller) override; @@ -51,7 +51,7 @@ class LevelsetScreen final : public Screen, void finished_level(bool win); private: - boost::optional> m_start_pos; + std::optional> m_start_pos; LevelsetScreen(const LevelsetScreen&) = delete; LevelsetScreen& operator=(const LevelsetScreen&) = delete; diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index ad5e3fde69b..0e7b3e7e05f 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -154,13 +154,13 @@ Main::init_tinygettext() class PhysfsSubsystem final { private: - boost::optional m_forced_datadir; - boost::optional m_forced_userdir; + std::optional m_forced_datadir; + std::optional m_forced_userdir; public: PhysfsSubsystem(const char* argv0, - boost::optional forced_datadir, - boost::optional forced_userdir) : + std::optional forced_datadir, + std::optional forced_userdir) : m_forced_datadir(std::move(forced_datadir)), m_forced_userdir(std::move(forced_userdir)) { @@ -500,12 +500,12 @@ Main::launch_game(const CommandLineArguments& args) if (args.sector || args.spawnpoint) { - std::string sectorname = args.sector.get_value_or("main"); + std::string sectorname = args.sector.value_or("main"); const auto& spawnpoints = session->get_current_sector().get_objects_by_type(); std::string default_spawnpoint = (spawnpoints.begin() != spawnpoints.end()) ? "" : spawnpoints.begin()->get_name(); - std::string spawnpointname = args.spawnpoint.get_value_or(default_spawnpoint); + std::string spawnpointname = args.spawnpoint.value_or(default_spawnpoint); session->set_start_point(sectorname, spawnpointname); session->restart_level(); diff --git a/src/supertux/menu/editor_menu.cpp b/src/supertux/menu/editor_menu.cpp index c18e3d0f06c..754cf44e96d 100644 --- a/src/supertux/menu/editor_menu.cpp +++ b/src/supertux/menu/editor_menu.cpp @@ -115,7 +115,7 @@ EditorMenu::menu_action(MenuItem& item) { editor->check_save_prerequisites([editor]() { MenuManager::instance().clear_menu_stack(); - editor->m_test_pos = boost::none; + editor->m_test_pos = std::nullopt; editor->m_test_request = true; }); } diff --git a/src/supertux/savegame.cpp b/src/supertux/savegame.cpp index 8e80d456bd5..af07d9e175a 100644 --- a/src/supertux/savegame.cpp +++ b/src/supertux/savegame.cpp @@ -176,7 +176,7 @@ Savegame::load() } else { - boost::optional tux; + std::optional tux; if (!mapping.get("tux", tux)) { throw std::runtime_error("No tux section in savegame"); @@ -185,7 +185,7 @@ Savegame::load() m_player_status->read(*tux); } - boost::optional state; + std::optional state; if (!mapping.get("state", state)) { throw std::runtime_error("No state section in savegame"); diff --git a/src/supertux/sector_parser.cpp b/src/supertux/sector_parser.cpp index 8e42a11af5e..353fe774a13 100644 --- a/src/supertux/sector_parser.cpp +++ b/src/supertux/sector_parser.cpp @@ -264,7 +264,7 @@ SectorParser::parse_old_format(const ReaderMapping& reader) } // read reset-points (now spawn-points) - boost::optional resetpoints; + std::optional resetpoints; if (reader.get("reset-points", resetpoints)) { auto iter = resetpoints->get_iter(); while (iter.next()) { @@ -281,7 +281,7 @@ SectorParser::parse_old_format(const ReaderMapping& reader) } // read objects - boost::optional objects; + std::optional objects; if (reader.get("objects", objects)) { for (auto const& obj : objects->get_objects()) { diff --git a/src/supertux/tile_set_parser.cpp b/src/supertux/tile_set_parser.cpp index 84f2e3523b5..18581fedbc4 100644 --- a/src/supertux/tile_set_parser.cpp +++ b/src/supertux/tile_set_parser.cpp @@ -159,13 +159,13 @@ TileSetParser::parse_tile(const ReaderMapping& reader) } std::vector editor_surfaces; - boost::optional editor_images_mapping; + std::optional editor_images_mapping; if (reader.get("editor-images", editor_images_mapping)) { editor_surfaces = parse_imagespecs(*editor_images_mapping); } std::vector surfaces; - boost::optional images_mapping; + std::optional images_mapping; if (reader.get("images", images_mapping)) { surfaces = parse_imagespecs(*images_mapping); } @@ -255,13 +255,13 @@ TileSetParser::parse_tiles(const ReaderMapping& reader) if (shared_surface) { std::vector editor_surfaces; - boost::optional editor_surfaces_mapping; + std::optional editor_surfaces_mapping; if (reader.get("editor-images", editor_surfaces_mapping)) { editor_surfaces = parse_imagespecs(*editor_surfaces_mapping); } std::vector surfaces; - boost::optional surfaces_mapping; + std::optional surfaces_mapping; if (reader.get("image", surfaces_mapping) || reader.get("images", surfaces_mapping)) { surfaces = parse_imagespecs(*surfaces_mapping); @@ -308,14 +308,14 @@ TileSetParser::parse_tiles(const ReaderMapping& reader) int y = static_cast(32 * (i / width)); std::vector surfaces; - boost::optional surfaces_mapping; + std::optional surfaces_mapping; if (reader.get("image", surfaces_mapping) || reader.get("images", surfaces_mapping)) { surfaces = parse_imagespecs(*surfaces_mapping, Rect(x, y, Size(32, 32))); } std::vector editor_surfaces; - boost::optional editor_surfaces_mapping; + std::optional editor_surfaces_mapping; if (reader.get("editor-images", editor_surfaces_mapping)) { editor_surfaces = parse_imagespecs(*editor_surfaces_mapping, Rect(x, y, Size(32, 32))); } @@ -335,7 +335,7 @@ TileSetParser::parse_tiles(const ReaderMapping& reader) std::vector TileSetParser::parse_imagespecs(const ReaderMapping& images_mapping, - const boost::optional& surface_region) const + const std::optional& surface_region) const { std::vector surfaces; diff --git a/src/supertux/tile_set_parser.hpp b/src/supertux/tile_set_parser.hpp index d0b26d88baa..28123f9a9ef 100644 --- a/src/supertux/tile_set_parser.hpp +++ b/src/supertux/tile_set_parser.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include "math/rect.hpp" #include "supertux/tile.hpp" @@ -44,7 +44,7 @@ class TileSetParser final void parse_tile(const ReaderMapping& reader); void parse_tiles(const ReaderMapping& reader); std::vector parse_imagespecs(const ReaderMapping& cur, - const boost::optional& region = boost::none) const; + const std::optional& region = std::nullopt) const; private: TileSetParser(const TileSetParser&) = delete; diff --git a/src/trigger/sequence_trigger.cpp b/src/trigger/sequence_trigger.cpp index 1767c2cd3d9..59b7c91da96 100644 --- a/src/trigger/sequence_trigger.cpp +++ b/src/trigger/sequence_trigger.cpp @@ -75,7 +75,7 @@ SequenceTrigger::get_settings() result.add_enum(_("Sequence"), reinterpret_cast(&sequence), {_("end sequence"), _("stop Tux"), _("fireworks")}, {"endsequence", "stoptux", "fireworks"}, - boost::none, "sequence"); + std::nullopt, "sequence"); result.add_text(_("New worldmap spawnpoint"), &new_spawnpoint, "new_spawnpoint"); result.add_text(_("Worldmap fade tilemap"), &fade_tilemap, "fade_tilemap"); diff --git a/src/util/reader_mapping.cpp b/src/util/reader_mapping.cpp index 12b6cbeeb38..18bb25472b2 100644 --- a/src/util/reader_mapping.cpp +++ b/src/util/reader_mapping.cpp @@ -17,10 +17,10 @@ #include "util/reader_mapping.hpp" #include -#include #include #include #include +#include #include "util/gettext.hpp" #include "util/reader_collection.hpp" @@ -80,25 +80,25 @@ ReaderMapping::get_item(const char* key) const } bool -ReaderMapping::get(const char* key, bool& value, const boost::optional& default_value) const +ReaderMapping::get(const char* key, bool& value, const std::optional& default_value) const { GET_VALUE_MACRO("bool", is_boolean, as_bool); } bool -ReaderMapping::get(const char* key, int& value, const boost::optional& default_value) const +ReaderMapping::get(const char* key, int& value, const std::optional& default_value) const { GET_VALUE_MACRO("int", is_integer, as_int); } bool -ReaderMapping::get(const char* key, uint32_t& value, const boost::optional& default_value) const +ReaderMapping::get(const char* key, uint32_t& value, const std::optional& default_value) const { GET_VALUE_MACRO("uint32_t", is_integer, as_int); } bool -ReaderMapping::get(const char* key, float& value, const boost::optional& default_value) const +ReaderMapping::get(const char* key, float& value, const std::optional& default_value) const { GET_VALUE_MACRO("float", is_real, as_float); } @@ -106,7 +106,7 @@ ReaderMapping::get(const char* key, float& value, const boost::optional& #undef GET_VALUE_MACRO bool -ReaderMapping::get(const char* key, std::string& value, const boost::optional& default_value) const +ReaderMapping::get(const char* key, std::string& value, const std::optional& default_value) const { auto const sx = get_item(key); if (!sx) { @@ -193,11 +193,11 @@ ReaderMapping::get(const char* key, std::vector& value) const #undef GET_VALUES_MACRO bool -ReaderMapping::get(const char* key, boost::optional& value) const +ReaderMapping::get(const char* key, std::optional& value) const { auto const sx = get_item(key); if (sx) { - value = boost::in_place(boost::ref(m_doc), boost::ref(*sx)); + value.emplace(std::ref(m_doc), std::ref(*sx)); return true; } else { return false; @@ -205,11 +205,11 @@ ReaderMapping::get(const char* key, boost::optional& value) const } bool -ReaderMapping::get(const char* key, boost::optional& value) const +ReaderMapping::get(const char* key, std::optional& value) const { auto const sx = get_item(key); if (sx) { - value = boost::in_place(boost::ref(m_doc), boost::ref(*sx)); + value.emplace(std::ref(m_doc), std::ref(*sx)); return true; } else { return false; diff --git a/src/util/reader_mapping.hpp b/src/util/reader_mapping.hpp index d6ba13f4eee..77f857f18d6 100644 --- a/src/util/reader_mapping.hpp +++ b/src/util/reader_mapping.hpp @@ -17,7 +17,7 @@ #ifndef HEADER_SUPERTUX_UTIL_READER_MAPPING_HPP #define HEADER_SUPERTUX_UTIL_READER_MAPPING_HPP -#include +#include #include "util/reader_iterator.hpp" @@ -39,11 +39,11 @@ class ReaderMapping final ReaderIterator get_iter() const; - bool get(const char* key, bool& value, const boost::optional& default_value = boost::none) const; - bool get(const char* key, int& value, const boost::optional& default_value = boost::none) const; - bool get(const char* key, uint32_t& value, const boost::optional& default_value = boost::none) const; - bool get(const char* key, float& value, const boost::optional& default_value = boost::none) const; - bool get(const char* key, std::string& value, const boost::optional& default_value = boost::none) const; + bool get(const char* key, bool& value, const std::optional& default_value = std::nullopt) const; + bool get(const char* key, int& value, const std::optional& default_value = std::nullopt) const; + bool get(const char* key, uint32_t& value, const std::optional& default_value = std::nullopt) const; + bool get(const char* key, float& value, const std::optional& default_value = std::nullopt) const; + bool get(const char* key, std::string& value, const std::optional& default_value = std::nullopt) const; bool get(const char* key, std::vector& value) const; bool get(const char* key, std::vector& value) const; @@ -51,8 +51,8 @@ class ReaderMapping final bool get(const char* key, std::vector& value) const; bool get(const char* key, std::vector& value) const; - bool get(const char* key, boost::optional&) const; - bool get(const char* key, boost::optional&) const; + bool get(const char* key, std::optional&) const; + bool get(const char* key, std::optional&) const; bool get(const char* key, sexp::Value& value) const; @@ -62,7 +62,7 @@ class ReaderMapping final mapping.get_custom("style", value, Style_from_string, Style::DEFAULT); */ template - bool get_custom(const char* key, C& value, F from_string, boost::optional default_value = boost::none) const + bool get_custom(const char* key, C& value, F from_string, std::optional default_value = std::nullopt) const { std::string text; if (!get(key, text)) diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index b8d020fedfe..cd0c3755204 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include "math/rect.hpp" #include "math/rectf.hpp" diff --git a/src/video/gl/gl_texture.cpp b/src/video/gl/gl_texture.cpp index a533f5d0bdc..220a2ac5713 100644 --- a/src/video/gl/gl_texture.cpp +++ b/src/video/gl/gl_texture.cpp @@ -22,7 +22,7 @@ #include "video/sampler.hpp" #include "video/sdl_surface.hpp" -GLTexture::GLTexture(int width, int height, boost::optional fill_color) : +GLTexture::GLTexture(int width, int height, std::optional fill_color) : m_handle(), m_sampler(), m_texture_width(), diff --git a/src/video/gl/gl_texture.hpp b/src/video/gl/gl_texture.hpp index 0dcc012243a..7b874976bdd 100644 --- a/src/video/gl/gl_texture.hpp +++ b/src/video/gl/gl_texture.hpp @@ -17,7 +17,7 @@ #ifndef HEADER_SUPERTUX_VIDEO_GL_GL_TEXTURE_HPP #define HEADER_SUPERTUX_VIDEO_GL_GL_TEXTURE_HPP -#include +#include #include "video/color.hpp" #include "video/gl.hpp" @@ -32,7 +32,7 @@ class Sampler; class GLTexture final : public Texture { public: - GLTexture(int width, int height, boost::optional fill_color = boost::none); + GLTexture(int width, int height, std::optional fill_color = std::nullopt); GLTexture(const SDL_Surface& image, const Sampler& sampler); ~GLTexture(); diff --git a/src/video/null/null_painter.cpp b/src/video/null/null_painter.cpp index 33207c89594..608405925ef 100644 --- a/src/video/null/null_painter.cpp +++ b/src/video/null/null_painter.cpp @@ -87,7 +87,7 @@ void NullPainter::clear_clip_rect() { log_info << "NullPainter::clear_clip_rect()" << std::endl; - m_clip_rect = boost::none; + m_clip_rect = std::nullopt; } /* EOF */ diff --git a/src/video/null/null_painter.hpp b/src/video/null/null_painter.hpp index 32746d13257..7241a46b111 100644 --- a/src/video/null/null_painter.hpp +++ b/src/video/null/null_painter.hpp @@ -19,7 +19,7 @@ #include "video/painter.hpp" -#include +#include class NullPainter : public Painter { @@ -41,7 +41,7 @@ class NullPainter : public Painter virtual void clear_clip_rect() override; private: - boost::optional m_clip_rect; + std::optional m_clip_rect; private: NullPainter(const NullPainter&) = delete; diff --git a/src/video/sdl/sdl_painter.hpp b/src/video/sdl/sdl_painter.hpp index 0686c33502a..4aae452fa07 100644 --- a/src/video/sdl/sdl_painter.hpp +++ b/src/video/sdl/sdl_painter.hpp @@ -19,7 +19,7 @@ #include "video/painter.hpp" -#include +#include class Renderer; class SDLScreenRenderer; @@ -49,7 +49,7 @@ class SDLPainter final : public Painter SDLVideoSystem& m_video_system; Renderer& m_renderer; SDL_Renderer* m_sdl_renderer; - boost::optional m_cliprect; + std::optional m_cliprect; private: SDLPainter(const SDLPainter&) = delete; diff --git a/src/video/sdl/sdl_screen_renderer.hpp b/src/video/sdl/sdl_screen_renderer.hpp index e66bf102080..4fe38a3ccff 100644 --- a/src/video/sdl/sdl_screen_renderer.hpp +++ b/src/video/sdl/sdl_screen_renderer.hpp @@ -18,7 +18,7 @@ #define HEADER_SUPERTUX_VIDEO_SDL_SDL_SCREEN_RENDERER_HPP #include -#include +#include #include "math/size.hpp" #include "video/renderer.hpp" diff --git a/src/video/sdl/sdl_texture_renderer.hpp b/src/video/sdl/sdl_texture_renderer.hpp index 8ca5ad5ce8d..f73211d7565 100644 --- a/src/video/sdl/sdl_texture_renderer.hpp +++ b/src/video/sdl/sdl_texture_renderer.hpp @@ -18,7 +18,7 @@ #define HEADER_SUPERTUX_VIDEO_SDL_SDL_TEXTURE_RENDERER_HPP #include -#include +#include #include "video/texture_ptr.hpp" #include "video/renderer.hpp" diff --git a/src/video/surface.cpp b/src/video/surface.cpp index ec536599e21..2bdb520e835 100644 --- a/src/video/surface.cpp +++ b/src/video/surface.cpp @@ -26,17 +26,17 @@ #include "video/video_system.hpp" SurfacePtr -Surface::from_reader(const ReaderMapping& mapping, const boost::optional& rect, const std::string& filename) +Surface::from_reader(const ReaderMapping& mapping, const std::optional& rect, const std::string& filename) { TexturePtr diffuse_texture; - boost::optional diffuse_texture_mapping; + std::optional diffuse_texture_mapping; if (mapping.get("diffuse-texture", diffuse_texture_mapping)) { diffuse_texture = TextureManager::current()->get(*diffuse_texture_mapping, rect); } TexturePtr displacement_texture; - boost::optional displacement_texture_mapping; + std::optional displacement_texture_mapping; if (mapping.get("displacement-texture", displacement_texture_mapping)) { displacement_texture = TextureManager::current()->get(*displacement_texture_mapping, rect); @@ -55,7 +55,7 @@ Surface::from_reader(const ReaderMapping& mapping, const boost::optional& } SurfacePtr -Surface::from_file(const std::string& filename, const boost::optional& rect) +Surface::from_file(const std::string& filename, const std::optional& rect) { if (StringUtil::has_suffix(filename, ".surface")) { diff --git a/src/video/surface.hpp b/src/video/surface.hpp index 609514564df..0a584fef929 100644 --- a/src/video/surface.hpp +++ b/src/video/surface.hpp @@ -18,7 +18,7 @@ #define HEADER_SUPERTUX_VIDEO_SURFACE_HPP #include -#include +#include #include "math/rect.hpp" #include "math/vector.hpp" @@ -36,8 +36,8 @@ class Surface final { public: static SurfacePtr from_texture(const TexturePtr& texture); - static SurfacePtr from_file(const std::string& filename, const boost::optional& rect = boost::none); - static SurfacePtr from_reader(const ReaderMapping& mapping, const boost::optional& rect = boost::none, const std::string& filename = ""); + static SurfacePtr from_file(const std::string& filename, const std::optional& rect = std::nullopt); + static SurfacePtr from_reader(const ReaderMapping& mapping, const std::optional& rect = std::nullopt, const std::string& filename = ""); private: Surface(const TexturePtr& diffuse_texture, const TexturePtr& displacement_texture, Flip flip, const std::string& filename = ""); diff --git a/src/video/texture.hpp b/src/video/texture.hpp index 2dc5d7d14c7..16534a53995 100644 --- a/src/video/texture.hpp +++ b/src/video/texture.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "math/rect.hpp" #include "video/flip.hpp" @@ -48,7 +48,7 @@ class Texture virtual int get_image_height() const = 0; private: - boost::optional m_cache_key; + std::optional m_cache_key; private: Texture(const Texture&) = delete; diff --git a/src/video/texture_manager.cpp b/src/video/texture_manager.cpp index 764222d9ed4..d8b583dd158 100644 --- a/src/video/texture_manager.cpp +++ b/src/video/texture_manager.cpp @@ -95,7 +95,7 @@ TextureManager::~TextureManager() } TexturePtr -TextureManager::get(const ReaderMapping& mapping, const boost::optional& region) +TextureManager::get(const ReaderMapping& mapping, const std::optional& region) { std::string filename; if (!mapping.get("file", filename)) @@ -107,7 +107,7 @@ TextureManager::get(const ReaderMapping& mapping, const boost::optional& r filename = FileSystem::join(mapping.get_doc().get_directory(), filename); } - boost::optional rect; + std::optional rect; std::vector rect_v; if (mapping.get("rect", rect_v)) { @@ -202,7 +202,7 @@ TextureManager::get(const std::string& _filename) TexturePtr TextureManager::get(const std::string& _filename, - const boost::optional& rect, + const std::optional& rect, const Sampler& sampler) { std::string filename = FileSystem::normalize(_filename); diff --git a/src/video/texture_manager.hpp b/src/video/texture_manager.hpp index 9a4e9166520..55b50fa87d8 100644 --- a/src/video/texture_manager.hpp +++ b/src/video/texture_manager.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include "math/rect.hpp" #include "util/currenton.hpp" @@ -46,10 +46,10 @@ class TextureManager final : public Currenton TextureManager(); ~TextureManager(); - TexturePtr get(const ReaderMapping& mapping, const boost::optional& region = boost::none); + TexturePtr get(const ReaderMapping& mapping, const std::optional& region = std::nullopt); TexturePtr get(const std::string& filename); TexturePtr get(const std::string& filename, - const boost::optional& rect, + const std::optional& rect, const Sampler& sampler = Sampler()); void debug_print(std::ostream& out) const; diff --git a/src/video/video_system.cpp b/src/video/video_system.cpp index 56934a5662e..91e13e35259 100644 --- a/src/video/video_system.cpp +++ b/src/video/video_system.cpp @@ -17,7 +17,7 @@ #include "video/video_system.hpp" #include -#include +#include #include #include #include @@ -164,7 +164,7 @@ VideoSystem::do_take_screenshot() } } - auto find_filename = [&]() -> boost::optional + auto find_filename = [&]() -> std::optional { for (int num = 0; num < 1000000; ++num) { @@ -175,7 +175,7 @@ VideoSystem::do_take_screenshot() return screenshot_filename; } } - return boost::none; + return std::nullopt; }; auto filename = find_filename(); diff --git a/src/worldmap/worldmap_parser.cpp b/src/worldmap/worldmap_parser.cpp index 91ae0fbe39a..947f653fcec 100644 --- a/src/worldmap/worldmap_parser.cpp +++ b/src/worldmap/worldmap_parser.cpp @@ -81,7 +81,7 @@ WorldMapParser::load_worldmap(const std::string& filename) m_worldmap.m_tileset = TileManager::current()->get_tileset("images/worldmap.strf"); } - boost::optional sector; + std::optional sector; if (!level_.get("sector", sector)) { throw std::runtime_error("No sector specified in worldmap file."); } else { diff --git a/tests/object_option_test.cpp b/tests/object_option_test.cpp index eaa5506912f..ecbbd6e888e 100644 --- a/tests/object_option_test.cpp +++ b/tests/object_option_test.cpp @@ -27,7 +27,7 @@ TEST(ObjectOption, to_string) { { std::string mystring = "field"; - StringObjectOption textfield("test", &mystring, {}, boost::none, 0); + StringObjectOption textfield("test", &mystring, {}, std::nullopt, 0); ASSERT_EQ(mystring, textfield.to_string()); } diff --git a/tests/reader_test.cpp b/tests/reader_test.cpp index 5831e3dee55..8147d5511d8 100644 --- a/tests/reader_test.cpp +++ b/tests/reader_test.cpp @@ -100,7 +100,7 @@ TEST(ReaderTest, get) } { - boost::optional child_mapping; + std::optional child_mapping; mapping.get("mymapping", child_mapping); int a; @@ -159,7 +159,7 @@ TEST(ReaderTest, syntax_error) bool mybool; int myint; float myfloat; - boost::optional mymapping; + std::optional mymapping; ASSERT_THROW({mapping.get("mybool", mybool);}, std::runtime_error); ASSERT_THROW({mapping.get("myint", myint);}, std::runtime_error); ASSERT_THROW({mapping.get("myfloat", myfloat);}, std::runtime_error); From f56945ab800f8c5faa426e75c03b57c12c04f433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Br=C3=BBl=C3=A9?= Date: Thu, 10 Dec 2020 13:16:51 +0100 Subject: [PATCH 2/7] Fixed missing includes --- src/editor/particle_editor.hpp | 1 + src/gui/menu.cpp | 2 ++ src/interface/control.hpp | 1 + src/interface/control_textbox.hpp | 1 + 4 files changed, 5 insertions(+) diff --git a/src/editor/particle_editor.hpp b/src/editor/particle_editor.hpp index acf636801dd..4c7a82669bf 100644 --- a/src/editor/particle_editor.hpp +++ b/src/editor/particle_editor.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_EDITOR_PARTICLE_EDITOR_HPP #include +#include #include #include diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 33cba5876a1..1057d33e1ae 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -16,6 +16,8 @@ #include "gui/menu.hpp" +#include + #include "control/input_manager.hpp" #include "gui/item_action.hpp" #include "gui/item_back.hpp" diff --git a/src/interface/control.hpp b/src/interface/control.hpp index 6418b5d8e6d..73373d4d4dc 100644 --- a/src/interface/control.hpp +++ b/src/interface/control.hpp @@ -17,6 +17,7 @@ #ifndef HEADER_SUPERTUX_INTERFACE_CONTROL_HPP #define HEADER_SUPERTUX_INTERFACE_CONTROL_HPP +#include #include #include "control/input_manager.hpp" diff --git a/src/interface/control_textbox.hpp b/src/interface/control_textbox.hpp index 54df039288e..750036d259b 100644 --- a/src/interface/control_textbox.hpp +++ b/src/interface/control_textbox.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_INTERFACE_CONTROL_TEXTBOX_HPP #include +#include #include "control/input_manager.hpp" #include "interface/control.hpp" From a35d7749869f31af2bce89345a201802b3b7f90d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Br=C3=BBl=C3=A9?= Date: Thu, 10 Dec 2020 13:28:05 +0100 Subject: [PATCH 3/7] Replace boost::filesystem by std::filesystem --- src/supertux/main.cpp | 24 +++++++++++------------- src/util/file_system.cpp | 9 +++------ 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 0e7b3e7e05f..2e8f1252c94 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -19,10 +19,10 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -202,7 +202,7 @@ class PhysfsSubsystem final { datadir = BUILD_DATA_DIR; // Add config dir for supplemental files - PHYSFS_mount(boost::filesystem::canonical(BUILD_CONFIG_DATA_DIR).string().c_str(), nullptr, 1); + PHYSFS_mount(std::filesystem::canonical(BUILD_CONFIG_DATA_DIR).string().c_str(), nullptr, 1); } else { @@ -213,7 +213,7 @@ class PhysfsSubsystem final } } - if (!PHYSFS_mount(boost::filesystem::canonical(datadir).string().c_str(), nullptr, 1)) + if (!PHYSFS_mount(std::filesystem::canonical(datadir).string().c_str(), nullptr, 1)) { log_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastErrorCode() << std::endl; } @@ -251,20 +251,20 @@ class PhysfsSubsystem final std::string olduserdir = FileSystem::join(physfs_userdir, "." PACKAGE_NAME); #endif if (FileSystem::is_directory(olduserdir)) { - boost::filesystem::path olduserpath(olduserdir); - boost::filesystem::path userpath(userdir); + std::filesystem::path olduserpath(olduserdir); + std::filesystem::path userpath(userdir); - boost::filesystem::directory_iterator end_itr; + std::filesystem::directory_iterator end_itr; bool success = true; // cycle through the directory - for (boost::filesystem::directory_iterator itr(olduserpath); itr != end_itr; ++itr) { + for (std::filesystem::directory_iterator itr(olduserpath); itr != end_itr; ++itr) { try { - boost::filesystem::rename(itr->path().string().c_str(), userpath / itr->path().filename()); + std::filesystem::rename(itr->path().string().c_str(), userpath / itr->path().filename()); } - catch (const boost::filesystem::filesystem_error& err) + catch (const std::filesystem::filesystem_error& err) { success = false; log_warning << "Failed to move contents of config directory: " << err.what() << std::endl; @@ -273,9 +273,9 @@ class PhysfsSubsystem final if (success) { try { - boost::filesystem::remove_all(olduserpath); + std::filesystem::remove_all(olduserpath); } - catch (const boost::filesystem::filesystem_error& err) + catch (const std::filesystem::filesystem_error& err) { success = false; log_warning << "Failed to remove old config directory: " << err.what(); @@ -565,8 +565,6 @@ Main::run(int argc, char** argv) // Create and install global locale std::locale::global(boost::locale::generator().generate("")); - // Make boost.filesystem use it - boost::filesystem::path::imbue(std::locale()); int result = 0; diff --git a/src/util/file_system.cpp b/src/util/file_system.cpp index 72243629b07..c6dece0d375 100644 --- a/src/util/file_system.cpp +++ b/src/util/file_system.cpp @@ -16,9 +16,8 @@ #include "util/file_system.hpp" -#include -#include #include +#include #include #include #include @@ -32,18 +31,16 @@ #include "util/log.hpp" -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace FileSystem { bool exists(const std::string& path) { fs::path location(path); - boost::system::error_code ec; - // If we get an error (such as "Permission denied"), then ignore it // and pretend that the path doesn't exist. - return fs::exists(location, ec); + return fs::exists(location); } bool is_directory(const std::string& path) From 4d60a4d08490167988514e34d385b8b4c2c7b53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Br=C3=BBl=C3=A9?= Date: Thu, 10 Dec 2020 16:06:47 +0100 Subject: [PATCH 4/7] Replace boost::locale by std::locale --- src/supertux/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 2e8f1252c94..564c5ec7e95 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include extern "C" { @@ -564,7 +563,7 @@ Main::run(int argc, char** argv) #endif // Create and install global locale - std::locale::global(boost::locale::generator().generate("")); + std::locale::global(std::locale::classic()); int result = 0; From 14cd9a93f7aa5ac01e4454a1b9741ac62c4d9733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Br=C3=BBl=C3=A9?= Date: Thu, 10 Dec 2020 13:16:51 +0100 Subject: [PATCH 5/7] Fixed missing includes --- src/editor/particle_editor.hpp | 1 + src/gui/menu.cpp | 2 ++ src/interface/control.hpp | 1 + src/interface/control_textbox.hpp | 1 + 4 files changed, 5 insertions(+) diff --git a/src/editor/particle_editor.hpp b/src/editor/particle_editor.hpp index acf636801dd..4c7a82669bf 100644 --- a/src/editor/particle_editor.hpp +++ b/src/editor/particle_editor.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_EDITOR_PARTICLE_EDITOR_HPP #include +#include #include #include diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 33cba5876a1..1057d33e1ae 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -16,6 +16,8 @@ #include "gui/menu.hpp" +#include + #include "control/input_manager.hpp" #include "gui/item_action.hpp" #include "gui/item_back.hpp" diff --git a/src/interface/control.hpp b/src/interface/control.hpp index 6418b5d8e6d..73373d4d4dc 100644 --- a/src/interface/control.hpp +++ b/src/interface/control.hpp @@ -17,6 +17,7 @@ #ifndef HEADER_SUPERTUX_INTERFACE_CONTROL_HPP #define HEADER_SUPERTUX_INTERFACE_CONTROL_HPP +#include #include #include "control/input_manager.hpp" diff --git a/src/interface/control_textbox.hpp b/src/interface/control_textbox.hpp index 54df039288e..750036d259b 100644 --- a/src/interface/control_textbox.hpp +++ b/src/interface/control_textbox.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_INTERFACE_CONTROL_TEXTBOX_HPP #include +#include #include "control/input_manager.hpp" #include "interface/control.hpp" From b905acde61cc01c0939328b108f70160fb81b4cb Mon Sep 17 00:00:00 2001 From: "striker.sh" Date: Fri, 11 Dec 2020 18:40:30 +0100 Subject: [PATCH 6/7] Add missing includes (required by ms cpp compiler) --- src/control/controller.hpp | 1 + src/interface/control.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/control/controller.hpp b/src/control/controller.hpp index 0b29833deb1..daacb5f2038 100644 --- a/src/control/controller.hpp +++ b/src/control/controller.hpp @@ -19,6 +19,7 @@ #include #include +#include enum class Control { LEFT = 0, diff --git a/src/interface/control.hpp b/src/interface/control.hpp index 73373d4d4dc..842e4c440cb 100644 --- a/src/interface/control.hpp +++ b/src/interface/control.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_INTERFACE_CONTROL_HPP #include +#include #include #include "control/input_manager.hpp" From 1fb721136ba2f15579b8892392eecb45536443ef Mon Sep 17 00:00:00 2001 From: "striker.sh" Date: Sat, 12 Dec 2020 11:04:50 +0100 Subject: [PATCH 7/7] Use std::u8path (depreciated with c++20 because of proper utf8 strings) --- src/control/controller.hpp | 1 + src/supertux/main.cpp | 4 ++-- src/util/file_system.cpp | 44 ++++---------------------------------- 3 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/control/controller.hpp b/src/control/controller.hpp index daacb5f2038..30af2e53bbb 100644 --- a/src/control/controller.hpp +++ b/src/control/controller.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_CONTROL_CONTROLLER_HPP #include +#include #include #include diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 564c5ec7e95..ebaa1c2f9a7 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -250,8 +250,8 @@ class PhysfsSubsystem final std::string olduserdir = FileSystem::join(physfs_userdir, "." PACKAGE_NAME); #endif if (FileSystem::is_directory(olduserdir)) { - std::filesystem::path olduserpath(olduserdir); - std::filesystem::path userpath(userdir); + std::filesystem::path olduserpath = std::filesystem::u8path(olduserdir); + std::filesystem::path userpath = std::filesystem::u8path(userdir); std::filesystem::directory_iterator end_itr; diff --git a/src/util/file_system.cpp b/src/util/file_system.cpp index c6dece0d375..ac4fbbfd627 100644 --- a/src/util/file_system.cpp +++ b/src/util/file_system.cpp @@ -37,7 +37,7 @@ namespace FileSystem { bool exists(const std::string& path) { - fs::path location(path); + fs::path location = fs::u8path(path); // If we get an error (such as "Permission denied"), then ignore it // and pretend that the path doesn't exist. return fs::exists(location); @@ -45,13 +45,13 @@ bool exists(const std::string& path) bool is_directory(const std::string& path) { - fs::path location(path); + fs::path location = fs::u8path(path); return fs::is_directory(location); } void mkdir(const std::string& directory) { - fs::path location(directory); + fs::path location = fs::u8path(directory); if (!fs::create_directory(location)) { throw std::runtime_error("failed to create directory: " + directory); @@ -82,43 +82,7 @@ std::string basename(const std::string& filename) std::string relpath(const std::string& filename, const std::string& basedir) { -#if BOOST_VERSION >= 106000 return fs::relative(filename, basedir).string(); -#else - fs::path from = basedir; - fs::path to = filename; - - // Taken from https://stackoverflow.com/a/29221546 - - // Start at the root path and while they are the same then do nothing then when they first - // diverge take the entire from path, swap it with '..' segments, and then append the remainder of the to path. - fs::path::const_iterator fromIter = from.begin(); - fs::path::const_iterator toIter = to.begin(); - - // Loop through both while they are the same to find nearest common directory - while (fromIter != from.end() && toIter != to.end() && (*toIter) == (*fromIter)) - { - ++toIter; - ++fromIter; - } - - // Replace from path segments with '..' (from => nearest common directory) - fs::path finalPath; - while (fromIter != from.end()) - { - finalPath /= ".."; - ++fromIter; - } - - // Append the remainder of the to path (nearest common directory => to) - while (toIter != to.end()) - { - finalPath /= *toIter; - ++toIter; - } - - return finalPath.string(); -#endif } std::string strip_extension(const std::string& filename) @@ -211,7 +175,7 @@ std::string join(const std::string& lhs, const std::string& rhs) bool remove(const std::string& path) { - fs::path location(path); + fs::path location = fs::u8path(path); return fs::remove(location); }