tzlaine wrote:
A couple of notes about your original patch, Carsten.
First, this:
Code:
@@ -4294,16 +4402,15 @@
ObjectSet& from_set = search_domain == MATCHES ? matches : non_matches;
ObjectSet& to_set = search_domain == MATCHES ? non_matches : matches;
- ObjectSet::iterator it = from_set.begin();
- ObjectSet::iterator end_it = from_set.end();
- for ( ; it != end_it; ) {
- ObjectSet::iterator temp = it++;
+ std::map<const UniverseObject *, std::pair<const UniverseObject *, int> > object_distances(BuildDistanceMap(subcondition_matches, from_set, jump_limit));
+
+ for (ObjectSet::iterator it = from_set.begin(), end_it = from_set.end(); it != end_it; ++it) {
// does candidate object contain any subcondition matches?
- bool match = WithinStarlaneJumpsSimpleMatch(*temp, subcondition_matches, jump_limit);
+ bool match = WithinStarlaneJumpsSimpleMatch(*it, subcondition_matches, jump_limit, object_distances);
// transfer
if ((search_domain == MATCHES && !match) || (search_domain == NON_MATCHES && match)) {
- to_set.insert(*temp);
- from_set.erase(temp);
+ to_set.insert(*it);
+ from_set.erase(it);
}
}
} else {
breaks things. Do you see why now that I've pointed it out?
Yes, the iterator is invalidated by erase.
Once we're at it: if you change ObjectSet to std::vector erase will invalidate ALL iterators.
tzlaine wrote:
Also, your implementation changed some logic from:
determining the shortest path for fleets in deep space by looking at both possible paths through the systems on either end of its starlane (accurate but slow)
with this:
Code:
+ if (!system_one && result < MANY_JUMPS) ++result; // object one isn't in a system, so add a jump
+ if (!system_two && result < MANY_JUMPS) ++result; // object two isn't in a system, so add a jump // TZL
This is probably wrong 50% of the time. We need to optimize, but we must also preserve correctness.
I know this is different, and I explicitly asked whether min(system1_distance, system2_distance) + 1 is ok instead of max(system1_distance, system2_distance). It's different, but it even makes more sense IMHO, as the fleet is at neither end but something away from both. It would have been possible to compute max using two separate precomputations, but I was told this simpler version is ok. I admit I didnt ask whether +2 is ok if both objects are fleets, but is the same argument as when only one object is a fleet.
Note that the +1 isn't executed when the fleet is inside a system.