#pragma once #include #include #include #include #include #include #include "basics.h" #include "adaptions.h" #include "simulation/Simulation.h" #include "simulation/Beat.h" using Vec2 = math::Vec2; using LineKind = simulation::LineKind; using ball_info = int; using line_info = void; using ball_type = simulation::Ball; using line_type = simulation::Line; using simu_type = simulation::Simulation; using note_info = Vec2; using note_type = Note; using beat_type = Beat; struct AbstractLine { math::Vec2 starting_point; math::Vec2 end_point; int line_kind; const float hsize = 5.0f; AbstractLine() = default; AbstractLine(math::Vec2 starting_point, math::Vec2 end_point, int line_kind) : starting_point(starting_point) , end_point(end_point) , line_kind(line_kind) {} // create 6 lines, to emulate width, and rounded edges std::vector calculate_lines() const { auto dir = normalize(end_point - starting_point); auto normal = rotate_ccw(dir); LineKind lk = static_cast(line_kind); if(line_kind == simulation::kOneWay){ std::vector ret; ret.emplace_back(starting_point + hsize*normal, end_point + hsize*normal, lk); ret.emplace_back(end_point + hsize*normal, end_point + hsize*dir, lk); ret.emplace_back(end_point + hsize*dir, end_point - hsize*normal, lk); ret.emplace_back(end_point - hsize*normal, starting_point - hsize*normal, lk); ret.emplace_back(starting_point - hsize*normal, starting_point - hsize*dir, lk); ret.emplace_back(starting_point - hsize*dir, starting_point + hsize*normal, lk); return ret; } else { std::vector ret; ret.emplace_back(starting_point, end_point, lk); return ret; } } }; BOOST_FUSION_ADAPT_STRUCT( AbstractLine, (::math::Vec2, starting_point) (::math::Vec2, end_point) (int, line_kind) ) struct libwebsocket; struct App{ std::vector people_online; libwebsocket * uberclient{nullptr}; simu_type sim; beat_type beat; const float iframerate = 1.0/60.0; int peopleuid{0}; int balluid{0}; App(){ beat.notes.emplace_back(note_type::kQuarterNote, note_info{100.0f, 100.0f}); AbstractLine line(Vec2{50.0f, 100.0f}, Vec2{150.0f, 200.0f}, simulation::kOneWay); add_line(line); } void add_line(AbstractLine const & line){ for(auto & l : line.calculate_lines()){ sim.lines.push_back(l); } } void login(User& user){ user.index = peopleuid++; people_online.push_back(&user); } void logout(User& user){ people_online.erase(std::remove(people_online.begin(), people_online.end(), &user), people_online.end()); } void update(){ float dt = iframerate; sim.update(dt); for(auto n : beat.update(dt)){ sim.balls.emplace_back(n.x, n.y, 0, 0, balluid++); } } };