1
Fork 0
This repository has been archived on 2025-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
beats-motor-client/src/client/client.hpp
2013-06-01 18:11:59 +02:00

130 lines
3.3 KiB
C++

#pragma once
#include <vector>
#include <memory>
#include <stack>
#include <motor/sound/sound.hpp>
#include <motor/basic/texture_label.hpp>
#include <lib/libwebsockets.h>
#include "../globals.hpp"
#include "../Base.hpp"
#include "../input.hpp"
#include "client_common.hpp"
#include "GameRenderer.h"
/*
Controls:
mouse: draw linez
1, .. 9, 0: change chord (will also be done automatically)
k: change line kind
a: toggle autopilot
d: toggle drum
p: pause
q, w, e: music speed (= generation of balls)
z, x, c: simulation speed
-, + (without shift): global speed
r: reload scales (aka chords)
s: reload shaders
b: clear balls
l: clear lines
*/
namespace games {
struct Client : public Base {
static constexpr char bundle_name[] = "client";
float global_speed = 1.0;
// websocket part
libwebsocket_context * context{nullptr};
libwebsocket * wsi{nullptr};
float push_time{0.0};
bool lines_changed{true};
// simulation part
int balluid{0};
std::vector<std::shared_ptr<Instrument>> lines;
std::shared_ptr<Instrument> kick;
std::shared_ptr<Instrument> snare;
simu_type sim;
beat_type beat;
beat_type chords;
float sim_speed{1.0};
bool pause{false};
void add_line(cheap_line_type const & line);
void remove_line(int ID);
void remove_line(std::shared_ptr<Instrument> const & instr);
void add_drum();
void remove_drum();
float x1;
float x2;
float x3;
// Input part
cheap_line_type current_line;
bool drawing = false;
simulation::LineKind current_kind = simulation::kFallThrough;
std::stack<std::shared_ptr<Instrument>> undo_stack;
// Sound part
const std::vector<std::string> scale_files{
::bundle.get_sound_path() + "pentatonic.txt", // 0 a
::bundle.get_sound_path() + "c.txt", // 1 c
::bundle.get_sound_path() + "d.txt", // 2 d
::bundle.get_sound_path() + "em.txt", // 3 e
::bundle.get_sound_path() + "maj7.txt", // 4 g
::bundle.get_sound_path() + "noon.txt", // 5 a
::bundle.get_sound_path() + "cnoon.txt", // 6 c
::bundle.get_sound_path() + "blues.txt", // 7 a
::bundle.get_sound_path() + "spanish.txt", // 8 a
::bundle.get_sound_path() + "f.txt", // 9 f
};
std::vector<Scale> scales;
Scale scale;
const std::vector<std::vector<int>> chord_progressions{
{1, 2, 3, 3, 1, 2, 3, 4, 1, 2, 3, 3, 1, 2, 3, 4},
{0, 7, 4, 4, 0, 1, 9, 3},
{0, 0, 9, 9, 0, 0, 5, 6}
};
std::vector<int> chord_progression{chord_progressions[0]};
std::vector<int>::const_iterator chord_progression_it{chord_progression.begin()};
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() + "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};
bool auto_pilot{true};
// Graphics
GameRenderer game_renderer;
std::shared_ptr<motor::TextureLabel> peeps_lbl;
void set_text(std::string peeps);
// Base part
Client(int window_width, int window_height, std::shared_ptr<Base>& active_base);
virtual bool has_ended();
virtual void update(float const dt, Input input);
virtual void draw();
void handle_input(float const dt, Input input);
~Client();
};
}