Commit 0fc1c17a authored by VAN TOLL Wouter's avatar VAN TOLL Wouter
Browse files

More performance enhancements:

- Agents are now stored in an unordered_map.
- Reduced copying in several Vector2D operations.
parent 9759d20b
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <queue> #include <queue>
#include <limits> // std::reference_wrapper #include <limits>
#include <unordered_map>
#include <tools/Polygon2D.h> #include <tools/Polygon2D.h>
#include <core/agent.h> #include <core/agent.h>
...@@ -87,7 +88,7 @@ private: ...@@ -87,7 +88,7 @@ private:
/// <remarks>Because agents can be removed during the simulation, the ID of an agent is not necessarily the same /// <remarks>Because agents can be removed during the simulation, the ID of an agent is not necessarily the same
/// as its position in the list. This is why we need this extra administration. /// as its position in the list. This is why we need this extra administration.
/// (We could also put all agents directly in a map, but then we could not loop over the agents in parallel with OpenMP.)</remarks> /// (We could also put all agents directly in a map, but then we could not loop over the agents in parallel with OpenMP.)</remarks>
std::map<size_t, size_t> agentPositionsInVector; std::unordered_map<size_t, size_t> agentPositionsInVector;
/// <summary>The agent ID that will be used for the next agent that gets added.</summary> /// <summary>The agent ID that will be used for the next agent that gets added.</summary>
size_t nextUnusedAgentID; size_t nextUnusedAgentID;
......
...@@ -109,27 +109,27 @@ typedef std::pair<Vector2D, Vector2D> LineSegment2D; ...@@ -109,27 +109,27 @@ typedef std::pair<Vector2D, Vector2D> LineSegment2D;
#pragma region [Arithmetic operators] #pragma region [Arithmetic operators]
inline Vector2D operator-(Vector2D lhs, Vector2D rhs) inline Vector2D operator-(const Vector2D& lhs, const Vector2D& rhs)
{ {
return Vector2D(lhs.x - rhs.x, lhs.y - rhs.y); return Vector2D(lhs.x - rhs.x, lhs.y - rhs.y);
} }
inline Vector2D operator+(Vector2D lhs, Vector2D rhs) inline Vector2D operator+(const Vector2D& lhs, const Vector2D& rhs)
{ {
return Vector2D(lhs.x + rhs.x, lhs.y + rhs.y); return Vector2D(lhs.x + rhs.x, lhs.y + rhs.y);
} }
inline Vector2D operator*(float lhs, Vector2D rhs) inline Vector2D operator*(float lhs, const Vector2D& rhs)
{ {
return Vector2D(rhs.x * lhs, rhs.y * lhs); return Vector2D(rhs.x * lhs, rhs.y * lhs);
} }
inline Vector2D operator*(Vector2D lhs, float rhs) inline Vector2D operator*(const Vector2D& lhs, float rhs)
{ {
return rhs * lhs; return rhs * lhs;
} }
inline Vector2D operator/(Vector2D lhs, float rhs) inline Vector2D operator/(const Vector2D& lhs, float rhs)
{ {
return (1.0f / rhs) * lhs; return (1.0f / rhs) * lhs;
} }
...@@ -144,7 +144,7 @@ inline bool operator!=(const Vector2D& p, const Vector2D& q) ...@@ -144,7 +144,7 @@ inline bool operator!=(const Vector2D& p, const Vector2D& q)
return p.x != q.x || p.y != q.y; return p.x != q.x || p.y != q.y;
} }
inline Vector2D operator-(Vector2D lhs) inline Vector2D operator-(const Vector2D& lhs)
{ {
return Vector2D(-lhs.x, -lhs.y); return Vector2D(-lhs.x, -lhs.y);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment