Skip to content

Commit

Permalink
Merge branch 'headless-mode' into Fix-usage-vcpkg-for-windows-and-add…
Browse files Browse the repository at this point in the history
…-cmake-preset-for-vscode
  • Loading branch information
Stepanov Igor committed Dec 20, 2024
2 parents dd09e3f + 1aca495 commit 3b96c13
Show file tree
Hide file tree
Showing 90 changed files with 1,957 additions and 1,146 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "main", "release-**"]
pull_request:
branches: [ "main" ]
branches: [ "main", "headless-mode" ]

jobs:
build-appimage:
Expand All @@ -24,7 +24,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y build-essential libglfw3-dev libglfw3 libglew-dev \
libglm-dev libpng-dev libopenal-dev libluajit-5.1-dev libvorbis-dev libcurl4-openssl-dev libgtest-dev cmake squashfs-tools tree
libglm-dev libpng-dev libopenal-dev libluajit-5.1-dev libvorbis-dev libcurl4-openssl-dev libgtest-dev cmake squashfs-tools
# fix luajit paths
sudo ln -s /usr/lib/x86_64-linux-gnu/libluajit-5.1.a /usr/lib/x86_64-linux-gnu/liblua5.1.a
sudo ln -s /usr/include/luajit-2.1 /usr/include/lua
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "main", "release-**"]
pull_request:
branches: [ "main" ]
branches: [ "main", "headless-mode" ]

jobs:
build-dmg:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "main", "release-**"]
pull_request:
branches: [ "main" ]
branches: [ "main", "headless-mode" ]

jobs:
build-windows:
Expand All @@ -31,7 +31,7 @@ jobs:
mingw-w64-clang-x86_64-cmake
mingw-w64-clang-x86_64-make
mingw-w64-clang-x86_64-luajit
git tree
git
- name: Set up vcpkg
shell: msys2 {0}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "main", "release-**"]
pull_request:
branches: [ "main" ]
branches: [ "main", "headless-mode" ]

jobs:
build-windows:
Expand Down
27 changes: 27 additions & 0 deletions dev/tests/chunks.lua
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)
19 changes: 0 additions & 19 deletions dev/tests/example.lua

This file was deleted.

6 changes: 3 additions & 3 deletions doc/en/audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Library **audio** contains available Audio API in Lua scripts.

```lua
audio.play_stream(
-- audio file location
-- audio file location (without entry point, but with extension included)
name: string,
-- audio source world position
x: number, y: number, z: number,
Expand All @@ -79,7 +79,7 @@ Plays streaming audio from the specified file at the specified world position. R

```lua
audio.play_stream_2d(
-- audio file location
-- audio file location (without entry point, but with extension included)
name: string,
-- audio gain (0.0 - 1.0)
volume: number
Expand Down Expand Up @@ -202,4 +202,4 @@ audio.count_speakers() -> integer

-- get current number of playing streams
audio.count_streams() -> integer
```
```
1 change: 1 addition & 0 deletions doc/en/world-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The main properties described in the configuration file:
- **biomes-bpd** - number of blocks per point of the biome selection parameter map. Default: 4.
- **heights-bpd** - number of blocks per point of the height map. Default: 4.
- **wide-structs-chunks-radius** - maximum radius for placing 'wide' structures, measured in chunks.
- **heightmap-inputs** - an array of parameter map numbers that will be passed by the inputs table to the height map generation function.

## Global variables

Expand Down
4 changes: 2 additions & 2 deletions doc/ru/audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

```lua
audio.play_stream(
-- путь к аудио-файлу
-- путь к аудио-файлу (без точки входа, но с указанием расширения)
name: string,
-- позиция источника аудио в мире
x: number, y: number, z: number,
Expand All @@ -80,7 +80,7 @@ audio.play_stream(

```lua
audio.play_stream_2d(
-- путь к аудио-файлу
-- путь к аудио-файлу (без точки входа, но с указанием расширения)
name: string,
-- громкость аудио (от 0.0 до 1.0)
volume: number
Expand Down
1 change: 1 addition & 0 deletions doc/ru/world-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- **biomes-bpd** - количество блоков на точку карты параметра выбора биомов. По-умолчанию: 4.
- **heights-bpd** - количество блоков на точку карты высот. По-умолчанию: 4.
- **wide-structs-chunks-radius** - масимальный радиус размещения 'широких' структур, измеряемый в чанках.
- **heightmap-inputs** - массив номеров карт параметров, которые будут переданы таблицей inputs в функцию генерации карты высот.

## Глобальные переменные

Expand Down
30 changes: 29 additions & 1 deletion res/scripts/stdlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,42 @@ function sleep(timesec)
end
end

function tb_frame_tostring(frame)
local s = frame.short_src
if frame.what ~= "C" then
s = s .. ":" .. tostring(frame.currentline)
end
if frame.what == "main" then
s = s .. ": in main chunk"
elseif frame.name then
s = s .. ": in function " .. utf8.escape(frame.name)
end
return s
end

if test then
test.sleep = sleep
test.name = __VC_TEST_NAME
test.new_world = core.new_world
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

function test.quit()
local tb = debug.get_traceback(1)
local s = "test.quit() traceback:"
for i, frame in ipairs(tb) do
s = s .. "\n\t"..tb_frame_tostring(frame)
end
debug.log(s)
core.quit()
coroutine.yield()
end

function test.sleep_until(predicate, max_ticks)
max_ticks = max_ticks or 1e9
local ticks = 0
Expand Down Expand Up @@ -382,7 +408,9 @@ end
function __vc_stop_coroutine(id)
local co = __vc_coroutines[id]
if co then
coroutine.close(co)
if coroutine.close then
coroutine.close(co)
end
__vc_coroutines[id] = nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion res/scripts/stdmin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function table.deep_copy(t)
end
end

return copied
return setmetatable(copied, getmetatable(t))
end

function table.count_pairs(t)
Expand Down
6 changes: 3 additions & 3 deletions src/Mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ void Mainloop::run() {
// destroy LevelScreen and run quit callbacks
engine.setScreen(nullptr);
// create and go to menu screen
engine.setScreen(std::make_shared<MenuScreen>(&engine));
engine.setScreen(std::make_shared<MenuScreen>(engine));
} else {
engine.setScreen(std::make_shared<LevelScreen>(&engine, std::move(level)));
engine.setScreen(std::make_shared<LevelScreen>(engine, std::move(level)));
}
});

logger.info() << "starting menu screen";
engine.setScreen(std::make_shared<MenuScreen>(&engine));
engine.setScreen(std::make_shared<MenuScreen>(engine));

logger.info() << "main loop started";
while (!Window::isShouldClose()){
Expand Down
85 changes: 85 additions & 0 deletions src/ServerMainloop.cpp
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
);
}
}
6 changes: 3 additions & 3 deletions src/TestMainloop.hpp → src/ServerMainloop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class Level;
class LevelController;
class Engine;

class TestMainloop {
class ServerMainloop {
Engine& engine;
std::unique_ptr<LevelController> controller;
public:
TestMainloop(Engine& engine);
~TestMainloop();
ServerMainloop(Engine& engine);
~ServerMainloop();

void run();

Expand Down
54 changes: 0 additions & 54 deletions src/TestMainloop.cpp

This file was deleted.

Loading

0 comments on commit 3b96c13

Please sign in to comment.