diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-21 15:48:27 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-21 15:48:27 +1000 |
commit | acc8bc02800ce97dbc5424a3d83a1add1593349d (patch) | |
tree | e1134bc87dbc7ff3a75cbe8766f3fb45ef0ffe9d | |
parent | d6fdd960768cbb94a67a1d3cdd34c606807ac180 (diff) |
EntityUpdate server-side optimization
Cache net states of the same net version. Also moved readNetState after init in EntityCreate, should fix bugs like MovementController rotation not being read.
-rw-r--r-- | source/client/starbound-largelogo.ico | bin | 370070 -> 410598 bytes | |||
-rw-r--r-- | source/client/starbound.ico | bin | 370070 -> 410598 bytes | |||
-rw-r--r-- | source/game/StarWorldClient.cpp | 2 | ||||
-rw-r--r-- | source/game/StarWorldServer.cpp | 15 | ||||
-rw-r--r-- | source/game/StarWorldServer.hpp | 1 |
5 files changed, 12 insertions, 6 deletions
diff --git a/source/client/starbound-largelogo.ico b/source/client/starbound-largelogo.ico Binary files differindex 1483c81..999d921 100644 --- a/source/client/starbound-largelogo.ico +++ b/source/client/starbound-largelogo.ico diff --git a/source/client/starbound.ico b/source/client/starbound.ico Binary files differindex 1483c81..999d921 100644 --- a/source/client/starbound.ico +++ b/source/client/starbound.ico diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 0dfddf8..f8942d2 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -656,8 +656,8 @@ void WorldClient::handleIncomingPackets(List<PacketPtr> const& packets) { } auto entity = entityFactory->netLoadEntity(entityCreate->entityType, entityCreate->storeData); - entity->readNetState(entityCreate->firstNetState); entity->init(this, entityCreate->entityId, EntityMode::Slave); + entity->readNetState(entityCreate->firstNetState); m_entityMap->addEntity(entity); if (m_interpolationTracker.interpolationEnabled()) { diff --git a/source/game/StarWorldServer.cpp b/source/game/StarWorldServer.cpp index 061335f..bf36e62 100644 --- a/source/game/StarWorldServer.cpp +++ b/source/game/StarWorldServer.cpp @@ -392,8 +392,8 @@ void WorldServer::handleIncomingPackets(ConnectionId clientId, List<PacketPtr> c } auto entity = entityFactory->netLoadEntity(entityCreate->entityType, entityCreate->storeData); - entity->readNetState(entityCreate->firstNetState); entity->init(this, entityCreate->entityId, EntityMode::Slave); + entity->readNetState(entityCreate->firstNetState); m_entityMap->addEntity(entity); if (clientInfo->interpolationTracker.interpolationEnabled()) @@ -605,6 +605,7 @@ void WorldServer::update() { signalRegion(monitoredRegion.padded(jsonToVec2I(m_serverConfig.get("playerActiveRegionPad")))); queueUpdatePackets(pair.first); } + m_netStateCache.clear(); for (auto& pair : m_clientInfo) pair.second->pendingForward = false; @@ -1743,10 +1744,14 @@ void WorldServer::queueUpdatePackets(ConnectionId clientId) { if (connectionId != clientId) { if (auto version = clientInfo->clientSlavesNetVersion.ptr(entityId)) { if (auto updateSetPacket = updateSetPackets.value(connectionId)) { - auto updateAndVersion = monitoredEntity->writeNetState(*version); - if (!updateAndVersion.first.empty()) - updateSetPacket->deltas[entityId] = move(updateAndVersion.first); - *version = updateAndVersion.second; + auto pair = make_pair(entityId, *version); + auto i = m_netStateCache.find(pair); + if (i == m_netStateCache.end()) + i = m_netStateCache.insert(pair, move(monitoredEntity->writeNetState(*version))).first; + const auto& netState = i->second; + if (!netState.first.empty()) + updateSetPacket->deltas[entityId] = netState.first; + *version = netState.second; } } else if (!monitoredEntity->masterOnly()) { // Client was unaware of this entity until now diff --git a/source/game/StarWorldServer.hpp b/source/game/StarWorldServer.hpp index 1def4f3..7609cdc 100644 --- a/source/game/StarWorldServer.hpp +++ b/source/game/StarWorldServer.hpp @@ -347,6 +347,7 @@ private: CollisionGenerator m_collisionGenerator; List<CollisionBlock> m_workingCollisionBlocks; + HashMap<pair<EntityId, uint64_t>, pair<ByteArray, uint64_t>> m_netStateCache; OrderedHashMap<ConnectionId, shared_ptr<ClientInfo>> m_clientInfo; GameTimer m_tileEntityBreakCheckTimer; |