Skip to content

Commit

Permalink
Merge branch 'main' into release-0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Jan 21, 2025
2 parents 7997e9a + da10151 commit b37c710
Show file tree
Hide file tree
Showing 28 changed files with 111 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
# install EnTT
git clone https://github.com/skypjack/entt.git
cd entt/build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake -DCMAKE_BUILD_TYPE=Release -DENTT_INSTALL=on ..
sudo make install
cd ../..
- name: Configure
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
# install EnTT
git clone https://github.com/skypjack/entt.git
cd entt/build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake -DCMAKE_BUILD_TYPE=Release -DENTT_INSTALL=on ..
sudo make install
cd ../..
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
```sh
git clone https://github.com/skypjack/entt.git
cd entt/build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake -DCMAKE_BUILD_TYPE=Release -DENTT_INSTALL=on ..
sudo make install
```

Expand Down
2 changes: 1 addition & 1 deletion doc/en/scripting/builtins/librules.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Creates a rule. If a handler is specified, returns the id for deletion.
> Rules that have not been created can be used, but resetting via rules.reset will result in setting the value to nil.
```lua
rules.listen(
rules.listen(
-- rule name
name: str,
-- value change handler function
Expand Down
3 changes: 3 additions & 0 deletions doc/en/scripting/ecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ entity:get_uid() -> int
entity:get_component(name: str) -> component or nil
-- Checks for the presence of a component by name
entity:has_component(name: str) -> bool

-- Enables/disables the component
entity:set_enabled(name: str, enable: bool)
```

## Built-in components
Expand Down
3 changes: 3 additions & 0 deletions doc/ru/scripting/ecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ entity:get_uid() -> int
entity:get_component(name: str) -> компонент или nil
-- Проверяет наличие компонента по имени
entity:has_component(name: str) -> bool

-- Включает/выключает компонент по имени
entity:set_enabled(name: str, enable: bool)
```

## Встроенные компоненты
Expand Down
1 change: 1 addition & 0 deletions res/content/base/blocks/lamp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"texture": "lamp",
"emission": [15, 14, 13],
"shadeless": true,
"material": "base:glass",
"base:durability": 0.3
}
4 changes: 2 additions & 2 deletions res/layouts/console.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
</container>

<container id="logContainer" pos="0,60"
size-func="unpack(vec2.add(gui.get_viewport(), {0,-100}))">
size-func="unpack(vec2.add(gui.get_viewport(), {-350,-100}))">
<textbox
id='log'
color='0'
autoresize='true'
margin='0'
editable='false'
multiline='true'
size-func="gui.get_viewport()[1],40"
size-func="gui.get_viewport()[1]-350,40"
gravity="bottom-left"
markup="md"
></textbox>
Expand Down
19 changes: 6 additions & 13 deletions res/layouts/ingame_chat.xml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@ local initialized = false
local max_lines = 15
local animation_fps = 30

local function remove_line(line)
document[line[1]]:destruct()
time.post_runnable(function()
if world.is_open() then document.root:reposition() end
end)
end

local function update_line(line, uptime)
local diff = uptime - line[2]
if diff > timeout then
remove_line(line)
table.insert(dead_lines, i)
document[line[1]]:destruct()
table.insert(dead_lines, table.index(lines, line))
elseif diff > timeout-fadeout then
local opacity = (timeout - diff) / fadeout
document[line[1]].color = {0, 0, 0, opacity * 80}
Expand All @@ -27,16 +20,16 @@ local function update_line(line, uptime)
end

events.on("core:chat", function(message)
while #lines >= max_lines do
document[lines[1][1]]:destruct()
table.remove(lines, 1)
end
local current_time = time.uptime()
local id = 'l'..tostring(nextid)
document.root:add(gui.template("chat_line", {id=id}))
document.root:reposition()
document[id.."L"].text = message
nextid = nextid + 1
if #lines == max_lines then
remove_line(lines[1])
table.remove(lines, 1)
end
table.insert(lines, {id, current_time})
end)

Expand Down
4 changes: 2 additions & 2 deletions res/modules/bit_converter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ function bit_converter.bytes_to_uint16(bytes, order)

return
bit.bor(
bit.lshift(bytes[1], 8),
bytes[2], 0)
bit.lshift(bytes[2], 8),
bytes[1], 0)
end

function bit_converter.bytes_to_int64(bytes, order)
Expand Down
14 changes: 7 additions & 7 deletions res/modules/data_buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,31 @@ function data_buffer:put_number(num)

if math.floor(num) ~= num then
type = TYPE_FLOAT64
bytes = bit_converter.float64_to_bytes(num)
bytes = bit_converter.float64_to_bytes(num, self.order)
elseif num == 0 then
type = TYPE_ZERO
bytes = { }
elseif num > 0 then
if num <= MAX_UINT16 then
type = TYPE_UINT16
bytes = bit_converter.uint16_to_bytes(num)
bytes = bit_converter.uint16_to_bytes(num, self.order)
elseif num <= MAX_UINT32 then
type = TYPE_UINT32
bytes = bit_converter.uint32_to_bytes(num)
bytes = bit_converter.uint32_to_bytes(num, self.order)
elseif num <= MAX_INT64 then
type = TYPE_INT64
bytes = bit_converter.int64_to_bytes(num)
bytes = bit_converter.int64_to_bytes(num, self.order)
end
elseif num < 0 then
if num >= MIN_INT16 then
type = TYPE_SINT16
bytes = bit_converter.sint16_to_bytes(num)
bytes = bit_converter.sint16_to_bytes(num, self.order)
elseif num >= MIN_INT32 then
type = TYPE_SINT32
bytes = bit_converter.sint32_to_bytes(num)
bytes = bit_converter.sint32_to_bytes(num, self.order)
elseif num >= MIN_INT64 then
type = TYPE_INT64
bytes = bit_converter.int64_to_bytes(num)
bytes = bit_converter.int64_to_bytes(num, self.order)
end
end

Expand Down
20 changes: 18 additions & 2 deletions res/modules/internal/stdcomp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ local Entity = {__index={
def_index=function(self) return entities.get_def(self.eid) end,
def_name=function(self) return entities.def_name(entities.get_def(self.eid)) end,
get_player=function(self) return entities.get_player(self.eid) end,
set_enabled=function(self, name, flag)
local comp = self.components[name]
if comp then
if flag then
if comp.__disabled and comp.on_enable then
comp.on_enable()
end
comp.__disabled = nil
else
if not comp.__disabled and comp.on_disable then
comp.on_disable()
end
comp.__disabled = true
end
end
end,
}}

local entities = {}
Expand Down Expand Up @@ -99,7 +115,7 @@ return {
end
for _, component in pairs(entity.components) do
local callback = component.on_update
if callback then
if not component.__disabled and callback then
local result, err = pcall(callback, tps)
if err then
debug.error(err)
Expand All @@ -113,7 +129,7 @@ return {
for _,entity in pairs(entities) do
for _, component in pairs(entity.components) do
local callback = component.on_render
if callback then
if not component.__disabled and callback then
local result, err = pcall(callback, delta)
if err then
debug.error(err)
Expand Down
18 changes: 16 additions & 2 deletions res/scripts/stdlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ local function complete_app_lib(app)
app.tick = coroutine.yield
app.get_version = core.get_version
app.get_setting_info = core.get_setting_info
app.load_content = core.load_content
app.load_content = function()
core.load_content()
app.tick()
end
app.reset_content = core.reset_content
app.is_content_loaded = core.is_content_loaded

Expand Down Expand Up @@ -416,7 +419,18 @@ end

function start_coroutine(chunk, name)
local co = coroutine.create(function()
local status, error = xpcall(chunk, __vc__error)
local status, error = xpcall(chunk, function(...)
gui.alert(debug.traceback(), function()
if world.is_open() then
__vc_app.close_world()
else
__vc_app.reset_content()
menu:reset()
menu.page = "main"
end
end)
return ...
end)
if not status then
debug.error(error)
end
Expand Down
1 change: 1 addition & 0 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ inline constexpr blockid_t BLOCK_OBSTACLE = 1;
inline constexpr blockid_t BLOCK_STRUCT_AIR = 2;
inline constexpr itemid_t ITEM_EMPTY = 0;
inline constexpr entityid_t ENTITY_NONE = 0;
inline constexpr entityid_t ENTITY_AUTO = std::numeric_limits<entityid_t>::max();

inline constexpr int CHUNK_W = 16;
inline constexpr int CHUNK_H = 256;
Expand Down
3 changes: 3 additions & 0 deletions src/data/dv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ namespace dv {
}

boolean_t value::asBoolean() const {
if (type == value_type::none) {
return false;
}
check_type(type, value_type::boolean);
return val.boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ void Engine::updateFrontend() {
audio::update(delta);
gui->act(delta, Viewport(Window::width, Window::height));
screen->update(delta);
gui->postAct();
}

void Engine::nextFrame() {
Expand All @@ -217,7 +218,6 @@ void Engine::renderFrame() {
Viewport viewport(Window::width, Window::height);
DrawContext ctx(nullptr, viewport, nullptr);
gui->draw(ctx, *assets);
gui->postAct();
}

void Engine::saveSettings() {
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/ui/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void GUI::act(float delta, const Viewport& vp) {

void GUI::postAct() {
while (!postRunnables.empty()) {
runnable callback = postRunnables.back();
runnable callback = postRunnables.front();
postRunnables.pop();
callback();
}
Expand Down
1 change: 1 addition & 0 deletions src/graphics/ui/elements/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void Panel::cropToContent() {
void Panel::fullRefresh() {
refresh();
cropToContent();
reposition();
Container::fullRefresh();
}

Expand Down
2 changes: 1 addition & 1 deletion src/graphics/ui/elements/TextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ void TextBox::setCaret(size_t position) {
scrolled(-glm::ceil(offset/static_cast<double>(scrollStep)+0.5f));
}
uint lcaret = caret - label->getTextLineOffset(line);
int realoffset = font->calcWidth(input, lcaret)-int(textOffset)+2;
int realoffset = font->calcWidth(input, lcaret)-int(textOffset) - padding.x;
if (realoffset-width > 0) {
setTextOffset(textOffset + realoffset-width);
} else if (realoffset < 0) {
Expand Down
19 changes: 10 additions & 9 deletions src/graphics/ui/gui_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ void guiutil::alert(
auto panel = std::make_shared<Panel>(glm::vec2(500, 300), glm::vec4(4.0f), 4.0f);
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));

auto menu = engine.getGUI()->getMenu();
runnable on_hidden_final = [on_hidden, menu, &engine]() {
menu->removePage("<alert>");
auto menuPtr = engine.getGUI()->getMenu();
auto& menu = *menuPtr;
runnable on_hidden_final = [on_hidden, &menu, &engine]() {
menu.removePage("<alert>");
if (on_hidden) {
on_hidden();
} else {
menu->back();
menu.back();
}
};

Expand All @@ -50,21 +51,21 @@ void guiutil::alert(
panel->add(label);
panel->add(std::make_shared<Button>(
langs::get(L"Ok"), glm::vec4(10.f),
[=](GUI*) {
[on_hidden_final](GUI*) {
on_hidden_final();
}
));
panel->refresh();
panel->keepAlive(Events::keyCallbacks[keycode::ENTER].add([=](){
panel->keepAlive(Events::keyCallbacks[keycode::ENTER].add([on_hidden_final](){
on_hidden_final();
return true;
}));
panel->keepAlive(Events::keyCallbacks[keycode::ESCAPE].add([=](){
panel->keepAlive(Events::keyCallbacks[keycode::ESCAPE].add([on_hidden_final](){
on_hidden_final();
return true;
}));
menu->addPage("<alert>", panel, true);
menu->setPage("<alert>");
menu.addPage("<alert>", panel, true);
menu.setPage("<alert>");
}

void guiutil::confirm(
Expand Down
5 changes: 5 additions & 0 deletions src/lighting/Lightmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "typedefs.hpp"

#include <memory>
#include <cstring>

inline constexpr int LIGHTMAP_DATA_LEN = CHUNK_VOL/2;

Expand All @@ -17,6 +18,10 @@ class Lightmap {

void set(const light_t* map);

void clear() {
std::memset(map, 0, sizeof(map));
}

inline unsigned short get(int x, int y, int z) const {
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x]);
}
Expand Down
4 changes: 3 additions & 1 deletion src/logic/scripting/lua/libs/libplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ static int l_set_entity(lua::State* L) {
if (player == nullptr) {
return 0;
}
if (auto entity = get_entity(L, 2)) {
if (lua::isnumber(L, 2)) {
player->setEntity(lua::tointeger(L, 2));
} else if (auto entity = get_entity(L, 2)) {
player->setEntity(entity->getUID());
}
return 0;
Expand Down
Loading

0 comments on commit b37c710

Please sign in to comment.