Big cleanup of rampant using std.

master
Zed A. Shaw 3 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
./escape_turings_tarpit.exe
clean:
meson compile --clean -C builddir

@ -18,18 +18,17 @@
#include <stdlib.h> // for EXIT_SUCCESS
#include <string> // for operator+, to_string
#include <unistd.h>
#include <vector>
#include <nlohmann/json.hpp>
#include <fstream>
using namespace std;
using std::string;
using namespace fmt;
using namespace nlohmann;
#define BUF_MAX 1024
Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) {
ifstream infile(".tarpit.json");
std::ifstream infile(".tarpit.json");
json config = json::parse(infile);
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() {
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?
ofstream stats_out;
std::ofstream stats_out;
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);
dbc::check(stats_out.good(), "Error opening stats.csv file.");
@ -64,10 +63,8 @@ Task<unsigned> Builder::run_build() {
co_yield 3;
string line(buffer); // yeah, that's probably a problem
cerr << buffer;
smatch err;
bool match = regex_match(line, err, err_re);
std::smatch err;
bool match = std::regex_match(line, err, err_re);
if(match) {
string file_name = err[1].str();

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

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

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

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

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

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

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

@ -5,7 +5,7 @@
using json = nlohmann::json;
using namespace fmt;
using namespace std;
using std::string, std::cout;
int main(int argc, char *argv[]) {
if(argc != 2) {
@ -13,10 +13,10 @@ int main(int argc, char *argv[]) {
return 0;
}
ifstream infile(argv[1]);
std::ifstream infile(argv[1]);
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()) {
cout << el.key() << "=" << el.value() << "\n";

@ -12,6 +12,7 @@
#include "sfmlgui.hpp"
using namespace ImGui;
using std::string;
void SFMLGui::ImGui_setup() {
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();
for(string &line : lines) {
log.push_back(line);

@ -6,6 +6,8 @@
#include "game_engine.hpp"
#include <string>
using std::string;
constexpr int FPS=30;
constexpr int X_DIM = 1920 / 2;
constexpr int Y_DIM = 1080 / 2;
@ -25,7 +27,7 @@ class SFMLGui {
int hit_points = 50;
sf::Font font;
GameEngine &game;
vector<string> log;
std::vector<string> log;
public:
SFMLGui(GameEngine &g);
@ -37,9 +39,9 @@ public:
void handle_events();
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_update();

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

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

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

Loading…
Cancel
Save