diff --git a/Makefile b/Makefile index 0c6ab86..0f0c968 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: build test +all: build reset: powershell -executionpolicy bypass .\scripts\reset_build.ps1 @@ -6,8 +6,8 @@ reset: patch: powershell "cp ./patches/process.h ./subprojects/libgit2-1.9.0/src/util/process.h" -build: patch - meson compile -j 4 -C builddir +build: + meson compile -C builddir config: powershell "cp tarpit_sample.json .tarpit.json" diff --git a/builder.cpp b/builder.cpp index c7324c0..bbeaf9d 100644 --- a/builder.cpp +++ b/builder.cpp @@ -72,11 +72,13 @@ MatchResult Builder::parse_line(const string &line) { } } -void Builder::BUILDING(BuildEvent ev) { +void Builder::BUILDING(BuildEvent) { // check if there's output if(build_done) { int rc = pclose(build_out); + fmt::println("PCLOSE RETURNED: {}", rc); + if(rc == 0) { game.event(GameEvent::BUILD_SUCCESS); gui.build_success(); @@ -98,7 +100,7 @@ void Builder::BUILDING(BuildEvent ev) { } } -void Builder::START(BuildEvent ev) { +void Builder::START(BuildEvent) { gui.output(fmt::format("Using build command: {}", build_cmd)); fileWatcher = new efsw::FileWatcher(); dbc::check(fileWatcher != nullptr, "Failed to create filewatcher."); @@ -118,7 +120,7 @@ void Builder::START(BuildEvent ev) { state(BuildState::WAITING); } -void Builder::WAITING(BuildEvent ev) { +void Builder::WAITING(BuildEvent) { if(listener->changes) { game.event(GameEvent::BUILD_START); gui.building(); @@ -127,7 +129,7 @@ void Builder::WAITING(BuildEvent ev) { } } -void Builder::FORKING(BuildEvent ev) { +void Builder::FORKING(BuildEvent) { if(build_fut.valid()) { std::future_status status = build_fut.wait_for(0ms); @@ -146,7 +148,7 @@ void Builder::FORKING(BuildEvent ev) { } } -void Builder::READING(BuildEvent ev) { +void Builder::READING(BuildEvent) { // BUG: too much copy-pasta so turn this into a class? if(read_fut.valid()) { std::future_status status = read_fut.wait_for(0ms); @@ -164,7 +166,7 @@ void Builder::READING(BuildEvent ev) { } } -void Builder::DONE(BuildEvent ev) { +void Builder::DONE(BuildEvent) { if(game.is_dead()) { gui.you_died(); } diff --git a/escape_turings_tarpit.cpp b/escape_turings_tarpit.cpp index 2e45105..bf5019f 100644 --- a/escape_turings_tarpit.cpp +++ b/escape_turings_tarpit.cpp @@ -2,7 +2,7 @@ #include "gui.hpp" #include -int main(int argc, char *argv[]) +int main() { GameEngine game{100}; auto backend = SFMLBackend(game); diff --git a/meson.build b/meson.build index 962f996..879501b 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,74 @@ -project('turings_tarpit', 'cpp', - default_options: ['cpp_std=c++20']) +# clang might need _LIBCPP_ENABLE_CXX26_REMOVED_CODECVT + +project('turings-tarpit', 'cpp', + version: '0.1.0', + default_options: [ + 'cpp_std=c++20', + 'cpp_args=-D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1', + ]) + +# use this for common options only for our executables +cpp_args=[] +link_args=[] +# these are passed as override_defaults +exe_defaults = [ 'warning_level=2' ] + +cc = meson.get_compiler('cpp') +dependencies = [] + +if build_machine.system() == 'windows' + add_global_link_arguments( + '-static-libgcc', + '-static-libstdc++', + '-static', + language: 'cpp', + ) + + sfml_main = dependency('sfml_main') + opengl32 = cc.find_library('opengl32', required: true) + winmm = cc.find_library('winmm', required: true) + gdi32 = cc.find_library('gdi32', required: true) + + dependencies += [ + opengl32, winmm, gdi32, sfml_main + ] + exe_defaults += ['werror=true'] + +elif build_machine.system() == 'darwin' + add_global_link_arguments( + language: 'cpp', + ) + + opengl = dependency('OpenGL') + corefoundation = dependency('CoreFoundation') + carbon = dependency('Carbon') + cocoa = dependency('Cocoa') + iokit = dependency('IOKit') + corevideo = dependency('CoreVideo') + + link_args += ['-ObjC'] + exe_defaults += ['werror=false'] + dependencies += [ + opengl, corefoundation, carbon, cocoa, iokit, corevideo + ] +endif + +catch2 = dependency('catch2-with-main') +fmt = subproject('fmt').get_variable('fmt_dep') +json = dependency('nlohmann_json') +freetype2 = dependency('freetype2') + +flac = dependency('flac') +ogg = dependency('ogg') +vorbis = dependency('vorbis') +vorbisfile = dependency('vorbisfile') +vorbisenc = dependency('vorbisenc') +sfml_audio = dependency('sfml_audio') +sfml_graphics = dependency('sfml_graphics') +sfml_network = dependency('sfml_network') +sfml_system = dependency('sfml_system') +sfml_window = dependency('sfml_window', + default_options: ['default_library=shared']) cmake = import('cmake') opts = cmake.subproject_options() @@ -14,36 +83,39 @@ libgit2_proj = cmake.subproject('libgit2', options: opts) libgit2package = libgit2_proj.dependency('libgit2package') efsw = dependency('efsw') -fmt = subproject('fmt').get_variable('fmt_dep') -catch2 = dependency('catch2-with-main') -sfml = dependency('sfml') -json = dependency('nlohmann_json') -imgui = dependency('imgui-sfml') -dependencies = [ - fmt, libgit2package, efsw, - sfml, imgui, json +dependencies += [ + fmt, json, freetype2, + flac, ogg, vorbis, vorbisfile, vorbisenc, + sfml_audio, sfml_graphics, + sfml_network, sfml_system, + sfml_window, libgit2package, efsw ] -subdir('scratchpad') - -executable('escape_turings_tarpit', - ['game_engine.cpp', +sources = [ + 'game_engine.cpp', 'dbc.cpp', 'gui.cpp', 'watcher.cpp', 'builder.cpp', 'sfmlbackend.cpp', - 'escape_turings_tarpit.cpp'], +] + + +executable('escape_turings_tarpit', sources + [ + 'escape_turings_tarpit.cpp' + ], + cpp_args: cpp_args, + link_args: link_args, + override_options: exe_defaults, dependencies: dependencies) -runtests = executable('runtests', [ - 'dbc.cpp', - 'game_engine.cpp', +executable('runtests', sources + [ 'tests/game_engine.cpp', 'tests/fsm.cpp', 'tests/dbc.cpp', ], + cpp_args: cpp_args, + link_args: link_args, + override_options: exe_defaults, dependencies: dependencies + [catch2]) - -test('tests', runtests) diff --git a/sfmlbackend.cpp b/sfmlbackend.cpp index 3f68e8f..904270e 100644 --- a/sfmlbackend.cpp +++ b/sfmlbackend.cpp @@ -13,9 +13,10 @@ #include "sfmlbackend.hpp" #include #include +#include "dbc.hpp" using namespace nlohmann; -using std::string; +using std::string, std::make_shared; std::array VALUES{ sf::Color{1, 4, 2}, // black @@ -31,23 +32,25 @@ std::array VALUES{ }; void SoundQuip::load(json &data, const char *file_key, bool loop) { + buffer = make_shared(); + auto audio = data["audio"]; json::string_t file_name = audio[file_key].template get(); - if(!buffer.loadFromFile(file_name)) { + if(!buffer->loadFromFile(file_name)) { fmt::println("Failed to load sound: {} with file {}", file_key, file_name); } - sound.setBuffer(buffer); - sound.setLoop(loop); + sound = make_shared(*buffer); + sound->setLooping(loop); } void SoundQuip::play() { - sound.play(); + sound->play(); } void SoundQuip::stop() { - sound.stop(); + sound->stop(); } void SFMLBackend::Window_update() { @@ -59,35 +62,11 @@ sf::Color SFMLBackend::value(Value level) { } void SFMLBackend::handle_events() { - sf::Event event; - // is this a main event loop - while (window.pollEvent(event)) { - switch(event.type) { - case sf::Event::Closed: - fmt::print("Exiting...\n"); - window.close(); - break; - case sf::Event::KeyPressed: - if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { - window.close(); - } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { - fmt::println("STOP THE CLOCK"); - } - break; - case sf::Event::MouseButtonPressed: { - // rect::contains(x,y) for if mouse is in the button rect - sf::Event::MouseButtonEvent btn = event.mouseButton; - if(stop_button.getGlobalBounds().contains(btn.x, btn.y)) { - buttons = Button::STOP; - } else if(start_button.getGlobalBounds().contains(btn.x, btn.y)) { - buttons = Button::START; - } - break; - } - default: - // do nothing - break; + while(const auto ev = window.pollEvent()) { + if(ev->is()) { + fmt::print("Exiting...\n"); + window.close(); } } } @@ -104,8 +83,7 @@ sf::Vector2f translate(int x, int y) { void SFMLBackend::write_text(int x, int y, string content, float size_mult, Value color) { sf::Vector2f position = translate(x,y); - sf::Text text; - text.setFont(font); + sf::Text text(font); text.setString(content); text.setCharacterSize(TEXT_SIZE * size_mult); text.setFillColor(value(color)); @@ -129,8 +107,8 @@ void SFMLBackend::update_entities() { window.clear(); sf::RectangleShape face_box = box(2, 2, X_ROWS/4, Y_LINES/2, Value::DARK_DARK); - face_sprite.setPosition(translate(2,2)); - window.draw(face_sprite); + face_sprite->setPosition(translate(2,2)); + window.draw(*face_sprite); sf::RectangleShape stats_box = box(X_ROWS/4 + 4, 2, X_ROWS - X_ROWS/4 - 5, Y_LINES/2, Value::DARK_DARK); @@ -160,10 +138,10 @@ void SFMLBackend::update_entities() { write_text(7, 14, time, 2.0f); - stop_button.setPosition(translate(27, 15)); - window.draw(start_button); - start_button.setPosition(translate(37, 15)); - window.draw(stop_button); + stop_button->setPosition(translate(27, 15)); + window.draw(*start_button); + start_button->setPosition(translate(37, 15)); + window.draw(*stop_button); Window_update(); } @@ -174,24 +152,27 @@ void SFMLBackend::change_face(const string name) { auto images = data["images"]; json::string_t file_name = images[name].template get(); - face_texture.loadFromFile(file_name); - face_sprite.setTexture(face_texture); + bool good = face_texture->loadFromFile(file_name); + dbc::check(good, fmt::format("failed to load texture {}", file_name)); + face_sprite->setTexture(*face_texture); } -SFMLBackend::SFMLBackend(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g) +SFMLBackend::SFMLBackend(GameEngine &g) + : window(sf::VideoMode({X_DIM, Y_DIM}), "Turing's Tarpit"), + game(g) { - change_face("building"); + face_texture = make_shared("./assets/building.png"); + stop_texture = make_shared("./assets/stop_button.png"); + start_texture = make_shared("./assets/start_button.png"); - stop_texture.loadFromFile("./assets/stop_button.png"); - stop_button.setTexture(stop_texture); + face_sprite = make_shared(*face_texture); + stop_button = make_shared(*stop_texture); + start_button = make_shared(*start_texture); - start_texture.loadFromFile("./assets/start_button.png"); - start_button.setTexture(start_texture); + change_face("building"); } - - /* * This makes my soul hurt. Make it stop. * @@ -208,9 +189,8 @@ void SFMLBackend::update_log(std::vector &lines) { void SFMLBackend::startup() { fmt::print("Setting up a window for you...\n"); - settings.antialiasingLevel = 8; - if(!font.loadFromFile("./assets/text.ttf")) { + if(!font.openFromFile("./assets/text.ttf")) { fmt::println("Cannot load font."); } diff --git a/sfmlbackend.hpp b/sfmlbackend.hpp index 01aa443..11f9738 100644 --- a/sfmlbackend.hpp +++ b/sfmlbackend.hpp @@ -35,8 +35,8 @@ enum class Button { class SoundQuip { public: - sf::Sound sound; - sf::SoundBuffer buffer; + std::shared_ptr sound = nullptr; + std::shared_ptr buffer = nullptr; bool initialized; SoundQuip() {}; @@ -49,12 +49,12 @@ public: class SFMLBackend { sf::ContextSettings settings; sf::RenderWindow window; - sf::Sprite face_sprite; - sf::Texture face_texture; - sf::Sprite stop_button; - sf::Texture stop_texture; - sf::Sprite start_button; - sf::Texture start_texture; + std::shared_ptr face_sprite = nullptr; + std::shared_ptr face_texture = nullptr; + std::shared_ptr stop_button = nullptr; + std::shared_ptr stop_texture = nullptr; + std::shared_ptr start_button = nullptr; + std::shared_ptr start_texture = nullptr; std::chrono::time_point clock_start; Button buttons = Button::STOP; int hit_points = 50; diff --git a/tests/fsm.cpp b/tests/fsm.cpp index bd43bf6..d071fe6 100644 --- a/tests/fsm.cpp +++ b/tests/fsm.cpp @@ -24,7 +24,7 @@ public: } } - void START(MyEvent ev) { + void START(MyEvent) { println("<<< START"); state(MyState::RUNNING); } @@ -39,7 +39,7 @@ public: } } - void END(MyEvent ev) { + void END(MyEvent) { println("<<< STOP"); state(MyState::END); } diff --git a/watcher.cpp b/watcher.cpp index 654ba6c..068bd18 100644 --- a/watcher.cpp +++ b/watcher.cpp @@ -12,6 +12,10 @@ void UpdateListener::handleFileAction(efsw::WatchID watchid, efsw::Action action, string oldFilename) { + (void)watchid; + (void)action; + (void)oldFilename; + // this is some gnarly BS here, probably tons // of memory leaks for now but it's working int ignored = 1; diff --git a/wraps/catch2.wrap b/wraps/catch2.wrap index 489db6c..f9bf436 100644 --- a/wraps/catch2.wrap +++ b/wraps/catch2.wrap @@ -1,10 +1,10 @@ [wrap-file] -directory = Catch2-3.7.0 -source_url = https://github.com/catchorg/Catch2/archive/v3.7.0.tar.gz -source_filename = Catch2-3.7.0.tar.gz -source_hash = 5b10cd536fa3818112a82820ce0787bd9f2a906c618429e7c4dea639983c8e88 -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.7.0-1/Catch2-3.7.0.tar.gz -wrapdb_version = 3.7.0-1 +directory = Catch2-3.7.1 +source_url = https://github.com/catchorg/Catch2/archive/v3.7.1.tar.gz +source_filename = Catch2-3.7.1.tar.gz +source_hash = c991b247a1a0d7bb9c39aa35faf0fe9e19764213f28ffba3109388e62ee0269c +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.7.1-1/Catch2-3.7.1.tar.gz +wrapdb_version = 3.7.1-1 [provide] catch2 = catch2_dep diff --git a/wraps/fmt.wrap b/wraps/fmt.wrap index 42b6159..fd50847 100644 --- a/wraps/fmt.wrap +++ b/wraps/fmt.wrap @@ -1,13 +1,13 @@ [wrap-file] -directory = fmt-11.0.1 -source_url = https://github.com/fmtlib/fmt/archive/11.0.1.tar.gz -source_filename = fmt-11.0.1.tar.gz -source_hash = 7d009f7f89ac84c0a83f79ed602463d092fbf66763766a907c97fd02b100f5e9 -patch_filename = fmt_11.0.1-1_patch.zip -patch_url = https://wrapdb.mesonbuild.com/v2/fmt_11.0.1-1/get_patch -patch_hash = 0a8b93d1ee6d84a82d3872a9bfb4c3977d8a53f7f484d42d1f7ed63ed496d549 -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/fmt_11.0.1-1/fmt-11.0.1.tar.gz -wrapdb_version = 11.0.1-1 +directory = fmt-11.0.2 +source_url = https://github.com/fmtlib/fmt/archive/11.0.2.tar.gz +source_filename = fmt-11.0.2.tar.gz +source_hash = 6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f +patch_filename = fmt_11.0.2-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/fmt_11.0.2-1/get_patch +patch_hash = 90c9e3b8e8f29713d40ca949f6f93ad115d78d7fb921064112bc6179e6427c5e +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/fmt_11.0.2-1/fmt-11.0.2.tar.gz +wrapdb_version = 11.0.2-1 [provide] fmt = fmt_dep diff --git a/wraps/imgui-sfml.wrap b/wraps/imgui-sfml.wrap deleted file mode 100644 index b385b05..0000000 --- a/wraps/imgui-sfml.wrap +++ /dev/null @@ -1,13 +0,0 @@ -[wrap-file] -directory = imgui-sfml-2.6 -source_url = https://github.com/eliasdaler/imgui-sfml/archive/refs/tags/v2.6.tar.gz -source_filename = v2.6.tar.gz -source_hash = b1195ca1210dd46c8049cfc8cae7f31cd34f1591da7de1c56297b277ac9c5cc0 -patch_filename = imgui-sfml_2.6-1_patch.zip -patch_url = https://wrapdb.mesonbuild.com/v2/imgui-sfml_2.6-1/get_patch -patch_hash = a804978cf015af2db13476eefd2ed16e64c2c5142eb4e4a93be5f19e0c7cbdbb -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/imgui-sfml_2.6-1/v2.6.tar.gz -wrapdb_version = 2.6-1 - -[provide] -imgui-sfml = imgui_sfml_dep diff --git a/wraps/imgui.wrap b/wraps/imgui.wrap deleted file mode 100644 index 6334713..0000000 --- a/wraps/imgui.wrap +++ /dev/null @@ -1,13 +0,0 @@ -[wrap-file] -directory = imgui-1.91.0 -source_url = https://github.com/ocornut/imgui/archive/refs/tags/v1.91.0.tar.gz -source_filename = imgui-1.91.0.tar.gz -source_hash = 6e62c87252e6b3725ba478a1c04dc604aa0aaeec78fedcf4011f1e52548f4cc9 -patch_filename = imgui_1.91.0-1_patch.zip -patch_url = https://wrapdb.mesonbuild.com/v2/imgui_1.91.0-1/get_patch -patch_hash = 354fc499bb53ed37ef7a23122d9253f6b119098ae95ff14a571d2d7e98fa3338 -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/imgui_1.91.0-1/imgui-1.91.0.tar.gz -wrapdb_version = 1.91.0-1 - -[provide] -imgui = imgui_dep diff --git a/wraps/libpng.wrap b/wraps/libpng.wrap index 2c5f9c6..06044a9 100644 --- a/wraps/libpng.wrap +++ b/wraps/libpng.wrap @@ -1,13 +1,13 @@ [wrap-file] -directory = libpng-1.6.43 -source_url = https://github.com/glennrp/libpng/archive/v1.6.43.tar.gz -source_filename = libpng-1.6.43.tar.gz -source_hash = fecc95b46cf05e8e3fc8a414750e0ba5aad00d89e9fdf175e94ff041caf1a03a -patch_filename = libpng_1.6.43-2_patch.zip -patch_url = https://wrapdb.mesonbuild.com/v2/libpng_1.6.43-2/get_patch -patch_hash = 49951297edf03e81d925ab03726555f09994ad1ed78fb539a269216430eef3da -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/libpng_1.6.43-2/libpng-1.6.43.tar.gz -wrapdb_version = 1.6.43-2 +directory = libpng-1.6.44 +source_url = https://github.com/glennrp/libpng/archive/v1.6.44.tar.gz +source_filename = libpng-1.6.44.tar.gz +source_hash = 0ef5b633d0c65f780c4fced27ff832998e71478c13b45dfb6e94f23a82f64f7c +patch_filename = libpng_1.6.44-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/libpng_1.6.44-1/get_patch +patch_hash = 394b07614c45fbd1beac8b660386216a490fe12f841a1a445799b676c9c892fb +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/libpng_1.6.44-1/libpng-1.6.44.tar.gz +wrapdb_version = 1.6.44-1 [provide] libpng = libpng_dep diff --git a/wraps/openal-soft.wrap b/wraps/openal-soft.wrap deleted file mode 100644 index a46c525..0000000 --- a/wraps/openal-soft.wrap +++ /dev/null @@ -1,13 +0,0 @@ -[wrap-file] -directory = openal-soft-1.23.1 -source_url = https://github.com/kcat/openal-soft/archive/refs/tags/1.23.1.tar.gz -source_filename = openal-soft-1.23.1.tar.gz -source_hash = dfddf3a1f61059853c625b7bb03de8433b455f2f79f89548cbcbd5edca3d4a4a -patch_filename = openal-soft_1.23.1-2_patch.zip -patch_url = https://wrapdb.mesonbuild.com/v2/openal-soft_1.23.1-2/get_patch -patch_hash = e03c3afe0bb40a931d25d41d92a08b90e3c33b217d1b47210b26ca6627eb3aa3 -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/openal-soft_1.23.1-2/openal-soft-1.23.1.tar.gz -wrapdb_version = 1.23.1-2 - -[provide] -openal = openal_dep diff --git a/wraps/sfml.wrap b/wraps/sfml.wrap index 1d84525..577ed1e 100644 --- a/wraps/sfml.wrap +++ b/wraps/sfml.wrap @@ -1,13 +1,14 @@ -[wrap-file] -directory = SFML-2.6.1 -source_url = https://github.com/SFML/SFML/archive/refs/tags/2.6.1.tar.gz -source_filename = 2.6.1.tar.gz -source_hash = 82535db9e57105d4f3a8aedabd138631defaedc593cab589c924b7d7a11ffb9d -patch_filename = sfml_2.6.1-1_patch.zip -patch_url = https://wrapdb.mesonbuild.com/v2/sfml_2.6.1-1/get_patch -patch_hash = 10367d927ec489dc575491de0059945a63ba08eef3f6fc146e6ba339176c9f18 -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/sfml_2.6.1-1/2.6.1.tar.gz -wrapdb_version = 2.6.1-1 +[wrap-git] +directory=SFML-3.0.0 +url=https://github.com/SFML/SFML.git +revision=3.0.0 +depth=1 +method=cmake [provide] -sfml = sfml_dep +sfml_audio = sfml_audio_dep +sfml_graphics = sfml_graphics_dep +sfml_main = sfml_main_dep +sfml_network = sfml_network_dep +sfml_system = sfml_system_dep +sfml_window = sfml_window_dep