Merge branch 'main' into framerate-control

This commit is contained in:
MihailRis
2024-07-28 22:20:25 +03:00
31 changed files with 569 additions and 326 deletions
+4
View File
@@ -71,6 +71,10 @@ Vertical sky light ray ignores block if **true**. (used for water)
Turns off block model shading Turns off block model shading
### *ambient-occlusion* (Vertex-based Ambient-Occlusion)
Determines the presence of the vertex AO effect. Turned-on by default.
## Physics ## Physics
### *obstacle* ### *obstacle*
+31 -102
View File
@@ -13,6 +13,7 @@ Subsections:
- [entities](scripting/builtins/libentities.md) - [entities](scripting/builtins/libentities.md)
- [cameras](scripting/builtins/libcameras.md) - [cameras](scripting/builtins/libcameras.md)
- [mat4](scripting/builtins/libmat4.md) - [mat4](scripting/builtins/libmat4.md)
- [player](scripting/builtins/libplayer.md)
- [quat](scripting/builtins/libquat.md) - [quat](scripting/builtins/libquat.md)
- [vec2, vec3, vec4](scripting/builtins/libvecn.md) - [vec2, vec3, vec4](scripting/builtins/libvecn.md)
- [Module core:bit_converter](scripting/modules/core_bit_converter.md) - [Module core:bit_converter](scripting/modules/core_bit_converter.md)
@@ -62,76 +63,55 @@ file.write(pack.data_file(PACK_ID, "example.txt"), text)
For pack *containermod* will write text to the file `world:data/containermod/example.txt` For pack *containermod* will write text to the file `world:data/containermod/example.txt`
## *player* library ```python
pack.get_folder(packid: str) -> str
```
Returns installed content-pack folder.
```python ```python
player.get_pos(playerid: int) -> number, number, number pack.is_installed(packid: str) -> bool
``` ```
Returns x, y, z coordinates of the player Check if the world has specified pack installed.
```python ```python
player.set_pos(playerid: int, x: number, y: number, z: number) pack.get_installed() -> strings array
``` ```
Set player position Returns all installed content-pack ids.
```python ```python
player.get_rot(playerid: int) -> number, number, number pack.get_available() -> strings array
``` ```
Returns x, y, z of camera rotation (radians) Returns the ids of all content packs available but not installed in the world.
```python ```python
player.set_rot(playerid: int, x: number, y: number, z: number) pack.get_base_packs() -> strings array
``` ```
Set camera rotation (radians) Returns the id of all base packages (non-removeable)
```python ```python
player.get_inventory(playerid: int) -> int, int pack.get_info(packid: str) -> {
id: str,
title: str,
creator: str,
description: str,
version: str,
icon: str,
dependencies: optional strings array
}
``` ```
Returns player inventory ID and selected slot index (0-9) Returns information about the pack (not necessarily installed).
- icon - name of the preview texture (loading automatically)
```python - dependencies - strings following format `{lvl}{id}`, where lvl:
player.is_flight() -> bool - `!` - required
player.set_flight(bool) - `?` - optional
``` - `~` - weak
for example `!teal`
Getter and setter for player flight mode
```python
player.is_noclip() -> bool
player.set_noclip(bool)
```
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
player.get_selected_block(playerid: int) -> x,y,z
```
Returns position of the selected block or nil
```python
player.get_selected_entity(playerid: int) -> int
```
Returns unique indentifier of the entity selected by player
```python
player.get_entity(playerid: int) -> int
```
Returns unique identifier of the player entity
## *world* library ## *world* library
@@ -200,57 +180,6 @@ world.exists() -> bool
Checks the existence of a world by name. Checks the existence of a world by name.
## *pack* library
```python
pack.get_folder(packid: str) -> str
```
Returns installed content-pack folder.
```python
pack.is_installed(packid: str) -> bool
```
Check if the world has specified pack installed.
```python
pack.get_installed() -> strings array
```
Returns all installed content-pack ids.
```python
pack.get_available() -> strings array
```
Returns the ids of all content packs available but not installed in the world.
```python
pack.get_base_packs() -> strings array
```
Returns the id of all base packages (non-removeable)
```python
pack.get_info(packid: str) -> {
id: str,
title: str,
creator: str,
description: str,
version: str,
icon: str,
dependencies: optional strings array
}
```
Returns information about the pack (not necessarily installed).
- icon - name of the preview texture (loading automatically)
- dependencies - strings following format `{lvl}{id}`, where lvl:
- `!` - required
- `?` - optional
- `~` - weak
for example `!teal`
## *gui* library ## *gui* library
@@ -282,7 +211,7 @@ gui.get_env(document: str) -> table
Returns environment (global variables table) of the specified document. Returns environment (global variables table) of the specified document.
```python ```python
get_locales_info() -> table of tables where gui.get_locales_info() -> table of tables where
key - locale id following isolangcode_ISOCOUNTRYCODE format key - locale id following isolangcode_ISOCOUNTRYCODE format
value - table { value - table {
name: str # name of the locale in its language name: str # name of the locale in its language
+7
View File
@@ -14,6 +14,7 @@ block.material(blockid: int) -> str
block.caption(blockid: int) -> str block.caption(blockid: int) -> str
-- Returns integer ID by block position -- Returns integer ID by block position
-- If the chunk at the specified coordinates is not loaded, returns -1.
block.get(x: int, y: int, z: int) -> int block.get(x: int, y: int, z: int) -> int
-- Returns block state (rotation + additional information) as an integer. -- Returns block state (rotation + additional information) as an integer.
@@ -31,6 +32,12 @@ block.place(x: int, y: int, z: int, id: int, states: int, [optional] playerid: i
-- Breaks a block at the given coordinates on behalf of the player, triggering the on_broken event. -- Breaks a block at the given coordinates on behalf of the player, triggering the on_broken event.
-- playerid is optional -- playerid is optional
block.destruct(x: int, y: int, z: int, playerid: int) block.destruct(x: int, y: int, z: int, playerid: int)
-- Compose the complete state as an integer
block.compose_state(rotation: int, segment: int, userbits: int) -> int
-- Decompose the complete state into: rotation, segment, user bits
block.decompose_state(state: int) -> int, int, int
``` ```
> [!WARNING] > [!WARNING]
+70
View File
@@ -0,0 +1,70 @@
# *player* library
```python
player.get_pos(playerid: int) -> number, number, number
```
Returns x, y, z coordinates of the player
```python
player.set_pos(playerid: int, x: number, y: number, z: number)
```
Set player position
```python
player.get_rot(playerid: int) -> number, number, number
```
Returns x, y, z of camera rotation (radians)
```python
player.set_rot(playerid: int, x: number, y: number, z: number)
```
Set camera rotation (radians)
```python
player.get_inventory(playerid: int) -> int, int
```
Returns player inventory ID and selected slot index (0-9)
```python
player.is_flight() -> bool
player.set_flight(bool)
```
Getter and setter for player flight mode
```python
player.is_noclip() -> bool
player.set_noclip(bool)
```
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
player.get_selected_block(playerid: int) -> x,y,z
```
Returns position of the selected block or nil
```python
player.get_selected_entity(playerid: int) -> int
```
Returns unique indentifier of the entity selected by player
```python
player.get_entity(playerid: int) -> int
```
Returns unique identifier of the player entity
+93 -44
View File
@@ -6,71 +6,120 @@ See also [ui elements in scripting](scripting/ui.md).
**2D vector** - pair of numbers separated with comma. **2D vector** - pair of numbers separated with comma.
Examples: Examples:
- "500,200" - `"500,200"`
- "0.4,53.01" - `"0.4,53.01"`
- "0,0" - `"0,0"`
**3D vector** - three numbers separated with comma. **3D vector** - three numbers separated with comma.
Examples: Examples:
- "60,30,53" - `"60,30,53"`
- "0.4,0.1,0.753" - `"0.4,0.1,0.753"`
**4D vector** - four numbers separated with comma. **4D vector** - four numbers separated with comma.
- "10,5,10,3" Examples:
- "0.1,0.5,0.0,0.0" - `"10,5,10,3"`
- `"0.1,0.5,0.0,0.0"`
**RGBA color** - only HEX notation available **RGBA color** - only HEX notation available
Examples: Examples:
- "#FF8000" - opaque orange - `"#FF8000"` - opaque orange
- "#FFFFFF80" - semi-transparent white - `"#FFFFFF80"` - semi-transparent white
- "#000000FF" - opaque black - `"#000000FF"` - opaque black
# Common element attributes # Common element attributes
- **id** - element identifier. Type: string. - `id` - element identifier. Type: string.
- **pos** - element position. Type: 2D vector. - `pos` - element position. Type: 2D vector.
- **size** - element size. Type: 2D vector. - `size` - element size. Type: 2D vector.
- **color** - element color. Type: RGBA color. - `color` - element color. Type: RGBA color.
- **margin** - element margin. Type: 4D vector - `margin` - element margin. Type: 4D vector
*left, top, right, bottom* *left, top, right, bottom*
- **visible** - element visibility. Type: boolean (true/false) - `visible` - element visibility. Type: boolean (true/false)
- **position-func** - position supplier for an element (two numbers), called on every parent container size update or on element adding on a container. May be called before *on_hud_open* - `position-func` - position supplier for an element (two numbers), called on every parent container size update or on element adding on a container. May be called before *on_hud_open*
- `size-func` - element size provider (two numbers), called when the size of the container in which the element is located changes, or when an element is added to the container. Can be called before on_hud_open is called.
- `onclick` - lua function called when an element is clicked.
- `ondoubleclick` - lua function called when you double click on an element.
- `tooltip` - tooltip text
- `tooltip-delay` - tooltip show-up delay
- `gravity` - automatic positioning of the element in the container. (Does not work in automatic containers like panel). Values: *top-left, top-center, top-right, center-left, center-center, center-right, bottom-left, bottom-center, bottom-right*.
- `z-index` - determines the order of elements, with a larger value it will overlap elements with a smaller one.
- `interactive` - if false, hovering over the element and all sub-elements will be ignored.
# Template attributes
- `if` with values ('', 'false', 'nil') the element will be ignored, including sub-elements.
- `ifnot` is the same as `if`, but with the opposite condition.
# Common *container* attributes # Common *container* attributes
Buttons and panels are also containers. Buttons and panels are also containers.
- **padding** - element padding. Type: 4D vector. - `padding` - element padding. Type: 4D vector.
*left, top, right, bottom* *left, top, right, bottom*
**scrollable** - element scrollability. Works on panels only. Type: boolean `scrollable` - element scrollability. Works on panels only. Type: boolean
# Common *panel* attributes # Common *panel* attributes
Buttons are also panels. Buttons are also panels.
- **max-length** - maximal length of panel stretching before scrolling (if scrollable = true). Type: number - `max-length` - maximal length of panel stretching before scrolling (if scrollable = true). Type: number
- `orientation` - panel orientation: horizontal/vertical.
# Common elements # Common elements
## *button* ## *button*
Inner text is a button text. Inner text is a button text.
- **text-align** - inner text alignment (*left/center/right*). Type: string. - `text-align` - inner text alignment (*left/center/right*). Type: string.
- **onclick** - Lua function called on button press.
## *checkbox*
- `checked` - defines the checked state.
- `supplier` - mark state supplier (called every frame).
- `consumer` - lua function-consumer of the state of the mark.
## *label*
- `valign` - vertical text alignment: top/center/bottom.
- `supplier` - text supplier (called every frame).
- `autoresize` - automatic change of element size (default - false). Does not affect font size.
- `multiline` - allows display of multiline text.
- `text-wrap` - allows automatic text wrapping (works only with multiline: "true").
## *image* ## *image*
- **src** - name of an image stored in textures folder. Extension is not specified. Type: string. - `src` - name of an image stored in textures folder. Extension is not specified. Type: string.
Example: *gui/error* Example: *gui/error*
## *textbox*
Inner text - initially entered text
- `placeholder` - placeholder text (used if the text field is empty)
- `supplier` - text supplier (called every frame)
- `consumer` - lua function that receives the entered text. Called only when input is complete
- `autoresize` - automatic change of element size (default - false). Does not affect font size.
- `multiline` - allows display of multiline text.
- `text-wrap` - allows automatic text wrapping (works only with multiline: "true")
- `editable` - determines whether the text can be edited.
- `error-color` - color when entering incorrect data (the text does not pass the validator check). Type: RGBA color.
- `validator` - lua function that checks text for correctness. Takes a string as input, returns true if the text is correct.
- `onup` - lua function called when the up arrow is pressed.
- `ondown` - lua function called when the down arrow is pressed.
## *trackbar* ## *trackbar*
- **min** - minimal value. Type: number. Default: 0 - `min` - minimal value. Type: number. Default: 0
- **max** - maximal value. Type: number. Default: 1 - `max` - maximal value. Type: number. Default: 1
- **value** - initial value. Type: number. Default: 0 - `value` - initial value. Type: number. Default: 0
- **step** - track step size. Type: number: Default: 1 - `step` - track step size. Type: number: Default: 1
- **track-width** track pointer width (in steps). Type: number. Default: 1 - `track-width` track pointer width (in steps). Type: number. Default: 1
- **consumer** - Lua function - new value consumer - `track-color` - the color of the pointer when hovering over the cursor. Type: RGBA color.
- **supplier** - Lua function - value supplier - `consumer` - Lua function - new value consumer
- `sub-consumer` - Lua function that receives intermediate values (use to update text when `change-on-release="true"`)
- `supplier` - Lua function - value supplier
- `change-on-release` - Call consumer on trackbar release only. Type: boolean. Default: false
# Inventory elements # Inventory elements
@@ -84,21 +133,21 @@ Element is a container. Does not have specific attributes.
## *slot* ## *slot*
Element must be in direct sub-element of *inventory*. Element must be in direct sub-element of *inventory*.
- **index** - inventory slot index (starting from 0). Type: integer - `index` - inventory slot index (starting from 0). Type: integer
- **item-source** - content access panel behaviour (infinite source of an item). Type: boolean - `item-source` - content access panel behaviour (infinite source of an item). Type: boolean
- **sharefunc** - Lua event called on <btn>LMB</btn> + <btn>Shift</btn>. Inventory id and slot index passed as arguments. - `sharefunc` - Lua event called on <btn>LMB</btn> + <btn>Shift</btn>. Inventory id and slot index passed as arguments.
- **updatefunc** - Lua event called on slot content update.Inventory id and slot index passed as arguments. - `updatefunc` - Lua event called on slot content update.Inventory id and slot index passed as arguments.
- **onrightclick** - Lua event called on <btn>RMB</btn> click. Inventory id and slot index passed as arguments. - `onrightclick` - Lua event called on <btn>RMB</btn> click. Inventory id and slot index passed as arguments.
## *slots-grid* ## *slots-grid*
- **start-index** - inventory slot index of the first slot. Type: integer - `start-index` - inventory slot index of the first slot. Type: integer
- **rows** - number of grid rows (unnecessary if *cols* and *count* specified). Type: integer - `rows` - number of grid rows (unnecessary if *cols* and *count* specified). Type: integer
- **cols** - number of grid columns (unnecessary if *rows* and *count* specified). Type: integer - `cols` - number of grid columns (unnecessary if *rows* and *count* specified). Type: integer
- **count** - total number of slots in grid (unnecessary if *rows* and *cols* specified). Type: integer - `count` - total number of slots in grid (unnecessary if *rows* and *cols* specified). Type: integer
- **interval** - visual slots interval. Type: number - `interval` - visual slots interval. Type: number
- **padding** - grid padding (not slots interval). Type: number. (*deprecated*) - `padding` - grid padding (not slots interval). Type: number. (*deprecated*)
- **sharefunc** - Lua event called on <btn>LMB</btn> + <btn>Shift</btn>. Inventory id and slot index passed as arguments. - `sharefunc` - Lua event called on <btn>LMB</btn> + <btn>Shift</btn>. Inventory id and slot index passed as arguments.
- **updatefunc** - Lua event called on slot content update.Inventory id and slot index passed as arguments. - `updatefunc` - Lua event called on slot content update.Inventory id and slot index passed as arguments.
- **onrightclick** - Lua event called on <btn>RMB</btn> click. Inventory id and slot index passed as arguments. - `onrightclick` - Lua event called on <btn>RMB</btn> click. Inventory id and slot index passed as arguments.
+4
View File
@@ -74,6 +74,10 @@
Выключает освещение на модели блока. Выключает освещение на модели блока.
### Вершинный Ambient-Occlusion - *ambient-occlusion*
Определяет наличие эффекта вершинного AO. Включен по-умолчанию.
## Физика ## Физика
### Препятствие - *obstacle* ### Препятствие - *obstacle*
+27 -99
View File
@@ -13,6 +13,7 @@
- [entities](scripting/builtins/libentities.md) - [entities](scripting/builtins/libentities.md)
- [cameras](scripting/builtins/libcameras.md) - [cameras](scripting/builtins/libcameras.md)
- [mat4](scripting/builtins/libmat4.md) - [mat4](scripting/builtins/libmat4.md)
- [player](scripting/builtins/libplayer.md)
- [quat](scripting/builtins/libquat.md) - [quat](scripting/builtins/libquat.md)
- [vec2, vec3, vec4](scripting/builtins/libvecn.md) - [vec2, vec3, vec4](scripting/builtins/libvecn.md)
- [Модуль core:bit_converter](scripting/modules/core_bit_converter.md) - [Модуль core:bit_converter](scripting/modules/core_bit_converter.md)
@@ -58,76 +59,55 @@ file.write(pack.data_file(PACK_ID, "example.txt"), text)
``` ```
Для пака *containermod* запишет текст в файл `world:data/containermod/example.txt` Для пака *containermod* запишет текст в файл `world:data/containermod/example.txt`
## Библиотека *player*
```python ```python
player.get_pos(playerid: int) -> number, number, number pack.get_folder(packid: str) -> str
``` ```
Возвращает x, y, z координаты игрока Возвращает путь к папке установленного контент-пака.
```python ```python
player.set_pos(playerid: int, x: number, y: number, z: number) pack.is_installed(packid: str) -> bool
``` ```
Устанавливает x, y, z координаты игрока Проверяет наличие контент-пака в мире
```python ```python
player.get_rot(playerid: int) -> number, number, number pack.get_installed() -> массив строк
``` ```
Возвращает x, y, z вращения камеры (в радианах) Возращает id всех установленных в мире контент-паков.
```python ```python
player.set_rot(playerid: int, x: number, y: number, z: number) pack.get_available() -> массив строк
``` ```
Устанавливает x, y вращения камеры (в радианах) Возвращает id всех доступных, но не установленных в мире контент-паков.
```python ```python
player.get_inventory(playerid: int) -> int, int pack.get_base_packs() -> массив строк
``` ```
Возвращает id инвентаря игрока и индекс выбранного слота (от 0 до 9) Возвращает id всех базовых паков (неудаляемых)
```python ```python
player.is_flight() -> bool pack.get_info(packid: str) -> {
player.set_flight(bool) id: str,
title: str,
creator: str,
description: str,
version: str,
icon: str,
dependencies: опциональный массив строк
}
``` ```
Геттер и сеттер режима полета Возвращает информацию о паке (не обязательно установленном).
- icon - название текстуры предпросмотра (загружается автоматически)
```python - dependencies - строки в формате `{lvl}{id}`, где lvl:
player.is_noclip() -> bool - `!` - required
player.set_noclip(bool) - `?` - optional
``` - `~` - weak
например `!teal`
Геттер и сеттер noclip режима (выключенная коллизия игрока)
```python
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
player.get_spawnpoint(playerid: int) -> number, number, number
```
Сеттер и геттер точки спавна игрока
```python
player.get_selected_block(playerid: int) -> x,y,z
```
Возвращает координаты выделенного блока, либо nil
```python
player.get_selected_entity(playerid: int) -> int
```
Возвращает уникальный идентификатор сущности, на которую нацелен игрок
```python
player.get_entity(playerid: int) -> int
```
Возвращает уникальный идентификатор сущности игрока
## Библиотека *world* ## Библиотека *world*
@@ -194,58 +174,6 @@ world.is_night() -> bool
Проверяет является ли текущее время ночью. От 0.8(8 вечера) до 0.2(8 утра) Проверяет является ли текущее время ночью. От 0.8(8 вечера) до 0.2(8 утра)
## Библиотека *pack*
```python
pack.get_folder(packid: str) -> str
```
Возвращает путь к папке установленного контент-пака.
```python
pack.is_installed(packid: str) -> bool
```
Проверяет наличие контент-пака в мире
```python
pack.get_installed() -> массив строк
```
Возращает id всех установленных в мире контент-паков.
```python
pack.get_available() -> массив строк
```
Возвращает id всех доступных, но не установленных в мире контент-паков.
```python
pack.get_base_packs() -> массив строк
```
Возвращает id всех базовых паков (неудаляемых)
```python
pack.get_info(packid: str) -> {
id: str,
title: str,
creator: str,
description: str,
version: str,
icon: str,
dependencies: опциональный массив строк
}
```
Возвращает информацию о паке (не обязательно установленном).
- icon - название текстуры предпросмотра (загружается автоматически)
- dependencies - строки в формате `{lvl}{id}`, где lvl:
- `!` - required
- `?` - optional
- `~` - weak
например `!teal`
## Библиотека *gui* ## Библиотека *gui*
Библиотека содержит функции для доступа к свойствам UI элементов. Вместо gui следует использовать объектную обертку, предоставляющую доступ к свойствам через мета-методы __index, __newindex: Библиотека содержит функции для доступа к свойствам UI элементов. Вместо gui следует использовать объектную обертку, предоставляющую доступ к свойствам через мета-методы __index, __newindex:
+7 -1
View File
@@ -17,7 +17,7 @@ block.caption(blockid: int) -> str
-- Если чанк на указанных координатах не загружен, возвращает -1. -- Если чанк на указанных координатах не загружен, возвращает -1.
block.get(x: int, y: int, z: int) -> int block.get(x: int, y: int, z: int) -> int
-- Возвращает состояние (поворот + доп. информация) в виде целого числа -- Возвращает полное состояние (поворот + сегмент + доп. информация) в виде целого числа
block.get_states(x: int, y: int, z: int) -> int block.get_states(x: int, y: int, z: int) -> int
-- Устанавливает блок с заданным числовым id и состоянием (0 - по-умолчанию) на заданных координатах. -- Устанавливает блок с заданным числовым id и состоянием (0 - по-умолчанию) на заданных координатах.
@@ -31,6 +31,12 @@ block.place(x: int, y: int, z: int, id: int, states: int, [optional] playerid: i
-- Ломает блок на заданных координатах от лица игрока, вызывая событие on_broken. -- Ломает блок на заданных координатах от лица игрока, вызывая событие on_broken.
-- playerid не является обязательным -- playerid не является обязательным
block.destruct(x: int, y: int, z: int, playerid: int) block.destruct(x: int, y: int, z: int, playerid: int)
-- Собирает полное состояние в виде целого числа
block.compose_state(rotation: int, segment: int, userbits: int) -> int
-- Разбирает полное состояние на: вращение, сегмент, пользовательские биты
block.decompose_state(state: int) -> int, int, int
``` ```
> [!WARNING] > [!WARNING]
+70
View File
@@ -0,0 +1,70 @@
# Библиотека *player*
```python
player.get_pos(playerid: int) -> number, number, number
```
Возвращает x, y, z координаты игрока
```python
player.set_pos(playerid: int, x: number, y: number, z: number)
```
Устанавливает x, y, z координаты игрока
```python
player.get_rot(playerid: int) -> number, number, number
```
Возвращает x, y, z вращения камеры (в радианах)
```python
player.set_rot(playerid: int, x: number, y: number, z: number)
```
Устанавливает x, y вращения камеры (в радианах)
```python
player.get_inventory(playerid: int) -> int, int
```
Возвращает id инвентаря игрока и индекс выбранного слота (от 0 до 9)
```python
player.is_flight() -> bool
player.set_flight(bool)
```
Геттер и сеттер режима полета
```python
player.is_noclip() -> bool
player.set_noclip(bool)
```
Геттер и сеттер noclip режима (выключенная коллизия игрока)
```python
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
player.get_spawnpoint(playerid: int) -> number, number, number
```
Сеттер и геттер точки спавна игрока
```python
player.get_selected_block(playerid: int) -> x,y,z
```
Возвращает координаты выделенного блока, либо nil
```python
player.get_selected_entity(playerid: int) -> int
```
Возвращает уникальный идентификатор сущности, на которую нацелен игрок
```python
player.get_entity(playerid: int) -> int
```
Возвращает уникальный идентификатор сущности игрока
+6 -2
View File
@@ -79,7 +79,8 @@
- `checked` - определяет состояние отметки. - `checked` - определяет состояние отметки.
- `supplier` - поставщик состояния отметки (вызывается каждый кадр) - `supplier` - поставщик состояния отметки (вызывается каждый кадр)
- `consumer` - lua функция-приемник состояния отметки. Вызывается только при завершении ввода - `consumer` - lua функция-приемник состояния отметки.
## Метка - *label* ## Метка - *label*
- `valign` - вертикальное выравнивание текста: top/center/bottom - `valign` - вертикальное выравнивание текста: top/center/bottom
@@ -96,7 +97,7 @@
Внутренний текст - изначально введенный текст Внутренний текст - изначально введенный текст
- `placeholder` - текст подстановки (используется текстовое поле пусто) - `placeholder` - текст подстановки (используется если текстовое поле пусто)
- `supplier` - поставщик текста (вызывается каждый кадр) - `supplier` - поставщик текста (вызывается каждый кадр)
- `consumer` - lua функция-приемник введенного текста. Вызывается только при завершении ввода - `consumer` - lua функция-приемник введенного текста. Вызывается только при завершении ввода
- `autoresize` - автоматическое изменение размера элемента (по-умолчанию - false). Не влияет на размер шрифта. - `autoresize` - автоматическое изменение размера элемента (по-умолчанию - false). Не влияет на размер шрифта.
@@ -107,6 +108,7 @@
- `validator` - lua функция, проверяющая текст на корректность. Принимает на вход строку, возвращает true если текст корректен. - `validator` - lua функция, проверяющая текст на корректность. Принимает на вход строку, возвращает true если текст корректен.
- `onup` - lua функция вызываемая при нажатии стрелки вверх. - `onup` - lua функция вызываемая при нажатии стрелки вверх.
- `ondown` - lua функция вызываемая при нажатии стрелки вниз. - `ondown` - lua функция вызываемая при нажатии стрелки вниз.
## Ползунок - *trackbar* ## Ползунок - *trackbar*
- `min` - минимальное значение. Тип: число. По-умолчанию: 0 - `min` - минимальное значение. Тип: число. По-умолчанию: 0
@@ -116,7 +118,9 @@
- `track-width` - ширина указателя (в пикселях). Тип: число. По-умолчанию: 12 - `track-width` - ширина указателя (в пикселях). Тип: число. По-умолчанию: 12
- `track-color` - цвет указателя при наведении курсора. Тип: RGBA цвет. - `track-color` - цвет указателя при наведении курсора. Тип: RGBA цвет.
- `consumer` - lua функция-приемник установленного значения - `consumer` - lua функция-приемник установленного значения
- `sub-consumer` - lua функция-приемник промежуточных значений (используйте для обновления текста при `change-on-release="true"`)
- `supplier` - lua функция-поставщик значения - `supplier` - lua функция-поставщик значения
- `change-on-release` - Вызов функции-приемника (consumer) происходит только тогда, когда пользователь отпускает указатель. Тип: логический. По-умолчанию: false
# Элементы инвентаря # Элементы инвентаря
+2 -1
View File
@@ -13,5 +13,6 @@
"size": [1, 2, 1], "size": [1, 2, 1],
"rotation": "pane", "rotation": "pane",
"model": "aabb", "model": "aabb",
"hitbox": [0.0, 0.0, 0.8, 1.0, 2.0, 0.2] "hitbox": [0.0, 0.0, 0.8, 1.0, 2.0, 0.2],
"ambient-occlusion": false
} }
+4 -3
View File
@@ -1,7 +1,8 @@
function create_setting(id, name, step, postfix, tooltip) function create_setting(id, name, step, postfix, tooltip, changeonrelease)
local info = core.get_setting_info(id) local info = core.get_setting_info(id)
postfix = postfix or "" postfix = postfix or ""
tooltip = tooltip or "" tooltip = tooltip or ""
changeonrelease = changeonrelease or ""
document.root:add(gui.template("track_setting", { document.root:add(gui.template("track_setting", {
id=id, id=id,
name=gui.str(name, "settings"), name=gui.str(name, "settings"),
@@ -10,13 +11,13 @@ function create_setting(id, name, step, postfix, tooltip)
max=info.max, max=info.max,
step=step, step=step,
postfix=postfix, postfix=postfix,
tooltip=tooltip tooltip=tooltip,
changeonrelease=changeonrelease
})) }))
update_setting(core.get_setting(id), id, name, postfix) update_setting(core.get_setting(id), id, name, postfix)
end end
function update_setting(x, id, name, postfix) function update_setting(x, id, name, postfix)
core.set_setting(id, x)
-- updating label -- updating label
document[id..".L"].text = string.format( document[id..".L"].text = string.format(
"%s: %s%s", "%s: %s%s",
+4 -3
View File
@@ -1,7 +1,8 @@
function create_setting(id, name, step, postfix, tooltip) function create_setting(id, name, step, postfix, tooltip, changeonrelease)
local info = core.get_setting_info(id) local info = core.get_setting_info(id)
postfix = postfix or "" postfix = postfix or ""
tooltip = tooltip or "" tooltip = tooltip or ""
changeonrelease = changeonrelease or ""
document.root:add(gui.template("track_setting", { document.root:add(gui.template("track_setting", {
id=id, id=id,
name=gui.str(name, "settings"), name=gui.str(name, "settings"),
@@ -10,13 +11,13 @@ function create_setting(id, name, step, postfix, tooltip)
max=info.max, max=info.max,
step=step, step=step,
postfix=postfix, postfix=postfix,
tooltip=tooltip tooltip=tooltip,
changeonrelease=changeonrelease
})) }))
update_setting(core.get_setting(id), id, name, postfix) update_setting(core.get_setting(id), id, name, postfix)
end end
function update_setting(x, id, name, postfix) function update_setting(x, id, name, postfix)
core.set_setting(id, x)
-- updating label -- updating label
document[id..".L"].text = string.format( document[id..".L"].text = string.format(
"%s: %s%s", "%s: %s%s",
+2 -1
View File
@@ -2,5 +2,6 @@
<label id='%{id}.L' margin='0,3,0,0'>%{name}: %{value}%{postfix}</label> <label id='%{id}.L' margin='0,3,0,0'>%{name}: %{value}%{postfix}</label>
<trackbar <trackbar
value='%{value}' min='%{min}' max='%{max}' step='%{step}' tooltip='%{tooltip}' value='%{value}' min='%{min}' max='%{max}' step='%{step}' tooltip='%{tooltip}'
consumer='function(x) update_setting(x, "%{id}", "%{name}", "%{postfix}") end'/> consumer='function(x) core.set_setting("%{id}", x) end' change-on-release='%{changeonrelease}'
sub-consumer='function(x) update_setting(x, "%{id}", "%{name}", "%{postfix}") end'/>
</panel> </panel>
+1
View File
@@ -217,6 +217,7 @@ void ContentLoader::loadBlock(Block& def, const std::string& name, const fs::pat
root->flag("light-passing", def.lightPassing); root->flag("light-passing", def.lightPassing);
root->flag("sky-light-passing", def.skyLightPassing); root->flag("sky-light-passing", def.skyLightPassing);
root->flag("shadeless", def.shadeless); root->flag("shadeless", def.shadeless);
root->flag("ambient-occlusion", def.ambientOcclusion);
root->flag("breakable", def.breakable); root->flag("breakable", def.breakable);
root->flag("selectable", def.selectable); root->flag("selectable", def.selectable);
root->flag("grounded", def.grounded); root->flag("grounded", def.grounded);
+3
View File
@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <variant> #include <variant>
#include <functional>
namespace dynamic { namespace dynamic {
class Map; class Map;
@@ -27,6 +28,8 @@ namespace dynamic {
bool, bool,
integer_t integer_t
>; >;
using to_string_func = std::function<std::string(const Value&)>;
} }
#endif // DATA_DYNAMIC_FWD_HPP_ #endif // DATA_DYNAMIC_FWD_HPP_
+1
View File
@@ -175,6 +175,7 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
auto dplotter = std::make_shared<Plotter>(350, 250, 2000, 16); auto dplotter = std::make_shared<Plotter>(350, 250, 2000, 16);
dplotter->setGravity(Gravity::bottom_right); dplotter->setGravity(Gravity::bottom_right);
dplotter->setInteractive(false);
add(HudElement(hud_element_mode::permanent, nullptr, dplotter, true)); add(HudElement(hud_element_mode::permanent, nullptr, dplotter, true));
} }
+107 -42
View File
@@ -104,7 +104,7 @@ void BlocksRenderer::face(
index(0, 1, 3, 1, 2, 3); index(0, 1, 3, 1, 2, 3);
} }
void BlocksRenderer::vertex( void BlocksRenderer::vertexAO(
const vec3& coord, const vec3& coord,
float u, float v, float u, float v,
const vec4& tint, const vec4& tint,
@@ -117,7 +117,7 @@ void BlocksRenderer::vertex(
vertex(coord, u, v, light * tint); vertex(coord, u, v, light * tint);
} }
void BlocksRenderer::face( void BlocksRenderer::faceAO(
const vec3& coord, const vec3& coord,
const vec3& X, const vec3& X,
const vec3& Y, const vec3& Y,
@@ -140,12 +140,12 @@ void BlocksRenderer::face(
vec3 axisZ = glm::normalize(Z); vec3 axisZ = glm::normalize(Z);
vec4 tint(d); vec4 tint(d);
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, axisX, axisY, axisZ); vertexAO(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, axisX, axisY, axisZ);
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint, axisX, axisY, axisZ); vertexAO(coord + ( X - Y + Z) * s, region.u2, region.v1, tint, axisX, axisY, axisZ);
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint, axisX, axisY, axisZ); vertexAO(coord + ( X + Y + Z) * s, region.u2, region.v2, tint, axisX, axisY, axisZ);
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, tint, axisX, axisY, axisZ); vertexAO(coord + (-X + Y + Z) * s, region.u1, region.v2, tint, axisX, axisY, axisZ);
} else { } else {
vec4 tint(1.0f); glm::vec4 tint(1.0f);
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint); vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint);
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint); vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint);
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint); vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint);
@@ -154,6 +154,33 @@ void BlocksRenderer::face(
index(0, 1, 2, 0, 2, 3); index(0, 1, 2, 0, 2, 3);
} }
void BlocksRenderer::face(
const vec3& coord,
const vec3& X,
const vec3& Y,
const vec3& Z,
const UVRegion& region,
vec4 tint,
bool lights
) {
if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
overflow = true;
return;
}
float s = 0.5f;
if (lights) {
float d = glm::dot(glm::normalize(Z), SUN_VECTOR);
d = 0.8f + d * 0.2f;
tint *= d;
}
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint);
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint);
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint);
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, tint);
index(0, 1, 2, 0, 2, 3);
}
void BlocksRenderer::tetragonicFace( void BlocksRenderer::tetragonicFace(
const vec3& coord, const vec3& coord,
const vec3& p1, const vec3& p2, const vec3& p3, const vec3& p4, const vec3& p1, const vec3& p2, const vec3& p3, const vec3& p4,
@@ -231,7 +258,8 @@ void BlocksRenderer::blockAABB(
const UVRegion(&texfaces)[6], const UVRegion(&texfaces)[6],
const Block* block, const Block* block,
ubyte rotation, ubyte rotation,
bool lights bool lights,
bool ao
) { ) {
if (block->hitboxes.empty()) { if (block->hitboxes.empty()) {
return; return;
@@ -256,18 +284,30 @@ void BlocksRenderer::blockAABB(
} }
coord = vec3(icoord) - vec3(0.5f) + hitbox.center(); coord = vec3(icoord) - vec3(0.5f) + hitbox.center();
face(coord, X*size.x, Y*size.y, Z*size.z, texfaces[5], lights); // north if (ao) {
face(coord, -X*size.x, Y*size.y, -Z*size.z, texfaces[4], lights); // south faceAO(coord, X*size.x, Y*size.y, Z*size.z, texfaces[5], lights); // north
faceAO(coord, -X*size.x, Y*size.y, -Z*size.z, texfaces[4], lights); // south
face(coord, X*size.x, -Z*size.z, Y*size.y, texfaces[3], lights); // top faceAO(coord, X*size.x, -Z*size.z, Y*size.y, texfaces[3], lights); // top
face(coord, -X*size.x, -Z*size.z, -Y*size.y, texfaces[2], lights); // bottom faceAO(coord, -X*size.x, -Z*size.z, -Y*size.y, texfaces[2], lights); // bottom
face(coord, -Z*size.z, Y*size.y, X*size.x, texfaces[1], lights); // west faceAO(coord, -Z*size.z, Y*size.y, X*size.x, texfaces[1], lights); // west
face(coord, Z*size.z, Y*size.y, -X*size.x, texfaces[0], lights); // east faceAO(coord, Z*size.z, Y*size.y, -X*size.x, texfaces[0], lights); // east
} else {
auto tint = pickLight(icoord);
face(coord, X*size.x, Y*size.y, Z*size.z, texfaces[5], tint, lights); // north
face(coord, -X*size.x, Y*size.y, -Z*size.z, texfaces[4], tint, lights); // south
face(coord, X*size.x, -Z*size.z, Y*size.y, texfaces[3], tint, lights); // top
face(coord, -X*size.x, -Z*size.z, -Y*size.y, texfaces[2], tint, lights); // bottom
face(coord, -Z*size.z, Y*size.y, X*size.x, texfaces[1], tint, lights); // west
face(coord, Z*size.z, Y*size.y, -X*size.x, texfaces[0], tint, lights); // east
}
} }
void BlocksRenderer::blockCustomModel( void BlocksRenderer::blockCustomModel(
const ivec3& icoord, const Block* block, ubyte rotation, bool lights const ivec3& icoord, const Block* block, ubyte rotation, bool lights, bool ao
) { ) {
vec3 X(1, 0, 0); vec3 X(1, 0, 0);
vec3 Y(0, 1, 0); vec3 Y(0, 1, 0);
@@ -289,12 +329,12 @@ void BlocksRenderer::blockCustomModel(
orient.transform(box); orient.transform(box);
} }
vec3 center_coord = coord - vec3(0.5f) + box.center(); vec3 center_coord = coord - vec3(0.5f) + box.center();
face(center_coord, X * size.x, Y * size.y, Z * size.z, block->modelUVs[i * 6 + 5], lights); // north faceAO(center_coord, X * size.x, Y * size.y, Z * size.z, block->modelUVs[i * 6 + 5], lights); // north
face(center_coord, -X * size.x, Y * size.y, -Z * size.z, block->modelUVs[i * 6 + 4], lights); // south faceAO(center_coord, -X * size.x, Y * size.y, -Z * size.z, block->modelUVs[i * 6 + 4], lights); // south
face(center_coord, X * size.x, -Z * size.z, Y * size.y, block->modelUVs[i * 6 + 3], lights); // top faceAO(center_coord, X * size.x, -Z * size.z, Y * size.y, block->modelUVs[i * 6 + 3], lights); // top
face(center_coord, -X * size.x, -Z * size.z, -Y * size.y, block->modelUVs[i * 6 + 2], lights); // bottom faceAO(center_coord, -X * size.x, -Z * size.z, -Y * size.y, block->modelUVs[i * 6 + 2], lights); // bottom
face(center_coord, -Z * size.z, Y * size.y, X * size.x, block->modelUVs[i * 6 + 1], lights); // west faceAO(center_coord, -Z * size.z, Y * size.y, X * size.x, block->modelUVs[i * 6 + 1], lights); // west
face(center_coord, Z * size.z, Y * size.y, -X * size.x, block->modelUVs[i * 6 + 0], lights); // east faceAO(center_coord, Z * size.z, Y * size.y, -X * size.x, block->modelUVs[i * 6 + 0], lights); // east
} }
for (size_t i = 0; i < block->modelExtraPoints.size()/4; i++) { for (size_t i = 0; i < block->modelExtraPoints.size()/4; i++) {
@@ -314,7 +354,8 @@ void BlocksRenderer::blockCube(
const UVRegion(&texfaces)[6], const UVRegion(&texfaces)[6],
const Block* block, const Block* block,
blockstate states, blockstate states,
bool lights bool lights,
bool ao
) { ) {
ubyte group = block->drawGroup; ubyte group = block->drawGroup;
@@ -330,23 +371,44 @@ void BlocksRenderer::blockCube(
Z = orient.axisZ; Z = orient.axisZ;
} }
if (isOpen(x+Z.x, y+Z.y, z+Z.z, group)) { if (ao) {
face(coord, X, Y, Z, texfaces[5], lights); if (isOpen(x+Z.x, y+Z.y, z+Z.z, group)) {
} faceAO(coord, X, Y, Z, texfaces[5], lights);
if (isOpen(x-Z.x, y-Z.y, z-Z.z, group)) { }
face(coord, -X, Y, -Z, texfaces[4], lights); if (isOpen(x-Z.x, y-Z.y, z-Z.z, group)) {
} faceAO(coord, -X, Y, -Z, texfaces[4], lights);
if (isOpen(x+Y.x, y+Y.y, z+Y.z, group)) { }
face(coord, X, -Z, Y, texfaces[3], lights); if (isOpen(x+Y.x, y+Y.y, z+Y.z, group)) {
} faceAO(coord, X, -Z, Y, texfaces[3], lights);
if (isOpen(x-Y.x, y-Y.y, z-Y.z, group)) { }
face(coord, X, Z, -Y, texfaces[2], lights); if (isOpen(x-Y.x, y-Y.y, z-Y.z, group)) {
} faceAO(coord, X, Z, -Y, texfaces[2], lights);
if (isOpen(x+X.x, y+X.y, z+X.z, group)) { }
face(coord, -Z, Y, X, texfaces[1], lights); if (isOpen(x+X.x, y+X.y, z+X.z, group)) {
} faceAO(coord, -Z, Y, X, texfaces[1], lights);
if (isOpen(x-X.x, y-X.y, z-X.z, group)) { }
face(coord, Z, Y, -X, texfaces[0], lights); if (isOpen(x-X.x, y-X.y, z-X.z, group)) {
faceAO(coord, Z, Y, -X, texfaces[0], lights);
}
} else {
if (isOpen(x+Z.x, y+Z.y, z+Z.z, group)) {
face(coord, X, Y, Z, texfaces[5], pickLight({x, y, z+1}), lights);
}
if (isOpen(x-Z.x, y-Z.y, z-Z.z, group)) {
face(coord, -X, Y, -Z, texfaces[4], pickLight({x, y, z-1}), lights);
}
if (isOpen(x+Y.x, y+Y.y, z+Y.z, group)) {
face(coord, X, -Z, Y, texfaces[3], pickLight({x, y+1, z}), lights);
}
if (isOpen(x-Y.x, y-Y.y, z-Y.z, group)) {
face(coord, X, Z, -Y, texfaces[2], pickLight({x, y-1, z}), lights);
}
if (isOpen(x+X.x, y+X.y, z+X.z, group)) {
face(coord, -Z, Y, X, texfaces[1], pickLight({x+1, y, z}), lights);
}
if (isOpen(x-X.x, y-X.y, z-X.z, group)) {
face(coord, Z, Y, -X, texfaces[0], pickLight({x-1, y, z}), lights);
}
} }
} }
@@ -440,7 +502,8 @@ void BlocksRenderer::render(const voxel* voxels) {
int z = (i / CHUNK_D) % CHUNK_W; int z = (i / CHUNK_D) % CHUNK_W;
switch (def.model) { switch (def.model) {
case BlockModel::block: case BlockModel::block:
blockCube(x, y, z, texfaces, &def, vox.state, !def.shadeless); blockCube(x, y, z, texfaces, &def, vox.state, !def.shadeless,
def.ambientOcclusion);
break; break;
case BlockModel::xsprite: { case BlockModel::xsprite: {
blockXSprite(x, y, z, vec3(1.0f), blockXSprite(x, y, z, vec3(1.0f),
@@ -448,11 +511,13 @@ void BlocksRenderer::render(const voxel* voxels) {
break; break;
} }
case BlockModel::aabb: { case BlockModel::aabb: {
blockAABB(ivec3(x,y,z), texfaces, &def, vox.state.rotation, !def.shadeless); blockAABB(ivec3(x,y,z), texfaces, &def, vox.state.rotation,
!def.shadeless, def.ambientOcclusion);
break; break;
} }
case BlockModel::custom: { case BlockModel::custom: {
blockCustomModel(ivec3(x, y, z), &def, vox.state.rotation, !def.shadeless); blockCustomModel(ivec3(x, y, z), &def, vox.state.rotation,
!def.shadeless, def.ambientOcclusion);
break; break;
} }
default: default:
+16 -4
View File
@@ -40,7 +40,7 @@ class BlocksRenderer {
void vertex(const glm::vec3& coord, float u, float v, const glm::vec4& light); void vertex(const glm::vec3& coord, float u, float v, const glm::vec4& light);
void index(int a, int b, int c, int d, int e, int f); void index(int a, int b, int c, int d, int e, int f);
void vertex( void vertexAO(
const glm::vec3& coord, float u, float v, const glm::vec3& coord, float u, float v,
const glm::vec4& brightness, const glm::vec4& brightness,
const glm::vec3& axisX, const glm::vec3& axisX,
@@ -58,6 +58,15 @@ class BlocksRenderer {
const glm::vec4& tint const glm::vec4& tint
); );
void face( void face(
const glm::vec3& coord,
const glm::vec3& X,
const glm::vec3& Y,
const glm::vec3& Z,
const UVRegion& region,
glm::vec4 tint,
bool lights
);
void faceAO(
const glm::vec3& coord, const glm::vec3& coord,
const glm::vec3& axisX, const glm::vec3& axisX,
const glm::vec3& axisY, const glm::vec3& axisY,
@@ -80,14 +89,16 @@ class BlocksRenderer {
const UVRegion(&faces)[6], const UVRegion(&faces)[6],
const Block* block, const Block* block,
blockstate states, blockstate states,
bool lights bool lights,
bool ao
); );
void blockAABB( void blockAABB(
const glm::ivec3& coord, const glm::ivec3& coord,
const UVRegion(&faces)[6], const UVRegion(&faces)[6],
const Block* block, const Block* block,
ubyte rotation, ubyte rotation,
bool lights bool lights,
bool ambientOcclusion
); );
void blockXSprite( void blockXSprite(
int x, int y, int z, int x, int y, int z,
@@ -100,7 +111,8 @@ class BlocksRenderer {
const glm::ivec3& icoord, const glm::ivec3& icoord,
const Block* block, const Block* block,
ubyte rotation, ubyte rotation,
bool lights bool lights,
bool ao
); );
bool isOpenForLight(int x, int y, int z) const; bool isOpenForLight(int x, int y, int z) const;
+1
View File
@@ -50,6 +50,7 @@ ChunksRenderer::ChunksRenderer(
renderer = std::make_unique<BlocksRenderer>( renderer = std::make_unique<BlocksRenderer>(
RENDERER_CAPACITY, level->content, cache, settings RENDERER_CAPACITY, level->content, cache, settings
); );
logger.info() << "created " << threadPool.getWorkersCount() << " workers";
} }
ChunksRenderer::~ChunksRenderer() { ChunksRenderer::~ChunksRenderer() {
+1 -1
View File
@@ -131,7 +131,7 @@ void GUI::actMouse(float delta) {
focus->defocus(); focus->defocus();
focus = nullptr; focus = nullptr;
} }
} else if (pressed) { } else if (!Events::clicked(mousecode::BUTTON_1) && pressed) {
pressed->mouseRelease(this, Events::cursor.x, Events::cursor.y); pressed->mouseRelease(this, Events::cursor.x, Events::cursor.y);
pressed = nullptr; pressed = nullptr;
} }
+21 -1
View File
@@ -50,6 +50,10 @@ void TrackBar::setConsumer(doubleconsumer consumer) {
this->consumer = std::move(consumer); this->consumer = std::move(consumer);
} }
void TrackBar::setSubConsumer(doubleconsumer consumer) {
this->subconsumer = std::move(consumer);
}
void TrackBar::mouseMove(GUI*, int x, int) { void TrackBar::mouseMove(GUI*, int x, int) {
glm::vec2 pos = calcPos(); glm::vec2 pos = calcPos();
value = x - trackWidth/2; value = x - trackWidth/2;
@@ -60,11 +64,19 @@ void TrackBar::mouseMove(GUI*, int x, int) {
value = (value < min) ? min : value; value = (value < min) ? min : value;
value = (int64_t)round(value / step) * step; value = (int64_t)round(value / step) * step;
if (consumer) { if (consumer && !changeOnRelease) {
consumer(value); consumer(value);
} }
if (subconsumer) {
subconsumer(value);
}
} }
void TrackBar::mouseRelease(GUI*, int, int) {
if (consumer && changeOnRelease) {
consumer(value);
}
}
double TrackBar::getValue() const { double TrackBar::getValue() const {
return value; return value;
@@ -90,6 +102,10 @@ glm::vec4 TrackBar::getTrackColor() const {
return trackColor; return trackColor;
} }
bool TrackBar::isChangeOnRelease() const {
return changeOnRelease;
}
void TrackBar::setValue(double x) { void TrackBar::setValue(double x) {
value = x; value = x;
} }
@@ -113,3 +129,7 @@ void TrackBar::setTrackWidth(int width) {
void TrackBar::setTrackColor(glm::vec4 color) { void TrackBar::setTrackColor(glm::vec4 color) {
trackColor = color; trackColor = color;
} }
void TrackBar::setChangeOnRelease(bool flag) {
changeOnRelease = flag;
}
+9 -2
View File
@@ -2,6 +2,7 @@
#define GRAPHICS_UI_ELEMENTS_TRACKBAR_HPP_ #define GRAPHICS_UI_ELEMENTS_TRACKBAR_HPP_
#include "UINode.hpp" #include "UINode.hpp"
#include "../../../data/dynamic_fwd.hpp"
namespace gui { namespace gui {
class TrackBar : public UINode { class TrackBar : public UINode {
@@ -9,11 +10,13 @@ namespace gui {
glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f}; glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f};
doublesupplier supplier = nullptr; doublesupplier supplier = nullptr;
doubleconsumer consumer = nullptr; doubleconsumer consumer = nullptr;
doubleconsumer subconsumer = nullptr;
double min; double min;
double max; double max;
double value; double value;
double step; double step;
int trackWidth; int trackWidth;
bool changeOnRelease = false;
public: public:
TrackBar(double min, TrackBar(double min,
double max, double max,
@@ -22,10 +25,12 @@ namespace gui {
int trackWidth=12); int trackWidth=12);
virtual void draw(const DrawContext* pctx, Assets* assets) override; virtual void draw(const DrawContext* pctx, Assets* assets) override;
virtual void setSupplier(doublesupplier supplier); virtual void setSupplier(doublesupplier);
virtual void setConsumer(doubleconsumer consumer); virtual void setConsumer(doubleconsumer);
virtual void setSubConsumer(doubleconsumer);
virtual void mouseMove(GUI*, int x, int y) override; virtual void mouseMove(GUI*, int x, int y) override;
virtual void mouseRelease(GUI*, int x, int y) override;
virtual double getValue() const; virtual double getValue() const;
virtual double getMin() const; virtual double getMin() const;
@@ -33,6 +38,7 @@ namespace gui {
virtual double getStep() const; virtual double getStep() const;
virtual int getTrackWidth() const; virtual int getTrackWidth() const;
virtual glm::vec4 getTrackColor() const; virtual glm::vec4 getTrackColor() const;
virtual bool isChangeOnRelease() const;
virtual void setValue(double); virtual void setValue(double);
virtual void setMin(double); virtual void setMin(double);
@@ -40,6 +46,7 @@ namespace gui {
virtual void setStep(double); virtual void setStep(double);
virtual void setTrackWidth(int); virtual void setTrackWidth(int);
virtual void setTrackColor(glm::vec4); virtual void setTrackColor(glm::vec4);
virtual void setChangeOnRelease(bool);
}; };
} }
+14 -11
View File
@@ -392,30 +392,33 @@ static std::shared_ptr<UINode> readImage(UiXmlReader& reader, const xml::xmlelem
} }
static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, const xml::xmlelement& element) { static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, const xml::xmlelement& element) {
float min = element->attr("min", "0.0").asFloat(); const auto& env = reader.getEnvironment();
float max = element->attr("max", "1.0").asFloat(); const auto& file = reader.getFilename();
float minv = element->attr("min", "0.0").asFloat();
float maxv = element->attr("max", "1.0").asFloat();
float def = element->attr("value", "0.0").asFloat(); float def = element->attr("value", "0.0").asFloat();
float step = element->attr("step", "1.0").asFloat(); float step = element->attr("step", "1.0").asFloat();
int trackWidth = element->attr("track-width", "12").asInt(); int trackWidth = element->attr("track-width", "12").asInt();
auto bar = std::make_shared<TrackBar>(min, max, def, step, trackWidth); auto bar = std::make_shared<TrackBar>(minv, maxv, def, step, trackWidth);
_readUINode(reader, element, *bar); _readUINode(reader, element, *bar);
if (element->has("consumer")) { if (element->has("consumer")) {
bar->setConsumer(scripting::create_number_consumer( bar->setConsumer(scripting::create_number_consumer(
reader.getEnvironment(), env, element->attr("consumer").getText(), file));
element->attr("consumer").getText(), }
reader.getFilename() if (element->has("sub-consumer")) {
)); bar->setSubConsumer(scripting::create_number_consumer(
env, element->attr("sub-consumer").getText(), file));
} }
if (element->has("supplier")) { if (element->has("supplier")) {
bar->setSupplier(scripting::create_number_supplier( bar->setSupplier(scripting::create_number_supplier(
reader.getEnvironment(), env, element->attr("supplier").getText(), file));
element->attr("supplier").getText(),
reader.getFilename()
));
} }
if (element->has("track-color")) { if (element->has("track-color")) {
bar->setTrackColor(element->attr("track-color").asColor()); bar->setTrackColor(element->attr("track-color").asColor());
} }
if (element->has("change-on-release")) {
bar->setChangeOnRelease(element->attr("change-on-release").asBool());
}
return bar; return bar;
} }
+3 -3
View File
@@ -169,13 +169,13 @@ void CameraControl::update(const PlayerInput& input, float delta, Chunks* chunks
if (player->currentCamera == spCamera) { if (player->currentCamera == spCamera) {
spCamera->position = chunks->rayCastToObstacle( spCamera->position = chunks->rayCastToObstacle(
camera->position, camera->front, 3.0f) - 0.2f * camera->front; camera->position, camera->front, 3.0f) - 0.4f * camera->front;
spCamera->dir = -camera->dir; spCamera->dir = -camera->dir;
spCamera->front = -camera->front; spCamera->front = -camera->front;
} }
else if (player->currentCamera == tpCamera) { else if (player->currentCamera == tpCamera) {
tpCamera->position = chunks->rayCastToObstacle( tpCamera->position = chunks->rayCastToObstacle(
camera->position, -camera->front, 3.0f) + 0.2f * camera->front; camera->position, -camera->front, 3.0f) + 0.4f * camera->front;
tpCamera->dir = camera->dir; tpCamera->dir = camera->dir;
tpCamera->front = camera->front; tpCamera->front = camera->front;
} }
@@ -391,7 +391,7 @@ voxel* PlayerController::updateSelection(float maxDistance) {
selection.position = chunks->seekOrigin( selection.position = chunks->seekOrigin(
iend, indices->blocks.get(selection.vox.id), selectedState iend, indices->blocks.get(selection.vox.id), selectedState
); );
auto origin = chunks->get(iend); auto origin = chunks->get(selection.position);
if (origin && origin->id != vox->id) { if (origin && origin->id != vox->id) {
chunks->set(iend.x, iend.y, iend.z, 0, {}); chunks->set(iend.x, iend.y, iend.z, 0, {});
return updateSelection(maxDistance); return updateSelection(maxDistance);
+19
View File
@@ -380,6 +380,23 @@ static int l_raycast(lua::State* L) {
return 0; return 0;
} }
static int l_compose_state(lua::State* L) {
blockstate state {};
state.rotation = lua::tointeger(L, 1);
state.segment = lua::tointeger(L, 2);
state.userbits = lua::tointeger(L, 3);
return lua::pushinteger(L, blockstate2int(state));
}
static int l_decompose_state(lua::State* L) {
auto stateInt = static_cast<blockstate_t>(lua::tointeger(L, 1));
auto state = int2blockstate(stateInt);
lua::pushinteger(L, state.rotation);
lua::pushinteger(L, state.segment);
lua::pushinteger(L, state.userbits);
return 3;
}
const luaL_Reg blocklib [] = { const luaL_Reg blocklib [] = {
{"index", lua::wrap<l_index>}, {"index", lua::wrap<l_index>},
{"name", lua::wrap<l_get_def>}, {"name", lua::wrap<l_get_def>},
@@ -411,5 +428,7 @@ const luaL_Reg blocklib [] = {
{"place", lua::wrap<l_place>}, {"place", lua::wrap<l_place>},
{"destruct", lua::wrap<l_destruct>}, {"destruct", lua::wrap<l_destruct>},
{"raycast", lua::wrap<l_raycast>}, {"raycast", lua::wrap<l_raycast>},
{"compose_state", lua::wrap<l_compose_state>},
{"decompose_state", lua::wrap<l_decompose_state>},
{NULL, NULL} {NULL, NULL}
}; };
@@ -2,6 +2,7 @@
#include "lua/lua_engine.hpp" #include "lua/lua_engine.hpp"
#include "../../debug/Logger.hpp" #include "../../debug/Logger.hpp"
#include "../../coders/json.hpp"
#include "../../util/stringutil.hpp" #include "../../util/stringutil.hpp"
using namespace scripting; using namespace scripting;
@@ -177,3 +178,25 @@ vec2supplier scripting::create_vec2_supplier(
return glm::vec2(0, 0); return glm::vec2(0, 0);
}; };
} }
dynamic::to_string_func scripting::create_tostring(
const scriptenv& env,
const std::string& src,
const std::string& file
) {
auto L = lua::get_main_thread();
try {
lua::loadbuffer(L, *env, src, file);
lua::call(L, 0, 1);
auto func = lua::create_lambda(L);
return [func](const dynamic::Value& value) {
auto result = func({value});
return json::stringify(result, true, " ");
};
} catch (const lua::luaerror& err) {
logger.error() << err.what();
return [](const auto& value) {
return json::stringify(value, true, " ");
};
}
}
@@ -72,6 +72,12 @@ namespace scripting {
const std::string& src, const std::string& src,
const std::string& file="<string>" const std::string& file="<string>"
); );
dynamic::to_string_func create_tostring(
const scriptenv& env,
const std::string& src,
const std::string& file="<string>"
);
} }
#endif // LOGIC_SCRIPTING_SCRIPTING_FUNCTIONAL_HPP_ #endif // LOGIC_SCRIPTING_SCRIPTING_FUNCTIONAL_HPP_
+5 -1
View File
@@ -200,7 +200,7 @@ public:
} }
} }
void enqueueJob(std::shared_ptr<T> job) { void enqueueJob(const std::shared_ptr<T>& job) {
{ {
std::lock_guard<std::mutex> lock(jobsMutex); std::lock_guard<std::mutex> lock(jobsMutex);
jobs.push(job); jobs.push(job);
@@ -244,6 +244,10 @@ public:
update(); update();
} }
} }
uint getWorkersCount() const {
return threads.size();
}
}; };
} // namespace util } // namespace util
+5 -5
View File
@@ -20,11 +20,11 @@ namespace timeutil {
* ... * ...
* } * }
*/ */
class ScopeLogTimer : public Timer{ class ScopeLogTimer : public Timer {
long long scopeid_; long long scopeid_;
public: public:
ScopeLogTimer(long long id); ScopeLogTimer(long long id);
~ScopeLogTimer(); ~ScopeLogTimer();
}; };
inline constexpr float time_value(float hour, float minute, float second) { inline constexpr float time_value(float hour, float minute, float second) {
+3
View File
@@ -137,6 +137,9 @@ public:
/// @brief Does block model have shading /// @brief Does block model have shading
bool shadeless = false; bool shadeless = false;
/// @brief Does block model have vertex-based AO effect
bool ambientOcclusion = true;
/// @brief Is the block a physical obstacle /// @brief Is the block a physical obstacle
bool obstacle = true; bool obstacle = true;