libtcod
Loading...
Searching...
No Matches
pathfinder.h
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32#pragma once
33#ifndef TCOD_PATHFINDER_H
34#define TCOD_PATHFINDER_H
35
36#include <stdbool.h>
37#include <stddef.h>
38#include <stdint.h>
39
40#include "heapq.h"
41#include "portability.h"
42
43#define TCOD_PATHFINDER_MAX_DIMENSIONS 4
44
46 int8_t ndim;
47 int int_type;
48 size_t shape[TCOD_PATHFINDER_MAX_DIMENSIONS + 1];
49 size_t strides[TCOD_PATHFINDER_MAX_DIMENSIONS + 1];
50 unsigned char* data;
51};
52
54 struct TCOD_ArrayData cost;
55 int cardinal;
56 int diagonal;
57};
58
60 int8_t ndim;
61 size_t shape[TCOD_PATHFINDER_MAX_DIMENSIONS];
62 bool owns_distance;
63 bool owns_graph;
64 bool owns_traversal;
65 struct TCOD_ArrayData distance;
66 struct TCOD_BasicGraph2D graph;
67 struct TCOD_ArrayData traversal;
68 struct TCOD_Heap heap;
69};
70
71TCODLIB_CAPI struct TCOD_Pathfinder* TCOD_pf_new(int ndim, const size_t* shape);
72TCODLIB_CAPI void TCOD_pf_delete(struct TCOD_Pathfinder* path);
73
74TCODLIB_CAPI void TCOD_pf_set_distance_pointer(
75 struct TCOD_Pathfinder* path, void* data, int int_type, const size_t* strides);
76TCODLIB_CAPI void TCOD_pf_set_graph2d_pointer(
77 struct TCOD_Pathfinder* path, void* data, int int_type, const size_t* strides, int cardinal, int diagonal);
78TCODLIB_CAPI void TCOD_pf_set_traversal_pointer(
79 struct TCOD_Pathfinder* path, void* data, int int_type, const size_t* strides);
80
81TCODLIB_CAPI int TCOD_pf_recompile(struct TCOD_Pathfinder* path);
82TCODLIB_CAPI int TCOD_pf_compute(struct TCOD_Pathfinder* path);
83TCODLIB_CAPI int TCOD_pf_compute_step(struct TCOD_Pathfinder* path);
84
85#endif // TCOD_PATHFINDER_H
Internal heap queue module.
Miscellaneous tools needed across platforms.
Definition pathfinder.h:45
Definition pathfinder.h:53
Definition heapq.h:43
Definition pathfinder.h:59