mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-16 14:08:59 +07:00
fix extracting components and nodes functions
This commit is contained in:
@@ -100,63 +100,107 @@ namespace e2d::nodes
|
||||
void for_extracted_nodes(const node_iptr& root, F&& f) {
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<node_iptr> nodes;
|
||||
const std::size_t begin_index = nodes.size();
|
||||
|
||||
try {
|
||||
extract_nodes(root, std::back_inserter(nodes));
|
||||
for ( const node_iptr& n : nodes ) {
|
||||
f(n);
|
||||
extract_nodes(
|
||||
root,
|
||||
std::back_inserter(nodes));
|
||||
|
||||
const std::size_t end_index = nodes.size();
|
||||
for ( std::size_t i = begin_index; i < end_index; ++i ) {
|
||||
f(nodes[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
nodes.clear();
|
||||
nodes.erase(
|
||||
nodes.begin() + begin_index,
|
||||
nodes.end());
|
||||
throw;
|
||||
}
|
||||
nodes.clear();
|
||||
|
||||
nodes.erase(
|
||||
nodes.begin() + begin_index,
|
||||
nodes.end());
|
||||
}
|
||||
|
||||
template < typename F >
|
||||
void for_extracted_nodes(const const_node_iptr& root, F&& f) {
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<const_node_iptr> nodes;
|
||||
const std::size_t begin_index = nodes.size();
|
||||
|
||||
try {
|
||||
extract_nodes(root, std::back_inserter(nodes));
|
||||
for ( const const_node_iptr& n : nodes ) {
|
||||
f(n);
|
||||
extract_nodes(
|
||||
root,
|
||||
std::back_inserter(nodes));
|
||||
|
||||
const std::size_t end_index = nodes.size();
|
||||
for ( std::size_t i = begin_index; i < end_index; ++i ) {
|
||||
f(nodes[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
nodes.clear();
|
||||
nodes.erase(
|
||||
nodes.begin() + begin_index,
|
||||
nodes.end());
|
||||
throw;
|
||||
}
|
||||
nodes.clear();
|
||||
|
||||
nodes.erase(
|
||||
nodes.begin() + begin_index,
|
||||
nodes.end());
|
||||
}
|
||||
|
||||
template < typename F >
|
||||
void for_extracted_nodes_reversed(const node_iptr& root, F&& f) {
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<node_iptr> nodes;
|
||||
const std::size_t begin_index = nodes.size();
|
||||
|
||||
try {
|
||||
extract_nodes_reversed(root, std::back_inserter(nodes));
|
||||
for ( const node_iptr& n : nodes ) {
|
||||
f(n);
|
||||
extract_nodes_reversed(
|
||||
root,
|
||||
std::back_inserter(nodes));
|
||||
|
||||
const std::size_t end_index = nodes.size();
|
||||
for ( std::size_t i = begin_index; i < end_index; ++i ) {
|
||||
f(nodes[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
nodes.clear();
|
||||
nodes.erase(
|
||||
nodes.begin() + begin_index,
|
||||
nodes.end());
|
||||
throw;
|
||||
}
|
||||
nodes.clear();
|
||||
|
||||
nodes.erase(
|
||||
nodes.begin() + begin_index,
|
||||
nodes.end());
|
||||
}
|
||||
|
||||
template < typename F >
|
||||
void for_extracted_nodes_reversed(const const_node_iptr& root, F&& f) {
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<const_node_iptr> nodes;
|
||||
const std::size_t begin_index = nodes.size();
|
||||
|
||||
try {
|
||||
extract_nodes_reversed(root, std::back_inserter(nodes));
|
||||
for ( const const_node_iptr& n : nodes ) {
|
||||
f(n);
|
||||
extract_nodes_reversed(
|
||||
root,
|
||||
std::back_inserter(nodes));
|
||||
|
||||
const std::size_t end_index = nodes.size();
|
||||
for ( std::size_t i = begin_index; i < end_index; ++i ) {
|
||||
f(nodes[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
nodes.clear();
|
||||
nodes.erase(
|
||||
nodes.begin() + begin_index,
|
||||
nodes.end());
|
||||
throw;
|
||||
}
|
||||
nodes.clear();
|
||||
|
||||
nodes.erase(
|
||||
nodes.begin() + begin_index,
|
||||
nodes.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,19 +70,28 @@ namespace e2d::systems
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<
|
||||
std::tuple<ecs::entity, Ts...>> components;
|
||||
const std::size_t begin_index = components.size();
|
||||
|
||||
try {
|
||||
extract_components<Ts...>(
|
||||
owner,
|
||||
std::back_inserter(components),
|
||||
std::forward<Opts>(opts)...);
|
||||
for ( auto& t : components ) {
|
||||
std::apply(f, t);
|
||||
|
||||
const std::size_t end_index = components.size();
|
||||
for ( std::size_t i = begin_index; i < end_index; ++i ) {
|
||||
std::apply(f, components[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
components.clear();
|
||||
components.erase(
|
||||
components.begin() + begin_index,
|
||||
components.end());
|
||||
throw;
|
||||
}
|
||||
components.clear();
|
||||
|
||||
components.erase(
|
||||
components.begin() + begin_index,
|
||||
components.end());
|
||||
}
|
||||
|
||||
template < typename... Ts, typename F, typename... Opts >
|
||||
@@ -90,19 +99,28 @@ namespace e2d::systems
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<
|
||||
std::tuple<ecs::const_entity, Ts...>> components;
|
||||
const std::size_t begin_index = components.size();
|
||||
|
||||
try {
|
||||
extract_components<Ts...>(
|
||||
owner,
|
||||
std::back_inserter(components),
|
||||
std::forward<Opts>(opts)...);
|
||||
for ( const auto& t : components ) {
|
||||
std::apply(f, t);
|
||||
|
||||
const std::size_t end_index = components.size();
|
||||
for ( std::size_t i = begin_index; i < end_index; ++i ) {
|
||||
std::apply(f, components[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
components.clear();
|
||||
components.erase(
|
||||
components.begin() + begin_index,
|
||||
components.end());
|
||||
throw;
|
||||
}
|
||||
components.clear();
|
||||
|
||||
components.erase(
|
||||
components.begin() + begin_index,
|
||||
components.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,20 +131,33 @@ namespace e2d::systems
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<
|
||||
std::tuple<ecs::entity, Ts...>> components;
|
||||
const std::size_t begin_index = components.size();
|
||||
|
||||
try {
|
||||
extract_components<Ts...>(
|
||||
owner,
|
||||
std::back_inserter(components),
|
||||
std::forward<Opts>(opts)...);
|
||||
std::sort(components.begin(), components.end(), comp);
|
||||
for ( auto& t : components ) {
|
||||
std::apply(f, t);
|
||||
|
||||
std::sort(
|
||||
components.begin() + begin_index,
|
||||
components.end(),
|
||||
comp);
|
||||
|
||||
const std::size_t end_index = components.size();
|
||||
for ( std::size_t i = begin_index; i < end_index; ++i ) {
|
||||
std::apply(f, components[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
components.clear();
|
||||
components.erase(
|
||||
components.begin() + begin_index,
|
||||
components.end());
|
||||
throw;
|
||||
}
|
||||
components.clear();
|
||||
|
||||
components.erase(
|
||||
components.begin() + begin_index,
|
||||
components.end());
|
||||
}
|
||||
|
||||
template < typename... Ts, typename Comp, typename F, typename... Opts >
|
||||
@@ -134,19 +165,32 @@ namespace e2d::systems
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<
|
||||
std::tuple<ecs::const_entity, Ts...>> components;
|
||||
const std::size_t begin_index = components.size();
|
||||
|
||||
try {
|
||||
extract_components<Ts...>(
|
||||
owner,
|
||||
std::back_inserter(components),
|
||||
std::forward<Opts>(opts)...);
|
||||
std::sort(components.begin(), components.end(), comp);
|
||||
for ( const auto& t : components ) {
|
||||
std::apply(f, t);
|
||||
|
||||
std::sort(
|
||||
components.begin() + begin_index,
|
||||
components.end(),
|
||||
comp);
|
||||
|
||||
const std::size_t end_index = components.size();
|
||||
for ( std::size_t i = begin_index; i < end_index; ++i ) {
|
||||
std::apply(f, components[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
components.clear();
|
||||
components.erase(
|
||||
components.begin() + begin_index,
|
||||
components.end());
|
||||
throw;
|
||||
}
|
||||
components.clear();
|
||||
|
||||
components.erase(
|
||||
components.begin() + begin_index,
|
||||
components.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
local world = {
|
||||
}
|
||||
|
||||
---@overload fun(): gobject
|
||||
---@overload fun(prefab: prefab): gobject
|
||||
---@overload fun(parent: node): gobject
|
||||
---@overload fun(prefab: prefab, parent: node): gobject
|
||||
---@overload fun(parent: node, transform: t3f): gobject
|
||||
---@overload fun(prefab: prefab, parent: node, transform: t3f): gobject
|
||||
---@return gobject
|
||||
function world:instantiate(...) end
|
||||
|
||||
@@ -15,21 +15,12 @@ namespace e2d::bindings::high
|
||||
sol::no_constructor,
|
||||
|
||||
"instantiate", sol::overload(
|
||||
[](world& w) -> gobject {
|
||||
return w.instantiate();
|
||||
},
|
||||
[](world& w, const prefab& prefab) -> gobject {
|
||||
return w.instantiate(prefab);
|
||||
},
|
||||
[](world& w, const node_iptr& parent) -> gobject {
|
||||
return w.instantiate(parent);
|
||||
},
|
||||
[](world& w, const prefab& prefab, const node_iptr& parent) -> gobject {
|
||||
return w.instantiate(prefab, parent);
|
||||
},
|
||||
[](world& w, const node_iptr& parent, const t3f& transform) -> gobject {
|
||||
return w.instantiate(parent, transform);
|
||||
},
|
||||
[](world& w, const prefab& prefab, const node_iptr& parent, const t3f& transform) -> gobject {
|
||||
return w.instantiate(prefab, parent, transform);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,10 @@ namespace
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<glyph_desc> glyphs;
|
||||
glyphs.clear();
|
||||
glyphs.reserve(text.size());
|
||||
|
||||
if ( glyphs.capacity() < text.size() ) {
|
||||
glyphs.reserve(math::max(glyphs.capacity() * 2u, text.size()));
|
||||
}
|
||||
|
||||
for ( std::size_t i = 0, e = text.size(); i < e; ++i ) {
|
||||
glyph_desc desc;
|
||||
@@ -248,7 +251,11 @@ namespace
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<string_desc> strings;
|
||||
strings.clear();
|
||||
strings.reserve(calculate_string_count(text));
|
||||
|
||||
const std::size_t string_count = calculate_string_count(text);
|
||||
if ( strings.capacity() < string_count ) {
|
||||
strings.reserve(math::max(strings.capacity() * 2u, string_count));
|
||||
}
|
||||
|
||||
f32 last_space_width = 0.f;
|
||||
std::size_t last_space_index = std::size_t(-1);
|
||||
|
||||
@@ -187,10 +187,10 @@ namespace e2d::render_system_impl
|
||||
continue;
|
||||
}
|
||||
|
||||
int vertex_count = 0;
|
||||
float* uvs = nullptr;
|
||||
unsigned short* indices = nullptr;
|
||||
int index_count = 0;
|
||||
std::size_t index_count = 0;
|
||||
std::size_t vertex_count = 0;
|
||||
const spAtlasPage* atlas_page = nullptr;
|
||||
const spColor* attachment_color = nullptr;
|
||||
|
||||
@@ -205,8 +205,8 @@ namespace e2d::render_system_impl
|
||||
|
||||
try {
|
||||
vertex_count = 8;
|
||||
if ( vertex_count > math::numeric_cast<int>(temp_vertices.size()) ) {
|
||||
temp_vertices.resize(vertex_count);
|
||||
if ( temp_vertices.size() < vertex_count ) {
|
||||
temp_vertices.resize(math::max(temp_vertices.size() * 2u, vertex_count));
|
||||
}
|
||||
} catch (...) {
|
||||
property_cache_.clear();
|
||||
@@ -236,8 +236,8 @@ namespace e2d::render_system_impl
|
||||
|
||||
try {
|
||||
vertex_count = mesh->super.worldVerticesLength;
|
||||
if ( vertex_count > math::numeric_cast<int>(temp_vertices.size()) ) {
|
||||
temp_vertices.resize(vertex_count);
|
||||
if ( temp_vertices.size() < vertex_count ) {
|
||||
temp_vertices.resize(math::max(temp_vertices.size() * 2u, vertex_count));
|
||||
}
|
||||
} catch (...) {
|
||||
property_cache_.clear();
|
||||
@@ -383,10 +383,10 @@ namespace e2d::render_system_impl
|
||||
}
|
||||
|
||||
try {
|
||||
const std::size_t batch_vertex_count =
|
||||
math::numeric_cast<std::size_t>(vertex_count >> 1);
|
||||
if ( batch_vertex_count > batch_vertices.size() ) {
|
||||
batch_vertices.resize(batch_vertex_count);
|
||||
const std::size_t batch_vertex_count = vertex_count >> 1;
|
||||
|
||||
if ( batch_vertices.size() < batch_vertex_count ) {
|
||||
batch_vertices.resize(math::max(batch_vertices.size() * 2u, batch_vertex_count));
|
||||
}
|
||||
|
||||
for ( std::size_t j = 0; j < batch_vertex_count; ++j ) {
|
||||
|
||||
Reference in New Issue
Block a user