Merge branch 'main' into entities
This commit is contained in:
commit
3cafc39555
@ -91,6 +91,13 @@ player.set_noclip(bool)
|
|||||||
|
|
||||||
Getter and setter for player noclip mode (collisions disabled)
|
Getter and setter for player noclip mode (collisions disabled)
|
||||||
|
|
||||||
|
``` python
|
||||||
|
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
|
||||||
|
player.get_spawnpoint(playerid: int) -> number, number, number
|
||||||
|
```
|
||||||
|
|
||||||
|
Point setter and getter added by player
|
||||||
|
|
||||||
```python
|
```python
|
||||||
player.get_selected_block(playerid: int) -> x,y,z
|
player.get_selected_block(playerid: int) -> x,y,z
|
||||||
```
|
```
|
||||||
@ -122,6 +129,18 @@ world.set_day_time(time: number)
|
|||||||
|
|
||||||
Set day time value.
|
Set day time value.
|
||||||
|
|
||||||
|
```python
|
||||||
|
world.set_day_time_speed(value: number)
|
||||||
|
```
|
||||||
|
|
||||||
|
Sets the specified speed for game time.
|
||||||
|
|
||||||
|
```python
|
||||||
|
world.get_day_time_speed() -> number
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns the speed for game time.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
world.get_total_time() -> number
|
world.get_total_time() -> number
|
||||||
```
|
```
|
||||||
@ -134,6 +153,18 @@ world.get_seed() -> int
|
|||||||
|
|
||||||
Returns world seed.
|
Returns world seed.
|
||||||
|
|
||||||
|
``` python
|
||||||
|
world.is_day() -> boolean
|
||||||
|
```
|
||||||
|
|
||||||
|
Proves that this is the current time during the day. From 0.2(8 am) to 0.8(8 pm)
|
||||||
|
|
||||||
|
``` python
|
||||||
|
world.is_night() -> bool
|
||||||
|
```
|
||||||
|
|
||||||
|
Checks that it is the current time at night. From 0.8(8 pm) to 0.2(8 am)
|
||||||
|
|
||||||
```python
|
```python
|
||||||
world.exists() -> bool
|
world.exists() -> bool
|
||||||
```
|
```
|
||||||
|
|||||||
@ -87,6 +87,13 @@ player.set_noclip(bool)
|
|||||||
|
|
||||||
Геттер и сеттер noclip режима (выключенная коллизия игрока)
|
Геттер и сеттер noclip режима (выключенная коллизия игрока)
|
||||||
|
|
||||||
|
```python
|
||||||
|
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
|
||||||
|
player.get_spawnpoint(playerid: int) -> number, number, number
|
||||||
|
```
|
||||||
|
|
||||||
|
Сеттер и геттер точки спавна игрока
|
||||||
|
|
||||||
```python
|
```python
|
||||||
player.get_selected_block(playerid: int) -> x,y,z
|
player.get_selected_block(playerid: int) -> x,y,z
|
||||||
```
|
```
|
||||||
@ -116,6 +123,18 @@ world.set_day_time(time: number)
|
|||||||
|
|
||||||
Устанавливает указанное игровое время.
|
Устанавливает указанное игровое время.
|
||||||
|
|
||||||
|
```python
|
||||||
|
world.set_day_time_speed(value: number)
|
||||||
|
```
|
||||||
|
|
||||||
|
Устанавливает указанную скорость для игрового времени.
|
||||||
|
|
||||||
|
```python
|
||||||
|
world.get_day_time_speed() -> number
|
||||||
|
```
|
||||||
|
|
||||||
|
Возвращает скорость для игрового времени.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
world.get_total_time() -> number
|
world.get_total_time() -> number
|
||||||
```
|
```
|
||||||
@ -134,6 +153,18 @@ world.exists() -> bool
|
|||||||
|
|
||||||
Проверяет существование мира по имени.
|
Проверяет существование мира по имени.
|
||||||
|
|
||||||
|
```python
|
||||||
|
world.is_day() -> bool
|
||||||
|
```
|
||||||
|
|
||||||
|
Проверяет является ли текущее время днём. От 0.2(8 утра) до 0.8(8 вечера)
|
||||||
|
|
||||||
|
```python
|
||||||
|
world.is_night() -> bool
|
||||||
|
```
|
||||||
|
|
||||||
|
Проверяет является ли текущее время ночью. От 0.8(8 вечера) до 0.2(8 утра)
|
||||||
|
|
||||||
## Библиотека *pack*
|
## Библиотека *pack*
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|||||||
196
doc/ru/scripting/builtins/libvecn.md
Normal file
196
doc/ru/scripting/builtins/libvecn.md
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
# Библиотека Vec*n*
|
||||||
|
|
||||||
|
*vecn* содержит набор функций для работы с векторами размерностью 2, 3 или 4.
|
||||||
|
Большинство функций имеют несколько вариантов списка аргументов (перегрузок).
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
>
|
||||||
|
> vecn, где n == размерность вектора (2, 3, 4), т.е vec2, vec3, vec4
|
||||||
|
>
|
||||||
|
|
||||||
|
## Типы данных
|
||||||
|
|
||||||
|
На данной странице будут использоваться условные обозначения типов.
|
||||||
|
- vector - массив из двух, трех или четырех чисел
|
||||||
|
- vec2 - массив из двух чисел
|
||||||
|
- vec3 - массив из трех чисел
|
||||||
|
- vec4 - массив из четырех чисел
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
>
|
||||||
|
> Аннотации типов являются частью документации и не указываются при вызове использовании.
|
||||||
|
|
||||||
|
|
||||||
|
## Операции с векторами
|
||||||
|
|
||||||
|
#### Сложение - *vecn.add(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает результат сложения векторов
|
||||||
|
vecn.add(a: vector, b: vector)
|
||||||
|
|
||||||
|
-- возвращает результат сложения вектора и скаляра
|
||||||
|
vecn.add(a: vector, b: number)
|
||||||
|
|
||||||
|
-- записывает результат сложения двух векторов в dst
|
||||||
|
vec.add(a: vector, b: vector, dst: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Вычитание - *vecn.sub(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает результат вычитания векторов
|
||||||
|
vecn.sub(a: vector, b: vector)
|
||||||
|
|
||||||
|
-- возвращает результат вычитания скаляра из вектора
|
||||||
|
vecn.sub(a: vector, b: number)
|
||||||
|
|
||||||
|
-- записывает результат вычитания двух векторов в dst
|
||||||
|
vec.sub(a: vector, b: vector, dst: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Умножение - *vecn.mul(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает результат умножения векторов
|
||||||
|
vecn.mul(a: vector, b: vector)
|
||||||
|
|
||||||
|
-- возвращает результат умножения вектора на скаляр
|
||||||
|
vecn.mul(a: vector, b: number)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Инверсия - *vecn.inv(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает результат инверсии (противоположный) вектора
|
||||||
|
vecn.inverse(a: vector)
|
||||||
|
|
||||||
|
-- записывает инвертированный вектор в dst
|
||||||
|
vec.inverse(v: vector, dst: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Деление - *vecn.div(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает результат деления векторов
|
||||||
|
vecn.div(a: vector, b: vector)
|
||||||
|
|
||||||
|
-- возвращает результат деления вектора на скаляр
|
||||||
|
vecn.div(a: vector, b: number)
|
||||||
|
|
||||||
|
-- записывает результат деления двух векторов в dst
|
||||||
|
vec.div(a: vector, b: vector, dst: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Нормализация - *vecn.norm(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает нормализованный вектор
|
||||||
|
vecn.normalize(a: vector)
|
||||||
|
|
||||||
|
-- записывает нормализованный вектор в dst
|
||||||
|
vec.normalize(v: vector, dst: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Длина вектора - *vecn.len(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает длину вектора
|
||||||
|
vecn.length(a: vector)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Абсолютное значение - *vecn.abs(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает вектор с абсолютными значениями
|
||||||
|
vecn.abs(a: vector)
|
||||||
|
|
||||||
|
-- записывает абсолютное значение вектора в dst
|
||||||
|
vec.abs(v: vector, dst: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Округление - *vecn.round(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает вектор с округленными значениями
|
||||||
|
vecn.round(a: vector)
|
||||||
|
|
||||||
|
-- записывает округленный вектор в dst
|
||||||
|
vec.round(v: vector, dst: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Степень - *vecn.pow(...)*
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- возвращает вектор с элементами, возведенными в степень
|
||||||
|
vecn.pow(a: vector, b: number)
|
||||||
|
|
||||||
|
-- записывает вектор, возведенный в степень, в dst
|
||||||
|
vec.pow(v: vector, exponent: number, dst: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Скалярное произведение - *vecn.dot(...)*
|
||||||
|
```lua
|
||||||
|
-- возвращает скалярное произведение векторов
|
||||||
|
vecn.dot(a: vector, b: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Перевод в строку - *vecn.tostring(...)*
|
||||||
|
> [!WARNING]
|
||||||
|
> Возвращает только тогда, когда содержимым является вектор
|
||||||
|
```lua
|
||||||
|
-- возвращает строку представляющую содержимое вектора
|
||||||
|
vecn.tostring(a: vector)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Пример
|
||||||
|
```lua
|
||||||
|
-- создание векторов разной размерности
|
||||||
|
local v1_3d = {1, 2, 2}
|
||||||
|
local v2_3d = {10, 20, 40}
|
||||||
|
local v3_4d = {1, 2, 4, 1}
|
||||||
|
local v4_2d = {1, 0}
|
||||||
|
local scal = 6 -- обычный скаляр
|
||||||
|
|
||||||
|
-- сложение векторов
|
||||||
|
local result_add = vec3.add(v1_3d, v2_3d)
|
||||||
|
print("add: " .. vec3.tostring(result_add)) -- {11, 22, 42}
|
||||||
|
|
||||||
|
-- вычитание векторов
|
||||||
|
local result_sub = vec3.sub(v2_3d, v1_3d)
|
||||||
|
print("sub: " .. vec3.tostring(result_sub)) -- {9, 18, 38}
|
||||||
|
|
||||||
|
-- умножение векторов
|
||||||
|
local result_mul = vec3.mul(v1_3d, v2_3d)
|
||||||
|
print("mul: " .. vec3.tostring(result_mul)) -- {10, 40, 80}
|
||||||
|
|
||||||
|
-- умножение вектора на скаляр
|
||||||
|
local result_mul_scal = vec3.mul(v1_3d, scal)
|
||||||
|
print("mul_scal: " .. vec3.tostring(result_mul_scal)) -- {6, 12, 12}
|
||||||
|
|
||||||
|
-- нормализация вектора
|
||||||
|
local result_norm = vec3.normalize(v1_3d)
|
||||||
|
print("norm: " .. vec3.tostring(result_norm)) -- {0.333, 0.667, 0.667}
|
||||||
|
|
||||||
|
-- длина вектора
|
||||||
|
local result_len = vec3.length(v1_3d)
|
||||||
|
print("len: " .. result_len) -- 3
|
||||||
|
|
||||||
|
-- абсолютное значение вектора
|
||||||
|
local result_abs = vec3.abs(v1_3d)
|
||||||
|
print("abs: " .. vec3.tostring(result_abs)) -- {1, 2, 2}
|
||||||
|
|
||||||
|
-- округление вектора
|
||||||
|
local result_round = vec3.round(v1_3d)
|
||||||
|
print("round: " .. vec3.tostring(result_round)) -- {1, 2, 2}
|
||||||
|
|
||||||
|
-- степень вектора
|
||||||
|
local result_pow = vec3.pow(v1_3d, 2)
|
||||||
|
print("pow: " .. vec3.tostring(result_pow)) -- {1, 4, 4}
|
||||||
|
|
||||||
|
-- скалярное произведение векторов
|
||||||
|
local result_dot = vec3.dot(v1_3d, v2_3d)
|
||||||
|
print("dot: " .. result_dot) -- 250
|
||||||
|
```
|
||||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1710146030,
|
||||||
|
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1717399147,
|
||||||
|
"narHash": "sha256-eCWaE/q1VItpFAxxLVt171MdtDcjEnwi6QB/yuF73JU=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "4a4ecb0ab415c9fccfb005567a215e6a9564cdf5",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
16
flake.nix
Normal file
16
flake.nix
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system: {
|
||||||
|
devShells.default = with nixpkgs.legacyPackages.${system}; mkShell {
|
||||||
|
nativeBuildInputs = [ cmake pkg-config ];
|
||||||
|
buildInputs = [ glm glfw glew zlib libpng libvorbis openal luajit ]; # libglvnd
|
||||||
|
packages = [ mesa freeglut entt ];
|
||||||
|
LD_LIBRARY_PATH = "${wayland}/lib:$LD_LIBRARY_PATH";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -20,3 +20,6 @@ sand=песок
|
|||||||
stone=камень
|
stone=камень
|
||||||
water=вода
|
water=вода
|
||||||
wood=бревно
|
wood=бревно
|
||||||
|
torch=факел
|
||||||
|
bazalt breaker=крушитель базальта
|
||||||
|
wooden door=деревянная дверь
|
||||||
|
|||||||
@ -26,24 +26,34 @@ console.add_command(
|
|||||||
"help name:str=''",
|
"help name:str=''",
|
||||||
"Show help infomation for the specified command",
|
"Show help infomation for the specified command",
|
||||||
function (args, kwargs)
|
function (args, kwargs)
|
||||||
|
|
||||||
local name = args[1]
|
local name = args[1]
|
||||||
if #name == 0 then
|
if #name == 0 then
|
||||||
|
|
||||||
local commands = console.get_commands_list()
|
local commands = console.get_commands_list()
|
||||||
table.sort(commands)
|
table.sort(commands)
|
||||||
local str = "Available commands:"
|
local str = "Available commands:"
|
||||||
|
|
||||||
for i,k in ipairs(commands) do
|
for i,k in ipairs(commands) do
|
||||||
str = str.."\n "..build_scheme(console.get_command_info(k))
|
str = str.."\n "..build_scheme(console.get_command_info(k))
|
||||||
end
|
end
|
||||||
|
|
||||||
return str.."\nuse 'help <command>'"
|
return str.."\nuse 'help <command>'"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local command = console.get_command_info(name)
|
local command = console.get_command_info(name)
|
||||||
|
|
||||||
if command == nil then
|
if command == nil then
|
||||||
return string.format("command %q not found", name)
|
return string.format("command %q not found", name)
|
||||||
end
|
end
|
||||||
local where = ""
|
|
||||||
|
local where = ":"
|
||||||
local str = SEPARATOR.."\n"..command.description.."\n"..name.." "
|
local str = SEPARATOR.."\n"..command.description.."\n"..name.." "
|
||||||
for i,arg in ipairs(command.args) do
|
|
||||||
|
for _, arg in ipairs(command.args) do
|
||||||
where = where.."\n "..arg.name.." - "..arg.type
|
where = where.."\n "..arg.name.." - "..arg.type
|
||||||
|
|
||||||
if arg.optional then
|
if arg.optional then
|
||||||
str = str.."["..arg.name.."] "
|
str = str.."["..arg.name.."] "
|
||||||
where = where.." (optional)"
|
where = where.." (optional)"
|
||||||
@ -51,11 +61,47 @@ console.add_command(
|
|||||||
str = str.."<"..arg.name.."> "
|
str = str.."<"..arg.name.."> "
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #command.args then
|
|
||||||
|
if #command.args > 0 then
|
||||||
str = str.."\nwhere"..where
|
str = str.."\nwhere"..where
|
||||||
end
|
end
|
||||||
|
|
||||||
return str.."\n"..SEPARATOR
|
return str.."\n"..SEPARATOR
|
||||||
|
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
console.add_command(
|
||||||
|
"time.uptime",
|
||||||
|
"Get time elapsed since the engine started",
|
||||||
|
function()
|
||||||
|
|
||||||
|
local uptime = time.uptime()
|
||||||
|
local years = math.floor(uptime / 31536000)
|
||||||
|
local days = math.floor((uptime % 31536000) / 86400) % 365
|
||||||
|
local hours = math.floor((uptime % 86400) / 3600) % 24
|
||||||
|
local minutes = math.floor((uptime % 3600) / 60) % 60
|
||||||
|
local seconds = math.floor(uptime % 60)
|
||||||
|
|
||||||
|
local formatted_uptime = ""
|
||||||
|
|
||||||
|
if years > 0 then
|
||||||
|
formatted_uptime = formatted_uptime .. years .. "y "
|
||||||
|
end
|
||||||
|
if days > 0 or years > 0 then
|
||||||
|
formatted_uptime = formatted_uptime .. days .. "d "
|
||||||
|
end
|
||||||
|
if hours > 0 or days > 0 or years > 0 then
|
||||||
|
formatted_uptime = formatted_uptime .. hours .. "h "
|
||||||
|
end
|
||||||
|
if minutes > 0 or hours > 0 or days > 0 or years > 0 then
|
||||||
|
formatted_uptime = formatted_uptime .. minutes .. "m "
|
||||||
|
end
|
||||||
|
if seconds > 0 or minutes > 0 or hours > 0 or days > 0 or years > 0 then
|
||||||
|
formatted_uptime = formatted_uptime .. seconds .. "s"
|
||||||
|
end
|
||||||
|
|
||||||
|
return uptime .. " (" .. formatted_uptime .. ")"
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -11,12 +11,17 @@
|
|||||||
#include "../../../window/Events.hpp"
|
#include "../../../window/Events.hpp"
|
||||||
#include "../../../window/Window.hpp"
|
#include "../../../window/Window.hpp"
|
||||||
#include "../../../world/WorldGenerators.hpp"
|
#include "../../../world/WorldGenerators.hpp"
|
||||||
|
#include "../../../constants.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
|
/// @brief Creating new world
|
||||||
|
/// @param name Name world
|
||||||
|
/// @param seed Seed world
|
||||||
|
/// @param generator Type of generation
|
||||||
static int l_new_world(lua::State* L) {
|
static int l_new_world(lua::State* L) {
|
||||||
auto name = lua::require_string(L, 1);
|
auto name = lua::require_string(L, 1);
|
||||||
auto seed = lua::require_string(L, 2);
|
auto seed = lua::require_string(L, 2);
|
||||||
@ -26,6 +31,8 @@ static int l_new_world(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Open world
|
||||||
|
/// @param name Name world
|
||||||
static int l_open_world(lua::State* L) {
|
static int l_open_world(lua::State* L) {
|
||||||
auto name = lua::require_string(L, 1);
|
auto name = lua::require_string(L, 1);
|
||||||
|
|
||||||
@ -34,12 +41,15 @@ static int l_open_world(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Reopen world
|
||||||
static int l_reopen_world(lua::State*) {
|
static int l_reopen_world(lua::State*) {
|
||||||
auto controller = engine->getController();
|
auto controller = engine->getController();
|
||||||
controller->reopenWorld(level->getWorld());
|
controller->reopenWorld(level->getWorld());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Close world
|
||||||
|
/// @param flag Save world (bool)
|
||||||
static int l_close_world(lua::State* L) {
|
static int l_close_world(lua::State* L) {
|
||||||
if (controller == nullptr) {
|
if (controller == nullptr) {
|
||||||
throw std::runtime_error("no world open");
|
throw std::runtime_error("no world open");
|
||||||
@ -55,6 +65,8 @@ static int l_close_world(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Delete world
|
||||||
|
/// @param name Name world
|
||||||
static int l_delete_world(lua::State* L) {
|
static int l_delete_world(lua::State* L) {
|
||||||
auto name = lua::require_string(L, 1);
|
auto name = lua::require_string(L, 1);
|
||||||
auto controller = engine->getController();
|
auto controller = engine->getController();
|
||||||
@ -62,6 +74,9 @@ static int l_delete_world(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Reconfigure packs
|
||||||
|
/// @param addPacks An array of packs to add
|
||||||
|
/// @param remPacks An array of packs to remove
|
||||||
static int l_reconfig_packs(lua::State* L) {
|
static int l_reconfig_packs(lua::State* L) {
|
||||||
if (!lua::istable(L, 1)) {
|
if (!lua::istable(L, 1)) {
|
||||||
throw std::runtime_error("strings array expected as the first argument");
|
throw std::runtime_error("strings array expected as the first argument");
|
||||||
@ -95,12 +110,18 @@ static int l_reconfig_packs(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Get a setting value
|
||||||
|
/// @param name The name of the setting
|
||||||
|
/// @return The value of the setting
|
||||||
static int l_get_setting(lua::State* L) {
|
static int l_get_setting(lua::State* L) {
|
||||||
auto name = lua::require_string(L, 1);
|
auto name = lua::require_string(L, 1);
|
||||||
const auto value = engine->getSettingsHandler().getValue(name);
|
const auto value = engine->getSettingsHandler().getValue(name);
|
||||||
return lua::pushvalue(L, value);
|
return lua::pushvalue(L, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Set a setting value
|
||||||
|
/// @param name The name of the setting
|
||||||
|
/// @param value The new value for the setting
|
||||||
static int l_set_setting(lua::State* L) {
|
static int l_set_setting(lua::State* L) {
|
||||||
auto name = lua::require_string(L, 1);
|
auto name = lua::require_string(L, 1);
|
||||||
const auto value = lua::tovalue(L, 2);
|
const auto value = lua::tovalue(L, 2);
|
||||||
@ -108,12 +129,18 @@ static int l_set_setting(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Convert a setting value to a string
|
||||||
|
/// @param name The name of the setting
|
||||||
|
/// @return The string representation of the setting value
|
||||||
static int l_str_setting(lua::State* L) {
|
static int l_str_setting(lua::State* L) {
|
||||||
auto name = lua::require_string(L, 1);
|
auto name = lua::require_string(L, 1);
|
||||||
const auto string = engine->getSettingsHandler().toString(name);
|
const auto string = engine->getSettingsHandler().toString(name);
|
||||||
return lua::pushstring(L, string);
|
return lua::pushstring(L, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Get information about a setting
|
||||||
|
/// @param name The name of the setting
|
||||||
|
/// @return A table with information about the setting
|
||||||
static int l_get_setting_info(lua::State* L) {
|
static int l_get_setting_info(lua::State* L) {
|
||||||
auto name = lua::require_string(L, 1);
|
auto name = lua::require_string(L, 1);
|
||||||
auto setting = engine->getSettingsHandler().getSetting(name);
|
auto setting = engine->getSettingsHandler().getSetting(name);
|
||||||
@ -136,15 +163,20 @@ static int l_get_setting_info(lua::State* L) {
|
|||||||
throw std::runtime_error("unsupported setting type");
|
throw std::runtime_error("unsupported setting type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Quit the game
|
||||||
static int l_quit(lua::State*) {
|
static int l_quit(lua::State*) {
|
||||||
Window::setShouldClose(true);
|
Window::setShouldClose(true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Get the default world generator
|
||||||
|
/// @return The ID of the default world generator
|
||||||
static int l_get_default_generator(lua::State* L) {
|
static int l_get_default_generator(lua::State* L) {
|
||||||
return lua::pushstring(L, WorldGenerators::getDefaultGeneratorID());
|
return lua::pushstring(L, WorldGenerators::getDefaultGeneratorID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Get a list of all world generators
|
||||||
|
/// @return A table with the IDs of all world generators
|
||||||
static int l_get_generators(lua::State* L) {
|
static int l_get_generators(lua::State* L) {
|
||||||
const auto& generators = WorldGenerators::getGeneratorsIDs();
|
const auto& generators = WorldGenerators::getGeneratorsIDs();
|
||||||
lua::createtable(L, generators.size(), 0);
|
lua::createtable(L, generators.size(), 0);
|
||||||
|
|||||||
@ -138,6 +138,27 @@ static int l_player_get_selected_block(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_player_get_spawnpoint(lua::State* L) {
|
||||||
|
if (auto player = get_player(L, 1)) {
|
||||||
|
return lua::pushvec3(L, player->getSpawnPoint());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int l_player_set_spawnpoint(lua::State* L) {
|
||||||
|
auto player = get_player(L, 1);
|
||||||
|
|
||||||
|
if (player) {
|
||||||
|
auto x = lua::tonumber(L, 2);
|
||||||
|
auto y = lua::tonumber(L, 3);
|
||||||
|
auto z = lua::tonumber(L, 4);
|
||||||
|
player->setSpawnPoint(glm::vec3(x, y, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg playerlib [] = {
|
const luaL_Reg playerlib [] = {
|
||||||
{"get_pos", lua::wrap<l_player_get_pos>},
|
{"get_pos", lua::wrap<l_player_get_pos>},
|
||||||
{"set_pos", lua::wrap<l_player_set_pos>},
|
{"set_pos", lua::wrap<l_player_set_pos>},
|
||||||
@ -152,5 +173,7 @@ const luaL_Reg playerlib [] = {
|
|||||||
{"is_noclip", lua::wrap<l_player_is_noclip>},
|
{"is_noclip", lua::wrap<l_player_is_noclip>},
|
||||||
{"set_noclip", lua::wrap<l_player_set_noclip>},
|
{"set_noclip", lua::wrap<l_player_set_noclip>},
|
||||||
{"get_selected_block", lua::wrap<l_player_get_selected_block>},
|
{"get_selected_block", lua::wrap<l_player_get_selected_block>},
|
||||||
|
{"set_spawnpoint", lua::wrap<l_player_set_spawnpoint>},
|
||||||
|
{"get_spawnpoint", lua::wrap<l_player_get_spawnpoint>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -69,6 +69,72 @@ static int l_scalar_op(lua::State* L) {
|
|||||||
return lua::pushnumber(L, func(vec));
|
return lua::pushnumber(L, func(vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<int n>
|
||||||
|
static int l_pow(lua::State* L) {
|
||||||
|
uint argc = lua::gettop(L);
|
||||||
|
if (argc != 2 && argc != 3) {
|
||||||
|
throw std::runtime_error("invalid arguments number (2 or 3 expected)");
|
||||||
|
}
|
||||||
|
auto a = lua::tovec<n>(L, 1);
|
||||||
|
|
||||||
|
if (lua::isnumber(L, 2)) {
|
||||||
|
auto b = lua::tonumber(L, 2);
|
||||||
|
if (argc == 2) {
|
||||||
|
lua::createtable(L, n, 0);
|
||||||
|
for (uint i = 0; i < n; i++) {
|
||||||
|
lua::pushnumber(L, pow(a[i], b));
|
||||||
|
lua::rawseti(L, i+1);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return lua::setvec(L, 3, pow(a, glm::vec<n, float>(b)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auto b = lua::tovec<n>(L, 2);
|
||||||
|
if (argc == 2) {
|
||||||
|
lua::createtable(L, n, 0);
|
||||||
|
for (uint i = 0; i < n; i++) {
|
||||||
|
lua::pushnumber(L, pow(a[i], b[i]));
|
||||||
|
lua::rawseti(L, i+1);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return lua::setvec(L, 3, pow(a, b));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int n>
|
||||||
|
static int l_dot(lua::State* L) {
|
||||||
|
uint argc = lua::gettop(L);
|
||||||
|
if (argc != 1) {
|
||||||
|
throw std::runtime_error("invalid arguments number (1 expected)");
|
||||||
|
}
|
||||||
|
const auto& a = lua::tovec<n>(L, 1);
|
||||||
|
const auto& b = lua::tovec<n>(L, 2);
|
||||||
|
return lua::pushnumber(L, glm::dot(a, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int n>
|
||||||
|
static int l_inverse(lua::State* L) {
|
||||||
|
uint argc = lua::gettop(L);
|
||||||
|
auto vec = lua::tovec<n>(L, 1);
|
||||||
|
switch (argc) {
|
||||||
|
case 1:
|
||||||
|
lua::createtable(L, n, 0);
|
||||||
|
for (uint i = 0; i < n; i++) {
|
||||||
|
lua::pushnumber(L, (-1)*vec[i]);
|
||||||
|
lua::rawseti(L, i+1);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
case 2:
|
||||||
|
return lua::setvec(L, 2, -vec);
|
||||||
|
default: {
|
||||||
|
throw std::runtime_error("invalid arguments number (1 or 2 expected)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<int n>
|
template<int n>
|
||||||
static int l_tostring(lua::State* L) {
|
static int l_tostring(lua::State* L) {
|
||||||
auto vec = lua::tovec<n>(L, 1);
|
auto vec = lua::tovec<n>(L, 1);
|
||||||
@ -95,6 +161,11 @@ const luaL_Reg vec2lib [] = {
|
|||||||
{"normalize", lua::wrap<l_unaryop<2, glm::normalize>>},
|
{"normalize", lua::wrap<l_unaryop<2, glm::normalize>>},
|
||||||
{"length", lua::wrap<l_scalar_op<2, glm::length>>},
|
{"length", lua::wrap<l_scalar_op<2, glm::length>>},
|
||||||
{"tostring", lua::wrap<l_tostring<2>>},
|
{"tostring", lua::wrap<l_tostring<2>>},
|
||||||
|
{"abs", lua::wrap<l_unaryop<2, glm::abs>>},
|
||||||
|
{"round", lua::wrap<l_unaryop<2, glm::round>>},
|
||||||
|
{"inverse", lua::wrap<l_inverse<2>>},
|
||||||
|
{"pow", lua::wrap<l_pow<2>>},
|
||||||
|
{"dot", lua::wrap<l_dot<2>>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -106,6 +177,11 @@ const luaL_Reg vec3lib [] = {
|
|||||||
{"normalize", lua::wrap<l_unaryop<3, glm::normalize>>},
|
{"normalize", lua::wrap<l_unaryop<3, glm::normalize>>},
|
||||||
{"length", lua::wrap<l_scalar_op<3, glm::length>>},
|
{"length", lua::wrap<l_scalar_op<3, glm::length>>},
|
||||||
{"tostring", lua::wrap<l_tostring<3>>},
|
{"tostring", lua::wrap<l_tostring<3>>},
|
||||||
|
{"abs", lua::wrap<l_unaryop<3, glm::abs>>},
|
||||||
|
{"round", lua::wrap<l_unaryop<3, glm::round>>},
|
||||||
|
{"inverse", lua::wrap<l_inverse<3>>},
|
||||||
|
{"pow", lua::wrap<l_pow<3>>},
|
||||||
|
{"dot", lua::wrap<l_dot<3>>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -117,5 +193,10 @@ const luaL_Reg vec4lib [] = {
|
|||||||
{"normalize", lua::wrap<l_unaryop<4, glm::normalize>>},
|
{"normalize", lua::wrap<l_unaryop<4, glm::normalize>>},
|
||||||
{"length", lua::wrap<l_scalar_op<4, glm::length>>},
|
{"length", lua::wrap<l_scalar_op<4, glm::length>>},
|
||||||
{"tostring", lua::wrap<l_tostring<4>>},
|
{"tostring", lua::wrap<l_tostring<4>>},
|
||||||
|
{"abs", lua::wrap<l_unaryop<4, glm::abs>>},
|
||||||
|
{"round", lua::wrap<l_unaryop<4, glm::round>>},
|
||||||
|
{"inverse", lua::wrap<l_inverse<4>>},
|
||||||
|
{"pow", lua::wrap<l_pow<4>>},
|
||||||
|
{"dot", lua::wrap<l_dot<4>>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
@ -54,6 +54,16 @@ static int l_world_set_day_time(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_world_set_day_time_speed(lua::State* L) {
|
||||||
|
auto value = lua::tonumber(L, 1);
|
||||||
|
level->getWorld()->daytimeSpeed = std::abs(value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_world_get_day_time_speed(lua::State* L) {
|
||||||
|
return lua::pushnumber(L, level->getWorld()->daytimeSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
static int l_world_get_seed(lua::State* L) {
|
static int l_world_get_seed(lua::State* L) {
|
||||||
return lua::pushinteger(L, level->getWorld()->getSeed());
|
return lua::pushinteger(L, level->getWorld()->getSeed());
|
||||||
}
|
}
|
||||||
@ -64,12 +74,26 @@ static int l_world_exists(lua::State* L) {
|
|||||||
return lua::pushboolean(L, fs::is_directory(worldsDir));
|
return lua::pushboolean(L, fs::is_directory(worldsDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_world_is_day(lua::State* L) {
|
||||||
|
auto daytime = level->getWorld()->daytime;
|
||||||
|
return lua::pushboolean(L, daytime >= 0.2 && daytime <= 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_world_is_night(lua::State* L) {
|
||||||
|
auto daytime = level->getWorld()->daytime;
|
||||||
|
return lua::pushboolean(L, daytime < 0.2 || daytime > 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg worldlib [] = {
|
const luaL_Reg worldlib [] = {
|
||||||
{"get_list", lua::wrap<l_world_get_list>},
|
{"get_list", lua::wrap<l_world_get_list>},
|
||||||
{"get_total_time", lua::wrap<l_world_get_total_time>},
|
{"get_total_time", lua::wrap<l_world_get_total_time>},
|
||||||
{"get_day_time", lua::wrap<l_world_get_day_time>},
|
{"get_day_time", lua::wrap<l_world_get_day_time>},
|
||||||
{"set_day_time", lua::wrap<l_world_set_day_time>},
|
{"set_day_time", lua::wrap<l_world_set_day_time>},
|
||||||
|
{"set_day_time_speed", lua::wrap<l_world_set_day_time_speed>},
|
||||||
|
{"get_day_time_speed", lua::wrap<l_world_get_day_time_speed>},
|
||||||
{"get_seed", lua::wrap<l_world_get_seed>},
|
{"get_seed", lua::wrap<l_world_get_seed>},
|
||||||
|
{"is_day", lua::wrap<l_world_is_day>},
|
||||||
|
{"is_night", lua::wrap<l_world_is_night>},
|
||||||
{"exists", lua::wrap<l_world_exists>},
|
{"exists", lua::wrap<l_world_exists>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
static debug::Logger logger("world");
|
static debug::Logger logger("world");
|
||||||
|
const float DAYIME_SPECIFIC_SPEED = 1.0f/1440.0f; //1.0f/60.0f/24.0f;
|
||||||
|
|
||||||
world_load_error::world_load_error(const std::string& message)
|
world_load_error::world_load_error(const std::string& message)
|
||||||
: std::runtime_error(message) {
|
: std::runtime_error(message) {
|
||||||
@ -46,7 +47,7 @@ World::~World(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void World::updateTimers(float delta) {
|
void World::updateTimers(float delta) {
|
||||||
daytime += delta * daytimeSpeed;
|
daytime += delta * daytimeSpeed * DAYIME_SPECIFIC_SPEED;
|
||||||
daytime = fmod(daytime, 1.0f);
|
daytime = fmod(daytime, 1.0f);
|
||||||
totalTime += delta;
|
totalTime += delta;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public:
|
|||||||
float daytime = timeutil::time_value(10, 00, 00);
|
float daytime = timeutil::time_value(10, 00, 00);
|
||||||
|
|
||||||
// looking bad
|
// looking bad
|
||||||
float daytimeSpeed = 1.0f/60.0f/24.0f;
|
float daytimeSpeed = 1.0f;
|
||||||
|
|
||||||
/// @brief total time passed in the world (not depending on daytimeSpeed)
|
/// @brief total time passed in the world (not depending on daytimeSpeed)
|
||||||
double totalTime = 0.0;
|
double totalTime = 0.0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user