Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
David Arutiunian committed Dec 22, 2017
1 parent 1a9b5b2 commit 78b8ab3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Doodler.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ class Doodler : public IEntity
sf::Vector2f m_position = sf::Vector2f(WINDOW_WIDTH / 2, m_floor - m_size.x / 2 - m_outlineThickness);
sf::RectangleShape m_shape;

const Lambda<bool(float, float)> m_areCloseAbsolute = [&](float lhs, float rhs) -> bool {
const std::function<bool(float, float)> m_areCloseAbsolute = [&](float lhs, float rhs) -> bool {
constexpr float tolerance = 0.001f;
return std::abs(lhs - rhs) < tolerance;
};

const Lambda<bool(float, float)> m_areCloseRelative = [&](float lhs, float rhs) -> bool {
const std::function<bool(float, float)> m_areCloseRelative = [&](float lhs, float rhs) -> bool {
constexpr float tolerance = 0.001f;
return std::abs((lhs - rhs) / rhs) < tolerance;
};

const Lambda<bool(float, float)> m_areFuzzyEqual = [&](float lhs, float rhs) -> bool {
const std::function<bool(float, float)> m_areFuzzyEqual = [&](float lhs, float rhs) -> bool {
if (std::abs(rhs) > 1.f)
{
return m_areCloseRelative(lhs, rhs);
Expand All @@ -68,7 +68,7 @@ class Doodler : public IEntity

void setNextY();

sf::FloatRect getBounds() const;
sf::FloatRect getBounds() const override;

float getNextY() const;
};
Expand Down
4 changes: 2 additions & 2 deletions Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class Engine
bool m_shouldSetFloor = false;
float m_floor = WINDOW_HEIGHT;

const Lambda<bool(const std::shared_ptr<IEntity> &)> m_isDoodler = [&](
const std::function<bool(const std::shared_ptr<IEntity> &)> m_isDoodler = [&](
const std::shared_ptr<IEntity> &p_entity) -> bool {
return p_entity->getType() == Types::Doodler;
};

const Lambda<void(const std::shared_ptr<IEntity> &)> m_applyForEach = [&](
const std::function<void(const std::shared_ptr<IEntity> &)> m_applyForEach = [&](
const std::shared_ptr<IEntity> &p_entity) -> void {
if (m_p_doodler == nullptr || m_isDoodler(p_entity))
{
Expand Down
2 changes: 1 addition & 1 deletion Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Platform : public IEntity

void draw(sf::RenderTarget &target, sf::RenderStates states) const override;

sf::FloatRect getBounds() const;
sf::FloatRect getBounds() const override;
};

#endif //DOODLE_JUMP_PLATFORM_H
3 changes: 0 additions & 3 deletions consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ static const float MOVE_SPEED = 500.f;
static const size_t PLATFORM_COUNT = 30;
static const unsigned MAX_PRECISION_COUNT = 128;

template<typename Signature>
using Lambda = std::function<Signature>;

enum class Types : size_t
{
Platform = 0,
Expand Down

0 comments on commit 78b8ab3

Please sign in to comment.