Merge branch 'dev' into generated-pcm-stream

This commit is contained in:
MihailRis
2025-11-10 12:44:49 +03:00
56 changed files with 609 additions and 242 deletions
@@ -1,6 +1,7 @@
#include "audio/audio.hpp"
#include "assets/Assets.hpp"
#include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "api_lua.hpp"
inline const char* DEFAULT_CHANNEL = "regular";
+11 -2
View File
@@ -8,7 +8,7 @@
#include "content/Content.hpp"
#include "content/ContentControl.hpp"
#include "engine/Engine.hpp"
#include "io/engine_paths.hpp"
#include "engine/EnginePaths.hpp"
#include "io/io.hpp"
#include "io/settings_io.hpp"
#include "frontend/menu.hpp"
@@ -43,7 +43,16 @@ static int l_reset_content(lua::State* L) {
if (level != nullptr) {
throw std::runtime_error("world must be closed before");
}
content_control->resetContent();
std::vector<std::string> nonResetPacks;
if (lua::istable(L, 1)) {
int len = lua::objlen(L, 1);
for (int i = 0; i < len; i++) {
lua::rawgeti(L, i + 1, 1);
nonResetPacks.emplace_back(lua::require_lstring(L, -1));
lua::pop(L);
}
}
content_control->resetContent(std::move(nonResetPacks));
return 0;
}
@@ -2,6 +2,7 @@
#include "content/Content.hpp"
#include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "objects/Entities.hpp"
#include "objects/EntityDef.hpp"
#include "objects/Entity.hpp"
+1 -1
View File
@@ -3,7 +3,7 @@
#include "coders/gzip.hpp"
#include "engine/Engine.hpp"
#include "io/engine_paths.hpp"
#include "engine/EnginePaths.hpp"
#include "io/io.hpp"
#include "io/devices/ZipFileDevice.hpp"
#include "util/stringutil.hpp"
@@ -9,6 +9,7 @@
#include "content/Content.hpp"
#include "content/ContentControl.hpp"
#include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "../usertypes/lua_type_voxelfragment.hpp"
using namespace scripting;
+6
View File
@@ -189,6 +189,11 @@ static int l_reload_script(lua::State* L) {
return 0;
}
static int l_is_open(lua::State* L) {
auto layoutid = lua::require_string(L, 1);
return lua::pushboolean(L, hud->isOpen(layoutid));
}
const luaL_Reg hudlib[] = {
{"open_inventory", wrap_hud<l_open_inventory>},
{"close_inventory", wrap_hud<l_close_inventory>},
@@ -208,5 +213,6 @@ const luaL_Reg hudlib[] = {
{"_set_debug_cheats", wrap_hud<l_set_debug_cheats>},
{"set_allow_pause", wrap_hud<l_set_allow_pause>},
{"reload_script", wrap_hud<l_reload_script>},
{"is_open", wrap_hud<l_is_open>},
{nullptr, nullptr}
};
+1 -1
View File
@@ -10,7 +10,7 @@
#include "graphics/ui/elements/Menu.hpp"
#include "frontend/locale.hpp"
#include "world/files/WorldFiles.hpp"
#include "io/engine_paths.hpp"
#include "engine/EnginePaths.hpp"
#include "world/Level.hpp"
#include "world/World.hpp"
#include "api_lua.hpp"
+1 -1
View File
@@ -10,7 +10,7 @@
#include "content/ContentControl.hpp"
#include "engine/Engine.hpp"
#include "world/files/WorldFiles.hpp"
#include "io/engine_paths.hpp"
#include "engine/EnginePaths.hpp"
#include "io/io.hpp"
#include "lighting/Lighting.hpp"
#include "voxels/Chunk.hpp"
+1 -1
View File
@@ -4,7 +4,7 @@
#include <iostream>
#include "io/io.hpp"
#include "io/engine_paths.hpp"
#include "engine/EnginePaths.hpp"
#include "debug/Logger.hpp"
#include "util/stringutil.hpp"
#include "libs/api_lua.hpp"
+16
View File
@@ -336,6 +336,22 @@ int lua::create_environment(State* L, int parent) {
return id;
}
int lua::restore_pack_environment(lua::State* L, const std::string& packid) {
if(!lua::getglobal(L, "__vc__pack_envs")) {
return -1;
}
int id = nextEnvironment++;
if (lua::getfield(L, packid)) {
// envname = env
setglobal(L, env_name(id));
lua::pop(L);
return id;
}
lua::pop(L);
return -1;
}
void lua::remove_environment(State* L, int id) {
if (id == 0) {
return;
+1
View File
@@ -613,6 +613,7 @@ namespace lua {
return 0;
}
int create_environment(lua::State*, int parent);
int restore_pack_environment(lua::State*, const std::string& packid);
void remove_environment(lua::State*, int id);
inline void close(lua::State* L) {
@@ -8,6 +8,7 @@
#include "graphics/core/ImageData.hpp"
#include "maths/Heightmap.hpp"
#include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "../lua_util.hpp"
#include "lua_type_heightmap.hpp"
+17 -4
View File
@@ -9,7 +9,7 @@
#include "content/ContentControl.hpp"
#include "debug/Logger.hpp"
#include "engine/Engine.hpp"
#include "io/engine_paths.hpp"
#include "engine/EnginePaths.hpp"
#include "io/io.hpp"
#include "frontend/UiDocument.hpp"
#include "items/Inventory.hpp"
@@ -172,7 +172,15 @@ std::unique_ptr<Process> scripting::start_app_script(const io::path& script) {
const ContentPack& pack
) {
auto L = lua::get_main_state();
int id = lua::create_environment(L, 0);
int id = lua::restore_pack_environment(L, pack.id);
if (id != -1) {
return std::shared_ptr<int>(new int(id), [=](int* id) { //-V508
lua::remove_environment(L, *id);
delete id;
});
}
id = lua::create_environment(L, 0);
lua::pushenv(L, id);
lua::pushvalue(L, -1);
lua::setfield(L, "PACK_ENV");
@@ -347,7 +355,7 @@ void scripting::on_world_quit() {
scripting::controller = nullptr;
}
void scripting::cleanup() {
void scripting::cleanup(const std::vector<std::string>& nonReset) {
auto L = lua::get_main_state();
lua::requireglobal(L, "pack");
for (auto& pack : content_control->getAllContentPacks()) {
@@ -358,7 +366,12 @@ void scripting::cleanup() {
lua::pop(L);
if (lua::getglobal(L, "__scripts_cleanup")) {
lua::call_nothrow(L, 0);
lua::createtable(L, nonReset.size(), 0);
for (size_t i = 0; i < nonReset.size(); i++) {
lua::pushstring(L, nonReset[i]);
lua::rawseti(L, i + 1);
}
lua::call_nothrow(L, 1);
}
}
+1 -1
View File
@@ -82,7 +82,7 @@ namespace scripting {
void on_world_tick(int tps);
void on_world_save();
void on_world_quit();
void cleanup();
void cleanup(const std::vector<std::string>& nonReset);
void on_blocks_tick(const Block& block, int tps);
void update_block(const Block& block, const glm::ivec3& pos);
void random_update_block(const Block& block, const glm::ivec3& pos);