This commit is contained in:
Jan Racek
2026-03-27 21:29:01 +01:00
parent 85eb7e59d9
commit bfab154547
42 changed files with 118 additions and 1013 deletions

View File

@@ -117,40 +117,6 @@ void NavRegionSystem::closestPointOnSegment(int32_t px, int32_t pz,
outZ = az + fpmul(t, abz);
}
// ============================================================================
// Segment crosses portal check (XZ)
// ============================================================================
bool NavRegionSystem::segmentCrossesPortal(int32_t p0x, int32_t p0z,
int32_t p1x, int32_t p1z,
int32_t ax, int32_t az,
int32_t bx, int32_t bz) {
// Standard 2D segment intersection test using cross products.
// Returns true if segment [p0,p1] crosses segment [a,b].
int32_t dx = p1x - p0x, dz = p1z - p0z;
int32_t ex = bx - ax, ez = bz - az;
int64_t denom = (int64_t)dx * ez - (int64_t)dz * ex;
if (denom == 0) return false; // Parallel
int32_t fx = ax - p0x, fz = az - p0z;
int64_t tNum = (int64_t)fx * ez - (int64_t)fz * ex;
int64_t uNum = (int64_t)fx * dz - (int64_t)fz * dx;
// Check t in [0,1] and u in [0,1]
if (denom > 0) {
if (tNum < 0 || tNum > denom) return false;
if (uNum < 0 || uNum > denom) return false;
} else {
if (tNum > 0 || tNum < denom) return false;
if (uNum > 0 || uNum < denom) return false;
}
return true;
}
// ============================================================================
// Get floor Y at position (plane equation)
// ============================================================================
@@ -316,36 +282,10 @@ int32_t NavRegionSystem::resolvePosition(int32_t& newX, int32_t& newZ,
bool NavRegionSystem::findPath(uint16_t startRegion, uint16_t endRegion,
NavPath& path) const {
// STUB: Returns false until NPC pathfinding is implemented.
// When implemented, this will be A* over the region adjacency graph:
// - Open set: priority queue by f-cost (g + heuristic)
// - g-cost: sum of Euclidean distances between region centroids
// - Heuristic: straight-line distance to goal centroid
// - Neighbor iteration: via portal edges
// - Max path length: NAV_MAX_PATH_STEPS
path.stepCount = 0;
(void)startRegion;
(void)endRegion;
return false;
}
// ============================================================================
// Get portal between two regions
// ============================================================================
const NavPortal* NavRegionSystem::getPortalBetween(uint16_t regionA, uint16_t regionB) const {
if (regionA >= m_header.regionCount) return nullptr;
const auto& reg = m_regions[regionA];
for (int i = 0; i < reg.portalCount; i++) {
uint16_t portalIdx = reg.portalStart + i;
if (portalIdx >= m_header.portalCount) break;
if (m_portals[portalIdx].neighborRegion == regionB) {
return &m_portals[portalIdx];
}
}
return nullptr;
}
} // namespace psxsplash