Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/model.cc180
-rw-r--r--src/core/model.h57
-rw-r--r--src/core/netserver.cc2
3 files changed, 152 insertions, 87 deletions
diff --git a/src/core/model.cc b/src/core/model.cc
index 88a1040..df6e563 100644
--- a/src/core/model.cc
+++ b/src/core/model.cc
@@ -12,6 +12,7 @@
#include <vector>
#include <list>
+#include "core/cvar.h"
#include "core/model.h"
#include "filesystem/filesystem.h"
@@ -21,6 +22,64 @@ 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];
+
+size_t VertexArray::vertex_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));
+
+ vertex_index = 0;
+ evertex_index = 0;
+}
+
+void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) {
+ if (vertex_index + 3 >= VERTEXARRAYSIZE) {
+ con_warn << "VertexArray overflow!" << std::endl;
+ return;
+ }
+
+ for (int i = 0; i < 3; i ++) {
+ vertex[vertex_index+i] = v[i];
+ vertex_normal[vertex_index+i] = n[i];
+ }
+
+ vertex_color[vertex_index] = color.r;
+ vertex_color[vertex_index+1] = color.g;
+ vertex_color[vertex_index+2] = color.b;
+
+ 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;
+ return;
+ }
+
+ for (int i = 0; i < 3; i ++) {
+ evertex[evertex_index+i] = v[i];
+ evertex_normal[evertex_index+i] = n[i];
+ }
+
+ evertex_index += 3;
+}
+
/* ---------- core::Light ------------------------------------------ */
Light::Light(math::Vector3f const & location, math::Color const & color) :
@@ -40,38 +99,6 @@ Engine::Engine(math::Vector3f const & location) :
Engine::~Engine()
{}
-/* ---------- core::Face ------------------------------------------ */
-
-Face::Face(math::Vector3f const & normal, math::Color const *color) :
- face_normal(normal)
-{
- face_normal.normalize();
-
- if (color)
- face_color = new math::Color(*color);
- else
- face_color = 0;
-}
-
-Face::~Face()
-{
- for (std::vector<math::Vector3f *>::iterator it = face_vertex.begin(); it != face_vertex.end(); it++) {
- delete (*it);
- }
-
- face_vertex.clear();
-
- if (face_color)
- delete face_color;
-}
-
-void Face::add_vertex(math::Vector3f const & vertex)
-{
- math::Vector3f *v = new math::Vector3f(vertex);
-
- face_vertex.push_back(v);
-}
-
/* ---------- core::Model ------------------------------------------ */
std::map<std::string, Model*> Model::registry;
@@ -81,6 +108,10 @@ Model::Model(std::string const & name) :
{
model_valid = false;
model_scale = 1.0f / 1024.0f;
+ model_first_vertex = 0;
+ model_first_evertex = 0;
+ model_vertex_count = 0;
+ model_evertex_count = 0;
std::string fn("maps/");
fn.append(name);
@@ -113,6 +144,9 @@ Model::Model(std::string const & name) :
math::Vector3f class_origin;
float class_angle;
math::Color class_color;
+
+ model_first_evertex = VertexArray::evertex_index/3;
+ model_first_vertex = VertexArray::vertex_index/3;
while (ifs) {
ifs.getline(data, 1023);
@@ -135,14 +169,15 @@ Model::Model(std::string const & name) :
} else if (firstword == "}") {
//cout << " LEVEL -" << level << std::endl;
if ((level == 2) && (class_name == "worldspawn")) {
- //cout << "brush with " << planes.size() << " faces" << std::endl;
-
- // for every face
- std::vector<Vector3f *>points;
- for (std::vector<Plane3f *>::iterator face = planes.begin(); face != planes.end(); face++) {
- make_face((*face), planes);
+
+ if (!(Cvar::sv_dedicated && Cvar::sv_dedicated->value())) {
+ // for every face
+ std::vector<Vector3f *>points;
+ for (std::vector<Plane3f *>::iterator face = planes.begin(); face != planes.end(); face++) {
+ make_face((*face), planes);
+ }
}
-
+
// clean planes
for (std::vector<Plane3f *>::iterator it = planes.begin(); it != planes.end(); it++) {
delete(*it);
@@ -246,7 +281,7 @@ Model::Model(std::string const & name) :
ifs.close();
- if (model_face.size()) {
+ if ((model_vertex_count + model_evertex_count) > 0 ) {
if (model_maxbbox.lengthsquared() > model_minbbox.lengthsquared()) {
model_radius = model_maxbbox.length();
} else {
@@ -254,17 +289,12 @@ 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_face.size() << " polygons\n";
+ con_debug << " maps/" << name << ".map " << (model_vertex_count + model_evertex_count)/3 << " triangles" << std::endl;
}
Model::~Model()
{
- // delete all faces
- for (std::list<Face *>::iterator fit = model_face.begin(); fit != model_face.end(); fit++) {
- delete(*fit);
- }
- model_face.clear();
-
// delete all engines
for (std::list<Engine *>::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++) {
delete(*eit);
@@ -291,7 +321,6 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
// using suggestions from
// http://www.flipcode.com/archives/Level_Editing.shtml
- //cout << "Face with normal " << face->normal() << endl;
std::vector<math::Vector3f *> vl;
// inital vertexes
@@ -496,28 +525,46 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
} else
color = new math::Color(1.0f, 0.0, 1.0f);
- /*
+ // calculate bounding box
+ for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
+
+ *(*it) *= model_scale;
+
+ for (int i=0; i < 3; i++) {
+ if (model_maxbbox[i] < (*(*it))[i])
+ model_maxbbox[i] = (*(*it))[i];
+
+ if (model_minbbox[i] > (*(*it))[i])
+ model_minbbox[i] = (*(*it))[i];
+ }
+ }
+
// split face into triangles
while (vl.size() >2 ) {
std::vector<Vector3f *>::iterator v0 = vl.begin();
std::vector<Vector3f *>::reverse_iterator vn = vl.rbegin();
std::vector<Vector3f *>::reverse_iterator vn1 = vl.rbegin();
++vn1;
- */
- Face *mf = new Face(face->normal()*-1, color);
- for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
- mf->add_vertex(*(*it) * model_scale);
- // bounding box
- for (int i=0; i < 3; i++) {
- if (model_maxbbox[i] < (*(*it))[i] * model_scale)
- model_maxbbox[i] = (*(*it))[i] * model_scale;
-
- if (model_minbbox[i] > (*(*it))[i] * model_scale)
- model_minbbox[i] = (*(*it))[i] * model_scale;
+ Vector3f n(face->normal()*-1);
+ n.normalize();
+
+ if (!color) {
+ 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);
+ VertexArray::add_vertex(*(*v0), n, *color);
+ model_vertex_count += 3;
}
+
+ delete (*vn);
+ vl.pop_back();
}
- add_face(mf);
+ //add_face(mf);
if (color) delete color;
} else {
con_debug << "Unresolved face!\n";
@@ -531,11 +578,6 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
}
-void Model::add_face(Face *face)
-{
- model_face.push_back(face);
-}
-
void Model::add_engine(Engine *engine)
{
model_engine.push_back(engine);
@@ -572,12 +614,16 @@ void Model::clear()
delete(*mit).second;
}
registry.clear();
+
+ // clear the vertex array
+ VertexArray::clear();
}
void Model::list()
{
for (std::map<std::string, Model*>::iterator mit = registry.begin(); mit != registry.end(); mit++) {
- con_print << " " << (*mit).second->model_name << " " << (*mit).second->model_face.size() << " polys "
+ con_print << " " << (*mit).second->name() << " "
+ << ((*mit).second->vertex_count() + (*mit).second->evertex_count())/3 << " triangles "
<< (*mit).second->model_engine.size() << " engines "
<< (*mit).second->model_light.size() << " lights\n";
}
diff --git a/src/core/model.h b/src/core/model.h
index 00c8a48..5deee35 100644
--- a/src/core/model.h
+++ b/src/core/model.h
@@ -18,27 +18,31 @@
namespace core
{
-/// one face (polygon) of a model
-class Face {
+/// Global vertex array
+
+
+const size_t VERTEXARRAYSIZE=65536*512;
+
+class VertexArray
+{
public:
- Face(math::Vector3f const & normal, math::Color const *color=0);
- ~Face();
+ /// model vertices
+ static float vertex[VERTEXARRAYSIZE];
+ static float vertex_color[VERTEXARRAYSIZE];
+ static float vertex_normal[VERTEXARRAYSIZE];
- /// the normal of this face
- inline math::Vector3f const & normal() const { return face_normal; };
+ /// model vertices with entity color
+ static float evertex[VERTEXARRAYSIZE];
+ static float evertex_normal[VERTEXARRAYSIZE];
- /// the color of this face
- inline math::Color const *color() const { return face_color; };
+ static size_t vertex_index;
+ static size_t evertex_index;
- /// add a vertex to the face
- void add_vertex(math::Vector3f const &vertex);
+ static void clear();
- /// face vertexes
- std::vector<math::Vector3f *> face_vertex;
+ 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);
-private:
- math::Vector3f face_normal;
- math::Color *face_color;
};
@@ -95,6 +99,18 @@ public:
/// minimum values of the bounding box
inline math::Vector3f const & minbbox() const { return model_minbbox; }
+ /// first vertex in the global VertexArray
+ inline size_t first_vertex() const { return model_first_vertex; }
+
+ /// number of vertexes in this model
+ inline size_t vertex_count() const { return model_vertex_count; }
+
+ /// first vertex in the global VertexArray
+ inline size_t first_evertex() const { return model_first_evertex; }
+
+ /// number of vertexes in this model
+ inline size_t evertex_count() const { return model_evertex_count; }
+
/// radius
inline float radius() const { return model_radius; }
@@ -115,19 +131,17 @@ public:
/// list the content of the model registry
static void list();
- /// list of Faces
- std::list<Face *> model_face;
-
/// list of Engines
std::list<Engine *> model_engine;
/// list of Lights
std::list<Light *> model_light;
+
+
private:
void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes);
void add_engine(Engine *engine);
- void add_face(Face *face);
void add_light(Light *light);
std::string model_name;
@@ -138,6 +152,11 @@ private:
math::Vector3f model_maxbbox;
math::Vector3f model_minbbox;
+
+ size_t model_first_vertex;
+ size_t model_vertex_count;
+ size_t model_first_evertex;
+ size_t model_evertex_count;
};
}
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index c8c0a9d..16beee0 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -284,7 +284,7 @@ void NetServer::broadcast(std::string const & message, Player *ignore_player)
}
}
-// find the client corresponding to a player id
+// find the client corresponding to a player
NetClient *NetServer::find_client(Player const *player)
{
for (std::list<NetClient *>::iterator it = clients.begin(); it != clients.end(); it++) {