add vctest (WIP)

This commit is contained in:
MihailRis
2024-12-07 15:49:23 +03:00
parent d9bd60f473
commit 5e8805f241
16 changed files with 439 additions and 52 deletions
+10 -39
View File
@@ -1,48 +1,16 @@
#include "command_line.hpp"
#include <cstring>
#include <filesystem>
#include <iostream>
#include <stdexcept>
#include <string>
#include "files/engine_paths.hpp"
#include "util/ArgsReader.hpp"
#include "engine.hpp"
namespace fs = std::filesystem;
class ArgsReader {
const char* last = "";
char** argv;
int argc;
int pos = 0;
public:
ArgsReader(int argc, char** argv) : argv(argv), argc(argc) {
}
void skip() {
pos++;
}
bool hasNext() const {
return pos < argc && strlen(argv[pos]);
}
bool isKeywordArg() const {
return last[0] == '-';
}
std::string next() {
if (pos >= argc) {
throw std::runtime_error("unexpected end");
}
last = argv[pos];
return argv[pos++];
}
};
static bool perform_keyword(
ArgsReader& reader, const std::string& keyword, CoreParameters& params
util::ArgsReader& reader, const std::string& keyword, CoreParameters& params
) {
if (keyword == "--res") {
auto token = reader.next();
@@ -53,22 +21,25 @@ static bool perform_keyword(
} else if (keyword == "--help" || keyword == "-h") {
std::cout << "VoxelEngine command-line arguments:\n";
std::cout << " --help - show help\n";
std::cout << " --res [path] - set resources directory\n";
std::cout << " --dir [path] - set userfiles directory\n";
std::cout << " --res <path> - set resources directory\n";
std::cout << " --dir <path> - set userfiles directory\n";
std::cout << " --headless - run in headless mode\n";
std::cout << " --test <path> - test script file\n";
std::cout << std::endl;
return false;
} else if (keyword == "--headless") {
params.headless = true;
} else if (keyword == "--test") {
auto token = reader.next();
params.testFile = fs::u8path(token);
} else {
std::cerr << "unknown argument " << keyword << std::endl;
return false;
throw std::runtime_error("unknown argument " + keyword);
}
return true;
}
bool parse_cmdline(int argc, char** argv, CoreParameters& params) {
ArgsReader reader(argc, argv);
util::ArgsReader reader(argc, argv);
reader.skip();
while (reader.hasNext()) {
std::string token = reader.next();