Big cleanup of rampant using std.
This commit is contained in:
parent
fcd1225370
commit
453c50c563
15 changed files with 49 additions and 40 deletions
3
Makefile
3
Makefile
|
@ -13,3 +13,6 @@ install: build test
|
|||
|
||||
run: install
|
||||
./escape_turings_tarpit.exe
|
||||
|
||||
clean:
|
||||
meson compile --clean -C builddir
|
||||
|
|
17
builder.cpp
17
builder.cpp
|
@ -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;
|
||||
|
|
1
coro.hpp
1
coro.hpp
|
@ -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();
|
||||
|
|
2
dbc.hpp
2
dbc.hpp
|
@ -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();
|
||||
|
|
8
gui.cpp
8
gui.cpp
|
@ -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
|
||||
|
|
4
gui.hpp
4
gui.hpp
|
@ -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…
Add table
Add a link
Reference in a new issue