Big cleanup of rampant using std.

master
Zed A. Shaw 4 months ago
parent fcd1225370
commit 453c50c563
  1. 3
      Makefile
  2. 17
      builder.cpp
  3. 2
      builder.hpp
  4. 1
      coro.hpp
  5. 4
      corotest.cpp
  6. 2
      dbc.hpp
  7. 10
      game_engine.hpp
  8. 8
      gui.cpp
  9. 4
      gui.hpp
  10. 6
      jsontest.cpp
  11. 3
      sfmlgui.cpp
  12. 8
      sfmlgui.hpp
  13. 4
      tests/game_engine.cpp
  14. 9
      watcher.cpp
  15. 8
      watcher.hpp

@ -13,3 +13,6 @@ install: build test
run: install run: install
./escape_turings_tarpit.exe ./escape_turings_tarpit.exe
clean:
meson compile --clean -C builddir

@ -18,18 +18,17 @@
#include <stdlib.h> // for EXIT_SUCCESS #include <stdlib.h> // for EXIT_SUCCESS
#include <string> // for operator+, to_string #include <string> // for operator+, to_string
#include <unistd.h> #include <unistd.h>
#include <vector>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <fstream> #include <fstream>
using namespace std; using std::string;
using namespace fmt; using namespace fmt;
using namespace nlohmann; using namespace nlohmann;
#define BUF_MAX 1024 #define BUF_MAX 1024
Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) { Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) {
ifstream infile(".tarpit.json"); std::ifstream infile(".tarpit.json");
json config = json::parse(infile); json config = json::parse(infile);
config["git_path"].template get_to<string>(git_path); config["git_path"].template get_to<string>(git_path);
@ -37,14 +36,14 @@ Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) {
} }
Task<unsigned> Builder::run_build() { Task<unsigned> Builder::run_build() {
regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*"); std::regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*");
char buffer[BUF_MAX]; // BUF_MAX is a define already? char buffer[BUF_MAX]; // BUF_MAX is a define already?
ofstream stats_out; std::ofstream stats_out;
co_await Pass{}; co_await Pass{};
stats_out.open("stats.csv", ios::out | ios::app); stats_out.open("stats.csv", std::ios::out | std::ios::app);
std::time_t tstamp = std::time(nullptr); std::time_t tstamp = std::time(nullptr);
dbc::check(stats_out.good(), "Error opening stats.csv file."); dbc::check(stats_out.good(), "Error opening stats.csv file.");
@ -64,10 +63,8 @@ Task<unsigned> Builder::run_build() {
co_yield 3; co_yield 3;
string line(buffer); // yeah, that's probably a problem string line(buffer); // yeah, that's probably a problem
cerr << buffer; std::smatch err;
bool match = std::regex_match(line, err, err_re);
smatch err;
bool match = regex_match(line, err, err_re);
if(match) { if(match) {
string file_name = err[1].str(); string file_name = err[1].str();

@ -3,6 +3,8 @@
#include "game_engine.hpp" #include "game_engine.hpp"
#include "coro.hpp" #include "coro.hpp"
using std::string;
class Builder { class Builder {
GUI gui; GUI gui;
GameEngine game; GameEngine game;

@ -4,7 +4,6 @@
#include <exception> #include <exception>
#include <assert.h> #include <assert.h>
using namespace std;
enum TaskStates { enum TaskStates {
STARTED, AWAIT, YIELD, STARTED, AWAIT, YIELD,

@ -3,6 +3,8 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
using std::cout, std::endl;
Task<unsigned> task_test() Task<unsigned> task_test()
{ {
co_await Pass{}; co_await Pass{};
@ -16,7 +18,7 @@ Task<unsigned> task_test()
int main() int main()
{ {
const int task_count = 4; const int task_count = 4;
vector<Task<unsigned>> tasks; std::vector<Task<unsigned>> tasks;
for(int i = 0; i < task_count; i++) { for(int i = 0; i < task_count; i++) {
auto t = task_test(); auto t = task_test();

@ -4,7 +4,7 @@
#include <fmt/core.h> #include <fmt/core.h>
#include <functional> #include <functional>
using namespace std; using std::string;
namespace dbc { namespace dbc {
class Error { class Error {

@ -2,15 +2,13 @@
#include <string> #include <string>
#include <map> #include <map>
#include <vector>
#include <array> #include <array>
#include <sstream> #include <sstream>
using namespace std; using std::string;
class GameEngine { class GameEngine {
map<string, int> damage_types{ std::map<string, int> damage_types{
{"error", 4}, {"error", 4},
{"warning", 1}, {"warning", 1},
{"note", 0}, {"note", 0},
@ -45,8 +43,8 @@ class Brainfucker {
public: public:
size_t dp = 0; size_t dp = 0;
size_t ip = 0; size_t ip = 0;
ostringstream out; std::stringstream out;
array<int, 100> data = {}; std::array<int, 100> data = {};
string code = {}; string code = {};
Brainfucker(); Brainfucker();

@ -4,21 +4,21 @@
#include <fmt/core.h> #include <fmt/core.h>
#include <memory> // for allocator, shared_ptr #include <memory> // for allocator, shared_ptr
#include <string> // for operator+, to_string #include <string> // for operator+, to_string
#include <thread> // for sleep_for
#include <vector> #include <vector>
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <fstream> #include <fstream>
#include "sfmlgui.hpp" #include "sfmlgui.hpp"
using namespace std; using std::string, std::vector;
using namespace fmt; using namespace fmt;
using namespace nlohmann; using namespace nlohmann;
namespace fs = std::filesystem; namespace fs = std::filesystem;
void SoundQuip::load(json &data, const char *file_key) { void SoundQuip::load(json &data, const char *file_key) {
auto audio = data["audio"]; auto audio = data["audio"];
json::string_t file_name = audio[file_key].template get<std::string>(); json::string_t file_name = audio[file_key].template get<string>();
if(!buffer.loadFromFile(file_name)) { if(!buffer.loadFromFile(file_name)) {
println("Failed to load sound: {} with file {}", file_key, file_name); println("Failed to load sound: {} with file {}", file_key, file_name);
@ -36,7 +36,7 @@ void SoundQuip::stop() {
} }
GUI::GUI() { GUI::GUI() {
ifstream infile(".tarpit.json"); std::ifstream infile(".tarpit.json");
json data = json::parse(infile); json data = json::parse(infile);
// json load the config file // json load the config file

@ -7,6 +7,8 @@
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
using std::string;
class SoundQuip { class SoundQuip {
public: public:
sf::Sound sound; sf::Sound sound;
@ -21,7 +23,7 @@ public:
}; };
class GUI { class GUI {
vector<string> lines; std::vector<string> lines;
SoundQuip you_died_sound; SoundQuip you_died_sound;
SoundQuip build_works_sound; SoundQuip build_works_sound;

@ -5,7 +5,7 @@
using json = nlohmann::json; using json = nlohmann::json;
using namespace fmt; using namespace fmt;
using namespace std; using std::string, std::cout;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if(argc != 2) { if(argc != 2) {
@ -13,10 +13,10 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
ifstream infile(argv[1]); std::ifstream infile(argv[1]);
json data = json::parse(infile); json data = json::parse(infile);
json::string_t s2 = data["happy"].template get<std::string>(); json::string_t s2 = data["happy"].template get<string>();
for(auto &el : data.items()) { for(auto &el : data.items()) {
cout << el.key() << "=" << el.value() << "\n"; cout << el.key() << "=" << el.value() << "\n";

@ -12,6 +12,7 @@
#include "sfmlgui.hpp" #include "sfmlgui.hpp"
using namespace ImGui; using namespace ImGui;
using std::string;
void SFMLGui::ImGui_setup() { void SFMLGui::ImGui_setup() {
bool res = SFML::Init(window); bool res = SFML::Init(window);
@ -139,7 +140,7 @@ SFMLGui::SFMLGui(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's
} }
void SFMLGui::update_log(vector<string> &lines) { void SFMLGui::update_log(std::vector<string> &lines) {
log.clear(); log.clear();
for(string &line : lines) { for(string &line : lines) {
log.push_back(line); log.push_back(line);

@ -6,6 +6,8 @@
#include "game_engine.hpp" #include "game_engine.hpp"
#include <string> #include <string>
using std::string;
constexpr int FPS=30; constexpr int FPS=30;
constexpr int X_DIM = 1920 / 2; constexpr int X_DIM = 1920 / 2;
constexpr int Y_DIM = 1080 / 2; constexpr int Y_DIM = 1080 / 2;
@ -25,7 +27,7 @@ class SFMLGui {
int hit_points = 50; int hit_points = 50;
sf::Font font; sf::Font font;
GameEngine &game; GameEngine &game;
vector<string> log; std::vector<string> log;
public: public:
SFMLGui(GameEngine &g); SFMLGui(GameEngine &g);
@ -37,9 +39,9 @@ public:
void handle_events(); void handle_events();
void update_entities(); void update_entities();
void update_log(vector<string> &lines); void update_log(std::vector<string> &lines);
void write_text(int x, int y, std::string content); void write_text(int x, int y, string content);
void ImGui_setup(); void ImGui_setup();
void ImGui_update(); void ImGui_update();

@ -7,7 +7,7 @@ using namespace fmt;
TEST_CASE("game engine can start and take hit", "[game_engine]") { TEST_CASE("game engine can start and take hit", "[game_engine]") {
// test fails on purpose right now // test fails on purpose right now
GameEngine game{4}; GameEngine game{4};
string err{"error"}; std::string err{"error"};
game.start_round(); game.start_round();
game.hit(err); game.hit(err);
game.end_round(); game.end_round();
@ -17,7 +17,7 @@ TEST_CASE("game engine can start and take hit", "[game_engine]") {
TEST_CASE("", "[game_engine]") { TEST_CASE("", "[game_engine]") {
// test fails on purpose right now // test fails on purpose right now
GameEngine game{100}; GameEngine game{100};
string err{"error"}; std::string err{"error"};
game.start_round(); game.start_round();
game.hit(err); game.hit(err);

@ -1,13 +1,14 @@
#include "watcher.hpp" #include "watcher.hpp"
#include <filesystem> #include <filesystem>
using namespace std;
using std::string;
namespace fs = std::filesystem; namespace fs = std::filesystem;
void UpdateListener::handleFileAction(efsw::WatchID watchid, void UpdateListener::handleFileAction(efsw::WatchID watchid,
const std::string& dir, const string& dir,
const std::string& filename, const string& filename,
efsw::Action action, efsw::Action action,
std::string oldFilename) string oldFilename)
{ {
// this is some gnarly BS here, probably tons // this is some gnarly BS here, probably tons

@ -3,6 +3,8 @@
#include <git2.h> #include <git2.h>
#include <string> // for operator+, to_string #include <string> // for operator+, to_string
using std::string;
class UpdateListener : public efsw::FileWatchListener { class UpdateListener : public efsw::FileWatchListener {
public: public:
bool changes = false; bool changes = false;
@ -11,10 +13,10 @@ class UpdateListener : public efsw::FileWatchListener {
UpdateListener(git_repository *r) : repo(r) {}; UpdateListener(git_repository *r) : repo(r) {};
void handleFileAction(efsw::WatchID watchid, void handleFileAction(efsw::WatchID watchid,
const std::string& dir, const string& dir,
const std::string& filename, const string& filename,
efsw::Action action, efsw::Action action,
std::string oldFilename) override; string oldFilename) override;
void reset_state(); void reset_state();
}; };

Loading…
Cancel
Save