Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-11-17 22:49:18 +0000
committerStijn Buys <ingar@osirion.org>2010-11-17 22:49:18 +0000
commitee017172af06f4b247038510e5ef7f8ac3596f66 (patch)
treed5103d67ed5e403a651c9963e8ae6e6aa2d5240d /src/model
parent145ce988324b8b7b1f2b329f618ad5c6dfc4aac9 (diff)
Cleaned up model::Mapfile axis related keys in the map reader, added warning messages where approriate. Support for multiple particle systems in render::ParticleScript. Cleaned up render::ParticleScript member variable names. Added support for axis related keys and scale key in particle scripts.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/mapfile.cc250
-rw-r--r--src/model/mapfile.h9
-rw-r--r--src/model/tags.cc32
-rw-r--r--src/model/tags.h61
4 files changed, 164 insertions, 188 deletions
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index 1dbf0df..560bbc1 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -789,6 +789,58 @@ bool MapFile::got_key_color(const char * keylabel, math::Color & color)
}
}
+bool MapFile::got_key_axis(math::Axis &axis)
+{
+ float pitch, yaw, roll = 0.0f;
+
+ if (got_key_float("angle", yaw)) {
+
+ if (yaw == ANGLEUP) {
+ axis.change_pitch(-90.0f);
+ } else if (yaw == ANGLEDOWN) {
+ axis.change_pitch(90.0f);
+ } else {
+ axis.change_direction(yaw);
+ }
+ return true;
+
+ } else if (got_key("angles")) {
+
+ std::istringstream str(value());
+ if (str >> pitch >> yaw >> roll) {
+ axis.clear();
+ axis.change_pitch(-pitch);
+ axis.change_direction(yaw);
+ axis.change_roll(-roll);
+ } else {
+ unknown_value();
+ }
+
+ return true;
+
+ } else if (got_key_float("pitch", pitch)) {
+ // TODO this warning should eventually disappear
+ unknown_error("'" + classname() + ":" + key() + "' has changed polarity");
+ axis.change_pitch(-pitch);
+
+ return true;
+
+ } else if (got_key_float("yaw", yaw)) {
+ axis.change_direction(yaw);
+
+ return true;
+
+ } else if (got_key_float("roll", roll)) {
+ // TODO this warning should eventually disappear
+ unknown_error("'" + classname() + ":" + key() + "' has changed polarity");
+ axis.change_roll(-roll);
+
+ return true;
+ }
+
+ return false;
+}
+
void MapFile::close()
{
mapfile_ifs.close();
@@ -938,6 +990,17 @@ void MapFile::warn_depricated() const
con_warn << name() << " depricated key '" << key() << "' for '" << classname() << "' at line " << line() << std::endl;
}
+void MapFile::unknown_error(const char *text) const
+{
+ con_warn << name() << " " << (text && text[0] ? text : "unknown error") << " at line " << line() << std::endl;
+}
+
+void MapFile::unknown_error(const std::string &text) const
+{
+ con_warn << name() << " " << text << " at line " << line() << std::endl;
+}
+
+
Model * MapFile::load(std::string const &name)
{
// open the .map file
@@ -965,7 +1028,6 @@ Model * MapFile::load(std::string const &name)
SubModelList submodel_list;
unsigned int u;
- float angle;
float r, s;
std::string str;
@@ -1026,42 +1088,9 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.in_class("func_rotate")) {
- if (mapfile.got_key_float("angle", angle)) {
-
- if (angle == ANGLEUP) {
- mapfile.class_axis.change_pitch(90.0f);
- } else if (angle == ANGLEDOWN) {
- mapfile.class_axis.change_pitch(-90.0f);
- } else {
- mapfile.class_axis.change_direction(angle);
- }
-
- } else if (mapfile.got_key("angles")) {
-
- std::istringstream str(mapfile.value());
- float yaw, pitch,roll = 0.0f;
-
- if (str >> yaw >> pitch >> roll) {
- mapfile.class_axis.clear();
- mapfile.class_axis.change_direction(yaw);
- mapfile.class_axis.change_pitch(pitch);
- mapfile.class_axis.change_roll(roll);
- } else {
- mapfile.unknown_value();
- }
-
- } else if (mapfile.got_key_float("direction", angle)) {
- mapfile.class_axis.change_direction(angle);
- mapfile.warn_depricated();
-
- } else if (mapfile.got_key_float("pitch", angle)) {
- mapfile.class_axis.change_pitch(angle);
- mapfile.warn_depricated();
-
- } else if (mapfile.got_key_float("roll", angle)) {
- mapfile.class_axis.change_roll(angle);
- mapfile.warn_depricated();
-
+ if (mapfile.got_key_axis(mapfile.class_axis)) {
+ continue;
+
} else if (mapfile.got_key_int("spawnflags", u)) {
mapfile.class_engine = spawnflag_isset(u, 4);
continue;
@@ -1140,7 +1169,10 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.classname().compare("fx_flare") == 0) {
// flare attributes
- if (mapfile.got_key_vector3f("origin", location)) {
+ if (mapfile.got_key_axis(tag_flare->get_axis())) {
+ continue;
+
+ } else if (mapfile.got_key_vector3f("origin", location)) {
tag_flare->get_location().assign(location * SCALE);
continue;
@@ -1177,42 +1209,6 @@ Model * MapFile::load(std::string const &name)
tag_flare->set_flare(u);
continue;
- } else if (mapfile.got_key_float("angle", angle)) {
-
- if (angle == ANGLEUP) {
- tag_flare->get_axis().change_pitch(90.0f);
- } else if (angle == ANGLEDOWN) {
- tag_flare->get_axis().change_pitch(-90.0f);
- } else {
- tag_flare->get_axis().change_direction(angle);
- }
-
- } else if (mapfile.got_key("angles")) {
-
- std::istringstream str(mapfile.value());
- float yaw, pitch,roll = 0.0f;
-
- if (str >> yaw >> pitch >> roll) {
- tag_flare->get_axis().clear();
- tag_flare->get_axis().change_direction(yaw);
- tag_flare->get_axis().change_pitch(pitch);
- tag_flare->get_axis().change_roll(roll);
- } else {
- mapfile.unknown_value();
- }
-
- } else if (mapfile.got_key_float("direction", angle)) {
- tag_flare->get_axis().change_direction(angle);
- mapfile.warn_depricated();
-
- } else if (mapfile.got_key_float("pitch", angle)) {
- tag_flare->get_axis().change_pitch(angle);
- mapfile.warn_depricated();
-
- } else if (mapfile.got_key_float("roll", angle)) {
- tag_flare->get_axis().change_roll(angle);
- mapfile.warn_depricated();
-
} else if (mapfile.got_key_string("cull", str)) {
aux::to_lowercase(str);
@@ -1239,7 +1235,10 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.classname().compare("fx_particles") == 0) {
// particle system attributes
- if (mapfile.got_key_vector3f("origin", location)) {
+ if (mapfile.got_key_axis(tag_particles->get_axis())) {
+ continue;
+
+ } else if (mapfile.got_key_vector3f("origin", location)) {
tag_particles->get_location().assign(location * SCALE);
continue;
@@ -1247,59 +1246,12 @@ Model * MapFile::load(std::string const &name)
tag_particles->set_script(str);
continue;
- } else if (mapfile.got_key_float("angle", angle)) {
- if (angle == ANGLEUP) {
- tag_particles->get_axis().change_pitch(90.0f);
- } else if (angle == ANGLEDOWN) {
- tag_particles->get_axis().change_pitch(-90.0f);
- } else {
- tag_particles->get_axis().change_direction(angle);
- }
-
- } else if (mapfile.got_key("angles")) {
-
- std::istringstream str(mapfile.value());
- float yaw, pitch,roll = 0.0f;
-
- if (str >> yaw >> pitch >> roll) {
- tag_particles->get_axis().clear();
- tag_particles->get_axis().change_direction(yaw);
- tag_particles->get_axis().change_pitch(pitch);
- tag_particles->get_axis().change_roll(roll);
- } else {
- mapfile.unknown_value();
- }
-
- } else if (mapfile.got_key_float("direction", angle)) {
- tag_particles->get_axis().change_direction(angle);
- mapfile.warn_depricated();
-
- } else if (mapfile.got_key_float("pitch", angle)) {
- tag_particles->get_axis().change_pitch(angle);
- mapfile.warn_depricated();
-
- } else if (mapfile.got_key_float("roll", angle)) {
- tag_particles->get_axis().change_roll(angle);
- mapfile.warn_depricated();
-
} else if (mapfile.got_key_int("spawnflags", u)) {
tag_particles->set_entity(spawnflag_isset(u, 2));
tag_particles->set_engine(spawnflag_isset(u, 4));
- } else if (mapfile.got_key_float("radius", r)) {
- tag_particles->set_radius(r * LIGHTSCALE);
-
- } else if (mapfile.got_key_string("cull", str)) {
- aux::to_lowercase(str);
- if (str.compare("none") == 0) {
- tag_particles->set_cull(CullNone);
- } else if (str.compare("back") == 0) {
- tag_particles->set_cull(CullBack);
- } else if (str.compare("front") == 0) {
- tag_particles->set_cull(CullFront);
- } else {
- mapfile.unknown_value();
- }
+ } else if (mapfile.got_key_float("scale", s)) {
+ tag_particles->set_scale(s);
} else if (mapfile.got_key()) {
mapfile.unknown_key();
@@ -1345,7 +1297,6 @@ Model * MapFile::load(std::string const &name)
}
-
} else if (mapfile.got_classname("misc_model")) {
// new submodel tag
@@ -1354,7 +1305,11 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.classname().compare("misc_model") == 0) {
- if (mapfile.got_key_vector3f("origin", location)) {
+ // submodel attributes
+ if (mapfile.got_key_axis(tag_submodel->get_axis())) {
+ continue;
+
+ } else if (mapfile.got_key_vector3f("origin", location)) {
tag_submodel->get_location().assign(location * SCALE);
continue;
@@ -1365,30 +1320,7 @@ Model * MapFile::load(std::string const &name)
}
tag_submodel->set_name(modelname);
continue;
-
- } else if (mapfile.got_key_float("angle", angle)) {
- if (angle == ANGLEUP) {
- tag_submodel->get_axis().change_pitch(90.0f);
- } else if (angle == ANGLEDOWN) {
- tag_submodel->get_axis().change_pitch(-90.0f);
- } else {
- tag_submodel->get_axis().change_direction(angle);
- }
- } else if (mapfile.got_key("angles")) {
-
- std::istringstream str(mapfile.value());
- float yaw, pitch,roll = 0.0f;
-
- if (str >> yaw >> pitch >> roll) {
- tag_submodel->get_axis().clear();
- tag_submodel->get_axis().change_direction(yaw);
- tag_submodel->get_axis().change_pitch(pitch);
- tag_submodel->get_axis().change_roll(roll);
- } else {
- mapfile.unknown_value();
- }
-
} else if (mapfile.got_key_float("modelscale", s)) {
if (s) {
tag_submodel->set_scale(s);
@@ -1401,7 +1333,6 @@ Model * MapFile::load(std::string const &name)
}
-
} else if (mapfile.got_classname("location_dock")) {
// new docking location
@@ -1411,20 +1342,15 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.classname().compare("location_dock") == 0) {
// dock attributes
- if (mapfile.got_key_vector3f("origin", location)) {
+ if (mapfile.got_key_axis(tag_dock->get_axis())) {
+ continue;
+
+ } else if (mapfile.got_key_vector3f("origin", location)) {
tag_dock->get_location().assign(location * SCALE);
continue;
} else if (mapfile.got_key_float("radius", r)) {
- tag_dock->set_radius(r);
- continue;
-
- } else if (mapfile.got_key("angle")) {
- // TODO
- continue;
-
- } else if (mapfile.got_key("angles")) {
- // TODO
+ tag_dock->set_radius(r * SCALE);
continue;
} else if (mapfile.got_key()) {
@@ -1539,7 +1465,7 @@ Model * MapFile::load(std::string const &name)
for (Model::ParticleSystems::const_iterator pit = submodel_model->particles().begin(); pit != submodel_model->particles().end(); pit++) {
tag_particles = new Particles(*(*pit));
tag_particles->get_location().assign(tag_submodel->location() + tag_particles->location() * tag_submodel->scale());
- tag_particles->set_radius(tag_particles->radius() * tag_submodel->scale());
+ tag_particles->set_scale(tag_particles->scale() * tag_submodel->scale());
model->add_particles(tag_particles);
}
@@ -1576,7 +1502,7 @@ Model * MapFile::load(std::string const &name)
fragmentgroup->set_location(fragmentgroup->location() - map_center);
}
- // translate tags
+ // translate tags
for (Model::Lights::iterator lit = model->lights().begin(); lit != model->lights().end(); lit++) {
(*lit)->get_location() -= map_center;
}
diff --git a/src/model/mapfile.h b/src/model/mapfile.h
index 7ee47d3..a12e295 100644
--- a/src/model/mapfile.h
+++ b/src/model/mapfile.h
@@ -105,6 +105,9 @@ private:
bool got_key_angle(const char * keylabel, float & f);
bool got_key_vector3f(const char * keylabel, math::Vector3f & v);
+
+ /// check if the last read key is one of the axis related keys (angle, angles, pitch, yaw, roll)
+ bool got_key_axis(math::Axis &axis);
/// return the number of lines read so far
@@ -152,6 +155,12 @@ private:
/// print 'depricated key' warning message to the console
void warn_depricated() const;
+
+ /// print a generic error message
+ void unknown_error(const char *text = 0) const;
+
+ /// print a generic error message
+ void unknown_error(const std::string &text) const;
/// list of planes for the current brush
std::vector<Face *> planes;
diff --git a/src/model/tags.cc b/src/model/tags.cc
index a47a16c..c1467a1 100644
--- a/src/model/tags.cc
+++ b/src/model/tags.cc
@@ -19,10 +19,6 @@ Tag::Tag(const Tag& other) : tag_location(other.location())
{
}
-Tag::Tag(const math::Vector3f& location) : tag_location(location)
-{
-}
-
Tag::~Tag()
{
}
@@ -71,12 +67,16 @@ Light::~Light()
/* ---- class Flare ------------------------------------------------ */
-Flare::Flare() : Light()
+Flare::Flare() :
+ Light(),
+ flare_axis()
{
flare_cull = CullBack;
}
-Flare::Flare(const Flare& other) : Light(other)
+Flare::Flare(const Flare& other) :
+ Light(other),
+ flare_axis(other.axis())
{
flare_cull = other.cull();
}
@@ -86,17 +86,26 @@ Flare::~Flare()
/* ---- class Particles -------------------------------------------- */
-Particles::Particles() : Tag()
+Particles::Particles() :
+ Tag(),
+ particles_axis(),
+ particles_script()
{
particles_entity = false;
particles_engine = false;
- particles_radius = 0.0f;
+ particles_scale = 1.0f;
particles_cull = CullNone;
}
-Particles::Particles(const math::Vector3f& location) :
- Tag(location)
+Particles::Particles(const Particles & other) :
+ Tag(other),
+ particles_axis(other.axis()),
+ particles_script(other.script())
{
+ particles_entity = other.entity();
+ particles_engine = other.engine();
+ particles_scale = other.scale();
+ particles_cull = other.cull();
}
Particles::~Particles()
@@ -113,6 +122,7 @@ Dock::Dock() : Tag()
Dock::Dock(const Dock& other) : Tag(other)
{
dock_radius = other.radius();
+ dock_axis.assign(other.axis());
}
Dock::~Dock()
@@ -126,7 +136,7 @@ Sound::Sound() : Tag()
}
Sound::Sound(const Sound& other) : Tag(other),
- sound_name(other.name())
+ sound_name(other.name())
{
}
diff --git a/src/model/tags.h b/src/model/tags.h
index 881b914..af1bc27 100644
--- a/src/model/tags.h
+++ b/src/model/tags.h
@@ -47,12 +47,6 @@ public:
Tag(const Tag& other);
/**
- * @brief constructor with location
- * @param location location of this part within the parent model
- */
- Tag(const math::Vector3f& location);
-
- /**
* @brief default destructor
*/
~Tag();
@@ -311,16 +305,28 @@ private:
class Particles : public Tag
{
public:
+ /**
+ * @brief default constructor
+ */
Particles();
- Particles(const math::Vector3f & location);
+ /**
+ * @brief copy constructor
+ */
+ Particles(const Particles & other);
+ /**
+ * @brief destructor
+ */
~Particles();
inline const math::Axis &axis() const {
return particles_axis;
}
+ /**
+ * @brief name of the script to load
+ */
inline const std::string& script() const {
return particles_script;
}
@@ -333,8 +339,8 @@ public:
return particles_engine;
}
- inline float radius() const {
- return particles_radius;
+ inline float scale() const {
+ return particles_scale;
}
inline Cull cull() const {
@@ -357,10 +363,6 @@ public:
particles_engine = engine;
}
- inline void set_radius(const float radius) {
- particles_radius = radius;
- }
-
inline void set_cull(const Cull cull) {
particles_cull = cull;
}
@@ -368,6 +370,10 @@ public:
inline void set_script(const std::string& script) {
particles_script.assign(script);
}
+
+ inline void set_scale(const float scale) {
+ particles_scale = scale;
+ }
/* ---- actors --------------------------------------------- */
@@ -384,8 +390,8 @@ private:
Cull particles_cull;
- float particles_radius;
-
+ float particles_scale;
+
math::Axis particles_axis;
std::string particles_script;
};
@@ -396,6 +402,9 @@ private:
class Dock : public Tag
{
public:
+ /**
+ * @brief default constructor
+ */
Dock();
/**
@@ -403,8 +412,15 @@ public:
*/
Dock(const Dock& other);
+ /**
+ * @brief destructor
+ */
~Dock();
+ inline const math::Axis &axis() const {
+ return dock_axis;
+ }
+
/// dock radius, default is 0.01f
inline float radius() const {
return dock_radius;
@@ -415,8 +431,23 @@ public:
dock_radius = radius;
}
+ /// set dock axis
+ inline void set_axis(const math::Axis& axis) {
+ dock_axis.assign(axis);
+ }
+
+ /* ---- actors --------------------------------------------- */
+
+ /**
+ * @brief mutable reference to the axis
+ */
+ inline math::Axis& get_axis() {
+ return dock_axis;
+ }
+
private:
float dock_radius;
+ math::Axis dock_axis;
};
/* ---- class Sound ------------------------------------------------ */