Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-05-24 10:10:37 +0000
committerStijn Buys <ingar@osirion.org>2008-05-24 10:10:37 +0000
commita010f94390422eefa366a5f390c1f9e3ccc66fd5 (patch)
tree798f63addb6931fb08208927afff509185709c7c /src
parent4a4a5473b82d1f5b6f654cabac99272bce89854b (diff)
text_length functions, improved lighting, r_bbox draws bounding boxes
Diffstat (limited to 'src')
-rw-r--r--src/audio/buffers.cc5
-rw-r--r--src/audio/sources.cc2
-rw-r--r--src/audio/sources.h2
-rw-r--r--src/auxiliary/functions.cc28
-rw-r--r--src/auxiliary/functions.h9
-rw-r--r--src/client/view.cc19
-rw-r--r--src/core/application.cc4
-rw-r--r--src/core/gameserver.cc8
-rw-r--r--src/math/color.h2
-rw-r--r--src/render/draw.cc58
-rw-r--r--src/render/render.cc7
-rw-r--r--src/render/render.h1
12 files changed, 126 insertions, 19 deletions
diff --git a/src/audio/buffers.cc b/src/audio/buffers.cc
index f7fbbb5..5ea1b05 100644
--- a/src/audio/buffers.cc
+++ b/src/audio/buffers.cc
@@ -23,7 +23,7 @@ void Buffers::init()
alGenBuffers(MAXBUFFERS, buffers);
if ((error = alGetError()) != AL_NO_ERROR) {
- con_warn << "Error " << error << " initializing OpenAL buffers!" << std::endl;
+ con_warn << "Error " << std::hex << error << " initializing OpenAL buffers!" << std::endl;
return;
}
}
@@ -80,8 +80,9 @@ size_t Buffers::load(std::string name)
size_t id = index;
alBufferData(buffers[id], format, pcm->data(), pcm->size(), pcm->samplerate());
- if (alGetError())
+ if (alGetError()!= AL_NO_ERROR) {
con_warn << "Error loading PCM data " << name << std::endl;
+ }
registry[name] = id;
index++;
diff --git a/src/audio/sources.cc b/src/audio/sources.cc
index 90a79fa..209bc94 100644
--- a/src/audio/sources.cc
+++ b/src/audio/sources.cc
@@ -21,7 +21,7 @@ void Sources::init()
alGenSources(MAXSOURCES, sources);
if ((error = alGetError()) != AL_NO_ERROR) {
- con_warn << "Error " << error << " initializing OpenAL sources!" << std::endl;
+ con_warn << "Error " << std::hex << error << " initializing OpenAL sources!" << std::endl;
return;
}
source_available[0] = true;
diff --git a/src/audio/sources.h b/src/audio/sources.h
index 405b944..f3d6470 100644
--- a/src/audio/sources.h
+++ b/src/audio/sources.h
@@ -15,7 +15,7 @@
namespace audio {
-const size_t MAXSOURCES = 128;
+const size_t MAXSOURCES = 32;
/// OpenAL sources wrapper class
class Sources {
diff --git a/src/auxiliary/functions.cc b/src/auxiliary/functions.cc
index 373a6f0..2b42bae 100644
--- a/src/auxiliary/functions.cc
+++ b/src/auxiliary/functions.cc
@@ -48,4 +48,32 @@ const std::string article(const char * word)
return w;
}
+size_t text_length(const std::string &text)
+{
+ const char *c = text.c_str();
+ size_t len = 0;
+ while (*c) {
+ if (is_color_code(c)) {
+ c++;
+ } else {
+ len++;
+ }
+ c++;
+ }
+
+ return len;
+}
+
+const std::string spaces(const std::string &text,size_t n)
+{
+ size_t l = text_length(text);
+ if (n <= l)
+ return text;
+
+ std::string s;
+ s.assign(n-l, ' ');
+ s.append(text);
+ return s;
+}
+
}
diff --git a/src/auxiliary/functions.h b/src/auxiliary/functions.h
index eff5143..cd9ed13 100644
--- a/src/auxiliary/functions.h
+++ b/src/auxiliary/functions.h
@@ -14,9 +14,10 @@
namespace aux
{
-/// if n != 1, append a plural s to word
+/// append an "s" to a word, depending on the amount
const std::string plural(const char * word, size_t n);
+/// append an "s" to a word, depending on the amount
inline const std::string plural(const std::string & word, size_t n) { return plural(word.c_str(), n); }
/// prepend the "a" or "an" article to a word
@@ -29,6 +30,12 @@ inline bool is_base_color_code(char const *c) { return ((*c == '^') && (*(c+1) >
inline bool is_core_color_code(char const *c) { return ((*c == '^') && (*(c+1) >= 'A') && (*(c+1) <= 'Z')); }
inline bool is_color_code(char const *c) { return (is_base_color_code(c) || is_core_color_code(c)); }
+
+/// length of a string, excluding color codes
+size_t text_length(const std::string &text);
+
+/// prepend spaces to a string up to the desired lenght, excluding color codes
+const std::string spaces(const std::string &text, size_t n);
}
#endif // __INCLUDED_AUX_FUNCTIONS_H__
diff --git a/src/client/view.cc b/src/client/view.cc
index 5c12710..1fcedb3 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -63,13 +63,19 @@ void reset()
gl::shademodel(GL_SMOOTH);
//gl::shademodel(GL_FLAT);
+ // load identity matrices
+ gl::matrixmode(GL_MODELVIEW);
+ gl::loadidentity();
+
+ gl::matrixmode(GL_MODELVIEW);
+ gl::loadidentity();
+
// lighting
GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
- GLfloat ambient_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
- GLfloat diffuse_light[] = { 0.4f, 0.4f, 0.4f, 1.0f };
- GLfloat specular_light[] = { 0.4f, 0.4f, 0.4f, 1.0f };
- GLfloat specular_reflectance[] = { 0.2f, 0.2f, 0.2f, 1.0f };
-
+ GLfloat ambient_light[] = { 0.01f, 0.01f, 0.01f, 1.0f };
+ GLfloat diffuse_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+ GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
@@ -78,6 +84,7 @@ void reset()
// color tracking
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+ GLfloat specular_reflectance[] = { 0.2f, 0.2f, 0.2f, 1.0f };
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance);
glMateriali(GL_FRONT, GL_SHININESS, 128); // shininess 1-128
@@ -237,7 +244,7 @@ void frame(float seconds)
const float frustumsize = 0.25f;
gl::frustum(-frustumsize*video::aspect, frustumsize*video::aspect, -frustumsize, frustumsize, 1.0f, 1024.0f);
- gl::matrixmode(GL_MODELVIEW); // map world to screen coordinates
+ gl::matrixmode(GL_MODELVIEW);
gl::loadidentity();
camera::draw(seconds); // draw the current camera transformation
diff --git a/src/core/application.cc b/src/core/application.cc
index db97af8..ac836df 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -282,8 +282,8 @@ void Application::frame(float seconds)
application_time += seconds;
// don't run zero lenght time frames
- if (seconds == 0.0f)
- return;
+ //if (seconds == 0.0f)
+ // return;
if (!connected())
return;
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 85c00ab..7e03c61 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -119,7 +119,7 @@ void GameServer::list_players(Player *player)
int count = 0;
if (!Cvar::sv_dedicated->value()) {
- msgstr << setw(3) << localplayer()->id() << setw(16) << localplayer()->name();
+ msgstr << setw(3) << localplayer()->id() << aux::spaces(localplayer()->name(), 24);
send(player, msgstr.str());
count++;
}
@@ -128,7 +128,7 @@ void GameServer::list_players(Player *player)
std::list<NetClient *>:: iterator it;
for (it = server_network->clients.begin(); it != server_network->clients.end(); it++) {
msgstr.str("");
- msgstr << setw(3) << (*it)->player()->id() << setw(16) << (*it)->player()->name();
+ msgstr << setw(3) << (*it)->player()->id() << aux::spaces((*it)->player()->name(), 24);
send(player, msgstr.str());
count++;
}
@@ -269,6 +269,8 @@ void GameServer::player_connect(Player *player)
// notify the game module
server_module->player_connect(player);
+
+ // TODO manage player list
}
void GameServer::player_disconnect(Player *player)
@@ -280,6 +282,8 @@ void GameServer::player_disconnect(Player *player)
// notify the game module
server_module->player_disconnect(player);
+
+ // TODO manage player list
}
void GameServer::frame(float seconds)
diff --git a/src/math/color.h b/src/math/color.h
index 0dd5fc8..ea6fe1c 100644
--- a/src/math/color.h
+++ b/src/math/color.h
@@ -46,6 +46,8 @@ public:
/// multiply rgb values with scalar value.
Color operator*(const float scalar) const;
+ inline float operator[](size_t index) const { return rgba_data[index]; }
+
/// pointer to the internal data
inline float *ptr() const { return (float *) rgba_data; };
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 9292460..8db77c1 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -235,6 +235,9 @@ void draw_model_shield(core::EntityControlable *entity)
/* calculate entity visibility */
void pass_prepare(float seconds)
{
+ // reset light state
+ gl::disable(GL_LIGHT1);
+
std::map<unsigned int, core::Entity *>::iterator it;
for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
@@ -286,11 +289,22 @@ void pass_prepare(float seconds)
// bright globes set level light
GLfloat light_position[4];
- for (size_t i=0; i <3; i++)
+ GLfloat diffuse_light[4];
+ GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+
+ for (size_t i=0; i <3; i++) {
light_position[i] = entity->location()[i];
+ diffuse_light[i] = entity->color()[i] * 0.4;
+ }
light_position[3] = 1.0f;
-
- glLightfv(GL_LIGHT0, GL_POSITION, light_position);
+ diffuse_light[3] = 1.0f;
+
+ glLightfv(GL_LIGHT1, GL_POSITION, light_position);
+ glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
+ glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
+ glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light);
+ gl::enable(GL_LIGHT1);
}
}
@@ -337,6 +351,44 @@ void draw_pass_default()
}
gl::pop();
+ } else if (r_bbox->value()) {
+ // draw bounding box if requested
+ model::Model *model = entity->model();
+ gl::color(entity->color());
+
+ gl::push();
+ gl::translate(entity->state()->location());
+ gl::multmatrix(entity->state()->axis());
+
+ // top
+ gl::begin(gl::LineLoop);
+ gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_maxbbox.z);
+ gl::vertex(model->model_minbbox.x, model->model_maxbbox.y, model->model_maxbbox.z);
+ gl::vertex(model->model_minbbox.x, model->model_minbbox.y, model->model_maxbbox.z);
+ gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_maxbbox.z);
+ gl::end();
+
+ // bottom
+ gl::begin(gl::LineLoop);
+ gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_minbbox.z);
+ gl::vertex(model->model_minbbox.x, model->model_maxbbox.y, model->model_minbbox.z);
+ gl::vertex(model->model_minbbox.x, model->model_minbbox.y, model->model_minbbox.z);
+ gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_minbbox.z);
+ gl::end();
+
+ gl::begin(gl::Lines);
+ gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_maxbbox.z);
+ gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_minbbox.z);
+ gl::vertex(model->model_minbbox.x, model->model_maxbbox.y, model->model_maxbbox.z);
+ gl::vertex(model->model_minbbox.x, model->model_maxbbox.y, model->model_minbbox.z);
+ gl::vertex(model->model_minbbox.x, model->model_minbbox.y, model->model_maxbbox.z);
+ gl::vertex(model->model_minbbox.x, model->model_minbbox.y, model->model_minbbox.z);
+ gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_maxbbox.z);
+ gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_minbbox.z);
+ gl::end();
+
+ gl::pop();
+
}
}
}
diff --git a/src/render/render.cc b/src/render/render.cc
index e602673..87ff64a 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -13,6 +13,7 @@
#include "render/textures.h"
#include "render/tga.h"
#include "render/render.h"
+#include "model/model.h"
#include "core/core.h"
#include "filesystem/filesystem.h"
@@ -24,7 +25,8 @@ GLuint textures[32];
core::Cvar *r_radius = 0;
core::Cvar *r_wireframe = 0;
-core::Cvar * r_arraysize = 0;
+core::Cvar *r_arraysize = 0;
+core::Cvar *r_bbox = 0;
using model::VertexArray;
@@ -80,6 +82,9 @@ void init()
r_wireframe = core::Cvar::get("r_wireframe", "0", core::Cvar::Archive);
r_wireframe->set_info("[bool] render wireframe");
+ r_bbox = core::Cvar::get("r_bbox", "0", core::Cvar::Archive);
+ r_bbox->set_info("[bool] render model bounding box");
+
Textures::init();
Text::init();
diff --git a/src/render/render.h b/src/render/render.h
index d1f79a7..68952f1 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -23,6 +23,7 @@ namespace render {
/// shutdown the render subsystem
void shutdown();
+ extern core::Cvar *r_bbox;
extern core::Cvar *r_radius;
extern core::Cvar *r_wireframe;
extern core::Cvar *r_arraysize;