Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/map.cc75
-rw-r--r--src/model/vertexarray.cc16
-rw-r--r--src/model/vertexarray.h8
3 files changed, 61 insertions, 38 deletions
diff --git a/src/model/map.cc b/src/model/map.cc
index 972ae82..192814c 100644
--- a/src/model/map.cc
+++ b/src/model/map.cc
@@ -157,7 +157,8 @@ Model * Map::load(std::string const &name)
mapfile.close();
- if (VertexArray::instance() && ((mapfile.class_tris.size() + mapfile.class_etris.size() + mapfile.class_ltris.size()) > 0)) {
+ // process the triangles calculated by the mapfile and add them to the vertex array
+ if (VertexArray::instance() && !VertexArray::instance()->overflow() && ((mapfile.class_tris.size() + mapfile.class_etris.size() + mapfile.class_ltris.size()) > 0)) {
math::Vector3f center = (mapfile.class_minbbox + mapfile.class_maxbbox) / 2;
@@ -168,24 +169,28 @@ Model * Map::load(std::string const &name)
// structural triangles
model->model_first_vertex = VertexArray::instance()->index()/3;
- for (std::list<Triangle *>::iterator it = mapfile.class_tris.begin(); it != mapfile.class_tris.end(); it++) {
+ for (std::list<Triangle *>::iterator it = mapfile.class_tris.begin(); it != mapfile.class_tris.end() && !VertexArray::instance()->overflow(); it++) {
Triangle *triangle = (*it);
if (!triangle->detail()) {
- VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
- model->model_vertex_count += 3;
+ size_t count = 0;
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ if (count == 3)
+ model->model_vertex_count += count;
}
}
// detail triangles
- for (std::list<Triangle *>::iterator it = mapfile.class_tris.begin(); it != mapfile.class_tris.end(); it++) {
+ for (std::list<Triangle *>::iterator it = mapfile.class_tris.begin(); it != mapfile.class_tris.end() && !VertexArray::instance()->overflow(); it++) {
Triangle *triangle = (*it);
if (triangle->detail()) {
- VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
- model->model_vertex_countdetail += 3;
+ size_t count = 0;
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ if (count == 3)
+ model->model_vertex_countdetail += count;
}
delete triangle;
}
@@ -193,24 +198,28 @@ Model * Map::load(std::string const &name)
// structural etriangles
model->model_first_evertex = VertexArray::instance()->index()/3;
- for (std::list<Triangle *>::iterator it = mapfile.class_etris.begin(); it != mapfile.class_etris.end(); it++) {
+ for (std::list<Triangle *>::iterator it = mapfile.class_etris.begin(); it != mapfile.class_etris.end() && !VertexArray::instance()->overflow(); it++) {
Triangle *triangle = (*it);
if (!triangle->detail()) {
- VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
- model->model_evertex_count += 3;
+ size_t count = 0;
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ if (count == 3)
+ model->model_evertex_count += count;
}
}
// detail etriangles
- for (std::list<Triangle *>::iterator it = mapfile.class_etris.begin(); it != mapfile.class_etris.end(); it++) {
+ for (std::list<Triangle *>::iterator it = mapfile.class_etris.begin(); it != mapfile.class_etris.end() && !VertexArray::instance()->overflow(); it++) {
Triangle *triangle = (*it);
if (triangle->detail()) {
- VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
- model->model_evertex_countdetail += 3;
+ size_t count = 0;
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ if (count == 3)
+ model->model_evertex_countdetail += count;
}
delete triangle;
}
@@ -218,24 +227,28 @@ Model * Map::load(std::string const &name)
// structural ltriangles
model->model_first_lvertex = VertexArray::instance()->index()/3;
- for (std::list<Triangle *>::iterator it = mapfile.class_ltris.begin(); it != mapfile.class_ltris.end(); it++) {
+ for (std::list<Triangle *>::iterator it = mapfile.class_ltris.begin(); it != mapfile.class_ltris.end() && !VertexArray::instance()->overflow(); it++) {
Triangle *triangle = (*it);
if (!triangle->detail()) {
- VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
- model->model_lvertex_count += 3;
+ size_t count = 0;
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ if (count == 3)
+ model->model_lvertex_count += count;
}
}
// detail ltriangles
- for (std::list<Triangle *>::iterator it = mapfile.class_ltris.begin(); it != mapfile.class_ltris.end(); it++) {
+ for (std::list<Triangle *>::iterator it = mapfile.class_ltris.begin(); it != mapfile.class_ltris.end() && !VertexArray::instance()->overflow(); it++) {
Triangle *triangle = (*it);
if (triangle->detail()) {
- VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
- VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
- model->model_lvertex_countdetail += 3;
+ size_t count = 0;
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ if (count == 3)
+ model->model_lvertex_countdetail += count;
}
delete triangle;
}
diff --git a/src/model/vertexarray.cc b/src/model/vertexarray.cc
index b0da6ab..27124fa 100644
--- a/src/model/vertexarray.cc
+++ b/src/model/vertexarray.cc
@@ -44,11 +44,12 @@ VertexArray::~VertexArray()
void VertexArray::clear()
{
vertex_index = 0;
+ vertex_overflow = false;
memset(vertex_vertex, 0, sizeof(vertex_vertex));
memset(vertex_color, 0, sizeof(vertex_color));
memset(vertex_normal, 0, sizeof(vertex_normal));
- memset(vertex_texture, 0, sizeof(vertex_normal));
+ memset(vertex_texture, 0, sizeof(vertex_texture));
add_sphere();
}
@@ -128,10 +129,11 @@ void VertexArray::add_sphere()
delete[] costable;
}
-void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) {
+size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) {
if (vertex_index + 3 >= vertex_size) {
con_warn << "VertexArray overflow!" << std::endl;
- return;
+ vertex_overflow = true;
+ return 0;
}
for (int i = 0; i < 3; i ++) {
@@ -144,12 +146,15 @@ void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, m
vertex_color[vertex_index+2] = color.b;
vertex_index += 3;
+
+ return 1;
}
-void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, math::Vector3f const &tex) {
+size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, math::Vector3f const &tex) {
if (vertex_index + 3 >= vertex_size) {
con_warn << "VertexArray overflow!" << std::endl;
- return;
+ vertex_overflow = true;
+ return 0;
}
for (int i = 0; i < 3; i ++) {
@@ -163,6 +168,7 @@ void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, m
vertex_color[vertex_index+2] = color.b;
vertex_index += 3;
+ return 1;
}
}
diff --git a/src/model/vertexarray.h b/src/model/vertexarray.h
index 6ff32bc..26d2514 100644
--- a/src/model/vertexarray.h
+++ b/src/model/vertexarray.h
@@ -24,14 +24,16 @@ public:
void clear();
- void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color);
- void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, math::Vector3f const &tex);
+ size_t add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color);
+ size_t add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, math::Vector3f const &tex);
inline float *vertex() { return vertex_vertex; }
inline float *color() { return vertex_color; }
inline float *normal() { return vertex_normal; }
inline float *texture() { return vertex_texture; }
+ inline bool overflow() const { return vertex_overflow; }
+
inline size_t size() const { return vertex_size; }
inline size_t index() const { return vertex_index; }
@@ -50,6 +52,8 @@ private:
void add_sphere();
static VertexArray *vertex_instance;
+
+ bool vertex_overflow;
};
}