mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
Merge pull request #110 from enduro2d/feature/inspector_gizmos
Feature/inspector gizmos
This commit is contained in:
@@ -44,10 +44,13 @@
|
||||
#include "components/sprite_renderer.hpp"
|
||||
|
||||
#include "systems/flipbook_system.hpp"
|
||||
#include "systems/frame_system.hpp"
|
||||
#include "systems/gizmos_system.hpp"
|
||||
#include "systems/label_system.hpp"
|
||||
#include "systems/render_system.hpp"
|
||||
#include "systems/script_system.hpp"
|
||||
#include "systems/spine_system.hpp"
|
||||
#include "systems/world_system.hpp"
|
||||
|
||||
#include "address.hpp"
|
||||
#include "asset.hpp"
|
||||
|
||||
@@ -62,10 +62,13 @@ namespace e2d
|
||||
class sprite_renderer;
|
||||
|
||||
class flipbook_system;
|
||||
class frame_system;
|
||||
class gizmos_system;
|
||||
class label_system;
|
||||
class render_system;
|
||||
class script_system;
|
||||
class spine_system;
|
||||
class world_system;
|
||||
|
||||
template < typename Asset, typename Content >
|
||||
class content_asset;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
namespace e2d
|
||||
{
|
||||
class camera final {
|
||||
public:
|
||||
class gizmos final {};
|
||||
public:
|
||||
camera() = default;
|
||||
|
||||
@@ -53,6 +55,20 @@ namespace e2d
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
class factory_loader<camera::gizmos> final : factory_loader<> {
|
||||
public:
|
||||
static const char* schema_source;
|
||||
|
||||
bool operator()(
|
||||
camera::gizmos& component,
|
||||
const fill_context& ctx) const;
|
||||
|
||||
bool operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
|
||||
@@ -18,8 +18,7 @@ namespace e2d
|
||||
{
|
||||
class label final {
|
||||
public:
|
||||
class dirty final {
|
||||
};
|
||||
class dirty final {};
|
||||
public:
|
||||
ENUM_HPP_CLASS_DECL(haligns, u8,
|
||||
(left)
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace e2d
|
||||
static const char* title;
|
||||
|
||||
void operator()(gcomponent<sprite_renderer>& c) const;
|
||||
void operator()(gcomponent<sprite_renderer>& c, gizmos_context& ctx) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,57 @@ namespace e2d
|
||||
template <>
|
||||
class component_inspector<> {
|
||||
public:
|
||||
class gizmos_context : private noncopyable {
|
||||
public:
|
||||
virtual void draw_line(
|
||||
const v2f& p1,
|
||||
const v2f& p2,
|
||||
const color32& color) = 0;
|
||||
|
||||
virtual void draw_rect(
|
||||
const v2f& p1,
|
||||
const v2f& p2,
|
||||
const v2f& p3,
|
||||
const v2f& p4,
|
||||
const color32& color) = 0;
|
||||
|
||||
virtual void draw_wire_rect(
|
||||
const v2f& p1,
|
||||
const v2f& p2,
|
||||
const v2f& p3,
|
||||
const v2f& p4,
|
||||
const color32& color) = 0;
|
||||
|
||||
virtual void draw_circle(
|
||||
const v2f& center,
|
||||
f32 radius,
|
||||
u32 segments,
|
||||
const color32& color) = 0;
|
||||
|
||||
virtual void draw_wire_circle(
|
||||
const v2f& center,
|
||||
f32 radius,
|
||||
u32 segments,
|
||||
const color32& color) = 0;
|
||||
|
||||
virtual bool selected() const noexcept = 0;
|
||||
};
|
||||
};
|
||||
|
||||
namespace impl
|
||||
{
|
||||
template < typename Component >
|
||||
using has_component_inspector =
|
||||
decltype(std::declval<component_inspector<Component>>()(
|
||||
std::declval<gcomponent<Component>&>()));
|
||||
|
||||
template < typename Component >
|
||||
using has_component_inspector_gizmos =
|
||||
decltype(std::declval<component_inspector<Component>>()(
|
||||
std::declval<gcomponent<Component>&>(),
|
||||
std::declval<component_inspector<>::gizmos_context&>()));
|
||||
}
|
||||
|
||||
//
|
||||
// inspector_drawer
|
||||
//
|
||||
@@ -51,7 +100,12 @@ namespace e2d
|
||||
inspector_drawer() = default;
|
||||
virtual ~inspector_drawer() noexcept = default;
|
||||
|
||||
virtual void operator()(gobject& go) const = 0;
|
||||
virtual void operator()(
|
||||
gobject& go) const = 0;
|
||||
|
||||
virtual void operator()(
|
||||
gobject& go,
|
||||
component_inspector<>::gizmos_context& ctx) const = 0;
|
||||
};
|
||||
|
||||
template < typename Component >
|
||||
@@ -60,7 +114,12 @@ namespace e2d
|
||||
typed_inspector_drawer() = default;
|
||||
~typed_inspector_drawer() noexcept final = default;
|
||||
|
||||
void operator()(gobject& go) const final;
|
||||
void operator()(
|
||||
gobject& go) const final;
|
||||
|
||||
void operator()(
|
||||
gobject& go,
|
||||
component_inspector<>::gizmos_context& ctx) const final;
|
||||
private:
|
||||
component_inspector<Component> inspector_;
|
||||
};
|
||||
@@ -78,7 +137,12 @@ namespace e2d
|
||||
template < typename Component >
|
||||
inspector& register_component(str_hash type);
|
||||
|
||||
void show_inspector_for(gobject& go);
|
||||
void show_for(
|
||||
gobject& go);
|
||||
|
||||
void show_for(
|
||||
gobject& go,
|
||||
component_inspector<>::gizmos_context& ctx);
|
||||
private:
|
||||
mutable std::mutex mutex_;
|
||||
hash_map<str_hash, impl::inspector_drawer_iptr> drawers_;
|
||||
|
||||
@@ -17,17 +17,39 @@ namespace e2d
|
||||
namespace impl
|
||||
{
|
||||
template < typename Component >
|
||||
void typed_inspector_drawer<Component>::operator()(gobject& go) const {
|
||||
gcomponent<Component> co = go.component<Component>();
|
||||
if ( !co ) {
|
||||
return;
|
||||
void typed_inspector_drawer<Component>::operator()(
|
||||
gobject& go) const
|
||||
{
|
||||
if constexpr ( utils::is_detected<has_component_inspector, Component>() ) {
|
||||
gcomponent<Component> co = go.component<Component>();
|
||||
if ( !co ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::PushID(co.find());
|
||||
E2D_DEFER([](){ ImGui::PopID(); });
|
||||
|
||||
if ( ImGui::CollapsingHeader(component_inspector<Component>::title) ) {
|
||||
inspector_(co);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PushID(co.find());
|
||||
E2D_DEFER([](){ ImGui::PopID(); });
|
||||
template < typename Component >
|
||||
void typed_inspector_drawer<Component>::operator()(
|
||||
gobject& go,
|
||||
component_inspector<>::gizmos_context& ctx) const
|
||||
{
|
||||
if constexpr ( utils::is_detected<has_component_inspector_gizmos, Component>() ) {
|
||||
gcomponent<Component> co = go.component<Component>();
|
||||
if ( !co ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ImGui::CollapsingHeader(component_inspector<Component>::title) ) {
|
||||
inspector_(co);
|
||||
ImGui::PushID(co.find());
|
||||
E2D_DEFER([](){ ImGui::PopID(); });
|
||||
|
||||
inspector_(co, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,20 @@ namespace e2d::systems
|
||||
f32 time{0.f};
|
||||
};
|
||||
|
||||
struct render_event {};
|
||||
struct pre_render_event {};
|
||||
struct post_render_event {};
|
||||
struct render_event {
|
||||
ecs::const_entity cam_e;
|
||||
};
|
||||
|
||||
struct pre_render_event {
|
||||
ecs::const_entity cam_e;
|
||||
};
|
||||
|
||||
struct post_render_event {
|
||||
ecs::const_entity cam_e;
|
||||
};
|
||||
|
||||
struct frame_update_event {};
|
||||
struct frame_render_event {};
|
||||
struct frame_finalize_event {};
|
||||
|
||||
using update_system = ecs::system<update_event>;
|
||||
|
||||
32
headers/enduro2d/high/systems/frame_system.hpp
Normal file
32
headers/enduro2d/high/systems/frame_system.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "_systems.hpp"
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
class frame_system final
|
||||
: public ecs::system<
|
||||
ecs::after<systems::frame_update_event>,
|
||||
ecs::after<systems::frame_render_event>> {
|
||||
public:
|
||||
frame_system();
|
||||
~frame_system() noexcept;
|
||||
|
||||
void process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::frame_update_event>& trigger) override;
|
||||
|
||||
void process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::frame_render_event>& trigger) override;
|
||||
private:
|
||||
class internal_state;
|
||||
std::unique_ptr<internal_state> state_;
|
||||
};
|
||||
}
|
||||
26
headers/enduro2d/high/systems/gizmos_system.hpp
Normal file
26
headers/enduro2d/high/systems/gizmos_system.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "_systems.hpp"
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
class gizmos_system final
|
||||
: public ecs::system<ecs::after<systems::render_event>> {
|
||||
public:
|
||||
gizmos_system();
|
||||
~gizmos_system() noexcept;
|
||||
|
||||
void process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::render_event>& trigger) override;
|
||||
private:
|
||||
class internal_state;
|
||||
std::unique_ptr<internal_state> state_;
|
||||
};
|
||||
}
|
||||
26
headers/enduro2d/high/systems/world_system.hpp
Normal file
26
headers/enduro2d/high/systems/world_system.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "_systems.hpp"
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
class world_system final
|
||||
: public ecs::system<ecs::after<systems::frame_finalize_event>> {
|
||||
public:
|
||||
world_system();
|
||||
~world_system() noexcept;
|
||||
|
||||
void process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::frame_finalize_event>& trigger) override;
|
||||
private:
|
||||
class internal_state;
|
||||
std::unique_ptr<internal_state> state_;
|
||||
};
|
||||
}
|
||||
@@ -73,6 +73,12 @@ namespace e2d
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
struct nonesuch {
|
||||
~nonesuch() = delete;
|
||||
nonesuch(const nonesuch&) = delete;
|
||||
void operator=(const nonesuch&) = delete;
|
||||
};
|
||||
|
||||
class noncopyable {
|
||||
public:
|
||||
noncopyable(const noncopyable&) = delete;
|
||||
@@ -212,4 +218,37 @@ namespace e2d::utils
|
||||
|
||||
template < typename... Ts >
|
||||
overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
//
|
||||
// detected
|
||||
//
|
||||
|
||||
namespace impl
|
||||
{
|
||||
template < typename Default
|
||||
, typename AlwaysVoid
|
||||
, template < typename... > class Op
|
||||
, typename... Args >
|
||||
struct detector {
|
||||
using value_t = std::false_type;
|
||||
using type = Default;
|
||||
};
|
||||
|
||||
template < typename Default
|
||||
, template < typename... > class Op
|
||||
, typename... Args >
|
||||
struct detector<Default, std::void_t<Op<Args...>>, Op, Args...> {
|
||||
using value_t = std::true_type;
|
||||
using type = Op<Args...>;
|
||||
};
|
||||
}
|
||||
|
||||
template < template < typename... > class Op, typename... Args >
|
||||
using is_detected = typename impl::detector<nonesuch, void, Op, Args...>::value_t;
|
||||
|
||||
template < template < typename... > class Op, typename... Args >
|
||||
using detected_t = typename impl::detector<nonesuch, void, Op, Args...>::type;
|
||||
|
||||
template < typename Default, template < typename... > class Op, typename... Args >
|
||||
using detected_or = impl::detector<Default, void, Op, Args...>;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
{
|
||||
"components" : {
|
||||
"named" : {
|
||||
"name" : "camera"
|
||||
},
|
||||
"camera" : {
|
||||
"background" : [1.0, 0.4, 0.0, 1.0]
|
||||
}
|
||||
},
|
||||
"camera.gizmos" : {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
"actor" : {
|
||||
"translation" : [0,0],
|
||||
"scale" : 20
|
||||
},
|
||||
"named" : {
|
||||
"name" : "gnome"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@@ -20,18 +23,25 @@
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [-50,-50]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"prototype" : "../prefabs/ship_prefab.json",
|
||||
"components" : {
|
||||
"sprite_renderer" : {
|
||||
"tint" : [255,0,0,255]
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [50,-50]
|
||||
"named" : {
|
||||
"name" : "ship(1)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"children" : [{
|
||||
"prototype" : "../prefabs/ship_prefab.json",
|
||||
"components" : {
|
||||
"sprite_renderer" : {
|
||||
"tint" : [255,0,0,255]
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [100,0]
|
||||
},
|
||||
"named" : {
|
||||
"name" : "ship(2)"
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
"prototype" : "../prefabs/label_bm_prefab.json",
|
||||
"components" : {
|
||||
@@ -44,6 +54,9 @@
|
||||
"actor" : {
|
||||
"translation" : [0,180],
|
||||
"scale" : 3
|
||||
},
|
||||
"named" : {
|
||||
"name" : "label(1)"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@@ -58,6 +71,9 @@
|
||||
"actor" : {
|
||||
"translation" : [0.5,-180.5],
|
||||
"scale" : 3
|
||||
},
|
||||
"named" : {
|
||||
"name" : "label(2)"
|
||||
}
|
||||
}
|
||||
}]
|
||||
@@ -10,6 +10,9 @@
|
||||
"actor" : {
|
||||
"translation" : [350,250],
|
||||
"scale" : 0.25
|
||||
},
|
||||
"named" : {
|
||||
"name" : "coin"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@@ -18,6 +21,9 @@
|
||||
"actor" : {
|
||||
"translation" : [300,-350],
|
||||
"scale" : 0.25
|
||||
},
|
||||
"named" : {
|
||||
"name" : "raptor"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@@ -26,6 +32,9 @@
|
||||
"actor" : {
|
||||
"translation" : [-100,0],
|
||||
"scale" : 0.9
|
||||
},
|
||||
"named" : {
|
||||
"name" : "dragon"
|
||||
}
|
||||
}
|
||||
}]
|
||||
@@ -212,6 +212,8 @@ namespace
|
||||
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
auto params = engine::parameters("sample_00", "enduro2d")
|
||||
.window_params(engine::window_parameters()
|
||||
.size({1024, 768}))
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100));
|
||||
modules::initialize<engine>(argc, argv, params).start<game>();
|
||||
|
||||
@@ -272,6 +272,8 @@ namespace
|
||||
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
auto params = engine::parameters("sample_01", "enduro2d")
|
||||
.window_params(engine::window_parameters()
|
||||
.size({1024, 768}))
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100));
|
||||
modules::initialize<engine>(argc, argv, params).start<game>();
|
||||
|
||||
@@ -254,6 +254,8 @@ namespace
|
||||
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
auto params = engine::parameters("sample_02", "enduro2d")
|
||||
.window_params(engine::window_parameters()
|
||||
.size({1024, 768}))
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100));
|
||||
modules::initialize<engine>(argc, argv, params).start<game>();
|
||||
|
||||
@@ -39,11 +39,11 @@ namespace
|
||||
}
|
||||
};
|
||||
|
||||
class camera_system final : public systems::render_system {
|
||||
class camera_system final : public systems::post_update_system {
|
||||
public:
|
||||
void process(
|
||||
ecs::registry& owner,
|
||||
const systems::render_event& event) override
|
||||
const systems::post_update_event& event) override
|
||||
{
|
||||
E2D_UNUSED(event);
|
||||
owner.for_joined_components<camera>(
|
||||
@@ -192,6 +192,8 @@ namespace
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
const auto starter_params = starter::parameters(
|
||||
engine::parameters("sample_03", "enduro2d")
|
||||
.window_params(engine::window_parameters()
|
||||
.size({1024, 768}))
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100)));
|
||||
modules::initialize<starter>(argc, argv, starter_params).start<game>();
|
||||
|
||||
@@ -32,11 +32,11 @@ namespace
|
||||
}
|
||||
};
|
||||
|
||||
class camera_system final : public systems::render_system {
|
||||
class camera_system final : public systems::post_update_system {
|
||||
public:
|
||||
void process(
|
||||
ecs::registry& owner,
|
||||
const systems::render_event& event) override
|
||||
const systems::post_update_event& event) override
|
||||
{
|
||||
E2D_UNUSED(event);
|
||||
owner.for_joined_components<camera>(
|
||||
@@ -59,7 +59,7 @@ namespace
|
||||
}
|
||||
private:
|
||||
bool create_scene() {
|
||||
auto scene_prefab_res = the<library>().load_asset<prefab_asset>("scenes/scene_prefab.json");
|
||||
auto scene_prefab_res = the<library>().load_asset<prefab_asset>("scenes/sample_04.json");
|
||||
auto scene_go = scene_prefab_res
|
||||
? the<world>().instantiate(scene_prefab_res->content())
|
||||
: gobject();
|
||||
@@ -79,6 +79,8 @@ namespace
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
const auto starter_params = starter::parameters(
|
||||
engine::parameters("sample_04", "enduro2d")
|
||||
.window_params(engine::window_parameters()
|
||||
.size({1024, 768}))
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100)));
|
||||
modules::initialize<starter>(argc, argv, starter_params).start<game>();
|
||||
|
||||
@@ -79,6 +79,8 @@ namespace
|
||||
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
auto params = engine::parameters("sample_05", "enduro2d")
|
||||
.window_params(engine::window_parameters()
|
||||
.size({1024, 768}))
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100));
|
||||
modules::initialize<engine>(argc, argv, params).start<game>();
|
||||
|
||||
@@ -70,11 +70,11 @@ namespace
|
||||
}
|
||||
};
|
||||
|
||||
class camera_system final : public systems::render_system {
|
||||
class camera_system final : public systems::post_update_system {
|
||||
public:
|
||||
void process(
|
||||
ecs::registry& owner,
|
||||
const systems::render_event& event) override
|
||||
const systems::post_update_event& event) override
|
||||
{
|
||||
E2D_UNUSED(event);
|
||||
owner.for_joined_components<camera>(
|
||||
@@ -97,7 +97,7 @@ namespace
|
||||
}
|
||||
private:
|
||||
bool create_scene() {
|
||||
auto scene_prefab_res = the<library>().load_asset<prefab_asset>("scenes/spine_scene_prefab.json");
|
||||
auto scene_prefab_res = the<library>().load_asset<prefab_asset>("scenes/sample_06.json");
|
||||
auto scene_go = scene_prefab_res
|
||||
? the<world>().instantiate(scene_prefab_res->content())
|
||||
: gobject();
|
||||
|
||||
@@ -32,11 +32,11 @@ namespace
|
||||
}
|
||||
};
|
||||
|
||||
class camera_system final : public systems::render_system {
|
||||
class camera_system final : public systems::post_update_system {
|
||||
public:
|
||||
void process(
|
||||
ecs::registry& owner,
|
||||
const systems::render_event& event) override
|
||||
const systems::post_update_event& event) override
|
||||
{
|
||||
E2D_UNUSED(event);
|
||||
owner.for_joined_components<camera>(
|
||||
@@ -79,6 +79,8 @@ namespace
|
||||
int e2d_main(int argc, char *argv[]) {
|
||||
const auto starter_params = starter::parameters(
|
||||
engine::parameters("sample_07", "enduro2d")
|
||||
.window_params(engine::window_parameters()
|
||||
.size({1024, 768}))
|
||||
.timer_params(engine::timer_parameters()
|
||||
.maximal_framerate(100)));
|
||||
modules::initialize<starter>(argc, argv, starter_params).start<game>();
|
||||
|
||||
@@ -97,20 +97,20 @@ namespace e2d::imgex
|
||||
|
||||
template < typename F >
|
||||
void with_main_dock_space(F&& f) {
|
||||
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport->Pos);
|
||||
ImGui::SetNextWindowSize(viewport->Size);
|
||||
ImGui::SetNextWindowViewport(viewport->ID);
|
||||
if ( ImGuiViewport* viewport = ImGui::GetMainViewport() ) {
|
||||
ImGui::SetNextWindowPos(viewport->Pos);
|
||||
ImGui::SetNextWindowSize(viewport->Size);
|
||||
ImGui::SetNextWindowViewport(viewport->ID);
|
||||
}
|
||||
|
||||
ImGuiWindowFlags window_flags =
|
||||
const ImGuiWindowFlags window_flags =
|
||||
ImGuiWindowFlags_MenuBar |
|
||||
ImGuiWindowFlags_NoNav |
|
||||
ImGuiWindowFlags_NoDocking |
|
||||
ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoBackground |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus;
|
||||
ImGuiWindowFlags_NoBackground;
|
||||
|
||||
ImGuiDockNodeFlags dock_node_flags =
|
||||
const ImGuiDockNodeFlags dock_node_flags =
|
||||
ImGuiDockNodeFlags_PassthruCentralNode |
|
||||
ImGuiDockNodeFlags_NoDockingInCentralNode;
|
||||
|
||||
|
||||
@@ -76,11 +76,47 @@ namespace e2d
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* factory_loader<camera::gizmos>::schema_source = R"json({
|
||||
"type" : "object",
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {}
|
||||
})json";
|
||||
|
||||
bool factory_loader<camera::gizmos>::operator()(
|
||||
camera::gizmos& component,
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(component, ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool factory_loader<camera::gizmos>::operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(dependencies, ctx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* component_inspector<camera>::title = "camera";
|
||||
|
||||
void component_inspector<camera>::operator()(gcomponent<camera>& c) const {
|
||||
if ( bool gizmos = c.owner().component<camera::gizmos>().exists();
|
||||
ImGui::Checkbox("gizmos", &gizmos) )
|
||||
{
|
||||
if ( gizmos ) {
|
||||
c.owner().component<camera::gizmos>().ensure();
|
||||
} else {
|
||||
c.owner().component<camera::gizmos>().remove();
|
||||
}
|
||||
}
|
||||
|
||||
if ( i32 depth = c->depth();
|
||||
ImGui::DragInt("depth", &depth) )
|
||||
{
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace e2d
|
||||
dependencies.add_dependency<atlas_asset, sprite_asset>(
|
||||
path::combine(ctx.parent_address, ctx.root["atlas"].GetString()));
|
||||
}
|
||||
|
||||
|
||||
if ( ctx.root.HasMember("sprite") ) {
|
||||
dependencies.add_dependency<sprite_asset>(
|
||||
path::combine(ctx.parent_address, ctx.root["sprite"].GetString()));
|
||||
@@ -196,4 +196,21 @@ namespace e2d
|
||||
///TODO(BlackMat): add 'sprite' inspector
|
||||
///TODO(BlackMat): add 'materials' inspector
|
||||
}
|
||||
|
||||
void component_inspector<sprite_renderer>::operator()(
|
||||
gcomponent<sprite_renderer>& c,
|
||||
gizmos_context& ctx) const
|
||||
{
|
||||
if ( const sprite_asset::ptr& spr_a = c->sprite() ) {
|
||||
const sprite& spr = spr_a->content();
|
||||
const v2f& s = spr.texrect().size;
|
||||
const v2f& p = spr.texrect().position - spr.pivot();
|
||||
ctx.draw_wire_rect(
|
||||
p,
|
||||
p + s * v2f::unit_x(),
|
||||
p + s,
|
||||
p + s * v2f::unit_y(),
|
||||
ctx.selected() ? color32::yellow() : color32::magenta());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,17 @@
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
void inspector::show_inspector_for(gobject& go) {
|
||||
void inspector::show_for(gobject& go) {
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
for ( auto& p : drawers_ ) {
|
||||
(*p.second)(go);
|
||||
}
|
||||
}
|
||||
|
||||
void inspector::show_for(gobject& go, component_inspector<>::gizmos_context& ctx) {
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
for ( auto& p : drawers_ ) {
|
||||
(*p.second)(go, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,13 @@
|
||||
#include <enduro2d/high/components/sprite_renderer.hpp>
|
||||
|
||||
#include <enduro2d/high/systems/flipbook_system.hpp>
|
||||
#include <enduro2d/high/systems/frame_system.hpp>
|
||||
#include <enduro2d/high/systems/gizmos_system.hpp>
|
||||
#include <enduro2d/high/systems/label_system.hpp>
|
||||
#include <enduro2d/high/systems/render_system.hpp>
|
||||
#include <enduro2d/high/systems/script_system.hpp>
|
||||
#include <enduro2d/high/systems/spine_system.hpp>
|
||||
#include <enduro2d/high/systems/world_system.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -54,6 +57,10 @@ namespace
|
||||
ecs::registry_filler(the<world>().registry())
|
||||
.feature<struct flipbook_feature>(ecs::feature()
|
||||
.add_system<flipbook_system>())
|
||||
.feature<struct frame_feature>(ecs::feature()
|
||||
.add_system<frame_system>())
|
||||
.feature<struct gizmos_feature>(ecs::feature()
|
||||
.add_system<gizmos_system>())
|
||||
.feature<struct label_feature>(ecs::feature()
|
||||
.add_system<label_system>())
|
||||
.feature<struct render_feature>(ecs::feature()
|
||||
@@ -61,7 +68,9 @@ namespace
|
||||
.feature<struct script_feature>(ecs::feature()
|
||||
.add_system<script_system>())
|
||||
.feature<struct spine_feature>(ecs::feature()
|
||||
.add_system<spine_system>());
|
||||
.add_system<spine_system>())
|
||||
.feature<struct world_feature>(ecs::feature()
|
||||
.add_system<world_system>());
|
||||
return !application_ || application_->initialize();
|
||||
}
|
||||
|
||||
@@ -73,67 +82,19 @@ namespace
|
||||
|
||||
bool frame_tick() final {
|
||||
E2D_PROFILER_SCOPE("application.frame_tick");
|
||||
|
||||
world& w = the<world>();
|
||||
engine& e = the<engine>();
|
||||
|
||||
const f32 dt = e.delta_time();
|
||||
const f32 time = e.time();
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.pre_update");
|
||||
w.registry().process_event(systems::pre_update_event{dt,time});
|
||||
}
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.update");
|
||||
w.registry().process_event(systems::update_event{dt,time});
|
||||
}
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.post_update");
|
||||
w.registry().process_event(systems::post_update_event{dt,time});
|
||||
}
|
||||
|
||||
the<world>().registry().process_event(systems::frame_update_event{});
|
||||
return !the<window>().should_close()
|
||||
|| (application_ && !application_->on_should_close());
|
||||
}
|
||||
|
||||
void frame_render() final {
|
||||
E2D_PROFILER_SCOPE("application.frame_render");
|
||||
|
||||
world& w = the<world>();
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.pre_render");
|
||||
w.registry().process_event(systems::pre_render_event{});
|
||||
}
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.render");
|
||||
w.registry().process_event(systems::render_event{});
|
||||
}
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.post_render");
|
||||
w.registry().process_event(systems::post_render_event{});
|
||||
}
|
||||
the<world>().registry().process_event(systems::frame_render_event{});
|
||||
}
|
||||
|
||||
void frame_finalize() final {
|
||||
E2D_PROFILER_SCOPE("application.frame_finalize");
|
||||
|
||||
world& w = the<world>();
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.frame_finalize");
|
||||
w.registry().process_event(systems::frame_finalize_event{});
|
||||
}
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("world.finalize_instances");
|
||||
w.finalize_instances();
|
||||
}
|
||||
the<world>().registry().process_event(systems::frame_finalize_event{});
|
||||
}
|
||||
private:
|
||||
starter::application_uptr application_;
|
||||
@@ -220,6 +181,7 @@ namespace e2d
|
||||
.register_component<actor>("actor")
|
||||
.register_component<behaviour>("behaviour")
|
||||
.register_component<camera>("camera")
|
||||
.register_component<camera::gizmos>("camera.gizmos")
|
||||
.register_component<flipbook_player>("flipbook_player")
|
||||
.register_component<label>("label")
|
||||
.register_component<label::dirty>("label.dirty")
|
||||
@@ -236,6 +198,7 @@ namespace e2d
|
||||
.register_component<actor>("actor")
|
||||
.register_component<behaviour>("behaviour")
|
||||
.register_component<camera>("camera")
|
||||
//.register_component<camera::gizmos>("camera.gizmos")
|
||||
.register_component<flipbook_player>("flipbook_player")
|
||||
.register_component<label>("label")
|
||||
//.register_component<label::dirty>("label.dirty")
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace e2d
|
||||
internal_state() = default;
|
||||
~internal_state() noexcept = default;
|
||||
|
||||
void process(f32 dt, ecs::registry& owner) {
|
||||
void process_update(f32 dt, ecs::registry& owner) {
|
||||
update_flipbook_timers(dt, owner);
|
||||
update_flipbook_sprites(owner);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ namespace e2d
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::update_event>& trigger)
|
||||
{
|
||||
E2D_PROFILER_SCOPE("flipbook_system.process");
|
||||
state_->process(trigger.event.dt, owner);
|
||||
E2D_PROFILER_SCOPE("flipbook_system.process_update");
|
||||
state_->process_update(trigger.event.dt, owner);
|
||||
}
|
||||
}
|
||||
|
||||
114
sources/enduro2d/high/systems/frame_system.cpp
Normal file
114
sources/enduro2d/high/systems/frame_system.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include <enduro2d/high/systems/frame_system.hpp>
|
||||
|
||||
#include <enduro2d/high/components/camera.hpp>
|
||||
#include <enduro2d/high/components/disabled.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace e2d;
|
||||
|
||||
template < typename Event >
|
||||
void for_all_cameras(ecs::registry& owner) {
|
||||
const auto comp = [](const auto& l, const auto& r) noexcept {
|
||||
return std::get<camera>(l).depth() < std::get<camera>(r).depth();
|
||||
};
|
||||
|
||||
const auto func = [&owner](
|
||||
const ecs::const_entity& e,
|
||||
const camera&)
|
||||
{
|
||||
owner.process_event(Event{e});
|
||||
};
|
||||
|
||||
systems::for_extracted_sorted_components<camera>(
|
||||
owner,
|
||||
comp,
|
||||
func,
|
||||
!ecs::exists<disabled<camera>>());
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
//
|
||||
// frame_system::internal_state
|
||||
//
|
||||
|
||||
class frame_system::internal_state final : private noncopyable {
|
||||
public:
|
||||
internal_state(engine& e)
|
||||
: engine_(e) {}
|
||||
~internal_state() noexcept = default;
|
||||
|
||||
void process_frame_update(ecs::registry& owner) {
|
||||
const f32 dt = engine_.delta_time();
|
||||
const f32 time = engine_.time();
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.pre_update");
|
||||
owner.process_event(systems::pre_update_event{dt,time});
|
||||
}
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.update");
|
||||
owner.process_event(systems::update_event{dt,time});
|
||||
}
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.post_update");
|
||||
owner.process_event(systems::post_update_event{dt,time});
|
||||
}
|
||||
}
|
||||
|
||||
void process_frame_render(ecs::registry& owner) {
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.pre_render");
|
||||
for_all_cameras<systems::pre_render_event>(owner);
|
||||
}
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.render");
|
||||
for_all_cameras<systems::render_event>(owner);
|
||||
}
|
||||
|
||||
{
|
||||
E2D_PROFILER_SCOPE("ecs.post_render");
|
||||
for_all_cameras<systems::post_render_event>(owner);
|
||||
}
|
||||
}
|
||||
private:
|
||||
engine& engine_;
|
||||
};
|
||||
|
||||
//
|
||||
// frame_system
|
||||
//
|
||||
|
||||
frame_system::frame_system()
|
||||
: state_(new internal_state(the<engine>())) {}
|
||||
frame_system::~frame_system() noexcept = default;
|
||||
|
||||
void frame_system::process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::frame_update_event>& trigger)
|
||||
{
|
||||
E2D_UNUSED(trigger);
|
||||
E2D_PROFILER_SCOPE("frame_system.frame_update");
|
||||
state_->process_frame_update(owner);
|
||||
}
|
||||
|
||||
void frame_system::process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::frame_render_event>& trigger)
|
||||
{
|
||||
E2D_UNUSED(trigger);
|
||||
E2D_PROFILER_SCOPE("frame_system.process_frame_render");
|
||||
state_->process_frame_render(owner);
|
||||
}
|
||||
}
|
||||
263
sources/enduro2d/high/systems/gizmos_system.cpp
Normal file
263
sources/enduro2d/high/systems/gizmos_system.cpp
Normal file
@@ -0,0 +1,263 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include <enduro2d/high/systems/gizmos_system.hpp>
|
||||
|
||||
#include <enduro2d/high/components/actor.hpp>
|
||||
#include <enduro2d/high/components/camera.hpp>
|
||||
|
||||
#include <enduro2d/high/editor.hpp>
|
||||
#include <enduro2d/high/inspector.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace e2d;
|
||||
|
||||
ImU32 to_imgui_color(const color32& c) noexcept {
|
||||
return ImGui::GetColorU32(make_vec4(color(c)));
|
||||
}
|
||||
|
||||
class imgui_gizmos_context final : public component_inspector<>::gizmos_context {
|
||||
public:
|
||||
imgui_gizmos_context(editor& e, inspector& i)
|
||||
: editor_(e)
|
||||
, inspector_(i) {}
|
||||
|
||||
bool setup_camera(const ecs::const_entity& cam_e) {
|
||||
if ( !cam_e.valid() || !ecs::exists_all<actor, camera, camera::gizmos>()(cam_e) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const camera& cam = cam_e.get_component<camera>();
|
||||
const actor& cam_a = cam_e.get_component<actor>();
|
||||
|
||||
const const_node_iptr& cam_n = cam_a.node();
|
||||
if ( !cam_n ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
camera_vp_ =
|
||||
math::inversed(cam_n->world_matrix()).first *
|
||||
cam.projection() *
|
||||
math::make_scale_matrix4(0.5f, -0.5f) *
|
||||
math::make_translation_matrix4(0.5f, 0.5f) *
|
||||
math::make_scale_matrix4(v2f(ImGui::GetIO().DisplaySize));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool setup_node(const ecs::const_entity& e) {
|
||||
if ( !e.valid() || !ecs::exists_all<actor>()(e) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const actor& e_a = e.get_component<actor>();
|
||||
const const_node_iptr& e_n = e_a.node();
|
||||
if ( !e_n ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gobject e_go = e_n->owner();
|
||||
if ( !e_go ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
go_matrix_ = e_n->world_matrix() * camera_vp_;
|
||||
go_selected_ = e_go == editor_.selection();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool show_for(const ecs::const_entity& e) {
|
||||
if ( !e.valid() || !ecs::exists_all<actor>()(e) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const actor& e_a = e.get_component<actor>();
|
||||
const const_node_iptr& e_n = e_a.node();
|
||||
if ( !e_n ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gobject e_go = e_n->owner();
|
||||
if ( !e_go ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
inspector_.show_for(e_go, *this);
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
void draw_line(
|
||||
const v2f& p1,
|
||||
const v2f& p2,
|
||||
const color32& color) final
|
||||
{
|
||||
const v2f pp1 = v2f(v4f(p1, 0.f, 1.f) * go_matrix_);
|
||||
const v2f pp2 = v2f(v4f(p2, 0.f, 1.f) * go_matrix_);
|
||||
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddLine(pp1, pp2, to_imgui_color(color));
|
||||
}
|
||||
|
||||
void draw_rect(
|
||||
const v2f& p1,
|
||||
const v2f& p2,
|
||||
const v2f& p3,
|
||||
const v2f& p4,
|
||||
const color32& color) final
|
||||
{
|
||||
const v2f pp1 = v2f(v4f(p1, 0.f, 1.f) * go_matrix_);
|
||||
const v2f pp2 = v2f(v4f(p2, 0.f, 1.f) * go_matrix_);
|
||||
const v2f pp3 = v2f(v4f(p3, 0.f, 1.f) * go_matrix_);
|
||||
const v2f pp4 = v2f(v4f(p4, 0.f, 1.f) * go_matrix_);
|
||||
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddQuadFilled(pp1, pp2, pp3, pp4, to_imgui_color(color));
|
||||
}
|
||||
|
||||
void draw_wire_rect(
|
||||
const v2f& p1,
|
||||
const v2f& p2,
|
||||
const v2f& p3,
|
||||
const v2f& p4,
|
||||
const color32& color) final
|
||||
{
|
||||
const v2f pp1 = v2f(v4f(p1, 0.f, 1.f) * go_matrix_);
|
||||
const v2f pp2 = v2f(v4f(p2, 0.f, 1.f) * go_matrix_);
|
||||
const v2f pp3 = v2f(v4f(p3, 0.f, 1.f) * go_matrix_);
|
||||
const v2f pp4 = v2f(v4f(p4, 0.f, 1.f) * go_matrix_);
|
||||
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddQuad(pp1, pp2, pp3, pp4, to_imgui_color(color));
|
||||
}
|
||||
|
||||
void draw_circle(
|
||||
const v2f& center,
|
||||
f32 radius,
|
||||
u32 segments,
|
||||
const color32& color) final
|
||||
{
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
for ( u32 i = 0, e = math::max(6u, segments); i < e; ++i ) {
|
||||
const radf a =
|
||||
math::two_pi<f32>() /
|
||||
math::numeric_cast<f32>(e) *
|
||||
math::numeric_cast<f32>(i);
|
||||
const v2f p =
|
||||
center +
|
||||
v2f(math::cos(a), math::sin(a)) *
|
||||
radius;
|
||||
draw_list->PathLineTo(v2f(v4f(p, 0.f, 1.f) * go_matrix_));
|
||||
}
|
||||
draw_list->PathFillConvex(to_imgui_color(color));
|
||||
}
|
||||
|
||||
void draw_wire_circle(
|
||||
const v2f& center,
|
||||
f32 radius,
|
||||
u32 segments,
|
||||
const color32& color) final
|
||||
{
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
for ( u32 i = 0, e = math::max(6u, segments); i < e; ++i ) {
|
||||
const radf a =
|
||||
math::two_pi<f32>() /
|
||||
math::numeric_cast<f32>(e) *
|
||||
math::numeric_cast<f32>(i);
|
||||
const v2f p =
|
||||
center +
|
||||
v2f(math::cos(a), math::sin(a)) *
|
||||
radius;
|
||||
draw_list->PathLineTo(v2f(v4f(p, 0.f, 1.f) * go_matrix_));
|
||||
}
|
||||
draw_list->PathStroke(to_imgui_color(color), true);
|
||||
}
|
||||
|
||||
bool selected() const noexcept final {
|
||||
return go_selected_;
|
||||
}
|
||||
private:
|
||||
editor& editor_;
|
||||
inspector& inspector_;
|
||||
m4f camera_vp_ = m4f::identity();
|
||||
m4f go_matrix_ = m4f::identity();
|
||||
bool go_selected_ = false;
|
||||
};
|
||||
|
||||
template < typename F, typename... Args >
|
||||
void with_gizmos_window(F&& f, Args&&... args) {
|
||||
if ( ImGuiViewport* viewport = ImGui::GetMainViewport() ) {
|
||||
ImGui::SetNextWindowPos(viewport->Pos);
|
||||
ImGui::SetNextWindowSize(viewport->Size);
|
||||
ImGui::SetNextWindowViewport(viewport->ID);
|
||||
}
|
||||
|
||||
const ImGuiWindowFlags window_flags =
|
||||
ImGuiWindowFlags_NoNav |
|
||||
ImGuiWindowFlags_NoDocking |
|
||||
ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoBackground |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
|
||||
|
||||
ImGui::Begin("e2d_gizmos_window", nullptr, window_flags);
|
||||
E2D_DEFER([](){ ImGui::End(); });
|
||||
|
||||
ImGui::PopStyleVar(3);
|
||||
|
||||
std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
//
|
||||
// gizmos_system::internal_state
|
||||
//
|
||||
|
||||
class gizmos_system::internal_state final : private noncopyable {
|
||||
public:
|
||||
internal_state(dbgui& d, editor& e, inspector& i)
|
||||
: dbgui_(d)
|
||||
, gcontext_(e, i) {}
|
||||
~internal_state() noexcept = default;
|
||||
|
||||
void process_render(const ecs::const_entity& cam_e, ecs::registry& owner) {
|
||||
if ( !dbgui_.visible() || !gcontext_.setup_camera(cam_e) ) {
|
||||
return;
|
||||
}
|
||||
with_gizmos_window([this, &owner](){
|
||||
owner.for_joined_components<actor>([this](const ecs::const_entity& e, const actor&){
|
||||
if ( gcontext_.setup_node(e) ) {
|
||||
gcontext_.show_for(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
private:
|
||||
dbgui& dbgui_;
|
||||
imgui_gizmos_context gcontext_;
|
||||
};
|
||||
|
||||
//
|
||||
// gizmos_system
|
||||
//
|
||||
|
||||
gizmos_system::gizmos_system()
|
||||
: state_(new internal_state(the<dbgui>(), the<editor>(), the<inspector>())) {}
|
||||
gizmos_system::~gizmos_system() noexcept = default;
|
||||
|
||||
void gizmos_system::process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::render_event>& trigger)
|
||||
{
|
||||
E2D_PROFILER_SCOPE("gizmos_system.process_render");
|
||||
state_->process_render(trigger.event.cam_e, owner);
|
||||
}
|
||||
}
|
||||
@@ -378,7 +378,7 @@ namespace e2d
|
||||
internal_state() = default;
|
||||
~internal_state() noexcept = default;
|
||||
|
||||
void process(ecs::registry& owner) {
|
||||
void process_update(ecs::registry& owner) {
|
||||
update_dirty_labels(owner);
|
||||
}
|
||||
};
|
||||
@@ -396,7 +396,7 @@ namespace e2d
|
||||
const ecs::after<systems::update_event>& trigger)
|
||||
{
|
||||
E2D_UNUSED(trigger);
|
||||
E2D_PROFILER_SCOPE("label_system.process");
|
||||
state_->process(owner);
|
||||
E2D_PROFILER_SCOPE("label_system.process_update");
|
||||
state_->process_update(owner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ namespace
|
||||
using namespace e2d::render_system_impl;
|
||||
|
||||
void for_all_scenes(drawer::context& ctx, const ecs::registry& owner) {
|
||||
E2D_PROFILER_SCOPE("render_system.for_all_scenes");
|
||||
|
||||
const auto comp = [](const auto& l, const auto& r) noexcept {
|
||||
return std::get<scene>(l).depth() < std::get<scene>(r).depth();
|
||||
};
|
||||
@@ -43,30 +41,6 @@ namespace
|
||||
func,
|
||||
!ecs::exists<disabled<scene>>());
|
||||
}
|
||||
|
||||
void for_all_cameras(drawer& drawer, const ecs::registry& owner) {
|
||||
E2D_PROFILER_SCOPE("render_system.for_all_cameras");
|
||||
|
||||
const auto comp = [](const auto& l, const auto& r) noexcept {
|
||||
return std::get<camera>(l).depth() < std::get<camera>(r).depth();
|
||||
};
|
||||
|
||||
const auto func = [&drawer, &owner](
|
||||
const ecs::const_entity&,
|
||||
const camera& cam,
|
||||
const actor& cam_a)
|
||||
{
|
||||
drawer.with(cam, cam_a.node(), [&owner](drawer::context& ctx){
|
||||
for_all_scenes(ctx, owner);
|
||||
});
|
||||
};
|
||||
|
||||
systems::for_extracted_sorted_components<camera, actor>(
|
||||
owner,
|
||||
comp,
|
||||
func,
|
||||
!ecs::exists<disabled<camera>>());
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
@@ -81,8 +55,16 @@ namespace e2d
|
||||
: drawer_(the<engine>(), the<debug>(), the<render>(), the<window>()) {}
|
||||
~internal_state() noexcept = default;
|
||||
|
||||
void process(ecs::registry& owner) {
|
||||
for_all_cameras(drawer_, owner);
|
||||
void process_render(const ecs::const_entity& cam_e, ecs::registry& owner) {
|
||||
if ( !cam_e.valid() || !ecs::exists_all<actor, camera>()(cam_e) ) {
|
||||
return;
|
||||
}
|
||||
drawer_.with(
|
||||
cam_e.get_component<camera>(),
|
||||
cam_e.get_component<actor>().node(),
|
||||
[&owner](drawer::context& ctx){
|
||||
for_all_scenes(ctx, owner);
|
||||
});
|
||||
}
|
||||
private:
|
||||
drawer drawer_;
|
||||
@@ -100,8 +82,7 @@ namespace e2d
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::render_event>& trigger)
|
||||
{
|
||||
E2D_UNUSED(trigger);
|
||||
E2D_PROFILER_SCOPE("render_system.process");
|
||||
state_->process(owner);
|
||||
E2D_PROFILER_SCOPE("render_system.process_render");
|
||||
state_->process_render(trigger.event.cam_e, owner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace e2d
|
||||
}
|
||||
~internal_state() noexcept = default;
|
||||
|
||||
void update_process(ecs::registry& owner) {
|
||||
void process_update(ecs::registry& owner) {
|
||||
systems::for_extracted_components<behaviour, actor>(owner,
|
||||
[](ecs::entity e, behaviour& b, actor& a){
|
||||
if ( !a.node() || !a.node()->owner() ) {
|
||||
@@ -125,8 +125,8 @@ namespace e2d
|
||||
const systems::update_event& event)
|
||||
{
|
||||
E2D_UNUSED(event);
|
||||
E2D_PROFILER_SCOPE("script_system.process");
|
||||
state_->update_process(owner);
|
||||
E2D_PROFILER_SCOPE("script_system.process_update");
|
||||
state_->process_update(owner);
|
||||
}
|
||||
|
||||
void script_system::process(
|
||||
@@ -134,7 +134,7 @@ namespace e2d
|
||||
const ecs::before<systems::update_event>& trigger)
|
||||
{
|
||||
E2D_UNUSED(trigger);
|
||||
E2D_PROFILER_SCOPE("script_system.process");
|
||||
E2D_PROFILER_SCOPE("script_system.process_events");
|
||||
state_->process_events(owner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ namespace e2d
|
||||
internal_state() = default;
|
||||
~internal_state() noexcept = default;
|
||||
|
||||
void process(f32 dt, ecs::registry& owner) {
|
||||
void process_update(f32 dt, ecs::registry& owner) {
|
||||
process_commands(owner);
|
||||
clear_commands(owner);
|
||||
clear_events(owner);
|
||||
@@ -258,7 +258,7 @@ namespace e2d
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::update_event>& trigger)
|
||||
{
|
||||
E2D_PROFILER_SCOPE("spine_system.process");
|
||||
state_->process(trigger.event.dt, owner);
|
||||
E2D_PROFILER_SCOPE("spine_system.process_update");
|
||||
state_->process_update(trigger.event.dt, owner);
|
||||
}
|
||||
}
|
||||
|
||||
47
sources/enduro2d/high/systems/world_system.cpp
Normal file
47
sources/enduro2d/high/systems/world_system.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include <enduro2d/high/systems/world_system.hpp>
|
||||
|
||||
#include <enduro2d/high/world.hpp>
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
//
|
||||
// world_system::internal_state
|
||||
//
|
||||
|
||||
class world_system::internal_state final : private noncopyable {
|
||||
public:
|
||||
internal_state(world& w)
|
||||
: world_(w) {}
|
||||
~internal_state() noexcept = default;
|
||||
|
||||
void process_frame_finalize(ecs::registry& owner) {
|
||||
E2D_UNUSED(owner);
|
||||
world_.finalize_instances();
|
||||
}
|
||||
private:
|
||||
world& world_;
|
||||
};
|
||||
|
||||
//
|
||||
// world_system
|
||||
//
|
||||
|
||||
world_system::world_system()
|
||||
: state_(new internal_state(the<world>())) {}
|
||||
world_system::~world_system() noexcept = default;
|
||||
|
||||
void world_system::process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::frame_finalize_event>& trigger)
|
||||
{
|
||||
E2D_UNUSED(trigger);
|
||||
E2D_PROFILER_SCOPE("world_system.process_frame_finalize");
|
||||
state_->process_frame_finalize(owner);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace e2d::dbgui_widgets
|
||||
}
|
||||
|
||||
gobject go = the<editor>().selection();
|
||||
the<inspector>().show_inspector_for(go);
|
||||
the<inspector>().show_for(go);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user