Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
skhaz committed Jan 5, 2025
1 parent e490f28 commit 844396c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
24 changes: 22 additions & 2 deletions src/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ void entity::draw() const noexcept {
_props.angle,
_props.reflection,
_props.alpha,
#ifdef HITBOX
debug
#endif
);
}

Expand All @@ -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<void(std::shared_ptr<entity>)> &fn) noexcept {
_onupdate = std::move(fn);
}
Expand Down Expand Up @@ -187,8 +193,22 @@ bool entity::visible() const noexcept {
}

bool entity::intersects(const std::shared_ptr<entity> &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;
}
Expand Down
1 change: 1 addition & 0 deletions src/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class entity : public std::enable_shared_from_this<entity> {
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<void(std::shared_ptr<entity>)> &fn) noexcept;
void set_onanimationfinished(const std::function<void(std::shared_ptr<entity>)> &fn) noexcept;
Expand Down
16 changes: 8 additions & 8 deletions src/eventmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/scriptengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
"PlacementProxy",
"set", &placementproxy::set
"set", &placementproxy::set,
"get", &placementproxy::get
);

struct velocityproxy {
Expand Down

0 comments on commit 844396c

Please sign in to comment.