Page MenuHomeWildfire Games

Fix EntitiesNearPoint range query.
ClosedPublic

Authored by wraitii on May 17 2020, 10:40 AM.

Details

Reviewers
None
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Commits
rP23680: Fix EntitiesNearPoint range query
Summary

rP23012 introduced logic in Attacking.EntitiesNearPoint to avoid returning GAIA entities in range. The reasoning was that an interface would speed things up, but we didn't want to return trees, and Health was "sufficient".
However, GAIA catafalques are possible and thus this breaks.
As further noted by elexis, this did two queries in case GAIA was targeted, which is inefficient.


This diff changes EntitiesNearPoint to accept an interface parameter, and returns by default all entities in range.
While this is pessimistic for attack effects, it seems doing several calls with the appropriate receiver interface would not be faster. Actual testing would be nice, however the ranges considered are always absurdly small anyways.

Indeed, EntitiesNearPoint was called with a radius of "2 times the distance between predicted target location at missile-launch and actual target-location at missile hit". This logic was introduced in the first iteration of this code at rP11886.
This does not make much sense anymore. We have splash damage to handle damaging nearby entities, so it seems instead this should simply be a small constant. Given that, the query is unlikely to return too many entities anyways, so simplifying the code seems fine.


Further, the previous code had a bug: GAIA entities would be returned twice. See tests.


EntitiesNearPoint is also used by Polar Sea Triggers with a range of 200, where it seems like performance might be an issue. Using the new interface argument, I pass IID_Health explicitly since wolves deal damage in the public mod.


This fixes concerns reported by elexis at rP23012 and by Freagarach at rP22754.

Test Plan

The actual constant can be debated. It seems like it could be 0, but that number seems odd to me. We might want to allow some lee-way in the missile hitting, for gameplay.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

wraitii created this revision.May 17 2020, 10:40 AM
Owners added a subscriber: Restricted Owners Package.May 17 2020, 10:40 AM
wraitii edited the summary of this revision. (Show Details)May 17 2020, 10:40 AM

Build failure - The Moirai have given mortals hearts that can endure.

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/725/display/redirect

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/2140/display/redirect

This revision was not accepted when it landed; it landed in state Needs Review.May 20 2020, 7:03 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Silier added a subscriber: Silier.May 21 2020, 12:54 PM

Further, the previous code had a bug: GAIA entities would be returned twice. See tests.

I have to disagree. Code was not bugged but tests are wrote buggy way.
They are mocked incorrectly

 AddMock(SYSTEM_ENTITY, IID_RangeManager, {
		"ExecuteQueryAroundPos": () => [61, 62]
	});

So since EntitiesNearPoint called ExecuteQueryAroundPos once with [0] and second with [1] mock does not care and returns [61, 62] twice. That is why there have been *2 hack.

The actual constant can be debated. It seems like it could be 0, but that number seems odd to me. We might want to allow some lee-way in the missile hitting, for gameplay.

Would not that mean no entities returned if it would be 0?

This diff changes EntitiesNearPoint to accept an interface parameter, and returns by default all entities in range.
While this is pessimistic for attack effects, it seems doing several calls with the appropriate receiver interface would not be faster. Actual ? > > testing would be nice, however the ranges considered are always absurdly small anyways.

So as pointed by Freagarach in commit, now is possible to damage anything, however if entity does not have required damage receiver, damage/effect will not be dealt/applied, but looks like Attacked message would be sent anyway.

Thanks for giving this another look ?

I have to disagree. Code was not bugged but tests are wrote buggy way.
They are mocked incorrectly

 AddMock(SYSTEM_ENTITY, IID_RangeManager, {
		"ExecuteQueryAroundPos": () => [61, 62]
	});

So since EntitiesNearPoint called ExecuteQueryAroundPos once with [0] and second with [1] mock does not care and returns [61, 62] twice. That is why there have been *2 hack.

Ha, that is true, good catch.
I misread the code and forgot that splice was in-place, and thus GAIA would no longer be in "players" in the second call. That being said, still dangerous behaviour...

Would not that mean no entities returned if it would be 0?

Err... I was operating under the assumption that range queries took entity size in question, but they do not. So yeah, it would.
Though most entities have clearance 0.8, which this covers, and large entities have clearance 3.
Could be bumped a tad, but I don't think it would actually matter much, and we should probably fix range queries too (since this appears to mean that buildings will basically never be hit by stray arrows, nor boats).

So as pointed by Freagarach in commit, now is possible to damage anything, however if entity does not have required damage receiver, damage/effect will not be dealt/applied, but looks like Attacked message would be sent anyway.

Are you referring to this concern: https://code.wildfiregames.com/rP22754#inline-3977 ? This was actually pointing out the opposite.

I do agree that we probably should early exit if no attack effect did anything though.