Archived
1
Fork 0

Cheaper lines (and single lines)

This commit is contained in:
Joshua Moerman 2013-04-09 16:16:39 +02:00
parent 97a5e453ad
commit 7486b68ec3
3 changed files with 23 additions and 1 deletions

View file

@ -14,6 +14,8 @@ struct App{
std::vector<User*> people_online; std::vector<User*> people_online;
libwebsocket * uberclient{nullptr}; libwebsocket * uberclient{nullptr};
std::vector<AbstractLine> lines;
simu_type sim; simu_type sim;
beat_type beat; beat_type beat;
@ -29,6 +31,7 @@ struct App{
} }
void add_line(AbstractLine const & line){ void add_line(AbstractLine const & line){
lines.push_back(line);
for(auto & l : line.calculate_lines()){ for(auto & l : line.calculate_lines()){
sim.lines.push_back(l); sim.lines.push_back(l);
} }

View file

@ -85,3 +85,22 @@ BOOST_FUSION_ADAPT_STRUCT(
(IntVec2, position) (IntVec2, position)
(ball_info, information) (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)
)

View file

@ -32,7 +32,7 @@ websockets::TestProtocol<User> default_protocol{
js::Object ret; js::Object ret;
ret["balls"] = vector_to_json(app->sim.balls, [](ball_type const & b){return cheap_ball_type(b);}); ret["balls"] = vector_to_json(app->sim.balls, [](ball_type const & b){return cheap_ball_type(b);});
if(user.update_lines){ 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; user.update_lines = false;
} }
return write_json(ret); return write_json(ret);