File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,6 +43,29 @@ using Vector3i = Vector3<int32_t>;
4343using Vector3u = Vector3<uint32_t >;
4444using Vector3f = Vector3<float >;
4545
46+ template <class T >
47+ struct Vector2Hash
48+ {
49+ static_assert (std::is_fundamental_v<T>, " Vector2Hash only works with fundamental types !" );
50+
51+ inline std::size_t operator ()(fge::Vector2<T> const & value) const
52+ {
53+ if constexpr (std::is_fundamental_v<T>)
54+ {
55+ return std::hash<T>{}(value.x ) ^ std::hash<T>{}(value.y );
56+ }
57+ else
58+ {
59+ static_assert (false , " Vector2Hash only works with fundamental types !" );
60+ }
61+ }
62+ };
63+
64+ using Vector2iHash = Vector2Hash<int32_t >;
65+ using Vector2uHash = Vector2Hash<uint32_t >;
66+ using Vector2fHash = Vector2Hash<float >;
67+ using Vector2sizeHash = Vector2Hash<std::size_t >;
68+
4669} // namespace fge
4770
4871namespace glm
Original file line number Diff line number Diff line change @@ -39,17 +39,7 @@ namespace fge::AStar
3939using HeuristicFunction = unsigned int (*)(fge::Vector2i, fge::Vector2i);
4040using CoordinateList = std::vector<fge::Vector2i>;
4141
42- struct Vector2iHash
43- {
44- static_assert (sizeof (fge::Vector2i) == 8 , " bad fge::Vector2i size, should be 8 !" );
45-
46- inline std::size_t operator ()(fge::Vector2i const & coord) const
47- {
48- return std::hash<uint64_t >()(*reinterpret_cast <uint64_t const *>(&coord));
49- }
50- };
51-
52- using CoordinateSet = std::unordered_set<fge::Vector2i, fge::AStar::Vector2iHash>;
42+ using CoordinateSet = std::unordered_set<fge::Vector2i, fge::Vector2iHash>;
5343
5444struct FGE_API Node
5545{
@@ -61,7 +51,7 @@ struct FGE_API Node
6151 std::optional<fge::Vector2i> _parent;
6252};
6353
64- using NodeMap = std::unordered_map<fge::Vector2i, fge::AStar::Node, fge::AStar:: Vector2iHash>;
54+ using NodeMap = std::unordered_map<fge::Vector2i, fge::AStar::Node, fge::Vector2iHash>;
6555
6656class FGE_API Generator
6757{
You can’t perform that action at this time.
0 commit comments