blob: 3ed5a9381d677a0327a8707b74d20ef2b7abe9e8 (
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/*
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/asefile.h"
#include "model/model.h"
#include "model/map.h"
#include "model/vertexarray.h"
namespace model
{
// static model registry
Model::Registry Model::model_registry;
Model::Model(std::string const & name) :
model_enginecolor(1.0f, 0.0f, 0.0f),
model_name(name)
{
model_radius = 0.5f;
model_enginesound = 0;
model_impulsesound = 0;
model_tris_detail_count = 0;
model_tris_count = 0;
model_quad_detail_count = 0;
model_quad_count = 0;
}
Model::~Model()
{
// delete all fragment groups
for (Groups::iterator git = model_groups.begin(); git != model_groups.end(); git++) {
delete (*git);
}
model_groups.clear();
// delete all docks
for (Docks::iterator dit = model_docks.begin(); dit != model_docks.end(); dit++) {
delete (*dit);
}
model_docks.clear();
// delete all particle systems
for (Model::ParticleSystems::iterator pit = model_particles.begin(); pit != model_particles.end(); pit++) {
delete (*pit);
}
model_particles.clear();
// delete all lights
for (Lights::iterator lit = model_lights.begin(); lit != model_lights.end(); lit++) {
delete(*lit);
}
model_lights.clear();
// delete all flares
for (Flares::iterator flit = model_flares.begin(); flit != model_flares.end(); flit++) {
delete(*flit);
}
model_flares.clear();
}
void Model::add_particles(Particles *particles)
{
model_particles.push_back(particles);
}
void Model::add_group(FragmentGroup *group)
{
model_groups.push_back(group);
}
void Model::add_light(Light *light)
{
model_lights.push_back(light);
}
void Model::add_flare(Flare *flare)
{
model_flares.push_back(flare);
}
void Model::add_dock(Dock *dock)
{
model_docks.push_back(dock);
}
Model *Model::find(std::string const & name)
{
Registry::iterator it = model_registry.find(name);
if (it == model_registry.end())
return 0;
else
return (*it).second;
}
Model *Model::load(std::string const & name)
{
Model *model = find(name);
if (!model) {
// try loading the .map model
model = Map::load(name);
}
if (!model) {
// if it can't be found, try the ase model
model = ASEFile::load(name);
}
if (!model) {
con_warn << "Could not load maps/" << name << ".map or models/" << name << ".ase" << std::endl;
} else {
model_registry[model->name()] = model;
}
return model;
}
void Model::clear()
{
// delete all models in the registry
for (Registry::iterator mit = model_registry.begin(); mit != model_registry.end(); mit++) {
delete(*mit).second;
}
model_registry.clear();
// clear the vertex array
if (VertexArray::instance())
VertexArray::instance()->clear();
}
void Model::list_model(Model *model)
{
size_t frags = 0;
for (Groups::iterator git = model->groups().begin(); git != model->groups().end(); git++) {
frags += (*git)->size();
}
con_print << " " << model->name() << " " << frags << " frags " <<
model->model_tris_count << "/" << model->model_tris_detail_count << " tris/detail " <<
model->model_quad_count << "/" << model->model_quad_detail_count << " quads/detail" << std::endl;
}
void Model::list()
{
for (Registry::iterator mit = model_registry.begin(); mit != model_registry.end(); mit++) {
list_model((*mit).second);
}
con_print << model_registry.size() << " registered models" << std::endl;
if (VertexArray::instance())
con_print << "vertex array " << (VertexArray::instance()->index() * 100 / VertexArray::instance()->size())
<< "% of " << VertexArray::instance()->size() * 4 *sizeof(float) / (1024*1024) << "Mb used" << std::endl;
}
}
|