diff options
author | kwolekr <kwolekr@minetest.net> | 2015-05-05 16:52:06 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-05-05 16:52:06 -0400 |
commit | 633af58a05fb9b3ad7a0a178011f4243e5f8be2e (patch) | |
tree | 709315cc088d2b3fc2db7c07caf00bd0dd6c053e /src/nodedef.cpp | |
parent | b785577f03d00c83236782876def4c900edbba4e (diff) | |
download | minetest-633af58a05fb9b3ad7a0a178011f4243e5f8be2e.tar.gz minetest-633af58a05fb9b3ad7a0a178011f4243e5f8be2e.tar.bz2 minetest-633af58a05fb9b3ad7a0a178011f4243e5f8be2e.zip |
NodeDefManager: Improve const-correctness of interfaces
- Add ability to explicitly reset NodeResolve state (useful for unittesting)
- Remove non-essential NodeResolve methods modifying state from INodeDefManager
- Add const qualifier to NodeDefManager and ContentFeatures serialize
Diffstat (limited to 'src/nodedef.cpp')
-rw-r--r-- | src/nodedef.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 48207da1f..2442799c7 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -241,7 +241,7 @@ void ContentFeatures::reset() sound_dug = SimpleSoundSpec(); } -void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) +void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const { if(protocol_version < 24){ serializeOld(os, protocol_version); @@ -398,9 +398,9 @@ public: virtual content_t allocateDummy(const std::string &name); virtual void updateAliases(IItemDefManager *idef); virtual void updateTextures(IGameDef *gamedef, - /*argument: */void (*progress_callback)(void *progress_args, u32 progress, u32 max_progress), - /*argument: */void *progress_callback_args); - void serialize(std::ostream &os, u16 protocol_version); + void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress), + void *progress_cbk_args); + void serialize(std::ostream &os, u16 protocol_version) const; void deSerialize(std::istream &is); inline virtual bool getNodeRegistrationStatus() const; @@ -409,6 +409,7 @@ public: virtual void pendNodeResolve(NodeResolver *nr, NodeResolveMethod how); virtual bool cancelNodeResolveCallback(NodeResolver *nr); virtual void runNodeResolveCallbacks(); + virtual void resetNodeResolveState(); private: void addNameIdMapping(content_t i, std::string name); @@ -474,8 +475,7 @@ void CNodeDefManager::clear() m_group_to_items.clear(); m_next_id = 0; - m_node_registration_complete = false; - m_pending_resolve_callbacks.clear(); + resetNodeResolveState(); u32 initial_length = 0; initial_length = MYMAX(initial_length, CONTENT_UNKNOWN + 1); @@ -972,7 +972,7 @@ void CNodeDefManager::fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, #endif -void CNodeDefManager::serialize(std::ostream &os, u16 protocol_version) +void CNodeDefManager::serialize(std::ostream &os, u16 protocol_version) const { writeU8(os, 1); // version u16 count = 0; @@ -981,7 +981,7 @@ void CNodeDefManager::serialize(std::ostream &os, u16 protocol_version) if (i == CONTENT_IGNORE || i == CONTENT_AIR || i == CONTENT_UNKNOWN) continue; - ContentFeatures *f = &m_content_features[i]; + const ContentFeatures *f = &m_content_features[i]; if (f->name == "") continue; writeU16(os2, i); @@ -1062,7 +1062,7 @@ IWritableNodeDefManager *createNodeDefManager() //// Serialization of old ContentFeatures formats -void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version) +void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version) const { if (protocol_version == 13) { @@ -1342,6 +1342,13 @@ void CNodeDefManager::runNodeResolveCallbacks() } +void CNodeDefManager::resetNodeResolveState() +{ + m_node_registration_complete = false; + m_pending_resolve_callbacks.clear(); +} + + //// //// NodeResolver //// |