codex-5.2: синхронизация ресурсов модов, частичная перезагрузка модов
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "glm/ext/quaternion_geometric.hpp"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#include <boost/asio/this_coro.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
@@ -15,12 +16,93 @@
|
||||
#include <memory>
|
||||
#include <Common/Packets.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
|
||||
namespace LV::Client {
|
||||
|
||||
namespace {
|
||||
|
||||
const char* assetTypeName(EnumAssets type) {
|
||||
switch(type) {
|
||||
case EnumAssets::Nodestate: return "nodestate";
|
||||
case EnumAssets::Model: return "model";
|
||||
case EnumAssets::Texture: return "texture";
|
||||
case EnumAssets::Particle: return "particle";
|
||||
case EnumAssets::Animation: return "animation";
|
||||
case EnumAssets::Sound: return "sound";
|
||||
case EnumAssets::Font: return "font";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<DefNodeId> debugExpectedGeneratedNodeId(int rx, int ry, int rz) {
|
||||
if(ry == 1 && rz == 0)
|
||||
return DefNodeId(0);
|
||||
if(rx == 0 && ry == 1)
|
||||
return DefNodeId(0);
|
||||
if(rx == 0 && rz == 0)
|
||||
return DefNodeId(1);
|
||||
if(ry == 0 && rz == 0)
|
||||
return DefNodeId(2);
|
||||
if(rx == 0 && ry == 0)
|
||||
return DefNodeId(3);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void debugCheckGeneratedChunkNodes(WorldId_t worldId,
|
||||
Pos::GlobalChunk chunkPos,
|
||||
const std::array<Node, 16 * 16 * 16>& chunk)
|
||||
{
|
||||
if(chunkPos[0] != 0 && chunkPos[1] != 0 && chunkPos[2] != 0)
|
||||
return;
|
||||
|
||||
static std::atomic<uint32_t> warnCount = 0;
|
||||
if(warnCount.load() >= 16)
|
||||
return;
|
||||
|
||||
Pos::bvec4u localChunk = chunkPos & 0x3;
|
||||
const int baseX = int(localChunk[0]) * 16;
|
||||
const int baseY = int(localChunk[1]) * 16;
|
||||
const int baseZ = int(localChunk[2]) * 16;
|
||||
const int globalBaseX = int(chunkPos[0]) * 16;
|
||||
const int globalBaseY = int(chunkPos[1]) * 16;
|
||||
const int globalBaseZ = int(chunkPos[2]) * 16;
|
||||
|
||||
for(int z = 0; z < 16; z++)
|
||||
for(int y = 0; y < 16; y++)
|
||||
for(int x = 0; x < 16; x++) {
|
||||
int rx = baseX + x;
|
||||
int ry = baseY + y;
|
||||
int rz = baseZ + z;
|
||||
int gx = globalBaseX + x;
|
||||
int gy = globalBaseY + y;
|
||||
int gz = globalBaseZ + z;
|
||||
std::optional<DefNodeId> expected = debugExpectedGeneratedNodeId(rx, ry, rz);
|
||||
if(!expected)
|
||||
continue;
|
||||
|
||||
const Node& node = chunk[x + y * 16 + z * 16 * 16];
|
||||
if(node.NodeId != *expected) {
|
||||
uint32_t index = warnCount.fetch_add(1);
|
||||
if(index < 16) {
|
||||
TOS::Logger("Client>WorldDebug").warn()
|
||||
<< "Generated node mismatch world " << worldId
|
||||
<< " chunk " << int(chunkPos[0]) << ',' << int(chunkPos[1]) << ',' << int(chunkPos[2])
|
||||
<< " at local " << rx << ',' << ry << ',' << rz
|
||||
<< " global " << gx << ',' << gy << ',' << gz
|
||||
<< " expected " << *expected
|
||||
<< " got " << node.NodeId;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ServerSession::ServerSession(asio::io_context &ioc, std::unique_ptr<Net::AsyncSocket>&& socket)
|
||||
: IAsyncDestructible(ioc), Socket(std::move(socket)) //, NetInputPackets(1024)
|
||||
{
|
||||
@@ -170,6 +252,18 @@ void ServerSession::shutdown(EnumDisconnect type) {
|
||||
LOG.info() << "Отключение от сервера: " << reason;
|
||||
}
|
||||
|
||||
void ServerSession::requestModsReload() {
|
||||
if(!Socket || !isConnected())
|
||||
return;
|
||||
|
||||
Net::Packet packet;
|
||||
packet << (uint8_t) ToServer::L1::System
|
||||
<< (uint8_t) ToServer::L2System::ReloadMods;
|
||||
|
||||
Socket->pushPacket(std::move(packet));
|
||||
LOG.info() << "Запрос на перезагрузку модов отправлен";
|
||||
}
|
||||
|
||||
void ServerSession::onResize(uint32_t width, uint32_t height) {
|
||||
|
||||
}
|
||||
@@ -284,10 +378,50 @@ void ServerSession::update(GlobalTime gTime, float dTime) {
|
||||
|
||||
// Получить ресурсы с AssetsManager
|
||||
{
|
||||
static std::atomic<uint32_t> debugAssetReadLogCount = 0;
|
||||
std::vector<std::pair<AssetsManager::ResourceKey, std::optional<Resource>>> resources = AM->pullReads();
|
||||
std::vector<Hash_t> needRequest;
|
||||
|
||||
for(auto& [key, res] : resources) {
|
||||
{
|
||||
auto& waitingByDomain = AsyncContext.ResourceWait[(int) key.Type];
|
||||
auto iterDomain = waitingByDomain.find(key.Domain);
|
||||
if(iterDomain != waitingByDomain.end()) {
|
||||
auto& entries = iterDomain->second;
|
||||
entries.erase(std::remove_if(entries.begin(), entries.end(),
|
||||
[&](const std::pair<std::string, Hash_t>& entry) {
|
||||
return entry.first == key.Key && entry.second == key.Hash;
|
||||
}),
|
||||
entries.end());
|
||||
if(entries.empty())
|
||||
waitingByDomain.erase(iterDomain);
|
||||
}
|
||||
}
|
||||
|
||||
if(key.Domain == "test"
|
||||
&& (key.Type == EnumAssets::Nodestate
|
||||
|| key.Type == EnumAssets::Model
|
||||
|| key.Type == EnumAssets::Texture))
|
||||
{
|
||||
uint32_t idx = debugAssetReadLogCount.fetch_add(1);
|
||||
if(idx < 128) {
|
||||
if(res) {
|
||||
LOG.debug() << "Cache hit type=" << assetTypeName(key.Type)
|
||||
<< " id=" << key.Id
|
||||
<< " key=" << key.Domain << ':' << key.Key
|
||||
<< " size=" << res->size();
|
||||
} else {
|
||||
LOG.debug() << "Cache miss type=" << assetTypeName(key.Type)
|
||||
<< " id=" << key.Id
|
||||
<< " key=" << key.Domain << ':' << key.Key
|
||||
<< " hash=" << int(key.Hash[0]) << '.'
|
||||
<< int(key.Hash[1]) << '.'
|
||||
<< int(key.Hash[2]) << '.'
|
||||
<< int(key.Hash[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!res) {
|
||||
// Проверить не был ли уже отправлен запрос на получение этого хеша
|
||||
auto iter = std::lower_bound(AsyncContext.AlreadyLoading.begin(), AsyncContext.AlreadyLoading.end(), key.Hash);
|
||||
@@ -311,6 +445,11 @@ void ServerSession::update(GlobalTime gTime, float dTime) {
|
||||
if(!needRequest.empty()) {
|
||||
assert(needRequest.size() < (1 << 16));
|
||||
|
||||
uint32_t idx = debugAssetReadLogCount.fetch_add(1);
|
||||
if(idx < 128) {
|
||||
LOG.debug() << "Send ResourceRequest count=" << needRequest.size();
|
||||
}
|
||||
|
||||
Net::Packet p;
|
||||
p << (uint8_t) ToServer::L1::System << (uint8_t) ToServer::L2System::ResourceRequest;
|
||||
p << (uint16_t) needRequest.size();
|
||||
@@ -416,8 +555,33 @@ void ServerSession::update(GlobalTime gTime, float dTime) {
|
||||
}
|
||||
|
||||
// Отправляем запрос на получение ресурсов
|
||||
if(!needToLoad.empty())
|
||||
if(!needToLoad.empty()) {
|
||||
static std::atomic<uint32_t> debugReadRequestLogCount = 0;
|
||||
AssetsManager::ResourceKey firstDebug;
|
||||
bool hasDebug = false;
|
||||
for(const auto& entry : needToLoad) {
|
||||
if(entry.Domain == "test"
|
||||
&& (entry.Type == EnumAssets::Nodestate
|
||||
|| entry.Type == EnumAssets::Model
|
||||
|| entry.Type == EnumAssets::Texture))
|
||||
{
|
||||
firstDebug = entry;
|
||||
hasDebug = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(hasDebug && debugReadRequestLogCount.fetch_add(1) < 64) {
|
||||
LOG.debug() << "Queue asset read count=" << needToLoad.size()
|
||||
<< " type=" << assetTypeName(firstDebug.Type)
|
||||
<< " id=" << firstDebug.Id
|
||||
<< " key=" << firstDebug.Domain << ':' << firstDebug.Key
|
||||
<< " hash=" << int(firstDebug.Hash[0]) << '.'
|
||||
<< int(firstDebug.Hash[1]) << '.'
|
||||
<< int(firstDebug.Hash[2]) << '.'
|
||||
<< int(firstDebug.Hash[3]);
|
||||
}
|
||||
AM->pushReads(std::move(needToLoad));
|
||||
}
|
||||
|
||||
AsyncContext.Binds.push_back(std::move(abc));
|
||||
}
|
||||
@@ -675,7 +839,9 @@ void ServerSession::update(GlobalTime gTime, float dTime) {
|
||||
auto& c = chunks_Changed[wId];
|
||||
|
||||
for(auto& [pos, val] : list) {
|
||||
unCompressNodes(val, caocvr[pos].data());
|
||||
auto& chunkNodes = caocvr[pos];
|
||||
unCompressNodes(val, chunkNodes.data());
|
||||
debugCheckGeneratedChunkNodes(wId, pos, chunkNodes);
|
||||
c.push_back(pos);
|
||||
}
|
||||
}
|
||||
@@ -940,6 +1106,19 @@ void ServerSession::setRenderSession(IRenderSession* session) {
|
||||
RS = session;
|
||||
}
|
||||
|
||||
void ServerSession::resetResourceSyncState() {
|
||||
AsyncContext.AssetsLoading.clear();
|
||||
AsyncContext.AlreadyLoading.clear();
|
||||
for(int type = 0; type < (int) EnumAssets::MAX_ENUM; type++)
|
||||
AsyncContext.ResourceWait[type].clear();
|
||||
AsyncContext.Binds.clear();
|
||||
AsyncContext.LoadedResources.clear();
|
||||
AsyncContext.ThisTickEntry = {};
|
||||
AsyncContext.LoadedAssets.lock()->clear();
|
||||
AsyncContext.AssetsBinds.lock()->clear();
|
||||
AsyncContext.TickSequence.lock()->clear();
|
||||
}
|
||||
|
||||
coro<> ServerSession::run(AsyncUseControl::Lock) {
|
||||
try {
|
||||
while(!IsGoingShutdown && IsConnected) {
|
||||
@@ -950,6 +1129,7 @@ coro<> ServerSession::run(AsyncUseControl::Lock) {
|
||||
}
|
||||
|
||||
IsConnected = false;
|
||||
resetResourceSyncState();
|
||||
|
||||
co_return;
|
||||
}
|
||||
@@ -1009,6 +1189,7 @@ coro<> ServerSession::rP_System(Net::AsyncSocket &sock) {
|
||||
}
|
||||
|
||||
coro<> ServerSession::rP_Resource(Net::AsyncSocket &sock) {
|
||||
static std::atomic<uint32_t> debugResourceLogCount = 0;
|
||||
uint8_t second = co_await sock.read<uint8_t>();
|
||||
|
||||
switch((ToClient::L2Resource) second) {
|
||||
@@ -1035,6 +1216,23 @@ coro<> ServerSession::rP_Resource(Net::AsyncSocket &sock) {
|
||||
(EnumAssets) type, (ResourceId) id, std::move(domain),
|
||||
std::move(key), hash
|
||||
);
|
||||
|
||||
if(binds.back().Domain == "test"
|
||||
&& (binds.back().Type == EnumAssets::Nodestate
|
||||
|| binds.back().Type == EnumAssets::Model
|
||||
|| binds.back().Type == EnumAssets::Texture))
|
||||
{
|
||||
uint32_t idx = debugResourceLogCount.fetch_add(1);
|
||||
if(idx < 128) {
|
||||
LOG.debug() << "Bind asset type=" << assetTypeName(binds.back().Type)
|
||||
<< " id=" << binds.back().Id
|
||||
<< " key=" << binds.back().Domain << ':' << binds.back().Key
|
||||
<< " hash=" << int(binds.back().Hash[0]) << '.'
|
||||
<< int(binds.back().Hash[1]) << '.'
|
||||
<< int(binds.back().Hash[2]) << '.'
|
||||
<< int(binds.back().Hash[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AsyncContext.AssetsBinds.lock()->push_back(AssetsBindsChange(binds, {}));
|
||||
@@ -1072,6 +1270,20 @@ coro<> ServerSession::rP_Resource(Net::AsyncSocket &sock) {
|
||||
std::string domain = co_await sock.read<std::string>();
|
||||
std::string key = co_await sock.read<std::string>();
|
||||
|
||||
if(domain == "test"
|
||||
&& (type == EnumAssets::Nodestate
|
||||
|| type == EnumAssets::Model
|
||||
|| type == EnumAssets::Texture))
|
||||
{
|
||||
uint32_t idx = debugResourceLogCount.fetch_add(1);
|
||||
if(idx < 128) {
|
||||
LOG.debug() << "InitResSend type=" << assetTypeName(type)
|
||||
<< " id=" << id
|
||||
<< " key=" << domain << ':' << key
|
||||
<< " size=" << size;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncContext.AssetsLoading[hash] = AssetLoading{
|
||||
type, id, std::move(domain), std::move(key),
|
||||
std::u8string(size, '\0'), 0
|
||||
@@ -1095,6 +1307,20 @@ coro<> ServerSession::rP_Resource(Net::AsyncSocket &sock) {
|
||||
|
||||
if(al.Offset == al.Data.size()) {
|
||||
// Ресурс полностью загружен
|
||||
if(al.Domain == "test"
|
||||
&& (al.Type == EnumAssets::Nodestate
|
||||
|| al.Type == EnumAssets::Model
|
||||
|| al.Type == EnumAssets::Texture))
|
||||
{
|
||||
uint32_t idx = debugResourceLogCount.fetch_add(1);
|
||||
if(idx < 128) {
|
||||
LOG.debug() << "Resource loaded type=" << assetTypeName(al.Type)
|
||||
<< " id=" << al.Id
|
||||
<< " key=" << al.Domain << ':' << al.Key
|
||||
<< " size=" << al.Data.size();
|
||||
}
|
||||
}
|
||||
|
||||
AsyncContext.LoadedAssets.lock()->emplace_back(
|
||||
al.Type, al.Id, std::move(al.Domain), std::move(al.Key), std::move(al.Data)
|
||||
);
|
||||
@@ -1118,6 +1344,7 @@ coro<> ServerSession::rP_Resource(Net::AsyncSocket &sock) {
|
||||
}
|
||||
|
||||
coro<> ServerSession::rP_Definition(Net::AsyncSocket &sock) {
|
||||
static std::atomic<uint32_t> debugDefLogCount = 0;
|
||||
uint8_t second = co_await sock.read<uint8_t>();
|
||||
|
||||
switch((ToClient::L2Definition) second) {
|
||||
@@ -1148,6 +1375,15 @@ coro<> ServerSession::rP_Definition(Net::AsyncSocket &sock) {
|
||||
def.NodestateId = co_await sock.read<uint32_t>();
|
||||
def.TexId = id;
|
||||
|
||||
if(id < 32) {
|
||||
uint32_t idx = debugDefLogCount.fetch_add(1);
|
||||
if(idx < 64) {
|
||||
LOG.debug() << "DefNode id=" << id
|
||||
<< " nodestate=" << def.NodestateId
|
||||
<< " tex=" << def.TexId;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncContext.ThisTickEntry.Profile_Node_AddOrChange.emplace_back(id, def);
|
||||
|
||||
co_return;
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
static coro<std::unique_ptr<Net::AsyncSocket>> asyncInitGameProtocol(asio::io_context &ioc, tcp::socket &&socket, std::function<void(const std::string&)> onProgress = nullptr);
|
||||
|
||||
void shutdown(EnumDisconnect type);
|
||||
void requestModsReload();
|
||||
|
||||
bool isConnected() {
|
||||
return Socket->isAlive() && IsConnected;
|
||||
@@ -182,6 +183,7 @@ private:
|
||||
ServerSession(asio::io_context &ioc, std::unique_ptr<Net::AsyncSocket> &&socket);
|
||||
|
||||
virtual coro<> asyncDestructor() override;
|
||||
void resetResourceSyncState();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2305,6 +2305,10 @@ void Vulkan::gui_ConnectedToServer() {
|
||||
if(ImGui::Button("Delimeter"))
|
||||
LOG.debug();
|
||||
|
||||
if(ImGui::Button("Перезагрузить моды")) {
|
||||
Game.Session->requestModsReload();
|
||||
}
|
||||
|
||||
if(ImGui::Button("Выйти")) {
|
||||
Game.Выйти = true;
|
||||
Game.ImGuiInterfaces.pop_back();
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
#include "glm/ext/scalar_constants.hpp"
|
||||
#include "glm/matrix.hpp"
|
||||
#include "glm/trigonometric.hpp"
|
||||
#include <atomic>
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
@@ -307,6 +309,15 @@ void ChunkMeshGenerator::run(uint8_t id) {
|
||||
NodeVertexStatic v;
|
||||
std::memset(&v, 0, sizeof(v));
|
||||
|
||||
static std::atomic<uint32_t> debugMeshWarnCount = 0;
|
||||
const bool debugMeshEnabled = debugMeshWarnCount.load() < 16;
|
||||
std::array<uint8_t, 16> expectedColumnX = {};
|
||||
std::array<uint8_t, 16> expectedColumnY = {};
|
||||
std::array<uint8_t, 16> expectedColumnZ = {};
|
||||
std::array<uint8_t, 16> generatedColumnX = {};
|
||||
std::array<uint8_t, 16> generatedColumnY = {};
|
||||
std::array<uint8_t, 16> generatedColumnZ = {};
|
||||
|
||||
struct ModelCacheEntry {
|
||||
std::vector<std::vector<std::pair<float, std::unordered_map<EnumFace, std::vector<NodeVertexStatic>>>>> Routes;
|
||||
};
|
||||
@@ -377,6 +388,7 @@ void ChunkMeshGenerator::run(uint8_t id) {
|
||||
for(int z = 0; z < 16; z++)
|
||||
for(int y = 0; y < 16; y++)
|
||||
for(int x = 0; x < 16; x++) {
|
||||
const size_t vertexStart = result.NodeVertexs.size();
|
||||
int fullCovered = 0;
|
||||
|
||||
fullCovered |= fullNodes[x+1+1][y+1][z+1];
|
||||
@@ -392,9 +404,18 @@ void ChunkMeshGenerator::run(uint8_t id) {
|
||||
const Node& nodeData = (*chunk)[x+y*16+z*16*16];
|
||||
const DefNode_t* node = getNodeProfile(nodeData.NodeId);
|
||||
|
||||
if(debugMeshEnabled) {
|
||||
const bool hasRenderable = (node->NodestateId != 0) || (node->TexId != 0);
|
||||
if(hasRenderable && fullCovered != 0b111111) {
|
||||
expectedColumnX[x] = 1;
|
||||
expectedColumnY[y] = 1;
|
||||
expectedColumnZ[z] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool usedModel = false;
|
||||
|
||||
if(NSP && node->NodestateId != 0) {
|
||||
if(NSP && (node->NodestateId != 0 || NSP->hasNodestate(node->NodestateId))) {
|
||||
auto iterCache = modelCache.find(nodeData.Data);
|
||||
if(iterCache == modelCache.end()) {
|
||||
std::unordered_map<std::string, int32_t> states;
|
||||
@@ -423,7 +444,7 @@ void ChunkMeshGenerator::run(uint8_t id) {
|
||||
}
|
||||
|
||||
if(usedModel)
|
||||
continue;
|
||||
goto node_done;
|
||||
|
||||
if(NSP && node->TexId != 0) {
|
||||
auto iterTex = baseTextureCache.find(node->TexId);
|
||||
@@ -439,7 +460,7 @@ void ChunkMeshGenerator::run(uint8_t id) {
|
||||
}
|
||||
|
||||
if(v.Tex == 0)
|
||||
continue;
|
||||
goto node_done;
|
||||
|
||||
// Рендерим обычный кубоид
|
||||
// XZ+Y
|
||||
@@ -645,6 +666,60 @@ void ChunkMeshGenerator::run(uint8_t id) {
|
||||
v.TV = 0;
|
||||
result.NodeVertexs.push_back(v);
|
||||
}
|
||||
|
||||
node_done:
|
||||
if(debugMeshEnabled) {
|
||||
const bool emitted = result.NodeVertexs.size() > vertexStart;
|
||||
if(emitted) {
|
||||
generatedColumnX[x] = 1;
|
||||
generatedColumnY[y] = 1;
|
||||
generatedColumnZ[z] = 1;
|
||||
} else {
|
||||
const bool hasRenderable = (node->NodestateId != 0) || (node->TexId != 0);
|
||||
if(hasRenderable && fullCovered != 0b111111) {
|
||||
uint32_t warnIndex = debugMeshWarnCount.fetch_add(1);
|
||||
if(warnIndex < 16) {
|
||||
LOG.warn() << "Missing node geometry at chunk " << int(pos[0]) << ','
|
||||
<< int(pos[1]) << ',' << int(pos[2])
|
||||
<< " local " << x << ',' << y << ',' << z
|
||||
<< " nodeId " << nodeData.NodeId
|
||||
<< " meta " << int(nodeData.Meta)
|
||||
<< " covered " << fullCovered
|
||||
<< " tex " << node->TexId
|
||||
<< " nodestate " << node->NodestateId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(debugMeshEnabled) {
|
||||
auto collectMissing = [](const std::array<uint8_t, 16>& expected,
|
||||
const std::array<uint8_t, 16>& generated) {
|
||||
std::string res;
|
||||
for(int i = 0; i < 16; i++) {
|
||||
if(expected[i] && !generated[i]) {
|
||||
if(!res.empty())
|
||||
res += ',';
|
||||
res += std::to_string(i);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
std::string missingX = collectMissing(expectedColumnX, generatedColumnX);
|
||||
std::string missingY = collectMissing(expectedColumnY, generatedColumnY);
|
||||
std::string missingZ = collectMissing(expectedColumnZ, generatedColumnZ);
|
||||
if(!missingX.empty() || !missingY.empty() || !missingZ.empty()) {
|
||||
uint32_t warnIndex = debugMeshWarnCount.fetch_add(1);
|
||||
if(warnIndex < 16) {
|
||||
LOG.warn() << "Missing mesh columns at chunk " << int(pos[0]) << ','
|
||||
<< int(pos[1]) << ',' << int(pos[2])
|
||||
<< " missingX[" << missingX << "]"
|
||||
<< " missingY[" << missingY << "]"
|
||||
<< " missingZ[" << missingZ << "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Вычислить индексы и сократить вершины
|
||||
@@ -1589,8 +1664,10 @@ void VulkanRenderSession::tickSync(const TickSyncData& data) {
|
||||
modelLost.insert(modelLost.end(), iter->second.begin(), iter->second.end());
|
||||
|
||||
std::vector<AssetsModel> changedModels;
|
||||
if(!modelResources.empty() || !modelLost.empty())
|
||||
changedModels = MP.onModelChanges(std::move(modelResources), std::move(modelLost));
|
||||
if(!modelResources.empty() || !modelLost.empty()) {
|
||||
const auto& modelAssets = ServerSession->Assets[EnumAssets::Model];
|
||||
changedModels = MP.onModelChanges(std::move(modelResources), std::move(modelLost), &modelAssets);
|
||||
}
|
||||
|
||||
if(TP) {
|
||||
std::vector<std::tuple<AssetsTexture, Resource>> textureResources;
|
||||
|
||||
@@ -85,7 +85,9 @@ public:
|
||||
}
|
||||
|
||||
// Применяет изменения, возвращая все затронутые модели
|
||||
std::vector<AssetsModel> onModelChanges(std::vector<std::tuple<AssetsModel, Resource>> newOrChanged, std::vector<AssetsModel> lost) {
|
||||
std::vector<AssetsModel> onModelChanges(std::vector<std::tuple<AssetsModel, Resource>> newOrChanged,
|
||||
std::vector<AssetsModel> lost,
|
||||
const std::unordered_map<ResourceId, AssetEntry>* modelAssets) {
|
||||
std::vector<AssetsModel> result;
|
||||
|
||||
std::move_only_function<void(ResourceId)> makeUnready;
|
||||
@@ -130,6 +132,14 @@ public:
|
||||
Models.erase(iterModel);
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, ResourceId> modelKeyToId;
|
||||
if(modelAssets) {
|
||||
modelKeyToId.reserve(modelAssets->size());
|
||||
for(const auto& [id, entry] : *modelAssets) {
|
||||
modelKeyToId.emplace(entry.Domain + ':' + entry.Key, id);
|
||||
}
|
||||
}
|
||||
|
||||
for(const auto& [key, resource] : newOrChanged) {
|
||||
result.push_back(key);
|
||||
|
||||
@@ -164,56 +174,59 @@ public:
|
||||
}
|
||||
|
||||
std::vector<Vertex> v;
|
||||
|
||||
|
||||
auto addQuad = [&](const glm::vec3& p0,
|
||||
const glm::vec3& p1,
|
||||
const glm::vec3& p2,
|
||||
const glm::vec3& p3,
|
||||
const glm::vec2& uv0,
|
||||
const glm::vec2& uv1,
|
||||
const glm::vec2& uv2,
|
||||
const glm::vec2& uv3) {
|
||||
v.emplace_back(p0, uv0, texId);
|
||||
v.emplace_back(p1, uv1, texId);
|
||||
v.emplace_back(p2, uv2, texId);
|
||||
v.emplace_back(p0, uv0, texId);
|
||||
v.emplace_back(p2, uv2, texId);
|
||||
v.emplace_back(p3, uv3, texId);
|
||||
};
|
||||
|
||||
const float x0 = min.x;
|
||||
const float x1 = max.x;
|
||||
const float y0 = min.y;
|
||||
const float y1 = max.y;
|
||||
const float z0 = min.z;
|
||||
const float z1 = max.z;
|
||||
const float u0 = from_uv.x;
|
||||
const float v0 = from_uv.y;
|
||||
const float u1 = to_uv.x;
|
||||
const float v1 = to_uv.y;
|
||||
|
||||
switch(face) {
|
||||
case EnumFace::Down:
|
||||
v.emplace_back(glm::vec3{min.x, min.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, min.y, max.z}, glm::vec2{from_uv.x, to_uv.y}, texId);
|
||||
v.emplace_back(glm::vec3{max.x, min.y, min.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, min.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, min.y, max.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, min.y, max.z}, glm::vec2{to_uv.x, from_uv.y}, texId);
|
||||
break;
|
||||
case EnumFace::Up:
|
||||
v.emplace_back(glm::vec3{min.x, max.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, min.z}, glm::vec2{from_uv.x, to_uv.y}, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, max.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, max.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, max.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, max.y, max.z}, glm::vec2{to_uv.x, from_uv.y}, texId);
|
||||
break;
|
||||
case EnumFace::North:
|
||||
v.emplace_back(glm::vec3{min.x, min.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, min.y, min.z}, glm::vec2{from_uv.x, to_uv.y}, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, min.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, min.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, min.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, max.y, min.z}, glm::vec2{to_uv.x, from_uv.y}, texId);
|
||||
break;
|
||||
case EnumFace::South:
|
||||
v.emplace_back(glm::vec3{min.x, min.y, max.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, min.y, max.z}, glm::vec2{from_uv.x, to_uv.y}, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, max.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, min.y, max.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, max.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, max.y, max.z}, glm::vec2{to_uv.x, from_uv.y}, texId);
|
||||
break;
|
||||
case EnumFace::West:
|
||||
v.emplace_back(glm::vec3{min.x, min.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, min.y, max.z}, glm::vec2{from_uv.x, to_uv.y}, texId);
|
||||
v.emplace_back(glm::vec3{min.x, max.y, max.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, min.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, max.y, max.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{min.x, max.y, min.z}, glm::vec2{to_uv.x, from_uv.y}, texId);
|
||||
break;
|
||||
addQuad({x0, y1, z1}, {x1, y1, z1}, {x1, y1, z0}, {x0, y1, z0},
|
||||
{u0, v0}, {u1, v0}, {u1, v1}, {u0, v1});
|
||||
break;
|
||||
case EnumFace::Down:
|
||||
addQuad({x0, y0, z1}, {x0, y0, z0}, {x1, y0, z0}, {x1, y0, z1},
|
||||
{u0, v0}, {u0, v1}, {u1, v1}, {u1, v0});
|
||||
break;
|
||||
case EnumFace::East:
|
||||
v.emplace_back(glm::vec3{max.x, min.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, min.y, max.z}, glm::vec2{from_uv.x, to_uv.y}, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, max.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, min.y, min.z}, from_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, max.z}, to_uv, texId);
|
||||
v.emplace_back(glm::vec3{max.x, max.y, min.z}, glm::vec2{to_uv.x, from_uv.y}, texId);
|
||||
break;
|
||||
addQuad({x1, y0, z1}, {x1, y0, z0}, {x1, y1, z0}, {x1, y1, z1},
|
||||
{u0, v0}, {u0, v1}, {u1, v1}, {u1, v0});
|
||||
break;
|
||||
case EnumFace::West:
|
||||
addQuad({x0, y0, z1}, {x0, y1, z1}, {x0, y1, z0}, {x0, y0, z0},
|
||||
{u0, v0}, {u1, v0}, {u1, v1}, {u0, v1});
|
||||
break;
|
||||
case EnumFace::South:
|
||||
addQuad({x0, y0, z1}, {x1, y0, z1}, {x1, y1, z1}, {x0, y1, z1},
|
||||
{u0, v0}, {u1, v0}, {u1, v1}, {u0, v1});
|
||||
break;
|
||||
case EnumFace::North:
|
||||
addQuad({x0, y0, z0}, {x0, y1, z0}, {x1, y1, z0}, {x1, y0, z0},
|
||||
{u0, v0}, {u0, v1}, {u1, v1}, {u1, v0});
|
||||
break;
|
||||
default:
|
||||
MAKE_ERROR("EnumFace::None");
|
||||
}
|
||||
@@ -223,6 +236,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
if(!pm.SubModels.empty() && modelAssets) {
|
||||
model.Depends.reserve(pm.SubModels.size());
|
||||
for(const auto& sub : pm.SubModels) {
|
||||
auto iter = modelKeyToId.find(sub.Domain + ':' + sub.Key);
|
||||
if(iter == modelKeyToId.end())
|
||||
continue;
|
||||
model.Depends.emplace_back(iter->second, Transformations{});
|
||||
}
|
||||
}
|
||||
|
||||
// struct Face {
|
||||
// int TintIndex = -1;
|
||||
// int16_t Rotation = 0;
|
||||
@@ -271,12 +294,16 @@ private:
|
||||
Logger LOG = "Client>ModelProvider";
|
||||
// Таблица моделей
|
||||
std::unordered_map<ResourceId, ModelObject> Models;
|
||||
std::unordered_set<ResourceId> MissingModelsLogged;
|
||||
uint64_t UniqId = 0;
|
||||
|
||||
Model getModel(ResourceId id, std::vector<ResourceId>& used) {
|
||||
auto iterModel = Models.find(id);
|
||||
if(iterModel == Models.end()) {
|
||||
// Нет такой модели, ну и хрен с ним
|
||||
if(MissingModelsLogged.insert(id).second) {
|
||||
LOG.warn() << "Missing model id=" << id;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -708,6 +735,15 @@ public:
|
||||
} else if(data.starts_with((const char8_t*) "{")) {
|
||||
type = "InternalJson";
|
||||
// nodestate в json формате
|
||||
} else {
|
||||
type = "InternalBinaryLegacy";
|
||||
// Старый двоичный формат без заголовка "bn"
|
||||
std::u8string patched;
|
||||
patched.reserve(data.size() + 2);
|
||||
patched.push_back(u8'b');
|
||||
patched.push_back(u8'n');
|
||||
patched.append(data);
|
||||
nodestate = PreparedNodeState(patched);
|
||||
}
|
||||
} catch(const std::exception& exc) {
|
||||
LOG.warn() << "Не удалось распарсить nodestate " << type << ":\n\t" << exc.what();
|
||||
@@ -715,6 +751,14 @@ public:
|
||||
}
|
||||
|
||||
Nodestates.insert_or_assign(key, std::move(nodestate));
|
||||
if(key < 64) {
|
||||
auto iter = Nodestates.find(key);
|
||||
if(iter != Nodestates.end()) {
|
||||
LOG.debug() << "Nodestate loaded id=" << key
|
||||
<< " routes=" << iter->second.Routes.size()
|
||||
<< " models=" << iter->second.LocalToModel.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!changedModels.empty()) {
|
||||
@@ -745,11 +789,26 @@ public:
|
||||
// states - Текущие значения состояний ноды
|
||||
std::vector<std::vector<std::pair<float, std::unordered_map<EnumFace, std::vector<NodeVertexStatic>>>>> getModelsForNode(AssetsNodestate id, const std::vector<NodeStateInfo>& statesInfo, const std::unordered_map<std::string, int32_t>& states) {
|
||||
auto iterNodestate = Nodestates.find(id);
|
||||
if(iterNodestate == Nodestates.end())
|
||||
if(iterNodestate == Nodestates.end()) {
|
||||
if(MissingNodestateLogged.insert(id).second) {
|
||||
LOG.warn() << "Missing nodestate id=" << id;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
PreparedNodeState& nodestate = iterNodestate->second;
|
||||
std::vector<uint16_t> routes = nodestate.getModelsForState(statesInfo, states);
|
||||
if(routes.empty()) {
|
||||
int32_t metaValue = 0;
|
||||
if(auto iterMeta = states.find("meta"); iterMeta != states.end())
|
||||
metaValue = iterMeta->second;
|
||||
uint64_t key = (uint64_t(id) << 32) | (uint32_t(metaValue) & 0xffffffffu);
|
||||
if(EmptyRouteLogged.insert(key).second) {
|
||||
LOG.warn() << "No nodestate routes id=" << id
|
||||
<< " meta=" << metaValue
|
||||
<< " total_routes=" << nodestate.Routes.size();
|
||||
}
|
||||
}
|
||||
std::vector<std::vector<std::pair<float, std::unordered_map<EnumFace, std::vector<NodeVertexStatic>>>>> result;
|
||||
|
||||
std::unordered_map<TexturePipeline, uint16_t> pipelineResolveCache;
|
||||
@@ -765,12 +824,12 @@ public:
|
||||
for(const Vertex& v : r) {
|
||||
NodeVertexStatic vert;
|
||||
|
||||
vert.FX = (v.Pos.x+0.5f)*64+224;
|
||||
vert.FY = (v.Pos.y+0.5f)*64+224;
|
||||
vert.FZ = (v.Pos.z+0.5f)*64+224;
|
||||
vert.FX = (v.Pos.x + 16.0f) * 2.0f + 224.0f;
|
||||
vert.FY = (v.Pos.y + 16.0f) * 2.0f + 224.0f;
|
||||
vert.FZ = (v.Pos.z + 16.0f) * 2.0f + 224.0f;
|
||||
|
||||
vert.TU = std::clamp<int32_t>(v.UV.x * (1 << 16), 0, (1 << 16) - 1);
|
||||
vert.TV = std::clamp<int32_t>(v.UV.y * (1 << 16), 0, (1 << 16) - 1);
|
||||
vert.TU = std::clamp<int32_t>(v.UV.x * (1 << 11), 0, (1 << 16) - 1);
|
||||
vert.TV = std::clamp<int32_t>(v.UV.y * (1 << 11), 0, (1 << 16) - 1);
|
||||
|
||||
const TexturePipeline& pipe = model.TextureMap[model.TextureKeys[v.TexId]];
|
||||
if(auto iterPipe = pipelineResolveCache.find(pipe); iterPipe != pipelineResolveCache.end()) {
|
||||
@@ -836,11 +895,17 @@ public:
|
||||
return TP.getTextureId(pipe);
|
||||
}
|
||||
|
||||
bool hasNodestate(AssetsNodestate id) const {
|
||||
return Nodestates.contains(id);
|
||||
}
|
||||
|
||||
private:
|
||||
Logger LOG = "Client>NodestateProvider";
|
||||
ModelProvider& MP;
|
||||
TextureProvider& TP;
|
||||
std::unordered_map<AssetsNodestate, PreparedNodeState> Nodestates;
|
||||
std::unordered_set<AssetsNodestate> MissingNodestateLogged;
|
||||
std::unordered_set<uint64_t> EmptyRouteLogged;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user