2012-02-19 04:30:59 +01:00
|
|
|
/* Copyright (C) 2012 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* Owner of all skeleton animations
|
2007-05-07 18:33:24 +02:00
|
|
|
*/
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
#include "SkeletonAnimManager.h"
|
|
|
|
|
|
|
|
#include "graphics/ColladaManager.h"
|
|
|
|
#include "graphics/Model.h"
|
|
|
|
#include "graphics/SkeletonAnimDef.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/CLogger.h"
|
2008-02-04 12:40:42 +01:00
|
|
|
#include "ps/FileIo.h"
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-08-15 22:57:31 +02:00
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CSkeletonAnimManager constructor
|
2007-03-01 19:52:53 +01:00
|
|
|
CSkeletonAnimManager::CSkeletonAnimManager(CColladaManager& colladaManager)
|
|
|
|
: m_ColladaManager(colladaManager)
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CSkeletonAnimManager destructor
|
|
|
|
CSkeletonAnimManager::~CSkeletonAnimManager()
|
|
|
|
{
|
2011-02-19 22:24:39 +01:00
|
|
|
typedef boost::unordered_map<VfsPath,CSkeletonAnimDef*>::iterator Iter;
|
2007-03-01 19:52:53 +01:00
|
|
|
for (Iter i = m_Animations.begin(); i != m_Animations.end(); ++i)
|
2004-05-30 02:46:58 +02:00
|
|
|
delete i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetAnimation: return a given animation by filename; return null if filename
|
|
|
|
// doesn't refer to valid animation file
|
2009-11-03 22:46:35 +01:00
|
|
|
CSkeletonAnimDef* CSkeletonAnimManager::GetAnimation(const VfsPath& pathname)
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
2011-03-23 14:36:20 +01:00
|
|
|
VfsPath name = pathname.ChangeExtension(L"");
|
2007-03-01 19:52:53 +01:00
|
|
|
|
|
|
|
// Find if it's already been loaded
|
2011-02-19 22:24:39 +01:00
|
|
|
boost::unordered_map<VfsPath, CSkeletonAnimDef*>::iterator iter = m_Animations.find(name);
|
2007-03-01 19:52:53 +01:00
|
|
|
if (iter != m_Animations.end())
|
2004-05-30 02:46:58 +02:00
|
|
|
return iter->second;
|
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
CSkeletonAnimDef* def = NULL;
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
// Find the file to load
|
2012-02-19 04:30:59 +01:00
|
|
|
VfsPath psaFilename = m_ColladaManager.GetLoadablePath(name, CColladaManager::PSA);
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
if (psaFilename.empty())
|
|
|
|
{
|
2011-03-23 14:36:20 +01:00
|
|
|
LOGERROR(L"Could not load animation '%ls'", pathname.string().c_str());
|
2007-03-01 19:52:53 +01:00
|
|
|
def = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
def = CSkeletonAnimDef::Load(psaFilename);
|
|
|
|
}
|
|
|
|
catch (PSERROR_File&)
|
|
|
|
{
|
2012-02-21 06:00:21 +01:00
|
|
|
LOGERROR(L"Could not load animation '%ls'", psaFilename.string().c_str());
|
2007-03-01 19:52:53 +01:00
|
|
|
}
|
2004-05-30 02:46:58 +02:00
|
|
|
}
|
2007-03-01 19:52:53 +01:00
|
|
|
|
|
|
|
if (def)
|
2011-03-23 14:36:20 +01:00
|
|
|
LOGMESSAGE(L"CSkeletonAnimManager::GetAnimation(%ls): Loaded successfully", pathname.string().c_str());
|
2007-03-01 19:52:53 +01:00
|
|
|
else
|
2011-03-23 14:36:20 +01:00
|
|
|
LOGERROR(L"CSkeletonAnimManager::GetAnimation(%ls): Failed loading, marked file as bad", pathname.string().c_str());
|
2007-03-01 19:52:53 +01:00
|
|
|
|
|
|
|
// Add to map
|
|
|
|
m_Animations[name] = def; // NULL if failed to load - we won't try loading it again
|
|
|
|
return def;
|
2004-05-30 02:46:58 +02:00
|
|
|
}
|