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

Beat visualizer

parent 7103ba0d
Pipeline #3231 failed with stage
in 1 minute and 42 seconds
......@@ -17,7 +17,7 @@ namespace phase_shifter::gameplay {
_acc = 0;
}
_state = {beat, _acc, beat_time - _acc};
_state = {beat, _acc, beat_time - _acc, beat_time};
}
} // namespace phase_shifter::gameplay
......@@ -14,20 +14,27 @@ namespace phase_shifter::ui {
namespace {
constexpr auto hud_height = 100;
constexpr auto count_down = 300;
}
constexpr auto bar_speed = 100;
} // namespace
Hud_system::Hud_system(mirrage::gui::Gui& gui,
mirrage::ecs::Entity_manager& ecs,
Hud_system::Hud_system(mirrage::gui::Gui& gui,
mirrage::ecs::Entity_manager& ecs,
const phase_shifter::gameplay::Beat_system& beat_system)
: _gui(gui)
, _ecs(ecs)
, _timeLeft(count_down)
, _beat_system(beat_system)
: _gui(gui), _ecs(ecs), _timeLeft(count_down), _beat_system(beat_system)
{
//_circle_texture = _gui.load_texture("tex:circle"_aid);
_max_distance = gui.viewport().z / 2;
}
void Hud_system::update(mirrage::util::Time dt) {
void Hud_system::update(mirrage::util::Time dt)
{
_timeLeft -= dt;
auto state = _beat_system.beat_state();
int max_bars = (int) (_max_distance / (bar_speed * state.avg_beat_time) + 1);
if(state.beat && _beats < max_bars) {
_beats++;
}
_offset = state.time_to_beat * bar_speed;
}
void Hud_system::draw()
......@@ -42,32 +49,51 @@ namespace phase_shifter::ui {
ImGui::WindowPosition_X::left,
ImGui::WindowPosition_Y::top);
if(ImGui::Begin("hud",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground)) {
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoBackground)) {
ImGui::Text("%.2f", _timeLeft.value());
ImGui::End();
}
ImGui::PositionNextWindow(glm::vec2(viewport.z, hud_height),
ImGui::WindowPosition_X::center,
ImGui::WindowPosition_Y::bottom);
ImGui::PositionNextWindow(
glm::vec2(viewport.z, 150), ImGui::WindowPosition_X::center, ImGui::WindowPosition_Y::bottom);
if(ImGui::Begin("beat",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground)) {
/*
ImVec2 p = ImGui::GetCursorScreenPos();
ImGui::BeginChild("Line", {200, 100}, true);
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoBackground)) {
ImGui::PushStyleColor(ImGuiCol_Border, "#00000000"_imcolor.Value); // Hide Border
ImVec2 cursor = ImGui::GetCursorScreenPos();
auto beat_state = _beat_system.beat_state();
int max_bars = (int) (_max_distance / (bar_speed * beat_state.avg_beat_time) + 1);
auto line_offset = bar_speed * beat_state.avg_beat_time;
auto start_offset = (max_bars - _beats) * line_offset;
ImGui::BeginChild("Line", {viewport.z, 90}, true);
ImDrawList* drawList = ImGui::GetWindowDrawList();
drawList->AddLine(p, {p.x, p.y + 50}, 0xFF0000FF, 10);
for(int i = 0; i < _beats; i++) {
ImVec2 p(cursor.x + _max_distance - _offset - start_offset - i * line_offset, cursor.y + 10);
drawList->AddLine(p, {p.x, p.y + 50}, 0xFFFFFFFF, 1);
}
for(int i = 0; i < _beats; i++) {
ImVec2 p(cursor.x + viewport.z / 2 + _offset + start_offset + i * line_offset, cursor.y + 10);
drawList->AddLine(p, {p.x, p.y + 50}, 0xFFFFFFFF, 1);
}
ImVec2 middle(cursor.x + viewport.z / 2, cursor.y);
drawList->AddLine(middle, {middle.x, middle.y + 70}, 0xFFFF0000, 3);
ImGui::EndChild();
*/
auto time_to_beat = _beat_system.beat_state().time_to_beat;
ImVec4 col = time_to_beat < 0.05f ? ImVec4(1, 0, 0, 1) : ImVec4(1,1,1,1);
ImGui::TextColored(col, "%.2f", time_to_beat);
ImGui::PopStyleColor();
ImGui::End();
if(beat_state.beat || beat_state.avg_beat_time - beat_state.time_since_beat < 0.1f
|| beat_state.time_to_beat < 0.1f) {
//TODO: Flash image to beat
//ImGui::Image(_circle_texture.get(), {10, 10});
}
}
if(font.is_some())
......
......@@ -24,6 +24,9 @@ namespace phase_shifter::ui {
mirrage::gui::Gui& _gui;
mirrage::ecs::Entity_manager& _ecs;
mirrage::util::Time _timeLeft;
int _beats = 0;
float _offset = 0;
float _max_distance;
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