From f030154fe727e25a2afe1f78b3998c2d2dba95e4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 18 Aug 2009 09:24:15 +0000 Subject: astyle cleanup, corrects not loading of material textures --- src/model/material.cc | 53 +++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'src/model/material.cc') diff --git a/src/model/material.cc b/src/model/material.cc index 416e491..6baf4f9 100644 --- a/src/model/material.cc +++ b/src/model/material.cc @@ -19,9 +19,9 @@ Material::LoaderFuncPtr Material::material_loaderfunc = 0; Material::Registry Material::material_registry; Material::Material(const std::string &name) : - material_name(name), - material_color(1.0f) , - material_size(64.0f, 64.0f) + material_name(name), + material_color(1.0f) , + material_size(64.0f, 64.0f) { aux::to_lowercase(material_name); material_flags = 0; @@ -41,11 +41,16 @@ void Material::set_color(const math::Color &color) void Material::set_texture(const std::string &texture) { - material_texture.assign(texture); - - if (material_loaderfunc) { - material_loaderfunc(this); - //con_debug << " material " << name() << " " << size().width() << "x" << size().height() << std::endl; + if (texture.size()) { + set_flags(Texture); + material_texture.assign(texture); + if (material_loaderfunc) { + material_loaderfunc(this); + } + } else { + unset_flags(Texture); + material_texture.clear(); + material_texture_id = 0; } } @@ -80,8 +85,8 @@ void Material::init() while (shaderlist.getline(line, 1023)) { if ((line[0] == 0) || (line[0] == '#') || (line[0] == ';')) { continue; - if ((line[0] == '/') && (line[1] == '/')) - continue; + if ((line[0] == '/') && (line[1] == '/')) + continue; } else { std::string s(line); aux::trim(s); @@ -115,7 +120,7 @@ void Material::load_shader(const std::string &shadername) unsigned int linenumber = 0; char line[1024]; unsigned int count = 0; - float r,g,b; + float r, g, b; Material *material = 0; while (shaderfile.getline(line, 1023)) { @@ -130,12 +135,12 @@ void Material::load_shader(const std::string &shadername) continue; // skip comments - if ((s[0] == '#') || (s[0] == ';') || ((s[0] == '/') && (s[1] == '/'))) + if ((s[0] == '#') || (s[0] == ';') || ((s[0] == '/') && (s[1] == '/'))) continue; - + std::istringstream linestream(s); std::string firstword; - + if (linestream >> firstword) { if (firstword.compare("//") == 0) { continue; @@ -146,7 +151,7 @@ void Material::load_shader(const std::string &shadername) } else if (firstword.compare("{") == 0) { parselevel++; - } else if ((firstword.size()) && (parselevel == 0) ) { + } else if ((firstword.size()) && (parselevel == 0)) { material = find(firstword); if (material) { @@ -163,8 +168,10 @@ void Material::load_shader(const std::string &shadername) if (firstword.compare("color") == 0) { if (linestream >> r >> g >> b) { if (math::max(r, math::max(g, b)) > 1.0f) { - r /= 255.0f; g /= 255.0f; b /= 255.0f; - } + r /= 255.0f; + g /= 255.0f; + b /= 255.0f; + } material->set_color(math::Color(r, g, b, 1.0f)); } } else if (firstword.compare("engine") == 0) { @@ -178,7 +185,7 @@ void Material::load_shader(const std::string &shadername) } else if (firstword.compare("entitysecond") == 0) { material->set_flags(Secondary); } else if (firstword.compare("entitythird") == 0) { - material->set_flags(Tertiary); + material->set_flags(Tertiary); } else if (firstword.compare("ignore") == 0) { material->set_flags(Ignore); } else if (firstword.compare("qer_editorimage") == 0) { @@ -189,19 +196,19 @@ void Material::load_shader(const std::string &shadername) // texture name should not contain spaces if (linestream >> firstword) { + // remove extension if (firstword[firstword.size()-4] == '.') { - firstword.erase(firstword.size()-4); + firstword.erase(firstword.size() - 4); } material->set_texture(firstword); - material->set_flags(Material::Texture); } else { con_warn << shaderfile.name() << " texture key without filename at line " << linenumber << std::endl; } } else { - con_warn << shaderfile.name() << " unknown key '" << firstword - << "' at line " << linenumber << std::endl; + con_warn << shaderfile.name() << " unknown key '" << firstword + << "' at line " << linenumber << std::endl; } } } @@ -222,7 +229,7 @@ void Material::clear() con_print << "^BClearing materials..." << std::endl; for (Registry::iterator i = material_registry.begin(); i != material_registry.end(); ++i) { - delete (*i).second; + delete(*i).second; } material_registry.clear(); -- cgit v1.2.3