Fix graphics removal
This commit is contained in:
parent
90292750fb
commit
55b8349e60
|
@ -35,6 +35,7 @@ public:
|
||||||
|
|
||||||
inline void resetSprite(const std::shared_ptr<Sprite> &sprite, Type action) noexcept
|
inline void resetSprite(const std::shared_ptr<Sprite> &sprite, Type action) noexcept
|
||||||
{
|
{
|
||||||
|
sprite->reset();
|
||||||
_sprite_dispatcher[action].push(sprite);
|
_sprite_dispatcher[action].push(sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
int main()
|
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);
|
ApplicationSFML app(&window);
|
||||||
if (app.init())
|
if (app.init())
|
||||||
app.run();
|
app.run();
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include "classicmode/classicnote.h"
|
#include "classicmode/classicnote.h"
|
||||||
|
|
||||||
ClassicNote::ClassicNote(const kku::microsec& perfect_offset) :
|
ClassicNote::ClassicNote(const kku::microsec& perfect_offset, int id) :
|
||||||
Note(perfect_offset),
|
Note(perfect_offset),
|
||||||
_state(State::NONE)
|
_state(State::NONE),
|
||||||
|
_id(id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void ClassicNote::setState(ClassicNote::State state) noexcept
|
void ClassicNote::setState(ClassicNote::State state) noexcept
|
||||||
|
@ -14,3 +15,8 @@ auto ClassicNote::getState() const noexcept -> State
|
||||||
{
|
{
|
||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ClassicNote::getId() const noexcept
|
||||||
|
{
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
|
||||||
_context(context),
|
_context(context),
|
||||||
_selected_type(Type::UP),
|
_selected_type(Type::UP),
|
||||||
_current_time(0),
|
_current_time(0),
|
||||||
_scroll_step(500000)
|
_scroll_step(500000),
|
||||||
|
_note_id(0)
|
||||||
{
|
{
|
||||||
kku::microsec starting_beat_offset = 402162;
|
kku::microsec starting_beat_offset = 402162;
|
||||||
int amount_of_beats = 209;
|
int amount_of_beats = 209;
|
||||||
|
@ -38,7 +39,6 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
|
||||||
float x = 90.;
|
float x = 90.;
|
||||||
|
|
||||||
int counter = 3;
|
int counter = 3;
|
||||||
|
|
||||||
while (bpm_iterator < bpm_end)
|
while (bpm_iterator < bpm_end)
|
||||||
{
|
{
|
||||||
ArrowElement element;
|
ArrowElement element;
|
||||||
|
@ -69,6 +69,7 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
|
||||||
|
|
||||||
ClassicArrowNote::Init init
|
ClassicArrowNote::Init init
|
||||||
{
|
{
|
||||||
|
_note_id++,
|
||||||
context,
|
context,
|
||||||
bpm_iterator,
|
bpm_iterator,
|
||||||
input_intervals,
|
input_intervals,
|
||||||
|
@ -144,6 +145,7 @@ void ClassicEditor::input(kku::GameEvent&& input)
|
||||||
|
|
||||||
ClassicArrowNote::Init init
|
ClassicArrowNote::Init init
|
||||||
{
|
{
|
||||||
|
_note_id++,
|
||||||
_context,
|
_context,
|
||||||
_current_time,
|
_current_time,
|
||||||
{},
|
{},
|
||||||
|
|
|
@ -34,4 +34,5 @@ private:
|
||||||
Type _selected_type;
|
Type _selected_type;
|
||||||
kku::microsec _current_time;
|
kku::microsec _current_time;
|
||||||
kku::microsec _scroll_step;
|
kku::microsec _scroll_step;
|
||||||
|
int _note_id;
|
||||||
};
|
};
|
||||||
|
|
|
@ -76,7 +76,11 @@ void EditorContext::update(ClassicArrowNote *note, const kku::microsec& music_of
|
||||||
|
|
||||||
case ClassicArrowNote::State::DYING:
|
case ClassicArrowNote::State::DYING:
|
||||||
if (elements[0].animations[note->getState()]->isDone())
|
if (elements[0].animations[note->getState()]->isDone())
|
||||||
|
{
|
||||||
note->setState(ClassicArrowNote::State::DEAD);
|
note->setState(ClassicArrowNote::State::DEAD);
|
||||||
|
for (auto& manager : _graphics_managers)
|
||||||
|
manager->update(music_offset, note);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "graphics/classicgraphicsmanager.h"
|
#include "graphics/classicgraphicsmanager.h"
|
||||||
|
|
||||||
ClassicArrowNote::ClassicArrowNote(Init&& init) :
|
ClassicArrowNote::ClassicArrowNote(Init&& init) :
|
||||||
ClassicNote(init.perfect_offset),
|
ClassicNote(init.perfect_offset, init.id),
|
||||||
_evaluator(init.intervals, init.perfect_offset),
|
_evaluator(init.intervals, init.perfect_offset),
|
||||||
_context(init.context),
|
_context(init.context),
|
||||||
_is_holding(init.is_holding)
|
_is_holding(init.is_holding)
|
||||||
|
|
|
@ -14,6 +14,7 @@ public:
|
||||||
|
|
||||||
struct Init
|
struct Init
|
||||||
{
|
{
|
||||||
|
const int id = 0;
|
||||||
const std::shared_ptr<const Context> context;
|
const std::shared_ptr<const Context> context;
|
||||||
const kku::microsec perfect_offset = 0;
|
const kku::microsec perfect_offset = 0;
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ auto classic::createBeatmap(const std::string& filepath, const std::shared_ptr<G
|
||||||
|
|
||||||
int counter = 3;
|
int counter = 3;
|
||||||
|
|
||||||
|
int id = 0;
|
||||||
while (bpm_iterator < bpm_end)
|
while (bpm_iterator < bpm_end)
|
||||||
{
|
{
|
||||||
ArrowElement element;
|
ArrowElement element;
|
||||||
|
@ -60,6 +61,7 @@ auto classic::createBeatmap(const std::string& filepath, const std::shared_ptr<G
|
||||||
|
|
||||||
ClassicArrowNote::Init init
|
ClassicArrowNote::Init init
|
||||||
{
|
{
|
||||||
|
id++,
|
||||||
context,
|
context,
|
||||||
bpm_iterator,
|
bpm_iterator,
|
||||||
input_intervals,
|
input_intervals,
|
||||||
|
|
|
@ -8,6 +8,8 @@ void ClassicFlyingAnimationScenario::launch(const std::shared_ptr<ClassicNoteGra
|
||||||
_time_end = time_end;
|
_time_end = time_end;
|
||||||
|
|
||||||
_percentage = ((_time_end - _time_begin) * 0.01);
|
_percentage = ((_time_end - _time_begin) * 0.01);
|
||||||
|
|
||||||
|
refillColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ClassicFlyingAnimationScenario::getPoint(const kku::Point& point, float perc) const
|
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);
|
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 )));
|
_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
|
bool ClassicFlyingAnimationScenario::isDone() const
|
||||||
|
@ -39,15 +36,7 @@ bool ClassicFlyingAnimationScenario::isDone() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassicFlyingAnimationScenario::fadeTrailSprite() const
|
void ClassicFlyingAnimationScenario::refillColor() const
|
||||||
{
|
{
|
||||||
auto fill_color = _sprite->getTrailColor();
|
_sprite->setTrailColor(_sprite->getColor());
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float getPoint(const kku::Point& position, float perc) const;
|
float getPoint(const kku::Point& position, float perc) const;
|
||||||
void fadeTrailSprite() const;
|
void refillColor() const;
|
||||||
|
|
||||||
float _percentage;
|
float _percentage;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "classicscenegraphicsmanager.h"
|
#include "classicscenegraphicsmanager.h"
|
||||||
#include "game/classicarrownote.h"
|
#include "game/classicarrownote.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
ClassicSceneGraphicsManager::ClassicSceneGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
ClassicSceneGraphicsManager::ClassicSceneGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
||||||
const std::shared_ptr<ClassicGraphicsFactory>& factory,
|
const std::shared_ptr<ClassicGraphicsFactory>& factory,
|
||||||
const kku::microsec& visibility_offset) :
|
const kku::microsec& visibility_offset) :
|
||||||
|
@ -33,7 +35,9 @@ void ClassicSceneGraphicsManager::display() const
|
||||||
|
|
||||||
for (auto it = _first; it != _last; ++it)
|
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)
|
void ClassicSceneGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note)
|
||||||
{
|
{
|
||||||
bool hasGraphics = (note->getElements()[0].sprite != nullptr);
|
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()});
|
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
|
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
|
bool ClassicSceneGraphicsManager::nothingToDraw() const noexcept
|
||||||
{
|
{
|
||||||
return _timeline->isExpired(_first)
|
return _timeline->isExpired(_first)
|
||||||
|
|
|
@ -24,7 +24,10 @@ public:
|
||||||
|
|
||||||
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 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:
|
protected:
|
||||||
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container;
|
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container;
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
DEAD = 4
|
DEAD = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ClassicNote(const kku::microsec& perfect_offset);
|
explicit ClassicNote(const kku::microsec& perfect_offset, int id);
|
||||||
virtual ~ClassicNote() override = default;
|
virtual ~ClassicNote() override = default;
|
||||||
|
|
||||||
virtual bool isActive(const kku::microsec& offset) const override = 0;
|
virtual bool isActive(const kku::microsec& offset) const override = 0;
|
||||||
|
@ -29,7 +29,9 @@ public:
|
||||||
|
|
||||||
void setState(State state) noexcept;
|
void setState(State state) noexcept;
|
||||||
State getState() const noexcept;
|
State getState() const noexcept;
|
||||||
|
int getId() const noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
State _state;
|
State _state;
|
||||||
|
int _id;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue