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
3 changed files with 26 additions and 25 deletions
Showing only changes of commit e999ebdaf2 - Show all commits

View File

@ -214,8 +214,8 @@ void BlenderSceneDelegate::clear()
for (auto &it : objects_.values()) { for (auto &it : objects_.values()) {
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

rename please it -> val as it misleads because values() doesn't return iterator.

rename please `it` -> `val` as it misleads because `values()` doesn't return iterator.

rename val -> data

rename `val` -> `data`
it->remove(); it->remove();
} }
for (auto &it : instancers_) { for (auto &it : instancers_.values()) {
it.second->remove(); it->remove();
} }
BogdanNagirniak marked this conversation as resolved Outdated

rename val -> obj_data, i_data, m_data

rename `val` -> `obj_data`, `i_data`, `m_data`
@ -320,9 +320,9 @@ InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool
p_id = id; p_id = id;
} }
auto it = instancers_.find(p_id); const std::unique_ptr<InstancerData> *value = instancers_.lookup_ptr(p_id);
if (it != instancers_.end()) { if (value != nullptr) {
return it->second.get(); return value->get();
} }
return nullptr; return nullptr;
} }
@ -357,8 +357,8 @@ void BlenderSceneDelegate::update_objects(Object *object)
void BlenderSceneDelegate::update_instancers(Object *object) void BlenderSceneDelegate::update_instancers(Object *object)
{ {
/* Check object inside instancers */ /* Check object inside instancers */
for (auto &it : instancers_) { for (auto &it : instancers_.values()) {
it.second->check_update(object); it->check_update(object);
} }
BogdanNagirniak marked this conversation as resolved Outdated

val -> i_data

`val` -> `i_data`
pxr::SdfPath id = instancer_prim_id(object); pxr::SdfPath id = instancer_prim_id(object);
@ -367,7 +367,7 @@ void BlenderSceneDelegate::update_instancers(Object *object)
if ((object->transflag & OB_DUPLI) == 0) { if ((object->transflag & OB_DUPLI) == 0) {
/* Object isn't instancer anymore and should be removed */ /* Object isn't instancer anymore and should be removed */
i_data->remove(); i_data->remove();
instancers_.erase(id); instancers_.remove(id);
return; return;
} }
@ -384,7 +384,7 @@ void BlenderSceneDelegate::update_instancers(Object *object)
return; return;
} }
instancers_[id] = std::make_unique<InstancerData>(this, object, id); instancers_.add_overwrite(id, std::make_unique<InstancerData>(this, object, id));
i_data = instancer_data(id); i_data = instancer_data(id);
i_data->init(); i_data->init();
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

seems like here should be add_new.

seems like here should be `add_new`.

use lookup_or_add_default

use `lookup_or_add_default`

implemented via lookup_or_add

implemented via `lookup_or_add`
i_data->insert(); i_data->insert();
@ -547,16 +547,16 @@ void BlenderSceneDelegate::remove_unused_objects()
ITER_END; ITER_END;
/* Remove unused instancers */ /* Remove unused instancers */
for (auto it = instancers_.begin(); it != instancers_.end(); ++it) { instancers_.remove_if([&](auto item) {
if (available_objects.find(it->first.GetName()) != available_objects.end()) { bool ret = available_objects.find(item.key.GetName()) == available_objects.end();
/* Remove objects from instancers */ if (ret){
it->second->check_remove(available_objects); item.value->remove();
continue;
} }
it->second->remove(); else{
instancers_.erase(it); item.value->check_remove(available_objects);
it = instancers_.begin();
} }
return ret;
});
/* Remove unused objects */ /* Remove unused objects */
objects_.remove_if([&](auto item) { objects_.remove_if([&](auto item) {
@ -580,8 +580,8 @@ void BlenderSceneDelegate::remove_unused_objects()
c_data->available_materials(available_materials); c_data->available_materials(available_materials);
} }
} }
for (auto &it : instancers_) { for (auto &it : instancers_.values()) {
it.second->available_materials(available_materials); it->available_materials(available_materials);
} }
materials_.remove_if([&](auto item) { materials_.remove_if([&](auto item) {
@ -599,8 +599,8 @@ void BlenderSceneDelegate::update_visibility()
for (auto &it : objects_.values()) { for (auto &it : objects_.values()) {
it->update_visibility(); it->update_visibility();
} }
for (auto &it : instancers_) { for (auto &it : instancers_.values()) {
it.second->update_visibility(); it->update_visibility();
} }
/* Add objects/instancers which were invisible before and not added yet */ /* Add objects/instancers which were invisible before and not added yet */

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include "BKE_duplilist.h" #include "BKE_duplilist.h"
#include "BLI_map.hh"
#include "light.h" #include "light.h"
#include "mesh.h" #include "mesh.h"
@ -62,6 +63,6 @@ class InstancerData : public ObjectData {
}; };
using InstancerDataMap = using InstancerDataMap =
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<InstancerData>, pxr::SdfPath::Hash>; Map<pxr::SdfPath, std::unique_ptr<InstancerData>>;
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -66,8 +66,8 @@ void MaterialData::update()
m_data->update_double_sided(this); m_data->update_double_sided(this);
} }
} }
for (auto &it : scene_delegate_->instancers_) { for (auto &it : scene_delegate_->instancers_.values()) {
it.second->update_double_sided(this); it->update_double_sided(this);
} }
} }
} }