blob: 6508fdfd350b5cd1dba6e4fdfdd934cd61c8d23e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
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<std::string, Model*> 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::~Model()
{
// delete all engines
for (std::list<Engine *>::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++) {
delete(*eit);
}
model_engine.clear();
// delete all lights
for (std::list<Light *>::iterator lit = model_light.begin(); lit != model_light.end(); lit++) {
delete (*lit);
}
model_light.clear();
// delete all flares
for (std::list<Flare *>::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<std::string, Model*>::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<std::string, Model*>::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<std::string, Model*>::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;
}
}
|