From 573ea4e5602c4321cc1d75daf9ed0beed5cde280 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 28 Apr 2018 18:13:29 +0300 Subject: [PATCH] Use vector when there's no reason to use some other container --- source/animation.cpp | 2 +- source/animation.h | 6 ++---- source/animationplayer.cpp | 26 +++++++++++++------------- source/animationplayer.h | 6 ++---- source/armature.cpp | 6 +++--- source/armature.h | 2 +- source/program.h | 4 ++-- source/programcompiler.cpp | 4 ++-- source/programcompiler.h | 6 +++--- source/scene.cpp | 2 +- source/scene.h | 4 ++-- 11 files changed, 32 insertions(+), 36 deletions(-) diff --git a/source/animation.cpp b/source/animation.cpp index 35d2ae7a..61c21ce8 100644 --- a/source/animation.cpp +++ b/source/animation.cpp @@ -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::const_iterator next = iter; ++next; if(next==animation->keyframes.end()) { diff --git a/source/animation.h b/source/animation.h index 32a06075..929cb13f 100644 --- a/source/animation.h +++ b/source/animation.h @@ -73,8 +73,6 @@ private: void prepare(); }; - typedef std::list KeyFrameList; - struct UniformInfo { std::string name; @@ -88,7 +86,7 @@ public: { private: const Animation *animation; - KeyFrameList::const_iterator iter; + std::vector::const_iterator iter; Time::TimeDelta time_since_keyframe; bool end; @@ -105,7 +103,7 @@ public: private: const Armature *armature; - KeyFrameList keyframes; + std::vector keyframes; bool looping; std::vector uniforms; diff --git a/source/animationplayer.cpp b/source/animationplayer.cpp index e73d1113..95b45dfd 100644 --- a/source/animationplayer.cpp +++ b/source/animationplayer.cpp @@ -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::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; iget_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::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; janimation.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::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::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 diff --git a/source/animationplayer.h b/source/animationplayer.h index f4eb0c76..93482c74 100644 --- a/source/animationplayer.h +++ b/source/animationplayer.h @@ -19,20 +19,18 @@ class AnimationPlayer private: struct AnimationSlot { - const Animation &animation; + const Animation *animation; Animation::Iterator iterator; AnimationSlot(const Animation &); }; - typedef std::list AnimationList; - struct ObjectSlot { AnimatedObject &object; Matrix base_matrix; const Armature *armature; - AnimationList animations; + std::vector animations; bool stacked; ObjectSlot(AnimatedObject &); diff --git a/source/armature.cpp b/source/armature.cpp index 887d974a..6e921e3f 100644 --- a/source/armature.cpp +++ b/source/armature.cpp @@ -14,7 +14,7 @@ Armature::Link &Armature::add_link() const Armature::Link &Armature::get_link(unsigned index) const { - for(list::const_iterator i=links.begin(); i!=links.end(); ++i) + for(vector::const_iterator i=links.begin(); i!=links.end(); ++i) if(i->get_index()==index) return *i; throw key_error(typeid(list)); @@ -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::const_iterator i=links.begin(); i!=links.end(); ++i) + for(vector::const_iterator i=links.begin(); i!=links.end(); ++i) if(i->get_name()==name) return *i; throw key_error(typeid(list)); @@ -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::const_iterator i=links.begin(); i!=links.end(); ++i) + for(vector::const_iterator i=links.begin(); i!=links.end(); ++i) max_index = max(max_index, i->get_index()); return max_index; } diff --git a/source/armature.h b/source/armature.h index 68e3c6e8..9dc2f505 100644 --- a/source/armature.h +++ b/source/armature.h @@ -55,7 +55,7 @@ public: }; private: - std::list links; + std::vector links; public: Link &add_link(); diff --git a/source/program.h b/source/program.h index a3fe57bf..cbb52cd4 100644 --- a/source/program.h +++ b/source/program.h @@ -1,8 +1,8 @@ #ifndef MSP_GL_PROGRAM_H_ #define MSP_GL_PROGRAM_H_ -#include #include +#include #include #include "bindable.h" #include "gl.h" @@ -59,7 +59,7 @@ public: LayoutHash layout_hash; }; - typedef std::list ShaderList; + typedef std::vector ShaderList; typedef std::map UniformMap; typedef std::map UniformBlockMap; diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index cafedc8f..fbcc6598 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -132,8 +132,8 @@ Stage *ProgramCompiler::get_builtins(StageType type) void ProgramCompiler::append_module(ProgramSyntax::Module &mod) { - list imports = apply >(mod.shared); - for(list::iterator i=imports.begin(); i!=imports.end(); ++i) + vector imports = apply >(mod.shared); + for(vector::iterator i=imports.begin(); i!=imports.end(); ++i) import((*i)->module); apply(mod.shared, set(imports.begin(), imports.end())); diff --git a/source/programcompiler.h b/source/programcompiler.h index be2afab6..b14c03d8 100644 --- a/source/programcompiler.h +++ b/source/programcompiler.h @@ -29,7 +29,7 @@ private: struct BlockModifier: Visitor { bool remove_node; - std::list > insert_nodes; + std::vector > insert_nodes; BlockModifier(); @@ -81,9 +81,9 @@ private: template struct NodeGatherer: Visitor { - typedef std::list ResultType; + typedef std::vector ResultType; - std::list nodes; + std::vector nodes; const ResultType &get_result() const { return nodes; } using Visitor::visit; diff --git a/source/scene.cpp b/source/scene.cpp index fbde0cd3..ef1f246b 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -11,7 +11,7 @@ namespace GL { Scene::~Scene() { - for(list::iterator i=owned_data.begin(); i!=owned_data.end(); ++i) + for(vector::iterator i=owned_data.begin(); i!=owned_data.end(); ++i) delete *i; } diff --git a/source/scene.h b/source/scene.h index e6e337b9..9e90b128 100644 --- a/source/scene.h +++ b/source/scene.h @@ -1,7 +1,7 @@ #ifndef MSP_GL_SCENE_H_ #define MSP_GL_SCENE_H_ -#include +#include #include #include "matrix.h" #include "renderable.h" @@ -28,7 +28,7 @@ public: }; protected: - std::list owned_data; + std::vector owned_data; mutable Matrix culling_matrix; mutable Vector4 frustum_edges[6]; -- 2.43.0