Page MenuHomeWildfire Games

Adds a function to pick entities with obstructions on screen
ClosedPublic

Authored by vladislavbelov on Aug 21 2019, 2:30 AM.

Details

Reviewers
wraitii
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Commits
rP22939: Adds a helper function to pick entities with a given component and a given…
Summary

Subj, it helps to move some performance related queries to C++ side, example D2079.

Test Plan
  1. Apply the patch and compile the game
  2. Run tests and make sure that tests are passes as before
  3. Run the game and check the function in console (Engine::PickEntitiesWithStaticObstructionOnScreen())

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

vladislavbelov created this revision.Aug 21 2019, 2:30 AM

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

Linter detected issues:
Executing section Source...

source/simulation2/scripting/JSInterface_Simulation.h
|  24| namespace·JSI_Simulation
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'namespaceJSI_Simulation{' is invalid C code. Use --std or --language to configure the language.

source/simulation2/helpers/Selection.h
|  30| namespace·EntitySelection
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'namespaceEntitySelection{' is invalid C code. Use --std or --language to configure the language.

source/simulation2/components/ICmpObstruction.h
|  29| class·ICmpObstruction·:·public·IComponent
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classICmpObstruction:' is invalid C code. Use --std or --language to configure the language.

source/simulation2/components/tests/test_ObstructionManager.h
|  23| class·MockObstruction·:·public·ICmpObstruction
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classMockObstruction:' is invalid C code. Use --std or --language to configure the language.
Executing section JS...
Executing section cli...

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

elexis added a subscriber: elexis.Aug 21 2019, 10:57 AM

(There is a catch with proposing unused code for review: It can't be tested against the use cases. But code looks ok.)

source/simulation2/components/CCmpObstruction.cpp
464 ↗(On Diff #9427)

If it's not the only function that overrides an inherited function, clang will complain. It wants override for either all overriding functions of a class or none.

source/simulation2/helpers/Selection.cpp
197 ↗(On Diff #9427)

Wondering if the the ObstructionType should be the argument, and not just the component.

It could be made generic to consume the component, then it could also use the other components,
and perhaps it could receive an optional function as an argument that performs the obstruction-specific checks?

Otherwise if we don't care to make it reusable for other random use cases, the argument could also be removed to add more specializations to the one use case.

205 ↗(On Diff #9427)

I see it's copied code, so it's okay to keep it consistent, otherwise I'd have said that it should complain if it receives broken values instead of pretending it didnt happen.

211 ↗(On Diff #9427)

Okay, the other functions in this file iterate over all gaia or player-owned entities, so this one is faster because it filters sooner.

But you also only want player-owned or (ally-owned too) entities, so you can skip even more entities here, right?

219 ↗(On Diff #9427)

You obtained the obstruction component here, so I wonder if CheckEntityInRect could be replaced with the collision check in the future. Doesn't have to be scheduled at all unless there is data to back it up that it's actually relevant.

Stan added a subscriber: Stan.Aug 21 2019, 11:09 AM
Stan added inline comments.
source/simulation2/helpers/Selection.h
22 ↗(On Diff #9427)

Forward declaration ?

source/simulation2/components/CCmpObstruction.cpp
464 ↗(On Diff #9427)

Yeah, it makes sense. I suppose we need to update virtual > override in future.

source/simulation2/helpers/Selection.cpp
197 ↗(On Diff #9427)

It's a good point to make more common, but I'd prefer to not pass the filter function as an argument. But use templates instead (for simpler compiler optimizations). Like:

PickEntitiesWithComponentInRect<StaticObstructionFilter>(simulation, IID_Obstruction, ...);
211 ↗(On Diff #9427)

But you also only want player-owned or (ally-owned too) entities, so you can skip even more entities here, right?

I thought about that. I think it's not a wrong behaviour to allow to a player to place a building near an ancient temple (which belongs to gaia).

219 ↗(On Diff #9427)

Yes, it's possible to replace, but it requires a more complex collision check.

vladislavbelov added inline comments.Aug 22 2019, 1:50 AM
source/simulation2/helpers/Selection.h
22 ↗(On Diff #9427)

There are only a typedef and a constant, so no.

On the whole, I think this is a minor feature that's useful for performance reasons, and we shouldn't worry too much about future-proofing these kind of things, which are easy to change, and generally used in specific use-cases (see also the shore-dock code thingy).

It'd say this looks good.

wraitii requested changes to this revision.Sep 1 2019, 5:05 PM

As said above this looks good. Some nitpicks:

  • Need to remove that override for clang.
  • Rename PickEntitiesWithObstructionInRect to GetEntitiesWithObstructionInRect since it doesn't actually add them to selection or anything, just returns a list.
This revision now requires changes to proceed.Sep 1 2019, 5:05 PM

As said above this looks good. Some nitpicks:

@wraitii What do you think about the attached patch?

Adds template function.

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

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

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

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/232/display/redirect

Stan added inline comments.Sep 18 2019, 12:24 PM
source/simulation2/helpers/Selection.h
87 ↗(On Diff #9839)

Should we really do that, or call the function correctly ?

EDIT: nvm saw @elexis's comment below.

95 ↗(On Diff #9839)

Any reason to call that ?

source/simulation2/helpers/Selection.h
95 ↗(On Diff #9839)

I suppose no, thank you!

Stan added inline comments.Sep 18 2019, 12:41 PM
source/simulation2/helpers/Selection.h
95 ↗(On Diff #9839)

No pb :)

source/simulation2/scripting/JSInterface_Simulation.cpp
126 ↗(On Diff #9839)

check if not null ?

vladislavbelov added inline comments.Sep 18 2019, 1:32 PM
source/simulation2/scripting/JSInterface_Simulation.cpp
126 ↗(On Diff #9839)

Not here, if it's needed. We request all entities with such component and it's wrong if we can get nullptr here (that means that an entity doesn't have such component).

Stan added inline comments.Sep 18 2019, 2:36 PM
source/simulation2/scripting/JSInterface_Simulation.cpp
126 ↗(On Diff #9839)

Alright.

Stan added inline comments.Sep 18 2019, 2:39 PM
source/simulation2/helpers/Selection.h
72 ↗(On Diff #9839)

"[...] with a given component" instead of obstruction, or isn't the below function generic ?

source/simulation2/helpers/Selection.h
72 ↗(On Diff #9839)

You're right.

Stan added a comment.Sep 18 2019, 3:07 PM

It looks like there is only one entity with obstruction component processing in these lines, no?

Yeah but I'm pretty sure it's called more than once, and that computing sqrt isn't cheap ^^

wraitii added inline comments.Sep 18 2019, 8:51 PM
source/simulation2/helpers/Selection.h
97 ↗(On Diff #9839)

Range-for loop

vladislavbelov marked an inline comment as done.

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

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

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

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/256/display/redirect

wraitii accepted this revision.Sep 20 2019, 8:09 AM
wraitii added inline comments.
source/simulation2/helpers/Selection.h
97 ↗(On Diff #9871)

I'd inline entities, you barely gain readability.

This revision is now accepted and ready to land.Sep 20 2019, 8:09 AM
This revision was landed with ongoing or failed builds.Sep 20 2019, 9:46 AM
This revision was automatically updated to reflect the committed changes.
Owners added a subscriber: Restricted Owners Package.Sep 20 2019, 9:46 AM