Fix graphics removal

This commit is contained in:
NaiJi ✨ 2022-05-26 05:13:13 +03:00
parent 90292750fb
commit 55b8349e60
14 changed files with 64 additions and 26 deletions

View File

@ -35,6 +35,7 @@ public:
inline void resetSprite(const std::shared_ptr<Sprite> &sprite, Type action) noexcept
{
sprite->reset();
_sprite_dispatcher[action].push(sprite);
}

View File

@ -2,7 +2,7 @@
int main()
{
sf::RenderWindow window(sf::VideoMode{1280, 720}, "Project Kyoku", sf::Style::Fullscreen);
sf::RenderWindow window(sf::VideoMode{1280, 720}, "Project Kyoku", sf::Style::Default);
ApplicationSFML app(&window);
if (app.init())
app.run();

View File

@ -1,8 +1,9 @@
#include "classicmode/classicnote.h"
ClassicNote::ClassicNote(const kku::microsec& perfect_offset) :
ClassicNote::ClassicNote(const kku::microsec& perfect_offset, int id) :
Note(perfect_offset),
_state(State::NONE)
_state(State::NONE),
_id(id)
{}
void ClassicNote::setState(ClassicNote::State state) noexcept
@ -14,3 +15,8 @@ auto ClassicNote::getState() const noexcept -> State
{
return _state;
}
int ClassicNote::getId() const noexcept
{
return _id;
}

View File

@ -18,7 +18,8 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
_context(context),
_selected_type(Type::UP),
_current_time(0),
_scroll_step(500000)
_scroll_step(500000),
_note_id(0)
{
kku::microsec starting_beat_offset = 402162;
int amount_of_beats = 209;
@ -38,7 +39,6 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
float x = 90.;
int counter = 3;
while (bpm_iterator < bpm_end)
{
ArrowElement element;
@ -69,6 +69,7 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
ClassicArrowNote::Init init
{
_note_id++,
context,
bpm_iterator,
input_intervals,
@ -144,6 +145,7 @@ void ClassicEditor::input(kku::GameEvent&& input)
ClassicArrowNote::Init init
{
_note_id++,
_context,
_current_time,
{},

View File

@ -34,4 +34,5 @@ private:
Type _selected_type;
kku::microsec _current_time;
kku::microsec _scroll_step;
int _note_id;
};

View File

@ -76,7 +76,11 @@ void EditorContext::update(ClassicArrowNote *note, const kku::microsec& music_of
case ClassicArrowNote::State::DYING:
if (elements[0].animations[note->getState()]->isDone())
{
note->setState(ClassicArrowNote::State::DEAD);
for (auto& manager : _graphics_managers)
manager->update(music_offset, note);
}
break;
}

View File

@ -3,7 +3,7 @@
#include "graphics/classicgraphicsmanager.h"
ClassicArrowNote::ClassicArrowNote(Init&& init) :
ClassicNote(init.perfect_offset),
ClassicNote(init.perfect_offset, init.id),
_evaluator(init.intervals, init.perfect_offset),
_context(init.context),
_is_holding(init.is_holding)

View File

@ -14,6 +14,7 @@ public:
struct Init
{
const int id = 0;
const std::shared_ptr<const Context> context;
const kku::microsec perfect_offset = 0;

View File

@ -30,6 +30,7 @@ auto classic::createBeatmap(const std::string& filepath, const std::shared_ptr<G
int counter = 3;
int id = 0;
while (bpm_iterator < bpm_end)
{
ArrowElement element;
@ -60,6 +61,7 @@ auto classic::createBeatmap(const std::string& filepath, const std::shared_ptr<G
ClassicArrowNote::Init init
{
id++,
context,
bpm_iterator,
input_intervals,

View File

@ -8,6 +8,8 @@ void ClassicFlyingAnimationScenario::launch(const std::shared_ptr<ClassicNoteGra
_time_end = time_end;
_percentage = ((_time_end - _time_begin) * 0.01);
refillColor();
}
float ClassicFlyingAnimationScenario::getPoint(const kku::Point& point, float perc) const
@ -27,11 +29,6 @@ void ClassicFlyingAnimationScenario::update(const kku::microsec& music_offset)
float yb = getPoint(kku::Point{crd.y - 150, crd.y}, i);
_sprite->setTrailPosition(kku::Point(getPoint( kku::Point{xa, xb}, i ), getPoint( kku::Point{ya, yb}, i )));
bool pastPerfectScore = (i >= 1);
if (pastPerfectScore)
fadeTrailSprite();
}
bool ClassicFlyingAnimationScenario::isDone() const
@ -39,15 +36,7 @@ bool ClassicFlyingAnimationScenario::isDone() const
return false;
}
void ClassicFlyingAnimationScenario::fadeTrailSprite() const
void ClassicFlyingAnimationScenario::refillColor() const
{
auto fill_color = _sprite->getTrailColor();
if (fill_color.alpha == 0)
return;
auto new_alpha = (int(fill_color.alpha) - 15) < 0 ? 0 : int(fill_color.alpha) - 15;
fill_color.alpha = new_alpha;
_sprite->setTrailColor(fill_color);
_sprite->setTrailColor(_sprite->getColor());
}

View File

@ -12,7 +12,7 @@ public:
private:
float getPoint(const kku::Point& position, float perc) const;
void fadeTrailSprite() const;
void refillColor() const;
float _percentage;
};

View File

@ -1,6 +1,8 @@
#include "classicscenegraphicsmanager.h"
#include "game/classicarrownote.h"
#include <iostream>
ClassicSceneGraphicsManager::ClassicSceneGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicGraphicsFactory>& factory,
const kku::microsec& visibility_offset) :
@ -33,7 +35,9 @@ void ClassicSceneGraphicsManager::display() const
for (auto it = _first; it != _last; ++it)
{
(*it)->draw(shared_from_this());
const auto note = *it;
if (note->getState() != ClassicNote::State::DEAD)
note->draw(shared_from_this());
}
}
@ -48,8 +52,17 @@ void ClassicSceneGraphicsManager::update(const kku::microsec &offset)
void ClassicSceneGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note)
{
bool hasGraphics = (note->getElements()[0].sprite != nullptr);
if (isVisiblyClose(note, offset) && (!hasGraphics))
if (isVisiblyClose(note, offset) && !hasGraphics)
{
std::cout << note->getId() << ": set graphics!\n" << std::flush;
setGraphics(note->getElements(), kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
}
else
{
std::cout << note->getId() << ": remove graphics!\n" << std::flush;
removeGraphics(note->getElements());
}
}
void ClassicSceneGraphicsManager::draw(const std::vector<ArrowElement>& elements) const
@ -87,6 +100,20 @@ void ClassicSceneGraphicsManager::setGraphics(std::vector<ArrowElement>& element
}
}
void ClassicSceneGraphicsManager::removeGraphics(std::vector<ArrowElement>& elements)
{
for (auto& element : elements)
{
_sprite_container.resetSprite(element.sprite, element.type);
element.sprite = nullptr;
element.animations[ClassicNote::State::NONE] = nullptr;
element.animations[ClassicNote::State::FLYING] = nullptr;
element.animations[ClassicNote::State::DYING] = nullptr;
element.animations[ClassicNote::State::DEAD] = nullptr;
}
}
bool ClassicSceneGraphicsManager::nothingToDraw() const noexcept
{
return _timeline->isExpired(_first)

View File

@ -24,7 +24,10 @@ public:
virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override;
virtual void draw(const std::vector<ArrowElement>& elements) const override;
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range);
void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range);
void removeGraphics(std::vector<ArrowElement>& elements);
protected:
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container;

View File

@ -19,7 +19,7 @@ public:
DEAD = 4
};
explicit ClassicNote(const kku::microsec& perfect_offset);
explicit ClassicNote(const kku::microsec& perfect_offset, int id);
virtual ~ClassicNote() override = default;
virtual bool isActive(const kku::microsec& offset) const override = 0;
@ -29,7 +29,9 @@ public:
void setState(State state) noexcept;
State getState() const noexcept;
int getId() const noexcept;
protected:
State _state;
int _id;
};