FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
animationmanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_ANIMATION_MANAGER_H
23 #define FIFE_ANIMATION_MANAGER_H
24 
25 // Standard C++ library includes
26 #include <map>
27 #include <string>
28 #include <vector>
29 
30 // 3rd party library includes
31 
32 // FIFE includes
33 // These includes are split up in two parts, separated by one empty line
34 // First block: files included from the FIFE root src directory
35 // Second block: files included from the same folder
36 #include "util/base/singleton.h"
37 #include "util/resource/resource.h"
39 
40 #include "animation.h"
41 
42 namespace FIFE {
43 
54  class AnimationManager : public IResourceManager, public DynamicSingleton<AnimationManager> {
55  public:
56 
60 
63  virtual ~AnimationManager();
64 
65  virtual size_t getMemoryUsed() const;
66  virtual size_t getTotalResourcesCreated() const;
67  virtual size_t getTotalResourcesLoaded() const;
68  virtual size_t getTotalResources() const;
69 
83  virtual AnimationPtr create(IResourceLoader* loader = 0);
84 
99  virtual AnimationPtr create(const std::string& name, IResourceLoader* loader = 0);
100 
119  virtual AnimationPtr load(const std::string& name, IResourceLoader* loader = 0);
120 
133  virtual AnimationPtr add(Animation* res);
134 
144  virtual bool exists(const std::string& name);
145 
155  virtual bool exists(ResourceHandle handle);
156 
167  virtual void reload(const std::string& name);
168 
179  virtual void reload(ResourceHandle handle);
180 
190  virtual void reloadAll();
191 
198  virtual void loadUnreferenced();
199 
213  virtual void free(const std::string& name);
214 
228  virtual void free(ResourceHandle handle);
229 
239  virtual void freeAll();
240 
250  virtual void freeUnreferenced();
251 
268  virtual void remove(AnimationPtr& resource);
269 
282  virtual void remove(const std::string& name);
283 
296  virtual void remove(ResourceHandle handle);
297 
307  virtual void removeAll();
308 
317  virtual void removeUnreferenced();
318 
329  virtual AnimationPtr get(const std::string& name);
330 
343  virtual AnimationPtr get(ResourceHandle handle);
344 
345  virtual AnimationPtr getPtr(const std::string& name);
346  virtual AnimationPtr getPtr(ResourceHandle handle);
347 
356  virtual ResourceHandle getResourceHandle(const std::string& name);
357 
358  virtual void invalidate(const std::string& name);
359  virtual void invalidate(ResourceHandle handle);
360  virtual void invalidateAll();
361 
362  private:
363  typedef std::map< ResourceHandle, AnimationPtr > AnimationHandleMap;
364  typedef std::map< ResourceHandle, AnimationPtr >::iterator AnimationHandleMapIterator;
365  typedef std::map< ResourceHandle, AnimationPtr >::const_iterator AnimationHandleMapConstIterator;
366  typedef std::pair< ResourceHandle, AnimationPtr > AnimationHandleMapPair;
367 
368  typedef std::map< std::string, AnimationPtr > AnimationNameMap;
369  typedef std::map< std::string, AnimationPtr >::iterator AnimationNameMapIterator;
370  typedef std::map< std::string, AnimationPtr >::const_iterator AnimationNameMapConstIterator;
371  typedef std::pair< std::string, AnimationPtr > AnimationNameMapPair;
372 
373  AnimationHandleMap m_animHandleMap;
374 
375  AnimationNameMap m_animNameMap;
376  };
377 
378 } //FIFE
379 
380 #endif //FIFE_ANIMATION_MANAGER_H
virtual ResourceHandle getResourceHandle(const std::string &name)
Gets an Animation handle by name.
virtual size_t getTotalResourcesLoaded() const
Returns the number of loaded resources.
Animation.
Definition: animation.h:53
virtual AnimationPtr getPtr(const std::string &name)
virtual size_t getTotalResources() const
Returns the number of defined resources.
virtual void freeUnreferenced()
Frees all unreferenced Animation.
std::map< std::string, AnimationPtr >::const_iterator AnimationNameMapConstIterator
std::size_t ResourceHandle
Definition: resource.h:38
virtual size_t getMemoryUsed() const
Gets the total amount of memory used by resources.
virtual AnimationPtr add(Animation *res)
Add an Animation to the manager.
virtual void removeAll()
Removes all Animations from the manager.
virtual AnimationPtr create(IResourceLoader *loader=0)
Creates a blank Animation but does not load it immediately.
std::map< ResourceHandle, AnimationPtr > AnimationHandleMap
virtual ~AnimationManager()
Destructor.
AnimationManager.
virtual void loadUnreferenced()
Loads all unreferenced Animations.
std::map< std::string, AnimationPtr >::iterator AnimationNameMapIterator
Another Singleton.
Definition: singleton.h:82
AnimationHandleMap m_animHandleMap
virtual AnimationPtr load(const std::string &name, IResourceLoader *loader=0)
Creates a blank resource and loads it from disk.
virtual size_t getTotalResourcesCreated() const
Returns the number of unloaded resources.
virtual void removeUnreferenced()
Removes all unreferenced Animations.
std::map< ResourceHandle, AnimationPtr >::const_iterator AnimationHandleMapConstIterator
virtual void invalidate(const std::string &name)
virtual bool exists(const std::string &name)
Checks to see if an Animation exists.
std::map< ResourceHandle, AnimationPtr >::iterator AnimationHandleMapIterator
virtual void reloadAll()
Reloads all Animations.
virtual void reload(const std::string &name)
Reloads an Animation.
std::map< std::string, AnimationPtr > AnimationNameMap
AnimationNameMap m_animNameMap
std::pair< std::string, AnimationPtr > AnimationNameMapPair
std::pair< ResourceHandle, AnimationPtr > AnimationHandleMapPair
virtual void free(const std::string &name)
Frees an Animation from memory.
AnimationManager()
Default constructor.
IResourceManager.
virtual void freeAll()
Frees all Animations.