Merge branch 'MihailRis:main' into sdl-try-2

This commit is contained in:
Ygrik2003 2025-10-15 22:31:18 +03:00 • committed by GitHub
commit 0c121f751b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 77 additions and 57 deletions

View file

@ -101,7 +101,7 @@ block.set_rotation(x: int, y: int, z: int, rotation: int)
## Extended blocks ## Extended blocks
Extended blocks are blocks with size greather than 1x1x1 Extended blocks are blocks with size greater than 1x1x1
```lua ```lua
-- Checks whether the block is extended. -- Checks whether the block is extended.

View file

@ -104,7 +104,7 @@ pack.get_info(packids: table) -> {id={...}, id2={...}, ...}
``` ```
```lua ```lua
pack.assemble(packis: table) -> table pack.assemble(packids: table) -> table
``` ```
Checks the configuration for correctness and adds dependencies, returning the complete configuration. Checks the configuration for correctness and adds dependencies, returning the complete configuration.

View file

@ -92,7 +92,7 @@ pack.get_info(packids: table) -> {id={...}, id2={...}, ...}
``` ```
```lua ```lua
pack.assemble(packis: table) -> table pack.assemble(packids: table) -> table
``` ```
Проверяет корректность конфигурации и добавляет зависимости, возвращая полную. Проверяет корректность конфигурации и добавляет зависимости, возвращая полную.

View file

@ -110,7 +110,7 @@ function unlock_access()
end end
local function reload_model(filename, name) local function reload_model(filename, name)
assets.parse_model("xml", document.editor.text, name) assets.parse_model(file.ext(filename), document.editor.text, name)
end end
function run_current_file() function run_current_file()

View file

@ -194,42 +194,49 @@ function Version.__equal(ver1, ver2)
return ver1[1] == ver2[1] and ver1[2] == ver2[2] and ver1[3] == ver2[3]; return ver1[1] == ver2[1] and ver1[2] == ver2[2] and ver1[3] == ver2[3];
end end
function Version.__more(ver1, ver2) function Version.__greater(ver1, ver2)
if ver1[1] ~= ver2[1] then return ver1[1] > ver2[1] end; if ver1[1] ~= ver2[1] then return ver1[1] > ver2[1] end;
if ver1[2] ~= ver2[2] then return ver1[2] > ver2[2] end; if ver1[2] ~= ver2[2] then return ver1[2] > ver2[2] end;
return ver1[3] > ver2[3]; return ver1[3] > ver2[3];
end end
function Version.__less(ver1, ver2) function Version.__less(ver1, ver2)
return Version.__more(ver2, ver1); return Version.__greater(ver2, ver1);
end end
function Version.__more_or_equal(ver1, ver2) function Version.__greater_or_equal(ver1, ver2)
return not Version.__less(ver1, ver2); return not Version.__less(ver1, ver2);
end end
function Version.__less_or_equal(ver1, ver2) function Version.__less_or_equal(ver1, ver2)
return not Version.__more(ver1, ver2); return not Version.__greater(ver1, ver2);
end end
Version.operators = {
["="] = Version.__equal,
[">"] = Version.__greater,
["<"] = Version.__less,
[">="] = Version.__greater_or_equal,
["<="] = Version.__less_or_equal
}
function Version.compare(op, ver1, ver2) function Version.compare(op, ver1, ver2)
ver1 = string.split(ver1, "."); ver1 = string.split(ver1, ".");
ver2 = string.split(ver2, "."); ver2 = string.split(ver2, ".");
if op == "=" then return Version.__equal(ver1, ver2); local comparison_func = Version.operators[op];
elseif op == ">" then return Version.__more(ver1, ver2);
elseif op == "<" then return Version.__less(ver1, ver2); if comparison_func then
elseif op == ">=" then return Version.__more_or_equal(ver1, ver2); return comparison_func(ver1, ver2);
elseif op == "<=" then return Version.__less_or_equal(ver1, ver2); else
else return false; end return false;
end
end end
function Version.parse(version) function Version.parse(version)
local op = string.sub(version, 1, 2); local op = string.sub(version, 1, 2);
if op == ">=" or op == "=>" then if op == ">=" or op == "<=" then
return ">=", string.sub(version, #op + 1); return op, string.sub(version, #op + 1);
elseif op == "<=" or op == "=<" then
return "<=", string.sub(version, #op + 1);
end end
op = string.sub(version, 1, 1); op = string.sub(version, 1, 1);
@ -340,12 +347,6 @@ function refresh()
packs_info[id] = {packinfo.id, packinfo.title} packs_info[id] = {packinfo.id, packinfo.title}
end end
for i,id in ipairs(packs_installed) do
if table.has(required, id) then
document["pack_"..id].enabled = false
end
end
if #packs_excluded == 0 then packs_excluded = table.copy(packs_available) end if #packs_excluded == 0 then packs_excluded = table.copy(packs_available) end
if #packs_included == 0 then packs_included = table.copy(packs_installed) end if #packs_included == 0 then packs_included = table.copy(packs_installed) end
@ -365,6 +366,12 @@ function refresh()
place_pack(packs_add, packinfo, callback, string.format('reposition_func("%s")', packinfo.id)) place_pack(packs_add, packinfo, callback, string.format('reposition_func("%s")', packinfo.id))
end end
for i,id in ipairs(packs_installed) do
if table.has(required, id) then
document["pack_"..id].enabled = false
end
end
check_deleted() check_deleted()
apply_movements(packs_cur, packs_add) apply_movements(packs_cur, packs_add)
refresh_changes() refresh_changes()

View file

@ -381,7 +381,8 @@ assetload::postfunc assetload::model(
auto text = io::read_string(path); auto text = io::read_string(path);
try { try {
auto model = vcm::parse(path.string(), text).release(); auto model = vcm::parse(path.string(), text, path.extension() == ".xml")
.release();
return [=](Assets* assets) { return [=](Assets* assets) {
request_textures(loader, *model); request_textures(loader, *model);
assets->store(std::unique_ptr<model::Model>(model), name); assets->store(std::unique_ptr<model::Model>(model), name);

View file

@ -139,8 +139,12 @@ void BasicParser<CharT>::skipLine() {
template<typename CharT> template<typename CharT>
void BasicParser<CharT>::skipEmptyLines() { void BasicParser<CharT>::skipEmptyLines() {
if (!hasNext()) {
return;
}
size_t initpos = pos;
skipWhitespace(); skipWhitespace();
pos = linestart; pos = std::max<size_t>(initpos, linestart);
} }
template<typename CharT> template<typename CharT>

View file

@ -163,11 +163,11 @@ static std::unique_ptr<model::Model> load_model(const xmlelement& root) {
} }
std::unique_ptr<model::Model> vcm::parse( std::unique_ptr<model::Model> vcm::parse(
std::string_view file, std::string_view src std::string_view file, std::string_view src, bool usexml
) { ) {
try { try {
auto doc = io::path(std::string(file)).extension() == ".xml" auto doc =
? xml::parse(file, src) : xml::parse_vcm(file, src, "model"); usexml ? xml::parse(file, src) : xml::parse_vcm(file, src, "model");
const auto& root = *doc->getRoot(); const auto& root = *doc->getRoot();
if (root.getTag() != "model") { if (root.getTag() != "model") {
throw std::runtime_error( throw std::runtime_error(

View file

@ -8,5 +8,7 @@ namespace model {
} }
namespace vcm { namespace vcm {
std::unique_ptr<model::Model> parse(std::string_view file, std::string_view src); std::unique_ptr<model::Model> parse(
std::string_view file, std::string_view src, bool usexml
);
} }

View file

@ -38,7 +38,7 @@ static dv::value perform_literal(std::string_view literal) {
literal == "false" || literal == "False") { literal == "false" || literal == "False") {
return literal[0] == 't'; return literal[0] == 't';
} }
if (literal == "null" || literal == "Null") { if (literal == "null" || literal == "Null" || literal == "~") {
return nullptr; return nullptr;
} }
return std::string(literal); return std::string(literal);
@ -204,8 +204,9 @@ dv::value Parser::parseFullValue(int indent) {
skipEmptyLines(); skipEmptyLines();
int init_pos = pos; int init_pos = pos;
int next_indent = countIndent(); int next_indent = countIndent();
if (next_indent < indent) { if (next_indent <= indent) {
throw error("indentation error"); pos = init_pos;
return nullptr;
} }
if (source[pos] == '-') { if (source[pos] == '-') {
pos = init_pos; pos = init_pos;
@ -269,6 +270,10 @@ dv::value Parser::parseArray(int indent) {
dv::value object = dv::object(); dv::value object = dv::object();
object[std::string(name)] = parseFullValue(next_indent); object[std::string(name)] = parseFullValue(next_indent);
skipEmptyLines(); skipEmptyLines();
if (!hasNext()) {
list.add(std::move(object));
break;
}
next_indent = countIndent(); next_indent = countIndent();
if (next_indent > indent) { if (next_indent > indent) {
pos = linestart; pos = linestart;

View file

@ -27,15 +27,15 @@ public:
}; };
enum class VersionOperator { enum class VersionOperator {
EQUAL, GREATHER, LESS, EQUAL, GREATER, LESS,
GREATHER_OR_EQUAL, LESS_OR_EQUAL GREATER_OR_EQUAL, LESS_OR_EQUAL
}; };
VC_ENUM_METADATA(VersionOperator) VC_ENUM_METADATA(VersionOperator)
{"=", VersionOperator::EQUAL}, {"=", VersionOperator::EQUAL},
{">", VersionOperator::GREATHER}, {">", VersionOperator::GREATER},
{"<", VersionOperator::LESS}, {"<", VersionOperator::LESS},
{">=", VersionOperator::GREATHER_OR_EQUAL}, {">=", VersionOperator::GREATER_OR_EQUAL},
{"<=", VersionOperator::LESS_OR_EQUAL}, {"<=", VersionOperator::LESS_OR_EQUAL},
VC_ENUM_END VC_ENUM_END

View file

@ -37,13 +37,13 @@ public:
switch (op) { switch (op) {
case VersionOperator::EQUAL: case VersionOperator::EQUAL:
return *this == other; return *this == other;
case VersionOperator::GREATHER: case VersionOperator::GREATER:
return *this > other; return *this > other;
case VersionOperator::LESS: case VersionOperator::LESS:
return *this < other; return *this < other;
case VersionOperator::LESS_OR_EQUAL: case VersionOperator::LESS_OR_EQUAL:
return *this <= other; return *this <= other;
case VersionOperator::GREATHER_OR_EQUAL: case VersionOperator::GREATER_OR_EQUAL:
return *this >= other; return *this >= other;
default: default:
return false; return false;

View file

@ -108,17 +108,15 @@ static bool resolve_dependencies(
continue; continue;
} }
auto dep_pack = found -> second; auto dep_pack = found->second;
if (Version::matchesPattern(dep.version) && Version::matchesPattern(dep_pack.version) if (Version::matchesPattern(dep.version) && Version::matchesPattern(dep_pack.version)
&& Version(dep_pack.version) && Version(dep_pack.version)
.processOperator(dep.op, Version(dep.version)) .processOperator(dep.op, Version(dep.version))
) { ) {
// dependency pack version meets the required one // dependency pack version meets the required one
continue;
} else if (dep.version == "*" || dep.version == dep_pack.version){ } else if (dep.version == "*" || dep.version == dep_pack.version){
// fallback: dependency pack version also meets required one // fallback: dependency pack version also meets required one
continue;
} else { } else {
throw contentpack_error( throw contentpack_error(
dep.id, dep.id,

View file

@ -54,7 +54,7 @@ public:
/// @brief Build atlas from all added images /// @brief Build atlas from all added images
/// @param extrusion textures extrusion pixels /// @param extrusion textures extrusion pixels
/// (greather is less mip-mapping artifacts) /// (greater is less mip-mapping artifacts)
/// @param prepare generate atlas texture (calls .prepare()) /// @param prepare generate atlas texture (calls .prepare())
/// @param maxResolution max atlas resolution /// @param maxResolution max atlas resolution
std::unique_ptr<Atlas> build(uint extrusion, bool prepare=true, uint maxResolution=0); std::unique_ptr<Atlas> build(uint extrusion, bool prepare=true, uint maxResolution=0);

View file

@ -25,7 +25,7 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
/// @brief Not greather than 64 for this BIG_PRIME value /// @brief Not greater than 64 for this BIG_PRIME value
inline constexpr int UPDATE_AREA_DIAMETER = 32; inline constexpr int UPDATE_AREA_DIAMETER = 32;
/// @brief Number of blocks in the volume /// @brief Number of blocks in the volume
inline constexpr int UPDATE_BLOCKS = inline constexpr int UPDATE_BLOCKS =

View file

@ -253,9 +253,10 @@ void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
float time = gui.getWindow().time(); float time = gui.getWindow().time();
if (editable && static_cast<int>((time - caretLastMove) * 2) % 2 == 0) { if (editable && static_cast<int>((time - caretLastMove) * 2) % 2 == 0) {
uint line = rawTextCache.getLineByTextIndex(caret); uint line = label->getLineByTextIndex(caret);
uint lcaret = caret - rawTextCache.getTextLineOffset(line); uint lcaret = caret - label->getTextLineOffset(line);
int width = rawTextCache.metrics.calcWidth(input, 0, lcaret); int width = rawTextCache.metrics.calcWidth(input, 0, lcaret);
batch->rect( batch->rect(
lcoord.x + width, lcoord.x + width,
lcoord.y + label->getLineYOffset(line), lcoord.y + label->getLineYOffset(line),
@ -272,10 +273,10 @@ void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
batch->setColor(glm::vec4(0.8f, 0.9f, 1.0f, 0.25f)); batch->setColor(glm::vec4(0.8f, 0.9f, 1.0f, 0.25f));
int start = rawTextCache.metrics.calcWidth( int start = rawTextCache.metrics.calcWidth(
labelText, selectionStart - label->getTextLineOffset(startLine) labelText, 0, selectionStart - label->getTextLineOffset(startLine)
); );
int end = rawTextCache.metrics.calcWidth( int end = rawTextCache.metrics.calcWidth(
labelText, selectionEnd - label->getTextLineOffset(endLine) labelText, 0, selectionEnd - label->getTextLineOffset(endLine)
); );
int lineY = label->getLineYOffset(startLine); int lineY = label->getLineYOffset(startLine);
@ -668,7 +669,7 @@ int TextBox::calcIndexAt(int x, int y) const {
line = std::min(line, label->getLinesNumber() - 1); line = std::min(line, label->getLinesNumber() - 1);
size_t lineLength = getLineLength(line); size_t lineLength = getLineLength(line);
uint offset = 0; uint offset = 0;
while (lcoord.x + rawTextCache.metrics.calcWidth(labelText, offset) < x && while (lcoord.x + rawTextCache.metrics.calcWidth(labelText, 0, offset) < x &&
offset < lineLength - 1) { offset < lineLength - 1) {
offset++; offset++;
} }
@ -1217,8 +1218,8 @@ void TextBox::setCaret(size_t position) {
scrolled(-glm::ceil(offset / static_cast<double>(scrollStep) + 0.5f)); scrolled(-glm::ceil(offset / static_cast<double>(scrollStep) + 0.5f));
} }
int lcaret = caret - rawTextCache.getTextLineOffset(line); int lcaret = caret - rawTextCache.getTextLineOffset(line);
int realoffset = int realoffset = rawTextCache.metrics.calcWidth(labelText, 0, lcaret) -
rawTextCache.metrics.calcWidth(labelText, 0, lcaret) - static_cast<int>(textOffset) + 2; static_cast<int>(textOffset) + 2;
if (realoffset - width > 0) { if (realoffset - width > 0) {
setTextOffset(textOffset + realoffset - width); setTextOffset(textOffset + realoffset - width);

View file

@ -44,7 +44,7 @@ namespace gui {
runnable onDownPressed; runnable onDownPressed;
/// @brief Is current input valid /// @brief Is current input valid
bool valid = true; bool valid = true;
/// @brief Text input pointer, value may be greather than text length /// @brief Text input pointer, value may be greater than text length
size_t caret = 0; size_t caret = 0;
/// @brief Actual local (line) position of the caret on vertical move /// @brief Actual local (line) position of the caret on vertical move
size_t maxLocalCaret = 0; size_t maxLocalCaret = 0;

View file

@ -55,7 +55,9 @@ static int l_parse_model(lua::State* L) {
auto name = lua::require_string(L, 3); auto name = lua::require_string(L, 3);
if (format == "xml" || format == "vcm") { if (format == "xml" || format == "vcm") {
engine->getAssets()->store(vcm::parse(name, string), name); engine->getAssets()->store(
vcm::parse(name, string, format == "xml"), name
);
} else { } else {
throw std::runtime_error("unknown format " + util::quote(std::string(format))); throw std::runtime_error("unknown format " + util::quote(std::string(format)));
} }

View file

@ -137,7 +137,7 @@ static int l_unpack(lua::State* L) {
for (size_t i = 0; format[i]; i++) { for (size_t i = 0; format[i]; i++) {
switch (format[i]) { switch (format[i]) {
case 'b': case 'b':
lua::pushinteger(L, reader.get()); lua::pushinteger(L, static_cast<int8_t>(reader.get()));
break; break;
case 'B': case 'B':
lua::pushinteger(L, reader.get() & 0xFF); lua::pushinteger(L, reader.get() & 0xFF);

View file

@ -272,7 +272,7 @@ static int l_meta_meta_call(lua::State* L) {
auto width = tointeger(L, 2); auto width = tointeger(L, 2);
auto height = tointeger(L, 3); auto height = tointeger(L, 3);
if (width <= 0 || height <= 0) { if (width <= 0 || height <= 0) {
throw std::runtime_error("width and height must be greather than 0"); throw std::runtime_error("width and height must be greater than 0");
} }
return newuserdata<LuaHeightmap>( return newuserdata<LuaHeightmap>(
L, static_cast<uint>(width), static_cast<uint>(height) L, static_cast<uint>(width), static_cast<uint>(height)

View file

@ -276,7 +276,7 @@ public:
/// @brief does the block emit any lights /// @brief does the block emit any lights
bool emissive = false; bool emissive = false;
// @brief block size is greather than 1x1x1 // @brief block size is greater than 1x1x1
bool extended = false; bool extended = false;
/// @brief set of hitboxes sets with all coord-systems precalculated /// @brief set of hitboxes sets with all coord-systems precalculated