From dd1849e2313c37fe60fe385ef460f53c3628b447 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 28 Aug 2015 16:05:27 +0200 Subject: [PATCH] sort chunk candidates before detailed check this makes the check from nearest to farthest which should save a lot of work. too bad that profiling currently runs with the aim pointing into nothingness, so results aren't visible. may have to check that again some time --- src/world/World.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/world/World.cpp b/src/world/World.cpp index 592558b..1d25e01 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -6,6 +6,7 @@ #include "../graphics/Format.hpp" #include "../graphics/Viewport.hpp" +#include #include #include #include @@ -42,6 +43,10 @@ struct Candidate { float dist; }; +bool CandidateLess(const Candidate &a, const Candidate &b) { + return a.dist < b.dist; +} + std::vector candidates; } @@ -63,6 +68,8 @@ bool World::Intersection( if (candidates.empty()) return false; + std::sort(candidates.begin(), candidates.end(), CandidateLess); + coll.chunk = nullptr; coll.block = -1; coll.depth = std::numeric_limits::infinity(); -- 2.39.2