Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 813515b798844a79a7e2443eb1ad2b72f7864bf2 (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
/*
   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
{

// 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_tris_detail_count = 0;
	model_tris_count = 0;
	model_quad_detail_count = 0;
	model_quad_count = 0;
}

Model::~Model()
{
	// delete worldspawn
	model_worldspawn.clear();
	
	// delete all docks
	for (Docks::iterator dit = model_docks.begin(); dit != model_docks.end(); dit++) {
		delete (*dit);
	}

	// delete all engines
	for (Engines::iterator eit = model_engines.begin(); eit != model_engines.end(); eit++) {
		delete(*eit);
	}
	model_engines.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_engine(Engine *engine)
{
	model_engines.push_back(engine);
}

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) {
		model = Map::load(name);
		if (model) {
			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)
{
	con_print << "  " << model->name() << " "  <<  model->worldspawn().size() << " 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;
}

}