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
2 changed files with 35 additions and 39 deletions
Showing only changes of commit 9c06b97fa2 - Show all commits

View File

@ -79,9 +79,9 @@ void InstancerData::remove()
} }
scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id); scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id);
for (auto &it : light_instances_) { for (auto &it : light_instances_.values()) {
it.second.transforms.clear(); it.transforms.clear();
update_light_instance(it.second); update_light_instance(it);
} }
} }
@ -125,10 +125,10 @@ bool InstancerData::update_visibility()
} }
} }
char name[16]; char name[16];
for (auto &it : light_instances_) { for (auto &it : light_instances_.values()) {
for (int i = 0; i < it.second.count; ++i) { for (int i = 0; i < it.count; ++i) {
snprintf(name, 16, "L_%08x", i); snprintf(name, 16, "L_%08x", i);
change_tracker.MarkRprimDirty(it.second.data->prim_id.AppendElementString(name), change_tracker.MarkRprimDirty(it.data->prim_id.AppendElementString(name),
pxr::HdChangeTracker::DirtyVisibility); pxr::HdChangeTracker::DirtyVisibility);
} }
} }
@ -215,7 +215,7 @@ void InstancerData::check_update(Object *object)
if (!is_instance_visible(object)) { if (!is_instance_visible(object)) {
l_inst->transforms.clear(); l_inst->transforms.clear();
update_light_instance(*l_inst); update_light_instance(*l_inst);
light_instances_.erase(path); light_instances_.remove(path);
return; return;
} }
@ -254,31 +254,30 @@ void InstancerData::check_update(Object *object)
void InstancerData::check_remove(std::set<std::string> &available_objects) void InstancerData::check_remove(std::set<std::string> &available_objects)
{ {
bool ret = false; bool ret = false;
for (auto it : mesh_instances_.items()) {
if (available_objects.find(it.key.GetName()) != available_objects.end()) { mesh_instances_.remove_if([&](auto item) {
continue; bool res = available_objects.find(item.key.GetName()) == available_objects.end();
} if (res){
it.value.data->remove(); item.value.data->remove();
mesh_instances_.remove(it.key);
auto it = mesh_instances_.items().begin();
ret = true; ret = true;
} };
return res;
});
if (ret) { if (ret) {
write_instances(); write_instances();
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
prim_id, pxr::HdChangeTracker::AllDirty); prim_id, pxr::HdChangeTracker::AllDirty);
} }
for (auto it = light_instances_.begin(); it != light_instances_.end(); ++it) { light_instances_.remove_if([&](auto item) {
if (available_objects.find(it->first.GetName()) != available_objects.end()) { bool res = available_objects.find(item.key.GetName()) == available_objects.end();
continue; if (res){
} item.value.transforms.clear();
it->second.transforms.clear(); update_light_instance(item.value);
update_light_instance(it->second); };
return res;
light_instances_.erase(it); });
it = light_instances_.begin();
}
} }
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const
@ -346,8 +345,8 @@ void InstancerData::write_instances()
for (auto &it : mesh_instances_.values()) { for (auto &it : mesh_instances_.values()) {
it.indices.clear(); it.indices.clear();
} }
for (auto &it : light_instances_) { for (auto &it : light_instances_.values()) {
it.second.transforms.clear(); it.transforms.clear();
} }
ListBase *lb = object_duplilist( ListBase *lb = object_duplilist(
@ -362,7 +361,7 @@ void InstancerData::write_instances()
if (ob->type == OB_LAMP) { if (ob->type == OB_LAMP) {
LightInstance *inst = light_instance(p_id); LightInstance *inst = light_instance(p_id);
if (!inst) { if (!inst) {
inst = &light_instances_[p_id]; inst = light_instances_.lookup_ptr(p_id);
inst->data = std::make_unique<LightData>(scene_delegate_, ob, p_id); inst->data = std::make_unique<LightData>(scene_delegate_, ob, p_id);
inst->data->init(); inst->data->init();
} }
@ -390,13 +389,10 @@ void InstancerData::write_instances()
mesh_instances_.remove_if([&](auto item) {return item.value.indices.empty();}); mesh_instances_.remove_if([&](auto item) {return item.value.indices.empty();});
/* Update light intances and remove instances without transforms */ /* Update light intances and remove instances without transforms */
for (auto it = light_instances_.begin(); it != light_instances_.end(); ++it) { light_instances_.remove_if([&](auto item) {
update_light_instance(it->second); update_light_instance(item.value);
if (it->second.transforms.empty()) { return item.value.transforms.empty();
light_instances_.erase(it); });
it = light_instances_.begin();
}
}
} }
void InstancerData::update_light_instance(LightInstance &inst) void InstancerData::update_light_instance(LightInstance &inst)
@ -465,11 +461,11 @@ InstancerData::MeshInstance *InstancerData::mesh_instance(pxr::SdfPath const &id
InstancerData::LightInstance *InstancerData::light_instance(pxr::SdfPath const &id) const InstancerData::LightInstance *InstancerData::light_instance(pxr::SdfPath const &id) const
{ {
auto it = light_instances_.find(id.GetPathElementCount() == 4 ? id.GetParentPath() : id); auto it = light_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() : id);
if (it == light_instances_.end()) { if (it == nullptr) {
return nullptr; return nullptr;
} }
return const_cast<LightInstance *>(&it->second); return const_cast<LightInstance *>(it);
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -58,7 +58,7 @@ class InstancerData : public ObjectData {
LightInstance *light_instance(pxr::SdfPath const &id) const; LightInstance *light_instance(pxr::SdfPath const &id) const;
Map<pxr::SdfPath, MeshInstance> mesh_instances_; Map<pxr::SdfPath, MeshInstance> mesh_instances_;
pxr::TfHashMap<pxr::SdfPath, LightInstance, pxr::SdfPath::Hash> light_instances_; Map<pxr::SdfPath, LightInstance> light_instances_;
pxr::VtMatrix4dArray mesh_transforms_; pxr::VtMatrix4dArray mesh_transforms_;
}; };