Opened 9 years ago
Closed 9 years ago
#2913 closed task (fixed)
[PATCH] Better way to handle visibilities in the simulation
Reported by: | Itms | Owned by: | Itms |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 18 |
Component: | Core engine | Keywords: | |
Cc: | Patch: |
Description (last modified by )
My work on #599 allowed me to work on the visibility systems (fog-of-war, line of sight, etc.), and currently, a large part of the visibility logic is handled by the RangeManager system component, especially in this function.
As a consequence, scripted components can't influence the visibility of an entity. Mods, but also planned features for the main game (like Iberian camouflaged units), would need a way to influence this visibility. Also, the way I plan to tackle #2710 needs it.
I propose to separate this logic into a Visibility component. Several things could benefit from this change.
I think it would be better to do changes in separate patches/commits, to avoid complexity and possible regressions. So I set this ticket as a task, and I will use it to track the changes. Remaining planned changes:
Create the Visibility component- Find a way to remove the hardcoded and duplicated VIS_FOO in the scripted components Fogging, Mirage and Visibility
Move template items GetRetainInFog and AlwaysVisible from Vision to VisibilityUpdate component documentations (RangeManager, Visibility), including code comments- Fix #2710 with the new system
Improve #958 with the new system if possible (see this TODO)- For fun, implement camouflaging for some units
Attachments (12)
Change History (42)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Description: | modified (diff) |
---|
comment:5 by , 9 years ago
Keywords: | review patch added |
---|
Here is a patch to use the cached visibility (introduced for mirages) for any entity. This would reduce the number of computations of the visibility, which is currently huge, but no profiling was done yet. I will come up with some data but I post the patch for review in the meantime.
by , 9 years ago
Attachment: | use_cached_visibility.patch added |
---|
comment:7 by , 9 years ago
Here is a patch moving back the computation of visibilities to C++. Now, the scripted component is called only if necessary.
As a use case of the scripted part, I fixed the TODO remaining from #958.
However, a style improvement would be handling properly the empty properties of scripted components in templates. For instance, currently Decay has an <Inactive/>
component, well handled in C++, but I was forced to write <Preview>true</Preview>
in my case to make the code work. This must be fixed before committing.
comment:8 by , 9 years ago
Keywords: | review patch added |
---|---|
Summary: | Better way to handle visibilities in the simulation → [PATCH] Better way to handle visibilities in the simulation |
by , 9 years ago
Attachment: | visibility-performance+958.patch added |
---|
comment:12 by , 9 years ago
Cc: | added |
---|
Hi Ben, could you take a look at the latest patch, which works around a code you wrote? I'd like to commit it asap, probably tomorrow. Thanks in advance :)
comment:14 by , 9 years ago
Description: | modified (diff) |
---|
Attached patch reduces drastically the number of mirages by making fogging conditional: entities will be miraged only if their health/resource amount is reduced, or if they have a non-gaia owner.
It also cleans out the code in some parts, and fixes the invisible animals problem and the missing status bars for mirages.
I'll commit it on Friday evening, so please give feedback :)
comment:15 by , 9 years ago
Some small comments from a quick look at the patch which looks nice
For gaia, we should also activate mirage if the health increases (i.e. gaia tower being repaired), so the activation should also be done in Health.prototype.Increase.
In StatusBar, we could remove useless parentheses: lines 106-108, 112-114 and 118-120 + those added in the patch
comment:16 by , 9 years ago
Ah yeah, missed these two things, thanks :) I can't fix them right now though.
In the meantime, could you or Yves run the tracelogger on a patched version to see what impact it would have? That would be great!
comment:17 by , 9 years ago
The tracelogger isn't the best tool for measuring here. Reducing the number of entities can have an impact on many different parts of the engine. I'd try with profiler1 and a preconfigured AI match (-autostart argument). Could you wait until Saturday evening before committing? I can have a look, but not before the weekend
comment:18 by , 9 years ago
I've done some counting of entities, but haven't tired to measured performance differences.
Normally, the map is currently revealed for AI players, so this patch doesn't have an effect on them and can't be tested. I've disabled revealing of the map for testing. This also means it will only improve performance for human players and especially if there are more human players (multiplayer).
I've used this command to test on a map with a lot of miraged entities (trees).
./pyrogenesis -autostart="random/deep_forest" -autostart-players=4 -autostart-size=256 -autostart-ai=1:petra -autostart-ai=2:petra -autostart-ai=3:petra -autostart-ai=4:petra
I've waited until the first few attacks are over (by this time, all players should have "scouted" quite a bit) and counted the total number of entities.
Original Start of the match: 5856 entities After first series of attacks: 12795 entities
Patch Start of the match: 5519 entities After first series of attacks: 5734 entities
As you see, it dramatically reduces the number of entities and I guess it also has quite an impact on performance. Very clever idea for this patch!
by , 9 years ago
Attachment: | conditional-fogging.patch added |
---|
comment:21 by , 9 years ago
Keywords: | review patch removed |
---|---|
Milestone: | Alpha 18 → Alpha 19 |
by , 9 years ago
Attachment: | commands.txt added |
---|
A match on deep forest with 3 AIs. Very laagy at the end during a large attack (up to 30 ms/frame in UpdateVisibilityData)
comment:22 by , 9 years ago
One problem I see is that m_DirtyVisibility is not player-specific. It will mark all tiles as dirty that have changed their visibility state for any player and then updates the visibility of that tile for all players. I've added some printing of the percentage of tiles that are dirty in each run of UpdateVisibilityData. It starts at around 3-4% and goes up to more than 20% later in game. I think it would be faster with caching per player and only updating the bits of the visibility flag for the player whose vision on that tile changed.
by , 9 years ago
Attachment: | Hack_CCmpVisibilityScripted_IsActive_0.1.diff added |
---|
A quick and ugly hack to reduce the number of IsActive() calls to JS along with some changes used for profiling
by , 9 years ago
Attachment: | Hack_CmpVisibilityScripted_IsActive.png added |
---|
Performance measurement of the hack. I've used the autostart options to setup a match with 4 AI players on deep_forest with SimRate set to 8 (ignore the absolute values and be careful with the interpretation of that data). However, the difference between the two UpdateVisibilityData lines is surprisingly big.
comment:23 by , 9 years ago
Keywords: | review patch added |
---|---|
Milestone: | Alpha 19 → Alpha 18 |
Make the dirty visibility flag a bit more clever.
by , 9 years ago
Attachment: | clever_dirty_visibility.patch added |
---|
comment:25 by , 9 years ago
This patch moves the Visibility activation logic to the range manager for performance. I upload in a few minutes a graph comparing it with r16329.
by , 9 years ago
Attachment: | cpp_activation.patch added |
---|
by , 9 years ago
Attachment: | profile.2.png added |
---|
comment:26 by , 9 years ago
Well done! Measurements are way better now (with both patches) and I've played a whole game without any laag caused by UpdateVisibilityData. I'd say it's fast enough now.
Something else: Is it intended that you can't build in the fog of war now? I didn't check when that was introduced. If it's intended, that seems to be OK for me (avoids some difficult situations like when players try to build on an obstructed place and the problem of cheating that arises when we give early feedback if building is possible or not).
by , 9 years ago
Attachment: | graph_2v2_ai_deepforest_all.png added |
---|
Updated graph (still with a sim rate of 8)
comment:28 by , 9 years ago
Keywords: | review patch removed |
---|---|
Milestone: | Alpha 18 → Alpha 19 |
comment:29 by , 9 years ago
Can be used to get spies units into the gameplay?, if is possibly modding feature to this
"As a consequence, scripted components can't influence the visibility of an entity. Mods, but also planned features for the main game (like Iberian camouflaged units), would need a way to influence this visibility. Also, the way I plan to tackle #2710 needs it."
comment:30 by , 9 years ago
Cc: | removed |
---|---|
Milestone: | Alpha 19 → Alpha 18 |
Resolution: | → fixed |
Status: | new → closed |
I don't see a clean way to remove the hardcoded values in the scripts (it would lead to more hacks and less flexibility).
So everything in the list is completed. Camouflaging is #3177.
In 15925: