]> git.tdb.fi Git - libs/gl.git/commitdiff
Use vector when there's no reason to use some other container
authorMikko Rasa <tdb@tdb.fi>
Sat, 28 Apr 2018 15:13:29 +0000 (18:13 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 28 Apr 2018 15:13:29 +0000 (18:13 +0300)
source/animation.cpp
source/animation.h
source/animationplayer.cpp
source/animationplayer.h
source/armature.cpp
source/armature.h
source/program.h
source/programcompiler.cpp
source/programcompiler.h
source/scene.cpp
source/scene.h

index 35d2ae7aca1565f79b6934b76a5b675a89afe1e9..61c21ce8611c88f40694efedea9a35f2d687a65e 100644 (file)
@@ -228,7 +228,7 @@ Animation::Iterator &Animation::Iterator::operator+=(const Time::TimeDelta &t)
        time_since_keyframe += t;
        while(time_since_keyframe>iter->delta_t)
        {
-               KeyFrameList::const_iterator next = iter;
+               vector<TimedKeyFrame>::const_iterator next = iter;
                ++next;
                if(next==animation->keyframes.end())
                {
index 32a06075ec18269450a9ab329317e1e7551b8994..929cb13f497318c3a91492cc1cf18d36584f267e 100644 (file)
@@ -73,8 +73,6 @@ private:
                void prepare();
        };
 
-       typedef std::list<TimedKeyFrame> KeyFrameList;
-
        struct UniformInfo
        {
                std::string name;
@@ -88,7 +86,7 @@ public:
        {
        private:
                const Animation *animation;
-               KeyFrameList::const_iterator iter;
+               std::vector<TimedKeyFrame>::const_iterator iter;
                Time::TimeDelta time_since_keyframe;
                bool end;
 
@@ -105,7 +103,7 @@ public:
 
 private:
        const Armature *armature;
-       KeyFrameList keyframes;
+       std::vector<TimedKeyFrame> keyframes;
        bool looping;
        std::vector<UniformInfo> uniforms;
 
index e73d1113f2a1443948e082d44258f2f39208bc8a..95b45dfd0ef5fc5869be3f62755f46888d04d27d 100644 (file)
@@ -55,8 +55,8 @@ void AnimationPlayer::stop(AnimatedObject &obj, const Animation &anim)
        if(i==objects.end())
                return;
 
-       for(AnimationList::iterator j=i->second.animations.begin(); j!=i->second.animations.end(); ++j)
-               if(&j->animation==&anim)
+       for(vector<AnimationSlot>::iterator j=i->second.animations.begin(); j!=i->second.animations.end(); ++j)
+               if(j->animation==&anim)
                {
                        i->second.animations.erase(j);
                        break;
@@ -89,9 +89,9 @@ bool AnimationPlayer::tick_single(ObjectSlot &slot, const Time::TimeDelta &dt)
        anim.iterator += dt;
        slot.object.set_matrix(anim.iterator.get_matrix());
 
-       unsigned n_uniforms = anim.animation.get_n_uniforms();
+       unsigned n_uniforms = anim.animation->get_n_uniforms();
        for(unsigned i=0; i<n_uniforms; ++i)
-               set_object_uniform(slot.object, anim.animation.get_uniform_name(i), anim.iterator.get_uniform(i));
+               set_object_uniform(slot.object, anim.animation->get_uniform_name(i), anim.iterator.get_uniform(i));
 
        if(slot.armature)
        {
@@ -106,14 +106,14 @@ bool AnimationPlayer::tick_single(ObjectSlot &slot, const Time::TimeDelta &dt)
 bool AnimationPlayer::tick_stacked(ObjectSlot &slot, const Time::TimeDelta &dt)
 {
        Matrix matrix = slot.base_matrix;
-       for(AnimationList::iterator i=slot.animations.begin(); i!=slot.animations.end(); ++i)
+       for(vector<AnimationSlot>::iterator i=slot.animations.begin(); i!=slot.animations.end(); ++i)
        {
                i->iterator += dt;
                matrix *= i->iterator.get_matrix();
 
-               unsigned n_uniforms = i->animation.get_n_uniforms();
+               unsigned n_uniforms = i->animation->get_n_uniforms();
                for(unsigned j=0; j<n_uniforms; ++j)
-                       set_object_uniform(slot.object, i->animation.get_uniform_name(j), i->iterator.get_uniform(j));
+                       set_object_uniform(slot.object, i->animation->get_uniform_name(j), i->iterator.get_uniform(j));
        }
        slot.object.set_matrix(matrix);
 
@@ -125,17 +125,17 @@ bool AnimationPlayer::tick_stacked(ObjectSlot &slot, const Time::TimeDelta &dt)
                        matrix = Matrix();
                        /* XXX This is in all likelihood incorrect.  The stacking should be
                        performed on local matrices. */
-                       for(AnimationList::iterator j=slot.animations.begin(); j!=slot.animations.end(); ++j)
-                               if(j->animation.get_armature())
+                       for(vector<AnimationSlot>::iterator j=slot.animations.begin(); j!=slot.animations.end(); ++j)
+                               if(j->animation->get_armature())
                                        matrix *= j->iterator.get_pose_matrix(i);
                        slot.object.set_pose_matrix(i, matrix);
                }
        }
 
-       for(AnimationList::iterator i=slot.animations.begin(); i!=slot.animations.end(); )
+       for(vector<AnimationSlot>::iterator i=slot.animations.begin(); i!=slot.animations.end(); )
        {
                if(i->iterator.is_end())
-                       slot.animations.erase(i++);
+                       i = slot.animations.erase(i);
                else
                        ++i;
        }
@@ -166,8 +166,8 @@ AnimationPlayer::ObjectSlot::ObjectSlot(AnimatedObject &o):
 
 
 AnimationPlayer::AnimationSlot::AnimationSlot(const Animation &a):
-       animation(a),
-       iterator(animation)
+       animation(&a),
+       iterator(*animation)
 { }
 
 } // namespace GL
index f4eb0c767c8c660296e35c204588c40f6d7da42e..93482c74f9b88daac2744e343f2bc04ab6bbdb42 100644 (file)
@@ -19,20 +19,18 @@ class AnimationPlayer
 private:
        struct AnimationSlot
        {
-               const Animation &animation;
+               const Animation *animation;
                Animation::Iterator iterator;
 
                AnimationSlot(const Animation &);
        };
 
-       typedef std::list<AnimationSlot> AnimationList;
-
        struct ObjectSlot
        {
                AnimatedObject &object;
                Matrix base_matrix;
                const Armature *armature;
-               AnimationList animations;
+               std::vector<AnimationSlot> animations;
                bool stacked;
 
                ObjectSlot(AnimatedObject &);
index 887d974a025a59827f83ed21219b58e2f5b79f4b..6e921e3f8e9ea95246b8dae655ba54f701d0689d 100644 (file)
@@ -14,7 +14,7 @@ Armature::Link &Armature::add_link()
 
 const Armature::Link &Armature::get_link(unsigned index) const
 {
-       for(list<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
+       for(vector<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
                if(i->get_index()==index)
                        return *i;
        throw key_error(typeid(list<Link>));
@@ -22,7 +22,7 @@ const Armature::Link &Armature::get_link(unsigned index) const
 
 const Armature::Link &Armature::get_link(const string &name) const
 {
-       for(list<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
+       for(vector<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
                if(i->get_name()==name)
                        return *i;
        throw key_error(typeid(list<Link>));
@@ -31,7 +31,7 @@ const Armature::Link &Armature::get_link(const string &name) const
 unsigned Armature::get_max_link_index() const
 {
        unsigned max_index = 0;
-       for(list<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
+       for(vector<Link>::const_iterator i=links.begin(); i!=links.end(); ++i)
                max_index = max(max_index, i->get_index());
        return max_index;
 }
index 68e3c6e82325a95d1c16ce0043ec943285f91413..9dc2f505a0e62378d022fd6a525043e32c956ca3 100644 (file)
@@ -55,7 +55,7 @@ public:
        };
 
 private:
-       std::list<Link> links;
+       std::vector<Link> links;
 
 public:
        Link &add_link();
index a3fe57bfbece6c409cf7e967191e580a5fd5c5ac..cbb52cd4536e93bd0b2cd65c0f9868cfe946b1f5 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef MSP_GL_PROGRAM_H_
 #define MSP_GL_PROGRAM_H_
 
-#include <list>
 #include <string>
+#include <vector>
 #include <msp/datafile/objectloader.h>
 #include "bindable.h"
 #include "gl.h"
@@ -59,7 +59,7 @@ public:
                LayoutHash layout_hash;
        };
 
-       typedef std::list<Shader *> ShaderList;
+       typedef std::vector<Shader *> ShaderList;
        typedef std::map<std::string, UniformInfo> UniformMap;
        typedef std::map<std::string, UniformBlockInfo> UniformBlockMap;
 
index cafedc8f03180d9be4285d7e189d7a9a1e4de975..fbcc6598d3bcd5e7e74bf50bdf3762e51de9e343 100644 (file)
@@ -132,8 +132,8 @@ Stage *ProgramCompiler::get_builtins(StageType type)
 
 void ProgramCompiler::append_module(ProgramSyntax::Module &mod)
 {
-       list<Import *> imports = apply<NodeGatherer<Import> >(mod.shared);
-       for(list<Import *>::iterator i=imports.begin(); i!=imports.end(); ++i)
+       vector<Import *> imports = apply<NodeGatherer<Import> >(mod.shared);
+       for(vector<Import *>::iterator i=imports.begin(); i!=imports.end(); ++i)
                import((*i)->module);
        apply<NodeRemover>(mod.shared, set<Node *>(imports.begin(), imports.end()));
 
index be2afab6fdd4d5746c5605aa8c1e9e1ea9707146..b14c03d8021fa5fa4726aa9a9ef6b9cbbb94be1c 100644 (file)
@@ -29,7 +29,7 @@ private:
        struct BlockModifier: Visitor
        {
                bool remove_node;
-               std::list<RefPtr<ProgramSyntax::Node> > insert_nodes;
+               std::vector<RefPtr<ProgramSyntax::Node> > insert_nodes;
 
                BlockModifier();
 
@@ -81,9 +81,9 @@ private:
        template<typename T>
        struct NodeGatherer: Visitor
        {
-               typedef std::list<T *> ResultType;
+               typedef std::vector<T *> ResultType;
 
-               std::list<T *> nodes;
+               std::vector<T *> nodes;
 
                const ResultType &get_result() const { return nodes; }
                using Visitor::visit;
index fbde0cd34dff6c0960238c6d5384cef1a99fcff5..ef1f246bac0c4f61b2ec5dc3bf402bf32067f10d 100644 (file)
@@ -11,7 +11,7 @@ namespace GL {
 
 Scene::~Scene()
 {
-       for(list<Renderable *>::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
+       for(vector<Renderable *>::iterator i=owned_data.begin(); i!=owned_data.end(); ++i)
                delete *i;
 }
 
index e6e337b907388591ea82f8a769cb9f163b819f0f..9e90b1284a014e90aa9a03191172b7137c80e35b 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef MSP_GL_SCENE_H_
 #define MSP_GL_SCENE_H_
 
-#include <list>
+#include <vector>
 #include <msp/datafile/objectloader.h>
 #include "matrix.h"
 #include "renderable.h"
@@ -28,7 +28,7 @@ public:
        };
 
 protected:
-       std::list<Renderable *> owned_data;
+       std::vector<Renderable *> owned_data;
        mutable Matrix culling_matrix;
        mutable Vector4 frustum_edges[6];