From 25d2c764443723eb7a3dd5f8bf0b76586c1ff10b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 5 Apr 2008 10:52:39 +0000 Subject: Makefile.am updates, math::Axis, improved VertexArray, r_arraysize --- src/core/entity.cc | 33 +++++++++++++++ src/core/entity.h | 25 ++++++++++- src/core/model.cc | 106 +++++++++++++++++++++++----------------------- src/core/model.h | 40 ++++++++++++----- src/core/module.cc | 5 +++ src/core/module.h | 3 +- src/core/netconnection.cc | 60 +++++++++++++------------- 7 files changed, 177 insertions(+), 95 deletions(-) (limited to 'src/core') diff --git a/src/core/entity.cc b/src/core/entity.cc index ebf9723..1e90b2a 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -335,4 +335,37 @@ void EntityControlable::set_direction(float direction) } } +/*----- EntityGlobe ------------------------------------------------ */ + +EntityGlobe::EntityGlobe(unsigned int flags) : + Entity(flags) +{ + entity_texture_id = 0; + entity_shape = Sphere; +} + +EntityGlobe::EntityGlobe(std::istream & is) : + Entity(is) +{ + std::string n; + char c; + while ( (is.get(c)) && (c != '"')); + while ( (is.get(c)) && (c != '"')) + n += c; + entity_texture = n; + n.clear(); + +} + +EntityGlobe::~EntityGlobe() +{ +} + +void EntityGlobe::serialize(std::ostream & os) const +{ + Entity::serialize(os); + os << " \"" << entity_texture << "\""; } + +} + diff --git a/src/core/entity.h b/src/core/entity.h index 54479be..20242a9 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -32,7 +32,7 @@ public: enum Flags {Static=1, Solid=2, Bright=4}; /// Entity type constants - enum Type {Default=0, Dynamic=1, Controlable=2}; + enum Type {Default=0, Dynamic=1, Controlable=2, Globe=3}; /// Entity shape constants enum Shape {Diamond=0, Sphere=1, Cube=2, Axis=3}; @@ -276,6 +276,29 @@ public: float target_direction; }; +/// a Globe entity +class EntityGlobe : public Entity +{ +public: + EntityGlobe(unsigned int flags = 0); + EntityGlobe(std::istream & is); + + ~EntityGlobe(); + + virtual void serialize(std::ostream & os) const; + + +/*----- inspectors ------------------------------------------------ */ + + /// core type id + virtual inline unsigned int type() const { return Entity::Globe; } + + std::string entity_texture; + + /// client side, texture id + unsigned int entity_texture_id; +}; + } #endif // __INCLUDED_CORE_ENTITY_H__ diff --git a/src/core/model.cc b/src/core/model.cc index 1ddefca..a09c7fd 100644 --- a/src/core/model.cc +++ b/src/core/model.cc @@ -19,37 +19,51 @@ namespace core { -//const float MAX_BOUNDS = 8192; const float MAX_BOUNDS = 16384; - const float delta = 10e-10; /* ---------- core::VertexArray ------------------------------------ */ -float VertexArray::vertex[VERTEXARRAYSIZE]; -float VertexArray::vertex_color[VERTEXARRAYSIZE]; -float VertexArray::vertex_normal[VERTEXARRAYSIZE]; +VertexArray *VertexArray::vertex_instance = 0 ; + +VertexArray::VertexArray(size_t size) +{ + vertex_instance = this; + vertex_size = size * 1024*1024; // megabytes + vertex_size = vertex_size / sizeof(float); // sizeof float + vertex_size = vertex_size / 4; // 4 arrays + + vertex_vertex = (float *) malloc(vertex_size * sizeof(float)); + vertex_color = (float *) malloc(vertex_size * sizeof(float)); + vertex_normal = (float *) malloc(vertex_size * sizeof(float)); + vertex_texture = (float *) malloc(vertex_size * sizeof(float)); -//float VertexArray::evertex[VERTEXARRAYSIZE]; -//float VertexArray::evertex_normal[VERTEXARRAYSIZE]; + con_print << "Initializing vertex array..." << std::endl; + con_debug << " " << size << " Mb allocated" << std::endl; -size_t VertexArray::vertex_index; -//size_t VertexArray::evertex_index; + clear(); +} + +VertexArray::~VertexArray() +{ + free(vertex_vertex); + free(vertex_normal); + free(vertex_color); + free(vertex_texture); + + vertex_instance = 0 ; +} void VertexArray::clear() { vertex_index = 0; - // 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)); - - add_sphere(); - } + 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)); - + add_sphere(); } void VertexArray::add_sphere() @@ -122,13 +136,13 @@ void VertexArray::add_sphere() } void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) { - if (vertex_index + 3 >= VERTEXARRAYSIZE) { + if (vertex_index + 3 >= vertex_size) { con_warn << "VertexArray overflow!" << std::endl; return; } for (int i = 0; i < 3; i ++) { - vertex[vertex_index+i] = v[i]; + vertex_vertex[vertex_index+i] = v[i]; vertex_normal[vertex_index+i] = n[i]; } @@ -139,21 +153,6 @@ 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; - 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::Triangle --------------------------------------- */ Triangle::Triangle(math::Vector3f const &v0, math::Vector3f const &v1, math::Vector3f const &v2, math::Vector3f const &n, math::Color *color, bool detail) : @@ -272,7 +271,7 @@ Model::Model(std::string const & name) : //cout << " LEVEL -" << level << std::endl; if ((level == 2) && (class_name == "worldspawn")) { - if (!(Cvar::sv_dedicated && Cvar::sv_dedicated->value())) { + if (VertexArray::instance()) { // for every face std::vectorpoints; for (std::vector::iterator face = planes.begin(); face != planes.end(); face++) { @@ -412,13 +411,13 @@ Model::Model(std::string const & name) : model_radius = model_maxbbox.length(); // structural triangles - model_first_vertex = VertexArray::vertex_index/3; + model_first_vertex = VertexArray::instance()->index()/3; for (std::list::iterator it = model_tris.begin(); it != model_tris.end(); it++) { Triangle *triangle = (*it); if (!triangle->detail()) { - VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + 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_vertex_count += 3; } } @@ -426,9 +425,9 @@ Model::Model(std::string const & name) : for (std::list::iterator it = model_tris.begin(); it != model_tris.end(); it++) { Triangle *triangle = (*it); if (triangle->detail()) { - VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + 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_vertex_countdetail += 3; } delete triangle; @@ -436,13 +435,13 @@ Model::Model(std::string const & name) : model_tris.clear(); // structural etriangles - model_first_evertex = VertexArray::vertex_index/3; + model_first_evertex = VertexArray::instance()->index()/3; for (std::list::iterator it = model_etris.begin(); it != model_etris.end(); it++) { Triangle *triangle = (*it); if (!triangle->detail()) { - VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + 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_evertex_count += 3; } } @@ -451,9 +450,9 @@ Model::Model(std::string const & name) : for (std::list::iterator it = model_etris.begin(); it != model_etris.end(); it++) { Triangle *triangle = (*it); if (triangle->detail()) { - VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + 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_evertex_countdetail += 3; } delete triangle; @@ -820,7 +819,8 @@ void Model::clear() registry.clear(); // clear the vertex array - VertexArray::clear(); + if (VertexArray::instance()) + VertexArray::instance()->clear(); } void Model::list() @@ -833,7 +833,9 @@ void Model::list() << (*mit).second->model_light.size() << " lights\n"; } con_print << registry.size() << " registered models" << std::endl; - con_print << "vertex array " << VertexArray::vertex_index/3 << "/" << VERTEXARRAYSIZE/3 << " used" << std::endl; + if (VertexArray::instance()) + con_print << "vertex array " << (VertexArray::instance()->index() * 100 / VertexArray::instance()->size()) + << "% used" << std::endl; } } diff --git a/src/core/model.h b/src/core/model.h index 958acc0..60746ae 100644 --- a/src/core/model.h +++ b/src/core/model.h @@ -23,27 +23,45 @@ class Model; namespace core { -/// size of the global vertex array - 32M -const size_t VERTEXARRAYSIZE=65536*512; +/// global vertex array + const int SPHERESEGMENTS=33; -/// global vertex array class VertexArray { public: - /// model vertices - static float vertex[VERTEXARRAYSIZE]; - static float vertex_color[VERTEXARRAYSIZE]; - static float vertex_normal[VERTEXARRAYSIZE]; + /// Create a new VertexArray with size in Mb + VertexArray(size_t size); + ~VertexArray(); - static size_t vertex_index; + void clear(); - static void clear(); + void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color); + + + 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 size_t size() const { return vertex_size; } + inline size_t index() const { return vertex_index; } - static void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color); + static inline VertexArray *instance() { return vertex_instance; } private: - static void add_sphere(); + /// model vertices + float *vertex_vertex; + float *vertex_color; + float *vertex_normal; + float *vertex_texture; + + size_t vertex_index; + size_t vertex_size; + + void add_sphere(); + + static VertexArray *vertex_instance; }; /// a model triangle diff --git a/src/core/module.cc b/src/core/module.cc index 45559f2..8eef50f 100644 --- a/src/core/module.cc +++ b/src/core/module.cc @@ -38,4 +38,9 @@ void Module::unload() } } +void Module::abort() +{ + module_running = false; +} + } diff --git a/src/core/module.h b/src/core/module.h index 053c9e5..61dc0dc 100644 --- a/src/core/module.h +++ b/src/core/module.h @@ -29,7 +29,7 @@ public: /// return the name of the module inline std::string const & name() const { return module_name; } - + /*----- mutators -------------------------------------------------- */ /// initialize the game module @@ -66,7 +66,6 @@ protected: private: static Module *module_preload; std::string module_name; - }; } diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 9fd4e33..fd590c0 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -304,48 +304,50 @@ void NetConnection::parse_incoming_message(const std::string & message) } else if (command == "die") { unsigned int id; - msgstream >> id; - - Entity *e = Entity::find(id); - //con_debug << "Received die entity id " << id << "\n"; - - if (localcontrol() == e) - localplayer()->player_control = 0; - if (e) - Entity::remove(id); - + if (msgstream >> id) { + //con_debug << "Received die entity id " << id << std::endl; + Entity *e = Entity::find(id); + if (localcontrol() == e) + localplayer()->player_control = 0; + if (e) + Entity::remove(id); + } } else if (command == "ent") { unsigned int type; - msgstream >> type; - - //con_debug << "Received create entity type " << type << "\n"; - switch (type) - { - case Entity::Default: - new Entity(msgstream); - break; - case Entity::Dynamic: - new EntityDynamic(msgstream); - break; - case Entity::Controlable: - new EntityControlable(msgstream); - break; - default: - break; + if (msgstream >> type) { + //con_debug << "Received create entity type " << type << std::endl; + switch (type) + { + case Entity::Default: + new Entity(msgstream); + break; + case Entity::Dynamic: + new EntityDynamic(msgstream); + break; + case Entity::Controlable: + new EntityControlable(msgstream); + break; + case Entity::Globe: + new EntityGlobe(msgstream); + break; + default: + con_warn << "Create for unknown entity type " << type << std::endl; + break; + } } - } else if (command == "sup") { unsigned int id; if (msgstream >> id) { + //con_debug << "Received update entity id " << id << std::endl; Entity *entity = Entity::find(id); if (!entity) { - con_warn << "Update for unknown entity " << id << "\n"; + con_warn << "Update for unknown entity " << id << std::endl; } else entity->recieve_server_update(msgstream); } } else if (command == "pif") { - + //con_debug << "Received update player info" << std::endl; connection()->localplayer()->recieve_server_update(msgstream); } -- cgit v1.2.3