mirror of
https://github.com/enduro2d/enduro2d.git
synced 2026-01-05 01:51:02 +07:00
use defer.hpp instead builtin impl
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
-Isources
|
-Isources
|
||||||
-Isources/3rdparty
|
-Isources/3rdparty
|
||||||
|
|
||||||
|
-Imodules/defer.hpp/headers
|
||||||
-Imodules/ecs.hpp/headers
|
-Imodules/ecs.hpp/headers
|
||||||
-Imodules/enum.hpp/headers
|
-Imodules/enum.hpp/headers
|
||||||
-Imodules/flat.hpp/headers
|
-Imodules/flat.hpp/headers
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -49,3 +49,6 @@
|
|||||||
[submodule "modules/yoga"]
|
[submodule "modules/yoga"]
|
||||||
path = modules/yoga
|
path = modules/yoga
|
||||||
url = https://github.com/facebook/yoga
|
url = https://github.com/facebook/yoga
|
||||||
|
[submodule "modules/defer.hpp"]
|
||||||
|
path = modules/defer.hpp
|
||||||
|
url = https://github.com/blackmatov/defer.hpp
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ file(GLOB_RECURSE E2D_3RDPARTY
|
|||||||
# e2d external 3rd party
|
# e2d external 3rd party
|
||||||
#
|
#
|
||||||
|
|
||||||
|
add_subdirectory(modules/defer.hpp)
|
||||||
add_subdirectory(modules/ecs.hpp)
|
add_subdirectory(modules/ecs.hpp)
|
||||||
add_subdirectory(modules/enum.hpp)
|
add_subdirectory(modules/enum.hpp)
|
||||||
add_subdirectory(modules/flat.hpp)
|
add_subdirectory(modules/flat.hpp)
|
||||||
@@ -153,6 +154,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES
|
|||||||
${E2D_3RDPARTY})
|
${E2D_3RDPARTY})
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
PUBLIC defer.hpp
|
||||||
PUBLIC ecs.hpp
|
PUBLIC ecs.hpp
|
||||||
PUBLIC enum.hpp
|
PUBLIC enum.hpp
|
||||||
PUBLIC flat.hpp
|
PUBLIC flat.hpp
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace e2d::ecsex
|
|||||||
Opts&&... opts)
|
Opts&&... opts)
|
||||||
{
|
{
|
||||||
static thread_local vector<ecs::entity> to_remove_components;
|
static thread_local vector<ecs::entity> to_remove_components;
|
||||||
E2D_DEFER([](){ to_remove_components.clear(); });
|
DEFER([](){ to_remove_components.clear(); });
|
||||||
|
|
||||||
owner.for_each_component<T>([](const ecs::entity& e, const T&){
|
owner.for_each_component<T>([](const ecs::entity& e, const T&){
|
||||||
to_remove_components.push_back(e);
|
to_remove_components.push_back(e);
|
||||||
@@ -167,7 +167,7 @@ namespace e2d::ecsex
|
|||||||
std::tuple<ecs::entity, Ts...>> components;
|
std::tuple<ecs::entity, Ts...>> components;
|
||||||
|
|
||||||
const std::size_t begin_index = components.size();
|
const std::size_t begin_index = components.size();
|
||||||
E2D_DEFER([begin_index](){
|
DEFER([begin_index](){
|
||||||
components.erase(
|
components.erase(
|
||||||
components.begin() + begin_index,
|
components.begin() + begin_index,
|
||||||
components.end());
|
components.end());
|
||||||
@@ -191,7 +191,7 @@ namespace e2d::ecsex
|
|||||||
std::tuple<ecs::const_entity, Ts...>> components;
|
std::tuple<ecs::const_entity, Ts...>> components;
|
||||||
|
|
||||||
const std::size_t begin_index = components.size();
|
const std::size_t begin_index = components.size();
|
||||||
E2D_DEFER([begin_index](){
|
DEFER([begin_index](){
|
||||||
components.erase(
|
components.erase(
|
||||||
components.begin() + begin_index,
|
components.begin() + begin_index,
|
||||||
components.end());
|
components.end());
|
||||||
@@ -218,7 +218,7 @@ namespace e2d::ecsex
|
|||||||
std::tuple<ecs::entity, Ts...>> components;
|
std::tuple<ecs::entity, Ts...>> components;
|
||||||
|
|
||||||
const std::size_t begin_index = components.size();
|
const std::size_t begin_index = components.size();
|
||||||
E2D_DEFER([begin_index](){
|
DEFER([begin_index](){
|
||||||
components.erase(
|
components.erase(
|
||||||
components.begin() + begin_index,
|
components.begin() + begin_index,
|
||||||
components.end());
|
components.end());
|
||||||
@@ -247,7 +247,7 @@ namespace e2d::ecsex
|
|||||||
std::tuple<ecs::const_entity, Ts...>> components;
|
std::tuple<ecs::const_entity, Ts...>> components;
|
||||||
|
|
||||||
const std::size_t begin_index = components.size();
|
const std::size_t begin_index = components.size();
|
||||||
E2D_DEFER([begin_index](){
|
DEFER([begin_index](){
|
||||||
components.erase(
|
components.erase(
|
||||||
components.begin() + begin_index,
|
components.begin() + begin_index,
|
||||||
components.end());
|
components.end());
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace e2d::impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PushID(co.find());
|
ImGui::PushID(co.find());
|
||||||
E2D_DEFER([](){ ImGui::PopID(); });
|
DEFER([](){ ImGui::PopID(); });
|
||||||
|
|
||||||
const bool inspector_opened = ImGui::CollapsingHeader(
|
const bool inspector_opened = ImGui::CollapsingHeader(
|
||||||
component_inspector<Component>::title,
|
component_inspector<Component>::title,
|
||||||
@@ -90,7 +90,7 @@ namespace e2d::impl
|
|||||||
|
|
||||||
const char* component_popup_context_str_id = "e2d_component_popup_context";
|
const char* component_popup_context_str_id = "e2d_component_popup_context";
|
||||||
if ( ImGui::BeginPopupContextItem(component_popup_context_str_id) ) {
|
if ( ImGui::BeginPopupContextItem(component_popup_context_str_id) ) {
|
||||||
E2D_DEFER([](){ ImGui::EndPopup(); });
|
DEFER([](){ ImGui::EndPopup(); });
|
||||||
|
|
||||||
auto disabled_co = co.owner().template component<disabled<Component>>();
|
auto disabled_co = co.owner().template component<disabled<Component>>();
|
||||||
if ( bool enabled = !disabled_co; ImGui::Checkbox("Enabled", &enabled) ) {
|
if ( bool enabled = !disabled_co; ImGui::Checkbox("Enabled", &enabled) ) {
|
||||||
@@ -137,7 +137,7 @@ namespace e2d::impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PushID(co.find());
|
ImGui::PushID(co.find());
|
||||||
E2D_DEFER([](){ ImGui::PopID(); });
|
DEFER([](){ ImGui::PopID(); });
|
||||||
|
|
||||||
if ( !co.owner().template component<disabled<Component>>() ) {
|
if ( !co.owner().template component<disabled<Component>>() ) {
|
||||||
inspector_(co, ctx);
|
inspector_(co, ctx);
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ namespace e2d::nodes
|
|||||||
static thread_local vector<intrusive_ptr<Node>> parents;
|
static thread_local vector<intrusive_ptr<Node>> parents;
|
||||||
|
|
||||||
const std::size_t begin_index = parents.size();
|
const std::size_t begin_index = parents.size();
|
||||||
E2D_DEFER([begin_index](){
|
DEFER([begin_index](){
|
||||||
parents.erase(
|
parents.erase(
|
||||||
parents.begin() + begin_index,
|
parents.begin() + begin_index,
|
||||||
parents.end());
|
parents.end());
|
||||||
@@ -184,7 +184,7 @@ namespace e2d::nodes
|
|||||||
static thread_local vector<intrusive_ptr<Node>> children;
|
static thread_local vector<intrusive_ptr<Node>> children;
|
||||||
|
|
||||||
const std::size_t begin_index = children.size();
|
const std::size_t begin_index = children.size();
|
||||||
E2D_DEFER([begin_index](){
|
DEFER([begin_index](){
|
||||||
children.erase(
|
children.erase(
|
||||||
children.begin() + begin_index,
|
children.begin() + begin_index,
|
||||||
children.end());
|
children.end());
|
||||||
@@ -253,7 +253,7 @@ namespace e2d::nodes
|
|||||||
static thread_local vector<gcomponent<Component>> components;
|
static thread_local vector<gcomponent<Component>> components;
|
||||||
|
|
||||||
const std::size_t begin_index = components.size();
|
const std::size_t begin_index = components.size();
|
||||||
E2D_DEFER([begin_index](){
|
DEFER([begin_index](){
|
||||||
components.erase(
|
components.erase(
|
||||||
components.begin() + begin_index,
|
components.begin() + begin_index,
|
||||||
components.end());
|
components.end());
|
||||||
@@ -284,7 +284,7 @@ namespace e2d::nodes
|
|||||||
static thread_local vector<gcomponent<Component>> components;
|
static thread_local vector<gcomponent<Component>> components;
|
||||||
|
|
||||||
const std::size_t begin_index = components.size();
|
const std::size_t begin_index = components.size();
|
||||||
E2D_DEFER([begin_index](){
|
DEFER([begin_index](){
|
||||||
components.erase(
|
components.erase(
|
||||||
components.begin() + begin_index,
|
components.begin() + begin_index,
|
||||||
components.end());
|
components.end());
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#include "buffer_view.hpp"
|
#include "buffer_view.hpp"
|
||||||
#include "color.hpp"
|
#include "color.hpp"
|
||||||
#include "color32.hpp"
|
#include "color32.hpp"
|
||||||
#include "defer.hpp"
|
|
||||||
#include "filesystem.hpp"
|
#include "filesystem.hpp"
|
||||||
#include "filesystem.inl"
|
#include "filesystem.inl"
|
||||||
#include "font.hpp"
|
#include "font.hpp"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "../base/_all.hpp"
|
#include "../base/_all.hpp"
|
||||||
#include "../math/_all.hpp"
|
#include "../math/_all.hpp"
|
||||||
|
|
||||||
|
#include <defer.hpp/defer.hpp>
|
||||||
#include <enum.hpp/enum.hpp>
|
#include <enum.hpp/enum.hpp>
|
||||||
|
|
||||||
namespace e2d
|
namespace e2d
|
||||||
|
|||||||
@@ -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<F> {
|
|
||||||
public:
|
|
||||||
explicit error_defer_impl(F f)
|
|
||||||
: defer_impl<F>(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<F> {
|
|
||||||
public:
|
|
||||||
explicit return_defer_impl(F f)
|
|
||||||
: defer_impl<F>(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<std::decay_t<F>> make_defer(F&& f) {
|
|
||||||
return impl::defer_impl<std::decay_t<F>>(std::forward<F>(f));
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename F >
|
|
||||||
impl::error_defer_impl<std::decay_t<F>> make_error_defer(F&& f) {
|
|
||||||
return impl::error_defer_impl<std::decay_t<F>>(std::forward<F>(f));
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename F >
|
|
||||||
impl::return_defer_impl<std::decay_t<F>> make_return_defer(F&& f) {
|
|
||||||
return impl::return_defer_impl<std::decay_t<F>>(std::forward<F>(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__)
|
|
||||||
@@ -37,7 +37,7 @@ namespace e2d::imgui_utils
|
|||||||
template < typename... Args >
|
template < typename... Args >
|
||||||
void show_colored_text(const color& color, str_view fmt, Args&&... args) {
|
void show_colored_text(const color& color, str_view fmt, Args&&... args) {
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, make_vec4(color));
|
ImGui::PushStyleColor(ImGuiCol_Text, make_vec4(color));
|
||||||
E2D_DEFER([](){ ImGui::PopStyleColor(); });
|
DEFER([](){ ImGui::PopStyleColor(); });
|
||||||
|
|
||||||
show_formatted_text(fmt, std::forward<Args>(args)...);
|
show_formatted_text(fmt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ namespace e2d::imgui_utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ImGui::BeginCombo(label_cstr, preview_cstr) ) {
|
if ( ImGui::BeginCombo(label_cstr, preview_cstr) ) {
|
||||||
E2D_DEFER([](){ ImGui::EndCombo(); });
|
DEFER([](){ ImGui::EndCombo(); });
|
||||||
|
|
||||||
for ( std::size_t i = 0; i < enum_hpp::size<E>(); ++i ) {
|
for ( std::size_t i = 0; i < enum_hpp::size<E>(); ++i ) {
|
||||||
str_view item_name = enum_hpp::names<E>()[i];
|
str_view item_name = enum_hpp::names<E>()[i];
|
||||||
@@ -80,10 +80,10 @@ namespace e2d::imgui_utils
|
|||||||
template < typename F, typename... Args >
|
template < typename F, typename... Args >
|
||||||
void with_disabled_flag(F&& f, Args&&... args) {
|
void with_disabled_flag(F&& f, Args&&... args) {
|
||||||
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
|
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
|
||||||
E2D_DEFER([](){ ImGui::PopItemFlag(); });
|
DEFER([](){ ImGui::PopItemFlag(); });
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
|
||||||
E2D_DEFER([](){ ImGui::PopStyleVar(); });
|
DEFER([](){ ImGui::PopStyleVar(); });
|
||||||
|
|
||||||
std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
|
std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|||||||
1
modules/defer.hpp
Submodule
1
modules/defer.hpp
Submodule
Submodule modules/defer.hpp added at 6ea555b98c
@@ -7,6 +7,8 @@ cloc \
|
|||||||
$SCRIPT_DIR/../samples/sources \
|
$SCRIPT_DIR/../samples/sources \
|
||||||
$SCRIPT_DIR/../untests/bin \
|
$SCRIPT_DIR/../untests/bin \
|
||||||
$SCRIPT_DIR/../untests/sources \
|
$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/headers \
|
||||||
$SCRIPT_DIR/../modules/ecs.hpp/untests \
|
$SCRIPT_DIR/../modules/ecs.hpp/untests \
|
||||||
$SCRIPT_DIR/../modules/enum.hpp/headers \
|
$SCRIPT_DIR/../modules/enum.hpp/headers \
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ SCRIPT_DIR=`dirname "$BASH_SOURCE"`
|
|||||||
cloc \
|
cloc \
|
||||||
$SCRIPT_DIR/../headers/enduro2d \
|
$SCRIPT_DIR/../headers/enduro2d \
|
||||||
$SCRIPT_DIR/../sources/enduro2d \
|
$SCRIPT_DIR/../sources/enduro2d \
|
||||||
|
$SCRIPT_DIR/../modules/defer.hpp/headers \
|
||||||
$SCRIPT_DIR/../modules/ecs.hpp/headers \
|
$SCRIPT_DIR/../modules/ecs.hpp/headers \
|
||||||
$SCRIPT_DIR/../modules/enum.hpp/headers \
|
$SCRIPT_DIR/../modules/enum.hpp/headers \
|
||||||
$SCRIPT_DIR/../modules/flat.hpp/headers \
|
$SCRIPT_DIR/../modules/flat.hpp/headers \
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
|
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
|
||||||
cloc \
|
cloc \
|
||||||
|
$SCRIPT_DIR/../modules/defer.hpp/headers \
|
||||||
|
$SCRIPT_DIR/../modules/defer.hpp/untests \
|
||||||
$SCRIPT_DIR/../modules/ecs.hpp/headers \
|
$SCRIPT_DIR/../modules/ecs.hpp/headers \
|
||||||
$SCRIPT_DIR/../modules/ecs.hpp/untests \
|
$SCRIPT_DIR/../modules/ecs.hpp/untests \
|
||||||
$SCRIPT_DIR/../modules/enum.hpp/headers \
|
$SCRIPT_DIR/../modules/enum.hpp/headers \
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace e2d::imgex
|
|||||||
char* id_cstr = static_cast<char*>(E2D_CLEAR_ALLOCA(id.size() + 1));
|
char* id_cstr = static_cast<char*>(E2D_CLEAR_ALLOCA(id.size() + 1));
|
||||||
std::memcpy(id_cstr, id.data(), id.size());
|
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) )
|
ImGui::BeginChild(id_cstr, ImVec2(0.f, 0.f), border, flags) )
|
||||||
{
|
{
|
||||||
f();
|
f();
|
||||||
@@ -58,7 +58,7 @@ namespace e2d::imgex
|
|||||||
std::memcpy(label_cstr, label.data(), label.size());
|
std::memcpy(label_cstr, label.data(), label.size());
|
||||||
|
|
||||||
if ( ImGui::BeginMenu(label_cstr) ) {
|
if ( ImGui::BeginMenu(label_cstr) ) {
|
||||||
E2D_DEFER([](){ ImGui::EndMenu(); });
|
DEFER([](){ ImGui::EndMenu(); });
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ namespace e2d::imgex
|
|||||||
template < typename F >
|
template < typename F >
|
||||||
void with_menu_bar(F&& f) {
|
void with_menu_bar(F&& f) {
|
||||||
if ( ImGui::BeginMenuBar() ) {
|
if ( ImGui::BeginMenuBar() ) {
|
||||||
E2D_DEFER([](){ ImGui::EndMenuBar(); });
|
DEFER([](){ ImGui::EndMenuBar(); });
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ namespace e2d::imgex
|
|||||||
std::memcpy(id_cstr, id.data(), id.size());
|
std::memcpy(id_cstr, id.data(), id.size());
|
||||||
|
|
||||||
if ( ImGui::BeginPopup(id_cstr) ) {
|
if ( ImGui::BeginPopup(id_cstr) ) {
|
||||||
E2D_DEFER([](){ ImGui::EndPopup(); });
|
DEFER([](){ ImGui::EndPopup(); });
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ namespace e2d::imgex
|
|||||||
char* name_cstr = static_cast<char*>(E2D_CLEAR_ALLOCA(name.size() + 1));
|
char* name_cstr = static_cast<char*>(E2D_CLEAR_ALLOCA(name.size() + 1));
|
||||||
std::memcpy(name_cstr, name.data(), name.size());
|
std::memcpy(name_cstr, name.data(), name.size());
|
||||||
|
|
||||||
if ( E2D_DEFER([](){ ImGui::End(); });
|
if ( DEFER([](){ ImGui::End(); });
|
||||||
ImGui::Begin(name_cstr, opened, flags) )
|
ImGui::Begin(name_cstr, opened, flags) )
|
||||||
{
|
{
|
||||||
f();
|
f();
|
||||||
@@ -118,7 +118,7 @@ namespace e2d::imgex
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
|
||||||
|
|
||||||
ImGui::Begin("e2d_dock_space_window", nullptr, window_flags);
|
ImGui::Begin("e2d_dock_space_window", nullptr, window_flags);
|
||||||
E2D_DEFER([](){ ImGui::End(); });
|
DEFER([](){ ImGui::End(); });
|
||||||
|
|
||||||
ImGui::PopStyleVar(3);
|
ImGui::PopStyleVar(3);
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace e2d::dbgui_widgets
|
|||||||
ImGui::Text("pressed keys:");
|
ImGui::Text("pressed keys:");
|
||||||
|
|
||||||
ImGui::Indent();
|
ImGui::Indent();
|
||||||
E2D_DEFER([](){ ImGui::Unindent(); });
|
DEFER([](){ ImGui::Unindent(); });
|
||||||
|
|
||||||
const vector<keyboard_key> pressed_keys = i.keyboard().pressed_keys();
|
const vector<keyboard_key> pressed_keys = i.keyboard().pressed_keys();
|
||||||
for ( keyboard_key pk : pressed_keys ) {
|
for ( keyboard_key pk : pressed_keys ) {
|
||||||
@@ -46,7 +46,7 @@ namespace e2d::dbgui_widgets
|
|||||||
ImGui::Text("pressed buttons:");
|
ImGui::Text("pressed buttons:");
|
||||||
|
|
||||||
ImGui::Indent();
|
ImGui::Indent();
|
||||||
E2D_DEFER([](){ ImGui::Unindent(); });
|
DEFER([](){ ImGui::Unindent(); });
|
||||||
|
|
||||||
const vector<mouse_button> pressed_buttons = i.mouse().pressed_buttons();
|
const vector<mouse_button> pressed_buttons = i.mouse().pressed_buttons();
|
||||||
for ( mouse_button mb : pressed_buttons ) {
|
for ( mouse_button mb : pressed_buttons ) {
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ namespace e2d
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ImGui::TreeNode("clipping") ) {
|
if ( ImGui::TreeNode("clipping") ) {
|
||||||
E2D_DEFER([](){ ImGui::TreePop(); });
|
DEFER([](){ ImGui::TreePop(); });
|
||||||
|
|
||||||
if ( f32 znear = c->znear();
|
if ( f32 znear = c->znear();
|
||||||
ImGui::DragFloat("znear", &znear, 1.f) )
|
ImGui::DragFloat("znear", &znear, 1.f) )
|
||||||
@@ -240,7 +240,7 @@ namespace e2d
|
|||||||
///TODO(BlackMat): add 'view' inspector
|
///TODO(BlackMat): add 'view' inspector
|
||||||
|
|
||||||
if ( ImGui::TreeNode("viewport") ) {
|
if ( ImGui::TreeNode("viewport") ) {
|
||||||
E2D_DEFER([](){ ImGui::TreePop(); });
|
DEFER([](){ ImGui::TreePop(); });
|
||||||
|
|
||||||
if ( b2f viewport = c->viewport();
|
if ( b2f viewport = c->viewport();
|
||||||
ImGui::DragFloat2("position", viewport.position.data(), 0.01f) )
|
ImGui::DragFloat2("position", viewport.position.data(), 0.01f) )
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ namespace e2d
|
|||||||
c->points().size());
|
c->points().size());
|
||||||
|
|
||||||
if ( ImGui::TreeNode(points_label.c_str()) ) {
|
if ( ImGui::TreeNode(points_label.c_str()) ) {
|
||||||
E2D_DEFER([](){ ImGui::TreePop(); });
|
DEFER([](){ ImGui::TreePop(); });
|
||||||
|
|
||||||
int count = math::numeric_cast<int>(c->points().size());
|
int count = math::numeric_cast<int>(c->points().size());
|
||||||
if ( ImGui::DragInt("count", &count, 1.f, 0, std::numeric_limits<int>::max()) ) {
|
if ( ImGui::DragInt("count", &count, 1.f, 0, std::numeric_limits<int>::max()) ) {
|
||||||
@@ -230,7 +230,7 @@ namespace e2d
|
|||||||
|
|
||||||
for ( std::size_t i = 0; i < c->points().size(); ++i ) {
|
for ( std::size_t i = 0; i < c->points().size(); ++i ) {
|
||||||
ImGui::PushID(math::numeric_cast<int>(i));
|
ImGui::PushID(math::numeric_cast<int>(i));
|
||||||
E2D_DEFER([](){ ImGui::PopID(); });
|
DEFER([](){ ImGui::PopID(); });
|
||||||
|
|
||||||
if ( v2f point = c->points()[i];
|
if ( v2f point = c->points()[i];
|
||||||
ImGui::DragFloat2("###point", point.data(), 1.f) )
|
ImGui::DragFloat2("###point", point.data(), 1.f) )
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace e2d
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ImGui::BeginPopup(add_component_popup_str_id) ) {
|
if ( ImGui::BeginPopup(add_component_popup_str_id) ) {
|
||||||
E2D_DEFER([](){ ImGui::EndPopup(); });
|
DEFER([](){ ImGui::EndPopup(); });
|
||||||
|
|
||||||
for ( const auto& p : inspector_impls_ ) {
|
for ( const auto& p : inspector_impls_ ) {
|
||||||
imgui_utils::with_disabled_flag_ex(
|
imgui_utils::with_disabled_flag_ex(
|
||||||
|
|||||||
@@ -217,12 +217,12 @@ namespace
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
|
||||||
|
|
||||||
ImGui::Begin("e2d_gizmos_window", nullptr, window_flags);
|
ImGui::Begin("e2d_gizmos_window", nullptr, window_flags);
|
||||||
E2D_DEFER([](){ ImGui::End(); });
|
DEFER([](){ ImGui::End(); });
|
||||||
|
|
||||||
ImGui::PopStyleVar(3);
|
ImGui::PopStyleVar(3);
|
||||||
|
|
||||||
ImGui::PushClipRect(clip_rect.Min, clip_rect.Max, true);
|
ImGui::PushClipRect(clip_rect.Min, clip_rect.Max, true);
|
||||||
E2D_DEFER([](){ ImGui::PopClipRect(); });
|
DEFER([](){ ImGui::PopClipRect(); });
|
||||||
|
|
||||||
std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
|
std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,13 +181,13 @@ namespace
|
|||||||
const actor& root_a)
|
const actor& root_a)
|
||||||
{
|
{
|
||||||
static thread_local vector<gcomponent<widget>> item_ws;
|
static thread_local vector<gcomponent<widget>> item_ws;
|
||||||
E2D_DEFER([](){ item_ws.clear(); });
|
DEFER([](){ item_ws.clear(); });
|
||||||
|
|
||||||
nodes::extract_components_from_children<widget>(
|
nodes::extract_components_from_children<widget>(
|
||||||
root_a.node(),
|
root_a.node(),
|
||||||
std::back_inserter(item_ws));
|
std::back_inserter(item_ws));
|
||||||
|
|
||||||
E2D_DEFER([&root_yn](){
|
DEFER([&root_yn](){
|
||||||
YGNodeRemoveAllChildren(root_yn.as_root.get());
|
YGNodeRemoveAllChildren(root_yn.as_root.get());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ namespace e2d::render_system_impl
|
|||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
E2D_ERROR_DEFER([this](){
|
ERROR_DEFER([this](){
|
||||||
clear(false);
|
clear(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ namespace e2d::render_system_impl
|
|||||||
|
|
||||||
template < typename Index, typename Vertex >
|
template < typename Index, typename Vertex >
|
||||||
render::property_block& batcher<Index, Vertex>::flush() {
|
render::property_block& batcher<Index, Vertex>::flush() {
|
||||||
E2D_DEFER([this](){
|
DEFER([this](){
|
||||||
clear(false);
|
clear(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ namespace e2d::render_system_impl
|
|||||||
.indices(index_buffer_)
|
.indices(index_buffer_)
|
||||||
.add_vertices(vertex_buffer_);
|
.add_vertices(vertex_buffer_);
|
||||||
|
|
||||||
E2D_DEFER([this](){
|
DEFER([this](){
|
||||||
property_cache_.clear();
|
property_cache_.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ namespace e2d::render_system_impl
|
|||||||
const model& mdl = mdl_r.model()->content();
|
const model& mdl = mdl_r.model()->content();
|
||||||
const mesh& msh = mdl.mesh()->content();
|
const mesh& msh = mdl.mesh()->content();
|
||||||
|
|
||||||
E2D_DEFER([this](){
|
DEFER([this](){
|
||||||
property_cache_.clear();
|
property_cache_.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ namespace e2d::render_system_impl
|
|||||||
|
|
||||||
unsigned short quad_indices[6] = { 0, 1, 2, 2, 3, 0 };
|
unsigned short quad_indices[6] = { 0, 1, 2, 2, 3, 0 };
|
||||||
|
|
||||||
E2D_DEFER([this, clipper](){
|
DEFER([this, clipper](){
|
||||||
property_cache_.clear();
|
property_cache_.clear();
|
||||||
spSkeletonClipping_clipEnd2(clipper);
|
spSkeletonClipping_clipEnd2(clipper);
|
||||||
});
|
});
|
||||||
@@ -190,7 +190,7 @@ namespace e2d::render_system_impl
|
|||||||
for ( int i = 0; i < skeleton->slotsCount; ++i ) {
|
for ( int i = 0; i < skeleton->slotsCount; ++i ) {
|
||||||
spSlot* slot = skeleton->drawOrder[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);
|
spSkeletonClipping_clipEnd(clipper, slot);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -474,7 +474,7 @@ namespace e2d::render_system_impl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
E2D_DEFER([this](){
|
DEFER([this](){
|
||||||
property_cache_.clear();
|
property_cache_.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ namespace e2d::touch_system_impl::impl
|
|||||||
const b2f& camera_viewport)
|
const b2f& camera_viewport)
|
||||||
{
|
{
|
||||||
static thread_local std::vector<v2f> points;
|
static thread_local std::vector<v2f> points;
|
||||||
E2D_DEFER([](){ points.clear(); });
|
DEFER([](){ points.clear(); });
|
||||||
|
|
||||||
if ( points.capacity() < c.points.size() ) {
|
if ( points.capacity() < c.points.size() ) {
|
||||||
points.reserve(math::max(points.capacity() * 2u, c.points.size()));
|
points.reserve(math::max(points.capacity() * 2u, c.points.size()));
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace
|
|||||||
scene,
|
scene,
|
||||||
actor>> scenes;
|
actor>> scenes;
|
||||||
|
|
||||||
E2D_DEFER([](){ scenes.clear(); });
|
DEFER([](){ scenes.clear(); });
|
||||||
ecsex::extract_components<scene, actor>(
|
ecsex::extract_components<scene, actor>(
|
||||||
owner,
|
owner,
|
||||||
std::back_inserter(scenes),
|
std::back_inserter(scenes),
|
||||||
@@ -62,7 +62,7 @@ namespace
|
|||||||
//
|
//
|
||||||
|
|
||||||
static thread_local std::vector<gcomponent<touchable>> parents;
|
static thread_local std::vector<gcomponent<touchable>> parents;
|
||||||
E2D_DEFER([](){ parents.clear(); });
|
DEFER([](){ parents.clear(); });
|
||||||
|
|
||||||
nodes::extract_components_from_parents<touchable>(
|
nodes::extract_components_from_parents<touchable>(
|
||||||
target_actor->node(),
|
target_actor->node(),
|
||||||
@@ -115,7 +115,7 @@ namespace
|
|||||||
namespace e2d::touch_system_impl
|
namespace e2d::touch_system_impl
|
||||||
{
|
{
|
||||||
void dispatcher::dispatch_all_events(ecs::registry& owner) {
|
void dispatcher::dispatch_all_events(ecs::registry& owner) {
|
||||||
E2D_DEFER([this](){ events_.clear(); });
|
DEFER([this](){ events_.clear(); });
|
||||||
|
|
||||||
owner.for_each_component<events<touchable_events::event>>([
|
owner.for_each_component<events<touchable_events::event>>([
|
||||||
](const ecs::const_entity&, events<touchable_events::event>& es) {
|
](const ecs::const_entity&, events<touchable_events::event>& es) {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace
|
|||||||
: strings::rformat("%0 %1", icon_name, component_name);
|
: strings::rformat("%0 %1", icon_name, component_name);
|
||||||
|
|
||||||
ImGui::PushID(root.get());
|
ImGui::PushID(root.get());
|
||||||
E2D_DEFER([](){ ImGui::PopID(); });
|
DEFER([](){ ImGui::PopID(); });
|
||||||
|
|
||||||
ImGuiTreeNodeFlags tree_node_flags =
|
ImGuiTreeNodeFlags tree_node_flags =
|
||||||
ImGuiTreeNodeFlags_OpenOnArrow |
|
ImGuiTreeNodeFlags_OpenOnArrow |
|
||||||
@@ -58,7 +58,7 @@ namespace
|
|||||||
tree_node_flags,
|
tree_node_flags,
|
||||||
"%s", tree_node_name.c_str());
|
"%s", tree_node_name.c_str());
|
||||||
|
|
||||||
E2D_DEFER([tree_node_opened](){
|
DEFER([tree_node_opened](){
|
||||||
if ( tree_node_opened ) {
|
if ( tree_node_opened ) {
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ImGui::BeginPopupContextItem() ) {
|
if ( ImGui::BeginPopupContextItem() ) {
|
||||||
E2D_DEFER([](){ ImGui::EndPopup(); });
|
DEFER([](){ ImGui::EndPopup(); });
|
||||||
|
|
||||||
if ( ImGui::MenuItem("Add child") ) {
|
if ( ImGui::MenuItem("Add child") ) {
|
||||||
gobject inst = w.instantiate();
|
gobject inst = w.instantiate();
|
||||||
|
|||||||
@@ -86,12 +86,12 @@ namespace
|
|||||||
|
|
||||||
gobject new_instance(world& world, const prefab& root_prefab) {
|
gobject new_instance(world& world, const prefab& root_prefab) {
|
||||||
ecs::entity ent = world.registry().create_entity(root_prefab.prototype());
|
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();
|
ent.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
gobject root_i(make_intrusive<gobject_state>(world, ent));
|
gobject root_i(make_intrusive<gobject_state>(world, ent));
|
||||||
E2D_ERROR_DEFER([&root_i](){
|
ERROR_DEFER([&root_i](){
|
||||||
delete_instance(root_i);
|
delete_instance(root_i);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ namespace
|
|||||||
|
|
||||||
for ( const prefab& child_prefab : root_prefab.children() ) {
|
for ( const prefab& child_prefab : root_prefab.children() ) {
|
||||||
gobject child_i = new_instance(world, child_prefab);
|
gobject child_i = new_instance(world, child_prefab);
|
||||||
E2D_ERROR_DEFER([&child_i](){
|
ERROR_DEFER([&child_i](){
|
||||||
delete_instance(child_i);
|
delete_instance(child_i);
|
||||||
});
|
});
|
||||||
gcomponent<actor> root_a{root_i};
|
gcomponent<actor> root_a{root_i};
|
||||||
@@ -158,7 +158,7 @@ namespace e2d
|
|||||||
|
|
||||||
gobject world::instantiate(const prefab& prefab, const node_iptr& parent) {
|
gobject world::instantiate(const prefab& prefab, const node_iptr& parent) {
|
||||||
gobject inst = new_instance(*this, prefab);
|
gobject inst = new_instance(*this, prefab);
|
||||||
E2D_ERROR_DEFER([inst](){
|
ERROR_DEFER([inst](){
|
||||||
delete_instance(inst);
|
delete_instance(inst);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ namespace e2d
|
|||||||
|
|
||||||
gobject world::instantiate(const prefab& prefab, const node_iptr& parent, const t2f& transform) {
|
gobject world::instantiate(const prefab& prefab, const node_iptr& parent, const t2f& transform) {
|
||||||
gobject inst = new_instance(*this, prefab);
|
gobject inst = new_instance(*this, prefab);
|
||||||
E2D_ERROR_DEFER([inst](){
|
ERROR_DEFER([inst](){
|
||||||
delete_instance(inst);
|
delete_instance(inst);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
using namespace e2d;
|
using namespace e2d;
|
||||||
|
|
||||||
TEST_CASE("filesystem") {
|
TEST_CASE("filesystem") {
|
||||||
E2D_DEFER([](){
|
DEFER([](){
|
||||||
filesystem::remove_file("files_test");
|
filesystem::remove_file("files_test");
|
||||||
});
|
});
|
||||||
SECTION("files") {
|
SECTION("files") {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
using namespace e2d;
|
using namespace e2d;
|
||||||
|
|
||||||
TEST_CASE("images") {
|
TEST_CASE("images") {
|
||||||
E2D_DEFER([](){
|
DEFER([](){
|
||||||
filesystem::remove_file("image_save_test.jpg");
|
filesystem::remove_file("image_save_test.jpg");
|
||||||
filesystem::remove_file("image_save_test.png");
|
filesystem::remove_file("image_save_test.png");
|
||||||
filesystem::remove_file("image_save_test.tga");
|
filesystem::remove_file("image_save_test.tga");
|
||||||
|
|||||||
Reference in New Issue
Block a user