From 7486b68ec3378b0b1be2c5396da8bddcc35c5418 Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Tue, 9 Apr 2013 16:16:39 +0200 Subject: [PATCH] Cheaper lines (and single lines) --- src/app.h | 3 +++ src/app_common.h | 19 +++++++++++++++++++ src/main.cpp | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/app.h b/src/app.h index ddd758d..d7f2ca4 100644 --- a/src/app.h +++ b/src/app.h @@ -14,6 +14,8 @@ struct App{ std::vector people_online; libwebsocket * uberclient{nullptr}; + std::vector lines; + simu_type sim; beat_type beat; @@ -29,6 +31,7 @@ struct App{ } void add_line(AbstractLine const & line){ + lines.push_back(line); for(auto & l : line.calculate_lines()){ sim.lines.push_back(l); } diff --git a/src/app_common.h b/src/app_common.h index 86fb37a..a5024a4 100644 --- a/src/app_common.h +++ b/src/app_common.h @@ -85,3 +85,22 @@ BOOST_FUSION_ADAPT_STRUCT( (IntVec2, position) (ball_info, information) ) + +struct cheap_line_type { + IntVec2 starting_point; + IntVec2 end_point; + int line_kind; + + cheap_line_type(AbstractLine const & l) + : starting_point(l.starting_point) + , end_point(l.end_point) + , line_kind(l.line_kind) + {} +}; + +BOOST_FUSION_ADAPT_STRUCT( + cheap_line_type, + (IntVec2, starting_point) + (IntVec2, end_point) + (int, line_kind) +) diff --git a/src/main.cpp b/src/main.cpp index 80adc38..f6ebd3f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,7 +32,7 @@ websockets::TestProtocol default_protocol{ js::Object ret; ret["balls"] = vector_to_json(app->sim.balls, [](ball_type const & b){return cheap_ball_type(b);}); if(user.update_lines){ - ret["lines"] = vector_to_json(app->sim.lines); + ret["lines"] = vector_to_json(app->lines, [](AbstractLine const & l){return cheap_line_type(l);}); user.update_lines = false; } return write_json(ret);