Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
graph.h
Go to the documentation of this file.
1#pragma once
2
3#include <cfloat>
4#include <functional>
5
14template <typename T>
15struct GraphEdge {
16 std::reference_wrapper<T> target;
17 std::reference_wrapper<T> source;
18 float cost;
19};
20
30 int x, y;
31
32 bool operator==(const GraphPosition& other) const noexcept {
33 return x == other.x && y == other.y;
34 }
35};
36
42 size_t operator()(const GraphPosition& p) const noexcept {
43 return (std::hash<int>()(p.x) << 1) ^ std::hash<int>()(p.y);
44 }
45};
46
59struct NodeRecord {
61 float cost_from_start = FLT_MAX;
62 float heuristic = 0.f;
64 bool has_parent = false;
65
66 float total_cost() const noexcept { return cost_from_start + heuristic; }
67};
Structure representing an edge in the navigation graph.
Definition graph.h:15
float cost
Definition graph.h:18
std::reference_wrapper< T > source
Definition graph.h:17
std::reference_wrapper< T > target
Definition graph.h:16
Hash function for GraphPosition to be used in unordered containers. Combines the hash values of the x...
Definition graph.h:41
size_t operator()(const GraphPosition &p) const noexcept
Definition graph.h:42
Structure representing a position in the navigation graph.
Definition graph.h:29
int x
Definition graph.h:30
bool operator==(const GraphPosition &other) const noexcept
Definition graph.h:32
int y
Definition graph.h:30
Record structure used in A* pathfinding algorithm.
Definition graph.h:59
float cost_from_start
Definition graph.h:61
float total_cost() const noexcept
Definition graph.h:66
GraphPosition parent
Definition graph.h:63
float heuristic
Definition graph.h:62
bool has_parent
Definition graph.h:64
GraphPosition pos
Definition graph.h:60