Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/model/mapfile.cc11
-rw-r--r--src/model/tags.cc7
-rw-r--r--src/model/tags.h46
-rw-r--r--src/render/draw.cc35
-rw-r--r--src/render/particles.cc40
-rw-r--r--src/render/particles.h18
6 files changed, 118 insertions, 39 deletions
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index f8e541c..84fd108 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -811,8 +811,7 @@ bool MapFile::got_key_axis(math::Axis &axis)
axis.assign(yaw, pitch, roll);
} else {
unknown_value();
- }
-
+ }
return true;
} else if (got_key_float("pitch", pitch)) {
@@ -1111,7 +1110,7 @@ Model * MapFile::load(std::string const &name)
continue;
} else if (mapfile.got_key_color("_color", color)) {
- tag_light->get_color().assign(color);
+ tag_light->set_color(color);
continue;
} else if (mapfile.got_key_int("spawnflags", u)) {
@@ -1167,7 +1166,7 @@ Model * MapFile::load(std::string const &name)
continue;
} else if (mapfile.got_key_color("_color", color)) {
- tag_flare->get_color().assign(color);
+ tag_flare->set_color(color);
continue;
} else if (mapfile.got_key_int("spawnflags", u)) {
@@ -1232,6 +1231,10 @@ Model * MapFile::load(std::string const &name)
tag_particles->get_location().assign(location * SCALE);
continue;
+ } else if (mapfile.got_key_color("_color", color)) {
+ tag_particles->set_color(color);
+ continue;
+
} else if (mapfile.got_key_string("script", str)) {
tag_particles->set_script(str);
continue;
diff --git a/src/model/tags.cc b/src/model/tags.cc
index c1467a1..5993f99 100644
--- a/src/model/tags.cc
+++ b/src/model/tags.cc
@@ -4,6 +4,7 @@
the terms of the GNU General Public License version 2
*/
+#include "model/model.h"
#include "model/tags.h"
namespace model
@@ -32,8 +33,9 @@ Light::Light() :
light_entity = false;
light_engine = false;
light_strobe = false;
+ light_has_color = false;
- light_radius = 1.0f;
+ light_radius = 100.0f * SCALE;
light_frequency = 1.0f;
light_offset = 0.0f;
light_time = 0.5f;
@@ -50,6 +52,7 @@ Light::Light(const Light& other) :
light_entity = other.entity();
light_engine = other.engine();
light_strobe = other.strobe();
+ light_has_color = other.has_color();
light_radius = other.radius();
light_frequency = other.frequency();
@@ -93,6 +96,7 @@ Particles::Particles() :
{
particles_entity = false;
particles_engine = false;
+ particles_has_color = false;
particles_scale = 1.0f;
particles_cull = CullNone;
}
@@ -106,6 +110,7 @@ Particles::Particles(const Particles & other) :
particles_engine = other.engine();
particles_scale = other.scale();
particles_cull = other.cull();
+ particles_has_color = other.has_color();
}
Particles::~Particles()
diff --git a/src/model/tags.h b/src/model/tags.h
index af1bc27..586fd21 100644
--- a/src/model/tags.h
+++ b/src/model/tags.h
@@ -117,7 +117,12 @@ public:
/// light color
inline const math::Color& color() const {
return light_color;
- };
+ }
+
+ /// true if the color was set
+ inline bool has_color() const {
+ return light_has_color;
+ }
/// true if this is a strobe light
inline bool strobe() const {
@@ -166,7 +171,17 @@ public:
/* ---- mutators ------------------------------------------- */
/**
- * @brief set strobe color on or off
+ * @brief set the light color
+ * light color overrides engine color if the engine flag is set
+ * @see engine()
+ */
+ inline void set_color(const math::Color& color) {
+ light_color.assign(color);
+ light_has_color = true;
+ }
+
+ /**
+ * @brief set strobe on or off
*/
inline void set_strobe(const bool strobe) {
light_strobe = strobe;
@@ -227,14 +242,7 @@ public:
inline void set_texture(size_t texture) {
light_texture = texture;
}
-
- /**
- * @brief mutable reference to the color
- */
- inline math::Color& get_color() {
- return light_color;
- }
-
+
private:
bool light_strobe;
bool light_engine;
@@ -248,6 +256,7 @@ private:
float light_time;
math::Color light_color;
+ bool light_has_color;
size_t light_texture;
};
@@ -338,6 +347,16 @@ public:
inline bool engine() const {
return particles_engine;
}
+
+ inline const math::Color & color() const {
+ return particles_color;
+ }
+
+ /// true if the color was set
+ inline bool has_color() const {
+ return particles_has_color;
+ }
+
inline float scale() const {
return particles_scale;
@@ -374,6 +393,11 @@ public:
inline void set_scale(const float scale) {
particles_scale = scale;
}
+
+ inline void set_color(const math::Color &color) {
+ particles_color.assign(color);
+ particles_has_color = true;
+ }
/* ---- actors --------------------------------------------- */
@@ -387,11 +411,13 @@ public:
private:
bool particles_entity;
bool particles_engine;
+ bool particles_has_color;
Cull particles_cull;
float particles_scale;
+ math::Color particles_color;
math::Axis particles_axis;
std::string particles_script;
};
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 9ebe2cc..4cf5571 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -939,21 +939,27 @@ void draw_pass_model_fx(float elapsed)
continue; // next light
}
}
-
- // default alpha is 0.8
- a = 0.8f;
+
+ // entity color overrides light color
+ // light color overrides engine color
if (light->entity()) {
color.assign(entity->color());
+ } else if (light->has_color()) {
+ color.assign(light->color());
} else if (light->engine()) {
color.assign(entity->model()->enginecolor());
- a *= thrust;
} else {
color.assign(light->color());
}
+
+ // default alpha is 0.8, engine flag alters alpha
+ a = 0.8f;
+ if (light->engine()) {
+ a *= thrust;
+ }
color.a = a;
- location.assign(entity->location() + (entity->axis() * light->location()) * modelscale);
-
+ location.assign(entity->location() + (entity->axis() * light->location()) * modelscale);
light_size = light->radius() * modelscale;
// track OpenGL state changes
@@ -1010,24 +1016,31 @@ void draw_pass_model_fx(float elapsed)
// calulcate viewing angle factor
flare_axis.assign(entity->axis() * flare->axis());
a = math::absf(dotproduct(flare_axis.forward(), Camera::axis().forward()));
- if (a < 0.01f) {
+ if (a < 0.001f) {
continue; // next flare
}
- // alpha decreases with viewing angle
- a *= 0.8f;
+ // entity color overrides light color
+ // light color overrides engine color
if (flare->entity()) {
color.assign(entity->color());
+ } else if (flare->has_color()) {
+ color.assign(flare->color());
} else if (flare->engine()) {
color.assign(entity->model()->enginecolor());
- a *= thrust;
} else {
color.assign(flare->color());
}
+
+ // default alpha is 0.8, engine flag alters alpha
+ // alpha decreases with viewing angle
+ a *= 0.8f;
+ if (flare->engine()) {
+ a *= thrust;
+ }
color.a = a;
location.assign(entity->location() + (entity->axis() * flare->location()) * modelscale );
-
light_size = flare->radius() * modelscale;
// track OpenGL state changes
diff --git a/src/render/particles.cc b/src/render/particles.cc
index 7a0094d..2e65449 100644
--- a/src/render/particles.cc
+++ b/src/render/particles.cc
@@ -171,8 +171,12 @@ ParticleScript *ParticleScript::load(const std::string &label)
} else if (inifile.got_key_float("timeout", script->particlescript_timeout)) {
continue;
} else if (inifile.got_key_color("color", script->particlescript_color)) {
+ script->particlescript_has_color = true;
+ continue;
+ } else if (inifile.got_key_bool("engine", script->particlescript_engine)) {
+ continue;
+ } else if (inifile.got_key_bool("entity", script->particlescript_entity)) {
continue;
-
} else if (inifile.got_key_float("angle", yaw)) {
if (yaw == model::ANGLEUP) {
@@ -244,20 +248,21 @@ ParticleScript *ParticleScript::load(const std::string &label)
ParticleScript::ParticleScript(const std::string & label) : particlescript_label(label)
{
+ particlescript_entity = false;
+ particlescript_engine = false;
+ particlescript_has_color = true;
particlescript_radius = 1.0f;
particlescript_alpha = 1.0f;
particlescript_speed = 0.0f;
particlescript_timeout = 2.0f;
particlescript_eject = 0.25f;
-
particlescript_offset = 0.1f;
-
+
particlescript_color.assign(1.0f, 1.0f);
+ particlescript_cull = model::CullNone;
particlescript_next = 0;
-
- particlescript_cull = model::CullNone;
}
ParticleScript::~ParticleScript()
@@ -284,22 +289,31 @@ ParticleSystem::ParticleSystem(const ParticleScript *script, const core::Entity
particlesystem_texture = Textures::load("textures/" + particlesystem_script->texture());
particlesystem_radius = particlesystem_script->radius();
particlesystem_cull = particlesystem_script->cull();
- particlesystem_color.assign(particlesystem_script->color());
+
+ if (particlesystem_script->entity()) {
+ particlesystem_color.assign(entity->color());
+ } else if (particlesystem_script->has_color()) {
+ particlesystem_color.assign(particlesystem_script->color());
+ } else if (particlesystem_script->engine()) {
+ particlesystem_color.assign(entity->model()->enginecolor());
+ }
+
particlesystem_axis.assign(particlesystem_script->axis());
}
if (particlesystem_modelclass) {
- particlesystem_location.assign(modelclass->location());
-
- if (modelclass->entity()) {
+ particlesystem_radius *= particlesystem_modelclass->scale();
+
+ if (particlesystem_modelclass->entity()) {
particlesystem_color.assign(entity->color());
- }
- if (modelclass->engine()) {
- // FIXME if not modelclass->has_color();
+ } else if (particlesystem_modelclass->has_color()) {
+ particlesystem_color.assign(particlesystem_modelclass->color());
+ } else if (particlesystem_modelclass->engine()) {
particlesystem_color.assign(entity->model()->enginecolor());
}
+
+ particlesystem_location.assign(modelclass->location());
particlesystem_axis.assign(modelclass->axis() * particlesystem_axis);
- particlesystem_radius *= particlesystem_modelclass->scale();
}
diff --git a/src/render/particles.h b/src/render/particles.h
index 909d027..a41065c 100644
--- a/src/render/particles.h
+++ b/src/render/particles.h
@@ -72,11 +72,25 @@ public:
return particlescript_color;
}
+ inline bool has_color() const {
+ return particlescript_has_color;
+ }
+
/// axis transformation relative to the ejector
inline const math::Axis &axis() const {
return particlescript_axis;
}
+ /// true if entity color is to be applied
+ inline bool engine() const {
+ return particlescript_engine;
+ }
+
+ /// true if engine color is to be applied
+ inline bool entity() const {
+ return particlescript_entity;
+ }
+
inline float radius() const {
return particlescript_radius;
}
@@ -125,6 +139,10 @@ private:
Type particlescript_type;
math::Color particlescript_color;
math::Axis particlescript_axis;
+
+ bool particlescript_entity;
+ bool particlescript_engine;
+ bool particlescript_has_color;
float particlescript_radius;
float particlescript_timeout;