Nodestate

This commit is contained in:
2025-09-01 13:39:38 +06:00
parent 2dd3ea60d7
commit 95fc3c7e74
11 changed files with 91 additions and 90 deletions

View File

@@ -151,6 +151,7 @@ struct DefItemInfo {
struct DefVoxel_t {};
struct DefNode_t {
AssetsNodestate NodestateId = 0;
AssetsTexture TexId = 0;
};

View File

@@ -436,7 +436,7 @@ void ServerSession::update(GlobalTime gTime, float dTime) {
// Профили
std::unordered_map<DefVoxelId, void*> profile_Voxel_AddOrChange;
std::vector<DefVoxelId> profile_Voxel_Lost;
std::unordered_map<DefNodeId, void*> profile_Node_AddOrChange;
std::unordered_map<DefNodeId, DefNode_t> profile_Node_AddOrChange;
std::vector<DefNodeId> profile_Node_Lost;
std::unordered_map<DefWorldId, void*> profile_World_AddOrChange;
std::vector<DefWorldId> profile_World_Lost;
@@ -811,6 +811,13 @@ void ServerSession::update(GlobalTime gTime, float dTime) {
}
}
// Определения
{
for(auto& [resId, def] : profile_Node_AddOrChange) {
Profiles.DefNode[resId] = def;
}
}
// Чанки
{
for(auto& [wId, lost] : regions_Lost_Result) {
@@ -1110,29 +1117,19 @@ coro<> ServerSession::rP_Definition(Net::AsyncSocket &sock) {
}
case ToClient::L2Definition::Node:
{
// DefNodeId id;
// DefNode_t def;
// id = co_await sock.read<DefNodeId>();
// def.DrawType = (DefNode_t::EnumDrawType) co_await sock.read<uint8_t>();
// for(int iter = 0; iter < 6; iter++) {
// auto &pl = def.Texs[iter].Pipeline;
// pl.resize(co_await sock.read<uint16_t>());
// co_await sock.read((std::byte*) pl.data(), pl.size());
// }
DefNode_t def;
DefNodeId id = co_await sock.read<DefNodeId>();
def.NodestateId = co_await sock.read<uint32_t>();
def.TexId = id;
// PP_Definition_Node *packet = new PP_Definition_Node(
// id,
// def
// );
AsyncContext.ThisTickEntry.Profile_Node_AddOrChange.emplace_back(id, def);
// while(!NetInputPackets.push(packet));
// co_return;
co_return;
}
case ToClient::L2Definition::FreeNode:
{
DefNodeId id = co_await sock.read<DefNodeId>();
AsyncContext.ThisTickEntry.Profile_Node_Lost.push_back(id);
co_return;
}

View File

@@ -94,7 +94,7 @@ private:
struct TickData {
std::vector<std::pair<DefVoxelId, void*>> Profile_Voxel_AddOrChange;
std::vector<DefVoxelId> Profile_Voxel_Lost;
std::vector<std::pair<DefNodeId, void*>> Profile_Node_AddOrChange;
std::vector<std::pair<DefNodeId, DefNode_t>> Profile_Node_AddOrChange;
std::vector<DefNodeId> Profile_Node_Lost;
std::vector<std::pair<DefWorldId, void*>> Profile_World_AddOrChange;
std::vector<DefWorldId> Profile_World_Lost;

View File

@@ -1108,6 +1108,7 @@ uint16_t PreparedNodeState::parseCondition(const std::string_view expression) {
ssize_t npos = pos;
for(; npos < expression.size() && std::isalpha(expression[npos]); npos++);
std::string_view value = expression.substr(pos, npos-pos);
pos += value.size();
if(value == "true")
tokens.push_back(1);
else if(value == "false")
@@ -1198,7 +1199,7 @@ uint16_t PreparedNodeState::parseCondition(const std::string_view expression) {
}
// Обрабатываем унарные операции
for(ssize_t index = end; index >= pos; index--) {
for(ssize_t index = end-1; index >= (ssize_t) pos; index--) {
if(EnumTokenKind *kind = std::get_if<EnumTokenKind>(&tokens[index])) {
if(*kind != EnumTokenKind::Not && *kind != EnumTokenKind::Plus && *kind != EnumTokenKind::Minus)
continue;
@@ -1367,11 +1368,7 @@ uint16_t PreparedNodeState::parseCondition(const std::string_view expression) {
}
};
uint16_t nodeId = lambdaParse(0);
if(!tokens.empty())
MAKE_ERROR("Выражение не действительно");
return nodeId;
return lambdaParse(0);
// std::unordered_map<std::string, int> vars;
// std::function<int(uint16_t)> lambdaCalcNode = [&](uint16_t nodeId) -> int {

View File

@@ -262,6 +262,13 @@ 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];
// Расширяем таблицу с ресурсами, если необходимо
if(type == EnumAssets::Nodestate)
Table_NodeState.emplace_back(std::make_unique<TableEntry<std::vector<AssetsModel>>>());
else if(type == EnumAssets::Model)
Table_Model.emplace_back(std::make_unique<TableEntry<ModelDependency>>());
}
return {id, *data};

View File

@@ -120,17 +120,6 @@ private:
auto [id, entry] = nextId(type);
keyToId[domain][key] = id;
// Расширяем таблицу с ресурсами, если необходимо
ssize_t tableChunks = (ssize_t) (id/TableEntry<DataEntry>::ChunkSize)-(ssize_t) Table[(int) type].size()+1;
for(; tableChunks > 0; tableChunks--) {
Table[(int) type].emplace_back(std::make_unique<TableEntry<DataEntry>>());
if(type == EnumAssets::Nodestate)
Table_NodeState.emplace_back(std::make_unique<TableEntry<std::vector<AssetsModel>>>());
else if(type == EnumAssets::Model)
Table_Model.emplace_back(std::make_unique<TableEntry<ModelDependency>>());
}
return id;
}
@@ -256,6 +245,8 @@ public:
models.append_range(subModel->FullSubModelDeps);
textures.append_range(subModel->FullSubTextureDeps);
}
} else {
LOG.debug() << "Для ноды " << domain << ':' << key << " отсутствует описание Nodestate";
}
{
@@ -271,6 +262,7 @@ public:
textures.erase(eraseIter, textures.end());
textures.shrink_to_fit();
}
return {nodestateId, std::move(models), std::move(textures)};
}

View File

@@ -4,18 +4,22 @@
namespace LV::Server {
ContentManager::ContentManager(asio::io_context& ioc) {
ContentManager::ContentManager(AssetsManager &am)
: AM(am)
{
}
ContentManager::~ContentManager() = default;
void ContentManager::registerBase_Node(ResourceId id, const sol::table& profile) {
void ContentManager::registerBase_Node(ResourceId id, const std::string& domain, const std::string& key, const sol::table& profile) {
std::optional<DefNode>& node = getEntry_Node(id);
if(!node)
node.emplace();
DefNode& def = *node;
def.Domain = domain;
def.Key = key;
{
std::optional<std::variant<std::string, sol::table>> parent = profile.get<std::optional<std::variant<std::string, sol::table>>>("parent");
@@ -70,7 +74,7 @@ void ContentManager::registerBase_Node(ResourceId id, const sol::table& profile)
// result.NodeAdvancementFactory = profile["node_advancement_factory"];
}
void ContentManager::registerBase_World(ResourceId id, const sol::table& profile) {
void ContentManager::registerBase_World(ResourceId id, const std::string& domain, const std::string& key, const sol::table& profile) {
std::optional<DefWorld>& world = getEntry_World(id);
if(!world)
world.emplace();
@@ -82,9 +86,9 @@ void ContentManager::registerBase(EnumDefContent type, const std::string& domain
ProfileChanges[(int) type].push_back(id);
if(type == EnumDefContent::Node)
registerBase_Node(id, profile);
registerBase_Node(id, domain, key, profile);
else if(type == EnumDefContent::World)
registerBase_World(id, profile);
registerBase_World(id, domain, key, profile);
else
MAKE_ERROR("Не реализовано");
}
@@ -117,8 +121,18 @@ ContentManager::Out_buildEndProfiles ContentManager::buildEndProfiles() {
keys.erase(iterErase, keys.end());
}
for(ResourceId id : ProfileChanges[(int) EnumDefContent::Voxel]) {
for(ResourceId id : ProfileChanges[(int) EnumDefContent::Node]) {
std::optional<DefNode>& node = getEntry_Node(id);
if(!node) {
continue;
}
auto [nodestateId, assetsModel, assetsTexture]
= AM.getNodeDependency(node->Domain, node->Key);
node->NodestateId = nodestateId;
node->ModelDeps = std::move(assetsModel);
node->TextureDeps = std::move(assetsTexture);
}
return result;

View File

@@ -29,7 +29,11 @@ struct ResourceBase {
};
struct DefVoxel : public ResourceBase { };
struct DefNode : public ResourceBase { };
struct DefNode : public ResourceBase {
AssetsNodestate NodestateId;
std::vector<AssetsModel> ModelDeps;
std::vector<AssetsTexture> TextureDeps;
};
struct DefWorld : public ResourceBase { };
struct DefPortal : public ResourceBase { };
struct DefEntity : public ResourceBase { };
@@ -126,11 +130,11 @@ class ContentManager {
return resId;
}
void registerBase_Node(ResourceId id, const sol::table& profile);
void registerBase_World(ResourceId id, const sol::table& profile);
void registerBase_Node(ResourceId id, const std::string& domain, const std::string& key, const sol::table& profile);
void registerBase_World(ResourceId id, const std::string& domain, const std::string& key, const sol::table& profile);
public:
ContentManager(asio::io_context& ioc);
ContentManager(AssetsManager &am);
~ContentManager();
// Регистрирует определение контента
@@ -199,6 +203,10 @@ public:
else
return std::nullopt;
}
private:
TOS::Logger LOG = "Server>ContentManager";
AssetsManager& AM;
};
}

View File

@@ -1472,6 +1472,7 @@ void GameServer::init(fs::path worldPath) {
initLuaPost();
pushEvent("postInit");
// Загрузить миры с существующими профилями
LOG.info() << "Загрузка существующих миров...";

View File

@@ -80,7 +80,7 @@ class GameServer : public AsyncObject {
ContentObj(asio::io_context& ioc)
: AM(ioc), CM(ioc)
: AM(ioc), CM(AM)
{}
} Content;

View File

@@ -579,50 +579,34 @@ void RemoteClient::NetworkAndResource_t::informateDefVoxel(const std::vector<std
void RemoteClient::NetworkAndResource_t::informateDefNode(const std::vector<std::pair<DefNodeId, DefNode*>>& nodes)
{
// for(auto& [id, def] : nodes) {
// if(!ResUses.DefNode.contains(id))
// continue;
for(auto& [id, def] : nodes) {
if(!ResUses.DefNode.contains(id))
continue;
checkPacketBorder(1+1+4+4);
NextPacket << (uint8_t) ToClient::L1::Definition
<< (uint8_t) ToClient::L2Definition::Node
<< id << (uint32_t) def->NodestateId;
ResUses_t::RefAssets_t refs;
{
refs.Resources[(uint8_t) EnumAssets::Nodestate].push_back(def->NodestateId);
refs.Resources[(uint8_t) EnumAssets::Texture] = def->TextureDeps;
refs.Resources[(uint8_t) EnumAssets::Model] = def->ModelDeps;
incrementAssets(refs);
}
// size_t reserve = 0;
// for(int iter = 0; iter < 6; iter++)
// reserve += def->Texs[iter].Pipeline.size();
// checkPacketBorder(1+1+4+1+2*6+reserve);
// NextPacket << (uint8_t) ToClient::L1::Definition
// << (uint8_t) ToClient::L2Definition::Node
// << id << (uint8_t) def->DrawType;
// for(int iter = 0; iter < 6; iter++) {
// NextPacket << (uint16_t) def->Texs[iter].Pipeline.size();
// NextPacket.write((const std::byte*) def->Texs[iter].Pipeline.data(), def->Texs[iter].Pipeline.size());
// }
// ResUsesObj::RefDefBin_t refs;
// {
// auto &array = refs.Resources[(uint8_t) EnumBinResource::Texture];
// for(int iter = 0; iter < 6; iter++) {
// array.insert(array.end(), def->Texs[iter].BinTextures.begin(), def->Texs[iter].BinTextures.end());
// }
// std::sort(array.begin(), array.end());
// auto eraseLast = std::unique(array.begin(), array.end());
// array.erase(eraseLast, array.end());
// incrementBinary(refs);
// }
// {
// auto iterDefRef = ResUses.RefDefNode.find(id);
// if(iterDefRef != ResUses.RefDefNode.end()) {
// decrementBinary(std::move(iterDefRef->second));
// iterDefRef->second = std::move(refs);
// } else {
// ResUses.RefDefNode[id] = std::move(refs);
// }
// }
// }
{
auto iterDefRef = ResUses.RefDefNode.find(id);
if(iterDefRef != ResUses.RefDefNode.end()) {
decrementAssets(std::move(iterDefRef->second));
iterDefRef->second = std::move(refs);
} else {
ResUses.RefDefNode[id] = std::move(refs);
}
}
}
}
void RemoteClient::NetworkAndResource_t::informateDefWorld(const std::vector<std::pair<DefWorldId, DefWorld*>>& worlds)