forked from NaiJi/project-kyoku
Implement Timeline Graphics Manager view
This commit is contained in:
parent
cf33d7c172
commit
4b91146c33
|
@ -15,7 +15,6 @@
|
|||
|
||||
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 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)
|
||||
{
|
||||
// read offset from beatmap metadata
|
||||
const kku::microsec visibility_offset = 1648648;
|
||||
|
||||
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
|
||||
|
|
|
@ -53,6 +53,14 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
|
|||
|
||||
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)
|
||||
{
|
||||
hold = true;
|
||||
|
@ -163,8 +171,9 @@ void ClassicEditor::input(kku::GameEvent&& input)
|
|||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_context->inputUI(std::move(input));
|
||||
}
|
||||
|
||||
void ClassicEditor::update(kku::UpdateData&& updatedata)
|
||||
|
|
|
@ -94,6 +94,12 @@ std::shared_ptr<SelectionManager<ClassicNote>> EditorContext::getSelectionManage
|
|||
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)
|
||||
{
|
||||
for (auto& manager : _graphics_managers)
|
||||
|
|
|
@ -17,6 +17,7 @@ public:
|
|||
virtual void input(ClassicArrowNote *note, kku::GameEvent&& input) 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 displayGraphics() const;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ void ClassicArrowNote::input(kku::GameEvent&& input)
|
|||
|
||||
void ClassicArrowNote::draw(const std::shared_ptr<const ClassicGraphicsManager>& graphics_manager) const
|
||||
{
|
||||
graphics_manager->draw(_elements);
|
||||
graphics_manager->draw(this);
|
||||
}
|
||||
|
||||
bool ClassicArrowNote::isHold() const
|
||||
|
@ -49,6 +49,11 @@ std::vector<ArrowElement>& ClassicArrowNote::getElements()
|
|||
return _elements;
|
||||
}
|
||||
|
||||
const std::vector<ArrowElement>& ClassicArrowNote::getElements() const
|
||||
{
|
||||
return _elements;
|
||||
}
|
||||
|
||||
auto ClassicArrowNote::calculatePrecision(const kku::microsec& offset) const -> Grade
|
||||
{
|
||||
return _evaluator.calculatePrecision(offset);
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
|
||||
bool isHold() const;
|
||||
std::vector<ArrowElement>& getElements();
|
||||
const std::vector<ArrowElement>& getElements() const;
|
||||
Grade calculatePrecision(const kku::microsec& offset) const;
|
||||
bool isPressedAs(kku::SystemEvent::Key::Code key) const;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
virtual void update(const kku::microsec& offset, ClassicArrowNote* 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;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
const auto& sprite = elements[i].sprite;
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
virtual void update(const kku::microsec& offset) 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 removeGraphics(std::vector<ArrowElement>& elements);
|
||||
|
|
|
@ -11,7 +11,9 @@ ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared
|
|||
Type::LEFT, Type::RIGHT},
|
||||
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(_last);
|
||||
|
@ -19,34 +21,49 @@ ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared
|
|||
|
||||
void ClassicTimelineGraphicsManager::input(kku::GameEvent&& input)
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
switch (input.event.type)
|
||||
{
|
||||
(*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
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
//if (nothingToDraw())
|
||||
//return;
|
||||
|
||||
std::cout << "displaying on tl: ";
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
{
|
||||
const auto note = *it;
|
||||
if (note->getState() != ClassicNote::State::DEAD)
|
||||
note->draw(shared_from_this());
|
||||
std::cout << (*it)->getId() << " ";
|
||||
(*it)->draw(shared_from_this());
|
||||
}
|
||||
|
||||
std::cout << "\n" << std::flush;
|
||||
}
|
||||
|
||||
void ClassicTimelineGraphicsManager::update(const kku::microsec &offset)
|
||||
{
|
||||
_last_offset = offset;
|
||||
fetchLastNote(offset);
|
||||
fetchFirstNote(offset);
|
||||
|
||||
updateVisibleNotes(offset);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
//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();
|
||||
timeline_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
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
//if (nothingToDraw())
|
||||
//return;
|
||||
|
||||
if (offset < (*_first)->getPerfectOffset())
|
||||
Iterator note_iterator = _first;
|
||||
while (note_iterator != _timeline->begin() && isVisiblyClose(*note_iterator, offset))
|
||||
{
|
||||
Iterator note_iterator = _first;
|
||||
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);
|
||||
}
|
||||
--note_iterator;
|
||||
}
|
||||
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)
|
||||
|
@ -142,24 +136,8 @@ void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& 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())
|
||||
{
|
||||
note->setState(ClassicNote::State::INITIAL);
|
||||
}
|
||||
|
||||
++note_iterator;
|
||||
}
|
||||
|
||||
_last = note_iterator;
|
||||
}
|
||||
|
||||
void ClassicTimelineGraphicsManager::updateVisibleNotes(const kku::microsec& offset)
|
||||
{
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
(*it)->update(offset);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
virtual void update(const kku::microsec& offset) 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:
|
||||
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container;
|
||||
|
@ -35,10 +35,11 @@ protected:
|
|||
Iterator _last;
|
||||
|
||||
const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline;
|
||||
kku::microsec _back_visibility_offset;
|
||||
kku::microsec _last_offset;
|
||||
|
||||
inline bool nothingToDraw() const noexcept;
|
||||
inline bool isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept;
|
||||
void fetchFirstNote(const kku::microsec& offset);
|
||||
void fetchLastNote(const kku::microsec& offset);
|
||||
void updateVisibleNotes(const kku::microsec& offset);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue