aboutsummaryrefslogtreecommitdiff
path: root/src/staticobject.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2022-11-03 17:35:31 +0100
committerGitHub <noreply@github.com>2022-11-03 17:35:31 +0100
commit322c8cf270a6fe2cd6ac152af0f3f5d2963fa0b3 (patch)
tree3d8a0adda30a54f9d2b266fda2d9752cf7d848be /src/staticobject.cpp
parent957a3e52fe2706f419b9357090829c10ccd8aef7 (diff)
downloadminetest-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/staticobject.cpp')
-rw-r--r--src/staticobject.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/staticobject.cpp b/src/staticobject.cpp
index f92995d0b..d728f5d10 100644
--- a/src/staticobject.cpp
+++ b/src/staticobject.cpp
@@ -99,6 +99,7 @@ void StaticObjectList::serialize(std::ostream &os)
s_obj.serialize(os);
}
}
+
void StaticObjectList::deSerialize(std::istream &is)
{
if (m_active.size()) {
@@ -121,3 +122,13 @@ void StaticObjectList::deSerialize(std::istream &is)
}
}
+bool StaticObjectList::storeActiveObject(u16 id)
+{
+ const auto i = m_active.find(id);
+ if (i == m_active.end())
+ return false;
+
+ m_stored.push_back(i->second);
+ m_active.erase(id);
+ return true;
+}