Skip to content

v2.7.0 - Hook System for Pathfinding Lifecycle Events

Choose a tag to compare

@apotema apotema released this 25 Dec 21:22
· 19 commits to main since this release

What's New

Hook System

A comptime-based, zero-overhead hook system for observing pathfinding lifecycle events.

Algorithm Hooks (A*, Floyd-Warshall):

  • path_requested - When pathfinding is initiated
  • path_found - When a valid path is discovered
  • no_path_found - When no path exists between nodes
  • node_visited - When a node is visited during search (for debugging/visualization)
  • search_complete - When the search algorithm finishes

Stair/Movement Hooks (PathfindingEngine):

  • stair_enter - When an entity enters a stair
  • stair_exit - When an entity exits a stair
  • stair_wait - When an entity starts waiting for a stair (blocked by traffic)

Usage Example

const MyHooks = struct {
    pub fn path_found(payload: pathfinding.hooks.HookPayload) void {
        const info = payload.path_found;
        std.log.info("Path found! Cost: {d}", .{info.cost});
    }
};

const Dispatcher = pathfinding.hooks.HookDispatcher(MyHooks);
var astar = pathfinding.AStarWithHooks(Dispatcher).init(allocator);

Other Changes

  • MergePathfindingHooks for combining multiple hook handlers
  • EmptyDispatcher as default when no hooks are needed
  • Hooks emit entity IDs (not internal indices) when using mapping methods