Changed LineKind to int, for assignability, now reading new lines :D
This commit is contained in:
parent
b7f3670329
commit
4bcf5682b0
2 changed files with 30 additions and 10 deletions
32
src/app.h
32
src/app.h
|
@ -29,11 +29,13 @@ using beat_type = Beat<note_info>;
|
|||
struct AbstractLine {
|
||||
math::Vec2 starting_point;
|
||||
math::Vec2 end_point;
|
||||
LineKind line_kind;
|
||||
int line_kind;
|
||||
|
||||
const float hsize = 5.0f;
|
||||
|
||||
AbstractLine(math::Vec2 starting_point, math::Vec2 end_point, LineKind line_kind)
|
||||
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)
|
||||
|
@ -43,24 +45,32 @@ struct AbstractLine {
|
|||
std::vector<line_type> calculate_lines() const {
|
||||
auto dir = normalize(end_point - starting_point);
|
||||
auto normal = rotate_ccw(dir);
|
||||
LineKind lk = static_cast<LineKind>(line_kind);
|
||||
|
||||
if(line_kind == simulation::kOneWay){
|
||||
std::vector<line_type> ret;
|
||||
ret.emplace_back(starting_point + hsize*normal, end_point + hsize*normal, line_kind);
|
||||
ret.emplace_back(end_point + hsize*normal, end_point + hsize*dir, line_kind);
|
||||
ret.emplace_back(end_point + hsize*dir, end_point - hsize*normal, line_kind);
|
||||
ret.emplace_back(end_point - hsize*normal, starting_point - hsize*normal, line_kind);
|
||||
ret.emplace_back(starting_point - hsize*normal, starting_point - hsize*dir, line_kind);
|
||||
ret.emplace_back(starting_point - hsize*dir, starting_point + hsize*normal, line_kind);
|
||||
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<line_type> ret;
|
||||
ret.emplace_back(starting_point, end_point, line_kind);
|
||||
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<User*> people_online;
|
||||
|
@ -77,6 +87,10 @@ struct 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);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,13 @@ websockets::TestProtocol<User> default_protocol{
|
|||
// receive
|
||||
[](User& user, std::string in, basic_websocket_info){
|
||||
try{
|
||||
user = from_json<IncomingPacket>(parse_json(in));
|
||||
auto object = parse_json(in).getObject();
|
||||
auto command = object["command"];
|
||||
if(command == "add line"){
|
||||
app->add_line(from_json<AbstractLine>(object["data"]));
|
||||
} else if (command == "update user") {
|
||||
user = from_json<IncomingPacket>(object["data"]);
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
throw websockets::runtime_error(e.what());
|
||||
}
|
||||
|
|
Reference in a new issue