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()
{
for (auto &val : objects_.values()) {
val->remove();
for (auto &obj_data : objects_.values()) {
obj_data->remove();
}
for (auto &val : instancers_.values()) {
val->remove();
for (auto &i_data : instancers_.values()) {
i_data->remove();
}
for (auto &val : materials_.values()) {
val->remove();
for (auto &mat_data : materials_.values()) {
mat_data->remove();
}
objects_.clear();
@ -269,9 +269,9 @@ pxr::SdfPath BlenderSceneDelegate::world_prim_id() const
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const
{
pxr::SdfPath p_id = (id.GetName().find("SM_") == 0) ? id.GetParentPath() : id;
const std::unique_ptr<ObjectData> *val = objects_.lookup_ptr(p_id);
if (val != nullptr) {
return val->get();
auto obj_data = objects_.lookup_ptr(p_id);
if (obj_data) {
return obj_data->get();
}
InstancerData *i_data = instancer_data(p_id, true);
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
{
const std::unique_ptr<MaterialData> *val = materials_.lookup_ptr(id);
if (!val) {
auto mat_data = materials_.lookup_ptr(id);
if (!mat_data) {
return nullptr;
}
return val->get();
return mat_data->get();
}
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;
}
const std::unique_ptr<InstancerData> *val = instancers_.lookup_ptr(p_id);
if (val != nullptr) {
return val->get();
auto i_data = instancers_.lookup_ptr(p_id);
if (i_data) {
return i_data->get();
}
return nullptr;
}
@ -359,8 +359,8 @@ void BlenderSceneDelegate::update_objects(Object *object)
void BlenderSceneDelegate::update_instancers(Object *object)
{
/* Check object inside instancers */
for (auto &val : instancers_.values()) {
val->check_update(object);
for (auto &i_data : instancers_.values()) {
i_data->check_update(object);
}
pxr::SdfPath id = instancer_prim_id(object);

View File

@ -74,14 +74,14 @@ void InstancerData::insert()
void InstancerData::remove()
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
for (auto &val : mesh_instances_.values()) {
val.data->remove();
for (auto &m_inst : mesh_instances_.values()) {
m_inst.data->remove();
}
scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id);
for (auto &val : light_instances_.values()) {
val.transforms.clear();
update_light_instance(val);
for (auto &l_inst : light_instances_.values()) {
l_inst.transforms.clear();
update_light_instance(l_inst);
}
}
@ -118,17 +118,17 @@ bool InstancerData::update_visibility()
if (ret) {
auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker();
change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility);
for (auto &val : mesh_instances_.values()) {
val.data->visible = visible;
for (auto &p : val.data->submesh_paths()) {
for (auto &m_inst : mesh_instances_.values()) {
m_inst.data->visible = visible;
for (auto &p : m_inst.data->submesh_paths()) {
change_tracker.MarkRprimDirty(p, pxr::HdChangeTracker::DirtyVisibility);
}
}
char name[16];
for (auto &val : light_instances_.values()) {
for (int i = 0; i < val.count; ++i) {
for (auto &l_inst : light_instances_.values()) {
for (int i = 0; i < l_inst.count; ++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);
}
}
@ -179,8 +179,8 @@ ObjectData *InstancerData::object_data(pxr::SdfPath const &id) const
pxr::SdfPathVector InstancerData::prototypes() const
{
pxr::SdfPathVector paths;
for (auto &val : mesh_instances_.values()) {
for (auto &p : val.data->submesh_paths()) {
for (auto &m_inst : mesh_instances_.values()) {
for (auto &p : m_inst.data->submesh_paths()) {
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
{
for (auto &val : mesh_instances_.values()) {
((MeshData *)val.data.get())->available_materials(paths);
for (auto &m_inst : mesh_instances_.values()) {
((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)
{
for (auto &val : mesh_instances_.values()) {
val.data->update_double_sided(mat_data);
for (auto &m_inst : mesh_instances_.values()) {
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()
{
mesh_transforms_.clear();
for (auto &val : mesh_instances_.values()) {
val.indices.clear();
for (auto &m_inst : mesh_instances_.values()) {
m_inst.indices.clear();
}
for (auto &val : light_instances_.values()) {
val.transforms.clear();
for (auto &l_inst : light_instances_.values()) {
l_inst.transforms.clear();
}
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
{
auto val = mesh_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() : id);
if (!val) {
auto m_inst = mesh_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() :
id);
if (!m_inst) {
return nullptr;
}
return const_cast<MeshInstance *>(val);
return const_cast<MeshInstance *>(m_inst);
}
InstancerData::LightInstance *InstancerData::light_instance(pxr::SdfPath const &id) const
{
auto val = light_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() : id);
if (!val) {
auto l_inst = light_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() :
id);
if (!l_inst) {
return nullptr;
}
return const_cast<LightInstance *>(val);
return const_cast<LightInstance *>(l_inst);
}
} // namespace blender::render::hydra

View File

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