Move to use blender::Map container instead std::unordered_map #47

Merged
Bogdan Nagirniak merged 17 commits from Vasyl-Pidhirskyi/blender_bn:BLEN-418 into hydra-render 2023-06-02 12:02:46 +02:00
8 changed files with 23 additions and 19 deletions
Showing only changes of commit a9e68d81b3 - Show all commits

View File

@ -524,7 +524,7 @@ void BlenderSceneDelegate::add_new_objects()
void BlenderSceneDelegate::remove_unused_objects() void BlenderSceneDelegate::remove_unused_objects()
{ {
/* Get available objects */ /* Get available objects */
std::set<std::string> available_objects; Set<std::string> available_objects;
DEGObjectIterSettings settings = {0}; DEGObjectIterSettings settings = {0};
settings.depsgraph = depsgraph; settings.depsgraph = depsgraph;
@ -542,15 +542,15 @@ void BlenderSceneDelegate::remove_unused_objects()
object) object)
{ {
if (ObjectData::is_supported(object)) { if (ObjectData::is_supported(object)) {
available_objects.insert(object_prim_id(object).GetName()); available_objects.add(object_prim_id(object).GetName());
} }
available_objects.insert(instancer_prim_id(object).GetName()); available_objects.add(instancer_prim_id(object).GetName());
} }
ITER_END; ITER_END;
/* Remove unused instancers */ /* Remove unused instancers */
instancers_.remove_if([&](auto item) { instancers_.remove_if([&](auto item) {
bool ret = available_objects.find(item.key.GetName()) == available_objects.end(); bool ret = !available_objects.contains(item.key.GetName());
if (ret) { if (ret) {
item.value->remove(); item.value->remove();
} }
@ -562,7 +562,7 @@ void BlenderSceneDelegate::remove_unused_objects()
/* Remove unused objects */ /* Remove unused objects */
objects_.remove_if([&](auto item) { objects_.remove_if([&](auto item) {
bool ret = available_objects.find(item.key.GetName()) == available_objects.end(); bool ret = !available_objects.contains(item.key.GetName());
if (ret) { if (ret) {
item.value->remove(); item.value->remove();
} }
@ -570,7 +570,7 @@ void BlenderSceneDelegate::remove_unused_objects()
}); });
/* Remove unused materials */ /* Remove unused materials */
std::set<pxr::SdfPath> available_materials; Set<pxr::SdfPath> available_materials;
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

Try to use blender::Set here

Try to use `blender::Set` here
for (auto &val : objects_.values()) { for (auto &val : objects_.values()) {
MeshData *m_data = dynamic_cast<MeshData *>(val.get()); MeshData *m_data = dynamic_cast<MeshData *>(val.get());
if (m_data) { if (m_data) {
@ -586,7 +586,7 @@ void BlenderSceneDelegate::remove_unused_objects()
} }
materials_.remove_if([&](auto item) { materials_.remove_if([&](auto item) {
bool ret = available_materials.find(item.key) == available_materials.end(); bool ret = !available_materials.contains(item.key);
if (ret) { if (ret) {
item.value->remove(); item.value->remove();
} }

View File

@ -11,6 +11,7 @@
#include "CLG_log.h" #include "CLG_log.h"
#include "BLI_set.hh"
#include "curves.h" #include "curves.h"
#include "instancer.h" #include "instancer.h"
#include "light.h" #include "light.h"

View File

@ -134,10 +134,10 @@ pxr::SdfPath CurvesData::material_id() const
return mat_data_->prim_id; return mat_data_->prim_id;
} }
void CurvesData::available_materials(std::set<pxr::SdfPath> &paths) const void CurvesData::available_materials(Set<pxr::SdfPath> &paths) const
{ {
if (mat_data_ && !mat_data_->prim_id.IsEmpty()) { if (mat_data_ && !mat_data_->prim_id.IsEmpty()) {
paths.insert(mat_data_->prim_id); paths.add(mat_data_->prim_id);
} }
} }

View File

@ -9,6 +9,7 @@
#include "BKE_duplilist.h" #include "BKE_duplilist.h"
#include "DNA_Curves_types.h" #include "DNA_Curves_types.h"
#include "BLI_set.hh"
#include "material.h" #include "material.h"
#include "object.h" #include "object.h"
@ -29,7 +30,7 @@ class CurvesData : public ObjectData {
pxr::HdBasisCurvesTopology curves_topology(pxr::SdfPath const &id) const; pxr::HdBasisCurvesTopology curves_topology(pxr::SdfPath const &id) const;
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
pxr::SdfPath material_id() const; pxr::SdfPath material_id() const;
void available_materials(std::set<pxr::SdfPath> &paths) const; void available_materials(Set<pxr::SdfPath> &paths) const;
private: private:
void write_curves(Curves *curves); void write_curves(Curves *curves);

View File

@ -251,12 +251,12 @@ void InstancerData::check_update(Object *object)
} }
} }
void InstancerData::check_remove(std::set<std::string> &available_objects) void InstancerData::check_remove(Set<std::string> &available_objects)
{ {
bool ret = false; bool ret = false;
mesh_instances_.remove_if([&](auto item) { mesh_instances_.remove_if([&](auto item) {
bool res = available_objects.find(item.key.GetName()) == available_objects.end(); bool res = !available_objects.contains(item.key.GetName());
if (res) { if (res) {
item.value.data->remove(); item.value.data->remove();
ret = true; ret = true;
@ -271,7 +271,7 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
} }
light_instances_.remove_if([&](auto item) { light_instances_.remove_if([&](auto item) {
bool res = available_objects.find(item.key.GetName()) == available_objects.end(); bool res = !available_objects.contains(item.key.GetName());
if (res) { if (res) {
item.value.transforms.clear(); item.value.transforms.clear();
update_light_instance(item.value); update_light_instance(item.value);
@ -280,7 +280,7 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
}); });
} }
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const void InstancerData::available_materials(Set<pxr::SdfPath> &paths) const
{ {
for (auto &m_inst : mesh_instances_.values()) { for (auto &m_inst : mesh_instances_.values()) {
((MeshData *)m_inst.data.get())->available_materials(paths); ((MeshData *)m_inst.data.get())->available_materials(paths);

View File

@ -5,6 +5,7 @@
#include "BKE_duplilist.h" #include "BKE_duplilist.h"
#include "BLI_map.hh" #include "BLI_map.hh"
#include "BLI_set.hh"
#include "light.h" #include "light.h"
#include "mesh.h" #include "mesh.h"
@ -42,8 +43,8 @@ class InstancerData : public ObjectData {
ObjectData *object_data(pxr::SdfPath const &id) const; ObjectData *object_data(pxr::SdfPath const &id) const;
pxr::SdfPathVector prototypes() const; pxr::SdfPathVector prototypes() const;
void check_update(Object *object); void check_update(Object *object);
void check_remove(std::set<std::string> &available_objects); void check_remove(Set<std::string> &available_objects);
void available_materials(std::set<pxr::SdfPath> &paths) const; void available_materials(Set<pxr::SdfPath> &paths) const;
void update_as_parent(); void update_as_parent();
void update_double_sided(MaterialData *mat_data); void update_double_sided(MaterialData *mat_data);

View File

@ -173,11 +173,11 @@ void MeshData::update_double_sided(MaterialData *mat_data)
} }
} }
void MeshData::available_materials(std::set<pxr::SdfPath> &paths) const void MeshData::available_materials(Set<pxr::SdfPath> &paths) const
{ {
for (auto &sm : submeshes_) { for (auto &sm : submeshes_) {
if (sm.mat_data && !sm.mat_data->prim_id.IsEmpty()) { if (sm.mat_data && !sm.mat_data->prim_id.IsEmpty()) {
paths.insert(sm.mat_data->prim_id); paths.add(sm.mat_data->prim_id);
} }
} }
} }

View File

@ -7,6 +7,7 @@
#include <pxr/imaging/hd/sceneDelegate.h> #include <pxr/imaging/hd/sceneDelegate.h>
#include "BKE_duplilist.h" #include "BKE_duplilist.h"
#include "BLI_set.hh"
#include "material.h" #include "material.h"
#include "object.h" #include "object.h"
@ -39,7 +40,7 @@ class MeshData : public ObjectData {
pxr::SdfPath material_id(pxr::SdfPath const &id) const; pxr::SdfPath material_id(pxr::SdfPath const &id) const;
bool double_sided(pxr::SdfPath const &id) const; bool double_sided(pxr::SdfPath const &id) const;
void update_double_sided(MaterialData *mat_data); void update_double_sided(MaterialData *mat_data);
void available_materials(std::set<pxr::SdfPath> &paths) const; void available_materials(Set<pxr::SdfPath> &paths) const;
pxr::SdfPathVector submesh_paths() const; pxr::SdfPathVector submesh_paths() const;
pxr::HdCullStyle cull_style = pxr::HdCullStyleBackUnlessDoubleSided; pxr::HdCullStyle cull_style = pxr::HdCullStyleBackUnlessDoubleSided;