From d6818bbd2f61bf68e5f948b75dcfbb593cf40521 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Tue, 18 Oct 2022 06:59:51 +0400 Subject: [PATCH] refactor(codestyle): Add clang-format and re-format all existing files --- .clang-format | 18 +++ include/core/area.h | 14 +- include/core/bpmsection.h | 4 +- include/core/color.h | 2 +- include/core/corefactory.h | 15 +- include/core/editor.h | 53 ++++--- include/core/editorcallback.h | 5 +- include/core/functional.h | 2 +- include/core/game.h | 8 +- include/core/gameevent.h | 2 +- include/core/line.h | 10 +- include/core/music.h | 10 +- include/core/note.h | 29 ++-- include/core/point.h | 18 +-- include/core/precisionevaluator.h | 27 ++-- include/core/rectangle.h | 14 +- include/core/resourceholder.h | 39 +++-- include/core/sprite.h | 11 +- include/core/spritecontainer.h | 30 ++-- include/core/systemevent.h | 11 +- include/core/text.h | 14 +- include/core/time.h | 13 +- include/core/timeline.h | 81 +++++----- include/core/updatedata.h | 4 +- include/core/vector.h | 7 +- src/application/include/application/about.h | 19 ++- .../include/application/editorstate.h | 23 +-- .../include/application/gamestate.h | 21 ++- .../include/application/mainmenu.h | 13 +- src/application/include/application/state.h | 14 +- .../shared/application/application.h | 12 +- src/application/shared/application/log.h | 31 ++-- src/application/src/about.cpp | 29 ++-- src/application/src/application.cpp | 35 +++-- src/application/src/editorstate.cpp | 141 ++++++++++-------- src/application/src/gamestate.cpp | 13 +- src/application/src/log.cpp | 5 +- src/application/src/mainmenu.cpp | 39 ++--- .../src/widgets/bpmcalculatorwidget.cpp | 68 +++++---- src/application/src/widgets/bpmslider.cpp | 23 ++- src/application/src/widgets/button.cpp | 21 +-- .../src/widgets/cascademenubutton.cpp | 22 +-- src/application/src/widgets/editorwidget.cpp | 23 +-- src/application/src/widgets/group.cpp | 21 +-- src/application/src/widgets/menubar.cpp | 61 ++++---- src/application/src/widgets/menudrop.cpp | 53 ++++--- src/application/src/widgets/menuseparator.cpp | 12 +- src/application/src/widgets/pushbutton.cpp | 17 ++- src/application/src/widgets/widget.cpp | 20 +-- src/application/src/widgets/window.cpp | 32 ++-- src/impl/sfml/application/applicationsfml.cpp | 10 +- src/impl/sfml/application/applicationsfml.h | 8 +- .../sfml/application/inputconvertersfml.h | 116 ++++---------- src/impl/sfml/corefactorysfml.cpp | 35 +++-- src/impl/sfml/corefactorysfml.h | 13 +- src/impl/sfml/linesfml.cpp | 8 +- src/impl/sfml/linesfml.h | 13 +- src/impl/sfml/musicsfml.cpp | 19 ++- src/impl/sfml/musicsfml.h | 10 +- src/impl/sfml/rectanglesfml.cpp | 21 +-- src/impl/sfml/rectanglesfml.h | 20 +-- src/impl/sfml/spritesfml.cpp | 26 ++-- src/impl/sfml/spritesfml.h | 15 +- src/impl/sfml/textsfml.cpp | 17 ++- src/impl/sfml/textsfml.h | 20 +-- src/main.cpp | 6 +- src/modes/classicmode/classicfactory.cpp | 37 +++-- src/modes/classicmode/classicnote.cpp | 9 +- .../editor/callbacks/callbacksimple.cpp | 10 +- .../classicmode/editor/classiceditor.cpp | 66 ++++---- .../classicmode/editor/editorcontext.cpp | 95 ++++++------ .../classicmode/game/classicarrownote.cpp | 46 +++--- src/modes/classicmode/game/classicgame.cpp | 29 ++-- .../classicmode/game/classicmapcreator.cpp | 27 ++-- src/modes/classicmode/game/gamecontext.cpp | 79 +++++----- src/modes/classicmode/game/holdmanager.cpp | 10 +- .../classicdyinganimationscenario.cpp | 11 +- .../classicflyinganimationscenario.cpp | 12 +- .../graphics/classicgraphicsfactory.cpp | 24 ++- .../graphics/classicnotegraphics.cpp | 12 +- .../graphics/classicscenegraphicsmanager.cpp | 96 ++++++------ .../graphics/classicselectiongraphics.cpp | 9 +- .../classictimelinegraphicsmanager.cpp | 78 +++++----- src/tools/src/beatutils.cpp | 16 +- src/tools/src/bpmcalculator.cpp | 10 +- 85 files changed, 1133 insertions(+), 1109 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..fe154f0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,18 @@ +IndentWidth: 4 +BreakBeforeBraces: Allman +AlignAfterOpenBracket: Align +AlignArrayOfStructures: Right +AllowShortBlocksOnASingleLine: Empty +AllowShortFunctionsOnASingleLine: None +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: true \ No newline at end of file diff --git a/include/core/area.h b/include/core/area.h index 2a79a90..47cc870 100644 --- a/include/core/area.h +++ b/include/core/area.h @@ -27,20 +27,22 @@ struct Area inline kku::Point position() const noexcept { - return kku::Point{static_cast(left), - static_cast(top) }; + return kku::Point{ + static_cast(left), + static_cast(top), + }; } - inline void moveBy(const kku::Vector2& vector) + inline void moveBy(const kku::Vector2 &vector) { top += vector.second; left += vector.first; } - inline bool contains(const kku::Point& point) const + inline bool contains(const kku::Point &point) const { - return point.x >= left ; // debug it when on computer + return point.x >= left; // debug it when on computer } }; -} +} // namespace kku diff --git a/include/core/bpmsection.h b/include/core/bpmsection.h index 282dddb..913c1c9 100644 --- a/include/core/bpmsection.h +++ b/include/core/bpmsection.h @@ -34,10 +34,10 @@ struct BPMSection /// by timestamp of start struct BPMSectionComparator { - bool operator()(const BPMSection& lhs, const BPMSection& rhs) const noexcept + bool operator()(const BPMSection &lhs, const BPMSection &rhs) const noexcept { return lhs.offset_start < rhs.offset_start; } }; -} +} // namespace kku diff --git a/include/core/color.h b/include/core/color.h index e17b970..63ad55e 100644 --- a/include/core/color.h +++ b/include/core/color.h @@ -14,4 +14,4 @@ struct Color unsigned char alpha = 0; }; -} +} // namespace kku diff --git a/include/core/corefactory.h b/include/core/corefactory.h index 5b899d8..2466e92 100644 --- a/include/core/corefactory.h +++ b/include/core/corefactory.h @@ -2,13 +2,13 @@ #include +#include "core/line.h" #include "core/music.h" -#include "core/text.h" -#include "core/resourceholder.h" #include "core/rectangle.h" -#include "core/vector.h" -#include "core/line.h" +#include "core/resourceholder.h" #include "core/sprite.h" +#include "core/text.h" +#include "core/vector.h" namespace kku { @@ -19,14 +19,15 @@ namespace kku /// multimedia elements and data class CoreFactory { -public: + public: virtual ~CoreFactory() = default; virtual std::shared_ptr getMusic() const = 0; virtual std::shared_ptr getText(kku::Font::Id id) const = 0; virtual std::shared_ptr getRectangle() const = 0; virtual std::shared_ptr getLine() const = 0; - virtual std::shared_ptr getSprite(kku::GUISprite::Id id) const = 0; + virtual std::shared_ptr + getSprite(kku::GUISprite::Id id) const = 0; virtual kku::Vector2 getRenderSize() const = 0; }; -} +} // namespace kku diff --git a/include/core/editor.h b/include/core/editor.h index 329774d..857298a 100644 --- a/include/core/editor.h +++ b/include/core/editor.h @@ -1,11 +1,11 @@ #pragma once -#include #include +#include +#include "core/bpmsection.h" #include "core/gameevent.h" #include "core/updatedata.h" -#include "core/bpmsection.h" namespace kku { @@ -16,41 +16,42 @@ namespace kku /// logic for Editor game mode class Editor { -public: + public: virtual ~Editor() = default; - virtual void input(GameEvent&& input) = 0; - virtual void update(UpdateData&& updatedata) = 0; + virtual void input(GameEvent &&input) = 0; + virtual void update(UpdateData &&updatedata) = 0; virtual void display() const = 0; - virtual void recalculate(const microsec& timestamp) = 0; + virtual void recalculate(const microsec ×tamp) = 0; - void setBPMSections(const std::set& sections) noexcept + void setBPMSections( + const std::set §ions) noexcept { _bpm_sections = sections; } - void setBPMSections(std::set&& sections) noexcept + void setBPMSections( + std::set &§ions) noexcept { _bpm_sections = std::move(sections); } - bool insertBPMSection(const BPMSection& section) + bool insertBPMSection(const BPMSection §ion) { return _bpm_sections.insert(section).second; } - bool insertBPMSection(BPMSection&& section) + bool insertBPMSection(BPMSection &§ion) { return _bpm_sections.insert(section).second; } - bool removeBPMSectionAt(const microsec& offset) + bool removeBPMSectionAt(const microsec &offset) { - auto section_it = std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(), - [offset](const auto& section) - { - return section.offset_start < offset; - }); + auto section_it = + std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(), + [offset](const auto §ion) + { return section.offset_start < offset; }); if (section_it != _bpm_sections.rend()) { @@ -63,13 +64,12 @@ public: return false; } - BPMSection getBPMSectionAt(const microsec& offset) const + BPMSection getBPMSectionAt(const microsec &offset) const { - auto section_it = std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(), - [offset](const auto& section) - { - return section.offset_start < offset; - }); + auto section_it = + std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(), + [offset](const auto §ion) + { return section.offset_start < offset; }); if (section_it != _bpm_sections.rend()) { @@ -80,13 +80,10 @@ public: return BPMSection(); } - void clearBPMSections() noexcept - { - _bpm_sections.clear(); - } + void clearBPMSections() noexcept { _bpm_sections.clear(); } -protected: + protected: std::set _bpm_sections; }; -} +} // namespace kku diff --git a/include/core/editorcallback.h b/include/core/editorcallback.h index d78a2bf..fac7c41 100644 --- a/include/core/editorcallback.h +++ b/include/core/editorcallback.h @@ -1,6 +1,5 @@ #pragma once -#include "core/systemevent.h" #include namespace kku @@ -8,7 +7,7 @@ namespace kku class EditorCallback { -public: + public: virtual ~EditorCallback() = default; struct Metadata @@ -23,4 +22,4 @@ public: virtual Metadata getMetadata() const = 0; }; -} +} // namespace kku diff --git a/include/core/functional.h b/include/core/functional.h index f11e80e..f6b38cc 100644 --- a/include/core/functional.h +++ b/include/core/functional.h @@ -8,4 +8,4 @@ namespace kku using lambda = std::function; using predicate = std::function; -} +} // namespace kku diff --git a/include/core/game.h b/include/core/game.h index 217ba94..3b94e79 100644 --- a/include/core/game.h +++ b/include/core/game.h @@ -12,13 +12,13 @@ namespace kku /// logic for actual game mode class Game { -public: + public: virtual ~Game() = default; virtual void run() = 0; - virtual void input(GameEvent&& inputdata) = 0; - virtual void update(UpdateData&& updatedata) = 0; + virtual void input(GameEvent &&inputdata) = 0; + virtual void update(UpdateData &&updatedata) = 0; virtual void display() const = 0; }; -} +} // namespace kku diff --git a/include/core/gameevent.h b/include/core/gameevent.h index 4bb117d..1e9cbb7 100644 --- a/include/core/gameevent.h +++ b/include/core/gameevent.h @@ -12,4 +12,4 @@ struct GameEvent const SystemEvent event; }; -} +} // namespace kku diff --git a/include/core/line.h b/include/core/line.h index 9170d65..755e846 100644 --- a/include/core/line.h +++ b/include/core/line.h @@ -1,7 +1,7 @@ #pragma once -#include "core/point.h" #include "core/color.h" +#include "core/point.h" namespace kku { @@ -11,11 +11,11 @@ namespace kku /// Graphical 2D line class Line { -public: + public: virtual ~Line() = default; - virtual void setPosition(const kku::Point& p1, const kku::Point& p2) = 0; - virtual void setColor(const kku::Color& c1, const kku::Color& c2) = 0; + virtual void setPosition(const kku::Point &p1, const kku::Point &p2) = 0; + virtual void setColor(const kku::Color &c1, const kku::Color &c2) = 0; virtual void display() = 0; }; -} +} // namespace kku diff --git a/include/core/music.h b/include/core/music.h index d968616..baa4664 100644 --- a/include/core/music.h +++ b/include/core/music.h @@ -12,10 +12,10 @@ namespace kku /// Object for streaming music file class Music { -public: + public: virtual ~Music() = default; - virtual bool open(const std::string& filepath) = 0; + virtual bool open(const std::string &filepath) = 0; virtual void play() = 0; virtual void pause() = 0; @@ -25,11 +25,11 @@ public: virtual void setVolume(float volume) = 0; - virtual void setOffset(const kku::microsec& offset) = 0; - virtual void moveOffset(const kku::microsec& delta) = 0; + virtual void setOffset(const kku::microsec &offset) = 0; + virtual void moveOffset(const kku::microsec &delta) = 0; virtual kku::microsec fetchOffset() = 0; virtual kku::microsec getDuration() const = 0; }; -} +} // namespace kku diff --git a/include/core/note.h b/include/core/note.h index 23ac834..0c3bd2b 100644 --- a/include/core/note.h +++ b/include/core/note.h @@ -1,55 +1,52 @@ #pragma once -#include "core/time.h" #include "core/gameevent.h" +#include "core/time.h" namespace kku { class Note { -public: - explicit Note(microsec perfect_offset) : - _perfect_offset(perfect_offset) {} + public: + explicit Note(microsec perfect_offset) : _perfect_offset(perfect_offset) {} virtual ~Note() = default; - virtual bool isActive(const microsec& offset) const = 0; - virtual void update(const microsec& music_offset) = 0; + virtual bool isActive(const microsec &offset) const = 0; + virtual void update(const microsec &music_offset) = 0; - virtual void input(kku::GameEvent&& input) = 0; + virtual void input(kku::GameEvent &&input) = 0; - inline const microsec& getPerfectOffset() const noexcept + inline const microsec &getPerfectOffset() const noexcept { return _perfect_offset; } - bool operator<(const Note& note) const + bool operator<(const Note ¬e) const { return _perfect_offset < note._perfect_offset; } - bool operator==(const Note& note) const + bool operator==(const Note ¬e) const { return _perfect_offset == note._perfect_offset; } - bool operator>(const Note& note) const + bool operator>(const Note ¬e) const { return _perfect_offset > note._perfect_offset; } -protected: + protected: microsec _perfect_offset; }; struct NotePtrComparator { - bool operator()(const Note* lhs, const Note* rhs) const noexcept + bool operator()(const Note *lhs, const Note *rhs) const noexcept { return lhs->getPerfectOffset() < rhs->getPerfectOffset(); } }; -} - - +} // namespace kku diff --git a/include/core/point.h b/include/core/point.h index a79192a..946f5c5 100644 --- a/include/core/point.h +++ b/include/core/point.h @@ -8,24 +8,18 @@ struct Point float x; float y; - constexpr inline explicit Point() noexcept : - x(0.), y(0.) - {} + constexpr inline explicit Point() noexcept : x(0.), y(0.) {} - constexpr inline explicit Point(int x, int y) noexcept : - x(x), y(y) - {} + constexpr inline explicit Point(int x, int y) noexcept : x(x), y(y) {} - constexpr inline explicit Point(float x, float y) noexcept : - x(x), y(y) - {} + constexpr inline explicit Point(float x, float y) noexcept : x(x), y(y) {} - constexpr inline Point operator+(const Point& right) const noexcept + constexpr inline Point operator+(const Point &right) const noexcept { return Point{right.x + x, right.y + y}; } - constexpr inline Point operator-(const Point& right) const noexcept + constexpr inline Point operator-(const Point &right) const noexcept { return Point{right.x - x, right.y - y}; } @@ -43,4 +37,4 @@ struct Point } }; -} \ No newline at end of file +} // namespace kku diff --git a/include/core/precisionevaluator.h b/include/core/precisionevaluator.h index 2491643..7cf48a8 100644 --- a/include/core/precisionevaluator.h +++ b/include/core/precisionevaluator.h @@ -1,37 +1,34 @@ #pragma once +#include +#include #include #include #include -#include -#include #include "core/time.h" namespace kku { -template::value>> +template ::value>> class PrecisionEvaluator { -public: - PrecisionEvaluator(const std::vector& intervals, microsec offset) : - _offset(offset), - _intervals(intervals) + public: + PrecisionEvaluator(const std::vector &intervals, microsec offset) + : _offset(offset), _intervals(intervals) { _start_handling_offset = _offset - intervals.back(); _end_handling_offset = _offset + intervals.back(); } - inline microsec offset() const noexcept - { - return _offset; - } + inline microsec offset() const noexcept { return _offset; } inline bool isActive(microsec music_play_offset) const noexcept { - return music_play_offset > _start_handling_offset - && music_play_offset < _end_handling_offset; + return music_play_offset > _start_handling_offset && + music_play_offset < _end_handling_offset; } Grade calculatePrecision(microsec odds) const @@ -51,7 +48,7 @@ public: return static_cast(raw_grade); } -private: + private: microsec _offset; microsec _start_handling_offset; microsec _end_handling_offset; @@ -66,4 +63,4 @@ private: const std::vector _intervals; }; -} +} // namespace kku diff --git a/include/core/rectangle.h b/include/core/rectangle.h index f8b831e..fc3d96a 100644 --- a/include/core/rectangle.h +++ b/include/core/rectangle.h @@ -8,20 +8,20 @@ namespace kku class Rectangle { -public: + public: virtual ~Rectangle() = default; - virtual void setRect(const Area& rect) = 0; + virtual void setRect(const Area &rect) = 0; virtual Area getRect() const = 0; - virtual void setPosition(const Point& position) = 0; + virtual void setPosition(const Point &position) = 0; virtual Point getPosition() const = 0; - virtual void move(const kku::Vector2& delta) = 0; + virtual void move(const kku::Vector2 &delta) = 0; - virtual void setColor(const Color& color) = 0; + virtual void setColor(const Color &color) = 0; virtual kku::Color getColor() const = 0; - virtual bool contains(const kku::Point& position) const = 0; + virtual bool contains(const kku::Point &position) const = 0; virtual void display() = 0; }; -} +} // namespace kku diff --git a/include/core/resourceholder.h b/include/core/resourceholder.h index 5b76e3f..122030e 100644 --- a/include/core/resourceholder.h +++ b/include/core/resourceholder.h @@ -1,16 +1,15 @@ #pragma once -#include #include +#include namespace kku { -template -class ResourceHolder +template class ResourceHolder { -public: - inline void load(Id id, std::unique_ptr&& resource) noexcept + public: + inline void load(Id id, std::unique_ptr &&resource) noexcept { _resources[id] = std::move(resource); } @@ -20,33 +19,33 @@ public: return _resources.find(id)->second; } -private: + private: std::map> _resources; }; namespace Font { - enum class Id - { - GUI - }; +enum class Id +{ + GUI +}; } namespace Texture { - enum class Id - { - GUI - }; +enum class Id +{ + GUI +}; } namespace GUISprite { - enum class Id - { - SFML_LOGO, - CRYPTOPP_LOGO - }; +enum class Id +{ + SFML_LOGO, + CRYPTOPP_LOGO +}; } -} +} // namespace kku diff --git a/include/core/sprite.h b/include/core/sprite.h index 63707b2..8aae583 100644 --- a/include/core/sprite.h +++ b/include/core/sprite.h @@ -1,20 +1,21 @@ #pragma once -#include "core/area.h" +#include "core/point.h" +#include "core/vector.h" namespace kku { class Sprite { -public: + public: virtual ~Sprite() = default; - virtual void setPosition(const Point& position) = 0; + virtual void setPosition(const Point &position) = 0; virtual Point getPosition() const = 0; - virtual void move(const kku::Vector2& delta) = 0; + virtual void move(const kku::Vector2 &delta) = 0; virtual void display() const = 0; }; -} +} // namespace kku diff --git a/include/core/spritecontainer.h b/include/core/spritecontainer.h index 51b7489..5be8466 100644 --- a/include/core/spritecontainer.h +++ b/include/core/spritecontainer.h @@ -1,28 +1,29 @@ #pragma once + +#include #include #include -#include + namespace kku { -template::value>> +template ::value>> class SpriteContainer { -public: - explicit SpriteContainer(std::initializer_list&& types, - const std::shared_ptr& factory, - std::size_t reserve_size = 20) : - _sprite_factory(factory), - _poll_reserve_size(reserve_size) + public: + explicit SpriteContainer(std::initializer_list &&types, + const std::shared_ptr &factory, + std::size_t reserve_size = 20) + : _sprite_factory(factory), _poll_reserve_size(reserve_size) { - for (const Type& type : types) + for (const Type &type : types) reallocatePoll(type); } inline std::shared_ptr getSprite(Type type) { - SpritePoll& poll = _sprite_dispatcher.at(type); + SpritePoll &poll = _sprite_dispatcher.at(type); if (poll.empty()) reallocatePoll(type); @@ -33,7 +34,8 @@ public: return sprite; } - inline void resetSprite(const std::shared_ptr &sprite, Type action) noexcept + inline void resetSprite(const std::shared_ptr &sprite, + Type action) noexcept { sprite->reset(); _sprite_dispatcher[action].push(sprite); @@ -41,7 +43,7 @@ public: ~SpriteContainer() = default; -private: + private: inline void reallocatePoll(Type sprite_type) { SpritePoll &poll = _sprite_dispatcher[sprite_type]; @@ -59,4 +61,4 @@ private: std::size_t _poll_reserve_size; }; -} +} // namespace kku diff --git a/include/core/systemevent.h b/include/core/systemevent.h index 2882b52..540b5d0 100644 --- a/include/core/systemevent.h +++ b/include/core/systemevent.h @@ -152,9 +152,9 @@ struct SystemEvent enum class Button { - None = 0, + None = 0, Wheel = 1, - Left = 2, + Left = 2, Right = 3 }; @@ -162,10 +162,11 @@ struct SystemEvent }; struct None - {}; + { + }; Type type = Type::None; std::variant data; }; - -} + +} // namespace kku diff --git a/include/core/text.h b/include/core/text.h index ec9fe35..7fa8522 100644 --- a/include/core/text.h +++ b/include/core/text.h @@ -1,24 +1,24 @@ #pragma once -#include #include "core/color.h" #include "core/point.h" #include "core/vector.h" +#include namespace kku { class Text { -public: + public: virtual ~Text() = default; - virtual void setString(const std::string& string) = 0; + virtual void setString(const std::string &string) = 0; virtual void setCharacterSize(std::size_t pixels) = 0; - virtual void setPosition(const Point& point) = 0; - virtual void move(const kku::Vector2& delta) = 0; - virtual void setColor(const Color& color) = 0; + virtual void setPosition(const Point &point) = 0; + virtual void move(const kku::Vector2 &delta) = 0; + virtual void setColor(const Color &color) = 0; virtual void display() = 0; }; -} +} // namespace kku diff --git a/include/core/time.h b/include/core/time.h index 3fa70f4..687c681 100644 --- a/include/core/time.h +++ b/include/core/time.h @@ -10,13 +10,12 @@ struct TimeRange const microsec begin = 0; const microsec end = 0; - constexpr inline explicit TimeRange() noexcept : - begin(0), end(0) - {} + constexpr inline explicit TimeRange() noexcept : begin(0), end(0) {} - constexpr inline explicit TimeRange(microsec x, microsec y) noexcept : - begin(x), end(y) - {} + constexpr inline explicit TimeRange(microsec x, microsec y) noexcept + : begin(x), end(y) + { + } }; -} +} // namespace kku diff --git a/include/core/timeline.h b/include/core/timeline.h index 198701b..8ac60ef 100644 --- a/include/core/timeline.h +++ b/include/core/timeline.h @@ -1,26 +1,25 @@ #pragma once -#include -#include #include +#include +#include -#include "core/time.h" #include "core/note.h" +#include "core/time.h" namespace kku { -template ::value>> +template ::value>> class Timeline { -public: - explicit Timeline() : - _current_offset(0) - {} + public: + explicit Timeline() : _current_offset(0) {} - typedef typename std::set::const_iterator Iterator; + typedef typename std::set::const_iterator Iterator; - void recalculate(const microsec& offset) + void recalculate(const microsec &offset) { _current_offset = offset; expire(_top_note); @@ -36,9 +35,10 @@ public: Iterator pre_head = head_iterator; --pre_head; - _top_note = !isExpired(pre_head) && (*pre_head)->isActive(offset) - ? pre_head - : head_iterator; + _top_note = + !isExpired(pre_head) && (*pre_head)->isActive(offset) + ? pre_head + : head_iterator; break; } @@ -50,7 +50,7 @@ public: } } - void setNotes(const std::set& notes) + void setNotes(const std::set ¬es) { _timeline = std::move(notes); @@ -60,43 +60,42 @@ public: return; } - void insertNote(TNote* note) + void insertNote(TNote *note) { _top_note = _timeline.insert(note).first; recalculate(_current_offset); update(_current_offset); } - void insertNotes(const std::set& notes) + void insertNotes(const std::set ¬es) { _timeline.insert(notes.begin(), notes.end()); recalculate(_current_offset); update(_current_offset); - } inline void clear() { - for (auto& note : _timeline) + for (auto ¬e : _timeline) delete note; _timeline.clear(); } - void update(const microsec& offset) + void update(const microsec &offset) { _current_offset = offset; updateTopNote(_current_offset); } - Iterator getActiveNote(const microsec& music_offset) noexcept + Iterator getActiveNote(const microsec &music_offset) noexcept { Iterator return_note = _timeline.end(); auto note_iterator = _top_note; while (!isExpired(note_iterator)) { - const auto& note = *note_iterator; + const auto ¬e = *note_iterator; if (note->isActive(music_offset)) { return_note = note_iterator; @@ -111,53 +110,43 @@ public: return return_note; } - inline Iterator getNoteBy(const microsec& music_offset) noexcept + inline Iterator getNoteBy(const microsec &music_offset) noexcept { return std::find_if(_timeline.begin(), _timeline.end(), - [music_offset](const auto& note) - { + [music_offset](const auto ¬e) { return note->getPerfectOffset() == music_offset; }); } - inline bool isExpired(const Iterator& iterator) const noexcept + inline bool isExpired(const Iterator &iterator) const noexcept { return iterator == _timeline.end(); } - inline void expire(Iterator& iterator) noexcept + inline void expire(Iterator &iterator) noexcept { iterator = _timeline.end(); } - inline Iterator getTopNote() const noexcept - { - return _top_note; - } + inline Iterator getTopNote() const noexcept { return _top_note; } - inline Iterator begin() const noexcept - { - return _timeline.begin(); - } + inline Iterator begin() const noexcept { return _timeline.begin(); } - inline Iterator end() const noexcept - { - return _timeline.end(); - } + inline Iterator end() const noexcept { return _timeline.end(); } -private: - std::set _timeline; + private: + std::set _timeline; microsec _current_offset; - inline void updateTopNote(const microsec& music_offset) noexcept + inline void updateTopNote(const microsec &music_offset) noexcept { if (isExpired(_top_note)) return; - const auto& top_note = *_top_note; + const auto &top_note = *_top_note; - bool already_played = top_note->getPerfectOffset() < music_offset - && !top_note->isActive(music_offset); + bool already_played = top_note->getPerfectOffset() < music_offset && + !top_note->isActive(music_offset); if (already_played) ++_top_note; @@ -166,6 +155,4 @@ private: Iterator _top_note; }; -} - - +} // namespace kku diff --git a/include/core/updatedata.h b/include/core/updatedata.h index 17a2183..d0682e9 100644 --- a/include/core/updatedata.h +++ b/include/core/updatedata.h @@ -11,6 +11,4 @@ struct UpdateData const microsec dt; }; -} - - +} // namespace kku diff --git a/include/core/vector.h b/include/core/vector.h index 871201d..777952d 100644 --- a/include/core/vector.h +++ b/include/core/vector.h @@ -9,13 +9,12 @@ namespace kku /// /// Meaning an element of a vector space in math. /// Don't mistake for std::vector -template -using Vector2 = std::pair; +template using Vector2 = std::pair; template -inline constexpr auto makeVector(T&& l, T&& r) -> Vector2 +inline constexpr auto makeVector(T &&l, T &&r) -> Vector2 { return std::make_pair(std::forward(l), std::forward(r)); } -} +} // namespace kku diff --git a/src/application/include/application/about.h b/src/application/include/application/about.h index 2785529..eb5f183 100644 --- a/src/application/include/application/about.h +++ b/src/application/include/application/about.h @@ -7,26 +7,30 @@ class Group; class PushButton; -namespace kku { class Sprite; class Text; } +namespace kku +{ +class Sprite; +class Text; +} // namespace kku class About : public GUIState { -public: - + public: struct Callbacks { kku::lambda onLeaveAboutState; }; - explicit About(const std::shared_ptr& factory, Callbacks&& callbacks); - virtual void input(const kku::SystemEvent& event) override; - virtual void update(const kku::microsec& dt) override; + explicit About(const std::shared_ptr &factory, + Callbacks &&callbacks); + virtual void input(const kku::SystemEvent &event) override; + virtual void update(const kku::microsec &dt) override; virtual void display() const override; virtual void enter() override; virtual void leave() override; -private: + private: const Callbacks _callbacks; const std::shared_ptr _core_factory; const std::shared_ptr _sfml_logo; @@ -36,4 +40,3 @@ private: std::shared_ptr _buttons; std::shared_ptr _exit_button; }; - diff --git a/src/application/include/application/editorstate.h b/src/application/include/application/editorstate.h index c63f254..3dd0c77 100644 --- a/src/application/include/application/editorstate.h +++ b/src/application/include/application/editorstate.h @@ -2,40 +2,43 @@ #include "application/state.h" #include "core/corefactory.h" -#include "core/music.h" #include "core/functional.h" +#include "core/music.h" class BPMCalculator; class Group; -namespace kku { class Editor; } +namespace kku +{ +class Editor; +} class EditorState : public GUIState { -public: - + public: struct Callbacks { kku::lambda onLeaveEditorState; }; - explicit EditorState(const std::shared_ptr& core_factory, std::unique_ptr&& editor, Callbacks&& callbacks); + explicit EditorState(const std::shared_ptr &core_factory, + std::unique_ptr &&editor, + Callbacks &&callbacks); virtual ~EditorState() override; - virtual void input(const kku::SystemEvent& event) override; - virtual void update(const kku::microsec& dt) override; + virtual void input(const kku::SystemEvent &event) override; + virtual void update(const kku::microsec &dt) override; virtual void display() const override; virtual void enter() override; virtual void leave() override; -private: + private: const Callbacks _callbacks; const std::shared_ptr _core_factory; std::shared_ptr _music; - + std::shared_ptr _bpm_calculator; std::shared_ptr _group; std::unique_ptr _editor; }; - diff --git a/src/application/include/application/gamestate.h b/src/application/include/application/gamestate.h index d9811ca..2a44d89 100644 --- a/src/application/include/application/gamestate.h +++ b/src/application/include/application/gamestate.h @@ -1,33 +1,33 @@ #pragma once -#include "state.h" -#include "core/music.h" -#include "core/game.h" #include "core/corefactory.h" #include "core/functional.h" +#include "core/game.h" +#include "core/music.h" +#include "state.h" class Group; class GameState : public GUIState { -public: - + public: struct Callbacks { kku::lambda onLeaveGame; }; + explicit GameState(const std::shared_ptr &core_factory, + const std::shared_ptr &game, + Callbacks &&callbacks); - explicit GameState(const std::shared_ptr& core_factory, const std::shared_ptr& game, Callbacks&& callbacks); - - virtual void input(const kku::SystemEvent& event) override; - virtual void update(const kku::microsec& dt) override; + virtual void input(const kku::SystemEvent &event) override; + virtual void update(const kku::microsec &dt) override; virtual void display() const override; virtual void enter() override; virtual void leave() override; -private: + private: const std::shared_ptr _core_factory; std::shared_ptr _music; std::shared_ptr _game; @@ -35,4 +35,3 @@ private: kku::lambda _onEnterGameCallback; kku::lambda _onLeaveGameCallback; }; - diff --git a/src/application/include/application/mainmenu.h b/src/application/include/application/mainmenu.h index c61f32f..0babffa 100644 --- a/src/application/include/application/mainmenu.h +++ b/src/application/include/application/mainmenu.h @@ -8,8 +8,7 @@ class Group; class MainMenu : public GUIState { -public: - + public: struct Callbacks { kku::lambda onAppendGameState; @@ -17,18 +16,18 @@ public: kku::lambda onAppendAboutState; }; - explicit MainMenu(const std::shared_ptr& factory, Callbacks&& callbacks); - virtual void input(const kku::SystemEvent& event) override; - virtual void update(const kku::microsec& dt) override; + explicit MainMenu(const std::shared_ptr &factory, + Callbacks &&callbacks); + virtual void input(const kku::SystemEvent &event) override; + virtual void update(const kku::microsec &dt) override; virtual void display() const override; virtual void enter() override; virtual void leave() override; -private: + private: const Callbacks _callbacks; const std::shared_ptr _core_factory; std::shared_ptr _buttons; }; - diff --git a/src/application/include/application/state.h b/src/application/include/application/state.h index 1db6b3e..208f664 100644 --- a/src/application/include/application/state.h +++ b/src/application/include/application/state.h @@ -1,17 +1,17 @@ #pragma once -#include #include +#include #include "core/systemevent.h" -#include "core/vector.h" #include "core/time.h" +#include "core/vector.h" class GUIState { -public: - - enum Tag { + public: + enum Tag + { SPLASH_SCREEN, MAIN_MENU, GAME_PICKER, @@ -26,8 +26,8 @@ public: virtual ~GUIState() = default; - virtual void input(const kku::SystemEvent& event) = 0; - virtual void update(const kku::microsec& dt) = 0; + virtual void input(const kku::SystemEvent &event) = 0; + virtual void update(const kku::microsec &dt) = 0; virtual void display() const = 0; virtual void enter() = 0; diff --git a/src/application/shared/application/application.h b/src/application/shared/application/application.h index 77f863f..78ae58f 100644 --- a/src/application/shared/application/application.h +++ b/src/application/shared/application/application.h @@ -1,24 +1,24 @@ #pragma once -#include -#include #include +#include +#include #include "../../include/application/state.h" // HOW? WHY DOESN'T "application/state.h" LINK ON BY ITSELF #include "core/corefactory.h" class Application { -public: + public: virtual ~Application() = default; virtual bool init(); virtual void display() = 0; virtual void run() = 0; - void input(const kku::SystemEvent& input); - void update(const kku::microsec& dt); + void input(const kku::SystemEvent &input); + void update(const kku::microsec &dt); -protected: + protected: std::shared_ptr _core_factory; std::array, GUIState::Tag::AMOUNT> _states; diff --git a/src/application/shared/application/log.h b/src/application/shared/application/log.h index d3725a0..6930d91 100644 --- a/src/application/shared/application/log.h +++ b/src/application/shared/application/log.h @@ -5,12 +5,13 @@ /** * @brief Basic logging class * - * Defines helper functions for logging facility. Configured in Application::init() - * + * Defines helper functions for logging facility. Configured in + * Application::init() + * */ class Log { -public: + public: enum LogLevel { FATAL, @@ -26,24 +27,30 @@ public: * @brief Prints message to stdout * * TODO: write to configurable stream, be it stdout, stderr or even a file - * + * * @param level the message level * @param fmt the message format * @param ... variable parameters */ void log(LogLevel level, const std::string &fmt, ...); - -private: + + private: inline std::string _getLabel(LogLevel level) { switch (level) { - case DEBUG: return "DEBUG"; - case INFO: return "INFO "; - case WARN: return "WARN "; - case ERROR: return "ERROR"; - case FATAL: return "FATAL"; - default: return "UNK "; + case DEBUG: + return "DEBUG"; + case INFO: + return "INFO "; + case WARN: + return "WARN "; + case ERROR: + return "ERROR"; + case FATAL: + return "FATAL"; + default: + return "UNK "; } } }; diff --git a/src/application/src/about.cpp b/src/application/src/about.cpp index eb1a31d..4717c01 100644 --- a/src/application/src/about.cpp +++ b/src/application/src/about.cpp @@ -1,14 +1,14 @@ #include "application/about.h" -#include "widgets/pushbutton.h" #include "widgets/group.h" +#include "widgets/pushbutton.h" -About::About(const std::shared_ptr& factory, About::Callbacks&& callbacks) : - _callbacks(std::move(callbacks)), - _core_factory(factory), - _sfml_logo(factory->getSprite(kku::GUISprite::Id::SFML_LOGO)), - _cryptopp_logo(factory->getSprite(kku::GUISprite::Id::CRYPTOPP_LOGO)), - _powered_by_text(factory->getText(kku::Font::Id::GUI)), - _buttons(std::make_shared()) +About::About(const std::shared_ptr &factory, + About::Callbacks &&callbacks) + : _callbacks(std::move(callbacks)), _core_factory(factory), + _sfml_logo(factory->getSprite(kku::GUISprite::Id::SFML_LOGO)), + _cryptopp_logo(factory->getSprite(kku::GUISprite::Id::CRYPTOPP_LOGO)), + _powered_by_text(factory->getText(kku::Font::Id::GUI)), + _buttons(std::make_shared()) { _powered_by_text->setString("Powered by: "); _powered_by_text->move(kku::Vector2{0., 60}); @@ -16,12 +16,12 @@ About::About(const std::shared_ptr& factory, About::Callbacks& _cryptopp_logo->move(kku::Vector2{250., 180}); } -void About::input(const kku::SystemEvent& event) +void About::input(const kku::SystemEvent &event) { _buttons->input(event); } -void About::update(const kku::microsec& dt) +void About::update(const kku::microsec &dt) { _buttons->update(dt); } @@ -42,13 +42,15 @@ void About::enter() if (!_exit_button) { - _exit_button = std::make_shared("Return", _core_factory, 48); + _exit_button = + std::make_shared("Return", _core_factory, 48); _exit_button->setCallback(_callbacks.onLeaveAboutState); _buttons->addChild(_exit_button); } - _exit_button->setRect(kku::Area{window_width / 3.f, window_height / 7.f * 4, - window_width / 3.f, window_height / 7.f}); + _exit_button->setRect( + kku::Area{window_width / 3.f, window_height / 7.f * 4, + window_width / 3.f, window_height / 7.f}); _buttons->setVisibility(); } @@ -56,4 +58,3 @@ void About::leave() { _buttons->setVisibility(false); } - diff --git a/src/application/src/application.cpp b/src/application/src/application.cpp index da11ffb..bd88692 100644 --- a/src/application/src/application.cpp +++ b/src/application/src/application.cpp @@ -1,12 +1,12 @@ #include "application/application.h" #include "application/log.h" -#include "core/gameevent.h" #include "core/editor.h" +#include "core/gameevent.h" -#include "application/mainmenu.h" -#include "application/gamestate.h" -#include "application/editorstate.h" #include "application/about.h" +#include "application/editorstate.h" +#include "application/gamestate.h" +#include "application/mainmenu.h" #include "classicmode/classicfactory.h" @@ -20,17 +20,22 @@ bool Application::init() if (!_core_factory) return false; - MainMenu::Callbacks callbacks = - { - [&](){ pushState(GUIState::Tag::GAME); }, - [&](){ pushState(GUIState::Tag::EDITOR); }, - [&](){ pushState(GUIState::Tag::ABOUT); }, + MainMenu::Callbacks callbacks = { + [&]() { pushState(GUIState::Tag::GAME); }, + [&]() { pushState(GUIState::Tag::EDITOR); }, + [&]() { pushState(GUIState::Tag::ABOUT); }, }; - const auto main_menu = std::make_shared(_core_factory, std::move(callbacks)); - const auto game_state = std::make_shared(_core_factory, classic::getGame(_core_factory), GameState::Callbacks{[&](){ popState(); }}); - const auto editor = std::make_shared(_core_factory, classic::getEditor(_core_factory), EditorState::Callbacks{[&](){ popState(); }}); - const auto about = std::make_shared(_core_factory, About::Callbacks{[&](){ popState(); }}); + const auto main_menu = + std::make_shared(_core_factory, std::move(callbacks)); + const auto game_state = std::make_shared( + _core_factory, classic::getGame(_core_factory), + GameState::Callbacks{[&]() { popState(); }}); + const auto editor = std::make_shared( + _core_factory, classic::getEditor(_core_factory), + EditorState::Callbacks{[&]() { popState(); }}); + const auto about = std::make_shared( + _core_factory, About::Callbacks{[&]() { popState(); }}); _states[GUIState::Tag::MAIN_MENU] = main_menu; _states[GUIState::Tag::GAME] = game_state; @@ -42,12 +47,12 @@ bool Application::init() return true; } -void Application::input(const kku::SystemEvent& event) +void Application::input(const kku::SystemEvent &event) { _state_stack.back()->input(event); } -void Application::update(const kku::microsec& dt) +void Application::update(const kku::microsec &dt) { _state_stack.back()->update(dt); } diff --git a/src/application/src/editorstate.cpp b/src/application/src/editorstate.cpp index b21635e..0bbd866 100644 --- a/src/application/src/editorstate.cpp +++ b/src/application/src/editorstate.cpp @@ -1,31 +1,32 @@ #include "application/editorstate.h" +#include "tools/bpmcalculator.h" +#include "widgets/bpmcalculatorwidget.h" #include "widgets/button.h" +#include "widgets/editorwidget.h" #include "widgets/group.h" #include "widgets/menubar.h" #include "widgets/window.h" -#include "widgets/editorwidget.h" -#include "widgets/bpmcalculatorwidget.h" -#include "tools/bpmcalculator.h" #include "core/editor.h" -EditorState::EditorState(const std::shared_ptr& core_factory, - std::unique_ptr&& editor, - Callbacks&& callbacks) : - _callbacks(std::move(callbacks)), - _core_factory(core_factory), - _editor(std::move(editor)) -{} +EditorState::EditorState(const std::shared_ptr &core_factory, + std::unique_ptr &&editor, + Callbacks &&callbacks) + : _callbacks(std::move(callbacks)), _core_factory(core_factory), + _editor(std::move(editor)) +{ +} EditorState::~EditorState() -{} +{ +} -void EditorState::input(const kku::SystemEvent& event) +void EditorState::input(const kku::SystemEvent &event) { _group->input(event); } -void EditorState::update(const kku::microsec& dt) +void EditorState::update(const kku::microsec &dt) { _group->update(dt); } @@ -41,54 +42,59 @@ void EditorState::enter() _music->open("resources/METEOR.flac"); _music->setVolume(5.f); - auto& group = _group; - auto& music = _music; - auto& editor = _editor; + auto &group = _group; + auto &music = _music; + auto &editor = _editor; _bpm_calculator = std::make_shared(); - auto& bpm_calculator = _bpm_calculator; - std::shared_ptr bpm_widget = std::make_shared(_bpm_calculator, _core_factory); + auto &bpm_calculator = _bpm_calculator; + std::shared_ptr bpm_widget = + std::make_shared(_bpm_calculator, _core_factory); auto button_start = std::make_shared("Start", _core_factory); auto button_stop = std::make_shared("Stop", _core_factory); auto button_apply = std::make_shared("Apply", _core_factory); - button_start->setCallback([bpm_calculator, button_start, button_stop, &music]() - { - music->play(); - bpm_calculator->start(); - button_start->setVisibility(false); - button_stop->setVisibility(true); - }); - - button_stop->setCallback([bpm_calculator, button_start, button_stop, &music]() - { - music->stop(); - bpm_calculator->stop(); - button_start->setVisibility(true); - button_stop->setVisibility(false); - }); - - button_apply->setCallback([&editor, bpm_calculator]() - { - kku::BPMSection section; - const auto& info = bpm_calculator->fetchApproximatedInfo(); - section.bpm = info.BPM; - section.interval = info.interval; - section.fraction = 2; - section.offset_start = bpm_calculator->getStartingOffset(); + button_start->setCallback( + [bpm_calculator, button_start, button_stop, &music]() + { + music->play(); + bpm_calculator->start(); + button_start->setVisibility(false); + button_stop->setVisibility(true); + }); + + button_stop->setCallback( + [bpm_calculator, button_start, button_stop, &music]() + { + music->stop(); + bpm_calculator->stop(); + button_start->setVisibility(true); + button_stop->setVisibility(false); + }); + + button_apply->setCallback( + [&editor, bpm_calculator]() + { + kku::BPMSection section; + const auto &info = bpm_calculator->fetchApproximatedInfo(); + section.bpm = info.BPM; + section.interval = info.interval; + section.fraction = 2; + section.offset_start = bpm_calculator->getStartingOffset(); - editor->insertBPMSection(std::move(section)); - }); + editor->insertBPMSection(std::move(section)); + }); BPMCalculatorWidget::Init bpm_widget_init; bpm_widget_init.stop = button_stop; bpm_widget_init.apply = button_apply; bpm_widget_init.start = button_start; - bpm_widget_init.current_time = [&music]() -> kku::microsec { return music->fetchOffset(); }; + bpm_widget_init.current_time = [&music]() -> kku::microsec + { return music->fetchOffset(); }; bpm_widget->init(std::move(bpm_widget_init)); - const auto bpm_widget_callback = [&group, bpm_widget=bpm_widget, &music]() + const auto bpm_widget_callback = [&group, bpm_widget = bpm_widget, &music]() { music->stop(); bpm_widget->setVisibility(false); @@ -100,16 +106,19 @@ void EditorState::enter() auto menu_bar = std::make_shared(_core_factory); - auto bpm_button = std::make_shared("Calculate BPM", _core_factory); + auto bpm_button = + std::make_shared("Calculate BPM", _core_factory); - bpm_button->setCallback([&group, bpm_widget=bpm_widget]() - { - group->blockBy(bpm_widget); - bpm_widget->setVisibility(true); - }); + bpm_button->setCallback( + [&group, bpm_widget = bpm_widget]() + { + group->blockBy(bpm_widget); + bpm_widget->setVisibility(true); + }); - bpm_widget->setRect(kku::Area{render_size.first / 3.f, render_size.second / 3.f, - render_size.first / 3.f, render_size.second / 3.f}); + bpm_widget->setRect( + kku::Area{render_size.first / 3.f, render_size.second / 3.f, + render_size.first / 3.f, render_size.second / 3.f}); bpm_widget->addBarButton("X", bpm_widget_callback); bpm_widget->setVisibility(false); @@ -120,9 +129,11 @@ void EditorState::enter() auto test_menu_3 = std::make_shared(_core_factory); test_menu_3->setRect(kku::Area{0., 0., 200., 27. * 5.}); - auto test_cascade_button = std::make_shared("Show submenu", _core_factory); + auto test_cascade_button = + std::make_shared("Show submenu", _core_factory); - auto test_cascade_button_2 = std::make_shared("Show submenu 2", _core_factory); + auto test_cascade_button_2 = + std::make_shared("Show submenu 2", _core_factory); auto quit_button = std::make_shared("Quit", _core_factory); quit_button->setCallback(_callbacks.onLeaveEditorState); @@ -150,19 +161,18 @@ void EditorState::enter() menu_bar->setVisibility(true); EditorWidget::Callbacks callbacks; - callbacks.onDisplay = [&editor]() - { - editor->display(); - }; + callbacks.onDisplay = [&editor]() { editor->display(); }; - callbacks.onInput = [&editor, &music](const kku::SystemEvent& event) + callbacks.onInput = [&editor, &music](const kku::SystemEvent &event) { - if (event.type == kku::SystemEvent::Type::KeyRelease - && std::get(event.data).view == kku::SystemEvent::Key::Code::Space) + if (event.type == kku::SystemEvent::Type::KeyRelease && + std::get(event.data).view == + kku::SystemEvent::Key::Code::Space) music->isPlaying() ? music->pause() : music->play(); else if (event.type == kku::SystemEvent::Type::MouseWheelScroll) { - const auto& up = std::get(event.data).scrolled_up; + const auto &up = + std::get(event.data).scrolled_up; music->moveOffset(up ? 500000 : -500000); editor->recalculate(music->fetchOffset()); } @@ -170,8 +180,7 @@ void EditorState::enter() editor->input(kku::GameEvent{music->fetchOffset(), event}); }; - callbacks.onUpdate = [&editor, &music](const kku::microsec& dt) - { + callbacks.onUpdate = [&editor, &music](const kku::microsec &dt) { editor->update(kku::UpdateData{music->fetchOffset(), dt}); }; diff --git a/src/application/src/gamestate.cpp b/src/application/src/gamestate.cpp index 6d515ca..742b090 100644 --- a/src/application/src/gamestate.cpp +++ b/src/application/src/gamestate.cpp @@ -4,14 +4,15 @@ #include "core/game.h" -GameState::GameState(const std::shared_ptr& core_factory, const std::shared_ptr& game, Callbacks&& callbacks) : - _core_factory(core_factory), - _game(game), - _onLeaveGameCallback(callbacks.onLeaveGame) +GameState::GameState(const std::shared_ptr &core_factory, + const std::shared_ptr &game, + Callbacks &&callbacks) + : _core_factory(core_factory), _game(game), + _onLeaveGameCallback(callbacks.onLeaveGame) { } -void GameState::input(const kku::SystemEvent& event) +void GameState::input(const kku::SystemEvent &event) { switch (event.type) { @@ -33,7 +34,7 @@ void GameState::input(const kku::SystemEvent& event) _game->input(kku::GameEvent{_music->fetchOffset(), event}); } -void GameState::update(const kku::microsec& dt) +void GameState::update(const kku::microsec &dt) { _game->update(kku::UpdateData{_music->fetchOffset(), dt}); } diff --git a/src/application/src/log.cpp b/src/application/src/log.cpp index aada004..c931d10 100644 --- a/src/application/src/log.cpp +++ b/src/application/src/log.cpp @@ -4,7 +4,8 @@ #include "application/log.h" -void Log::log(LogLevel level, const std::string &fmt, ...) { +void Log::log(LogLevel level, const std::string &fmt, ...) +{ if (level > this->level) return; @@ -23,4 +24,4 @@ void Log::log(LogLevel level, const std::string &fmt, ...) { va_end(args); std::cout << this->_getLabel(level) << " " << &buf[0] << std::endl; -} \ No newline at end of file +} diff --git a/src/application/src/mainmenu.cpp b/src/application/src/mainmenu.cpp index e5fb395..22913fa 100644 --- a/src/application/src/mainmenu.cpp +++ b/src/application/src/mainmenu.cpp @@ -1,20 +1,20 @@ #include "application/mainmenu.h" -#include "widgets/pushbutton.h" #include "widgets/group.h" +#include "widgets/pushbutton.h" -MainMenu::MainMenu(const std::shared_ptr& factory, MainMenu::Callbacks&& callbacks) : - _callbacks(std::move(callbacks)), - _core_factory(factory), - _buttons(std::make_shared()) +MainMenu::MainMenu(const std::shared_ptr &factory, + MainMenu::Callbacks &&callbacks) + : _callbacks(std::move(callbacks)), _core_factory(factory), + _buttons(std::make_shared()) { } -void MainMenu::input(const kku::SystemEvent& event) +void MainMenu::input(const kku::SystemEvent &event) { _buttons->input(event); } -void MainMenu::update(const kku::microsec& dt) +void MainMenu::update(const kku::microsec &dt) { _buttons->update(dt); } @@ -30,19 +30,25 @@ void MainMenu::enter() const float window_width = render_size.first; const float window_height = render_size.second; - auto button_start = std::make_shared("Start", _core_factory, 48); - button_start->setRect(kku::Area{window_width / 3.f, window_height / 7.f, - window_width / 3.f, window_height / 7.f}); + auto button_start = + std::make_shared("Start", _core_factory, 48); + button_start->setRect( + kku::Area{window_width / 3.f, window_height / 7.f, + window_width / 3.f, window_height / 7.f}); button_start->setCallback(_callbacks.onAppendGameState); - auto button_editor = std::make_shared("Editor", _core_factory, 48); - button_editor->setRect(kku::Area{window_width / 3.f, window_height / 7.f * 3, - window_width / 3.f, window_height / 7.f}); + auto button_editor = + std::make_shared("Editor", _core_factory, 48); + button_editor->setRect( + kku::Area{window_width / 3.f, window_height / 7.f * 3, + window_width / 3.f, window_height / 7.f}); button_editor->setCallback(_callbacks.onAppendEditorState); - auto button_about = std::make_shared("About", _core_factory, 48); - button_about->setRect(kku::Area{window_width / 3.f, window_height / 7.f * 5, - window_width / 3.f, window_height / 7.f}); + auto button_about = + std::make_shared("About", _core_factory, 48); + button_about->setRect( + kku::Area{window_width / 3.f, window_height / 7.f * 5, + window_width / 3.f, window_height / 7.f}); button_about->setCallback(_callbacks.onAppendAboutState); _buttons->addChild(button_start); @@ -56,4 +62,3 @@ void MainMenu::leave() { _buttons->setVisibility(false); } - diff --git a/src/application/src/widgets/bpmcalculatorwidget.cpp b/src/application/src/widgets/bpmcalculatorwidget.cpp index 4576128..16c5560 100644 --- a/src/application/src/widgets/bpmcalculatorwidget.cpp +++ b/src/application/src/widgets/bpmcalculatorwidget.cpp @@ -1,15 +1,15 @@ #include "bpmcalculatorwidget.h" -#include "tools/bpmcalculator.h" #include "core/editor.h" +#include "tools/bpmcalculator.h" #include -BPMCalculatorWidget::BPMCalculatorWidget(const std::shared_ptr& bpm_calculator, const std::shared_ptr& factory) : - Window(factory, "BPM Calculation"), - _bpm_calculator(bpm_calculator), - _slider(std::make_shared(factory)), - _core_factory(factory), - _ticked(false) +BPMCalculatorWidget::BPMCalculatorWidget( + const std::shared_ptr &bpm_calculator, + const std::shared_ptr &factory) + : Window(factory, "BPM Calculation"), _bpm_calculator(bpm_calculator), + _slider(std::make_shared(factory)), _core_factory(factory), + _ticked(false) { _bpm_value = _core_factory->getText(kku::Font::Id::GUI); _bpm_value->setCharacterSize(40); @@ -20,7 +20,7 @@ BPMCalculatorWidget::BPMCalculatorWidget(const std::shared_ptr& b _slap.setVolume(30.);*/ } -void BPMCalculatorWidget::input(const kku::SystemEvent& event) +void BPMCalculatorWidget::input(const kku::SystemEvent &event) { switch (event.type) { @@ -29,7 +29,8 @@ void BPMCalculatorWidget::input(const kku::SystemEvent& event) case kku::SystemEvent::Type::KeyPress: { - if (std::get(event.data).view == kku::SystemEvent::Key::Code::Space) + if (std::get(event.data).view == + kku::SystemEvent::Key::Code::Space) { _bpm_calculator->click(_current_time()); } @@ -40,7 +41,7 @@ void BPMCalculatorWidget::input(const kku::SystemEvent& event) Window::input(event); } -void BPMCalculatorWidget::update(const kku::microsec& dt) +void BPMCalculatorWidget::update(const kku::microsec &dt) { Window::update(dt); @@ -49,13 +50,16 @@ void BPMCalculatorWidget::update(const kku::microsec& dt) { _bpm_value->setString(std::to_string(static_cast(beat_info.BPM))); - const kku::microsec until_beat = _bpm_calculator->fetchTimeUntilNextBeat(_current_time()); - const auto time_relation = static_cast(beat_info.interval) / static_cast(until_beat); + const kku::microsec until_beat = + _bpm_calculator->fetchTimeUntilNextBeat(_current_time()); + const auto time_relation = + static_cast(beat_info.interval) / + static_cast(until_beat); const auto slider_path_left = _slider->getRect().width / time_relation; if (slider_path_left < 50) { - //if (!_ticked) - //_slap.play(); + // if (!_ticked) + //_slap.play(); _ticked = true; } else @@ -79,30 +83,38 @@ void BPMCalculatorWidget::display() const } } -void BPMCalculatorWidget::setRect(const kku::Area& rect) +void BPMCalculatorWidget::setRect(const kku::Area &rect) { Window::setRect(rect); _slider->setRect(kku::Area{0, 0, rect.width / 8 * 6, 100}); - _slider->setPosition(kku::Point{_window_content->getRect().left + rect.width / 8, - _window_content->getRect().top + rect.height / 8 * 3}); + _slider->setPosition( + kku::Point{_window_content->getRect().left + rect.width / 8, + _window_content->getRect().top + rect.height / 8 * 3}); _button_start->setRect(kku::Area{0, 0, rect.width / 10 * 3, 30}); - _button_start->setPosition(kku::Point{_window_content->getRect().left + rect.width / 7, - _window_content->getRect().top + _window_content->getRect().height - 40}); + _button_start->setPosition( + kku::Point{_window_content->getRect().left + rect.width / 7, + _window_content->getRect().top + + _window_content->getRect().height - 40}); _button_stop->setRect(kku::Area{0, 0, rect.width / 10 * 3, 30}); - _button_stop->setPosition(kku::Point{_window_content->getRect().left + rect.width / 7, - _window_content->getRect().top + _window_content->getRect().height - 40}); + _button_stop->setPosition( + kku::Point{_window_content->getRect().left + rect.width / 7, + _window_content->getRect().top + + _window_content->getRect().height - 40}); _button_apply->setRect(kku::Area{0, 0, rect.width / 10 * 3, 30}); - _button_apply->setPosition(kku::Point{_window_content->getRect().left + 50 + (2 * (rect.width / 7)), - _window_content->getRect().top + _window_content->getRect().height - 40}); - - _bpm_value->setPosition(kku::Point{_window_content->getRect().left + rect.width / 8, - _window_content->getRect().top + rect.height / 8 }); + _button_apply->setPosition(kku::Point{ + _window_content->getRect().left + 50 + (2 * (rect.width / 7)), + _window_content->getRect().top + _window_content->getRect().height - + 40}); + + _bpm_value->setPosition( + kku::Point{_window_content->getRect().left + rect.width / 8, + _window_content->getRect().top + rect.height / 8}); } -void BPMCalculatorWidget::move(const kku::Vector2& delta) +void BPMCalculatorWidget::move(const kku::Vector2 &delta) { Window::move(delta); @@ -110,7 +122,7 @@ void BPMCalculatorWidget::move(const kku::Vector2& delta) _bpm_value->move(delta); } -void BPMCalculatorWidget::setPosition(const kku::Point& position) +void BPMCalculatorWidget::setPosition(const kku::Point &position) { Window::setPosition(position); } diff --git a/src/application/src/widgets/bpmslider.cpp b/src/application/src/widgets/bpmslider.cpp index 8f23b02..1566779 100644 --- a/src/application/src/widgets/bpmslider.cpp +++ b/src/application/src/widgets/bpmslider.cpp @@ -9,12 +9,12 @@ BPMSlider::BPMSlider(const std::shared_ptr &factory) _slider_tick->setColor(kku::Color{255, 0, 0, 255}); } -void BPMSlider::input(const kku::SystemEvent& event) +void BPMSlider::input(const kku::SystemEvent &event) { Widget::input(event); } -void BPMSlider::update(const kku::microsec& dt) +void BPMSlider::update(const kku::microsec &dt) { Widget::update(dt); } @@ -26,28 +26,26 @@ void BPMSlider::display() const Widget::display(); } -void BPMSlider::setRect(const kku::Area& rect) +void BPMSlider::setRect(const kku::Area &rect) { _slider_background->setRect(rect); - _slider_tick->setRect(kku::Area{rect.left, - rect.top, - rect.width / 30.f, - rect.height}); + _slider_tick->setRect( + kku::Area{rect.left, rect.top, rect.width / 30.f, rect.height}); } -void BPMSlider::setPosition(const kku::Point& position) +void BPMSlider::setPosition(const kku::Point &position) { _slider_background->setPosition(position); _slider_tick->setPosition(position); } -void BPMSlider::move(const kku::Vector2& delta) +void BPMSlider::move(const kku::Vector2 &delta) { _slider_background->move(delta); _slider_tick->move(delta); } -bool BPMSlider::isUnderMouse(const kku::Point& position) const +bool BPMSlider::isUnderMouse(const kku::Point &position) const { return _slider_background->contains(position); } @@ -64,6 +62,7 @@ kku::Point BPMSlider::getPosition() const void BPMSlider::setTickPosition(float x_position) { - _slider_tick->setPosition(kku::Point{_slider_background->getPosition().x + x_position, - _slider_tick->getPosition().y}); + _slider_tick->setPosition( + kku::Point{_slider_background->getPosition().x + x_position, + _slider_tick->getPosition().y}); } diff --git a/src/application/src/widgets/button.cpp b/src/application/src/widgets/button.cpp index 840c9f8..6ae83fd 100644 --- a/src/application/src/widgets/button.cpp +++ b/src/application/src/widgets/button.cpp @@ -1,8 +1,10 @@ #include "button.h" #include -Button::Button(const std::string &text, const std::shared_ptr& factory, unsigned int font_size) : - _core_factory(factory) +Button::Button(const std::string &text, + const std::shared_ptr &factory, + unsigned int font_size) + : _core_factory(factory) { _button_text = _core_factory->getText(kku::Font::Id::GUI); _button_text->setString(text); @@ -10,7 +12,7 @@ Button::Button(const std::string &text, const std::shared_ptr& _button_text->setCharacterSize(font_size); } -void Button::update(const kku::microsec& dt) +void Button::update(const kku::microsec &dt) { Widget::update(dt); } @@ -26,14 +28,13 @@ void Button::display() const Widget::display(); } -void Button::setRect(const kku::Area& rect) +void Button::setRect(const kku::Area &rect) { _button_content->setRect(rect); - _button_text->setPosition(kku::Point{rect.left + 5, - rect.top + 5}); + _button_text->setPosition(kku::Point{rect.left + 5, rect.top + 5}); } -void Button::setPosition(const kku::Point& position) +void Button::setPosition(const kku::Point &position) { _button_content->setPosition(position); @@ -42,19 +43,19 @@ void Button::setPosition(const kku::Point& position) _button_text->setPosition(new_point); } -void Button::move(const kku::Vector2& delta) +void Button::move(const kku::Vector2 &delta) { _button_content->move(delta); _button_text->move(delta); Widget::move(delta); } -bool Button::isUnderMouse(const kku::Point& position) const +bool Button::isUnderMouse(const kku::Point &position) const { return _is_visible && _button_content->contains(position); } -void Button::setText(const std::string& text) +void Button::setText(const std::string &text) { _button_text->setString(text); } diff --git a/src/application/src/widgets/cascademenubutton.cpp b/src/application/src/widgets/cascademenubutton.cpp index 5834961..7e16a66 100644 --- a/src/application/src/widgets/cascademenubutton.cpp +++ b/src/application/src/widgets/cascademenubutton.cpp @@ -1,8 +1,10 @@ #include "cascademenubutton.h" #include "menudrop.h" -CascadeMenuButton::CascadeMenuButton(const std::string& text, const std::shared_ptr& factory, unsigned int font_size) : - Button(text, factory, font_size) +CascadeMenuButton::CascadeMenuButton( + const std::string &text, const std::shared_ptr &factory, + unsigned int font_size) + : Button(text, factory, font_size) { _color_idle = kku::Color{230, 230, 230, 255}; _color_hover = kku::Color{84, 158, 253, 255}; @@ -11,7 +13,7 @@ CascadeMenuButton::CascadeMenuButton(const std::string& text, const std::shared_ _button_content->setColor(_color_idle); } -void CascadeMenuButton::input(const kku::SystemEvent& event) +void CascadeMenuButton::input(const kku::SystemEvent &event) { if (!_submenu) return; @@ -23,7 +25,8 @@ void CascadeMenuButton::input(const kku::SystemEvent& event) case kku::SystemEvent::Type::MouseMove: { - const auto position = std::get(event.data).position; + const auto position = + std::get(event.data).position; if (isUnderMouse(position)) { _button_content->setColor(_color_hover); @@ -40,17 +43,16 @@ void CascadeMenuButton::input(const kku::SystemEvent& event) } break; } - } } -void CascadeMenuButton::setRect(const kku::Area& rect) +void CascadeMenuButton::setRect(const kku::Area &rect) { Button::setRect(rect); resetRect(); } -void CascadeMenuButton::setSubmenu(const std::shared_ptr& submenu) +void CascadeMenuButton::setSubmenu(const std::shared_ptr &submenu) { _submenu = submenu; resetRect(); @@ -65,12 +67,14 @@ void CascadeMenuButton::resetRect() { if (_submenu) { - _submenu->setPosition(kku::Point{_button_content->getPosition().x + _button_content->getRect().width, + _submenu->setPosition(kku::Point{_button_content->getPosition().x + + _button_content->getRect().width, _button_content->getPosition().y}); } } -void CascadeMenuButton::setFillColors(kku::Color&& idle_color, kku::Color&& hover_color) +void CascadeMenuButton::setFillColors(kku::Color &&idle_color, + kku::Color &&hover_color) { _color_idle = idle_color; _color_hover = hover_color; diff --git a/src/application/src/widgets/editorwidget.cpp b/src/application/src/widgets/editorwidget.cpp index bc2a3e4..50f1273 100644 --- a/src/application/src/widgets/editorwidget.cpp +++ b/src/application/src/widgets/editorwidget.cpp @@ -1,18 +1,19 @@ #include "editorwidget.h" #include "core/editor.h" -EditorWidget::EditorWidget(Callbacks&& callbacks) : - _input(std::move(callbacks.onInput)), - _update(std::move(callbacks.onUpdate)), - _draw(std::move(callbacks.onDisplay)) -{} +EditorWidget::EditorWidget(Callbacks &&callbacks) + : _input(std::move(callbacks.onInput)), + _update(std::move(callbacks.onUpdate)), + _draw(std::move(callbacks.onDisplay)) +{ +} -void EditorWidget::input(const kku::SystemEvent& event) +void EditorWidget::input(const kku::SystemEvent &event) { _input(event); } -void EditorWidget::update(const kku::microsec& dt) +void EditorWidget::update(const kku::microsec &dt) { _update(dt); } @@ -22,18 +23,18 @@ void EditorWidget::display() const _draw(); } -void EditorWidget::move(const kku::Vector2& delta) +void EditorWidget::move(const kku::Vector2 &delta) { (void)delta; // delegate to children } -bool EditorWidget::isUnderMouse(const kku::Point& position) const +bool EditorWidget::isUnderMouse(const kku::Point &position) const { return _parent->isUnderMouse(position); } -void EditorWidget::setRect(const kku::Area& rect) +void EditorWidget::setRect(const kku::Area &rect) { (void)rect; // basically useless beacuse editor widget fills the entire screen @@ -44,7 +45,7 @@ kku::Area EditorWidget::getRect() const return {}; } -void EditorWidget::setPosition(const kku::Point& position) +void EditorWidget::setPosition(const kku::Point &position) { (void)position; } diff --git a/src/application/src/widgets/group.cpp b/src/application/src/widgets/group.cpp index 2642584..96b8955 100644 --- a/src/application/src/widgets/group.cpp +++ b/src/application/src/widgets/group.cpp @@ -1,11 +1,11 @@ #include "group.h" -void Group::input(const kku::SystemEvent& event) +void Group::input(const kku::SystemEvent &event) { Widget::input(event); } -void Group::update(const kku::microsec& dt) +void Group::update(const kku::microsec &dt) { Widget::update(dt); } @@ -15,18 +15,18 @@ void Group::display() const Widget::display(); } -void Group::setRect(const kku::Area& rect) +void Group::setRect(const kku::Area &rect) { _rect = rect; } -void Group::setPosition(const kku::Point& position) +void Group::setPosition(const kku::Point &position) { _rect.top = position.y; _rect.left = position.x; } -void Group::move(const kku::Vector2& delta) +void Group::move(const kku::Vector2 &delta) { _rect.top += delta.first; _rect.left += delta.second; @@ -34,9 +34,9 @@ void Group::move(const kku::Vector2& delta) Widget::move(delta); } -bool Group::isUnderMouse(const kku::Point& position) const +bool Group::isUnderMouse(const kku::Point &position) const { - return _rect.contains(position); + return _rect.contains(position); } kku::Area Group::getRect() const @@ -46,10 +46,5 @@ kku::Area Group::getRect() const kku::Point Group::getPosition() const { - return kku::Point - { - _rect.top, - _rect.left - }; + return kku::Point{_rect.top, _rect.left}; } - diff --git a/src/application/src/widgets/menubar.cpp b/src/application/src/widgets/menubar.cpp index e6e568e..7ef651b 100644 --- a/src/application/src/widgets/menubar.cpp +++ b/src/application/src/widgets/menubar.cpp @@ -1,10 +1,8 @@ #include "menubar.h" -MenuBar::MenuBar(const std::shared_ptr& factory) : - _core_factory(factory), - _bar_rect(factory->getRectangle()), - _amount_buttons(0), - _button_width(170) +MenuBar::MenuBar(const std::shared_ptr &factory) + : _core_factory(factory), _bar_rect(factory->getRectangle()), + _amount_buttons(0), _button_width(170) { _bar_rect->setColor(kku::Color{88, 57, 107, 255}); } @@ -18,10 +16,11 @@ void MenuBar::input(const kku::SystemEvent &event) case kku::SystemEvent::Type::MouseRelease: { - const auto position = std::get(event.data).position; + const auto position = + std::get(event.data).position; if (!isUnderMouse(position)) { - for (auto& submenu : _submenus) + for (auto &submenu : _submenus) submenu->unlock(); } break; @@ -31,7 +30,7 @@ void MenuBar::input(const kku::SystemEvent &event) Widget::input(event); } -void MenuBar::update(const kku::microsec& dt) +void MenuBar::update(const kku::microsec &dt) { Widget::update(dt); } @@ -44,58 +43,58 @@ void MenuBar::display() const Widget::display(); } -void MenuBar::setRect(const kku::Area& rect) +void MenuBar::setRect(const kku::Area &rect) { _bar_rect->setRect(rect); // Buttons will not resize } -void MenuBar::setPosition(const kku::Point& position) +void MenuBar::setPosition(const kku::Point &position) { _bar_rect->setPosition(position); } -void MenuBar::move(const kku::Vector2& delta) +void MenuBar::move(const kku::Vector2 &delta) { _bar_rect->move(delta); Widget::move(delta); - for (auto& menu : _submenus) + for (auto &menu : _submenus) menu->move(delta); } -bool MenuBar::isUnderMouse(const kku::Point& position) const +bool MenuBar::isUnderMouse(const kku::Point &position) const { bool bar_under_mouse = _bar_rect->contains(position); bool submenus_under_mouse = std::any_of(_children.begin(), _children.end(), - [p=position](const auto& child) - { - return child->isUnderMouse(p); - }); + [p = position](const auto &child) + { return child->isUnderMouse(p); }); return bar_under_mouse || submenus_under_mouse; } -void MenuBar::addRootSubMenu(std::string name, const std::shared_ptr& submenu) +void MenuBar::addRootSubMenu(std::string name, + const std::shared_ptr &submenu) { const auto new_button = std::make_shared(name, _core_factory); std::size_t current_index = _amount_buttons; - new_button->setRect(kku::Area{static_cast(current_index * _button_width), - 0.f, - static_cast(_button_width), - _bar_rect->getRect().height}); - new_button->setCallback([submenu=submenu]() - { - submenu->setVisibility(true); - submenu->lock(); - }); - - submenu->setPosition(kku::Point{static_cast(current_index * _button_width), - _bar_rect->getRect().height}); + new_button->setRect(kku::Area{ + static_cast(current_index * _button_width), 0.f, + static_cast(_button_width), _bar_rect->getRect().height}); + new_button->setCallback( + [submenu = submenu]() + { + submenu->setVisibility(true); + submenu->lock(); + }); + + submenu->setPosition( + kku::Point{static_cast(current_index * _button_width), + _bar_rect->getRect().height}); new_button->setColors(kku::Color{171, 141, 189, 255}, kku::Color{48, 27, 57, 255}); @@ -116,7 +115,7 @@ void MenuBar::setVisibility(bool is_visible) { Widget::setVisibility(is_visible); - for (auto& submenu : _submenus) + for (auto &submenu : _submenus) submenu->setVisibility(false); } diff --git a/src/application/src/widgets/menudrop.cpp b/src/application/src/widgets/menudrop.cpp index 8b6165f..c6e10a0 100644 --- a/src/application/src/widgets/menudrop.cpp +++ b/src/application/src/widgets/menudrop.cpp @@ -1,17 +1,15 @@ #include "menudrop.h" #include "core/corefactory.h" -MenuDrop::MenuDrop(const std::shared_ptr& factory) : - _is_locked(false), - _button_height(27), - _button_index(0) +MenuDrop::MenuDrop(const std::shared_ptr &factory) + : _is_locked(false), _button_height(27), _button_index(0) { _is_visible = false; _content_rect = factory->getRectangle(); _content_rect->setColor(kku::Color{200, 200, 200, 255}); } -void MenuDrop::input(const kku::SystemEvent& event) +void MenuDrop::input(const kku::SystemEvent &event) { if (!_is_visible) return; @@ -25,11 +23,12 @@ void MenuDrop::input(const kku::SystemEvent& event) case kku::SystemEvent::Type::MouseRelease: { - const auto position = std::get(event.data).position; + const auto position = + std::get(event.data).position; if (isUnderMouse(position)) { setVisibility(false); - for (auto& submenu : _submenus) + for (auto &submenu : _submenus) { submenu->unlock(); submenu->setVisibility(false); @@ -40,7 +39,8 @@ void MenuDrop::input(const kku::SystemEvent& event) case kku::SystemEvent::Type::MouseMove: { - const auto position = std::get(event.data).position; + const auto position = + std::get(event.data).position; if (!isUnderMouse(position)) { if (!isLocked() && !hasActiveSubmenus()) @@ -54,13 +54,11 @@ void MenuDrop::input(const kku::SystemEvent& event) bool MenuDrop::hasActiveSubmenus() const { return std::any_of(_submenus.begin(), _submenus.end(), - [](const auto& submenu) -> bool - { - return submenu->_is_visible; - }); + [](const auto &submenu) -> bool + { return submenu->_is_visible; }); } -void MenuDrop::update(const kku::microsec& dt) +void MenuDrop::update(const kku::microsec &dt) { Widget::update(dt); } @@ -73,27 +71,27 @@ void MenuDrop::display() const Widget::display(); } -void MenuDrop::setRect(const kku::Area& rect) +void MenuDrop::setRect(const kku::Area &rect) { _content_rect->setRect(rect); } -void MenuDrop::setPosition(const kku::Point& position) +void MenuDrop::setPosition(const kku::Point &position) { _content_rect->setPosition(position); } -void MenuDrop::move(const kku::Vector2& delta) +void MenuDrop::move(const kku::Vector2 &delta) { _content_rect->move(delta); Widget::move(delta); - for (auto& submenu : _submenus) + for (auto &submenu : _submenus) submenu->move(delta); } -bool MenuDrop::isUnderMouse(const kku::Point& position) const +bool MenuDrop::isUnderMouse(const kku::Point &position) const { return _is_visible && _content_rect->contains(position); } @@ -106,33 +104,34 @@ void MenuDrop::setVisibility(bool is_visible) _is_locked = false; } -void MenuDrop::addPushButton(const std::shared_ptr& button) +void MenuDrop::addPushButton(const std::shared_ptr &button) { add(button); } -void MenuDrop::addCascadeButton(const std::shared_ptr& button) +void MenuDrop::addCascadeButton( + const std::shared_ptr &button) { - auto& submenu = button->submenu(); + auto &submenu = button->submenu(); _submenus.emplace_back(submenu); add(button); submenu->setParent(_parent); } -void MenuDrop::addSeparator(const std::shared_ptr& separator) +void MenuDrop::addSeparator(const std::shared_ptr &separator) { add(separator); } void MenuDrop::add(const std::shared_ptr &widget) { - const auto& parent_rect = _content_rect->getRect(); + const auto &parent_rect = _content_rect->getRect(); - widget->setRect(kku::Area{parent_rect.left, - parent_rect.top + (parent_rect.height * _button_index), - parent_rect.width, - static_cast(_button_height)}); + widget->setRect(kku::Area{ + parent_rect.left, + parent_rect.top + (parent_rect.height * _button_index), + parent_rect.width, static_cast(_button_height)}); addChild(widget); ++_button_index; diff --git a/src/application/src/widgets/menuseparator.cpp b/src/application/src/widgets/menuseparator.cpp index cb7d8d9..4de5746 100644 --- a/src/application/src/widgets/menuseparator.cpp +++ b/src/application/src/widgets/menuseparator.cpp @@ -1,11 +1,11 @@ #include "menuseparator.h" -void MenuSeparator::input(const kku::SystemEvent& event) +void MenuSeparator::input(const kku::SystemEvent &event) { Widget::input(event); } -void MenuSeparator::update(const kku::microsec& dt) +void MenuSeparator::update(const kku::microsec &dt) { Widget::update(dt); } @@ -15,24 +15,24 @@ void MenuSeparator::display() const _line->display(); } -void MenuSeparator::setRect(const kku::Area& rect) +void MenuSeparator::setRect(const kku::Area &rect) { _rect = rect; //_line } -void MenuSeparator::setPosition(const kku::Point& position) +void MenuSeparator::setPosition(const kku::Point &position) { (void)position; } -void MenuSeparator::move(const kku::Vector2& delta) +void MenuSeparator::move(const kku::Vector2 &delta) { (void)delta; } -bool MenuSeparator::isUnderMouse(const kku::Point& position) const +bool MenuSeparator::isUnderMouse(const kku::Point &position) const { return _is_visible && _rect.contains(position); } diff --git a/src/application/src/widgets/pushbutton.cpp b/src/application/src/widgets/pushbutton.cpp index 8f3fc57..33b9cab 100644 --- a/src/application/src/widgets/pushbutton.cpp +++ b/src/application/src/widgets/pushbutton.cpp @@ -1,8 +1,9 @@ #include "pushbutton.h" -PushButton::PushButton(const std::string& text, const std::shared_ptr& factory, unsigned int font_size) : - Button(text, factory, font_size), - _pressed(false) +PushButton::PushButton(const std::string &text, + const std::shared_ptr &factory, + unsigned int font_size) + : Button(text, factory, font_size), _pressed(false) { _color_idle = kku::Color{230, 230, 230, 255}; _color_pressed = kku::Color{200, 200, 200, 255}; @@ -10,7 +11,7 @@ PushButton::PushButton(const std::string& text, const std::shared_ptrsetColor(_color_idle); } -void PushButton::input(const kku::SystemEvent& event) +void PushButton::input(const kku::SystemEvent &event) { switch (event.type) { @@ -19,7 +20,8 @@ void PushButton::input(const kku::SystemEvent& event) case kku::SystemEvent::Type::MousePress: { - const auto position = std::get(event.data).position; + const auto position = + std::get(event.data).position; if (isUnderMouse(position)) { _pressed = true; @@ -32,7 +34,8 @@ void PushButton::input(const kku::SystemEvent& event) { if (_pressed) { - const auto position = std::get(event.data).position; + const auto position = + std::get(event.data).position; _button_content->setColor(_color_idle); _pressed = false; if (isUnderMouse(position)) @@ -48,7 +51,7 @@ void PushButton::setCallback(kku::lambda callback) _on_click_callback = callback; } -void PushButton::setColors(kku::Color&& idle_color, kku::Color&& pressed_color) +void PushButton::setColors(kku::Color &&idle_color, kku::Color &&pressed_color) { _color_idle = idle_color; _color_pressed = pressed_color; diff --git a/src/application/src/widgets/widget.cpp b/src/application/src/widgets/widget.cpp index dc3a972..1f1b90b 100644 --- a/src/application/src/widgets/widget.cpp +++ b/src/application/src/widgets/widget.cpp @@ -7,33 +7,33 @@ void Widget::input(const kku::SystemEvent &event) _blocker->input(event); else { - for (auto& child : _children) + for (auto &child : _children) child->input(event); } } -void Widget::update(const kku::microsec& dt) +void Widget::update(const kku::microsec &dt) { - for (auto& child : _children) + for (auto &child : _children) child->update(dt); } void Widget::display() const { - for (const auto& child : _children) + for (const auto &child : _children) child->display(); } -void Widget::move(const kku::Vector2& delta) +void Widget::move(const kku::Vector2 &delta) { - for (auto& child : _children) + for (auto &child : _children) child->move(delta); } void Widget::setVisibility(bool is_visible) { _is_visible = is_visible; - for (auto& child : _children) + for (auto &child : _children) child->setVisibility(_is_visible); } @@ -42,7 +42,7 @@ bool Widget::isVisible() const return _is_visible; } -void Widget::addChild(const std::shared_ptr& child) +void Widget::addChild(const std::shared_ptr &child) { child->setParent(shared_from_this()); @@ -51,7 +51,7 @@ void Widget::addChild(const std::shared_ptr& child) _children.emplace_back(child); } -void Widget::setParent(const std::shared_ptr& parent) +void Widget::setParent(const std::shared_ptr &parent) { if (_parent != parent) { @@ -60,7 +60,7 @@ void Widget::setParent(const std::shared_ptr& parent) } } -void Widget::blockBy(const std::shared_ptr& blocker) +void Widget::blockBy(const std::shared_ptr &blocker) { _blocker = blocker; } diff --git a/src/application/src/widgets/window.cpp b/src/application/src/widgets/window.cpp index 2af79e9..054f825 100644 --- a/src/application/src/widgets/window.cpp +++ b/src/application/src/widgets/window.cpp @@ -1,8 +1,8 @@ #include "window.h" -Window::Window(const std::shared_ptr& factory, const std::string& title) : - _core_factory(factory), - _is_dragging(false) +Window::Window(const std::shared_ptr &factory, + const std::string &title) + : _core_factory(factory), _is_dragging(false) { _bar_title = _core_factory->getText(kku::Font::Id::GUI); _bar_title->setString(title); @@ -16,7 +16,7 @@ Window::Window(const std::shared_ptr& factory, const std::stri _window_content->setColor(kku::Color{188, 157, 207, 255}); } -void Window::input(const kku::SystemEvent& event) +void Window::input(const kku::SystemEvent &event) { Widget::input(event); @@ -27,7 +27,8 @@ void Window::input(const kku::SystemEvent& event) case kku::SystemEvent::Type::MousePress: { - const auto position = std::get(event.data).position; + const auto position = + std::get(event.data).position; if (_bar->contains(position)) { _is_dragging = true; @@ -42,7 +43,8 @@ void Window::input(const kku::SystemEvent& event) case kku::SystemEvent::Type::MouseMove: { - const auto position = std::get(event.data).position; + const auto position = + std::get(event.data).position; if (_is_dragging) { float x_mouse_diff = position.x - _previous_click_position.x; @@ -57,7 +59,7 @@ void Window::input(const kku::SystemEvent& event) } } -void Window::update(const kku::microsec& dt) +void Window::update(const kku::microsec &dt) { Widget::update(dt); } @@ -73,18 +75,17 @@ void Window::display() const } } -void Window::setRect(const kku::Area& rect) +void Window::setRect(const kku::Area &rect) { _window_content->setRect(rect); kku::Area bar_rect = {rect.left, rect.top, rect.width, 30}; _bar->setRect(bar_rect); - - _bar_title->setPosition(kku::Point{rect.left + 5, - rect.top + 5}); + + _bar_title->setPosition(kku::Point{rect.left + 5, rect.top + 5}); } -void Window::setPosition(const kku::Point& position) +void Window::setPosition(const kku::Point &position) { _window_content->setPosition(position); _bar->setPosition(position); @@ -94,7 +95,7 @@ void Window::setPosition(const kku::Point& position) _bar_title->setPosition(new_position); } -void Window::move(const kku::Vector2& delta) +void Window::move(const kku::Vector2 &delta) { _window_content->move(delta); _bar->move(delta); @@ -103,7 +104,7 @@ void Window::move(const kku::Vector2& delta) Widget::move(delta); } -bool Window::isUnderMouse(const kku::Point& position) const +bool Window::isUnderMouse(const kku::Point &position) const { return _is_visible && _window_content->contains(position); } @@ -114,8 +115,7 @@ void Window::addBarButton(const std::string &text, kku::lambda callback) auto b = std::make_shared(text, _core_factory, 20); b->setCallback(callback); - b->setRect({area.left + area.width - 35, - area.top, 30, 30}); + b->setRect({area.left + area.width - 35, area.top, 30, 30}); Widget::addChild(b); } diff --git a/src/impl/sfml/application/applicationsfml.cpp b/src/impl/sfml/application/applicationsfml.cpp index cc9ef2a..844f873 100644 --- a/src/impl/sfml/application/applicationsfml.cpp +++ b/src/impl/sfml/application/applicationsfml.cpp @@ -1,13 +1,13 @@ #include "applicationsfml.h" -#include "sfml/corefactorysfml.h" #include "sfml/application/inputconvertersfml.h" +#include "sfml/corefactorysfml.h" #include const sf::Time TIME_PER_FRAME = sf::seconds(1.f / 90.f); -ApplicationSFML::ApplicationSFML(sf::RenderWindow * const render_window) : - _render_window(render_window) +ApplicationSFML::ApplicationSFML(sf::RenderWindow *const render_window) + : _render_window(render_window) { _render_window->setFramerateLimit(60); _render_window->setKeyRepeatEnabled(false); @@ -21,7 +21,7 @@ void ApplicationSFML::display() { _render_window->clear(); - for (const auto& state : _state_stack) + for (const auto &state : _state_stack) state->display(); _render_window->display(); @@ -39,7 +39,7 @@ void ApplicationSFML::run() sf::Event event; while (_render_window->pollEvent(event)) { - switch(event.type) + switch (event.type) { case sf::Event::Closed: _render_window->close(); diff --git a/src/impl/sfml/application/applicationsfml.h b/src/impl/sfml/application/applicationsfml.h index 6a5c122..9c13d58 100644 --- a/src/impl/sfml/application/applicationsfml.h +++ b/src/impl/sfml/application/applicationsfml.h @@ -7,11 +7,11 @@ class ApplicationSFML : public Application { -public: - explicit ApplicationSFML(sf::RenderWindow * const _render_window); + public: + explicit ApplicationSFML(sf::RenderWindow *const _render_window); virtual void display() override; virtual void run() override; -private: - sf::RenderWindow * const _render_window; + private: + sf::RenderWindow *const _render_window; }; diff --git a/src/impl/sfml/application/inputconvertersfml.h b/src/impl/sfml/application/inputconvertersfml.h index 2261588..dfa1d75 100644 --- a/src/impl/sfml/application/inputconvertersfml.h +++ b/src/impl/sfml/application/inputconvertersfml.h @@ -11,7 +11,7 @@ constexpr kku::SystemEvent::Key::Code convert(sf::Keyboard::Key key) noexcept return kku::SystemEvent::Key::Code{int(key)}; } -constexpr kku::SystemEvent convert(const sf::Event& event) noexcept +constexpr kku::SystemEvent convert(const sf::Event &event) noexcept { switch (event.type) { @@ -19,120 +19,64 @@ constexpr kku::SystemEvent convert(const sf::Event& event) noexcept break; case sf::Event::Resized: - return kku::SystemEvent - { + return kku::SystemEvent{ kku::SystemEvent::Type::Resize, - kku::SystemEvent::Size - { - event.size.width, - event.size.height - } - }; + kku::SystemEvent::Size{event.size.width, event.size.height}}; case sf::Event::KeyPressed: - return kku::SystemEvent - { + return kku::SystemEvent{ kku::SystemEvent::Type::KeyPress, - kku::SystemEvent::Key - { - kku::convert(event.key.code), - event.key.alt, - event.key.control, - event.key.shift - } - }; + kku::SystemEvent::Key{kku::convert(event.key.code), event.key.alt, + event.key.control, event.key.shift}}; case sf::Event::KeyReleased: - return kku::SystemEvent - { + return kku::SystemEvent{ kku::SystemEvent::Type::KeyRelease, - kku::SystemEvent::Key - { - kku::convert(event.key.code), - event.key.alt, - event.key.control, - event.key.shift - } - }; + kku::SystemEvent::Key{kku::convert(event.key.code), event.key.alt, + event.key.control, event.key.shift}}; case sf::Event::MouseWheelScrolled: - return kku::SystemEvent - { + return kku::SystemEvent{ kku::SystemEvent::Type::MouseWheelScroll, - kku::SystemEvent::Mouse - { - kku::Point - { - event.mouseWheelScroll.x, - event.mouseWheelScroll.y - }, + kku::SystemEvent::Mouse{ + kku::Point{event.mouseWheelScroll.x, event.mouseWheelScroll.y}, (event.mouseWheelScroll.delta > 0), - kku::SystemEvent::Mouse::Button::Wheel - } - }; + kku::SystemEvent::Mouse::Button::Wheel}}; case sf::Event::MouseMoved: - return kku::SystemEvent - { + return kku::SystemEvent{ kku::SystemEvent::Type::MouseMove, - kku::SystemEvent::Mouse - { - kku::Point - { - event.mouseMove.x, - event.mouseMove.y - }, + kku::SystemEvent::Mouse{ + kku::Point{event.mouseMove.x, event.mouseMove.y}, - false, - kku::SystemEvent::Mouse::Button::None - } - }; + false, kku::SystemEvent::Mouse::Button::None}}; case sf::Event::MouseButtonPressed: - return kku::SystemEvent - { + return kku::SystemEvent{ kku::SystemEvent::Type::MousePress, - kku::SystemEvent::Mouse - { - kku::Point - { - event.mouseButton.x, - event.mouseButton.y - }, + kku::SystemEvent::Mouse{ + kku::Point{event.mouseButton.x, event.mouseButton.y}, false, ((event.mouseButton.button == sf::Mouse::Button::Left) - ? kku::SystemEvent::Mouse::Button::Left - : kku::SystemEvent::Mouse::Button::Right) - } - }; + ? kku::SystemEvent::Mouse::Button::Left + : kku::SystemEvent::Mouse::Button::Right)}}; case sf::Event::MouseButtonReleased: - return kku::SystemEvent - { + return kku::SystemEvent{ kku::SystemEvent::Type::MouseRelease, - kku::SystemEvent::Mouse - { - kku::Point - { - event.mouseButton.x, - event.mouseButton.y - }, + kku::SystemEvent::Mouse{ + kku::Point{event.mouseButton.x, event.mouseButton.y}, false, ((event.mouseButton.button == sf::Mouse::Button::Left) - ? kku::SystemEvent::Mouse::Button::Left - : kku::SystemEvent::Mouse::Button::Right) - } - }; + ? kku::SystemEvent::Mouse::Button::Left + : kku::SystemEvent::Mouse::Button::Right)}}; } - return kku::SystemEvent - { - kku::SystemEvent::Type::None, - kku::SystemEvent::None{} - }; + return kku::SystemEvent{kku::SystemEvent::Type::None, + kku::SystemEvent::None{}}; } -} +} // namespace kku diff --git a/src/impl/sfml/corefactorysfml.cpp b/src/impl/sfml/corefactorysfml.cpp index f8f2626..dea2644 100644 --- a/src/impl/sfml/corefactorysfml.cpp +++ b/src/impl/sfml/corefactorysfml.cpp @@ -1,13 +1,13 @@ #include "corefactorysfml.h" -#include "rectanglesfml.h" -#include "musicsfml.h" -#include "textsfml.h" #include "linesfml.h" +#include "musicsfml.h" +#include "rectanglesfml.h" #include "spritesfml.h" +#include "textsfml.h" -CoreFactorySFML::CoreFactorySFML(sf::RenderTarget * const render_target) : - _render_target(render_target) +CoreFactorySFML::CoreFactorySFML(sf::RenderTarget *const render_target) + : _render_target(render_target) { auto gui_font = std::make_unique(); gui_font->loadFromFile("resources/SourceCodePro-Regular.ttf"); @@ -33,13 +33,14 @@ std::shared_ptr CoreFactorySFML::getRectangle() const return std::make_unique(_render_target); } - std::shared_ptr CoreFactorySFML::getLine() const - { - return std::make_unique(_render_target); - } +std::shared_ptr CoreFactorySFML::getLine() const +{ + return std::make_unique(_render_target); +} - std::shared_ptr CoreFactorySFML::getSprite(kku::GUISprite::Id id) const - { +std::shared_ptr +CoreFactorySFML::getSprite(kku::GUISprite::Id id) const +{ const auto texture = _texture_holder.get(kku::Texture::Id::GUI); switch (id) { @@ -48,16 +49,18 @@ std::shared_ptr CoreFactorySFML::getRectangle() const break; case kku::GUISprite::Id::SFML_LOGO: - return std::make_unique(_render_target, _texture_holder.get(kku::Texture::Id::GUI), - kku::Area{0, 0, 252, 81}); + return std::make_unique( + _render_target, _texture_holder.get(kku::Texture::Id::GUI), + kku::Area{0, 0, 252, 81}); break; case kku::GUISprite::Id::CRYPTOPP_LOGO: - return std::make_unique(_render_target, _texture_holder.get(kku::Texture::Id::GUI), - kku::Area{252, 0, 135, 36}); + return std::make_unique( + _render_target, _texture_holder.get(kku::Texture::Id::GUI), + kku::Area{252, 0, 135, 36}); break; } - } +} kku::Vector2 CoreFactorySFML::getRenderSize() const { diff --git a/src/impl/sfml/corefactorysfml.h b/src/impl/sfml/corefactorysfml.h index 5592466..0d0c4da 100644 --- a/src/impl/sfml/corefactorysfml.h +++ b/src/impl/sfml/corefactorysfml.h @@ -1,8 +1,8 @@ #pragma once +#include #include #include -#include #include #include @@ -10,17 +10,18 @@ class CoreFactorySFML : public kku::CoreFactory { -public: - explicit CoreFactorySFML(sf::RenderTarget * const render_target); + public: + explicit CoreFactorySFML(sf::RenderTarget *const render_target); virtual std::shared_ptr getMusic() const override; virtual std::shared_ptr getText(kku::Font::Id id) const override; virtual std::shared_ptr getRectangle() const override; virtual std::shared_ptr getLine() const override; - virtual std::shared_ptr getSprite(kku::GUISprite::Id id) const override; + virtual std::shared_ptr + getSprite(kku::GUISprite::Id id) const override; virtual kku::Vector2 getRenderSize() const override; -private: - sf::RenderTarget * const _render_target; + private: + sf::RenderTarget *const _render_target; kku::ResourceHolder _font_holder; kku::ResourceHolder _texture_holder; }; diff --git a/src/impl/sfml/linesfml.cpp b/src/impl/sfml/linesfml.cpp index e3ae567..276946b 100644 --- a/src/impl/sfml/linesfml.cpp +++ b/src/impl/sfml/linesfml.cpp @@ -1,18 +1,18 @@ #include "linesfml.h" -LineSFML::LineSFML(sf::RenderTarget * const render_target) : - _render_target(render_target) +LineSFML::LineSFML(sf::RenderTarget *const render_target) + : _render_target(render_target) { _vertex = sf::VertexArray(sf::LinesStrip, 2); } -void LineSFML::setPosition(const kku::Point& p1, const kku::Point& p2) +void LineSFML::setPosition(const kku::Point &p1, const kku::Point &p2) { _vertex[0].position = {p1.x, p1.y}; _vertex[1].position = {p2.x, p2.y}; } -void LineSFML::setColor(const kku::Color& c1, const kku::Color& c2) +void LineSFML::setColor(const kku::Color &c1, const kku::Color &c2) { _vertex[0].color = sf::Color{c1.red, c1.green, c1.blue, c1.alpha}; _vertex[1].color = sf::Color{c2.red, c2.green, c2.blue, c2.alpha}; diff --git a/src/impl/sfml/linesfml.h b/src/impl/sfml/linesfml.h index 2f12083..e3824d6 100644 --- a/src/impl/sfml/linesfml.h +++ b/src/impl/sfml/linesfml.h @@ -8,13 +8,14 @@ class LineSFML : public kku::Line { -public: - explicit LineSFML(sf::RenderTarget * const render_target); - virtual void setPosition(const kku::Point& p1, const kku::Point& p2) override; - virtual void setColor(const kku::Color& c1, const kku::Color& c2) override; + public: + explicit LineSFML(sf::RenderTarget *const render_target); + virtual void setPosition(const kku::Point &p1, + const kku::Point &p2) override; + virtual void setColor(const kku::Color &c1, const kku::Color &c2) override; virtual void display() override; -private: - sf::RenderTarget * const _render_target; + private: + sf::RenderTarget *const _render_target; sf::VertexArray _vertex; }; diff --git a/src/impl/sfml/musicsfml.cpp b/src/impl/sfml/musicsfml.cpp index 9b54f54..9aa62ac 100644 --- a/src/impl/sfml/musicsfml.cpp +++ b/src/impl/sfml/musicsfml.cpp @@ -1,12 +1,11 @@ #include "musicsfml.h" -MusicSFML::MusicSFML() : - _sfml_music_offset(0), - _previous_frame_offset(0), - _absolute_offset(0) -{} +MusicSFML::MusicSFML() + : _sfml_music_offset(0), _previous_frame_offset(0), _absolute_offset(0) +{ +} -bool MusicSFML::open(const std::string& filepath) +bool MusicSFML::open(const std::string &filepath) { return _music.openFromFile(filepath); } @@ -37,7 +36,7 @@ void MusicSFML::setVolume(float volume) _music.setVolume(volume); } -void MusicSFML::setOffset(const kku::microsec& offset) +void MusicSFML::setOffset(const kku::microsec &offset) { //_previous_frame_offset += (offset - _absolute_offset); _music.setPlayingOffset(sf::microseconds(offset)); @@ -48,7 +47,8 @@ kku::microsec MusicSFML::fetchOffset() if (_music.getStatus() != sf::Music::Status::Playing) return _absolute_offset; - const auto interpolator_timestamp = _offset_interpolator.getElapsedTime().asMicroseconds(); + const auto interpolator_timestamp = + _offset_interpolator.getElapsedTime().asMicroseconds(); const auto sfml_new_offset = _music.getPlayingOffset().asMicroseconds(); _absolute_offset += (interpolator_timestamp - _previous_frame_offset); @@ -62,7 +62,7 @@ kku::microsec MusicSFML::fetchOffset() return _absolute_offset; } -void MusicSFML::moveOffset(const kku::microsec& delta) +void MusicSFML::moveOffset(const kku::microsec &delta) { const auto offset = fetchOffset(); const auto result = offset + delta; @@ -86,4 +86,3 @@ kku::microsec MusicSFML::getDuration() const { return _music.getDuration().asMicroseconds(); } - diff --git a/src/impl/sfml/musicsfml.h b/src/impl/sfml/musicsfml.h index 8327dd6..27f5449 100644 --- a/src/impl/sfml/musicsfml.h +++ b/src/impl/sfml/musicsfml.h @@ -7,9 +7,9 @@ class MusicSFML : public kku::Music { -public: + public: explicit MusicSFML(); - virtual bool open(const std::string& filepath) override; + virtual bool open(const std::string &filepath) override; virtual void play() override; virtual void pause() override; @@ -19,13 +19,13 @@ public: virtual void setVolume(float volume) override; - virtual void setOffset(const kku::microsec& offset) override; - virtual void moveOffset(const kku::microsec& delta) override; + virtual void setOffset(const kku::microsec &offset) override; + virtual void moveOffset(const kku::microsec &delta) override; virtual kku::microsec fetchOffset() override; virtual kku::microsec getDuration() const override; -private: + private: sf::Music _music; sf::Clock _offset_interpolator; diff --git a/src/impl/sfml/rectanglesfml.cpp b/src/impl/sfml/rectanglesfml.cpp index b828182..542c8ce 100644 --- a/src/impl/sfml/rectanglesfml.cpp +++ b/src/impl/sfml/rectanglesfml.cpp @@ -1,10 +1,11 @@ #include "rectanglesfml.h" -RectangleSFML::RectangleSFML(sf::RenderTarget * const render_target) : - _render_target(render_target) -{} +RectangleSFML::RectangleSFML(sf::RenderTarget *const render_target) + : _render_target(render_target) +{ +} -void RectangleSFML::setRect(const kku::Area& rect) +void RectangleSFML::setRect(const kku::Area &rect) { _rectangle.setPosition(rect.left, rect.top); _rectangle.setSize({rect.width, rect.height}); @@ -18,12 +19,12 @@ kku::Area RectangleSFML::getRect() const return kku::Area{position.x, position.y, size.x, size.y}; } -void RectangleSFML::move(const kku::Vector2& delta) +void RectangleSFML::move(const kku::Vector2 &delta) { _rectangle.move({delta.first, delta.second}); } -void RectangleSFML::setPosition(const kku::Point& position) +void RectangleSFML::setPosition(const kku::Point &position) { _rectangle.setPosition({position.x, position.y}); } @@ -34,10 +35,10 @@ kku::Point RectangleSFML::getPosition() const return kku::Point{position.x, position.y}; } -void RectangleSFML::setColor(const kku::Color& color) +void RectangleSFML::setColor(const kku::Color &color) { - _rectangle.setFillColor(sf::Color{color.red, color.green, - color.blue, color.alpha}); + _rectangle.setFillColor( + sf::Color{color.red, color.green, color.blue, color.alpha}); } kku::Color RectangleSFML::getColor() const @@ -46,7 +47,7 @@ kku::Color RectangleSFML::getColor() const return kku::Color{color.r, color.g, color.b, color.a}; } -bool RectangleSFML::contains(const kku::Point& position) const +bool RectangleSFML::contains(const kku::Point &position) const { return _rectangle.getGlobalBounds().contains(position.x, position.y); } diff --git a/src/impl/sfml/rectanglesfml.h b/src/impl/sfml/rectanglesfml.h index 03a26b1..8ae8733 100644 --- a/src/impl/sfml/rectanglesfml.h +++ b/src/impl/sfml/rectanglesfml.h @@ -1,29 +1,29 @@ #pragma once -#include #include +#include #include #include "core/rectangle.h" class RectangleSFML : public kku::Rectangle { -public: - explicit RectangleSFML(sf::RenderTarget * const render_target); - virtual void setRect(const kku::Area& rect) override; + public: + explicit RectangleSFML(sf::RenderTarget *const render_target); + virtual void setRect(const kku::Area &rect) override; virtual kku::Area getRect() const override; - virtual void setPosition(const kku::Point& position) override; + virtual void setPosition(const kku::Point &position) override; virtual kku::Point getPosition() const override; - virtual void move(const kku::Vector2& delta) override; + virtual void move(const kku::Vector2 &delta) override; - virtual void setColor(const kku::Color& color) override; + virtual void setColor(const kku::Color &color) override; virtual kku::Color getColor() const override; - virtual bool contains(const kku::Point& position) const override; + virtual bool contains(const kku::Point &position) const override; virtual void display() override; -private: - sf::RenderTarget * const _render_target; + private: + sf::RenderTarget *const _render_target; sf::RectangleShape _rectangle; }; diff --git a/src/impl/sfml/spritesfml.cpp b/src/impl/sfml/spritesfml.cpp index dc0706b..be47f11 100644 --- a/src/impl/sfml/spritesfml.cpp +++ b/src/impl/sfml/spritesfml.cpp @@ -1,28 +1,26 @@ #include "spritesfml.h" -SpriteSFML::SpriteSFML(sf::RenderTarget * const render_target, - const std::shared_ptr& texture, - const kku::Area &cropping) : - _render_target(render_target), - _sprite(*texture, sf::IntRect(cropping.left, cropping.top, cropping.width, cropping.height)) -{} +SpriteSFML::SpriteSFML(sf::RenderTarget *const render_target, + const std::shared_ptr &texture, + const kku::Area &cropping) + : _render_target(render_target), + _sprite(*texture, sf::IntRect(cropping.left, cropping.top, cropping.width, + cropping.height)) +{ +} -void SpriteSFML::setPosition(const kku::Point& position) +void SpriteSFML::setPosition(const kku::Point &position) { _sprite.setPosition(position.x, position.y); } kku::Point SpriteSFML::getPosition() const { - const auto& position = _sprite.getPosition(); - return kku::Point - { - position.x, - position.y - }; + const auto &position = _sprite.getPosition(); + return kku::Point{position.x, position.y}; } -void SpriteSFML::move(const kku::Vector2& delta) +void SpriteSFML::move(const kku::Vector2 &delta) { _sprite.move({delta.first, delta.second}); } diff --git a/src/impl/sfml/spritesfml.h b/src/impl/sfml/spritesfml.h index e7310f9..8c05245 100644 --- a/src/impl/sfml/spritesfml.h +++ b/src/impl/sfml/spritesfml.h @@ -4,22 +4,23 @@ #include #include +#include "core/area.h" #include "core/sprite.h" class SpriteSFML : public kku::Sprite { -public: - explicit SpriteSFML(sf::RenderTarget * const render_target, + public: + explicit SpriteSFML(sf::RenderTarget *const render_target, const std::shared_ptr &texture, - const kku::Area& cropping); + const kku::Area &cropping); - virtual void setPosition(const kku::Point& position) override; + virtual void setPosition(const kku::Point &position) override; virtual kku::Point getPosition() const override; - virtual void move(const kku::Vector2& delta) override; + virtual void move(const kku::Vector2 &delta) override; virtual void display() const override; -protected: - sf::RenderTarget * const _render_target; + protected: + sf::RenderTarget *const _render_target; sf::Sprite _sprite; }; diff --git a/src/impl/sfml/textsfml.cpp b/src/impl/sfml/textsfml.cpp index 2aa11c6..c3acdc7 100644 --- a/src/impl/sfml/textsfml.cpp +++ b/src/impl/sfml/textsfml.cpp @@ -1,13 +1,13 @@ #include "textsfml.h" -TextSFML::TextSFML(sf::RenderTarget * const render_target, - const std::shared_ptr& font) : - _render_target(render_target) +TextSFML::TextSFML(sf::RenderTarget *const render_target, + const std::shared_ptr &font) + : _render_target(render_target) { _text.setFont(*font); } -void TextSFML::setString(const std::string& string) +void TextSFML::setString(const std::string &string) { _text.setString(string); } @@ -17,19 +17,20 @@ void TextSFML::setCharacterSize(std::size_t pixels) _text.setCharacterSize(pixels); } -void TextSFML::setPosition(const kku::Point& point) +void TextSFML::setPosition(const kku::Point &point) { _text.setPosition(point.x, point.y); } -void TextSFML::move(const kku::Vector2& delta) +void TextSFML::move(const kku::Vector2 &delta) { _text.move({delta.first, delta.second}); } -void TextSFML::setColor(const kku::Color& color) +void TextSFML::setColor(const kku::Color &color) { - _text.setFillColor(sf::Color{color.red, color.green, color.blue, color.alpha}); + _text.setFillColor( + sf::Color{color.red, color.green, color.blue, color.alpha}); } void TextSFML::display() diff --git a/src/impl/sfml/textsfml.h b/src/impl/sfml/textsfml.h index aecbc98..97248b5 100644 --- a/src/impl/sfml/textsfml.h +++ b/src/impl/sfml/textsfml.h @@ -1,27 +1,27 @@ #pragma once +#include #include #include -#include #include #include "core/text.h" class TextSFML : public kku::Text { -public: - explicit TextSFML(sf::RenderTarget * const render_target, - const std::shared_ptr& font); + public: + explicit TextSFML(sf::RenderTarget *const render_target, + const std::shared_ptr &font); - virtual void setString(const std::string& string) override; + virtual void setString(const std::string &string) override; virtual void setCharacterSize(std::size_t pixels) override; - virtual void setPosition(const kku::Point& point) override; - virtual void move(const kku::Vector2& delta) override; - virtual void setColor(const kku::Color& color) override; + virtual void setPosition(const kku::Point &point) override; + virtual void move(const kku::Vector2 &delta) override; + virtual void setColor(const kku::Color &color) override; virtual void display() override; -protected: - sf::RenderTarget * const _render_target; + protected: + sf::RenderTarget *const _render_target; sf::Text _text; }; diff --git a/src/main.cpp b/src/main.cpp index c295739..276d0b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,10 @@ #include "application/applicationsfml.h" int main() -{ - sf::RenderWindow window(sf::VideoMode{1280, 720}, "Project Kyoku", sf::Style::Default); +{ + sf::RenderWindow window(sf::VideoMode{1280, 720}, "Project Kyoku", + sf::Style::Default); + ApplicationSFML app(&window); if (app.init()) app.run(); diff --git a/src/modes/classicmode/classicfactory.cpp b/src/modes/classicmode/classicfactory.cpp index 90a72bf..930d234 100644 --- a/src/modes/classicmode/classicfactory.cpp +++ b/src/modes/classicmode/classicfactory.cpp @@ -1,44 +1,53 @@ #include "classicmode/classicfactory.h" +#include "graphics/classicgraphicsfactory.h" #include "graphics/classicscenegraphicsmanager.h" #include "graphics/classictimelinegraphicsmanager.h" -#include "graphics/classicgraphicsfactory.h" #include "core/timeline.h" -#include "game/classicgame.h" -#include "game/gamecontext.h" -#include "game/holdmanager.h" #include "editor/classiceditor.h" #include "editor/editorcontext.h" #include "editor/selectionmanager.h" +#include "game/classicgame.h" +#include "game/gamecontext.h" +#include "game/holdmanager.h" - -std::unique_ptr classic::getGame(const std::shared_ptr& core_factory) +std::unique_ptr +classic::getGame(const std::shared_ptr &core_factory) { const kku::microsec visibility_offset = 1648648; const auto factory = std::make_shared(core_factory); const auto timeline = std::make_shared>(); - const auto graphics_manager = std::make_shared(timeline, factory, visibility_offset); + const auto graphics_manager = std::make_shared( + timeline, factory, visibility_offset); const auto hold_manager = std::make_shared(); - const auto context = std::make_shared(hold_manager, graphics_manager); + const auto context = + std::make_shared(hold_manager, graphics_manager); return std::make_unique(timeline, context); } -std::unique_ptr classic::getEditor(const std::shared_ptr& core_factory) +std::unique_ptr +classic::getEditor(const std::shared_ptr &core_factory) { const kku::microsec visibility_offset = 1648648; const auto factory = std::make_shared(core_factory); const auto timeline = std::make_shared>(); - const auto selection_manager = std::make_shared>(); + const auto selection_manager = + std::make_shared>(); std::vector> graphics_managers; - graphics_managers.emplace_back(std::make_shared(timeline, factory, visibility_offset)); - graphics_managers.emplace_back(std::make_shared(timeline, factory, visibility_offset * 2)); - - const auto context = std::make_shared(selection_manager, std::move(graphics_managers)); + graphics_managers.emplace_back( + std::make_shared(timeline, factory, + visibility_offset)); + graphics_managers.emplace_back( + std::make_shared( + timeline, factory, visibility_offset * 2)); + + const auto context = std::make_shared( + selection_manager, std::move(graphics_managers)); return std::make_unique(timeline, context); } diff --git a/src/modes/classicmode/classicnote.cpp b/src/modes/classicmode/classicnote.cpp index 76d4aea..c4afe98 100644 --- a/src/modes/classicmode/classicnote.cpp +++ b/src/modes/classicmode/classicnote.cpp @@ -1,10 +1,9 @@ #include "classicmode/classicnote.h" -ClassicNote::ClassicNote(const kku::microsec& perfect_offset, int id) : - Note(perfect_offset), - _state(State::NONE), - _id(id) -{} +ClassicNote::ClassicNote(const kku::microsec &perfect_offset, int id) + : Note(perfect_offset), _state(State::NONE), _id(id) +{ +} void ClassicNote::setState(ClassicNote::State state) noexcept { diff --git a/src/modes/classicmode/editor/callbacks/callbacksimple.cpp b/src/modes/classicmode/editor/callbacks/callbacksimple.cpp index dde6d47..e6f0187 100644 --- a/src/modes/classicmode/editor/callbacks/callbacksimple.cpp +++ b/src/modes/classicmode/editor/callbacks/callbacksimple.cpp @@ -1,10 +1,10 @@ #include "callbacksimple.h" -CallbackSimple::CallbackSimple(Init&& init, Metadata&& metadata) : - _run(std::move(init.run)), - _is_enabled(std::move(init.is_enabled)), - _metadata(std::move(metadata)) -{} +CallbackSimple::CallbackSimple(Init &&init, Metadata &&metadata) + : _run(std::move(init.run)), _is_enabled(std::move(init.is_enabled)), + _metadata(std::move(metadata)) +{ +} bool CallbackSimple::isEnabled() const { diff --git a/src/modes/classicmode/editor/classiceditor.cpp b/src/modes/classicmode/editor/classiceditor.cpp index ee0490d..2b5c878 100644 --- a/src/modes/classicmode/editor/classiceditor.cpp +++ b/src/modes/classicmode/editor/classiceditor.cpp @@ -1,37 +1,35 @@ #include "classiceditor.h" -#include "graphics/classicgraphicsmanager.h" #include "editor/selectionmanager.h" +#include "graphics/classicgraphicsmanager.h" // Replace with interface by dependency injection -#include "graphics/animations/classicflyinganimationscenario.h" #include "graphics/animations/classicdyinganimationscenario.h" +#include "graphics/animations/classicflyinganimationscenario.h" // -#include "game/classicarrownote.h" -#include "editorcontext.h" #include "callbacks/callbacksimple.h" +#include "editorcontext.h" +#include "game/classicarrownote.h" -ClassicEditor::ClassicEditor(const std::shared_ptr>& timeline, - const std::shared_ptr& context) : - _timeline(timeline), - _context(context), - _selected_type(Type::UP), - _current_time(0), - _scroll_step(500000), - _note_id(0) +ClassicEditor::ClassicEditor( + const std::shared_ptr> &timeline, + const std::shared_ptr &context) + : _timeline(timeline), _context(context), _selected_type(Type::UP), + _current_time(0), _scroll_step(500000), _note_id(0) { kku::microsec starting_beat_offset = 402162; int amount_of_beats = 209; kku::microsec interval = 1412162; kku::microsec tempo_interval = interval / 4; kku::microsec note_input_offset = 412162 / 2; - //microsec note_input_offset_fast = 412162 / 6; + // microsec note_input_offset_fast = 412162 / 6; kku::microsec bpm_iterator = starting_beat_offset; kku::microsec bpm_end = starting_beat_offset + (interval * amount_of_beats); - std::vector input_intervals = {note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset}; - std::set notes; + std::vector input_intervals = { + note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset}; + std::set notes; input_intervals.shrink_to_fit(); bpm_iterator += tempo_interval; @@ -75,15 +73,8 @@ ClassicEditor::ClassicEditor(const std::shared_ptr>& --counter; - ClassicArrowNote::Init init - { - _note_id++, - context, - bpm_iterator, - input_intervals, - {element}, - hold - }; + ClassicArrowNote::Init init{_note_id++, context, bpm_iterator, + input_intervals, {element}, hold}; notes.insert(new ClassicArrowNote(std::move(init))); @@ -99,16 +90,16 @@ ClassicEditor::ClassicEditor(const std::shared_ptr>& kku::microsec ClassicEditor::adjustOffset(kku::microsec offset) const noexcept { - const auto& section = getBPMSectionAt(offset); + const auto §ion = getBPMSectionAt(offset); const kku::microsec actual_offset = offset - section.offset_start; return actual_offset + (actual_offset % (section.interval + 1)); } -void ClassicEditor::input(kku::GameEvent&& input) +void ClassicEditor::input(kku::GameEvent &&input) { _current_time = input.timestamp; - const auto& event = input.event; + const auto &event = input.event; switch (input.event.type) { @@ -139,11 +130,13 @@ void ClassicEditor::input(kku::GameEvent&& input) case kku::SystemEvent::Type::MousePress: { const auto note = _timeline->getNoteBy(_current_time); - if (_timeline->isExpired(note) && !_bpm_sections.empty() && _current_time >= (*_bpm_sections.begin()).offset_start) + if (_timeline->isExpired(note) && !_bpm_sections.empty() && + _current_time >= (*_bpm_sections.begin()).offset_start) { ArrowElement element; - element.position = std::get(event.data).position; + element.position = + std::get(event.data).position; element.falling_curve_interpolation = {}; element.keys = {kku::SystemEvent::Key::Code::W, @@ -151,15 +144,8 @@ void ClassicEditor::input(kku::GameEvent&& input) element.type = Type::UP; - ClassicArrowNote::Init init - { - _note_id++, - _context, - _current_time, - {}, - {element}, - false - }; + ClassicArrowNote::Init init{_note_id++, _context, _current_time, + {}, {element}, false}; _timeline->insertNote(new ClassicArrowNote(std::move(init))); } @@ -176,7 +162,7 @@ void ClassicEditor::input(kku::GameEvent&& input) _context->inputUI(std::move(input)); } -void ClassicEditor::update(kku::UpdateData&& updatedata) +void ClassicEditor::update(kku::UpdateData &&updatedata) { _timeline->update(updatedata.timestamp); _context->updateGraphics(updatedata.timestamp); @@ -187,7 +173,7 @@ void ClassicEditor::display() const _context->displayGraphics(); } -void ClassicEditor::recalculate(const kku::microsec& timestamp) +void ClassicEditor::recalculate(const kku::microsec ×tamp) { _timeline->recalculate(timestamp); } diff --git a/src/modes/classicmode/editor/editorcontext.cpp b/src/modes/classicmode/editor/editorcontext.cpp index b69ceb8..6160f24 100644 --- a/src/modes/classicmode/editor/editorcontext.cpp +++ b/src/modes/classicmode/editor/editorcontext.cpp @@ -4,13 +4,15 @@ #include "graphics/classicgraphicsmanager.h" #include "graphics/classicnotegraphics.h" -EditorContext::EditorContext(const std::shared_ptr>& selection_manager, - std::vector>&& graphics_managers) : - _selection_manager(selection_manager), - _graphics_managers(std::move(graphics_managers)) -{} +EditorContext::EditorContext( + const std::shared_ptr> &selection_manager, + std::vector> &&graphics_managers) + : _selection_manager(selection_manager), + _graphics_managers(std::move(graphics_managers)) +{ +} -void EditorContext::input(ClassicArrowNote *note, kku::GameEvent&& input) const +void EditorContext::input(ClassicArrowNote *note, kku::GameEvent &&input) const { (void)note; switch (input.event.type) @@ -19,58 +21,62 @@ void EditorContext::input(ClassicArrowNote *note, kku::GameEvent&& input) const default: break; - /*case kku::SystemEvent::Type::MousePress: - { - bool selection_changed = false; - std::size_t amount_selected = 0; - - const auto position = std::get(input.event.data).position; - for (auto& element : note->getElements()) + /*case kku::SystemEvent::Type::MousePress: { - if (element.sprite->getRectangle()->contains(position)) + bool selection_changed = false; + std::size_t amount_selected = 0; + + const auto position = + std::get(input.event.data).position; for (auto& + element : note->getElements()) { - element.selected = !element.selected; - selection_changed = true; - if (element.selected) - ++amount_selected; + if (element.sprite->getRectangle()->contains(position)) + { + element.selected = !element.selected; + selection_changed = true; + if (element.selected) + ++amount_selected; + } } - } - if (selection_changed) - { - if (amount_selected > 0) - _selection_manager->fetch(note); - else - _selection_manager->remove(note); - } - - break; - }*/ + if (selection_changed) + { + if (amount_selected > 0) + _selection_manager->fetch(note); + else + _selection_manager->remove(note); + } + break; + }*/ } } -void EditorContext::update(ClassicArrowNote *note, const kku::microsec& music_offset) const +void EditorContext::update(ClassicArrowNote *note, + const kku::microsec &music_offset) const { - auto& elements = note->getElements(); + auto &elements = note->getElements(); switch (note->getState()) { - default: return; + default: + return; break; case ClassicArrowNote::State::INITIAL: note->setState(ClassicArrowNote::State::FLYING); - for (auto& manager : _graphics_managers) + for (auto &manager : _graphics_managers) manager->update(music_offset, note); break; case ClassicArrowNote::State::FLYING: - if (!note->isActive(music_offset) && music_offset > note->getPerfectOffset()) + if (!note->isActive(music_offset) && + music_offset > note->getPerfectOffset()) { note->setState(ClassicArrowNote::State::DYING); - for (auto& element : elements) - element.animations[note->getState()]->launch(element.sprite, music_offset, note->getPerfectOffset()); + for (auto &element : elements) + element.animations[note->getState()]->launch( + element.sprite, music_offset, note->getPerfectOffset()); } break; @@ -78,36 +84,37 @@ void EditorContext::update(ClassicArrowNote *note, const kku::microsec& music_of if (elements[0].animations[note->getState()]->isDone()) { note->setState(ClassicArrowNote::State::DEAD); - for (auto& manager : _graphics_managers) + for (auto &manager : _graphics_managers) manager->update(music_offset, note); } break; } - for (auto& element : elements) + for (auto &element : elements) if (element.animations[note->getState()]) element.animations[note->getState()]->update(music_offset); } -std::shared_ptr> EditorContext::getSelectionManager() const +std::shared_ptr> +EditorContext::getSelectionManager() const { return _selection_manager; } -void EditorContext::inputUI(kku::GameEvent&& input) +void EditorContext::inputUI(kku::GameEvent &&input) { - for (auto& manager : _graphics_managers) + for (auto &manager : _graphics_managers) manager->input(std::move(input)); } -void EditorContext::updateGraphics(const kku::microsec& music_offset) +void EditorContext::updateGraphics(const kku::microsec &music_offset) { - for (auto& manager : _graphics_managers) + for (auto &manager : _graphics_managers) manager->update(music_offset); } void EditorContext::displayGraphics() const { - for (const auto& manager : _graphics_managers) + for (const auto &manager : _graphics_managers) manager->display(); } diff --git a/src/modes/classicmode/game/classicarrownote.cpp b/src/modes/classicmode/game/classicarrownote.cpp index 38a51fa..8080fda 100644 --- a/src/modes/classicmode/game/classicarrownote.cpp +++ b/src/modes/classicmode/game/classicarrownote.cpp @@ -2,26 +2,24 @@ #include "classicmode/context.h" #include "graphics/classicgraphicsmanager.h" -ClassicArrowNote::ClassicArrowNote(Init&& init) : - ClassicNote(init.perfect_offset, init.id), - _evaluator(init.intervals, init.perfect_offset), - _context(init.context), - _is_holding(init.is_holding) +ClassicArrowNote::ClassicArrowNote(Init &&init) + : ClassicNote(init.perfect_offset, init.id), + _evaluator(init.intervals, init.perfect_offset), _context(init.context), + _is_holding(init.is_holding) { - _elements.resize(init.elements.size()); + _elements.resize(init.elements.size()); - for (std::size_t i = 0; i < _elements.size(); ++i) - { - _elements[i].keys = init.elements[i].keys; - _elements[i].position = init.elements[i].position; - _elements[i].type = init.elements[i].type; - } + for (std::size_t i = 0; i < _elements.size(); ++i) + { + _elements[i].keys = init.elements[i].keys; + _elements[i].position = init.elements[i].position; + _elements[i].type = init.elements[i].type; + } } -bool ClassicArrowNote::isActive(const kku::microsec& offset) const +bool ClassicArrowNote::isActive(const kku::microsec &offset) const { - return _evaluator.isActive(offset) - && _state != State::DYING; + return _evaluator.isActive(offset) && _state != State::DYING; } void ClassicArrowNote::update(const kku::microsec &music_offset) @@ -29,12 +27,13 @@ void ClassicArrowNote::update(const kku::microsec &music_offset) _context->update(this, music_offset); } -void ClassicArrowNote::input(kku::GameEvent&& input) +void ClassicArrowNote::input(kku::GameEvent &&input) { _context->input(this, std::move(input)); } -void ClassicArrowNote::draw(const std::shared_ptr& graphics_manager) const +void ClassicArrowNote::draw( + const std::shared_ptr &graphics_manager) const { graphics_manager->draw(this); } @@ -44,17 +43,18 @@ bool ClassicArrowNote::isHold() const return _is_holding; } -std::vector& ClassicArrowNote::getElements() +std::vector &ClassicArrowNote::getElements() { return _elements; } -const std::vector& ClassicArrowNote::getElements() const +const std::vector &ClassicArrowNote::getElements() const { return _elements; } -auto ClassicArrowNote::calculatePrecision(const kku::microsec& offset) const -> Grade +auto ClassicArrowNote::calculatePrecision(const kku::microsec &offset) const + -> Grade { return _evaluator.calculatePrecision(offset); } @@ -62,8 +62,6 @@ auto ClassicArrowNote::calculatePrecision(const kku::microsec& offset) const -> bool ClassicArrowNote::isPressedAs(kku::SystemEvent::Key::Code key) const { return std::any_of(_elements.begin(), _elements.end(), - [key](const auto& element) - { - return key == element.pressed_as; - }); + [key](const auto &element) + { return key == element.pressed_as; }); } diff --git a/src/modes/classicmode/game/classicgame.cpp b/src/modes/classicmode/game/classicgame.cpp index e1a9138..d3808f7 100644 --- a/src/modes/classicmode/game/classicgame.cpp +++ b/src/modes/classicmode/game/classicgame.cpp @@ -1,15 +1,16 @@ #include "classicgame.h" -#include "classicmode/classicnote.h" #include "classicmapcreator.h" +#include "classicmode/classicnote.h" #include "gamecontext.h" -#include "holdmanager.h" #include "graphics/classicgraphicsmanager.h" +#include "holdmanager.h" -ClassicGame::ClassicGame(const std::shared_ptr>& timeline, - const std::shared_ptr& context) : - _timeline(timeline), - _context(context) -{} +ClassicGame::ClassicGame( + const std::shared_ptr> &timeline, + const std::shared_ptr &context) + : _timeline(timeline), _context(context) +{ +} void ClassicGame::run() { @@ -17,7 +18,7 @@ void ClassicGame::run() _timeline->setNotes(beatmap.notes); } -void ClassicGame::input(kku::GameEvent&& input) +void ClassicGame::input(kku::GameEvent &&input) { switch (input.event.type) { @@ -39,22 +40,24 @@ void ClassicGame::input(kku::GameEvent&& input) case kku::SystemEvent::Type::KeyRelease: { - _context->getHoldManager()->checkRelease(std::get(input.event.data).view); + _context->getHoldManager()->checkRelease( + std::get(input.event.data).view); } break; - } } -void ClassicGame::update(kku::UpdateData&& updatedata) +void ClassicGame::update(kku::UpdateData &&updatedata) { // UNCOMMENT TO TEST AUTOPLAY /*auto note_it = _timeline->getActiveNote(updatedata.timestamp); - if (!_timeline->isExpired(note_it) && updatedata.timestamp >= (*note_it)->getPerfectOffset()) + if (!_timeline->isExpired(note_it) && updatedata.timestamp >= + (*note_it)->getPerfectOffset()) { auto note = (*note_it); - note->input(kku::GameEvent{updatedata.timestamp, kku::SystemEvent{kku::SystemEvent::Type::None, kku::SystemEvent::Key{}}}); + note->input(kku::GameEvent{updatedata.timestamp, + kku::SystemEvent{kku::SystemEvent::Type::None, kku::SystemEvent::Key{}}}); }*/ _timeline->update(updatedata.timestamp); diff --git a/src/modes/classicmode/game/classicmapcreator.cpp b/src/modes/classicmode/game/classicmapcreator.cpp index eff0974..dd221dc 100644 --- a/src/modes/classicmode/game/classicmapcreator.cpp +++ b/src/modes/classicmode/game/classicmapcreator.cpp @@ -3,25 +3,28 @@ #include "gamecontext.h" // Replace with interface by dependency injection -#include "graphics/animations/classicflyinganimationscenario.h" #include "graphics/animations/classicdyinganimationscenario.h" +#include "graphics/animations/classicflyinganimationscenario.h" // -auto classic::createBeatmap(const std::string& filepath, const std::shared_ptr& context) -> Beatmap +auto classic::createBeatmap(const std::string &filepath, + const std::shared_ptr &context) + -> Beatmap { - (void) filepath; + (void)filepath; kku::microsec starting_beat_offset = 402162; int amount_of_beats = 209; kku::microsec interval = 1412162; kku::microsec tempo_interval = interval / 4; kku::microsec note_input_offset = 412162 / 2; - //microsec note_input_offset_fast = 412162 / 6; + // microsec note_input_offset_fast = 412162 / 6; kku::microsec bpm_iterator = starting_beat_offset; kku::microsec bpm_end = starting_beat_offset + (interval * amount_of_beats); - std::vector input_intervals = {note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset}; - std::set notes; + std::vector input_intervals = { + note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset}; + std::set notes; input_intervals.shrink_to_fit(); bpm_iterator += tempo_interval; @@ -59,15 +62,8 @@ auto classic::createBeatmap(const std::string& filepath, const std::shared_ptr& hold_manager, - const std::shared_ptr& graphics_manager) : - _hold_manager(hold_manager), - _graphics_manager(graphics_manager) -{} +GameContext::GameContext( + const std::shared_ptr &hold_manager, + const std::shared_ptr &graphics_manager) + : _hold_manager(hold_manager), _graphics_manager(graphics_manager) +{ +} -void GameContext::input(ClassicArrowNote *note, kku::GameEvent&& input) const +void GameContext::input(ClassicArrowNote *note, kku::GameEvent &&input) const { auto grade = ClassicArrowNote::Grade::BAD; - auto& elements = note->getElements(); + auto &elements = note->getElements(); - bool input_valid = std::any_of(elements.begin(), elements.end(), - [input=input](auto& element) - { - if (element.pressed) - return false; + bool input_valid = std::any_of( + elements.begin(), elements.end(), + [input = input](auto &element) + { + if (element.pressed) + return false; - const auto code = std::get(input.event.data).view; - auto key_iterator = std::find(element.keys.begin(), element.keys.end(), code); + const auto code = + std::get(input.event.data).view; + auto key_iterator = + std::find(element.keys.begin(), element.keys.end(), code); - bool found_key = key_iterator != element.keys.end(); - if (found_key) - { - element.pressed = true; - element.pressed_as = code; - } + bool found_key = key_iterator != element.keys.end(); + if (found_key) + { + element.pressed = true; + element.pressed_as = code; + } - return found_key; - }); + return found_key; + }); - bool all_pressed = std::all_of(elements.begin(), elements.end(), - [](const auto& element) - { - return element.pressed; - }); + bool all_pressed = + std::all_of(elements.begin(), elements.end(), + [](const auto &element) { return element.pressed; }); if (all_pressed) { @@ -50,20 +52,23 @@ void GameContext::input(ClassicArrowNote *note, kku::GameEvent&& input) const if (all_pressed || !input_valid) { note->setState(ClassicArrowNote::State::DYING); - for (auto& element : elements) - element.animations[note->getState()]->launch(element.sprite, input.timestamp, note->getPerfectOffset()); + for (auto &element : elements) + element.animations[note->getState()]->launch( + element.sprite, input.timestamp, note->getPerfectOffset()); } std::cout << "User input: " << static_cast(grade) << "\n"; } -void GameContext::update(ClassicArrowNote *note, const kku::microsec& music_offset) const +void GameContext::update(ClassicArrowNote *note, + const kku::microsec &music_offset) const { - auto& elements = note->getElements(); + auto &elements = note->getElements(); switch (note->getState()) { - default: return; + default: + return; break; case ClassicArrowNote::State::INITIAL: @@ -72,11 +77,13 @@ void GameContext::update(ClassicArrowNote *note, const kku::microsec& music_offs break; case ClassicArrowNote::State::FLYING: - if (!note->isActive(music_offset) && music_offset > note->getPerfectOffset()) + if (!note->isActive(music_offset) && + music_offset > note->getPerfectOffset()) { note->setState(ClassicArrowNote::State::DYING); - for (auto& element : elements) - element.animations[note->getState()]->launch(element.sprite, music_offset, note->getPerfectOffset()); + for (auto &element : elements) + element.animations[note->getState()]->launch( + element.sprite, music_offset, note->getPerfectOffset()); } break; @@ -86,7 +93,7 @@ void GameContext::update(ClassicArrowNote *note, const kku::microsec& music_offs break; } - for (auto& element : elements) + for (auto &element : elements) if (element.animations[note->getState()]) element.animations[note->getState()]->update(music_offset); } diff --git a/src/modes/classicmode/game/holdmanager.cpp b/src/modes/classicmode/game/holdmanager.cpp index 8fef198..dc49050 100644 --- a/src/modes/classicmode/game/holdmanager.cpp +++ b/src/modes/classicmode/game/holdmanager.cpp @@ -1,10 +1,10 @@ #include "holdmanager.h" #include "classicarrownote.h" -#include #include +#include -void HoldManager::emplace(ClassicArrowNote* note) +void HoldManager::emplace(ClassicArrowNote *note) { _notes_on_hold.emplace_back(note); } @@ -12,10 +12,8 @@ void HoldManager::emplace(ClassicArrowNote* note) void HoldManager::checkRelease(kku::SystemEvent::Key::Code released_key) { bool key_match = std::any_of(_notes_on_hold.begin(), _notes_on_hold.end(), - [released_key](const auto& note) - { - return note->isPressedAs(released_key); - }); + [released_key](const auto ¬e) + { return note->isPressedAs(released_key); }); if (key_match) _notes_on_hold.clear(); diff --git a/src/modes/classicmode/graphics/animations/classicdyinganimationscenario.cpp b/src/modes/classicmode/graphics/animations/classicdyinganimationscenario.cpp index 117e164..c3e54af 100644 --- a/src/modes/classicmode/graphics/animations/classicdyinganimationscenario.cpp +++ b/src/modes/classicmode/graphics/animations/classicdyinganimationscenario.cpp @@ -1,7 +1,9 @@ #include "classicdyinganimationscenario.h" #include "graphics/classicnotegraphics.h" -void ClassicDyingAnimationScenario::launch(const std::shared_ptr sprite, const kku::microsec& time_begin, const kku::microsec &time_end) +void ClassicDyingAnimationScenario::launch( + const std::shared_ptr sprite, + const kku::microsec &time_begin, const kku::microsec &time_end) { _sprite = sprite; _time_begin = time_begin; @@ -12,9 +14,9 @@ void ClassicDyingAnimationScenario::launch(const std::shared_ptrsetTrailPosition(kku::Point{0, 0}); } -void ClassicDyingAnimationScenario::update(const kku::microsec& music_offset) +void ClassicDyingAnimationScenario::update(const kku::microsec &music_offset) { - (void) music_offset; + (void)music_offset; auto fill_color = _sprite->getColor(); @@ -25,7 +27,8 @@ void ClassicDyingAnimationScenario::update(const kku::microsec& music_offset) return; } - auto new_alpha = (int(fill_color.alpha) - 15) < 0 ? 0 : int(fill_color.alpha) - 15; + auto new_alpha = + (int(fill_color.alpha) - 15) < 0 ? 0 : int(fill_color.alpha) - 15; fill_color.alpha = new_alpha; _sprite->setColor(fill_color); diff --git a/src/modes/classicmode/graphics/animations/classicflyinganimationscenario.cpp b/src/modes/classicmode/graphics/animations/classicflyinganimationscenario.cpp index 0413986..6cf6a04 100644 --- a/src/modes/classicmode/graphics/animations/classicflyinganimationscenario.cpp +++ b/src/modes/classicmode/graphics/animations/classicflyinganimationscenario.cpp @@ -1,7 +1,9 @@ #include "classicflyinganimationscenario.h" #include "graphics/classicnotegraphics.h" -void ClassicFlyingAnimationScenario::launch(const std::shared_ptr sprite, const kku::microsec& time_begin, const kku::microsec &time_end) +void ClassicFlyingAnimationScenario::launch( + const std::shared_ptr sprite, + const kku::microsec &time_begin, const kku::microsec &time_end) { _sprite = sprite; _time_begin = time_begin; @@ -12,12 +14,13 @@ void ClassicFlyingAnimationScenario::launch(const std::shared_ptrsetTrailColor(_sprite->getColor()); } -float ClassicFlyingAnimationScenario::getPoint(const kku::Point& point, float perc) const +float ClassicFlyingAnimationScenario::getPoint(const kku::Point &point, + float perc) const { return point.x + ((point.y - point.x) * perc); } -void ClassicFlyingAnimationScenario::update(const kku::microsec& music_offset) +void ClassicFlyingAnimationScenario::update(const kku::microsec &music_offset) { const auto crd = _sprite->getPosition(); auto update_time = music_offset - _time_begin; @@ -28,7 +31,8 @@ void ClassicFlyingAnimationScenario::update(const kku::microsec& music_offset) float xb = getPoint(kku::Point{crd.x + 90, crd.x}, i); float yb = getPoint(kku::Point{crd.y - 150, crd.y}, i); - _sprite->setTrailPosition(kku::Point(getPoint( kku::Point{xa, xb}, i ), getPoint( kku::Point{ya, yb}, i ))); + _sprite->setTrailPosition(kku::Point(getPoint(kku::Point{xa, xb}, i), + getPoint(kku::Point{ya, yb}, i))); } bool ClassicFlyingAnimationScenario::isDone() const diff --git a/src/modes/classicmode/graphics/classicgraphicsfactory.cpp b/src/modes/classicmode/graphics/classicgraphicsfactory.cpp index 0bb0c5b..ae67a7b 100644 --- a/src/modes/classicmode/graphics/classicgraphicsfactory.cpp +++ b/src/modes/classicmode/graphics/classicgraphicsfactory.cpp @@ -1,8 +1,10 @@ #include "classicgraphicsfactory.h" -ClassicGraphicsFactory::ClassicGraphicsFactory(const std::shared_ptr& core_factory) : - _core_factory(core_factory) -{} +ClassicGraphicsFactory::ClassicGraphicsFactory( + const std::shared_ptr &core_factory) + : _core_factory(core_factory) +{ +} auto ClassicGraphicsFactory::generate(Type type) const -> SpriteData { @@ -31,7 +33,7 @@ auto ClassicGraphicsFactory::generate(Type type) const -> SpriteData color = kku::Color{255, 0, 255, 255}; break; - default: // yellow + default: // yellow color = kku::Color{255, 239, 0, 255}; } @@ -41,14 +43,20 @@ auto ClassicGraphicsFactory::generate(Type type) const -> SpriteData return SpriteData{shape, trail, color}; } -std::shared_ptr ClassicGraphicsFactory::createSprite(Type type) const +std::shared_ptr +ClassicGraphicsFactory::createSprite(Type type) const { const auto data = generate(type); - return std::make_shared(ClassicNoteGraphics::Init{data.shape, data.trail, data.color}); + return std::make_shared( + ClassicNoteGraphics::Init{data.shape, data.trail, data.color}); } -std::shared_ptr ClassicGraphicsFactory::createSelection() const +std::shared_ptr +ClassicGraphicsFactory::createSelection() const { const auto shape = _core_factory->getRectangle(); - return std::make_shared(ClassicSelectionGraphics::Init{shape, kku::Color{51, 153, 255, 120}}); + return std::make_shared( + ClassicSelectionGraphics::Init{ + shape, kku::Color{51, 153, 255, 120} + }); } diff --git a/src/modes/classicmode/graphics/classicnotegraphics.cpp b/src/modes/classicmode/graphics/classicnotegraphics.cpp index 134e4e8..8872855 100644 --- a/src/modes/classicmode/graphics/classicnotegraphics.cpp +++ b/src/modes/classicmode/graphics/classicnotegraphics.cpp @@ -1,9 +1,7 @@ #include "classicnotegraphics.h" -ClassicNoteGraphics::ClassicNoteGraphics(ClassicNoteGraphics::Init&& init) : - _reset_color(init.color), - _shape(init.shape), - _trail(init.trail) +ClassicNoteGraphics::ClassicNoteGraphics(ClassicNoteGraphics::Init &&init) + : _reset_color(init.color), _shape(init.shape), _trail(init.trail) { _shape->setColor(init.color); _trail->setColor(init.color); @@ -18,7 +16,7 @@ void ClassicNoteGraphics::reset() _trail->setColor(_reset_color); } -void ClassicNoteGraphics::setPosition(const kku::Point& position) +void ClassicNoteGraphics::setPosition(const kku::Point &position) { _shape->setPosition(position); } @@ -38,12 +36,12 @@ kku::Point ClassicNoteGraphics::getTrailPosition() const return _trail->getPosition(); } -void ClassicNoteGraphics::setColor(const kku::Color& color) +void ClassicNoteGraphics::setColor(const kku::Color &color) { _shape->setColor(color); } -void ClassicNoteGraphics::setTrailColor(const kku::Color& color) +void ClassicNoteGraphics::setTrailColor(const kku::Color &color) { _trail->setColor(color); } diff --git a/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp b/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp index f89a93d..6f8987a 100644 --- a/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp +++ b/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp @@ -3,21 +3,20 @@ #include -ClassicSceneGraphicsManager::ClassicSceneGraphicsManager(const std::shared_ptr>& timeline, - const std::shared_ptr& factory, - const kku::microsec& visibility_offset) : - ClassicGraphicsManager(visibility_offset), - _sprite_container({Type::UP, Type::DOWN, - Type::LEFT, Type::RIGHT}, - factory), - _factory(factory), - _timeline(timeline) +ClassicSceneGraphicsManager::ClassicSceneGraphicsManager( + const std::shared_ptr> &timeline, + const std::shared_ptr &factory, + const kku::microsec &visibility_offset) + : ClassicGraphicsManager(visibility_offset), + _sprite_container({Type::UP, Type::DOWN, Type::LEFT, Type::RIGHT}, + factory), + _factory(factory), _timeline(timeline) { _timeline->expire(_first); _timeline->expire(_last); } -void ClassicSceneGraphicsManager::input(kku::GameEvent&& input) +void ClassicSceneGraphicsManager::input(kku::GameEvent &&input) { if (nothingToDraw()) return; @@ -49,14 +48,18 @@ void ClassicSceneGraphicsManager::update(const kku::microsec &offset) updateVisibleNotes(offset); } -void ClassicSceneGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note) +void ClassicSceneGraphicsManager::update(const kku::microsec &offset, + ClassicArrowNote *note) { bool hasGraphics = (note->getElements()[0].sprite != nullptr); if (isVisiblyClose(note, offset) && !hasGraphics) { std::cout << note->getId() << ": set graphics!\n" << std::flush; - setGraphics(note->getElements(), kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()}); + setGraphics( + note->getElements(), + kku::TimeRange{note->getPerfectOffset() - _visibility_offset, + note->getPerfectOffset()}); } else { @@ -65,18 +68,18 @@ void ClassicSceneGraphicsManager::update(const kku::microsec& offset, ClassicArr } } -void ClassicSceneGraphicsManager::draw(const ClassicArrowNote * const note) const +void ClassicSceneGraphicsManager::draw(const ClassicArrowNote *const note) const { const auto elements = note->getElements(); for (std::size_t i = 0; i < elements.size(); ++i) { - const auto& sprite = elements[i].sprite; + const auto &sprite = elements[i].sprite; if (i >= 1) { - //const auto& neighbor_sprite = elements[i - 1].sprite; - //const auto c1 = neighbor_sprite->trailPosition(); - //const auto c2 = sprite->trailPosition(); + // const auto& neighbor_sprite = elements[i - 1].sprite; + // const auto c1 = neighbor_sprite->trailPosition(); + // const auto c2 = sprite->trailPosition(); //_render_target->draw(makeLine(c1, c2)); } @@ -84,26 +87,31 @@ void ClassicSceneGraphicsManager::draw(const ClassicArrowNote * const note) cons } } -void ClassicSceneGraphicsManager::setGraphics(std::vector& elements, kku::TimeRange&& range) +void ClassicSceneGraphicsManager::setGraphics( + std::vector &elements, kku::TimeRange &&range) { - for (auto& element : elements) + for (auto &element : elements) { element.sprite = _sprite_container.getSprite(element.type); element.sprite->setPosition(element.position); - element.sprite->setTrailPosition(kku::Point( 0.f, 9.f )); + element.sprite->setTrailPosition(kku::Point(0.f, 9.f)); element.animations[ClassicNote::State::NONE] = nullptr; - element.animations[ClassicNote::State::FLYING] = std::make_shared(); - element.animations[ClassicNote::State::DYING] = std::make_shared(); + element.animations[ClassicNote::State::FLYING] = + std::make_shared(); + element.animations[ClassicNote::State::DYING] = + std::make_shared(); element.animations[ClassicNote::State::DEAD] = nullptr; - element.animations[ClassicNote::State::FLYING]->launch(element.sprite, range.begin, range.end); + element.animations[ClassicNote::State::FLYING]->launch( + element.sprite, range.begin, range.end); } } -void ClassicSceneGraphicsManager::removeGraphics(std::vector& elements) +void ClassicSceneGraphicsManager::removeGraphics( + std::vector &elements) { - for (auto& element : elements) + for (auto &element : elements) { _sprite_container.resetSprite(element.sprite, element.type); element.sprite = nullptr; @@ -117,16 +125,17 @@ void ClassicSceneGraphicsManager::removeGraphics(std::vector& elem bool ClassicSceneGraphicsManager::nothingToDraw() const noexcept { - return _timeline->isExpired(_first) - || _timeline->isExpired(_last); + return _timeline->isExpired(_first) || _timeline->isExpired(_last); } -bool ClassicSceneGraphicsManager::isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept +bool ClassicSceneGraphicsManager::isVisiblyClose( + const ClassicNote *const note, + const kku::microsec &music_offset) const noexcept { return (note->getPerfectOffset() - _visibility_offset) <= music_offset; } -void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset) +void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec &offset) { if (nothingToDraw()) return; @@ -134,7 +143,8 @@ void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset) if (offset < (*_first)->getPerfectOffset()) { Iterator note_iterator = _first; - while (note_iterator != _timeline->begin() && isVisiblyClose(*note_iterator, offset)) + while (note_iterator != _timeline->begin() && + isVisiblyClose(*note_iterator, offset)) { --note_iterator; } @@ -143,10 +153,10 @@ void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset) auto note = *_first; const auto state = note->getState(); - if (state != ClassicNote::State::FLYING - && state != ClassicNote::State::DYING - && state != ClassicNote::State::INITIAL - && offset <= note->getPerfectOffset()) + if (state != ClassicNote::State::FLYING && + state != ClassicNote::State::DYING && + state != ClassicNote::State::INITIAL && + offset <= note->getPerfectOffset()) { note->setState(ClassicNote::State::INITIAL); } @@ -159,7 +169,7 @@ void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset) auto note = *note_iterator; if (note->getState() == ClassicNote::State::DEAD) { - // note->removeGraphics(this); + // note->removeGraphics(this); ++_first; } @@ -168,20 +178,21 @@ void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset) } } -void ClassicSceneGraphicsManager::fetchLastNote(const kku::microsec& offset) +void ClassicSceneGraphicsManager::fetchLastNote(const kku::microsec &offset) { Iterator note_iterator = _timeline->getTopNote(); - while (!_timeline->isExpired(note_iterator) && isVisiblyClose(*note_iterator, offset)) + while (!_timeline->isExpired(note_iterator) && + isVisiblyClose(*note_iterator, offset)) { if (nothingToDraw()) _first = note_iterator; auto note = *note_iterator; const auto state = note->getState(); - if (state != ClassicNote::State::FLYING - && state != ClassicNote::State::DYING - && state != ClassicNote::State::INITIAL - && offset <= note->getPerfectOffset()) + if (state != ClassicNote::State::FLYING && + state != ClassicNote::State::DYING && + state != ClassicNote::State::INITIAL && + offset <= note->getPerfectOffset()) { note->setState(ClassicNote::State::INITIAL); } @@ -192,7 +203,8 @@ void ClassicSceneGraphicsManager::fetchLastNote(const kku::microsec& offset) _last = note_iterator; } -void ClassicSceneGraphicsManager::updateVisibleNotes(const kku::microsec& offset) +void ClassicSceneGraphicsManager::updateVisibleNotes( + const kku::microsec &offset) { for (auto it = _first; it != _last; ++it) (*it)->update(offset); diff --git a/src/modes/classicmode/graphics/classicselectiongraphics.cpp b/src/modes/classicmode/graphics/classicselectiongraphics.cpp index 8781425..6ec7224 100644 --- a/src/modes/classicmode/graphics/classicselectiongraphics.cpp +++ b/src/modes/classicmode/graphics/classicselectiongraphics.cpp @@ -1,9 +1,9 @@ #include "classicselectiongraphics.h" #include "classicnotegraphics.h" -ClassicSelectionGraphics::ClassicSelectionGraphics(ClassicSelectionGraphics::Init&& init) : - _fill_color(init.color), - _shape(init.shape) +ClassicSelectionGraphics::ClassicSelectionGraphics( + ClassicSelectionGraphics::Init &&init) + : _fill_color(init.color), _shape(init.shape) { _shape->setColor(init.color); } @@ -19,7 +19,8 @@ void ClassicSelectionGraphics::display() const _shape->display(); } -void ClassicSelectionGraphics::adjustTo(const std::shared_ptr& sprite) +void ClassicSelectionGraphics::adjustTo( + const std::shared_ptr &sprite) { _shape->setRect(sprite->getRectangle()->getRect()); } diff --git a/src/modes/classicmode/graphics/classictimelinegraphicsmanager.cpp b/src/modes/classicmode/graphics/classictimelinegraphicsmanager.cpp index 44a6f64..f261e95 100644 --- a/src/modes/classicmode/graphics/classictimelinegraphicsmanager.cpp +++ b/src/modes/classicmode/graphics/classictimelinegraphicsmanager.cpp @@ -3,23 +3,22 @@ #include -ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared_ptr>& timeline, - const std::shared_ptr& factory, - const kku::microsec& visibility_offset) : - ClassicGraphicsManager(visibility_offset), - _sprite_container({Type::UP, Type::DOWN, - Type::LEFT, Type::RIGHT}, - factory), - _factory(factory), - _timeline(timeline), - _back_visibility_offset(static_cast(visibility_offset) / 4.f), - _last_offset(0) +ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager( + const std::shared_ptr> &timeline, + const std::shared_ptr &factory, + const kku::microsec &visibility_offset) + : ClassicGraphicsManager(visibility_offset), + _sprite_container({Type::UP, Type::DOWN, Type::LEFT, Type::RIGHT}, + factory), + _factory(factory), _timeline(timeline), + _back_visibility_offset(static_cast(visibility_offset) / 4.f), + _last_offset(0) { _timeline->expire(_first); _timeline->expire(_last); } -void ClassicTimelineGraphicsManager::input(kku::GameEvent&& input) +void ClassicTimelineGraphicsManager::input(kku::GameEvent &&input) { switch (input.event.type) { @@ -32,12 +31,14 @@ void ClassicTimelineGraphicsManager::input(kku::GameEvent&& input) if (key_data.view == kku::SystemEvent::Key::Code::Add) { _visibility_offset += 200000; - _back_visibility_offset = static_cast(_visibility_offset) / 4.f; + _back_visibility_offset = + static_cast(_visibility_offset) / 4.f; } else if (key_data.view == kku::SystemEvent::Key::Code::Subtract) { _visibility_offset -= 200000; - _back_visibility_offset = static_cast(_visibility_offset) / 4.f; + _back_visibility_offset = + static_cast(_visibility_offset) / 4.f; } break; } @@ -46,8 +47,8 @@ void ClassicTimelineGraphicsManager::input(kku::GameEvent&& input) void ClassicTimelineGraphicsManager::display() const { - //if (nothingToDraw()) - //return; + // if (nothingToDraw()) + // return; std::cout << "displaying on tl: "; for (auto it = _first; it != _last; ++it) @@ -66,7 +67,8 @@ void ClassicTimelineGraphicsManager::update(const kku::microsec &offset) fetchFirstNote(offset); } -void ClassicTimelineGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note) +void ClassicTimelineGraphicsManager::update(const kku::microsec &offset, + ClassicArrowNote *note) { bool hasGraphics = (note->getElements()[0].sprite != nullptr); @@ -80,13 +82,17 @@ void ClassicTimelineGraphicsManager::update(const kku::microsec& offset, Classic } } -void ClassicTimelineGraphicsManager::draw(const ClassicArrowNote * const note) const +void ClassicTimelineGraphicsManager::draw( + const ClassicArrowNote *const note) const { - const double d_visibility_offset = static_cast(_last_offset + _visibility_offset); - const double d_back_visibility_offset = static_cast(_last_offset - _back_visibility_offset); + const double d_visibility_offset = + static_cast(_last_offset + _visibility_offset); + const double d_back_visibility_offset = + static_cast(_last_offset - _back_visibility_offset); const double span = d_visibility_offset - d_back_visibility_offset; - const double note_span = static_cast(note->getPerfectOffset()) - d_visibility_offset; + const double note_span = + static_cast(note->getPerfectOffset()) - d_visibility_offset; const double percent = note_span / (span / 100.f); @@ -94,7 +100,8 @@ void ClassicTimelineGraphicsManager::draw(const ClassicArrowNote * const note) c for (std::size_t i = 0; i < elements.size(); ++i) { auto timeline_sprite = _factory->createSprite(elements[i].type); - timeline_sprite->setPosition(kku::Point{static_cast(850 + 1280.f / 100.f * percent), 700}); + timeline_sprite->setPosition( + kku::Point{static_cast(850 + 1280.f / 100.f * percent), 700}); timeline_sprite->display(); } @@ -102,25 +109,27 @@ void ClassicTimelineGraphicsManager::draw(const ClassicArrowNote * const note) c bool ClassicTimelineGraphicsManager::nothingToDraw() const noexcept { - return _timeline->isExpired(_first) - || _timeline->isExpired(_last); + return _timeline->isExpired(_first) || _timeline->isExpired(_last); } -bool ClassicTimelineGraphicsManager::isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept +bool ClassicTimelineGraphicsManager::isVisiblyClose( + const ClassicNote *const note, + const kku::microsec &music_offset) const noexcept { - const auto& perfect_offset = note->getPerfectOffset(); + const auto &perfect_offset = note->getPerfectOffset(); - return ((perfect_offset - _visibility_offset) <= music_offset) - || ((perfect_offset + (_visibility_offset / 4.)) >= music_offset); + return ((perfect_offset - _visibility_offset) <= music_offset) || + ((perfect_offset + (_visibility_offset / 4.)) >= music_offset); } -void ClassicTimelineGraphicsManager::fetchFirstNote(const kku::microsec& offset) +void ClassicTimelineGraphicsManager::fetchFirstNote(const kku::microsec &offset) { - //if (nothingToDraw()) - //return; + // if (nothingToDraw()) + // return; Iterator note_iterator = _first; - while (note_iterator != _timeline->begin() && isVisiblyClose(*note_iterator, offset)) + while (note_iterator != _timeline->begin() && + isVisiblyClose(*note_iterator, offset)) { --note_iterator; } @@ -128,10 +137,11 @@ void ClassicTimelineGraphicsManager::fetchFirstNote(const kku::microsec& offset) _first = note_iterator; } -void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& offset) +void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec &offset) { Iterator note_iterator = _timeline->getTopNote(); - while (!_timeline->isExpired(note_iterator) && isVisiblyClose(*note_iterator, offset)) + while (!_timeline->isExpired(note_iterator) && + isVisiblyClose(*note_iterator, offset)) { if (nothingToDraw()) _first = note_iterator; diff --git a/src/tools/src/beatutils.cpp b/src/tools/src/beatutils.cpp index 52b1fb9..8f1db4e 100644 --- a/src/tools/src/beatutils.cpp +++ b/src/tools/src/beatutils.cpp @@ -1,23 +1,21 @@ #include "tools/beatutils.h" -#include #include +#include -auto beat_utils::calculateBeatRateInfo(const std::vector& approximate_deltas) -> BeatInfo +auto beat_utils::calculateBeatRateInfo( + const std::vector &approximate_deltas) -> BeatInfo { if (approximate_deltas.empty()) return {}; - const long double sum = std::accumulate(approximate_deltas.begin(), approximate_deltas.end(), 0); + const long double sum = std::accumulate(approximate_deltas.begin(), + approximate_deltas.end(), 0); const long double amount = approximate_deltas.size(); long double average = sum / amount; const int bpm = static_cast(60000000. / average); - - return BeatInfo - { - bpm, - static_cast(1. / static_cast(bpm) * 60000000.) - }; + return BeatInfo{bpm, static_cast( + 1. / static_cast(bpm) * 60000000.)}; } diff --git a/src/tools/src/bpmcalculator.cpp b/src/tools/src/bpmcalculator.cpp index ea597de..7162368 100644 --- a/src/tools/src/bpmcalculator.cpp +++ b/src/tools/src/bpmcalculator.cpp @@ -1,8 +1,8 @@ #include "tools/bpmcalculator.h" #include -#include #include +#include BPMCalculator::BPMCalculator() { @@ -55,7 +55,7 @@ void BPMCalculator::click(const kku::microsec &offset) _previous_click_offset = offset; } -const beat_utils::BeatInfo& BPMCalculator::fetchApproximatedInfo() +const beat_utils::BeatInfo &BPMCalculator::fetchApproximatedInfo() { if (!_need_recalculate) return _approximated_info; @@ -65,8 +65,8 @@ const beat_utils::BeatInfo& BPMCalculator::fetchApproximatedInfo() bool hasEnoughDeltas = _deltas.size() >= 8; _approximated_info = (!hasEnoughDeltas) - ? beat_utils::BeatInfo{} - : beat_utils::calculateBeatRateInfo(_deltas); + ? beat_utils::BeatInfo{} + : beat_utils::calculateBeatRateInfo(_deltas); return _approximated_info; } @@ -86,7 +86,7 @@ void BPMCalculator::moveStartingOffsetBy(kku::microsec shift) _first_click_offset += shift; } -kku::microsec BPMCalculator::fetchTimeUntilNextBeat(const kku::microsec& offset) +kku::microsec BPMCalculator::fetchTimeUntilNextBeat(const kku::microsec &offset) { const kku::microsec actual_offset = offset - getStartingOffset();