diff --git a/CMakeLists.txt b/CMakeLists.txt index 39acc9b..f5792bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,22 +4,24 @@ project(project-kyoku LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(SOURCES application.cpp note.cpp main.cpp) -set(HEADER_FILES application.h note.h) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +set(SOURCES application.cpp note.cpp debughelper.cpp main.cpp timeline.cpp timelineviews/timelineviewmanager.cpp timelineviews/classicviewmanager.cpp) +set(HEADER_FILES application.h note.h debughelper.h timeline.h timelineviews/timelineviewmanager.h timelineviews/classicviewmanager.h) # STATIC # # You need to build SFML from sources with cmake -#set(SFML_LIB_DIR -# ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-graphics.so.2.5 -# ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-system.so.2.5 -# ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-window.so.2.5) -#set(SFML_INCL_DIR ${CMAKE_SOURCE_DIR}/SFML-2.5.1/include) -#include_directories(${SFML_INCL_DIR}) -#add_executable(project-kyoku ${SOURCES} ${HEADER_FILES} ) -#target_link_libraries(project-kyoku ${SFML_LIB_DIR}) +set(SFML_LIB_DIR + ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-graphics.so.2.5 + ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-system.so.2.5 + ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-window.so.2.5 + ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-audio.so.2.5) +set(SFML_INCL_DIR ${CMAKE_SOURCE_DIR}/SFML-2.5.1/include) +include_directories(${SFML_INCL_DIR}) +add_executable(project-kyoku ${SOURCES} ${HEADER_FILES} ) +target_link_libraries(project-kyoku ${SFML_LIB_DIR}) # DYNAMIC # # You only need to install SFML from your package manager -find_package(SFML REQUIRED graphics window system) -add_executable(project-kyoku ${SOURCES} ${HEADER_FILES} ) -target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network) +#find_package(SFML REQUIRED graphics window system) +#add_executable(project-kyoku ${SOURCES} ${HEADER_FILES} ) +#target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network) diff --git a/application.cpp b/application.cpp index 2a3fbd6..730896d 100644 --- a/application.cpp +++ b/application.cpp @@ -30,12 +30,6 @@ void Application::run() startGameLoop(); } - -static bool isOneFramePassed(const sf::Time& time_since_last_update) -{ - return time_since_last_update >= TIME_PER_FRAME; -} - void Application::startGameLoop() { sf::Clock timer; @@ -46,7 +40,9 @@ void Application::startGameLoop() input(); time_since_last_update += timer.restart(); - if (isOneFramePassed(time_since_last_update)) + + bool isOneFramePassed = time_since_last_update >= TIME_PER_FRAME; + if (isOneFramePassed) { time_since_last_update -= TIME_PER_FRAME; update(); @@ -148,11 +144,11 @@ void Application::onTap(const Note::Arrow &arrow) return; const auto music_offset = _music.getPlayingOffset().asMicroseconds(); - const auto note = _timeline.fetchActiveNote(music_offset); + auto note = _timeline.fetchActiveNote(music_offset); if (note) { - const auto tap_result = note->onTap(arrow, music_offset); + auto tap_result = note->onTap(arrow, music_offset); makeGradeString(tap_result.rating, _grade); _grade.setFillColor(sf::Color(255, 255, 255, 255)); } diff --git a/note.cpp b/note.cpp index 16e8df6..98abab1 100644 --- a/note.cpp +++ b/note.cpp @@ -24,8 +24,11 @@ microsec Note::offset() const noexcept return _offset; } -NoteGrade Note::onTap(Arrow arrow_type, microsec tap_time_stamp) const +NoteGrade Note::onTap(Arrow arrow_type, microsec tap_time_stamp) { + _sprite->setAttachment(false); + _sprite = nullptr; + if (arrow_type != _type) return {0, NoteGrade::Rating::WRONG}; @@ -56,4 +59,9 @@ void Note::resetPrecisionQualifier(microsec qualifier) _precision_qualifier = qualifier; } +void Note::resetSprite(const std::shared_ptr &sprite) noexcept +{ + _sprite = sprite; +} + microsec Note::_precision_qualifier = 500000; // Default initialization as 0.5 second. diff --git a/note.h b/note.h index c2a3682..75477ec 100644 --- a/note.h +++ b/note.h @@ -3,12 +3,30 @@ #include #include +#include // TEMP MOCK + +#include //////////////////////////////// using microsec = sf::Int64; using coordinates = sf::Vector2i; +class Sprite // MOCK +{ +public: + Sprite(sf::RectangleShape shape) : _shape(shape), _attached(false) {}; + bool isAttached() const noexcept + { return _attached; } + + void setAttachment(bool attached) noexcept + { _attached = attached; } + +private: + sf::RectangleShape _shape; + bool _attached; +}; + struct NoteGrade { int score; @@ -44,9 +62,11 @@ public: coordinates position() const noexcept; microsec offset() const noexcept; - NoteGrade onTap(Arrow arrow_type, microsec tap_time_stamp) const; + NoteGrade onTap(Arrow arrow_type, microsec tap_time_stamp); bool isActive(microsec music_play_offset) const noexcept; + void resetSprite(const std::shared_ptr& sprite) noexcept; + static void resetPrecisionQualifier(microsec qualifier = 500000); private: @@ -58,6 +78,8 @@ private: static microsec _precision_qualifier; NoteGrade calculatePrecision(microsec odds) const; + + std::shared_ptr _sprite; }; #endif // NOTE_H diff --git a/timeline.cpp b/timeline.cpp index 700b9b9..a28c3d2 100644 --- a/timeline.cpp +++ b/timeline.cpp @@ -124,7 +124,7 @@ void Timeline::checkForNextActiveNote(const microsec &music_offset) } } -const Note* Timeline::fetchActiveNote(const microsec &music_offset) noexcept +Note* Timeline::fetchActiveNote(const microsec &music_offset) noexcept { std::cout << "Clicked at: " << music_offset << '\n'; update(music_offset); diff --git a/timeline.h b/timeline.h index d7997c4..8dd8df5 100644 --- a/timeline.h +++ b/timeline.h @@ -19,7 +19,7 @@ public: virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void update(const microsec& music_offset); - const Note* fetchActiveNote(const microsec &music_offset) noexcept; + Note *fetchActiveNote(const microsec &music_offset) noexcept; /* void init(); */ void clear(); diff --git a/timelineviewmanager.cpp b/timelineviewmanager.cpp new file mode 100644 index 0000000..41f0f5d --- /dev/null +++ b/timelineviewmanager.cpp @@ -0,0 +1,6 @@ +#include "timelineviewmanager.h" + +TimelineViewManager::TimelineViewManager() +{ + +} diff --git a/timelineviewmanager.h b/timelineviewmanager.h new file mode 100644 index 0000000..4a7e474 --- /dev/null +++ b/timelineviewmanager.h @@ -0,0 +1,11 @@ +#ifndef TIMELINEVIEWMANAGER_H +#define TIMELINEVIEWMANAGER_H + + +class TimelineViewManager +{ +public: + TimelineViewManager(); +}; + +#endif // TIMELINEVIEWMANAGER_H diff --git a/timelineviews/classicviewmanager.cpp b/timelineviews/classicviewmanager.cpp new file mode 100644 index 0000000..2ee38c5 --- /dev/null +++ b/timelineviews/classicviewmanager.cpp @@ -0,0 +1,28 @@ +#include "classicviewmanager.h" +#include "../note.h" +#include + +static constexpr std::size_t RESERVED_SIZE = 20; + +ClassicViewManager::ClassicViewManager() +{ + for (std::size_t i = ARROW_UP; i < AMOUNT_OF_KINDS; ++i) + { + SpritePoll &poll = _sprite_dispatcher.at(i); + poll.reserve(RESERVED_SIZE); + for (auto &sprite : poll) + { + + } + } +} + +std::shared_ptr ClassicViewManager::createSprite(Button kind_of_button) const +{ + auto sprite = std::make_shared(); + sprite->setSize({20.f, 20.f}); + switch (kind_of_button) + { + return + } +} diff --git a/timelineviews/classicviewmanager.h b/timelineviews/classicviewmanager.h new file mode 100644 index 0000000..8595343 --- /dev/null +++ b/timelineviews/classicviewmanager.h @@ -0,0 +1,43 @@ +#ifndef CLASSICDIVAVIEWMANAGER_H +#define CLASSICDIVAVIEWMANAGER_H + +#include "timelineviewmanager.h" + +#include +#include + +class Sprite; + +class ClassicViewManager : public TimelineViewManager +{ +public: + explicit ClassicViewManager(); + virtual ~ClassicViewManager() override; + + virtual void update() override; + virtual void draw() override; + virtual void initNoteGraphics(Note *note) override; + +private: + + enum Button + { + ARROW_UP, + ARROW_DOWN, + ARROW_LEFT, + ARROW_RIGHT, + + SHOULDER_RIGHT, + SHOULDER_LEFT, + + AMOUNT_OF_KINDS + }; + + using SpritePoll = std::vector>; + using SpriteDispatcher = std::array; + SpriteDispatcher _sprite_dispatcher; + + std::shared_ptr createSprite(Button kind_of_button) const; +}; + +#endif // CLASSICDIVAVIEWMANAGER_H diff --git a/timelineviews/timelineviewmanager.cpp b/timelineviews/timelineviewmanager.cpp new file mode 100644 index 0000000..15593cb --- /dev/null +++ b/timelineviews/timelineviewmanager.cpp @@ -0,0 +1,7 @@ +#include "timelineviewmanager.h" + +TimelineViewManager::TimelineViewManager() +{} + +TimelineViewManager::~TimelineViewManager() +{} diff --git a/timelineviews/timelineviewmanager.h b/timelineviews/timelineviewmanager.h new file mode 100644 index 0000000..f1b3b7a --- /dev/null +++ b/timelineviews/timelineviewmanager.h @@ -0,0 +1,17 @@ +#ifndef TIMELINEVIEWMANAGER_H +#define TIMELINEVIEWMANAGER_H + +class Note; + +class TimelineViewManager +{ +public: + explicit TimelineViewManager(); + virtual ~TimelineViewManager(); + + virtual void update() = 0; + virtual void draw() = 0; + virtual void initNoteGraphics(Note *note) = 0; +}; + +#endif // TIMELINEVIEWMANAGER_H