diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2022-11-03 17:35:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-03 17:35:31 +0100 |
commit | 322c8cf270a6fe2cd6ac152af0f3f5d2963fa0b3 (patch) | |
tree | 3d8a0adda30a54f9d2b266fda2d9752cf7d848be /src/server.cpp | |
parent | 957a3e52fe2706f419b9357090829c10ccd8aef7 (diff) | |
download | minetest-322c8cf270a6fe2cd6ac152af0f3f5d2963fa0b3.tar.xz |
Reduce exposure of various internals (#12885)
* refactoring(StaticObjectList): don't expose m_active and m_stored anymore
This prevents our old crap code where anyone can access to StaticObjectList. use proper modifiers. It also permits to do a short cleanup on MapBlock using a helper
* refactoring(MapBlock): reduce a bit exposed m_active_blocks variable
* refactoring: MapBlock::m_node_timers is now private
We already had various helpers to perform this privatization, just use it. Also factorize the MapBlock stepping code for timers using already existing code and importing them from ServerEnvironment to MapBlock.
It's currently done pretty straight forward without any inheritance as MapBlock is just used everywhere, maybe in a future we'll have ServerMapBlock over MapBlock. Currently for a simple function let's just use proper objects and add a comment warning
* refactoring(Server): fix duplicated function for add/remove node
* refactoring(guiFormSpecMenu): add removeAll function to prevent duplicated code
* refactoring(ShadowRenderer) + perf: code quality + increase performance
* All callers are already using the point and we should never test a function with nullptr node, it's a bug. Removed workaround which was hacky and fix the bug
* Drop clientmap lookup from shadowrendered, just use directly its
pointer and forbid to push it in the generic list
* Reduce memory pressure on the renderShadowObject by preventing
deallocating and reallocating multiple vectors on each node
* refactoring(MapBlock): reduce exposure of MapBlock::m_static_objects
It's not complete as some parts of the code are pretty nested, but it's better than before :)
* fix: better working on new functions & drop unwanted 2 lines
Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com>
Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com>
Diffstat (limited to 'src/server.cpp')
-rw-r--r-- | src/server.cpp | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/src/server.cpp b/src/server.cpp index 5451e3833..10c41bc76 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1870,7 +1870,7 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting) { NetworkPacket pkt(TOCLIENT_SET_LIGHTING, 4, peer_id); - + pkt << lighting.shadow_intensity; Send(&pkt); @@ -2251,50 +2251,31 @@ void Server::fadeSound(s32 handle, float step, float gain) void Server::sendRemoveNode(v3s16 p, std::unordered_set<u16> *far_players, float far_d_nodes) { - float maxd = far_d_nodes * BS; v3f p_f = intToFloat(p, BS); v3s16 block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_REMOVENODE, 6); pkt << p; - std::vector<session_t> clients = m_clients.getClientIDs(); - ClientInterface::AutoLock clientlock(m_clients); - - for (session_t client_id : clients) { - RemoteClient *client = m_clients.lockedGetClientNoEx(client_id); - if (!client) - continue; - - RemotePlayer *player = m_env->getPlayer(client_id); - PlayerSAO *sao = player ? player->getPlayerSAO() : nullptr; - - // If player is far away, only set modified blocks not sent - if (!client->isBlockSent(block_pos) || (sao && - sao->getBasePosition().getDistanceFrom(p_f) > maxd)) { - if (far_players) - far_players->emplace(client_id); - else - client->SetBlockNotSent(block_pos); - continue; - } - - // Send as reliable - m_clients.send(client_id, 0, &pkt, true); - } + sendNodeChangePkt(pkt, block_pos, p_f, far_d_nodes, far_players); } void Server::sendAddNode(v3s16 p, MapNode n, std::unordered_set<u16> *far_players, float far_d_nodes, bool remove_metadata) { - float maxd = far_d_nodes * BS; v3f p_f = intToFloat(p, BS); v3s16 block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1); pkt << p << n.param0 << n.param1 << n.param2 << (u8) (remove_metadata ? 0 : 1); + sendNodeChangePkt(pkt, block_pos, p_f, far_d_nodes, far_players); +} +void Server::sendNodeChangePkt(NetworkPacket &pkt, v3s16 block_pos, + v3f p, float far_d_nodes, std::unordered_set<u16> *far_players) +{ + float maxd = far_d_nodes * BS; std::vector<session_t> clients = m_clients.getClientIDs(); ClientInterface::AutoLock clientlock(m_clients); @@ -2308,7 +2289,7 @@ void Server::sendAddNode(v3s16 p, MapNode n, std::unordered_set<u16> *far_player // If player is far away, only set modified blocks not sent if (!client->isBlockSent(block_pos) || (sao && - sao->getBasePosition().getDistanceFrom(p_f) > maxd)) { + sao->getBasePosition().getDistanceFrom(p) > maxd)) { if (far_players) far_players->emplace(client_id); else |