more defers instead try/catch in render_system

This commit is contained in:
BlackMATov
2020-02-18 03:28:32 +07:00
parent bb39b280cf
commit ab8b0ea236
2 changed files with 65 additions and 58 deletions

View File

@@ -20,6 +20,17 @@ namespace
using namespace e2d; using namespace e2d;
using namespace e2d::render_system_impl; using namespace e2d::render_system_impl;
void for_all_children(
const const_node_iptr& root,
drawer::context& ctx)
{
ctx.draw(root);
nodes::for_each_child(root, [&ctx](const const_node_iptr& child){
for_all_children(child, ctx);
});
}
void for_all_scenes(drawer::context& ctx, const ecs::registry& owner) { void for_all_scenes(drawer::context& ctx, const ecs::registry& owner) {
const auto comp = [](const auto& l, const auto& r) noexcept { const auto comp = [](const auto& l, const auto& r) noexcept {
return std::get<scene>(l).depth() < std::get<scene>(r).depth(); return std::get<scene>(l).depth() < std::get<scene>(r).depth();
@@ -28,18 +39,18 @@ namespace
const auto func = [&ctx]( const auto func = [&ctx](
const ecs::const_entity&, const ecs::const_entity&,
const scene&, const scene&,
const actor& scn_a) const actor& scene_a)
{ {
nodes::for_extracted_children(scn_a.node(), [&ctx](const const_node_iptr& node){ for_all_children(scene_a.node(), ctx);
ctx.draw(node);
}, nodes::options().recursive(true).include_root(true));
}; };
ecsex::for_extracted_sorted_components<scene, actor>( ecsex::for_extracted_sorted_components<scene, actor>(
owner, owner,
comp, comp,
func, func,
!ecs::exists<disabled<scene>>()); !ecs::exists_any<
disabled<actor>,
disabled<scene>>());
} }
} }

View File

@@ -106,52 +106,50 @@ namespace e2d::render_system_impl
flush(); flush();
} }
try { E2D_ERROR_DEFER([this](){
const bool batching_available =
!batches_.empty() &&
(batches_.back().material == material || batches_.back().material->content() == material->content()) &&
batches_.back().properties == properties;
if ( !batching_available ) {
const std::size_t start = batches_.empty()
? 0u
: batches_.back().start + batches_.back().count;
batches_.emplace_back(start, material, properties);
}
if ( indices && index_count ) {
auto iter = indices_.insert(
indices_.end(),
indices, indices + index_count);
std::transform(
iter, indices_.end(), iter,
[add = vertices_.size()](index_type v) noexcept {
return static_cast<index_type>(v + add);
});
batches_.back().count += index_count;
}
if ( vertices && vertex_count ) {
vertices_.insert(
vertices_.end(),
vertices, vertices + vertex_count);
}
} catch ( ... ) {
clear(false); clear(false);
throw; });
const bool batching_available =
!batches_.empty() &&
(batches_.back().material == material || batches_.back().material->content() == material->content()) &&
batches_.back().properties == properties;
if ( !batching_available ) {
const std::size_t start = batches_.empty()
? 0u
: batches_.back().start + batches_.back().count;
batches_.emplace_back(start, material, properties);
}
if ( indices && index_count ) {
auto iter = indices_.insert(
indices_.end(),
indices, indices + index_count);
std::transform(
iter, indices_.end(), iter,
[add = vertices_.size()](index_type v) noexcept {
return static_cast<index_type>(v + add);
});
batches_.back().count += index_count;
}
if ( vertices && vertex_count ) {
vertices_.insert(
vertices_.end(),
vertices, vertices + vertex_count);
} }
} }
template < typename Index, typename Vertex > template < typename Index, typename Vertex >
render::property_block& batcher<Index, Vertex>::flush() { render::property_block& batcher<Index, Vertex>::flush() {
try { E2D_DEFER([this](){
update_buffers_();
render_buffers_();
} catch (...) {
clear(false); clear(false);
throw; });
}
clear(false); update_buffers_();
render_buffers_();
return internal_properties_; return internal_properties_;
} }
@@ -181,22 +179,20 @@ namespace e2d::render_system_impl
.indices(index_buffer_) .indices(index_buffer_)
.add_vertices(vertex_buffer_); .add_vertices(vertex_buffer_);
try { E2D_DEFER([this](){
for ( const batch_type& batch : batches_ ) {
const render::material& mat = batch.material->content();
render_.execute(render::draw_command(
mat,
geo,
property_cache_
.merge(internal_properties_)
.merge(batch.properties)
).index_range(batch.start, batch.count));
}
} catch ( ... ) {
property_cache_.clear(); property_cache_.clear();
throw; });
for ( const batch_type& batch : batches_ ) {
const render::material& mat = batch.material->content();
render_.execute(render::draw_command(
mat,
geo,
property_cache_
.merge(internal_properties_)
.merge(batch.properties)
).index_range(batch.start, batch.count));
} }
property_cache_.clear();
} }
template < typename Index, typename Vertex > template < typename Index, typename Vertex >