Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/model.cc')
-rw-r--r--src/core/model.cc84
1 files changed, 62 insertions, 22 deletions
diff --git a/src/core/model.cc b/src/core/model.cc
index 7c83edd..9f135b4 100644
--- a/src/core/model.cc
+++ b/src/core/model.cc
@@ -22,30 +22,32 @@ namespace core
const float MAX_BOUNDS = 8192;
const float delta = 10e-10;
-const size_t VERTEXARRAYVERTEXARRAYSIZE=65536*3;
-
/* ---------- core::VertexArray ------------------------------------ */
+
float VertexArray::vertex[VERTEXARRAYSIZE];
float VertexArray::vertex_color[VERTEXARRAYSIZE];
float VertexArray::vertex_normal[VERTEXARRAYSIZE];
-float VertexArray::evertex[VERTEXARRAYSIZE];
-float VertexArray::evertex_normal[VERTEXARRAYSIZE];
+//float VertexArray::evertex[VERTEXARRAYSIZE];
+//float VertexArray::evertex_normal[VERTEXARRAYSIZE];
size_t VertexArray::vertex_index;
-size_t VertexArray::evertex_index;
+//size_t VertexArray::evertex_index;
void VertexArray::clear()
{
- memset(vertex, 0, sizeof(vertex));
- memset(vertex_color, 0, sizeof(vertex_color));
- memset(vertex_normal, 0, sizeof(vertex_normal));
-
- memset(evertex, 0, sizeof(evertex));
- memset(evertex_normal, 0, sizeof(evertex_normal));
+ // The VertexArray is only used by the client
+ if (!(Cvar::sv_dedicated && Cvar::sv_dedicated->value())) {
+ memset(vertex, 0, sizeof(vertex));
+ memset(vertex_color, 0, sizeof(vertex_color));
+ memset(vertex_normal, 0, sizeof(vertex_normal));
+
+ //memset(evertex, 0, sizeof(evertex));
+ //memset(evertex_normal, 0, sizeof(evertex_normal));
+ }
vertex_index = 0;
- evertex_index = 0;
+ //evertex_index = 0;
}
void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) {
@@ -66,6 +68,7 @@ void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, m
vertex_index += 3;
}
+/*
void VertexArray::add_evertex(math::Vector3f const &v, math::Vector3f const &n) {
if (evertex_index + 3 >= VERTEXARRAYSIZE) {
con_warn << "EVertexArray overflow!" << std::endl;
@@ -79,6 +82,27 @@ void VertexArray::add_evertex(math::Vector3f const &v, math::Vector3f const &n)
evertex_index += 3;
}
+*/
+
+/* ---------- core::Triangle --------------------------------------- */
+Triangle::Triangle(math::Vector3f const &v0, math::Vector3f const &v1, math::Vector3f const &v2, math::Vector3f const &n, math::Color *color, bool detail) :
+ triangle_v0(v0),
+ triangle_v1(v1),
+ triangle_v2(v2),
+ triangle_normal(n)
+{
+
+ if (color)
+ triangle_color = *color;
+ else
+ math::Color(1.0f, 1.0f, 1.0f);
+
+ triangle_detail = detail;
+}
+
+Triangle::~Triangle()
+{
+}
/* ---------- core::Light ------------------------------------------ */
@@ -148,7 +172,6 @@ Model::Model(std::string const & name) :
math::Color class_color;
unsigned int class_spawnflags;
- model_first_evertex = VertexArray::evertex_index/3;
model_first_vertex = VertexArray::vertex_index/3;
while (ifs) {
@@ -296,7 +319,20 @@ Model::Model(std::string const & name) :
}
ifs.close();
-
+
+ model_first_evertex = VertexArray::vertex_index/3;
+ if (model_etris.size()) {
+ for (std::list<Triangle *>::iterator it = model_etris.begin(); it != model_etris.end(); it++) {
+ Triangle *triangle = (*it);
+ VertexArray::add_vertex(triangle->triangle_v0, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v1, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v2, triangle->normal(), triangle->color() );
+ model_evertex_count += 3;
+ delete triangle;
+ }
+ model_etris.clear();
+ }
+
if ((model_vertex_count + model_evertex_count) > 0 ) {
if (model_maxbbox.lengthsquared() > model_minbbox.lengthsquared()) {
model_radius = model_maxbbox.length();
@@ -306,7 +342,7 @@ Model::Model(std::string const & name) :
model_valid = true;
}
//con_debug << " maps/" << name << ".map " << model_face.size() << " polygons\n";
- con_debug << " maps/" << name << ".map " << (model_vertex_count + model_evertex_count)/3 << " triangles" << std::endl;
+ con_debug << " maps/" << name << ".map " << tris() << " triangles" << std::endl;
}
Model::~Model()
@@ -344,7 +380,7 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
std::vector<math::Vector3f *> vl;
- // inital vertexes
+ // inital vertices
// check if the face is x-axis oriented
if ((fabsf(face->normal().x) >= fabsf(face->normal().y)) && (fabsf(face->normal().x) >= fabsf(face->normal().z))) {
@@ -544,6 +580,7 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
} else if (face->texture() == "common/entity") {
color = 0;
} else
+ // unknown textures get hot pink
color = new math::Color(1.0f, 0.0, 1.0f);
// calculate bounding box
@@ -571,10 +608,13 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
n.normalize();
if (!color) {
- VertexArray::add_evertex(*(*vn1), n);
- VertexArray::add_evertex(*(*vn), n);
- VertexArray::add_evertex(*(*v0), n);
- model_evertex_count += 3;
+ // evertices will be added to the VertexArray after normal vertices
+ Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, 0, false);
+ model_etris.push_back(triangle);
+ //VertexArray::add_evertex(*(*vn1), n);
+ //VertexArray::add_evertex(*(*vn), n);
+ //VertexArray::add_evertex(*(*v0), n);
+ //model_evertex_count += 3;
} else {
VertexArray::add_vertex(*(*vn1), n, *color);
VertexArray::add_vertex(*(*vn), n, *color);
@@ -649,7 +689,7 @@ void Model::list()
<< (*mit).second->model_light.size() << " lights\n";
}
con_print << registry.size() << " registered models" << std::endl;
- con_print << "vertex/evertex array usage " << (VertexArray::vertex_index * 100) / VERTEXARRAYSIZE << "%/" <<
- (VertexArray::evertex_index * 100) / VERTEXARRAYSIZE << "%\n";
+ con_print << "vertex array " << VertexArray::vertex_index << "/" << VERTEXARRAYSIZE << " used" << std::endl;
}
+
}