diff options
author | Stijn Buys <ingar@osirion.org> | 2014-12-22 16:02:48 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2014-12-22 16:02:48 +0000 |
commit | 871552eab28d07c3aaf0cabb5fb167c0eb365bdf (patch) | |
tree | 0c91777d067e3b5323070b458c1affd6f11669da /src/model | |
parent | a5aef07b4a2b85933f3a2f358a4d1b6fe27948b7 (diff) |
Fixed a bug where the lad/savegame dialog wouldn't show the screenshot of the first selected savegame,
minor code cleamups in material handling.
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/material.cc | 35 | ||||
-rw-r--r-- | src/model/material.h | 7 |
2 files changed, 29 insertions, 13 deletions
diff --git a/src/model/material.cc b/src/model/material.cc index 9f47f1e..93492f5 100644 --- a/src/model/material.cc +++ b/src/model/material.cc @@ -240,8 +240,7 @@ void Material::load_shaderfile(const std::string &shadername) material = 0; layer = 0; } else { - material = new Material(firstword); - material_registry[material->name()] = material; + material = add(firstword); count++; layer = 0; @@ -386,20 +385,33 @@ void Material::load_shaderfile(const std::string &shadername) void Material::list() { - for (Registry::iterator i = material_registry.begin(); i != material_registry.end(); ++i) { + for (Registry::iterator i = material_registry.begin(); i != material_registry.end(); ++i) + { con_print << " " << (*i).second->name() << std::endl; } con_print << material_registry.size() << " registered materials" << std::endl; } + +Material * Material::add(const std::string &name) +{ + Material *material = new Material(name); + material_registry[material->name()] = material; + + return material; +} + Material *Material::find(const std::string &name) { std::string searchstr(name); aux::to_lowercase(searchstr); - for (Registry::iterator i = material_registry.begin(); i != material_registry.end(); ++i) { + for (Registry::iterator i = material_registry.begin(); i != material_registry.end(); ++i) + { if ((*i).first.compare(searchstr) == 0) + { return (*i).second; + } } return 0; } @@ -414,27 +426,26 @@ Material *Material::load(const std::string &name, const bool ui_texture) } // create a new material - material = new Material(name); + material = add(name); - // create a single layer - Layer *layer = new Layer(); + // add a single layer + Layer *layer = material->add_layer(); // add a texture layer->set_texture(name); - if (ui_texture) { + if (ui_texture) + { layer->set_fullbright(true); layer->set_blendfunc(Layer::BlendFuncBlend); } if (material_imageloaderfunc) { material_imageloaderfunc(layer); - if ((layer->size().width() > 0) && (layer->size().height() > 0)) { + if ((layer->size().width() > 0) && (layer->size().height() > 0)) + { material->material_size.assign(layer->size()); } } - // add the new layer to the material - material->material_layers.push_back(layer); - // add the new material to the registry material_registry[material->name()] = material; diff --git a/src/model/material.h b/src/model/material.h index c775c04..c6577ef 100644 --- a/src/model/material.h +++ b/src/model/material.h @@ -174,7 +174,7 @@ public: /** * @brief material registry * */ - static inline Registry registry() + static inline Registry & registry() { return material_registry; } @@ -213,6 +213,11 @@ public: * @brief find a material in the registry * */ static Material *find(const std::string &name); + + /** + * @brief add a new material to the registry. + * */ + static Material *add(const std::string &name); static void set_imageloader_func(ImageLoaderFuncPtr func); |