diff --git a/dev/tests/chunks.lua b/dev/tests/chunks.lua new file mode 100644 index 00000000..dbc001ba --- /dev/null +++ b/dev/tests/chunks.lua @@ -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) diff --git a/dev/tests/example.lua b/dev/tests/example.lua index 89302aa4..e69de29b 100644 --- a/dev/tests/example.lua +++ b/dev/tests/example.lua @@ -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) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 9ddda13c..aa56bc31 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -29,6 +29,7 @@ if test then test.open_world = core.open_world test.close_world = core.close_world test.reopen_world = core.reopen_world + test.delete_world = core.delete_world test.reconfig_packs = core.reconfig_packs test.set_setting = core.set_setting test.tick = coroutine.yield diff --git a/src/ServerMainloop.cpp b/src/ServerMainloop.cpp index 3d05f55b..559196c6 100644 --- a/src/ServerMainloop.cpp +++ b/src/ServerMainloop.cpp @@ -37,9 +37,9 @@ void ServerMainloop::run() { logger.info() << "starting test " << coreParams.scriptFile; auto process = scripting::start_coroutine(coreParams.scriptFile); - double targetDelta = 1.0f / static_cast(TPS); + double targetDelta = 1.0 / static_cast(TPS); double delta = targetDelta; - auto begin = steady_clock::now(); + auto begin = system_clock::now(); while (process->isActive()) { if (engine.isQuitSignal()) { process->terminate(); @@ -49,16 +49,15 @@ void ServerMainloop::run() { time.step(delta); process->update(); if (controller) { - float delta = time.getDelta(); controller->getLevel()->getWorld()->updateTimers(delta); - controller->update(glm::min(delta, 0.2f), false); + controller->update(glm::min(delta, 0.2), false); } if (!coreParams.testMode) { - auto end = steady_clock::now(); + auto end = system_clock::now(); platform::sleep(targetDelta * 1000 - duration_cast(end - begin).count() / 1000); - end = steady_clock::now(); + end = system_clock::now(); delta = duration_cast(end - begin).count() / 1e6; begin = end; } diff --git a/vctest/main.cpp b/vctest/main.cpp index 7757041e..86e61553 100644 --- a/vctest/main.cpp +++ b/vctest/main.cpp @@ -117,8 +117,10 @@ static void setup_working_dir(const fs::path& workingDir) { fs::create_directories(dir); } -static void display_test_output(const fs::path& path, std::ostream& stream) { - stream << "[OUTPUT]" << std::endl; +static void display_test_output( + const fs::path& path, const fs::path& name, std::ostream& stream +) { + stream << "[OUTPUT] " << name << std::endl; if (fs::exists(path)) { std::ifstream t(path); stream << t.rdbuf(); @@ -160,13 +162,13 @@ static bool run_test(const Config& config, const fs::path& path) { .count(); if (code) { - display_test_output(outputFile, std::cerr); + display_test_output(outputFile, name, std::cerr); std::cerr << "[FAILED] " << name << " in " << testTime << " ms" << std::endl; fs::remove(outputFile); return false; } else { 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; fs::remove(outputFile);