Multi-user gravity beats for Sound of Science 2013 (server)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 

42 lines
1012 B

#pragma once
#include <chrono>
#include <cmath>
#include <vector>
#include <algorithm>
#include "basics.h"
struct App{
std::vector<User*> people_online;
int uid{0};
void update_positions(){
const float speed = 0.4;
typedef std::chrono::duration<double, std::ratio<1,1>> fseconds;
static auto start = std::chrono::steady_clock::now();
auto end = std::chrono::steady_clock::now();
double time = std::chrono::duration_cast<fseconds>(end-start).count();
//std::cout << time << std::endl;
auto n = people_online.size();
for(int i = 0; i < n; ++i){
User& user = *people_online[i];
double x = cos(speed * time + 2*M_PI*i/double(n));
double y = sin(speed * time + 2*M_PI*i/double(n));
user.position.x = 200 + 200*x;
user.position.y = 200 + 200*y;
}
}
void login(User& user){
user.index = uid++;
people_online.push_back(&user);
}
void logout(User& user){
people_online.erase(std::remove(people_online.begin(), people_online.end(), &user), people_online.end());
}
};