This class is for getting the actual properties of nodes from their content ID. More...
#include <nodedef.h>
Public Member Functions | |
NodeDefManager () | |
~NodeDefManager () | |
const ContentFeatures & | get (content_t c) const |
const ContentFeatures & | get (const MapNode &n) const |
ContentLightingFlags | getLightingFlags (content_t c) const |
ContentLightingFlags | getLightingFlags (const MapNode &n) const |
const ContentFeatures & | get (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_args) |
void | serialize (std::ostream &os, u16 protocol_version) const |
void | deSerialize (std::istream &is, u16 protocol_version) |
void | setNodeRegistrationStatus (bool completed) |
void | runNodeResolveCallbacks () |
void | resetNodeResolveState () |
void | resolveCrossrefs () |
Private Member Functions | |
void | clear () |
content_t | allocateId () |
void | addNameIdMapping (content_t i, const std::string &name) |
void | eraseIdFromGroups (content_t id) |
void | fixSelectionBoxIntUnion () |
Private Attributes | |
std::vector< ContentFeatures > | m_content_features |
Features indexed by ID. | |
NameIdMapping | m_name_id_mapping |
A mapping for fast conversion between names and IDs. | |
std::unordered_map< std::string, content_t > | m_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. | |
aabb3f | m_selection_box_union |
core::aabbox3d< s16 > | m_selection_box_int_union |
std::vector< NodeResolver * > | m_pending_resolve_callbacks |
ContentLightingFlags | m_content_lighting_flag_cache [CONTENT_MAX+1L] |
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.
NodeDefManager::NodeDefManager | ( | ) |
Creates a NodeDefManager, and registers three ContentFeatures: CONTENT_AIR, CONTENT_UNKNOWN and CONTENT_IGNORE.
References clear().
NodeDefManager::~NodeDefManager | ( | ) |
References m_content_features.
|
private |
Binds the given content ID and node name. Registers them in m_name_id_mapping and m_name_id_mapping_with_aliases.
i | a content ID |
name | a node name |
References m_name_id_mapping, m_name_id_mapping_with_aliases, and NameIdMapping::set().
Referenced by clear(), deSerialize(), and set().
content_t NodeDefManager::allocateDummy | ( | const std::string & | name | ) |
Allocates a blank node ID for the given name.
name | name of a node |
References ContentFeatures::name, and set().
Referenced by DummyGameDef::allocateUnknownNodeId(), and Server::allocateUnknownNodeId().
|
private |
Allocates a new content ID, and returns it.
References CONTENT_IGNORE, m_content_features, m_next_id, and ContentFeatures::name.
Referenced by set().
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
overrides | the texture overrides |
References ALIGN_STYLE_WORLD, BACK, BOTTOM, FRONT, getId(), infostream, LEFT, m_content_features, 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().
bool NodeDefManager::cancelNodeResolveCallback | ( | NodeResolver * | nr | ) | const |
Stops listening to the NodeDefManager.
References m_pending_resolve_callbacks.
Referenced by NodeResolver::~NodeResolver(), and TestNodeResolver::testPendingResolveCancellation().
|
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_MAX, CONTENT_UNKNOWN, CPT_LIGHT, CPT_NONE, ContentFeatures::diggable, ContentFeatures::drawtype, ContentFeatures::floodable, ContentFeatures::getLightingFlags(), ContentFeatures::is_ground_content, ContentFeatures::light_propagates, m_content_features, m_content_lighting_flag_cache, 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, TileDef::name, NDT_AIRLIKE, ContentFeatures::param_type, ContentFeatures::pointable, POINTABLE_NOT, resetNodeResolveState(), ContentFeatures::sunlight_propagates, ContentFeatures::tiledef, and ContentFeatures::walkable.
Referenced by NodeDefManager(), and deSerialize().
void NodeDefManager::deSerialize | ( | std::istream & | is, |
u16 | protocol_version ) |
Restores the manager from a serialized stream. This clears the previous state.
is | input stream containing a serialized NodeDefManager |
protocol_version | Active network protocol version |
References addNameIdMapping(), clear(), CONTENT_AIR, CONTENT_IGNORE, CONTENT_UNKNOWN, ContentFeatures::deSerialize(), deSerializeString16(), deSerializeString32(), fixSelectionBoxIntUnion(), NameIdMapping::getId(), ContentFeatures::getLightingFlags(), getNodeBoxUnion(), ContentFeatures::groups, itemgroup_get(), m_content_features, m_content_lighting_flag_cache, m_name_id_mapping, m_selection_box_union, ContentFeatures::name, readU16(), readU8(), resolveCrossrefs(), ContentFeatures::selection_box, TRACESTREAM, and warningstream.
Referenced by Client::handleCommand_NodeDef().
|
private |
Removes a content ID from all groups. Erases content IDs from vectors in m_group_to_items and removes empty vectors.
id | Content ID |
References m_group_to_items.
Referenced by removeNode(), and set().
|
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().
|
inline |
Returns the properties of the given node.
n | a map node |
References get(), and MapNode::getContent().
const ContentFeatures & NodeDefManager::get | ( | const std::string & | name | ) | const |
Returns the node properties for a node name.
name | name of a node |
References CONTENT_UNKNOWN, get(), and getId().
|
inline |
Returns the properties for the given content type.
c | content type of a node |
References CONTENT_UNKNOWN, and m_content_features.
Referenced by RollbackNode::RollbackNode(), ServerMap::addNodeAndUpdate(), RollbackAction::applyRevert(), Minimap::blitMinimapPixelsToImageSurface(), Pathfinder::calcCost(), CavesRandomWalk::carveRoute(), CavesV6::carveRoute(), Schematic::condenseContentIds(), MapBlock::deSerialize_pre22(), MapblockMeshGenerator::drawFencelikeNode(), MapblockMeshGenerator::drawLiquidSides(), MapblockMeshGenerator::drawNodeboxNode(), MapblockMeshGenerator::drawSolidNode(), MapgenBasic::dustTopNodes(), Mapgen::findGroundLevel(), Mapgen::findLiquidSurface(), ModApiEnvBase::findNodesInArea(), Server::findSpawnPos(), ServerEnvironment::findSunlight(), MapgenV6::flowMud(), DungeonGen::generate(), MapblockMeshGenerator::generate(), CavernsNoise::generateCaverns(), CavesNoiseIntersection::generateCaves(), get(), get(), get_solid_sides(), getBlockNodeIdMapping(), MapNode::getCollisionBoxes(), MapNode::getDegRotate(), MapNode::getFaceDir(), getItemMesh(), MapNode::getLevel(), MapblockMeshGenerator::getLiquidNeighborhood(), MapNode::getMaxLevel(), MapNode::getNeighbors(), MapNode::getNodeBoxes(), getNodeTileN(), Pathfinder::getPath(), MapNode::getSelectionBoxes(), LocalPlayer::getSlipFactor(), getSmoothLightCombined(), Mapgen::getSurfaces(), MapNode::getWallMounted(), MapgenV6::growGrass(), LocalPlayer::handleAutojump(), Server::handleCommand_Interact(), Game::handleDigging(), ParticleManager::handleParticleEvent(), Game::handlePointingAtNode(), GridNodeContainer::initNode(), RollbackAction::isImportant(), ReflowScan::isLiquidFlowableTo(), Mapgen::isLiquidHorizontallyFlowable(), isPointableNode(), MapblockMeshGenerator::isSameRail(), ModApiItem::l_get_name_from_content_id(), ModApiClient::l_get_node_def(), ModApiEnv::l_place_node(), ModApiMapgen::l_read_schematic(), MapgenSinglenode::makeChunk(), 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(), ServerEnvironment::removeNode(), ClientMap::renderPostFx(), MapblockMeshGenerator::renderSingle(), MapNode::rotateAlongYAxis(), ReflowScan::scanColumn(), Schematic::serializeToLua(), set_node_in_block(), WieldMeshSceneNode::setItem(), MapNode::setLevel(), ServerEnvironment::setNode(), ParticleSpawner::spawnParticle(), GenericCAO::step(), PlayerSAO::step(), TestMapNode::testNodeProperties(), TestMapBlock::testSaveLoad(), ServerMap::transformLiquids(), Camera::update(), GameUI::update(), ClientMap::updateDrawList(), Mapgen::updateLiquid(), LocalPlayer::updateSneakNode(), Game::updateSound(), and Pathfinder::walkDownwards().
content_t NodeDefManager::getId | ( | const std::string & | name | ) | const |
Returns the content ID for the given name.
name | a node name |
References CONTENT_IGNORE, and getId().
bool NodeDefManager::getId | ( | const std::string & | name, |
content_t & | result ) const |
Returns the content ID for the given name.
name | a node name | |
[out] | result | will contain the content ID if found, otherwise remains unchanged |
References m_name_id_mapping_with_aliases.
Referenced by CavernsNoise::CavernsNoise(), CavesRandomWalk::CavesRandomWalk(), CavesV6::CavesV6(), DungeonGen::DungeonGen(), MapgenBasic::MapgenBasic(), MapgenSinglenode::MapgenSinglenode(), MapgenV6::MapgenV6(), RollbackAction::applyRevert(), applyTextureOverrides(), correctBlockNodeIds(), MapBlock::deSerialize_pre22(), get(), getId(), NodeResolver::getIdFromNrBacklog(), getIds(), NodeResolver::getIdsFromNrBacklog(), getItemMesh(), Game::handleDigging(), ModApiItem::l_get_content_id(), ModApiClient::l_get_node_def(), treegen::make_jungletree(), treegen::make_pine_tree(), treegen::make_tree(), Game::nodePlacement(), MapgenV6::placeTreesAndJungleGrass(), resolveCrossrefs(), and WieldMeshSceneNode::setItem().
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:".
name | a node name or node group name | |
[out] | result | will be appended with matching IDs |
name
is a valid node name or a (not necessarily valid) group name References CONTENT_IGNORE, getId(), m_group_to_items, and str_starts_with().
Referenced by ABMHandler::ABMHandler(), LBMContentMapping::addLBM(), ModApiEnvBase::collectNodeIds(), NodeResolver::getIdsFromNrBacklog(), and resolveCrossrefs().
|
inline |
|
inline |
References m_content_lighting_flag_cache.
Referenced by MapgenSinglenode::MapgenSinglenode(), SmokePuffCSO::SmokePuffCSO(), Map::addNodeAndUpdate(), voxalgo::blit_back_with_light(), voxalgo::fill_with_sunlight(), voxalgo::fill_with_sunlight(), voxalgo::finish_bulk_light_update(), ClientMap::getBackgroundBrightness(), getFaceLight(), getInteriorLight(), getLightingFlags(), getVisibleBrightness(), voxalgo::is_light_locally_correct(), voxalgo::is_sunlight_above(), voxalgo::is_sunlight_above_block(), Map::isOccluded(), ModApiEnv::l_get_node_light(), Mapgen::lightSpread(), MapblockMeshGenerator::prepareLiquidNodeDrawing(), VoxelManipulator::print(), voxalgo::propagate_block_sunlight(), Mapgen::propagateSunlight(), voxalgo::repair_block_light(), voxalgo::spread_light(), Mapgen::spreadLight(), TestVoxelAlgorithms::testLighting(), TestMapNode::testNodeProperties(), ServerMap::transformLiquids(), voxalgo::unspread_light(), voxalgo::update_block_border_lighting(), voxalgo::update_lighting_nodes(), and Particle::updateLight().
|
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().
Checks whether a node connects to an adjacent node.
from | the node to be checked |
to | the adjacent node |
connect_face | a 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). |
References ContentFeatures::connect_sides, ContentFeatures::connects_to_ids, CONTAINS, CPT2_4DIR, CPT2_COLORED_4DIR, 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().
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(), read_tree_def(), TestNodeResolver::testNodeResolving(), and TestNodeResolver::testPendingResolveCancellation().
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.
name | name to be removed |
References CONTENT_IGNORE, eraseIdFromGroups(), NameIdMapping::eraseName(), NameIdMapping::getId(), m_name_id_mapping, and m_name_id_mapping_with_aliases.
Referenced by ModApiItem::l_unregister_item_raw().
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().
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(), m_content_features, NDT_NODEBOX, NODEBOX_CONNECTED, and removeDupes().
Referenced by deSerialize(), and Server::init().
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().
void NodeDefManager::serialize | ( | std::ostream & | os, |
u16 | protocol_version ) const |
Writes the content of this manager to the given output stream.
protocol_version | Active network protocol version |
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().
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.
name | name of the node, must match with def.name . |
def | definition of the registered node type. |
References addNameIdMapping(), allocateId(), CONTENT_IGNORE, eraseIdFromGroups(), fixSelectionBoxIntUnion(), NameIdMapping::getId(), ContentFeatures::getLightingFlags(), getNodeBoxUnion(), ContentFeatures::groups, itemgroup_get(), m_content_features, m_content_lighting_flag_cache, 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(), ModApiItem::l_register_item_raw(), and TEST_CASE().
|
inline |
Used to indicate that node registration has finished.
completed | tells whether registration is complete |
References m_node_registration_complete.
Referenced by Client::afterContentReceived(), Server::init(), TestSchematic::runTests(), TestNodeResolver::testNodeResolving(), and TestNodeResolver::testPendingResolveCancellation().
void NodeDefManager::updateAliases | ( | IItemDefManager * | idef | ) |
Regenerates the alias list (a map from names to node IDs).
idef | the 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().
void NodeDefManager::updateTextures | ( | IGameDef * | gamedef, |
void * | progress_cbk_args ) |
Only the client uses this. Loads textures and shaders required for rendering the nodes.
gamedef | must be a Client. |
progress_cbk | called each time a node is loaded. Arguments: progress_cbk_args , number of loaded ContentFeatures, number of total ContentFeatures. |
progress_cbk_args | passed to the callback function |
References infostream, m_content_features, and TextureSettings::readSettings().
Referenced by Client::afterContentReceived().
|
private |
Features indexed by ID.
Referenced by ~NodeDefManager(), allocateId(), applyTextureOverrides(), clear(), deSerialize(), get(), resolveCrossrefs(), serialize(), set(), and updateTextures().
|
private |
Fast cache of content lighting flags.
Referenced by clear(), deSerialize(), getLightingFlags(), and set().
|
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().
|
private |
A mapping for fast conversion between names and IDs.
Referenced by addNameIdMapping(), clear(), deSerialize(), removeNode(), set(), and updateAliases().
|
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().
|
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().
|
private |
True if all nodes have been registered.
Referenced by pendNodeResolve(), resetNodeResolveState(), and setNodeRegistrationStatus().
|
mutableprivate |
NodeResolver instances to notify once node registration has finished. Even constant NodeDefManager instances can register listeners.
Referenced by cancelNodeResolveCallback(), pendNodeResolve(), resetNodeResolveState(), and runNodeResolveCallbacks().
|
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().
|
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().