Skip to content

Commit

Permalink
Merge branch 'release/0.10.14' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Oct 10, 2024
2 parents e4dd1e4 + 3ffbbfa commit 35d21b5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.10.14
Fix for NaN in the move penalty calculation when moving over regions.

# 0.10.13
Use a cached map to track move penalties for different region combinations. Improves compatibility with DAE while not severely impacting performance. Addresses #209.
Use a mixed wrap instead of override for `Ruler#_computeDistance`, which improves compatibility with some systems, like dnd4e. Closes #213.
Expand Down
4 changes: 3 additions & 1 deletion scripts/Ruler.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ function _getSegmentLabel(wrapped, segment) {
const origTotalDistance = this.totalDistance;
segment.distance = roundMultiple(segment.waypoint.cost);
this.totalDistance = this.totalCost;
const origLabel = wrapped(segment);

// Issue #214 and GURPS PR.
const origLabel = game.system.id === "gurps" ? wrapped(segment, this.totalDistance) : wrapped(segment);
segment.distance = origSegmentDistance;
this.totalDistance = origTotalDistance;

Expand Down
11 changes: 7 additions & 4 deletions scripts/measurement/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ game
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
"use strict";

import { Point3d } from "../geometry/3d/Point3d.js";
import { Settings } from "../settings.js";
import { log } from "../util.js";

/**
* Modify Grid classes to measure in 3d.
Expand All @@ -32,7 +32,7 @@ PATCHES_HexagonalGrid.BASIC = {};
*/
function getDirectPathGridless(wrapped, waypoints) {
const offsets2d = wrapped(waypoints);
if ( !(waypoints[0] instanceof Point3d) ) return offsets2d;
if ( !(waypoints[0] instanceof CONFIG.GeometryLib.threeD.Point3d) ) return offsets2d;

// 1-to-1 relationship between the waypoints and the offsets2d for gridless.
const GridCoordinates3d = CONFIG.GeometryLib.threeD.GridCoordinates3d;
Expand All @@ -54,13 +54,16 @@ function getDirectPathGridless(wrapped, waypoints) {
function getDirectPathGridded(wrapped, waypoints) {
const { HexGridCoordinates3d, GridCoordinates3d } = CONFIG.GeometryLib.threeD;

if ( !(waypoints[0] instanceof Point3d) ) return wrapped(waypoints);
if ( !(waypoints[0] instanceof CONFIG.GeometryLib.threeD.Point3d) ) return wrapped(waypoints);
let prevWaypoint = GridCoordinates3d.fromObject(waypoints[0]);
const path3d = [];
const path3dFn = canvas.grid.isHexagonal ? HexGridCoordinates3d._directPathHex : GridCoordinates3d._directPathSquare;
log(`getDirectPathGridded|${waypoints.length} waypoints`);
for ( let i = 1, n = waypoints.length; i < n; i += 1 ) {
const currWaypoint = GridCoordinates3d.fromObject(waypoints[i]);
log(`getDirectPathGridded|Path from ${prevWaypoint.x},${prevWaypoint.y},${prevWaypoint.z} to ${currWaypoint.x},${currWaypoint.y},${currWaypoint.z}`);
const segments3d = path3dFn(prevWaypoint, currWaypoint);
log(`getDirectPathGridded|Adding ${segments3d.length} segments`, segments3d);
path3d.push(...segments3d);
prevWaypoint = currWaypoint;
}
Expand All @@ -77,7 +80,7 @@ function getDirectPathGridded(wrapped, waypoints) {
* @param {GridMeasurePathResult} result The measurement result that the measurements need to be written to
*/
function _measurePath(wrapped, waypoints, { cost }, result) {
if ( !(waypoints[0] instanceof Point3d) ) return wrapped(waypoints, { cost }, result);
if ( !(waypoints[0] instanceof CONFIG.GeometryLib.threeD.Point3d) ) return wrapped(waypoints, { cost }, result);
const GridCoordinates3d = CONFIG.GeometryLib.threeD.GridCoordinates3d;
initializeResultObject(result);
result.waypoints.forEach(waypoint => initializeResultObject(waypoint));
Expand Down
3 changes: 2 additions & 1 deletion scripts/segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ CONFIG
import { MODULE_ID } from "./const.js";
import { Settings } from "./settings.js";
import { Ray3d } from "./geometry/3d/Ray3d.js";
import { Point3d } from "./geometry/3d/Point3d.js";
import { log } from "./util.js";
import { Pathfinder, hasCollision } from "./pathfinding/pathfinding.js";
import { MovePenalty } from "./measurement/MovePenalty.js";
Expand All @@ -18,6 +17,7 @@ import { MovePenalty } from "./measurement/MovePenalty.js";
* @returns {PIXI.Point[]}
*/
export function calculatePathPointsForSegment(segment, token) {
const Point3d = CONFIG.GeometryLib.threeD.Point3d;
const A = Point3d.fromObject(segment.ray.A);
const B = Point3d.fromObject(segment.ray.B);

Expand Down Expand Up @@ -79,6 +79,7 @@ export function constructPathfindingSegments(segments, segmentMap) {
// Make sure to keep the label for the last segment piece only
if ( !segmentMap.size ) return segments;
const newSegments = [];
const Point3d = CONFIG.GeometryLib.threeD.Point3d;
for ( const segment of segments ) {
const key = `${segment.ray.A.key}|${segment.ray.B.key}`;
const pathPoints = segmentMap.get(key);
Expand Down
6 changes: 3 additions & 3 deletions scripts/token_speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ PIXI

import { SPEED } from "./const.js";
import { Settings } from "./settings.js";
import { Point3d } from "./geometry/3d/Point3d.js";
import { Ray3d } from "./geometry/3d/Ray3d.js";
import { gridShape } from "./util.js";
import { MovePenalty } from "./measurement/MovePenalty.js";
Expand Down Expand Up @@ -123,6 +122,7 @@ function locateSegmentBreakpoint(segment, splitMoveDistance, { mp, gridless, num
if ( !segment.cost || splitMoveDistance > segment.cost ) return null;

// Attempt to move the split distance and determine the split location.
const Point3d = CONFIG.GeometryLib.threeD.Point3d;
const { A, B } = segment.ray;
let breakpoint = targetSplitForSegment(splitMoveDistance, A, B, mp, numPrevDiagonal);
if ( !gridless ) {
Expand Down Expand Up @@ -156,7 +156,7 @@ function targetSplitForSegment(targetCost, a, b, mp, numPrevDiagonal = 0) {
// Assume linear cost increment.
// So divide move in half each time.
if ( splitCost(a, b, mp, 0, numPrevDiagonal) > targetCost ) return a;
const totalDist = Point3d.distanceBetween(a, b);
const totalDist = CONFIG.GeometryLib.threeD.Point3d.distanceBetween(a, b);
if ( splitCost(a, b, mp, totalDist, numPrevDiagonal) <= targetCost ) return b;

// Now increment distance until we exceed the target cost.
Expand Down Expand Up @@ -184,7 +184,7 @@ function targetSplitForSegment(targetCost, a, b, mp, numPrevDiagonal = 0) {
* @param {number} [numPrevDiagonal=0]
*/
function splitCost(a, b, mp, stepDist = 1, numPrevDiagonal = 0) {
b = a.towardsPoint(b, stepDist, Point3d._tmp);
b = a.towardsPoint(b, stepDist, CONFIG.GeometryLib.threeD.Point3d._tmp);
b.roundDecimals(); // Ensure b is on a pixel, so we don't inadvertently exceed the cost at a border.
return mp.measureSegment(a, b, { numPrevDiagonal }).cost;
}
Expand Down

0 comments on commit 35d21b5

Please sign in to comment.