Added drum and stereo sound (reversed?)
This commit is contained in:
parent
56748e1349
commit
666197087e
3 changed files with 96 additions and 6 deletions
|
@ -111,13 +111,13 @@ void GameRenderer::draw(Client const & client){
|
||||||
gl::draw_arrays(GL_POINTS, 0, client.beat.notes.size());
|
gl::draw_arrays(GL_POINTS, 0, client.beat.notes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!client.lines.empty()){
|
if(!client.lines.empty() || client.kick || client.snare){
|
||||||
moggle::gl::blend_function(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
moggle::gl::blend_function(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
line_shader.s.use();
|
line_shader.s.use();
|
||||||
line_shader.s.uniform<matrix<float, 4>>("modelViewProjectionMatrix").set(modelViewProjectionMatrix);
|
line_shader.s.uniform<matrix<float, 4>>("modelViewProjectionMatrix").set(modelViewProjectionMatrix);
|
||||||
|
|
||||||
lines.clear();
|
lines.clear();
|
||||||
lines.reserve(client.lines.size() * 2);
|
lines.reserve(client.lines.size() * 2 + 2 * 2);
|
||||||
for(auto const & l : client.lines){
|
for(auto const & l : client.lines){
|
||||||
Color color = (l->line_kind == simulation::kFallThrough)
|
Color color = (l->line_kind == simulation::kFallThrough)
|
||||||
? Color{1.0f, l->color_intensity, std::sin(l->color_intensity)}
|
? Color{1.0f, l->color_intensity, std::sin(l->color_intensity)}
|
||||||
|
@ -126,6 +126,17 @@ void GameRenderer::draw(Client const & client){
|
||||||
lines.push_back({l->end_point, color});
|
lines.push_back({l->end_point, color});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(client.kick){
|
||||||
|
Color color{0.6f + client.kick->color_intensity, 0.5f, 0.4f};
|
||||||
|
lines.push_back({client.kick->starting_point, color});
|
||||||
|
lines.push_back({client.kick->end_point, color});
|
||||||
|
}
|
||||||
|
if(client.snare){
|
||||||
|
Color color{0.6f + client.snare->color_intensity, 0.7f, 0.8f};
|
||||||
|
lines.push_back({client.snare->starting_point, color});
|
||||||
|
lines.push_back({client.snare->end_point, color});
|
||||||
|
}
|
||||||
|
|
||||||
if(debug_draw){
|
if(debug_draw){
|
||||||
for(auto const & l : client.sim.lines){
|
for(auto const & l : client.sim.lines){
|
||||||
Color color = (l.line_kind == simulation::kFallThrough) ? Color{1.0, 0.0, 0.0} : Color{0.0, 0.5, 1.0};
|
Color color = (l.line_kind == simulation::kFallThrough) ? Color{1.0, 0.0, 0.0} : Color{0.0, 0.5, 1.0};
|
||||||
|
|
|
@ -44,8 +44,18 @@ namespace games {
|
||||||
case LWS_CALLBACK_CLIENT_WRITEABLE:{
|
case LWS_CALLBACK_CLIENT_WRITEABLE:{
|
||||||
js::Object ret;
|
js::Object ret;
|
||||||
if(current_client->lines_changed){
|
if(current_client->lines_changed){
|
||||||
|
int extra = 0;
|
||||||
|
if(current_client->kick){
|
||||||
|
current_client->lines.push_back(current_client->kick);
|
||||||
|
extra++;
|
||||||
|
}
|
||||||
|
if(current_client->snare){
|
||||||
|
current_client->lines.push_back(current_client->snare);
|
||||||
|
extra++;
|
||||||
|
}
|
||||||
ret["lines"] = vector_to_json(current_client->lines, [](std::shared_ptr<Instrument> const & i){return cheap_line_type(*i);});
|
ret["lines"] = vector_to_json(current_client->lines, [](std::shared_ptr<Instrument> const & i){return cheap_line_type(*i);});
|
||||||
current_client->lines_changed = false;
|
current_client->lines_changed = false;
|
||||||
|
current_client->lines.erase(current_client->lines.end()-extra, current_client->lines.end());
|
||||||
} else {
|
} else {
|
||||||
ret["balls"] = vector_to_json(current_client->sim.balls, [](ball_type const & b){return cheap_ball_type(b);});
|
ret["balls"] = vector_to_json(current_client->sim.balls, [](ball_type const & b){return cheap_ball_type(b);});
|
||||||
}
|
}
|
||||||
|
@ -102,6 +112,28 @@ namespace games {
|
||||||
lines_changed = true;
|
lines_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::add_drum(){
|
||||||
|
kick = std::make_shared<Instrument>(math::Vec2{x1 - 25.0f, window_height - 100.0f}, math::Vec2{x1 + 25.0f, window_height - 50.0f}, 1, -1);
|
||||||
|
kick->sound.reset(new motor::al::Source(sounds[2]));
|
||||||
|
for(auto & l : kick->calculate_lines()){
|
||||||
|
sim.lines.push_back(l);
|
||||||
|
}
|
||||||
|
snare = std::make_shared<Instrument>(math::Vec2{x3 - 25.0f, window_height - 50.0f}, math::Vec2{x3 + 25.0f, window_height - 100.0f}, 1, -2);
|
||||||
|
snare->sound.reset(new motor::al::Source(sounds[3]));
|
||||||
|
for(auto & l : snare->calculate_lines()){
|
||||||
|
sim.lines.push_back(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::remove_drum(){
|
||||||
|
auto& v = sim.lines;
|
||||||
|
v.erase(std::remove_if(v.begin(), v.end(), [this](line_type const &l2){ return kick.get() == l2.information; }), v.end());
|
||||||
|
v.erase(std::remove_if(v.begin(), v.end(), [this](line_type const &l2){ return snare.get() == l2.information; }), v.end());
|
||||||
|
|
||||||
|
kick.reset();
|
||||||
|
snare.reset();
|
||||||
|
}
|
||||||
|
|
||||||
bool Client::has_ended(){
|
bool Client::has_ended(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -115,6 +147,10 @@ namespace games {
|
||||||
}
|
}
|
||||||
current_client = this;
|
current_client = this;
|
||||||
|
|
||||||
|
x1 = window_width / 5.0f;
|
||||||
|
x2 = window_width / 2.0f;
|
||||||
|
x3 = 4.0f * window_width / 5.0f;
|
||||||
|
|
||||||
// sound
|
// sound
|
||||||
for(auto & str : scale_files){
|
for(auto & str : scale_files){
|
||||||
scales.push_back(Scale::load_from_file(str));
|
scales.push_back(Scale::load_from_file(str));
|
||||||
|
@ -123,13 +159,20 @@ namespace games {
|
||||||
|
|
||||||
chords.notes.emplace_back(note_type::kWholeNote, note_info{100.0f, 100.0f});
|
chords.notes.emplace_back(note_type::kWholeNote, note_info{100.0f, 100.0f});
|
||||||
|
|
||||||
|
add_drum();
|
||||||
|
|
||||||
|
alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
|
||||||
|
alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f);
|
||||||
|
ALfloat atup[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f};
|
||||||
|
alListenerfv(AL_ORIENTATION, atup);
|
||||||
|
|
||||||
// simulation
|
// simulation
|
||||||
sim.bounds.xmax = window_width_;
|
sim.bounds.xmax = window_width_;
|
||||||
sim.bounds.ymax = window_height_;
|
sim.bounds.ymax = window_height_;
|
||||||
|
|
||||||
beat.notes.emplace_back(note_type::kQuarterNote, note_info{window_width / 5.0f, 10.0f});
|
beat.notes.emplace_back(note_type::kQuarterNote, note_info{x1, 10.0f});
|
||||||
beat.notes.emplace_back(note_type::kWholeNote, note_info{window_width / 2.0f, 10.0f});
|
beat.notes.emplace_back(note_type::kWholeNote, note_info{x2, 10.0f});
|
||||||
beat.notes.emplace_back(note_type::kHalfNote, note_info{4.0f * window_width / 5.0f, 10.0f});
|
beat.notes.emplace_back(note_type::kHalfNote, note_info{x3, 10.0f});
|
||||||
|
|
||||||
// websockets
|
// websockets
|
||||||
lws_context_creation_info info;
|
lws_context_creation_info info;
|
||||||
|
@ -144,6 +187,7 @@ namespace games {
|
||||||
if(!context) throw std::runtime_error("context could not be created.");
|
if(!context) throw std::runtime_error("context could not be created.");
|
||||||
|
|
||||||
std::string address = "127.0.0.1";
|
std::string address = "127.0.0.1";
|
||||||
|
// std::string address = "vadovas-studios.com";
|
||||||
wsi = libwebsocket_client_connect(context, address.c_str(), 7681, false, "/", address.c_str(), "origin", "uberclient", -1);
|
wsi = libwebsocket_client_connect(context, address.c_str(), 7681, false, "/", address.c_str(), "origin", "uberclient", -1);
|
||||||
if(!wsi) throw std::runtime_error("socket could not be created.");
|
if(!wsi) throw std::runtime_error("socket could not be created.");
|
||||||
|
|
||||||
|
@ -194,8 +238,25 @@ namespace games {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(input.keys_went_down[SDLK_l]){
|
if(input.keys_went_down[SDLK_l]){
|
||||||
|
bool restore_drum = false;
|
||||||
|
if(kick || snare){
|
||||||
|
remove_drum();
|
||||||
|
restore_drum = true;
|
||||||
|
}
|
||||||
|
|
||||||
lines.clear();
|
lines.clear();
|
||||||
sim.lines.clear();
|
sim.lines.clear();
|
||||||
|
|
||||||
|
if(restore_drum) add_drum();
|
||||||
|
lines_changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(input.keys_went_down[SDLK_d]){
|
||||||
|
if(kick || snare){
|
||||||
|
remove_drum();
|
||||||
|
} else {
|
||||||
|
add_drum();
|
||||||
|
}
|
||||||
lines_changed = true;
|
lines_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,9 +303,15 @@ namespace games {
|
||||||
// simulation
|
// simulation
|
||||||
for(auto l : lines){
|
for(auto l : lines){
|
||||||
l->update(dt2);
|
l->update(dt2);
|
||||||
|
if(kick) kick->update(dt2);
|
||||||
|
if(snare) snare->update(dt2);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto x : sim.update(sim_speed * dt2)){
|
for(auto x : sim.update(sim_speed * dt2)){
|
||||||
|
float phi = x.ball.position.x / window_width - 0.5f;
|
||||||
|
float xpos = sin(M_PI * phi);
|
||||||
|
float zpos = cos(M_PI * phi);
|
||||||
|
x.line.information->sound->set_position({2.0f*xpos, 0.0f, 1.0f*zpos});
|
||||||
x.line.information->play();
|
x.line.information->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
q, w, e: music speed (= generation of balls)
|
q, w, e: music speed (= generation of balls)
|
||||||
z, x, c: simulation speed
|
z, x, c: simulation speed
|
||||||
a: toggle autopilot
|
a: toggle autopilot
|
||||||
|
d: toggle drum
|
||||||
p: pause
|
p: pause
|
||||||
r: reload scales (aka chords)
|
r: reload scales (aka chords)
|
||||||
s: reload shaders
|
s: reload shaders
|
||||||
|
@ -41,6 +42,8 @@ namespace games {
|
||||||
// simulation part
|
// simulation part
|
||||||
int balluid{0};
|
int balluid{0};
|
||||||
std::vector<std::shared_ptr<Instrument>> lines;
|
std::vector<std::shared_ptr<Instrument>> lines;
|
||||||
|
std::shared_ptr<Instrument> kick;
|
||||||
|
std::shared_ptr<Instrument> snare;
|
||||||
|
|
||||||
simu_type sim;
|
simu_type sim;
|
||||||
beat_type beat;
|
beat_type beat;
|
||||||
|
@ -52,6 +55,13 @@ namespace games {
|
||||||
void add_line(cheap_line_type const & line);
|
void add_line(cheap_line_type const & line);
|
||||||
void remove_line(int ID);
|
void remove_line(int ID);
|
||||||
|
|
||||||
|
void add_drum();
|
||||||
|
void remove_drum();
|
||||||
|
|
||||||
|
float x1;
|
||||||
|
float x2;
|
||||||
|
float x3;
|
||||||
|
|
||||||
// Sound part
|
// Sound part
|
||||||
const std::vector<std::string> scale_files{
|
const std::vector<std::string> scale_files{
|
||||||
::bundle.get_sound_path() + "pentatonic.txt", // 0 a
|
::bundle.get_sound_path() + "pentatonic.txt", // 0 a
|
||||||
|
@ -78,7 +88,9 @@ namespace games {
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<motor::al::Buffer>> sounds{
|
const std::vector<std::shared_ptr<motor::al::Buffer>> sounds{
|
||||||
resource_cache.get_sound_buffer(::bundle.get_sound_path() + "guitar440.wav"),
|
resource_cache.get_sound_buffer(::bundle.get_sound_path() + "guitar440.wav"),
|
||||||
resource_cache.get_sound_buffer(::bundle.get_sound_path() + "marimba.wav")
|
resource_cache.get_sound_buffer(::bundle.get_sound_path() + "marimba.wav"),
|
||||||
|
resource_cache.get_sound_buffer(::bundle.get_sound_path() + "kick.wav"),
|
||||||
|
resource_cache.get_sound_buffer(::bundle.get_sound_path() + "snare.wav")
|
||||||
};
|
};
|
||||||
|
|
||||||
float music_speed{1.0};
|
float music_speed{1.0};
|
||||||
|
|
Reference in a new issue