Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless mode #402

Draft
wants to merge 66 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
3e01a39
refactor
MihailRis Dec 6, 2024
27acc1d
rename voxel_engine.cpp to main.cpp
MihailRis Dec 6, 2024
1ab3707
update locale log messages
MihailRis Dec 6, 2024
ee1a170
add headless mode (engine initialization and finalization)
MihailRis Dec 6, 2024
c80e2df
add 'Run tests' step to appimage.yml workflow
MihailRis Dec 6, 2024
d81718a
update appimage workflow
MihailRis Dec 6, 2024
1d1d5c3
update appimage workflow
MihailRis Dec 6, 2024
e0670c1
add 'Run engine (headless)' step to appimage workflow & disable Build…
MihailRis Dec 6, 2024
d1f92c2
fix on_block_interact & fix segfault after engine finished
MihailRis Dec 6, 2024
d2fbb83
disable extra locale reload in headless mode
MihailRis Dec 6, 2024
d9bd60f
update windows and macos workflows & add engine version to log
MihailRis Dec 6, 2024
5e8805f
add vctest (WIP)
MihailRis Dec 7, 2024
95b848f
replace 'Run engine (headless)' with 'Run engine tests' in AppImage w…
MihailRis Dec 7, 2024
7405caa
update appimage.yml
MihailRis Dec 7, 2024
df4b4a3
update appimage.yml
MihailRis Dec 7, 2024
19b458d
replace 'Run engine (headless)' with 'Run engine tests'
MihailRis Dec 7, 2024
2834fbe
update macos.yml
MihailRis Dec 7, 2024
7528649
update macos.yml
MihailRis Dec 7, 2024
c030944
replace 'Run engine (headless)' with 'Run engine tests' in windows wo…
MihailRis Dec 7, 2024
ed4bfee
update windows.yml
MihailRis Dec 7, 2024
95be0e7
update vctest
MihailRis Dec 7, 2024
f86bbaa
update vctest
MihailRis Dec 7, 2024
c9207a8
update vctest
MihailRis Dec 7, 2024
798a86d
update vctest
MihailRis Dec 7, 2024
bc10207
update vctest (MSVC)
MihailRis Dec 7, 2024
edc3d47
update vctest (MSVC)
MihailRis Dec 7, 2024
eb53ccf
update vctest (MSVC)
MihailRis Dec 7, 2024
6e5df53
update vctest (MSVC)
MihailRis Dec 7, 2024
bbb9987
windows (#405)
MihailRis Dec 7, 2024
59402b6
add 'test' library
MihailRis Dec 7, 2024
eaffc0c
Merge branch 'main' into headless-mode
MihailRis Dec 7, 2024
a036c5e
fix base:bazalt durability
MihailRis Dec 8, 2024
5fe5c6b
fix player tick rate
MihailRis Dec 8, 2024
5ffc054
refactor
MihailRis Dec 8, 2024
8f37704
fix libworld docs
MihailRis Dec 10, 2024
9b4dd8f
refactor & add test.new_world
MihailRis Dec 10, 2024
d3f74b5
add test.close_world(bool)
MihailRis Dec 10, 2024
9e18dcc
enable verbose engine tests output
MihailRis Dec 10, 2024
3c2eb30
add test.reconfig_packs & fix world.get_total_time() & enable level c…
MihailRis Dec 10, 2024
c67f158
remove default player from headless mode
MihailRis Dec 10, 2024
b05c2fc
fix 'timeit' in headless mode
MihailRis Dec 11, 2024
cfc1667
add test.open_world
MihailRis Dec 11, 2024
91fa283
reduce 'corrupted block detected ...' spam if chunk data is corrupted
MihailRis Dec 11, 2024
436bfd2
update ChunksStorage
MihailRis Dec 11, 2024
60f2303
Merge branch 'main' into headless-mode
MihailRis Dec 11, 2024
0d071ab
fix camera-related bugs
MihailRis Dec 11, 2024
c1a7b75
change components on_render call timing
MihailRis Dec 11, 2024
9adaf6d
update workflows
MihailRis Dec 11, 2024
863146c
move PlayerController to LevelScreen
MihailRis Dec 11, 2024
7e92a16
fix weak_ptr leak
MihailRis Dec 11, 2024
8a5042f
fix msvc build
MihailRis Dec 11, 2024
9ec8788
add player.create, test.set_setting, test.sleep_until, world.count_ch…
MihailRis Dec 12, 2024
8e6fb1d
update libworld docs
MihailRis Dec 12, 2024
913f942
add platform::get_process_id
MihailRis Dec 12, 2024
086c20c
cache block.index, block.name, item.index, item.name
MihailRis Dec 12, 2024
53cc8d3
add core.blank
MihailRis Dec 12, 2024
e0b3425
migrate blocks interaction (scripting) to global chunks storage (WIP)
MihailRis Dec 13, 2024
bf43fd7
update libblock
MihailRis Dec 13, 2024
251aca7
test
MihailRis Dec 13, 2024
76559cc
Revert "test"
MihailRis Dec 13, 2024
12c10d1
Add Windows build with Clang (#411)
MihailRis Dec 14, 2024
59978f4
rename workflows
MihailRis Dec 14, 2024
5e025b5
update test
MihailRis Dec 14, 2024
323acb2
static link libstdc++ (mingw)
MihailRis Dec 14, 2024
e713412
rename ChunksStorage to GlobalChunks
MihailRis Dec 14, 2024
92f11dd
Merge branch 'main' into headless-mode
MihailRis Dec 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: C/C++ AppImage
name: x86-64 AppImage

on:
push:
Expand All @@ -20,11 +20,11 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: install dependencies
- name: Install dependencies
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 cmake squashfs-tools
libglm-dev libpng-dev libopenal-dev libluajit-5.1-dev libvorbis-dev libcurl4-openssl-dev libgtest-dev cmake squashfs-tools tree
# 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 All @@ -34,10 +34,18 @@ jobs:
cmake -DCMAKE_BUILD_TYPE=Release ..
sudo make install
cd ../..
- name: configure
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_APPDIR=1
- name: build
- name: Configure
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_APPDIR=1 -DVOXELENGINE_BUILD_TESTS=ON
- name: Build
run: cmake --build build -t install
- name: Run tests
run: ctest --test-dir build
- name: Run engine tests
timeout-minutes: 1
run: |
chmod +x build/VoxelEngine
chmod +x AppDir/usr/bin/vctest
AppDir/usr/bin/vctest -e build/VoxelEngine -d dev/tests -u build --output-always
- name: Build AppImage
uses: AppImageCrafters/build-appimage-action@fe2205a4d6056be47051f7b1b3811106e9814910
env:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ jobs:
- name: Run tests
run: ctest --output-on-failure --test-dir build

- name: Run engine tests
timeout-minutes: 1
run: |
chmod +x build/VoxelEngine
chmod +x AppDir/usr/bin/vctest
AppDir/usr/bin/vctest -e build/VoxelEngine -d dev/tests -u build --output-always
- name: Create DMG
run: |
mkdir VoxelEngineDmgContent
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/windows-clang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Windows Build (CLang)

on:
push:
branches: [ "main", "release-**"]
pull_request:
branches: [ "main" ]

jobs:
build-windows:

strategy:
matrix:
include:
- os: windows-latest
compiler: clang

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- uses: msys2/setup-msys2@v2
id: msys2
name: Setup MSYS2
with:
msystem: clang64
install: >-
mingw-w64-clang-x86_64-toolchain
mingw-w64-clang-x86_64-cmake
mingw-w64-clang-x86_64-make
mingw-w64-clang-x86_64-luajit
git tree
- name: Set up vcpkg
shell: msys2 {0}
run: |
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat
./vcpkg integrate install
cd ..
- name: Configure project with CMake and vcpkg
shell: msys2 {0}
run: |
export VCPKG_DEFAULT_TRIPLET=x64-mingw-static
export VCPKG_DEFAULT_HOST_TRIPLET=x64-mingw-static
mkdir build
cd build
cmake -G "MinGW Makefiles" -DVCPKG_TARGET_TRIPLET=x64-mingw-static -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_WINDOWS_VCPKG=ON ..
cmake --build . --config Release
- name: Package for Windows
run: |
mkdir packaged
mkdir packaged/res
cp build/VoxelEngine.exe packaged/
cp build/vctest/vctest.exe packaged/
cp build/*.dll packaged/
cp -r build/res/* packaged/res/
mv packaged/VoxelEngine.exe packaged/VoxelCore.exe
- env:
MSYS2_LOCATION: ${{ steps.msys2.outputs.msys2-location }}
name: Add lua51.dll to the package
run: |
cp $env:MSYS2_LOCATION/clang64/bin/lua51.dll ${{ github.workspace }}/packaged/
working-directory: ${{ github.workspace }}
- uses: actions/upload-artifact@v4
with:
name: Windows-Build
path: 'packaged/*'
- name: Run engine tests
shell: msys2 {0}
working-directory: ${{ github.workspace }}
run: |
packaged/vctest.exe -e packaged/VoxelCore.exe -d dev/tests -u build --output-always
12 changes: 8 additions & 4 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Windows Build
name: MSVC Build

on:
push:
Expand Down Expand Up @@ -34,16 +34,20 @@ jobs:
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_WINDOWS_VCPKG=ON -DVOXELENGINE_BUILD_TESTS=ON ..
cmake --build . --config Release
- name: Run tests
run: ctest --output-on-failure --test-dir build
- name: Run engine tests
run: |
build/vctest/Release/vctest.exe -e build/Release/VoxelEngine.exe -d dev/tests -u build --output-always
timeout-minutes: 1
- name: Package for Windows
run: |
mkdir packaged
cp -r build/* packaged/
cp C:/Windows/System32/msvcp140.dll packaged/Release/msvcp140.dll
mv packaged/Release/VoxelEngine.exe packaged/Release/VoxelCore.exe
working-directory: ${{ github.workspace }}
- name: Run tests
run: ctest --output-on-failure --test-dir build
- uses: actions/upload-artifact@v4
with:
name: Windows-Build
path: 'packaged/Release/*'
path: 'build/Release/*'
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ option(VOXELENGINE_BUILD_TESTS OFF)
set(CMAKE_CXX_STANDARD 17)

add_subdirectory(src)
add_executable(${PROJECT_NAME} src/voxel_engine.cpp)
add_executable(${PROJECT_NAME} src/main.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)

if(VOXELENGINE_BUILD_APPDIR)
Expand All @@ -39,6 +39,9 @@ else()
if (CMAKE_BUILD_TYPE MATCHES "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE -Og)
endif()
if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
endif()
endif()

if(VOXELENGINE_BUILD_WINDOWS_VCPKG AND WIN32)
Expand Down Expand Up @@ -81,4 +84,6 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res DESTINATION ${CMAKE_CURRENT_BINARY_DIR
if (VOXELENGINE_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
endif()

add_subdirectory(vctest)
19 changes: 19 additions & 0 deletions dev/tests/example.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test.set_setting("chunks.load-distance", 3)
test.set_setting("chunks.load-speed", 16)

test.reconfig_packs({"base"}, {})
test.new_world("demo", "2019", "core:default")
local pid = player.create("Xerxes")
assert(player.get_name(pid) == "Xerxes")
test.sleep_until(function() return world.count_chunks() >= 9 end, 1000)
print(world.count_chunks())

for i=1,3 do
print("---")
timeit(1000000, block.get, 0, 0, 0)
timeit(1000000, block.get_slow, 0, 0, 0)
end

block.destruct(0, 0, 0, pid)
assert(block.get(0, 0, 0) == 0)
test.close_world(true)
23 changes: 23 additions & 0 deletions dev/tests/world.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Create/close/open/close world

-- Open
test.new_world("demo", "2019", "core:default")
assert(world.is_open())
assert(world.get_generator() == "core:default")
test.sleep(1)
assert(world.get_total_time() > 0.0)
print(world.get_total_time())

-- Close
test.close_world(true)
assert(not world.is_open())

-- Reopen
test.open_world("demo")
assert(world.is_open())
assert(world.get_total_time() > 0.0)
assert(world.get_seed() == 2019)
test.tick()

-- Close
test.close_world(true)
15 changes: 8 additions & 7 deletions doc/en/scripting/builtins/libworld.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ world.get_seed() -> int
-- Returns generator name.
world.get_generator() -> str

-- Proves that this is the current time during the day
-- from 0.333(8 am) to 0.833(8 pm).
world.is_day() -> boolean
-- Checks the existence of a world by name.
world.exists(name: str) -> bool

-- Checks if the current time is daytime. From 0.333(8am) to 0.833(8pm).
world.is_day() -> bool

-- Checks that it is the current time at night
-- from 0.833(8 pm) to 0.333(8 am).
-- Checks if the current time is nighttime. From 0.833(8pm) to 0.333(8am).
world.is_night() -> bool

-- Checks the existence of a world by name.
world.exists() -> bool
-- Returns the total number of chunks loaded into memory
world.count_chunks() -> int
```
5 changes: 4 additions & 1 deletion doc/ru/scripting/builtins/libworld.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ world.get_seed() -> int
world.get_generator() -> str

-- Проверяет существование мира по имени.
world.exists() -> bool
world.exists(name: str) -> bool

-- Проверяет является ли текущее время днём. От 0.333(8 утра) до 0.833(8 вечера).
world.is_day() -> bool

-- Проверяет является ли текущее время ночью. От 0.833(8 вечера) до 0.333(8 утра).
world.is_night() -> bool

-- Возвращает общее количество загруженных в память чанков
world.count_chunks() -> int
```
3 changes: 2 additions & 1 deletion res/content/base/blocks/bazalt.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"texture": "bazalt",
"breakable": false
"breakable": false,
"base:durability": 1e9
}
22 changes: 12 additions & 10 deletions res/content/base/scripts/world.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
function on_block_broken(id, x, y, z, playerid)
gfx.particles.emit({x+0.5, y+0.5, z+0.5}, 64, {
lifetime=1.0,
spawn_interval=0.0001,
explosion={4, 4, 4},
texture="blocks:"..block.get_textures(id)[1],
random_sub_uv=0.1,
size={0.1, 0.1, 0.1},
spawn_shape="box",
spawn_spread={0.4, 0.4, 0.4}
})
if gfx then
gfx.particles.emit({x+0.5, y+0.5, z+0.5}, 64, {
lifetime=1.0,
spawn_interval=0.0001,
explosion={4, 4, 4},
texture="blocks:"..block.get_textures(id)[1],
random_sub_uv=0.1,
size={0.1, 0.1, 0.1},
spawn_shape="box",
spawn_spread={0.4, 0.4, 0.4}
})
end
end
23 changes: 22 additions & 1 deletion res/scripts/post_content.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local names = {
"hidden", "draw-group", "picking-item", "surface-replacement", "script-name",
"ui-layout", "inventory-size", "tick-interval", "overlay-texture",
"translucent", "fields", "particles", "icon-type", "icon", "placing-block",
"stack-size"
"stack-size", "name"
}
for name, _ in pairs(user_props) do
table.insert(names, name)
Expand Down Expand Up @@ -40,3 +40,24 @@ make_read_only(block.properties)
for k,v in pairs(block.properties) do
make_read_only(v)
end

local function cache_names(library)
local indices = {}
local names = {}
for id=0,library.defs_count()-1 do
local name = library.properties[id].name
indices[name] = id
names[id] = name
end

function library.name(id)
return names[id]
end

function library.index(name)
return indices[name]
end
end

cache_names(block)
cache_names(item)
Loading
Loading