Skip to content

Commit

Permalink
Merge pull request #2673 from MatusGuy/raycast-variant
Browse files Browse the repository at this point in the history
RaycastResult uses variant instead of union
  • Loading branch information
Rusty-Box authored Nov 11, 2023
2 parents f89c7fc + 46b133f commit 412ccc9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/collision/collision_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ CollisionSystem::get_first_line_intersection(const Vector& line_start,
if ((tile->get_attributes() & Tile::SOLID))
{
result.is_valid = true;
result.hit.tile = tile;
result.hit = tile;
result.box = {glm::floor((test_vector - solids->get_offset()) / 32.0f), Sizef(32.f, 32.f)};
return result;
}
Expand All @@ -769,7 +769,7 @@ CollisionSystem::get_first_line_intersection(const Vector& line_start,
if (intersects_line(object->get_bbox(), line_start, line_end))
{
result.is_valid = true;
result.hit.object = object;
result.hit = object;
result.box = object->get_bbox();
return result;
}
Expand Down
7 changes: 2 additions & 5 deletions src/collision/collision_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <vector>
#include <memory>
#include <variant>
#include <stdint.h>

#include "collision/collision.hpp"
Expand All @@ -38,11 +39,7 @@ class CollisionSystem final
struct RaycastResult
{
bool is_valid; /**< true if raycast hit something */
union
{
const CollisionObject* object;
const Tile* tile;
} hit; /**< tile/object that the raycast hit */
std::variant<const Tile*, CollisionObject*> hit; /**< tile/object that the raycast hit */
Rectf box = {}; /**< hitbox of tile/object */
};

Expand Down

0 comments on commit 412ccc9

Please sign in to comment.