Only updates lines when changed
This commit is contained in:
parent
a5ce8b568d
commit
a4ef07ef3f
3 changed files with 8 additions and 1 deletions
|
@ -94,6 +94,9 @@ struct App{
|
||||||
for(auto & l : line.calculate_lines()){
|
for(auto & l : line.calculate_lines()){
|
||||||
sim.lines.push_back(l);
|
sim.lines.push_back(l);
|
||||||
}
|
}
|
||||||
|
for(auto & u : people_online){
|
||||||
|
u->update_lines = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void login(User& user){
|
void login(User& user){
|
||||||
|
|
|
@ -28,6 +28,7 @@ struct User {
|
||||||
unsigned int index{0};
|
unsigned int index{0};
|
||||||
std::string name{"Unknown guest"};
|
std::string name{"Unknown guest"};
|
||||||
|
|
||||||
|
bool update_lines{true};
|
||||||
Size size{0,0};
|
Size size{0,0};
|
||||||
Position position{0,0};
|
Position position{0,0};
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,10 @@ websockets::TestProtocol<User> default_protocol{
|
||||||
[](User& user, basic_websocket_info) -> std::string{
|
[](User& user, basic_websocket_info) -> std::string{
|
||||||
js::Object ret;
|
js::Object ret;
|
||||||
ret["balls"] = vector_to_json(app->sim.balls);
|
ret["balls"] = vector_to_json(app->sim.balls);
|
||||||
|
if(user.update_lines){
|
||||||
ret["lines"] = vector_to_json(app->sim.lines);
|
ret["lines"] = vector_to_json(app->sim.lines);
|
||||||
|
user.update_lines = false;
|
||||||
|
}
|
||||||
return write_json(ret);
|
return write_json(ret);
|
||||||
},
|
},
|
||||||
// receive
|
// receive
|
||||||
|
|
Reference in a new issue