Change some class names
authorMikko Rasa <tdb@tdb.fi>
Wed, 2 May 2018 15:43:55 +0000 (18:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 2 May 2018 17:18:03 +0000 (20:18 +0300)
source/animationplayer.cpp
source/animationplayer.h
source/object.h
source/resourcemanager.cpp
source/resourcemanager.h
source/resourceobserver.h [new file with mode: 0644]
source/resourcewatcher.h

index 95b45dfd0ef5fc5869be3f62755f46888d04d27d..a3676ac90543331ddcba021b60d1c1f2c038f10b 100644 (file)
@@ -8,34 +8,34 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-AnimationPlayer::ObjectSlot &AnimationPlayer::get_slot(AnimatedObject &obj)
+AnimationPlayer::Target &AnimationPlayer::get_slot(AnimatedObject &obj)
 {
        ObjectMap::iterator i = objects.find(&obj);
        if(i!=objects.end())
                return i->second;
 
-       return objects.insert(ObjectMap::value_type(&obj, ObjectSlot(obj))).first->second;
+       return objects.insert(ObjectMap::value_type(&obj, Target(obj))).first->second;
 }
 
 void AnimationPlayer::play(AnimatedObject &obj, const Animation &anim)
 {
-       ObjectSlot &obj_slot = get_slot(obj);
-       obj_slot.animations.clear();
-       obj_slot.base_matrix = Matrix();
-       obj_slot.stacked = false;
-       obj_slot.armature = anim.get_armature();
-       obj_slot.animations.push_back(AnimationSlot(anim));
+       Target &target = get_slot(obj);
+       target.animations.clear();
+       target.base_matrix = Matrix();
+       target.stacked = false;
+       target.armature = anim.get_armature();
+       target.animations.push_back(PlayingAnimation(anim));
 }
 
 void AnimationPlayer::play_stacked(AnimatedObject &obj, const Animation &anim)
 {
-       ObjectSlot &obj_slot = get_slot(obj);
-       if(obj_slot.animations.empty())
-               obj_slot.base_matrix = *obj.get_matrix();
+       Target &target = get_slot(obj);
+       if(target.animations.empty())
+               target.base_matrix = *obj.get_matrix();
        // TODO check for incompatible armature
-       obj_slot.stacked = true;
-       obj_slot.armature = anim.get_armature();
-       obj_slot.animations.push_back(AnimationSlot(anim));
+       target.stacked = true;
+       target.armature = anim.get_armature();
+       target.animations.push_back(PlayingAnimation(anim));
 }
 
 unsigned AnimationPlayer::get_n_active_animations(const AnimatedObject &obj) const
@@ -55,7 +55,7 @@ void AnimationPlayer::stop(AnimatedObject &obj, const Animation &anim)
        if(i==objects.end())
                return;
 
-       for(vector<AnimationSlot>::iterator j=i->second.animations.begin(); j!=i->second.animations.end(); ++j)
+       for(vector<PlayingAnimation>::iterator j=i->second.animations.begin(); j!=i->second.animations.end(); ++j)
                if(j->animation==&anim)
                {
                        i->second.animations.erase(j);
@@ -83,64 +83,64 @@ void AnimationPlayer::tick(const Time::TimeDelta &dt)
        }
 }
 
-bool AnimationPlayer::tick_single(ObjectSlot &slot, const Time::TimeDelta &dt)
+bool AnimationPlayer::tick_single(Target &target, const Time::TimeDelta &dt)
 {
-       AnimationSlot &anim = slot.animations.front();
+       PlayingAnimation &anim = target.animations.front();
        anim.iterator += dt;
-       slot.object.set_matrix(anim.iterator.get_matrix());
+       target.object.set_matrix(anim.iterator.get_matrix());
 
        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(target.object, anim.animation->get_uniform_name(i), anim.iterator.get_uniform(i));
 
-       if(slot.armature)
+       if(target.armature)
        {
-               unsigned max_index = slot.armature->get_max_link_index();
+               unsigned max_index = target.armature->get_max_link_index();
                for(unsigned i=0; i<=max_index; ++i)
-                       slot.object.set_pose_matrix(i, anim.iterator.get_pose_matrix(i));
+                       target.object.set_pose_matrix(i, anim.iterator.get_pose_matrix(i));
        }
 
        return !anim.iterator.is_end();
 }
 
-bool AnimationPlayer::tick_stacked(ObjectSlot &slot, const Time::TimeDelta &dt)
+bool AnimationPlayer::tick_stacked(Target &target, const Time::TimeDelta &dt)
 {
-       Matrix matrix = slot.base_matrix;
-       for(vector<AnimationSlot>::iterator i=slot.animations.begin(); i!=slot.animations.end(); ++i)
+       Matrix matrix = target.base_matrix;
+       for(vector<PlayingAnimation>::iterator i=target.animations.begin(); i!=target.animations.end(); ++i)
        {
                i->iterator += dt;
                matrix *= i->iterator.get_matrix();
 
                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(target.object, i->animation->get_uniform_name(j), i->iterator.get_uniform(j));
        }
-       slot.object.set_matrix(matrix);
+       target.object.set_matrix(matrix);
 
-       if(slot.armature)
+       if(target.armature)
        {
-               unsigned max_index = slot.armature->get_max_link_index();
+               unsigned max_index = target.armature->get_max_link_index();
                for(unsigned i=0; i<=max_index; ++i)
                {
                        matrix = Matrix();
                        /* XXX This is in all likelihood incorrect.  The stacking should be
                        performed on local matrices. */
-                       for(vector<AnimationSlot>::iterator j=slot.animations.begin(); j!=slot.animations.end(); ++j)
+                       for(vector<PlayingAnimation>::iterator j=target.animations.begin(); j!=target.animations.end(); ++j)
                                if(j->animation->get_armature())
                                        matrix *= j->iterator.get_pose_matrix(i);
-                       slot.object.set_pose_matrix(i, matrix);
+                       target.object.set_pose_matrix(i, matrix);
                }
        }
 
-       for(vector<AnimationSlot>::iterator i=slot.animations.begin(); i!=slot.animations.end(); )
+       for(vector<PlayingAnimation>::iterator i=target.animations.begin(); i!=target.animations.end(); )
        {
                if(i->iterator.is_end())
-                       i = slot.animations.erase(i);
+                       i = target.animations.erase(i);
                else
                        ++i;
        }
 
-       return !slot.animations.empty();
+       return !target.animations.empty();
 }
 
 void AnimationPlayer::set_object_uniform(AnimatedObject &obj, const string &name, const KeyFrame::AnimatedUniform &uni)
@@ -158,14 +158,14 @@ void AnimationPlayer::set_object_uniform(AnimatedObject &obj, const string &name
 }
 
 
-AnimationPlayer::ObjectSlot::ObjectSlot(AnimatedObject &o):
+AnimationPlayer::Target::Target(AnimatedObject &o):
        object(o),
        armature(0),
        stacked(false)
 { }
 
 
-AnimationPlayer::AnimationSlot::AnimationSlot(const Animation &a):
+AnimationPlayer::PlayingAnimation::PlayingAnimation(const Animation &a):
        animation(&a),
        iterator(*animation)
 { }
index 93482c74f9b88daac2744e343f2bc04ab6bbdb42..63e6e030d03aa68b30efa2a63aa169b077986402 100644 (file)
@@ -17,31 +17,31 @@ can handle an arbitrary number of animations simultaneously.
 class AnimationPlayer
 {
 private:
-       struct AnimationSlot
+       struct PlayingAnimation
        {
                const Animation *animation;
                Animation::Iterator iterator;
 
-               AnimationSlot(const Animation &);
+               PlayingAnimation(const Animation &);
        };
 
-       struct ObjectSlot
+       struct Target: AnimationEventObserver
        {
                AnimatedObject &object;
                Matrix base_matrix;
                const Armature *armature;
-               std::vector<AnimationSlot> animations;
+               std::vector<PlayingAnimation> animations;
                bool stacked;
 
-               ObjectSlot(AnimatedObject &);
+               Target(AnimatedObject &);
        };
 
-       typedef std::map<const AnimatedObject *, ObjectSlot> ObjectMap;
+       typedef std::map<const AnimatedObject *, Target> ObjectMap;
 
        ObjectMap objects;
 
 private:
-       ObjectSlot &get_slot(AnimatedObject &);
+       Target &get_slot(AnimatedObject &);
 
 public:
        /// Plays an animation on an object.  Any previous animations are replaced.
@@ -65,8 +65,8 @@ public:
        void tick(const Time::TimeDelta &);
 
 private:
-       bool tick_single(ObjectSlot &, const Time::TimeDelta &);
-       bool tick_stacked(ObjectSlot &, const Time::TimeDelta &);
+       bool tick_single(Target &, const Time::TimeDelta &);
+       bool tick_stacked(Target &, const Time::TimeDelta &);
        static void set_object_uniform(AnimatedObject &, const std::string &, const KeyFrame::AnimatedUniform &);
 };
 
index 88a5d9e91659189310d0f3b951841fe4ef5c4cbf..c8e372601077c1b1e9c43dd82a221b53b1a904a7 100644 (file)
@@ -5,7 +5,7 @@
 #include "bindable.h"
 #include "renderable.h"
 #include "renderpass.h"
-#include "resourcewatcher.h"
+#include "resourceobserver.h"
 
 namespace Msp {
 namespace GL {
@@ -28,7 +28,7 @@ Objects can have multiple levels of detail.  The most detailed level has index
 0, with increasing indices having less detail.  When rendering an instance, the
 instance's get_level_of_detail method is called to determine which LoD to use.
 */
-class Object: public Renderable, private ResourceWatcher
+class Object: public Renderable, private ResourceObserver
 {
 private:
        struct LevelOfDetail;
index 9835adde3e8dd7efffe038f6eeb7f39a7c26101c..4b72685d4d4ba6f4594a2349101cc253b9ecd36f 100644 (file)
@@ -5,7 +5,7 @@
 #include <msp/time/utils.h>
 #include "resourcemanager.h"
 #include "resources.h"
-#include "resourcewatcher.h"
+#include "resourceobserver.h"
 
 using namespace std;
 
@@ -163,21 +163,21 @@ void ResourceManager::remove_resource(Resource &r)
        else if(state>ManagedResource::LOAD_QUEUED && state<ManagedResource::LOADED)
                thread.remove_resource(managed);
 
-       for(vector<ResourceWatcher *>::const_iterator i=managed.watchers.begin(); i!=managed.watchers.end(); ++i)
+       for(vector<ResourceObserver *>::const_iterator i=managed.observers.begin(); i!=managed.observers.end(); ++i)
                (*i)->resource_removed(r);
 
        MutexLock lock(map_mutex);
        remove_existing(resources, &r);
 }
 
-void ResourceManager::watch_resource(const Resource &r, ResourceWatcher &w)
+void ResourceManager::observe_resource(const Resource &r, ResourceObserver &w)
 {
-       get_managed_resource(r).add_watcher(w);
+       get_managed_resource(r).add_observer(w);
 }
 
-void ResourceManager::unwatch_resource(const Resource &r, ResourceWatcher &w)
+void ResourceManager::unobserve_resource(const Resource &r, ResourceObserver &w)
 {
-       get_managed_resource(r).remove_watcher(w);
+       get_managed_resource(r).remove_observer(w);
 }
 
 void ResourceManager::tick()
@@ -336,7 +336,7 @@ void ResourceManager::ManagedResource::finish_loading(bool successful)
                state = LOADED;
                data_size = resource->get_data_size();
 
-               for(vector<ResourceWatcher *>::const_iterator i=watchers.begin(); i!=watchers.end(); ++i)
+               for(vector<ResourceObserver *>::const_iterator i=observers.begin(); i!=observers.end(); ++i)
                        (*i)->resource_loaded(*resource);
        }
        else
@@ -356,21 +356,21 @@ void ResourceManager::ManagedResource::unload()
        resource->unload();
        state = NOT_LOADED;
 
-       for(vector<ResourceWatcher *>::const_iterator i=watchers.begin(); i!=watchers.end(); ++i)
+       for(vector<ResourceObserver *>::const_iterator i=observers.begin(); i!=observers.end(); ++i)
                (*i)->resource_unloaded(*resource);
 }
 
-void ResourceManager::ManagedResource::add_watcher(ResourceWatcher &w)
+void ResourceManager::ManagedResource::add_observer(ResourceObserver &w)
 {
-       if(find(watchers.begin(), watchers.end(), &w)==watchers.end())
-               watchers.push_back(&w);
+       if(find(observers.begin(), observers.end(), &w)==observers.end())
+               observers.push_back(&w);
 }
 
-void ResourceManager::ManagedResource::remove_watcher(ResourceWatcher &w)
+void ResourceManager::ManagedResource::remove_observer(ResourceObserver &w)
 {
-       vector<ResourceWatcher *>::iterator end = remove(watchers.begin(), watchers.end(), &w);
-       if(end!=watchers.end())
-               watchers.erase(end, watchers.end());
+       vector<ResourceObserver *>::iterator end = remove(observers.begin(), observers.end(), &w);
+       if(end!=observers.end())
+               observers.erase(end, observers.end());
 }
 
 
index afa2c2d073e45b32b25332a91a3be9c7c8568461..9dcd9b997a56a25214ea691d27f2f616197ae55f 100644 (file)
@@ -11,7 +11,7 @@
 namespace Msp {
 namespace GL {
 
-class ResourceWatcher;
+class ResourceObserver;
 
 class resource_load_error: public std::runtime_error
 {
@@ -62,7 +62,7 @@ private:
                State state;
                unsigned last_used;
                UInt64 data_size;
-               std::vector<ResourceWatcher *> watchers;
+               std::vector<ResourceObserver *> observers;
 
                ManagedResource(Resource &);
 
@@ -72,8 +72,8 @@ private:
                void finish_loading();
                void unload();
 
-               void add_watcher(ResourceWatcher &);
-               void remove_watcher(ResourceWatcher &);
+               void add_observer(ResourceObserver &);
+               void remove_observer(ResourceObserver &);
        };
 
        typedef std::list<ManagedResource *> LoadQueue;
@@ -152,8 +152,12 @@ public:
        void resource_used(const Resource &);
        void remove_resource(Resource &);
 
-       void watch_resource(const Resource &, ResourceWatcher &);
-       void unwatch_resource(const Resource &, ResourceWatcher &);
+       void observe_resource(const Resource &, ResourceObserver &);
+       void unobserve_resource(const Resource &, ResourceObserver &);
+
+       // Deprecated names
+       void watch_resource(const Resource &r, ResourceObserver &o) { observe_resource(r, o); }
+       void unwatch_resource(const Resource &r, ResourceObserver &o) { unobserve_resource(r, o); }
 
        void tick();
 private:
diff --git a/source/resourceobserver.h b/source/resourceobserver.h
new file mode 100644 (file)
index 0000000..d1313d3
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef MSP_GL_RESOURCEOBSERVER_H_
+#define MSP_GL_RESOURCEOBSERVER_H_
+
+namespace Msp {
+namespace GL {
+
+class Resource;
+
+class ResourceObserver
+{
+protected:
+       ResourceObserver() { }
+public:
+       virtual ~ResourceObserver() { }
+
+       virtual void resource_loaded(Resource &) { }
+       virtual void resource_unloaded(Resource &) { }
+       virtual void resource_removed(Resource &) { }
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif
index 47dc7983d9c99241ef941fdc7438018667b0fdaf..5281d24dc284c1f15176ea0ad8e1cf5678f1c0fd 100644 (file)
@@ -1,22 +1,13 @@
 #ifndef MSP_GL_RESOURCEWATCHER_H_
 #define MSP_GL_RESOURCEWATCHER_H_
 
+#include "resourceobserver.h"
+
 namespace Msp {
 namespace GL {
 
-class Resource;
-
-class ResourceWatcher
-{
-protected:
-       ResourceWatcher() { }
-public:
-       virtual ~ResourceWatcher() { }
-
-       virtual void resource_loaded(Resource &) { }
-       virtual void resource_unloaded(Resource &) { }
-       virtual void resource_removed(Resource &) { }
-};
+// Deprecated name
+typedef ResourceObserver ResourceWatcher;
 
 } // namespace GL
 } // namespace Msp