Browse Source

Cheaper lines (and single lines)

master
Joshua Moerman 12 years ago
parent
commit
7486b68ec3
  1. 3
      src/app.h
  2. 19
      src/app_common.h
  3. 2
      src/main.cpp

3
src/app.h

@ -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);
} }

19
src/app_common.h

@ -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)
)

2
src/main.cpp

@ -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);