diff --git a/.clang_complete b/.clang_complete index e0358627..fad17bfe 100644 --- a/.clang_complete +++ b/.clang_complete @@ -6,6 +6,7 @@ -Isources -Isources/3rdparty +-Imodules/defer.hpp/headers -Imodules/ecs.hpp/headers -Imodules/enum.hpp/headers -Imodules/flat.hpp/headers diff --git a/.gitmodules b/.gitmodules index 8d6cba7e..2053c371 100644 --- a/.gitmodules +++ b/.gitmodules @@ -49,3 +49,6 @@ [submodule "modules/yoga"] path = modules/yoga url = https://github.com/facebook/yoga +[submodule "modules/defer.hpp"] + path = modules/defer.hpp + url = https://github.com/blackmatov/defer.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2eb138f6..1162ddc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,7 @@ file(GLOB_RECURSE E2D_3RDPARTY # e2d external 3rd party # +add_subdirectory(modules/defer.hpp) add_subdirectory(modules/ecs.hpp) add_subdirectory(modules/enum.hpp) add_subdirectory(modules/flat.hpp) @@ -153,6 +154,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${E2D_3RDPARTY}) target_link_libraries(${PROJECT_NAME} + PUBLIC defer.hpp PUBLIC ecs.hpp PUBLIC enum.hpp PUBLIC flat.hpp diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index 72723a84..a67d1f51 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -112,7 +112,7 @@ namespace e2d::ecsex Opts&&... opts) { static thread_local vector to_remove_components; - E2D_DEFER([](){ to_remove_components.clear(); }); + DEFER([](){ to_remove_components.clear(); }); owner.for_each_component([](const ecs::entity& e, const T&){ to_remove_components.push_back(e); @@ -167,7 +167,7 @@ namespace e2d::ecsex std::tuple> components; const std::size_t begin_index = components.size(); - E2D_DEFER([begin_index](){ + DEFER([begin_index](){ components.erase( components.begin() + begin_index, components.end()); @@ -191,7 +191,7 @@ namespace e2d::ecsex std::tuple> components; const std::size_t begin_index = components.size(); - E2D_DEFER([begin_index](){ + DEFER([begin_index](){ components.erase( components.begin() + begin_index, components.end()); @@ -218,7 +218,7 @@ namespace e2d::ecsex std::tuple> components; const std::size_t begin_index = components.size(); - E2D_DEFER([begin_index](){ + DEFER([begin_index](){ components.erase( components.begin() + begin_index, components.end()); @@ -247,7 +247,7 @@ namespace e2d::ecsex std::tuple> components; const std::size_t begin_index = components.size(); - E2D_DEFER([begin_index](){ + DEFER([begin_index](){ components.erase( components.begin() + begin_index, components.end()); diff --git a/headers/enduro2d/high/inspector.inl b/headers/enduro2d/high/inspector.inl index cc0797bd..ae2467b9 100644 --- a/headers/enduro2d/high/inspector.inl +++ b/headers/enduro2d/high/inspector.inl @@ -82,7 +82,7 @@ namespace e2d::impl } ImGui::PushID(co.find()); - E2D_DEFER([](){ ImGui::PopID(); }); + DEFER([](){ ImGui::PopID(); }); const bool inspector_opened = ImGui::CollapsingHeader( component_inspector::title, @@ -90,7 +90,7 @@ namespace e2d::impl const char* component_popup_context_str_id = "e2d_component_popup_context"; if ( ImGui::BeginPopupContextItem(component_popup_context_str_id) ) { - E2D_DEFER([](){ ImGui::EndPopup(); }); + DEFER([](){ ImGui::EndPopup(); }); auto disabled_co = co.owner().template component>(); if ( bool enabled = !disabled_co; ImGui::Checkbox("Enabled", &enabled) ) { @@ -137,7 +137,7 @@ namespace e2d::impl } ImGui::PushID(co.find()); - E2D_DEFER([](){ ImGui::PopID(); }); + DEFER([](){ ImGui::PopID(); }); if ( !co.owner().template component>() ) { inspector_(co, ctx); diff --git a/headers/enduro2d/high/node.inl b/headers/enduro2d/high/node.inl index 7288a3a1..53543315 100644 --- a/headers/enduro2d/high/node.inl +++ b/headers/enduro2d/high/node.inl @@ -153,7 +153,7 @@ namespace e2d::nodes static thread_local vector> parents; const std::size_t begin_index = parents.size(); - E2D_DEFER([begin_index](){ + DEFER([begin_index](){ parents.erase( parents.begin() + begin_index, parents.end()); @@ -184,7 +184,7 @@ namespace e2d::nodes static thread_local vector> children; const std::size_t begin_index = children.size(); - E2D_DEFER([begin_index](){ + DEFER([begin_index](){ children.erase( children.begin() + begin_index, children.end()); @@ -253,7 +253,7 @@ namespace e2d::nodes static thread_local vector> components; const std::size_t begin_index = components.size(); - E2D_DEFER([begin_index](){ + DEFER([begin_index](){ components.erase( components.begin() + begin_index, components.end()); @@ -284,7 +284,7 @@ namespace e2d::nodes static thread_local vector> components; const std::size_t begin_index = components.size(); - E2D_DEFER([begin_index](){ + DEFER([begin_index](){ components.erase( components.begin() + begin_index, components.end()); diff --git a/headers/enduro2d/utils/_all.hpp b/headers/enduro2d/utils/_all.hpp index b9cd2a73..492255bd 100644 --- a/headers/enduro2d/utils/_all.hpp +++ b/headers/enduro2d/utils/_all.hpp @@ -12,7 +12,6 @@ #include "buffer_view.hpp" #include "color.hpp" #include "color32.hpp" -#include "defer.hpp" #include "filesystem.hpp" #include "filesystem.inl" #include "font.hpp" diff --git a/headers/enduro2d/utils/_utils.hpp b/headers/enduro2d/utils/_utils.hpp index f44a1648..dd1a033a 100644 --- a/headers/enduro2d/utils/_utils.hpp +++ b/headers/enduro2d/utils/_utils.hpp @@ -9,6 +9,7 @@ #include "../base/_all.hpp" #include "../math/_all.hpp" +#include #include namespace e2d diff --git a/headers/enduro2d/utils/defer.hpp b/headers/enduro2d/utils/defer.hpp deleted file mode 100644 index faf3f4eb..00000000 --- a/headers/enduro2d/utils/defer.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * This file is part of the "Enduro2D" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#pragma once - -#include "_utils.hpp" - -namespace e2d -{ - namespace impl - { - template < typename F > - class defer_impl : noncopyable { - public: - explicit defer_impl(F f) - : f_(std::move(f)) {} - - virtual ~defer_impl() noexcept { - if ( !dismissed_ ) { - f_(); - } - } - - void dismiss() noexcept { - dismissed_ = true; - } - private: - F f_; - bool dismissed_{}; - }; - - template < typename F > - class error_defer_impl final : public defer_impl { - public: - explicit error_defer_impl(F f) - : defer_impl(std::move(f)) - , exceptions_(std::uncaught_exceptions()) {} - - ~error_defer_impl() noexcept final { - if ( exceptions_ == std::uncaught_exceptions() ) { - this->dismiss(); - } - } - private: - int exceptions_{}; - }; - - template < typename F > - class return_defer_impl final : public defer_impl { - public: - explicit return_defer_impl(F f) - : defer_impl(std::move(f)) - , exceptions_(std::uncaught_exceptions()) {} - - ~return_defer_impl() noexcept final { - if ( exceptions_ != std::uncaught_exceptions() ) { - this->dismiss(); - } - } - private: - int exceptions_{}; - }; - } - - template < typename F > - impl::defer_impl> make_defer(F&& f) { - return impl::defer_impl>(std::forward(f)); - } - - template < typename F > - impl::error_defer_impl> make_error_defer(F&& f) { - return impl::error_defer_impl>(std::forward(f)); - } - - template < typename F > - impl::return_defer_impl> make_return_defer(F&& f) { - return impl::return_defer_impl>(std::forward(f)); - } -} - -#define E2D_DEFER(...)\ - auto E2D_PP_CAT(e2d_generated_defer_, __LINE__) =\ - ::e2d::make_defer(__VA_ARGS__) - -#define E2D_ERROR_DEFER(...)\ - auto E2D_PP_CAT(e2d_generated_error_defer_, __LINE__) =\ - ::e2d::make_error_defer(__VA_ARGS__) - -#define E2D_RETURN_DEFER(...)\ - auto E2D_PP_CAT(e2d_generated_return_defer_, __LINE__) =\ - ::e2d::make_return_defer(__VA_ARGS__) diff --git a/headers/enduro2d/utils/imgui_utils.hpp b/headers/enduro2d/utils/imgui_utils.hpp index ccc47dfc..4507e938 100644 --- a/headers/enduro2d/utils/imgui_utils.hpp +++ b/headers/enduro2d/utils/imgui_utils.hpp @@ -37,7 +37,7 @@ namespace e2d::imgui_utils template < typename... Args > void show_colored_text(const color& color, str_view fmt, Args&&... args) { ImGui::PushStyleColor(ImGuiCol_Text, make_vec4(color)); - E2D_DEFER([](){ ImGui::PopStyleColor(); }); + DEFER([](){ ImGui::PopStyleColor(); }); show_formatted_text(fmt, std::forward(args)...); } @@ -54,7 +54,7 @@ namespace e2d::imgui_utils } if ( ImGui::BeginCombo(label_cstr, preview_cstr) ) { - E2D_DEFER([](){ ImGui::EndCombo(); }); + DEFER([](){ ImGui::EndCombo(); }); for ( std::size_t i = 0; i < enum_hpp::size(); ++i ) { str_view item_name = enum_hpp::names()[i]; @@ -80,10 +80,10 @@ namespace e2d::imgui_utils template < typename F, typename... Args > void with_disabled_flag(F&& f, Args&&... args) { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); - E2D_DEFER([](){ ImGui::PopItemFlag(); }); + DEFER([](){ ImGui::PopItemFlag(); }); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); - E2D_DEFER([](){ ImGui::PopStyleVar(); }); + DEFER([](){ ImGui::PopStyleVar(); }); std::invoke(std::forward(f), std::forward(args)...); } diff --git a/modules/defer.hpp b/modules/defer.hpp new file mode 160000 index 00000000..6ea555b9 --- /dev/null +++ b/modules/defer.hpp @@ -0,0 +1 @@ +Subproject commit 6ea555b98c58f002d843127186eeea4a905bb88c diff --git a/scripts/cloc_all.sh b/scripts/cloc_all.sh index 578ec943..0505905e 100755 --- a/scripts/cloc_all.sh +++ b/scripts/cloc_all.sh @@ -7,6 +7,8 @@ cloc \ $SCRIPT_DIR/../samples/sources \ $SCRIPT_DIR/../untests/bin \ $SCRIPT_DIR/../untests/sources \ + $SCRIPT_DIR/../modules/defer.hpp/headers \ + $SCRIPT_DIR/../modules/defer.hpp/untests \ $SCRIPT_DIR/../modules/ecs.hpp/headers \ $SCRIPT_DIR/../modules/ecs.hpp/untests \ $SCRIPT_DIR/../modules/enum.hpp/headers \ diff --git a/scripts/cloc_engine.sh b/scripts/cloc_engine.sh index 0cab7ce1..2d7bcd1b 100755 --- a/scripts/cloc_engine.sh +++ b/scripts/cloc_engine.sh @@ -3,6 +3,7 @@ SCRIPT_DIR=`dirname "$BASH_SOURCE"` cloc \ $SCRIPT_DIR/../headers/enduro2d \ $SCRIPT_DIR/../sources/enduro2d \ + $SCRIPT_DIR/../modules/defer.hpp/headers \ $SCRIPT_DIR/../modules/ecs.hpp/headers \ $SCRIPT_DIR/../modules/enum.hpp/headers \ $SCRIPT_DIR/../modules/flat.hpp/headers \ diff --git a/scripts/cloc_modules.sh b/scripts/cloc_modules.sh index 9a747a5c..e9732f2a 100755 --- a/scripts/cloc_modules.sh +++ b/scripts/cloc_modules.sh @@ -1,6 +1,8 @@ #!/bin/bash SCRIPT_DIR=`dirname "$BASH_SOURCE"` cloc \ + $SCRIPT_DIR/../modules/defer.hpp/headers \ + $SCRIPT_DIR/../modules/defer.hpp/untests \ $SCRIPT_DIR/../modules/ecs.hpp/headers \ $SCRIPT_DIR/../modules/ecs.hpp/untests \ $SCRIPT_DIR/../modules/enum.hpp/headers \ diff --git a/sources/enduro2d/core/dbgui_impl/dbgui.hpp b/sources/enduro2d/core/dbgui_impl/dbgui.hpp index 34c70728..f3c987e4 100644 --- a/sources/enduro2d/core/dbgui_impl/dbgui.hpp +++ b/sources/enduro2d/core/dbgui_impl/dbgui.hpp @@ -45,7 +45,7 @@ namespace e2d::imgex char* id_cstr = static_cast(E2D_CLEAR_ALLOCA(id.size() + 1)); std::memcpy(id_cstr, id.data(), id.size()); - if ( E2D_DEFER([](){ ImGui::EndChild(); }); + if ( DEFER([](){ ImGui::EndChild(); }); ImGui::BeginChild(id_cstr, ImVec2(0.f, 0.f), border, flags) ) { f(); @@ -58,7 +58,7 @@ namespace e2d::imgex std::memcpy(label_cstr, label.data(), label.size()); if ( ImGui::BeginMenu(label_cstr) ) { - E2D_DEFER([](){ ImGui::EndMenu(); }); + DEFER([](){ ImGui::EndMenu(); }); f(); } } @@ -66,7 +66,7 @@ namespace e2d::imgex template < typename F > void with_menu_bar(F&& f) { if ( ImGui::BeginMenuBar() ) { - E2D_DEFER([](){ ImGui::EndMenuBar(); }); + DEFER([](){ ImGui::EndMenuBar(); }); f(); } } @@ -77,7 +77,7 @@ namespace e2d::imgex std::memcpy(id_cstr, id.data(), id.size()); if ( ImGui::BeginPopup(id_cstr) ) { - E2D_DEFER([](){ ImGui::EndPopup(); }); + DEFER([](){ ImGui::EndPopup(); }); f(); } } @@ -87,7 +87,7 @@ namespace e2d::imgex char* name_cstr = static_cast(E2D_CLEAR_ALLOCA(name.size() + 1)); std::memcpy(name_cstr, name.data(), name.size()); - if ( E2D_DEFER([](){ ImGui::End(); }); + if ( DEFER([](){ ImGui::End(); }); ImGui::Begin(name_cstr, opened, flags) ) { f(); @@ -118,7 +118,7 @@ namespace e2d::imgex ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f)); ImGui::Begin("e2d_dock_space_window", nullptr, window_flags); - E2D_DEFER([](){ ImGui::End(); }); + DEFER([](){ ImGui::End(); }); ImGui::PopStyleVar(3); diff --git a/sources/enduro2d/core/dbgui_impl/widgets/input_widget.cpp b/sources/enduro2d/core/dbgui_impl/widgets/input_widget.cpp index 9a22f031..91aa81d6 100644 --- a/sources/enduro2d/core/dbgui_impl/widgets/input_widget.cpp +++ b/sources/enduro2d/core/dbgui_impl/widgets/input_widget.cpp @@ -34,7 +34,7 @@ namespace e2d::dbgui_widgets ImGui::Text("pressed keys:"); ImGui::Indent(); - E2D_DEFER([](){ ImGui::Unindent(); }); + DEFER([](){ ImGui::Unindent(); }); const vector pressed_keys = i.keyboard().pressed_keys(); for ( keyboard_key pk : pressed_keys ) { @@ -46,7 +46,7 @@ namespace e2d::dbgui_widgets ImGui::Text("pressed buttons:"); ImGui::Indent(); - E2D_DEFER([](){ ImGui::Unindent(); }); + DEFER([](){ ImGui::Unindent(); }); const vector pressed_buttons = i.mouse().pressed_buttons(); for ( mouse_button mb : pressed_buttons ) { diff --git a/sources/enduro2d/high/components/camera.cpp b/sources/enduro2d/high/components/camera.cpp index 73dab1b7..f115cfb3 100644 --- a/sources/enduro2d/high/components/camera.cpp +++ b/sources/enduro2d/high/components/camera.cpp @@ -220,7 +220,7 @@ namespace e2d } if ( ImGui::TreeNode("clipping") ) { - E2D_DEFER([](){ ImGui::TreePop(); }); + DEFER([](){ ImGui::TreePop(); }); if ( f32 znear = c->znear(); ImGui::DragFloat("znear", &znear, 1.f) ) @@ -240,7 +240,7 @@ namespace e2d ///TODO(BlackMat): add 'view' inspector if ( ImGui::TreeNode("viewport") ) { - E2D_DEFER([](){ ImGui::TreePop(); }); + DEFER([](){ ImGui::TreePop(); }); if ( b2f viewport = c->viewport(); ImGui::DragFloat2("position", viewport.position.data(), 0.01f) ) diff --git a/sources/enduro2d/high/components/colliders.cpp b/sources/enduro2d/high/components/colliders.cpp index a8c3b463..e538a7cd 100644 --- a/sources/enduro2d/high/components/colliders.cpp +++ b/sources/enduro2d/high/components/colliders.cpp @@ -221,7 +221,7 @@ namespace e2d c->points().size()); if ( ImGui::TreeNode(points_label.c_str()) ) { - E2D_DEFER([](){ ImGui::TreePop(); }); + DEFER([](){ ImGui::TreePop(); }); int count = math::numeric_cast(c->points().size()); if ( ImGui::DragInt("count", &count, 1.f, 0, std::numeric_limits::max()) ) { @@ -230,7 +230,7 @@ namespace e2d for ( std::size_t i = 0; i < c->points().size(); ++i ) { ImGui::PushID(math::numeric_cast(i)); - E2D_DEFER([](){ ImGui::PopID(); }); + DEFER([](){ ImGui::PopID(); }); if ( v2f point = c->points()[i]; ImGui::DragFloat2("###point", point.data(), 1.f) ) diff --git a/sources/enduro2d/high/inspector.cpp b/sources/enduro2d/high/inspector.cpp index 295774cc..93dc4378 100644 --- a/sources/enduro2d/high/inspector.cpp +++ b/sources/enduro2d/high/inspector.cpp @@ -25,7 +25,7 @@ namespace e2d } if ( ImGui::BeginPopup(add_component_popup_str_id) ) { - E2D_DEFER([](){ ImGui::EndPopup(); }); + DEFER([](){ ImGui::EndPopup(); }); for ( const auto& p : inspector_impls_ ) { imgui_utils::with_disabled_flag_ex( diff --git a/sources/enduro2d/high/systems/gizmos_system.cpp b/sources/enduro2d/high/systems/gizmos_system.cpp index 240ef815..da537d98 100644 --- a/sources/enduro2d/high/systems/gizmos_system.cpp +++ b/sources/enduro2d/high/systems/gizmos_system.cpp @@ -217,12 +217,12 @@ namespace ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f)); ImGui::Begin("e2d_gizmos_window", nullptr, window_flags); - E2D_DEFER([](){ ImGui::End(); }); + DEFER([](){ ImGui::End(); }); ImGui::PopStyleVar(3); ImGui::PushClipRect(clip_rect.Min, clip_rect.Max, true); - E2D_DEFER([](){ ImGui::PopClipRect(); }); + DEFER([](){ ImGui::PopClipRect(); }); std::invoke(std::forward(f), std::forward(args)...); } diff --git a/sources/enduro2d/high/systems/layout_system.cpp b/sources/enduro2d/high/systems/layout_system.cpp index 5a400c14..523336c9 100644 --- a/sources/enduro2d/high/systems/layout_system.cpp +++ b/sources/enduro2d/high/systems/layout_system.cpp @@ -181,13 +181,13 @@ namespace const actor& root_a) { static thread_local vector> item_ws; - E2D_DEFER([](){ item_ws.clear(); }); + DEFER([](){ item_ws.clear(); }); nodes::extract_components_from_children( root_a.node(), std::back_inserter(item_ws)); - E2D_DEFER([&root_yn](){ + DEFER([&root_yn](){ YGNodeRemoveAllChildren(root_yn.as_root.get()); }); diff --git a/sources/enduro2d/high/systems/render_system_impl/render_system_batcher.hpp b/sources/enduro2d/high/systems/render_system_impl/render_system_batcher.hpp index 1e40c041..e7074e90 100644 --- a/sources/enduro2d/high/systems/render_system_impl/render_system_batcher.hpp +++ b/sources/enduro2d/high/systems/render_system_impl/render_system_batcher.hpp @@ -106,7 +106,7 @@ namespace e2d::render_system_impl flush(); } - E2D_ERROR_DEFER([this](){ + ERROR_DEFER([this](){ clear(false); }); @@ -143,7 +143,7 @@ namespace e2d::render_system_impl template < typename Index, typename Vertex > render::property_block& batcher::flush() { - E2D_DEFER([this](){ + DEFER([this](){ clear(false); }); @@ -179,7 +179,7 @@ namespace e2d::render_system_impl .indices(index_buffer_) .add_vertices(vertex_buffer_); - E2D_DEFER([this](){ + DEFER([this](){ property_cache_.clear(); }); diff --git a/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.cpp b/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.cpp index 7c477b49..c64e7290 100644 --- a/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.cpp +++ b/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.cpp @@ -128,7 +128,7 @@ namespace e2d::render_system_impl const model& mdl = mdl_r.model()->content(); const mesh& msh = mdl.mesh()->content(); - E2D_DEFER([this](){ + DEFER([this](){ property_cache_.clear(); }); @@ -182,7 +182,7 @@ namespace e2d::render_system_impl unsigned short quad_indices[6] = { 0, 1, 2, 2, 3, 0 }; - E2D_DEFER([this, clipper](){ + DEFER([this, clipper](){ property_cache_.clear(); spSkeletonClipping_clipEnd2(clipper); }); @@ -190,7 +190,7 @@ namespace e2d::render_system_impl for ( int i = 0; i < skeleton->slotsCount; ++i ) { spSlot* slot = skeleton->drawOrder[i]; - auto slot_clipping_defer = make_defer([clipper, slot](){ + auto slot_clipping_defer = defer_hpp::make_defer([clipper, slot](){ spSkeletonClipping_clipEnd(clipper, slot); }); @@ -474,7 +474,7 @@ namespace e2d::render_system_impl return; } - E2D_DEFER([this](){ + DEFER([this](){ property_cache_.clear(); }); diff --git a/sources/enduro2d/high/systems/touch_system_impl/touch_system_colliders.cpp b/sources/enduro2d/high/systems/touch_system_impl/touch_system_colliders.cpp index 2c141921..c25c238e 100644 --- a/sources/enduro2d/high/systems/touch_system_impl/touch_system_colliders.cpp +++ b/sources/enduro2d/high/systems/touch_system_impl/touch_system_colliders.cpp @@ -126,7 +126,7 @@ namespace e2d::touch_system_impl::impl const b2f& camera_viewport) { static thread_local std::vector points; - E2D_DEFER([](){ points.clear(); }); + DEFER([](){ points.clear(); }); if ( points.capacity() < c.points.size() ) { points.reserve(math::max(points.capacity() * 2u, c.points.size())); diff --git a/sources/enduro2d/high/systems/touch_system_impl/touch_system_dispatcher.cpp b/sources/enduro2d/high/systems/touch_system_impl/touch_system_dispatcher.cpp index 7a3d4170..0ab97623 100644 --- a/sources/enduro2d/high/systems/touch_system_impl/touch_system_dispatcher.cpp +++ b/sources/enduro2d/high/systems/touch_system_impl/touch_system_dispatcher.cpp @@ -17,7 +17,7 @@ namespace scene, actor>> scenes; - E2D_DEFER([](){ scenes.clear(); }); + DEFER([](){ scenes.clear(); }); ecsex::extract_components( owner, std::back_inserter(scenes), @@ -62,7 +62,7 @@ namespace // static thread_local std::vector> parents; - E2D_DEFER([](){ parents.clear(); }); + DEFER([](){ parents.clear(); }); nodes::extract_components_from_parents( target_actor->node(), @@ -115,7 +115,7 @@ namespace namespace e2d::touch_system_impl { void dispatcher::dispatch_all_events(ecs::registry& owner) { - E2D_DEFER([this](){ events_.clear(); }); + DEFER([this](){ events_.clear(); }); owner.for_each_component>([ ](const ecs::const_entity&, events& es) { diff --git a/sources/enduro2d/high/widgets/hierarchy_widget.cpp b/sources/enduro2d/high/widgets/hierarchy_widget.cpp index b4f23922..4275f958 100644 --- a/sources/enduro2d/high/widgets/hierarchy_widget.cpp +++ b/sources/enduro2d/high/widgets/hierarchy_widget.cpp @@ -38,7 +38,7 @@ namespace : strings::rformat("%0 %1", icon_name, component_name); ImGui::PushID(root.get()); - E2D_DEFER([](){ ImGui::PopID(); }); + DEFER([](){ ImGui::PopID(); }); ImGuiTreeNodeFlags tree_node_flags = ImGuiTreeNodeFlags_OpenOnArrow | @@ -58,7 +58,7 @@ namespace tree_node_flags, "%s", tree_node_name.c_str()); - E2D_DEFER([tree_node_opened](){ + DEFER([tree_node_opened](){ if ( tree_node_opened ) { ImGui::TreePop(); } @@ -73,7 +73,7 @@ namespace } if ( ImGui::BeginPopupContextItem() ) { - E2D_DEFER([](){ ImGui::EndPopup(); }); + DEFER([](){ ImGui::EndPopup(); }); if ( ImGui::MenuItem("Add child") ) { gobject inst = w.instantiate(); diff --git a/sources/enduro2d/high/world.cpp b/sources/enduro2d/high/world.cpp index 425fcf5b..e2343351 100644 --- a/sources/enduro2d/high/world.cpp +++ b/sources/enduro2d/high/world.cpp @@ -86,12 +86,12 @@ namespace gobject new_instance(world& world, const prefab& root_prefab) { ecs::entity ent = world.registry().create_entity(root_prefab.prototype()); - auto ent_defer = make_error_defer([&ent](){ + auto ent_defer = defer_hpp::make_error_defer([&ent](){ ent.destroy(); }); gobject root_i(make_intrusive(world, ent)); - E2D_ERROR_DEFER([&root_i](){ + ERROR_DEFER([&root_i](){ delete_instance(root_i); }); @@ -108,7 +108,7 @@ namespace for ( const prefab& child_prefab : root_prefab.children() ) { gobject child_i = new_instance(world, child_prefab); - E2D_ERROR_DEFER([&child_i](){ + ERROR_DEFER([&child_i](){ delete_instance(child_i); }); gcomponent root_a{root_i}; @@ -158,7 +158,7 @@ namespace e2d gobject world::instantiate(const prefab& prefab, const node_iptr& parent) { gobject inst = new_instance(*this, prefab); - E2D_ERROR_DEFER([inst](){ + ERROR_DEFER([inst](){ delete_instance(inst); }); @@ -173,7 +173,7 @@ namespace e2d gobject world::instantiate(const prefab& prefab, const node_iptr& parent, const t2f& transform) { gobject inst = new_instance(*this, prefab); - E2D_ERROR_DEFER([inst](){ + ERROR_DEFER([inst](){ delete_instance(inst); }); diff --git a/untests/sources/untests_utils/filesystem.cpp b/untests/sources/untests_utils/filesystem.cpp index 95ee75a9..99fa4606 100644 --- a/untests/sources/untests_utils/filesystem.cpp +++ b/untests/sources/untests_utils/filesystem.cpp @@ -8,7 +8,7 @@ using namespace e2d; TEST_CASE("filesystem") { - E2D_DEFER([](){ + DEFER([](){ filesystem::remove_file("files_test"); }); SECTION("files") { diff --git a/untests/sources/untests_utils/image.cpp b/untests/sources/untests_utils/image.cpp index 5ac6f746..8234fe05 100644 --- a/untests/sources/untests_utils/image.cpp +++ b/untests/sources/untests_utils/image.cpp @@ -8,7 +8,7 @@ using namespace e2d; TEST_CASE("images") { - E2D_DEFER([](){ + DEFER([](){ filesystem::remove_file("image_save_test.jpg"); filesystem::remove_file("image_save_test.png"); filesystem::remove_file("image_save_test.tga");