Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2755 terrain vbl #2976

Merged

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Sep 18, 2021

Implements #2755. Intentionally leaving as a draft for now as there is remaining work to do.

This change implements "terrain VBL", a new kind of VBL that allows vision into but not out of the area. Using terrain VBL allows players to see walls, pillar, landscapes, etc., while still not allowing them to see behind the VBL.

This PR has the following features:

  1. Add a new kind of topology called "terrain VBL" which allows vision into the area, but not out.
  2. If the option is selected for AI to navigate around VBL, then the AI will also navigate around terrain VBL.
  3. A new toggle button has been added to the toolbar to enable drawing terrain VBL instead of regular VBL.
  4. Tokens can be marked as terrain or not terrain.
    • If marked as terrain, the token's VBL is terrain VBL, otherwise it is regular VBL.
  5. Terrain VBL can be transferred to/from terrain tokens.
    • Terrain VBL cannot be transferred to/from non-terrain tokens
    • Regular VBL cannot be transferred to/from terrain tokens.
  6. Existing VBL functions (drawVBL(), eraseVBL(), getVBL()) now accept/return both regular and terrain VBL.
    • Terrain VBL is identified by "terrain": 1 in the shape JSON.
    • Regular VBL is identified by "terrain": 0 in the shape JSON, or if the "terrain" key is missing.
  7. Existing token VBL functions (getTokenVBL(), setTokenVBL(), transferVBL()) respect whether the token is a terrain token.
    • transferVBL respects the rules in (4). So it only operates on terrain VBL if the token is a terrain token. Otherwise, it only operates on regular VBL.
    • If setTokenVBL() is given a shape with a "terrain" key, then it will only apply terrain VBL if the token is a terrain token, and will only apply regular VBL if the token is a non-terrain token.

This change is Reviewable

This is not a feature-complete implementation. It simply treats all VBL as terrain VBL depending on the value of
`FogUtil.USE_TERRAIN_VBL`. A full implementation requires some way to distinguish aras of terrain VBL and regular VBL,
as well as some way in the GUI to draw each independently of each other.

Some implementation details have changed to support this:
- `AreaTree.getOceanAt()` always returns an ocean for valid topology, even if the point is within an island.
- `VisibleAreaSegment` can either be created from the front side or back side of an `AreaContainer`. Which side gets
used depends on whether terrain VBL is in use and whether the point is within a given `AreaContainer`.
- `GeometryFactory` instances are shared between `FogUtil` and `VisibleAreaSegment` in order to enforce consistent
precision models. This is important as the default precision is far too prone to slight differences between what ought
to be equal points. At the same time, we don't want to be too lax or else obviously distinct points can appear the
same. We currently use 10e-6 at the precision.
- `net.rptools.maptool.client.ui.zone` package had the classes `AreaData`, `AreaMeta`, and `AreaFace`. These are
redundant analogues to the classes under `net.rptools.maptool.client.ui.zone.vbl`. They were also unused except in
some expository tests, and thus have been removed.

The high-level idea of terrain VBL is that vision is able to enter terrain VBL but not leave it. Unlike Foundry, our
vision blocking is represented as solid regions of VBL rather than ideal lines acting as wall. Thus, while Foundry
terrain walls affect vision based on the number of crossings (1st crossing is allowed, 2nd and higher is blocked), our
terrain VBL affects vision by checking whether we are entering or leaving the VBL. This approach even works for line VBL
since our lines of VBL are not ideal lines but are 1-unit-wide rectangles.

Do not buffer geometry as much as it hurts performance

Buffer shadow geometry to make sure it is valid. This seems to fix all other errors meaning we do not need the expensive collection buffer at the end

buffer(1) rather than buffer(0)

Add timings; try figuring stuff out

Try keeping vision as JTS Geometry and convert that back

Various tweaks

1. Build shadows into a geometry collection which can be buffered with zero distance. This is the only buffering we do.
2. Only union the buffered geometry collection and nothing else. We don't bother unioning indvidual shadows.
3. Go back to using `Area.subtract()` instead of `Geometry.difference()`. This has less overhead (in small cases at
least) and avoid some cases of non-noded line segments.

TEMP Needs to be reverted

Split out some timers; simplify redundant variables

Include notes about future integration of GeometryFixer to avoid buffering: no net gain

Renable expose visible area timer

Code format

Invert conditions so that terrain VBL check is done per-island

Move terrain determination to AreaIsland

Allow drawing terrain VBL; digest terrain VBL as its own topology tree; note that calculateVisibility() can handle intermixed terrain and non-terrain VBL, but it is more convenient to keep them as separate trees

Remove USE_TERRAIN_VBL constant

Implement terrain VBL erase; invalidate terrain VBL tree on change; backwards compatibility for zones with no terrain VBL

Add missing selection tool

Remove stats
… not mitigate the need for the union since the geometry remains all funky. I think it is not ready for primetime
…rue, but existing tokens will have it be false
… the Is Terrain? checkbox rather than the value stored in token. This is important as the token is not updated until the dialog is successfully closed
…nsfer the same type of VBL as the token represents
…rameters to control whether is terrain VBL or not
@Phergus Phergus marked this pull request as ready for review September 30, 2021 16:29
@Phergus Phergus changed the base branch from develop to feature-terrain-vbl September 30, 2021 16:34
@Phergus Phergus merged commit bd6b054 into RPTools:feature-terrain-vbl Sep 30, 2021
@Phergus
Copy link
Contributor

Phergus commented Sep 30, 2021

Merged to branch feature-terrain-vbl for testing.

@kwvanderlinde kwvanderlinde deleted the issue-2755-terrain-vbl branch October 12, 2021 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants