/* render/model.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #include "sys/sys.h" #include "model/model.h" #include "model/map.h" #include "model/vertexarray.h" namespace model { std::map Model::registry; Model::Model(std::string const & name) : model_name(name) { model_first_vertex = 0; model_first_evertex = 0; model_first_lvertex = 0; model_vertex_count = 0; model_vertex_countdetail = 0; model_evertex_count = 0; model_evertex_countdetail = 0; model_lvertex_count = 0; model_lvertex_countdetail = 0; model_radius = 0.5f; model_enginesound = 0; } Model::~Model() { // delete all engines for (std::list::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++) { delete(*eit); } model_engine.clear(); // delete all lights for (std::list::iterator lit = model_light.begin(); lit != model_light.end(); lit++) { delete (*lit); } model_light.clear(); // delete all flares for (std::list::iterator flit = model_flare.begin(); flit != model_flare.end(); flit++) { delete (*flit); } model_flare.clear(); } size_t Model::tris() const { return ((model_vertex_count + model_vertex_countdetail + model_evertex_count + model_evertex_countdetail + model_lvertex_count + model_lvertex_countdetail)/3); } size_t Model::details() const { return ((model_vertex_countdetail + model_evertex_countdetail + model_lvertex_countdetail)/3); } void Model::add_engine(Engine *engine) { model_engine.push_back(engine); } void Model::add_light(Light *light) { model_light.push_back(light); } void Model::add_flare(Flare *flare) { model_flare.push_back(flare); } Model *Model::find(std::string const & name) { std::map::iterator it = registry.find(name); if (it == registry.end()) return 0; else return (*it).second; } Model *Model::load(std::string const & name) { Model *model = find(name); if (!model) { model = Map::load(name); if (model) registry[model->name()] = model; } return model; } void Model::clear() { // delete all models in the registry for (std::map::iterator mit = registry.begin(); mit != registry.end(); mit++) { delete(*mit).second; } registry.clear(); // clear the vertex array if (VertexArray::instance()) VertexArray::instance()->clear(); } void Model::list() { for (std::map::iterator mit = registry.begin(); mit != registry.end(); mit++) { con_print << " " << (*mit).second->name() << " " << (*mit).second->tris() << " triangles (" << (*mit).second->details() << " detail) " << (*mit).second->model_engine.size() << " engines " << (*mit).second->model_light.size() << " lights " << (*mit).second->model_flare.size() << " flares "; } con_print << registry.size() << " registered models" << std::endl; if (VertexArray::instance()) con_print << "vertex array " << (VertexArray::instance()->index() * 100 / VertexArray::instance()->size()) << "% used" << std::endl; } }