Subj, it helps to move some performance related queries to C++ side, example D2079.
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…
- Apply the patch and compile the game
- Run tests and make sure that tests are passes as before
- 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
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
(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, 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. |
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) |
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. |
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.
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.
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
source/simulation2/helpers/Selection.h | ||
---|---|---|
95 ↗ | (On Diff #9839) | I suppose no, thank you! |
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). |
source/simulation2/scripting/JSInterface_Simulation.cpp | ||
---|---|---|
126 ↗ | (On Diff #9839) | Alright. |
source/simulation2/helpers/Selection.h | ||
---|---|---|
72 ↗ | (On Diff #9839) | "[...] with a given component" instead of obstruction, or isn't the below function generic ? |
If you are looking for more things regarding obstructions that could be moved to cpp Have a look at (ping @wraitii):
- https://code.wildfiregames.com/source/0ad/browse/ps/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js$252 findBestDropsiteLocation
- https://code.wildfiregames.com/source/0ad/browse/ps/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js$1044 checkTargetObstruction
- https://code.wildfiregames.com/source/0ad/browse/ps/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js$934 findEconomicCCLocation
- https://code.wildfiregames.com/source/0ad/browse/ps/trunk/binaries/data/mods/public/simulation/ai/common-api/entity.js$137 obstructionRadius
It looks like there is only one entity with obstruction component processing in these lines, no?
source/simulation2/helpers/Selection.h | ||
---|---|---|
72 ↗ | (On Diff #9839) | You're right. |
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 ^^
source/simulation2/helpers/Selection.h | ||
---|---|---|
97 ↗ | (On Diff #9839) | Range-for loop |
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
source/simulation2/helpers/Selection.h | ||
---|---|---|
97 ↗ | (On Diff #9871) | I'd inline entities, you barely gain readability. |