Refactor core

selection
NaiJi ✨ 1 year ago
parent ac88cd9dfa
commit 833dd2b781
  1. 2
      .gitignore
  2. 41
      CMakeLists.txt
  3. 15
      core/CMakeLists.txt
  4. 10
      core/shared/core/inputtype.h
  5. 10
      core/shared/core/updatedata.h
  6. 37
      include/core/area.h
  7. 13
      include/core/bpmsection.h
  8. 14
      include/core/color.h
  9. 26
      include/core/corefactory.h
  10. 17
      include/core/editor.h
  11. 9
      include/core/game.h
  12. 15
      include/core/gameevent.h
  13. 18
      include/core/line.h
  14. 32
      include/core/music.h
  15. 24
      include/core/note.h
  16. 46
      include/core/point.h
  17. 17
      include/core/precisionevaluator.h
  18. 26
      include/core/rectangle.h
  19. 35
      include/core/resourceholder.h
  20. 5
      include/core/sprite.h
  21. 5
      include/core/spritecontainer.h
  22. 65
      include/core/systemevent.h
  23. 24
      include/core/text.h
  24. 22
      include/core/time.h
  25. 24
      include/core/timeline.h
  26. 16
      include/core/updatedata.h
  27. 22
      include/core/vector.h
  28. 35
      include/state.h
  29. 24
      modes/classicmode/CMakeLists.txt
  30. 37
      modes/classicmode/editor/classiceditor.h
  31. 41
      modes/classicmode/editor/mockclassicnote.cpp
  32. 28
      modes/classicmode/editor/mockclassicnote.h
  33. 21
      modes/classicmode/editor/mockelement.h
  34. 116
      modes/classicmode/game/classicgame.cpp
  35. 37
      modes/classicmode/graphics/animations/classicdyinganimationscenario.cpp
  36. 55
      modes/classicmode/graphics/animations/classicflyinganimationscenario.cpp
  37. 37
      modes/classicmode/graphics/classicscenegraphicsmanager.h
  38. 65
      modes/classicmode/graphics/classicsprite.cpp
  39. 34
      modes/classicmode/graphics/classicsprite.h
  40. 14
      modes/classicmode/include/classicmode/elementinitializer.h
  41. 0
      modes/classicmode/sfml/classicspritesfml.cpp
  42. 0
      modes/classicmode/sfml/classicspritesfml.h
  43. 14
      modes/classicmode/shared/classicmode/classicfactorysfml.h
  44. 18
      src/application/CMakeLists.txt
  45. 119
      src/application/application.cpp
  46. 40
      src/application/application.h
  47. 41
      src/application/editorstate.h
  48. 44
      src/application/gamestate.cpp
  49. 36
      src/application/gamestate.h
  50. 43
      src/application/include/application/editorstate.h
  51. 35
      src/application/include/application/gamestate.h
  52. 32
      src/application/include/application/mainmenu.h
  53. 35
      src/application/include/application/state.h
  54. 50
      src/application/mainmenu.cpp
  55. 33
      src/application/mainmenu.h
  56. 32
      src/application/shared/application/application.h
  57. 61
      src/application/src/application.cpp
  58. 97
      src/application/src/editorstate.cpp
  59. 49
      src/application/src/gamestate.cpp
  60. 53
      src/application/src/mainmenu.cpp
  61. 140
      src/application/src/widgets/bpmcalculatorwidget.cpp
  62. 54
      src/application/src/widgets/bpmcalculatorwidget.h
  63. 66
      src/application/src/widgets/bpmslider.cpp
  64. 30
      src/application/src/widgets/bpmslider.h
  65. 70
      src/application/src/widgets/button.cpp
  66. 33
      src/application/src/widgets/button.h
  67. 75
      src/application/src/widgets/cascademenubutton.cpp
  68. 12
      src/application/src/widgets/cascademenubutton.h
  69. 55
      src/application/src/widgets/editorwidget.cpp
  70. 36
      src/application/src/widgets/editorwidget.h
  71. 55
      src/application/src/widgets/group.cpp
  72. 23
      src/application/src/widgets/group.h
  73. 131
      src/application/src/widgets/menubar.cpp
  74. 35
      src/application/src/widgets/menubar.h
  75. 72
      src/application/src/widgets/menudrop.cpp
  76. 46
      src/application/src/widgets/menudrop.h
  77. 48
      src/application/src/widgets/menuseparator.cpp
  78. 25
      src/application/src/widgets/menuseparator.h
  79. 57
      src/application/src/widgets/pushbutton.cpp
  80. 10
      src/application/src/widgets/pushbutton.h
  81. 13
      src/application/src/widgets/widget.cpp
  82. 42
      src/application/src/widgets/widget.h
  83. 132
      src/application/src/widgets/window.cpp
  84. 41
      src/application/src/widgets/window.h
  85. 136
      src/application/widgets/bpmcalculatorwidget.cpp
  86. 56
      src/application/widgets/bpmcalculatorwidget.h
  87. 65
      src/application/widgets/bpmslider.cpp
  88. 32
      src/application/widgets/bpmslider.h
  89. 67
      src/application/widgets/button.cpp
  90. 32
      src/application/widgets/button.h
  91. 71
      src/application/widgets/cascademenubutton.cpp
  92. 55
      src/application/widgets/editorwidget.cpp
  93. 35
      src/application/widgets/editorwidget.h
  94. 55
      src/application/widgets/group.cpp
  95. 23
      src/application/widgets/group.h
  96. 125
      src/application/widgets/menubar.cpp
  97. 37
      src/application/widgets/menubar.h
  98. 45
      src/application/widgets/menudrop.h
  99. 48
      src/application/widgets/menuseparator.cpp
  100. 26
      src/application/widgets/menuseparator.h
  101. Some files were not shown because too many files have changed in this diff Show More

2
.gitignore vendored

@ -2,7 +2,7 @@
# ----------------------------------------------------------------------------
build
SFML*
SFML-*
*.user
*CMakeFiles*
*Makefile

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.13)
project(project-kyoku LANGUAGES CXX)
@ -16,38 +16,25 @@ set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
file(GLOB_RECURSE SOURCES "src/main.cpp" "src/application/*.cpp" "src/application/*.h")
include_directories(${CMAKE_SOURCE_DIR}/include)
file(GLOB_RECURSE SOURCES "src/main.cpp")
add_executable(project-kyoku ${SOURCES})
option(SFML_BUILT "SFML_BUILT" OFF)
if(SFML_BUILT)
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)
target_link_libraries(project-kyoku ${SFML_LIB_DIR})
else()
find_package(SFML REQUIRED graphics window system)
include_directories(${SFML_INCL_DIR} ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network)
endif()
include_directories(${SFML_INCL_DIR} ${CMAKE_SOURCE_DIR}/include)
SET(CMAKE_INSTALL_PREFIX /)
# When new game modes appear, aggregate them into a ONE subdirectory
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modes/classicmode/CMakeLists.txt")
add_subdirectory(modes/classicmode)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/modes/classicmode/CMakeLists.txt")
add_subdirectory(src/modes/classicmode)
target_link_libraries(project-kyoku classicmode)
endif()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tools/CMakeLists.txt")
add_subdirectory(tools)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/CMakeLists.txt")
add_subdirectory(src/tools)
target_link_libraries(project-kyoku tools)
endif()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/core/CMakeLists.txt")
add_subdirectory(core)
target_link_libraries(project-kyoku core)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/application/CMakeLists.txt")
add_subdirectory(src/application)
target_link_libraries(project-kyoku application)
endif()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/impl/CMakeLists.txt")
add_subdirectory(src/impl)
target_link_libraries(project-kyoku impl)
endif()

@ -1,15 +0,0 @@
cmake_minimum_required(VERSION 2.8.8)
project(core)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(${CMAKE_SOURCE_DIR}/include)
file(GLOB_RECURSE HEADERS "shared/*.h")
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_library(core STATIC ${SOURCES} ${HEADERS})
target_include_directories(core PRIVATE ${CMAKE_SOURCE_DIR}/tools/shared)
target_link_libraries(core tools)
target_include_directories(project-kyoku PRIVATE ${CMAKE_SOURCE_DIR}/core/shared)

@ -1,10 +0,0 @@
#pragma once
#include <SFML/Window/Event.hpp>
#include "tools/mathutils.h"
struct PlayerInput
{
microsec timestamp;
sf::Event event;
};

@ -1,10 +0,0 @@
#pragma once
#include <SFML/System/Time.hpp>
#include "tools/mathutils.h"
struct UpdateData
{
const microsec timestamp;
const sf::Time dt;
};

@ -0,0 +1,37 @@
#pragma once
#include <type_traits>
#include "core/point.h"
#include "core/vector.h"
namespace kku
{
template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
struct Area
{
T left = 0;
T top = 0;
T width = 0;
T height = 0;
inline kku::Point position() const noexcept
{
return kku::Point{static_cast<float>(left),
static_cast<float>(top) };
}
inline void moveBy(const kku::Vector2<T>& vector)
{
top += vector.second;
left += vector.first;
}
inline bool contains(const kku::Point& point) const
{
return point.x >= left ; // debug it when on computer
}
};
}

@ -1,19 +1,24 @@
#pragma once
#include "tools/mathutils.h"
#include "core/time.h"
namespace kku
{
struct BPMSection
{
int bpm = 120; // Hi, osu
int fraction = 2;
unsigned int bpm = 120; // Hi, osu
unsigned int fraction = 2;
microsec offset_start = 0;
microsec interval = 0;
};
struct BPMSectionCompt
struct BPMSectionComparator
{
bool operator()(const BPMSection& lhs, const BPMSection& rhs) const noexcept
{
return lhs.offset_start < rhs.offset_start;
}
};
}

@ -0,0 +1,14 @@
#pragma once
namespace kku
{
struct Color
{
unsigned char red = 0;
unsigned char green = 0;
unsigned char blue = 0;
unsigned char alpha = 0;
};
}

@ -0,0 +1,26 @@
#pragma once
#include <memory>
#include "core/music.h"
#include "core/text.h"
#include "core/resourceholder.h"
#include "core/rectangle.h"
#include "core/vector.h"
#include "core/line.h"
namespace kku
{
class CoreFactory
{
public:
virtual ~CoreFactory() = default;
virtual std::shared_ptr<kku::Music> getMusic() const = 0;
virtual std::shared_ptr<kku::Text> getText(kku::Font::Id id) const = 0;
virtual std::shared_ptr<kku::Rectangle> getRectangle() const = 0;
virtual std::shared_ptr<kku::Line> getLine() const = 0;
virtual kku::Vector2<std::size_t> getRenderSize() const = 0;
};
}

@ -1,26 +1,31 @@
#pragma once
#include <set>
#include "core/inputtype.h"
#include <algorithm>
#include "core/gameevent.h"
#include "core/updatedata.h"
#include "core/bpmsection.h"
namespace kku
{
class Editor
{
public:
virtual ~Editor() = default;
virtual void input(PlayerInput&& inputdata) = 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;
void setBPMSections(const std::set<BPMSection, BPMSectionCompt>& sections) noexcept
void setBPMSections(const std::set<BPMSection, BPMSectionComparator>& sections) noexcept
{
_bpm_sections = sections;
}
void setBPMSections(std::set<BPMSection, BPMSectionCompt>&& sections) noexcept
void setBPMSections(std::set<BPMSection, BPMSectionComparator>&& sections) noexcept
{
_bpm_sections = std::move(sections);
}
@ -77,5 +82,7 @@ public:
}
protected:
std::set<BPMSection, BPMSectionCompt> _bpm_sections;
std::set<BPMSection, BPMSectionComparator> _bpm_sections;
};
}

@ -1,15 +1,20 @@
#pragma once
#include "core/inputtype.h"
#include "core/gameevent.h"
#include "core/updatedata.h"
namespace kku
{
class Game
{
public:
virtual ~Game() = default;
virtual void run() = 0;
virtual void input(PlayerInput&& inputdata) = 0;
virtual void input(GameEvent&& inputdata) = 0;
virtual void update(UpdateData&& updatedata) = 0;
virtual void display() const = 0;
};
}

@ -0,0 +1,15 @@
#pragma once
#include "core/systemevent.h"
#include "core/time.h"
namespace kku
{
struct GameEvent
{
const microsec timestamp = 0;
const SystemEvent event;
};
}

@ -0,0 +1,18 @@
#pragma once
#include "core/point.h"
#include "core/color.h"
namespace kku
{
class Line
{
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 display() = 0;
};
}

@ -0,0 +1,32 @@
#pragma once
#include <string>
#include "core/time.h"
namespace kku
{
class Music
{
public:
virtual ~Music() = default;
virtual bool open(const std::string& filepath) = 0;
virtual void play() = 0;
virtual void pause() = 0;
virtual void stop() = 0;
virtual bool isPlaying() const = 0;
virtual void setVolume(float volume) = 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;
};
}

@ -1,6 +1,10 @@
#pragma once
#include "core/inputtype.h"
#include "core/time.h"
#include "core/gameevent.h"
namespace kku
{
class Note
{
@ -16,34 +20,40 @@ public:
virtual bool isInGame() const = 0;
virtual bool shouldRemove() const = 0;
const microsec& offset() const noexcept
virtual void input(kku::GameEvent&& input) = 0;
inline const microsec& getPerfectOffset() const noexcept
{
return _perfect_offset;
}
bool operator<(const Note& note) const
{
return (_perfect_offset < note._perfect_offset);
return _perfect_offset < note._perfect_offset;
}
bool operator==(const Note& note) const
{
return (_perfect_offset == note._perfect_offset);
return _perfect_offset == note._perfect_offset;
}
bool operator>(const Note& note) const
{
return (_perfect_offset > note._perfect_offset);
return _perfect_offset > note._perfect_offset;
}
protected:
microsec _perfect_offset;
};
struct NotePtrCompt
struct NotePtrComparator
{
bool operator()(const Note* lhs, const Note* rhs) const noexcept
{
return lhs->offset() < rhs->offset();
return lhs->getPerfectOffset() < rhs->getPerfectOffset();
}
};
}

@ -0,0 +1,46 @@
#pragma once
namespace kku
{
struct Point
{
float x;
float y;
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(float x, float y) noexcept :
x(x), y(y)
{}
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
{
return Point{right.x - x, right.y - y};
}
inline void moveBy(float x, float y) noexcept
{
this->x += x;
this->y += y;
}
inline void scaleBy(float factor) noexcept
{
x *= factor;
y *= factor;
}
};
}

@ -1,7 +1,4 @@
#ifndef PRECISIONEVALUATOR_H
#define PRECISIONEVALUATOR_H
#include "tools/mathutils.h"
#pragma once
#include <numeric>
#include <type_traits>
@ -9,6 +6,11 @@
#include <cmath>
#include <iostream>
#include "core/time.h"
namespace kku
{
template<typename Grade, typename = std::enable_if_t<std::is_enum<Grade>::value>>
class PrecisionEvaluator
{
@ -32,11 +34,12 @@ public:
&& music_play_offset < _end_handling_offset;
}
inline Grade calculatePrecision(microsec odds) const noexcept
Grade calculatePrecision(microsec odds) const
{
microsec shift_from_perfect = std::abs(odds - offset());
std::cout << "Shift " << ((odds > _offset) ? "late: " : "early: ") << shift_from_perfect << "\n";
std::cout << "Shift " << ((odds > _offset) ? "late: " : "early: ")
<< shift_from_perfect << "\n";
std::size_t raw_grade;
for (raw_grade = 0; raw_grade < _intervals.size(); ++raw_grade)
@ -63,4 +66,4 @@ private:
const std::vector<microsec> _intervals;
};
#endif // PRECISIONEVALUATOR_H
}

@ -0,0 +1,26 @@
#pragma once
#include "core/area.h"
#include "core/color.h"
namespace kku
{
class Rectangle
{
public:
virtual ~Rectangle() = default;
virtual void setRect(const Area<float>& rect) = 0;
virtual Area<float> getRect() const = 0;
virtual void setPosition(const Point& position) = 0;
virtual Point getPosition() const = 0;
virtual void move(const kku::Vector2<float>& delta) = 0;
virtual void setColor(const Color& color) = 0;
virtual bool contains(const kku::Point& position) const = 0;
virtual void display() = 0;
};
}

@ -0,0 +1,35 @@
#pragma once
#include <memory>
#include <map>
namespace kku
{
template <typename Resource, typename Id>
class ResourceHolder
{
public:
inline void load(Id id, std::unique_ptr<Resource>&& resource) noexcept
{
_resources[id] = std::move(resource);
}
inline const std::shared_ptr<Resource>& get(Id id) const
{
return _resources.find(id)->second;
}
private:
std::map<Id, std::shared_ptr<Resource>> _resources;
};
namespace Font
{
enum class Id
{
GUI
};
}
}

@ -1,5 +1,8 @@
#pragma once
namespace kku
{
class Sprite
{
public:
@ -7,3 +10,5 @@ public:
virtual void reset() = 0;
virtual void display() const = 0;
};
}

@ -4,6 +4,9 @@
#include <stack>
#include <map>
namespace kku
{
template<typename Type, class SpriteFactory, class Sprite,
typename = std::enable_if_t<std::is_enum<Type>::value>>
class SpriteContainer
@ -56,3 +59,5 @@ private:
std::size_t _poll_reserve_size;
};
}

@ -0,0 +1,65 @@
#pragma once
#include <variant>
#include "core/point.h"
namespace kku
{
struct SystemEvent
{
enum class Type
{
None = 0,
Resize = 1,
KeyPress = 2,
KeyRelease = 3,
MouseWheelScroll = 4,
MouseMove = 5,
MousePress = 6,
MouseRelease = 7
};
struct Size
{
std::size_t width = 0;
std::size_t height = 0;
};
struct Key
{
char view = char(0);
bool alt = false;
bool control = false;
bool shift = false;
};
struct Mouse
{
Point position;
bool scrolled_up = false;
enum class Button
{
None = 0,
Wheel = 1,
Left = 2,
Right = 3
};
Button button = Button::Left;
};
struct None
{};
Type type = Type::None;
std::variant<Size, Key, Mouse, None> data;
};
}

@ -0,0 +1,24 @@
#pragma once
#include <string>
#include "core/color.h"
#include "core/point.h"
#include "core/vector.h"
namespace kku
{
class Text
{
public:
virtual ~Text() = default;
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<float>& delta) = 0;
virtual void setColor(const Color& color) = 0;
virtual void display() = 0;
};
}

@ -0,0 +1,22 @@
#pragma once
namespace kku
{
using microsec = long long;
struct TimeRange
{
const microsec begin = 0;
const microsec end = 0;
constexpr inline explicit TimeRange() noexcept :
begin(0), end(0)
{}
constexpr inline explicit TimeRange(microsec x, microsec y) noexcept :
begin(x), end(y)
{}
};
}

@ -3,11 +3,13 @@
#include <set>
#include <memory>
#include <algorithm>
#include <iostream>
#include "tools/mathutils.h"
#include "core/time.h"
#include "core/note.h"
namespace kku
{
template <class TNote, class = std::enable_if_t<std::is_base_of<Note, TNote>::value>>
class Timeline
{
@ -29,7 +31,7 @@ public:
while (!isExpired(head_iterator))
{
if ((*head_iterator)->offset() >= offset)
if ((*head_iterator)->getPerfectOffset() >= offset)
{
Iterator pre_head = head_iterator;
--pre_head;
@ -48,7 +50,7 @@ public:
}
}
void setNotes(const std::set<TNote*, NotePtrCompt>& notes)
void setNotes(const std::set<TNote*, NotePtrComparator>& notes)
{
_timeline = std::move(notes);
@ -65,7 +67,7 @@ public:
update(_current_offset);
}
void insertNotes(const std::set<TNote*, NotePtrCompt>& notes)
void insertNotes(const std::set<TNote*, NotePtrComparator>& notes)
{
_timeline.insert(notes.begin(), notes.end());
recalculate(_current_offset);
@ -100,7 +102,7 @@ public:
return_note = note_iterator;
break;
}
else if (note->offset() > music_offset)
else if (note->getPerfectOffset() > music_offset)
break;
++note_iterator;
@ -114,7 +116,7 @@ public:
return std::find_if(_timeline.begin(), _timeline.end(),
[music_offset](const auto& note)
{
return note->offset() == music_offset;
return note->getPerfectOffset() == music_offset;
});
}
@ -134,14 +136,14 @@ public:
}
private:
std::set<TNote*, NotePtrCompt> _timeline;
std::set<TNote*, NotePtrComparator> _timeline;
microsec _current_offset;
inline void updateTopNote(const microsec& music_offset) noexcept
{
const auto& top_note = *_top_note;
bool already_played = top_note->offset() < music_offset
bool already_played = top_note->getPerfectOffset() < music_offset
&& !top_note->isActive(music_offset);
if (already_played)
@ -150,3 +152,7 @@ private:
Iterator _top_note;
};
}

@ -0,0 +1,16 @@
#pragma once
#include "core/time.h"
namespace kku
{
struct UpdateData
{
const microsec timestamp;
const microsec dt;
};
}

@ -0,0 +1,22 @@
#pragma once
#include <utility>
namespace kku
{
/* Meaning an element of a vector space in math.
* Don't mistake for std::vector<T>
* For now we don't need it as a special class,
* so let it be a wrapper. */
template <typename T>
using Vector2 = std::pair<T, T>;
template <typename T>
inline constexpr auto makeVector(T&& l, T&& r) -> Vector2<T>
{
return std::make_pair(std::forward<T>(l), std::forward<T>(r));
}
}

@ -1,35 +0,0 @@
#pragma once
#include <stack>
#include <memory>
#include <functional>
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Rect.hpp>
class GUIState : public sf::Drawable
{
public:
enum Tag {
SPLASH_SCREEN,
MAIN_MENU,
GAME_PICKER,
GAME,
EDITOR_PICKER,
EDITOR,
SETTINGS,
AMOUNT
};
virtual ~GUIState() = default;
virtual void input(const sf::Event& event) = 0;
virtual void update(const sf::Time& dt) = 0;
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override = 0;
virtual void enter(sf::Vector2u&& render_size) = 0;
virtual void leave() = 0;
};

@ -1,24 +0,0 @@
cmake_minimum_required(VERSION 2.8.8)
project(classicmode)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(${CMAKE_SOURCE_DIR}/include)
file(GLOB_RECURSE HEADERS "shared/*.h" )
file(GLOB_RECURSE SOURCES "editor/*.h" "editor/*.cpp"
"graphics/*.h" "graphics/*.cpp"
"game/*.h" "game/*.cpp"
"sfml/*.h" "sfml/*.cpp"
"./classicfactory.cpp")
add_library(classicmode STATIC ${SOURCES} ${HEADERS})
target_include_directories(classicmode PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(classicmode PRIVATE ${CMAKE_SOURCE_DIR}/tools/shared)
target_include_directories(classicmode PRIVATE ${CMAKE_SOURCE_DIR}/core/shared)
target_link_libraries(classicmode tools core)
target_include_directories(project-kyoku PRIVATE ${CMAKE_SOURCE_DIR}/modes/classicmode/shared)

@ -1,37 +0,0 @@
#pragma once
#include <memory>
#include "core/editor.h"
#include "core/timeline.h"
#include "game/classicnote.h"
#include "classicmode/classicactions.h"
class ClassicGraphicsManager;
class ClassicEditor : public Editor
{
public:
explicit ClassicEditor(const std::shared_ptr<Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager);
virtual void input(PlayerInput&& inputdata) override;
virtual void update(UpdateData&& updatedata) override;
virtual void display() const override;
virtual void recalculate(const microsec& timestamp) override;
void selectNoteType(Type type) noexcept;
private:
inline microsec adjustOffset(microsec offset) const noexcept;
Context _context;
const std::shared_ptr<Timeline<ClassicNote>> _timeline;
const std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
Type _selected_type;
microsec _current_time;
microsec _scroll_step;
};

@ -1,41 +0,0 @@
#include "mockclassicnote.h"
#include "graphics/classicgraphicsmanager.h"
#include "graphics/animations/classicanimationscenario.h"
MockClassicNote::MockClassicNote(MockArrowNoteInitializer&& init) :
ClassicNote({nullptr, {}, init.initializer.perfect_offset}),
_state(State::NONE),
_context(init.initializer.context)
{
_elements.resize(init.elements.size());
for (std::size_t i = 0; i < _elements.size(); ++i)
{
_elements[i].coordinates = init.elements[i].coordinates;
_elements[i].type = init.elements[i].type;
}
}
void MockClassicNote::putToGame()
{
_state = State::FLYING;
}
void MockClassicNote::update(const microsec &music_offset)
{
switch (_state)
{
default: return;
break;
case State::FLYING:
if (music_offset > offset())
_state = State::DEAD;
break;
}
for (auto& element : _elements)
if (element.animations[_state])
element.animations[_state]->update(music_offset);
}

@ -1,28 +0,0 @@
#pragma once
#include <memory>
#include <array>
#include "mockelement.h"
#include "game/classicnote.h"
#include "initializers/mockarrownoteinitializer.h"
class MockClassicNote : public ClassicNote
{
public:
explicit MockClassicNote(MockArrowNoteInitializer&& init);
virtual ~MockClassicNote() override = default;
virtual void putToGame() override;
virtual void update(const microsec &music_offset) override;
virtual void input(PlayerInput&& inputdata) override;
virtual void display(const ClassicGraphicsManager * const manager) const override;
virtual void setGraphics(ClassicGraphicsManager * const manager, TimeRange&& range) override;
private:
std::vector<MockElement> _elements;
State _state;
const Context *_context;
};

@ -1,21 +0,0 @@
#pragma once
#include "classicmode/classicactions.h"
#include "tools/mathutils.h"
#include <vector>
#include <memory>
#include <array>
class ClassicSprite;
class ClassicAnimationScenario;
struct MockElement
{
std::shared_ptr<ClassicSprite> sprite;
std::array<std::shared_ptr<ClassicAnimationScenario>, 4> animations;
Type type = Type::NONE;
Coordinates coordinates;
std::vector<Coordinates> falling_curve_interpolation;
};

@ -1,116 +0,0 @@
#include "classicgame.h"
#include "classicnote.h"
#include "classicmapcreator.h"
#include "graphics/classicscenegraphicsmanager.h"
#include "holdmanager.h"
ClassicGame::ClassicGame(const std::shared_ptr<Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager) :
_timeline(timeline),
_graphics_manager(graphics_manager),
_hold_manager(std::make_unique<HoldManager>())
{
_slap_buffer.loadFromFile("Tick.ogg");
_slap.setBuffer(_slap_buffer);
_slap.setVolume(50);
_keys_to_buttons =
{
{sf::Keyboard::Up, Type::UP}, // Load from settings
{sf::Keyboard::Right, Type::RIGHT},
{sf::Keyboard::Down, Type::DOWN},
{sf::Keyboard::Left, Type::LEFT},
{sf::Keyboard::W, Type::UP},
{sf::Keyboard::D, Type::RIGHT},
{sf::Keyboard::S, Type::DOWN},
{sf::Keyboard::A, Type::LEFT},
{sf::Keyboard::E, Type::SLIDER_RIGHT},
{sf::Keyboard::Q, Type::SLIDER_LEFT}
};
_buttons_to_pressed_actions=
{
{Type::UP, Action::PRESS_UP},
{Type::RIGHT, Action::PRESS_RIGHT},
{Type::DOWN, Action::PRESS_DOWN},
{Type::LEFT, Action::PRESS_LEFT},
{Type::SLIDER_RIGHT, Action::PRESS_SLIDER_RIGHT},
{Type::SLIDER_LEFT, Action::PRESS_SLIDER_LEFT}
};
_buttons_to_released_actions=
{
{Type::UP, Action::RELEASE_UP},
{Type::RIGHT, Action::RELEASE_RIGHT},
{Type::DOWN, Action::RELEASE_DOWN},
{Type::LEFT, Action::RELEASE_LEFT},
{Type::SLIDER_RIGHT, Action::RELEASE_SLIDER_RIGHT},
{Type::SLIDER_LEFT, Action::RELEASE_SLIDER_LEFT}
};
}
ClassicGame::~ClassicGame()
{}
void ClassicGame::run()
{
_context.hold_manager = _hold_manager;
auto beatmap = classic::createBeatmap("aa", _context);
_timeline->setNotes(beatmap.notes);
}
void ClassicGame::input(PlayerInput&& inputdata)
{
switch (inputdata.event.type)
{
default:
return;
break;
case sf::Event::KeyPressed:
{
auto note_it = _timeline->getActiveNote(inputdata.timestamp);
if (!_timeline->isExpired(note_it))
{
auto note = (*note_it);
note->input(std::move(inputdata));
_slap.play();
}
}
break;
case sf::Event::KeyReleased:
{
_hold_manager->checkRelease(inputdata.event.key.code);
}
break;
}
}
void ClassicGame::update(UpdateData&& updatedata)
{
// UNCOMMENT TO TEST AUTOPLAY
auto note_it = _timeline->getActiveNote(updatedata.timestamp);
if (!_timeline->isExpired(note_it) && updatedata.timestamp >= (*note_it)->offset())
{
auto note = (*note_it);
note->input(PlayerInput{updatedata.timestamp, sf::Event{}});
_slap.play();
}
_timeline->update(updatedata.timestamp);
_graphics_manager->update(updatedata.timestamp);
}
void ClassicGame::display() const
{
_graphics_manager->display();
}

@ -1,37 +0,0 @@
#include "classicdyinganimationscenario.h"
#include "graphics/classicsprite.h"
void ClassicDyingAnimationScenario::launch(const std::shared_ptr<ClassicSprite> sprite, const microsec& time_begin, const microsec &time_end)
{
_sprite = sprite;
_time_begin = time_begin;
_time_end = time_end;
_sprite->setColor(sf::Color(140, 140, 140));
_sprite->setTrailColor(sf::Color(0, 0, 0, 0));
_sprite->setTrailCoordinates(Coordinates(0, 0));
}
void ClassicDyingAnimationScenario::update(const microsec& music_offset)
{
(void) music_offset;
auto fill_color = _sprite->color();
if (fill_color.a == 0)
{
fill_color.a = 0;
_sprite->setColor(fill_color);
return;
}
auto new_alpha = fill_color.a - 15;
fill_color.a = new_alpha < 0 ? 0 : new_alpha;
_sprite->setColor(fill_color);
}
bool ClassicDyingAnimationScenario::isDone() const
{
return _sprite->color().a == 0;
}

@ -1,55 +0,0 @@
#include "classicflyinganimationscenario.h"
#include "graphics/classicsprite.h"
void ClassicFlyingAnimationScenario::launch(const std::shared_ptr<ClassicSprite> sprite, const microsec& time_begin, const microsec &time_end)
{
_sprite = sprite;
_time_begin = time_begin;
_time_end = time_end;
_percentage = ((_time_end - _time_begin) * 0.01);
}
float ClassicFlyingAnimationScenario::getPoint(float n1, float n2, float perc) const
{
float diff = n2 - n1;
return n1 + ( diff * perc );
}
void ClassicFlyingAnimationScenario::update(const microsec& music_offset)
{
const auto crd = _sprite->coordinates();
auto update_time = music_offset - _time_begin;
float i = update_time / _percentage * 0.01;
float xa = getPoint( crd.x + 20. , crd.x + 90. , i );
float ya = getPoint( crd.y - 600. , crd.y - 150. , i );
float xb = getPoint( crd.x + 90. , crd.x , i );
float yb = getPoint( crd.y - 150. , crd.y , i );
_sprite->setTrailCoordinates(Coordinates(getPoint( xa , xb , i ), getPoint( ya , yb , i )));
bool pastPerfectScore = (i >= 1);
if (pastPerfectScore)
fadeTrailSprite();
}
bool ClassicFlyingAnimationScenario::isDone() const
{
return false;
}
void ClassicFlyingAnimationScenario::fadeTrailSprite() const
{
auto fill_color = _sprite->trailColor();
if (fill_color.a == 0)
return;
auto new_alpha = fill_color.a - 35;
fill_color.a = new_alpha < 0 ? 0 : new_alpha;
_sprite->setTrailColor(fill_color);
}

@ -1,37 +0,0 @@
#pragma once
#include "game/classicnote.h"
#include "graphics/classicgraphicsmanager.h"
#include "core/timeline.h"
class ClassicSprite;
class ClassicSceneGraphicsManager : public ClassicGraphicsManager
{
public:
explicit ClassicSceneGraphicsManager(const std::shared_ptr<Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicSpriteFactory>& factory,
const microsec& visibility_offset);
virtual void display() const override;
virtual void update(const microsec& offset) override;
virtual void display(const std::vector<ArrowElement>& elements) const override;
virtual void setGraphics(std::vector<ArrowElement>& elements, TimeRange&& range) override;
protected:
using Iterator = Timeline<ClassicNote>::Iterator;
Iterator _first;
Iterator _last;
const std::shared_ptr<Timeline<ClassicNote>> _timeline;
inline bool nothingToDraw() const noexcept;
inline bool isVisiblyClose(const Iterator& iterator, const microsec& music_offset) const noexcept;