|
Capycore Engine
0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
|
Component representing a navigation graph for AI pathfinding. More...
#include <navigation_graph.h>
Public Member Functions | |
| NavigationGraph (int grid_size=16, int stride=10) | |
| void | update (float dt) override |
| Update is left empty as the navigation graph does not require per-frame updates. | |
| NavigationGraph & | generate_graph () |
| Generates the navigation graph by populating it with nodes. | |
| NavigationGraph & | clear () |
| Clears all nodes from the navigation graph. | |
| std::unordered_map< GraphPosition, std::reference_wrapper< NavigationNode >, GraphPositionHash > & | get_nodes () |
| std::optional< std::reference_wrapper< NavigationNode > > | get_node (const GraphPosition &position) const |
| Retrieves a navigation node at the specified position. | |
| std::optional< GraphPosition > | get_position_of_node (const NavigationNode &node) const |
| GraphPosition | world_to_graph_position (const Vector3 &world_position) const |
| NavigationGraph & | add_node (const GraphPosition &position, NavigationNode &node) |
| Adds a navigation node at the specified position. | |
| NavigationGraph & | remove_node (const GraphPosition &position) |
| Removes a navigation node at the specified position. | |
| std::optional< std::reference_wrapper< NavigationNode > > | get_closest_node (const GraphPosition &position) const |
| Finds the closest navigation node to the specified position. | |
| std::optional< std::reference_wrapper< NavigationNode > > | get_closest_node (const Vector3 &world_position) const |
| int | get_grid_size () const noexcept |
| int | get_grid_max_x () const noexcept |
| int | get_grid_max_y () const noexcept |
| int | get_stride () const noexcept |
| NavigationGraph & | stride (int stride) noexcept |
| int | max_drop_distance () const noexcept |
| NavigationGraph & | max_drop_distance (int distance) noexcept |
| int | max_jump_distance () const noexcept |
| NavigationGraph & | max_jump_distance (int distance) noexcept |
| std::string | type_name () const override |
| Provides a consistent type name for the component. | |
Public Member Functions inherited from Component | |
| Component () | |
| virtual | ~Component ()=default |
| bool | active () const noexcept |
| Checks if the component is active. | |
| Component & | active (bool value) noexcept |
| bool | marked_for_deletion () const noexcept |
| Activates the component. | |
| Component & | mark_for_deletion () noexcept |
| virtual void | on_attach () |
| Called when the component is attached to a GameObject. | |
| virtual void | on_detach () |
| Called when the component is detached from a GameObject. | |
| virtual void | on_serialize (std::vector< uint8_t > &) const |
| Serializes the component's state into a byte array. | |
| virtual void | on_deserialize (const std::vector< uint8_t > &, size_t &) |
| Deserializes the component's state from a byte array. | |
| const std::optional< std::reference_wrapper< GameObject > > & | parent () const noexcept |
| Gets the parent GameObject of this component. | |
| std::optional< std::reference_wrapper< GameObject > > & | parent () noexcept |
| Gets the parent GameObject of this component. | |
| Component & | parent (GameObject &parent) |
| Component & | parent (std::nullopt_t nullopt) |
| size_t | add_on_attach (const std::function< void(Component &)> &action) |
| Retrieves the type information of the component. | |
| void | remove_on_attach (size_t index) |
| size_t | add_on_detach (const std::function< void(Component &)> &action) |
| Adds an action to be performed when the component is attached. | |
| void | remove_on_detach (size_t index) |
Component representing a navigation graph for AI pathfinding.
This component manages a collection of navigation nodes, allowing for the generation, clearing, and querying of the navigation graph.
NOTE: This component should be placed on a GameObject that serves as the parent for all the tiles. NOTHING ELSE should be a child of this GameObject except the tiles, which automatically get assigned navigation nodes as children when generating the graph.
Usage:
| NavigationGraph::NavigationGraph | ( | int | grid_size = 16, |
| int | stride = 10 |
||
| ) |
| NavigationGraph & NavigationGraph::add_node | ( | const GraphPosition & | position, |
| NavigationNode & | node | ||
| ) |
Adds a navigation node at the specified position.
| position | The position to add the navigation node. |
| node | The NavigationNode to add. |
| NavigationGraph & NavigationGraph::clear | ( | ) |
Clears all nodes from the navigation graph.
| NavigationGraph & NavigationGraph::generate_graph | ( | ) |
Generates the navigation graph by populating it with nodes.
Generates nodes based on the children of the parent GameObject and tries to connect them based on the specified node distance.
| std::optional< std::reference_wrapper< NavigationNode > > NavigationGraph::get_closest_node | ( | const GraphPosition & | position | ) | const |
Finds the closest navigation node to the specified position.
| position | The position to find the closest navigation node to. |
| std::optional< std::reference_wrapper< NavigationNode > > NavigationGraph::get_closest_node | ( | const Vector3 & | world_position | ) | const |
|
noexcept |
|
noexcept |
|
noexcept |
| std::optional< std::reference_wrapper< NavigationNode > > NavigationGraph::get_node | ( | const GraphPosition & | position | ) | const |
Retrieves a navigation node at the specified position.
| position | The position to query for a navigation node. |
| std::unordered_map< GraphPosition, std::reference_wrapper< NavigationNode >, GraphPositionHash > & NavigationGraph::get_nodes | ( | ) |
| std::optional< GraphPosition > NavigationGraph::get_position_of_node | ( | const NavigationNode & | node | ) | const |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
| NavigationGraph & NavigationGraph::remove_node | ( | const GraphPosition & | position | ) |
Removes a navigation node at the specified position.
| position | The position of the navigation node to remove. |
|
noexcept |
|
overridevirtual |
Provides a consistent type name for the component.
Implements Component.
|
inlineoverridevirtual |
Update is left empty as the navigation graph does not require per-frame updates.
Implements Component.
| GraphPosition NavigationGraph::world_to_graph_position | ( | const Vector3 & | world_position | ) | const |