Sounds are working...BUT...I have to make ones I own so hang on until I do that.

master
Zed A. Shaw 1 month ago
parent 7309ec2f40
commit 268d8abf52
  1. 13
      audiotest.cpp
  2. 8
      builder.cpp
  3. 40
      gui.cpp
  4. 17
      gui.hpp
  5. 8
      scripts/reset_build.sh

@ -6,10 +6,10 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
sf::SoundBuffer buffer; sf::SoundBuffer buffer;
sf::Sound click; sf::Sound sound;
if(argc != 2) { if(argc != 2) {
fmt::println("USAGE: audiotest click.mp3"); fmt::println("USAGE: audiotest [FILE]");
return 0; return 0;
} }
@ -17,15 +17,16 @@ int main(int argc, char *argv[]) {
if(!buffer.loadFromFile(in_file)) { if(!buffer.loadFromFile(in_file)) {
fmt::println("Failed to load {}", in_file); fmt::println("Failed to load {}", in_file);
return 0;
} }
click.setBuffer(buffer); sound.setBuffer(buffer);
fmt::println("Playing {}. Hit ctrl-c to exit.", in_file); fmt::println("Playing {}. Hit ctrl-c to exit.", in_file);
while(true) { sound.play();
click.play(); while(sound.getStatus() != sf::SoundSource::Status::Stopped) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
return 0; return 0;

@ -66,7 +66,7 @@ void Builder::run_build(GameEngine &game, const char* command) {
// refactor this // refactor this
if(game.is_dead()) { if(game.is_dead()) {
gui.output(format("YOU DIED!\n")); gui.you_died();
} }
} }
} }
@ -75,9 +75,9 @@ void Builder::run_build(GameEngine &game, const char* command) {
int rc = pclose(build_out); int rc = pclose(build_out);
if(rc == 0) { if(rc == 0) {
gui.output("BUILD FINISHED!"); gui.build_works();
} else { } else {
gui.output(format("!!! BUILD FAILED. Your command correct? '{}'", command)); gui.build_failed(command);
} }
stats_out.close(); stats_out.close();
@ -107,7 +107,7 @@ void Builder::run(const char *git_path, const char *build_cmd) {
fileWatcher->watch(); fileWatcher->watch();
if(listener->changes) { if(listener->changes) {
gui.output("############# START ############"); gui.building();
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
gui.output(format("CHANGES! Running build {}", build_cmd)); gui.output(format("CHANGES! Running build {}", build_cmd));
run_build(game, build_cmd); run_build(game, build_cmd);

@ -13,12 +13,28 @@
#include "ftxui/component/loop.hpp" // for Loop #include "ftxui/component/loop.hpp" // for Loop
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive #include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include <vector> #include <vector>
#include <SFML/Audio.hpp>
using namespace ftxui; using namespace ftxui;
using namespace std; using namespace std;
using namespace fmt; using namespace fmt;
namespace fs = std::filesystem; namespace fs = std::filesystem;
void load_sound(sf::Sound &sound, sf::SoundBuffer &buffer, const char *in_file) {
if(!buffer.loadFromFile(in_file)) {
fmt::println("Failed to load {}", in_file);
}
sound.setBuffer(buffer);
}
GUI::GUI() {
load_sound(you_died_sound, you_died_buffer, "./assets/you_died.wav");
load_sound(build_works_sound, build_works_buffer, "./assets/build_works.wav");
load_sound(build_failed_sound, build_failed_buffer, "./assets/build_failed.wav");
load_sound(building_sound, building_buffer, "./assets/building.wav");
}
void GUI::output(const string &msg) { void GUI::output(const string &msg) {
lines.push_back(msg); lines.push_back(msg);
} }
@ -98,3 +114,27 @@ int GUI::main_loop(GameEngine &game, std::function<bool()> runner) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void GUI::build_works() {
building_sound.stop();
build_works_sound.play();
output("BUILD FINISHED!");
}
void GUI::build_failed(const string &command) {
building_sound.stop();
build_failed_sound.play();
output(format("!!! BUILD FAILED. Your command correct? '{}'", command));
}
void GUI::you_died() {
building_sound.stop();
you_died_sound.play();
output("YOU DIED!");
}
void GUI::building() {
output("############# START ############");
output(">>>> Will it Build?");
building_sound.play();
}

@ -4,13 +4,30 @@
#include "game_engine.hpp" #include "game_engine.hpp"
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#include <SFML/Audio.hpp>
class GUI { class GUI {
vector<string> lines; vector<string> lines;
sf::Sound you_died_sound;
sf::Sound build_works_sound;
sf::Sound build_failed_sound;
sf::Sound building_sound;
sf::SoundBuffer you_died_buffer;
sf::SoundBuffer build_works_buffer;
sf::SoundBuffer build_failed_buffer;
sf::SoundBuffer building_buffer;
public: public:
GUI();
void output(const string &msg); void output(const string &msg);
int main_loop(GameEngine &game, std::function<bool()> runner); int main_loop(GameEngine &game, std::function<bool()> runner);
void build_works();
void build_failed(const string &command);
void you_died();
void building();
}; };

@ -8,9 +8,15 @@ mv packagecache ./subprojects/
mkdir builddir mkdir builddir
cp *.wrap subprojects cp *.wrap subprojects
meson wrap install fmt meson wrap install fmt
meson wrap install openal-soft
meson wrap install sqlite3 meson wrap install sqlite3
meson wrap install sqlitecpp meson wrap install sqlitecpp
meson wrap install ftxui meson wrap install ftxui
meson wrap install catch2 meson wrap install catch2
meson wrap install libpng
meson wrap install vorbis
meson wrap install ogg
meson wrap install flac
meson wrap install freetype2
meson wrap install openal-soft
meson wrap install sfml
meson setup builddir meson setup builddir

Loading…
Cancel
Save