X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fnodedef.cpp;h=bb08871df371890cdf2685d96c59b9bd70254a3c;hb=cd563473fa298db3b910009f26ba263bacd84be9;hp=045615fbbf72f08eb5cd3c20964d1457cbcb7944;hpb=89e7bacd991060fe6cdada6bf8112f9f20c3e310;p=oweals%2Fminetest.git diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 045615fbb..bb08871df 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -25,10 +25,70 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "tile.h" #endif #include "log.h" +#include "settings.h" +#include "nameidmapping.h" + +/* + NodeBox +*/ + +void NodeBox::serialize(std::ostream &os) const +{ + writeU8(os, 0); // version + writeU8(os, type); + writeV3F1000(os, fixed.MinEdge); + writeV3F1000(os, fixed.MaxEdge); + writeV3F1000(os, wall_top.MinEdge); + writeV3F1000(os, wall_top.MaxEdge); + writeV3F1000(os, wall_bottom.MinEdge); + writeV3F1000(os, wall_bottom.MaxEdge); + writeV3F1000(os, wall_side.MinEdge); + writeV3F1000(os, wall_side.MaxEdge); +} + +void NodeBox::deSerialize(std::istream &is) +{ + int version = readU8(is); + if(version != 0) + throw SerializationError("unsupported NodeBox version"); + type = (enum NodeBoxType)readU8(is); + fixed.MinEdge = readV3F1000(is); + fixed.MaxEdge = readV3F1000(is); + wall_top.MinEdge = readV3F1000(is); + wall_top.MaxEdge = readV3F1000(is); + wall_bottom.MinEdge = readV3F1000(is); + wall_bottom.MaxEdge = readV3F1000(is); + wall_side.MinEdge = readV3F1000(is); + wall_side.MaxEdge = readV3F1000(is); +} + +/* + MaterialSpec +*/ + +void MaterialSpec::serialize(std::ostream &os) const +{ + os<reset(); - if(i == CONTENT_IGNORE || i == CONTENT_AIR) - continue; - f->setAllTextures("unknown_block.png"); - f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; + ContentFeatures &f = m_content_features[i]; + f.reset(); // Reset to defaults + f.setAllTextures("unknown_block.png"); + } + + // Set CONTENT_AIR + { + ContentFeatures f; + f.name = "air"; + f.drawtype = NDT_AIRLIKE; + f.param_type = CPT_LIGHT; + f.light_propagates = true; + f.sunlight_propagates = true; + f.walkable = false; + f.pointable = false; + f.diggable = false; + f.buildable_to = true; + // Insert directly into containers + content_t c = CONTENT_AIR; + m_content_features[c] = f; + m_name_id_mapping.set(c, f.name); + } + // Set CONTENT_IGNORE + { + ContentFeatures f; + f.name = "ignore"; + f.drawtype = NDT_AIRLIKE; + f.param_type = CPT_NONE; + f.light_propagates = false; + f.sunlight_propagates = false; + f.walkable = false; + f.pointable = false; + f.diggable = false; + // A way to remove accidental CONTENT_IGNOREs + f.buildable_to = true; + // Insert directly into containers + content_t c = CONTENT_IGNORE; + m_content_features[c] = f; + m_name_id_mapping.set(c, f.name); } - // Make CONTENT_IGNORE to not block the view when occlusion culling - m_content_features[CONTENT_IGNORE].solidness = 0; + } + // CONTENT_IGNORE = not found + content_t getFreeId(bool require_full_param2) + { + // If allowed, first search in the large 4-byte-param2 pool + if(!require_full_param2){ + for(u16 i=0x800; i<=0xfff; i++){ + const ContentFeatures &f = m_content_features[i]; + if(f.name == "") + return i; + } + } + // Then search from the small 8-byte-param2 pool + for(u16 i=0; i<=125; i++){ + const ContentFeatures &f = m_content_features[i]; + if(f.name == "") + return i; + } + return CONTENT_IGNORE; + } + CNodeDefManager() + { + clear(); } virtual ~CNodeDefManager() { @@ -106,27 +397,154 @@ public: { return get(n.getContent()); } - // Writable + virtual bool getId(const std::string &name, content_t &result) const + { + return m_name_id_mapping.getId(name, result); + } + virtual content_t getId(const std::string &name) const + { + content_t id = CONTENT_IGNORE; + getId(name, id); + return id; + } + virtual const ContentFeatures& get(const std::string &name) const + { + content_t id = CONTENT_IGNORE; + getId(name, id); + return get(id); + } + // IWritableNodeDefManager virtual void set(content_t c, const ContentFeatures &def) { - infostream<<"registerNode: registering content \""<getBool("new_style_water"); + bool new_style_leaves = g_settings->getBool("new_style_leaves"); + bool opaque_water = g_settings->getBool("opaque_water"); + for(u16 i=0; i<=MAX_CONTENT; i++) { - infostream<<"Updating content "<drawtype){ + default: + case NDT_NORMAL: + f->solidness = 2; + break; + case NDT_AIRLIKE: + f->solidness = 0; + break; + case NDT_LIQUID: + assert(f->liquid_type == LIQUID_SOURCE); + if(opaque_water) + f->alpha = 255; + if(new_style_water){ + f->solidness = 0; + } else { + f->solidness = 1; + if(f->alpha == 255) + f->solidness = 2; + f->backface_culling = false; + } + break; + case NDT_FLOWINGLIQUID: + assert(f->liquid_type == LIQUID_FLOWING); + f->solidness = 0; + if(opaque_water) + f->alpha = 255; + break; + case NDT_GLASSLIKE: + f->solidness = 0; + f->visual_solidness = 1; + break; + case NDT_ALLFACES: + f->solidness = 0; + f->visual_solidness = 1; + break; + case NDT_ALLFACES_OPTIONAL: + if(new_style_leaves){ + f->drawtype = NDT_ALLFACES; + f->solidness = 0; + f->visual_solidness = 1; + } else { + f->drawtype = NDT_NORMAL; + f->solidness = 1; + for(u32 i=0; i<6; i++){ + f->tname_tiles[i] = f->tname_tiles[i] + + std::string("^[noalpha"); + } + } + break; + case NDT_TORCHLIKE: + case NDT_SIGNLIKE: + case NDT_PLANTLIKE: + case NDT_FENCELIKE: + case NDT_RAILLIKE: + f->solidness = 0; + break; + } + // Inventory texture if(f->tname_inventory != "") f->inventory_texture = tsrc->getTextureRaw(f->tname_inventory); @@ -171,12 +589,55 @@ public: f->special_materials[j]->setFlag(video::EMF_BILINEAR_FILTER, false); f->special_materials[j]->setFlag(video::EMF_FOG_ENABLE, true); f->special_materials[j]->setTexture(0, f->special_aps[j]->atlas); + if(f->alpha != 255) + f->special_materials[j]->MaterialType = + video::EMT_TRANSPARENT_VERTEX_ALPHA; } } #endif } + void serialize(std::ostream &os) + { + u16 count = 0; + std::ostringstream tmp_os(std::ios::binary); + for(u16 i=0; i<=MAX_CONTENT; i++) + { + if(i == CONTENT_IGNORE || i == CONTENT_AIR) + continue; + ContentFeatures *f = &m_content_features[i]; + if(f->name == "") + continue; + writeU16(tmp_os, i); + f->serialize(tmp_os); + count++; + } + writeU16(os, count); + os< MAX_CONTENT){ + errorstream<<"ContentFeatures::deSerialize(): " + <<"Too large content id: "<deSerialize(tmp_is, gamedef); + if(f->name != "") + m_name_id_mapping.set(i, f->name); + } + } private: ContentFeatures m_content_features[MAX_CONTENT+1]; + NameIdMapping m_name_id_mapping; }; IWritableNodeDefManager* createNodeDefManager()