Commit ccede621 authored by Kevin Balz's avatar Kevin Balz
Browse files

Update hud_system to detected beats

parent b70d11a4
Pipeline #3297 failed with stage
in 4 minutes and 44 seconds
......@@ -76,4 +76,12 @@ namespace phase_shifter::gameplay {
}
}
const std::vector<float>& Beat_system::time_stamps() const {
return _time_stamps;
}
int Beat_system::beat_index() const {
return _beat_index;
}
} // namespace phase_shifter::gameplay
......@@ -29,6 +29,9 @@ namespace phase_shifter::gameplay {
auto graphic_time_scale() const -> float;
const std::vector<float>& time_stamps() const ;
int beat_index() const;
private:
mirrage::util::Message_bus& _bus;
mirrage::asset::Asset_manager& _assets;
......
......@@ -14,9 +14,10 @@ namespace phase_shifter::ui {
namespace {
constexpr auto hud_height = 100;
constexpr auto bar_height = 90;
constexpr auto beat_bar_height = 80;
constexpr auto bar_height = 80;
constexpr auto beat_bar_height = 79;
constexpr auto bar_speed = 100;
constexpr auto beat_bar_length = 300.0f;
} // namespace
Hud_system::Hud_system(mirrage::gui::Gui& gui,
......@@ -27,9 +28,8 @@ namespace phase_shifter::ui {
//_circle_texture = _gui.load_texture("tex:circle"_aid);
}
void Hud_system::update(mirrage::util::Time dt)
{
_offset = _beat_system.beat_state().time_to_beat * bar_speed;
void Hud_system::update(mirrage::util::Time dt) {
_passed += dt.value();
}
void Hud_system::draw()
......@@ -63,20 +63,27 @@ namespace phase_shifter::ui {
ImGui::PushStyleColor(ImGuiCol_Border, "#00000000"_imcolor.Value); // Hide Border
ImVec2 cursor = ImGui::GetCursorScreenPos();
cursor.y += hud_height / 2.f - 10;
auto beat_state = _beat_system.beat_state();
auto line_offset = bar_speed * beat_state.avg_beat_time;
auto beats = std::clamp(beat_state.beats_left, 0, 5);
auto beat_state = _beat_system.beat_state();
auto beats = _beat_system.time_stamps();
auto beat_index = _beat_system.beat_index() + 1;
//auto line_offset = bar_speed * beat_state.avg_beat_time;
//auto beats = std::clamp(beat_state.beats_left, 0, 5);
ImGui::BeginChild("Line", {viewport.z, bar_height}, true);
ImDrawList* drawList = ImGui::GetWindowDrawList();
for(int i = 0; i < beats; i++) {
auto x_offset = _offset + i * line_offset;
auto height = beat_bar_height * (1.f - glm::smoothstep(0.f, beats * line_offset, x_offset));
while (beat_index < beats.size()) {
auto x_offset = (beats[beat_index] - _passed) * bar_speed;
auto height = beat_bar_height * (1.f - glm::smoothstep(0.f, beat_bar_length, x_offset));
ImVec2 p(cursor.x + viewport.z / 2 - x_offset, cursor.y - height / 2.f);
drawList->AddLine(p, {p.x, p.y + height}, 0xFFFFFFFF, 1);
p.x = cursor.x + viewport.z / 2 + x_offset;
drawList->AddLine(p, {p.x, p.y + height}, 0xFFFFFFFF, 1);
if(x_offset > beat_bar_length + 50) {
break;
}
beat_index++;
}
ImVec2 middle(cursor.x + viewport.z / 2, cursor.y - bar_height / 2.f);
......
......@@ -24,7 +24,7 @@ namespace phase_shifter::ui {
private:
mirrage::gui::Gui& _gui;
mirrage::ecs::Entity_manager& _ecs;
float _offset = 0;
float _passed = 0;
const phase_shifter::gameplay::Beat_system& _beat_system;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment