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];
41 void ContentFeatures::setTexture(ITextureSource *tsrc,
42 u16 i, std::string name, u8 alpha)
44 used_texturenames.insert(name);
48 tiles[i].texture = tsrc->getTexture(name);
53 tiles[i].alpha = alpha;
54 tiles[i].material_type = MATERIAL_ALPHA_VERTEX;
57 if(inventory_texture == NULL)
58 setInventoryTexture(name, tsrc);
61 void ContentFeatures::setInventoryTexture(std::string imgname,
67 imgname += "^[forcesingle";
69 inventory_texture = tsrc->getTextureRaw(imgname);
72 void ContentFeatures::setInventoryTextureCube(std::string top,
73 std::string left, std::string right, ITextureSource *tsrc)
78 str_replace_char(top, '^', '&');
79 str_replace_char(left, '^', '&');
80 str_replace_char(right, '^', '&');
82 std::string imgname_full;
83 imgname_full += "[inventorycube{";
88 imgname_full += right;
89 inventory_texture = tsrc->getTextureRaw(imgname_full);
93 void ContentFeatures::setTexture(u16 i, std::string name)
95 used_texturenames.insert(name);
96 tname_tiles[i] = name;
97 if(tname_inventory == "")
98 tname_inventory = name;
101 void ContentFeatures::setInventoryTexture(std::string imgname)
103 tname_inventory = imgname + "^[forcesingle";
106 void ContentFeatures::setInventoryTextureCube(std::string top,
107 std::string left, std::string right)
109 str_replace_char(top, '^', '&');
110 str_replace_char(left, '^', '&');
111 str_replace_char(right, '^', '&');
113 std::string imgname_full;
114 imgname_full += "[inventorycube{";
117 imgname_full += left;
119 imgname_full += right;
120 tname_inventory = imgname_full;
123 class CNodeDefManager: public IWritableNodeDefManager
128 for(u16 i=0; i<=MAX_CONTENT; i++)
130 ContentFeatures *f = &m_content_features[i];
133 if(i == CONTENT_IGNORE || i == CONTENT_AIR)
135 f->setAllTextures("unknown_block.png");
136 f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
138 // Make CONTENT_IGNORE to not block the view when occlusion culling
139 m_content_features[CONTENT_IGNORE].solidness = 0;
141 virtual ~CNodeDefManager()
144 virtual IWritableNodeDefManager* clone()
146 CNodeDefManager *mgr = new CNodeDefManager();
147 for(u16 i=0; i<=MAX_CONTENT; i++)
153 virtual const ContentFeatures& get(content_t c) const
155 assert(c <= MAX_CONTENT);
156 return m_content_features[c];
158 virtual const ContentFeatures& get(const MapNode &n) const
160 return get(n.getContent());
163 virtual void set(content_t c, const ContentFeatures &def)
165 infostream<<"registerNode: registering content \""<<c<<"\""<<std::endl;
166 assert(c <= MAX_CONTENT);
167 m_content_features[c] = def;
169 virtual ContentFeatures* getModifiable(content_t c)
171 assert(c <= MAX_CONTENT);
172 return &m_content_features[c];
174 virtual void updateTextures(ITextureSource *tsrc)
177 infostream<<"CNodeDefManager::updateTextures(): Updating "
178 <<"textures in node definitions"<<std::endl;
179 for(u16 i=0; i<=MAX_CONTENT; i++)
181 infostream<<"Updating content "<<i<<std::endl;
182 ContentFeatures *f = &m_content_features[i];
184 if(f->tname_inventory != "")
185 f->inventory_texture = tsrc->getTextureRaw(f->tname_inventory);
187 f->inventory_texture = NULL;
189 for(u16 j=0; j<6; j++){
190 if(f->tname_tiles[j] == "")
192 f->tiles[j].texture = tsrc->getTexture(f->tname_tiles[j]);
193 f->tiles[j].alpha = f->alpha;
195 f->tiles[j].material_type = MATERIAL_ALPHA_SIMPLE;
197 f->tiles[j].material_type = MATERIAL_ALPHA_VERTEX;
198 if(f->backface_culling)
199 f->tiles[j].material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
201 f->tiles[j].material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
204 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
206 if(f->special_aps[j]){
207 delete f->special_aps[j];
208 f->special_aps[j] = NULL;
210 if(f->special_materials[j]){
211 delete f->special_materials[j];
212 f->special_materials[j] = NULL;
214 // Skip if should not exist
215 if(f->mspec_special[j].tname == "")
218 f->special_aps[j] = new AtlasPointer(
219 tsrc->getTexture(f->mspec_special[j].tname));
220 f->special_materials[j] = new video::SMaterial;
221 f->special_materials[j]->setFlag(video::EMF_LIGHTING, false);
222 f->special_materials[j]->setFlag(video::EMF_BACK_FACE_CULLING,
223 f->mspec_special[j].backface_culling);
224 f->special_materials[j]->setFlag(video::EMF_BILINEAR_FILTER, false);
225 f->special_materials[j]->setFlag(video::EMF_FOG_ENABLE, true);
226 f->special_materials[j]->setTexture(0, f->special_aps[j]->atlas);
232 ContentFeatures m_content_features[MAX_CONTENT+1];
235 IWritableNodeDefManager* createNodeDefManager()
237 return new CNodeDefManager();