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
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);
}
}
-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)
}
-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)
{ }
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.
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 &);
};
#include "bindable.h"
#include "renderable.h"
#include "renderpass.h"
-#include "resourcewatcher.h"
+#include "resourceobserver.h"
namespace Msp {
namespace GL {
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;
#include <msp/time/utils.h>
#include "resourcemanager.h"
#include "resources.h"
-#include "resourcewatcher.h"
+#include "resourceobserver.h"
using namespace std;
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()
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
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());
}
namespace Msp {
namespace GL {
-class ResourceWatcher;
+class ResourceObserver;
class resource_load_error: public std::runtime_error
{
State state;
unsigned last_used;
UInt64 data_size;
- std::vector<ResourceWatcher *> watchers;
+ std::vector<ResourceObserver *> observers;
ManagedResource(Resource &);
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;
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:
--- /dev/null
+#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
#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