diff --git a/src/entity.cpp b/src/entity.cpp index 8aa0c87..919daf8 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -124,7 +124,9 @@ void entity::draw() const noexcept { _props.angle, _props.reflection, _props.alpha, +#ifdef HITBOX debug +#endif ); } @@ -136,6 +138,10 @@ void entity::set_placement(int32_t x, int32_t y) noexcept { _props.position.set(x, y); } +geometry::point entity::get_placement() const noexcept { + return _props.position; +} + void entity::set_onupdate(const std::function)> &fn) noexcept { _onupdate = std::move(fn); } @@ -187,8 +193,22 @@ bool entity::visible() const noexcept { } bool entity::intersects(const std::shared_ptr &other) const noexcept { - const auto &hitbox = _props.animations.at(_props.action).hitbox; - const auto &other_hitbox = other->_props.animations.at(_props.action).hitbox; + if (_props.action.empty() || other->_props.action.empty()) [[unlikely]] { + return false; + } + + const auto sit = _props.animations.find(_props.action); + if (sit == _props.animations.end()) [[unlikely]] { + return false; + } + + const auto oit = other->_props.animations.find(other->_props.action); + if (oit == other->_props.animations.end()) [[unlikely]] { + return false; + } + + const auto &hitbox = sit->second.hitbox; + const auto &other_hitbox = oit->second.hitbox; if (!hitbox || !other_hitbox) [[likely]] { return false; } diff --git a/src/entity.hpp b/src/entity.hpp index b55e835..63bbb8e 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -34,6 +34,7 @@ class entity : public std::enable_shared_from_this { algebra::vector2d velocity() const noexcept; void set_placement(int32_t x, int32_t y) noexcept; + geometry::point get_placement() const noexcept; void set_onupdate(const std::function)> &fn) noexcept; void set_onanimationfinished(const std::function)> &fn) noexcept; diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp index fd73ff6..e12fe9d 100644 --- a/src/eventmanager.cpp +++ b/src/eventmanager.cpp @@ -4,14 +4,14 @@ using namespace input; eventmanager::eventmanager() { - const auto number = SDL_NumJoysticks(); - for (auto id = 0; id < number; ++id) { - if (SDL_IsGameController(id)) { - if (auto controller = SDL_GameControllerOpen(id)) { - _controllers.emplace(SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller)), gamecontroller_ptr(controller)); - } - } - } + // const auto number = SDL_NumJoysticks(); + // for (auto id = 0; id < number; ++id) { + // if (SDL_IsGameController(id)) { + // if (auto controller = SDL_GameControllerOpen(id)) { + // _controllers.emplace(SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller)), gamecontroller_ptr(controller)); + // } + // } + // } } void eventmanager::update(float_t delta) { diff --git a/src/scriptengine.cpp b/src/scriptengine.cpp index 785c737..668b4e2 100644 --- a/src/scriptengine.cpp +++ b/src/scriptengine.cpp @@ -211,14 +211,19 @@ void framework::scriptengine::run() { struct placementproxy { entity &e; - void set(int32_t x, int32_t y) { + void set(int32_t x, int32_t y) noexcept { e.set_placement(x, y); } + + geometry::point get() const noexcept { + return e.get_placement(); + } }; lua.new_usertype( "PlacementProxy", - "set", &placementproxy::set + "set", &placementproxy::set, + "get", &placementproxy::get ); struct velocityproxy {