-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'headless-mode' into Fix-usage-vcpkg-for-windows-and-add…
…-cmake-preset-for-vscode
- Loading branch information
Showing
90 changed files
with
1,957 additions
and
1,146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include "ServerMainloop.hpp" | ||
|
||
#include "logic/scripting/scripting.hpp" | ||
#include "logic/LevelController.hpp" | ||
#include "interfaces/Process.hpp" | ||
#include "debug/Logger.hpp" | ||
#include "world/Level.hpp" | ||
#include "world/World.hpp" | ||
#include "util/platform.hpp" | ||
#include "engine.hpp" | ||
|
||
#include <chrono> | ||
|
||
using namespace std::chrono; | ||
|
||
static debug::Logger logger("mainloop"); | ||
|
||
inline constexpr int TPS = 20; | ||
|
||
ServerMainloop::ServerMainloop(Engine& engine) : engine(engine) { | ||
} | ||
|
||
ServerMainloop::~ServerMainloop() = default; | ||
|
||
void ServerMainloop::run() { | ||
const auto& coreParams = engine.getCoreParameters(); | ||
auto& time = engine.getTime(); | ||
|
||
if (coreParams.scriptFile.empty()) { | ||
logger.info() << "nothing to do"; | ||
return; | ||
} | ||
engine.setLevelConsumer([this](auto level) { | ||
setLevel(std::move(level)); | ||
}); | ||
|
||
logger.info() << "starting test " << coreParams.scriptFile; | ||
auto process = scripting::start_coroutine(coreParams.scriptFile); | ||
|
||
double targetDelta = 1.0 / static_cast<double>(TPS); | ||
double delta = targetDelta; | ||
auto begin = system_clock::now(); | ||
auto startupTime = begin; | ||
|
||
while (process->isActive()) { | ||
if (engine.isQuitSignal()) { | ||
process->terminate(); | ||
logger.info() << "script has been terminated due to quit signal"; | ||
break; | ||
} | ||
if (coreParams.testMode) { | ||
time.step(delta); | ||
} else { | ||
auto now = system_clock::now(); | ||
time.update( | ||
duration_cast<microseconds>(now - startupTime).count() / 1e6); | ||
delta = time.getDelta(); | ||
} | ||
process->update(); | ||
if (controller) { | ||
controller->getLevel()->getWorld()->updateTimers(delta); | ||
controller->update(glm::min(delta, 0.2), false); | ||
} | ||
|
||
if (!coreParams.testMode) { | ||
auto end = system_clock::now(); | ||
platform::sleep(targetDelta * 1000 - | ||
duration_cast<microseconds>(end - begin).count() / 1000); | ||
begin = system_clock::now(); | ||
} | ||
} | ||
logger.info() << "test finished"; | ||
} | ||
|
||
void ServerMainloop::setLevel(std::unique_ptr<Level> level) { | ||
if (level == nullptr) { | ||
controller->onWorldQuit(); | ||
engine.getPaths().setCurrentWorldFolder(fs::path()); | ||
controller = nullptr; | ||
} else { | ||
controller = std::make_unique<LevelController>( | ||
&engine, std::move(level), nullptr | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.