Skip to content

Conversation

@GGiter
Copy link

@GGiter GGiter commented Nov 14, 2019

No description provided.


AllNodes.push_back(s);
openList.Push(std::make_pair(AllNodes.size() - 1, s.TotalCost()));
openList.push(std::make_pair(AllNodes.size() - 1, s.TotalCost()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider constructing element in-place with emplace, this applies to whole PR

Copy link
Contributor

@MuniuDev MuniuDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job. Consider applying @JDuchniewicz comment. LGTM

std::vector<::pe::core::storage::PriorityQueue<std::pair<u8, float>, std::function<bool(const std::pair<u8, float>&, const std::pair<u8, float>&)>>> tmpBonesList;
tmpBonesList.resize(mesh->mNumVertices, { [](const std::pair<u8, float>& v1, const std::pair<u8, float>& v2) { return v1.second > v2.second; } });

std::vector<std::priority_queue<std::pair<u8, float>,std::vector<std::pair<u8, float>>, std::function<bool(const std::pair<u8, float>&, const std::pair<u8, float>&)>>> tmpBonesList;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that's a mouthful. Nice job though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about usings for this one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a good idea. Let's do it.

@MuniuDev
Copy link
Contributor

One comment, emplace create object in place in the container. Thus when changing it from push to emplace replace this:
q.push(MyObj(arg1, arg2));
with this:
q.emplace(arg1, arg2);

if (meshCmp->GetBlendingMode() == eBlendingMode::OPAUQE)
{
sceneView.OpaqueQueue.push(meshCmp);
sceneView.OpaqueQueue.emplace(meshCmp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you're not constructing object inside or right before push, don't bother with emplace.
It's actually a decline in performance.

size_t vertId = vertWeight.mVertexId;
float weight = vertWeight.mWeight;
tmpBonesList[vertId].push({ boneId, weight });
tmpBonesList[vertId].emplace(std::pair<u8, float>( boneId, weight ));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using emplace in such cases is good, just don't call the constructor, emplace will call it for you. Just provide it with constructor's arguments.

{
if(m_ttlEnabled && !enabled)
{
bool bResult = m_ttlEntries.empty();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what to do here i keep getting "discarding return value of function with 'nodiscard' attribute queue.empty()" warning which is then treated as error by compiler

@GGiter GGiter requested a review from MuniuDev November 30, 2019 23:00
if(m_ttlEnabled && !enabled)
{
m_ttlEntries.Clear();
DISCARD m_ttlEntries.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not clearing the queue. Replace with m_ttlEntries.c.clear()


AllNodes.push_back(PathNode(startNode, 0, graph->GetHeuristicCost(startNode, destNode) ));
openList.Push(std::make_pair(AllNodes.size() - 1, graph->GetHeuristicCost(startNode, destNode)));
openList.emplace(std::make_pair(AllNodes.size() - 1, graph->GetHeuristicCost(startNode, destNode)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for make_pair here, since we have emplace.


AllNodes.push_back(s);
openList.Push(std::make_pair(AllNodes.size() - 1, s.TotalCost()));
openList.emplace(std::make_pair(AllNodes.size() - 1, s.TotalCost()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for make_pair here, since we have emplace.

}

closedList.Push(std::make_pair(qIdx, AllNodes[qIdx].TotalCost()));
closedList.emplace(std::make_pair(qIdx, AllNodes[qIdx].TotalCost()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for make_pair here, since we have emplace.

if(m_ttlEnabled && !enabled)
{
DISCARD m_ttlEntries.empty();
std::swap(m_ttlEntries, std::priority_queue<TTLEntry>());
Copy link
Contributor

@JDuchniewicz JDuchniewicz Dec 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not compile because you are trying to swap into a temporary (rvalue) and unless it is called as member function as shown here it won't.
Why just not call clear on the m_ttlEntries?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe stl priority queue doesn't have clear method.

@GGiter GGiter requested a review from MuniuDev January 17, 2020 20:19
CHECK(q.size() == i+1);
}

for (int i = testSize-1; i >= 0; --i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any preference for spacings in such cases?

}
}

TEST_CASE("PriorityQueue reverrse sorted push test", "[PriorityQueue]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling


namespace pe::core::storage
{
template<class _Ty,class _Pr = std::less<typename std::vector<_Ty>::value_type> >
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would stick to normal engine conventions for template parameters, underscores are better left off in the stl implementation

@@ -1,5 +1,6 @@
#include <pe/core/storage/impl/IndexedStringManager.hpp>


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary newline

@MuniuDev MuniuDev merged commit 5098ee7 into PolyEngineTeam:dev Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants