Merge branch 'main' into volume-renderer

This commit is contained in:
MihailRis 2026-02-13 02:07:20 +03:00
commit c7508d6270
35 changed files with 532 additions and 68 deletions

View file

@ -15,10 +15,10 @@
using namespace scripting;
static void load_texture(
const ubyte* bytes, size_t size, const std::string& destname
Assets& assets, const ubyte* bytes, size_t size, const std::string& destname
) {
try {
engine->getAssets()->store(png::load_texture(bytes, size), destname);
assets.store(png::load_texture(bytes, size), destname);
} catch (const std::runtime_error& err) {
debug::Logger logger("lua.assetslib");
logger.error() << err.what();
@ -34,6 +34,8 @@ static int l_request_texture(lua::State* L) {
}
static int l_load_texture(lua::State* L) {
auto& assets = engine->requireAssets();
if (lua::isstring(L, 3) && lua::require_lstring(L, 3) != "png") {
throw std::runtime_error("unsupportd image format");
}
@ -47,10 +49,13 @@ static int l_load_texture(lua::State* L) {
lua::pop(L);
}
lua::pop(L);
load_texture(buffer.data(), buffer.size(), lua::require_string(L, 2));
load_texture(
assets, buffer.data(), buffer.size(), lua::require_string(L, 2)
);
} else {
auto string = lua::bytearray_as_string(L, 1);
load_texture(
assets,
reinterpret_cast<const ubyte*>(string.data()),
string.size(),
lua::require_string(L, 2)
@ -61,13 +66,15 @@ static int l_load_texture(lua::State* L) {
}
static int l_parse_model(lua::State* L) {
auto& assets = engine->requireAssets();
auto format = lua::require_lstring(L, 1);
auto string = lua::require_lstring(L, 2);
auto name = lua::require_string(L, 3);
if (format == "xml" || format == "vcm") {
auto vcmModel = vcm::parse(name, string, format == "xml");
engine->getAssets()->store(
assets.store(
std::make_unique<model::Model>(std::move(vcmModel.squash())), name
);
} else {
@ -79,7 +86,7 @@ static int l_parse_model(lua::State* L) {
}
static int l_to_canvas(lua::State* L) {
auto& assets = *engine->getAssets();
auto& assets = engine->requireAssets();
auto alias = lua::require_lstring(L, 1);
size_t sep = alias.rfind(':');

View file

@ -33,7 +33,7 @@ using namespace scripting;
static DocumentNode get_document_node_impl(
lua::State*, const std::string& name, const std::string& nodeName, bool throwable=true
) {
auto doc = engine->getAssets()->get<UiDocument>(name);
auto doc = engine->requireAssets().get<UiDocument>(name);
if (doc == nullptr) {
if (throwable) {
throw std::runtime_error("document '" + name + "' not found");
@ -1027,7 +1027,7 @@ static int l_gui_str(lua::State* L) {
static int l_gui_reindex(lua::State* L) {
auto name = lua::require_string(L, 1);
auto doc = engine->getAssets()->get<UiDocument>(name);
auto doc = engine->requireAssets().get<UiDocument>(name);
if (doc == nullptr) {
throw std::runtime_error(
"document '" + std::string(name) + "' not found"
@ -1125,7 +1125,7 @@ static int l_gui_load_document(lua::State* L) {
engine->getGUI(), std::move(env), alias, filename, filename.string()
);
auto document = documentPtr.get();
engine->getAssets()->store(std::move(documentPtr), alias);
engine->requireAssets().store(std::move(documentPtr), alias);
// namespace extension
if (lua::istable(L, 4)) {