Minetest  5.4.0
NodeDefManager Class Reference

This class is for getting the actual properties of nodes from their content ID. More...

#include <nodedef.h>

+ Collaboration diagram for NodeDefManager:

Public Member Functions

 NodeDefManager ()
 
 ~NodeDefManager ()
 
const ContentFeaturesget (content_t c) const
 
const ContentFeaturesget (const MapNode &n) const
 
const ContentFeaturesget (const std::string &name) const
 
bool getId (const std::string &name, content_t &result) const
 
content_t getId (const std::string &name) const
 
bool getIds (const std::string &name, std::vector< content_t > &result) const
 
core::aabbox3d< s16 > getSelectionBoxIntUnion () const
 
bool nodeboxConnects (MapNode from, MapNode to, u8 connect_face) const
 
void pendNodeResolve (NodeResolver *nr) const
 
bool cancelNodeResolveCallback (NodeResolver *nr) const
 
content_t set (const std::string &name, const ContentFeatures &def)
 
content_t allocateDummy (const std::string &name)
 
void removeNode (const std::string &name)
 
void updateAliases (IItemDefManager *idef)
 
void applyTextureOverrides (const std::vector< TextureOverride > &overrides)
 
void updateTextures (IGameDef *gamedef, 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)
 
void setNodeRegistrationStatus (bool completed)
 
void runNodeResolveCallbacks ()
 
void resetNodeResolveState ()
 
void resolveCrossrefs ()
 

Private Member Functions

void clear ()
 
content_t allocateId ()
 
void addNameIdMapping (content_t i, std::string name)
 
void eraseIdFromGroups (content_t id)
 
void fixSelectionBoxIntUnion ()
 

Private Attributes

std::vector< ContentFeaturesm_content_features
 Features indexed by ID. More...
 
NameIdMapping m_name_id_mapping
 A mapping for fast conversion between names and IDs. More...
 
std::unordered_map< std::string, content_tm_name_id_mapping_with_aliases
 
std::unordered_map< std::string, std::vector< content_t > > m_group_to_items
 
content_t m_next_id
 
bool m_node_registration_complete
 True if all nodes have been registered. More...
 
aabb3f m_selection_box_union
 
core::aabbox3d< s16 > m_selection_box_int_union
 
std::vector< NodeResolver * > m_pending_resolve_callbacks
 

Detailed Description

This class is for getting the actual properties of nodes from their content ID.

The nodes on the map are represented by three numbers (see MapNode). The first number (param0) is the type of a node. All node types have own properties (see ContentFeatures). This class is for storing and getting the properties of nodes. The manager is first filled with registered nodes, then as the game begins, functions only get const pointers to it, to prevent modification of registered nodes.

Constructor & Destructor Documentation

◆ NodeDefManager()

NodeDefManager::NodeDefManager ( )

Creates a NodeDefManager, and registers three ContentFeatures: CONTENT_AIR, CONTENT_UNKNOWN and CONTENT_IGNORE.

References clear().

+ Here is the call graph for this function:

◆ ~NodeDefManager()

NodeDefManager::~NodeDefManager ( )

References m_content_features.

Member Function Documentation

◆ addNameIdMapping()

void NodeDefManager::addNameIdMapping ( content_t  i,
std::string  name 
)
private

Binds the given content ID and node name. Registers them in m_name_id_mapping and m_name_id_mapping_with_aliases.

Parameters
ia content ID
namea node name

References m_name_id_mapping, m_name_id_mapping_with_aliases, and NameIdMapping::set().

Referenced by clear(), deSerialize(), and set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ allocateDummy()

content_t NodeDefManager::allocateDummy ( const std::string &  name)

Allocates a blank node ID for the given name.

Parameters
namename of a node
Returns
allocated ID or CONTENT_IGNORE if could not allocate an ID.

References ContentFeatures::name, and set().

Referenced by Server::allocateUnknownNodeId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ allocateId()

content_t NodeDefManager::allocateId ( )
private

Allocates a new content ID, and returns it.

Returns
the allocated ID or CONTENT_IGNORE if could not allocate

References CONTENT_IGNORE, m_content_features, m_next_id, and ContentFeatures::name.

Referenced by set().

+ Here is the caller graph for this function:

◆ applyTextureOverrides()

void NodeDefManager::applyTextureOverrides ( const std::vector< TextureOverride > &  overrides)

Replaces the textures of registered nodes with the ones specified in the texturepack's override.txt file

Parameters
overridesthe texture overrides

References BACK, BOTTOM, FRONT, getId(), infostream, LEFT, m_content_features, TileDef::name, RIGHT, SPECIAL_1, SPECIAL_2, SPECIAL_3, SPECIAL_4, SPECIAL_5, SPECIAL_6, ContentFeatures::tiledef, ContentFeatures::tiledef_special, and TOP.

Referenced by Client::afterContentReceived(), and Server::init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cancelNodeResolveCallback()

bool NodeDefManager::cancelNodeResolveCallback ( NodeResolver nr) const

Stops listening to the NodeDefManager.

Returns
true if the listener was registered before, false otherwise

References m_pending_resolve_callbacks.

Referenced by NodeResolver::~NodeResolver(), and TestNodeResolver::testPendingResolveCancellation().

+ Here is the caller graph for this function:

◆ clear()

void NodeDefManager::clear ( )
private

Resets the manager to its initial state. See the documentation of the constructor.

References addNameIdMapping(), ContentFeatures::buildable_to, NameIdMapping::clear(), CONTENT_AIR, CONTENT_IGNORE, CONTENT_UNKNOWN, CPT_LIGHT, CPT_NONE, ContentFeatures::diggable, ContentFeatures::drawtype, ContentFeatures::floodable, ContentFeatures::is_ground_content, ContentFeatures::light_propagates, m_content_features, m_group_to_items, m_name_id_mapping, m_name_id_mapping_with_aliases, m_next_id, m_selection_box_int_union, m_selection_box_union, MYMAX, ContentFeatures::name, NDT_AIRLIKE, ContentFeatures::param_type, ContentFeatures::pointable, resetNodeResolveState(), ContentFeatures::sunlight_propagates, and ContentFeatures::walkable.

Referenced by NodeDefManager(), and deSerialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deSerialize()

void NodeDefManager::deSerialize ( std::istream &  is)

Restores the manager from a serialized stream. This clears the previous state.

Parameters
isinput stream containing a serialized NodeDefManager

References addNameIdMapping(), clear(), CONTENT_AIR, CONTENT_IGNORE, CONTENT_UNKNOWN, ContentFeatures::deSerialize(), deSerializeString16(), deSerializeString32(), fixSelectionBoxIntUnion(), NameIdMapping::getId(), getNodeBoxUnion(), m_content_features, m_name_id_mapping, m_selection_box_union, ContentFeatures::name, readU16(), readU8(), resolveCrossrefs(), ContentFeatures::selection_box, TRACESTREAM, and warningstream.

Referenced by Client::handleCommand_NodeDef().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eraseIdFromGroups()

void NodeDefManager::eraseIdFromGroups ( content_t  id)
private

Removes a content ID from all groups. Erases content IDs from vectors in m_group_to_items and removes empty vectors.

Parameters
idContent ID

References m_group_to_items.

Referenced by removeNode(), and set().

+ Here is the caller graph for this function:

◆ fixSelectionBoxIntUnion()

void NodeDefManager::fixSelectionBoxIntUnion ( )
inlineprivate

Recalculates m_selection_box_int_union based on m_selection_box_union.

References BS, m_selection_box_int_union, and m_selection_box_union.

Referenced by deSerialize(), and set().

+ Here is the caller graph for this function:

◆ get() [1/3]

const ContentFeatures& NodeDefManager::get ( const MapNode n) const
inline

Returns the properties of the given node.

Parameters
na map node
Returns
properties of the given node or CONTENT_UNKNOWN if the given content type is not registered.

References get(), and MapNode::getContent().

+ Here is the call graph for this function:

◆ get() [2/3]

const ContentFeatures & NodeDefManager::get ( const std::string &  name) const

Returns the node properties for a node name.

Parameters
namename of a node
Returns
properties of the given node or CONTENT_UNKNOWN if not found

References CONTENT_UNKNOWN, get(), and getId().

+ Here is the call graph for this function:

◆ get() [3/3]

const ContentFeatures& NodeDefManager::get ( content_t  c) const
inline

Returns the properties for the given content type.

Parameters
ccontent type of a node
Returns
properties of the given content type, or CONTENT_UNKNOWN if the given content type is not registered.

References CONTENT_UNKNOWN, and m_content_features.

Referenced by MapgenSinglenode::MapgenSinglenode(), RollbackNode::RollbackNode(), Map::addNodeAndUpdate(), RollbackAction::applyRevert(), voxalgo::blit_back_with_light(), Minimap::blitMinimapPixelsToImageSurface(), Pathfinder::calcCost(), CavesRandomWalk::carveRoute(), CavesV6::carveRoute(), collisionMoveSimple(), MapBlock::deSerialize_pre22(), MapblockMeshGenerator::drawFencelikeNode(), MapblockMeshGenerator::drawLiquidSides(), MapblockMeshGenerator::drawRaillikeNode(), MapgenBasic::dustTopNodes(), face_contents(), voxalgo::fill_with_sunlight(), Mapgen::findGroundLevel(), Mapgen::findLiquidSurface(), Server::findSpawnPos(), ServerEnvironment::findSunlight(), voxalgo::finish_bulk_light_update(), MapgenV6::flowMud(), MapblockMeshGenerator::generate(), DungeonGen::generate(), generate_nodelist_and_update_ids(), CavernsNoise::generateCaverns(), CavesNoiseIntersection::generateCaves(), get(), ClientMap::getBackgroundBrightness(), getBlockNodeIdMapping(), MapNode::getCollisionBoxes(), MapNode::getFaceDir(), getFaceLight(), MapBlock::getGroundLevel(), getItemMesh(), MapNode::getLevel(), MapNode::getLight(), MapNode::getLightBanks(), MapblockMeshGenerator::getLiquidNeighborhood(), MapNode::getMaxLevel(), MapNode::getNeighbors(), MapNode::getNodeBoxes(), getNodeTileN(), Pathfinder::getPath(), MapNode::getSelectionBoxes(), LocalPlayer::getSlipFactor(), getSmoothLightCombined(), Mapgen::getSurfaces(), getTileInfo(), getVisibleBrightness(), MapNode::getWallMounted(), MapgenV6::growGrass(), LocalPlayer::handleAutojump(), Server::handleCommand_Interact(), Game::handleDigging(), ParticleManager::handleParticleEvent(), Game::handlePointingAtNode(), GridNodeContainer::initNode(), voxalgo::is_light_locally_correct(), RollbackAction::isImportant(), MapNode::isLightDayNightEq(), ReflowScan::isLiquidFlowableTo(), Mapgen::isLiquidHorizontallyFlowable(), Map::isOccluded(), isPointableNode(), MapblockMeshGenerator::isSameRail(), ModApiEnvMod::l_find_nodes_in_area(), ModApiItemMod::l_get_name_from_content_id(), ModApiClient::l_get_node_def(), ModApiEnvMod::l_place_node(), Mapgen::lightSpread(), LocalPlayer::move(), ScriptApiNode::node_after_destruct(), ScriptApiNode::node_on_construct(), ScriptApiNode::node_on_destruct(), ScriptApiNode::node_on_dig(), ScriptApiNode::node_on_flood(), ScriptApiNode::node_on_punch(), ScriptApiNode::node_on_receive_fields(), ScriptApiNode::node_on_timer(), nodeboxConnects(), SoundMaker::nodeDug(), ScriptApiNodemeta::nodemeta_inventory_AllowMove(), ScriptApiNodemeta::nodemeta_inventory_AllowPut(), ScriptApiNodemeta::nodemeta_inventory_AllowTake(), ScriptApiNodemeta::nodemeta_inventory_OnMove(), ScriptApiNodemeta::nodemeta_inventory_OnPut(), ScriptApiNodemeta::nodemeta_inventory_OnTake(), Game::nodePlacement(), LocalPlayer::old_move(), MapblockMeshGenerator::prepareLiquidNodeDrawing(), VoxelManipulator::print(), voxalgo::propagate_block_sunlight(), Mapgen::propagateSunlight(), pushnode(), ServerEnvironment::removeNode(), ClientMap::renderPostFx(), MapblockMeshGenerator::renderSingle(), voxalgo::repair_block_light(), MapNode::rotateAlongYAxis(), ReflowScan::scanColumn(), WieldMeshSceneNode::setItem(), MapNode::setLevel(), MapNode::setLight(), ServerEnvironment::setNode(), Map::setNode(), ParticleSpawner::spawnParticle(), voxalgo::spread_light(), Mapgen::spreadLight(), PlayerSAO::step(), GenericCAO::step(), TestMapNode::testNodeProperties(), Map::transformLiquids(), voxalgo::unspread_light(), GameUI::update(), Camera::update(), voxalgo::update_lighting_nodes(), ClientMap::updateDrawList(), Mapgen::updateLiquid(), LocalPlayer::updateSneakNode(), Game::updateSound(), and Pathfinder::walkDownwards().

◆ getId() [1/2]

content_t NodeDefManager::getId ( const std::string &  name) const

Returns the content ID for the given name.

Parameters
namea node name
Returns
ID of the node or CONTENT_IGNORE if not found

References CONTENT_IGNORE, and getId().

+ Here is the call graph for this function:

◆ getId() [2/2]

bool NodeDefManager::getId ( const std::string &  name,
content_t result 
) const

◆ getIds()

bool NodeDefManager::getIds ( const std::string &  name,
std::vector< content_t > &  result 
) const

Returns the content IDs of the given node name or node group name. Group names start with "group:".

Parameters
namea node name or node group name
[out]resultwill be appended with matching IDs
Returns
true if name is a valid node name or a (not necessarily valid) group name

References CONTENT_IGNORE, getId(), and m_group_to_items.

Referenced by ABMHandler::ABMHandler(), LBMContentMapping::addLBM(), ModApiEnvMod::collectNodeIds(), NodeResolver::getIdsFromNrBacklog(), and resolveCrossrefs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSelectionBoxIntUnion()

core::aabbox3d<s16> NodeDefManager::getSelectionBoxIntUnion ( ) const
inline

Returns the smallest box in integer node coordinates that contains all nodes' selection boxes. The returned box might be larger than the minimal size if the largest node is removed from the manager.

References m_selection_box_int_union.

Referenced by Environment::continueRaycast().

+ Here is the caller graph for this function:

◆ nodeboxConnects()

bool NodeDefManager::nodeboxConnects ( MapNode  from,
MapNode  to,
u8  connect_face 
) const

Checks whether a node connects to an adjacent node.

Parameters
fromthe node to be checked
tothe adjacent node
connect_facea bit field indicating which face of the node is adjacent to the other node. Bits: +y (least significant), -y, -z, -x, +z, +x (most significant).
Returns
true if the node connects, false otherwise

References ContentFeatures::connect_sides, ContentFeatures::connects_to_ids, CONTAINS, CPT2_COLORED_FACEDIR, CPT2_FACEDIR, ContentFeatures::drawtype, get(), NDT_NODEBOX, ContentFeatures::node_box, NODEBOX_CONNECTED, MapNode::param0, MapNode::param2, ContentFeatures::param_type_2, and NodeBox::type.

Referenced by MapblockMeshGenerator::drawNodeboxNode(), and getNeighborConnectingFace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pendNodeResolve()

void NodeDefManager::pendNodeResolve ( NodeResolver nr) const

Registers a NodeResolver to wait for the registration of ContentFeatures. Once the node registration finishes, all listeners are notified.

References NodeResolver::m_ndef, m_node_registration_complete, m_pending_resolve_callbacks, and NodeResolver::nodeResolveInternal().

Referenced by BiomeManager::BiomeManager(), ModApiMapgen::l_register_decoration(), ModApiMapgen::l_register_ore(), load_schematic_from_def(), Schematic::loadSchematicFromFile(), read_biome_def(), TestNodeResolver::testNodeResolving(), and TestNodeResolver::testPendingResolveCancellation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeNode()

void NodeDefManager::removeNode ( const std::string &  name)

Removes the given node name from the manager. The node ID will remain in the manager, but won't be linked to any name.

Parameters
namename to be removed

References CONTENT_IGNORE, eraseIdFromGroups(), NameIdMapping::eraseName(), NameIdMapping::getId(), m_name_id_mapping, and m_name_id_mapping_with_aliases.

Referenced by ModApiItemMod::l_unregister_item_raw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetNodeResolveState()

void NodeDefManager::resetNodeResolveState ( )

Sets the registration completion flag to false and unregisters all NodeResolver instances listening to the manager.

References m_node_registration_complete, and m_pending_resolve_callbacks.

Referenced by clear(), TestNodeResolver::runTests(), and TestSchematic::runTests().

+ Here is the caller graph for this function:

◆ resolveCrossrefs()

void NodeDefManager::resolveCrossrefs ( )

Resolves (caches the IDs) cross-references between nodes, like liquid alternatives. Must be called after node registration has finished!

References getId(), getIds(), LIQUID_NONE, m_content_features, NDT_FLOWINGLIQUID, NDT_LIQUID, NDT_NODEBOX, NODEBOX_CONNECTED, and removeDupes().

Referenced by deSerialize(), and Server::init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ runNodeResolveCallbacks()

void NodeDefManager::runNodeResolveCallbacks ( )

Notifies the registered NodeResolver instances that node registration has finished, then unregisters all listeners. Must be called after node registration has finished!

References m_pending_resolve_callbacks, and NodeResolver::nodeResolveInternal().

Referenced by Client::afterContentReceived(), Server::init(), TestNodeResolver::testNodeResolving(), and TestNodeResolver::testPendingResolveCancellation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialize()

void NodeDefManager::serialize ( std::ostream &  os,
u16  protocol_version 
) const

Writes the content of this manager to the given output stream.

Parameters
protocol_versionserialization version of ContentFeatures

References CONTENT_AIR, CONTENT_IGNORE, CONTENT_UNKNOWN, FATAL_ERROR_IF, m_content_features, ContentFeatures::name, ContentFeatures::serialize(), serializeString16(), serializeString32(), writeU16(), and writeU8().

Referenced by Server::SendNodeDef().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set()

content_t NodeDefManager::set ( const std::string &  name,
const ContentFeatures def 
)

Registers a new node type with the given name and allocates a new content ID. Should not be called with an already existing name.

Parameters
namename of the node, must match with def.name.
defdefinition of the registered node type.
Returns
ID of the registered node or CONTENT_IGNORE if the function could not allocate an ID.

References addNameIdMapping(), allocateId(), CONTENT_IGNORE, eraseIdFromGroups(), fixSelectionBoxIntUnion(), NameIdMapping::getId(), getNodeBoxUnion(), ContentFeatures::groups, m_content_features, m_group_to_items, m_name_id_mapping, m_selection_box_union, ContentFeatures::name, ContentFeatures::selection_box, verbosestream, and warningstream.

Referenced by allocateDummy(), TestGameDef::defineSomeNodes(), and ModApiItemMod::l_register_item_raw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setNodeRegistrationStatus()

void NodeDefManager::setNodeRegistrationStatus ( bool  completed)
inline

Used to indicate that node registration has finished.

Parameters
completedtells whether registration is complete

References m_node_registration_complete.

Referenced by Client::afterContentReceived(), Server::init(), TestSchematic::runTests(), TestNodeResolver::testNodeResolving(), and TestNodeResolver::testPendingResolveCancellation().

+ Here is the caller graph for this function:

◆ updateAliases()

void NodeDefManager::updateAliases ( IItemDefManager idef)

Regenerates the alias list (a map from names to node IDs).

Parameters
idefthe item definition manager containing alias information

References IItemDefManager::getAlias(), IItemDefManager::getAll(), NameIdMapping::getId(), m_name_id_mapping, and m_name_id_mapping_with_aliases.

Referenced by Client::afterContentReceived(), and Server::init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateTextures()

void NodeDefManager::updateTextures ( IGameDef gamedef,
void(*)(void *progress_args, u32 progress, u32 max_progress)  progress_cbk,
void *  progress_cbk_args 
)

Only the client uses this. Loads textures and shaders required for rendering the nodes.

Parameters
gamedefmust be a Client.
progress_cbkcalled each time a node is loaded. Arguments: progress_cbk_args, number of loaded ContentFeatures, number of total ContentFeatures.
progress_cbk_argspassed to the callback function

References RenderingEngine::get_scene_manager(), infostream, m_content_features, TextureSettings::readSettings(), and ContentFeatures::updateTextures().

Referenced by Client::afterContentReceived().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_content_features

std::vector<ContentFeatures> NodeDefManager::m_content_features
private

◆ m_group_to_items

std::unordered_map<std::string, std::vector<content_t> > NodeDefManager::m_group_to_items
private

A mapping from group names to a vector of content types that belong to it. Necessary for a direct lookup in getIds(). Note: Not serialized.

Referenced by clear(), eraseIdFromGroups(), getIds(), and set().

◆ m_name_id_mapping

NameIdMapping NodeDefManager::m_name_id_mapping
private

A mapping for fast conversion between names and IDs.

Referenced by addNameIdMapping(), clear(), deSerialize(), removeNode(), set(), and updateAliases().

◆ m_name_id_mapping_with_aliases

std::unordered_map<std::string, content_t> NodeDefManager::m_name_id_mapping_with_aliases
private

Like m_name_id_mapping, but maps only from names to IDs, and includes aliases too. Updated by updateAliases(). Note: Not serialized.

Referenced by addNameIdMapping(), clear(), getId(), removeNode(), and updateAliases().

◆ m_next_id

content_t NodeDefManager::m_next_id
private

The next ID that might be free to allocate. It can be allocated already, because CONTENT_AIR, CONTENT_UNKNOWN and CONTENT_IGNORE are registered when the manager is initialized, and new IDs are allocated from 0.

Referenced by allocateId(), and clear().

◆ m_node_registration_complete

bool NodeDefManager::m_node_registration_complete
private

True if all nodes have been registered.

Referenced by pendNodeResolve(), resetNodeResolveState(), and setNodeRegistrationStatus().

◆ m_pending_resolve_callbacks

std::vector<NodeResolver *> NodeDefManager::m_pending_resolve_callbacks
mutableprivate

NodeResolver instances to notify once node registration has finished. Even constant NodeDefManager instances can register listeners.

Referenced by cancelNodeResolveCallback(), pendNodeResolve(), resetNodeResolveState(), and runNodeResolveCallbacks().

◆ m_selection_box_int_union

core::aabbox3d<s16> NodeDefManager::m_selection_box_int_union
private

The smallest box in integer node coordinates that contains all nodes' selection boxes. Might be larger if big nodes are removed from the manager.

Referenced by clear(), fixSelectionBoxIntUnion(), and getSelectionBoxIntUnion().

◆ m_selection_box_union

aabb3f NodeDefManager::m_selection_box_union
private

The union of all nodes' selection boxes. Might be larger if big nodes are removed from the manager.

Referenced by clear(), deSerialize(), fixSelectionBoxIntUnion(), and set().


The documentation for this class was generated from the following files: