RenderQueues now use std::map::insert only if necessary
It looks like my std::map::insert implementation allocates something, even if the element is present (It's not a leak, just some useless allocation) Former-commit-id: 9490bfb7994c23f893a74d5710381ba5919bb38c
This commit is contained in:
parent
0ca2c9ccb2
commit
268d3ae86d
|
|
@ -119,22 +119,28 @@ void NzDeferredRenderQueue::AddSubMesh(const NzMaterial* material, const NzSubMe
|
|||
{
|
||||
const NzStaticMesh* staticMesh = static_cast<const NzStaticMesh*>(subMesh);
|
||||
|
||||
auto pair = opaqueModels.insert(std::make_pair(material, BatchedModelContainer::mapped_type()));
|
||||
if (pair.second)
|
||||
auto it = opaqueModels.find(material);
|
||||
if (it == opaqueModels.end())
|
||||
{
|
||||
it = opaqueModels.insert(std::make_pair(material, BatchedModelContainer::mapped_type())).first;
|
||||
material->AddResourceListener(this, ResourceType_Material);
|
||||
}
|
||||
|
||||
bool& used = std::get<0>(pair.first->second);
|
||||
bool& enableInstancing = std::get<1>(pair.first->second);
|
||||
bool& used = std::get<0>(it->second);
|
||||
bool& enableInstancing = std::get<1>(it->second);
|
||||
|
||||
used = true;
|
||||
|
||||
auto& meshMap = std::get<3>(pair.first->second);
|
||||
auto& meshMap = std::get<3>(it->second);
|
||||
|
||||
auto pair2 = meshMap.insert(std::make_pair(staticMesh, BatchedStaticMeshContainer::mapped_type()));
|
||||
if (pair2.second)
|
||||
auto it2 = meshMap.find(staticMesh);
|
||||
if (it2 == meshMap.end())
|
||||
{
|
||||
it2 = meshMap.insert(std::make_pair(staticMesh, BatchedStaticMeshContainer::mapped_type())).first;
|
||||
staticMesh->AddResourceListener(this, ResourceType_StaticMesh);
|
||||
}
|
||||
|
||||
std::vector<StaticData>& staticDataContainer = pair2.first->second;
|
||||
std::vector<StaticData>& staticDataContainer = it2->second;
|
||||
|
||||
unsigned int instanceCount = staticDataContainer.size() + 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -130,28 +130,32 @@ void NzForwardRenderQueue::AddSubMesh(const NzMaterial* material, const NzSubMes
|
|||
}
|
||||
else
|
||||
{
|
||||
auto pair = opaqueModels.insert(std::make_pair(material, BatchedModelContainer::mapped_type()));
|
||||
if (pair.second)
|
||||
auto it = opaqueModels.find(material);
|
||||
if (it == opaqueModels.end())
|
||||
{
|
||||
it = opaqueModels.insert(std::make_pair(material, BatchedModelContainer::mapped_type())).first;
|
||||
material->AddResourceListener(this, ResourceType_Material);
|
||||
}
|
||||
|
||||
bool& used = std::get<0>(pair.first->second);
|
||||
bool& enableInstancing = std::get<1>(pair.first->second);
|
||||
bool& used = std::get<0>(it->second);
|
||||
bool& enableInstancing = std::get<1>(it->second);
|
||||
|
||||
used = true;
|
||||
|
||||
auto& meshMap = std::get<3>(pair.first->second);
|
||||
auto& meshMap = std::get<3>(it->second);
|
||||
|
||||
auto pair2 = meshMap.insert(std::make_pair(staticMesh, BatchedStaticMeshContainer::mapped_type()));
|
||||
if (pair2.second)
|
||||
auto it2 = meshMap.find(staticMesh);
|
||||
if (it2 == meshMap.end())
|
||||
{
|
||||
it2 = meshMap.insert(std::make_pair(staticMesh, BatchedStaticMeshContainer::mapped_type())).first;
|
||||
staticMesh->AddResourceListener(this, ResourceType_StaticMesh);
|
||||
|
||||
NzSpheref& squaredBoundingSphere = pair2.first->second.first;
|
||||
NzSpheref& squaredBoundingSphere = it2->second.first;
|
||||
squaredBoundingSphere.Set(staticMesh->GetAABB().GetSquaredBoundingSphere());
|
||||
///TODO: Écouter le StaticMesh pour repérer tout changement de géométrie
|
||||
}
|
||||
|
||||
std::vector<StaticData>& staticDataContainer = pair2.first->second.second;
|
||||
std::vector<StaticData>& staticDataContainer = it2->second.second;
|
||||
|
||||
unsigned int instanceCount = staticDataContainer.size() + 1;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue