This commit is contained in:
2025-09-01 18:43:23 +06:00
parent 95fc3c7e74
commit 05570b0844
6 changed files with 83 additions and 52 deletions

View File

@@ -31,11 +31,11 @@ project(LuaVox VERSION 0.0 DESCRIPTION "LuaVox Description")
add_library(luavox_common INTERFACE)
target_compile_features(luavox_common INTERFACE cxx_std_23)
# if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# target_compile_options(luavox_common INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all)
# target_link_options(luavox_common INTERFACE -fsanitize=address,undefined)
# set(ENV{ASAN_OPTIONS} detect_leaks=0)
# endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(luavox_common INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all)
target_link_options(luavox_common INTERFACE -fsanitize=address,undefined)
set(ENV{ASAN_OPTIONS} detect_leaks=0)
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
target_compile_options(luavox_common INTERFACE -fcoroutines)

View File

@@ -1440,7 +1440,7 @@ std::pair<float, std::variant<PreparedNodeState::Model, PreparedNodeState::Vecto
if(const auto model_key = model.try_as_string()) {
// Одна модель
Model result;
result.UVLock = uvlock;
result.UVLock = false;
result.Transforms = std::move(transforms);
auto [domain, key] = parseDomainKey((std::string) *model_key, modid);
@@ -1548,8 +1548,8 @@ PreparedModel::PreparedModel(const std::string_view modid, const js::object& pro
GuiLight = EnumGuiLight::Default;
}
if(profile.contains("AmbientOcclusion")) {
AmbientOcclusion = profile.at("ambientocclusion").as_bool();
if(profile.contains("ambient_occlusion")) {
AmbientOcclusion = profile.at("ambient_occlusion").as_bool();
}
if(profile.contains("display")) {
@@ -1588,7 +1588,6 @@ PreparedModel::PreparedModel(const std::string_view modid, const js::object& pro
Display[key] = result;
}
}
if(boost::system::result<const js::value&> textures_val = profile.try_at("textures")) {
@@ -1745,13 +1744,22 @@ PreparedModel::PreparedModel(const std::string_view modid, const js::object& pro
for(const js::value& sub_val : subModels) {
SubModel result;
const js::object& sub = sub_val.as_object();
auto [domain, key] = parseDomainKey((std::string) sub.at("path").as_string(), modid);
result.Domain = std::move(domain);
result.Key = std::move(key);
if(boost::system::result<const js::value&> scene_val = profile.try_at("scene"))
result.Scene = scene_val->to_number<uint16_t>();
if(auto path = sub_val.try_as_string()) {
auto [domain, key] = parseDomainKey((std::string) path.value(), modid);
result.Domain = std::move(domain);
result.Key = std::move(key);
} else {
const js::object& sub = sub_val.as_object();
auto [domain, key] = parseDomainKey((std::string) sub.at("path").as_string(), modid);
result.Domain = std::move(domain);
result.Key = std::move(key);
if(boost::system::result<const js::value&> scene_val = profile.try_at("scene"))
result.Scene = scene_val->to_number<uint16_t>();
}
SubModels.emplace_back(std::move(result));
}
}
}

View File

@@ -673,7 +673,7 @@ enum struct TexturePipelineCMD : uint8_t {
using Hash_t = std::array<uint8_t, 32>;
inline std::pair<std::string, std::string> parseDomainKey(const std::string& value, const std::string_view defaultDomain = "core") {
auto regResult = TOS::Str::match(value, "(?:([\\w\\d_]+):)?([\\w\\d_]+)");
auto regResult = TOS::Str::match(value, "(?:([\\w\\d_]+):)?([\\w\\d/_.]+)");
if(!regResult)
MAKE_ERROR("Недействительный домен:ключ");

View File

@@ -115,18 +115,20 @@ void AssetsManager::loadResourceFromFile_Model(ResourceChangeObj& out, const std
Resource res(path);
std::filesystem::file_time_type ftt = fs::last_write_time(path);
PreparedModel pmc;
auto extension = path.extension();
if(path.extension() == "json") {
if(extension == ".json") {
js::object obj = js::parse(std::string_view((const char*) res.data(), res.size())).as_object();
LV::PreparedModel pm(domain, obj);
std::u8string data = pm.dump();
pmc = PreparedModel(domain, pm);
out.NewOrChange[(int) EnumAssets::Model][domain].emplace_back(key, Resource((const uint8_t*) data.data(), data.size()), ftt);
} else if(path.extension() == "gltf") {
} else if(extension == ".gltf") {
js::object obj = js::parse(std::string_view((const char*) res.data(), res.size())).as_object();
pmc = PreparedModel(domain, obj);
out.NewOrChange[(int) EnumAssets::Model][domain].emplace_back(key, res, ftt);
} else if(path.extension() == "glb") {
} else if(extension == ".glb") {
pmc = PreparedModel(domain, res);
out.NewOrChange[(int) EnumAssets::Model][domain].emplace_back(key, res, ftt);
} else {
@@ -251,7 +253,7 @@ std::tuple<ResourceId, std::optional<AssetsManager::DataEntry>&> AssetsManager::
uint32_t pos = entry.Empty._Find_first();
entry.Empty.reset(pos);
if(entry.Empty._Find_first() == entry.Empty.size())
if(entry.Empty._Find_next(pos) == entry.Empty.size())
entry.IsFull = true;
id = index*TableEntry<DataEntry>::ChunkSize + pos;
@@ -262,6 +264,7 @@ std::tuple<ResourceId, std::optional<AssetsManager::DataEntry>&> AssetsManager::
table.emplace_back(std::make_unique<TableEntry<DataEntry>>());
id = (table.size()-1)*TableEntry<DataEntry>::ChunkSize;
data = &table.back()->Entries[0];
table.back()->Empty.reset(0);
// Расширяем таблицу с ресурсами, если необходимо
if(type == EnumAssets::Nodestate)
@@ -517,8 +520,8 @@ AssetsManager::Out_applyResourceChange AssetsManager::applyResourceChange(const
std::vector<AssetsModel> models;
for(auto& [domain, key] : value.ModelToLocalId) {
models.push_back(lock->getId(EnumAssets::Model, domain, key));
for(auto& [domain2, key2] : value.ModelToLocalId) {
models.push_back(lock->getId(EnumAssets::Model, domain2, key2));
}
{
@@ -542,14 +545,18 @@ AssetsManager::Out_applyResourceChange AssetsManager::applyResourceChange(const
ResourceId resId = lock->getId(EnumAssets::Model, domain, key);
ModelDependency deps;
for(auto& [domain, list] : value.ModelDependencies) {
ResourceId subResId = lock->getId(EnumAssets::Model, domain, key);
deps.ModelDeps.push_back(subResId);
for(auto& [domain2, list] : value.ModelDependencies) {
for(const std::string& key2 : list) {
ResourceId subResId = lock->getId(EnumAssets::Model, domain2, key2);
deps.ModelDeps.push_back(subResId);
}
}
for(auto& [domain, list] : value.TextureDependencies) {
ResourceId subResId = lock->getId(EnumAssets::Texture, domain, key);
deps.TextureDeps.push_back(subResId);
for(auto& [domain2, list] : value.TextureDependencies) {
for(const std::string& key2 : list) {
ResourceId subResId = lock->getId(EnumAssets::Texture, domain2, key2);
deps.TextureDeps.push_back(subResId);
}
}
lock->Table_Model[resId / TableEntry<DataEntry>::ChunkSize]
@@ -574,7 +581,8 @@ AssetsManager::Out_applyResourceChange AssetsManager::applyResourceChange(const
}
// Вычисляем зависимости
std::function<void(AssetsModel resId, ModelDependency&)> calcDeps = [&](AssetsModel resId, ModelDependency& entry) {
std::function<void(AssetsModel resId, ModelDependency&)> calcDeps;
calcDeps = [&](AssetsModel resId, ModelDependency& entry) {
for(AssetsModel subResId : entry.ModelDeps) {
auto& model = lock->Table_Model[subResId / TableEntry<ModelDependency>::ChunkSize]
->Entries[subResId % TableEntry<ModelDependency>::ChunkSize];
@@ -582,6 +590,14 @@ AssetsManager::Out_applyResourceChange AssetsManager::applyResourceChange(const
if(!model)
continue;
if(resId == subResId) {
const auto object1 = lock->getResource(EnumAssets::Model, resId);
const auto object2 = lock->getResource(EnumAssets::Model, subResId);
LOG.warn() << "В моделе " << std::get<1>(*object1) << ':' << std::get<2>(*object1)
<< " обнаружена циклическая зависимость с самой собою";
continue;
}
if(!model->Ready)
calcDeps(subResId, *model);

View File

@@ -229,7 +229,7 @@ public:
getNodeDependency(const std::string& domain, const std::string& key)
{
auto lock = LocalObj.lock();
AssetsNodestate nodestateId = lock->getId(EnumAssets::Nodestate, domain, key);
AssetsNodestate nodestateId = lock->getId(EnumAssets::Nodestate, domain, key+".json");
std::vector<AssetsModel> models;
std::vector<AssetsTexture> textures;

View File

@@ -1444,13 +1444,13 @@ void GameServer::init(fs::path worldPath) {
{
sol::table t = LuaMainState.create_table();
Content.CM.registerBase(EnumDefContent::Node, "core", "test0", t);
Content.CM.registerBase(EnumDefContent::Node, "core", "test1", t);
Content.CM.registerBase(EnumDefContent::Node, "core", "test2", t);
Content.CM.registerBase(EnumDefContent::Node, "core", "test3", t);
Content.CM.registerBase(EnumDefContent::Node, "core", "test4", t);
Content.CM.registerBase(EnumDefContent::Node, "core", "test5", t);
Content.CM.registerBase(EnumDefContent::World, "core", "devel_world", t);
Content.CM.registerBase(EnumDefContent::Node, "test", "test0", t);
Content.CM.registerBase(EnumDefContent::Node, "test", "test1", t);
Content.CM.registerBase(EnumDefContent::Node, "test", "test2", t);
Content.CM.registerBase(EnumDefContent::Node, "test", "test3", t);
Content.CM.registerBase(EnumDefContent::Node, "test", "test4", t);
Content.CM.registerBase(EnumDefContent::Node, "test", "test5", t);
Content.CM.registerBase(EnumDefContent::World, "test", "devel_world", t);
}
initLuaPre();
@@ -1513,15 +1513,15 @@ void GameServer::prerun() {
}
void GameServer::run() {
{
IWorldSaveBackend::TickSyncInfo_In in;
for(int x = -1; x <= 1; x++)
for(int y = -1; y <= 1; y++)
for(int z = -1; z <= 1; z++)
in.Load[0].push_back(Pos::GlobalChunk(x, y, z));
// {
// IWorldSaveBackend::TickSyncInfo_In in;
// for(int x = -1; x <= 1; x++)
// for(int y = -1; y <= 1; y++)
// for(int z = -1; z <= 1; z++)
// in.Load[0].push_back(Pos::GlobalChunk(x, y, z));
stepGeneratorAndLuaAsync(SaveBackend.World->tickSync(std::move(in)));
}
// stepGeneratorAndLuaAsync(SaveBackend.World->tickSync(std::move(in)));
// }
while(true) {
((uint32_t&) Game.AfterStartTime) += (uint32_t) (CurrentTickDuration*256);
@@ -2467,13 +2467,20 @@ void GameServer::stepSyncContent() {
}
for(std::shared_ptr<RemoteClient>& remoteClient : Game.RemoteClients) {
remoteClient->informateAssets(resources);
remoteClient->informateDefVoxel(voxels);
remoteClient->informateDefNode(nodes);
remoteClient->informateDefWorld(worlds);
remoteClient->informateDefPortal(portals);
remoteClient->informateDefEntity(entities);
remoteClient->informateDefItem(items);
if(!resources.empty())
remoteClient->informateAssets(resources);
if(!voxels.empty())
remoteClient->informateDefVoxel(voxels);
if(!nodes.empty())
remoteClient->informateDefNode(nodes);
if(!worlds.empty())
remoteClient->informateDefWorld(worlds);
if(!portals.empty())
remoteClient->informateDefPortal(portals);
if(!entities.empty())
remoteClient->informateDefEntity(entities);
if(!items.empty())
remoteClient->informateDefItem(items);
}