]> git.tdb.fi Git - r2c2.git/commitdiff
Support mirroring only a subset of rods based on a tag filter
authorMikko Rasa <tdb@tdb.fi>
Wed, 14 Aug 2013 14:08:20 +0000 (17:08 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 14 Aug 2013 14:08:20 +0000 (17:08 +0300)
source/libr2c2/vehicletype.cpp
source/libr2c2/vehicletype.h

index 786d18aa40f1ac3abec97fa603b7ff120b9f5f56..7200b99ec1d71518dcdded13484dab409b35e9ce 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/maputils.h>
 #include <msp/geometry/box.h>
 #include <msp/geometry/transformedshape.h>
+#include <msp/strings/regex.h>
 #include <msp/strings/format.h>
 #include "vehicletype.h"
 
@@ -179,12 +180,24 @@ void VehicleType::Loader::mirror_rods()
 {
        MirrorParametersLoader params;
        load_sub_with(params);
+       Regex r_filter(params.filter);
+
+       vector<unsigned> mirror_indices(obj.rods.size(), 0);
+       for(TagMap::const_iterator i=rod_tags.begin(); i!=rod_tags.end(); ++i)
+               if(i->second<0x10000 && r_filter.match(i->first))
+                       mirror_indices[i->second] = 1;
+
+       for(unsigned i=0, j=obj.rods.size(); i<mirror_indices.size(); ++i)
+               if(mirror_indices[i])
+                       mirror_indices[i] = j++;
 
        Transform axle_trans = Transform::rotation(params.phase_offset, Vector(0, 1, 0));
 
-       unsigned index_offset = obj.rods.size();
-       for(unsigned i=0; i<index_offset; ++i)
+       for(unsigned i=0; i<mirror_indices.size(); ++i)
        {
+               if(!mirror_indices[i])
+                       continue;
+
                Rod mr = obj.rods[i];
                mr.initial_position.y = -mr.initial_position.y;
                mr.mirror_object = !mr.mirror_object;
@@ -193,8 +206,8 @@ void VehicleType::Loader::mirror_rods()
                        j->target_position.y = -j->target_position.y;
                        j->local_position.y = -j->local_position.y;
                        j->axis.y = -j->axis.y;
-                       if(j->target==RodConstraint::ROD)
-                               j->target_index += index_offset;
+                       if(j->target==RodConstraint::ROD && mirror_indices[j->target_index])
+                               j->target_index = mirror_indices[j->target_index];
                        else if(j->target==RodConstraint::AXLE)
                                j->target_position = axle_trans.transform(j->target_position);
                }
@@ -360,9 +373,15 @@ void VehicleType::Rod::Loader::initial_position(float x, float y, float z)
 
 VehicleType::MirrorParametersLoader::MirrorParametersLoader()
 {
+       add("filter", &MirrorParametersLoader::filt);
        add("phase_offset", &MirrorParametersLoader::phase_offs);
 }
 
+void VehicleType::MirrorParametersLoader::filt(const string &f)
+{
+       filter = f;
+}
+
 void VehicleType::MirrorParametersLoader::phase_offs(float o)
 {
        phase_offset = Angle::from_degrees(o);
index 1305a19263a2a11488e03ba95268d314d671abed..a02791503e1ed700fee92f7bca0490e487c82fdf 100644 (file)
@@ -148,10 +148,12 @@ public:
        class MirrorParametersLoader: public Msp::DataFile::Loader
        {
        public:
+               std::string filter;
                Angle phase_offset;
 
                MirrorParametersLoader();
        private:
+               void filt(const std::string &);
                void phase_offs(float);
        };