Skip to content

Commit

Permalink
Merge branch 'release/0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Oct 2, 2022
2 parents fa84870 + 8f39b59 commit beb100d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.1.2
Fix for testing detect range. This should fix functionality for detect tremor. Note that detection is using a 3d range, which affects detection when token or target is elevated. Tremor does not currently consider whether or not a token is "on the ground."

Fix for issue #16 (negative elevation).
Fix for issue #12 (levels compatibility) and #14 (_testRange check).
Possible fix for issue #15.

## 0.1.1
Fix for issue #13 (applying elevation data to limited vision).

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ Special thanks to:
- [Wall Height](https://foundryvtt.com/packages/wall-height/)

## Recommended modules
- [Token Lean](https://foundryvtt.com/packages/token-lean). Token Lean is a great addition because it allows tokens to "peak" over the edge of a cliff.
- [Token Lean](https://foundryvtt.com/packages/token-lean). Token Lean is a great addition because it allows tokens to "peak" over the edge of a cliff. For v10, I have created a fork: https://github.com/caewok/token-lean/releases.

## Incompatible modules
- Only partially compatible with [Perfect Vision](https://foundryvtt.com/packages/perfect-vision). As of Elevated Vision v0.1.0, lighting shadows work but vision shadows do not. But Perfect Vision should load and possibly work without throwing errors.
- [Levels](https://foundryvtt.com/packages/levels) likely will have issues. If you want real 3d, I recommend [Ripper's 3d Canvas](https://theripper93.com/). It probably goes without saying, but I will say it anyway, that mixing this module with 3d Canvas will likely result in serious errors.
## Problematic modules
- Currently only partially compatible with [Perfect Vision](https://foundryvtt.com/packages/perfect-vision). As of Elevated Vision v0.1.0, lighting shadows work but vision shadows do not. But Perfect Vision should load and possibly work without throwing errors.
- [Levels](https://foundryvtt.com/packages/levels) should now work. When Levels or Perfect Vision are present, Elevated Vision hands off visibility testing to those modules. In theory, visibility tests should be comparable using only Elevated Vision versus using Levels or Perfect Vision. Please report potential discrepancies in the Git issue tracker.
- If you want real 3d, I recommend [Ripper's 3d Canvas](https://theripper93.com/). It probably goes without saying, but I will say it anyway, that mixing this module with 3d Canvas will likely result in serious errors.

# Examples

Expand Down
23 changes: 16 additions & 7 deletions scripts/ElevationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class ElevationLayer extends InteractionLayer {
* @type {number}
*/
get elevationMax() {
return (this.#maximumPixelValue * this.elevationStep) - this.elevationMin;
return this.elevationMin + (this.#maximumPixelValue * this.elevationStep);
}

/* ------------------------ */
Expand All @@ -265,17 +265,26 @@ export class ElevationLayer extends InteractionLayer {
* @returns {number}
*/
pixelValueToElevation(value) {
return (Math.round(value * this.elevationStep * 10) / 10) - this.elevationMin;
return this.elevationMin + (Math.round(value * this.elevationStep * 10) / 10);
}

/**
* Convert an elevation value to a pixel value between 0 and 255
* @param {number} value Elevation
* @returns {number}
*/
elevationToPixelValue(elevation) {
elevation = this.clampElevation(elevation);
return (elevation - this.elevationMin) / this.elevationStep;
}

/**
* Color used to store this elevation value.
* @param {number} e Proposed elevation value. May be corrected by clampElevation.
* @param {number} elevation Proposed elevation value. May be corrected by clampElevation.
* @return {Hex}
*/
elevationHex(e) {
e = this.clampElevation(e);
const value = (e + this.elevationMin) / this.elevationStep;
elevationHex(elevation) {
const value = this.elevationToPixelValue(elevation);

// Gradient from red (255, 0, 0) to blue (0, 0, 255)
// Flip at 128
Expand All @@ -284,7 +293,7 @@ export class ElevationLayer extends InteractionLayer {
// const g = 0;
// const b = value - 255;

log(`elevationHex elevation ${e}, value ${value}`);
log(`elevationHex elevation ${elevation}, value ${value}`);

return PIXI.utils.rgb2hex([value / this.#maximumPixelValue, 0, 0]);
}
Expand Down
4 changes: 3 additions & 1 deletion scripts/lighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ const FN_PERPENDICULAR_POINT =
// Maps 0–1 to elevation in canvas coordinates.
// EV_elevationResolution:
// r: elevation min; g: elevation step; b: max pixel value (likely 255); a: canvas size / distance
// u.EV_elevationResolution = [elevationMin, elevationStep, maximumPixelValue, elevationMult];

const FN_CANVAS_ELEVATION_FROM_PIXEL =
`
return ((pixel * EV_elevationResolution.b * EV_elevationResolution.g) - EV_elevationResolution.r) * EV_elevationResolution.a;
return (EV_elevationResolution.r + (pixel * EV_elevationResolution.b * EV_elevationResolution.g)) * EV_elevationResolution.a;
`;

// Determine if a given location from a wall is in shadow or not.
Expand Down
11 changes: 7 additions & 4 deletions scripts/patching.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ function shaderPVAdditions() {
export function registerPatches() {
const use_shader = getSetting(SETTINGS.VISION_USE_SHADER);
const pv_present = game.modules.get("perfect-vision")?.active;
const levels_present = game.modules.get("levels")?.active;
const shader_choice = use_shader | (pv_present << 1);

if ( pv_present ) PerfectVision.debug = true; // Turn off GLSL optimizer b/c it is buggy.
Expand All @@ -238,10 +239,12 @@ export function registerPatches() {
libWrapper.register(MODULE_ID, "LightSource.prototype._createPolygon", _createPolygonLightSource, libWrapper.WRAPPER, {perf_mode: libWrapper.PERF_FAST});

// ----- Visibility testing ----- //
libWrapper.register(MODULE_ID, "LightSource.prototype.testVisibility", testVisibilityLightSource, libWrapper.MIXED, {perf_mode: libWrapper.PERF_FAST});
libWrapper.register(MODULE_ID, "DetectionMode.prototype.testVisibility", testVisibilityDetectionMode, libWrapper.WRAPPER, {perf_mode: libWrapper.PERF_FAST});
libWrapper.register(MODULE_ID, "DetectionMode.prototype._testRange", _testRangeDetectionMode, libWrapper.WRAPPER, {perf_mode: libWrapper.PERF_FAST});
libWrapper.register(MODULE_ID, "DetectionMode.prototype._testLOS", _testLOSDetectionMode, libWrapper.WRAPPER, {perf_mode: libWrapper.PERF_FAST});
if ( !pv_present && !levels_present ) {
libWrapper.register(MODULE_ID, "LightSource.prototype.testVisibility", testVisibilityLightSource, libWrapper.MIXED, {perf_mode: libWrapper.PERF_FAST});
libWrapper.register(MODULE_ID, "DetectionMode.prototype.testVisibility", testVisibilityDetectionMode, libWrapper.WRAPPER, {perf_mode: libWrapper.PERF_FAST});
libWrapper.register(MODULE_ID, "DetectionMode.prototype._testRange", _testRangeDetectionMode, libWrapper.WRAPPER, {perf_mode: libWrapper.PERF_FAST});
libWrapper.register(MODULE_ID, "DetectionMode.prototype._testLOS", _testLOSDetectionMode, libWrapper.WRAPPER, {perf_mode: libWrapper.PERF_FAST});
}

// ----- Token animation and elevation change ---- //
libWrapper.register(MODULE_ID, "Token.prototype._refresh", _refreshToken, libWrapper.WRAPPER, {perf_mode: libWrapper.PERF_FAST});
Expand Down
2 changes: 1 addition & 1 deletion scripts/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function _testRangeDetectionMode(wrapper, visionSource, mode, target, tes
const radius = visionSource.object.getLightRadius(mode.range);
const dx = test.point.x - visionSource.x;
const dy = test.point.y - visionSource.y;
const dz = test.point.z - visionSource.topZ;
const dz = test.point.z - visionSource.elevationZ;
return ((dx * dx) + (dy * dy) + (dz * dz)) <= (radius * radius);
}

Expand Down

0 comments on commit beb100d

Please sign in to comment.