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 50 additions and 48 deletions
Showing only changes of commit 3f4cfa89c9 - Show all commits

View File

@ -211,14 +211,14 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
void BlenderSceneDelegate::clear() void BlenderSceneDelegate::clear()
{ {
for (auto &val : objects_.values()) { for (auto &obj_data : objects_.values()) {
val->remove(); obj_data->remove();
} }
for (auto &val : instancers_.values()) { for (auto &i_data : instancers_.values()) {
val->remove(); i_data->remove();
} }
for (auto &val : materials_.values()) { for (auto &mat_data : materials_.values()) {
val->remove(); mat_data->remove();
} }
objects_.clear(); objects_.clear();
@ -269,9 +269,9 @@ pxr::SdfPath BlenderSceneDelegate::world_prim_id() const
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const
{ {
pxr::SdfPath p_id = (id.GetName().find("SM_") == 0) ? id.GetParentPath() : id; pxr::SdfPath p_id = (id.GetName().find("SM_") == 0) ? id.GetParentPath() : id;
const std::unique_ptr<ObjectData> *val = objects_.lookup_ptr(p_id); auto obj_data = objects_.lookup_ptr(p_id);
if (val != nullptr) { if (obj_data) {
return val->get(); return obj_data->get();
} }
InstancerData *i_data = instancer_data(p_id, true); InstancerData *i_data = instancer_data(p_id, true);
if (i_data) { if (i_data) {
@ -297,11 +297,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
{ {
const std::unique_ptr<MaterialData> *val = materials_.lookup_ptr(id); auto mat_data = materials_.lookup_ptr(id);
if (!val) { if (!mat_data) {
return nullptr; return nullptr;
} }
return val->get(); return mat_data->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
@ -322,9 +322,9 @@ InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool
p_id = id; p_id = id;
} }
const std::unique_ptr<InstancerData> *val = instancers_.lookup_ptr(p_id); auto i_data = instancers_.lookup_ptr(p_id);
if (val != nullptr) { if (i_data) {
return val->get(); return i_data->get();
} }
return nullptr; return nullptr;
} }
@ -359,8 +359,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 &val : instancers_.values()) { for (auto &i_data : instancers_.values()) {
val->check_update(object); i_data->check_update(object);
} }
pxr::SdfPath id = instancer_prim_id(object); pxr::SdfPath id = instancer_prim_id(object);

View File

@ -74,14 +74,14 @@ void InstancerData::insert()
void InstancerData::remove() void InstancerData::remove()
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
for (auto &val : mesh_instances_.values()) { for (auto &m_inst : mesh_instances_.values()) {
val.data->remove(); m_inst.data->remove();
} }
scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id); scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id);
for (auto &val : light_instances_.values()) { for (auto &l_inst : light_instances_.values()) {
val.transforms.clear(); l_inst.transforms.clear();
update_light_instance(val); update_light_instance(l_inst);
} }
} }
@ -118,17 +118,17 @@ bool InstancerData::update_visibility()
if (ret) { if (ret) {
auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker();
change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility);
for (auto &val : mesh_instances_.values()) { for (auto &m_inst : mesh_instances_.values()) {
val.data->visible = visible; m_inst.data->visible = visible;
for (auto &p : val.data->submesh_paths()) { for (auto &p : m_inst.data->submesh_paths()) {
change_tracker.MarkRprimDirty(p, pxr::HdChangeTracker::DirtyVisibility); change_tracker.MarkRprimDirty(p, pxr::HdChangeTracker::DirtyVisibility);
} }
} }
char name[16]; char name[16];
for (auto &val : light_instances_.values()) { for (auto &l_inst : light_instances_.values()) {
for (int i = 0; i < val.count; ++i) { for (int i = 0; i < l_inst.count; ++i) {
snprintf(name, 16, "L_%08x", i); snprintf(name, 16, "L_%08x", i);
change_tracker.MarkRprimDirty(val.data->prim_id.AppendElementString(name), change_tracker.MarkRprimDirty(l_inst.data->prim_id.AppendElementString(name),
pxr::HdChangeTracker::DirtyVisibility); pxr::HdChangeTracker::DirtyVisibility);
} }
} }
@ -179,8 +179,8 @@ ObjectData *InstancerData::object_data(pxr::SdfPath const &id) const
pxr::SdfPathVector InstancerData::prototypes() const pxr::SdfPathVector InstancerData::prototypes() const
{ {
pxr::SdfPathVector paths; pxr::SdfPathVector paths;
for (auto &val : mesh_instances_.values()) { for (auto &m_inst : mesh_instances_.values()) {
for (auto &p : val.data->submesh_paths()) { for (auto &p : m_inst.data->submesh_paths()) {
paths.push_back(p); paths.push_back(p);
} }
} }
@ -282,8 +282,8 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const
{ {
for (auto &val : mesh_instances_.values()) { for (auto &m_inst : mesh_instances_.values()) {
((MeshData *)val.data.get())->available_materials(paths); ((MeshData *)m_inst.data.get())->available_materials(paths);
} }
} }
@ -296,8 +296,8 @@ void InstancerData::update_as_parent()
void InstancerData::update_double_sided(MaterialData *mat_data) void InstancerData::update_double_sided(MaterialData *mat_data)
{ {
for (auto &val : mesh_instances_.values()) { for (auto &m_inst : mesh_instances_.values()) {
val.data->update_double_sided(mat_data); m_inst.data->update_double_sided(mat_data);
} }
} }
@ -342,11 +342,11 @@ int InstancerData::light_prim_id_index(pxr::SdfPath const &id) const
void InstancerData::write_instances() void InstancerData::write_instances()
{ {
mesh_transforms_.clear(); mesh_transforms_.clear();
for (auto &val : mesh_instances_.values()) { for (auto &m_inst : mesh_instances_.values()) {
val.indices.clear(); m_inst.indices.clear();
} }
for (auto &val : light_instances_.values()) { for (auto &l_inst : light_instances_.values()) {
val.transforms.clear(); l_inst.transforms.clear();
} }
ListBase *lb = object_duplilist( ListBase *lb = object_duplilist(
@ -456,20 +456,22 @@ void InstancerData::update_light_instance(LightInstance &inst)
InstancerData::MeshInstance *InstancerData::mesh_instance(pxr::SdfPath const &id) const InstancerData::MeshInstance *InstancerData::mesh_instance(pxr::SdfPath const &id) const
{ {
auto val = mesh_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() : id); auto m_inst = mesh_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() :
if (!val) { id);
if (!m_inst) {
return nullptr; return nullptr;
} }
return const_cast<MeshInstance *>(val); return const_cast<MeshInstance *>(m_inst);
} }
InstancerData::LightInstance *InstancerData::light_instance(pxr::SdfPath const &id) const InstancerData::LightInstance *InstancerData::light_instance(pxr::SdfPath const &id) const
{ {
auto val = light_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() : id); auto l_inst = light_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() :
if (!val) { id);
if (!l_inst) {
return nullptr; return nullptr;
} }
return const_cast<LightInstance *>(val); return const_cast<LightInstance *>(l_inst);
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -60,14 +60,14 @@ void MaterialData::update()
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
pxr::HdMaterial::AllDirty); pxr::HdMaterial::AllDirty);
if (prev_double_sided != double_sided) { if (prev_double_sided != double_sided) {
for (auto &val : scene_delegate_->objects_.values()) { for (auto &obj_data : scene_delegate_->objects_.values()) {
MeshData *m_data = dynamic_cast<MeshData *>(val.get()); MeshData *m_data = dynamic_cast<MeshData *>(obj_data.get());
if (m_data) { if (m_data) {
m_data->update_double_sided(this); m_data->update_double_sided(this);
} }
} }
for (auto &val : scene_delegate_->instancers_.values()) { for (auto &i_data : scene_delegate_->instancers_.values()) {
val->update_double_sided(this); i_data->update_double_sided(this);
} }
} }
} }