update vctest & add new test

This commit is contained in:
MihailRis 2024-12-18 05:16:06 +03:00
parent d745a34657
commit a144dd75b7
5 changed files with 39 additions and 31 deletions

27
dev/tests/chunks.lua Normal file
View File

@ -0,0 +1,27 @@
test.set_setting("chunks.load-distance", 3)
test.set_setting("chunks.load-speed", 1)
test.reconfig_packs({"base"}, {})
test.new_world("demo", "2019", "core:default")
local pid1 = player.create("Xerxes")
assert(player.get_name(pid1) == "Xerxes")
local pid2 = player.create("Segfault")
assert(player.get_name(pid2) == "Segfault")
local seed = math.floor(math.random() * 1e6)
print("random seed", seed)
math.randomseed(seed)
for i=1,25 do
if i % 5 == 0 then
print(tostring(i*4).." % done")
print("chunks loaded", world.count_chunks())
end
player.set_pos(pid1, math.random() * 100 - 50, 100, math.random() * 100 - 50)
player.set_pos(pid2, math.random() * 200 - 100, 100, math.random() * 200 - 100)
test.tick()
end
test.close_world(true)

View File

@ -1,21 +0,0 @@
test.set_setting("chunks.load-distance", 3)
test.set_setting("chunks.load-speed", 1)
test.reconfig_packs({"base"}, {})
test.new_world("demo", "2019", "core:default")
local pid1 = player.create("Xerxes")
assert(player.get_name(pid) == "Xerxes")
local pid2 = player.create("Undefined")
for i=1,100 do
if i % 10 == 0 then
print(tostring(i).." % done")
print("chunks loaded", world.count_chunks())
end
player.set_pos(pid1, math.random() * 100 - 50, 100, math.random() * 100 - 50)
player.set_pos(pid2, math.random() * 200 - 100, 100, math.random() * 200 - 100)
test.tick()
end
test.close_world(true)

View File

@ -29,6 +29,7 @@ if test then
test.open_world = core.open_world test.open_world = core.open_world
test.close_world = core.close_world test.close_world = core.close_world
test.reopen_world = core.reopen_world test.reopen_world = core.reopen_world
test.delete_world = core.delete_world
test.reconfig_packs = core.reconfig_packs test.reconfig_packs = core.reconfig_packs
test.set_setting = core.set_setting test.set_setting = core.set_setting
test.tick = coroutine.yield test.tick = coroutine.yield

View File

@ -37,9 +37,9 @@ void ServerMainloop::run() {
logger.info() << "starting test " << coreParams.scriptFile; logger.info() << "starting test " << coreParams.scriptFile;
auto process = scripting::start_coroutine(coreParams.scriptFile); auto process = scripting::start_coroutine(coreParams.scriptFile);
double targetDelta = 1.0f / static_cast<float>(TPS); double targetDelta = 1.0 / static_cast<double>(TPS);
double delta = targetDelta; double delta = targetDelta;
auto begin = steady_clock::now(); auto begin = system_clock::now();
while (process->isActive()) { while (process->isActive()) {
if (engine.isQuitSignal()) { if (engine.isQuitSignal()) {
process->terminate(); process->terminate();
@ -49,16 +49,15 @@ void ServerMainloop::run() {
time.step(delta); time.step(delta);
process->update(); process->update();
if (controller) { if (controller) {
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.2), false);
} }
if (!coreParams.testMode) { if (!coreParams.testMode) {
auto end = steady_clock::now(); auto end = system_clock::now();
platform::sleep(targetDelta * 1000 - platform::sleep(targetDelta * 1000 -
duration_cast<microseconds>(end - begin).count() / 1000); duration_cast<microseconds>(end - begin).count() / 1000);
end = steady_clock::now(); end = system_clock::now();
delta = duration_cast<microseconds>(end - begin).count() / 1e6; delta = duration_cast<microseconds>(end - begin).count() / 1e6;
begin = end; begin = end;
} }

View File

@ -117,8 +117,10 @@ static void setup_working_dir(const fs::path& workingDir) {
fs::create_directories(dir); fs::create_directories(dir);
} }
static void display_test_output(const fs::path& path, std::ostream& stream) { static void display_test_output(
stream << "[OUTPUT]" << std::endl; const fs::path& path, const fs::path& name, std::ostream& stream
) {
stream << "[OUTPUT] " << name << std::endl;
if (fs::exists(path)) { if (fs::exists(path)) {
std::ifstream t(path); std::ifstream t(path);
stream << t.rdbuf(); stream << t.rdbuf();
@ -160,13 +162,13 @@ static bool run_test(const Config& config, const fs::path& path) {
.count(); .count();
if (code) { if (code) {
display_test_output(outputFile, std::cerr); display_test_output(outputFile, name, std::cerr);
std::cerr << "[FAILED] " << name << " in " << testTime << " ms" << std::endl; std::cerr << "[FAILED] " << name << " in " << testTime << " ms" << std::endl;
fs::remove(outputFile); fs::remove(outputFile);
return false; return false;
} else { } else {
if (config.outputAlways) { if (config.outputAlways) {
display_test_output(outputFile, std::cout); display_test_output(outputFile, name, std::cout);
} }
std::cout << "[PASSED] " << name << " in " << testTime << " ms" << std::endl; std::cout << "[PASSED] " << name << " in " << testTime << " ms" << std::endl;
fs::remove(outputFile); fs::remove(outputFile);