diff --git a/RN_DetourNavMeshBuilder.pas b/RN_DetourNavMeshBuilder.pas index 495f9a3..07fd0c3 100644 --- a/RN_DetourNavMeshBuilder.pas +++ b/RN_DetourNavMeshBuilder.pas @@ -21,6 +21,8 @@ interface type + PPByte = ^PByte; + /// Represents the source data used to build an navigation mesh tile. /// @ingroup detour PdtNavMeshCreateParams = ^TdtNavMeshCreateParams; @@ -109,7 +111,7 @@ TdtNavMeshCreateParams = record /// @param[out] outData The resulting tile data. /// @param[out] outDataSize The size of the tile data array. /// @return True if the tile data was successfully created. -function dtCreateNavMeshData(params: PdtNavMeshCreateParams; outData: PPointer; outDataSize: PInteger): Boolean; +function dtCreateNavMeshData(params: PdtNavMeshCreateParams; outData: PPByte; outDataSize: PInteger): Boolean; /// Swaps the endianess of the tile data's header (#dtMeshHeader). /// @param[in,out] data The tile data array. @@ -262,7 +264,7 @@ procedure subdivide(items: PBVItem; nitems, imin, imax: Integer; curNode: PInteg else begin // Split - calcExtends(items, nitems, imin, imax, @node.bmin, @node.bmax); + calcExtends(items, nitems, imin, imax, @node.bmin[0], @node.bmax[0]); axis := longestAxis(node.bmax[0] - node.bmin[0], node.bmax[1] - node.bmin[1], @@ -379,7 +381,7 @@ function classifyOffMeshPoint(pt, bmin, bmax: PSingle): Byte; /// mesh. /// /// @see dtNavMesh, dtNavMesh::addTile() -function dtCreateNavMeshData(params: PdtNavMeshCreateParams; outData: PPointer; outDataSize: PInteger): Boolean; +function dtCreateNavMeshData(params: PdtNavMeshCreateParams; outData: PPByte; outDataSize: PInteger): Boolean; var nvp: Integer; offMeshConClass: PByte; storedOffMeshConCount,offMeshConLinkCount: Integer; hmin,hmax,h: Single; i,j: Integer; iv,p: PWord; bmin,bmax: array [0..2] of Single; p0,p1: PSingle; totPolyCount, totVertCount: Integer; edgeCount, portalCount: Integer; dir: Word; maxLinkCount, uniqueDetailVertCount, detailTriCount,ndv,nv: Integer; @@ -436,8 +438,8 @@ function dtCreateNavMeshData(params: PdtNavMeshCreateParams; outData: PPointer; hmin := hmin - params.walkableClimb; hmax := hmax + params.walkableClimb; - dtVcopy(@bmin, @params.bmin); - dtVcopy(@bmax, @params.bmax); + dtVcopy(@bmin[0], @params.bmin[0]); + dtVcopy(@bmax[0], @params.bmax[0]); bmin[1] := hmin; bmax[1] := hmax; @@ -445,8 +447,8 @@ function dtCreateNavMeshData(params: PdtNavMeshCreateParams; outData: PPointer; begin p0 := @params.offMeshConVerts[(i*2+0)*3]; p1 := @params.offMeshConVerts[(i*2+1)*3]; - offMeshConClass[i*2+0] := classifyOffMeshPoint(p0, @bmin, @bmax); - offMeshConClass[i*2+1] := classifyOffMeshPoint(p1, @bmin, @bmax); + offMeshConClass[i*2+0] := classifyOffMeshPoint(p0, @bmin[0], @bmax[0]); + offMeshConClass[i*2+1] := classifyOffMeshPoint(p1, @bmin[0], @bmax[0]); // Zero out off-mesh start positions which are not even potentially touching the mesh. if (offMeshConClass[i*2+0] = $ff) then @@ -571,8 +573,8 @@ offMeshConClass[i*2+1] := classifyOffMeshPoint(p1, @bmin, @bmax); header.polyCount := totPolyCount; header.vertCount := totVertCount; header.maxLinkCount := maxLinkCount; - dtVcopy(@header.bmin, @params.bmin); - dtVcopy(@header.bmax, @params.bmax); + dtVcopy(@header.bmin[0], @params.bmin[0]); + dtVcopy(@header.bmax[0], @params.bmax[0]); header.detailMeshCount := params.polyCount; header.detailVertCount := uniqueDetailVertCount; header.detailTriCount := detailTriCount; diff --git a/RN_DetourObstacleAvoidance.pas b/RN_DetourObstacleAvoidance.pas index 784d3d4..28ac546 100644 --- a/RN_DetourObstacleAvoidance.pas +++ b/RN_DetourObstacleAvoidance.pas @@ -162,14 +162,14 @@ function sweepCircleCircle(const c0: PSingle; const r0: Single; const v: PSingle const EPS = 0.0001; var s: array [0..2] of Single; r,c,a,b,d,rd: Single; begin - dtVsub(@s,c1,c0); + dtVsub(@s[0],c1,c0); r := r0+r1; - c := dtVdot2D(@s,@s) - r*r; + c := dtVdot2D(@s[0],@s[0]) - r*r; a := dtVdot2D(v,v); if (a < EPS) then Exit(0); // not moving // Overlap, calc time to exit. - b := dtVdot2D(v,@s); + b := dtVdot2D(v,@s[0]); d := b*b - a*c; if (d < 0.0) then Exit(0); // no intersection. a := 1.0 / a; @@ -183,14 +183,14 @@ function isectRaySeg(const ap, u, bp, bq: PSingle; t: PSingle): Integer; var v,w: array [0..2] of Single; d,s: Single; begin - dtVsub(@v,bq,bp); - dtVsub(@w,ap,bp); - d := dtVperp2D(u,@v); + dtVsub(@v[0],bq,bp); + dtVsub(@w[0],ap,bp); + d := dtVperp2D(u,@v[0]); if (abs(d) < 0.000001) then Exit(0); d := 1.0/d; - t^ := dtVperp2D(@v,@w) * d; + t^ := dtVperp2D(@v[0],@w[0]) * d; if (t^ < 0) or (t^ > 1) then Exit(0); - s := dtVperp2D(u,@w) * d; + s := dtVperp2D(u,@w[0]) * d; if (s < 0) or (s > 1) then Exit(0); Result := 1; end; @@ -225,13 +225,13 @@ constructor TdtObstacleAvoidanceDebugData.Create(); destructor TdtObstacleAvoidanceDebugData.Destroy; begin - FreeAndNil(m_vel); - FreeAndNil(m_ssize); - FreeAndNil(m_pen); - FreeAndNil(m_vpen); - FreeAndNil(m_vcpen); - FreeAndNil(m_spen); - FreeAndNil(m_tpen); + if m_vel <> nil then FreeMem(m_vel); + if m_ssize <> nil then FreeMem(m_ssize); + if m_pen <> nil then FreeMem(m_pen); + if m_vpen <> nil then FreeMem(m_vpen); + if m_vcpen <> nil then FreeMem(m_vcpen); + if m_spen <> nil then FreeMem(m_spen); + if m_tpen <> nil then FreeMem(m_tpen); inherited; end; @@ -377,8 +377,8 @@ procedure TdtObstacleAvoidanceQuery.addCircle(const pos: PSingle; const rad: Sin Inc(m_ncircles); dtVcopy(@cir.p, pos); cir.rad := rad; - dtVcopy(@cir.vel, vel); - dtVcopy(@cir.dvel, dvel); + dtVcopy(@cir.vel[0], vel); + dtVcopy(@cir.dvel[0], dvel); end; procedure TdtObstacleAvoidanceQuery.addSegment(const p, q: PSingle); @@ -390,7 +390,7 @@ procedure TdtObstacleAvoidanceQuery.addSegment(const p, q: PSingle); seg := @m_segments[m_nsegments]; Inc(m_nsegments); dtVcopy(@seg.p, p); - dtVcopy(@seg.q, q); + dtVcopy(@seg.q[0], q); end; procedure TdtObstacleAvoidanceQuery.prepare(const pos, dvel: PSingle); @@ -406,11 +406,11 @@ procedure TdtObstacleAvoidanceQuery.prepare(const pos, dvel: PSingle); pb := @cir.p; orig[0] := 0; orig[1] := 0; orig[2] := 0; - dtVsub(@cir.dp,pb,pa); - dtVnormalize(@cir.dp); - dtVsub(@dv, @cir.dvel, dvel); + dtVsub(@cir.dp[0],pb,pa); + dtVnormalize(@cir.dp[0]); + dtVsub(@dv[0], @cir.dvel[0], dvel); - a := dtTriArea2D(@orig, @cir.dp, @dv); + a := dtTriArea2D(@orig[0], @cir.dp[0], @dv[0]); if (a < 0.01) then begin cir.np[0] := -cir.dp[2]; @@ -429,7 +429,7 @@ procedure TdtObstacleAvoidanceQuery.prepare(const pos, dvel: PSingle); // Precalc if the agent is really close to the segment. r := 0.01; - seg.touch := dtDistancePtSegSqr2D(pos, @seg.p, @seg.q, @t) < Sqr(r); + seg.touch := dtDistancePtSegSqr2D(pos, @seg.p[0], @seg.q[0], @t) < Sqr(r); end; end; @@ -470,16 +470,16 @@ function TdtObstacleAvoidanceQuery.processSample(const vcand: PSingle; const cs: cir := @m_circles[i]; // RVO - dtVscale(@vab, vcand, 2); - dtVsub(@vab, @vab, vel); - dtVsub(@vab, @vab, @cir.vel); + dtVscale(@vab[0], vcand, 2); + dtVsub(@vab[0], @vab[0], vel); + dtVsub(@vab[0], @vab[0], @cir.vel[0]); // Side - side := side + dtClamp(dtMin(dtVdot2D(@cir.dp,@vab)*0.5+0.5, dtVdot2D(@cir.np,@vab)*2), 0.0, 1.0); + side := side + dtClamp(dtMin(dtVdot2D(@cir.dp[0],@vab[0])*0.5+0.5, dtVdot2D(@cir.np[0],@vab[0])*2), 0.0, 1.0); Inc(nside); htmin := 0; htmax := 0; - if (sweepCircleCircle(pos,rad, @vab, @cir.p,cir.rad, @htmin, @htmax) = 0) then + if (sweepCircleCircle(pos,rad, @vab[0], @cir.p,cir.rad, @htmin, @htmax) = 0) then continue; // Handle overlapping obstacles. @@ -509,18 +509,18 @@ function TdtObstacleAvoidanceQuery.processSample(const vcand: PSingle; const cs: if (seg.touch) then begin // Special case when the agent is very close to the segment. - dtVsub(@sdir, @seg.q, @seg.p); + dtVsub(@sdir[0], @seg.q[0], @seg.p[0]); snorm[0] := -sdir[2]; snorm[2] := sdir[0]; // If the velocity is pointing towards the segment, no collision. - if (dtVdot2D(@snorm, vcand) < 0.0) then + if (dtVdot2D(@snorm[0], vcand) < 0.0) then continue; // Else immediate collision. htmin := 0.0; end else begin - if (isectRaySeg(pos, vcand, @seg.p, @seg.q, @htmin) = 0) then + if (isectRaySeg(pos, vcand, @seg.p[0], @seg.q[0], @htmin) = 0) then continue; end; @@ -588,12 +588,12 @@ function TdtObstacleAvoidanceQuery.sampleVelocityGrid(const pos: PSingle; const if (Sqr(vcand[0])+Sqr(vcand[2]) > Sqr(vmax+cs/2)) then continue; - penalty := processSample(@vcand, cs, pos,rad,vel,dvel, minPenalty, debug); + penalty := processSample(@vcand[0], cs, pos,rad,vel,dvel, minPenalty, debug); Inc(ns); if (penalty < minPenalty) then begin minPenalty := penalty; - dtVcopy(nvel, @vcand); + dtVcopy(nvel, @vcand[0]); end; end; end; @@ -661,9 +661,9 @@ function TdtObstacleAvoidanceQuery.sampleVelocityAdaptive(const pos: PSingle; co sa := sin(da); // desired direction - dtVcopy(@ddir, dvel); - dtNormalize2D(@ddir); - dtRorate2D(@ddir[3], @ddir, da*0.5); // rotated by da/2 + dtVcopy(@ddir[0], dvel); + dtNormalize2D(@ddir[0]); + dtRorate2D(@ddir[3], @ddir[0], da*0.5); // rotated by da/2 // Always add sample at zero pat[npat*2+0] := 0; @@ -707,13 +707,13 @@ function TdtObstacleAvoidanceQuery.sampleVelocityAdaptive(const pos: PSingle; co // Start sampling. cr := vmax * (1.0 - m_params.velBias); - dtVset(@res, dvel[0] * m_params.velBias, 0, dvel[2] * m_params.velBias); + dtVset(@res[0], dvel[0] * m_params.velBias, 0, dvel[2] * m_params.velBias); ns := 0; for k := 0 to depth - 1 do begin minPenalty := MaxSingle; - dtVset(@bvel, 0,0,0); + dtVset(@bvel[0], 0,0,0); for i := 0 to npat - 1 do begin @@ -723,21 +723,21 @@ function TdtObstacleAvoidanceQuery.sampleVelocityAdaptive(const pos: PSingle; co if (Sqr(vcand[0])+Sqr(vcand[2]) > Sqr(vmax+0.001)) then continue; - penalty := processSample(@vcand,cr/10, pos,rad,vel,dvel, minPenalty, debug); + penalty := processSample(@vcand[0],cr/10, pos,rad,vel,dvel, minPenalty, debug); Inc(ns); if (penalty < minPenalty) then begin minPenalty := penalty; - dtVcopy(@bvel, @vcand); + dtVcopy(@bvel[0], @vcand[0]); end; end; - dtVcopy(@res, @bvel); + dtVcopy(@res[0], @bvel[0]); cr := cr * 0.5; end; - dtVcopy(nvel, @res); + dtVcopy(nvel, @res[0]); Result := ns; end; diff --git a/RN_DetourPathCorridor.pas b/RN_DetourPathCorridor.pas index b4764a1..c1af706 100644 --- a/RN_DetourPathCorridor.pas +++ b/RN_DetourPathCorridor.pas @@ -358,8 +358,8 @@ function TdtPathCorridor.init(const maxPath: Integer): Boolean; procedure TdtPathCorridor.reset(ref: TdtPolyRef; const pos: PSingle); begin Assert(m_path <> nil); - dtVcopy(@m_pos, pos); - dtVcopy(@m_target, pos); + dtVcopy(@m_pos[0], pos); + dtVcopy(@m_target[0], pos); m_path[0] := ref; m_npath := 1; end; @@ -386,14 +386,14 @@ function TdtPathCorridor.findCorners(cornerVerts: PSingle; cornerFlags: PByte; Assert(m_npath <> 0); ncorners := 0; - navquery.findStraightPath(@m_pos, @m_target, m_path, m_npath, + navquery.findStraightPath(@m_pos[0], @m_target[0], m_path, m_npath, cornerVerts, cornerFlags, cornerPolys, @ncorners, maxCorners); // Prune points in the beginning of the path which are too close. while (ncorners <> 0) do begin if ((cornerFlags[0] and Byte(DT_STRAIGHTPATH_OFFMESH_CONNECTION)) <> 0) or - (dtVdist2DSqr(@cornerVerts[0], @m_pos) > Sqr(MIN_TARGET_DIST)) then + (dtVdist2DSqr(@cornerVerts[0], @m_pos[0]) > Sqr(MIN_TARGET_DIST)) then break; Dec(ncorners); if (ncorners <> 0) then @@ -443,8 +443,8 @@ procedure TdtPathCorridor.optimizePathVisibility(const next: PSingle; const path Assert(m_path <> nil); // Clamp the ray to max distance. - dtVcopy(@goal, next); - dist := dtVdist2D(@m_pos, @goal); + dtVcopy(@goal[0], next); + dist := dtVdist2D(@m_pos[0], @goal[0]); // If too close to the goal, do not try to optimize. if (dist < 0.01) then @@ -454,14 +454,14 @@ procedure TdtPathCorridor.optimizePathVisibility(const next: PSingle; const path dist := dtMin(dist+0.01, pathOptimizationRange); // Adjust ray length. - dtVsub(@delta, @goal, @m_pos); - dtVmad(@goal, @m_pos, @delta, pathOptimizationRange/dist); + dtVsub(@delta[0], @goal[0], @m_pos[0]); + dtVmad(@goal[0], @m_pos[0], @delta[0], pathOptimizationRange/dist); nres := 0; - navquery.raycast(m_path[0], @m_pos, @goal, filter, @t, @norm, @res, @nres, MAX_RES); + navquery.raycast(m_path[0], @m_pos[0], @goal[0], filter, @t, @norm[0], @res[0], @nres, MAX_RES); if (nres > 1) and (t > 0.99) then begin - m_npath := dtMergeCorridorStartShortcut(m_path, m_npath, m_maxPath, @res, nres); + m_npath := dtMergeCorridorStartShortcut(m_path, m_npath, m_maxPath, @res[0], nres); end; end; @@ -488,13 +488,13 @@ function TdtPathCorridor.optimizePathTopology(navquery: TdtNavMeshQuery; const f Exit(false); nres := 0; - navquery.initSlicedFindPath(m_path[0], m_path[m_npath-1], @m_pos, @m_target, filter); + navquery.initSlicedFindPath(m_path[0], m_path[m_npath-1], @m_pos[0], @m_target[0], filter); navquery.updateSlicedFindPath(MAX_ITER, nil); - status := navquery.finalizeSlicedFindPathPartial(m_path, m_npath, @res, @nres, MAX_RES); + status := navquery.finalizeSlicedFindPathPartial(m_path, m_npath, @res[0], @nres, MAX_RES); if dtStatusSucceed(status) and (nres > 0) then begin - m_npath := dtMergeCorridorStartShortcut(m_path, m_npath, m_maxPath, @res, nres); + m_npath := dtMergeCorridorStartShortcut(m_path, m_npath, m_maxPath, @res[0], nres); Exit(true); end; @@ -539,7 +539,7 @@ function TdtPathCorridor.moveOverOffmeshConnection(offMeshConRef: TdtPolyRef; re status := nav.getOffMeshConnectionPolyEndPoints(refs[0], refs[1], startPos, endPos); if (dtStatusSucceed(status)) then begin - dtVcopy(@m_pos, endPos); + dtVcopy(@m_pos[0], endPos); Exit(true); end; @@ -571,17 +571,17 @@ function TdtPathCorridor.movePosition(const npos: PSingle; navquery: TdtNavMeshQ // Move along navmesh and update new position. nvisited := 0; - status := navquery.moveAlongSurface(m_path[0], @m_pos, npos, filter, - @reslt, @visited, @nvisited, MAX_VISITED); + status := navquery.moveAlongSurface(m_path[0], @m_pos[0], npos, filter, + @reslt[0], @visited[0], @nvisited, MAX_VISITED); if (dtStatusSucceed(status)) then begin - m_npath := dtMergeCorridorStartMoved(m_path, m_npath, m_maxPath, @visited, nvisited); + m_npath := dtMergeCorridorStartMoved(m_path, m_npath, m_maxPath, @visited[0], nvisited); // Adjust the position to stay on top of the navmesh. h := m_pos[1]; - navquery.getPolyHeight(m_path[0], @reslt, @h); + navquery.getPolyHeight(m_path[0], @reslt[0], @h); reslt[1] := h; - dtVcopy(@m_pos, @reslt); + dtVcopy(@m_pos[0], @reslt[0]); Exit(true); end; Result := false; @@ -609,18 +609,18 @@ function TdtPathCorridor.moveTargetPosition(const npos: PSingle; navquery: TdtNa // Move along navmesh and update new position. nvisited := 0; - status := navquery.moveAlongSurface(m_path[m_npath-1], @m_target, npos, filter, - @reslt, @visited, @nvisited, MAX_VISITED); + status := navquery.moveAlongSurface(m_path[m_npath-1], @m_target[0], npos, filter, + @reslt[0], @visited[0], @nvisited, MAX_VISITED); if (dtStatusSucceed(status)) then begin - m_npath := dtMergeCorridorEndMoved(m_path, m_npath, m_maxPath, @visited, nvisited); + m_npath := dtMergeCorridorEndMoved(m_path, m_npath, m_maxPath, @visited[0], nvisited); // TODO: should we do that? // Adjust the position to stay on top of the navmesh. (* float h := m_target[1]; navquery.getPolyHeight(m_path[m_npath-1], reslt, &h); reslt[1] := h;*) - dtVcopy(@m_target, @reslt); + dtVcopy(@m_target[0], @reslt[0]); Exit(true); end; @@ -639,7 +639,7 @@ procedure TdtPathCorridor.setCorridor(const target: PSingle; const path: PdtPoly Assert(npath > 0); Assert(npath < m_maxPath); - dtVcopy(@m_target, target); + dtVcopy(@m_target[0], target); Move(path^, m_path^, sizeof(TdtPolyRef)*npath); m_npath := npath; end; @@ -648,7 +648,7 @@ function TdtPathCorridor.fixPathStart(safeRef: TdtPolyRef; const safePos: PSingl begin Assert(m_path <> nil); - dtVcopy(@m_pos, safePos); + dtVcopy(@m_pos[0], safePos); if (m_npath < 3) and (m_npath > 0) then begin m_path[2] := m_path[m_npath-1]; @@ -688,7 +688,7 @@ function TdtPathCorridor.trimInvalidPath(safeRef: TdtPolyRef; const safePos: PSi else if (n = 0) then begin // The first polyref is bad, use current safe values. - dtVcopy(@m_pos, safePos); + dtVcopy(@m_pos[0], safePos); m_path[0] := safeRef; m_npath := 1; end @@ -699,8 +699,8 @@ function TdtPathCorridor.trimInvalidPath(safeRef: TdtPolyRef; const safePos: PSi end; // Clamp target pos to last poly - dtVcopy(@tgt, @m_target); - navquery.closestPointOnPolyBoundary(m_path[m_npath-1], @tgt, @m_target); + dtVcopy(@tgt[0], @m_target[0]); + navquery.closestPointOnPolyBoundary(m_path[m_npath-1], @tgt[0], @m_target[0]); Result := true; end; @@ -723,8 +723,8 @@ function TdtPathCorridor.isValid(const maxLookAhead: Integer; navquery: TdtNavMe Result := true; end; -function TdtPathCorridor.getPos(): PSingle; begin Result := @m_pos; end; -function TdtPathCorridor.getTarget(): PSingle; begin Result := @m_target; end; +function TdtPathCorridor.getPos(): PSingle; begin Result := @m_pos[0]; end; +function TdtPathCorridor.getTarget(): PSingle; begin Result := @m_target[0]; end; function TdtPathCorridor.getFirstPoly(): TdtPolyRef; begin if m_npath <> 0 then Result := m_path[0] else Result := 0; end; function TdtPathCorridor.getLastPoly(): TdtPolyRef; begin if m_npath <> 0 then Result := m_path[m_npath-1] else Result := 0; end; function TdtPathCorridor.getPath(): PdtPolyRef; begin Result := m_path; end; diff --git a/RN_DetourPathQueue.pas b/RN_DetourPathQueue.pas index 395c00b..dc9574b 100644 --- a/RN_DetourPathQueue.pas +++ b/RN_DetourPathQueue.pas @@ -170,7 +170,7 @@ procedure TdtPathQueue.update(const maxIters: Integer); // Handle query start. if (q.status = 0) then begin - q.status := m_navquery.initSlicedFindPath(q.startRef, q.endRef, @q.startPos, @q.endPos, q.filter); + q.status := m_navquery.initSlicedFindPath(q.startRef, q.endRef, @q.startPos[0], @q.endPos[0], q.filter); end; // Handle query in progress. if (dtStatusInProgress(q.status)) then @@ -216,9 +216,9 @@ function TdtPathQueue.request(startRef, endRef: TdtPolyRef; q := @m_queue[slot]; q.ref := ref; - dtVcopy(@q.startPos, startPos); + dtVcopy(@q.startPos[0], startPos); q.startRef := startRef; - dtVcopy(@q.endPos, endPos); + dtVcopy(@q.endPos[0], endPos); q.endRef := endRef; q.status := 0; diff --git a/RN_DetourProximityGrid.pas b/RN_DetourProximityGrid.pas index 84433d0..755df06 100644 --- a/RN_DetourProximityGrid.pas +++ b/RN_DetourProximityGrid.pas @@ -226,7 +226,7 @@ function TdtProximityGrid.getItemCountAt(const x, y: Integer): Integer; Result := n; end; -function TdtProximityGrid.getBounds(): PInteger; begin Result := @m_bounds; end; +function TdtProximityGrid.getBounds(): PInteger; begin Result := @m_bounds[0]; end; function TdtProximityGrid.getCellSize(): Single; begin Result := m_cellSize; end; end. diff --git a/RN_InputGeom.pas b/RN_InputGeom.pas index 5c127fe..2b0b80d 100644 --- a/RN_InputGeom.pas +++ b/RN_InputGeom.pas @@ -51,7 +51,7 @@ TInputGeom = class m_offMeshConDirs: array [0..MAX_OFFMESH_CONNECTIONS-1] of Byte; m_offMeshConAreas: array [0..MAX_OFFMESH_CONNECTIONS-1] of Byte; m_offMeshConFlags: array [0..MAX_OFFMESH_CONNECTIONS-1] of Word; - m_offMeshConId: array [0..MAX_OFFMESH_CONNECTIONS-1] of Integer; + m_offMeshConId: array [0..MAX_OFFMESH_CONNECTIONS-1] of Cardinal; m_offMeshConCount: Integer; ///@} @@ -109,32 +109,32 @@ implementation function intersectSegmentTriangle(sp, sq, a, b, c: PSingle; t: PSingle): Boolean; var v,w,d: Single; ab,ac,qp,ap,norm,e: array [0..2] of Single; begin - rcVsub(@ab, b, a); - rcVsub(@ac, c, a); - rcVsub(@qp, sp, sq); + rcVsub(@ab[0], b, a); + rcVsub(@ac[0], c, a); + rcVsub(@qp[0], sp, sq); // Compute triangle normal. Can be precalculated or cached if // intersecting multiple segments against the same triangle - rcVcross(@norm, @ab, @ac); + rcVcross(@norm[0], @ab[0], @ac[0]); // Compute denominator d. If d <= 0, segment is parallel to or points // away from triangle, so exit early - d := rcVdot(@qp, @norm); + d := rcVdot(@qp[0], @norm[0]); if (d <= 0.0) then Exit(false); // Compute intersection t value of pq with plane of triangle. A ray // intersects iff 0 <= t. Segment intersects iff 0 <= t <= 1. Delay // dividing by d until intersection has been found to pierce triangle - rcVsub(@ap, sp, a); - t^ := rcVdot(@ap, @norm); + rcVsub(@ap[0], sp, a); + t^ := rcVdot(@ap[0], @norm[0]); if (t^ < 0.0) then Exit(false); if (t^ > d) then Exit(false); // For segment; exclude this code line for a ray test // Compute barycentric coordinate components and test if within bounds - rcVcross(@e, @qp, @ap); - v := rcVdot(@ac, @e); + rcVcross(@e[0], @qp[0], @ap[0]); + v := rcVdot(@ac[0], @e[0]); if (v < 0.0) or (v > d) then Exit(false); - w := -rcVdot(@ab, @e); + w := -rcVdot(@ab[0], @e[0]); if (w < 0.0) or (v + w > d) then Exit(false); // Segment/ray intersects triangle. Perform delayed division @@ -184,42 +184,42 @@ destructor TInputGeom.Destroy; function TInputGeom.getMeshBoundsMax: PSingle; begin - Result := @m_meshBMax; + Result := @m_meshBMax[0]; end; function TInputGeom.getMeshBoundsMin: PSingle; begin - Result := @m_meshBMin; + Result := @m_meshBMin[0]; end; function TInputGeom.getOffMeshConnectionAreas: PByte; begin - Result := @m_offMeshConAreas; + Result := @m_offMeshConAreas[0]; end; function TInputGeom.getOffMeshConnectionDirs: PByte; begin - Result := @m_offMeshConDirs; + Result := @m_offMeshConDirs[0]; end; function TInputGeom.getOffMeshConnectionFlags: PWord; begin - Result := @m_offMeshConFlags; + Result := @m_offMeshConFlags[0]; end; function TInputGeom.getOffMeshConnectionId: PCardinal; begin - Result := @m_offMeshConId; + Result := @m_offMeshConId[0]; end; function TInputGeom.getOffMeshConnectionRads: PSingle; begin - Result := @m_offMeshConRads; + Result := @m_offMeshConRads[0]; end; function TInputGeom.getOffMeshConnectionVerts: PSingle; begin - Result := @m_offMeshConVerts; + Result := @m_offMeshConVerts[0]; end; function TInputGeom.loadMesh(ctx: TrcContext; const filepath: string): Boolean; @@ -414,18 +414,18 @@ function TInputGeom.raycastMesh(src, dst: PSingle; tmin: PSingle): Boolean; var dir: array [0..2] of Single; p,q: array [0..1] of Single; btmin,btmax,t: Single; hit: Boolean; ncid: Integer; verts: PSingle; cid: array [0..511] of Integer; tris: PInteger; i,j,ntris: Integer; node: PrcChunkyTriMeshNode; begin - rcVsub(@dir, dst, src); + rcVsub(@dir[0], dst, src); // Prune hit ray. - if (not isectSegAABB(src, dst, @m_meshBMin, @m_meshBMax, @btmin, @btmax)) then Exit(false); + if (not isectSegAABB(src, dst, @m_meshBMin[0], @m_meshBMax[0], @btmin, @btmax)) then Exit(false); p[0] := src[0] + (dst[0]-src[0])*btmin; p[1] := src[2] + (dst[2]-src[2])*btmin; q[0] := src[0] + (dst[0]-src[0])*btmax; q[1] := src[2] + (dst[2]-src[2])*btmax; - ncid := rcGetChunksOverlappingSegment(@m_chunkyMesh, @p, @q, @cid, 512); + ncid := rcGetChunksOverlappingSegment(@m_chunkyMesh, @p[0], @q[0], @cid[0], 512); if (ncid = 0) then Exit(false); diff --git a/RN_NavMeshPruneTool.pas b/RN_NavMeshPruneTool.pas index 8843b94..6050b6f 100644 --- a/RN_NavMeshPruneTool.pas +++ b/RN_NavMeshPruneTool.pas @@ -339,7 +339,7 @@ procedure TNavMeshPruneTool.handleClick(s,p: PSingle; shift: Boolean); query := m_sample.getNavMeshQuery; if (query = nil) then Exit; - dtVcopy(@m_hitPos, p); + dtVcopy(@m_hitPos[0], p); m_hitPosSet := true; if (m_flags = nil) then @@ -352,7 +352,7 @@ procedure TNavMeshPruneTool.handleClick(s,p: PSingle; shift: Boolean); // Delphi: Assume C++ invokes constructor filter := TdtQueryFilter.Create; ref := 0; - query.findNearestPoly(p, @ext, filter, @ref, nil); + query.findNearestPoly(p, @ext[0], filter, @ref, nil); floodNavmesh(nav, m_flags, ref, 1); diff --git a/RN_Recast.pas b/RN_Recast.pas index 738e549..38c5005 100644 --- a/RN_Recast.pas +++ b/RN_Recast.pas @@ -667,8 +667,8 @@ function rcCreateHeightfield(ctx: TrcContext; var hf: TrcHeightfield; width, hei hf.width := width; hf.height := height; - rcVcopy(@hf.bmin, bmin); - rcVcopy(@hf.bmax, bmax); + rcVcopy(@hf.bmin[0], bmin); + rcVcopy(@hf.bmax[0], bmax); hf.cs := cs; hf.ch := ch; SetLength(hf.spans, hf.width * hf.height); @@ -679,9 +679,9 @@ function rcCreateHeightfield(ctx: TrcContext; var hf: TrcHeightfield; width, hei procedure calcTriNormal(const v0, v1, v2: PSingle; norm: PSingle); var e0, e1: array [0..2] of Single; begin - rcVsub(@e0, v1, v0); - rcVsub(@e1, v2, v0); - rcVcross(norm, @e0, @e1); + rcVsub(@e0[0], v1, v0); + rcVsub(@e1[0], v2, v0); + rcVcross(norm, @e0[0], @e1[0]); rcVnormalize(norm); end; @@ -704,7 +704,7 @@ procedure rcMarkWalkableTriangles(ctx: TrcContext; const walkableSlopeAngle: Sin for i := 0 to nt - 1 do begin tri := @tris[i*3]; - calcTriNormal(@verts[tri[0]*3], @verts[tri[1]*3], @verts[tri[2]*3], @norm); + calcTriNormal(@verts[tri[0]*3], @verts[tri[1]*3], @verts[tri[2]*3], @norm[0]); // Check if the face is walkable. if (norm[1] > walkableThr) then areas[i] := RC_WALKABLE_AREA; @@ -793,8 +793,8 @@ function rcBuildCompactHeightfield(ctx: TrcContext; const walkableHeight, walkab chf.walkableHeight := walkableHeight; chf.walkableClimb := walkableClimb; chf.maxRegions := 0; - rcVcopy(@chf.bmin, @hf.bmin); - rcVcopy(@chf.bmax, @hf.bmax); + rcVcopy(@chf.bmin[0], @hf.bmin[0]); + rcVcopy(@chf.bmax[0], @hf.bmax[0]); chf.bmax[1] := chf.bmax[1] + walkableHeight*hf.ch; chf.cs := hf.cs; chf.ch := hf.ch;