diff --git a/.github/workflows/appimage.yml b/.github/workflows/appimage.yml index cb5993081..148056559 100644 --- a/.github/workflows/appimage.yml +++ b/.github/workflows/appimage.yml @@ -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 diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 69fb0a46a..ddaa95f8a 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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 ../.. diff --git a/README.md b/README.md index e31e1436f..8270f9b08 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/doc/en/scripting/builtins/librules.md b/doc/en/scripting/builtins/librules.md index c4b1c3779..acdf11d86 100644 --- a/doc/en/scripting/builtins/librules.md +++ b/doc/en/scripting/builtins/librules.md @@ -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 diff --git a/doc/en/scripting/ecs.md b/doc/en/scripting/ecs.md index 8763d9819..90a648285 100644 --- a/doc/en/scripting/ecs.md +++ b/doc/en/scripting/ecs.md @@ -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 diff --git a/doc/ru/scripting/ecs.md b/doc/ru/scripting/ecs.md index 3e8e00e54..db44a1ac5 100644 --- a/doc/ru/scripting/ecs.md +++ b/doc/ru/scripting/ecs.md @@ -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) ``` ## Встроенные компоненты diff --git a/res/content/base/blocks/lamp.json b/res/content/base/blocks/lamp.json index 4a1f1ce71..b8f911008 100644 --- a/res/content/base/blocks/lamp.json +++ b/res/content/base/blocks/lamp.json @@ -2,5 +2,6 @@ "texture": "lamp", "emission": [15, 14, 13], "shadeless": true, + "material": "base:glass", "base:durability": 0.3 } diff --git a/res/layouts/console.xml b/res/layouts/console.xml index 43e72dd8d..18d72163c 100644 --- a/res/layouts/console.xml +++ b/res/layouts/console.xml @@ -12,7 +12,7 @@ + size-func="unpack(vec2.add(gui.get_viewport(), {-350,-100}))"> diff --git a/res/layouts/ingame_chat.xml.lua b/res/layouts/ingame_chat.xml.lua index ec4e12b09..dce629887 100644 --- a/res/layouts/ingame_chat.xml.lua +++ b/res/layouts/ingame_chat.xml.lua @@ -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} @@ -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) diff --git a/res/modules/bit_converter.lua b/res/modules/bit_converter.lua index c2ada355f..b72dc3114 100644 --- a/res/modules/bit_converter.lua +++ b/res/modules/bit_converter.lua @@ -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) diff --git a/res/modules/data_buffer.lua b/res/modules/data_buffer.lua index 91dce29c7..ad9ad4867 100644 --- a/res/modules/data_buffer.lua +++ b/res/modules/data_buffer.lua @@ -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 diff --git a/res/modules/internal/stdcomp.lua b/res/modules/internal/stdcomp.lua index bdb2468fc..a62989a99 100644 --- a/res/modules/internal/stdcomp.lua +++ b/res/modules/internal/stdcomp.lua @@ -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 = {} @@ -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) @@ -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) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 9ee20241d..67cdd0fe8 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -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 @@ -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 diff --git a/src/constants.hpp b/src/constants.hpp index 6f4a6ce6e..8755331d2 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -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::max(); inline constexpr int CHUNK_W = 16; inline constexpr int CHUNK_H = 256; diff --git a/src/data/dv.cpp b/src/data/dv.cpp index 5709fd847..cccf348e4 100644 --- a/src/data/dv.cpp +++ b/src/data/dv.cpp @@ -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; } diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index ce29e8c17..c9de5a64f 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -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() { @@ -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() { diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index 2cc280244..08485201f 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -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(); } diff --git a/src/graphics/ui/elements/Panel.cpp b/src/graphics/ui/elements/Panel.cpp index d90b8830c..d76866f08 100644 --- a/src/graphics/ui/elements/Panel.cpp +++ b/src/graphics/ui/elements/Panel.cpp @@ -53,6 +53,7 @@ void Panel::cropToContent() { void Panel::fullRefresh() { refresh(); cropToContent(); + reposition(); Container::fullRefresh(); } diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index f1ed66087..12f262f1c 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -826,7 +826,7 @@ void TextBox::setCaret(size_t position) { scrolled(-glm::ceil(offset/static_cast(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) { diff --git a/src/graphics/ui/gui_util.cpp b/src/graphics/ui/gui_util.cpp index b84dcfd0e..04026132c 100644 --- a/src/graphics/ui/gui_util.cpp +++ b/src/graphics/ui/gui_util.cpp @@ -34,13 +34,14 @@ void guiutil::alert( auto panel = std::make_shared(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(""); + auto menuPtr = engine.getGUI()->getMenu(); + auto& menu = *menuPtr; + runnable on_hidden_final = [on_hidden, &menu, &engine]() { + menu.removePage(""); if (on_hidden) { on_hidden(); } else { - menu->back(); + menu.back(); } }; @@ -50,21 +51,21 @@ void guiutil::alert( panel->add(label); panel->add(std::make_shared