Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/auxiliary/functions.cc32
-rw-r--r--src/auxiliary/functions.h7
-rw-r--r--src/client/Makefile.am6
-rw-r--r--src/client/radar.cc79
-rw-r--r--src/client/radar.h26
-rw-r--r--src/client/view.cc11
-rw-r--r--src/core/gameserver.cc2
-rw-r--r--src/render/draw.h3
8 files changed, 161 insertions, 5 deletions
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<unsigned int, core::Entity *>::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<Player *>:: 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();