diff --git a/src/Core/Animation/Animation.cpp b/src/Core/Animation/Animation.cpp index 5686ddf6a..95cdd89cd 100644 --- a/src/Core/Animation/Animation.cpp +++ b/src/Core/Animation/Animation.cpp @@ -72,7 +72,10 @@ namespace obe::animation std::vector group_keys; group_keys.reserve(m_groups.size()); std::transform(m_groups.cbegin(), m_groups.cend(), group_keys.begin(), - [](const auto& pair) { return pair.first; }); + [](const auto& pair) + { + return pair.first; + }); return group_keys; } diff --git a/src/Core/Audio/Sound.cpp b/src/Core/Audio/Sound.cpp index 52b8d7a47..4532e8aad 100644 --- a/src/Core/Audio/Sound.cpp +++ b/src/Core/Audio/Sound.cpp @@ -118,7 +118,8 @@ namespace obe::audio } else { - m_handle = m_sound.m_manager.play(*m_sound.m_source, m_sound.m_source->mVolume, 0, true); + m_handle + = m_sound.m_manager.play(*m_sound.m_source, m_sound.m_source->mVolume, 0, true); this->apply_changes(); m_sound.m_manager.setPause(m_handle, false); } diff --git a/src/Core/Collision/ColliderComponent.cpp b/src/Core/Collision/ColliderComponent.cpp index 0bcbd830a..9a5852a8c 100644 --- a/src/Core/Collision/ColliderComponent.cpp +++ b/src/Core/Collision/ColliderComponent.cpp @@ -137,7 +137,8 @@ namespace obe::collision } std::visit( - [&collider_dump](auto&& collider) { + [&collider_dump](auto&& collider) + { const auto& position = collider.get_position(); const std::string& tag = collider.get_tag(); collider_dump.insert("x", position.x); @@ -183,7 +184,8 @@ namespace obe::collision throw exceptions::InvalidColliderComponentType(m_id, collider_type_str); } std::visit( - [this, x, y, tag](auto&& collider) { + [this, x, y, tag](auto&& collider) + { collider.set_position(transform::UnitVector(x, y, m_unit)); collider.set_tag(tag); }, @@ -219,14 +221,21 @@ namespace obe::collision Collider* ColliderComponent::get_inner_collider() { Collider* collider = std::visit( - [](auto& collider_variant) -> Collider* { return &collider_variant; }, m_collider); + [](auto& collider_variant) -> Collider* + { + return &collider_variant; + }, + m_collider); return collider; } const Collider* ColliderComponent::get_inner_collider() const { const Collider* collider = std::visit( - [](auto& collider_variant) -> const Collider* { return &collider_variant; }, + [](auto& collider_variant) -> const Collider* + { + return &collider_variant; + }, m_collider); return collider; } diff --git a/src/Core/Collision/CollisionSpace.cpp b/src/Core/Collision/CollisionSpace.cpp index 17610b6e8..faa03da43 100644 --- a/src/Core/Collision/CollisionSpace.cpp +++ b/src/Core/Collision/CollisionSpace.cpp @@ -32,7 +32,6 @@ namespace obe::collision const bool is_valid = (!check_both_directions || can_collide_with(collider2, collider1, false)); - // if true, check if we need to check for tags on collider2 -> collider1 return is_valid; } @@ -41,11 +40,8 @@ namespace obe::collision CollisionSpace::CollisionSpace() : m_quadtree( - transform::AABB( - transform::UnitVector(-COLLISION_SPACE_SIZE, -COLLISION_SPACE_SIZE), - transform::UnitVector(2 * COLLISION_SPACE_SIZE, 2 * COLLISION_SPACE_SIZE) - ) - ) + transform::AABB(transform::UnitVector(-COLLISION_SPACE_SIZE, -COLLISION_SPACE_SIZE), + transform::UnitVector(2 * COLLISION_SPACE_SIZE, 2 * COLLISION_SPACE_SIZE))) { } @@ -102,10 +98,11 @@ namespace obe::collision return false; } - transform::UnitVector CollisionSpace::get_offset_before_collision(const Collider& collider, - const transform::UnitVector& offset) const + transform::UnitVector CollisionSpace::get_offset_before_collision( + const Collider& collider, const transform::UnitVector& offset) const { - const std::vector reachable_colliders = this->get_reachable_colliders(collider, offset); + const std::vector reachable_colliders + = this->get_reachable_colliders(collider, offset); return this->get_offset_before_collision(collider, reachable_colliders, offset); } @@ -166,8 +163,8 @@ namespace obe::collision return reachable_colliders; } - void CollisionSpace::add_tag_to_blacklist(const std::string& source_tag, - const std::string& rejected_tag) + void CollisionSpace::add_tag_to_blacklist( + const std::string& source_tag, const std::string& rejected_tag) { if (!m_tags_blacklists.contains(source_tag)) { @@ -176,8 +173,8 @@ namespace obe::collision m_tags_blacklists.at(source_tag).insert(rejected_tag); } - void CollisionSpace::remove_tag_to_blacklist(const std::string& source_tag, - const std::string& rejected_tag) + void CollisionSpace::remove_tag_to_blacklist( + const std::string& source_tag, const std::string& rejected_tag) { if (m_tags_blacklists.contains(source_tag)) { diff --git a/src/Core/Collision/ComplexPolygonCollider.cpp b/src/Core/Collision/ComplexPolygonCollider.cpp index 3ad84c89a..d915c5389 100644 --- a/src/Core/Collision/ComplexPolygonCollider.cpp +++ b/src/Core/Collision/ComplexPolygonCollider.cpp @@ -166,7 +166,7 @@ namespace obe::collision transform::UnitVector min_dep; const auto calc_min_distance_dep = [this](const std::vector& sol1, const std::vector& sol2, - const transform::UnitVector& t_offset) + const transform::UnitVector& t_offset) -> std::tuple { double min_distance = -1; @@ -256,10 +256,15 @@ namespace obe::collision { // TODO: handle rotation auto [min_x, max_x] = std::minmax_element(m_points.begin(), m_points.end(), - [](auto& point1, auto& point2) { return point1.x < point2.x; }); - auto [min_y, max_y] - = std::minmax_element(m_points.begin(), m_points.end(), - [](auto& point1, auto& point2) { return point1.y < point2.y; }); + [](auto& point1, auto& point2) + { + return point1.x < point2.x; + }); + auto [min_y, max_y] = std::minmax_element(m_points.begin(), m_points.end(), + [](auto& point1, auto& point2) + { + return point1.y < point2.y; + }); const double width = max_x->x - min_x->x; const double height = max_y->y - min_y->y; return transform::AABB( diff --git a/src/Core/Collision/PolygonCollider.cpp b/src/Core/Collision/PolygonCollider.cpp index f6421d8a7..1ef7be4a7 100644 --- a/src/Core/Collision/PolygonCollider.cpp +++ b/src/Core/Collision/PolygonCollider.cpp @@ -55,10 +55,16 @@ namespace obe::collision const auto verts_span = std::span { m_shape.verts }; auto [min_x, max_x] = std::minmax_element(verts_span.begin(), verts_span.begin() + m_shape.count, - [](auto& point1, auto& point2) { return point1.x < point2.x; }); + [](auto& point1, auto& point2) + { + return point1.x < point2.x; + }); auto [min_y, max_y] = std::minmax_element(verts_span.begin(), verts_span.begin() + m_shape.count, - [](auto& point1, auto& point2) { return point1.y < point2.y; }); + [](auto& point1, auto& point2) + { + return point1.y < point2.y; + }); const double width = max_x->x - min_x->x; const double height = max_y->y - min_y->y; return transform::AABB( diff --git a/src/Core/Collision/Quadtree.cpp b/src/Core/Collision/Quadtree.cpp index 8ba05f19e..adbe6a1cc 100644 --- a/src/Core/Collision/Quadtree.cpp +++ b/src/Core/Collision/Quadtree.cpp @@ -147,8 +147,8 @@ namespace obe::collision auto i = get_quadrant(box, value->get_bounding_box()); if (i != -1) { - if (remove_internal(node->children[static_cast(i)].get(), compute_box(box, i), - value)) + if (remove_internal(node->children[static_cast(i)].get(), + compute_box(box, i), value)) return try_merge(node); } // Otherwise, we remove the value from the current node @@ -162,7 +162,10 @@ namespace obe::collision { // Find the value in node->values auto it = std::find_if(std::begin(node->values), std::end(node->values), - [this, &value](const auto& rhs) { return value == rhs; }); + [this, &value](const auto& rhs) + { + return value == rhs; + }); assert(it != std::end(node->values) && "Trying to remove a value that is not present in the node"); // Swap with the last element and pop back diff --git a/src/Core/Collision/TrajectoryNode.cpp b/src/Core/Collision/TrajectoryNode.cpp index 64d35eeaa..e900d3e25 100644 --- a/src/Core/Collision/TrajectoryNode.cpp +++ b/src/Core/Collision/TrajectoryNode.cpp @@ -57,7 +57,8 @@ namespace obe::collision void TrajectoryNode::update(const double dt) const { - auto get_offset = [&dt](const Trajectory& trajectory) { + auto get_offset = [&dt](const Trajectory& trajectory) + { const double speed = trajectory.get_speed() + trajectory.get_acceleration() * dt; const double rad_angle = (utils::math::pi / 180.0) * -trajectory.get_angle(); const double x_offset = std::cos(rad_angle) * (speed * dt); diff --git a/src/Core/Debug/Render.cpp b/src/Core/Debug/Render.cpp index 6671f5847..63dfe8c69 100644 --- a/src/Core/Debug/Render.cpp +++ b/src/Core/Debug/Render.cpp @@ -29,7 +29,10 @@ namespace obe::debug::render std::transform(polygon_points.begin(), polygon_points.end(), std::back_inserter(pixel_points), - [](const auto& point) { return point.to(transform::Units::ScenePixels); }); + [](const auto& point) + { + return point.to(transform::Units::ScenePixels); + }); for (const transform::UnitVector& point : pixel_points) { @@ -110,8 +113,8 @@ namespace obe::debug::render target.draw(shape); } - void draw_collider(const graphics::RenderTarget target, const collision::ColliderComponent& collider, - const ColliderRenderOptions& render_options) + void draw_collider(const graphics::RenderTarget target, + const collision::ColliderComponent& collider, const ColliderRenderOptions& render_options) { switch (collider.get_collider_type()) { @@ -119,7 +122,8 @@ namespace obe::debug::render break; case collision::ColliderType::Circle: draw_circle_collider(target, - *static_cast(collider.get_inner_collider()), render_options); + *static_cast(collider.get_inner_collider()), + render_options); break; case collision::ColliderType::Rectangle: draw_rectangle_collider(target, @@ -136,7 +140,7 @@ namespace obe::debug::render *static_cast(collider.get_inner_collider()), render_options); break; - default: ; + default:; } } } diff --git a/src/Core/Event/EventManager.cpp b/src/Core/Event/EventManager.cpp index 96e7214da..babf83dc2 100644 --- a/src/Core/Event/EventManager.cpp +++ b/src/Core/Event/EventManager.cpp @@ -23,9 +23,11 @@ namespace obe::event } } } - m_schedulers.erase( - std::remove_if(m_schedulers.begin(), m_schedulers.end(), - [](auto& scheduler) { return scheduler->m_state == CallbackSchedulerState::Done; }), + m_schedulers.erase(std::remove_if(m_schedulers.begin(), m_schedulers.end(), + [](auto& scheduler) + { + return scheduler->m_state == CallbackSchedulerState::Done; + }), m_schedulers.end()); } diff --git a/src/Core/Graphics/Canvas.cpp b/src/Core/Graphics/Canvas.cpp index 17bb47bdc..c9032539a 100644 --- a/src/Core/Graphics/Canvas.cpp +++ b/src/Core/Graphics/Canvas.cpp @@ -185,7 +185,10 @@ namespace obe::graphics::canvas void Canvas::sort_elements() { std::sort(m_elements.begin(), m_elements.end(), - [](const auto& elem1, const auto& elem2) { return elem1->layer > elem2->layer; }); + [](const auto& elem1, const auto& elem2) + { + return elem1->layer > elem2->layer; + }); } Canvas::Canvas(unsigned int width, unsigned int height) @@ -230,7 +233,11 @@ namespace obe::graphics::canvas void Canvas::remove(const std::string& id) { - std::erase_if(m_elements, [&id](auto& elem) { return elem->get_id() == id; }); + std::erase_if(m_elements, + [&id](auto& elem) + { + return elem->get_id() == id; + }); } Texture Canvas::get_texture() const diff --git a/src/Core/Graphics/Color.cpp b/src/Core/Graphics/Color.cpp index 627734cf3..5e16c47f6 100644 --- a/src/Core/Graphics/Color.cpp +++ b/src/Core/Graphics/Color.cpp @@ -322,7 +322,11 @@ namespace obe::graphics bool Color::from_name(std::string name, bool strict) { - std::for_each(name.begin(), name.end(), [](char& c) { c = std::tolower(c); }); + std::for_each(name.begin(), name.end(), + [](char& c) + { + c = std::tolower(c); + }); if (const auto& color = ColorNames.find(name); color != ColorNames.end()) { this->r = color->second.r; @@ -512,7 +516,10 @@ namespace obe::graphics std::optional Color::to_name() const { auto it = std::find_if(ColorNames.begin(), ColorNames.end(), - [this](const std::pair& color) { return color.second == *this; }); + [this](const std::pair& color) + { + return color.second == *this; + }); if (it != ColorNames.end()) { return it->first; diff --git a/src/Core/Graphics/NinePatch.cpp b/src/Core/Graphics/NinePatch.cpp index 191d34183..423be60b7 100644 --- a/src/Core/Graphics/NinePatch.cpp +++ b/src/Core/Graphics/NinePatch.cpp @@ -18,8 +18,7 @@ namespace obe::graphics { if (!found_start) { - if (image.getPixel(texture_rect.left + x, texture_rect.top) - == sf::Color::Black) + if (image.getPixel(texture_rect.left + x, texture_rect.top) == sf::Color::Black) { found_start = true; top_left.x = x - 1.f; @@ -29,8 +28,7 @@ namespace obe::graphics } if (found_start) { - if (image.getPixel(texture_rect.left + x, texture_rect.top) - == sf::Color::Black) + if (image.getPixel(texture_rect.left + x, texture_rect.top) == sf::Color::Black) bottom_right.x = x - 1.f; else break; @@ -42,8 +40,7 @@ namespace obe::graphics { if (!found_start) { - if (image.getPixel(texture_rect.left, texture_rect.top + y) - == sf::Color::Black) + if (image.getPixel(texture_rect.left, texture_rect.top + y) == sf::Color::Black) { found_start = true; top_left.y = y - 1.f; @@ -53,8 +50,7 @@ namespace obe::graphics } if (found_start) { - if (image.getPixel(texture_rect.left, texture_rect.top + y) - == sf::Color::Black) + if (image.getPixel(texture_rect.left, texture_rect.top + y) == sf::Color::Black) bottom_right.y = y - 1.f; else break; @@ -120,7 +116,6 @@ namespace obe::graphics } } - NinePatch::NinePatch() : m_vertices(36, sf::Vertex({ 0.f, 0.f })) , m_texture { nullptr } @@ -140,9 +135,9 @@ namespace obe::graphics m_texture = &texture; if (reset_rect) m_texture_rect = { { 0, 0 }, sf::Vector2i(m_texture->getSize()) }; - m_trimmed_size = sf::Vector2f { static_cast(m_texture_rect.width), - static_cast(m_texture_rect.height) } - - trim_amount * 2.f; + m_trimmed_size = sf::Vector2f { + static_cast(m_texture_rect.width), static_cast(m_texture_rect.height) + } - trim_amount * 2.f; if (reset_size) m_size = m_trimmed_size; extract_scale_positions_and_content_area_from_texture(m_texture, m_texture_rect, @@ -158,7 +153,8 @@ namespace obe::graphics void NinePatch::set_size(sf::Vector2f size) { m_size = size; - const sf::Vector2f minimum_size { m_scale_top_left + (m_trimmed_size - m_scale_bottom_right) }; + const sf::Vector2f minimum_size { m_scale_top_left + + (m_trimmed_size - m_scale_bottom_right) }; if (m_size.x < minimum_size.x) m_size.x = minimum_size.x; if (m_size.y < minimum_size.y) @@ -174,9 +170,9 @@ namespace obe::graphics void NinePatch::set_texture_rect(const sf::IntRect texture_rectangle, const bool reset_size) { m_texture_rect = texture_rectangle; - m_trimmed_size = sf::Vector2f { static_cast(m_texture_rect.width), - static_cast(m_texture_rect.height) } - - trim_amount * 2.f; + m_trimmed_size = sf::Vector2f { + static_cast(m_texture_rect.width), static_cast(m_texture_rect.height) + } - trim_amount * 2.f; if (reset_size) m_size = m_trimmed_size; if (m_texture != nullptr) @@ -203,7 +199,6 @@ namespace obe::graphics return m_size; } - sf::FloatRect NinePatch::getLocalBounds() const { return { { 0.f, 0.f }, m_size }; @@ -249,7 +244,8 @@ namespace obe::graphics void NinePatch::update_vertices_positions() { - const sf::Vector2f new_bottom_right_scaled { m_size - (m_trimmed_size - m_scale_bottom_right) }; + const sf::Vector2f new_bottom_right_scaled { m_size + - (m_trimmed_size - m_scale_bottom_right) }; // top row m_vertices[0].position = { 0.f, 0.f }; @@ -359,27 +355,27 @@ namespace obe::graphics vertex.texCoords += texture_rectangle_offset + trim_amount; } - sf::Vector2f NinePatch::get_resulting_position_of_texture_coord(sf::Vector2f texture_coord) const + sf::Vector2f NinePatch::get_resulting_position_of_texture_coord( + sf::Vector2f texture_coord) const { sf::Vector2f result; - const sf::Vector2f new_bottom_right_scaled { m_size - (m_trimmed_size - m_scale_bottom_right) }; + const sf::Vector2f new_bottom_right_scaled { m_size + - (m_trimmed_size - m_scale_bottom_right) }; const sf::Vector2f scale_size { m_scale_bottom_right - m_scale_top_left }; const sf::Vector2f new_scale_size { new_bottom_right_scaled - m_scale_top_left }; if (texture_coord.x <= m_scale_top_left.x) result.x = texture_coord.x; else if (texture_coord.x >= m_scale_bottom_right.x) - result.x = new_bottom_right_scaled.x - + (texture_coord.x - m_scale_bottom_right.x); + result.x = new_bottom_right_scaled.x + (texture_coord.x - m_scale_bottom_right.x); else result.x = ((texture_coord.x - m_scale_top_left.x) / scale_size.x) * new_scale_size.x + m_scale_top_left.x; if (texture_coord.y <= m_scale_top_left.y) result.y = texture_coord.y; else if (texture_coord.y >= m_scale_bottom_right.y) - result.y = new_bottom_right_scaled.y - + (texture_coord.y - m_scale_bottom_right.y); + result.y = new_bottom_right_scaled.y + (texture_coord.y - m_scale_bottom_right.y); else result.y = ((texture_coord.y - m_scale_top_left.y) / (scale_size.y)) * new_scale_size.y + m_scale_top_left.y; diff --git a/src/Core/Graphics/PositionTransformers.cpp b/src/Core/Graphics/PositionTransformers.cpp index 5892565df..463d24218 100644 --- a/src/Core/Graphics/PositionTransformers.cpp +++ b/src/Core/Graphics/PositionTransformers.cpp @@ -4,13 +4,18 @@ namespace obe::graphics { std::map Transformers; - CoordinateTransformer Parallax = [](double pos, double cam, int layer) -> double { + CoordinateTransformer Parallax = [](double pos, double cam, int layer) -> double + { return (pos * layer - cam) / static_cast(layer); }; - CoordinateTransformer Camera - = [](double pos, double cam, int layer) -> double { return pos - cam; }; - CoordinateTransformer Position - = [](double pos, double cam, int layer) -> double { return pos; }; + CoordinateTransformer Camera = [](double pos, double cam, int layer) -> double + { + return pos - cam; + }; + CoordinateTransformer Position = [](double pos, double cam, int layer) -> double + { + return pos; + }; PositionTransformer::PositionTransformer() { diff --git a/src/Core/Graphics/Sprite.cpp b/src/Core/Graphics/Sprite.cpp index bf43c41ad..6f36524c1 100644 --- a/src/Core/Graphics/Sprite.cpp +++ b/src/Core/Graphics/Sprite.cpp @@ -45,11 +45,13 @@ namespace obe::graphics { m_sprite.setTextureRect(sf::IntRect(0, 0, px_size.x, px_size.y)); const auto [min_vx, max_vx] = std::minmax_element(vertices.begin(), vertices.end(), - [](const sf::Vertex& vert1, const sf::Vertex& vert2) -> float { + [](const sf::Vertex& vert1, const sf::Vertex& vert2) -> float + { return vert1.position.x < vert2.position.x; }); const auto [min_vy, max_vy] = std::minmax_element(vertices.begin(), vertices.end(), - [](const sf::Vertex& vert1, const sf::Vertex& vert2) -> float { + [](const sf::Vertex& vert1, const sf::Vertex& vert2) -> float + { return vert1.position.y < vert2.position.y; }); const float min_x = min_vx->position.x; @@ -156,11 +158,12 @@ namespace obe::graphics m_horizontal_flip = horizontally; m_vertical_flip = vertically; sf::IntRect texture_rect = m_sprite.getTextureRect(); - sf::IntRect normalized_texture_rect( - texture_rect.width < 0 ? texture_rect.left - std::abs(texture_rect.width) : texture_rect.left, - texture_rect.height < 0 ? texture_rect.top - std::abs(texture_rect.height) : texture_rect.top, - std::abs(texture_rect.width), std::abs(texture_rect.height) - ); + sf::IntRect normalized_texture_rect(texture_rect.width < 0 + ? texture_rect.left - std::abs(texture_rect.width) + : texture_rect.left, + texture_rect.height < 0 ? texture_rect.top - std::abs(texture_rect.height) + : texture_rect.top, + std::abs(texture_rect.width), std::abs(texture_rect.height)); this->set_texture_rect(normalized_texture_rect.left, normalized_texture_rect.top, normalized_texture_rect.width, normalized_texture_rect.height); } @@ -203,13 +206,8 @@ namespace obe::graphics unsigned int x, unsigned int y, unsigned int width, unsigned int height) { m_sprite.setTextureRect( - sf::IntRect( - m_horizontal_flip ? x + width : x, - m_vertical_flip ? y + height : y, - m_horizontal_flip ? -width : width, - m_vertical_flip ? -height : height - ) - ); + sf::IntRect(m_horizontal_flip ? x + width : x, m_vertical_flip ? y + height : y, + m_horizontal_flip ? -width : width, m_vertical_flip ? -height : height)); } void Sprite::set_texture(const TexturePart& texture) diff --git a/src/Core/Graphics/Spritesheet.cpp b/src/Core/Graphics/Spritesheet.cpp index e90523c6b..ee5896e6f 100644 --- a/src/Core/Graphics/Spritesheet.cpp +++ b/src/Core/Graphics/Spritesheet.cpp @@ -14,6 +14,7 @@ namespace obe::graphics const vili::node& Spritesheet::Schema() { + // clang-format off static const vili::node schema = vili::object { { "type", vili::object_typename }, { "properties", vili::object { @@ -42,6 +43,7 @@ namespace obe::graphics }} }} }; + // clang-format on return schema; } @@ -62,7 +64,8 @@ namespace obe::graphics { transform::UnitVector frame_texture_rect_position(frame.at("x"), frame.at("y")); transform::UnitVector frame_texture_rect_size(frame.at("width"), frame.at("height")); - m_frames.push_back(transform::AABB(frame_texture_rect_position, frame_texture_rect_size)); + m_frames.push_back( + transform::AABB(frame_texture_rect_position, frame_texture_rect_size)); } } diff --git a/src/Core/Graphics/Texture.cpp b/src/Core/Graphics/Texture.cpp index 9460c3e47..8a6f3c092 100644 --- a/src/Core/Graphics/Texture.cpp +++ b/src/Core/Graphics/Texture.cpp @@ -110,24 +110,44 @@ namespace obe::graphics sf::Texture& Texture::get_mutable_texture() { - constexpr static obe::utils::Visitor visitor { [](sf::Texture& texture) -> sf::Texture& { - return texture; - }, - [](std::shared_ptr& texture) -> sf::Texture& { return *texture; }, - [](const sf::Texture*) -> sf::Texture& { throw exceptions::ReadOnlyTexture("create"); }, - [](SvgTexture& texture) -> sf::Texture& { return texture.get_texture(); } }; + constexpr static obe::utils::Visitor visitor { [](sf::Texture& texture) -> sf::Texture& + { + return texture; + }, + [](std::shared_ptr& texture) -> sf::Texture& + { + return *texture; + }, + [](const sf::Texture*) -> sf::Texture& + { + throw exceptions::ReadOnlyTexture("create"); + }, + [](SvgTexture& texture) -> sf::Texture& + { + return texture.get_texture(); + } }; return std::visit(visitor, m_texture); } const sf::Texture& Texture::get_texture() const { constexpr static obe::utils::Visitor visitor { - [](const sf::Texture& texture) -> const sf::Texture& { return texture; }, - [](const std::shared_ptr& texture) -> const sf::Texture& { + [](const sf::Texture& texture) -> const sf::Texture& + { + return texture; + }, + [](const std::shared_ptr& texture) -> const sf::Texture& + { + return *texture; + }, + [](const sf::Texture* texture) -> const sf::Texture& + { return *texture; }, - [](const sf::Texture* texture) -> const sf::Texture& { return *texture; }, - [](const SvgTexture& texture) -> const sf::Texture& { return texture.get_texture(); } + [](const SvgTexture& texture) -> const sf::Texture& + { + return texture.get_texture(); + } }; return std::visit(visitor, m_texture); } diff --git a/src/Core/Input/InputButtonMonitor.cpp b/src/Core/Input/InputButtonMonitor.cpp index a1e0c0404..a1320f61b 100644 --- a/src/Core/Input/InputButtonMonitor.cpp +++ b/src/Core/Input/InputButtonMonitor.cpp @@ -53,8 +53,8 @@ namespace obe::input if (old_state != m_button_state) { m_should_refresh = true; - events->trigger( - m_input_source.get_name(), events::Keys::StateChanged { m_button_state, old_state, m_input_source }); + events->trigger(m_input_source.get_name(), + events::Keys::StateChanged { m_button_state, old_state, m_input_source }); } } diff --git a/src/Core/Input/InputInitializer.cpp b/src/Core/Input/InputInitializer.cpp index ed414c6a4..82148181b 100644 --- a/src/Core/Input/InputInitializer.cpp +++ b/src/Core/Input/InputInitializer.cpp @@ -10,7 +10,11 @@ namespace obe::input void InputManager::create_input_map() { // Gamepad - std::thread gamepad_loader_thr([this]() { this->initialize_gamepads(); }); + std::thread gamepad_loader_thr( + [this]() + { + this->initialize_gamepads(); + }); // Letters m_inputs["A"] = std::make_unique(sf::Keyboard::A, "A"); @@ -88,24 +92,27 @@ namespace obe::input m_inputs["MouseButtonLeft"] = std::make_unique(sf::Mouse::Left); m_inputs["MouseButtonRight"] = std::make_unique(sf::Mouse::Right); m_inputs["MouseButtonMiddle"] = std::make_unique(sf::Mouse::Middle); - m_inputs["MouseButtonXButton1"] = std::make_unique(sf::Mouse::XButton1); - m_inputs["MouseButtonXButton2"] = std::make_unique(sf::Mouse::XButton2); + m_inputs["MouseButtonXButton1"] + = std::make_unique(sf::Mouse::XButton1); + m_inputs["MouseButtonXButton2"] + = std::make_unique(sf::Mouse::XButton2); // Scroll Wheel - m_inputs["MouseWheelScrollLeft"] = std::make_unique( - input::MouseWheelScrollDirection::Left); - m_inputs["MouseWheelScrollRight"] - = std::make_unique( + m_inputs["MouseWheelScrollLeft"] + = std::make_unique(input::MouseWheelScrollDirection::Left); + m_inputs["MouseWheelScrollRight"] = std::make_unique( input::MouseWheelScrollDirection::Right); - m_inputs["MouseWheelScrollUp"] = std::make_unique( - input::MouseWheelScrollDirection::Up); - m_inputs["MouseWheelScrollDown"] = std::make_unique( - input::MouseWheelScrollDirection::Down); + m_inputs["MouseWheelScrollUp"] + = std::make_unique(input::MouseWheelScrollDirection::Up); + m_inputs["MouseWheelScrollDown"] + = std::make_unique(input::MouseWheelScrollDirection::Down); // Others m_inputs["Add"] = std::make_unique(sf::Keyboard::Add, "+"); - m_inputs["Backslash"] = std::make_unique(sf::Keyboard::BackSlash, "\\"); - m_inputs["Backspace"] = std::make_unique(sf::Keyboard::BackSpace, ""); + m_inputs["Backslash"] + = std::make_unique(sf::Keyboard::BackSlash, "\\"); + m_inputs["Backspace"] + = std::make_unique(sf::Keyboard::BackSpace, ""); m_inputs["Comma"] = std::make_unique(sf::Keyboard::Comma, ","); m_inputs["Dash"] = std::make_unique(sf::Keyboard::Dash, "-"); m_inputs["Delete"] = std::make_unique(sf::Keyboard::Delete, ""); @@ -116,26 +123,31 @@ namespace obe::input m_inputs["Home"] = std::make_unique(sf::Keyboard::Home, ""); m_inputs["Insert"] = std::make_unique(sf::Keyboard::Insert, ""); m_inputs["LAlt"] = std::make_unique(sf::Keyboard::LAlt, ""); - m_inputs["LBracket"] = std::make_unique(sf::Keyboard::LBracket, "["); + m_inputs["LBracket"] + = std::make_unique(sf::Keyboard::LBracket, "["); m_inputs["LControl"] = std::make_unique(sf::Keyboard::LControl, ""); m_inputs["LShift"] = std::make_unique(sf::Keyboard::LShift, ""); m_inputs["Menu"] = std::make_unique(sf::Keyboard::Menu, ""); - m_inputs["Multiply"] = std::make_unique(sf::Keyboard::Multiply, "*"); + m_inputs["Multiply"] + = std::make_unique(sf::Keyboard::Multiply, "*"); m_inputs["PageDown"] = std::make_unique(sf::Keyboard::PageDown, ""); m_inputs["PageUp"] = std::make_unique(sf::Keyboard::PageUp, ""); m_inputs["Pause"] = std::make_unique(sf::Keyboard::Pause, ""); m_inputs["Period"] = std::make_unique(sf::Keyboard::Period, "."); m_inputs["Quote"] = std::make_unique(sf::Keyboard::Quote, ""); m_inputs["RAlt"] = std::make_unique(sf::Keyboard::RAlt, ""); - m_inputs["RBracket"] = std::make_unique(sf::Keyboard::RBracket, "]"); + m_inputs["RBracket"] + = std::make_unique(sf::Keyboard::RBracket, "]"); m_inputs["RControl"] = std::make_unique(sf::Keyboard::RControl, ""); m_inputs["Return"] = std::make_unique(sf::Keyboard::Return, ""); m_inputs["RShift"] = std::make_unique(sf::Keyboard::RShift, ""); m_inputs["RSystem"] = std::make_unique(sf::Keyboard::RSystem, ""); - m_inputs["Semicolon"] = std::make_unique(sf::Keyboard::SemiColon, ";"); + m_inputs["Semicolon"] + = std::make_unique(sf::Keyboard::SemiColon, ";"); m_inputs["Slash"] = std::make_unique(sf::Keyboard::Slash, "/"); m_inputs["Space"] = std::make_unique(sf::Keyboard::Space, " "); - m_inputs["Subtract"] = std::make_unique(sf::Keyboard::Subtract, "-"); + m_inputs["Subtract"] + = std::make_unique(sf::Keyboard::Subtract, "-"); m_inputs["Tab"] = std::make_unique(sf::Keyboard::Tab, " "); m_inputs["Tilde"] = std::make_unique(sf::Keyboard::Tilde, "~"); gamepad_loader_thr.join(); @@ -154,7 +166,9 @@ namespace obe::input button_count = sf::Joystick::getButtonCount(gamepad_index); } - auto set_or_reset_button = [this] (const std::string& name, const InputSourceGamepadButton& button) { + auto set_or_reset_button + = [this](const std::string& name, const InputSourceGamepadButton& button) + { if (!m_inputs.contains(name)) { m_inputs[name] = std::make_unique(button); @@ -164,8 +178,7 @@ namespace obe::input *m_inputs.at(name) = button; } }; - auto set_or_reset_axis - = [this](const std::string& name, const InputSourceGamepadAxis& axis) + auto set_or_reset_axis = [this](const std::string& name, const InputSourceGamepadAxis& axis) { if (!m_inputs.contains(name)) { @@ -187,8 +200,8 @@ namespace obe::input auto add_horizontal_axis = [&gamepad_index, use_every_axis, set_or_reset_axis, this]( - sf::Joystick::Axis axis, const std::string& axis_name, - bool invert_axis = false) { + sf::Joystick::Axis axis, const std::string& axis_name, bool invert_axis = false) + { if (use_every_axis || sf::Joystick::hasAxis(gamepad_index, axis)) { const std::string gamepad_axis_name @@ -199,16 +212,16 @@ namespace obe::input = (!invert_axis) ? gamepad_axis_name + "_LEFT" : gamepad_axis_name + "_RIGHT"; const std::string right_axis_name = (!invert_axis) ? gamepad_axis_name + "_RIGHT" : gamepad_axis_name + "_LEFT"; - set_or_reset_axis( - left_axis_name, InputSourceGamepadAxis(gamepad_index, axis, left_x, left_axis_name)); - set_or_reset_axis( - right_axis_name, InputSourceGamepadAxis(gamepad_index, axis, right_x, right_axis_name)); + set_or_reset_axis(left_axis_name, + InputSourceGamepadAxis(gamepad_index, axis, left_x, left_axis_name)); + set_or_reset_axis(right_axis_name, + InputSourceGamepadAxis(gamepad_index, axis, right_x, right_axis_name)); } }; auto add_vertical_axis = [&gamepad_index, use_every_axis, set_or_reset_axis, this]( - sf::Joystick::Axis axis, const std::string& axis_name, - bool invert_axis = false) { + sf::Joystick::Axis axis, const std::string& axis_name, bool invert_axis = false) + { if (use_every_axis || sf::Joystick::hasAxis(gamepad_index, axis)) { const std::string gamepad_axis_name diff --git a/src/Core/Input/InputManager.cpp b/src/Core/Input/InputManager.cpp index 59c722363..7e6d1908c 100644 --- a/src/Core/Input/InputManager.cpp +++ b/src/Core/Input/InputManager.cpp @@ -82,9 +82,11 @@ namespace obe::input break; } } - std::erase_if(m_monitors, [this](const std::weak_ptr& element) { - return update_or_clean_monitor(e_keys, element); - }); + std::erase_if(m_monitors, + [this](const std::weak_ptr& element) + { + return update_or_clean_monitor(e_keys, element); + }); for (const auto& monitor_ptr : m_monitors) { if (const auto& monitor = monitor_ptr.lock()) @@ -138,7 +140,8 @@ namespace obe::input this->get_action(action_name).clear_conditions(); } auto input_condition = [this](const InputManager* input_manager, - const std::string& action, vili::node& condition) { + const std::string& action, vili::node& condition) + { InputCondition action_condition; InputCombination combination; try @@ -210,7 +213,8 @@ namespace obe::input // Multiple context, keep which one, remove keys of wrong // context m_current_actions.erase(std::remove_if(m_current_actions.begin(), m_current_actions.end(), - [&context](auto& action) -> bool { + [&context](auto& action) -> bool + { const auto& contexts = action->get_contexts(); auto is_action_in_context = std::find(contexts.begin(), contexts.end(), context) @@ -422,15 +426,19 @@ namespace obe::input { e_keys->add(input_source->get_name()); e_keys->on_add_listener(input_source->get_name(), - [input_source, this](event::ListenerChangeState, const std::string&) { + [input_source, this](event::ListenerChangeState, const std::string&) + { m_key_monitors.push_back(this->monitor(*input_source)); }); e_keys->on_remove_listener(input_source->get_name(), - [input_source, this](event::ListenerChangeState, const std::string&) { - const auto position = std::find_if(m_key_monitors.begin(), - m_key_monitors.end(), [input_source](const auto& monitor) { - return &monitor->get_input_source() == input_source; - }); + [input_source, this](event::ListenerChangeState, const std::string&) + { + const auto position + = std::find_if(m_key_monitors.begin(), m_key_monitors.end(), + [input_source](const auto& monitor) + { + return &monitor->get_input_source() == input_source; + }); if (position != m_key_monitors.end()) m_key_monitors.erase(position); }); diff --git a/src/Core/Input/InputSourceKeyboard.cpp b/src/Core/Input/InputSourceKeyboard.cpp index 1906a0970..188cd5da3 100644 --- a/src/Core/Input/InputSourceKeyboard.cpp +++ b/src/Core/Input/InputSourceKeyboard.cpp @@ -9,8 +9,8 @@ namespace obe::input { } - InputSourceKeyboardKey::InputSourceKeyboardKey(sf::Keyboard::Key key, const std::string& name, - const std::string& printable_char) + InputSourceKeyboardKey::InputSourceKeyboardKey( + sf::Keyboard::Key key, const std::string& name, const std::string& printable_char) : InputSource(name, printable_char) , m_key(key) { diff --git a/src/Core/Input/InputSourceMouse.cpp b/src/Core/Input/InputSourceMouse.cpp index 30dad2e1f..9ce68d446 100644 --- a/src/Core/Input/InputSourceMouse.cpp +++ b/src/Core/Input/InputSourceMouse.cpp @@ -8,7 +8,6 @@ namespace obe::input : InputSource(fmt::format("MouseButton{}", magic_enum::enum_name(button).data()), "") , m_button(button) { - } sf::Mouse::Button InputSourceMouseButton::get_mouse_button() const @@ -28,7 +27,8 @@ namespace obe::input InputSourceMouseWheelScroll::InputSourceMouseWheelScroll( MouseWheelScrollDirection direction, float threshold) - : InputSource(fmt::format("MouseWheelScroll{}", magic_enum::enum_name(direction).data()), "") + : InputSource( + fmt::format("MouseWheelScroll{}", magic_enum::enum_name(direction).data()), "") , m_direction(direction) , m_threshold(threshold) { diff --git a/src/Core/ObEngineCore.cpp b/src/Core/ObEngineCore.cpp index 2daaba1d3..a68c4a331 100644 --- a/src/Core/ObEngineCore.cpp +++ b/src/Core/ObEngineCore.cpp @@ -9,7 +9,8 @@ namespace obe { - void init_engine(unsigned int surface_width, unsigned int surface_height, const vili::node& arguments) + void init_engine( + unsigned int surface_width, unsigned int surface_height, const vili::node& arguments) { debug::Log->info("Using ObEngineCore (Version : {} ({}:{}))", config::OBENGINE_VERSION, config::OBENGINE_GIT_BRANCH, config::OBENGINE_GIT_HASH); diff --git a/src/Core/Scene/Scene.cpp b/src/Core/Scene/Scene.cpp index 0c8a44311..3e4d897a5 100644 --- a/src/Core/Scene/Scene.cpp +++ b/src/Core/Scene/Scene.cpp @@ -21,7 +21,8 @@ namespace obe::scene } std::sort(m_render_cache.begin(), m_render_cache.end(), - [](const auto& renderable1, const auto& renderable2) { + [](const auto& renderable1, const auto& renderable2) + { if (renderable1->get_layer() == renderable2->get_layer()) { return renderable1->get_sublayer() > renderable2->get_sublayer(); @@ -205,19 +206,25 @@ namespace obe::scene } debug::Log->debug(" Cleaning GameObject Array"); std::erase_if(m_game_object_array, - [](const std::unique_ptr& ptr) { return (!ptr->is_permanent()); }); + [](const std::unique_ptr& ptr) + { + return (!ptr->is_permanent()); + }); // Required for the next does_game_object_exists this->_rebuild_ids(); debug::Log->debug(" Cleaning Sprite Array"); - std::erase_if(m_sprite_array, [this](const std::unique_ptr& ptr) { - if (!ptr->get_parent_id().empty() - && this->does_game_object_exists(ptr->get_parent_id())) - return false; - return true; - }); + std::erase_if(m_sprite_array, + [this](const std::unique_ptr& ptr) + { + if (!ptr->get_parent_id().empty() + && this->does_game_object_exists(ptr->get_parent_id())) + return false; + return true; + }); debug::Log->debug(" Cleaning Collider Array"); - std::erase_if( - m_collider_array, [this](const std::unique_ptr& ptr) { + std::erase_if(m_collider_array, + [this](const std::unique_ptr& ptr) + { for (const auto& game_object : m_game_object_array) { if (game_object->is_parent_of_component(ptr->get_unique_id())) @@ -489,8 +496,9 @@ namespace obe::scene if (!game_object.deletable) game_object.update(); } - std::erase_if( - m_game_object_array, [this](const std::unique_ptr& ptr) { + std::erase_if(m_game_object_array, + [this](const std::unique_ptr& ptr) + { if (ptr->deletable) { m_game_object_ids.erase(ptr->get_id()); @@ -613,9 +621,11 @@ namespace obe::scene void Scene::remove_game_object(const std::string& id) { - std::erase_if(m_game_object_array, [&id](const std::unique_ptr& ptr) { - return (ptr->get_id() == id); - }); + std::erase_if(m_game_object_array, + [&id](const std::unique_ptr& ptr) + { + return (ptr->get_id() == id); + }); m_game_object_ids.erase(id); } @@ -755,9 +765,11 @@ namespace obe::scene void Scene::remove_sprite(const std::string& id) { debug::Log->debug(" Removing Sprite {0}", id); - std::erase_if(m_sprite_array, [&id](const std::unique_ptr& sprite) { - return (sprite->get_id() == id); - }); + std::erase_if(m_sprite_array, + [&id](const std::unique_ptr& sprite) + { + return (sprite->get_id() == id); + }); m_sprite_ids.erase(id); } @@ -834,7 +846,8 @@ namespace obe::scene void Scene::remove_collider(const std::string& id) { const auto collider_it = std::find_if(m_collider_array.begin(), m_collider_array.end(), - [&id](const std::unique_ptr& collider) { + [&id](const std::unique_ptr& collider) + { return (collider->get_id() == id); }); m_collision_space.remove_collider(collider_it->get()->get_inner_collider()); diff --git a/src/Core/Script/ViliLuaBridge.cpp b/src/Core/Script/ViliLuaBridge.cpp index afd6bf1f9..d67f2afac 100644 --- a/src/Core/Script/ViliLuaBridge.cpp +++ b/src/Core/Script/ViliLuaBridge.cpp @@ -27,7 +27,8 @@ namespace obe::script::vili_lua_bridge vili::integer expect = 1; for (auto& [k, _] : convert.as()) { - if (!k.is() || (k.is() && (k.as() != expect++))) + if (!k.is() + || (k.is() && (k.as() != expect++))) { return lua_table_to_vili_object(convert); } diff --git a/src/Core/System/Cursor.cpp b/src/Core/System/Cursor.cpp index 884ba3f90..83677c640 100644 --- a/src/Core/System/Cursor.cpp +++ b/src/Core/System/Cursor.cpp @@ -7,8 +7,10 @@ namespace obe::system { namespace constraints { - std::function(Cursor*)> Default - = [](Cursor* cursor) { return std::pair(cursor->get_x(), cursor->get_y()); }; + std::function(Cursor*)> Default = [](Cursor* cursor) + { + return std::pair(cursor->get_x(), cursor->get_y()); + }; } std::string MouseButtonToString(const sf::Mouse::Button button) @@ -28,7 +30,10 @@ namespace obe::system , e_cursor(event_namespace.create_group("Cursor")) , m_constraint(constraints::Default) { - m_constraint_condition = []() { return true; }; + m_constraint_condition = []() + { + return true; + }; m_button_state[sf::Mouse::Button::Left] = sf::Mouse::isButtonPressed(sf::Mouse::Button::Left); diff --git a/src/Core/System/MountablePath.cpp b/src/Core/System/MountablePath.cpp index 90f56911e..8ae339548 100644 --- a/src/Core/System/MountablePath.cpp +++ b/src/Core/System/MountablePath.cpp @@ -226,7 +226,10 @@ namespace obe::system { throw exceptions::InvalidDeferredMountablePath(path.prefix); } - auto path_cmp = [&path](const auto& mounted_path) { return path == *mounted_path; }; + auto path_cmp = [&path](const auto& mounted_path) + { + return path == *mounted_path; + }; const bool path_already_exists = std::find_if(MountedPaths.begin(), MountedPaths.end(), path_cmp) != MountedPaths.end(); @@ -239,9 +242,11 @@ namespace obe::system } if (same_prefix_policy == SamePrefixPolicy::Replace) { - std::erase_if(MountedPaths, [path](const auto& mountable_path) { - return mountable_path->prefix == path.prefix; - }); + std::erase_if(MountedPaths, + [path](const auto& mountable_path) + { + return mountable_path->prefix == path.prefix; + }); MountedPaths.push_back(std::make_shared(path)); } if (same_prefix_policy != SamePrefixPolicy::Skip) @@ -250,8 +255,9 @@ namespace obe::system } else { - const auto existing_prefix_it = std::find_if( - MountedPaths.begin(), MountedPaths.end(), [path](const auto& mountable_path) { + const auto existing_prefix_it = std::find_if(MountedPaths.begin(), MountedPaths.end(), + [path](const auto& mountable_path) + { return mountable_path->prefix == path.prefix; }); if (existing_prefix_it == MountedPaths.end()) @@ -264,8 +270,11 @@ namespace obe::system void MountablePath::unmount(const MountablePath path) { - std::erase_if( - MountedPaths, [path](const auto& mountable_path) { return *mountable_path == path; }); + std::erase_if(MountedPaths, + [path](const auto& mountable_path) + { + return *mountable_path == path; + }); } void MountablePath::unmount_all() @@ -291,8 +300,9 @@ namespace obe::system void MountablePath::sort() { - std::sort( - MountedPaths.begin(), MountedPaths.end(), [](const auto& first, const auto& second) { + std::sort(MountedPaths.begin(), MountedPaths.end(), + [](const auto& first, const auto& second) + { return first->priority > second->priority; }); } @@ -315,7 +325,10 @@ namespace obe::system std::vector all_prefixes; all_prefixes.reserve(mounts.size()); std::transform(mounts.begin(), mounts.end(), std::back_inserter(all_prefixes), - [](const auto& mount) { return mount->prefix; }); + [](const auto& mount) + { + return mount->prefix; + }); return all_prefixes; } diff --git a/src/Core/System/Path.cpp b/src/Core/System/Path.cpp index c195ee9cb..7a1bf3257 100644 --- a/src/Core/System/Path.cpp +++ b/src/Core/System/Path.cpp @@ -40,7 +40,10 @@ namespace obe::system std::vector all_prefixes; all_prefixes.reserve(mounts.size()); std::transform(mounts.begin(), mounts.end(), std::back_inserter(all_prefixes), - [](const auto& mount) { return mount->prefix; }); + [](const auto& mount) + { + return mount->prefix; + }); throw exceptions::UnknownPathPrefix(prefix, all_prefixes); } return valid_mounts; @@ -54,7 +57,8 @@ namespace obe::system { std::vector mounts_as_strings; std::transform(m_mounts.begin(), m_mounts.end(), std::back_inserter(mounts_as_strings), - [](const auto& mount) { + [](const auto& mount) + { return fmt::format("\"{}:// = {}\"", mount->prefix, mount->base_path); }); std::string path_type; diff --git a/src/Core/System/Window.cpp b/src/Core/System/Window.cpp index e174cbe95..f3dc052b2 100644 --- a/src/Core/System/Window.cpp +++ b/src/Core/System/Window.cpp @@ -15,7 +15,9 @@ namespace obe::system const float f_render_height = static_cast(m_render_height); if (m_width != m_render_width || m_height != m_render_height) { - if (m_stretch == StretchMode::None) { } + if (m_stretch == StretchMode::None) + { + } else if (m_stretch == StretchMode::Center) { m_view.setSize(f_render_width, f_render_height); diff --git a/src/Core/Tiles/Animation.cpp b/src/Core/Tiles/Animation.cpp index eaffb481a..6b5fb101d 100644 --- a/src/Core/Tiles/Animation.cpp +++ b/src/Core/Tiles/Animation.cpp @@ -52,7 +52,10 @@ namespace obe::tiles void AnimatedTile::detach_quad(sf::Vertex* quad) { std::erase_if(m_quads, - [&quad](const std::pair& item) { return item.first == quad; }); + [&quad](const std::pair& item) + { + return item.first == quad; + }); } void AnimatedTile::start() diff --git a/src/Core/Tiles/Scene.cpp b/src/Core/Tiles/Scene.cpp index a108b74cc..9d6d69262 100644 --- a/src/Core/Tiles/Scene.cpp +++ b/src/Core/Tiles/Scene.cpp @@ -149,7 +149,10 @@ namespace obe::tiles { std::vector layers; std::transform(m_layers.begin(), m_layers.end(), std::back_inserter(layers), - [](const auto& layer) { return layer.get(); }); + [](const auto& layer) + { + return layer.get(); + }); return layers; } diff --git a/src/Core/Tiles/Tileset.cpp b/src/Core/Tiles/Tileset.cpp index f2cb4b30f..a23a2b5b2 100644 --- a/src/Core/Tiles/Tileset.cpp +++ b/src/Core/Tiles/Tileset.cpp @@ -87,7 +87,8 @@ namespace obe::tiles m_tilesets.push_back( std::make_unique(id, first_tile_id, count, source, columns, width, height)); std::sort(m_tilesets.begin(), m_tilesets.end(), - [](const std::unique_ptr& tileset1, const std::unique_ptr& tileset2) { + [](const std::unique_ptr& tileset1, const std::unique_ptr& tileset2) + { return tileset1->get_first_tile_id() > tileset2->get_first_tile_id(); }); } diff --git a/src/Core/Transform/Polygon.cpp b/src/Core/Transform/Polygon.cpp index 36828fc49..964d8e2d2 100644 --- a/src/Core/Transform/Polygon.cpp +++ b/src/Core/Transform/Polygon.cpp @@ -164,38 +164,39 @@ namespace obe::transform const transform::UnitVector p3 = position.to(); constexpr auto distance_line_from_point = [](const transform::UnitVector& point, const transform::UnitVector& line_p1, - const transform::UnitVector& line_p2) { - transform::UnitVector line_diff = line_p2 - line_p1; - if (line_diff.x == 0 && line_diff.y == 0) - { - line_diff = point - line_p1; - return sqrt(line_diff.x * line_diff.x + line_diff.y * line_diff.y); - } - - const double t - = ((point.x - line_p1.x) * line_diff.x + (point.y - line_p1.y) * line_diff.y) - / (line_diff.x * line_diff.x + line_diff.y * line_diff.y); - - if (t < 0) - { - // point is nearest to the first point i.e x1 and y1 - line_diff = point - line_p1; - } - else if (t > 1) - { - // point is nearest to the end point i.e x2 and y2 - line_diff = point - line_p2; - } - else - { - // if perpendicular line intersect the line segment. - line_diff.x = point.x - (line_p1.x + t * line_diff.x); - line_diff.y = point.y - (line_p1.y + t * line_diff.y); - } - - // returning shortest distance - return sqrt(line_diff.x * line_diff.x + line_diff.y * line_diff.y); - }; + const transform::UnitVector& line_p2) + { + transform::UnitVector line_diff = line_p2 - line_p1; + if (line_diff.x == 0 && line_diff.y == 0) + { + line_diff = point - line_p1; + return sqrt(line_diff.x * line_diff.x + line_diff.y * line_diff.y); + } + + const double t + = ((point.x - line_p1.x) * line_diff.x + (point.y - line_p1.y) * line_diff.y) + / (line_diff.x * line_diff.x + line_diff.y * line_diff.y); + + if (t < 0) + { + // point is nearest to the first point i.e x1 and y1 + line_diff = point - line_p1; + } + else if (t > 1) + { + // point is nearest to the end point i.e x2 and y2 + line_diff = point - line_p2; + } + else + { + // if perpendicular line intersect the line segment. + line_diff.x = point.x - (line_p1.x + t * line_diff.x); + line_diff.y = point.y - (line_p1.y + t * line_diff.y); + } + + // returning shortest distance + return sqrt(line_diff.x * line_diff.x + line_diff.y * line_diff.y); + }; double shortest_distance = -1; std::size_t shortest_index = 0; for (std::size_t i = 0, j = get_all_points().size() - 1; i < get_all_points().size(); @@ -402,9 +403,15 @@ namespace obe::transform AABB Polygon::get_bounding_box() const { auto [min_x, max_x] = std::minmax_element(m_points.begin(), m_points.end(), - [](auto& point1, auto& point2) { return point1.x < point2.x; }); + [](auto& point1, auto& point2) + { + return point1.x < point2.x; + }); auto [min_y, max_y] = std::minmax_element(m_points.begin(), m_points.end(), - [](auto& point1, auto& point2) { return point1.y < point2.y; }); + [](auto& point1, auto& point2) + { + return point1.y < point2.y; + }); const double width = max_x->x - min_x->x; const double height = max_y->y - min_y->y; return AABB( diff --git a/src/Core/Types/UniqueIdentifiable.cpp b/src/Core/Types/UniqueIdentifiable.cpp index 6eb12fc55..b124702a1 100644 --- a/src/Core/Types/UniqueIdentifiable.cpp +++ b/src/Core/Types/UniqueIdentifiable.cpp @@ -5,7 +5,8 @@ namespace obe::types { - constexpr std::string_view BASE58_ALPHABET = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"; + constexpr std::string_view BASE58_ALPHABET + = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"; // uint64_t::max / 42 still makes 11 chars identifiers constexpr uint64_t RANDOM_U64_LOWER_BOUND = std::numeric_limits::max() / 42; constexpr uint64_t RANDOM_U64_UPPER_BOUND = std::numeric_limits::max(); diff --git a/src/Core/Utils/ArgParser.cpp b/src/Core/Utils/ArgParser.cpp index 0c226816f..4aaf8ec63 100644 --- a/src/Core/Utils/ArgParser.cpp +++ b/src/Core/Utils/ArgParser.cpp @@ -8,10 +8,10 @@ namespace obe::utils::argparser { bool b = false; std::transform(str.begin(), str.end(), str.begin(), - [](unsigned char c) - { - return std::tolower(c); - }); + [](unsigned char c) + { + return std::tolower(c); + }); if (str.rfind("true", 0) == 0 || str.rfind("false", 0) == 0) { b = true; @@ -20,11 +20,11 @@ namespace obe::utils::argparser return b; } - template + template bool is_numeric(const std::string& str) { Numeric n; - return((std::istringstream(str) >> n >> std::ws).eof()); + return ((std::istringstream(str) >> n >> std::ws).eof()); } bool to_bool(std::string str) @@ -40,22 +40,23 @@ namespace obe::utils::argparser { vili::node ret = argvalue; - if(std::isalpha(argvalue[0])) + if (std::isalpha(argvalue[0])) { // bool: - if(is_bool(argvalue)) + if (is_bool(argvalue)) { bool bv = to_bool(argvalue); ret = bv; } } - else { + else + { // int or float - if(is_numeric(argvalue)) + if (is_numeric(argvalue)) { ret = atoi(argvalue.c_str()); } - else if(is_numeric(argvalue)) + else if (is_numeric(argvalue)) { ret = atof(argvalue.c_str()); } @@ -74,7 +75,10 @@ namespace obe::utils::argparser const bool valid_arg_format = argument_name.starts_with("--") && argument_name.size() > 2 && std::isalpha(argument_name[2]) && std::all_of(argument_name_strip.begin(), argument_name_strip.end(), - [](const char c) { return std::isalpha(c) || c == '-' || c == '_'; }); + [](const char c) + { + return std::isalpha(c) || c == '-' || c == '_'; + }); if (!valid_arg_format) { throw exceptions::InvalidArgumentFormat(argument_name); diff --git a/src/Core/Utils/StringUtils.cpp b/src/Core/Utils/StringUtils.cpp index 551621f12..6f4a4160c 100644 --- a/src/Core/Utils/StringUtils.cpp +++ b/src/Core/Utils/StringUtils.cpp @@ -185,7 +185,8 @@ namespace obe::utils::string { std::vector sorted_by_distance = words; std::sort(sorted_by_distance.begin(), sorted_by_distance.end(), - [source](const std::string& s1, const std::string& s2) { + [source](const std::string& s1, const std::string& s2) + { return utils::string::distance(s1, source) < utils::string::distance(s2, source); }); if (limit && !sorted_by_distance.empty()) diff --git a/src/Player/ObEnginePlayer.cpp b/src/Player/ObEnginePlayer.cpp index cb64d6416..274220d5a 100644 --- a/src/Player/ObEnginePlayer.cpp +++ b/src/Player/ObEnginePlayer.cpp @@ -7,9 +7,9 @@ #include #include +#include #include #include -#include #include @@ -26,7 +26,7 @@ int main(int argc, char** argv) vili::node arguments; try { - arguments = utils::argparser::parse_args(argvector); + arguments = utils::argparser::parse_args(argvector); } catch (const std::exception& e) { diff --git a/src/Toolkit/Toolkit.cpp b/src/Toolkit/Toolkit.cpp index 9dabc5e02..bd288529b 100644 --- a/src/Toolkit/Toolkit.cpp +++ b/src/Toolkit/Toolkit.cpp @@ -93,20 +93,22 @@ void run(std::string command) lua.set_exception_handler(&lua_exception_handler2); lua["_term_display"] - = [](std::vector texts, std::vector colors) { - for (size_t i = 0; i < texts.size(); i++) - { - const std::string_view text = texts[i]; - const graphics::Color color = colors[i]; - std::cout << convert_color(color) << text; - } - std::cout << std::endl; - }; + = [](std::vector texts, std::vector colors) + { + for (size_t i = 0; i < texts.size(); i++) + { + const std::string_view text = texts[i]; + const graphics::Color color = colors[i]; + std::cout << convert_color(color) << text; + } + std::cout << std::endl; + }; lua.safe_script_file("obe://Lib/Toolkit/Toolkit.lua"_fs); lua["TOOLKIT_CONTEXTS"] = std::map { { "terminal", true } }; - auto is_interactive = [&lua]() { + auto is_interactive = [&lua]() + { std::map contexts = lua["TOOLKIT_CONTEXTS"].get>(); if (contexts.find("interactive") == contexts.end() || !contexts.at("interactive")) @@ -128,8 +130,11 @@ int main(int argc, char** argv) using namespace obe; std::string command; - std::for_each( - argv + 1, argv + argc, [&](const char* c_str) { command += std::string(c_str) + " "; }); + std::for_each(argv + 1, argv + argc, + [&](const char* c_str) + { + command += std::string(c_str) + " "; + }); #if defined _DEBUG run(command);