Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/savegamemenu.cc12
-rw-r--r--src/core/commandbuffer.cc10
-rw-r--r--src/model/material.cc35
-rw-r--r--src/model/material.h7
-rw-r--r--src/render/textures.cc2
5 files changed, 43 insertions, 23 deletions
diff --git a/src/client/savegamemenu.cc b/src/client/savegamemenu.cc
index 4b546ac..b91a45c 100644
--- a/src/client/savegamemenu.cc
+++ b/src/client/savegamemenu.cc
@@ -152,7 +152,7 @@ void SaveGameMenu::resize()
);
// resize screenshot
- model::Material *screenshotmaterial = model::Material::find("ui/screenshot");
+ const model::Material *screenshotmaterial = model::Material::find("ui/screenshot");
if (screenshotmaterial) {
float sx = savegamemenu_descrtitle->width() / screenshotmaterial->size().width();
float sy = ui::UI::elementsize.width() / screenshotmaterial->size().height();
@@ -280,6 +280,7 @@ void SaveGameMenu::hide()
if ((*lit)->texture().size()) {
render::Textures::unload((*lit)->texture());
(*lit)->set_texture("");
+ (*lit)->set_texture_id(0);
}
}
@@ -329,8 +330,7 @@ void SaveGameMenu::show_file_info()
model::Material *screenshotmaterial = model::Material::find("ui/screenshot");
if (!screenshotmaterial) {
- screenshotmaterial = new model::Material("ui/screenshot");
- model::Material::registry()[screenshotmaterial->name()] = screenshotmaterial;
+ screenshotmaterial = model::Material::add("ui/screenshot");
}
model::Layer *screenshotlayer = 0;
@@ -345,16 +345,16 @@ void SaveGameMenu::show_file_info()
screenshotlayer->set_texture("");
}
- std::string screenshotfilename("savegames/" + savename);
+ const std::string screenshotfilename("savegames/" + savename);
screenshotlayer->set_texture(screenshotfilename);
render::Textures::image_loader(screenshotlayer);
screenshotmaterial->set_size(screenshotlayer->size());
-
+
savegamemenu_screenshot->set_texture(screenshotmaterial->name());
savegamemenu_screenshot->show();
resize();
-
+
} else {
// new savegame, immediatly show the save game dialog
show_save_dialog();
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index 53d200f..11a48b4 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -172,9 +172,13 @@ void func_list_model(std::string const &args)
void func_list_materials(std::string const &args)
{
- model::Material *material = model::Material::find(args);
- if (material) {
- material->print();
+ if (args.size()) {
+ model::Material *material = model::Material::find(args);
+ if (material) {
+ material->print();
+ } else {
+ con_warn << "Unknown material '" << args << "'" << std::endl;
+ }
} else {
model::Material::list();
}
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);
diff --git a/src/render/textures.cc b/src/render/textures.cc
index bd75a45..15c9bd5 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -414,7 +414,7 @@ size_t Textures::bind(const size_t texture, const bool filter)
void Textures::image_loader(model::Layer *layer)
{
if (layer->texture().size() > 0 ) {
- size_t id = load(layer->texture());
+ size_t id = load(layer->texture().c_str());
layer->set_texture_id(id);
layer->set_size(texture_size[id]);
}