diff options
-rw-r--r-- | osirion.kdevelop | 2 | ||||
-rw-r--r-- | osirion.kdevelop.pcs | bin | 523363 -> 556279 bytes | |||
-rw-r--r-- | osirion.kdevses | 19 | ||||
-rw-r--r-- | src/Makefile.am | 10 | ||||
-rw-r--r-- | src/client/Makefile.am | 5 | ||||
-rw-r--r-- | src/client/input.cc | 9 | ||||
-rw-r--r-- | src/client/input.h | 3 | ||||
-rw-r--r-- | src/client/view.cc | 62 | ||||
-rw-r--r-- | src/core/entity.cc | 33 | ||||
-rw-r--r-- | src/core/entity.h | 25 | ||||
-rw-r--r-- | src/core/model.cc | 106 | ||||
-rw-r--r-- | src/core/model.h | 40 | ||||
-rw-r--r-- | src/core/module.cc | 5 | ||||
-rw-r--r-- | src/core/module.h | 3 | ||||
-rw-r--r-- | src/core/netconnection.cc | 60 | ||||
-rw-r--r-- | src/math/Makefile.am | 4 | ||||
-rw-r--r-- | src/math/axis.cc | 54 | ||||
-rw-r--r-- | src/math/axis.h | 52 | ||||
-rw-r--r-- | src/math/color.h | 2 | ||||
-rw-r--r-- | src/render/draw.cc | 8 | ||||
-rw-r--r-- | src/render/render.cc | 39 | ||||
-rw-r--r-- | src/render/render.h | 7 | ||||
-rw-r--r-- | src/server/Makefile.am | 3 |
23 files changed, 417 insertions, 134 deletions
diff --git a/osirion.kdevelop b/osirion.kdevelop index 0a41004..475045a 100644 --- a/osirion.kdevelop +++ b/osirion.kdevelop @@ -21,7 +21,7 @@ </general> <kdevautoproject> <general> - <activetarget>src/render/librender.la</activetarget> + <activetarget>src/math/libmath.la</activetarget> <useconfiguration>debug</useconfiguration> </general> <run> diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs Binary files differindex 053b777..89b1535 100644 --- a/osirion.kdevelop.pcs +++ b/osirion.kdevelop.pcs diff --git a/osirion.kdevses b/osirion.kdevses index 9b9e01d..1fa919a 100644 --- a/osirion.kdevses +++ b/osirion.kdevses @@ -1,13 +1,22 @@ <?xml version = '1.0' encoding = 'UTF-8'?> <!DOCTYPE KDevPrjSession> <KDevPrjSession> - <DocsAndViews NumberOfDocuments="2" > - <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/input.cc" > - <View0 Encoding="" line="153" Type="Source" /> + <DocsAndViews NumberOfDocuments="5" > + <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/model.cc" > + <View0 Encoding="" line="75" Type="Source" /> </Doc0> - <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/video.cc" > - <View0 Encoding="" line="221" Type="Source" /> + <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/model.h" > + <View0 Encoding="" line="28" Type="Source" /> </Doc1> + <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/draw.cc" > + <View0 Encoding="" line="381" Type="Source" /> + </Doc2> + <Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/render.h" > + <View0 Encoding="" line="28" Type="Source" /> + </Doc3> + <Doc4 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/render.cc" > + <View0 Encoding="" line="89" Type="Source" /> + </Doc4> </DocsAndViews> <pluginList> <kdevdebugger> diff --git a/src/Makefile.am b/src/Makefile.am index 504afb6..e6595f6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,16 +12,14 @@ bin_PROGRAMS = osiriond osirion osiriond_SOURCES = osiriond.cc EXTRA_osiriond_SOURCES = osiriond-res.rc osiriond_DEPENDENCIES = $(ICON_SERVER) -osiriond_LDADD = $(ICON_SERVER) $(top_builddir)/src/game/libgame.la \ - $(top_builddir)/src/core/libcore.la $(top_builddir)/src/server/libserver.la \ - $(HOST_LIBS) +osiriond_LDADD = $(top_builddir)/src/game/libgame.la \ + $(top_builddir)/src/server/libserver.la $(HOST_LIBS) $(ICON_SERVER) # client osirion_SOURCES = osirion.cc EXTRA_osirion_SOURCES = osirion-res.rc osirion_DEPENDENCIES = $(ICON_CLIENT) osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) $(GLUT_CFLAGS) -osirion_LDADD = $(ICON_CLIENT) $(top_builddir)/src/game/libgame.la \ - $(top_builddir)/src/core/libcore.la $(top_builddir)/src/client/libclient.la \ - $(HOST_LIBS) $(GL_LIBS) +osirion_LDADD = $(top_builddir)/src/game/libgame.la \ + $(top_builddir)/src/client/libclient.la $(GL_LIBS) $(HOST_LIBS) $(ICON_CLIENT) osirion_LDFLAGS = $(LIBSDL_LIBS) diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 0d74532..8022dfa 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -8,6 +8,5 @@ libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS) noinst_LTLIBRARIES = libclient.la noinst_HEADERS = camera.h chat.h client.h console.h input.h keyboard.h video.h \ view.h -libclient_la_LIBADD = $(top_builddir)/src/core/libcore.la \ - $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/render/librender.la $(top_builddir)/src/sys/libsys.la +libclient_la_LIBADD = $(top_builddir)/src/render/librender.la \ + $(top_builddir)/src/core/libcore.la diff --git a/src/client/input.cc b/src/client/input.cc index 1a61424..88d1dd3 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -28,6 +28,10 @@ float local_thrust; // last controlled entity unsigned int last_control = 0; +// mouse cursor position +int mouse_x = 0; +int mouse_y = 0; + void init() { con_print << "Initializing input..." << std::endl; @@ -117,6 +121,11 @@ void frame(float seconds) while (SDL_PollEvent(&event)) { switch (event.type) { + case SDL_MOUSEMOTION: + mouse_x = event.motion.x; + mouse_y = event.motion.y; + break; + case SDL_KEYUP: if (event.key.keysym.sym == SDLK_PRINT) { video::screenshot(); diff --git a/src/client/input.h b/src/client/input.h index daca0d6..9d47eb8 100644 --- a/src/client/input.h +++ b/src/client/input.h @@ -22,6 +22,9 @@ void shutdown(); /// handle one frame of input events void frame(float seconds); +extern int mouse_x; +extern int mouse_y; + } // namespace input } // namespace client diff --git a/src/client/view.cc b/src/client/view.cc index a19f98a..c31cc12 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -15,6 +15,7 @@ #include "client/camera.h" #include "client/chat.h" #include "client/console.h" +#include "client/input.h" #include "client/video.h" #include "render/draw.h" #include "render/render.h" @@ -25,6 +26,9 @@ namespace client { +core::Cvar *draw_stats = 0; +core::Cvar *draw_crosshaircolor = 0; + namespace view { @@ -33,6 +37,9 @@ float fps = 0; void init() { camera::init(); + + draw_stats = core::Cvar::get("draw_stats", "0", core::Cvar::Archive); + draw_crosshaircolor = core::Cvar::get("draw_crosshaircolor", "1 1 1", core::Cvar::Archive); } void shutdown() @@ -93,7 +100,6 @@ void draw_loader() { using namespace render; - gl::enable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, render::textures[0]); // bitmaps/loader.tga gl::color(1.0f, 1.0f, 1.0f, 1.0f); @@ -111,8 +117,6 @@ void draw_loader() glTexCoord2f(0.0f, 1.0f); gl::vertex(0,video::height,0); gl::end(); - - gl::disable(GL_TEXTURE_2D); } void draw_status() @@ -123,7 +127,6 @@ void draw_status() return; glBindTexture(GL_TEXTURE_2D, render::textures[1]); // bitmaps/conchars.tga - gl::enable(GL_TEXTURE_2D); // print the status in the upper left corner gl::color(1.0f, 1.0f, 1.0f, 1.0f); @@ -144,7 +147,7 @@ void draw_status() draw_text(CHARWIDTH, 4, status); // print stats if desired - if (render::r_drawstats && render::r_drawstats->value()) { + if (draw_stats && draw_stats->value()) { std::stringstream stats; stats << "fps " << std::setw(6) << fps << "\n"; if (core::application()->connected()) { @@ -184,11 +187,49 @@ void draw_status() if (core::localcontrol()) { status.str(""); status << " dir " << std::setfill('0') << std::setw(3) << roundf(core::localcontrol()->direction()) << - " speed " << std::setfill(' ') << std::setw(5) << std::fixed << std::setprecision(2) << core::localcontrol()->speed(); + " speed " << std::setfill(' ') << std::setw(5) << std::fixed << std::setprecision(2) << core::localcontrol()->speed() << " - " << input::mouse_x << "+" << input::mouse_y; + draw_text(CHARWIDTH, video::height - CHARHEIGHT -4, status); } - gl::disable(GL_TEXTURE_2D); +} + +void draw_cursor() +{ + if (!core::localcontrol() || console::visible()) + return; + + float crosshair_size = 48.0f; + float x = input::mouse_x - (crosshair_size /2); + float y = input::mouse_y - (crosshair_size /2); + + using namespace render; + + glBindTexture(GL_TEXTURE_2D, render::textures[2]); // bitmaps/crosshairs.tga + + math::Color color; + if (draw_crosshaircolor && draw_crosshaircolor->value()) { + std::stringstream colorstr(draw_crosshaircolor->str()); + colorstr >> color; + } + color.a = 0.5f; + + gl::color(color); + gl::begin(gl::Quads); + + glTexCoord2f(0,0 ); + gl::vertex(x,y,0.0f); + + glTexCoord2f(1, 0); + gl::vertex(x+crosshair_size, y, 0.0f); + + glTexCoord2f(1, 1); + gl::vertex(x+crosshair_size, y+crosshair_size, 0.0f); + + glTexCoord2f(0, 1); + gl::vertex(x, y+crosshair_size, 0.0f); + + gl::end(); } void frame(float seconds) @@ -234,6 +275,8 @@ void frame(float seconds) gl::matrixmode(GL_MODELVIEW); gl::loadidentity(); + gl::enable(GL_TEXTURE_2D); + if (!core::application()->connected()) { // draw the loader bitmap draw_loader(); @@ -245,6 +288,11 @@ void frame(float seconds) // draw the status line draw_status(); + + // draw the mouse cursor + draw_cursor(); + + gl::disable(GL_TEXTURE_2D); } } //namespace view 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::vector<Vector3f *>points; for (std::vector<Plane3f *>::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<Triangle *>::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<Triangle *>::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<Triangle *>::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<Triangle *>::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); } diff --git a/src/math/Makefile.am b/src/math/Makefile.am index a622ba7..465f9b0 100644 --- a/src/math/Makefile.am +++ b/src/math/Makefile.am @@ -1,9 +1,9 @@ METASOURCES = AUTO -libmath_la_SOURCES = color.cc functions.cc plane3f.cc vector3f.cc +libmath_la_SOURCES = axis.cc color.cc functions.cc plane3f.cc vector3f.cc libmath_la_LDFLAGS = -avoid-version -no-undefined -lm noinst_LTLIBRARIES = libmath.la -noinst_HEADERS = color.h functions.h mathlib.h plane3f.h vector3f.h +noinst_HEADERS = axis.h color.h functions.h mathlib.h plane3f.h vector3f.h INCLUDES = -I$(top_srcdir)/src diff --git a/src/math/axis.cc b/src/math/axis.cc new file mode 100644 index 0000000..7bd5262 --- /dev/null +++ b/src/math/axis.cc @@ -0,0 +1,54 @@ +/* + math/axis.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +// project headers +#include "math/axis.h" + +namespace math +{ + +Axis::Axis() +{ + clear(); +} + +Axis::Axis(const Axis & other) { + assign(other); +} + +void Axis::clear() +{ + axis_vector[0] = Vector3f(1.0f, 0.0f, 0.0f); + axis_vector[1] = Vector3f(0.0f, 1.0f, 0.0f); + axis_vector[2] = Vector3f(0.0f, 0.0f, 1.0f); +} + +void Axis::assign(const Axis & other) { + for (size_t i=0; i < 3; i++) { + axis_vector[i].assign(other.axis_vector[i]); + } +} + +Axis & Axis::operator=(const Axis & other) { + assign(other); + return *this; +} + +// alter heading, rotate around Z-axis (positive is left) +void Axis::direction(const float angle) { + for (size_t i=0; i < 3; i++) { + //axis_vector[i].rotate(axis_vector[2], angle); + } +} + +// alter heading, rotate around negative Y-axis (positive is up) +void Axis::pitch(const float pitch) { + for (size_t i=0; i < 3; i++) { + //axis_vector[i].rotate(axis_vector[1], -angle); + } +} + +} diff --git a/src/math/axis.h b/src/math/axis.h new file mode 100644 index 0000000..73474ef --- /dev/null +++ b/src/math/axis.h @@ -0,0 +1,52 @@ +/* + math/axis.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_MATH_AXIS_H__ +#define __INCLUDED_MATH_AXIS_H__ + +#include <iostream> + +#include "math/vector3f.h" + +namespace math +{ + +/// a local coordinates system +class Axis { +public: + Axis(); + Axis(const Axis & other); + + void clear(); + + void assign(const Axis & other); + + /// global coordinates of the X-axis in the local coordinates system + inline Vector3f const & forward() { return axis_vector[0]; } + + /// global coordinates of the Y-axis in the local coordinates system + inline Vector3f const & left() { return axis_vector[1]; } + + /// global coordinates of the Z-axis in the local coordinates system + inline Vector3f const & up() { return axis_vector[2]; } + + inline Vector3f const operator[](size_t index) { return axis_vector[index]; } + + Axis & operator=(const Axis & other); + + /// alter heading, rotate around Z-axis (positive is left) + void direction(const float angle); + + /// alter heading, rotate around negative Y-axis (positive is up) + void pitch(const float angle); + +private: + Vector3f axis_vector[3]; +}; + +} + +#endif // __INCLUDED_MATH_AXIS_H__ diff --git a/src/math/color.h b/src/math/color.h index 5684770..7fa0d68 100644 --- a/src/math/color.h +++ b/src/math/color.h @@ -1,5 +1,5 @@ /* - common/color.h + math/color.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ diff --git a/src/render/draw.cc b/src/render/draw.cc index 2775f63..4305b4d 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -381,7 +381,7 @@ void draw_pass_model_fx() { void draw_pass_model_radius() { - if (!(r_drawradius && r_drawradius->value())) + if (!(r_radius && r_radius->value())) return; for (std::map<unsigned int, core::Entity *>::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { @@ -457,9 +457,9 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds gl::disable(GL_BLEND); // disbable alpha blending for world polys gl::disable(GL_RESCALE_NORMAL); - 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); + glVertexPointer(3, GL_FLOAT, 0, vertexarray->vertex()); + glNormalPointer(GL_FLOAT, 0, vertexarray->normal()); + glColorPointer(3, GL_FLOAT, 0, vertexarray->color()); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); diff --git a/src/render/render.cc b/src/render/render.cc index 76704a4..8311c16 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -20,9 +20,11 @@ namespace render { GLuint textures[32]; -core::Cvar *r_drawradius = 0; -core::Cvar *r_drawstats = 0; +core::Cvar *r_radius = 0; core::Cvar *r_wireframe = 0; +core::Cvar * r_arraysize = 0; + +core::VertexArray *vertexarray = 0; bool texture(const char *filename, size_t id) { @@ -30,8 +32,6 @@ bool texture(const char *filename, size_t id) if (!image) return false; - // FIXME - I don't get this part... yet - glGenTextures(1, &textures[id]); glBindTexture(GL_TEXTURE_2D, textures[id]); @@ -64,19 +64,46 @@ void init() con_error << "Essential file bitmaps/loader.tga missing" << std::endl; core::application()->shutdown(); } + if (!texture("bitmaps/conchars.tga", 1)) { con_error << "Essential file bitmaps/conchars.tga missing" << std::endl; core::application()->shutdown(); } - r_drawradius = core::Cvar::get("r_drawradius", "0", core::Cvar::Archive); - r_drawstats = core::Cvar::get("r_drawstats", "0", core::Cvar::Archive); + if (!texture("bitmaps/crosshair.tga", 2)) { + con_error << "Essential file bitmaps/crosshair.tga missing" << std::endl; + core::application()->shutdown(); + } + + r_arraysize = core::Cvar::get("r_arraysize", 4.0f * (float) sizeof(float) , core::Cvar::Archive); + size_t mb = (size_t) r_arraysize->value(); + if (mb < 8) + mb = 8; + if (mb > 256) + mb = 256; + (*r_arraysize) = (float) mb; + vertexarray = new core::VertexArray(mb); + + r_radius = core::Cvar::get("r_radius", "0", core::Cvar::Archive); r_wireframe = core::Cvar::get("r_wireframe", "0", core::Cvar::Archive); } void shutdown() { con_print << "Shutting down renderer..." << std::endl; + + glDeleteTextures(2, textures); + + // clear entity models, this will force a reload + for (std::map<unsigned int, core::Entity *>::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { + core::Entity *entity = (*it).second; + if (entity->model()) + entity->entity_model = 0; + } + + core::Model::clear(); + delete vertexarray; + vertexarray = 0; } } diff --git a/src/render/render.h b/src/render/render.h index 34ba974..00b4672 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -9,6 +9,7 @@ #include "GL/gl.h" #include "core/cvar.h" +#include "core/model.h" namespace render { @@ -23,9 +24,11 @@ namespace render { extern GLuint textures[32]; - extern core::Cvar *r_drawradius; - extern core::Cvar *r_drawstats; + extern core::Cvar *r_radius; extern core::Cvar *r_wireframe; + extern core::Cvar *r_arraysize; + + extern core::VertexArray *vertexarray; } #include "render/draw.h" diff --git a/src/server/Makefile.am b/src/server/Makefile.am index 2c46543..ed43cd7 100644 --- a/src/server/Makefile.am +++ b/src/server/Makefile.am @@ -4,5 +4,4 @@ noinst_HEADERS = console.h server.h timer.h noinst_LTLIBRARIES = libserver.la INCLUDES = -I$(top_srcdir)/src libserver_la_LDFLAGS = -avoid-version -no-undefined -libserver_la_LIBADD = $(top_builddir)/src/core/libcore.la \ - $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la +libserver_la_LIBADD = $(top_builddir)/src/core/libcore.la |