Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkeletonAnimManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * Owner of all skeleton animations
20  */
21 
22 #include "precompiled.h"
23 
24 #include "SkeletonAnimManager.h"
25 
27 #include "graphics/Model.h"
29 #include "ps/CLogger.h"
30 #include "ps/FileIo.h"
31 
32 
33 ///////////////////////////////////////////////////////////////////////////////
34 // CSkeletonAnimManager constructor
36 : m_ColladaManager(colladaManager)
37 {
38 }
39 
40 ///////////////////////////////////////////////////////////////////////////////
41 // CSkeletonAnimManager destructor
43 {
44  typedef boost::unordered_map<VfsPath,CSkeletonAnimDef*>::iterator Iter;
45  for (Iter i = m_Animations.begin(); i != m_Animations.end(); ++i)
46  delete i->second;
47 }
48 
49 ///////////////////////////////////////////////////////////////////////////////
50 // GetAnimation: return a given animation by filename; return null if filename
51 // doesn't refer to valid animation file
53 {
54  VfsPath name = pathname.ChangeExtension(L"");
55 
56  // Find if it's already been loaded
57  boost::unordered_map<VfsPath, CSkeletonAnimDef*>::iterator iter = m_Animations.find(name);
58  if (iter != m_Animations.end())
59  return iter->second;
60 
61  CSkeletonAnimDef* def = NULL;
62 
63  // Find the file to load
65 
66  if (psaFilename.empty())
67  {
68  LOGERROR(L"Could not load animation '%ls'", pathname.string().c_str());
69  def = NULL;
70  }
71  else
72  {
73  try
74  {
75  def = CSkeletonAnimDef::Load(psaFilename);
76  }
77  catch (PSERROR_File&)
78  {
79  LOGERROR(L"Could not load animation '%ls'", psaFilename.string().c_str());
80  }
81  }
82 
83  if (def)
84  LOGMESSAGE(L"CSkeletonAnimManager::GetAnimation(%ls): Loaded successfully", pathname.string().c_str());
85  else
86  LOGERROR(L"CSkeletonAnimManager::GetAnimation(%ls): Failed loading, marked file as bad", pathname.string().c_str());
87 
88  // Add to map
89  m_Animations[name] = def; // NULL if failed to load - we won't try loading it again
90  return def;
91 }
VfsPath GetLoadablePath(const VfsPath &pathnameNoExtension, FileType type)
Returns the VFS path to a PMD/PSA file for the given source file.
#define LOGERROR
Definition: CLogger.h:35
#define LOGMESSAGE
Definition: CLogger.h:32
CColladaManager & m_ColladaManager
CSkeletonAnimDef * GetAnimation(const VfsPath &pathname)
boost::unordered_map< VfsPath, CSkeletonAnimDef * > m_Animations
Definition: path.h:75
const String & string() const
Definition: path.h:123
Path ChangeExtension(Path extension) const
Definition: path.h:185
CSkeletonAnimManager(CColladaManager &colladaManager)
static CSkeletonAnimDef * Load(const VfsPath &filename)