From 66fae0f16077937cc50fe29a94d14fc915d34ad0 Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <joseph@walton-rivers.uk> Date: Sun, 4 Sep 2022 17:43:18 +0100 Subject: [PATCH] don't use = for lamdas --- demo/demo/grid.cpp | 21 +++++++++------------ demo/demo/robot/programmer.cpp | 4 ++-- demo/include/robot/programmer.hpp | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/demo/demo/grid.cpp b/demo/demo/grid.cpp index 53794f3..9f373c5 100644 --- a/demo/demo/grid.cpp +++ b/demo/demo/grid.cpp @@ -112,10 +112,10 @@ namespace demo { auto btnGrid = std::make_unique<fggl::gui::GridBox>(0, 2); std::array<Action, 4> actions{{ - {"<", [=]() { this->rotate(true); }}, - {">", [=]() { this->rotate(false); }}, - {"^", [=]() { this->forward(); }}, - {"Z", [=]() { } } + {"<", [this]() { this->rotate(true); }}, + {">", [this]() { this->rotate(false); }}, + {"^", [this]() { this->forward(); }}, + {"Z", [this]() { } } }}; fggl::math::vec2i pos{0, 0}; @@ -134,7 +134,7 @@ namespace demo { fggl::math::vec2i size{64, 32}; auto btn = std::make_unique<fggl::gui::Button>(pos, size); btn->label("go"); - btn->addCallback([=](){ + btn->addCallback([this](){ if ( !this->m_program.playing ) { resetPuzzle(); this->m_program.m_currInstruction = 0; @@ -148,7 +148,7 @@ namespace demo { fggl::math::vec2i size{64, 64}; auto btn = std::make_unique<fggl::gui::Button>(pos, size); btn->label("Del"); - btn->addCallback([=](){ + btn->addCallback([this](){ if ( !this->m_program.playing ) { if ( !m_program.m_instructions.empty() ) { m_program.m_instructions.pop_back(); @@ -292,19 +292,16 @@ namespace demo { } robotState.power--; - m_program.m_instructions[ m_program.m_currInstruction ].m_func(); - m_program.m_currInstruction++; + m_program.step(); } else { - m_program.playing = false; - m_program.m_currInstruction = 0; + m_program.stop(); checkVictory(); } } void GridScene::resetPuzzle() { // reset instruction panel - m_program.playing = false; - m_program.m_currInstruction = 0; + m_program.stop(); // reset robot state auto& robotPos = m_grid->entities().get<CellPos>(m_player); diff --git a/demo/demo/robot/programmer.cpp b/demo/demo/robot/programmer.cpp index 6bdadcd..5d3a1e5 100644 --- a/demo/demo/robot/programmer.cpp +++ b/demo/demo/robot/programmer.cpp @@ -30,7 +30,7 @@ namespace demo::robot { float trackHeight = m_tracks.size() * 32.0F; std::size_t widestTrack = 0; for ( auto& track : m_tracks ) { - widestTrack = std::max(widestTrack, track.get().m_instructions.size()); + widestTrack = std::max(widestTrack, track.get().size()); } float instructionWidth = 32 * widestTrack; @@ -52,7 +52,7 @@ namespace demo::robot { for ( auto track=0U; track < m_tracks.size(); ++track) { auto& trackRef = m_tracks[track].get(); - for (auto i = 0U; i < trackRef.m_instructions.size(); ++i) { + for (auto i = 0U; i < trackRef.size(); ++i) { auto barCenter = this->topLeft(); barCenter.x += (i * (barExtents.x * 2) ) + barExtents.x; diff --git a/demo/include/robot/programmer.hpp b/demo/include/robot/programmer.hpp index 1025c18..628dd9a 100644 --- a/demo/include/robot/programmer.hpp +++ b/demo/include/robot/programmer.hpp @@ -34,6 +34,20 @@ namespace demo::robot { std::vector<Instruction> m_instructions; uint32_t m_currInstruction; bool playing = false; + + inline std::size_t size() { + return m_instructions.size(); + } + + inline void step() { + m_instructions[ m_currInstruction ].m_func(); + m_currInstruction++; + } + + inline void stop() { + playing = false; + m_currInstruction = 0; + } }; class Timeline : public fggl::gui::Panel { -- GitLab