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
4 changed files with 24 additions and 18 deletions
Showing only changes of commit cc456bf8d4 - Show all commits

View File

@ -217,13 +217,11 @@ void BlenderSceneDelegate::clear()
for (auto &it : instancers_) { for (auto &it : instancers_) {
it.second->remove(); it.second->remove();
} }
for (auto &it : materials_) {
it.second->remove();
}
objects_.clear(); objects_.clear();
instancers_.clear(); instancers_.clear();
materials_.clear(); materials_.clear_and_shrink();
depsgraph = nullptr; depsgraph = nullptr;
context = nullptr; context = nullptr;
@ -297,11 +295,11 @@ LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) const
MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) const MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) const
{ {
auto it = materials_.find(id); const std::unique_ptr<MaterialData> *value = materials_.lookup_ptr(id);
if (it == materials_.end()) { if (value == nullptr) {
return nullptr; return nullptr;
} }
return it->second.get(); return value->get();
} }
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool child_id) const InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool child_id) const
@ -585,14 +583,14 @@ void BlenderSceneDelegate::remove_unused_objects()
for (auto &it : instancers_) { for (auto &it : instancers_) {
it.second->available_materials(available_materials); it.second->available_materials(available_materials);
} }
for (auto it = materials_.begin(); it != materials_.end(); ++it) {
if (available_materials.find(it->first) != available_materials.end()) { materials_.remove_if([&](auto item) {
continue; bool ret = available_materials.find(item.key) == available_materials.end();
} if (ret){
it->second->remove(); item.value->remove();
materials_.erase(it);
it = materials_.begin();
} }
return ret;
});
} }
void BlenderSceneDelegate::update_visibility() void BlenderSceneDelegate::update_visibility()

View File

@ -8,6 +8,7 @@
#include "BKE_context.h" #include "BKE_context.h"
#include "DEG_depsgraph.h" #include "DEG_depsgraph.h"
#include "BLI_hash.hh"
#include "CLG_log.h" #include "CLG_log.h"
@ -18,6 +19,13 @@
#include "object.h" #include "object.h"
#include "world.h" #include "world.h"
template<> struct blender::DefaultHash<pxr::SdfPath> {
uint64_t operator()(const pxr::SdfPath &value) const
{
return pxr::SdfPath::Hash()(value);
}
};
namespace blender::render::hydra { namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;

View File

@ -8,6 +8,7 @@
#include <pxr/usd/sdf/path.h> #include <pxr/usd/sdf/path.h>
#include "DNA_material_types.h" #include "DNA_material_types.h"
#include "BLI_map.hh"
#include "id.h" #include "id.h"
@ -37,7 +38,6 @@ class MaterialData : public IdData {
pxr::VtValue material_network_map_; pxr::VtValue material_network_map_;
}; };
using MaterialDataMap = using MaterialDataMap = Map<pxr::SdfPath, std::unique_ptr<MaterialData>>;
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<MaterialData>, pxr::SdfPath::Hash>;
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -304,8 +304,8 @@ void MeshData::write_materials()
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat); pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
m.mat_data = scene_delegate_->material_data(p_id); m.mat_data = scene_delegate_->material_data(p_id);
if (!m.mat_data) { if (!m.mat_data) {
scene_delegate_->materials_[p_id] = std::make_unique<MaterialData>( scene_delegate_->materials_.add_overwrite(p_id,
scene_delegate_, mat, p_id); std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
m.mat_data = scene_delegate_->material_data(p_id); m.mat_data = scene_delegate_->material_data(p_id);
m.mat_data->init(); m.mat_data->init();
m.mat_data->insert(); m.mat_data->insert();