3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "main.h" // For g_settings
23 #include "nodemetadata.h"
29 ContentFeatures::~ContentFeatures()
31 delete initial_metadata;
33 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
34 delete special_materials[j];
35 delete special_aps[j];
40 void ContentFeatures::setTexture(u16 i, std::string name)
42 used_texturenames.insert(name);
43 tname_tiles[i] = name;
44 if(tname_inventory == "")
45 tname_inventory = name;
48 void ContentFeatures::setInventoryTexture(std::string imgname)
50 tname_inventory = imgname + "^[forcesingle";
53 void ContentFeatures::setInventoryTextureCube(std::string top,
54 std::string left, std::string right)
56 str_replace_char(top, '^', '&');
57 str_replace_char(left, '^', '&');
58 str_replace_char(right, '^', '&');
60 std::string imgname_full;
61 imgname_full += "[inventorycube{";
66 imgname_full += right;
67 tname_inventory = imgname_full;
70 class CNodeDefManager: public IWritableNodeDefManager
75 for(u16 i=0; i<=MAX_CONTENT; i++)
77 ContentFeatures *f = &m_content_features[i];
80 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
82 f->setAllTextures("unknown_block.png");
83 f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
85 // Make CONTENT_IGNORE to not block the view when occlusion culling
86 m_content_features[CONTENT_IGNORE].solidness = 0;
88 virtual ~CNodeDefManager()
91 virtual IWritableNodeDefManager* clone()
93 CNodeDefManager *mgr = new CNodeDefManager();
94 for(u16 i=0; i<=MAX_CONTENT; i++)
100 virtual const ContentFeatures& get(content_t c) const
102 assert(c <= MAX_CONTENT);
103 return m_content_features[c];
105 virtual const ContentFeatures& get(const MapNode &n) const
107 return get(n.getContent());
110 virtual void set(content_t c, const ContentFeatures &def)
112 infostream<<"registerNode: registering content \""<<c<<"\""<<std::endl;
113 assert(c <= MAX_CONTENT);
114 m_content_features[c] = def;
116 virtual ContentFeatures* getModifiable(content_t c)
118 assert(c <= MAX_CONTENT);
119 return &m_content_features[c];
121 virtual void updateTextures(ITextureSource *tsrc)
124 infostream<<"CNodeDefManager::updateTextures(): Updating "
125 <<"textures in node definitions"<<std::endl;
126 for(u16 i=0; i<=MAX_CONTENT; i++)
128 infostream<<"Updating content "<<i<<std::endl;
129 ContentFeatures *f = &m_content_features[i];
131 if(f->tname_inventory != "")
132 f->inventory_texture = tsrc->getTextureRaw(f->tname_inventory);
134 f->inventory_texture = NULL;
136 for(u16 j=0; j<6; j++){
137 if(f->tname_tiles[j] == "")
139 f->tiles[j].texture = tsrc->getTexture(f->tname_tiles[j]);
140 f->tiles[j].alpha = f->alpha;
142 f->tiles[j].material_type = MATERIAL_ALPHA_SIMPLE;
144 f->tiles[j].material_type = MATERIAL_ALPHA_VERTEX;
145 if(f->backface_culling)
146 f->tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
148 f->tiles[j].material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
151 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
153 if(f->special_aps[j]){
154 delete f->special_aps[j];
155 f->special_aps[j] = NULL;
157 if(f->special_materials[j]){
158 delete f->special_materials[j];
159 f->special_materials[j] = NULL;
161 // Skip if should not exist
162 if(f->mspec_special[j].tname == "")
165 f->special_aps[j] = new AtlasPointer(
166 tsrc->getTexture(f->mspec_special[j].tname));
167 f->special_materials[j] = new video::SMaterial;
168 f->special_materials[j]->setFlag(video::EMF_LIGHTING, false);
169 f->special_materials[j]->setFlag(video::EMF_BACK_FACE_CULLING,
170 f->mspec_special[j].backface_culling);
171 f->special_materials[j]->setFlag(video::EMF_BILINEAR_FILTER, false);
172 f->special_materials[j]->setFlag(video::EMF_FOG_ENABLE, true);
173 f->special_materials[j]->setTexture(0, f->special_aps[j]->atlas);
179 ContentFeatures m_content_features[MAX_CONTENT+1];
182 IWritableNodeDefManager* createNodeDefManager()
184 return new CNodeDefManager();