From ee017172af06f4b247038510e5ef7f8ac3596f66 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 17 Nov 2010 22:49:18 +0000 Subject: 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. --- src/model/mapfile.cc | 250 ++++++++++++++++++--------------------------------- 1 file changed, 88 insertions(+), 162 deletions(-) (limited to 'src/model/mapfile.cc') 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; } -- cgit v1.2.3