Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an a* pathfinder #113

Merged
merged 24 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ toml-dep = { version = "0.5.8", package="toml", optional = true }
aho-corasick = { version = "0.7.18", optional = true}
rayon = { version = "1.5", optional = true}
dbpnoise = { version = "0.1.2", optional = true}
pathfinding = { version = "3.0.13", optional = true }
num = { version = "0.4.0", optional = true }

[features]
default = ["acreplace", "cellularnoise", "dmi", "file", "git", "http", "json", "log", "noise", "sql", "time", "toml", "url"]
Expand All @@ -67,6 +69,7 @@ url = ["url-dep", "percent-encoding"]
# additional features
batchnoise = ["dbpnoise"]
hash = ["base64", "const-random", "md-5", "hex", "sha-1", "sha2", "twox-hash", "serde", "serde_json"]
pathfinder = [ "num", "pathfinding", "serde", "serde_json"]
redis_pubsub = ["flume", "redis", "serde", "serde_json"]
unzip = ["zip", "jobs"]
worleynoise = ["rand","rayon"]
Expand Down
32 changes: 32 additions & 0 deletions dmsrc/pathfinder.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Register a list of nodes into a rust library. This list of nodes must have been serialized in a json.
* Node {// Index of this node in the list of nodes
* unique_id: usize,
* // Position of the node in byond
* x: usize,
* y: usize,
* z: usize,
* // Indexes of nodes connected to this one
* connected_nodes_id: Vec<usize>}
* It is important that the node with the unique_id 0 is the first in the json, unique_id 1 right after that, etc.
* It is also important that all unique ids follow. {0, 1, 2, 4} is not a correct list and the registering will fail
* Nodes should not link across z levels.
* A node cannot link twice to the same node and shouldn't link itself either
*/
#define rustg_register_nodes_astar(json) call(RUST_G, "register_nodes_astar")(json)

/**
* Add a new node to the static list of nodes. Same rule as registering_nodes applies.
* This node unique_id must be equal to the current length of the static list of nodes
*/
#define rustg_add_node_astar(json) call(RUST_G, "add_node_astar")(json)

/**²
* Remove every link to the node with unique_id. Replace that node by null
*/
#define rustg_remove_node_astart(unique_id) call(RUST_G, "remove_node_astar")(unique_id)

/**
* Compute the shortest path between start_node and goal_node using A*. Heuristic used is simple geometric distance
*/
#define rustg_generate_path_astar(start_node_id, goal_node_id) call(RUST_G, "generate_path_astar")(start_node_id, goal_node_id)
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub mod json;
pub mod log;
#[cfg(feature = "noise")]
pub mod noise_gen;
#[cfg(feature = "pathfinder")]
pub mod pathfinder;
#[cfg(feature = "redis_pubsub")]
pub mod redis_pubsub;
#[cfg(feature = "sql")]
Expand Down
Loading