add fragment.crop, fragment:crop() & fix fragments rotation when width is not equal to depth & fix extra structures placements

This commit is contained in:
MihailRis
2024-10-15 00:03:06 +03:00
parent 44eedadc06
commit 48143c5a2b
13 changed files with 93 additions and 20 deletions
@@ -36,9 +36,8 @@ static int l_create_fragment(lua::State* L) {
static int l_load_fragment(lua::State* L) {
auto paths = engine->getPaths();
auto [prefix, filename] = EnginePaths::parsePath(lua::require_string(L, 1));
auto path = paths->resolve(prefix+":generators/"+filename+".vox");
auto filename = lua::require_string(L, 1);
auto path = paths->resolve(filename);
if (!std::filesystem::exists(path)) {
throw std::runtime_error("file "+path.u8string()+" does not exist");
}
@@ -13,6 +13,17 @@ LuaVoxelFragment::LuaVoxelFragment(std::shared_ptr<VoxelFragment> fragment)
LuaVoxelFragment::~LuaVoxelFragment() {
}
static int l_crop(lua::State* L) {
if (auto fragment = touserdata<LuaVoxelFragment>(L, 1)) {
fragment->getFragment()->crop();
}
return 0;
}
static std::unordered_map<std::string, lua_CFunction> methods {
{"crop", lua::wrap<l_crop>},
};
static int l_meta_tostring(lua::State* L) {
return pushstring(L, "VoxelFragment(0x" + util::tohex(
reinterpret_cast<uint64_t>(topointer(L, 1)))+")");
@@ -27,12 +38,16 @@ static int l_meta_index(lua::State* L) {
auto fieldname = tostring(L, 2);
if (!std::strcmp(fieldname, "size")) {
return pushivec(L, fragment->getFragment()->getSize());
} else {
auto found = methods.find(tostring(L, 2));
if (found != methods.end()) {
return pushcfunction(L, found->second);
}
}
}
return 0;
}
int LuaVoxelFragment::createMetatable(lua::State* L) {
createtable(L, 0, 2);
pushcfunction(L, lua::wrap<l_meta_tostring>);