2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined( INCLUDED_MODELSKINKEY_H )
23 #define INCLUDED_MODELSKINKEY_H
25 #include "modelskin.h"
28 #include "stream/stringstream.h"
29 #include "moduleobserver.h"
30 #include "entitylib.h"
31 #include "traverselib.h"
33 inline void parseTextureName( CopiedString& name, const char* token ){
34 StringOutputStream cleaned( 256 );
35 cleaned << PathCleaned( token );
36 name = StringRange( cleaned.c_str(), path_get_filename_base_end( cleaned.c_str() ) ); // remove extension
39 class ModelSkinKey : public ModuleObserver
43 Callback<void()> m_skinChangedCallback;
45 ModelSkinKey( const ModelSkinKey& );
46 ModelSkinKey operator=( const ModelSkinKey& );
49 m_skin = &GlobalModelSkinCache().capture( m_name.c_str() );
50 m_skin->attach( *this );
53 m_skin->detach( *this );
54 GlobalModelSkinCache().release( m_name.c_str() );
58 ModelSkinKey( const Callback<void()>& skinChangedCallback ) : m_skinChangedCallback( skinChangedCallback ){
64 ModelSkin& get() const {
67 void skinChanged( const char* value ){
69 parseTextureName( m_name, value );
72 typedef MemberCaller<ModelSkinKey, void(const char*), &ModelSkinKey::skinChanged> SkinChangedCaller;
75 m_skinChangedCallback();
81 class InstanceSkinChanged : public scene::Instantiable::Visitor
84 void visit( scene::Instance& instance ) const {
85 //\todo don't do this for instances that are not children of the entity setting the skin
86 SkinnedModel* skinned = InstanceTypeCast<SkinnedModel>::cast( instance );
88 skinned->skinChanged();
93 inline void Node_modelSkinChanged( scene::Node& node ){
94 scene::Instantiable* instantiable = Node_getInstantiable( node );
95 ASSERT_NOTNULL( instantiable );
96 instantiable->forEachInstance( InstanceSkinChanged() );