From f71901eeab126bb4b7e2552dd2edf0b34632c683 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 26 May 2008 16:34:39 +0000 Subject: radar, aux text functions, restore original frustum, documentation update --- MODELS | 12 ++++++- osirion.kdevelop | 2 +- osirion.kdevelop.pcs | Bin 720726 -> 728934 bytes osirion.kdevses | 27 +++++++++++++++- src/auxiliary/functions.cc | 32 ++++++++++++++++++ src/auxiliary/functions.h | 7 ++++ src/client/Makefile.am | 6 ++-- src/client/radar.cc | 79 +++++++++++++++++++++++++++++++++++++++++++++ src/client/radar.h | 26 +++++++++++++++ src/client/view.cc | 11 ++++++- src/core/gameserver.cc | 2 +- src/render/draw.h | 3 ++ 12 files changed, 199 insertions(+), 8 deletions(-) create mode 100644 src/client/radar.cc create mode 100644 src/client/radar.h diff --git a/MODELS b/MODELS index 4a876c4..4ecd03a 100644 --- a/MODELS +++ b/MODELS @@ -153,6 +153,17 @@ Lights In short, the green light should be on the right side, the red light on the left side. +Flares + + The default light entity creates omnidirectional lights. To create + a directional flare, use the target_flare entity. Values for a + target_flare are the same as those for a default light, with one + small diference: the size of the flare is set through the radius + value. The default flare radius is 100. Rotate the entity or set the + angle value to point the flare in a different direction. + + target_flares can only be rotated in the XY-plane. + Engines Add a target_engine entity to add an engine exhaust to a ship model. @@ -167,4 +178,3 @@ Other entities target_cockpit, target_turret and target_cannon are not yet implemented. - diff --git a/osirion.kdevelop b/osirion.kdevelop index 82878a1..58a8bfc 100644 --- a/osirion.kdevelop +++ b/osirion.kdevelop @@ -21,7 +21,7 @@ - src/game/libgame.la + src/client/libclient.la debug diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs index f8f5974..cb82248 100644 Binary files a/osirion.kdevelop.pcs and b/osirion.kdevelop.pcs differ diff --git a/osirion.kdevses b/osirion.kdevses index e8415d1..2b16c97 100644 --- a/osirion.kdevses +++ b/osirion.kdevses @@ -1,7 +1,32 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/auxiliary/functions.cc b/src/auxiliary/functions.cc index b417a4a..e9861ac 100644 --- a/src/auxiliary/functions.cc +++ b/src/auxiliary/functions.cc @@ -64,6 +64,38 @@ size_t text_length(const std::string &text) return len; } +const std::string text_strip(const std::string &text) +{ + const char *c = text.c_str(); + std::string r; + while (*c) { + if (is_color_code(c)) { + c++; + } else { + r += *c; + } + c++; + } + + return r; +} + +const std::string text_strip_lowercase(const std::string &text) +{ + const char *c = text.c_str(); + std::string r; + while (*c) { + if (is_color_code(c)) { + c++; + } else { + r += tolower(*c); + } + c++; + } + + return r; +} + const std::string spaces(const std::string &text,size_t n) { size_t l = text_length(text); diff --git a/src/auxiliary/functions.h b/src/auxiliary/functions.h index 2202b87..90eb2ed 100644 --- a/src/auxiliary/functions.h +++ b/src/auxiliary/functions.h @@ -42,6 +42,13 @@ void to_lowercase(std::string &text); /// return text, converted to lowercase const std::string lowercase(const std::string &text); + +/// return text, stripped of color codes +const std::string text_strip(const std::string &text); + +/// return text, stripped of color codes and converted to lowercase +const std::string text_strip_lowercase(const std::string &text); + } #endif // __INCLUDED_AUX_FUNCTIONS_H__ diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 8022dfa..7e0c9e9 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -2,11 +2,11 @@ METASOURCES = AUTO INCLUDES = -I$(top_srcdir)/src libclient_la_SOURCES = camera.cc chat.cc client.cc console.cc hud.cc input.cc \ - keyboard.cc video.cc view.cc + keyboard.cc radar.cc video.cc view.cc libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) 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 +noinst_HEADERS = camera.h chat.h client.h console.h input.h keyboard.h radar.h \ + video.h view.h libclient_la_LIBADD = $(top_builddir)/src/render/librender.la \ $(top_builddir)/src/core/libcore.la diff --git a/src/client/radar.cc b/src/client/radar.cc new file mode 100644 index 0000000..cc4257e --- /dev/null +++ b/src/client/radar.cc @@ -0,0 +1,79 @@ +/* + client/rader.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "core/core.h" +#include "client/radar.h" +#include "client/video.h" +#include "render/draw.h" +#include "render/render.h" +namespace client +{ + +void Radar::draw() +{ + using namespace render; + + if (!core::localcontrol()) + return; + + const float width = (float) video::width/4; + const float height = (float) video::height/4; + + const float margin = 16; + const float xscale = 128; + const float yscale = xscale * height / width; + + const float left = video::width - margin - width; + const float top = video::height -margin - height; + + gl::disable(GL_TEXTURE_2D); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + //glEnableClientState(GL_COLOR_ARRAY); + + // draw the transparent radar background + gl::color(0.0f, 0.0f, 0.0f, 0.2f); + gl::begin(gl::Quads); + gl::vertex(left, top, 0.0f); + gl::vertex(left + width, top, 0.0f); + gl::vertex(left + width, top + height, 0.0f); + gl::vertex(left, top + height, 0.0f); + gl::end(); + + math::Vector3f center(core::localcontrol()->location()); + + gl::begin(gl::Points); + std::map::iterator it; + for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { + core::Entity *entity = (*it).second; + + math::Vector3f position(entity->state()->location() - center); + if ((position.x > -yscale) && (position.x < yscale) && (position.y > -xscale) && (position.y < xscale)) { + float x = left + width/2 - position.y / xscale * width/2; + float y = top + height/2 - position.x / xscale * width/2; + if (entity->type() == core::Entity::Globe) { + gl::end(); + gl::push(); + gl::translate(x, y, 0); + float r = entity->radius() / xscale * width/2; + draw_sphere(entity->color(), r); + gl::pop(); + gl::begin(gl::Points); + } else { + gl::color(entity->color()); + gl::vertex(x , y , 0); + } + } + } + gl::end(); + + gl::enable(GL_TEXTURE_2D); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + //glDisableClientState(GL_COLOR_ARRAY); +} + +} diff --git a/src/client/radar.h b/src/client/radar.h new file mode 100644 index 0000000..d3eee4d --- /dev/null +++ b/src/client/radar.h @@ -0,0 +1,26 @@ +/* + client/rader.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_CLIENT_RADAR_H__ +#define __INCLUDED_CLIENT_RADAR_H__ + +#include "render/render.h" +#include "render/gl.h" +#include "render/text.h" + +namespace client { + +/// Class to draw the radar view +class Radar { + +public: + /// draw the radar view + static void draw(); +}; + +} + +#endif // __INCLUDED_CLIENT_RADAR_H__ diff --git a/src/client/view.cc b/src/client/view.cc index 174e1ed..d5f7d49 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -16,6 +16,7 @@ #include "client/chat.h" #include "client/console.h" #include "client/input.h" +#include "client/radar.h" #include "client/video.h" #include "render/draw.h" #include "render/render.h" @@ -31,6 +32,7 @@ namespace client core::Cvar *draw_ui = 0; core::Cvar *draw_stats = 0; core::Cvar *cl_crosshaircolor = 0; +core::Cvar *draw_radar = 0; namespace view { @@ -47,6 +49,9 @@ void init() draw_ui = core::Cvar::get("draw_ui", "1", core::Cvar::Archive); draw_ui->set_info("[bool] draw the user interface"); + draw_radar = core::Cvar::get("draw_radar", "1", core::Cvar::Archive); + draw_radar->set_info("[bool] draw the radar view"); + cl_crosshaircolor = core::Cvar::get("cl_crosshaircolor", "1 1 1", core::Cvar::Archive); cl_crosshaircolor->set_info("[r g b] crosshairs color"); } @@ -245,7 +250,7 @@ void frame(float seconds) gl::loadidentity(); // FIXME width must always be one - const float frustumsize = 0.4f; + const float frustumsize = .5f; gl::frustum(-frustumsize*video::aspect, frustumsize*video::aspect, -frustumsize, frustumsize, 1.0f, 1024.0f); gl::matrixmode(GL_MODELVIEW); @@ -277,6 +282,10 @@ void frame(float seconds) console()->draw(); chat::draw(); + if (draw_radar->value()) { + Radar::draw(); + } + if (draw_ui->value()) { Text::setfont("bitmaps/fonts/gui", 16, 24); draw_status(); diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 5d973f1..46cb742 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -131,7 +131,7 @@ Player *GameServer::find_player(std::string const search) return 0; for (std::list:: iterator it = players.begin(); it != players.end(); it++) { - if (lowercase((*it)->name()).find(lowercase(search)) != std::string::npos) + if (aux::text_strip_lowercase((*it)->name()).find(lowercase(search)) != std::string::npos) return (*it); } diff --git a/src/render/draw.h b/src/render/draw.h index c7d68b1..a260f34 100644 --- a/src/render/draw.h +++ b/src/render/draw.h @@ -16,6 +16,9 @@ namespace render /// draw the world void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f const &target, float seconds); +/// draw a sphere +void draw_sphere(math::Color const & color, float radius); + class Stats { public: static void clear(); -- cgit v1.2.3