diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/model.cc | 84 | ||||
-rw-r--r-- | src/core/model.h | 47 | ||||
-rw-r--r-- | src/core/net.h | 2 | ||||
-rw-r--r-- | src/render/draw.cc | 45 |
4 files changed, 117 insertions, 61 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; } + } 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<Triangle *> model_tris; + std::list<Triangle *> 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; } diff --git a/src/render/draw.cc b/src/render/draw.cc index e904888..590cddd 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -146,12 +146,7 @@ void draw_model_evertex(core::Entity *entity) size_t count = entity->model()->evertex_count(); render::gl::color(entity->color()); - glVertexPointer(3, GL_FLOAT, 0, core::VertexArray::evertex); - glNormalPointer(GL_FLOAT, 0, core::VertexArray::evertex_normal); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - + if (r_drawwireframe && r_drawwireframe->value()) { glDrawArrays(gl::LineLoop, index, count); } else { @@ -316,14 +311,6 @@ void draw_pass_default() /* Draw model vertices*/ void draw_pass_model_vertex() { - glVertexPointer(3, GL_FLOAT, 0, core::VertexArray::vertex); - glNormalPointer(GL_FLOAT, 0, core::VertexArray::vertex_normal); - glColorPointer(3, GL_FLOAT, 0, core::VertexArray::vertex_color); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - std::map<unsigned int, core::Entity *>::iterator it; for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { @@ -339,21 +326,11 @@ void draw_pass_model_vertex() gl::pop(); } } - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); } /* Draw entites with model evertices */ void draw_pass_model_evertex() { - glVertexPointer(3, GL_FLOAT, 0, core::VertexArray::evertex); - glNormalPointer(GL_FLOAT, 0, core::VertexArray::evertex_normal); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - std::map<unsigned int, core::Entity *>::iterator it; for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { @@ -369,9 +346,6 @@ void draw_pass_model_evertex() gl::pop(); } } - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); } /* Draw model lights, engines */ @@ -476,9 +450,24 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds gl::disable(GL_BLEND); // disbable alpha blending for world polys draw_pass_default(); // draw entities without model + + glVertexPointer(3, GL_FLOAT, 0, core::VertexArray::vertex); + glNormalPointer(GL_FLOAT, 0, core::VertexArray::vertex_normal); + glColorPointer(3, GL_FLOAT, 0, core::VertexArray::vertex_color); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + draw_pass_model_vertex(); // draw entities with model + + glDisableClientState(GL_COLOR_ARRAY); + draw_pass_model_evertex(); // draw entities with model, vertices with entity color - + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + gl::disable(GL_LIGHTING); gl::enable(GL_BLEND); |