X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fnodedef.cpp;h=6ccbc1557d993ba7055d68770a8cc242f13706b5;hb=3caad3f3c9e319ca67d63231e8c64b2ace855fff;hp=966275076b026e2cc4f960016f60f2d70b3ac26d;hpb=3342dcc4bc6ee573ab0ce7ecff966faf60e09d56;p=oweals%2Fminetest.git diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 966275076..6ccbc1557 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -21,9 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "itemdef.h" #ifndef SERVER -#include "client/tile.h" #include "mesh.h" #include "client.h" +#include "client/renderingengine.h" +#include "client/tile.h" #include #endif #include "log.h" @@ -248,15 +249,21 @@ void TileDef::deSerialize(std::istream &is, const u8 contenfeatures_version, con */ static void serializeSimpleSoundSpec(const SimpleSoundSpec &ss, - std::ostream &os) + std::ostream &os, u8 version) { os<= 11) + writeF1000(os, ss.pitch); } -static void deSerializeSimpleSoundSpec(SimpleSoundSpec &ss, std::istream &is) +static void deSerializeSimpleSoundSpec(SimpleSoundSpec &ss, std::istream &is, u8 version) { ss.name = deSerializeString(is); ss.gain = readF1000(is); + + if (version >= 11) + ss.pitch = readF1000(is); } void TextureSettings::readSettings() @@ -384,7 +391,8 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const } // version - writeU8(os, 10); + u8 version = (protocol_version >= 34) ? 11 : 10; + writeU8(os, version); // general os << serializeString(name); @@ -460,30 +468,27 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const collision_box.serialize(os, protocol_version); // sound - serializeSimpleSoundSpec(sound_footstep, os); - serializeSimpleSoundSpec(sound_dig, os); - serializeSimpleSoundSpec(sound_dug, os); + serializeSimpleSoundSpec(sound_footstep, os, version); + serializeSimpleSoundSpec(sound_dig, os, version); + serializeSimpleSoundSpec(sound_dug, os, version); // legacy writeU8(os, legacy_facedir_simple); writeU8(os, legacy_wallmounted); } -void ContentFeatures::correctAlpha() +void ContentFeatures::correctAlpha(TileDef *tiles, int length) { + // alpha == 0 means that the node is using texture alpha if (alpha == 0 || alpha == 255) return; - for (u32 i = 0; i < 6; i++) { - std::stringstream s; - s << tiledef[i].name << "^[noalpha^[opacity:" << ((int)alpha); - tiledef[i].name = s.str(); - } - - for (u32 i = 0; i < CF_SPECIAL_COUNT; i++) { + for (int i = 0; i < length; i++) { + if (tiles[i].name == "") + continue; std::stringstream s; - s << tiledef_special[i].name << "^[noalpha^[opacity:" << ((int)alpha); - tiledef_special[i].name = s.str(); + s << tiles[i].name << "^[noalpha^[opacity:" << ((int)alpha); + tiles[i].name = s.str(); } } @@ -494,7 +499,7 @@ void ContentFeatures::deSerialize(std::istream &is) if (version < 9) { deSerializeOld(is, version); return; - } else if (version > 10) { + } else if (version > 11) { throw SerializationError("unsupported ContentFeatures version"); } @@ -576,9 +581,9 @@ void ContentFeatures::deSerialize(std::istream &is) collision_box.deSerialize(is); // sounds - deSerializeSimpleSoundSpec(sound_footstep, is); - deSerializeSimpleSoundSpec(sound_dig, is); - deSerializeSimpleSoundSpec(sound_dug, is); + deSerializeSimpleSoundSpec(sound_footstep, is, version); + deSerializeSimpleSoundSpec(sound_dig, is, version); + deSerializeSimpleSoundSpec(sound_dug, is, version); // read legacy properties legacy_facedir_simple = readU8(is); @@ -668,6 +673,14 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc if (tdef[j].name == "") tdef[j].name = "unknown_node.png"; } + // also the overlay tiles + TileDef tdef_overlay[6]; + for (u32 j = 0; j < 6; j++) + tdef_overlay[j] = tiledef_overlay[j]; + // also the special tiles + TileDef tdef_spec[6]; + for (u32 j = 0; j < CF_SPECIAL_COUNT; j++) + tdef_spec[j] = tiledef_special[j]; bool is_liquid = false; @@ -677,6 +690,8 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc switch (drawtype) { default: case NDT_NORMAL: + material_type = (alpha == 255) ? + TILE_MATERIAL_OPAQUE : TILE_MATERIAL_ALPHA; solidness = 2; break; case NDT_AIRLIKE: @@ -720,8 +735,8 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc visual_solidness = 1; } else if (tsettings.leaves_style == LEAVES_SIMPLE) { for (u32 j = 0; j < 6; j++) { - if (tiledef_special[j].name != "") - tdef[j].name = tiledef_special[j].name; + if (tdef_spec[j].name != "") + tdef[j].name = tdef_spec[j].name; } drawtype = NDT_GLASSLIKE; solidness = 0; @@ -759,35 +774,47 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc break; } - if (is_liquid) + if (is_liquid) { + // Vertex alpha is no longer supported, correct if necessary. + correctAlpha(tdef, 6); + correctAlpha(tdef_overlay, 6); + correctAlpha(tdef_spec, CF_SPECIAL_COUNT); material_type = (alpha == 255) ? TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT; - - // Vertex alpha is no longer supported, correct if necessary. - correctAlpha(); + } u32 tile_shader[6]; for (u16 j = 0; j < 6; j++) { tile_shader[j] = shdsrc->getShader("nodes_shader", material_type, drawtype); } + u8 overlay_material = material_type; + if (overlay_material == TILE_MATERIAL_OPAQUE) + overlay_material = TILE_MATERIAL_BASIC; + else if (overlay_material == TILE_MATERIAL_LIQUID_OPAQUE) + overlay_material = TILE_MATERIAL_LIQUID_TRANSPARENT; + u32 overlay_shader[6]; + for (u16 j = 0; j < 6; j++) { + overlay_shader[j] = shdsrc->getShader("nodes_shader", + overlay_material, drawtype); + } // Tiles (fill in f->tiles[]) for (u16 j = 0; j < 6; j++) { fillTileAttribs(tsrc, &tiles[j].layers[0], &tdef[j], tile_shader[j], tsettings.use_normal_texture, - tiledef[j].backface_culling, material_type); - if (tiledef_overlay[j].name!="") - fillTileAttribs(tsrc, &tiles[j].layers[1], &tiledef_overlay[j], - tile_shader[j], tsettings.use_normal_texture, - tiledef[j].backface_culling, material_type); + tdef[j].backface_culling, material_type); + if (tdef_overlay[j].name != "") + fillTileAttribs(tsrc, &tiles[j].layers[1], &tdef_overlay[j], + overlay_shader[j], tsettings.use_normal_texture, + tdef[j].backface_culling, overlay_material); } // Special tiles (fill in f->special_tiles[]) for (u16 j = 0; j < CF_SPECIAL_COUNT; j++) { - fillTileAttribs(tsrc, &special_tiles[j].layers[0], &tiledef_special[j], + fillTileAttribs(tsrc, &special_tiles[j].layers[0], &tdef_spec[j], tile_shader[j], tsettings.use_normal_texture, - tiledef_special[j].backface_culling, material_type); + tdef_spec[j].backface_culling, material_type); } if (param_type_2 == CPT2_COLOR || @@ -874,7 +901,6 @@ public: void serialize(std::ostream &os, u16 protocol_version) const; void deSerialize(std::istream &is); - inline virtual bool getNodeRegistrationStatus() const; inline virtual void setNodeRegistrationStatus(bool completed); virtual void pendNodeResolve(NodeResolver *nr); @@ -906,12 +932,12 @@ private: // item aliases too. Updated by updateAliases() // Note: Not serialized. - UNORDERED_MAP m_name_id_mapping_with_aliases; + std::unordered_map m_name_id_mapping_with_aliases; // A mapping from groups to a list of content_ts (and their levels) // that belong to it. Necessary for a direct lookup in getIds(). // Note: Not serialized. - UNORDERED_MAP m_group_to_items; + std::unordered_map m_group_to_items; // Next possibly free id content_t m_next_id; @@ -1044,7 +1070,7 @@ inline const ContentFeatures& CNodeDefManager::get(const MapNode &n) const bool CNodeDefManager::getId(const std::string &name, content_t &result) const { - UNORDERED_MAP::const_iterator + std::unordered_map::const_iterator i = m_name_id_mapping_with_aliases.find(name); if(i == m_name_id_mapping_with_aliases.end()) return false; @@ -1074,7 +1100,7 @@ bool CNodeDefManager::getIds(const std::string &name, } std::string group = name.substr(6); - UNORDERED_MAP::const_iterator + std::unordered_map::const_iterator i = m_group_to_items.find(group); if (i == m_group_to_items.end()) return true; @@ -1276,7 +1302,7 @@ content_t CNodeDefManager::set(const std::string &name, const ContentFeatures &d i != def.groups.end(); ++i) { std::string group_name = i->first; - UNORDERED_MAP::iterator + std::unordered_map::iterator j = m_group_to_items.find(group_name); if (j == m_group_to_items.end()) { m_group_to_items[group_name].push_back( @@ -1312,7 +1338,7 @@ void CNodeDefManager::removeNode(const std::string &name) } // Erase node content from all groups it belongs to - for (UNORDERED_MAP::iterator iter_groups = + for (std::unordered_map::iterator iter_groups = m_group_to_items.begin(); iter_groups != m_group_to_items.end();) { GroupItems &items = iter_groups->second; for (GroupItems::iterator iter_groupitems = items.begin(); @@ -1414,8 +1440,8 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef, Client *client = (Client *)gamedef; ITextureSource *tsrc = client->tsrc(); IShaderSource *shdsrc = client->getShaderSource(); - scene::ISceneManager* smgr = client->getSceneManager(); - scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator(); + scene::IMeshManipulator *meshmanip = + RenderingEngine::get_scene_manager()->getMeshManipulator(); TextureSettings tsettings; tsettings.readSettings(); @@ -1598,9 +1624,9 @@ void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version) const selection_box.serialize(os, protocol_version); writeU8(os, legacy_facedir_simple); writeU8(os, legacy_wallmounted); - serializeSimpleSoundSpec(sound_footstep, os); - serializeSimpleSoundSpec(sound_dig, os); - serializeSimpleSoundSpec(sound_dug, os); + serializeSimpleSoundSpec(sound_footstep, os, 10); + serializeSimpleSoundSpec(sound_dig, os, 10); + serializeSimpleSoundSpec(sound_dug, os, 10); writeU8(os, rightclickable); writeU8(os, drowning); writeU8(os, leveled); @@ -1670,9 +1696,9 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version) selection_box.deSerialize(is); legacy_facedir_simple = readU8(is); legacy_wallmounted = readU8(is); - deSerializeSimpleSoundSpec(sound_footstep, is); - deSerializeSimpleSoundSpec(sound_dig, is); - deSerializeSimpleSoundSpec(sound_dug, is); + deSerializeSimpleSoundSpec(sound_footstep, is, version); + deSerializeSimpleSoundSpec(sound_dig, is, version); + deSerializeSimpleSoundSpec(sound_dug, is, version); } else if (version == 6) { name = deSerializeString(is); groups.clear(); @@ -1720,9 +1746,9 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version) selection_box.deSerialize(is); legacy_facedir_simple = readU8(is); legacy_wallmounted = readU8(is); - deSerializeSimpleSoundSpec(sound_footstep, is); - deSerializeSimpleSoundSpec(sound_dig, is); - deSerializeSimpleSoundSpec(sound_dug, is); + deSerializeSimpleSoundSpec(sound_footstep, is, version); + deSerializeSimpleSoundSpec(sound_dig, is, version); + deSerializeSimpleSoundSpec(sound_dug, is, version); rightclickable = readU8(is); drowning = readU8(is); leveled = readU8(is); @@ -1775,9 +1801,9 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version) selection_box.deSerialize(is); legacy_facedir_simple = readU8(is); legacy_wallmounted = readU8(is); - deSerializeSimpleSoundSpec(sound_footstep, is); - deSerializeSimpleSoundSpec(sound_dig, is); - deSerializeSimpleSoundSpec(sound_dug, is); + deSerializeSimpleSoundSpec(sound_footstep, is, version); + deSerializeSimpleSoundSpec(sound_dig, is, version); + deSerializeSimpleSoundSpec(sound_dug, is, version); rightclickable = readU8(is); drowning = readU8(is); leveled = readU8(is); @@ -1798,13 +1824,6 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version) } } - -inline bool CNodeDefManager::getNodeRegistrationStatus() const -{ - return m_node_registration_complete; -} - - inline void CNodeDefManager::setNodeRegistrationStatus(bool completed) { m_node_registration_complete = completed; @@ -1917,11 +1936,6 @@ bool CNodeDefManager::nodeboxConnects(MapNode from, MapNode to, u8 connect_face) NodeResolver::NodeResolver() { - m_ndef = NULL; - m_nodenames_idx = 0; - m_nnlistsizes_idx = 0; - m_resolve_done = false; - m_nodenames.reserve(16); m_nnlistsizes.reserve(4); }