diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..97296c7e339 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,87 @@ + +root = true + +[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}] + +# Visual C++ Code Style settings + +cpp_generate_documentation_comments = doxygen_slash_star + +# Visual C++ Formatting settings + +indent_style = space +indent_size = 2 +tab_width = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +cpp_indent_braces = false +cpp_indent_multi_line_relative_to = innermost_parenthesis +cpp_indent_within_parentheses = indent +cpp_indent_preserve_within_parentheses = false +cpp_indent_case_contents = true +cpp_indent_case_labels = false +cpp_indent_case_contents_when_block = false +cpp_indent_lambda_braces_when_parameter = true +cpp_indent_goto_labels = one_left +cpp_indent_preprocessor = leftmost_column +cpp_indent_access_specifiers = false +cpp_indent_namespace_contents = true +cpp_indent_preserve_comments = false +cpp_new_line_before_open_brace_namespace = ignore +cpp_new_line_before_open_brace_type = ignore +cpp_new_line_before_open_brace_function = ignore +cpp_new_line_before_open_brace_block = ignore +cpp_new_line_before_open_brace_lambda = ignore +cpp_new_line_scope_braces_on_separate_lines = false +cpp_new_line_close_brace_same_line_empty_type = false +cpp_new_line_close_brace_same_line_empty_function = false +cpp_new_line_before_catch = true +cpp_new_line_before_else = true +cpp_new_line_before_while_in_do_while = false +cpp_space_before_function_open_parenthesis = remove +cpp_space_within_parameter_list_parentheses = false +cpp_space_between_empty_parameter_list_parentheses = false +cpp_space_after_keywords_in_control_flow_statements = true +cpp_space_within_control_flow_statement_parentheses = false +cpp_space_before_lambda_open_parenthesis = false +cpp_space_within_cast_parentheses = false +cpp_space_after_cast_close_parenthesis = false +cpp_space_within_expression_parentheses = false +cpp_space_before_block_open_brace = true +cpp_space_between_empty_braces = false +cpp_space_before_initializer_list_open_brace = false +cpp_space_within_initializer_list_braces = true +cpp_space_preserve_in_initializer_list = true +cpp_space_before_open_square_bracket = false +cpp_space_within_square_brackets = false +cpp_space_before_empty_square_brackets = false +cpp_space_between_empty_square_brackets = false +cpp_space_group_square_brackets = true +cpp_space_within_lambda_brackets = false +cpp_space_between_empty_lambda_brackets = false +cpp_space_before_comma = false +cpp_space_after_comma = true +cpp_space_remove_around_member_operators = true +cpp_space_before_inheritance_colon = true +cpp_space_before_constructor_colon = true +cpp_space_remove_before_semicolon = true +cpp_space_after_semicolon = true +cpp_space_remove_around_unary_operator = true +cpp_space_around_binary_operator = insert +cpp_space_around_assignment_operator = insert +cpp_space_pointer_reference_alignment = left +cpp_space_around_ternary_operator = insert +cpp_use_unreal_engine_macro_formatting = true +cpp_wrap_preserve_blocks = one_liners +cpp_include_cleanup_add_missing_error_tag_type = none +cpp_include_cleanup_remove_unused_error_tag_type = none +cpp_include_cleanup_optimize_unused_error_tag_type = none +cpp_include_cleanup_sort_after_edits = false +cpp_include_cleanup_format_after_edits = false +cpp_sort_includes_error_tag_type = none +cpp_sort_includes_priority_case_sensitive = false +cpp_sort_includes_priority_style = quoted +cpp_includes_style = default +cpp_includes_use_forward_slash = true diff --git a/CMake/Common.cmake b/CMake/Common.cmake index 580158aca84..f777cb014ba 100644 --- a/CMake/Common.cmake +++ b/CMake/Common.cmake @@ -50,13 +50,39 @@ endif () # Common Definitions # ================================ +macro (carla_add_compile_option FLAG) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}") +endmacro () + +macro (carla_add_link_option FLAG) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}") +endmacro () + +macro (carla_try_add_compile_options) + foreach (NAME ${ARGN}) + string (REPLACE "/" "__" NAME2 ${NAME}) + string (MAKE_C_IDENTIFIER "CO_${NAME2}" RESULT) + check_c_compiler_flag(${NAME} ${RESULT}) + if (${VARIABLE_IDENTIFIER}) + carla_add_compile_option (${NAME}) + endif () + endforeach () +endmacro () + +macro (carla_try_add_link_options) + foreach (NAME ${ARGN}) + string (REPLACE "/" "__" NAME2 ${NAME}) + string (MAKE_C_IDENTIFIER "LO_${NAME2}" RESULT) + check_linker_flag(C ${NAME} ${RESULT}) + if (${RESULT}) + carla_add_link_option (${NAME}) + endif () + endforeach () +endmacro () + if (WIN32) add_compile_definitions (_CRT_SECURE_NO_WARNINGS) - check_cxx_compiler_flag (/utf-8 HAS_MSVC_UTF8) - if (HAS_MSVC_UTF8) - # @TODO This causes warnings with MASM. A better approach should be looked into. - add_compile_options ($<$:/utf-8>) - endif () + carla_try_add_compile_options (/utf-8) endif () set (CARLA_COMMON_DEFINITIONS) @@ -107,13 +133,9 @@ else () endif () carla_message ("Checking for ${EXCEPTIONS_FLAG} support") -check_cxx_compiler_flag (${EXCEPTIONS_FLAG} HAS_EXCEPTIONS_FLAG) -if (HAS_EXCEPTIONS_FLAG) - add_compile_options ($<$:${EXCEPTIONS_FLAG}>) -endif () +carla_try_add_compile_options (${EXCEPTIONS_FLAG}) set (CARLA_EXCEPTION_DEFINITIONS) - if (ENABLE_EXCEPTIONS) # Nothing else () @@ -128,29 +150,15 @@ endif () # RTTI Definitions # ================================ -if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" AND - NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - if (ENABLE_RTTI) - set (RTTI_FLAG /GR) - else () - set (RTTI_FLAG /GR-) - endif () +if (ENABLE_RTTI) + carla_try_add_compile_options (/GR) + carla_try_add_compile_options (-frtti) else () - if (ENABLE_RTTI) - set (RTTI_FLAG -frtti) - else () - set (RTTI_FLAG -fno-rtti) - endif () -endif () - -carla_message ("Checking for ${RTTI_FLAG} support") -check_cxx_compiler_flag (${RTTI_FLAG} HAS_RTTI_FLAG) -if (HAS_RTTI_FLAG) - add_compile_options ($<$:${RTTI_FLAG}>) + carla_try_add_compile_options (/GR-) + carla_try_add_compile_options (-fno-rtti) endif () set (CARLA_RTTI_DEFINITIONS) - if (ENABLE_RTTI) # Nothing else () @@ -163,76 +171,30 @@ endif () # ================================ if (ENABLE_ALL_WARNINGS) - check_cxx_compiler_flag(-Wall HAS_WALL_GNU) - if (HAS_WALL_GNU) - set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") - endif () - check_cxx_compiler_flag(-Wextra HAS_WEXTRA_GNU) - if (HAS_WEXTRA_GNU) - set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") - endif () - check_cxx_compiler_flag(/Wall HAS_WALL_MSVC) - if (HAS_WALL_MSVC) - set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /Wall") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall") + if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + carla_try_add_compile_options (/W4) + else () + carla_try_add_compile_options (-Wall) + carla_try_add_compile_options (-Wextra) endif () endif () -if (CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "GNU") - set (SUPPRESS_WARNING_DIRECTIVE_PREFIX -Wno-) -elseif (CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") - set (SUPPRESS_WARNING_DIRECTIVE_PREFIX /wd) -endif () - -macro (carla_try_suppress_cxx_warning NAME FLAG) - check_cxx_compiler_flag ( - ${SUPPRESS_WARNING_DIRECTIVE_PREFIX}${FLAG} - HAS_${NAME} - ) - if (HAS_${NAME}) - add_compile_options ( - $<$:${SUPPRESS_WARNING_DIRECTIVE_PREFIX}${FLAG}>) - endif () -endmacro () - -macro (carla_try_suppress_c_warning NAME FLAG) - check_c_compiler_flag ( - ${SUPPRESS_WARNING_DIRECTIVE_PREFIX}${FLAG} - HAS_${NAME} - ) - if (HAS_${NAME}) - add_compile_options ( - $<$:${SUPPRESS_WARNING_DIRECTIVE_PREFIX}${FLAG}>) +function (carla_try_suppress_warning WARNING_ID) + if (CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "GNU") + carla_try_add_compile_options (-Wno-${WARNING_ID}) + elseif (CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + carla_try_add_compile_options (/wd${WARNING_ID}) endif () -endmacro () +endfunction () set ( - CARLA_C_SUPRESSED_WARNING_LIST + CARLA_SUPRESSED_WARNING_LIST macro-redefined 4005 incompatible-pointer-types ) -set ( - CARLA_CXX_SUPRESSED_WARNING_LIST - macro-redefined 4005 -) - -foreach (WARNING ${CARLA_C_SUPRESSED_WARNING_LIST}) - string (MAKE_C_IDENTIFIER "${WARNING}" WARNING_NAME) - carla_try_suppress_c_warning ( - ${WARNING_NAME} - ${WARNING} - ) -endforeach () - -foreach (WARNING ${CARLA_CXX_SUPRESSED_WARNING_LIST}) - string (MAKE_C_IDENTIFIER "${WARNING}" WARNING_NAME) - carla_try_suppress_cxx_warning ( - ${WARNING_NAME} - ${WARNING} - ) +foreach (WARNING ${CARLA_SUPRESSED_WARNING_LIST}) + carla_try_suppress_warning (${WARNING}) endforeach () # ================================ @@ -241,21 +203,8 @@ endforeach () if (ENABLE_WARNINGS_TO_ERRORS) if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - check_cxx_compiler_flag(-Werror HAS_WALL) - if (HAS_WALL) - add_compile_options (-Werror) - endif () - else () - check_cxx_compiler_flag(/WX HAS_WALL) - if (HAS_WALL) - add_compile_options (/WX) - endif () - endif () + carla_try_add_compile_options (/WX) else () - check_cxx_compiler_flag(-Werror HAS_WALL) - if (HAS_WALL) - add_compile_options (-Werror) - endif () + carla_try_add_compile_options (-Werror) endif () endif () diff --git a/CMake/Dependencies.cmake b/CMake/Dependencies.cmake index c1374dbf166..30da9886720 100644 --- a/CMake/Dependencies.cmake +++ b/CMake/Dependencies.cmake @@ -173,7 +173,7 @@ carla_dependency_option (BOOST_GIL_BUILD_HEADER_TESTS OFF) carla_dependency_add( boost ${CARLA_BOOST_TAG} - https://github.com/boostorg/boost/releases/download/${CARLA_BOOST_TAG}/${CARLA_BOOST_TAG}.zip + https://github.com/boostorg/boost/releases/download/${CARLA_BOOST_TAG}/${CARLA_BOOST_TAG}-cmake.zip https://github.com/boostorg/boost.git ) diff --git a/CMake/Options.cmake b/CMake/Options.cmake index b42c4d77d60..8b8e4a0c782 100644 --- a/CMake/Options.cmake +++ b/CMake/Options.cmake @@ -268,7 +268,7 @@ carla_option ( carla_string_option ( CARLA_BOOST_VERSION "Target boost version." - 1.84.0 + 1.89.0 ) carla_string_option ( @@ -309,7 +309,7 @@ carla_string_option ( # We can not upgrade any further due to ZLIB. # See https://github.com/madler/zlib/issues/1019 -# Once this is resolved we can target 1.6.50 +# Once this is resolved we can target >1.6.40 carla_string_option ( CARLA_LIBPNG_VERSION "Target libpng version." diff --git a/CMakePresets.json b/CMakePresets.json index 8fd5880aae7..4f0ca85199d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,7 +15,8 @@ "installDir": "${sourceDir}/Install/${presetName}", "cacheVariables": { - "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/CMake/Toolchain.cmake" + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/CMake/Toolchain.cmake", + "CMAKE_POLICY_VERSION_MINIMUM" : "3.5" }, "hidden": true }, diff --git a/LibCarla/source/carla/AtomicList.h b/LibCarla/source/carla/AtomicList.h index b0894c280c9..0c9fbadf21b 100644 --- a/LibCarla/source/carla/AtomicList.h +++ b/LibCarla/source/carla/AtomicList.h @@ -13,9 +13,8 @@ #include #include -namespace carla { -namespace client { -namespace detail { +namespace carla::client::detail +{ /// Holds an atomic pointer to a list. /// @@ -70,6 +69,4 @@ namespace detail { AtomicSharedPtr _list; }; -} // namespace detail -} // namespace client -} // namespace carla +} // namespace carla::client::detail diff --git a/LibCarla/source/carla/ThreadPool.h b/LibCarla/source/carla/ThreadPool.h index 829cec790fe..85884d87ea2 100644 --- a/LibCarla/source/carla/ThreadPool.h +++ b/LibCarla/source/carla/ThreadPool.h @@ -16,31 +16,41 @@ #include #include +#include #include namespace carla { /// A thread pool based on Boost.Asio's io context. - class ThreadPool : private NonCopyable { + class ThreadPool : + private NonCopyable + { public: - ThreadPool() : _work_to_do(_io_context) {} + ThreadPool() : + _io_context(), + _work_guard(), + _workers() + { + } /// Stops the ThreadPool and joins all its threads. - ~ThreadPool() { + ~ThreadPool() + { Stop(); } /// Return the underlying io_context. - auto &io_context() { + auto &io_context() + { return _io_context; } /// Post a task to the pool. - template < - typename FunctorT, - typename ResultT = typename std::invoke_result_t> - std::future Post(FunctorT &&functor) { + template + auto Post(FunctorT &&functor) + { + using ResultT = std::invoke_result_t; auto task = std::packaged_task(std::forward(functor)); auto future = task.get_future(); boost::asio::post(_io_context, carla::MoveHandler(task)); @@ -50,19 +60,25 @@ namespace carla { /// Launch threads to run tasks asynchronously. Launch specific number of /// threads if @a worker_threads is provided, otherwise use all available /// hardware concurrency. - void AsyncRun(size_t worker_threads) { + void AsyncRun(size_t worker_threads) + { + _work_guard.emplace( + boost::asio::make_work_guard( + _io_context.get_executor())); _workers.CreateThreads(worker_threads, [this]() { Run(); }); } /// @copydoc AsyncRun(size_t) - void AsyncRun() { + void AsyncRun() + { AsyncRun(std::thread::hardware_concurrency()); } /// Run tasks in this thread. /// /// @warning This function blocks until the ThreadPool has been stopped. - void Run() { + void Run() + { _io_context.run(); } @@ -70,23 +86,30 @@ namespace carla { /// /// @warning This function blocks until the ThreadPool has been stopped, or /// until the specified time duration has elapsed. - void RunFor(time_duration duration) { + void RunFor(time_duration duration) + { _io_context.run_for(duration.to_chrono()); } /// Stop the ThreadPool and join all its threads. void Stop() { + if (_work_guard) + _work_guard.reset(); _io_context.stop(); _workers.JoinAll(); } private: - boost::asio::io_context _io_context; - - boost::asio::io_context::work _work_to_do; + using work_guard_type = + std::optional< + boost::asio::executor_work_guard< + boost::asio::io_context::executor_type>>; + boost::asio::io_context _io_context; + work_guard_type _work_guard; ThreadGroup _workers; + }; } // namespace carla diff --git a/LibCarla/source/carla/client/Actor.cpp b/LibCarla/source/carla/client/Actor.cpp index 529d481f65a..d534322acbd 100644 --- a/LibCarla/source/carla/client/Actor.cpp +++ b/LibCarla/source/carla/client/Actor.cpp @@ -9,8 +9,7 @@ #include "carla/Logging.h" #include "carla/client/detail/Simulator.h" -namespace carla { -namespace client { +namespace carla::client { geom::Location Actor::GetLocation() const { return GetEpisode().Lock()->GetActorLocation(*this); @@ -137,5 +136,4 @@ namespace client { return result; } -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/Actor.h b/LibCarla/source/carla/client/Actor.h index c38997399f9..c62239168d0 100644 --- a/LibCarla/source/carla/client/Actor.h +++ b/LibCarla/source/carla/client/Actor.h @@ -11,8 +11,7 @@ #include "carla/client/detail/ActorState.h" #include "carla/profiler/LifetimeProfiled.h" -namespace carla { -namespace client { +namespace carla::client { /// Represents an actor in the simulation. class Actor @@ -157,5 +156,4 @@ namespace client { }; -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/ActorAttribute.cpp b/LibCarla/source/carla/client/ActorAttribute.cpp index 02c27fc2e6e..7c6610b4c84 100644 --- a/LibCarla/source/carla/client/ActorAttribute.cpp +++ b/LibCarla/source/carla/client/ActorAttribute.cpp @@ -10,8 +10,7 @@ #include "carla/Logging.h" #include "carla/StringUtil.h" -namespace carla { -namespace client { +namespace carla::client { #define LIBCARLA_THROW_INVALID_VALUE(message) throw_exception(InvalidAttributeValue(GetId() + ": " + message)); #define LIBCARLA_THROW_BAD_VALUE_CAST(type) \ @@ -103,5 +102,4 @@ namespace client { #undef LIBCARLA_THROW_BAD_VALUE_CAST #undef LIBCARLA_THROW_INVALID_VALUE -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/ActorAttribute.h b/LibCarla/source/carla/client/ActorAttribute.h index 5585f1cc9e6..12d75774ab4 100644 --- a/LibCarla/source/carla/client/ActorAttribute.h +++ b/LibCarla/source/carla/client/ActorAttribute.h @@ -13,8 +13,7 @@ #include #include -namespace carla { -namespace client { +namespace carla::client { // =========================================================================== // -- InvalidAttributeValue -------------------------------------------------- @@ -237,5 +236,4 @@ namespace client { return rhs.operator==(*this); } -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/ActorBlueprint.cpp b/LibCarla/source/carla/client/ActorBlueprint.cpp index 12895664cf3..b37b66b8148 100644 --- a/LibCarla/source/carla/client/ActorBlueprint.cpp +++ b/LibCarla/source/carla/client/ActorBlueprint.cpp @@ -11,8 +11,7 @@ #include -namespace carla { -namespace client { +namespace carla::client { template static void FillMap(Map &destination, Container &source) { @@ -62,5 +61,4 @@ namespace client { return description; } -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/ActorBlueprint.h b/LibCarla/source/carla/client/ActorBlueprint.h index f08b7d09d86..b501254f39c 100644 --- a/LibCarla/source/carla/client/ActorBlueprint.h +++ b/LibCarla/source/carla/client/ActorBlueprint.h @@ -16,8 +16,7 @@ #include #include -namespace carla { -namespace client { +namespace carla::client { /// Contains all the necessary information for spawning an Actor. class ActorBlueprint { @@ -120,5 +119,4 @@ namespace client { std::unordered_map _attributes; }; -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/ActorList.cpp b/LibCarla/source/carla/client/ActorList.cpp index 2c4fac39658..46366796b15 100644 --- a/LibCarla/source/carla/client/ActorList.cpp +++ b/LibCarla/source/carla/client/ActorList.cpp @@ -11,8 +11,7 @@ #include -namespace carla { -namespace client { +namespace carla::client { ActorList::ActorList( detail::EpisodeProxy episode, @@ -39,5 +38,4 @@ namespace client { return filtered; } -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/ActorList.h b/LibCarla/source/carla/client/ActorList.h index 9a51b54e04c..32b79c33d4e 100644 --- a/LibCarla/source/carla/client/ActorList.h +++ b/LibCarla/source/carla/client/ActorList.h @@ -12,8 +12,7 @@ #include -namespace carla { -namespace client { +namespace carla::client { class ActorList : public EnableSharedFromThis { private: @@ -68,5 +67,4 @@ namespace client { std::vector _actors; }; -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/ActorSnapshot.h b/LibCarla/source/carla/client/ActorSnapshot.h index 0636eac9f07..037015c405a 100644 --- a/LibCarla/source/carla/client/ActorSnapshot.h +++ b/LibCarla/source/carla/client/ActorSnapshot.h @@ -12,8 +12,7 @@ #include "carla/rpc/ActorState.h" #include "carla/sensor/data/ActorDynamicState.h" -namespace carla { -namespace client { +namespace carla::client { struct ActorSnapshot { ActorId id = 0u; @@ -25,5 +24,4 @@ namespace client { sensor::data::ActorDynamicState::TypeDependentState state; }; -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/BlueprintLibrary.cpp b/LibCarla/source/carla/client/BlueprintLibrary.cpp index 81e4ada9481..5ddf1c2d119 100644 --- a/LibCarla/source/carla/client/BlueprintLibrary.cpp +++ b/LibCarla/source/carla/client/BlueprintLibrary.cpp @@ -11,8 +11,7 @@ #include #include -namespace carla { -namespace client { +namespace carla::client { BlueprintLibrary::BlueprintLibrary( const std::vector &blueprints) { @@ -85,5 +84,4 @@ namespace client { return operator[](pos); } -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/BlueprintLibrary.h b/LibCarla/source/carla/client/BlueprintLibrary.h index 03986c07603..359d6ea834e 100644 --- a/LibCarla/source/carla/client/BlueprintLibrary.h +++ b/LibCarla/source/carla/client/BlueprintLibrary.h @@ -16,8 +16,7 @@ #include #include -namespace carla { -namespace client { +namespace carla::client { /// @todo Works as a list but its actually a map. We should assess the use /// cases and reconsider this implementation. @@ -84,5 +83,4 @@ namespace client { map_type _blueprints; }; -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/Client.h b/LibCarla/source/carla/client/Client.h index 9355cca5c5d..f2ef57eca60 100644 --- a/LibCarla/source/carla/client/Client.h +++ b/LibCarla/source/carla/client/Client.h @@ -12,8 +12,7 @@ #include "carla/PythonUtil.h" #include "carla/trafficmanager/TrafficManager.h" -namespace carla { -namespace client { +namespace carla::client { using namespace carla::traffic_manager; @@ -188,5 +187,4 @@ namespace client { new detail::Simulator(host, port, worker_threads), PythonUtil::ReleaseGILDeleter()) {} -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/client/ClientSideSensor.h b/LibCarla/source/carla/client/ClientSideSensor.h index 194d638999e..6ec4d1ed2be 100644 --- a/LibCarla/source/carla/client/ClientSideSensor.h +++ b/LibCarla/source/carla/client/ClientSideSensor.h @@ -8,8 +8,7 @@ #include "carla/client/Sensor.h" -namespace carla { -namespace client { +namespace carla::client { class ClientSideSensor : public Sensor { public: @@ -17,5 +16,4 @@ namespace client { using Sensor::Sensor; }; -} // namespace client -} // namespace carla +} // namespace carla::client diff --git a/LibCarla/source/carla/multigpu/listener.cpp b/LibCarla/source/carla/multigpu/listener.cpp index ca789aee3d5..335f96ca1ba 100644 --- a/LibCarla/source/carla/multigpu/listener.cpp +++ b/LibCarla/source/carla/multigpu/listener.cpp @@ -31,7 +31,7 @@ namespace multigpu { _acceptor.cancel(); _acceptor.close(); _io_context.stop(); - _io_context.reset(); + _io_context.restart(); } void Listener::OpenSession( diff --git a/LibCarla/source/carla/multigpu/router.cpp b/LibCarla/source/carla/multigpu/router.cpp index 398fdbf5247..d297dd29722 100644 --- a/LibCarla/source/carla/multigpu/router.cpp +++ b/LibCarla/source/carla/multigpu/router.cpp @@ -27,9 +27,10 @@ void Router::Stop() { } Router::Router(uint16_t port) : - _next(0) { - - _endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("0.0.0.0"), port); + _next(0) +{ + _endpoint = boost::asio::ip::tcp::endpoint( + boost::asio::ip::make_address_v4("0.0.0.0"), port); _listener = std::make_shared(_pool.io_context(), _endpoint); } diff --git a/LibCarla/source/carla/multigpu/secondary.cpp b/LibCarla/source/carla/multigpu/secondary.cpp index 6fe8cd5da8e..a5fa148da57 100644 --- a/LibCarla/source/carla/multigpu/secondary.cpp +++ b/LibCarla/source/carla/multigpu/secondary.cpp @@ -48,7 +48,7 @@ namespace multigpu { _connection_timer(_pool.io_context()), _buffer_pool(std::make_shared()) { - boost::asio::ip::address ip_address = boost::asio::ip::address::from_string(ip); + auto ip_address = boost::asio::ip::make_address(ip); _endpoint = boost::asio::ip::tcp::endpoint(ip_address, port); _commander.set_callback(callback); } diff --git a/LibCarla/source/carla/rpc/Server.h b/LibCarla/source/carla/rpc/Server.h index 6b89e5b57b6..f6b8ee61413 100644 --- a/LibCarla/source/carla/rpc/Server.h +++ b/LibCarla/source/carla/rpc/Server.h @@ -56,7 +56,7 @@ namespace rpc { TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__); #include #endif // LIBCARLA_INCLUDED_FROM_UE4 - _sync_io_context.reset(); + _sync_io_context.restart(); _sync_io_context.run_for(duration.to_chrono()); } diff --git a/LibCarla/source/carla/streaming/EndPoint.h b/LibCarla/source/carla/streaming/EndPoint.h index 0ac03949713..221d80730d1 100644 --- a/LibCarla/source/carla/streaming/EndPoint.h +++ b/LibCarla/source/carla/streaming/EndPoint.h @@ -10,9 +10,10 @@ #include #include #include +#include + +namespace carla::streaming { -namespace carla { -namespace streaming { namespace detail { // When in doubt, V4 addresses are returned. @@ -24,87 +25,92 @@ namespace detail { class EndPoint; template - class EndPoint { + class EndPoint + { public: - explicit EndPoint(boost::asio::ip::basic_endpoint ep) - : _endpoint(std::move(ep)) {} + explicit EndPoint(boost::asio::ip::basic_endpoint ep) + : _endpoint(std::move(ep)) { + } - auto address() const { - return _endpoint.address(); - } + auto address() const { + return _endpoint.address(); + } - uint16_t port() const { - return _endpoint.port(); - } + uint16_t port() const { + return _endpoint.port(); + } - operator boost::asio::ip::basic_endpoint() const { - return _endpoint; - } + operator boost::asio::ip::basic_endpoint() const { + return _endpoint; + } private: - boost::asio::ip::basic_endpoint _endpoint; + boost::asio::ip::basic_endpoint _endpoint; }; template class EndPoint { public: - explicit EndPoint(uint16_t port) : _port(port) {} + explicit EndPoint(uint16_t port) : _port(port) {} - uint16_t port() const { - return _port; - } + uint16_t port() const { + return _port; + } - operator boost::asio::ip::basic_endpoint() const { - return {Protocol::v4(), _port}; - } + operator boost::asio::ip::basic_endpoint() const { + return { Protocol::v4(), _port }; + } private: - uint16_t _port; + uint16_t _port; }; } // namespace detail - static inline auto make_localhost_address() { - return boost::asio::ip::make_address("127.0.0.1"); - } - - static inline auto make_address(const std::string &address) { - boost::asio::io_context io_context; - boost::asio::ip::tcp::resolver resolver(io_context); - boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), address, "", boost::asio::ip::tcp::resolver::query::canonical_name); - boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query); - boost::asio::ip::tcp::resolver::iterator end; - while (iter != end) - { - boost::asio::ip::tcp::endpoint endpoint = *iter++; - return endpoint.address(); - } - return boost::asio::ip::make_address(address); - } - - template - static inline auto make_endpoint(boost::asio::ip::basic_endpoint ep) { - return detail::EndPoint{std::move(ep)}; - } - - template - static inline auto make_endpoint(const char *address, uint16_t port) { - return make_endpoint({make_address(address), port}); - } - - template - static inline auto make_endpoint(const std::string &address, uint16_t port) { - return make_endpoint(address.c_str(), port); +static inline auto make_localhost_address() { + return boost::asio::ip::make_address("127.0.0.1"); +} + +template +static inline auto make_address(std::string_view address) +{ + using namespace boost::asio; + io_context io_context; + ip::basic_resolver resolver(io_context); + auto resolve_results = resolver.resolve( + ip::tcp::v4(), + address, + std::string_view(), + ip::resolver_base::flags::canonical_name); + for (auto& result : resolve_results) + { + auto endpoint = result.endpoint(); + return endpoint.address(); } - - template - static inline auto make_endpoint(uint16_t port) { - return detail::EndPoint{port}; - } - -} // namespace streaming -} // namespace carla + return ip::make_address(address); +} + +template +static inline auto make_endpoint(boost::asio::ip::basic_endpoint ep) { + return detail::EndPoint{std::move(ep)}; +} + +template +static inline auto make_endpoint(std::string_view address, uint16_t port) { + return make_endpoint( + { + make_address(address), + port + }); +} + +template +static inline auto make_endpoint(uint16_t port) { + return detail::EndPoint{port}; +} + +} // namespace carla::streaming diff --git a/PythonAPI/CMakeLists.txt b/PythonAPI/CMakeLists.txt index c0cf4eed61b..4e737d56e80 100644 --- a/PythonAPI/CMakeLists.txt +++ b/PythonAPI/CMakeLists.txt @@ -8,27 +8,6 @@ find_package ( REQUIRED ) -# -- Temporary check for numpy 2 presence, which breaks our current version of Boost.Python. -execute_process ( - COMMAND - ${Python3_EXECUTABLE} - -c - "import numpy; print(numpy.__version__)" - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE - NUMPY_VERSION_STRING - RESULT_VARIABLE - NUMPY_VERSION_QUERY_RESULT -) -if (NUMPY_VERSION_QUERY_RESULT) - carla_warning ("Failed to query numpy version.") -endif () -carla_message ("Found Numpy ${NUMPY_VERSION_STRING} for Python ${Python3_VERSION} (${Python3_EXECUTABLE}).") -if ("${NUMPY_VERSION_STRING}" VERSION_GREATER "2.0.0") - carla_error ("Unsupported Numpy version, please downgrade to a version prior to numpy 2.") -endif () -# -- - set ( PYTHON_API_DEPENDENCIES carla-client diff --git a/Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index 5994107bc18..125d95653ca 100644 --- a/Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -2822,6 +2822,8 @@ void FCarlaServer::Tick() bool FCarlaServer::TickCueReceived() { TRACE_CPUPROFILER_EVENT_SCOPE(FCarlaServer::TickCueReceived); + if (Pimpl->TickCuesReceived.load(std::memory_order_acquire) == 0) + return false; auto k = Pimpl->TickCuesReceived.fetch_sub(1, std::memory_order_acquire); bool flag = (k > 0); if (!flag) diff --git a/Unreal/CarlaUnreal/Plugins/CarlaTools/Source/CarlaTools/Private/MapPreviewUserWidget.cpp b/Unreal/CarlaUnreal/Plugins/CarlaTools/Source/CarlaTools/Private/MapPreviewUserWidget.cpp index 597334cc50d..12cd9080b08 100644 --- a/Unreal/CarlaUnreal/Plugins/CarlaTools/Source/CarlaTools/Private/MapPreviewUserWidget.cpp +++ b/Unreal/CarlaUnreal/Plugins/CarlaTools/Source/CarlaTools/Private/MapPreviewUserWidget.cpp @@ -22,7 +22,6 @@ #include "Misc/Paths.h" #include -namespace Asio = boost::asio; using AsioStreamBuf = boost::asio::streambuf; using AsioTCP = boost::asio::ip::tcp; using AsioSocket = boost::asio::ip::tcp::socket; @@ -74,9 +73,9 @@ void UMapPreviewUserWidget::RenderMap(FString Latitude, FString Longitude, FStri { AsioStreamBuf Buffer; std::size_t BytesReceived = - Asio::read(*SocketPtr, Buffer, Asio::transfer_at_least(2)); + boost::asio::read(*SocketPtr, Buffer, boost::asio::transfer_at_least(2)); TArray ThisReceivedData; - const char* DataPtr = Asio::buffer_cast(Buffer.data()); + const char* DataPtr = (const char*)Buffer.data().data(); for (std::size_t i = 0; i < Buffer.size(); ++i) { ThisReceivedData.Add(DataPtr[i]); @@ -118,8 +117,8 @@ FString UMapPreviewUserWidget::RecvCornersLatLonCoords() AsioStreamBuf Buffer; std::size_t BytesReceived = - Asio::read(*SocketPtr, Buffer, Asio::transfer_at_least(2)); - std::string BytesStr = Asio::buffer_cast(Buffer.data()); + boost::asio::read(*SocketPtr, Buffer, boost::asio::transfer_at_least(2)); + std::string BytesStr = (const char*)Buffer.data().data(); FString CoordStr = FString(BytesStr.size(), UTF8_TO_TCHAR(BytesStr.c_str())); UE_LOG(LogTemp, Log, TEXT("Received Coords %s"), *CoordStr); @@ -157,7 +156,7 @@ bool UMapPreviewUserWidget::SendStr(FString Msg) std::size_t BytesSent = 0; try { - BytesSent = Asio::write(*SocketPtr, Asio::buffer(MessageStr)); + BytesSent = boost::asio::write(*SocketPtr, boost::asio::buffer(MessageStr)); } catch (const boost::system::system_error& e) { diff --git a/Unreal/CarlaUnreal/Plugins/CarlaTools/Source/CarlaTools/Public/MapPreviewUserWidget.h b/Unreal/CarlaUnreal/Plugins/CarlaTools/Source/CarlaTools/Public/MapPreviewUserWidget.h index 785fb28cf5d..75d26393039 100644 --- a/Unreal/CarlaUnreal/Plugins/CarlaTools/Source/CarlaTools/Public/MapPreviewUserWidget.h +++ b/Unreal/CarlaUnreal/Plugins/CarlaTools/Source/CarlaTools/Public/MapPreviewUserWidget.h @@ -7,10 +7,19 @@ #include "Blueprint/UserWidget.h" #include +#ifdef _WIN32 +#pragma warning(push) +#pragma warning(disable : 4459) +#endif + #include #include #include +#ifdef _WIN32 +#pragma warning(pop) +#endif + #include #include "MapPreviewUserWidget.generated.h" @@ -25,7 +34,7 @@ class CARLATOOLS_API UMapPreviewUserWidget : public UUserWidget private: // Boost socket - boost::asio::io_service io_service; + boost::asio::io_context io_service; std::unique_ptr SocketPtr;