#include "entitylib.h"
#include "traverselib.h"
-inline void parseTextureName(CopiedString &name, const char *token)
-{
- StringOutputStream cleaned(256);
- cleaned << PathCleaned(token);
- name = StringRange(cleaned.c_str(), path_get_filename_base_end(cleaned.c_str())); // remove extension
+inline void parseTextureName( CopiedString& name, const char* token ){
+ StringOutputStream cleaned( 256 );
+ cleaned << PathCleaned( token );
+ name = StringRange( cleaned.c_str(), path_get_filename_base_end( cleaned.c_str() ) ); // remove extension
}
-class ModelSkinKey : public ModuleObserver {
- CopiedString m_name;
- ModelSkin *m_skin;
- Callback<void()> m_skinChangedCallback;
-
- ModelSkinKey(const ModelSkinKey &);
-
- ModelSkinKey operator=(const ModelSkinKey &);
+class ModelSkinKey : public ModuleObserver
+{
+CopiedString m_name;
+ModelSkin* m_skin;
+Callback<void()> m_skinChangedCallback;
- void construct()
- {
- m_skin = &GlobalModelSkinCache().capture(m_name.c_str());
- m_skin->attach(*this);
- }
+ModelSkinKey( const ModelSkinKey& );
+ModelSkinKey operator=( const ModelSkinKey& );
- void destroy()
- {
- m_skin->detach(*this);
- GlobalModelSkinCache().release(m_name.c_str());
- }
+void construct(){
+ m_skin = &GlobalModelSkinCache().capture( m_name.c_str() );
+ m_skin->attach( *this );
+}
+void destroy(){
+ m_skin->detach( *this );
+ GlobalModelSkinCache().release( m_name.c_str() );
+}
public:
- ModelSkinKey(const Callback<void()> &skinChangedCallback) : m_skinChangedCallback(skinChangedCallback)
- {
- construct();
- }
-
- ~ModelSkinKey()
- {
- destroy();
- }
-
- ModelSkin &get() const
- {
- return *m_skin;
- }
-
- void skinChanged(const char *value)
- {
- destroy();
- parseTextureName(m_name, value);
- construct();
- }
-
- typedef MemberCaller<ModelSkinKey, void(const char *), &ModelSkinKey::skinChanged> SkinChangedCaller;
-
- void realise()
- {
- m_skinChangedCallback();
- }
-
- void unrealise()
- {
- }
+ModelSkinKey( const Callback<void()>& skinChangedCallback ) : m_skinChangedCallback( skinChangedCallback ){
+ construct();
+}
+~ModelSkinKey(){
+ destroy();
+}
+ModelSkin& get() const {
+ return *m_skin;
+}
+void skinChanged( const char* value ){
+ destroy();
+ parseTextureName( m_name, value );
+ construct();
+}
+typedef MemberCaller<ModelSkinKey, void(const char*), &ModelSkinKey::skinChanged> SkinChangedCaller;
+
+void realise(){
+ m_skinChangedCallback();
+}
+void unrealise(){
+}
};
-class InstanceSkinChanged : public scene::Instantiable::Visitor {
+class InstanceSkinChanged : public scene::Instantiable::Visitor
+{
public:
- void visit(scene::Instance &instance) const
- {
- //\todo don't do this for instances that are not children of the entity setting the skin
- SkinnedModel *skinned = InstanceTypeCast<SkinnedModel>::cast(instance);
- if (skinned != 0) {
- skinned->skinChanged();
- }
- }
+void visit( scene::Instance& instance ) const {
+ //\todo don't do this for instances that are not children of the entity setting the skin
+ SkinnedModel* skinned = InstanceTypeCast<SkinnedModel>::cast( instance );
+ if ( skinned != 0 ) {
+ skinned->skinChanged();
+ }
+}
};
-inline void Node_modelSkinChanged(scene::Node &node)
-{
- scene::Instantiable *instantiable = Node_getInstantiable(node);
- ASSERT_NOTNULL(instantiable);
- instantiable->forEachInstance(InstanceSkinChanged());
+inline void Node_modelSkinChanged( scene::Node& node ){
+ scene::Instantiable* instantiable = Node_getInstantiable( node );
+ ASSERT_NOTNULL( instantiable );
+ instantiable->forEachInstance( InstanceSkinChanged() );
}
#endif