add 'tps' command line argument
This commit is contained in:
parent
06e65911a3
commit
dbab645c94
@ -50,6 +50,7 @@ struct CoreParameters {
|
|||||||
std::filesystem::path userFolder = ".";
|
std::filesystem::path userFolder = ".";
|
||||||
std::filesystem::path scriptFile;
|
std::filesystem::path scriptFile;
|
||||||
std::filesystem::path projectFolder;
|
std::filesystem::path projectFolder;
|
||||||
|
int tps = 20;
|
||||||
};
|
};
|
||||||
|
|
||||||
using OnWorldOpen = std::function<void(std::unique_ptr<Level>, int64_t)>;
|
using OnWorldOpen = std::function<void(std::unique_ptr<Level>, int64_t)>;
|
||||||
|
|||||||
@ -15,8 +15,6 @@ using namespace std::chrono;
|
|||||||
|
|
||||||
static debug::Logger logger("mainloop");
|
static debug::Logger logger("mainloop");
|
||||||
|
|
||||||
inline constexpr int TPS = 20;
|
|
||||||
|
|
||||||
ServerMainloop::ServerMainloop(Engine& engine) : engine(engine) {
|
ServerMainloop::ServerMainloop(Engine& engine) : engine(engine) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +37,7 @@ void ServerMainloop::run() {
|
|||||||
"script:" + coreParams.scriptFile.filename().u8string()
|
"script:" + coreParams.scriptFile.filename().u8string()
|
||||||
);
|
);
|
||||||
|
|
||||||
double targetDelta = 1.0 / static_cast<double>(TPS);
|
double targetDelta = 1.0 / static_cast<double>(coreParams.tps);
|
||||||
double delta = targetDelta;
|
double delta = targetDelta;
|
||||||
auto begin = system_clock::now();
|
auto begin = system_clock::now();
|
||||||
auto startupTime = begin;
|
auto startupTime = begin;
|
||||||
|
|||||||
@ -33,5 +33,14 @@ namespace util {
|
|||||||
last = argv[pos];
|
last = argv[pos];
|
||||||
return argv[pos++];
|
return argv[pos++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nextInt() {
|
||||||
|
auto text = next();
|
||||||
|
try {
|
||||||
|
return std::stoi(text);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
throw std::runtime_error(e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
#include "io/engine_paths.hpp"
|
#include "io/engine_paths.hpp"
|
||||||
#include "util/ArgsReader.hpp"
|
#include "util/ArgsReader.hpp"
|
||||||
@ -15,10 +16,17 @@ class ArgC {
|
|||||||
public:
|
public:
|
||||||
std::string keyword;
|
std::string keyword;
|
||||||
std::function<bool()> execute;
|
std::function<bool()> execute;
|
||||||
|
std::string args;
|
||||||
std::string help;
|
std::string help;
|
||||||
ArgC(const std::string& keyword, std::function<bool()> execute, const std::string& help) {
|
ArgC(
|
||||||
|
const std::string& keyword,
|
||||||
|
std::function<bool()> execute,
|
||||||
|
const std::string& args,
|
||||||
|
const std::string& help
|
||||||
|
) {
|
||||||
this->keyword = keyword;
|
this->keyword = keyword;
|
||||||
this->execute = execute;
|
this->execute = execute;
|
||||||
|
this->args = args;
|
||||||
this->help = help;
|
this->help = help;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -31,42 +39,47 @@ static bool perform_keyword(
|
|||||||
ArgC("--res", [¶ms, &reader]() -> bool {
|
ArgC("--res", [¶ms, &reader]() -> bool {
|
||||||
params.resFolder = reader.next();
|
params.resFolder = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path> - set resources directory."),
|
}, "<path>", "set resources directory."),
|
||||||
ArgC("--dir", [¶ms, &reader]() -> bool {
|
ArgC("--dir", [¶ms, &reader]() -> bool {
|
||||||
params.userFolder = reader.next();
|
params.userFolder = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path> - set userfiles directory."),
|
}, "<path>", "set userfiles directory."),
|
||||||
ArgC("--project", [¶ms, &reader]() -> bool {
|
ArgC("--project", [¶ms, &reader]() -> bool {
|
||||||
params.projectFolder = reader.next();
|
params.projectFolder = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path> - set project directory."),
|
}, "<path>", "set project directory."),
|
||||||
ArgC("--test", [¶ms, &reader]() -> bool {
|
ArgC("--test", [¶ms, &reader]() -> bool {
|
||||||
params.testMode = true;
|
params.testMode = true;
|
||||||
params.scriptFile = reader.next();
|
params.scriptFile = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path> - test script file."),
|
}, "<path>", "test script file."),
|
||||||
ArgC("--script", [¶ms, &reader]() -> bool {
|
ArgC("--script", [¶ms, &reader]() -> bool {
|
||||||
params.testMode = false;
|
params.testMode = false;
|
||||||
params.scriptFile = reader.next();
|
params.scriptFile = reader.next();
|
||||||
return true;
|
return true;
|
||||||
}, "<path> - main script file."),
|
}, "<path>", "main script file."),
|
||||||
ArgC("--headless", [¶ms]() -> bool {
|
ArgC("--headless", [¶ms]() -> bool {
|
||||||
params.headless = true;
|
params.headless = true;
|
||||||
return true;
|
return true;
|
||||||
}, "- run in headless mode."),
|
}, "", "run in headless mode."),
|
||||||
|
ArgC("--tps", [¶ms, &reader]() -> bool {
|
||||||
|
params.tps = reader.nextInt();
|
||||||
|
return true;
|
||||||
|
}, "<tps>", "headless mode tick-rate (default - 20)."),
|
||||||
ArgC("--version", []() -> bool {
|
ArgC("--version", []() -> bool {
|
||||||
std::cout << ENGINE_VERSION_STRING << std::endl;
|
std::cout << ENGINE_VERSION_STRING << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}, "- display the engine version."),
|
}, "", "display the engine version."),
|
||||||
ArgC("--help", []() -> bool {
|
ArgC("--help", []() -> bool {
|
||||||
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
|
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
|
||||||
std::cout << "Command-line arguments:\n";
|
std::cout << "Command-line arguments:\n";
|
||||||
for (auto& a : argumentsCommandline) {
|
for (auto& a : argumentsCommandline) {
|
||||||
std::cout << a.keyword << " " << a.help << std::endl;
|
std::cout << std::setw(20) << std::left << (a.keyword + " " + a.args);
|
||||||
|
std::cout << "- " << a.help << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}, "- display this help.")
|
}, "", "display this help.")
|
||||||
};
|
};
|
||||||
for (auto& a : argumentsCommandline) {
|
for (auto& a : argumentsCommandline) {
|
||||||
if (a.keyword == keyword) {
|
if (a.keyword == keyword) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user