From 80ad7e99b738f367eb045768d054cf74347ee1b4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 24 Mar 2008 11:08:22 +0000 Subject: merged vertex and evertex arrays --- src/core/model.cc | 84 ++++++++++++++++++++++++++++++++++++++++--------------- src/core/model.h | 47 ++++++++++++++++++++++++------- src/core/net.h | 2 +- 3 files changed, 100 insertions(+), 33 deletions(-) (limited to 'src/core') 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::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 & planes std::vector 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 & 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 & 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; } + } diff --git a/src/core/model.h b/src/core/model.h index bdfeb86..51e9ca7 100644 --- a/src/core/model.h +++ b/src/core/model.h @@ -23,11 +23,10 @@ class Model; namespace core { -/// Global vertex array - - +/// size of the global vertex array - 32M const size_t VERTEXARRAYSIZE=65536*512; +/// global vertex array class VertexArray { public: @@ -36,19 +35,40 @@ public: static float vertex_color[VERTEXARRAYSIZE]; static float vertex_normal[VERTEXARRAYSIZE]; - /// model vertices with entity color - static float evertex[VERTEXARRAYSIZE]; - static float evertex_normal[VERTEXARRAYSIZE]; - static size_t vertex_index; - static size_t evertex_index; static void clear(); static void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color); - static void add_evertex(math::Vector3f const &v, math::Vector3f const &n); +}; - +/// a model triangle +class Triangle +{ +public: + /// a new triangle with 3 vertices, a normal, color and a detail flag + Triangle(math::Vector3f const &v0, math::Vector3f const &v1, math::Vector3f const &v2, math::Vector3f const &n, + math::Color *color=0, bool detail=false); + ~Triangle(); + + /// normal of the triangle + inline math::Vector3f const & normal() const { return triangle_normal; } + /// color of the triangle + inline math::Color const & color() const { return triangle_color;} + /// indidcates if this triangle was generated from a detail brush + inline bool detail() const { return triangle_detail; } + + /// triangle vertex 0 + math::Vector3f triangle_v0; + /// triangle vertex 1 + math::Vector3f triangle_v1; + /// triangle vertex 2 + math::Vector3f triangle_v2; + +private: + math::Vector3f triangle_normal; + math::Color triangle_color; + bool triangle_detail; }; /// a spacecraft engine @@ -119,6 +139,9 @@ public: /// number of vertexes in this model inline size_t evertex_count() const { return model_evertex_count; } + /// number of triangles in this mdel + inline size_t tris() const { return (model_vertex_count + model_evertex_count)/3; } + /// radius inline float radius() const { return model_radius; } @@ -161,6 +184,10 @@ private: math::Vector3f model_maxbbox; math::Vector3f model_minbbox; + // tmp lists with triangles + std::list model_tris; + std::list model_etris; + size_t model_first_vertex; size_t model_vertex_count; size_t model_first_evertex; diff --git a/src/core/net.h b/src/core/net.h index 150bbc1..a659a7f 100644 --- a/src/core/net.h +++ b/src/core/net.h @@ -22,7 +22,7 @@ const unsigned int MAXPENDINGCONNECTIONS = 32; const unsigned int DEFAULTPORT = 8042; /// network timeout in seconds -const float NETTIMEOUT = 15; +const float NETTIMEOUT = 20; } -- cgit v1.2.3