Adjust game process to new game context

selection
NaiJi ✨ 2 years ago
parent 45132ff82a
commit c24ecc0acc

@ -34,14 +34,9 @@ void ClassicArrowNote::input(kku::GameEvent&& input)
_context->input(this, std::move(input));
}
void ClassicArrowNote::setGraphics(const std::shared_ptr<const ClassicGraphicsManager>& graphics_manager, kku::TimeRange&& range) const
{
}
void ClassicArrowNote::draw(const std::shared_ptr<const ClassicGraphicsManager>& graphics_manager) const
{
graphics_manager->draw(this);
graphics_manager->draw(_elements);
}
bool ClassicArrowNote::isHold() const
@ -49,7 +44,7 @@ bool ClassicArrowNote::isHold() const
return _is_holding;
}
const std::vector<ArrowElement>& ClassicArrowNote::getElements() const
std::vector<ArrowElement>& ClassicArrowNote::getElements()
{
return _elements;
}

@ -35,11 +35,10 @@ public:
virtual bool isActive(const kku::microsec& offset) const override;
virtual void update(const kku::microsec &music_offset) override;
virtual void input(kku::GameEvent&& input) override;
virtual void setGraphics(const std::shared_ptr<const ClassicGraphicsManager>& graphics_manager, kku::TimeRange&& range) const override;
virtual void draw(const std::shared_ptr<const ClassicGraphicsManager> &graphics_manager) const override;
bool isHold() const;
const std::vector<ArrowElement>& getElements() const;
std::vector<ArrowElement>& getElements();
Grade calculatePrecision(const kku::microsec& offset) const;
bool isPressedAs(kku::SystemEvent::Key::Code key) const;

@ -3,6 +3,7 @@
#include "classicmapcreator.h"
#include "gamecontext.h"
#include "holdmanager.h"
#include "graphics/classicgraphicsmanager.h"
ClassicGame::ClassicGame(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
const std::shared_ptr<GameContext>& context) :
@ -60,9 +61,10 @@ void ClassicGame::update(kku::UpdateData&& updatedata)
}*/
_timeline->update(updatedata.timestamp);
_context->getGraphicsManager()->update(updatedata.timestamp);
}
void ClassicGame::display() const
{
_context->display();
_context->getGraphicsManager()->display();
}

@ -66,6 +66,11 @@ void GameContext::update(ClassicArrowNote *note, const kku::microsec& music_offs
default: return;
break;
case ClassicArrowNote::State::INITIAL:
note->setState(ClassicArrowNote::State::FLYING);
_graphics_manager->update(music_offset, note);
break;
case ClassicArrowNote::State::FLYING:
if (!note->isActive(music_offset) && music_offset > note->getPerfectOffset())
{
@ -91,7 +96,7 @@ std::shared_ptr<HoldManager> GameContext::getHoldManager() const
return _hold_manager;
}
void GameContext::display() const
std::shared_ptr<ClassicGraphicsManager> GameContext::getGraphicsManager() const
{
_graphics_manager->display();
return _graphics_manager;
}

@ -14,9 +14,9 @@ public:
virtual void input(ClassicArrowNote *note, kku::GameEvent&& input) const override;
virtual void update(ClassicArrowNote *note, const kku::microsec &music_offset) const override;
virtual void display() const override;
std::shared_ptr<HoldManager> getHoldManager() const;
std::shared_ptr<ClassicGraphicsManager> getGraphicsManager() const;
private:
const std::shared_ptr<HoldManager> _hold_manager;

@ -4,8 +4,10 @@
#include "core/gameevent.h"
#include <memory>
#include <vector>
class ClassicArrowNote;
class ArrowElement;
// class ClassicSliderNote;
class ClassicGraphicsManager : public std::enable_shared_from_this<ClassicGraphicsManager>
@ -18,10 +20,12 @@ public:
virtual void input(kku::GameEvent&& input) = 0;
virtual void display() const = 0;
virtual void update(const kku::microsec& offset) = 0;
virtual void update(const kku::microsec& offset, ClassicArrowNote* note) = 0;
// virtual void update(const kku::microsec& offset, ClassicSliderNote* note) = 0;
virtual void draw(const ClassicArrowNote* note) const = 0;
virtual void draw(const std::vector<ArrowElement>& elements) const = 0;
// virtual void draw(ClassicSliderNote* note) const = 0;
protected:

@ -37,19 +37,23 @@ void ClassicSceneGraphicsManager::display() const
}
}
void ClassicSceneGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note)
void ClassicSceneGraphicsManager::update(const kku::microsec &offset)
{
//TODO
(void)note;
fetchLastNote(offset);
fetchFirstNote(offset);
updateVisibleNotes(offset);
}
void ClassicSceneGraphicsManager::draw(const ClassicArrowNote* note) const
void ClassicSceneGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note)
{
bool hasGraphics = (note->getElements()[0].sprite != nullptr);
if (isVisiblyClose(note, offset) && (!hasGraphics))
setGraphics(note->getElements(), kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
}
void ClassicSceneGraphicsManager::draw(const std::vector<ArrowElement>& elements) const
{
auto& elements = note->getElements();
for (std::size_t i = 0; i < elements.size(); ++i)
{
const auto& sprite = elements[i].sprite;
@ -89,9 +93,9 @@ bool ClassicSceneGraphicsManager::nothingToDraw() const noexcept
|| _timeline->isExpired(_last);
}
bool ClassicSceneGraphicsManager::isVisiblyClose(const Iterator& iterator, const kku::microsec& music_offset) const noexcept
bool ClassicSceneGraphicsManager::isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept
{
return ((*iterator)->getPerfectOffset() - _visibility_offset) <= music_offset;
return (note->getPerfectOffset() - _visibility_offset) <= music_offset;
}
void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset)
@ -102,7 +106,7 @@ 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;
}
@ -110,12 +114,13 @@ void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset)
_first = note_iterator;
auto note = *_first;
if (note->getState() != ClassicNote::State::FLYING
&& note->getState() != ClassicNote::State::DYING
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::FLYING);
note->setGraphics(shared_from_this(), kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
note->setState(ClassicNote::State::INITIAL);
}
}
else
@ -138,19 +143,19 @@ void ClassicSceneGraphicsManager::fetchFirstNote(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;
if (note->getState() != ClassicNote::State::FLYING
&& note->getState() != ClassicNote::State::DYING
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::FLYING);
note->setGraphics(shared_from_this(), kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
note->setState(ClassicNote::State::INITIAL);
}
++note_iterator;

@ -20,9 +20,10 @@ public:
virtual void input(kku::GameEvent&& input) override;
virtual void display() const override;
virtual void update(const kku::microsec& offset) override;
virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override;
virtual void draw(const ClassicArrowNote* note) const override;
virtual void draw(const std::vector<ArrowElement>& elements) const override;
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range);
protected:
@ -37,7 +38,7 @@ protected:
const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline;
inline bool nothingToDraw() const noexcept;
inline bool isVisiblyClose(const Iterator& iterator, 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 fetchLastNote(const kku::microsec& offset);
void updateVisibleNotes(const kku::microsec& offset);

@ -13,9 +13,10 @@ public:
{
NONE = 0,
FLYING = 1,
DYING = 2,
DEAD = 3
INITIAL = 1,
FLYING = 2,
DYING = 3,
DEAD = 4
};
explicit ClassicNote(const kku::microsec& perfect_offset);
@ -24,8 +25,6 @@ public:
virtual bool isActive(const kku::microsec& offset) const override = 0;
virtual void update(const kku::microsec &music_offset) override = 0;
virtual void input(kku::GameEvent&& input) override = 0;
virtual void setGraphics(const std::shared_ptr<const ClassicGraphicsManager>& graphics_manager, kku::TimeRange&& range) const = 0;
virtual void draw(const std::shared_ptr<const ClassicGraphicsManager>& graphics_manager) const = 0;
void setState(State state) noexcept;

@ -12,5 +12,4 @@ public:
virtual void input(ClassicArrowNote *note, kku::GameEvent&& input) const = 0;
virtual void update(ClassicArrowNote *note, const kku::microsec &music_offset) const = 0;
virtual void display() const = 0;
};

Loading…
Cancel
Save