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.
60 lines
1.2 KiB
60 lines
1.2 KiB
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
#include <chrono>
|
|
#include <cmath>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
#include "app_common.h"
|
|
|
|
struct libwebsocket;
|
|
struct App{
|
|
std::vector<User*> people_online;
|
|
libwebsocket * uberclient{nullptr};
|
|
|
|
std::vector<AbstractLine> lines;
|
|
|
|
simu_type sim;
|
|
beat_type beat;
|
|
|
|
const float iframerate = 1.0/60.0;
|
|
int peopleuid{0};
|
|
int balluid{0};
|
|
|
|
App(){
|
|
beat.notes.emplace_back(note_type::kQuarterNote, note_info{100.0f, 100.0f});
|
|
|
|
AbstractLine line(Vec2{50.0f, 100.0f}, Vec2{150.0f, 200.0f}, simulation::kOneWay);
|
|
add_line(line);
|
|
}
|
|
|
|
void add_line(AbstractLine const & line){
|
|
lines.push_back(line);
|
|
for(auto & l : line.calculate_lines()){
|
|
sim.lines.push_back(l);
|
|
}
|
|
for(auto & u : people_online){
|
|
u->update_lines = true;
|
|
}
|
|
}
|
|
|
|
void login(User& user){
|
|
user.index = peopleuid++;
|
|
people_online.push_back(&user);
|
|
}
|
|
|
|
void logout(User& user){
|
|
people_online.erase(std::remove(people_online.begin(), people_online.end(), &user), people_online.end());
|
|
}
|
|
|
|
void update(){
|
|
float dt = iframerate;
|
|
sim.update(dt);
|
|
|
|
for(auto n : beat.update(dt)){
|
|
sim.balls.emplace_back(n.x, n.y, 0, 0, balluid++);
|
|
}
|
|
}
|
|
};
|