Implement Timeline Graphics Manager view

This commit is contained in:
NaiJi ✨ 2022-05-28 08:52:59 +03:00
parent cf33d7c172
commit 4b91146c33
11 changed files with 84 additions and 84 deletions

View File

@ -15,7 +15,6 @@
std::unique_ptr<kku::Game> classic::getGame(const std::shared_ptr<kku::CoreFactory>& core_factory) std::unique_ptr<kku::Game> classic::getGame(const std::shared_ptr<kku::CoreFactory>& core_factory)
{ {
// read offset from beatmap metadata
const kku::microsec visibility_offset = 1648648; const kku::microsec visibility_offset = 1648648;
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory); const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
@ -30,7 +29,6 @@ std::unique_ptr<kku::Game> classic::getGame(const std::shared_ptr<kku::CoreFacto
std::unique_ptr<kku::Editor> classic::getEditor(const std::shared_ptr<kku::CoreFactory>& core_factory) std::unique_ptr<kku::Editor> classic::getEditor(const std::shared_ptr<kku::CoreFactory>& core_factory)
{ {
// read offset from beatmap metadata
const kku::microsec visibility_offset = 1648648; const kku::microsec visibility_offset = 1648648;
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory); const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);

View File

@ -53,6 +53,14 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
bool hold = false; bool hold = false;
if (_note_id == 0)
{
element.keys = {kku::SystemEvent::Key::Code::S,
kku::SystemEvent::Key::Code::Down};
element.type = Type::DOWN;
}
if (counter == 0) if (counter == 0)
{ {
hold = true; hold = true;
@ -163,8 +171,9 @@ void ClassicEditor::input(kku::GameEvent&& input)
break; break;
} }
} }
_context->inputUI(std::move(input));
} }
void ClassicEditor::update(kku::UpdateData&& updatedata) void ClassicEditor::update(kku::UpdateData&& updatedata)

View File

@ -94,6 +94,12 @@ std::shared_ptr<SelectionManager<ClassicNote>> EditorContext::getSelectionManage
return _selection_manager; return _selection_manager;
} }
void EditorContext::inputUI(kku::GameEvent&& input)
{
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)

View File

@ -17,6 +17,7 @@ public:
virtual void input(ClassicArrowNote *note, kku::GameEvent&& input) const override; virtual void input(ClassicArrowNote *note, kku::GameEvent&& input) const override;
virtual void update(ClassicArrowNote *note, const kku::microsec &music_offset) const override; virtual void update(ClassicArrowNote *note, const kku::microsec &music_offset) const override;
void inputUI(kku::GameEvent&& input);
void updateGraphics(const kku::microsec& music_offset); void updateGraphics(const kku::microsec& music_offset);
void displayGraphics() const; void displayGraphics() const;

View File

@ -36,7 +36,7 @@ void ClassicArrowNote::input(kku::GameEvent&& input)
void ClassicArrowNote::draw(const std::shared_ptr<const ClassicGraphicsManager>& graphics_manager) const void ClassicArrowNote::draw(const std::shared_ptr<const ClassicGraphicsManager>& graphics_manager) const
{ {
graphics_manager->draw(_elements); graphics_manager->draw(this);
} }
bool ClassicArrowNote::isHold() const bool ClassicArrowNote::isHold() const
@ -49,6 +49,11 @@ std::vector<ArrowElement>& ClassicArrowNote::getElements()
return _elements; return _elements;
} }
const std::vector<ArrowElement>& 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); return _evaluator.calculatePrecision(offset);

View File

@ -40,6 +40,7 @@ public:
bool isHold() const; bool isHold() const;
std::vector<ArrowElement>& getElements(); std::vector<ArrowElement>& getElements();
const std::vector<ArrowElement>& getElements() const;
Grade calculatePrecision(const kku::microsec& offset) const; Grade calculatePrecision(const kku::microsec& offset) const;
bool isPressedAs(kku::SystemEvent::Key::Code key) const; bool isPressedAs(kku::SystemEvent::Key::Code key) const;

View File

@ -25,7 +25,7 @@ public:
virtual void update(const kku::microsec& offset, ClassicArrowNote* note) = 0; virtual void update(const kku::microsec& offset, ClassicArrowNote* note) = 0;
// virtual void update(const kku::microsec& offset, ClassicSliderNote* note) = 0; // virtual void update(const kku::microsec& offset, ClassicSliderNote* note) = 0;
virtual void draw(const std::vector<ArrowElement>& elements) const = 0; virtual void draw(const ClassicArrowNote * const note) const = 0;
// virtual void draw(ClassicSliderNote* note) const = 0; // virtual void draw(ClassicSliderNote* note) const = 0;
protected: protected:

View File

@ -65,8 +65,9 @@ void ClassicSceneGraphicsManager::update(const kku::microsec& offset, ClassicArr
} }
} }
void ClassicSceneGraphicsManager::draw(const std::vector<ArrowElement>& elements) const void ClassicSceneGraphicsManager::draw(const ClassicArrowNote * const note) const
{ {
const auto elements = note->getElements();
for (std::size_t i = 0; i < elements.size(); ++i) for (std::size_t i = 0; i < elements.size(); ++i)
{ {
const auto& sprite = elements[i].sprite; const auto& sprite = elements[i].sprite;

View File

@ -23,7 +23,7 @@ public:
virtual void update(const kku::microsec& offset) override; virtual void update(const kku::microsec& offset) override;
virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override; virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override;
virtual void draw(const std::vector<ArrowElement>& elements) const override; virtual void draw(const ClassicArrowNote * const note) const override;
void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range); void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range);
void removeGraphics(std::vector<ArrowElement>& elements); void removeGraphics(std::vector<ArrowElement>& elements);

View File

@ -11,7 +11,9 @@ ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared
Type::LEFT, Type::RIGHT}, Type::LEFT, Type::RIGHT},
factory), factory),
_factory(factory), _factory(factory),
_timeline(timeline) _timeline(timeline),
_back_visibility_offset(static_cast<double>(visibility_offset) / 4.f),
_last_offset(0)
{ {
_timeline->expire(_first); _timeline->expire(_first);
_timeline->expire(_last); _timeline->expire(_last);
@ -19,34 +21,49 @@ ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared
void ClassicTimelineGraphicsManager::input(kku::GameEvent&& input) void ClassicTimelineGraphicsManager::input(kku::GameEvent&& input)
{ {
if (nothingToDraw()) switch (input.event.type)
return;
for (auto it = _first; it != _last; ++it)
{ {
(*it)->input(std::move(input)); default:
break;
case kku::SystemEvent::Type::KeyPress:
{
const auto key_data = std::get<kku::SystemEvent::Key>(input.event.data);
if (key_data.view == kku::SystemEvent::Key::Code::Add)
{
_visibility_offset += 200000;
_back_visibility_offset = static_cast<double>(_visibility_offset) / 4.f;
}
else if (key_data.view == kku::SystemEvent::Key::Code::Subtract)
{
_visibility_offset -= 200000;
_back_visibility_offset = static_cast<double>(_visibility_offset) / 4.f;
}
break;
}
} }
} }
void ClassicTimelineGraphicsManager::display() const void ClassicTimelineGraphicsManager::display() const
{ {
if (nothingToDraw()) //if (nothingToDraw())
return; //return;
std::cout << "displaying on tl: ";
for (auto it = _first; it != _last; ++it) for (auto it = _first; it != _last; ++it)
{ {
const auto note = *it; std::cout << (*it)->getId() << " ";
if (note->getState() != ClassicNote::State::DEAD) (*it)->draw(shared_from_this());
note->draw(shared_from_this());
} }
std::cout << "\n" << std::flush;
} }
void ClassicTimelineGraphicsManager::update(const kku::microsec &offset) void ClassicTimelineGraphicsManager::update(const kku::microsec &offset)
{ {
_last_offset = offset;
fetchLastNote(offset); fetchLastNote(offset);
fetchFirstNote(offset); fetchFirstNote(offset);
updateVisibleNotes(offset);
} }
void ClassicTimelineGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note) void ClassicTimelineGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note)
@ -63,21 +80,23 @@ void ClassicTimelineGraphicsManager::update(const kku::microsec& offset, Classic
} }
} }
void ClassicTimelineGraphicsManager::draw(const std::vector<ArrowElement>& elements) const void ClassicTimelineGraphicsManager::draw(const ClassicArrowNote * const note) const
{ {
const double d_visibility_offset = static_cast<double>(_last_offset + _visibility_offset);
const double d_back_visibility_offset = static_cast<double>(_last_offset - _back_visibility_offset);
const double span = d_visibility_offset - d_back_visibility_offset;
const double note_span = static_cast<double>(note->getPerfectOffset()) - d_visibility_offset;
const double percent = note_span / (span / 100.f);
const auto elements = note->getElements();
for (std::size_t i = 0; i < elements.size(); ++i) for (std::size_t i = 0; i < elements.size(); ++i)
{ {
const auto& sprite = elements[i].sprite; auto timeline_sprite = _factory->createSprite(elements[i].type);
timeline_sprite->setPosition(kku::Point{static_cast<int>(850 + 1280.f / 100.f * percent), 700});
if (i >= 1) timeline_sprite->display();
{
//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));
}
sprite->display();
} }
} }
@ -89,49 +108,24 @@ bool ClassicTimelineGraphicsManager::nothingToDraw() const noexcept
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
{ {
return (note->getPerfectOffset() - _visibility_offset) <= music_offset; const auto& perfect_offset = note->getPerfectOffset();
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()) //if (nothingToDraw())
return; //return;
if (offset < (*_first)->getPerfectOffset()) Iterator note_iterator = _first;
while (note_iterator != _timeline->begin() && isVisiblyClose(*note_iterator, offset))
{ {
Iterator note_iterator = _first; --note_iterator;
while (note_iterator != _timeline->begin() && isVisiblyClose(*note_iterator, offset))
{
--note_iterator;
}
_first = note_iterator;
auto note = *_first;
const auto state = note->getState();
if (state != ClassicNote::State::FLYING
&& state != ClassicNote::State::DYING
&& state != ClassicNote::State::INITIAL
&& offset <= note->getPerfectOffset())
{
note->setState(ClassicNote::State::INITIAL);
}
} }
else
{
Iterator note_iterator = _first;
while (note_iterator != _last)
{
auto note = *note_iterator;
if (note->getState() == ClassicNote::State::DEAD)
{
// note->removeGraphics(this);
++_first;
}
++note_iterator; _first = note_iterator;
}
}
} }
void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& offset) void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& offset)
@ -142,24 +136,8 @@ void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& offset)
if (nothingToDraw()) if (nothingToDraw())
_first = note_iterator; _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())
{
note->setState(ClassicNote::State::INITIAL);
}
++note_iterator; ++note_iterator;
} }
_last = note_iterator; _last = note_iterator;
} }
void ClassicTimelineGraphicsManager::updateVisibleNotes(const kku::microsec& offset)
{
for (auto it = _first; it != _last; ++it)
(*it)->update(offset);
}

View File

@ -23,7 +23,7 @@ public:
virtual void update(const kku::microsec& offset) override; virtual void update(const kku::microsec& offset) override;
virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override; virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override;
virtual void draw(const std::vector<ArrowElement>& elements) const override; virtual void draw(const ClassicArrowNote * const note) const override;
protected: protected:
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container; kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container;
@ -35,10 +35,11 @@ protected:
Iterator _last; Iterator _last;
const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline; const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline;
kku::microsec _back_visibility_offset;
kku::microsec _last_offset;
inline bool nothingToDraw() const noexcept; inline bool nothingToDraw() const noexcept;
inline bool isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept; inline bool isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept;
void fetchFirstNote(const kku::microsec& offset); void fetchFirstNote(const kku::microsec& offset);
void fetchLastNote(const kku::microsec& offset); void fetchLastNote(const kku::microsec& offset);
void updateVisibleNotes(const kku::microsec& offset);
}; };