add '--script', '--version' command line arguments
This commit is contained in:
parent
48d94036fd
commit
fa1646a9bd
@ -1,4 +1,4 @@
|
|||||||
#include "TestMainloop.hpp"
|
#include "ServerMainloop.hpp"
|
||||||
|
|
||||||
#include "logic/scripting/scripting.hpp"
|
#include "logic/scripting/scripting.hpp"
|
||||||
#include "logic/LevelController.hpp"
|
#include "logic/LevelController.hpp"
|
||||||
@ -6,22 +6,27 @@
|
|||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
|
#include "util/platform.hpp"
|
||||||
#include "engine.hpp"
|
#include "engine.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
static debug::Logger logger("mainloop");
|
static debug::Logger logger("mainloop");
|
||||||
|
|
||||||
inline constexpr int TPS = 20;
|
inline constexpr int TPS = 20;
|
||||||
|
|
||||||
TestMainloop::TestMainloop(Engine& engine) : engine(engine) {
|
ServerMainloop::ServerMainloop(Engine& engine) : engine(engine) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TestMainloop::~TestMainloop() = default;
|
ServerMainloop::~ServerMainloop() = default;
|
||||||
|
|
||||||
void TestMainloop::run() {
|
void ServerMainloop::run() {
|
||||||
const auto& coreParams = engine.getCoreParameters();
|
const auto& coreParams = engine.getCoreParameters();
|
||||||
auto& time = engine.getTime();
|
auto& time = engine.getTime();
|
||||||
|
|
||||||
if (coreParams.testFile.empty()) {
|
if (coreParams.scriptFile.empty()) {
|
||||||
logger.info() << "nothing to do";
|
logger.info() << "nothing to do";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -29,21 +34,34 @@ void TestMainloop::run() {
|
|||||||
setLevel(std::move(level));
|
setLevel(std::move(level));
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info() << "starting test " << coreParams.testFile;
|
logger.info() << "starting test " << coreParams.scriptFile;
|
||||||
auto process = scripting::start_coroutine(coreParams.testFile);
|
auto process = scripting::start_coroutine(coreParams.scriptFile);
|
||||||
|
|
||||||
|
double targetDelta = 1.0f / static_cast<float>(TPS);
|
||||||
|
double delta = targetDelta;
|
||||||
|
auto begin = steady_clock::now();
|
||||||
while (process->isActive()) {
|
while (process->isActive()) {
|
||||||
time.step(1.0f / static_cast<float>(TPS));
|
time.step(delta);
|
||||||
process->update();
|
process->update();
|
||||||
if (controller) {
|
if (controller) {
|
||||||
float delta = time.getDelta();
|
float delta = time.getDelta();
|
||||||
controller->getLevel()->getWorld()->updateTimers(delta);
|
controller->getLevel()->getWorld()->updateTimers(delta);
|
||||||
controller->update(glm::min(delta, 0.2f), false);
|
controller->update(glm::min(delta, 0.2f), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!coreParams.testMode) {
|
||||||
|
auto end = steady_clock::now();
|
||||||
|
platform::sleep(targetDelta * 1000 -
|
||||||
|
duration_cast<microseconds>(end - begin).count() / 1000);
|
||||||
|
end = steady_clock::now();
|
||||||
|
delta = duration_cast<microseconds>(end - begin).count() / 1e6;
|
||||||
|
begin = end;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logger.info() << "test finished";
|
logger.info() << "test finished";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestMainloop::setLevel(std::unique_ptr<Level> level) {
|
void ServerMainloop::setLevel(std::unique_ptr<Level> level) {
|
||||||
if (level == nullptr) {
|
if (level == nullptr) {
|
||||||
controller->onWorldQuit();
|
controller->onWorldQuit();
|
||||||
engine.getPaths()->setCurrentWorldFolder(fs::path());
|
engine.getPaths()->setCurrentWorldFolder(fs::path());
|
||||||
@ -6,12 +6,12 @@ class Level;
|
|||||||
class LevelController;
|
class LevelController;
|
||||||
class Engine;
|
class Engine;
|
||||||
|
|
||||||
class TestMainloop {
|
class ServerMainloop {
|
||||||
Engine& engine;
|
Engine& engine;
|
||||||
std::unique_ptr<LevelController> controller;
|
std::unique_ptr<LevelController> controller;
|
||||||
public:
|
public:
|
||||||
TestMainloop(Engine& engine);
|
ServerMainloop(Engine& engine);
|
||||||
~TestMainloop();
|
~ServerMainloop();
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
@ -36,7 +36,7 @@
|
|||||||
#include "window/Window.hpp"
|
#include "window/Window.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "Mainloop.hpp"
|
#include "Mainloop.hpp"
|
||||||
#include "TestMainloop.hpp"
|
#include "ServerMainloop.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -173,7 +173,7 @@ void Engine::saveScreenshot() {
|
|||||||
|
|
||||||
void Engine::run() {
|
void Engine::run() {
|
||||||
if (params.headless) {
|
if (params.headless) {
|
||||||
TestMainloop(*this).run();
|
ServerMainloop(*this).run();
|
||||||
} else {
|
} else {
|
||||||
Mainloop(*this).run();
|
Mainloop(*this).run();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,9 +48,10 @@ public:
|
|||||||
|
|
||||||
struct CoreParameters {
|
struct CoreParameters {
|
||||||
bool headless = false;
|
bool headless = false;
|
||||||
|
bool testMode = false;
|
||||||
std::filesystem::path resFolder {"res"};
|
std::filesystem::path resFolder {"res"};
|
||||||
std::filesystem::path userFolder {"."};
|
std::filesystem::path userFolder {"."};
|
||||||
std::filesystem::path testFile;
|
std::filesystem::path scriptFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Engine : public util::ObjectsKeeper {
|
class Engine : public util::ObjectsKeeper {
|
||||||
|
|||||||
@ -121,7 +121,7 @@ void lua::initialize(const EnginePaths& paths, const CoreParameters& params) {
|
|||||||
main_thread = create_state(
|
main_thread = create_state(
|
||||||
paths, params.headless ? StateType::TEST : StateType::BASE
|
paths, params.headless ? StateType::TEST : StateType::BASE
|
||||||
);
|
);
|
||||||
lua::pushstring(main_thread, params.testFile.stem().u8string());
|
lua::pushstring(main_thread, params.scriptFile.stem().u8string());
|
||||||
lua::setglobal(main_thread, "__VC_TEST_NAME");
|
lua::setglobal(main_thread, "__VC_TEST_NAME");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,19 +19,30 @@ static bool perform_keyword(
|
|||||||
auto token = reader.next();
|
auto token = reader.next();
|
||||||
params.userFolder = fs::u8path(token);
|
params.userFolder = fs::u8path(token);
|
||||||
} else if (keyword == "--help" || keyword == "-h") {
|
} else if (keyword == "--help" || keyword == "-h") {
|
||||||
std::cout << "VoxelEngine command-line arguments:\n";
|
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
|
||||||
|
std::cout << "command-line arguments:\n";
|
||||||
std::cout << " --help - show help\n";
|
std::cout << " --help - show help\n";
|
||||||
|
std::cout << " --version - print engine version\n";
|
||||||
std::cout << " --res <path> - set resources directory\n";
|
std::cout << " --res <path> - set resources directory\n";
|
||||||
std::cout << " --dir <path> - set userfiles directory\n";
|
std::cout << " --dir <path> - set userfiles directory\n";
|
||||||
std::cout << " --headless - run in headless mode\n";
|
std::cout << " --headless - run in headless mode\n";
|
||||||
std::cout << " --test <path> - test script file\n";
|
std::cout << " --test <path> - test script file\n";
|
||||||
|
std::cout << " --script <path> - main script file\n";
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
return false;
|
return false;
|
||||||
|
} else if (keyword == "--version") {
|
||||||
|
std::cout << ENGINE_VERSION_STRING << std::endl;
|
||||||
|
return false;
|
||||||
} else if (keyword == "--headless") {
|
} else if (keyword == "--headless") {
|
||||||
params.headless = true;
|
params.headless = true;
|
||||||
} else if (keyword == "--test") {
|
} else if (keyword == "--test") {
|
||||||
auto token = reader.next();
|
auto token = reader.next();
|
||||||
params.testFile = fs::u8path(token);
|
params.testMode = true;
|
||||||
|
params.scriptFile = fs::u8path(token);
|
||||||
|
} else if (keyword == "--script") {
|
||||||
|
auto token = reader.next();
|
||||||
|
params.testMode = false;
|
||||||
|
params.scriptFile = fs::u8path(token);
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error("unknown argument " + keyword);
|
throw std::runtime_error("unknown argument " + keyword);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,6 @@ public:
|
|||||||
|
|
||||||
std::unique_ptr<GlobalChunks> chunks;
|
std::unique_ptr<GlobalChunks> chunks;
|
||||||
std::unique_ptr<Inventories> inventories;
|
std::unique_ptr<Inventories> inventories;
|
||||||
|
|
||||||
std::unique_ptr<PhysicsSolver> physics;
|
std::unique_ptr<PhysicsSolver> physics;
|
||||||
std::unique_ptr<LevelEvents> events;
|
std::unique_ptr<LevelEvents> events;
|
||||||
std::unique_ptr<Entities> entities;
|
std::unique_ptr<Entities> entities;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user