Skip to content

Commit

Permalink
clean up pathfinding docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Herringway committed Sep 15, 2024
1 parent 69dfdc8 commit af2fecb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion source/earthbound/bank00.d
Original file line number Diff line number Diff line change
Expand Up @@ -9110,7 +9110,7 @@ short unknownC0BA35(PathCtx* pathState, short targets, short baseX, short baseY,
pathfinders++;
}
pathState.patherCount = pathfinders;
ushort x28 = pathMain(0xC00, &pathfindingBuffer[0], &pathState.radius, &buffer[0x3000], 4, targets, &pathState.targetsPos[0], pathfinders, &pathState.pathers[0], -1, arg6, arg7);
ushort x28 = pathMain(0xC00, &pathfindingBuffer[0], &pathState.radius, &buffer[0x3000], 4, targets, &pathState.targetsPos[0], pathfinders, &pathState.pathers[0], 0xFFFF, arg6, arg7);
assert(pathGetHeapSize() <= 0xC00);
if (x28 == 0) {
for (short i = 0; i != maxEntities; i++) {
Expand Down
38 changes: 18 additions & 20 deletions source/earthbound/bank04.d
Original file line number Diff line number Diff line change
Expand Up @@ -7623,42 +7623,42 @@ ushort pathGetHeapSize() {

/** Finds a path from pathers to targets
* Params:
* heap_size = Size of the heap used for allocation of various temporary arrays/structs
* heap_start = Pointer to the start of the heap
* matrix_dim = Pointer to a VecYX struct containing the pathfinding matrix dimensions
* heapSize = Size of the heap used for allocation of various temporary arrays/structs
* heapStart = Pointer to the start of the heap
* matrixDimensions = Pointer to a VecYX struct containing the pathfinding matrix dimensions
* matrix = pointer to the pathfinding matrix
* border_size = Size of the border used for the start positions of deliverymen
* borderSize = Size of the border used for the start positions of offscreen targets
* targetCount = Amount of VecYX elements in the `targetsPos` array
* targetsPos = Array of VecYX containing the positions of the targets
* patherCount = Amount of Pather elements in the `pathers` array
* pathers = Array of Pather for the pathfinding objects
* unk1 = Unknown (-1 as called from unknownC0BA35)
* maxIterations = Maximum number of painting iterations, for setting an upper bound on execution time
* maxPoints = maximum number of points to generate in matrix
* search_radius = Just a guess...
* Returns: unknown
* radius = Distance from the center of the pathfinding matrix to the edge
* Returns: Number of paths found
* Original_Address: $(DOLLAR)C4B59F
**/
ushort pathMain(ushort heap_size, void* heap_start, VecYX* matrix_dim, ubyte* matrix, ushort border_size, ushort targetCount, VecYX* targetsPos, ushort patherCount, Pather* pathers, short unk1, ushort maxPoints, ushort search_radius) {
ushort pathMain(ushort heapSize, void* heapStart, VecYX* matrixDimensions, ubyte* matrix, ushort borderSize, ushort targetCount, VecYX* targetsPos, ushort patherCount, Pather* pathers, ushort maxIterations, ushort maxPoints, ushort radius) {
debug(pathing) {
import std.stdio;
writeln(heap_size, ", ", *matrix_dim, ", ", border_size, ", ", targetCount, ", ", *targetsPos, ", ", patherCount, ", ", *pathers, ", ", unk1, ", ", maxPoints, ", ", search_radius);
writeln(heapSize, ", ", *matrixDimensions, ", ", borderSize, ", ", targetCount, ", ", *targetsPos, ", ", patherCount, ", ", *pathers, ", ", maxIterations, ", ", maxPoints, ", ", radius);
}
ushort successes = 0;

pathHeapStart = heap_start;
pathHeapCurrent = heap_start;
pathHeapEnd = cast(byte*)heap_start + heap_size;
pathHeapStart = heapStart;
pathHeapCurrent = heapStart;
pathHeapEnd = cast(byte*)heapStart + heapSize;

pathMatrixRows = matrix_dim.y;
pathMatrixColumns = matrix_dim.x;
pathMatrixBorder = border_size;
pathMatrixRows = matrixDimensions.y;
pathMatrixColumns = matrixDimensions.x;
pathMatrixBorder = borderSize;
pathMatrixSize = cast(ushort)(pathMatrixRows * pathMatrixColumns);
pathMatrixBuffer = matrix;

// allocates n + 1 offsets to work around a bug in matrix painting
ushort* offsetBuffer = cast(ushort*)pathSbrk((search_radius + 1) * ushort.sizeof);
ushort* offsetBuffer = cast(ushort*)pathSbrk((radius + 1) * ushort.sizeof);
pathSearchTempStart = offsetBuffer;
pathSearchTempEnd = offsetBuffer + search_radius;
pathSearchTempEnd = offsetBuffer + radius;
pathSearchTempA = offsetBuffer;
pathSearchTempB = offsetBuffer;

Expand Down Expand Up @@ -7725,7 +7725,7 @@ ushort pathMain(ushort heap_size, void* heap_start, VecYX* matrix_dim, ubyte* ma
}

paintPathMatrixPass1(matching, &tempPathers[i]);
paintPathMatrixPass2(targetCount, targetsPos, tempPather, matching, maxPoints, unk1);
paintPathMatrixPass2(targetCount, targetsPos, tempPather, matching, maxPoints, maxIterations);
}

tempPather.initialPointCount = pathBuildPathPoints(&tempPather.origin, maxPoints, points);
Expand All @@ -7747,8 +7747,6 @@ ushort pathMain(ushort heap_size, void* heap_start, VecYX* matrix_dim, ubyte* ma
++successes;
}
}
debug(pathing) printPathMatrix();

return successes;
}

Expand Down

0 comments on commit af2fecb

Please sign in to comment.